1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SMESH_MeshEditor.hxx
24 // Created : Mon Apr 12 14:56:19 2004
25 // Author : Edward AGAPOV (eap)
28 #ifndef SMESH_MeshEditor_HeaderFile
29 #define SMESH_MeshEditor_HeaderFile
31 #include "SMESH_SMESH.hxx"
33 #include "SMESH_Controls.hxx"
34 #include "SMESH_TypeDefs.hxx"
35 #include "SMESH_ComputeError.hxx"
37 #include <utilities.h>
39 #include <TColStd_HSequenceOfReal.hxx>
46 class SMDS_MeshElement;
51 class SMESHDS_SubMesh;
52 class SMESH_ElementSearcher;
55 class SMESH_MesherHelper;
56 class SMESH_NodeSearcher;
65 // ============================================================
67 * \brief Editor of a mesh
69 // ============================================================
71 class SMESH_EXPORT SMESH_MeshEditor
75 SMESH_MeshEditor( SMESH_Mesh* theMesh );
77 SMESH_Mesh * GetMesh() { return myMesh; }
78 SMESHDS_Mesh * GetMeshDS();
80 const SMESH_SequenceOfElemPtr& GetLastCreatedNodes() const { return myLastCreatedNodes; }
81 const SMESH_SequenceOfElemPtr& GetLastCreatedElems() const { return myLastCreatedElems; }
82 void ClearLastCreated();
83 SMESH_ComputeErrorPtr & GetError() { return myError; }
85 // --------------------------------------------------------------------------------
86 struct ElemFeatures //!< Features of element to create
88 SMDSAbs_ElementType myType;
89 bool myIsPoly, myIsQuad;
91 double myBallDiameter;
92 std::vector<int> myPolyhedQuantities;
93 std::vector<const SMDS_MeshNode*> myNodes; // not managed by ElemFeatures
95 SMESH_EXPORT ElemFeatures( SMDSAbs_ElementType type=SMDSAbs_All, bool isPoly=false, bool isQuad=false )
96 :myType( type ), myIsPoly(isPoly), myIsQuad(isQuad), myID(-1), myBallDiameter(0) {}
98 SMESH_EXPORT ElemFeatures& Init( SMDSAbs_ElementType type, bool isPoly=false, bool isQuad=false )
99 { myType = type; myIsPoly = isPoly; myIsQuad = isQuad; return *this; }
101 SMESH_EXPORT ElemFeatures& Init( const SMDS_MeshElement* elem, bool basicOnly=true );
103 SMESH_EXPORT ElemFeatures& Init( double diameter )
104 { myType = SMDSAbs_Ball; myBallDiameter = diameter; return *this; }
106 SMESH_EXPORT ElemFeatures& Init( std::vector<int>& quanities, bool isQuad=false )
107 { myType = SMDSAbs_Volume; myIsPoly = 1; myIsQuad = isQuad;
108 myPolyhedQuantities.swap( quanities ); return *this; }
110 SMESH_EXPORT ElemFeatures& Init( const std::vector<int>& quanities, bool isQuad=false )
111 { myType = SMDSAbs_Volume; myIsPoly = 1; myIsQuad = isQuad;
112 myPolyhedQuantities = quanities; return *this; }
114 SMESH_EXPORT ElemFeatures& SetPoly(bool isPoly) { myIsPoly = isPoly; return *this; }
115 SMESH_EXPORT ElemFeatures& SetQuad(bool isQuad) { myIsQuad = isQuad; return *this; }
116 SMESH_EXPORT ElemFeatures& SetID (smIdType ID) { myID = ID; return *this; }
122 SMDS_MeshElement* AddElement(const std::vector<const SMDS_MeshNode*> & nodes,
123 const ElemFeatures& features);
127 SMDS_MeshElement* AddElement(const std::vector<smIdType> & nodeIDs,
128 const ElemFeatures& features);
130 smIdType Remove (const std::list< smIdType >& theElemIDs, const bool isNodes);
131 // Remove a node or an element.
132 // Modify a compute state of sub-meshes which become empty
134 void Create0DElementsOnAllNodes( const TIDSortedElemSet& elements,
135 TIDSortedElemSet& all0DElems,
136 const bool duplicateElements);
137 // Create 0D elements on all nodes of the given. \a all0DElems returns
138 // all 0D elements found or created on nodes of \a elements
140 bool InverseDiag (const SMDS_MeshElement * theTria1,
141 const SMDS_MeshElement * theTria2 );
142 // Replace two neighbour triangles with ones built on the same 4 nodes
143 // but having other common link.
144 // Return False if args are improper
146 bool InverseDiag (const SMDS_MeshNode * theNode1,
147 const SMDS_MeshNode * theNode2 );
148 // Replace two neighbour triangles sharing theNode1-theNode2 link
149 // with ones built on the same 4 nodes but having other common link.
150 // Return false if proper faces not found
152 bool DeleteDiag (const SMDS_MeshNode * theNode1,
153 const SMDS_MeshNode * theNode2 );
154 // Replace two neighbour triangles sharing theNode1-theNode2 link
155 // with a quadrangle built on the same 4 nodes.
156 // Return false if proper faces not found
158 bool Reorient (const SMDS_MeshElement * theElement);
159 // Reverse theElement orientation
161 int Reorient2D (TIDSortedElemSet & theFaces,
162 const gp_Vec& theDirection,
163 TIDSortedElemSet & theRefFaces,
164 bool theAllowNonManifold);
165 // Reverse theFaces whose orientation to be same as that of theRefFaces
166 // optionally oriented according to theDirection. Return nb of reoriented faces
168 int Reorient2DBy3D (TIDSortedElemSet & theFaces,
169 TIDSortedElemSet & theVolumes,
170 const bool theOutsideNormal);
171 // Reorient faces basing on orientation of adjacent volumes.
172 // Return nb of reoriented faces
175 * \brief Fuse neighbour triangles into quadrangles.
176 * \param theElems - The triangles to be fused.
177 * \param theCriterion - Is used to choose a neighbour to fuse with.
178 * \param theMaxAngle - Is a max angle between element normals at which fusion
179 * is still performed; theMaxAngle is measured in radians.
180 * \return bool - Success or not.
182 bool TriToQuad (TIDSortedElemSet & theElems,
183 SMESH::Controls::NumericalFunctorPtr theCriterion,
184 const double theMaxAngle);
186 * \brief Split quadrangles into triangles.
187 * \param theElems - The faces to be split.
188 * \param theCriterion - Is used to choose a diagonal for splitting.
189 * \return bool - Success or not.
191 bool QuadToTri (TIDSortedElemSet & theElems,
192 SMESH::Controls::NumericalFunctorPtr theCriterion);
194 * \brief Split quadrangles into triangles.
195 * \param theElems - The faces to be split.
196 * \param the13Diag - Is used to choose a diagonal for splitting.
197 * \return bool - Success or not.
199 bool QuadToTri (TIDSortedElemSet & theElems,
200 const bool the13Diag);
202 * \brief Split each of given quadrangles into 4 triangles.
203 * \param theElems - The faces to be split. If empty all faces are split.
205 void QuadTo4Tri (TIDSortedElemSet & theElems);
208 * \brief Find better diagonal for splitting.
209 * \param theQuad - The face to find better splitting of.
210 * \param theCriterion - Is used to choose a diagonal for splitting.
211 * \return int - 1 for 1-3 diagonal, 2 for 2-4, -1 - for errors.
213 int BestSplit (const SMDS_MeshElement* theQuad,
214 SMESH::Controls::NumericalFunctorPtr theCriterion);
217 typedef std::map < const SMDS_MeshElement*, int, TIDCompare > TFacetOfElem;
219 //!<2nd arg of SplitVolumes()
220 enum SplitVolumToTetraFlags { HEXA_TO_5 = 1, // split into tetrahedra
223 HEXA_TO_2_PRISMS, // split into prisms
226 * \brief Split volumic elements into tetrahedra or prisms.
227 * If facet ID < 0, element is split into tetrahedra,
228 * else a hexahedron is split into prisms so that the given facet is
229 * split into triangles
231 void SplitVolumes (const TFacetOfElem & theElems, const int theMethodFlags);
234 * \brief For hexahedra that will be split into prisms, finds facets to
235 * split into triangles
236 * \param [in,out] theHexas - the hexahedra
237 * \param [in] theFacetNormal - facet normal
238 * \param [out] theFacets - the hexahedra and found facet IDs
240 void GetHexaFacetsToSplit( TIDSortedElemSet& theHexas,
241 const gp_Ax1& theFacetNormal,
242 TFacetOfElem & theFacets);
245 * \brief Split bi-quadratic elements into linear ones without creation of additional nodes
246 * - bi-quadratic triangle will be split into 3 linear quadrangles;
247 * - bi-quadratic quadrangle will be split into 4 linear quadrangles;
248 * - tri-quadratic hexahedron will be split into 8 linear hexahedra;
249 * Quadratic elements of lower dimension adjacent to the split bi-quadratic element
250 * will be split in order to keep the mesh conformal.
251 * \param elems - elements to split
253 void SplitBiQuadraticIntoLinear(TIDSortedElemSet& theElems);
255 enum SmoothMethod { LAPLACIAN = 0, CENTROIDAL };
257 void Smooth (TIDSortedElemSet & theElements,
258 std::set<const SMDS_MeshNode*> & theFixedNodes,
259 const SmoothMethod theSmoothMethod,
260 const int theNbIterations,
261 double theTgtAspectRatio = 1.0,
262 const bool the2D = true);
263 // Smooth theElements using theSmoothMethod during theNbIterations
264 // or until a worst element has aspect ratio <= theTgtAspectRatio.
265 // Aspect Ratio varies in range [1.0, inf].
266 // If theElements is empty, the whole mesh is smoothed.
267 // theFixedNodes contains additionally fixed nodes. Nodes built
268 // on edges and boundary nodes are always fixed.
269 // If the2D, smoothing is performed using UV parameters of nodes
270 // on geometrical faces
272 typedef TIDTypeCompare TElemSort;
273 typedef std::map < const SMDS_MeshElement*,
274 std::list<const SMDS_MeshElement*>, TElemSort > TTElemOfElemListMap;
275 typedef std::map<const SMDS_MeshNode*, std::list<const SMDS_MeshNode*> > TNodeOfNodeListMap;
276 typedef TNodeOfNodeListMap::iterator TNodeOfNodeListMapItr;
277 typedef std::vector<TNodeOfNodeListMapItr> TVecOfNnlmiMap;
278 typedef std::map<const SMDS_MeshElement*, TVecOfNnlmiMap, TElemSort > TElemOfVecOfNnlmiMap;
279 typedef std::unique_ptr< std::list< int > > PGroupIDs;
281 PGroupIDs RotationSweep (TIDSortedElemSet theElements[2],
282 const gp_Ax1& theAxis,
283 const double theAngle,
284 const int theNbSteps,
285 const double theToler,
286 const bool theMakeGroups,
287 const bool theMakeWalls=true);
288 // Generate new elements by rotation of theElements around theAxis
289 // by theAngle by theNbSteps
292 * Flags of extrusion.
293 * BOUNDARY: create or not boundary for result of extrusion
294 * SEW: try to use existing nodes or create new nodes in any case
295 * GROUPS: to create groups
296 * BY_AVG_NORMAL: step size is measured along average normal to elements,
297 * else step size is measured along average normal of any element
298 * USE_INPUT_ELEMS_ONLY: to use only input elements to compute extrusion direction
299 * for ExtrusionByNormal()
300 * SCALE_LINEAR_VARIATION: to make linear variation of scale factors
301 * ANGLE_LINEAR_VARIATION: to make linear variation of angles
303 enum ExtrusionFlags {
304 EXTRUSION_FLAG_BOUNDARY = 0x01,
305 EXTRUSION_FLAG_SEW = 0x02,
306 EXTRUSION_FLAG_GROUPS = 0x04,
307 EXTRUSION_FLAG_BY_AVG_NORMAL = 0x08,
308 EXTRUSION_FLAG_USE_INPUT_ELEMS_ONLY = 0x10,
309 EXTRUSION_FLAG_SCALE_LINEAR_VARIATION = 0x20,
310 EXTRUSION_FLAG_ANGLE_LINEAR_VARIATION = 0x40
314 * Generator of nodes for extrusion functionality
316 class SMESH_EXPORT ExtrusParam
319 //! Point on extrusion path
324 double myAngle, myScale;
325 PathPoint(): myPnt(99., 99., 99.), myTgt(1.,0.,0.), myAngle(0), myScale(0) {}
328 ExtrusParam( const gp_Vec& theStep,
329 const int theNbSteps,
330 const std::list<double>& theScales,
331 const std::list<double>& theAngles,
332 const gp_XYZ* theBaseP,
333 const int theFlags = 0,
334 const double theTolerance = 1e-6);
335 ExtrusParam( const gp_Dir& theDir,
336 Handle(TColStd_HSequenceOfReal) theSteps,
337 const int theFlags = 0,
338 const double theTolerance = 1e-6);
339 ExtrusParam( const double theStep,
340 const int theNbSteps,
342 const int theDim); // for extrusion by normal
343 ExtrusParam( const std::vector< PathPoint >& thePoints,
344 const gp_Pnt* theBaseP,
345 const std::list<double>& theScales,
346 const bool theMakeGroups); // for extrusion along path
348 SMESH_SequenceOfNode& ChangeNodes() { return myNodes; }
349 int& Flags() { return myFlags; }
350 bool ToMakeBoundary() const { return myFlags & EXTRUSION_FLAG_BOUNDARY; }
351 bool ToMakeGroups() const { return myFlags & EXTRUSION_FLAG_GROUPS; }
352 bool ToUseInpElemsOnly() const { return myFlags & EXTRUSION_FLAG_USE_INPUT_ELEMS_ONLY; }
353 bool IsScaleVariation() const { return myFlags & EXTRUSION_FLAG_SCALE_LINEAR_VARIATION; }
354 bool IsAngleVariation() const { return myFlags & EXTRUSION_FLAG_ANGLE_LINEAR_VARIATION; }
355 int NbSteps() const {
356 return mySteps.IsNull() ? (int)myPathPoints.size() - 1: mySteps->Length();
358 // stores elements to use for extrusion by normal, depending on
359 // state of EXTRUSION_FLAG_USE_INPUT_ELEMS_ONLY flag;
360 // define myBaseP for scaling
361 void SetElementsToUse( const TIDSortedElemSet& elems, const TIDSortedElemSet& nodes );
363 // creates nodes and returns number of nodes added in \a newNodes
364 int MakeNodes( SMESHDS_Mesh* mesh,
365 const SMDS_MeshNode* srcNode,
366 std::list<const SMDS_MeshNode*> & newNodes,
367 const bool makeMediumNodes)
369 return (this->*myMakeNodesFun)( mesh, srcNode, newNodes, makeMediumNodes );
373 gp_Dir myDir; // direction of extrusion
374 Handle(TColStd_HSequenceOfReal) mySteps; // magnitudes for each step
375 std::vector<double> myScales;// scale factors
376 std::vector<double> myAngles;// angles
377 gp_XYZ myBaseP; // scaling/rotation center
378 SMESH_SequenceOfNode myNodes; // nodes for using in sewing
379 int myFlags; // see ExtrusionFlags
380 double myTolerance; // tolerance for sewing nodes
381 const TIDSortedElemSet* myElemsToUse; // elements to use for extrusion by normal
382 std::vector< PathPoint > myPathPoints; // points along a path
383 int (ExtrusParam::* myMakeNodesFun)(SMESHDS_Mesh*, // function of extrusion method
384 const SMDS_MeshNode*,
385 std::list<const SMDS_MeshNode*> &,
387 int makeNodesByDir( SMESHDS_Mesh* mesh,
388 const SMDS_MeshNode* srcNode,
389 std::list<const SMDS_MeshNode*> & newNodes,
390 const bool makeMediumNodes);
391 int makeNodesByDirAndSew( SMESHDS_Mesh* mesh,
392 const SMDS_MeshNode* srcNode,
393 std::list<const SMDS_MeshNode*> & newNodes,
394 const bool makeMediumNodes);
395 int makeNodesByNormal2D( SMESHDS_Mesh* mesh,
396 const SMDS_MeshNode* srcNode,
397 std::list<const SMDS_MeshNode*> & newNodes,
398 const bool makeMediumNodes);
399 int makeNodesByNormal1D( SMESHDS_Mesh* mesh,
400 const SMDS_MeshNode* srcNode,
401 std::list<const SMDS_MeshNode*> & newNodes,
402 const bool makeMediumNodes);
403 int makeNodesAlongTrack( SMESHDS_Mesh* mesh,
404 const SMDS_MeshNode* srcNode,
405 std::list<const SMDS_MeshNode*> & newNodes,
406 const bool makeMediumNodes);
408 void beginStepIter( bool withMediumNodes );
411 std::vector< double > myCurSteps;
412 bool myWithMediumNodes;
417 * Generate new elements by extrusion of theElements
418 * It is a method used in .idl file. All functionality
419 * is implemented in the next method (see below) which
420 * is used in the current method.
421 * @param theElems - list of elements for extrusion
422 * @param newElemsMap returns history of extrusion
423 * @param theFlags set flags for performing extrusion (see description
424 * of enum ExtrusionFlags for additional information)
425 * @param theTolerance - uses for comparing locations of nodes if flag
426 * EXTRUSION_FLAG_SEW is set
428 PGroupIDs ExtrusionSweep (TIDSortedElemSet theElems[2],
429 const gp_Vec& theStep,
430 const int theNbSteps,
431 TTElemOfElemListMap& newElemsMap,
433 const double theTolerance = 1.e-6);
436 * Generate new elements by extrusion of theElements
437 * @param theElems - list of elements for extrusion
438 * @param newElemsMap returns history of extrusion
439 * @param theFlags set flags for performing extrusion (see description
440 * of enum ExtrusionFlags for additional information)
441 * @param theTolerance - uses for comparing locations of nodes if flag
442 * EXTRUSION_FLAG_SEW is set
443 * @param theParams - special structure for manage of extrusion
445 PGroupIDs ExtrusionSweep (TIDSortedElemSet theElems[2],
446 ExtrusParam& theParams,
447 TTElemOfElemListMap& newElemsMap);
450 // Generate new elements by extrusion of theElements
451 // by theStep by theNbSteps
453 enum Extrusion_Error {
458 EXTR_BAD_STARTING_NODE,
459 EXTR_BAD_ANGLES_NUMBER,
460 EXTR_CANT_GET_TANGENT
463 Extrusion_Error ExtrusionAlongTrack (TIDSortedElemSet theElements[2],
464 SMESH_Mesh* theTrackMesh,
465 SMDS_ElemIteratorPtr theTrackIterator,
466 const SMDS_MeshNode* theNodeStart,
467 std::list<double>& theAngles,
468 const bool theAngleVariation,
469 std::list<double>& theScales,
470 const bool theScaleVariation,
471 const gp_Pnt* theRefPoint,
472 const bool theMakeGroups);
473 // Generate new elements by extrusion of theElements along path given by theTrackIterator,
474 // theHasAngles are the rotation angles, base point can be given by theRefPoint
476 PGroupIDs Transform (TIDSortedElemSet & theElements,
477 const gp_Trsf& theTrsf,
479 const bool theMakeGroups,
480 SMESH_Mesh* theTargetMesh=0);
481 // Move or copy theElements applying theTrsf to their nodes
483 PGroupIDs Offset( TIDSortedElemSet & theElements,
484 const double theValue,
485 SMESH_Mesh* theTgtMesh,
486 const bool theMakeGroups,
487 const bool theCopyElements,
488 const bool theFixSelfIntersection);
489 // Make an offset mesh from a source 2D mesh
491 typedef std::list< std::list< const SMDS_MeshNode* > > TListOfListOfNodes;
493 void FindCoincidentNodes (TIDSortedNodeSet & theNodes,
494 const double theTolerance,
495 TListOfListOfNodes & theGroupsOfNodes,
496 bool theSeparateCornersAndMedium);
497 // Return list of group of nodes close to each other within theTolerance.
498 // Search among theNodes or in the whole mesh if theNodes is empty.
500 void MergeNodes (TListOfListOfNodes & theNodeGroups,
501 const bool theAvoidMakingHoles = false);
502 // In each group, the cdr of nodes are substituted by the first one
505 typedef std::list< std::list< smIdType > > TListOfListOfElementsID;
507 void FindEqualElements(TIDSortedElemSet & theElements,
508 TListOfListOfElementsID & theGroupsOfElementsID);
509 // Return list of group of elements build on the same nodes.
510 // Search among theElements or in the whole mesh if theElements is empty.
512 void MergeElements(TListOfListOfElementsID & theGroupsOfElementsID);
513 // In each group remove all but first of elements.
515 void MergeEqualElements();
516 // Remove all but one of elements built on the same nodes.
517 // Return nb of successfully merged groups.
519 int SimplifyFace (const std::vector<const SMDS_MeshNode *>& faceNodes,
520 std::vector<const SMDS_MeshNode *>& poly_nodes,
521 std::vector<int>& quantities) const;
522 // Split face, defined by <faceNodes>, into several faces by repeating nodes.
523 // Is used by MergeNodes()
525 static bool CheckFreeBorderNodes(const SMDS_MeshNode* theNode1,
526 const SMDS_MeshNode* theNode2,
527 const SMDS_MeshNode* theNode3 = 0);
528 // Return true if the three nodes are on a free border
530 static bool FindFreeBorder (const SMDS_MeshNode* theFirstNode,
531 const SMDS_MeshNode* theSecondNode,
532 const SMDS_MeshNode* theLastNode,
533 std::list< const SMDS_MeshNode* > & theNodes,
534 std::list< const SMDS_MeshElement* >& theFaces);
535 // Return nodes and faces of a free border if found
539 // for SewFreeBorder()
540 SEW_BORDER1_NOT_FOUND,
541 SEW_BORDER2_NOT_FOUND,
542 SEW_BOTH_BORDERS_NOT_FOUND,
544 SEW_VOLUMES_TO_SPLIT,
545 // for SewSideElements()
546 SEW_DIFF_NB_OF_ELEMENTS,
547 SEW_TOPO_DIFF_SETS_OF_ELEMENTS,
554 Sew_Error SewFreeBorder (const SMDS_MeshNode* theBorderFirstNode,
555 const SMDS_MeshNode* theBorderSecondNode,
556 const SMDS_MeshNode* theBorderLastNode,
557 const SMDS_MeshNode* theSide2FirstNode,
558 const SMDS_MeshNode* theSide2SecondNode,
559 const SMDS_MeshNode* theSide2ThirdNode = 0,
560 const bool theSide2IsFreeBorder = true,
561 const bool toCreatePolygons = false,
562 const bool toCreatePolyedrs = false);
563 // Sew the free border to the side2 by replacing nodes in
564 // elements on the free border with nodes of the elements
565 // of the side 2. If nb of links in the free border and
566 // between theSide2FirstNode and theSide2LastNode are different,
567 // additional nodes are inserted on a link provided that no
568 // volume elements share the split link.
569 // The side 2 is a free border if theSide2IsFreeBorder == true.
570 // Sewing is performed between the given first, second and last
571 // nodes on the sides.
572 // theBorderFirstNode is merged with theSide2FirstNode.
573 // if (!theSide2IsFreeBorder) then theSide2SecondNode gives
574 // the last node on the side 2, which will be merged with
575 // theBorderLastNode.
576 // if (theSide2IsFreeBorder) then theSide2SecondNode will
577 // be merged with theBorderSecondNode.
578 // if (theSide2IsFreeBorder && theSide2ThirdNode == 0) then
579 // the 2 free borders are sewn link by link and no additional
580 // nodes are inserted.
581 // Return false, if sewing failed.
583 Sew_Error SewSideElements (TIDSortedElemSet& theSide1,
584 TIDSortedElemSet& theSide2,
585 const SMDS_MeshNode* theFirstNode1ToMerge,
586 const SMDS_MeshNode* theFirstNode2ToMerge,
587 const SMDS_MeshNode* theSecondNode1ToMerge,
588 const SMDS_MeshNode* theSecondNode2ToMerge);
589 // Sew two sides of a mesh. Nodes belonging to theSide1 are
590 // merged with nodes of elements of theSide2.
591 // Number of elements in theSide1 and in theSide2 must be
592 // equal and they should have similar node connectivity.
593 // The nodes to merge should belong to side s borders and
594 // the first node should be linked to the second.
596 void InsertNodesIntoLink(const SMDS_MeshElement* theFace,
597 const SMDS_MeshNode* theBetweenNode1,
598 const SMDS_MeshNode* theBetweenNode2,
599 std::list<const SMDS_MeshNode*>& theNodesToInsert,
600 const bool toCreatePoly = false);
601 // insert theNodesToInsert into theFace between theBetweenNode1 and theBetweenNode2.
602 // If toCreatePoly is true, replace theFace by polygon, else split theFace.
604 void UpdateVolumes (const SMDS_MeshNode* theBetweenNode1,
605 const SMDS_MeshNode* theBetweenNode2,
606 std::list<const SMDS_MeshNode*>& theNodesToInsert);
607 // insert theNodesToInsert into all volumes, containing link
608 // theBetweenNode1 - theBetweenNode2, between theBetweenNode1 and theBetweenNode2.
610 void ConvertToQuadratic(const bool theForce3d, const bool theToBiQuad);
611 void ConvertToQuadratic(const bool theForce3d,
612 TIDSortedElemSet& theElements, const bool theToBiQuad);
613 // Converts all mesh to quadratic or bi-quadratic one, deletes old elements,
614 // replacing them with quadratic or bi-quadratic ones with the same id.
615 // If theForce3d = 1; this results in the medium node lying at the
616 // middle of the line segments connecting start and end node of a mesh element.
617 // If theForce3d = 0; this results in the medium node lying at the
618 // geometrical edge from which the mesh element is built.
620 bool ConvertFromQuadratic();
621 void ConvertFromQuadratic(TIDSortedElemSet& theElements);
622 // Converts all mesh from quadratic to ordinary ones, deletes old quadratic elements, replacing
623 // them with ordinary mesh elements with the same id.
624 // Returns true in case of success, false otherwise.
626 static void AddToSameGroups (const SMDS_MeshElement* elemToAdd,
627 const SMDS_MeshElement* elemInGroups,
628 SMESHDS_Mesh * aMesh);
629 // Add elemToAdd to the all groups the elemInGroups belongs to
631 static void RemoveElemFromGroups (const SMDS_MeshElement* element,
632 SMESHDS_Mesh * aMesh);
633 // remove element from the all groups
635 static void ReplaceElemInGroups (const SMDS_MeshElement* elemToRm,
636 const SMDS_MeshElement* elemToAdd,
637 SMESHDS_Mesh * aMesh);
638 // replace elemToRm by elemToAdd in the all groups
640 static void ReplaceElemInGroups (const SMDS_MeshElement* elemToRm,
641 const std::vector<const SMDS_MeshElement*>& elemToAdd,
642 SMESHDS_Mesh * aMesh);
643 // replace elemToRm by elemToAdd in the all groups
646 * \brief Return nodes linked to the given one in elements of the type
648 static void GetLinkedNodes( const SMDS_MeshNode* node,
649 TIDSortedElemSet & linkedNodes,
650 SMDSAbs_ElementType type = SMDSAbs_All );
653 * \brief Find corresponding nodes in two sets of faces
654 * \param theSide1 - first face set
655 * \param theSide2 - second first face
656 * \param theFirstNode1 - a boundary node of set 1
657 * \param theFirstNode2 - a node of set 2 corresponding to theFirstNode1
658 * \param theSecondNode1 - a boundary node of set 1 linked with theFirstNode1
659 * \param theSecondNode2 - a node of set 2 corresponding to theSecondNode1
660 * \param nReplaceMap - output map of corresponding nodes
661 * \return Sew_Error - is a success or not
663 static Sew_Error FindMatchingNodes(std::set<const SMDS_MeshElement*>& theSide1,
664 std::set<const SMDS_MeshElement*>& theSide2,
665 const SMDS_MeshNode* theFirstNode1,
666 const SMDS_MeshNode* theFirstNode2,
667 const SMDS_MeshNode* theSecondNode1,
668 const SMDS_MeshNode* theSecondNode2,
669 TNodeNodeMap & theNodeReplaceMap);
672 * \brief Returns true if given node is medium
673 * \param n - node to check
674 * \param typeToCheck - type of elements containing the node to ask about node status
675 * \return bool - check result
677 static bool IsMedium(const SMDS_MeshNode* node,
678 const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
680 int FindShape (const SMDS_MeshElement * theElem);
681 // Return an index of the shape theElem is on
682 // or zero if a shape not found
684 void DoubleElements( const TIDSortedElemSet& theElements );
686 bool DoubleNodes( const std::list< int >& theListOfNodes,
687 const std::list< int >& theListOfModifiedElems );
689 bool DoubleNodes( const TIDSortedElemSet& theElems,
690 const TIDSortedElemSet& theNodesNot,
691 const TIDSortedElemSet& theAffectedElems );
693 bool AffectedElemGroupsInRegion( const TIDSortedElemSet& theElems,
694 const TIDSortedElemSet& theNodesNot,
695 const TopoDS_Shape& theShape,
696 TIDSortedElemSet& theAffectedElems);
698 bool DoubleNodesInRegion( const TIDSortedElemSet& theElems,
699 const TIDSortedElemSet& theNodesNot,
700 const TopoDS_Shape& theShape );
702 double OrientedAngle(const gp_Pnt& p0, const gp_Pnt& p1, const gp_Pnt& g1, const gp_Pnt& g2);
704 bool DoubleNodesOnGroupBoundaries( const std::vector<TIDSortedElemSet>& theElems,
705 bool createJointElems,
706 bool onAllBoundaries);
708 bool CreateFlatElementsOnFacesGroups( const std::vector<TIDSortedElemSet>& theElems );
710 void CreateHoleSkin(double radius,
711 const TopoDS_Shape& theShape,
712 SMESH_NodeSearcher* theNodeSearcher,
713 const char* groupName,
714 std::vector<double>& nodesCoords,
715 std::vector<std::vector<int> >& listOfListOfNodes);
718 * \brief Generated skin mesh (containing 2D cells) from 3D mesh
719 * The created 2D mesh elements based on nodes of free faces of boundary volumes
720 * \return TRUE if operation has been completed successfully, FALSE otherwise
722 bool Make2DMeshFrom3D();
724 enum Bnd_Dimension { BND_2DFROM3D, BND_1DFROM3D, BND_1DFROM2D };
726 int MakeBoundaryMesh(const TIDSortedElemSet& elements,
727 Bnd_Dimension dimension,
728 SMESH_Group* group = 0,
729 SMESH_Mesh* targetMesh = 0,
730 bool toCopyElements = false,
731 bool toCopyExistingBondary = false,
732 bool toAddExistingBondary = false,
733 bool aroundElements = false);
738 * \brief Convert elements contained in a submesh to quadratic
739 * \return smIdType - nb of checked elements
741 smIdType convertElemToQuadratic(SMESHDS_SubMesh * theSm,
742 SMESH_MesherHelper& theHelper,
743 const bool theForce3d);
746 * \brief Convert quadratic elements to linear ones and remove quadratic nodes
747 * \return nb of checked elements
749 smIdType removeQuadElem( SMESHDS_SubMesh * theSm,
750 SMDS_ElemIteratorPtr theItr,
751 const int theShapeID);
753 * \brief Create groups of elements made during transformation
754 * \param nodeGens - nodes making corresponding myLastCreatedNodes
755 * \param elemGens - elements making corresponding myLastCreatedElems
756 * \param postfix - to append to names of new groups
757 * \param targetMesh - mesh to create groups in
758 * \param topPresent - is there "top" elements that are created by sweeping
760 PGroupIDs generateGroups(const SMESH_SequenceOfElemPtr& nodeGens,
761 const SMESH_SequenceOfElemPtr& elemGens,
762 const std::string& postfix,
763 SMESH_Mesh* targetMesh=0,
764 const bool topPresent=true);
766 * \brief Create elements by sweeping an element
767 * \param elem - element to sweep
768 * \param newNodesItVec - nodes generated from each node of the element
769 * \param newElems - generated elements
770 * \param nbSteps - number of sweeping steps
771 * \param srcElements - to append elem for each generated element
773 void sweepElement(const SMDS_MeshElement* elem,
774 const std::vector<TNodeOfNodeListMapItr> & newNodesItVec,
775 std::list<const SMDS_MeshElement*>& newElems,
776 const size_t nbSteps,
777 SMESH_SequenceOfElemPtr& srcElements);
780 * \brief Computes new connectivity of an element after merging nodes
781 * \param [in] elems - the element
782 * \param [out] newElemDefs - definition(s) of result element(s)
783 * \param [inout] nodeNodeMap - nodes to merge
784 * \param [in] avoidMakingHoles - if true and and the element becomes invalid
785 * after merging (but not degenerated), removes nodes causing
786 * the invalidity from \a nodeNodeMap.
787 * \return bool - true if the element should be removed
789 bool applyMerge( const SMDS_MeshElement* elems,
790 std::vector< ElemFeatures >& newElemDefs,
791 TNodeNodeMap& nodeNodeMap,
792 const bool avoidMakingHoles );
794 * \brief Create 1D and 2D elements around swept elements
795 * \param mapNewNodes - source nodes and ones generated from them
796 * \param newElemsMap - source elements and ones generated from them
797 * \param elemNewNodesMap - nodes generated from each node of each element
798 * \param elemSet - all swept elements
799 * \param nbSteps - number of sweeping steps
800 * \param srcElements - to append elem for each generated element
802 void makeWalls (TNodeOfNodeListMap & mapNewNodes,
803 TTElemOfElemListMap & newElemsMap,
804 TElemOfVecOfNnlmiMap & elemNewNodesMap,
805 TIDSortedElemSet& elemSet,
807 SMESH_SequenceOfElemPtr& srcElements);
809 static void linearAngleVariation(const int NbSteps,
810 std::list<double>& theAngles);
811 static void linearScaleVariation(const int NbSteps,
812 std::list<double>& theScales);
814 bool doubleNodes( SMESHDS_Mesh* theMeshDS,
815 const TIDSortedElemSet& theElems,
816 const TIDSortedElemSet& theNodesNot,
817 TNodeNodeMap& theNodeNodeMap,
818 const bool theIsDoubleElem );
820 void copyPosition( const SMDS_MeshNode* from,
821 const SMDS_MeshNode* to );
827 // Nodes and elements created during last operation
828 SMESH_SequenceOfElemPtr myLastCreatedNodes, myLastCreatedElems;
830 // Description of error/warning occurred during last operation
831 SMESH_ComputeErrorPtr myError;