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 // Return list of group of nodes close to each other within theTolerance.
445 // Search among theNodes or in the whole mesh if theNodes is empty.
447 void MergeNodes (TListOfListOfNodes & theNodeGroups);
448 // In each group, the cdr of nodes are substituted by the first one
451 typedef std::list< std::list< int > > TListOfListOfElementsID;
453 void FindEqualElements(TIDSortedElemSet & theElements,
454 TListOfListOfElementsID & theGroupsOfElementsID);
455 // Return list of group of elements build on the same nodes.
456 // Search among theElements or in the whole mesh if theElements is empty.
458 void MergeElements(TListOfListOfElementsID & theGroupsOfElementsID);
459 // In each group remove all but first of elements.
461 void MergeEqualElements();
462 // Remove all but one of elements built on the same nodes.
463 // Return nb of successfully merged groups.
465 int SimplifyFace (const std::vector<const SMDS_MeshNode *>& faceNodes,
466 std::vector<const SMDS_MeshNode *>& poly_nodes,
467 std::vector<int>& quantities) const;
468 // Split face, defined by <faceNodes>, into several faces by repeating nodes.
469 // Is used by MergeNodes()
471 static bool CheckFreeBorderNodes(const SMDS_MeshNode* theNode1,
472 const SMDS_MeshNode* theNode2,
473 const SMDS_MeshNode* theNode3 = 0);
474 // Return true if the three nodes are on a free border
476 static bool FindFreeBorder (const SMDS_MeshNode* theFirstNode,
477 const SMDS_MeshNode* theSecondNode,
478 const SMDS_MeshNode* theLastNode,
479 std::list< const SMDS_MeshNode* > & theNodes,
480 std::list< const SMDS_MeshElement* >& theFaces);
481 // Return nodes and faces of a free border if found
485 // for SewFreeBorder()
486 SEW_BORDER1_NOT_FOUND,
487 SEW_BORDER2_NOT_FOUND,
488 SEW_BOTH_BORDERS_NOT_FOUND,
490 SEW_VOLUMES_TO_SPLIT,
491 // for SewSideElements()
492 SEW_DIFF_NB_OF_ELEMENTS,
493 SEW_TOPO_DIFF_SETS_OF_ELEMENTS,
500 Sew_Error SewFreeBorder (const SMDS_MeshNode* theBorderFirstNode,
501 const SMDS_MeshNode* theBorderSecondNode,
502 const SMDS_MeshNode* theBorderLastNode,
503 const SMDS_MeshNode* theSide2FirstNode,
504 const SMDS_MeshNode* theSide2SecondNode,
505 const SMDS_MeshNode* theSide2ThirdNode = 0,
506 const bool theSide2IsFreeBorder = true,
507 const bool toCreatePolygons = false,
508 const bool toCreatePolyedrs = false);
509 // Sew the free border to the side2 by replacing nodes in
510 // elements on the free border with nodes of the elements
511 // of the side 2. If nb of links in the free border and
512 // between theSide2FirstNode and theSide2LastNode are different,
513 // additional nodes are inserted on a link provided that no
514 // volume elements share the splitted link.
515 // The side 2 is a free border if theSide2IsFreeBorder == true.
516 // Sewing is peformed between the given first, second and last
517 // nodes on the sides.
518 // theBorderFirstNode is merged with theSide2FirstNode.
519 // if (!theSide2IsFreeBorder) then theSide2SecondNode gives
520 // the last node on the side 2, which will be merged with
521 // theBorderLastNode.
522 // if (theSide2IsFreeBorder) then theSide2SecondNode will
523 // be merged with theBorderSecondNode.
524 // if (theSide2IsFreeBorder && theSide2ThirdNode == 0) then
525 // the 2 free borders are sewn link by link and no additional
526 // nodes are inserted.
527 // Return false, if sewing failed.
529 Sew_Error SewSideElements (TIDSortedElemSet& theSide1,
530 TIDSortedElemSet& theSide2,
531 const SMDS_MeshNode* theFirstNode1ToMerge,
532 const SMDS_MeshNode* theFirstNode2ToMerge,
533 const SMDS_MeshNode* theSecondNode1ToMerge,
534 const SMDS_MeshNode* theSecondNode2ToMerge);
535 // Sew two sides of a mesh. Nodes belonging to theSide1 are
536 // merged with nodes of elements of theSide2.
537 // Number of elements in theSide1 and in theSide2 must be
538 // equal and they should have similar node connectivity.
539 // The nodes to merge should belong to side s borders and
540 // the first node should be linked to the second.
542 void InsertNodesIntoLink(const SMDS_MeshElement* theFace,
543 const SMDS_MeshNode* theBetweenNode1,
544 const SMDS_MeshNode* theBetweenNode2,
545 std::list<const SMDS_MeshNode*>& theNodesToInsert,
546 const bool toCreatePoly = false);
547 // insert theNodesToInsert into theFace between theBetweenNode1 and theBetweenNode2.
548 // If toCreatePoly is true, replace theFace by polygon, else split theFace.
550 void UpdateVolumes (const SMDS_MeshNode* theBetweenNode1,
551 const SMDS_MeshNode* theBetweenNode2,
552 std::list<const SMDS_MeshNode*>& theNodesToInsert);
553 // insert theNodesToInsert into all volumes, containing link
554 // theBetweenNode1 - theBetweenNode2, between theBetweenNode1 and theBetweenNode2.
556 void ConvertToQuadratic(const bool theForce3d, const bool theToBiQuad);
557 void ConvertToQuadratic(const bool theForce3d,
558 TIDSortedElemSet& theElements, const bool theToBiQuad);
559 // Converts all mesh to quadratic or bi-quadratic one, deletes old elements,
560 // replacing them with quadratic or bi-quadratic ones with the same id.
561 // If theForce3d = 1; this results in the medium node lying at the
562 // middle of the line segments connecting start and end node of a mesh element.
563 // If theForce3d = 0; this results in the medium node lying at the
564 // geometrical edge from which the mesh element is built.
566 bool ConvertFromQuadratic();
567 void ConvertFromQuadratic(TIDSortedElemSet& theElements);
568 // Converts all mesh from quadratic to ordinary ones, deletes old quadratic elements, replacing
569 // them with ordinary mesh elements with the same id.
570 // Returns true in case of success, false otherwise.
572 static void AddToSameGroups (const SMDS_MeshElement* elemToAdd,
573 const SMDS_MeshElement* elemInGroups,
574 SMESHDS_Mesh * aMesh);
575 // Add elemToAdd to the all groups the elemInGroups belongs to
577 static void RemoveElemFromGroups (const SMDS_MeshElement* element,
578 SMESHDS_Mesh * aMesh);
579 // remove element from the all groups
581 static void ReplaceElemInGroups (const SMDS_MeshElement* elemToRm,
582 const SMDS_MeshElement* elemToAdd,
583 SMESHDS_Mesh * aMesh);
584 // replace elemToRm by elemToAdd in the all groups
586 static void ReplaceElemInGroups (const SMDS_MeshElement* elemToRm,
587 const std::vector<const SMDS_MeshElement*>& elemToAdd,
588 SMESHDS_Mesh * aMesh);
589 // replace elemToRm by elemToAdd in the all groups
592 * \brief Return nodes linked to the given one in elements of the type
594 static void GetLinkedNodes( const SMDS_MeshNode* node,
595 TIDSortedElemSet & linkedNodes,
596 SMDSAbs_ElementType type = SMDSAbs_All );
599 * \brief Find corresponding nodes in two sets of faces
600 * \param theSide1 - first face set
601 * \param theSide2 - second first face
602 * \param theFirstNode1 - a boundary node of set 1
603 * \param theFirstNode2 - a node of set 2 corresponding to theFirstNode1
604 * \param theSecondNode1 - a boundary node of set 1 linked with theFirstNode1
605 * \param theSecondNode2 - a node of set 2 corresponding to theSecondNode1
606 * \param nReplaceMap - output map of corresponding nodes
607 * \return Sew_Error - is a success or not
609 static Sew_Error FindMatchingNodes(std::set<const SMDS_MeshElement*>& theSide1,
610 std::set<const SMDS_MeshElement*>& theSide2,
611 const SMDS_MeshNode* theFirstNode1,
612 const SMDS_MeshNode* theFirstNode2,
613 const SMDS_MeshNode* theSecondNode1,
614 const SMDS_MeshNode* theSecondNode2,
615 TNodeNodeMap & theNodeReplaceMap);
618 * \brief Returns true if given node is medium
619 * \param n - node to check
620 * \param typeToCheck - type of elements containing the node to ask about node status
621 * \return bool - check result
623 static bool IsMedium(const SMDS_MeshNode* node,
624 const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
626 int FindShape (const SMDS_MeshElement * theElem);
627 // Return an index of the shape theElem is on
628 // or zero if a shape not found
630 void DoubleElements( const TIDSortedElemSet& theElements );
632 bool DoubleNodes( const std::list< int >& theListOfNodes,
633 const std::list< int >& theListOfModifiedElems );
635 bool DoubleNodes( const TIDSortedElemSet& theElems,
636 const TIDSortedElemSet& theNodesNot,
637 const TIDSortedElemSet& theAffectedElems );
639 bool AffectedElemGroupsInRegion( const TIDSortedElemSet& theElems,
640 const TIDSortedElemSet& theNodesNot,
641 const TopoDS_Shape& theShape,
642 TIDSortedElemSet& theAffectedElems);
644 bool DoubleNodesInRegion( const TIDSortedElemSet& theElems,
645 const TIDSortedElemSet& theNodesNot,
646 const TopoDS_Shape& theShape );
648 double OrientedAngle(const gp_Pnt& p0, const gp_Pnt& p1, const gp_Pnt& g1, const gp_Pnt& g2);
650 bool DoubleNodesOnGroupBoundaries( const std::vector<TIDSortedElemSet>& theElems,
651 bool createJointElems,
652 bool onAllBoundaries);
654 bool CreateFlatElementsOnFacesGroups( const std::vector<TIDSortedElemSet>& theElems );
656 void CreateHoleSkin(double radius,
657 const TopoDS_Shape& theShape,
658 SMESH_NodeSearcher* theNodeSearcher,
659 const char* groupName,
660 std::vector<double>& nodesCoords,
661 std::vector<std::vector<int> >& listOfListOfNodes);
664 * \brief Generated skin mesh (containing 2D cells) from 3D mesh
665 * The created 2D mesh elements based on nodes of free faces of boundary volumes
666 * \return TRUE if operation has been completed successfully, FALSE otherwise
668 bool Make2DMeshFrom3D();
670 enum Bnd_Dimension { BND_2DFROM3D, BND_1DFROM3D, BND_1DFROM2D };
672 int MakeBoundaryMesh(const TIDSortedElemSet& elements,
673 Bnd_Dimension dimension,
674 SMESH_Group* group = 0,
675 SMESH_Mesh* targetMesh = 0,
676 bool toCopyElements = false,
677 bool toCopyExistingBondary = false,
678 bool toAddExistingBondary = false,
679 bool aroundElements = false);
684 * \brief Convert elements contained in a submesh to quadratic
685 * \return int - nb of checked elements
687 int convertElemToQuadratic(SMESHDS_SubMesh * theSm,
688 SMESH_MesherHelper& theHelper,
689 const bool theForce3d);
692 * \brief Convert quadratic elements to linear ones and remove quadratic nodes
693 * \return nb of checked elements
695 int removeQuadElem( SMESHDS_SubMesh * theSm,
696 SMDS_ElemIteratorPtr theItr,
697 const int theShapeID);
699 * \brief Create groups of elements made during transformation
700 * \param nodeGens - nodes making corresponding myLastCreatedNodes
701 * \param elemGens - elements making corresponding myLastCreatedElems
702 * \param postfix - to append to names of new groups
703 * \param targetMesh - mesh to create groups in
704 * \param topPresent - is there "top" elements that are created by sweeping
706 PGroupIDs generateGroups(const SMESH_SequenceOfElemPtr& nodeGens,
707 const SMESH_SequenceOfElemPtr& elemGens,
708 const std::string& postfix,
709 SMESH_Mesh* targetMesh=0,
710 const bool topPresent=true);
712 * \brief Create elements by sweeping an element
713 * \param elem - element to sweep
714 * \param newNodesItVec - nodes generated from each node of the element
715 * \param newElems - generated elements
716 * \param nbSteps - number of sweeping steps
717 * \param srcElements - to append elem for each generated element
719 void sweepElement(const SMDS_MeshElement* elem,
720 const std::vector<TNodeOfNodeListMapItr> & newNodesItVec,
721 std::list<const SMDS_MeshElement*>& newElems,
723 SMESH_SequenceOfElemPtr& srcElements);
726 * \brief Create 1D and 2D elements around swept elements
727 * \param mapNewNodes - source nodes and ones generated from them
728 * \param newElemsMap - source elements and ones generated from them
729 * \param elemNewNodesMap - nodes generated from each node of each element
730 * \param elemSet - all swept elements
731 * \param nbSteps - number of sweeping steps
732 * \param srcElements - to append elem for each generated element
734 void makeWalls (TNodeOfNodeListMap & mapNewNodes,
735 TTElemOfElemListMap & newElemsMap,
736 TElemOfVecOfNnlmiMap & elemNewNodesMap,
737 TIDSortedElemSet& elemSet,
739 SMESH_SequenceOfElemPtr& srcElements);
741 struct SMESH_MeshEditor_PathPoint
745 double myAngle, myPrm;
747 SMESH_MeshEditor_PathPoint(): myPnt(99., 99., 99.), myTgt(1.,0.,0.), myAngle(0), myPrm(0) {}
748 void SetPnt (const gp_Pnt& aP3D) { myPnt =aP3D; }
749 void SetTangent (const gp_Dir& aTgt) { myTgt =aTgt; }
750 void SetAngle (const double& aBeta) { myAngle=aBeta; }
751 void SetParameter(const double& aPrm) { myPrm =aPrm; }
752 const gp_Pnt& Pnt ()const { return myPnt; }
753 const gp_Dir& Tangent ()const { return myTgt; }
754 double Angle ()const { return myAngle; }
755 double Parameter ()const { return myPrm; }
757 Extrusion_Error MakeEdgePathPoints(std::list<double>& aPrms,
758 const TopoDS_Edge& aTrackEdge,
760 std::list<SMESH_MeshEditor_PathPoint>& aLPP);
761 Extrusion_Error MakeExtrElements(TIDSortedElemSet theElements[2],
762 std::list<SMESH_MeshEditor_PathPoint>& theFullList,
763 const bool theHasAngles,
764 std::list<double>& theAngles,
765 const bool theLinearVariation,
766 const bool theHasRefPoint,
767 const gp_Pnt& theRefPoint,
768 const bool theMakeGroups);
769 void LinearAngleVariation(const int NbSteps,
770 list<double>& theAngles);
772 bool doubleNodes( SMESHDS_Mesh* theMeshDS,
773 const TIDSortedElemSet& theElems,
774 const TIDSortedElemSet& theNodesNot,
775 TNodeNodeMap& theNodeNodeMap,
776 const bool theIsDoubleElem );
778 void copyPosition( const SMDS_MeshNode* from,
779 const SMDS_MeshNode* to );
785 // Nodes and elements created during last operation
786 SMESH_SequenceOfElemPtr myLastCreatedNodes, myLastCreatedElems;
788 // Description of error/warning occured during last operation
789 SMESH_ComputeErrorPtr myError;