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_SMESH.hxx"
35 #include "SMESH_Mesh.hxx"
36 #include "SMESH_Controls.hxx"
37 #include "SMESH_SequenceOfNode.hxx"
39 #include "TColStd_HSequenceOfReal.hxx"
44 typedef map<const SMDS_MeshElement*,
45 list<const SMDS_MeshElement*> > TElemOfElemListMap;
47 class SMDS_MeshElement;
54 class SMESH_EXPORT SMESH_MeshEditor {
57 SMESH_MeshEditor( SMESH_Mesh* theMesh );
59 bool Remove (const std::list< int >& theElemIDs, const bool isNodes);
60 // Remove a node or an element.
61 // Modify a compute state of sub-meshes which become empty
63 bool InverseDiag (const SMDS_MeshElement * theTria1,
64 const SMDS_MeshElement * theTria2 );
65 // Replace two neighbour triangles with ones built on the same 4 nodes
66 // but having other common link.
67 // Return False if args are improper
69 bool InverseDiag (const SMDS_MeshNode * theNode1,
70 const SMDS_MeshNode * theNode2 );
71 // Replace two neighbour triangles sharing theNode1-theNode2 link
72 // with ones built on the same 4 nodes but having other common link.
73 // Return false if proper faces not found
75 bool DeleteDiag (const SMDS_MeshNode * theNode1,
76 const SMDS_MeshNode * theNode2 );
77 // Replace two neighbour triangles sharing theNode1-theNode2 link
78 // with a quadrangle built on the same 4 nodes.
79 // Return false if proper faces not found
81 bool Reorient (const SMDS_MeshElement * theElement);
82 // Reverse theElement orientation
86 * \brief Fuse neighbour triangles into quadrangles.
87 * \param theElems - The triangles to be fused.
88 * \param theCriterion - Is used to choose a neighbour to fuse with.
89 * \param theMaxAngle - Is a max angle between element normals at which fusion
90 * is still performed; theMaxAngle is mesured in radians.
91 * \retval bool - Success or not.
93 bool TriToQuad (std::set<const SMDS_MeshElement*> & theElems,
94 SMESH::Controls::NumericalFunctorPtr theCriterion,
95 const double theMaxAngle);
98 * \brief Split quadrangles into triangles.
99 * \param theElems - The faces to be splitted.
100 * \param theCriterion - Is used to choose a diagonal for splitting.
101 * \retval bool - Success or not.
103 bool QuadToTri (std::set<const SMDS_MeshElement*> & theElems,
104 SMESH::Controls::NumericalFunctorPtr theCriterion);
107 * \brief Split quadrangles into triangles.
108 * \param theElems - The faces to be splitted.
109 * \param the13Diag - Is used to choose a diagonal for splitting.
110 * \retval bool - Success or not.
112 bool QuadToTri (std::set<const SMDS_MeshElement*> & theElems,
113 const bool the13Diag);
116 * \brief Find better diagonal for splitting.
117 * \param theQuad - The face to find better splitting of.
118 * \param theCriterion - Is used to choose a diagonal for splitting.
119 * \retval int - 1 for 1-3 diagonal, 2 for 2-4, -1 - for errors.
121 int BestSplit (const SMDS_MeshElement* theQuad,
122 SMESH::Controls::NumericalFunctorPtr theCriterion);
125 enum SmoothMethod { LAPLACIAN = 0, CENTROIDAL };
127 void Smooth (std::set<const SMDS_MeshElement*> & theElements,
128 std::set<const SMDS_MeshNode*> & theFixedNodes,
129 const SmoothMethod theSmoothMethod,
130 const int theNbIterations,
131 double theTgtAspectRatio = 1.0,
132 const bool the2D = true);
133 // Smooth theElements using theSmoothMethod during theNbIterations
134 // or until a worst element has aspect ratio <= theTgtAspectRatio.
135 // Aspect Ratio varies in range [1.0, inf].
136 // If theElements is empty, the whole mesh is smoothed.
137 // theFixedNodes contains additionally fixed nodes. Nodes built
138 // on edges and boundary nodes are always fixed.
139 // If the2D, smoothing is performed using UV parameters of nodes
140 // on geometrical faces
143 void RotationSweep (std::set<const SMDS_MeshElement*> & theElements,
144 const gp_Ax1& theAxis,
145 const double theAngle,
146 const int theNbSteps,
147 const double theToler);
148 // Generate new elements by rotation of theElements around theAxis
149 // by theAngle by theNbSteps
152 * Auxilary flag for advanced extrusion.
153 * BOUNDARY: create or not boundary for result of extrusion
154 * SEW: try to use existing nodes or create new nodes in any case
156 enum ExtrusionFlags {
157 EXTRUSION_FLAG_BOUNDARY = 0x01,
158 EXTRUSION_FLAG_SEW = 0x02
162 * special structire for control of extrusion functionality
165 gp_Dir myDir; // direction of extrusion
166 Handle(TColStd_HSequenceOfReal) mySteps; // magnitudes for each step
167 SMESH_SequenceOfNode myNodes; // nodes for using in sewing
171 * Create new node in the mesh with given coordinates
172 * (auxilary for advanced extrusion)
174 const SMDS_MeshNode* CreateNode(const double x,
177 const double tolnode,
178 SMESH_SequenceOfNode& aNodes);
181 * Generate new elements by extrusion of theElements
182 * It is a method used in .idl file. All functionality
183 * is implemented in the next method (see below) which
184 * is used in the cuurent method.
185 * param theElems - list of elements for extrusion
186 * param newElemsMap returns history of extrusion
187 * param theFlags set flags for performing extrusion (see description
188 * of enum ExtrusionFlags for additional information)
189 * param theTolerance - uses for comparing locations of nodes if flag
190 * EXTRUSION_FLAG_SEW is set
193 (set<const SMDS_MeshElement*> & theElems,
194 const gp_Vec& theStep,
195 const int theNbSteps,
196 TElemOfElemListMap& newElemsMap,
197 const int theFlags = EXTRUSION_FLAG_BOUNDARY,
198 const double theTolerance = 1.e-6);
201 * Generate new elements by extrusion of theElements
202 * param theElems - list of elements for extrusion
203 * param newElemsMap returns history of extrusion
204 * param theFlags set flags for performing extrusion (see description
205 * of enum ExtrusionFlags for additional information)
206 * param theTolerance - uses for comparing locations of nodes if flag
207 * EXTRUSION_FLAG_SEW is set
208 * param theParams - special structure for manage of extrusion
210 void ExtrusionSweep (set<const SMDS_MeshElement*> & theElems,
211 ExtrusParam& theParams,
212 TElemOfElemListMap& newElemsMap,
214 const double theTolerance);
217 // Generate new elements by extrusion of theElements
218 // by theStep by theNbSteps
220 enum Extrusion_Error {
225 EXTR_BAD_STARTING_NODE,
226 EXTR_BAD_ANGLES_NUMBER,
227 EXTR_CANT_GET_TANGENT
230 Extrusion_Error ExtrusionAlongTrack (std::set<const SMDS_MeshElement*> & theElements,
231 SMESH_subMesh* theTrackPattern,
232 const SMDS_MeshNode* theNodeStart,
233 const bool theHasAngles,
234 std::list<double>& theAngles,
235 const bool theHasRefPoint,
236 const gp_Pnt& theRefPoint);
237 // Generate new elements by extrusion of theElements along path given by theTrackPattern,
238 // theHasAngles are the rotation angles, base point can be given by theRefPoint
240 void Transform (std::set<const SMDS_MeshElement*> & theElements,
241 const gp_Trsf& theTrsf,
243 // Move or copy theElements applying theTrsf to their nodes
245 typedef std::list< std::list< const SMDS_MeshNode* > > TListOfListOfNodes;
247 void FindCoincidentNodes (std::set<const SMDS_MeshNode*> & theNodes,
248 const double theTolerance,
249 TListOfListOfNodes & theGroupsOfNodes);
250 // Return list of group of nodes close to each other within theTolerance.
251 // Search among theNodes or in the whole mesh if theNodes is empty.
253 int SimplifyFace (const vector<const SMDS_MeshNode *> faceNodes,
254 vector<const SMDS_MeshNode *>& poly_nodes,
255 vector<int>& quantities) const;
256 // Split face, defined by <faceNodes>, into several faces by repeating nodes.
257 // Is used by MergeNodes()
259 void MergeNodes (TListOfListOfNodes & theNodeGroups);
260 // In each group, the cdr of nodes are substituted by the first one
263 void MergeEqualElements();
264 // Remove all but one of elements built on the same nodes.
265 // Return nb of successfully merged groups.
267 static bool CheckFreeBorderNodes(const SMDS_MeshNode* theNode1,
268 const SMDS_MeshNode* theNode2,
269 const SMDS_MeshNode* theNode3 = 0);
270 // Return true if the three nodes are on a free border
274 // for SewFreeBorder()
275 SEW_BORDER1_NOT_FOUND,
276 SEW_BORDER2_NOT_FOUND,
277 SEW_BOTH_BORDERS_NOT_FOUND,
279 SEW_VOLUMES_TO_SPLIT,
280 // for SewSideElements()
281 SEW_DIFF_NB_OF_ELEMENTS,
282 SEW_TOPO_DIFF_SETS_OF_ELEMENTS,
288 Sew_Error SewFreeBorder (const SMDS_MeshNode* theBorderFirstNode,
289 const SMDS_MeshNode* theBorderSecondNode,
290 const SMDS_MeshNode* theBorderLastNode,
291 const SMDS_MeshNode* theSide2FirstNode,
292 const SMDS_MeshNode* theSide2SecondNode,
293 const SMDS_MeshNode* theSide2ThirdNode = 0,
294 const bool theSide2IsFreeBorder = true,
295 const bool toCreatePolygons = false,
296 const bool toCreatePolyedrs = false);
297 // Sew the free border to the side2 by replacing nodes in
298 // elements on the free border with nodes of the elements
299 // of the side 2. If nb of links in the free border and
300 // between theSide2FirstNode and theSide2LastNode are different,
301 // additional nodes are inserted on a link provided that no
302 // volume elements share the splitted link.
303 // The side 2 is a free border if theSide2IsFreeBorder == true.
304 // Sewing is peformed between the given first, second and last
305 // nodes on the sides.
306 // theBorderFirstNode is merged with theSide2FirstNode.
307 // if (!theSide2IsFreeBorder) then theSide2SecondNode gives
308 // the last node on the side 2, which will be merged with
309 // theBorderLastNode.
310 // if (theSide2IsFreeBorder) then theSide2SecondNode will
311 // be merged with theBorderSecondNode.
312 // if (theSide2IsFreeBorder && theSide2ThirdNode == 0) then
313 // the 2 free borders are sewn link by link and no additional
314 // nodes are inserted.
315 // Return false, if sewing failed.
317 Sew_Error SewSideElements (std::set<const SMDS_MeshElement*>& theSide1,
318 std::set<const SMDS_MeshElement*>& theSide2,
319 const SMDS_MeshNode* theFirstNode1ToMerge,
320 const SMDS_MeshNode* theFirstNode2ToMerge,
321 const SMDS_MeshNode* theSecondNode1ToMerge,
322 const SMDS_MeshNode* theSecondNode2ToMerge);
323 // Sew two sides of a mesh. Nodes belonging to theSide1 are
324 // merged with nodes of elements of theSide2.
325 // Number of elements in theSide1 and in theSide2 must be
326 // equal and they should have similar node connectivity.
327 // The nodes to merge should belong to side s borders and
328 // the first node should be linked to the second.
330 void InsertNodesIntoLink(const SMDS_MeshElement* theFace,
331 const SMDS_MeshNode* theBetweenNode1,
332 const SMDS_MeshNode* theBetweenNode2,
333 std::list<const SMDS_MeshNode*>& theNodesToInsert,
334 const bool toCreatePoly = false);
335 // insert theNodesToInsert into theFace between theBetweenNode1 and theBetweenNode2.
336 // If toCreatePoly is true, replace theFace by polygon, else split theFace.
338 void UpdateVolumes (const SMDS_MeshNode* theBetweenNode1,
339 const SMDS_MeshNode* theBetweenNode2,
340 std::list<const SMDS_MeshNode*>& theNodesToInsert);
341 // insert theNodesToInsert into all volumes, containing link
342 // theBetweenNode1 - theBetweenNode2, between theBetweenNode1 and theBetweenNode2.
344 // static int SortQuadNodes (const SMDS_Mesh * theMesh,
345 // int theNodeIds[] );
346 // // Set 4 nodes of a quadrangle face in a good order.
347 // // Swap 1<->2 or 2<->3 nodes and correspondingly return
350 // static bool SortHexaNodes (const SMDS_Mesh * theMesh,
351 // int theNodeIds[] );
352 // // Set 8 nodes of a hexahedron in a good order.
353 // // Return success status
355 static void AddToSameGroups (const SMDS_MeshElement* elemToAdd,
356 const SMDS_MeshElement* elemInGroups,
357 SMESHDS_Mesh * aMesh);
358 // Add elemToAdd to the groups the elemInGroups belongs to
360 static const SMDS_MeshElement*
361 FindFaceInSet(const SMDS_MeshNode* n1,
362 const SMDS_MeshNode* n2,
363 const std::set<const SMDS_MeshElement*>& elemSet,
364 const std::set<const SMDS_MeshElement*>& avoidSet);
365 // Return a face having linked nodes n1 and n2 and which is
366 // - not in avoidSet,
367 // - in elemSet provided that !elemSet.empty()
369 int FindShape (const SMDS_MeshElement * theElem);
370 // Return an index of the shape theElem is on
371 // or zero if a shape not found
374 SMESH_Mesh * GetMesh() { return myMesh; }
376 SMESHDS_Mesh * GetMeshDS() { return myMesh->GetMeshDS(); }