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;
92 SMESH_EXPORT ElemFeatures( SMDSAbs_ElementType type=SMDSAbs_All, bool isPoly=false, bool isQuad=false )
93 :myType( type ), myIsPoly(isPoly), myIsQuad(isQuad), myID(-1), myBallDiameter(0) {}
95 SMESH_EXPORT ElemFeatures& Init( SMDSAbs_ElementType type, bool isPoly=false, bool isQuad=false )
96 { myType = type; myIsPoly = isPoly; myIsQuad = isQuad; return *this; }
98 SMESH_EXPORT ElemFeatures& Init( const SMDS_MeshElement* elem, bool basicOnly=true );
100 SMESH_EXPORT ElemFeatures& Init( double diameter )
101 { myType = SMDSAbs_Ball; myBallDiameter = diameter; return *this; }
103 SMESH_EXPORT ElemFeatures& Init( std::vector<int>& quanities, bool isQuad=false )
104 { myType = SMDSAbs_Volume; myIsPoly = 1; myIsQuad = isQuad;
105 myPolyhedQuantities.swap( quanities ); return *this; }
107 SMESH_EXPORT ElemFeatures& Init( const std::vector<int>& quanities, bool isQuad=false )
108 { myType = SMDSAbs_Volume; myIsPoly = 1; myIsQuad = isQuad;
109 myPolyhedQuantities = quanities; return *this; }
111 SMESH_EXPORT ElemFeatures& SetPoly(bool isPoly) { myIsPoly = isPoly; return *this; }
112 SMESH_EXPORT ElemFeatures& SetQuad(bool isQuad) { myIsQuad = isQuad; return *this; }
113 SMESH_EXPORT ElemFeatures& SetID (int ID) { myID = ID; return *this; }
119 SMDS_MeshElement* AddElement(const std::vector<const SMDS_MeshNode*> & nodes,
120 const ElemFeatures& features);
124 SMDS_MeshElement* AddElement(const std::vector<int> & nodeIDs,
125 const ElemFeatures& features);
127 int Remove (const std::list< int >& theElemIDs, const bool isNodes);
128 // Remove a node or an element.
129 // Modify a compute state of sub-meshes which become empty
131 void Create0DElementsOnAllNodes( const TIDSortedElemSet& elements,
132 TIDSortedElemSet& all0DElems);
133 // Create 0D elements on all nodes of the given object except those
134 // nodes on which a 0D element already exists. \a all0DElems returns
135 // all 0D elements found or created on nodes of \a elements
137 bool InverseDiag (const SMDS_MeshElement * theTria1,
138 const SMDS_MeshElement * theTria2 );
139 // Replace two neighbour triangles with ones built on the same 4 nodes
140 // but having other common link.
141 // Return False if args are improper
143 bool InverseDiag (const SMDS_MeshNode * theNode1,
144 const SMDS_MeshNode * theNode2 );
145 // Replace two neighbour triangles sharing theNode1-theNode2 link
146 // with ones built on the same 4 nodes but having other common link.
147 // Return false if proper faces not found
149 bool DeleteDiag (const SMDS_MeshNode * theNode1,
150 const SMDS_MeshNode * theNode2 );
151 // Replace two neighbour triangles sharing theNode1-theNode2 link
152 // with a quadrangle built on the same 4 nodes.
153 // Return false if proper faces not found
155 bool Reorient (const SMDS_MeshElement * theElement);
156 // Reverse theElement orientation
158 int Reorient2D (TIDSortedElemSet & theFaces,
159 const gp_Dir& theDirection,
160 const SMDS_MeshElement * theFace);
161 // Reverse theFaces whose orientation to be same as that of theFace
162 // oriented according to theDirection. Return nb of reoriented faces
164 int Reorient2DBy3D (TIDSortedElemSet & theFaces,
165 TIDSortedElemSet & theVolumes,
166 const bool theOutsideNormal);
167 // Reorient faces basing on orientation of adjacent volumes.
168 // Return nb of reoriented faces
171 * \brief Fuse neighbour triangles into quadrangles.
172 * \param theElems - The triangles to be fused.
173 * \param theCriterion - Is used to choose a neighbour to fuse with.
174 * \param theMaxAngle - Is a max angle between element normals at which fusion
175 * is still performed; theMaxAngle is mesured in radians.
176 * \return bool - Success or not.
178 bool TriToQuad (TIDSortedElemSet & theElems,
179 SMESH::Controls::NumericalFunctorPtr theCriterion,
180 const double theMaxAngle);
182 * \brief Split quadrangles into triangles.
183 * \param theElems - The faces to be splitted.
184 * \param theCriterion - Is used to choose a diagonal for splitting.
185 * \return bool - Success or not.
187 bool QuadToTri (TIDSortedElemSet & theElems,
188 SMESH::Controls::NumericalFunctorPtr theCriterion);
190 * \brief Split quadrangles into triangles.
191 * \param theElems - The faces to be splitted.
192 * \param the13Diag - Is used to choose a diagonal for splitting.
193 * \return bool - Success or not.
195 bool QuadToTri (TIDSortedElemSet & theElems,
196 const bool the13Diag);
198 * \brief Split each of given quadrangles into 4 triangles.
199 * \param theElems - The faces to be splitted. If empty all faces are split.
201 void QuadTo4Tri (TIDSortedElemSet & theElems);
204 * \brief Find better diagonal for splitting.
205 * \param theQuad - The face to find better splitting of.
206 * \param theCriterion - Is used to choose a diagonal for splitting.
207 * \return int - 1 for 1-3 diagonal, 2 for 2-4, -1 - for errors.
209 int BestSplit (const SMDS_MeshElement* theQuad,
210 SMESH::Controls::NumericalFunctorPtr theCriterion);
213 typedef std::map < const SMDS_MeshElement*, int, TIDCompare > TFacetOfElem;
215 //!<2nd arg of SplitVolumes()
216 enum SplitVolumToTetraFlags { HEXA_TO_5 = 1, // split into tetrahedra
219 HEXA_TO_2_PRISMS, // split into prisms
222 * \brief Split volumic elements into tetrahedra or prisms.
223 * If facet ID < 0, element is split into tetrahedra,
224 * else a hexahedron is split into prisms so that the given facet is
225 * split into triangles
227 void SplitVolumes (const TFacetOfElem & theElems, const int theMethodFlags);
230 * \brief For hexahedra that will be split into prisms, finds facets to
231 * split into triangles
232 * \param [in,out] theHexas - the hexahedra
233 * \param [in] theFacetNormal - facet normal
234 * \param [out] theFacets - the hexahedra and found facet IDs
236 void GetHexaFacetsToSplit( TIDSortedElemSet& theHexas,
237 const gp_Ax1& theFacetNormal,
238 TFacetOfElem & theFacets);
241 * \brief Split bi-quadratic elements into linear ones without creation of additional nodes
242 * - bi-quadratic triangle will be split into 3 linear quadrangles;
243 * - bi-quadratic quadrangle will be split into 4 linear quadrangles;
244 * - tri-quadratic hexahedron will be split into 8 linear hexahedra;
245 * Quadratic elements of lower dimension adjacent to the split bi-quadratic element
246 * will be split in order to keep the mesh conformal.
247 * \param elems - elements to split
249 void SplitBiQuadraticIntoLinear(TIDSortedElemSet& theElems);
251 enum SmoothMethod { LAPLACIAN = 0, CENTROIDAL };
253 void Smooth (TIDSortedElemSet & theElements,
254 std::set<const SMDS_MeshNode*> & theFixedNodes,
255 const SmoothMethod theSmoothMethod,
256 const int theNbIterations,
257 double theTgtAspectRatio = 1.0,
258 const bool the2D = true);
259 // Smooth theElements using theSmoothMethod during theNbIterations
260 // or until a worst element has aspect ratio <= theTgtAspectRatio.
261 // Aspect Ratio varies in range [1.0, inf].
262 // If theElements is empty, the whole mesh is smoothed.
263 // theFixedNodes contains additionally fixed nodes. Nodes built
264 // on edges and boundary nodes are always fixed.
265 // If the2D, smoothing is performed using UV parameters of nodes
266 // on geometrical faces
268 typedef TIDTypeCompare TElemSort;
269 typedef std::map < const SMDS_MeshElement*,
270 std::list<const SMDS_MeshElement*>, TElemSort > TTElemOfElemListMap;
271 typedef std::map<const SMDS_MeshNode*, std::list<const SMDS_MeshNode*> > TNodeOfNodeListMap;
272 typedef TNodeOfNodeListMap::iterator TNodeOfNodeListMapItr;
273 typedef std::vector<TNodeOfNodeListMapItr> TVecOfNnlmiMap;
274 typedef std::map<const SMDS_MeshElement*, TVecOfNnlmiMap, TElemSort > TElemOfVecOfNnlmiMap;
275 typedef std::auto_ptr< std::list<int> > PGroupIDs;
277 PGroupIDs RotationSweep (TIDSortedElemSet theElements[2],
278 const gp_Ax1& theAxis,
279 const double theAngle,
280 const int theNbSteps,
281 const double theToler,
282 const bool theMakeGroups,
283 const bool theMakeWalls=true);
284 // Generate new elements by rotation of theElements around theAxis
285 // by theAngle by theNbSteps
288 * Flags of extrusion.
289 * BOUNDARY: create or not boundary for result of extrusion
290 * SEW: try to use existing nodes or create new nodes in any case
291 * GROUPS: to create groups
292 * BY_AVG_NORMAL: step size is measured along average normal to elements,
293 * else step size is measured along average normal of any element
294 * USE_INPUT_ELEMS_ONLY: to use only input elements to compute extrusion direction
295 * for ExtrusionByNormal()
297 enum ExtrusionFlags {
298 EXTRUSION_FLAG_BOUNDARY = 0x01,
299 EXTRUSION_FLAG_SEW = 0x02,
300 EXTRUSION_FLAG_GROUPS = 0x04,
301 EXTRUSION_FLAG_BY_AVG_NORMAL = 0x08,
302 EXTRUSION_FLAG_USE_INPUT_ELEMS_ONLY = 0x10
306 * Generator of nodes for extrusion functionality
308 class SMESH_EXPORT ExtrusParam {
309 gp_Dir myDir; // direction of extrusion
310 Handle(TColStd_HSequenceOfReal) mySteps; // magnitudes for each step
311 SMESH_SequenceOfNode myNodes; // nodes for using in sewing
312 int myFlags; // see ExtrusionFlags
313 double myTolerance; // tolerance for sewing nodes
314 const TIDSortedElemSet* myElemsToUse; // elements to use for extrusion by normal
316 int (ExtrusParam::*myMakeNodesFun)(SMESHDS_Mesh* mesh,
317 const SMDS_MeshNode* srcNode,
318 std::list<const SMDS_MeshNode*> & newNodes,
319 const bool makeMediumNodes);
322 ExtrusParam( const gp_Vec& theStep,
323 const int theNbSteps,
324 const int theFlags = 0,
325 const double theTolerance = 1e-6);
326 ExtrusParam( const gp_Dir& theDir,
327 Handle(TColStd_HSequenceOfReal) theSteps,
328 const int theFlags = 0,
329 const double theTolerance = 1e-6);
330 ExtrusParam( const double theStep,
331 const int theNbSteps,
333 const int theDim); // for extrusion by normal
335 SMESH_SequenceOfNode& ChangeNodes() { return myNodes; }
336 int& Flags() { return myFlags; }
337 bool ToMakeBoundary() const { return myFlags & EXTRUSION_FLAG_BOUNDARY; }
338 bool ToMakeGroups() const { return myFlags & EXTRUSION_FLAG_GROUPS; }
339 bool ToUseInpElemsOnly() const { return myFlags & EXTRUSION_FLAG_USE_INPUT_ELEMS_ONLY; }
340 int NbSteps() const { return mySteps->Length(); }
342 // stores elements to use for extrusion by normal, depending on
343 // state of EXTRUSION_FLAG_USE_INPUT_ELEMS_ONLY flag
344 void SetElementsToUse( const TIDSortedElemSet& elems );
346 // creates nodes and returns number of nodes added in \a newNodes
347 int MakeNodes( SMESHDS_Mesh* mesh,
348 const SMDS_MeshNode* srcNode,
349 std::list<const SMDS_MeshNode*> & newNodes,
350 const bool makeMediumNodes)
352 return (this->*myMakeNodesFun)( mesh, srcNode, newNodes, makeMediumNodes );
356 int makeNodesByDir( SMESHDS_Mesh* mesh,
357 const SMDS_MeshNode* srcNode,
358 std::list<const SMDS_MeshNode*> & newNodes,
359 const bool makeMediumNodes);
360 int makeNodesByDirAndSew( SMESHDS_Mesh* mesh,
361 const SMDS_MeshNode* srcNode,
362 std::list<const SMDS_MeshNode*> & newNodes,
363 const bool makeMediumNodes);
364 int makeNodesByNormal2D( SMESHDS_Mesh* mesh,
365 const SMDS_MeshNode* srcNode,
366 std::list<const SMDS_MeshNode*> & newNodes,
367 const bool makeMediumNodes);
368 int makeNodesByNormal1D( SMESHDS_Mesh* mesh,
369 const SMDS_MeshNode* srcNode,
370 std::list<const SMDS_MeshNode*> & newNodes,
371 const bool makeMediumNodes);
373 void beginStepIter( bool withMediumNodes );
376 std::vector< double > myCurSteps;
377 bool myWithMediumNodes;
382 * Generate new elements by extrusion of theElements
383 * It is a method used in .idl file. All functionality
384 * is implemented in the next method (see below) which
385 * is used in the current method.
386 * @param theElems - list of elements for extrusion
387 * @param newElemsMap returns history of extrusion
388 * @param theFlags set flags for performing extrusion (see description
389 * of enum ExtrusionFlags for additional information)
390 * @param theTolerance - uses for comparing locations of nodes if flag
391 * EXTRUSION_FLAG_SEW is set
393 PGroupIDs ExtrusionSweep (TIDSortedElemSet theElems[2],
394 const gp_Vec& theStep,
395 const int theNbSteps,
396 TTElemOfElemListMap& newElemsMap,
398 const double theTolerance = 1.e-6);
401 * Generate new elements by extrusion of theElements
402 * @param theElems - list of elements for extrusion
403 * @param newElemsMap returns history of extrusion
404 * @param theFlags set flags for performing extrusion (see description
405 * of enum ExtrusionFlags for additional information)
406 * @param theTolerance - uses for comparing locations of nodes if flag
407 * EXTRUSION_FLAG_SEW is set
408 * @param theParams - special structure for manage of extrusion
410 PGroupIDs ExtrusionSweep (TIDSortedElemSet theElems[2],
411 ExtrusParam& theParams,
412 TTElemOfElemListMap& newElemsMap);
415 // Generate new elements by extrusion of theElements
416 // by theStep by theNbSteps
418 enum Extrusion_Error {
423 EXTR_BAD_STARTING_NODE,
424 EXTR_BAD_ANGLES_NUMBER,
425 EXTR_CANT_GET_TANGENT
428 Extrusion_Error ExtrusionAlongTrack (TIDSortedElemSet theElements[2],
429 SMESH_subMesh* theTrackPattern,
430 const SMDS_MeshNode* theNodeStart,
431 const bool theHasAngles,
432 std::list<double>& theAngles,
433 const bool theLinearVariation,
434 const bool theHasRefPoint,
435 const gp_Pnt& theRefPoint,
436 const bool theMakeGroups);
437 Extrusion_Error ExtrusionAlongTrack (TIDSortedElemSet theElements[2],
438 SMESH_Mesh* theTrackPattern,
439 const SMDS_MeshNode* theNodeStart,
440 const bool theHasAngles,
441 std::list<double>& theAngles,
442 const bool theLinearVariation,
443 const bool theHasRefPoint,
444 const gp_Pnt& theRefPoint,
445 const bool theMakeGroups);
446 // Generate new elements by extrusion of theElements along path given by theTrackPattern,
447 // theHasAngles are the rotation angles, base point can be given by theRefPoint
449 PGroupIDs Transform (TIDSortedElemSet & theElements,
450 const gp_Trsf& theTrsf,
452 const bool theMakeGroups,
453 SMESH_Mesh* theTargetMesh=0);
454 // Move or copy theElements applying theTrsf to their nodes
456 typedef std::list< std::list< const SMDS_MeshNode* > > TListOfListOfNodes;
458 void FindCoincidentNodes (TIDSortedNodeSet & theNodes,
459 const double theTolerance,
460 TListOfListOfNodes & theGroupsOfNodes,
461 bool theSeparateCornersAndMedium);
462 // Return list of group of nodes close to each other within theTolerance.
463 // Search among theNodes or in the whole mesh if theNodes is empty.
465 void MergeNodes (TListOfListOfNodes & theNodeGroups);
466 // In each group, the cdr of nodes are substituted by the first one
469 typedef std::list< std::list< int > > TListOfListOfElementsID;
471 void FindEqualElements(TIDSortedElemSet & theElements,
472 TListOfListOfElementsID & theGroupsOfElementsID);
473 // Return list of group of elements build on the same nodes.
474 // Search among theElements or in the whole mesh if theElements is empty.
476 void MergeElements(TListOfListOfElementsID & theGroupsOfElementsID);
477 // In each group remove all but first of elements.
479 void MergeEqualElements();
480 // Remove all but one of elements built on the same nodes.
481 // Return nb of successfully merged groups.
483 int SimplifyFace (const std::vector<const SMDS_MeshNode *>& faceNodes,
484 std::vector<const SMDS_MeshNode *>& poly_nodes,
485 std::vector<int>& quantities) const;
486 // Split face, defined by <faceNodes>, into several faces by repeating nodes.
487 // Is used by MergeNodes()
489 static bool CheckFreeBorderNodes(const SMDS_MeshNode* theNode1,
490 const SMDS_MeshNode* theNode2,
491 const SMDS_MeshNode* theNode3 = 0);
492 // Return true if the three nodes are on a free border
494 static bool FindFreeBorder (const SMDS_MeshNode* theFirstNode,
495 const SMDS_MeshNode* theSecondNode,
496 const SMDS_MeshNode* theLastNode,
497 std::list< const SMDS_MeshNode* > & theNodes,
498 std::list< const SMDS_MeshElement* >& theFaces);
499 // Return nodes and faces of a free border if found
503 // for SewFreeBorder()
504 SEW_BORDER1_NOT_FOUND,
505 SEW_BORDER2_NOT_FOUND,
506 SEW_BOTH_BORDERS_NOT_FOUND,
508 SEW_VOLUMES_TO_SPLIT,
509 // for SewSideElements()
510 SEW_DIFF_NB_OF_ELEMENTS,
511 SEW_TOPO_DIFF_SETS_OF_ELEMENTS,
518 Sew_Error SewFreeBorder (const SMDS_MeshNode* theBorderFirstNode,
519 const SMDS_MeshNode* theBorderSecondNode,
520 const SMDS_MeshNode* theBorderLastNode,
521 const SMDS_MeshNode* theSide2FirstNode,
522 const SMDS_MeshNode* theSide2SecondNode,
523 const SMDS_MeshNode* theSide2ThirdNode = 0,
524 const bool theSide2IsFreeBorder = true,
525 const bool toCreatePolygons = false,
526 const bool toCreatePolyedrs = false);
527 // Sew the free border to the side2 by replacing nodes in
528 // elements on the free border with nodes of the elements
529 // of the side 2. If nb of links in the free border and
530 // between theSide2FirstNode and theSide2LastNode are different,
531 // additional nodes are inserted on a link provided that no
532 // volume elements share the splitted link.
533 // The side 2 is a free border if theSide2IsFreeBorder == true.
534 // Sewing is peformed between the given first, second and last
535 // nodes on the sides.
536 // theBorderFirstNode is merged with theSide2FirstNode.
537 // if (!theSide2IsFreeBorder) then theSide2SecondNode gives
538 // the last node on the side 2, which will be merged with
539 // theBorderLastNode.
540 // if (theSide2IsFreeBorder) then theSide2SecondNode will
541 // be merged with theBorderSecondNode.
542 // if (theSide2IsFreeBorder && theSide2ThirdNode == 0) then
543 // the 2 free borders are sewn link by link and no additional
544 // nodes are inserted.
545 // Return false, if sewing failed.
547 Sew_Error SewSideElements (TIDSortedElemSet& theSide1,
548 TIDSortedElemSet& theSide2,
549 const SMDS_MeshNode* theFirstNode1ToMerge,
550 const SMDS_MeshNode* theFirstNode2ToMerge,
551 const SMDS_MeshNode* theSecondNode1ToMerge,
552 const SMDS_MeshNode* theSecondNode2ToMerge);
553 // Sew two sides of a mesh. Nodes belonging to theSide1 are
554 // merged with nodes of elements of theSide2.
555 // Number of elements in theSide1 and in theSide2 must be
556 // equal and they should have similar node connectivity.
557 // The nodes to merge should belong to side s borders and
558 // the first node should be linked to the second.
560 void InsertNodesIntoLink(const SMDS_MeshElement* theFace,
561 const SMDS_MeshNode* theBetweenNode1,
562 const SMDS_MeshNode* theBetweenNode2,
563 std::list<const SMDS_MeshNode*>& theNodesToInsert,
564 const bool toCreatePoly = false);
565 // insert theNodesToInsert into theFace between theBetweenNode1 and theBetweenNode2.
566 // If toCreatePoly is true, replace theFace by polygon, else split theFace.
568 void UpdateVolumes (const SMDS_MeshNode* theBetweenNode1,
569 const SMDS_MeshNode* theBetweenNode2,
570 std::list<const SMDS_MeshNode*>& theNodesToInsert);
571 // insert theNodesToInsert into all volumes, containing link
572 // theBetweenNode1 - theBetweenNode2, between theBetweenNode1 and theBetweenNode2.
574 void ConvertToQuadratic(const bool theForce3d, const bool theToBiQuad);
575 void ConvertToQuadratic(const bool theForce3d,
576 TIDSortedElemSet& theElements, const bool theToBiQuad);
577 // Converts all mesh to quadratic or bi-quadratic one, deletes old elements,
578 // replacing them with quadratic or bi-quadratic ones with the same id.
579 // If theForce3d = 1; this results in the medium node lying at the
580 // middle of the line segments connecting start and end node of a mesh element.
581 // If theForce3d = 0; this results in the medium node lying at the
582 // geometrical edge from which the mesh element is built.
584 bool ConvertFromQuadratic();
585 void ConvertFromQuadratic(TIDSortedElemSet& theElements);
586 // Converts all mesh from quadratic to ordinary ones, deletes old quadratic elements, replacing
587 // them with ordinary mesh elements with the same id.
588 // Returns true in case of success, false otherwise.
590 static void AddToSameGroups (const SMDS_MeshElement* elemToAdd,
591 const SMDS_MeshElement* elemInGroups,
592 SMESHDS_Mesh * aMesh);
593 // Add elemToAdd to the all groups the elemInGroups belongs to
595 static void RemoveElemFromGroups (const SMDS_MeshElement* element,
596 SMESHDS_Mesh * aMesh);
597 // remove element from the all groups
599 static void ReplaceElemInGroups (const SMDS_MeshElement* elemToRm,
600 const SMDS_MeshElement* elemToAdd,
601 SMESHDS_Mesh * aMesh);
602 // replace elemToRm by elemToAdd in the all groups
604 static void ReplaceElemInGroups (const SMDS_MeshElement* elemToRm,
605 const std::vector<const SMDS_MeshElement*>& elemToAdd,
606 SMESHDS_Mesh * aMesh);
607 // replace elemToRm by elemToAdd in the all groups
610 * \brief Return nodes linked to the given one in elements of the type
612 static void GetLinkedNodes( const SMDS_MeshNode* node,
613 TIDSortedElemSet & linkedNodes,
614 SMDSAbs_ElementType type = SMDSAbs_All );
617 * \brief Find corresponding nodes in two sets of faces
618 * \param theSide1 - first face set
619 * \param theSide2 - second first face
620 * \param theFirstNode1 - a boundary node of set 1
621 * \param theFirstNode2 - a node of set 2 corresponding to theFirstNode1
622 * \param theSecondNode1 - a boundary node of set 1 linked with theFirstNode1
623 * \param theSecondNode2 - a node of set 2 corresponding to theSecondNode1
624 * \param nReplaceMap - output map of corresponding nodes
625 * \return Sew_Error - is a success or not
627 static Sew_Error FindMatchingNodes(std::set<const SMDS_MeshElement*>& theSide1,
628 std::set<const SMDS_MeshElement*>& theSide2,
629 const SMDS_MeshNode* theFirstNode1,
630 const SMDS_MeshNode* theFirstNode2,
631 const SMDS_MeshNode* theSecondNode1,
632 const SMDS_MeshNode* theSecondNode2,
633 TNodeNodeMap & theNodeReplaceMap);
636 * \brief Returns true if given node is medium
637 * \param n - node to check
638 * \param typeToCheck - type of elements containing the node to ask about node status
639 * \return bool - check result
641 static bool IsMedium(const SMDS_MeshNode* node,
642 const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
644 int FindShape (const SMDS_MeshElement * theElem);
645 // Return an index of the shape theElem is on
646 // or zero if a shape not found
648 void DoubleElements( const TIDSortedElemSet& theElements );
650 bool DoubleNodes( const std::list< int >& theListOfNodes,
651 const std::list< int >& theListOfModifiedElems );
653 bool DoubleNodes( const TIDSortedElemSet& theElems,
654 const TIDSortedElemSet& theNodesNot,
655 const TIDSortedElemSet& theAffectedElems );
657 bool AffectedElemGroupsInRegion( const TIDSortedElemSet& theElems,
658 const TIDSortedElemSet& theNodesNot,
659 const TopoDS_Shape& theShape,
660 TIDSortedElemSet& theAffectedElems);
662 bool DoubleNodesInRegion( const TIDSortedElemSet& theElems,
663 const TIDSortedElemSet& theNodesNot,
664 const TopoDS_Shape& theShape );
666 double OrientedAngle(const gp_Pnt& p0, const gp_Pnt& p1, const gp_Pnt& g1, const gp_Pnt& g2);
668 bool DoubleNodesOnGroupBoundaries( const std::vector<TIDSortedElemSet>& theElems,
669 bool createJointElems,
670 bool onAllBoundaries);
672 bool CreateFlatElementsOnFacesGroups( const std::vector<TIDSortedElemSet>& theElems );
674 void CreateHoleSkin(double radius,
675 const TopoDS_Shape& theShape,
676 SMESH_NodeSearcher* theNodeSearcher,
677 const char* groupName,
678 std::vector<double>& nodesCoords,
679 std::vector<std::vector<int> >& listOfListOfNodes);
682 * \brief Generated skin mesh (containing 2D cells) from 3D mesh
683 * The created 2D mesh elements based on nodes of free faces of boundary volumes
684 * \return TRUE if operation has been completed successfully, FALSE otherwise
686 bool Make2DMeshFrom3D();
688 enum Bnd_Dimension { BND_2DFROM3D, BND_1DFROM3D, BND_1DFROM2D };
690 int MakeBoundaryMesh(const TIDSortedElemSet& elements,
691 Bnd_Dimension dimension,
692 SMESH_Group* group = 0,
693 SMESH_Mesh* targetMesh = 0,
694 bool toCopyElements = false,
695 bool toCopyExistingBondary = false,
696 bool toAddExistingBondary = false,
697 bool aroundElements = false);
702 * \brief Convert elements contained in a submesh to quadratic
703 * \return int - nb of checked elements
705 int convertElemToQuadratic(SMESHDS_SubMesh * theSm,
706 SMESH_MesherHelper& theHelper,
707 const bool theForce3d);
710 * \brief Convert quadratic elements to linear ones and remove quadratic nodes
711 * \return nb of checked elements
713 int removeQuadElem( SMESHDS_SubMesh * theSm,
714 SMDS_ElemIteratorPtr theItr,
715 const int theShapeID);
717 * \brief Create groups of elements made during transformation
718 * \param nodeGens - nodes making corresponding myLastCreatedNodes
719 * \param elemGens - elements making corresponding myLastCreatedElems
720 * \param postfix - to append to names of new groups
721 * \param targetMesh - mesh to create groups in
722 * \param topPresent - is there "top" elements that are created by sweeping
724 PGroupIDs generateGroups(const SMESH_SequenceOfElemPtr& nodeGens,
725 const SMESH_SequenceOfElemPtr& elemGens,
726 const std::string& postfix,
727 SMESH_Mesh* targetMesh=0,
728 const bool topPresent=true);
730 * \brief Create elements by sweeping an element
731 * \param elem - element to sweep
732 * \param newNodesItVec - nodes generated from each node of the element
733 * \param newElems - generated elements
734 * \param nbSteps - number of sweeping steps
735 * \param srcElements - to append elem for each generated element
737 void sweepElement(const SMDS_MeshElement* elem,
738 const std::vector<TNodeOfNodeListMapItr> & newNodesItVec,
739 std::list<const SMDS_MeshElement*>& newElems,
740 const size_t nbSteps,
741 SMESH_SequenceOfElemPtr& srcElements);
744 * \brief Create 1D and 2D elements around swept elements
745 * \param mapNewNodes - source nodes and ones generated from them
746 * \param newElemsMap - source elements and ones generated from them
747 * \param elemNewNodesMap - nodes generated from each node of each element
748 * \param elemSet - all swept elements
749 * \param nbSteps - number of sweeping steps
750 * \param srcElements - to append elem for each generated element
752 void makeWalls (TNodeOfNodeListMap & mapNewNodes,
753 TTElemOfElemListMap & newElemsMap,
754 TElemOfVecOfNnlmiMap & elemNewNodesMap,
755 TIDSortedElemSet& elemSet,
757 SMESH_SequenceOfElemPtr& srcElements);
759 struct SMESH_MeshEditor_PathPoint
763 double myAngle, myPrm;
765 SMESH_MeshEditor_PathPoint(): myPnt(99., 99., 99.), myTgt(1.,0.,0.), myAngle(0), myPrm(0) {}
766 void SetPnt (const gp_Pnt& aP3D) { myPnt =aP3D; }
767 void SetTangent (const gp_Dir& aTgt) { myTgt =aTgt; }
768 void SetAngle (const double& aBeta) { myAngle=aBeta; }
769 void SetParameter(const double& aPrm) { myPrm =aPrm; }
770 const gp_Pnt& Pnt ()const { return myPnt; }
771 const gp_Dir& Tangent ()const { return myTgt; }
772 double Angle ()const { return myAngle; }
773 double Parameter ()const { return myPrm; }
775 Extrusion_Error MakeEdgePathPoints(std::list<double>& aPrms,
776 const TopoDS_Edge& aTrackEdge,
778 std::list<SMESH_MeshEditor_PathPoint>& aLPP);
779 Extrusion_Error MakeExtrElements(TIDSortedElemSet theElements[2],
780 std::list<SMESH_MeshEditor_PathPoint>& theFullList,
781 const bool theHasAngles,
782 std::list<double>& theAngles,
783 const bool theLinearVariation,
784 const bool theHasRefPoint,
785 const gp_Pnt& theRefPoint,
786 const bool theMakeGroups);
787 void LinearAngleVariation(const int NbSteps,
788 std::list<double>& theAngles);
790 bool doubleNodes( SMESHDS_Mesh* theMeshDS,
791 const TIDSortedElemSet& theElems,
792 const TIDSortedElemSet& theNodesNot,
793 TNodeNodeMap& theNodeNodeMap,
794 const bool theIsDoubleElem );
796 void copyPosition( const SMDS_MeshNode* from,
797 const SMDS_MeshNode* to );
803 // Nodes and elements created during last operation
804 SMESH_SequenceOfElemPtr myLastCreatedNodes, myLastCreatedElems;
806 // Description of error/warning occured during last operation
807 SMESH_ComputeErrorPtr myError;