1 // Copyright (C) 2007-2015 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 "SMDS_MeshElement.hxx"
34 #include "SMESH_Controls.hxx"
35 #include "SMESH_Mesh.hxx"
36 #include "SMESH_TypeDefs.hxx"
37 #include "SMESH_ComputeError.hxx"
39 #include <utilities.h>
41 #include <TColStd_HSequenceOfReal.hxx>
53 class SMESH_MesherHelper;
54 class SMESH_NodeSearcher;
56 // ============================================================
58 * \brief Editor of a mesh
60 // ============================================================
62 class SMESH_EXPORT SMESH_MeshEditor
66 SMESH_MeshEditor( SMESH_Mesh* theMesh );
68 SMESH_Mesh * GetMesh() { return myMesh; }
69 SMESHDS_Mesh * GetMeshDS() { return myMesh->GetMeshDS(); }
71 const SMESH_SequenceOfElemPtr& GetLastCreatedNodes() const { return myLastCreatedNodes; }
72 const SMESH_SequenceOfElemPtr& GetLastCreatedElems() const { return myLastCreatedElems; }
73 void ClearLastCreated();
74 SMESH_ComputeErrorPtr & GetError() { return myError; }
76 // --------------------------------------------------------------------------------
77 struct ElemFeatures //!< Features of element to create
79 SMDSAbs_ElementType myType;
80 bool myIsPoly, myIsQuad;
82 double myBallDiameter;
83 std::vector<int> myPolyhedQuantities;
85 ElemFeatures( SMDSAbs_ElementType type=SMDSAbs_All, bool isPoly=false, bool isQuad=false )
86 :myType( type ), myIsPoly(isPoly), myIsQuad(isQuad), myID(-1), myBallDiameter(0) {}
88 ElemFeatures& Init( SMDSAbs_ElementType type, bool isPoly=false, bool isQuad=false )
89 { myType = type; myIsPoly = isPoly; myIsQuad = isQuad; return *this; }
91 ElemFeatures& Init( const SMDS_MeshElement* elem, bool basicOnly=true );
93 ElemFeatures& Init( double diameter )
94 { myType = SMDSAbs_Ball; myBallDiameter = diameter; return *this; }
96 ElemFeatures& Init( vector<int>& quanities, bool isQuad=false )
97 { myType = SMDSAbs_Volume; myIsPoly = 1; myIsQuad = isQuad;
98 myPolyhedQuantities.swap( quanities ); return *this; }
100 ElemFeatures& Init( const vector<int>& quanities, bool isQuad=false )
101 { myType = SMDSAbs_Volume; myIsPoly = 1; myIsQuad = isQuad;
102 myPolyhedQuantities = quanities; return *this; }
104 ElemFeatures& SetPoly(bool isPoly) { myIsPoly = isPoly; return *this; }
105 ElemFeatures& SetQuad(bool isQuad) { myIsQuad = isQuad; return *this; }
106 ElemFeatures& SetID (int ID) { myID = ID; return *this; }
112 SMDS_MeshElement* AddElement(const std::vector<const SMDS_MeshNode*> & nodes,
113 const ElemFeatures& features);
117 SMDS_MeshElement* AddElement(const std::vector<int> & nodeIDs,
118 const ElemFeatures& features);
120 int Remove (const std::list< int >& theElemIDs, const bool isNodes);
121 // Remove a node or an element.
122 // Modify a compute state of sub-meshes which become empty
124 void Create0DElementsOnAllNodes( const TIDSortedElemSet& elements,
125 TIDSortedElemSet& all0DElems);
126 // Create 0D elements on all nodes of the given object except those
127 // nodes on which a 0D element already exists. \a all0DElems returns
128 // all 0D elements found or created on nodes of \a elements
130 bool InverseDiag (const SMDS_MeshElement * theTria1,
131 const SMDS_MeshElement * theTria2 );
132 // Replace two neighbour triangles with ones built on the same 4 nodes
133 // but having other common link.
134 // Return False if args are improper
136 bool InverseDiag (const SMDS_MeshNode * theNode1,
137 const SMDS_MeshNode * theNode2 );
138 // Replace two neighbour triangles sharing theNode1-theNode2 link
139 // with ones built on the same 4 nodes but having other common link.
140 // Return false if proper faces not found
142 bool DeleteDiag (const SMDS_MeshNode * theNode1,
143 const SMDS_MeshNode * theNode2 );
144 // Replace two neighbour triangles sharing theNode1-theNode2 link
145 // with a quadrangle built on the same 4 nodes.
146 // Return false if proper faces not found
148 bool Reorient (const SMDS_MeshElement * theElement);
149 // Reverse theElement orientation
151 int Reorient2D (TIDSortedElemSet & theFaces,
152 const gp_Dir& theDirection,
153 const SMDS_MeshElement * theFace);
154 // Reverse theFaces whose orientation to be same as that of theFace
155 // oriented according to theDirection. Return nb of reoriented faces
157 int Reorient2DBy3D (TIDSortedElemSet & theFaces,
158 TIDSortedElemSet & theVolumes,
159 const bool theOutsideNormal);
160 // Reorient faces basing on orientation of adjacent volumes.
161 // Return nb of reoriented faces
164 * \brief Fuse neighbour triangles into quadrangles.
165 * \param theElems - The triangles to be fused.
166 * \param theCriterion - Is used to choose a neighbour to fuse with.
167 * \param theMaxAngle - Is a max angle between element normals at which fusion
168 * is still performed; theMaxAngle is mesured in radians.
169 * \return bool - Success or not.
171 bool TriToQuad (TIDSortedElemSet & theElems,
172 SMESH::Controls::NumericalFunctorPtr theCriterion,
173 const double theMaxAngle);
175 * \brief Split quadrangles into triangles.
176 * \param theElems - The faces to be splitted.
177 * \param theCriterion - Is used to choose a diagonal for splitting.
178 * \return bool - Success or not.
180 bool QuadToTri (TIDSortedElemSet & theElems,
181 SMESH::Controls::NumericalFunctorPtr theCriterion);
183 * \brief Split quadrangles into triangles.
184 * \param theElems - The faces to be splitted.
185 * \param the13Diag - Is used to choose a diagonal for splitting.
186 * \return bool - Success or not.
188 bool QuadToTri (TIDSortedElemSet & theElems,
189 const bool the13Diag);
191 * \brief Split each of given quadrangles into 4 triangles.
192 * \param theElems - The faces to be splitted. If empty all faces are split.
194 void QuadTo4Tri (TIDSortedElemSet & theElems);
197 * \brief Find better diagonal for splitting.
198 * \param theQuad - The face to find better splitting of.
199 * \param theCriterion - Is used to choose a diagonal for splitting.
200 * \return int - 1 for 1-3 diagonal, 2 for 2-4, -1 - for errors.
202 int BestSplit (const SMDS_MeshElement* theQuad,
203 SMESH::Controls::NumericalFunctorPtr theCriterion);
206 typedef std::map < const SMDS_MeshElement*, int, TIDCompare > TFacetOfElem;
208 //!<2nd arg of SplitVolumes()
209 enum SplitVolumToTetraFlags { HEXA_TO_5 = 1, // split into tetrahedra
212 HEXA_TO_2_PRISMS, // split into prisms
215 * \brief Split volumic elements into tetrahedra or prisms.
216 * If facet ID < 0, element is split into tetrahedra,
217 * else a hexahedron is split into prisms so that the given facet is
218 * split into triangles
220 void SplitVolumes (const TFacetOfElem & theElems, const int theMethodFlags);
223 * \brief For hexahedra that will be split into prisms, finds facets to
224 * split into triangles
225 * \param [in,out] theHexas - the hexahedra
226 * \param [in] theFacetNormal - facet normal
227 * \param [out] theFacets - the hexahedra and found facet IDs
229 void GetHexaFacetsToSplit( TIDSortedElemSet& theHexas,
230 const gp_Ax1& theFacetNormal,
231 TFacetOfElem & theFacets);
234 enum SmoothMethod { LAPLACIAN = 0, CENTROIDAL };
236 void Smooth (TIDSortedElemSet & theElements,
237 std::set<const SMDS_MeshNode*> & theFixedNodes,
238 const SmoothMethod theSmoothMethod,
239 const int theNbIterations,
240 double theTgtAspectRatio = 1.0,
241 const bool the2D = true);
242 // Smooth theElements using theSmoothMethod during theNbIterations
243 // or until a worst element has aspect ratio <= theTgtAspectRatio.
244 // Aspect Ratio varies in range [1.0, inf].
245 // If theElements is empty, the whole mesh is smoothed.
246 // theFixedNodes contains additionally fixed nodes. Nodes built
247 // on edges and boundary nodes are always fixed.
248 // If the2D, smoothing is performed using UV parameters of nodes
249 // on geometrical faces
251 typedef TIDTypeCompare TElemSort;
252 typedef std::map < const SMDS_MeshElement*,
253 std::list<const SMDS_MeshElement*>, TElemSort > TTElemOfElemListMap;
254 typedef std::map<const SMDS_MeshNode*, std::list<const SMDS_MeshNode*> > TNodeOfNodeListMap;
255 typedef TNodeOfNodeListMap::iterator TNodeOfNodeListMapItr;
256 typedef std::vector<TNodeOfNodeListMapItr> TVecOfNnlmiMap;
257 typedef std::map<const SMDS_MeshElement*, TVecOfNnlmiMap, TElemSort > TElemOfVecOfNnlmiMap;
258 typedef std::auto_ptr< std::list<int> > PGroupIDs;
260 PGroupIDs RotationSweep (TIDSortedElemSet theElements[2],
261 const gp_Ax1& theAxis,
262 const double theAngle,
263 const int theNbSteps,
264 const double theToler,
265 const bool theMakeGroups,
266 const bool theMakeWalls=true);
267 // Generate new elements by rotation of theElements around theAxis
268 // by theAngle by theNbSteps
271 * Flags of extrusion.
272 * BOUNDARY: create or not boundary for result of extrusion
273 * SEW: try to use existing nodes or create new nodes in any case
274 * GROUPS: to create groups
275 * BY_AVG_NORMAL: step size is measured along average normal to elements,
276 * else step size is measured along average normal of any element
277 * USE_INPUT_ELEMS_ONLY: to use only input elements to compute extrusion direction
278 * for ExtrusionByNormal()
280 enum ExtrusionFlags {
281 EXTRUSION_FLAG_BOUNDARY = 0x01,
282 EXTRUSION_FLAG_SEW = 0x02,
283 EXTRUSION_FLAG_GROUPS = 0x04,
284 EXTRUSION_FLAG_BY_AVG_NORMAL = 0x08,
285 EXTRUSION_FLAG_USE_INPUT_ELEMS_ONLY = 0x10
289 * Generator of nodes for extrusion functionality
291 class SMESH_EXPORT ExtrusParam {
292 gp_Dir myDir; // direction of extrusion
293 Handle(TColStd_HSequenceOfReal) mySteps; // magnitudes for each step
294 SMESH_SequenceOfNode myNodes; // nodes for using in sewing
295 int myFlags; // see ExtrusionFlags
296 double myTolerance; // tolerance for sewing nodes
297 const TIDSortedElemSet* myElemsToUse; // elements to use for extrusion by normal
299 int (ExtrusParam::*myMakeNodesFun)(SMESHDS_Mesh* mesh,
300 const SMDS_MeshNode* srcNode,
301 std::list<const SMDS_MeshNode*> & newNodes,
302 const bool makeMediumNodes);
305 ExtrusParam( const gp_Vec& theStep,
306 const int theNbSteps,
307 const int theFlags = 0,
308 const double theTolerance = 1e-6);
309 ExtrusParam( const gp_Dir& theDir,
310 Handle(TColStd_HSequenceOfReal) theSteps,
311 const int theFlags = 0,
312 const double theTolerance = 1e-6);
313 ExtrusParam( const double theStep,
314 const int theNbSteps,
316 const int theDim); // for extrusion by normal
318 SMESH_SequenceOfNode& ChangeNodes() { return myNodes; }
319 int& Flags() { return myFlags; }
320 bool ToMakeBoundary() const { return myFlags & EXTRUSION_FLAG_BOUNDARY; }
321 bool ToMakeGroups() const { return myFlags & EXTRUSION_FLAG_GROUPS; }
322 bool ToUseInpElemsOnly() const { return myFlags & EXTRUSION_FLAG_USE_INPUT_ELEMS_ONLY; }
323 int NbSteps() const { return mySteps->Length(); }
325 // stores elements to use for extrusion by normal, depending on
326 // state of EXTRUSION_FLAG_USE_INPUT_ELEMS_ONLY flag
327 void SetElementsToUse( const TIDSortedElemSet& elems );
329 // creates nodes and returns number of nodes added in \a newNodes
330 int MakeNodes( SMESHDS_Mesh* mesh,
331 const SMDS_MeshNode* srcNode,
332 std::list<const SMDS_MeshNode*> & newNodes,
333 const bool makeMediumNodes)
335 return (this->*myMakeNodesFun)( mesh, srcNode, newNodes, makeMediumNodes );
339 int makeNodesByDir( SMESHDS_Mesh* mesh,
340 const SMDS_MeshNode* srcNode,
341 std::list<const SMDS_MeshNode*> & newNodes,
342 const bool makeMediumNodes);
343 int makeNodesByDirAndSew( SMESHDS_Mesh* mesh,
344 const SMDS_MeshNode* srcNode,
345 std::list<const SMDS_MeshNode*> & newNodes,
346 const bool makeMediumNodes);
347 int makeNodesByNormal2D( SMESHDS_Mesh* mesh,
348 const SMDS_MeshNode* srcNode,
349 std::list<const SMDS_MeshNode*> & newNodes,
350 const bool makeMediumNodes);
351 int makeNodesByNormal1D( SMESHDS_Mesh* mesh,
352 const SMDS_MeshNode* srcNode,
353 std::list<const SMDS_MeshNode*> & newNodes,
354 const bool makeMediumNodes);
356 void beginStepIter( bool withMediumNodes );
359 std::vector< double > myCurSteps;
360 bool myWithMediumNodes;
365 * Generate new elements by extrusion of theElements
366 * It is a method used in .idl file. All functionality
367 * is implemented in the next method (see below) which
368 * is used in the current method.
369 * @param theElems - list of elements for extrusion
370 * @param newElemsMap returns history of extrusion
371 * @param theFlags set flags for performing extrusion (see description
372 * of enum ExtrusionFlags for additional information)
373 * @param theTolerance - uses for comparing locations of nodes if flag
374 * EXTRUSION_FLAG_SEW is set
376 PGroupIDs ExtrusionSweep (TIDSortedElemSet theElems[2],
377 const gp_Vec& theStep,
378 const int theNbSteps,
379 TTElemOfElemListMap& newElemsMap,
381 const double theTolerance = 1.e-6);
384 * Generate new elements by extrusion of theElements
385 * @param theElems - list of elements for extrusion
386 * @param newElemsMap returns history of extrusion
387 * @param theFlags set flags for performing extrusion (see description
388 * of enum ExtrusionFlags for additional information)
389 * @param theTolerance - uses for comparing locations of nodes if flag
390 * EXTRUSION_FLAG_SEW is set
391 * @param theParams - special structure for manage of extrusion
393 PGroupIDs ExtrusionSweep (TIDSortedElemSet theElems[2],
394 ExtrusParam& theParams,
395 TTElemOfElemListMap& newElemsMap);
398 // Generate new elements by extrusion of theElements
399 // by theStep by theNbSteps
401 enum Extrusion_Error {
406 EXTR_BAD_STARTING_NODE,
407 EXTR_BAD_ANGLES_NUMBER,
408 EXTR_CANT_GET_TANGENT
411 Extrusion_Error ExtrusionAlongTrack (TIDSortedElemSet theElements[2],
412 SMESH_subMesh* theTrackPattern,
413 const SMDS_MeshNode* theNodeStart,
414 const bool theHasAngles,
415 std::list<double>& theAngles,
416 const bool theLinearVariation,
417 const bool theHasRefPoint,
418 const gp_Pnt& theRefPoint,
419 const bool theMakeGroups);
420 Extrusion_Error ExtrusionAlongTrack (TIDSortedElemSet theElements[2],
421 SMESH_Mesh* theTrackPattern,
422 const SMDS_MeshNode* theNodeStart,
423 const bool theHasAngles,
424 std::list<double>& theAngles,
425 const bool theLinearVariation,
426 const bool theHasRefPoint,
427 const gp_Pnt& theRefPoint,
428 const bool theMakeGroups);
429 // Generate new elements by extrusion of theElements along path given by theTrackPattern,
430 // theHasAngles are the rotation angles, base point can be given by theRefPoint
432 PGroupIDs Transform (TIDSortedElemSet & theElements,
433 const gp_Trsf& theTrsf,
435 const bool theMakeGroups,
436 SMESH_Mesh* theTargetMesh=0);
437 // Move or copy theElements applying theTrsf to their nodes
439 typedef std::list< std::list< const SMDS_MeshNode* > > TListOfListOfNodes;
441 void FindCoincidentNodes (TIDSortedNodeSet & theNodes,
442 const double theTolerance,
443 TListOfListOfNodes & theGroupsOfNodes,
444 bool theSeparateCornersAndMedium);
445 // Return list of group of nodes close to each other within theTolerance.
446 // Search among theNodes or in the whole mesh if theNodes is empty.
448 void MergeNodes (TListOfListOfNodes & theNodeGroups);
449 // In each group, the cdr of nodes are substituted by the first one
452 typedef std::list< std::list< int > > TListOfListOfElementsID;
454 void FindEqualElements(TIDSortedElemSet & theElements,
455 TListOfListOfElementsID & theGroupsOfElementsID);
456 // Return list of group of elements build on the same nodes.
457 // Search among theElements or in the whole mesh if theElements is empty.
459 void MergeElements(TListOfListOfElementsID & theGroupsOfElementsID);
460 // In each group remove all but first of elements.
462 void MergeEqualElements();
463 // Remove all but one of elements built on the same nodes.
464 // Return nb of successfully merged groups.
466 int SimplifyFace (const std::vector<const SMDS_MeshNode *>& faceNodes,
467 std::vector<const SMDS_MeshNode *>& poly_nodes,
468 std::vector<int>& quantities) const;
469 // Split face, defined by <faceNodes>, into several faces by repeating nodes.
470 // Is used by MergeNodes()
472 static bool CheckFreeBorderNodes(const SMDS_MeshNode* theNode1,
473 const SMDS_MeshNode* theNode2,
474 const SMDS_MeshNode* theNode3 = 0);
475 // Return true if the three nodes are on a free border
477 static bool FindFreeBorder (const SMDS_MeshNode* theFirstNode,
478 const SMDS_MeshNode* theSecondNode,
479 const SMDS_MeshNode* theLastNode,
480 std::list< const SMDS_MeshNode* > & theNodes,
481 std::list< const SMDS_MeshElement* >& theFaces);
482 // Return nodes and faces of a free border if found
486 // for SewFreeBorder()
487 SEW_BORDER1_NOT_FOUND,
488 SEW_BORDER2_NOT_FOUND,
489 SEW_BOTH_BORDERS_NOT_FOUND,
491 SEW_VOLUMES_TO_SPLIT,
492 // for SewSideElements()
493 SEW_DIFF_NB_OF_ELEMENTS,
494 SEW_TOPO_DIFF_SETS_OF_ELEMENTS,
501 Sew_Error SewFreeBorder (const SMDS_MeshNode* theBorderFirstNode,
502 const SMDS_MeshNode* theBorderSecondNode,
503 const SMDS_MeshNode* theBorderLastNode,
504 const SMDS_MeshNode* theSide2FirstNode,
505 const SMDS_MeshNode* theSide2SecondNode,
506 const SMDS_MeshNode* theSide2ThirdNode = 0,
507 const bool theSide2IsFreeBorder = true,
508 const bool toCreatePolygons = false,
509 const bool toCreatePolyedrs = false);
510 // Sew the free border to the side2 by replacing nodes in
511 // elements on the free border with nodes of the elements
512 // of the side 2. If nb of links in the free border and
513 // between theSide2FirstNode and theSide2LastNode are different,
514 // additional nodes are inserted on a link provided that no
515 // volume elements share the splitted link.
516 // The side 2 is a free border if theSide2IsFreeBorder == true.
517 // Sewing is peformed between the given first, second and last
518 // nodes on the sides.
519 // theBorderFirstNode is merged with theSide2FirstNode.
520 // if (!theSide2IsFreeBorder) then theSide2SecondNode gives
521 // the last node on the side 2, which will be merged with
522 // theBorderLastNode.
523 // if (theSide2IsFreeBorder) then theSide2SecondNode will
524 // be merged with theBorderSecondNode.
525 // if (theSide2IsFreeBorder && theSide2ThirdNode == 0) then
526 // the 2 free borders are sewn link by link and no additional
527 // nodes are inserted.
528 // Return false, if sewing failed.
530 Sew_Error SewSideElements (TIDSortedElemSet& theSide1,
531 TIDSortedElemSet& theSide2,
532 const SMDS_MeshNode* theFirstNode1ToMerge,
533 const SMDS_MeshNode* theFirstNode2ToMerge,
534 const SMDS_MeshNode* theSecondNode1ToMerge,
535 const SMDS_MeshNode* theSecondNode2ToMerge);
536 // Sew two sides of a mesh. Nodes belonging to theSide1 are
537 // merged with nodes of elements of theSide2.
538 // Number of elements in theSide1 and in theSide2 must be
539 // equal and they should have similar node connectivity.
540 // The nodes to merge should belong to side s borders and
541 // the first node should be linked to the second.
543 void InsertNodesIntoLink(const SMDS_MeshElement* theFace,
544 const SMDS_MeshNode* theBetweenNode1,
545 const SMDS_MeshNode* theBetweenNode2,
546 std::list<const SMDS_MeshNode*>& theNodesToInsert,
547 const bool toCreatePoly = false);
548 // insert theNodesToInsert into theFace between theBetweenNode1 and theBetweenNode2.
549 // If toCreatePoly is true, replace theFace by polygon, else split theFace.
551 void UpdateVolumes (const SMDS_MeshNode* theBetweenNode1,
552 const SMDS_MeshNode* theBetweenNode2,
553 std::list<const SMDS_MeshNode*>& theNodesToInsert);
554 // insert theNodesToInsert into all volumes, containing link
555 // theBetweenNode1 - theBetweenNode2, between theBetweenNode1 and theBetweenNode2.
557 void ConvertToQuadratic(const bool theForce3d, const bool theToBiQuad);
558 void ConvertToQuadratic(const bool theForce3d,
559 TIDSortedElemSet& theElements, const bool theToBiQuad);
560 // Converts all mesh to quadratic or bi-quadratic one, deletes old elements,
561 // replacing them with quadratic or bi-quadratic ones with the same id.
562 // If theForce3d = 1; this results in the medium node lying at the
563 // middle of the line segments connecting start and end node of a mesh element.
564 // If theForce3d = 0; this results in the medium node lying at the
565 // geometrical edge from which the mesh element is built.
567 bool ConvertFromQuadratic();
568 void ConvertFromQuadratic(TIDSortedElemSet& theElements);
569 // Converts all mesh from quadratic to ordinary ones, deletes old quadratic elements, replacing
570 // them with ordinary mesh elements with the same id.
571 // Returns true in case of success, false otherwise.
573 static void AddToSameGroups (const SMDS_MeshElement* elemToAdd,
574 const SMDS_MeshElement* elemInGroups,
575 SMESHDS_Mesh * aMesh);
576 // Add elemToAdd to the all groups the elemInGroups belongs to
578 static void RemoveElemFromGroups (const SMDS_MeshElement* element,
579 SMESHDS_Mesh * aMesh);
580 // remove element from the all groups
582 static void ReplaceElemInGroups (const SMDS_MeshElement* elemToRm,
583 const SMDS_MeshElement* elemToAdd,
584 SMESHDS_Mesh * aMesh);
585 // replace elemToRm by elemToAdd in the all groups
587 static void ReplaceElemInGroups (const SMDS_MeshElement* elemToRm,
588 const std::vector<const SMDS_MeshElement*>& elemToAdd,
589 SMESHDS_Mesh * aMesh);
590 // replace elemToRm by elemToAdd in the all groups
593 * \brief Return nodes linked to the given one in elements of the type
595 static void GetLinkedNodes( const SMDS_MeshNode* node,
596 TIDSortedElemSet & linkedNodes,
597 SMDSAbs_ElementType type = SMDSAbs_All );
600 * \brief Find corresponding nodes in two sets of faces
601 * \param theSide1 - first face set
602 * \param theSide2 - second first face
603 * \param theFirstNode1 - a boundary node of set 1
604 * \param theFirstNode2 - a node of set 2 corresponding to theFirstNode1
605 * \param theSecondNode1 - a boundary node of set 1 linked with theFirstNode1
606 * \param theSecondNode2 - a node of set 2 corresponding to theSecondNode1
607 * \param nReplaceMap - output map of corresponding nodes
608 * \return Sew_Error - is a success or not
610 static Sew_Error FindMatchingNodes(std::set<const SMDS_MeshElement*>& theSide1,
611 std::set<const SMDS_MeshElement*>& theSide2,
612 const SMDS_MeshNode* theFirstNode1,
613 const SMDS_MeshNode* theFirstNode2,
614 const SMDS_MeshNode* theSecondNode1,
615 const SMDS_MeshNode* theSecondNode2,
616 TNodeNodeMap & theNodeReplaceMap);
619 * \brief Returns true if given node is medium
620 * \param n - node to check
621 * \param typeToCheck - type of elements containing the node to ask about node status
622 * \return bool - check result
624 static bool IsMedium(const SMDS_MeshNode* node,
625 const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
627 int FindShape (const SMDS_MeshElement * theElem);
628 // Return an index of the shape theElem is on
629 // or zero if a shape not found
631 void DoubleElements( const TIDSortedElemSet& theElements );
633 bool DoubleNodes( const std::list< int >& theListOfNodes,
634 const std::list< int >& theListOfModifiedElems );
636 bool DoubleNodes( const TIDSortedElemSet& theElems,
637 const TIDSortedElemSet& theNodesNot,
638 const TIDSortedElemSet& theAffectedElems );
640 bool AffectedElemGroupsInRegion( const TIDSortedElemSet& theElems,
641 const TIDSortedElemSet& theNodesNot,
642 const TopoDS_Shape& theShape,
643 TIDSortedElemSet& theAffectedElems);
645 bool DoubleNodesInRegion( const TIDSortedElemSet& theElems,
646 const TIDSortedElemSet& theNodesNot,
647 const TopoDS_Shape& theShape );
649 double OrientedAngle(const gp_Pnt& p0, const gp_Pnt& p1, const gp_Pnt& g1, const gp_Pnt& g2);
651 bool DoubleNodesOnGroupBoundaries( const std::vector<TIDSortedElemSet>& theElems,
652 bool createJointElems,
653 bool onAllBoundaries);
655 bool CreateFlatElementsOnFacesGroups( const std::vector<TIDSortedElemSet>& theElems );
657 void CreateHoleSkin(double radius,
658 const TopoDS_Shape& theShape,
659 SMESH_NodeSearcher* theNodeSearcher,
660 const char* groupName,
661 std::vector<double>& nodesCoords,
662 std::vector<std::vector<int> >& listOfListOfNodes);
665 * \brief Generated skin mesh (containing 2D cells) from 3D mesh
666 * The created 2D mesh elements based on nodes of free faces of boundary volumes
667 * \return TRUE if operation has been completed successfully, FALSE otherwise
669 bool Make2DMeshFrom3D();
671 enum Bnd_Dimension { BND_2DFROM3D, BND_1DFROM3D, BND_1DFROM2D };
673 int MakeBoundaryMesh(const TIDSortedElemSet& elements,
674 Bnd_Dimension dimension,
675 SMESH_Group* group = 0,
676 SMESH_Mesh* targetMesh = 0,
677 bool toCopyElements = false,
678 bool toCopyExistingBondary = false,
679 bool toAddExistingBondary = false,
680 bool aroundElements = false);
685 * \brief Convert elements contained in a submesh to quadratic
686 * \return int - nb of checked elements
688 int convertElemToQuadratic(SMESHDS_SubMesh * theSm,
689 SMESH_MesherHelper& theHelper,
690 const bool theForce3d);
693 * \brief Convert quadratic elements to linear ones and remove quadratic nodes
694 * \return nb of checked elements
696 int removeQuadElem( SMESHDS_SubMesh * theSm,
697 SMDS_ElemIteratorPtr theItr,
698 const int theShapeID);
700 * \brief Create groups of elements made during transformation
701 * \param nodeGens - nodes making corresponding myLastCreatedNodes
702 * \param elemGens - elements making corresponding myLastCreatedElems
703 * \param postfix - to append to names of new groups
704 * \param targetMesh - mesh to create groups in
705 * \param topPresent - is there "top" elements that are created by sweeping
707 PGroupIDs generateGroups(const SMESH_SequenceOfElemPtr& nodeGens,
708 const SMESH_SequenceOfElemPtr& elemGens,
709 const std::string& postfix,
710 SMESH_Mesh* targetMesh=0,
711 const bool topPresent=true);
713 * \brief Create elements by sweeping an element
714 * \param elem - element to sweep
715 * \param newNodesItVec - nodes generated from each node of the element
716 * \param newElems - generated elements
717 * \param nbSteps - number of sweeping steps
718 * \param srcElements - to append elem for each generated element
720 void sweepElement(const SMDS_MeshElement* elem,
721 const std::vector<TNodeOfNodeListMapItr> & newNodesItVec,
722 std::list<const SMDS_MeshElement*>& newElems,
724 SMESH_SequenceOfElemPtr& srcElements);
727 * \brief Create 1D and 2D elements around swept elements
728 * \param mapNewNodes - source nodes and ones generated from them
729 * \param newElemsMap - source elements and ones generated from them
730 * \param elemNewNodesMap - nodes generated from each node of each element
731 * \param elemSet - all swept elements
732 * \param nbSteps - number of sweeping steps
733 * \param srcElements - to append elem for each generated element
735 void makeWalls (TNodeOfNodeListMap & mapNewNodes,
736 TTElemOfElemListMap & newElemsMap,
737 TElemOfVecOfNnlmiMap & elemNewNodesMap,
738 TIDSortedElemSet& elemSet,
740 SMESH_SequenceOfElemPtr& srcElements);
742 struct SMESH_MeshEditor_PathPoint
746 double myAngle, myPrm;
748 SMESH_MeshEditor_PathPoint(): myPnt(99., 99., 99.), myTgt(1.,0.,0.), myAngle(0), myPrm(0) {}
749 void SetPnt (const gp_Pnt& aP3D) { myPnt =aP3D; }
750 void SetTangent (const gp_Dir& aTgt) { myTgt =aTgt; }
751 void SetAngle (const double& aBeta) { myAngle=aBeta; }
752 void SetParameter(const double& aPrm) { myPrm =aPrm; }
753 const gp_Pnt& Pnt ()const { return myPnt; }
754 const gp_Dir& Tangent ()const { return myTgt; }
755 double Angle ()const { return myAngle; }
756 double Parameter ()const { return myPrm; }
758 Extrusion_Error MakeEdgePathPoints(std::list<double>& aPrms,
759 const TopoDS_Edge& aTrackEdge,
761 std::list<SMESH_MeshEditor_PathPoint>& aLPP);
762 Extrusion_Error MakeExtrElements(TIDSortedElemSet theElements[2],
763 std::list<SMESH_MeshEditor_PathPoint>& theFullList,
764 const bool theHasAngles,
765 std::list<double>& theAngles,
766 const bool theLinearVariation,
767 const bool theHasRefPoint,
768 const gp_Pnt& theRefPoint,
769 const bool theMakeGroups);
770 void LinearAngleVariation(const int NbSteps,
771 list<double>& theAngles);
773 bool doubleNodes( SMESHDS_Mesh* theMeshDS,
774 const TIDSortedElemSet& theElems,
775 const TIDSortedElemSet& theNodesNot,
776 TNodeNodeMap& theNodeNodeMap,
777 const bool theIsDoubleElem );
779 void copyPosition( const SMDS_MeshNode* from,
780 const SMDS_MeshNode* to );
786 // Nodes and elements created during last operation
787 SMESH_SequenceOfElemPtr myLastCreatedNodes, myLastCreatedElems;
789 // Description of error/warning occured during last operation
790 SMESH_ComputeErrorPtr myError;