1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 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.
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESH_MeshEditor.hxx
25 // Created : Mon Apr 12 14:56:19 2004
26 // Author : Edward AGAPOV (eap)
30 #ifndef SMESH_MeshEditor_HeaderFile
31 #define SMESH_MeshEditor_HeaderFile
33 #include "SMESH_Mesh.hxx"
34 #include "SMESH_Controls.hxx"
35 #include "SMESH_SequenceOfNode.hxx"
37 #include "TColStd_HSequenceOfReal.hxx"
42 typedef map<const SMDS_MeshElement*,
43 list<const SMDS_MeshElement*> > TElemOfElemListMap;
45 class SMDS_MeshElement;
52 class SMESH_MeshEditor {
55 SMESH_MeshEditor( SMESH_Mesh* theMesh );
57 bool Remove (const std::list< int >& theElemIDs, const bool isNodes);
58 // Remove a node or an element.
59 // Modify a compute state of sub-meshes which become empty
61 bool InverseDiag (const SMDS_MeshElement * theTria1,
62 const SMDS_MeshElement * theTria2 );
63 // Replace two neighbour triangles with ones built on the same 4 nodes
64 // but having other common link.
65 // Return False if args are improper
67 bool InverseDiag (const SMDS_MeshNode * theNode1,
68 const SMDS_MeshNode * theNode2 );
69 // Replace two neighbour triangles sharing theNode1-theNode2 link
70 // with ones built on the same 4 nodes but having other common link.
71 // Return false if proper faces not found
73 bool DeleteDiag (const SMDS_MeshNode * theNode1,
74 const SMDS_MeshNode * theNode2 );
75 // Replace two neighbour triangles sharing theNode1-theNode2 link
76 // with a quadrangle built on the same 4 nodes.
77 // Return false if proper faces not found
79 bool Reorient (const SMDS_MeshElement * theElement);
80 // Reverse theElement orientation
84 * \brief Fuse neighbour triangles into quadrangles.
85 * \param theElems - The triangles to be fused.
86 * \param theCriterion - Is used to choose a neighbour to fuse with.
87 * \param theMaxAngle - Is a max angle between element normals at which fusion
88 * is still performed; theMaxAngle is mesured in radians.
89 * \retval bool - Success or not.
91 bool TriToQuad (std::set<const SMDS_MeshElement*> & theElems,
92 SMESH::Controls::NumericalFunctorPtr theCriterion,
93 const double theMaxAngle);
96 * \brief Split quadrangles into triangles.
97 * \param theElems - The faces to be splitted.
98 * \param theCriterion - Is used to choose a diagonal for splitting.
99 * \retval bool - Success or not.
101 bool QuadToTri (std::set<const SMDS_MeshElement*> & theElems,
102 SMESH::Controls::NumericalFunctorPtr theCriterion);
105 * \brief Split quadrangles into triangles.
106 * \param theElems - The faces to be splitted.
107 * \param the13Diag - Is used to choose a diagonal for splitting.
108 * \retval bool - Success or not.
110 bool QuadToTri (std::set<const SMDS_MeshElement*> & theElems,
111 const bool the13Diag);
114 * \brief Find better diagonal for splitting.
115 * \param theQuad - The face to find better splitting of.
116 * \param theCriterion - Is used to choose a diagonal for splitting.
117 * \retval int - 1 for 1-3 diagonal, 2 for 2-4, -1 - for errors.
119 int BestSplit (const SMDS_MeshElement* theQuad,
120 SMESH::Controls::NumericalFunctorPtr theCriterion);
123 enum SmoothMethod { LAPLACIAN = 0, CENTROIDAL };
125 void Smooth (std::set<const SMDS_MeshElement*> & theElements,
126 std::set<const SMDS_MeshNode*> & theFixedNodes,
127 const SmoothMethod theSmoothMethod,
128 const int theNbIterations,
129 double theTgtAspectRatio = 1.0,
130 const bool the2D = true);
131 // Smooth theElements using theSmoothMethod during theNbIterations
132 // or until a worst element has aspect ratio <= theTgtAspectRatio.
133 // Aspect Ratio varies in range [1.0, inf].
134 // If theElements is empty, the whole mesh is smoothed.
135 // theFixedNodes contains additionally fixed nodes. Nodes built
136 // on edges and boundary nodes are always fixed.
137 // If the2D, smoothing is performed using UV parameters of nodes
138 // on geometrical faces
141 void RotationSweep (std::set<const SMDS_MeshElement*> & theElements,
142 const gp_Ax1& theAxis,
143 const double theAngle,
144 const int theNbSteps,
145 const double theToler);
146 // Generate new elements by rotation of theElements around theAxis
147 // by theAngle by theNbSteps
150 * Auxilary flag for advanced extrusion.
151 * BOUNDARY: create or not boundary for result of extrusion
152 * SEW: try to use existing nodes or create new nodes in any case
154 enum ExtrusionFlags {
155 EXTRUSION_FLAG_BOUNDARY = 0x01,
156 EXTRUSION_FLAG_SEW = 0x02
160 * special structire for control of extrusion functionality
163 gp_Dir myDir; // direction of extrusion
164 Handle(TColStd_HSequenceOfReal) mySteps; // magnitudes for each step
165 SMESH_SequenceOfNode myNodes; // nodes for using in sewing
169 * Create new node in the mesh with given coordinates
170 * (auxilary for advanced extrusion)
172 const SMDS_MeshNode* CreateNode(const double x,
175 const double tolnode,
176 SMESH_SequenceOfNode& aNodes);
179 * Generate new elements by extrusion of theElements
180 * It is a method used in .idl file. All functionality
181 * is implemented in the next method (see below) which
182 * is used in the cuurent method.
183 * param theElems - list of elements for extrusion
184 * param newElemsMap returns history of extrusion
185 * param theFlags set flags for performing extrusion (see description
186 * of enum ExtrusionFlags for additional information)
187 * param theTolerance - uses for comparing locations of nodes if flag
188 * EXTRUSION_FLAG_SEW is set
191 (set<const SMDS_MeshElement*> & theElems,
192 const gp_Vec& theStep,
193 const int theNbSteps,
194 TElemOfElemListMap& newElemsMap,
195 const int theFlags = EXTRUSION_FLAG_BOUNDARY,
196 const double theTolerance = 1.e-6);
199 * Generate new elements by extrusion of theElements
200 * param theElems - list of elements for extrusion
201 * param newElemsMap returns history of extrusion
202 * param theFlags set flags for performing extrusion (see description
203 * of enum ExtrusionFlags for additional information)
204 * param theTolerance - uses for comparing locations of nodes if flag
205 * EXTRUSION_FLAG_SEW is set
206 * param theParams - special structure for manage of extrusion
208 void ExtrusionSweep (set<const SMDS_MeshElement*> & theElems,
209 ExtrusParam& theParams,
210 TElemOfElemListMap& newElemsMap,
212 const double theTolerance);
215 // Generate new elements by extrusion of theElements
216 // by theStep by theNbSteps
218 enum Extrusion_Error {
223 EXTR_BAD_STARTING_NODE,
224 EXTR_BAD_ANGLES_NUMBER,
225 EXTR_CANT_GET_TANGENT
228 Extrusion_Error ExtrusionAlongTrack (std::set<const SMDS_MeshElement*> & theElements,
229 SMESH_subMesh* theTrackPattern,
230 const SMDS_MeshNode* theNodeStart,
231 const bool theHasAngles,
232 std::list<double>& theAngles,
233 const bool theHasRefPoint,
234 const gp_Pnt& theRefPoint);
235 // Generate new elements by extrusion of theElements along path given by theTrackPattern,
236 // theHasAngles are the rotation angles, base point can be given by theRefPoint
238 void Transform (std::set<const SMDS_MeshElement*> & theElements,
239 const gp_Trsf& theTrsf,
241 // Move or copy theElements applying theTrsf to their nodes
243 typedef std::list< std::list< const SMDS_MeshNode* > > TListOfListOfNodes;
245 void FindCoincidentNodes (std::set<const SMDS_MeshNode*> & theNodes,
246 const double theTolerance,
247 TListOfListOfNodes & theGroupsOfNodes);
248 // Return list of group of nodes close to each other within theTolerance.
249 // Search among theNodes or in the whole mesh if theNodes is empty.
251 int SimplifyFace (const vector<const SMDS_MeshNode *> faceNodes,
252 vector<const SMDS_MeshNode *>& poly_nodes,
253 vector<int>& quantities) const;
254 // Split face, defined by <faceNodes>, into several faces by repeating nodes.
255 // Is used by MergeNodes()
257 void MergeNodes (TListOfListOfNodes & theNodeGroups);
258 // In each group, the cdr of nodes are substituted by the first one
261 void MergeEqualElements();
262 // Remove all but one of elements built on the same nodes.
263 // Return nb of successfully merged groups.
265 static bool CheckFreeBorderNodes(const SMDS_MeshNode* theNode1,
266 const SMDS_MeshNode* theNode2,
267 const SMDS_MeshNode* theNode3 = 0);
268 // Return true if the three nodes are on a free border
272 // for SewFreeBorder()
273 SEW_BORDER1_NOT_FOUND,
274 SEW_BORDER2_NOT_FOUND,
275 SEW_BOTH_BORDERS_NOT_FOUND,
277 SEW_VOLUMES_TO_SPLIT,
278 // for SewSideElements()
279 SEW_DIFF_NB_OF_ELEMENTS,
280 SEW_TOPO_DIFF_SETS_OF_ELEMENTS,
286 Sew_Error SewFreeBorder (const SMDS_MeshNode* theBorderFirstNode,
287 const SMDS_MeshNode* theBorderSecondNode,
288 const SMDS_MeshNode* theBorderLastNode,
289 const SMDS_MeshNode* theSide2FirstNode,
290 const SMDS_MeshNode* theSide2SecondNode,
291 const SMDS_MeshNode* theSide2ThirdNode = 0,
292 const bool theSide2IsFreeBorder = true,
293 const bool toCreatePolygons = false,
294 const bool toCreatePolyedrs = false);
295 // Sew the free border to the side2 by replacing nodes in
296 // elements on the free border with nodes of the elements
297 // of the side 2. If nb of links in the free border and
298 // between theSide2FirstNode and theSide2LastNode are different,
299 // additional nodes are inserted on a link provided that no
300 // volume elements share the splitted link.
301 // The side 2 is a free border if theSide2IsFreeBorder == true.
302 // Sewing is peformed between the given first, second and last
303 // nodes on the sides.
304 // theBorderFirstNode is merged with theSide2FirstNode.
305 // if (!theSide2IsFreeBorder) then theSide2SecondNode gives
306 // the last node on the side 2, which will be merged with
307 // theBorderLastNode.
308 // if (theSide2IsFreeBorder) then theSide2SecondNode will
309 // be merged with theBorderSecondNode.
310 // if (theSide2IsFreeBorder && theSide2ThirdNode == 0) then
311 // the 2 free borders are sewn link by link and no additional
312 // nodes are inserted.
313 // Return false, if sewing failed.
315 Sew_Error SewSideElements (std::set<const SMDS_MeshElement*>& theSide1,
316 std::set<const SMDS_MeshElement*>& theSide2,
317 const SMDS_MeshNode* theFirstNode1ToMerge,
318 const SMDS_MeshNode* theFirstNode2ToMerge,
319 const SMDS_MeshNode* theSecondNode1ToMerge,
320 const SMDS_MeshNode* theSecondNode2ToMerge);
321 // Sew two sides of a mesh. Nodes belonging to theSide1 are
322 // merged with nodes of elements of theSide2.
323 // Number of elements in theSide1 and in theSide2 must be
324 // equal and they should have similar node connectivity.
325 // The nodes to merge should belong to side s borders and
326 // the first node should be linked to the second.
328 void InsertNodesIntoLink(const SMDS_MeshElement* theFace,
329 const SMDS_MeshNode* theBetweenNode1,
330 const SMDS_MeshNode* theBetweenNode2,
331 std::list<const SMDS_MeshNode*>& theNodesToInsert,
332 const bool toCreatePoly = false);
333 // insert theNodesToInsert into theFace between theBetweenNode1 and theBetweenNode2.
334 // If toCreatePoly is true, replace theFace by polygon, else split theFace.
336 void UpdateVolumes (const SMDS_MeshNode* theBetweenNode1,
337 const SMDS_MeshNode* theBetweenNode2,
338 std::list<const SMDS_MeshNode*>& theNodesToInsert);
339 // insert theNodesToInsert into all volumes, containing link
340 // theBetweenNode1 - theBetweenNode2, between theBetweenNode1 and theBetweenNode2.
342 // static int SortQuadNodes (const SMDS_Mesh * theMesh,
343 // int theNodeIds[] );
344 // // Set 4 nodes of a quadrangle face in a good order.
345 // // Swap 1<->2 or 2<->3 nodes and correspondingly return
348 // static bool SortHexaNodes (const SMDS_Mesh * theMesh,
349 // int theNodeIds[] );
350 // // Set 8 nodes of a hexahedron in a good order.
351 // // Return success status
353 static void AddToSameGroups (const SMDS_MeshElement* elemToAdd,
354 const SMDS_MeshElement* elemInGroups,
355 SMESHDS_Mesh * aMesh);
356 // Add elemToAdd to the groups the elemInGroups belongs to
358 static const SMDS_MeshElement*
359 FindFaceInSet(const SMDS_MeshNode* n1,
360 const SMDS_MeshNode* n2,
361 const std::set<const SMDS_MeshElement*>& elemSet,
362 const std::set<const SMDS_MeshElement*>& avoidSet);
363 // Return a face having linked nodes n1 and n2 and which is
364 // - not in avoidSet,
365 // - in elemSet provided that !elemSet.empty()
368 * \brief Returns true if given node is medium
369 * \param n - node to check
370 * \param typeToCheck - type of elements containing the node to ask about node status
371 * \retval bool - check result
373 static bool IsMedium(const SMDS_MeshNode* node,
374 const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
376 int FindShape (const SMDS_MeshElement * theElem);
377 // Return an index of the shape theElem is on
378 // or zero if a shape not found
381 SMESH_Mesh * GetMesh() { return myMesh; }
383 SMESHDS_Mesh * GetMeshDS() { return myMesh->GetMeshDS(); }