From 2362b00dd27b541d718d967a217ba74572b6f65f Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=A9rald=20NICOLAS?= Date: Thu, 4 Jun 2020 17:44:51 +0200 Subject: [PATCH] =?utf8?q?mise=20=C3=A0=20jour?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx | 1 + src/SMESHUtils/SMESH_ControlPnt.cxx | 95 ++++++------ src/SMESHUtils/SMESH_ControlPnt.hxx | 28 ++-- src/SMESH_I/SMESH_Mesh_i.cxx | 156 ++++++++++---------- 4 files changed, 140 insertions(+), 140 deletions(-) diff --git a/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx b/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx index e4654aa62..165b1487c 100644 --- a/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx @@ -217,6 +217,7 @@ namespace SMESH void SetBallPosition(SMESH_Actor* theActor,TVTKIds& theIds, double theDiameter) { vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid(); + myBallPolyData->SetPoints(NULL); myBallPolyData->Reset(); myBallPolyData->DeleteCells(); myBallPolyData->SetPoints(aGrid->GetPoints()); diff --git a/src/SMESHUtils/SMESH_ControlPnt.cxx b/src/SMESHUtils/SMESH_ControlPnt.cxx index 16ab68651..2e644c135 100644 --- a/src/SMESHUtils/SMESH_ControlPnt.cxx +++ b/src/SMESHUtils/SMESH_ControlPnt.cxx @@ -58,9 +58,10 @@ namespace SMESHUtils const double& theSize, std::vector& thePoints ); - std::vector computePointsForSplitting( const gp_Pnt& p1, - const gp_Pnt& p2, - const gp_Pnt& p3 ); + void computePointsForSplitting( const gp_Pnt& p1, + const gp_Pnt& p2, + const gp_Pnt& p3, + gp_Pnt midPoints[3]); gp_Pnt tangencyPoint(const gp_Pnt& p1, const gp_Pnt& p2, const gp_Pnt& Center); @@ -164,8 +165,7 @@ void SMESHUtils::createPointsSampleFromFace( const TopoDS_Face& theFace, // Get triangles int nbTriangles = aTri->NbTriangles(); - Poly_Array1OfTriangle triangles(1,nbTriangles); - triangles=aTri->Triangles(); + const Poly_Array1OfTriangle& triangles = aTri->Triangles(); // GetNodes int nbNodes = aTri->NbNodes(); @@ -173,9 +173,10 @@ void SMESHUtils::createPointsSampleFromFace( const TopoDS_Face& theFace, nodes = aTri->Nodes(); // Iterate on triangles and subdivide them - for(int i=1; i<=nbTriangles; i++) + thePoints.reserve( thePoints.size() + nbTriangles ); + for ( int i = 1; i <= nbTriangles; i++ ) { - Poly_Triangle aTriangle = triangles.Value(i); + const Poly_Triangle& aTriangle = triangles.Value(i); gp_Pnt p1 = nodes.Value(aTriangle.Value(1)); gp_Pnt p2 = nodes.Value(aTriangle.Value(2)); gp_Pnt p3 = nodes.Value(aTriangle.Value(3)); @@ -184,7 +185,7 @@ void SMESHUtils::createPointsSampleFromFace( const TopoDS_Face& theFace, p2.Transform(aTrsf); p3.Transform(aTrsf); - subdivideTriangle(p1, p2, p3, theSize, thePoints); + subdivideTriangle( p1, p2, p3, theSize, thePoints ); } } @@ -221,10 +222,8 @@ void SMESHUtils::createPointsSampleFromSolid( const TopoDS_Solid& theSolid, // Step2 : for each face of theSolid: std::set intersections; - std::set::iterator it = intersections.begin(); - TopExp_Explorer Ex; - for (Ex.Init(theSolid,TopAbs_FACE); Ex.More(); Ex.Next()) + for ( TopExp_Explorer Ex( theSolid, TopAbs_FACE ); Ex.More(); Ex.Next() ) { // check if there is an intersection IntCurvesFace_Intersector anIntersector(TopoDS::Face(Ex.Current()), Precision::Confusion()); @@ -232,13 +231,13 @@ void SMESHUtils::createPointsSampleFromSolid( const TopoDS_Solid& theSolid, // get the intersection's parameter and store it int nbPoints = anIntersector.NbPnt(); - for(int i = 0 ; i < nbPoints ; i++ ) + for ( int i = 0 ; i < nbPoints; i++ ) { - it = intersections.insert( it, anIntersector.WParameter(i+1) ); + intersections.insert( anIntersector.WParameter(i+1) ); } } // Step3 : go through the line chunk by chunk - if ( intersections.begin() != intersections.end() ) + if ( intersections.size() > 1 ) { std::set::iterator intersectionsIterator=intersections.begin(); double first = *intersectionsIterator; @@ -254,9 +253,9 @@ void SMESHUtils::createPointsSampleFromSolid( const TopoDS_Solid& theSolid, double localStep = (second -first) / ceil( (second - first) / step ); for ( double z = Zmin + first; z < Zmin + second; z = z + localStep ) { - thePoints.push_back(ControlPnt( x, y, z, theSize )); + thePoints.emplace_back( x, y, z, theSize ); } - thePoints.push_back(ControlPnt( x, y, Zmin + second, theSize )); + thePoints.emplace_back( x, y, Zmin + second, theSize ); } first = second; innerPoints = !innerPoints; @@ -288,45 +287,45 @@ void SMESHUtils::subdivideTriangle( const gp_Pnt& p1, // and the distance between two mass centers of two neighbouring triangles // sharing an edge is < 2 * 1/2 * S = S // If the traingles share a Vertex and no Edge the distance of the mass centers - // to the Vertices is 2*D < S so the mass centers are distant of less than 2*S + // to the Vertices is 2*D < S so the mass centers are distant of less than 2*S double threshold = sqrt( 3. ) * theSize; - if ( (p1.Distance(p2) > threshold || - p2.Distance(p3) > threshold || - p3.Distance(p1) > threshold)) - { - std::vector midPoints = computePointsForSplitting(p1, p2, p3); - - subdivideTriangle( midPoints[0], midPoints[1], midPoints[2], theSize, thePoints ); - subdivideTriangle( midPoints[0], p2, midPoints[1], theSize, thePoints ); - subdivideTriangle( midPoints[2], midPoints[1], p3, theSize, thePoints ); - subdivideTriangle( p1, midPoints[0], midPoints[2], theSize, thePoints ); - } - else - { - double x = (p1.X() + p2.X() + p3.X()) / 3 ; - double y = (p1.Y() + p2.Y() + p3.Y()) / 3 ; - double z = (p1.Z() + p2.Z() + p3.Z()) / 3 ; + if ( p1.Distance(p2) > threshold || + p2.Distance(p3) > threshold || + p3.Distance(p1) > threshold ) + try + { + gp_Pnt midPoints[3]; + computePointsForSplitting( p1, p2, p3, midPoints ); + + subdivideTriangle( midPoints[0], midPoints[1], midPoints[2], theSize, thePoints ); + subdivideTriangle( midPoints[0], p2, midPoints[1], theSize, thePoints ); + subdivideTriangle( midPoints[2], midPoints[1], p3, theSize, thePoints ); + subdivideTriangle( p1, midPoints[0], midPoints[2], theSize, thePoints ); + return; + } + catch (...) + { + } - ControlPnt massCenter( x ,y ,z, theSize ); - thePoints.push_back( massCenter ); - } + gp_Pnt massCenter = ( p1.XYZ() + p2.XYZ() + p3.XYZ() ) / 3.; + thePoints.emplace_back( massCenter, theSize ); } //================================================================================ /*! * \brief Returns the appropriate points for splitting a triangle - * \brief the tangency points of the incircle are used in order to have mostly - * \brief well-shaped sub-triangles + * the tangency points of the incircle are used in order to have mostly + * well-shaped sub-triangles */ //================================================================================ -std::vector SMESHUtils::computePointsForSplitting( const gp_Pnt& p1, - const gp_Pnt& p2, - const gp_Pnt& p3 ) +void SMESHUtils::computePointsForSplitting( const gp_Pnt& p1, + const gp_Pnt& p2, + const gp_Pnt& p3, + gp_Pnt midPoints[3]) { - std::vector midPoints; //Change coordinates gp_Trsf Trsf_1; // Identity transformation gp_Ax3 reference_system(gp::Origin(), gp::DZ(), gp::DX()); // OXY @@ -359,15 +358,11 @@ std::vector SMESHUtils::computePointsForSplitting( const gp_Pnt& p1, gp_Pnt T2 = tangencyPoint( B, C, Center); gp_Pnt T3 = tangencyPoint( C, A, Center); - gp_Pnt p1_2 = T1.Transformed(Trsf_1.Inverted()); - gp_Pnt p2_3 = T2.Transformed(Trsf_1.Inverted()); - gp_Pnt p3_1 = T3.Transformed(Trsf_1.Inverted()); - - midPoints.push_back(p1_2); - midPoints.push_back(p2_3); - midPoints.push_back(p3_1); + midPoints[0] = T1.Transformed(Trsf_1.Inverted()); + midPoints[1] = T2.Transformed(Trsf_1.Inverted()); + midPoints[2] = T3.Transformed(Trsf_1.Inverted()); - return midPoints; + return; } //================================================================================ diff --git a/src/SMESHUtils/SMESH_ControlPnt.hxx b/src/SMESHUtils/SMESH_ControlPnt.hxx index 9ebdd909a..f19da4aa9 100644 --- a/src/SMESHUtils/SMESH_ControlPnt.hxx +++ b/src/SMESHUtils/SMESH_ControlPnt.hxx @@ -42,11 +42,9 @@ namespace SMESHUtils { ControlPnt() : gp_Pnt(), size(0) {} - ControlPnt( const gp_Pnt& aPnt, double theSize) + ControlPnt( const gp_Pnt& aPnt, double theSize=0) : gp_Pnt( aPnt ), size( theSize ) {} - ControlPnt(double theX,double theY,double theZ) - : gp_Pnt(theX, theY, theZ), size(0) {} - ControlPnt(double theX,double theY,double theZ, double theSize) + ControlPnt(double theX,double theY,double theZ, double theSize=0) : gp_Pnt(theX, theY, theZ), size( theSize ) {} double Size() const { return size; }; @@ -57,20 +55,20 @@ namespace SMESHUtils // Functions to get sample point from shapes SMESHUtils_EXPORT void createControlPoints( const TopoDS_Shape& theShape, - const double& theSize, - std::vector< ControlPnt >& thePoints ); + const double& theSize, + std::vector< ControlPnt >& thePoints ); - SMESHUtils_EXPORT void createPointsSampleFromEdge( const TopoDS_Edge& theEdge, - const double& theSize, - std::vector& thePoints ); + SMESHUtils_EXPORT void createPointsSampleFromEdge( const TopoDS_Edge& theEdge, + const double& theSize, + std::vector& thePoints ); - SMESHUtils_EXPORT void createPointsSampleFromFace( const TopoDS_Face& theFace, - const double& theSize, - std::vector& thePoints ); + SMESHUtils_EXPORT void createPointsSampleFromFace( const TopoDS_Face& theFace, + const double& theSize, + std::vector& thePoints ); - SMESHUtils_EXPORT void createPointsSampleFromSolid( const TopoDS_Solid& theSolid, - const double& theSize, - std::vector& thePoints ); + SMESHUtils_EXPORT void createPointsSampleFromSolid( const TopoDS_Solid& theSolid, + const double& theSize, + std::vector& thePoints ); } #endif diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index b24e3ba2d..cf2a16ea6 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -6425,8 +6425,8 @@ class SMESH_DimHyp //! fields int _dim; //!< a dimension the algo can build (concurrent dimension) int _ownDim; //!< dimension of shape of _subMesh (>=_dim) - TopTools_MapOfShape _shapeMap; //!< [sub-]shapes of dimension == _dim - SMESH_subMesh* _subMesh; + TopTools_MapOfShape _shapeMap; //!< [sub-]shapes of dimension == _dim + const SMESH_subMesh* _subMesh; list _hypotheses; //!< algo is first, then its parameters //----------------------------------------------------------------------------- @@ -6440,7 +6440,7 @@ class SMESH_DimHyp const int theDim, const TopoDS_Shape& theShape) { - _subMesh = (SMESH_subMesh*)theSubMesh; + _subMesh = theSubMesh; SetShape( theDim, theShape ); } @@ -6571,7 +6571,8 @@ void addDimHypInstance(const int theDim, theAlgo->NeedLowerHyps( theDim )) // IPAL54678 return; TDimHypList& listOfdimHyp = theDimHypListArr[theDim]; - if ( listOfdimHyp.empty() || listOfdimHyp.back()->_subMesh != theSubMesh ) { + if ( listOfdimHyp.empty() || listOfdimHyp.back()->_subMesh != theSubMesh ) + { SMESH_DimHyp* dimHyp = new SMESH_DimHyp( theSubMesh, theDim, theShape ); dimHyp->_hypotheses.push_front(theAlgo); listOfdimHyp.push_back( dimHyp ); @@ -6627,7 +6628,8 @@ void unionLists(TListOfInt& theListOfId, const int theIndx ) { TListOfListOfInt::iterator it = theListOfListOfId.begin(); - for ( int i = 0; it != theListOfListOfId.end(); it++, i++ ) { + for ( int i = 0; it != theListOfListOfId.end(); it++, i++ ) + { if ( i < theIndx ) continue; //skip already treated lists // check if other list has any same submesh object @@ -6750,82 +6752,84 @@ TListOfListOfInt SMESH_Mesh_i::findConcurrentSubMeshes() { TListOfListOfInt anOrder; ::SMESH_Mesh& mesh = GetImpl(); - { - // collect submeshes and detect concurrent algorithms and hypothesises - TDimHypList dimHypListArr[4]; // dimHyp list for each shape dimension - - map::iterator i_sm = _mapSubMesh.begin(); - for ( ; i_sm != _mapSubMesh.end(); i_sm++ ) { - ::SMESH_subMesh* sm = (*i_sm).second; - // shape of submesh - const TopoDS_Shape& aSubMeshShape = sm->GetSubShape(); - - // list of assigned hypothesises - const list & hypList = mesh.GetHypothesisList(aSubMeshShape); - // Find out dimensions where the submesh can be concurrent. - // We define the dimensions by algo of each of hypotheses in hypList - list ::const_iterator hypIt = hypList.begin(); - for( ; hypIt != hypList.end(); hypIt++ ) { - SMESH_Algo* anAlgo = 0; - const SMESH_Hypothesis* hyp = dynamic_cast(*hypIt); - if ( hyp->GetType() != SMESHDS_Hypothesis::PARAM_ALGO ) - // hyp it-self is algo - anAlgo = (SMESH_Algo*)dynamic_cast(hyp); - else { - // try to find algorithm with help of sub-shapes - TopExp_Explorer anExp( aSubMeshShape, shapeTypeByDim(hyp->GetDim()) ); - for ( ; !anAlgo && anExp.More(); anExp.Next() ) - anAlgo = mesh.GetGen()->GetAlgo( mesh, anExp.Current() ); - } - if (!anAlgo) - continue; // no algorithm assigned to a current submesh - - int dim = anAlgo->GetDim(); // top concurrent dimension (see comment to SMESH_DimHyp) - // the submesh can concurrent at (or lower dims if !anAlgo->NeedDiscreteBoundary() - // and !anAlgo->NeedLowerHyps( dim )) - // create instance of dimension-hypothesis for found concurrent dimension(s) and algorithm - for ( int j = anAlgo->NeedDiscreteBoundary() ? dim : 1, jn = dim; j <= jn; j++ ) - addDimHypInstance( j, aSubMeshShape, anAlgo, sm, hypList, dimHypListArr ); + // collect submeshes and detect concurrent algorithms and hypothesises + TDimHypList dimHypListArr[4]; // dimHyp list for each shape dimension + + map::iterator i_sm = _mapSubMesh.begin(); + for ( ; i_sm != _mapSubMesh.end(); i_sm++ ) { + ::SMESH_subMesh* sm = (*i_sm).second; + // shape of submesh + const TopoDS_Shape& aSubMeshShape = sm->GetSubShape(); + + // list of assigned hypothesises + const list & hypList = mesh.GetHypothesisList(aSubMeshShape); + // Find out dimensions where the submesh can be concurrent. + // We define the dimensions by algo of each of hypotheses in hypList + list ::const_iterator hypIt = hypList.begin(); + for( ; hypIt != hypList.end(); hypIt++ ) { + SMESH_Algo* anAlgo = 0; + const SMESH_Hypothesis* hyp = dynamic_cast(*hypIt); + if ( hyp->GetType() != SMESHDS_Hypothesis::PARAM_ALGO ) + // hyp it-self is algo + anAlgo = (SMESH_Algo*)dynamic_cast(hyp); + else { + // try to find algorithm with help of sub-shapes + TopExp_Explorer anExp( aSubMeshShape, shapeTypeByDim(hyp->GetDim()) ); + for ( ; !anAlgo && anExp.More(); anExp.Next() ) + anAlgo = mesh.GetGen()->GetAlgo( mesh, anExp.Current() ); } - } // end iterations on submesh + if (!anAlgo) + continue; // no algorithm assigned to a current submesh + + int dim = anAlgo->GetDim(); // top concurrent dimension (see comment to SMESH_DimHyp) + // the submesh can concurrent at (or lower dims if !anAlgo->NeedDiscreteBoundary() + // and !anAlgo->NeedLowerHyps( dim )) + + // create instance of dimension-hypothesis for found concurrent dimension(s) and algorithm + for ( int j = anAlgo->NeedDiscreteBoundary() ? dim : 1, jn = dim; j <= jn; j++ ) + addDimHypInstance( j, aSubMeshShape, anAlgo, sm, hypList, dimHypListArr ); + } + } // end iterations on submesh // iterate on created dimension-hypotheses and check for concurrents - for ( int i = 0; i < 4; i++ ) { - const TDimHypList& listOfDimHyp = dimHypListArr[i]; - // check for concurrents in own and other dimensions (step-by-step) - TDimHypList::const_iterator dhIt = listOfDimHyp.begin(); - for ( ; dhIt != listOfDimHyp.end(); dhIt++ ) { - const SMESH_DimHyp* dimHyp = *dhIt; - TDimHypList listOfConcurr; - set setOfConcurrIds; - // looking for concurrents and collect into own list - for ( int j = i; j < 4; j++ ) - findConcurrents( dimHyp, dimHypListArr[j], listOfConcurr, setOfConcurrIds ); - // check if any concurrents found - if ( listOfConcurr.size() > 0 ) { - // add own submesh to list of concurrent - addInOrderOfPriority( dimHyp, listOfConcurr ); - list listOfConcurrIds; - TDimHypList::iterator hypIt = listOfConcurr.begin(); - for ( ; hypIt != listOfConcurr.end(); ++hypIt ) - listOfConcurrIds.push_back( (*hypIt)->_subMesh->GetId() ); - anOrder.push_back( listOfConcurrIds ); - } + for ( int i = 0; i < 4; i++ ) + { + const TDimHypList& listOfDimHyp = dimHypListArr[i]; + // check for concurrents in own and other dimensions (step-by-step) + TDimHypList::const_iterator dhIt = listOfDimHyp.begin(); + for ( ; dhIt != listOfDimHyp.end(); dhIt++ ) + { + const SMESH_DimHyp* dimHyp = *dhIt; + TDimHypList listOfConcurr; + set setOfConcurrIds; + // looking for concurrents and collect into own list + for ( int j = i; j < 4; j++ ) + findConcurrents( dimHyp, dimHypListArr[j], listOfConcurr, setOfConcurrIds ); + // check if any concurrents found + if ( listOfConcurr.size() > 0 ) + { + // add own submesh to list of concurrent + addInOrderOfPriority( dimHyp, listOfConcurr ); + list listOfConcurrIds; + TDimHypList::iterator hypIt = listOfConcurr.begin(); + for ( ; hypIt != listOfConcurr.end(); ++hypIt ) + listOfConcurrIds.push_back( (*hypIt)->_subMesh->GetId() ); + anOrder.push_back( listOfConcurrIds ); } } + } - removeDimHyps(dimHypListArr); + removeDimHyps(dimHypListArr); - // now, minimize the number of concurrent groups - // Here we assume that lists of submeshes can have same submesh - // in case of multi-dimension algorithms, as result - // list with common submesh has to be united into one list - int listIndx = 0; - TListOfListOfInt::iterator listIt = anOrder.begin(); - for(; listIt != anOrder.end(); listIt++, listIndx++ ) - unionLists( *listIt, anOrder, listIndx + 1 ); - } + // now, minimize the number of concurrent groups + // Here we assume that lists of submeshes can have same submesh + // in case of multi-dimension algorithms, as result + // list with common submesh has to be united into one list + int listIndx = 0; + TListOfListOfInt::iterator listIt = anOrder.begin(); + for(; listIt != anOrder.end(); listIt++, listIndx++ ) + unionLists( *listIt, anOrder, listIndx + 1 ); return anOrder; } @@ -6913,7 +6917,8 @@ void SMESH_Mesh_i::convertMeshOrder (const TListOfListOfInt& theIdsOrder, theResOrder.length(nbSet); TListOfListOfInt::const_iterator it = theIdsOrder.begin(); int listIndx = 0; - for( ; it != theIdsOrder.end(); it++ ) { + for( ; it != theIdsOrder.end(); it++ ) + { // translate submesh identificators into submesh objects // takeing into account real number of concurrent lists const TListOfInt& aSubOrder = (*it); @@ -6926,7 +6931,8 @@ void SMESH_Mesh_i::convertMeshOrder (const TListOfListOfInt& theIdsOrder, aResSubSet->length(aSubOrder.size()); TListOfInt::const_iterator subIt = aSubOrder.begin(); int j; - for( j = 0; subIt != aSubOrder.end(); subIt++ ) { + for( j = 0; subIt != aSubOrder.end(); subIt++ ) + { if ( _mapSubMeshIor.find(*subIt) == _mapSubMeshIor.end() ) continue; SMESH::SMESH_subMesh_var subMesh = -- 2.30.2