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 SMESH_EXPORT ElemFeatures( SMDSAbs_ElementType type=SMDSAbs_All, bool isPoly=false, bool isQuad=false )
86 :myType( type ), myIsPoly(isPoly), myIsQuad(isQuad), myID(-1), myBallDiameter(0) {}
88 SMESH_EXPORT ElemFeatures& Init( SMDSAbs_ElementType type, bool isPoly=false, bool isQuad=false )
89 { myType = type; myIsPoly = isPoly; myIsQuad = isQuad; return *this; }
91 SMESH_EXPORT ElemFeatures& Init( const SMDS_MeshElement* elem, bool basicOnly=true );
93 SMESH_EXPORT ElemFeatures& Init( double diameter )
94 { myType = SMDSAbs_Ball; myBallDiameter = diameter; return *this; }
96 SMESH_EXPORT ElemFeatures& Init( vector<int>& quanities, bool isQuad=false )
97 { myType = SMDSAbs_Volume; myIsPoly = 1; myIsQuad = isQuad;
98 myPolyhedQuantities.swap( quanities ); return *this; }
100 SMESH_EXPORT ElemFeatures& Init( const vector<int>& quanities, bool isQuad=false )
101 { myType = SMDSAbs_Volume; myIsPoly = 1; myIsQuad = isQuad;
102 myPolyhedQuantities = quanities; return *this; }
104 SMESH_EXPORT ElemFeatures& SetPoly(bool isPoly) { myIsPoly = isPoly; return *this; }
105 SMESH_EXPORT ElemFeatures& SetQuad(bool isQuad) { myIsQuad = isQuad; return *this; }
106 SMESH_EXPORT 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 * \brief Split bi-quadratic elements into linear ones without creation of additional nodes
235 * - bi-quadratic triangle will be split into 3 linear quadrangles;
236 * - bi-quadratic quadrangle will be split into 4 linear quadrangles;
237 * - tri-quadratic hexahedron will be split into 8 linear hexahedra;
238 * Quadratic elements of lower dimension adjacent to the split bi-quadratic element
239 * will be split in order to keep the mesh conformal.
240 * \param elems - elements to split
242 void SplitBiQuadraticIntoLinear(TIDSortedElemSet& theElems);
244 enum SmoothMethod { LAPLACIAN = 0, CENTROIDAL };
246 void Smooth (TIDSortedElemSet & theElements,
247 std::set<const SMDS_MeshNode*> & theFixedNodes,
248 const SmoothMethod theSmoothMethod,
249 const int theNbIterations,
250 double theTgtAspectRatio = 1.0,
251 const bool the2D = true);
252 // Smooth theElements using theSmoothMethod during theNbIterations
253 // or until a worst element has aspect ratio <= theTgtAspectRatio.
254 // Aspect Ratio varies in range [1.0, inf].
255 // If theElements is empty, the whole mesh is smoothed.
256 // theFixedNodes contains additionally fixed nodes. Nodes built
257 // on edges and boundary nodes are always fixed.
258 // If the2D, smoothing is performed using UV parameters of nodes
259 // on geometrical faces
261 typedef TIDTypeCompare TElemSort;
262 typedef std::map < const SMDS_MeshElement*,
263 std::list<const SMDS_MeshElement*>, TElemSort > TTElemOfElemListMap;
264 typedef std::map<const SMDS_MeshNode*, std::list<const SMDS_MeshNode*> > TNodeOfNodeListMap;
265 typedef TNodeOfNodeListMap::iterator TNodeOfNodeListMapItr;
266 typedef std::vector<TNodeOfNodeListMapItr> TVecOfNnlmiMap;
267 typedef std::map<const SMDS_MeshElement*, TVecOfNnlmiMap, TElemSort > TElemOfVecOfNnlmiMap;
268 typedef std::auto_ptr< std::list<int> > PGroupIDs;
270 PGroupIDs RotationSweep (TIDSortedElemSet theElements[2],
271 const gp_Ax1& theAxis,
272 const double theAngle,
273 const int theNbSteps,
274 const double theToler,
275 const bool theMakeGroups,
276 const bool theMakeWalls=true);
277 // Generate new elements by rotation of theElements around theAxis
278 // by theAngle by theNbSteps
281 * Flags of extrusion.
282 * BOUNDARY: create or not boundary for result of extrusion
283 * SEW: try to use existing nodes or create new nodes in any case
284 * GROUPS: to create groups
285 * BY_AVG_NORMAL: step size is measured along average normal to elements,
286 * else step size is measured along average normal of any element
287 * USE_INPUT_ELEMS_ONLY: to use only input elements to compute extrusion direction
288 * for ExtrusionByNormal()
290 enum ExtrusionFlags {
291 EXTRUSION_FLAG_BOUNDARY = 0x01,
292 EXTRUSION_FLAG_SEW = 0x02,
293 EXTRUSION_FLAG_GROUPS = 0x04,
294 EXTRUSION_FLAG_BY_AVG_NORMAL = 0x08,
295 EXTRUSION_FLAG_USE_INPUT_ELEMS_ONLY = 0x10
299 * Generator of nodes for extrusion functionality
301 class SMESH_EXPORT ExtrusParam {
302 gp_Dir myDir; // direction of extrusion
303 Handle(TColStd_HSequenceOfReal) mySteps; // magnitudes for each step
304 SMESH_SequenceOfNode myNodes; // nodes for using in sewing
305 int myFlags; // see ExtrusionFlags
306 double myTolerance; // tolerance for sewing nodes
307 const TIDSortedElemSet* myElemsToUse; // elements to use for extrusion by normal
309 int (ExtrusParam::*myMakeNodesFun)(SMESHDS_Mesh* mesh,
310 const SMDS_MeshNode* srcNode,
311 std::list<const SMDS_MeshNode*> & newNodes,
312 const bool makeMediumNodes);
315 ExtrusParam( const gp_Vec& theStep,
316 const int theNbSteps,
317 const int theFlags = 0,
318 const double theTolerance = 1e-6);
319 ExtrusParam( const gp_Dir& theDir,
320 Handle(TColStd_HSequenceOfReal) theSteps,
321 const int theFlags = 0,
322 const double theTolerance = 1e-6);
323 ExtrusParam( const double theStep,
324 const int theNbSteps,
326 const int theDim); // for extrusion by normal
328 SMESH_SequenceOfNode& ChangeNodes() { return myNodes; }
329 int& Flags() { return myFlags; }
330 bool ToMakeBoundary() const { return myFlags & EXTRUSION_FLAG_BOUNDARY; }
331 bool ToMakeGroups() const { return myFlags & EXTRUSION_FLAG_GROUPS; }
332 bool ToUseInpElemsOnly() const { return myFlags & EXTRUSION_FLAG_USE_INPUT_ELEMS_ONLY; }
333 int NbSteps() const { return mySteps->Length(); }
335 // stores elements to use for extrusion by normal, depending on
336 // state of EXTRUSION_FLAG_USE_INPUT_ELEMS_ONLY flag
337 void SetElementsToUse( const TIDSortedElemSet& elems );
339 // creates nodes and returns number of nodes added in \a newNodes
340 int MakeNodes( SMESHDS_Mesh* mesh,
341 const SMDS_MeshNode* srcNode,
342 std::list<const SMDS_MeshNode*> & newNodes,
343 const bool makeMediumNodes)
345 return (this->*myMakeNodesFun)( mesh, srcNode, newNodes, makeMediumNodes );
349 int makeNodesByDir( SMESHDS_Mesh* mesh,
350 const SMDS_MeshNode* srcNode,
351 std::list<const SMDS_MeshNode*> & newNodes,
352 const bool makeMediumNodes);
353 int makeNodesByDirAndSew( SMESHDS_Mesh* mesh,
354 const SMDS_MeshNode* srcNode,
355 std::list<const SMDS_MeshNode*> & newNodes,
356 const bool makeMediumNodes);
357 int makeNodesByNormal2D( SMESHDS_Mesh* mesh,
358 const SMDS_MeshNode* srcNode,
359 std::list<const SMDS_MeshNode*> & newNodes,
360 const bool makeMediumNodes);
361 int makeNodesByNormal1D( SMESHDS_Mesh* mesh,
362 const SMDS_MeshNode* srcNode,
363 std::list<const SMDS_MeshNode*> & newNodes,
364 const bool makeMediumNodes);
366 void beginStepIter( bool withMediumNodes );
369 std::vector< double > myCurSteps;
370 bool myWithMediumNodes;
375 * Generate new elements by extrusion of theElements
376 * It is a method used in .idl file. All functionality
377 * is implemented in the next method (see below) which
378 * is used in the current method.
379 * @param theElems - list of elements for extrusion
380 * @param newElemsMap returns history of extrusion
381 * @param theFlags set flags for performing extrusion (see description
382 * of enum ExtrusionFlags for additional information)
383 * @param theTolerance - uses for comparing locations of nodes if flag
384 * EXTRUSION_FLAG_SEW is set
386 PGroupIDs ExtrusionSweep (TIDSortedElemSet theElems[2],
387 const gp_Vec& theStep,
388 const int theNbSteps,
389 TTElemOfElemListMap& newElemsMap,
391 const double theTolerance = 1.e-6);
394 * Generate new elements by extrusion of theElements
395 * @param theElems - list of elements for extrusion
396 * @param newElemsMap returns history of extrusion
397 * @param theFlags set flags for performing extrusion (see description
398 * of enum ExtrusionFlags for additional information)
399 * @param theTolerance - uses for comparing locations of nodes if flag
400 * EXTRUSION_FLAG_SEW is set
401 * @param theParams - special structure for manage of extrusion
403 PGroupIDs ExtrusionSweep (TIDSortedElemSet theElems[2],
404 ExtrusParam& theParams,
405 TTElemOfElemListMap& newElemsMap);
408 // Generate new elements by extrusion of theElements
409 // by theStep by theNbSteps
411 enum Extrusion_Error {
416 EXTR_BAD_STARTING_NODE,
417 EXTR_BAD_ANGLES_NUMBER,
418 EXTR_CANT_GET_TANGENT
421 Extrusion_Error ExtrusionAlongTrack (TIDSortedElemSet theElements[2],
422 SMESH_subMesh* theTrackPattern,
423 const SMDS_MeshNode* theNodeStart,
424 const bool theHasAngles,
425 std::list<double>& theAngles,
426 const bool theLinearVariation,
427 const bool theHasRefPoint,
428 const gp_Pnt& theRefPoint,
429 const bool theMakeGroups);
430 Extrusion_Error ExtrusionAlongTrack (TIDSortedElemSet theElements[2],
431 SMESH_Mesh* theTrackPattern,
432 const SMDS_MeshNode* theNodeStart,
433 const bool theHasAngles,
434 std::list<double>& theAngles,
435 const bool theLinearVariation,
436 const bool theHasRefPoint,
437 const gp_Pnt& theRefPoint,
438 const bool theMakeGroups);
439 // Generate new elements by extrusion of theElements along path given by theTrackPattern,
440 // theHasAngles are the rotation angles, base point can be given by theRefPoint
442 PGroupIDs Transform (TIDSortedElemSet & theElements,
443 const gp_Trsf& theTrsf,
445 const bool theMakeGroups,
446 SMESH_Mesh* theTargetMesh=0);
447 // Move or copy theElements applying theTrsf to their nodes
449 typedef std::list< std::list< const SMDS_MeshNode* > > TListOfListOfNodes;
451 void FindCoincidentNodes (TIDSortedNodeSet & theNodes,
452 const double theTolerance,
453 TListOfListOfNodes & theGroupsOfNodes,
454 bool theSeparateCornersAndMedium);
455 // Return list of group of nodes close to each other within theTolerance.
456 // Search among theNodes or in the whole mesh if theNodes is empty.
458 void MergeNodes (TListOfListOfNodes & theNodeGroups);
459 // In each group, the cdr of nodes are substituted by the first one
462 typedef std::list< std::list< int > > TListOfListOfElementsID;
464 void FindEqualElements(TIDSortedElemSet & theElements,
465 TListOfListOfElementsID & theGroupsOfElementsID);
466 // Return list of group of elements build on the same nodes.
467 // Search among theElements or in the whole mesh if theElements is empty.
469 void MergeElements(TListOfListOfElementsID & theGroupsOfElementsID);
470 // In each group remove all but first of elements.
472 void MergeEqualElements();
473 // Remove all but one of elements built on the same nodes.
474 // Return nb of successfully merged groups.
476 int SimplifyFace (const std::vector<const SMDS_MeshNode *>& faceNodes,
477 std::vector<const SMDS_MeshNode *>& poly_nodes,
478 std::vector<int>& quantities) const;
479 // Split face, defined by <faceNodes>, into several faces by repeating nodes.
480 // Is used by MergeNodes()
482 static bool CheckFreeBorderNodes(const SMDS_MeshNode* theNode1,
483 const SMDS_MeshNode* theNode2,
484 const SMDS_MeshNode* theNode3 = 0);
485 // Return true if the three nodes are on a free border
487 static bool FindFreeBorder (const SMDS_MeshNode* theFirstNode,
488 const SMDS_MeshNode* theSecondNode,
489 const SMDS_MeshNode* theLastNode,
490 std::list< const SMDS_MeshNode* > & theNodes,
491 std::list< const SMDS_MeshElement* >& theFaces);
492 // Return nodes and faces of a free border if found
496 // for SewFreeBorder()
497 SEW_BORDER1_NOT_FOUND,
498 SEW_BORDER2_NOT_FOUND,
499 SEW_BOTH_BORDERS_NOT_FOUND,
501 SEW_VOLUMES_TO_SPLIT,
502 // for SewSideElements()
503 SEW_DIFF_NB_OF_ELEMENTS,
504 SEW_TOPO_DIFF_SETS_OF_ELEMENTS,
511 Sew_Error SewFreeBorder (const SMDS_MeshNode* theBorderFirstNode,
512 const SMDS_MeshNode* theBorderSecondNode,
513 const SMDS_MeshNode* theBorderLastNode,
514 const SMDS_MeshNode* theSide2FirstNode,
515 const SMDS_MeshNode* theSide2SecondNode,
516 const SMDS_MeshNode* theSide2ThirdNode = 0,
517 const bool theSide2IsFreeBorder = true,
518 const bool toCreatePolygons = false,
519 const bool toCreatePolyedrs = false);
520 // Sew the free border to the side2 by replacing nodes in
521 // elements on the free border with nodes of the elements
522 // of the side 2. If nb of links in the free border and
523 // between theSide2FirstNode and theSide2LastNode are different,
524 // additional nodes are inserted on a link provided that no
525 // volume elements share the splitted link.
526 // The side 2 is a free border if theSide2IsFreeBorder == true.
527 // Sewing is peformed between the given first, second and last
528 // nodes on the sides.
529 // theBorderFirstNode is merged with theSide2FirstNode.
530 // if (!theSide2IsFreeBorder) then theSide2SecondNode gives
531 // the last node on the side 2, which will be merged with
532 // theBorderLastNode.
533 // if (theSide2IsFreeBorder) then theSide2SecondNode will
534 // be merged with theBorderSecondNode.
535 // if (theSide2IsFreeBorder && theSide2ThirdNode == 0) then
536 // the 2 free borders are sewn link by link and no additional
537 // nodes are inserted.
538 // Return false, if sewing failed.
540 Sew_Error SewSideElements (TIDSortedElemSet& theSide1,
541 TIDSortedElemSet& theSide2,
542 const SMDS_MeshNode* theFirstNode1ToMerge,
543 const SMDS_MeshNode* theFirstNode2ToMerge,
544 const SMDS_MeshNode* theSecondNode1ToMerge,
545 const SMDS_MeshNode* theSecondNode2ToMerge);
546 // Sew two sides of a mesh. Nodes belonging to theSide1 are
547 // merged with nodes of elements of theSide2.
548 // Number of elements in theSide1 and in theSide2 must be
549 // equal and they should have similar node connectivity.
550 // The nodes to merge should belong to side s borders and
551 // the first node should be linked to the second.
553 void InsertNodesIntoLink(const SMDS_MeshElement* theFace,
554 const SMDS_MeshNode* theBetweenNode1,
555 const SMDS_MeshNode* theBetweenNode2,
556 std::list<const SMDS_MeshNode*>& theNodesToInsert,
557 const bool toCreatePoly = false);
558 // insert theNodesToInsert into theFace between theBetweenNode1 and theBetweenNode2.
559 // If toCreatePoly is true, replace theFace by polygon, else split theFace.
561 void UpdateVolumes (const SMDS_MeshNode* theBetweenNode1,
562 const SMDS_MeshNode* theBetweenNode2,
563 std::list<const SMDS_MeshNode*>& theNodesToInsert);
564 // insert theNodesToInsert into all volumes, containing link
565 // theBetweenNode1 - theBetweenNode2, between theBetweenNode1 and theBetweenNode2.
567 void ConvertToQuadratic(const bool theForce3d, const bool theToBiQuad);
568 void ConvertToQuadratic(const bool theForce3d,
569 TIDSortedElemSet& theElements, const bool theToBiQuad);
570 // Converts all mesh to quadratic or bi-quadratic one, deletes old elements,
571 // replacing them with quadratic or bi-quadratic ones with the same id.
572 // If theForce3d = 1; this results in the medium node lying at the
573 // middle of the line segments connecting start and end node of a mesh element.
574 // If theForce3d = 0; this results in the medium node lying at the
575 // geometrical edge from which the mesh element is built.
577 bool ConvertFromQuadratic();
578 void ConvertFromQuadratic(TIDSortedElemSet& theElements);
579 // Converts all mesh from quadratic to ordinary ones, deletes old quadratic elements, replacing
580 // them with ordinary mesh elements with the same id.
581 // Returns true in case of success, false otherwise.
583 static void AddToSameGroups (const SMDS_MeshElement* elemToAdd,
584 const SMDS_MeshElement* elemInGroups,
585 SMESHDS_Mesh * aMesh);
586 // Add elemToAdd to the all groups the elemInGroups belongs to
588 static void RemoveElemFromGroups (const SMDS_MeshElement* element,
589 SMESHDS_Mesh * aMesh);
590 // remove element from the all groups
592 static void ReplaceElemInGroups (const SMDS_MeshElement* elemToRm,
593 const SMDS_MeshElement* elemToAdd,
594 SMESHDS_Mesh * aMesh);
595 // replace elemToRm by elemToAdd in the all groups
597 static void ReplaceElemInGroups (const SMDS_MeshElement* elemToRm,
598 const std::vector<const SMDS_MeshElement*>& elemToAdd,
599 SMESHDS_Mesh * aMesh);
600 // replace elemToRm by elemToAdd in the all groups
603 * \brief Return nodes linked to the given one in elements of the type
605 static void GetLinkedNodes( const SMDS_MeshNode* node,
606 TIDSortedElemSet & linkedNodes,
607 SMDSAbs_ElementType type = SMDSAbs_All );
610 * \brief Find corresponding nodes in two sets of faces
611 * \param theSide1 - first face set
612 * \param theSide2 - second first face
613 * \param theFirstNode1 - a boundary node of set 1
614 * \param theFirstNode2 - a node of set 2 corresponding to theFirstNode1
615 * \param theSecondNode1 - a boundary node of set 1 linked with theFirstNode1
616 * \param theSecondNode2 - a node of set 2 corresponding to theSecondNode1
617 * \param nReplaceMap - output map of corresponding nodes
618 * \return Sew_Error - is a success or not
620 static Sew_Error FindMatchingNodes(std::set<const SMDS_MeshElement*>& theSide1,
621 std::set<const SMDS_MeshElement*>& theSide2,
622 const SMDS_MeshNode* theFirstNode1,
623 const SMDS_MeshNode* theFirstNode2,
624 const SMDS_MeshNode* theSecondNode1,
625 const SMDS_MeshNode* theSecondNode2,
626 TNodeNodeMap & theNodeReplaceMap);
629 * \brief Returns true if given node is medium
630 * \param n - node to check
631 * \param typeToCheck - type of elements containing the node to ask about node status
632 * \return bool - check result
634 static bool IsMedium(const SMDS_MeshNode* node,
635 const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
637 int FindShape (const SMDS_MeshElement * theElem);
638 // Return an index of the shape theElem is on
639 // or zero if a shape not found
641 void DoubleElements( const TIDSortedElemSet& theElements );
643 bool DoubleNodes( const std::list< int >& theListOfNodes,
644 const std::list< int >& theListOfModifiedElems );
646 bool DoubleNodes( const TIDSortedElemSet& theElems,
647 const TIDSortedElemSet& theNodesNot,
648 const TIDSortedElemSet& theAffectedElems );
650 bool AffectedElemGroupsInRegion( const TIDSortedElemSet& theElems,
651 const TIDSortedElemSet& theNodesNot,
652 const TopoDS_Shape& theShape,
653 TIDSortedElemSet& theAffectedElems);
655 bool DoubleNodesInRegion( const TIDSortedElemSet& theElems,
656 const TIDSortedElemSet& theNodesNot,
657 const TopoDS_Shape& theShape );
659 double OrientedAngle(const gp_Pnt& p0, const gp_Pnt& p1, const gp_Pnt& g1, const gp_Pnt& g2);
661 bool DoubleNodesOnGroupBoundaries( const std::vector<TIDSortedElemSet>& theElems,
662 bool createJointElems,
663 bool onAllBoundaries);
665 bool CreateFlatElementsOnFacesGroups( const std::vector<TIDSortedElemSet>& theElems );
667 void CreateHoleSkin(double radius,
668 const TopoDS_Shape& theShape,
669 SMESH_NodeSearcher* theNodeSearcher,
670 const char* groupName,
671 std::vector<double>& nodesCoords,
672 std::vector<std::vector<int> >& listOfListOfNodes);
675 * \brief Generated skin mesh (containing 2D cells) from 3D mesh
676 * The created 2D mesh elements based on nodes of free faces of boundary volumes
677 * \return TRUE if operation has been completed successfully, FALSE otherwise
679 bool Make2DMeshFrom3D();
681 enum Bnd_Dimension { BND_2DFROM3D, BND_1DFROM3D, BND_1DFROM2D };
683 int MakeBoundaryMesh(const TIDSortedElemSet& elements,
684 Bnd_Dimension dimension,
685 SMESH_Group* group = 0,
686 SMESH_Mesh* targetMesh = 0,
687 bool toCopyElements = false,
688 bool toCopyExistingBondary = false,
689 bool toAddExistingBondary = false,
690 bool aroundElements = false);
695 * \brief Convert elements contained in a submesh to quadratic
696 * \return int - nb of checked elements
698 int convertElemToQuadratic(SMESHDS_SubMesh * theSm,
699 SMESH_MesherHelper& theHelper,
700 const bool theForce3d);
703 * \brief Convert quadratic elements to linear ones and remove quadratic nodes
704 * \return nb of checked elements
706 int removeQuadElem( SMESHDS_SubMesh * theSm,
707 SMDS_ElemIteratorPtr theItr,
708 const int theShapeID);
710 * \brief Create groups of elements made during transformation
711 * \param nodeGens - nodes making corresponding myLastCreatedNodes
712 * \param elemGens - elements making corresponding myLastCreatedElems
713 * \param postfix - to append to names of new groups
714 * \param targetMesh - mesh to create groups in
715 * \param topPresent - is there "top" elements that are created by sweeping
717 PGroupIDs generateGroups(const SMESH_SequenceOfElemPtr& nodeGens,
718 const SMESH_SequenceOfElemPtr& elemGens,
719 const std::string& postfix,
720 SMESH_Mesh* targetMesh=0,
721 const bool topPresent=true);
723 * \brief Create elements by sweeping an element
724 * \param elem - element to sweep
725 * \param newNodesItVec - nodes generated from each node of the element
726 * \param newElems - generated elements
727 * \param nbSteps - number of sweeping steps
728 * \param srcElements - to append elem for each generated element
730 void sweepElement(const SMDS_MeshElement* elem,
731 const std::vector<TNodeOfNodeListMapItr> & newNodesItVec,
732 std::list<const SMDS_MeshElement*>& newElems,
733 const size_t nbSteps,
734 SMESH_SequenceOfElemPtr& srcElements);
737 * \brief Create 1D and 2D elements around swept elements
738 * \param mapNewNodes - source nodes and ones generated from them
739 * \param newElemsMap - source elements and ones generated from them
740 * \param elemNewNodesMap - nodes generated from each node of each element
741 * \param elemSet - all swept elements
742 * \param nbSteps - number of sweeping steps
743 * \param srcElements - to append elem for each generated element
745 void makeWalls (TNodeOfNodeListMap & mapNewNodes,
746 TTElemOfElemListMap & newElemsMap,
747 TElemOfVecOfNnlmiMap & elemNewNodesMap,
748 TIDSortedElemSet& elemSet,
750 SMESH_SequenceOfElemPtr& srcElements);
752 struct SMESH_MeshEditor_PathPoint
756 double myAngle, myPrm;
758 SMESH_MeshEditor_PathPoint(): myPnt(99., 99., 99.), myTgt(1.,0.,0.), myAngle(0), myPrm(0) {}
759 void SetPnt (const gp_Pnt& aP3D) { myPnt =aP3D; }
760 void SetTangent (const gp_Dir& aTgt) { myTgt =aTgt; }
761 void SetAngle (const double& aBeta) { myAngle=aBeta; }
762 void SetParameter(const double& aPrm) { myPrm =aPrm; }
763 const gp_Pnt& Pnt ()const { return myPnt; }
764 const gp_Dir& Tangent ()const { return myTgt; }
765 double Angle ()const { return myAngle; }
766 double Parameter ()const { return myPrm; }
768 Extrusion_Error MakeEdgePathPoints(std::list<double>& aPrms,
769 const TopoDS_Edge& aTrackEdge,
771 std::list<SMESH_MeshEditor_PathPoint>& aLPP);
772 Extrusion_Error MakeExtrElements(TIDSortedElemSet theElements[2],
773 std::list<SMESH_MeshEditor_PathPoint>& theFullList,
774 const bool theHasAngles,
775 std::list<double>& theAngles,
776 const bool theLinearVariation,
777 const bool theHasRefPoint,
778 const gp_Pnt& theRefPoint,
779 const bool theMakeGroups);
780 void LinearAngleVariation(const int NbSteps,
781 list<double>& theAngles);
783 bool doubleNodes( SMESHDS_Mesh* theMeshDS,
784 const TIDSortedElemSet& theElems,
785 const TIDSortedElemSet& theNodesNot,
786 TNodeNodeMap& theNodeNodeMap,
787 const bool theIsDoubleElem );
789 void copyPosition( const SMDS_MeshNode* from,
790 const SMDS_MeshNode* to );
796 // Nodes and elements created during last operation
797 SMESH_SequenceOfElemPtr myLastCreatedNodes, myLastCreatedElems;
799 // Description of error/warning occured during last operation
800 SMESH_ComputeErrorPtr myError;