Debian Codegraph @

src/3rdParty/salomesmesh/inc/SMESH_MeshEditor.hxx

raw
1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : [email protected]
21 //
22
23 // File : SMESH_MeshEditor.hxx
24 // Created : Mon Apr 12 14:56:19 2004
25 // Author : Edward AGAPOV (eap)
26 // Module : SMESH
27 //
28 #ifndef SMESH_MeshEditor_HeaderFile
29 #define SMESH_MeshEditor_HeaderFile
30
31 #include "SMESH_SMESH.hxx"
32
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"
38
39 #include <utilities.h>
40
41 #include <TColStd_HSequenceOfReal.hxx>
42 #include <gp_Dir.hxx>
43
44 #include <list>
45 #include <map>
46 #include <set>
47
48 #if defined(__MINGW32__)
49 #define SMESH_EXPORT_MINGW SMESH_EXPORT
50 #define SMESH_EXPORT_MSVC
51 #elif defined(_MSC_VER)
52 #define SMESH_EXPORT_MINGW
53 #define SMESH_EXPORT_MSVC SMESH_EXPORT
54 #else
55 #define SMESH_EXPORT_MSVC
56 #define SMESH_EXPORT_MINGW
57 #endif
58
59 class SMDS_MeshFace;
60 class SMDS_MeshNode;
61 class gp_Ax1;
62 class gp_Vec;
63 class gp_Pnt;
64 class SMESH_MesherHelper;
65 struct SMESH_NodeSearcher;
66
67 // ============================================================
68 /*!
69 * \brief Editor of a mesh
70 */
71 // ============================================================
72
73 class SMESH_EXPORT SMESH_MeshEditor
74 {
75 public:
76
77 SMESH_MeshEditor( SMESH_Mesh* theMesh );
78
79 SMESH_Mesh * GetMesh() { return myMesh; }
80 SMESHDS_Mesh * GetMeshDS() { return myMesh->GetMeshDS(); }
81
82 const SMESH_SequenceOfElemPtr& GetLastCreatedNodes() const { return myLastCreatedNodes; }
83 const SMESH_SequenceOfElemPtr& GetLastCreatedElems() const { return myLastCreatedElems; }
84 void ClearLastCreated();
85 SMESH_ComputeErrorPtr & GetError() { return myError; }
86
87 // --------------------------------------------------------------------------------
88 struct SMESH_EXPORT_MINGW ElemFeatures //!< Features of element to create
89 {
90 SMDSAbs_ElementType myType;
91 bool myIsPoly, myIsQuad;
92 int myID;
93 double myBallDiameter;
94 std::vector<int> myPolyhedQuantities;
95
96 SMESH_EXPORT_MSVC ElemFeatures( SMDSAbs_ElementType type=SMDSAbs_All, bool isPoly=false, bool isQuad=false )
97 :myType( type ), myIsPoly(isPoly), myIsQuad(isQuad), myID(-1), myBallDiameter(0) {}
98
99 SMESH_EXPORT_MSVC ElemFeatures& Init( SMDSAbs_ElementType type, bool isPoly=false, bool isQuad=false )
100 { myType = type; myIsPoly = isPoly; myIsQuad = isQuad; return *this; }
101
102 SMESH_EXPORT_MSVC ElemFeatures& Init( const SMDS_MeshElement* elem, bool basicOnly=true );
103
104 SMESH_EXPORT_MSVC ElemFeatures& Init( double diameter )
105 { myType = SMDSAbs_Ball; myBallDiameter = diameter; return *this; }
106
107 SMESH_EXPORT_MSVC ElemFeatures& Init( std::vector<int>& quanities, bool isQuad=false )
108 { myType = SMDSAbs_Volume; myIsPoly = 1; myIsQuad = isQuad;
109 myPolyhedQuantities.swap( quanities ); return *this; }
110
111 SMESH_EXPORT_MSVC ElemFeatures& Init( const std::vector<int>& quanities, bool isQuad=false )
112 { myType = SMDSAbs_Volume; myIsPoly = 1; myIsQuad = isQuad;
113 myPolyhedQuantities = quanities; return *this; }
114
115 SMESH_EXPORT_MSVC ElemFeatures& SetPoly(bool isPoly) { myIsPoly = isPoly; return *this; }
116 SMESH_EXPORT_MSVC ElemFeatures& SetQuad(bool isQuad) { myIsQuad = isQuad; return *this; }
117 SMESH_EXPORT_MSVC ElemFeatures& SetID (int ID) { myID = ID; return *this; }
118 };
119
120 /*!
121 * \brief Add element
122 */
123 SMDS_MeshElement* AddElement(const std::vector<const SMDS_MeshNode*> & nodes,
124 const ElemFeatures& features);
125 /*!
126 * \brief Add element
127 */
128 SMDS_MeshElement* AddElement(const std::vector<int> & nodeIDs,
129 const ElemFeatures& features);
130
131 int Remove (const std::list< int >& theElemIDs, const bool isNodes);
132 // Remove a node or an element.
133 // Modify a compute state of sub-meshes which become empty
134
135 void Create0DElementsOnAllNodes( const TIDSortedElemSet& elements,
136 TIDSortedElemSet& all0DElems);
137 // Create 0D elements on all nodes of the given object except those
138 // nodes on which a 0D element already exists. \a all0DElems returns
139 // all 0D elements found or created on nodes of \a elements
140
141 bool InverseDiag (const SMDS_MeshElement * theTria1,
142 const SMDS_MeshElement * theTria2 );
143 // Replace two neighbour triangles with ones built on the same 4 nodes
144 // but having other common link.
145 // Return False if args are improper
146
147 bool InverseDiag (const SMDS_MeshNode * theNode1,
148 const SMDS_MeshNode * theNode2 );
149 // Replace two neighbour triangles sharing theNode1-theNode2 link
150 // with ones built on the same 4 nodes but having other common link.
151 // Return false if proper faces not found
152
153 bool DeleteDiag (const SMDS_MeshNode * theNode1,
154 const SMDS_MeshNode * theNode2 );
155 // Replace two neighbour triangles sharing theNode1-theNode2 link
156 // with a quadrangle built on the same 4 nodes.
157 // Return false if proper faces not found
158
159 bool Reorient (const SMDS_MeshElement * theElement);
160 // Reverse theElement orientation
161
162 int Reorient2D (TIDSortedElemSet & theFaces,
163 const gp_Dir& theDirection,
164 const SMDS_MeshElement * theFace);
165 // Reverse theFaces whose orientation to be same as that of theFace
166 // oriented according to theDirection. Return nb of reoriented faces
167
168 int Reorient2DBy3D (TIDSortedElemSet & theFaces,
169 TIDSortedElemSet & theVolumes,
170 const bool theOutsideNormal);
171 // Reorient faces basing on orientation of adjacent volumes.
172 // Return nb of reoriented faces
173
174 /*!
175 * \brief Fuse neighbour triangles into quadrangles.
176 * \param theElems - The triangles to be fused.
177 * \param theCriterion - Is used to choose a neighbour to fuse with.
178 * \param theMaxAngle - Is a max angle between element normals at which fusion
179 * is still performed; theMaxAngle is measured in radians.
180 * \return bool - Success or not.
181 */
182 bool TriToQuad (TIDSortedElemSet & theElems,
183 SMESH::Controls::NumericalFunctorPtr theCriterion,
184 const double theMaxAngle);
185 /*!
186 * \brief Split quadrangles into triangles.
187 * \param theElems - The faces to be split.
188 * \param theCriterion - Is used to choose a diagonal for splitting.
189 * \return bool - Success or not.
190 */
191 bool QuadToTri (TIDSortedElemSet & theElems,
192 SMESH::Controls::NumericalFunctorPtr theCriterion);
193 /*!
194 * \brief Split quadrangles into triangles.
195 * \param theElems - The faces to be split.
196 * \param the13Diag - Is used to choose a diagonal for splitting.
197 * \return bool - Success or not.
198 */
199 bool QuadToTri (TIDSortedElemSet & theElems,
200 const bool the13Diag);
201 /*!
202 * \brief Split each of given quadrangles into 4 triangles.
203 * \param theElems - The faces to be split. If empty all faces are split.
204 */
205 void QuadTo4Tri (TIDSortedElemSet & theElems);
206
207 /*!
208 * \brief Find better diagonal for splitting.
209 * \param theQuad - The face to find better splitting of.
210 * \param theCriterion - Is used to choose a diagonal for splitting.
211 * \return int - 1 for 1-3 diagonal, 2 for 2-4, -1 - for errors.
212 */
213 int BestSplit (const SMDS_MeshElement* theQuad,
214 SMESH::Controls::NumericalFunctorPtr theCriterion);
215
216
217 typedef std::map < const SMDS_MeshElement*, int, TIDCompare > TFacetOfElem;
218
219 //!<2nd arg of SplitVolumes()
220 enum SplitVolumToTetraFlags { HEXA_TO_5 = 1, // split into tetrahedra
221 HEXA_TO_6,
222 HEXA_TO_24,
223 HEXA_TO_2_PRISMS, // split into prisms
224 HEXA_TO_4_PRISMS };
225 /*!
226 * \brief Split volumic elements into tetrahedra or prisms.
227 * If facet ID < 0, element is split into tetrahedra,
228 * else a hexahedron is split into prisms so that the given facet is
229 * split into triangles
230 */
231 void SplitVolumes (const TFacetOfElem & theElems, const int theMethodFlags);
232
233 /*!
234 * \brief For hexahedra that will be split into prisms, finds facets to
235 * split into triangles
236 * \param [in,out] theHexas - the hexahedra
237 * \param [in] theFacetNormal - facet normal
238 * \param [out] theFacets - the hexahedra and found facet IDs
239 */
240 void GetHexaFacetsToSplit( TIDSortedElemSet& theHexas,
241 const gp_Ax1& theFacetNormal,
242 TFacetOfElem & theFacets);
243
244 /*!
245 * \brief Split bi-quadratic elements into linear ones without creation of additional nodes
246 * - bi-quadratic triangle will be split into 3 linear quadrangles;
247 * - bi-quadratic quadrangle will be split into 4 linear quadrangles;
248 * - tri-quadratic hexahedron will be split into 8 linear hexahedra;
249 * Quadratic elements of lower dimension adjacent to the split bi-quadratic element
250 * will be split in order to keep the mesh conformal.
251 * \param elems - elements to split
252 */
253 void SplitBiQuadraticIntoLinear(TIDSortedElemSet& theElems);
254
255 enum SmoothMethod { LAPLACIAN = 0, CENTROIDAL };
256
257 void Smooth (TIDSortedElemSet & theElements,
258 std::set<const SMDS_MeshNode*> & theFixedNodes,
259 const SmoothMethod theSmoothMethod,
260 const int theNbIterations,
261 double theTgtAspectRatio = 1.0,
262 const bool the2D = true);
263 // Smooth theElements using theSmoothMethod during theNbIterations
264 // or until a worst element has aspect ratio <= theTgtAspectRatio.
265 // Aspect Ratio varies in range [1.0, inf].
266 // If theElements is empty, the whole mesh is smoothed.
267 // theFixedNodes contains additionally fixed nodes. Nodes built
268 // on edges and boundary nodes are always fixed.
269 // If the2D, smoothing is performed using UV parameters of nodes
270 // on geometrical faces
271
272 typedef TIDTypeCompare TElemSort;
273 typedef std::map < const SMDS_MeshElement*,
274 std::list<const SMDS_MeshElement*>, TElemSort > TTElemOfElemListMap;
275 typedef std::map<const SMDS_MeshNode*, std::list<const SMDS_MeshNode*> > TNodeOfNodeListMap;
276 typedef TNodeOfNodeListMap::iterator TNodeOfNodeListMapItr;
277 typedef std::vector<TNodeOfNodeListMapItr> TVecOfNnlmiMap;
278 typedef std::map<const SMDS_MeshElement*, TVecOfNnlmiMap, TElemSort > TElemOfVecOfNnlmiMap;
279 typedef std::unique_ptr< std::list<int> > PGroupIDs;
280
281 PGroupIDs RotationSweep (TIDSortedElemSet theElements[2],
282 const gp_Ax1& theAxis,
283 const double theAngle,
284 const int theNbSteps,
285 const double theToler,
286 const bool theMakeGroups,
287 const bool theMakeWalls=true);
288 // Generate new elements by rotation of theElements around theAxis
289 // by theAngle by theNbSteps
290
291 /*!
292 * Flags of extrusion.
293 * BOUNDARY: create or not boundary for result of extrusion
294 * SEW: try to use existing nodes or create new nodes in any case
295 * GROUPS: to create groups
296 * BY_AVG_NORMAL: step size is measured along average normal to elements,
297 * else step size is measured along average normal of any element
298 * USE_INPUT_ELEMS_ONLY: to use only input elements to compute extrusion direction
299 * for ExtrusionByNormal()
300 */
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 };
308
309 /*!
310 * Generator of nodes for extrusion functionality
311 */
312 class SMESH_EXPORT ExtrusParam {
313 gp_Dir myDir; // direction of extrusion
314 Handle(TColStd_HSequenceOfReal) mySteps; // magnitudes for each step
315 SMESH_SequenceOfNode myNodes; // nodes for using in sewing
316 int myFlags; // see ExtrusionFlags
317 double myTolerance; // tolerance for sewing nodes
318 const TIDSortedElemSet* myElemsToUse; // elements to use for extrusion by normal
319
320 int (ExtrusParam::*myMakeNodesFun)(SMESHDS_Mesh* mesh,
321 const SMDS_MeshNode* srcNode,
322 std::list<const SMDS_MeshNode*> & newNodes,
323 const bool makeMediumNodes);
324
325 public:
326 ExtrusParam( const gp_Vec& theStep,
327 const int theNbSteps,
328 const int theFlags = 0,
329 const double theTolerance = 1e-6);
330 ExtrusParam( const gp_Dir& theDir,
331 Handle(TColStd_HSequenceOfReal) theSteps,
332 const int theFlags = 0,
333 const double theTolerance = 1e-6);
334 ExtrusParam( const double theStep,
335 const int theNbSteps,
336 const int theFlags,
337 const int theDim); // for extrusion by normal
338
339 SMESH_SequenceOfNode& ChangeNodes() { return myNodes; }
340 int& Flags() { return myFlags; }
341 bool ToMakeBoundary() const { return myFlags & EXTRUSION_FLAG_BOUNDARY; }
342 bool ToMakeGroups() const { return myFlags & EXTRUSION_FLAG_GROUPS; }
343 bool ToUseInpElemsOnly() const { return myFlags & EXTRUSION_FLAG_USE_INPUT_ELEMS_ONLY; }
344 int NbSteps() const { return mySteps->Length(); }
345
346 // stores elements to use for extrusion by normal, depending on
347 // state of EXTRUSION_FLAG_USE_INPUT_ELEMS_ONLY flag
348 void SetElementsToUse( const TIDSortedElemSet& elems );
349
350 // creates nodes and returns number of nodes added in \a newNodes
351 int MakeNodes( SMESHDS_Mesh* mesh,
352 const SMDS_MeshNode* srcNode,
353 std::list<const SMDS_MeshNode*> & newNodes,
354 const bool makeMediumNodes)
355 {
356 return (this->*myMakeNodesFun)( mesh, srcNode, newNodes, makeMediumNodes );
357 }
358 private:
359
360 int makeNodesByDir( SMESHDS_Mesh* mesh,
361 const SMDS_MeshNode* srcNode,
362 std::list<const SMDS_MeshNode*> & newNodes,
363 const bool makeMediumNodes);
364 int makeNodesByDirAndSew( SMESHDS_Mesh* mesh,
365 const SMDS_MeshNode* srcNode,
366 std::list<const SMDS_MeshNode*> & newNodes,
367 const bool makeMediumNodes);
368 int makeNodesByNormal2D( SMESHDS_Mesh* mesh,
369 const SMDS_MeshNode* srcNode,
370 std::list<const SMDS_MeshNode*> & newNodes,
371 const bool makeMediumNodes);
372 int makeNodesByNormal1D( SMESHDS_Mesh* mesh,
373 const SMDS_MeshNode* srcNode,
374 std::list<const SMDS_MeshNode*> & newNodes,
375 const bool makeMediumNodes);
376 // step iteration
377 void beginStepIter( bool withMediumNodes );
378 bool moreSteps();
379 double nextStep();
380 std::vector< double > myCurSteps;
381 bool myWithMediumNodes;
382 int myNextStep;
383 };
384
385 /*!
386 * Generate new elements by extrusion of theElements
387 * It is a method used in .idl file. All functionality
388 * is implemented in the next method (see below) which
389 * is used in the current method.
390 * @param theElems - list of elements for extrusion
391 * @param newElemsMap returns history of extrusion
392 * @param theFlags set flags for performing extrusion (see description
393 * of enum ExtrusionFlags for additional information)
394 * @param theTolerance - uses for comparing locations of nodes if flag
395 * EXTRUSION_FLAG_SEW is set
396 */
397 PGroupIDs ExtrusionSweep (TIDSortedElemSet theElems[2],
398 const gp_Vec& theStep,
399 const int theNbSteps,
400 TTElemOfElemListMap& newElemsMap,
401 const int theFlags,
402 const double theTolerance = 1.e-6);
403
404 /*!
405 * Generate new elements by extrusion of theElements
406 * @param theElems - list of elements for extrusion
407 * @param newElemsMap returns history of extrusion
408 * @param theFlags set flags for performing extrusion (see description
409 * of enum ExtrusionFlags for additional information)
410 * @param theTolerance - uses for comparing locations of nodes if flag
411 * EXTRUSION_FLAG_SEW is set
412 * @param theParams - special structure for manage of extrusion
413 */
414 PGroupIDs ExtrusionSweep (TIDSortedElemSet theElems[2],
415 ExtrusParam& theParams,
416 TTElemOfElemListMap& newElemsMap);
417
418
419 // Generate new elements by extrusion of theElements
420 // by theStep by theNbSteps
421
422 enum Extrusion_Error {
423 EXTR_OK,
424 EXTR_NO_ELEMENTS,
425 EXTR_PATH_NOT_EDGE,
426 EXTR_BAD_PATH_SHAPE,
427 EXTR_BAD_STARTING_NODE,
428 EXTR_BAD_ANGLES_NUMBER,
429 EXTR_CANT_GET_TANGENT
430 };
431
432 Extrusion_Error ExtrusionAlongTrack (TIDSortedElemSet theElements[2],
433 SMESH_subMesh* theTrackPattern,
434 const SMDS_MeshNode* theNodeStart,
435 const bool theHasAngles,
436 std::list<double>& theAngles,
437 const bool theLinearVariation,
438 const bool theHasRefPoint,
439 const gp_Pnt& theRefPoint,
440 const bool theMakeGroups);
441 Extrusion_Error ExtrusionAlongTrack (TIDSortedElemSet theElements[2],
442 SMESH_Mesh* theTrackPattern,
443 const SMDS_MeshNode* theNodeStart,
444 const bool theHasAngles,
445 std::list<double>& theAngles,
446 const bool theLinearVariation,
447 const bool theHasRefPoint,
448 const gp_Pnt& theRefPoint,
449 const bool theMakeGroups);
450 // Generate new elements by extrusion of theElements along path given by theTrackPattern,
451 // theHasAngles are the rotation angles, base point can be given by theRefPoint
452
453 PGroupIDs Transform (TIDSortedElemSet & theElements,
454 const gp_Trsf& theTrsf,
455 const bool theCopy,
456 const bool theMakeGroups,
457 SMESH_Mesh* theTargetMesh=0);
458 // Move or copy theElements applying theTrsf to their nodes
459
460 typedef std::list< std::list< const SMDS_MeshNode* > > TListOfListOfNodes;
461
462 void FindCoincidentNodes (TIDSortedNodeSet & theNodes,
463 const double theTolerance,
464 TListOfListOfNodes & theGroupsOfNodes,
465 bool theSeparateCornersAndMedium);
466 // Return list of group of nodes close to each other within theTolerance.
467 // Search among theNodes or in the whole mesh if theNodes is empty.
468
469 void MergeNodes (TListOfListOfNodes & theNodeGroups);
470 // In each group, the cdr of nodes are substituted by the first one
471 // in all elements.
472
473 typedef std::list< std::list< int > > TListOfListOfElementsID;
474
475 void FindEqualElements(TIDSortedElemSet & theElements,
476 TListOfListOfElementsID & theGroupsOfElementsID);
477 // Return list of group of elements build on the same nodes.
478 // Search among theElements or in the whole mesh if theElements is empty.
479
480 void MergeElements(TListOfListOfElementsID & theGroupsOfElementsID);
481 // In each group remove all but first of elements.
482
483 void MergeEqualElements();
484 // Remove all but one of elements built on the same nodes.
485 // Return nb of successfully merged groups.
486
487 int SimplifyFace (const std::vector<const SMDS_MeshNode *>& faceNodes,
488 std::vector<const SMDS_MeshNode *>& poly_nodes,
489 std::vector<int>& quantities) const;
490 // Split face, defined by <faceNodes>, into several faces by repeating nodes.
491 // Is used by MergeNodes()
492
493 static bool CheckFreeBorderNodes(const SMDS_MeshNode* theNode1,
494 const SMDS_MeshNode* theNode2,
495 const SMDS_MeshNode* theNode3 = 0);
496 // Return true if the three nodes are on a free border
497
498 static bool FindFreeBorder (const SMDS_MeshNode* theFirstNode,
499 const SMDS_MeshNode* theSecondNode,
500 const SMDS_MeshNode* theLastNode,
501 std::list< const SMDS_MeshNode* > & theNodes,
502 std::list< const SMDS_MeshElement* >& theFaces);
503 // Return nodes and faces of a free border if found
504
505 enum Sew_Error {
506 SEW_OK,
507 // for SewFreeBorder()
508 SEW_BORDER1_NOT_FOUND,
509 SEW_BORDER2_NOT_FOUND,
510 SEW_BOTH_BORDERS_NOT_FOUND,
511 SEW_BAD_SIDE_NODES,
512 SEW_VOLUMES_TO_SPLIT,
513 // for SewSideElements()
514 SEW_DIFF_NB_OF_ELEMENTS,
515 SEW_TOPO_DIFF_SETS_OF_ELEMENTS,
516 SEW_BAD_SIDE1_NODES,
517 SEW_BAD_SIDE2_NODES,
518 SEW_INTERNAL_ERROR
519 };
520
521
522 Sew_Error SewFreeBorder (const SMDS_MeshNode* theBorderFirstNode,
523 const SMDS_MeshNode* theBorderSecondNode,
524 const SMDS_MeshNode* theBorderLastNode,
525 const SMDS_MeshNode* theSide2FirstNode,
526 const SMDS_MeshNode* theSide2SecondNode,
527 const SMDS_MeshNode* theSide2ThirdNode = 0,
528 const bool theSide2IsFreeBorder = true,
529 const bool toCreatePolygons = false,
530 const bool toCreatePolyedrs = false);
531 // Sew the free border to the side2 by replacing nodes in
532 // elements on the free border with nodes of the elements
533 // of the side 2. If nb of links in the free border and
534 // between theSide2FirstNode and theSide2LastNode are different,
535 // additional nodes are inserted on a link provided that no
536 // volume elements share the split link.
537 // The side 2 is a free border if theSide2IsFreeBorder == true.
538 // Sewing is performed between the given first, second and last
539 // nodes on the sides.
540 // theBorderFirstNode is merged with theSide2FirstNode.
541 // if (!theSide2IsFreeBorder) then theSide2SecondNode gives
542 // the last node on the side 2, which will be merged with
543 // theBorderLastNode.
544 // if (theSide2IsFreeBorder) then theSide2SecondNode will
545 // be merged with theBorderSecondNode.
546 // if (theSide2IsFreeBorder && theSide2ThirdNode == 0) then
547 // the 2 free borders are sewn link by link and no additional
548 // nodes are inserted.
549 // Return false, if sewing failed.
550
551 Sew_Error SewSideElements (TIDSortedElemSet& theSide1,
552 TIDSortedElemSet& theSide2,
553 const SMDS_MeshNode* theFirstNode1ToMerge,
554 const SMDS_MeshNode* theFirstNode2ToMerge,
555 const SMDS_MeshNode* theSecondNode1ToMerge,
556 const SMDS_MeshNode* theSecondNode2ToMerge);
557 // Sew two sides of a mesh. Nodes belonging to theSide1 are
558 // merged with nodes of elements of theSide2.
559 // Number of elements in theSide1 and in theSide2 must be
560 // equal and they should have similar node connectivity.
561 // The nodes to merge should belong to side s borders and
562 // the first node should be linked to the second.
563
564 void InsertNodesIntoLink(const SMDS_MeshElement* theFace,
565 const SMDS_MeshNode* theBetweenNode1,
566 const SMDS_MeshNode* theBetweenNode2,
567 std::list<const SMDS_MeshNode*>& theNodesToInsert,
568 const bool toCreatePoly = false);
569 // insert theNodesToInsert into theFace between theBetweenNode1 and theBetweenNode2.
570 // If toCreatePoly is true, replace theFace by polygon, else split theFace.
571
572 void UpdateVolumes (const SMDS_MeshNode* theBetweenNode1,
573 const SMDS_MeshNode* theBetweenNode2,
574 std::list<const SMDS_MeshNode*>& theNodesToInsert);
575 // insert theNodesToInsert into all volumes, containing link
576 // theBetweenNode1 - theBetweenNode2, between theBetweenNode1 and theBetweenNode2.
577
578 void ConvertToQuadratic(const bool theForce3d, const bool theToBiQuad);
579 void ConvertToQuadratic(const bool theForce3d,
580 TIDSortedElemSet& theElements, const bool theToBiQuad);
581 // Converts all mesh to quadratic or bi-quadratic one, deletes old elements,
582 // replacing them with quadratic or bi-quadratic ones with the same id.
583 // If theForce3d = 1; this results in the medium node lying at the
584 // middle of the line segments connecting start and end node of a mesh element.
585 // If theForce3d = 0; this results in the medium node lying at the
586 // geometrical edge from which the mesh element is built.
587
588 bool ConvertFromQuadratic();
589 void ConvertFromQuadratic(TIDSortedElemSet& theElements);
590 // Converts all mesh from quadratic to ordinary ones, deletes old quadratic elements, replacing
591 // them with ordinary mesh elements with the same id.
592 // Returns true in case of success, false otherwise.
593
594 static void AddToSameGroups (const SMDS_MeshElement* elemToAdd,
595 const SMDS_MeshElement* elemInGroups,
596 SMESHDS_Mesh * aMesh);
597 // Add elemToAdd to the all groups the elemInGroups belongs to
598
599 static void RemoveElemFromGroups (const SMDS_MeshElement* element,
600 SMESHDS_Mesh * aMesh);
601 // remove element from the all groups
602
603 static void ReplaceElemInGroups (const SMDS_MeshElement* elemToRm,
604 const SMDS_MeshElement* elemToAdd,
605 SMESHDS_Mesh * aMesh);
606 // replace elemToRm by elemToAdd in the all groups
607
608 static void ReplaceElemInGroups (const SMDS_MeshElement* elemToRm,
609 const std::vector<const SMDS_MeshElement*>& elemToAdd,
610 SMESHDS_Mesh * aMesh);
611 // replace elemToRm by elemToAdd in the all groups
612
613 /*!
614 * \brief Return nodes linked to the given one in elements of the type
615 */
616 static void GetLinkedNodes( const SMDS_MeshNode* node,
617 TIDSortedElemSet & linkedNodes,
618 SMDSAbs_ElementType type = SMDSAbs_All );
619
620 /*!
621 * \brief Find corresponding nodes in two sets of faces
622 * \param theSide1 - first face set
623 * \param theSide2 - second first face
624 * \param theFirstNode1 - a boundary node of set 1
625 * \param theFirstNode2 - a node of set 2 corresponding to theFirstNode1
626 * \param theSecondNode1 - a boundary node of set 1 linked with theFirstNode1
627 * \param theSecondNode2 - a node of set 2 corresponding to theSecondNode1
628 * \param nReplaceMap - output map of corresponding nodes
629 * \return Sew_Error - is a success or not
630 */
631 static Sew_Error FindMatchingNodes(std::set<const SMDS_MeshElement*>& theSide1,
632 std::set<const SMDS_MeshElement*>& theSide2,
633 const SMDS_MeshNode* theFirstNode1,
634 const SMDS_MeshNode* theFirstNode2,
635 const SMDS_MeshNode* theSecondNode1,
636 const SMDS_MeshNode* theSecondNode2,
637 TNodeNodeMap & theNodeReplaceMap);
638
639 /*!
640 * \brief Returns true if given node is medium
641 * \param n - node to check
642 * \param typeToCheck - type of elements containing the node to ask about node status
643 * \return bool - check result
644 */
645 static bool IsMedium(const SMDS_MeshNode* node,
646 const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
647
648 int FindShape (const SMDS_MeshElement * theElem);
649 // Return an index of the shape theElem is on
650 // or zero if a shape not found
651
652 void DoubleElements( const TIDSortedElemSet& theElements );
653
654 bool DoubleNodes( const std::list< int >& theListOfNodes,
655 const std::list< int >& theListOfModifiedElems );
656
657 bool DoubleNodes( const TIDSortedElemSet& theElems,
658 const TIDSortedElemSet& theNodesNot,
659 const TIDSortedElemSet& theAffectedElems );
660
661 bool AffectedElemGroupsInRegion( const TIDSortedElemSet& theElems,
662 const TIDSortedElemSet& theNodesNot,
663 const TopoDS_Shape& theShape,
664 TIDSortedElemSet& theAffectedElems);
665
666 bool DoubleNodesInRegion( const TIDSortedElemSet& theElems,
667 const TIDSortedElemSet& theNodesNot,
668 const TopoDS_Shape& theShape );
669
670 double OrientedAngle(const gp_Pnt& p0, const gp_Pnt& p1, const gp_Pnt& g1, const gp_Pnt& g2);
671
672 bool DoubleNodesOnGroupBoundaries( const std::vector<TIDSortedElemSet>& theElems,
673 bool createJointElems,
674 bool onAllBoundaries);
675
676 bool CreateFlatElementsOnFacesGroups( const std::vector<TIDSortedElemSet>& theElems );
677
678 void CreateHoleSkin(double radius,
679 const TopoDS_Shape& theShape,
680 SMESH_NodeSearcher* theNodeSearcher,
681 const char* groupName,
682 std::vector<double>& nodesCoords,
683 std::vector<std::vector<int> >& listOfListOfNodes);
684
685 /*!
686 * \brief Generated skin mesh (containing 2D cells) from 3D mesh
687 * The created 2D mesh elements based on nodes of free faces of boundary volumes
688 * \return TRUE if operation has been completed successfully, FALSE otherwise
689 */
690 bool Make2DMeshFrom3D();
691
692 enum Bnd_Dimension { BND_2DFROM3D, BND_1DFROM3D, BND_1DFROM2D };
693
694 int MakeBoundaryMesh(const TIDSortedElemSet& elements,
695 Bnd_Dimension dimension,
696 SMESH_Group* group = 0,
697 SMESH_Mesh* targetMesh = 0,
698 bool toCopyElements = false,
699 bool toCopyExistingBondary = false,
700 bool toAddExistingBondary = false,
701 bool aroundElements = false);
702
703 private:
704
705 /*!
706 * \brief Convert elements contained in a submesh to quadratic
707 * \return int - nb of checked elements
708 */
709 int convertElemToQuadratic(SMESHDS_SubMesh * theSm,
710 SMESH_MesherHelper& theHelper,
711 const bool theForce3d);
712
713 /*!
714 * \brief Convert quadratic elements to linear ones and remove quadratic nodes
715 * \return nb of checked elements
716 */
717 int removeQuadElem( SMESHDS_SubMesh * theSm,
718 SMDS_ElemIteratorPtr theItr,
719 const int theShapeID);
720 /*!
721 * \brief Create groups of elements made during transformation
722 * \param nodeGens - nodes making corresponding myLastCreatedNodes
723 * \param elemGens - elements making corresponding myLastCreatedElems
724 * \param postfix - to append to names of new groups
725 * \param targetMesh - mesh to create groups in
726 * \param topPresent - is there "top" elements that are created by sweeping
727 */
728 PGroupIDs generateGroups(const SMESH_SequenceOfElemPtr& nodeGens,
729 const SMESH_SequenceOfElemPtr& elemGens,
730 const std::string& postfix,
731 SMESH_Mesh* targetMesh=0,
732 const bool topPresent=true);
733 /*!
734 * \brief Create elements by sweeping an element
735 * \param elem - element to sweep
736 * \param newNodesItVec - nodes generated from each node of the element
737 * \param newElems - generated elements
738 * \param nbSteps - number of sweeping steps
739 * \param srcElements - to append elem for each generated element
740 */
741 void sweepElement(const SMDS_MeshElement* elem,
742 const std::vector<TNodeOfNodeListMapItr> & newNodesItVec,
743 std::list<const SMDS_MeshElement*>& newElems,
744 const int nbSteps,
745 SMESH_SequenceOfElemPtr& srcElements);
746
747 /*!
748 * \brief Create 1D and 2D elements around swept elements
749 * \param mapNewNodes - source nodes and ones generated from them
750 * \param newElemsMap - source elements and ones generated from them
751 * \param elemNewNodesMap - nodes generated from each node of each element
752 * \param elemSet - all swept elements
753 * \param nbSteps - number of sweeping steps
754 * \param srcElements - to append elem for each generated element
755 */
756 void makeWalls (TNodeOfNodeListMap & mapNewNodes,
757 TTElemOfElemListMap & newElemsMap,
758 TElemOfVecOfNnlmiMap & elemNewNodesMap,
759 TIDSortedElemSet& elemSet,
760 const int nbSteps,
761 SMESH_SequenceOfElemPtr& srcElements);
762
763 struct SMESH_MeshEditor_PathPoint
764 {
765 gp_Pnt myPnt;
766 gp_Dir myTgt;
767 double myAngle, myPrm;
768
769 SMESH_MeshEditor_PathPoint(): myPnt(99., 99., 99.), myTgt(1.,0.,0.), myAngle(0), myPrm(0) {}
770 void SetPnt (const gp_Pnt& aP3D) { myPnt =aP3D; }
771 void SetTangent (const gp_Dir& aTgt) { myTgt =aTgt; }
772 void SetAngle (const double& aBeta) { myAngle=aBeta; }
773 void SetParameter(const double& aPrm) { myPrm =aPrm; }
774 const gp_Pnt& Pnt ()const { return myPnt; }
775 const gp_Dir& Tangent ()const { return myTgt; }
776 double Angle ()const { return myAngle; }
777 double Parameter ()const { return myPrm; }
778 };
779 Extrusion_Error MakeEdgePathPoints(std::list<double>& aPrms,
780 const TopoDS_Edge& aTrackEdge,
781 bool aFirstIsStart,
782 std::list<SMESH_MeshEditor_PathPoint>& aLPP);
783 Extrusion_Error MakeExtrElements(TIDSortedElemSet theElements[2],
784 std::list<SMESH_MeshEditor_PathPoint>& theFullList,
785 const bool theHasAngles,
786 std::list<double>& theAngles,
787 const bool theLinearVariation,
788 const bool theHasRefPoint,
789 const gp_Pnt& theRefPoint,
790 const bool theMakeGroups);
791 void LinearAngleVariation(const int NbSteps,
792 std::list<double>& theAngles);
793
794 bool doubleNodes( SMESHDS_Mesh* theMeshDS,
795 const TIDSortedElemSet& theElems,
796 const TIDSortedElemSet& theNodesNot,
797 TNodeNodeMap& theNodeNodeMap,
798 const bool theIsDoubleElem );
799
800 void copyPosition( const SMDS_MeshNode* from,
801 const SMDS_MeshNode* to );
802
803 private:
804
805 SMESH_Mesh * myMesh;
806
807 // Nodes and elements created during last operation
808 SMESH_SequenceOfElemPtr myLastCreatedNodes, myLastCreatedElems;
809
810 // Description of error/warning occurred during last operation
811 SMESH_ComputeErrorPtr myError;
812 };
813
814 #endif