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"
39 class SMDS_MeshElement;
46 class SMESH_MeshEditor {
49 SMESH_MeshEditor( SMESH_Mesh* theMesh );
51 bool Remove (const std::list< int >& theElemIDs, const bool isNodes);
52 // Remove a node or an element.
53 // Modify a compute state of sub-meshes which become empty
55 bool InverseDiag (const SMDS_MeshElement * theTria1,
56 const SMDS_MeshElement * theTria2 );
57 // Replace two neighbour triangles with ones built on the same 4 nodes
58 // but having other common link.
59 // Return False if args are improper
61 bool InverseDiag (const SMDS_MeshNode * theNode1,
62 const SMDS_MeshNode * theNode2 );
63 // Replace two neighbour triangles sharing theNode1-theNode2 link
64 // with ones built on the same 4 nodes but having other common link.
65 // Return false if proper faces not found
67 bool DeleteDiag (const SMDS_MeshNode * theNode1,
68 const SMDS_MeshNode * theNode2 );
69 // Replace two neighbour triangles sharing theNode1-theNode2 link
70 // with a quadrangle built on the same 4 nodes.
71 // Return false if proper faces not found
73 bool Reorient (const SMDS_MeshElement * theElement);
74 // Reverse theElement orientation
77 bool TriToQuad (std::set<const SMDS_MeshElement*> & theElems,
78 SMESH::Controls::NumericalFunctorPtr theCriterion,
79 const double theMaxAngle);
80 // Fuse neighbour triangles into quadrangles.
81 // theCriterion is used to choose a neighbour to fuse with.
82 // theMaxAngle is a max angle between element normals at which
83 // fusion is still performed; theMaxAngle is mesured in radians.
85 bool QuadToTri (std::set<const SMDS_MeshElement*> & theElems,
86 SMESH::Controls::NumericalFunctorPtr theCriterion);
87 // Cut quadrangles into triangles.
88 // theCriterion is used to choose a diagonal to cut
90 bool QuadToTri (std::set<const SMDS_MeshElement*> & theElems,
91 const bool the13Diag);
92 // Cut quadrangles into triangles
95 enum SmoothMethod { LAPLACIAN = 0, CENTROIDAL };
97 void Smooth (std::set<const SMDS_MeshElement*> & theElements,
98 std::set<const SMDS_MeshNode*> & theFixedNodes,
99 const SmoothMethod theSmoothMethod,
100 const int theNbIterations,
101 double theTgtAspectRatio = 1.0,
102 const bool the2D = true);
103 // Smooth theElements using theSmoothMethod during theNbIterations
104 // or until a worst element has aspect ratio <= theTgtAspectRatio.
105 // Aspect Ratio varies in range [1.0, inf].
106 // If theElements is empty, the whole mesh is smoothed.
107 // theFixedNodes contains additionally fixed nodes. Nodes built
108 // on edges and boundary nodes are always fixed.
109 // If the2D, smoothing is performed using UV parameters of nodes
110 // on geometrical faces
113 void RotationSweep (std::set<const SMDS_MeshElement*> & theElements,
114 const gp_Ax1& theAxis,
115 const double theAngle,
116 const int theNbSteps,
117 const double theToler);
118 // Generate new elements by rotation of theElements around theAxis
119 // by theAngle by theNbSteps
121 void ExtrusionSweep (std::set<const SMDS_MeshElement*> & theElements,
122 const gp_Vec& theStep,
123 const int theNbSteps);
124 // Generate new elements by extrusion of theElements
125 // by theStep by theNbSteps
127 enum Extrusion_Error {
132 EXTR_BAD_STARTING_NODE,
133 EXTR_BAD_ANGLES_NUMBER,
134 EXTR_CANT_GET_TANGENT
137 Extrusion_Error ExtrusionAlongTrack (std::set<const SMDS_MeshElement*> & theElements,
138 SMESH_subMesh* theTrackPattern,
139 const SMDS_MeshNode* theNodeStart,
140 const bool theHasAngles,
141 std::list<double>& theAngles,
142 const bool theHasRefPoint,
143 const gp_Pnt& theRefPoint);
144 // Generate new elements by extrusion of theElements along path given by theTrackPattern,
145 // theHasAngles are the rotation angles, base point can be given by theRefPoint
147 void Transform (std::set<const SMDS_MeshElement*> & theElements,
148 const gp_Trsf& theTrsf,
150 // Move or copy theElements applying theTrsf to their nodes
152 typedef std::list< std::list< const SMDS_MeshNode* > > TListOfListOfNodes;
154 void FindCoincidentNodes (std::set<const SMDS_MeshNode*> & theNodes,
155 const double theTolerance,
156 TListOfListOfNodes & theGroupsOfNodes);
157 // Return list of group of nodes close to each other within theTolerance.
158 // Search among theNodes or in the whole mesh if theNodes is empty.
160 int SimplifyFace (const vector<const SMDS_MeshNode *> faceNodes,
161 vector<const SMDS_MeshNode *>& poly_nodes,
162 vector<int>& quantities) const;
163 // Split face, defined by <faceNodes>, into several faces by repeating nodes.
164 // Is used by MergeNodes()
166 void MergeNodes (TListOfListOfNodes & theNodeGroups);
167 // In each group, the cdr of nodes are substituted by the first one
170 void MergeEqualElements();
171 // Remove all but one of elements built on the same nodes.
172 // Return nb of successfully merged groups.
174 static bool CheckFreeBorderNodes(const SMDS_MeshNode* theNode1,
175 const SMDS_MeshNode* theNode2,
176 const SMDS_MeshNode* theNode3 = 0);
177 // Return true if the three nodes are on a free border
181 // for SewFreeBorder()
182 SEW_BORDER1_NOT_FOUND,
183 SEW_BORDER2_NOT_FOUND,
184 SEW_BOTH_BORDERS_NOT_FOUND,
186 SEW_VOLUMES_TO_SPLIT,
187 // for SewSideElements()
188 SEW_DIFF_NB_OF_ELEMENTS,
189 SEW_TOPO_DIFF_SETS_OF_ELEMENTS,
195 Sew_Error SewFreeBorder (const SMDS_MeshNode* theBorderFirstNode,
196 const SMDS_MeshNode* theBorderSecondNode,
197 const SMDS_MeshNode* theBorderLastNode,
198 const SMDS_MeshNode* theSide2FirstNode,
199 const SMDS_MeshNode* theSide2SecondNode,
200 const SMDS_MeshNode* theSide2ThirdNode = 0,
201 const bool theSide2IsFreeBorder = true,
202 const bool toCreatePolygons = false,
203 const bool toCreatePolyedrs = false);
204 // Sew the free border to the side2 by replacing nodes in
205 // elements on the free border with nodes of the elements
206 // of the side 2. If nb of links in the free border and
207 // between theSide2FirstNode and theSide2LastNode are different,
208 // additional nodes are inserted on a link provided that no
209 // volume elements share the splitted link.
210 // The side 2 is a free border if theSide2IsFreeBorder == true.
211 // Sewing is peformed between the given first, second and last
212 // nodes on the sides.
213 // theBorderFirstNode is merged with theSide2FirstNode.
214 // if (!theSide2IsFreeBorder) then theSide2SecondNode gives
215 // the last node on the side 2, which will be merged with
216 // theBorderLastNode.
217 // if (theSide2IsFreeBorder) then theSide2SecondNode will
218 // be merged with theBorderSecondNode.
219 // if (theSide2IsFreeBorder && theSide2ThirdNode == 0) then
220 // the 2 free borders are sewn link by link and no additional
221 // nodes are inserted.
222 // Return false, if sewing failed.
224 Sew_Error SewSideElements (std::set<const SMDS_MeshElement*>& theSide1,
225 std::set<const SMDS_MeshElement*>& theSide2,
226 const SMDS_MeshNode* theFirstNode1ToMerge,
227 const SMDS_MeshNode* theFirstNode2ToMerge,
228 const SMDS_MeshNode* theSecondNode1ToMerge,
229 const SMDS_MeshNode* theSecondNode2ToMerge);
230 // Sew two sides of a mesh. Nodes belonging to theSide1 are
231 // merged with nodes of elements of theSide2.
232 // Number of elements in theSide1 and in theSide2 must be
233 // equal and they should have similar node connectivity.
234 // The nodes to merge should belong to side s borders and
235 // the first node should be linked to the second.
237 void InsertNodesIntoLink(const SMDS_MeshElement* theFace,
238 const SMDS_MeshNode* theBetweenNode1,
239 const SMDS_MeshNode* theBetweenNode2,
240 std::list<const SMDS_MeshNode*>& theNodesToInsert,
241 const bool toCreatePoly = false);
242 // insert theNodesToInsert into theFace between theBetweenNode1 and theBetweenNode2.
243 // If toCreatePoly is true, replace theFace by polygon, else split theFace.
245 void UpdateVolumes (const SMDS_MeshNode* theBetweenNode1,
246 const SMDS_MeshNode* theBetweenNode2,
247 std::list<const SMDS_MeshNode*>& theNodesToInsert);
248 // insert theNodesToInsert into all volumes, containing link
249 // theBetweenNode1 - theBetweenNode2, between theBetweenNode1 and theBetweenNode2.
251 // static int SortQuadNodes (const SMDS_Mesh * theMesh,
252 // int theNodeIds[] );
253 // // Set 4 nodes of a quadrangle face in a good order.
254 // // Swap 1<->2 or 2<->3 nodes and correspondingly return
257 // static bool SortHexaNodes (const SMDS_Mesh * theMesh,
258 // int theNodeIds[] );
259 // // Set 8 nodes of a hexahedron in a good order.
260 // // Return success status
262 static void AddToSameGroups (const SMDS_MeshElement* elemToAdd,
263 const SMDS_MeshElement* elemInGroups,
264 SMESHDS_Mesh * aMesh);
265 // Add elemToAdd to the groups the elemInGroups belongs to
267 static const SMDS_MeshElement*
268 FindFaceInSet(const SMDS_MeshNode* n1,
269 const SMDS_MeshNode* n2,
270 const std::set<const SMDS_MeshElement*>& elemSet,
271 const std::set<const SMDS_MeshElement*>& avoidSet);
272 // Return a face having linked nodes n1 and n2 and which is
273 // - not in avoidSet,
274 // - in elemSet provided that !elemSet.empty()
276 int FindShape (const SMDS_MeshElement * theElem);
277 // Return an index of the shape theElem is on
278 // or zero if a shape not found
281 SMESH_Mesh * GetMesh() { return myMesh; }
283 SMESHDS_Mesh * GetMeshDS() { return myMesh->GetMeshDS(); }