1 // Copyright (C) 2007-2016 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;
50 class SMESHDS_SubMesh;
53 class SMESH_MesherHelper;
54 class SMESH_NodeSearcher;
63 // ============================================================
65 * \brief Editor of a mesh
67 // ============================================================
69 class SMESH_EXPORT SMESH_MeshEditor
73 SMESH_MeshEditor( SMESH_Mesh* theMesh );
75 SMESH_Mesh * GetMesh() { return myMesh; }
76 SMESHDS_Mesh * GetMeshDS();
78 const SMESH_SequenceOfElemPtr& GetLastCreatedNodes() const { return myLastCreatedNodes; }
79 const SMESH_SequenceOfElemPtr& GetLastCreatedElems() const { return myLastCreatedElems; }
80 void ClearLastCreated();
81 SMESH_ComputeErrorPtr & GetError() { return myError; }
83 // --------------------------------------------------------------------------------
84 struct ElemFeatures //!< Features of element to create
86 SMDSAbs_ElementType myType;
87 bool myIsPoly, myIsQuad;
89 double myBallDiameter;
90 std::vector<int> myPolyhedQuantities;
91 std::vector<const SMDS_MeshNode*> myNodes; // not managed by ElemFeatures
93 SMESH_EXPORT ElemFeatures( SMDSAbs_ElementType type=SMDSAbs_All, bool isPoly=false, bool isQuad=false )
94 :myType( type ), myIsPoly(isPoly), myIsQuad(isQuad), myID(-1), myBallDiameter(0) {}
96 SMESH_EXPORT ElemFeatures& Init( SMDSAbs_ElementType type, bool isPoly=false, bool isQuad=false )
97 { myType = type; myIsPoly = isPoly; myIsQuad = isQuad; return *this; }
99 SMESH_EXPORT ElemFeatures& Init( const SMDS_MeshElement* elem, bool basicOnly=true );
101 SMESH_EXPORT ElemFeatures& Init( double diameter )
102 { myType = SMDSAbs_Ball; myBallDiameter = diameter; return *this; }
104 SMESH_EXPORT ElemFeatures& Init( std::vector<int>& quanities, bool isQuad=false )
105 { myType = SMDSAbs_Volume; myIsPoly = 1; myIsQuad = isQuad;
106 myPolyhedQuantities.swap( quanities ); return *this; }
108 SMESH_EXPORT ElemFeatures& Init( const std::vector<int>& quanities, bool isQuad=false )
109 { myType = SMDSAbs_Volume; myIsPoly = 1; myIsQuad = isQuad;
110 myPolyhedQuantities = quanities; return *this; }
112 SMESH_EXPORT ElemFeatures& SetPoly(bool isPoly) { myIsPoly = isPoly; return *this; }
113 SMESH_EXPORT ElemFeatures& SetQuad(bool isQuad) { myIsQuad = isQuad; return *this; }
114 SMESH_EXPORT ElemFeatures& SetID (int ID) { myID = ID; return *this; }
120 SMDS_MeshElement* AddElement(const std::vector<const SMDS_MeshNode*> & nodes,
121 const ElemFeatures& features);
125 SMDS_MeshElement* AddElement(const std::vector<int> & nodeIDs,
126 const ElemFeatures& features);
128 int Remove (const std::list< int >& theElemIDs, const bool isNodes);
129 // Remove a node or an element.
130 // Modify a compute state of sub-meshes which become empty
132 void Create0DElementsOnAllNodes( const TIDSortedElemSet& elements,
133 TIDSortedElemSet& all0DElems,
134 const bool duplicateElements);
135 // Create 0D elements on all nodes of the given. \a all0DElems returns
136 // all 0D elements found or created on nodes of \a elements
138 bool InverseDiag (const SMDS_MeshElement * theTria1,
139 const SMDS_MeshElement * theTria2 );
140 // Replace two neighbour triangles with ones built on the same 4 nodes
141 // but having other common link.
142 // Return False if args are improper
144 bool InverseDiag (const SMDS_MeshNode * theNode1,
145 const SMDS_MeshNode * theNode2 );
146 // Replace two neighbour triangles sharing theNode1-theNode2 link
147 // with ones built on the same 4 nodes but having other common link.
148 // Return false if proper faces not found
150 bool DeleteDiag (const SMDS_MeshNode * theNode1,
151 const SMDS_MeshNode * theNode2 );
152 // Replace two neighbour triangles sharing theNode1-theNode2 link
153 // with a quadrangle built on the same 4 nodes.
154 // Return false if proper faces not found
156 bool Reorient (const SMDS_MeshElement * theElement);
157 // Reverse theElement orientation
159 int Reorient2D (TIDSortedElemSet & theFaces,
160 const gp_Dir& theDirection,
161 const SMDS_MeshElement * theFace);
162 // Reverse theFaces whose orientation to be same as that of theFace
163 // oriented according to theDirection. Return nb of reoriented faces
165 int Reorient2DBy3D (TIDSortedElemSet & theFaces,
166 TIDSortedElemSet & theVolumes,
167 const bool theOutsideNormal);
168 // Reorient faces basing on orientation of adjacent volumes.
169 // Return nb of reoriented faces
172 * \brief Fuse neighbour triangles into quadrangles.
173 * \param theElems - The triangles to be fused.
174 * \param theCriterion - Is used to choose a neighbour to fuse with.
175 * \param theMaxAngle - Is a max angle between element normals at which fusion
176 * is still performed; theMaxAngle is measured in radians.
177 * \return bool - Success or not.
179 bool TriToQuad (TIDSortedElemSet & theElems,
180 SMESH::Controls::NumericalFunctorPtr theCriterion,
181 const double theMaxAngle);
183 * \brief Split quadrangles into triangles.
184 * \param theElems - The faces to be split.
185 * \param theCriterion - Is used to choose a diagonal for splitting.
186 * \return bool - Success or not.
188 bool QuadToTri (TIDSortedElemSet & theElems,
189 SMESH::Controls::NumericalFunctorPtr theCriterion);
191 * \brief Split quadrangles into triangles.
192 * \param theElems - The faces to be split.
193 * \param the13Diag - Is used to choose a diagonal for splitting.
194 * \return bool - Success or not.
196 bool QuadToTri (TIDSortedElemSet & theElems,
197 const bool the13Diag);
199 * \brief Split each of given quadrangles into 4 triangles.
200 * \param theElems - The faces to be splitted. If empty all faces are split.
202 void QuadTo4Tri (TIDSortedElemSet & theElems);
205 * \brief Find better diagonal for splitting.
206 * \param theQuad - The face to find better splitting of.
207 * \param theCriterion - Is used to choose a diagonal for splitting.
208 * \return int - 1 for 1-3 diagonal, 2 for 2-4, -1 - for errors.
210 int BestSplit (const SMDS_MeshElement* theQuad,
211 SMESH::Controls::NumericalFunctorPtr theCriterion);
214 typedef std::map < const SMDS_MeshElement*, int, TIDCompare > TFacetOfElem;
216 //!<2nd arg of SplitVolumes()
217 enum SplitVolumToTetraFlags { HEXA_TO_5 = 1, // split into tetrahedra
220 HEXA_TO_2_PRISMS, // split into prisms
223 * \brief Split volumic elements into tetrahedra or prisms.
224 * If facet ID < 0, element is split into tetrahedra,
225 * else a hexahedron is split into prisms so that the given facet is
226 * split into triangles
228 void SplitVolumes (const TFacetOfElem & theElems, const int theMethodFlags);
231 * \brief For hexahedra that will be split into prisms, finds facets to
232 * split into triangles
233 * \param [in,out] theHexas - the hexahedra
234 * \param [in] theFacetNormal - facet normal
235 * \param [out] theFacets - the hexahedra and found facet IDs
237 void GetHexaFacetsToSplit( TIDSortedElemSet& theHexas,
238 const gp_Ax1& theFacetNormal,
239 TFacetOfElem & theFacets);
242 * \brief Split bi-quadratic elements into linear ones without creation of additional nodes
243 * - bi-quadratic triangle will be split into 3 linear quadrangles;
244 * - bi-quadratic quadrangle will be split into 4 linear quadrangles;
245 * - tri-quadratic hexahedron will be split into 8 linear hexahedra;
246 * Quadratic elements of lower dimension adjacent to the split bi-quadratic element
247 * will be split in order to keep the mesh conformal.
248 * \param elems - elements to split
250 void SplitBiQuadraticIntoLinear(TIDSortedElemSet& theElems);
252 enum SmoothMethod { LAPLACIAN = 0, CENTROIDAL };
254 void Smooth (TIDSortedElemSet & theElements,
255 std::set<const SMDS_MeshNode*> & theFixedNodes,
256 const SmoothMethod theSmoothMethod,
257 const int theNbIterations,
258 double theTgtAspectRatio = 1.0,
259 const bool the2D = true);
260 // Smooth theElements using theSmoothMethod during theNbIterations
261 // or until a worst element has aspect ratio <= theTgtAspectRatio.
262 // Aspect Ratio varies in range [1.0, inf].
263 // If theElements is empty, the whole mesh is smoothed.
264 // theFixedNodes contains additionally fixed nodes. Nodes built
265 // on edges and boundary nodes are always fixed.
266 // If the2D, smoothing is performed using UV parameters of nodes
267 // on geometrical faces
269 typedef TIDTypeCompare TElemSort;
270 typedef std::map < const SMDS_MeshElement*,
271 std::list<const SMDS_MeshElement*>, TElemSort > TTElemOfElemListMap;
272 typedef std::map<const SMDS_MeshNode*, std::list<const SMDS_MeshNode*> > TNodeOfNodeListMap;
273 typedef TNodeOfNodeListMap::iterator TNodeOfNodeListMapItr;
274 typedef std::vector<TNodeOfNodeListMapItr> TVecOfNnlmiMap;
275 typedef std::map<const SMDS_MeshElement*, TVecOfNnlmiMap, TElemSort > TElemOfVecOfNnlmiMap;
276 typedef std::auto_ptr< std::list<int> > PGroupIDs;
278 PGroupIDs RotationSweep (TIDSortedElemSet theElements[2],
279 const gp_Ax1& theAxis,
280 const double theAngle,
281 const int theNbSteps,
282 const double theToler,
283 const bool theMakeGroups,
284 const bool theMakeWalls=true);
285 // Generate new elements by rotation of theElements around theAxis
286 // by theAngle by theNbSteps
289 * Flags of extrusion.
290 * BOUNDARY: create or not boundary for result of extrusion
291 * SEW: try to use existing nodes or create new nodes in any case
292 * GROUPS: to create groups
293 * BY_AVG_NORMAL: step size is measured along average normal to elements,
294 * else step size is measured along average normal of any element
295 * USE_INPUT_ELEMS_ONLY: to use only input elements to compute extrusion direction
296 * for ExtrusionByNormal()
297 * SCALE_LINEAR_VARIATION: to make linear variation of scale factors
299 enum ExtrusionFlags {
300 EXTRUSION_FLAG_BOUNDARY = 0x01,
301 EXTRUSION_FLAG_SEW = 0x02,
302 EXTRUSION_FLAG_GROUPS = 0x04,
303 EXTRUSION_FLAG_BY_AVG_NORMAL = 0x08,
304 EXTRUSION_FLAG_USE_INPUT_ELEMS_ONLY = 0x10,
305 EXTRUSION_FLAG_SCALE_LINEAR_VARIATION = 0x20
309 * Generator of nodes for extrusion functionality
311 class SMESH_EXPORT ExtrusParam
313 gp_Dir myDir; // direction of extrusion
314 Handle(TColStd_HSequenceOfReal) mySteps; // magnitudes for each step
315 std::vector<double> myScales, myMediumScales;// scale factors
316 gp_XYZ myBaseP; // scaling center
317 SMESH_SequenceOfNode myNodes; // nodes for using in sewing
318 int myFlags; // see ExtrusionFlags
319 double myTolerance; // tolerance for sewing nodes
320 const TIDSortedElemSet* myElemsToUse; // elements to use for extrusion by normal
322 int (ExtrusParam::*myMakeNodesFun)(SMESHDS_Mesh* mesh,
323 const SMDS_MeshNode* srcNode,
324 std::list<const SMDS_MeshNode*> & newNodes,
325 const bool makeMediumNodes);
328 ExtrusParam( const gp_Vec& theStep,
329 const int theNbSteps,
330 const std::list<double>& theScales,
331 const gp_XYZ* theBaseP,
332 const int theFlags = 0,
333 const double theTolerance = 1e-6);
334 ExtrusParam( const gp_Dir& theDir,
335 Handle(TColStd_HSequenceOfReal) theSteps,
336 const int theFlags = 0,
337 const double theTolerance = 1e-6);
338 ExtrusParam( const double theStep,
339 const int theNbSteps,
341 const int theDim); // for extrusion by normal
343 SMESH_SequenceOfNode& ChangeNodes() { return myNodes; }
344 int& Flags() { return myFlags; }
345 bool ToMakeBoundary() const { return myFlags & EXTRUSION_FLAG_BOUNDARY; }
346 bool ToMakeGroups() const { return myFlags & EXTRUSION_FLAG_GROUPS; }
347 bool ToUseInpElemsOnly() const { return myFlags & EXTRUSION_FLAG_USE_INPUT_ELEMS_ONLY; }
348 bool IsLinearVariation() const { return myFlags & EXTRUSION_FLAG_SCALE_LINEAR_VARIATION; }
349 int NbSteps() const { return mySteps->Length(); }
351 // stores elements to use for extrusion by normal, depending on
352 // state of EXTRUSION_FLAG_USE_INPUT_ELEMS_ONLY flag;
353 // define myBaseP for scaling
354 void SetElementsToUse( const TIDSortedElemSet& elems, const TIDSortedElemSet& nodes );
356 // creates nodes and returns number of nodes added in \a newNodes
357 int MakeNodes( SMESHDS_Mesh* mesh,
358 const SMDS_MeshNode* srcNode,
359 std::list<const SMDS_MeshNode*> & newNodes,
360 const bool makeMediumNodes)
362 return (this->*myMakeNodesFun)( mesh, srcNode, newNodes, makeMediumNodes );
366 int makeNodesByDir( SMESHDS_Mesh* mesh,
367 const SMDS_MeshNode* srcNode,
368 std::list<const SMDS_MeshNode*> & newNodes,
369 const bool makeMediumNodes);
370 int makeNodesByDirAndSew( SMESHDS_Mesh* mesh,
371 const SMDS_MeshNode* srcNode,
372 std::list<const SMDS_MeshNode*> & newNodes,
373 const bool makeMediumNodes);
374 int makeNodesByNormal2D( SMESHDS_Mesh* mesh,
375 const SMDS_MeshNode* srcNode,
376 std::list<const SMDS_MeshNode*> & newNodes,
377 const bool makeMediumNodes);
378 int makeNodesByNormal1D( SMESHDS_Mesh* mesh,
379 const SMDS_MeshNode* srcNode,
380 std::list<const SMDS_MeshNode*> & newNodes,
381 const bool makeMediumNodes);
383 void beginStepIter( bool withMediumNodes );
386 std::vector< double > myCurSteps;
387 bool myWithMediumNodes;
392 * Generate new elements by extrusion of theElements
393 * It is a method used in .idl file. All functionality
394 * is implemented in the next method (see below) which
395 * is used in the current method.
396 * @param theElems - list of elements for extrusion
397 * @param newElemsMap returns history of extrusion
398 * @param theFlags set flags for performing extrusion (see description
399 * of enum ExtrusionFlags for additional information)
400 * @param theTolerance - uses for comparing locations of nodes if flag
401 * EXTRUSION_FLAG_SEW is set
403 PGroupIDs ExtrusionSweep (TIDSortedElemSet theElems[2],
404 const gp_Vec& theStep,
405 const int theNbSteps,
406 TTElemOfElemListMap& newElemsMap,
408 const double theTolerance = 1.e-6);
411 * Generate new elements by extrusion of theElements
412 * @param theElems - list of elements for extrusion
413 * @param newElemsMap returns history of extrusion
414 * @param theFlags set flags for performing extrusion (see description
415 * of enum ExtrusionFlags for additional information)
416 * @param theTolerance - uses for comparing locations of nodes if flag
417 * EXTRUSION_FLAG_SEW is set
418 * @param theParams - special structure for manage of extrusion
420 PGroupIDs ExtrusionSweep (TIDSortedElemSet theElems[2],
421 ExtrusParam& theParams,
422 TTElemOfElemListMap& newElemsMap);
425 // Generate new elements by extrusion of theElements
426 // by theStep by theNbSteps
428 enum Extrusion_Error {
433 EXTR_BAD_STARTING_NODE,
434 EXTR_BAD_ANGLES_NUMBER,
435 EXTR_CANT_GET_TANGENT
438 Extrusion_Error ExtrusionAlongTrack (TIDSortedElemSet theElements[2],
439 SMESH_subMesh* theTrackPattern,
440 const SMDS_MeshNode* theNodeStart,
441 const bool theHasAngles,
442 std::list<double>& theAngles,
443 const bool theLinearVariation,
444 const bool theHasRefPoint,
445 const gp_Pnt& theRefPoint,
446 const bool theMakeGroups);
447 Extrusion_Error ExtrusionAlongTrack (TIDSortedElemSet theElements[2],
448 SMESH_Mesh* theTrackPattern,
449 const SMDS_MeshNode* theNodeStart,
450 const bool theHasAngles,
451 std::list<double>& theAngles,
452 const bool theLinearVariation,
453 const bool theHasRefPoint,
454 const gp_Pnt& theRefPoint,
455 const bool theMakeGroups);
456 // Generate new elements by extrusion of theElements along path given by theTrackPattern,
457 // theHasAngles are the rotation angles, base point can be given by theRefPoint
459 PGroupIDs Transform (TIDSortedElemSet & theElements,
460 const gp_Trsf& theTrsf,
462 const bool theMakeGroups,
463 SMESH_Mesh* theTargetMesh=0);
464 // Move or copy theElements applying theTrsf to their nodes
466 typedef std::list< std::list< const SMDS_MeshNode* > > TListOfListOfNodes;
468 void FindCoincidentNodes (TIDSortedNodeSet & theNodes,
469 const double theTolerance,
470 TListOfListOfNodes & theGroupsOfNodes,
471 bool theSeparateCornersAndMedium);
472 // Return list of group of nodes close to each other within theTolerance.
473 // Search among theNodes or in the whole mesh if theNodes is empty.
475 void MergeNodes (TListOfListOfNodes & theNodeGroups,
476 const bool theAvoidMakingHoles = false);
477 // In each group, the cdr of nodes are substituted by the first one
480 typedef std::list< std::list< int > > TListOfListOfElementsID;
482 void FindEqualElements(TIDSortedElemSet & theElements,
483 TListOfListOfElementsID & theGroupsOfElementsID);
484 // Return list of group of elements build on the same nodes.
485 // Search among theElements or in the whole mesh if theElements is empty.
487 void MergeElements(TListOfListOfElementsID & theGroupsOfElementsID);
488 // In each group remove all but first of elements.
490 void MergeEqualElements();
491 // Remove all but one of elements built on the same nodes.
492 // Return nb of successfully merged groups.
494 int SimplifyFace (const std::vector<const SMDS_MeshNode *>& faceNodes,
495 std::vector<const SMDS_MeshNode *>& poly_nodes,
496 std::vector<int>& quantities) const;
497 // Split face, defined by <faceNodes>, into several faces by repeating nodes.
498 // Is used by MergeNodes()
500 static bool CheckFreeBorderNodes(const SMDS_MeshNode* theNode1,
501 const SMDS_MeshNode* theNode2,
502 const SMDS_MeshNode* theNode3 = 0);
503 // Return true if the three nodes are on a free border
505 static bool FindFreeBorder (const SMDS_MeshNode* theFirstNode,
506 const SMDS_MeshNode* theSecondNode,
507 const SMDS_MeshNode* theLastNode,
508 std::list< const SMDS_MeshNode* > & theNodes,
509 std::list< const SMDS_MeshElement* >& theFaces);
510 // Return nodes and faces of a free border if found
514 // for SewFreeBorder()
515 SEW_BORDER1_NOT_FOUND,
516 SEW_BORDER2_NOT_FOUND,
517 SEW_BOTH_BORDERS_NOT_FOUND,
519 SEW_VOLUMES_TO_SPLIT,
520 // for SewSideElements()
521 SEW_DIFF_NB_OF_ELEMENTS,
522 SEW_TOPO_DIFF_SETS_OF_ELEMENTS,
529 Sew_Error SewFreeBorder (const SMDS_MeshNode* theBorderFirstNode,
530 const SMDS_MeshNode* theBorderSecondNode,
531 const SMDS_MeshNode* theBorderLastNode,
532 const SMDS_MeshNode* theSide2FirstNode,
533 const SMDS_MeshNode* theSide2SecondNode,
534 const SMDS_MeshNode* theSide2ThirdNode = 0,
535 const bool theSide2IsFreeBorder = true,
536 const bool toCreatePolygons = false,
537 const bool toCreatePolyedrs = false);
538 // Sew the free border to the side2 by replacing nodes in
539 // elements on the free border with nodes of the elements
540 // of the side 2. If nb of links in the free border and
541 // between theSide2FirstNode and theSide2LastNode are different,
542 // additional nodes are inserted on a link provided that no
543 // volume elements share the splitted link.
544 // The side 2 is a free border if theSide2IsFreeBorder == true.
545 // Sewing is performed between the given first, second and last
546 // nodes on the sides.
547 // theBorderFirstNode is merged with theSide2FirstNode.
548 // if (!theSide2IsFreeBorder) then theSide2SecondNode gives
549 // the last node on the side 2, which will be merged with
550 // theBorderLastNode.
551 // if (theSide2IsFreeBorder) then theSide2SecondNode will
552 // be merged with theBorderSecondNode.
553 // if (theSide2IsFreeBorder && theSide2ThirdNode == 0) then
554 // the 2 free borders are sewn link by link and no additional
555 // nodes are inserted.
556 // Return false, if sewing failed.
558 Sew_Error SewSideElements (TIDSortedElemSet& theSide1,
559 TIDSortedElemSet& theSide2,
560 const SMDS_MeshNode* theFirstNode1ToMerge,
561 const SMDS_MeshNode* theFirstNode2ToMerge,
562 const SMDS_MeshNode* theSecondNode1ToMerge,
563 const SMDS_MeshNode* theSecondNode2ToMerge);
564 // Sew two sides of a mesh. Nodes belonging to theSide1 are
565 // merged with nodes of elements of theSide2.
566 // Number of elements in theSide1 and in theSide2 must be
567 // equal and they should have similar node connectivity.
568 // The nodes to merge should belong to side s borders and
569 // the first node should be linked to the second.
571 void InsertNodesIntoLink(const SMDS_MeshElement* theFace,
572 const SMDS_MeshNode* theBetweenNode1,
573 const SMDS_MeshNode* theBetweenNode2,
574 std::list<const SMDS_MeshNode*>& theNodesToInsert,
575 const bool toCreatePoly = false);
576 // insert theNodesToInsert into theFace between theBetweenNode1 and theBetweenNode2.
577 // If toCreatePoly is true, replace theFace by polygon, else split theFace.
579 void UpdateVolumes (const SMDS_MeshNode* theBetweenNode1,
580 const SMDS_MeshNode* theBetweenNode2,
581 std::list<const SMDS_MeshNode*>& theNodesToInsert);
582 // insert theNodesToInsert into all volumes, containing link
583 // theBetweenNode1 - theBetweenNode2, between theBetweenNode1 and theBetweenNode2.
585 void ConvertToQuadratic(const bool theForce3d, const bool theToBiQuad);
586 void ConvertToQuadratic(const bool theForce3d,
587 TIDSortedElemSet& theElements, const bool theToBiQuad);
588 // Converts all mesh to quadratic or bi-quadratic one, deletes old elements,
589 // replacing them with quadratic or bi-quadratic ones with the same id.
590 // If theForce3d = 1; this results in the medium node lying at the
591 // middle of the line segments connecting start and end node of a mesh element.
592 // If theForce3d = 0; this results in the medium node lying at the
593 // geometrical edge from which the mesh element is built.
595 bool ConvertFromQuadratic();
596 void ConvertFromQuadratic(TIDSortedElemSet& theElements);
597 // Converts all mesh from quadratic to ordinary ones, deletes old quadratic elements, replacing
598 // them with ordinary mesh elements with the same id.
599 // Returns true in case of success, false otherwise.
601 static void AddToSameGroups (const SMDS_MeshElement* elemToAdd,
602 const SMDS_MeshElement* elemInGroups,
603 SMESHDS_Mesh * aMesh);
604 // Add elemToAdd to the all groups the elemInGroups belongs to
606 static void RemoveElemFromGroups (const SMDS_MeshElement* element,
607 SMESHDS_Mesh * aMesh);
608 // remove element from the all groups
610 static void ReplaceElemInGroups (const SMDS_MeshElement* elemToRm,
611 const SMDS_MeshElement* elemToAdd,
612 SMESHDS_Mesh * aMesh);
613 // replace elemToRm by elemToAdd in the all groups
615 static void ReplaceElemInGroups (const SMDS_MeshElement* elemToRm,
616 const std::vector<const SMDS_MeshElement*>& elemToAdd,
617 SMESHDS_Mesh * aMesh);
618 // replace elemToRm by elemToAdd in the all groups
621 * \brief Return nodes linked to the given one in elements of the type
623 static void GetLinkedNodes( const SMDS_MeshNode* node,
624 TIDSortedElemSet & linkedNodes,
625 SMDSAbs_ElementType type = SMDSAbs_All );
628 * \brief Find corresponding nodes in two sets of faces
629 * \param theSide1 - first face set
630 * \param theSide2 - second first face
631 * \param theFirstNode1 - a boundary node of set 1
632 * \param theFirstNode2 - a node of set 2 corresponding to theFirstNode1
633 * \param theSecondNode1 - a boundary node of set 1 linked with theFirstNode1
634 * \param theSecondNode2 - a node of set 2 corresponding to theSecondNode1
635 * \param nReplaceMap - output map of corresponding nodes
636 * \return Sew_Error - is a success or not
638 static Sew_Error FindMatchingNodes(std::set<const SMDS_MeshElement*>& theSide1,
639 std::set<const SMDS_MeshElement*>& theSide2,
640 const SMDS_MeshNode* theFirstNode1,
641 const SMDS_MeshNode* theFirstNode2,
642 const SMDS_MeshNode* theSecondNode1,
643 const SMDS_MeshNode* theSecondNode2,
644 TNodeNodeMap & theNodeReplaceMap);
647 * \brief Returns true if given node is medium
648 * \param n - node to check
649 * \param typeToCheck - type of elements containing the node to ask about node status
650 * \return bool - check result
652 static bool IsMedium(const SMDS_MeshNode* node,
653 const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
655 int FindShape (const SMDS_MeshElement * theElem);
656 // Return an index of the shape theElem is on
657 // or zero if a shape not found
659 void DoubleElements( const TIDSortedElemSet& theElements );
661 bool DoubleNodes( const std::list< int >& theListOfNodes,
662 const std::list< int >& theListOfModifiedElems );
664 bool DoubleNodes( const TIDSortedElemSet& theElems,
665 const TIDSortedElemSet& theNodesNot,
666 const TIDSortedElemSet& theAffectedElems );
668 bool AffectedElemGroupsInRegion( const TIDSortedElemSet& theElems,
669 const TIDSortedElemSet& theNodesNot,
670 const TopoDS_Shape& theShape,
671 TIDSortedElemSet& theAffectedElems);
673 bool DoubleNodesInRegion( const TIDSortedElemSet& theElems,
674 const TIDSortedElemSet& theNodesNot,
675 const TopoDS_Shape& theShape );
677 double OrientedAngle(const gp_Pnt& p0, const gp_Pnt& p1, const gp_Pnt& g1, const gp_Pnt& g2);
679 bool DoubleNodesOnGroupBoundaries( const std::vector<TIDSortedElemSet>& theElems,
680 bool createJointElems,
681 bool onAllBoundaries);
683 bool CreateFlatElementsOnFacesGroups( const std::vector<TIDSortedElemSet>& theElems );
685 void CreateHoleSkin(double radius,
686 const TopoDS_Shape& theShape,
687 SMESH_NodeSearcher* theNodeSearcher,
688 const char* groupName,
689 std::vector<double>& nodesCoords,
690 std::vector<std::vector<int> >& listOfListOfNodes);
693 * \brief Generated skin mesh (containing 2D cells) from 3D mesh
694 * The created 2D mesh elements based on nodes of free faces of boundary volumes
695 * \return TRUE if operation has been completed successfully, FALSE otherwise
697 bool Make2DMeshFrom3D();
699 enum Bnd_Dimension { BND_2DFROM3D, BND_1DFROM3D, BND_1DFROM2D };
701 int MakeBoundaryMesh(const TIDSortedElemSet& elements,
702 Bnd_Dimension dimension,
703 SMESH_Group* group = 0,
704 SMESH_Mesh* targetMesh = 0,
705 bool toCopyElements = false,
706 bool toCopyExistingBondary = false,
707 bool toAddExistingBondary = false,
708 bool aroundElements = false);
713 * \brief Convert elements contained in a submesh to quadratic
714 * \return int - nb of checked elements
716 int convertElemToQuadratic(SMESHDS_SubMesh * theSm,
717 SMESH_MesherHelper& theHelper,
718 const bool theForce3d);
721 * \brief Convert quadratic elements to linear ones and remove quadratic nodes
722 * \return nb of checked elements
724 int removeQuadElem( SMESHDS_SubMesh * theSm,
725 SMDS_ElemIteratorPtr theItr,
726 const int theShapeID);
728 * \brief Create groups of elements made during transformation
729 * \param nodeGens - nodes making corresponding myLastCreatedNodes
730 * \param elemGens - elements making corresponding myLastCreatedElems
731 * \param postfix - to append to names of new groups
732 * \param targetMesh - mesh to create groups in
733 * \param topPresent - is there "top" elements that are created by sweeping
735 PGroupIDs generateGroups(const SMESH_SequenceOfElemPtr& nodeGens,
736 const SMESH_SequenceOfElemPtr& elemGens,
737 const std::string& postfix,
738 SMESH_Mesh* targetMesh=0,
739 const bool topPresent=true);
741 * \brief Create elements by sweeping an element
742 * \param elem - element to sweep
743 * \param newNodesItVec - nodes generated from each node of the element
744 * \param newElems - generated elements
745 * \param nbSteps - number of sweeping steps
746 * \param srcElements - to append elem for each generated element
748 void sweepElement(const SMDS_MeshElement* elem,
749 const std::vector<TNodeOfNodeListMapItr> & newNodesItVec,
750 std::list<const SMDS_MeshElement*>& newElems,
751 const size_t nbSteps,
752 SMESH_SequenceOfElemPtr& srcElements);
755 * \brief Computes new connectivity of an element after merging nodes
756 * \param [in] elems - the element
757 * \param [out] newElemDefs - definition(s) of result element(s)
758 * \param [inout] nodeNodeMap - nodes to merge
759 * \param [in] avoidMakingHoles - if true and and the element becomes invalid
760 * after merging (but not degenerated), removes nodes causing
761 * the invalidity from \a nodeNodeMap.
762 * \return bool - true if the element should be removed
764 bool applyMerge( const SMDS_MeshElement* elems,
765 std::vector< ElemFeatures >& newElemDefs,
766 TNodeNodeMap& nodeNodeMap,
767 const bool avoidMakingHoles );
769 * \brief Create 1D and 2D elements around swept elements
770 * \param mapNewNodes - source nodes and ones generated from them
771 * \param newElemsMap - source elements and ones generated from them
772 * \param elemNewNodesMap - nodes generated from each node of each element
773 * \param elemSet - all swept elements
774 * \param nbSteps - number of sweeping steps
775 * \param srcElements - to append elem for each generated element
777 void makeWalls (TNodeOfNodeListMap & mapNewNodes,
778 TTElemOfElemListMap & newElemsMap,
779 TElemOfVecOfNnlmiMap & elemNewNodesMap,
780 TIDSortedElemSet& elemSet,
782 SMESH_SequenceOfElemPtr& srcElements);
784 struct SMESH_MeshEditor_PathPoint
788 double myAngle, myPrm;
790 SMESH_MeshEditor_PathPoint(): myPnt(99., 99., 99.), myTgt(1.,0.,0.), myAngle(0), myPrm(0) {}
791 void SetPnt (const gp_Pnt& aP3D) { myPnt =aP3D; }
792 void SetTangent (const gp_Dir& aTgt) { myTgt =aTgt; }
793 void SetAngle (const double& aBeta) { myAngle=aBeta; }
794 void SetParameter(const double& aPrm) { myPrm =aPrm; }
795 const gp_Pnt& Pnt ()const { return myPnt; }
796 const gp_Dir& Tangent ()const { return myTgt; }
797 double Angle ()const { return myAngle; }
798 double Parameter ()const { return myPrm; }
800 Extrusion_Error makeEdgePathPoints(std::list<double>& aPrms,
801 const TopoDS_Edge& aTrackEdge,
803 std::list<SMESH_MeshEditor_PathPoint>& aLPP);
804 Extrusion_Error makeExtrElements(TIDSortedElemSet theElements[2],
805 std::list<SMESH_MeshEditor_PathPoint>& theFullList,
806 const bool theHasAngles,
807 std::list<double>& theAngles,
808 const bool theLinearVariation,
809 const bool theHasRefPoint,
810 const gp_Pnt& theRefPoint,
811 const bool theMakeGroups);
812 static void linearAngleVariation(const int NbSteps,
813 std::list<double>& theAngles);
815 bool doubleNodes( SMESHDS_Mesh* theMeshDS,
816 const TIDSortedElemSet& theElems,
817 const TIDSortedElemSet& theNodesNot,
818 TNodeNodeMap& theNodeNodeMap,
819 const bool theIsDoubleElem );
821 void copyPosition( const SMDS_MeshNode* from,
822 const SMDS_MeshNode* to );
828 // Nodes and elements created during last operation
829 SMESH_SequenceOfElemPtr myLastCreatedNodes, myLastCreatedElems;
831 // Description of error/warning occurred during last operation
832 SMESH_ComputeErrorPtr myError;