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;
51 class SMESHDS_SubMesh;
52 class SMESH_ElementSearcher;
55 class SMESH_MesherHelper;
56 class SMESH_NodeSearcher;
65 // ============================================================
67 * \brief Editor of a mesh
69 // ============================================================
71 class SMESH_EXPORT SMESH_MeshEditor
75 SMESH_MeshEditor( SMESH_Mesh* theMesh );
77 SMESH_Mesh * GetMesh() { return myMesh; }
78 SMESHDS_Mesh * GetMeshDS();
80 const SMESH_SequenceOfElemPtr& GetLastCreatedNodes() const { return myLastCreatedNodes; }
81 const SMESH_SequenceOfElemPtr& GetLastCreatedElems() const { return myLastCreatedElems; }
82 void ClearLastCreated();
83 SMESH_ComputeErrorPtr & GetError() { return myError; }
85 // --------------------------------------------------------------------------------
86 struct ElemFeatures //!< Features of element to create
88 SMDSAbs_ElementType myType;
89 bool myIsPoly, myIsQuad;
91 double myBallDiameter;
92 std::vector<int> myPolyhedQuantities;
93 std::vector<const SMDS_MeshNode*> myNodes; // not managed by ElemFeatures
95 SMESH_EXPORT ElemFeatures( SMDSAbs_ElementType type=SMDSAbs_All, bool isPoly=false, bool isQuad=false )
96 :myType( type ), myIsPoly(isPoly), myIsQuad(isQuad), myID(-1), myBallDiameter(0) {}
98 SMESH_EXPORT ElemFeatures& Init( SMDSAbs_ElementType type, bool isPoly=false, bool isQuad=false )
99 { myType = type; myIsPoly = isPoly; myIsQuad = isQuad; return *this; }
101 SMESH_EXPORT ElemFeatures& Init( const SMDS_MeshElement* elem, bool basicOnly=true );
103 SMESH_EXPORT ElemFeatures& Init( double diameter )
104 { myType = SMDSAbs_Ball; myBallDiameter = diameter; return *this; }
106 SMESH_EXPORT ElemFeatures& Init( std::vector<int>& quanities, bool isQuad=false )
107 { myType = SMDSAbs_Volume; myIsPoly = 1; myIsQuad = isQuad;
108 myPolyhedQuantities.swap( quanities ); return *this; }
110 SMESH_EXPORT ElemFeatures& Init( const std::vector<int>& quanities, bool isQuad=false )
111 { myType = SMDSAbs_Volume; myIsPoly = 1; myIsQuad = isQuad;
112 myPolyhedQuantities = quanities; return *this; }
114 SMESH_EXPORT ElemFeatures& SetPoly(bool isPoly) { myIsPoly = isPoly; return *this; }
115 SMESH_EXPORT ElemFeatures& SetQuad(bool isQuad) { myIsQuad = isQuad; return *this; }
116 SMESH_EXPORT ElemFeatures& SetID (int ID) { myID = ID; return *this; }
122 SMDS_MeshElement* AddElement(const std::vector<const SMDS_MeshNode*> & nodes,
123 const ElemFeatures& features);
127 SMDS_MeshElement* AddElement(const std::vector<int> & nodeIDs,
128 const ElemFeatures& features);
130 int Remove (const std::list< int >& theElemIDs, const bool isNodes);
131 // Remove a node or an element.
132 // Modify a compute state of sub-meshes which become empty
134 void Create0DElementsOnAllNodes( const TIDSortedElemSet& elements,
135 TIDSortedElemSet& all0DElems,
136 const bool duplicateElements);
137 // Create 0D elements on all nodes of the given. \a all0DElems returns
138 // all 0D elements found or created on nodes of \a elements
140 bool InverseDiag (const SMDS_MeshElement * theTria1,
141 const SMDS_MeshElement * theTria2 );
142 // Replace two neighbour triangles with ones built on the same 4 nodes
143 // but having other common link.
144 // Return False if args are improper
146 bool InverseDiag (const SMDS_MeshNode * theNode1,
147 const SMDS_MeshNode * theNode2 );
148 // Replace two neighbour triangles sharing theNode1-theNode2 link
149 // with ones built on the same 4 nodes but having other common link.
150 // Return false if proper faces not found
152 bool DeleteDiag (const SMDS_MeshNode * theNode1,
153 const SMDS_MeshNode * theNode2 );
154 // Replace two neighbour triangles sharing theNode1-theNode2 link
155 // with a quadrangle built on the same 4 nodes.
156 // Return false if proper faces not found
158 bool Reorient (const SMDS_MeshElement * theElement);
159 // Reverse theElement orientation
161 int Reorient2D (TIDSortedElemSet & theFaces,
162 const gp_Dir& theDirection,
163 const SMDS_MeshElement * theFace);
164 // Reverse theFaces whose orientation to be same as that of theFace
165 // oriented according to theDirection. Return nb of reoriented faces
167 int Reorient2DBy3D (TIDSortedElemSet & theFaces,
168 TIDSortedElemSet & theVolumes,
169 const bool theOutsideNormal);
170 // Reorient faces basing on orientation of adjacent volumes.
171 // Return nb of reoriented faces
174 * \brief Fuse neighbour triangles into quadrangles.
175 * \param theElems - The triangles to be fused.
176 * \param theCriterion - Is used to choose a neighbour to fuse with.
177 * \param theMaxAngle - Is a max angle between element normals at which fusion
178 * is still performed; theMaxAngle is mesured in radians.
179 * \return bool - Success or not.
181 bool TriToQuad (TIDSortedElemSet & theElems,
182 SMESH::Controls::NumericalFunctorPtr theCriterion,
183 const double theMaxAngle);
185 * \brief Split quadrangles into triangles.
186 * \param theElems - The faces to be splitted.
187 * \param theCriterion - Is used to choose a diagonal for splitting.
188 * \return bool - Success or not.
190 bool QuadToTri (TIDSortedElemSet & theElems,
191 SMESH::Controls::NumericalFunctorPtr theCriterion);
193 * \brief Split quadrangles into triangles.
194 * \param theElems - The faces to be splitted.
195 * \param the13Diag - Is used to choose a diagonal for splitting.
196 * \return bool - Success or not.
198 bool QuadToTri (TIDSortedElemSet & theElems,
199 const bool the13Diag);
201 * \brief Split each of given quadrangles into 4 triangles.
202 * \param theElems - The faces to be splitted. If empty all faces are split.
204 void QuadTo4Tri (TIDSortedElemSet & theElems);
207 * \brief Find better diagonal for splitting.
208 * \param theQuad - The face to find better splitting of.
209 * \param theCriterion - Is used to choose a diagonal for splitting.
210 * \return int - 1 for 1-3 diagonal, 2 for 2-4, -1 - for errors.
212 int BestSplit (const SMDS_MeshElement* theQuad,
213 SMESH::Controls::NumericalFunctorPtr theCriterion);
216 typedef std::map < const SMDS_MeshElement*, int, TIDCompare > TFacetOfElem;
218 //!<2nd arg of SplitVolumes()
219 enum SplitVolumToTetraFlags { HEXA_TO_5 = 1, // split into tetrahedra
222 HEXA_TO_2_PRISMS, // split into prisms
225 * \brief Split volumic elements into tetrahedra or prisms.
226 * If facet ID < 0, element is split into tetrahedra,
227 * else a hexahedron is split into prisms so that the given facet is
228 * split into triangles
230 void SplitVolumes (const TFacetOfElem & theElems, const int theMethodFlags);
233 * \brief For hexahedra that will be split into prisms, finds facets to
234 * split into triangles
235 * \param [in,out] theHexas - the hexahedra
236 * \param [in] theFacetNormal - facet normal
237 * \param [out] theFacets - the hexahedra and found facet IDs
239 void GetHexaFacetsToSplit( TIDSortedElemSet& theHexas,
240 const gp_Ax1& theFacetNormal,
241 TFacetOfElem & theFacets);
244 * \brief Split bi-quadratic elements into linear ones without creation of additional nodes
245 * - bi-quadratic triangle will be split into 3 linear quadrangles;
246 * - bi-quadratic quadrangle will be split into 4 linear quadrangles;
247 * - tri-quadratic hexahedron will be split into 8 linear hexahedra;
248 * Quadratic elements of lower dimension adjacent to the split bi-quadratic element
249 * will be split in order to keep the mesh conformal.
250 * \param elems - elements to split
252 void SplitBiQuadraticIntoLinear(TIDSortedElemSet& theElems);
254 enum SmoothMethod { LAPLACIAN = 0, CENTROIDAL };
256 void Smooth (TIDSortedElemSet & theElements,
257 std::set<const SMDS_MeshNode*> & theFixedNodes,
258 const SmoothMethod theSmoothMethod,
259 const int theNbIterations,
260 double theTgtAspectRatio = 1.0,
261 const bool the2D = true);
262 // Smooth theElements using theSmoothMethod during theNbIterations
263 // or until a worst element has aspect ratio <= theTgtAspectRatio.
264 // Aspect Ratio varies in range [1.0, inf].
265 // If theElements is empty, the whole mesh is smoothed.
266 // theFixedNodes contains additionally fixed nodes. Nodes built
267 // on edges and boundary nodes are always fixed.
268 // If the2D, smoothing is performed using UV parameters of nodes
269 // on geometrical faces
271 typedef TIDTypeCompare TElemSort;
272 typedef std::map < const SMDS_MeshElement*,
273 std::list<const SMDS_MeshElement*>, TElemSort > TTElemOfElemListMap;
274 typedef std::map<const SMDS_MeshNode*, std::list<const SMDS_MeshNode*> > TNodeOfNodeListMap;
275 typedef TNodeOfNodeListMap::iterator TNodeOfNodeListMapItr;
276 typedef std::vector<TNodeOfNodeListMapItr> TVecOfNnlmiMap;
277 typedef std::map<const SMDS_MeshElement*, TVecOfNnlmiMap, TElemSort > TElemOfVecOfNnlmiMap;
278 typedef std::auto_ptr< std::list<int> > PGroupIDs;
280 PGroupIDs RotationSweep (TIDSortedElemSet theElements[2],
281 const gp_Ax1& theAxis,
282 const double theAngle,
283 const int theNbSteps,
284 const double theToler,
285 const bool theMakeGroups,
286 const bool theMakeWalls=true);
287 // Generate new elements by rotation of theElements around theAxis
288 // by theAngle by theNbSteps
291 * Flags of extrusion.
292 * BOUNDARY: create or not boundary for result of extrusion
293 * SEW: try to use existing nodes or create new nodes in any case
294 * GROUPS: to create groups
295 * BY_AVG_NORMAL: step size is measured along average normal to elements,
296 * else step size is measured along average normal of any element
297 * USE_INPUT_ELEMS_ONLY: to use only input elements to compute extrusion direction
298 * for ExtrusionByNormal()
299 * SCALE_LINEAR_VARIATION: to make linear variation of scale factors
301 enum ExtrusionFlags {
302 EXTRUSION_FLAG_BOUNDARY = 0x01,
303 EXTRUSION_FLAG_SEW = 0x02,
304 EXTRUSION_FLAG_GROUPS = 0x04,
305 EXTRUSION_FLAG_BY_AVG_NORMAL = 0x08,
306 EXTRUSION_FLAG_USE_INPUT_ELEMS_ONLY = 0x10,
307 EXTRUSION_FLAG_SCALE_LINEAR_VARIATION = 0x20
311 * Generator of nodes for extrusion functionality
313 class SMESH_EXPORT ExtrusParam
315 gp_Dir myDir; // direction of extrusion
316 Handle(TColStd_HSequenceOfReal) mySteps; // magnitudes for each step
317 std::vector<double> myScales, myMediumScales;// scale factors
318 gp_XYZ myBaseP; // scaling center
319 SMESH_SequenceOfNode myNodes; // nodes for using in sewing
320 int myFlags; // see ExtrusionFlags
321 double myTolerance; // tolerance for sewing nodes
322 const TIDSortedElemSet* myElemsToUse; // elements to use for extrusion by normal
324 int (ExtrusParam::*myMakeNodesFun)(SMESHDS_Mesh* mesh,
325 const SMDS_MeshNode* srcNode,
326 std::list<const SMDS_MeshNode*> & newNodes,
327 const bool makeMediumNodes);
330 ExtrusParam( const gp_Vec& theStep,
331 const int theNbSteps,
332 const std::list<double>& theScales,
333 const gp_XYZ* theBaseP,
334 const int theFlags = 0,
335 const double theTolerance = 1e-6);
336 ExtrusParam( const gp_Dir& theDir,
337 Handle(TColStd_HSequenceOfReal) theSteps,
338 const int theFlags = 0,
339 const double theTolerance = 1e-6);
340 ExtrusParam( const double theStep,
341 const int theNbSteps,
343 const int theDim); // for extrusion by normal
345 SMESH_SequenceOfNode& ChangeNodes() { return myNodes; }
346 int& Flags() { return myFlags; }
347 bool ToMakeBoundary() const { return myFlags & EXTRUSION_FLAG_BOUNDARY; }
348 bool ToMakeGroups() const { return myFlags & EXTRUSION_FLAG_GROUPS; }
349 bool ToUseInpElemsOnly() const { return myFlags & EXTRUSION_FLAG_USE_INPUT_ELEMS_ONLY; }
350 bool IsLinearVariation() const { return myFlags & EXTRUSION_FLAG_SCALE_LINEAR_VARIATION; }
351 int NbSteps() const { return mySteps->Length(); }
353 // stores elements to use for extrusion by normal, depending on
354 // state of EXTRUSION_FLAG_USE_INPUT_ELEMS_ONLY flag;
355 // define myBaseP for scaling
356 void SetElementsToUse( const TIDSortedElemSet& elems, const TIDSortedElemSet& nodes );
358 // creates nodes and returns number of nodes added in \a newNodes
359 int MakeNodes( SMESHDS_Mesh* mesh,
360 const SMDS_MeshNode* srcNode,
361 std::list<const SMDS_MeshNode*> & newNodes,
362 const bool makeMediumNodes)
364 return (this->*myMakeNodesFun)( mesh, srcNode, newNodes, makeMediumNodes );
368 int makeNodesByDir( SMESHDS_Mesh* mesh,
369 const SMDS_MeshNode* srcNode,
370 std::list<const SMDS_MeshNode*> & newNodes,
371 const bool makeMediumNodes);
372 int makeNodesByDirAndSew( SMESHDS_Mesh* mesh,
373 const SMDS_MeshNode* srcNode,
374 std::list<const SMDS_MeshNode*> & newNodes,
375 const bool makeMediumNodes);
376 int makeNodesByNormal2D( SMESHDS_Mesh* mesh,
377 const SMDS_MeshNode* srcNode,
378 std::list<const SMDS_MeshNode*> & newNodes,
379 const bool makeMediumNodes);
380 int makeNodesByNormal1D( SMESHDS_Mesh* mesh,
381 const SMDS_MeshNode* srcNode,
382 std::list<const SMDS_MeshNode*> & newNodes,
383 const bool makeMediumNodes);
385 void beginStepIter( bool withMediumNodes );
388 std::vector< double > myCurSteps;
389 bool myWithMediumNodes;
394 * Generate new elements by extrusion of theElements
395 * It is a method used in .idl file. All functionality
396 * is implemented in the next method (see below) which
397 * is used in the current method.
398 * @param theElems - list of elements for extrusion
399 * @param newElemsMap returns history of extrusion
400 * @param theFlags set flags for performing extrusion (see description
401 * of enum ExtrusionFlags for additional information)
402 * @param theTolerance - uses for comparing locations of nodes if flag
403 * EXTRUSION_FLAG_SEW is set
405 PGroupIDs ExtrusionSweep (TIDSortedElemSet theElems[2],
406 const gp_Vec& theStep,
407 const int theNbSteps,
408 TTElemOfElemListMap& newElemsMap,
410 const double theTolerance = 1.e-6);
413 * Generate new elements by extrusion of theElements
414 * @param theElems - list of elements for extrusion
415 * @param newElemsMap returns history of extrusion
416 * @param theFlags set flags for performing extrusion (see description
417 * of enum ExtrusionFlags for additional information)
418 * @param theTolerance - uses for comparing locations of nodes if flag
419 * EXTRUSION_FLAG_SEW is set
420 * @param theParams - special structure for manage of extrusion
422 PGroupIDs ExtrusionSweep (TIDSortedElemSet theElems[2],
423 ExtrusParam& theParams,
424 TTElemOfElemListMap& newElemsMap);
427 // Generate new elements by extrusion of theElements
428 // by theStep by theNbSteps
430 enum Extrusion_Error {
435 EXTR_BAD_STARTING_NODE,
436 EXTR_BAD_ANGLES_NUMBER,
437 EXTR_CANT_GET_TANGENT
440 Extrusion_Error ExtrusionAlongTrack (TIDSortedElemSet theElements[2],
441 SMESH_subMesh* theTrackPattern,
442 const SMDS_MeshNode* theNodeStart,
443 const bool theHasAngles,
444 std::list<double>& theAngles,
445 const bool theLinearVariation,
446 const bool theHasRefPoint,
447 const gp_Pnt& theRefPoint,
448 const bool theMakeGroups);
449 Extrusion_Error ExtrusionAlongTrack (TIDSortedElemSet theElements[2],
450 SMESH_Mesh* theTrackPattern,
451 const SMDS_MeshNode* theNodeStart,
452 const bool theHasAngles,
453 std::list<double>& theAngles,
454 const bool theLinearVariation,
455 const bool theHasRefPoint,
456 const gp_Pnt& theRefPoint,
457 const bool theMakeGroups);
458 // Generate new elements by extrusion of theElements along path given by theTrackPattern,
459 // theHasAngles are the rotation angles, base point can be given by theRefPoint
461 PGroupIDs Transform (TIDSortedElemSet & theElements,
462 const gp_Trsf& theTrsf,
464 const bool theMakeGroups,
465 SMESH_Mesh* theTargetMesh=0);
466 // Move or copy theElements applying theTrsf to their nodes
468 typedef std::list< std::list< const SMDS_MeshNode* > > TListOfListOfNodes;
470 void FindCoincidentNodes (TIDSortedNodeSet & theNodes,
471 const double theTolerance,
472 TListOfListOfNodes & theGroupsOfNodes,
473 bool theSeparateCornersAndMedium);
474 // Return list of group of nodes close to each other within theTolerance.
475 // Search among theNodes or in the whole mesh if theNodes is empty.
477 void MergeNodes (TListOfListOfNodes & theNodeGroups,
478 const bool theAvoidMakingHoles = false);
479 // In each group, the cdr of nodes are substituted by the first one
482 typedef std::list< std::list< int > > TListOfListOfElementsID;
484 void FindEqualElements(TIDSortedElemSet & theElements,
485 TListOfListOfElementsID & theGroupsOfElementsID);
486 // Return list of group of elements build on the same nodes.
487 // Search among theElements or in the whole mesh if theElements is empty.
489 void MergeElements(TListOfListOfElementsID & theGroupsOfElementsID);
490 // In each group remove all but first of elements.
492 void MergeEqualElements();
493 // Remove all but one of elements built on the same nodes.
494 // Return nb of successfully merged groups.
496 int SimplifyFace (const std::vector<const SMDS_MeshNode *>& faceNodes,
497 std::vector<const SMDS_MeshNode *>& poly_nodes,
498 std::vector<int>& quantities) const;
499 // Split face, defined by <faceNodes>, into several faces by repeating nodes.
500 // Is used by MergeNodes()
502 static bool CheckFreeBorderNodes(const SMDS_MeshNode* theNode1,
503 const SMDS_MeshNode* theNode2,
504 const SMDS_MeshNode* theNode3 = 0);
505 // Return true if the three nodes are on a free border
507 static bool FindFreeBorder (const SMDS_MeshNode* theFirstNode,
508 const SMDS_MeshNode* theSecondNode,
509 const SMDS_MeshNode* theLastNode,
510 std::list< const SMDS_MeshNode* > & theNodes,
511 std::list< const SMDS_MeshElement* >& theFaces);
512 // Return nodes and faces of a free border if found
516 // for SewFreeBorder()
517 SEW_BORDER1_NOT_FOUND,
518 SEW_BORDER2_NOT_FOUND,
519 SEW_BOTH_BORDERS_NOT_FOUND,
521 SEW_VOLUMES_TO_SPLIT,
522 // for SewSideElements()
523 SEW_DIFF_NB_OF_ELEMENTS,
524 SEW_TOPO_DIFF_SETS_OF_ELEMENTS,
531 Sew_Error SewFreeBorder (const SMDS_MeshNode* theBorderFirstNode,
532 const SMDS_MeshNode* theBorderSecondNode,
533 const SMDS_MeshNode* theBorderLastNode,
534 const SMDS_MeshNode* theSide2FirstNode,
535 const SMDS_MeshNode* theSide2SecondNode,
536 const SMDS_MeshNode* theSide2ThirdNode = 0,
537 const bool theSide2IsFreeBorder = true,
538 const bool toCreatePolygons = false,
539 const bool toCreatePolyedrs = false);
540 // Sew the free border to the side2 by replacing nodes in
541 // elements on the free border with nodes of the elements
542 // of the side 2. If nb of links in the free border and
543 // between theSide2FirstNode and theSide2LastNode are different,
544 // additional nodes are inserted on a link provided that no
545 // volume elements share the splitted link.
546 // The side 2 is a free border if theSide2IsFreeBorder == true.
547 // Sewing is performed between the given first, second and last
548 // nodes on the sides.
549 // theBorderFirstNode is merged with theSide2FirstNode.
550 // if (!theSide2IsFreeBorder) then theSide2SecondNode gives
551 // the last node on the side 2, which will be merged with
552 // theBorderLastNode.
553 // if (theSide2IsFreeBorder) then theSide2SecondNode will
554 // be merged with theBorderSecondNode.
555 // if (theSide2IsFreeBorder && theSide2ThirdNode == 0) then
556 // the 2 free borders are sewn link by link and no additional
557 // nodes are inserted.
558 // Return false, if sewing failed.
560 Sew_Error SewSideElements (TIDSortedElemSet& theSide1,
561 TIDSortedElemSet& theSide2,
562 const SMDS_MeshNode* theFirstNode1ToMerge,
563 const SMDS_MeshNode* theFirstNode2ToMerge,
564 const SMDS_MeshNode* theSecondNode1ToMerge,
565 const SMDS_MeshNode* theSecondNode2ToMerge);
566 // Sew two sides of a mesh. Nodes belonging to theSide1 are
567 // merged with nodes of elements of theSide2.
568 // Number of elements in theSide1 and in theSide2 must be
569 // equal and they should have similar node connectivity.
570 // The nodes to merge should belong to side s borders and
571 // the first node should be linked to the second.
573 void InsertNodesIntoLink(const SMDS_MeshElement* theFace,
574 const SMDS_MeshNode* theBetweenNode1,
575 const SMDS_MeshNode* theBetweenNode2,
576 std::list<const SMDS_MeshNode*>& theNodesToInsert,
577 const bool toCreatePoly = false);
578 // insert theNodesToInsert into theFace between theBetweenNode1 and theBetweenNode2.
579 // If toCreatePoly is true, replace theFace by polygon, else split theFace.
581 void UpdateVolumes (const SMDS_MeshNode* theBetweenNode1,
582 const SMDS_MeshNode* theBetweenNode2,
583 std::list<const SMDS_MeshNode*>& theNodesToInsert);
584 // insert theNodesToInsert into all volumes, containing link
585 // theBetweenNode1 - theBetweenNode2, between theBetweenNode1 and theBetweenNode2.
587 void ConvertToQuadratic(const bool theForce3d, const bool theToBiQuad);
588 void ConvertToQuadratic(const bool theForce3d,
589 TIDSortedElemSet& theElements, const bool theToBiQuad);
590 // Converts all mesh to quadratic or bi-quadratic one, deletes old elements,
591 // replacing them with quadratic or bi-quadratic ones with the same id.
592 // If theForce3d = 1; this results in the medium node lying at the
593 // middle of the line segments connecting start and end node of a mesh element.
594 // If theForce3d = 0; this results in the medium node lying at the
595 // geometrical edge from which the mesh element is built.
597 bool ConvertFromQuadratic();
598 void ConvertFromQuadratic(TIDSortedElemSet& theElements);
599 // Converts all mesh from quadratic to ordinary ones, deletes old quadratic elements, replacing
600 // them with ordinary mesh elements with the same id.
601 // Returns true in case of success, false otherwise.
603 static void AddToSameGroups (const SMDS_MeshElement* elemToAdd,
604 const SMDS_MeshElement* elemInGroups,
605 SMESHDS_Mesh * aMesh);
606 // Add elemToAdd to the all groups the elemInGroups belongs to
608 static void RemoveElemFromGroups (const SMDS_MeshElement* element,
609 SMESHDS_Mesh * aMesh);
610 // remove element from the all groups
612 static void ReplaceElemInGroups (const SMDS_MeshElement* elemToRm,
613 const SMDS_MeshElement* elemToAdd,
614 SMESHDS_Mesh * aMesh);
615 // replace elemToRm by elemToAdd in the all groups
617 static void ReplaceElemInGroups (const SMDS_MeshElement* elemToRm,
618 const std::vector<const SMDS_MeshElement*>& elemToAdd,
619 SMESHDS_Mesh * aMesh);
620 // replace elemToRm by elemToAdd in the all groups
623 * \brief Return nodes linked to the given one in elements of the type
625 static void GetLinkedNodes( const SMDS_MeshNode* node,
626 TIDSortedElemSet & linkedNodes,
627 SMDSAbs_ElementType type = SMDSAbs_All );
630 * \brief Find corresponding nodes in two sets of faces
631 * \param theSide1 - first face set
632 * \param theSide2 - second first face
633 * \param theFirstNode1 - a boundary node of set 1
634 * \param theFirstNode2 - a node of set 2 corresponding to theFirstNode1
635 * \param theSecondNode1 - a boundary node of set 1 linked with theFirstNode1
636 * \param theSecondNode2 - a node of set 2 corresponding to theSecondNode1
637 * \param nReplaceMap - output map of corresponding nodes
638 * \return Sew_Error - is a success or not
640 static Sew_Error FindMatchingNodes(std::set<const SMDS_MeshElement*>& theSide1,
641 std::set<const SMDS_MeshElement*>& theSide2,
642 const SMDS_MeshNode* theFirstNode1,
643 const SMDS_MeshNode* theFirstNode2,
644 const SMDS_MeshNode* theSecondNode1,
645 const SMDS_MeshNode* theSecondNode2,
646 TNodeNodeMap & theNodeReplaceMap);
649 * \brief Returns true if given node is medium
650 * \param n - node to check
651 * \param typeToCheck - type of elements containing the node to ask about node status
652 * \return bool - check result
654 static bool IsMedium(const SMDS_MeshNode* node,
655 const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
657 int FindShape (const SMDS_MeshElement * theElem);
658 // Return an index of the shape theElem is on
659 // or zero if a shape not found
661 void DoubleElements( const TIDSortedElemSet& theElements );
663 bool DoubleNodes( const std::list< int >& theListOfNodes,
664 const std::list< int >& theListOfModifiedElems );
666 bool DoubleNodes( const TIDSortedElemSet& theElems,
667 const TIDSortedElemSet& theNodesNot,
668 const TIDSortedElemSet& theAffectedElems );
670 bool AffectedElemGroupsInRegion( const TIDSortedElemSet& theElems,
671 const TIDSortedElemSet& theNodesNot,
672 const TopoDS_Shape& theShape,
673 TIDSortedElemSet& theAffectedElems);
675 bool DoubleNodesInRegion( const TIDSortedElemSet& theElems,
676 const TIDSortedElemSet& theNodesNot,
677 const TopoDS_Shape& theShape );
679 double OrientedAngle(const gp_Pnt& p0, const gp_Pnt& p1, const gp_Pnt& g1, const gp_Pnt& g2);
681 bool DoubleNodesOnGroupBoundaries( const std::vector<TIDSortedElemSet>& theElems,
682 bool createJointElems,
683 bool onAllBoundaries);
685 bool CreateFlatElementsOnFacesGroups( const std::vector<TIDSortedElemSet>& theElems );
687 void CreateHoleSkin(double radius,
688 const TopoDS_Shape& theShape,
689 SMESH_NodeSearcher* theNodeSearcher,
690 const char* groupName,
691 std::vector<double>& nodesCoords,
692 std::vector<std::vector<int> >& listOfListOfNodes);
695 * \brief Generated skin mesh (containing 2D cells) from 3D mesh
696 * The created 2D mesh elements based on nodes of free faces of boundary volumes
697 * \return TRUE if operation has been completed successfully, FALSE otherwise
699 bool Make2DMeshFrom3D();
701 enum Bnd_Dimension { BND_2DFROM3D, BND_1DFROM3D, BND_1DFROM2D };
703 int MakeBoundaryMesh(const TIDSortedElemSet& elements,
704 Bnd_Dimension dimension,
705 SMESH_Group* group = 0,
706 SMESH_Mesh* targetMesh = 0,
707 bool toCopyElements = false,
708 bool toCopyExistingBondary = false,
709 bool toAddExistingBondary = false,
710 bool aroundElements = false);
713 // structure used in MakePolyLine() to define a cutting plane
716 // 2 points: if myNode2 != 0, then the point is the middle of a face edge defined
717 // by two nodes, else it is at myNode1
718 const SMDS_MeshNode* myNode1[2];
719 const SMDS_MeshNode* myNode2[2];
721 gp_Vec myVector; // vector on the plane; to use a default plane set vector = (0,0,0)
723 // point to return coordinates of a middle of the two points, projected to mesh
724 gp_Pnt myMidProjPoint;
726 typedef std::vector<PolySegment> TListOfPolySegments;
729 * \brief Create a polyline consisting of 1D mesh elements each lying on a 2D element of
730 * the initial mesh. Positions of new nodes are found by cutting the mesh by the
731 * plane passing through pairs of points specified by each PolySegment structure.
732 * If there are several paths connecting a pair of points, the shortest path is
733 * selected by the module. Position of the cutting plane is defined by the two
734 * points and an optional vector lying on the plane specified by a PolySegment.
735 * By default the vector is defined by Mesh module as following. A middle point
736 * of the two given points is computed. The middle point is projected to the mesh.
737 * The vector goes from the middle point to the projection point. In case of planar
738 * mesh, the vector is normal to the mesh.
739 * \param [inout] segments - PolySegment's defining positions of cutting planes.
740 * Return the used vector and position of the middle point.
741 * \param [in] group - an optional group where created mesh segments will
744 void MakePolyLine( TListOfPolySegments& segments,
745 SMESHDS_Group* group=0,
746 SMESH_ElementSearcher* searcher=0);
751 * \brief Convert elements contained in a submesh to quadratic
752 * \return int - nb of checked elements
754 int convertElemToQuadratic(SMESHDS_SubMesh * theSm,
755 SMESH_MesherHelper& theHelper,
756 const bool theForce3d);
759 * \brief Convert quadratic elements to linear ones and remove quadratic nodes
760 * \return nb of checked elements
762 int removeQuadElem( SMESHDS_SubMesh * theSm,
763 SMDS_ElemIteratorPtr theItr,
764 const int theShapeID);
766 * \brief Create groups of elements made during transformation
767 * \param nodeGens - nodes making corresponding myLastCreatedNodes
768 * \param elemGens - elements making corresponding myLastCreatedElems
769 * \param postfix - to append to names of new groups
770 * \param targetMesh - mesh to create groups in
771 * \param topPresent - is there "top" elements that are created by sweeping
773 PGroupIDs generateGroups(const SMESH_SequenceOfElemPtr& nodeGens,
774 const SMESH_SequenceOfElemPtr& elemGens,
775 const std::string& postfix,
776 SMESH_Mesh* targetMesh=0,
777 const bool topPresent=true);
779 * \brief Create elements by sweeping an element
780 * \param elem - element to sweep
781 * \param newNodesItVec - nodes generated from each node of the element
782 * \param newElems - generated elements
783 * \param nbSteps - number of sweeping steps
784 * \param srcElements - to append elem for each generated element
786 void sweepElement(const SMDS_MeshElement* elem,
787 const std::vector<TNodeOfNodeListMapItr> & newNodesItVec,
788 std::list<const SMDS_MeshElement*>& newElems,
789 const size_t nbSteps,
790 SMESH_SequenceOfElemPtr& srcElements);
793 * \brief Computes new connectivity of an element after merging nodes
794 * \param [in] elems - the element
795 * \param [out] newElemDefs - definition(s) of result element(s)
796 * \param [inout] nodeNodeMap - nodes to merge
797 * \param [in] avoidMakingHoles - if true and and the element becomes invalid
798 * after merging (but not degenerated), removes nodes causing
799 * the invalidity from \a nodeNodeMap.
800 * \return bool - true if the element should be removed
802 bool applyMerge( const SMDS_MeshElement* elems,
803 std::vector< ElemFeatures >& newElemDefs,
804 TNodeNodeMap& nodeNodeMap,
805 const bool avoidMakingHoles );
807 * \brief Create 1D and 2D elements around swept elements
808 * \param mapNewNodes - source nodes and ones generated from them
809 * \param newElemsMap - source elements and ones generated from them
810 * \param elemNewNodesMap - nodes generated from each node of each element
811 * \param elemSet - all swept elements
812 * \param nbSteps - number of sweeping steps
813 * \param srcElements - to append elem for each generated element
815 void makeWalls (TNodeOfNodeListMap & mapNewNodes,
816 TTElemOfElemListMap & newElemsMap,
817 TElemOfVecOfNnlmiMap & elemNewNodesMap,
818 TIDSortedElemSet& elemSet,
820 SMESH_SequenceOfElemPtr& srcElements);
822 struct SMESH_MeshEditor_PathPoint
826 double myAngle, myPrm;
828 SMESH_MeshEditor_PathPoint(): myPnt(99., 99., 99.), myTgt(1.,0.,0.), myAngle(0), myPrm(0) {}
829 void SetPnt (const gp_Pnt& aP3D) { myPnt =aP3D; }
830 void SetTangent (const gp_Dir& aTgt) { myTgt =aTgt; }
831 void SetAngle (const double& aBeta) { myAngle=aBeta; }
832 void SetParameter(const double& aPrm) { myPrm =aPrm; }
833 const gp_Pnt& Pnt ()const { return myPnt; }
834 const gp_Dir& Tangent ()const { return myTgt; }
835 double Angle ()const { return myAngle; }
836 double Parameter ()const { return myPrm; }
838 Extrusion_Error makeEdgePathPoints(std::list<double>& aPrms,
839 const TopoDS_Edge& aTrackEdge,
841 std::list<SMESH_MeshEditor_PathPoint>& aLPP);
842 Extrusion_Error makeExtrElements(TIDSortedElemSet theElements[2],
843 std::list<SMESH_MeshEditor_PathPoint>& theFullList,
844 const bool theHasAngles,
845 std::list<double>& theAngles,
846 const bool theLinearVariation,
847 const bool theHasRefPoint,
848 const gp_Pnt& theRefPoint,
849 const bool theMakeGroups);
850 static void linearAngleVariation(const int NbSteps,
851 std::list<double>& theAngles);
853 bool doubleNodes( SMESHDS_Mesh* theMeshDS,
854 const TIDSortedElemSet& theElems,
855 const TIDSortedElemSet& theNodesNot,
856 TNodeNodeMap& theNodeNodeMap,
857 const bool theIsDoubleElem );
859 void copyPosition( const SMDS_MeshNode* from,
860 const SMDS_MeshNode* to );
866 // Nodes and elements created during last operation
867 SMESH_SequenceOfElemPtr myLastCreatedNodes, myLastCreatedElems;
869 // Description of error/warning occurred during last operation
870 SMESH_ComputeErrorPtr myError;