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"
38 //#include <TColStd_DataMapOfIntegerListOfInteger.hxx>
39 #include <SMESH_DataMapOfElemPtrSequenceOfElemPtr.hxx>
41 class SMDS_MeshElement;
48 class SMESH_MeshEditor {
51 SMESH_MeshEditor( SMESH_Mesh* theMesh );
53 bool Remove (const std::list< int >& theElemIDs, const bool isNodes);
54 // Remove a node or an element.
55 // Modify a compute state of sub-meshes which become empty
57 bool InverseDiag (const SMDS_MeshElement * theTria1,
58 const SMDS_MeshElement * theTria2 );
59 // Replace two neighbour triangles with ones built on the same 4 nodes
60 // but having other common link.
61 // Return False if args are improper
63 bool InverseDiag (const SMDS_MeshNode * theNode1,
64 const SMDS_MeshNode * theNode2 );
65 // Replace two neighbour triangles sharing theNode1-theNode2 link
66 // with ones built on the same 4 nodes but having other common link.
67 // Return false if proper faces not found
69 bool DeleteDiag (const SMDS_MeshNode * theNode1,
70 const SMDS_MeshNode * theNode2 );
71 // Replace two neighbour triangles sharing theNode1-theNode2 link
72 // with a quadrangle built on the same 4 nodes.
73 // Return false if proper faces not found
75 bool Reorient (const SMDS_MeshElement * theElement);
76 // Reverse theElement orientation
80 * \brief Fuse neighbour triangles into quadrangles.
81 * \param theElems - The triangles to be fused.
82 * \param theCriterion - Is used to choose a neighbour to fuse with.
83 * \param theMaxAngle - Is a max angle between element normals at which fusion
84 * is still performed; theMaxAngle is mesured in radians.
85 * \retval bool - Success or not.
87 bool TriToQuad (std::set<const SMDS_MeshElement*> & theElems,
88 SMESH::Controls::NumericalFunctorPtr theCriterion,
89 const double theMaxAngle);
92 * \brief Split quadrangles into triangles.
93 * \param theElems - The faces to be splitted.
94 * \param theCriterion - Is used to choose a diagonal for splitting.
95 * \retval bool - Success or not.
97 bool QuadToTri (std::set<const SMDS_MeshElement*> & theElems,
98 SMESH::Controls::NumericalFunctorPtr theCriterion);
101 * \brief Split quadrangles into triangles.
102 * \param theElems - The faces to be splitted.
103 * \param the13Diag - Is used to choose a diagonal for splitting.
104 * \retval bool - Success or not.
106 bool QuadToTri (std::set<const SMDS_MeshElement*> & theElems,
107 const bool the13Diag);
110 * \brief Find better diagonal for splitting.
111 * \param theQuad - The face to find better splitting of.
112 * \param theCriterion - Is used to choose a diagonal for splitting.
113 * \retval int - 1 for 1-3 diagonal, 2 for 2-4, -1 - for errors.
115 int BestSplit (const SMDS_MeshElement* theQuad,
116 SMESH::Controls::NumericalFunctorPtr theCriterion);
119 enum SmoothMethod { LAPLACIAN = 0, CENTROIDAL };
121 void Smooth (std::set<const SMDS_MeshElement*> & theElements,
122 std::set<const SMDS_MeshNode*> & theFixedNodes,
123 const SmoothMethod theSmoothMethod,
124 const int theNbIterations,
125 double theTgtAspectRatio = 1.0,
126 const bool the2D = true);
127 // Smooth theElements using theSmoothMethod during theNbIterations
128 // or until a worst element has aspect ratio <= theTgtAspectRatio.
129 // Aspect Ratio varies in range [1.0, inf].
130 // If theElements is empty, the whole mesh is smoothed.
131 // theFixedNodes contains additionally fixed nodes. Nodes built
132 // on edges and boundary nodes are always fixed.
133 // If the2D, smoothing is performed using UV parameters of nodes
134 // on geometrical faces
137 void RotationSweep (std::set<const SMDS_MeshElement*> & theElements,
138 const gp_Ax1& theAxis,
139 const double theAngle,
140 const int theNbSteps,
141 const double theToler);
142 // Generate new elements by rotation of theElements around theAxis
143 // by theAngle by theNbSteps
145 void ExtrusionSweep (std::set<const SMDS_MeshElement*> & theElements,
146 const gp_Vec& theStep,
147 const int theNbSteps);
148 // Generate new elements by extrusion of theElements
149 // by theStep by theNbSteps
151 enum Extrusion_Error {
156 EXTR_BAD_STARTING_NODE,
157 EXTR_BAD_ANGLES_NUMBER,
158 EXTR_CANT_GET_TANGENT
161 Extrusion_Error ExtrusionAlongTrack (std::set<const SMDS_MeshElement*> & theElements,
162 SMESH_subMesh* theTrackPattern,
163 const SMDS_MeshNode* theNodeStart,
164 const bool theHasAngles,
165 std::list<double>& theAngles,
166 const bool theHasRefPoint,
167 const gp_Pnt& theRefPoint);
168 // Generate new elements by extrusion of theElements along path given by theTrackPattern,
169 // theHasAngles are the rotation angles, base point can be given by theRefPoint
171 void Transform (std::set<const SMDS_MeshElement*> & theElements,
172 const gp_Trsf& theTrsf,
174 // Move or copy theElements applying theTrsf to their nodes
176 typedef std::list< std::list< const SMDS_MeshNode* > > TListOfListOfNodes;
178 void FindCoincidentNodes (std::set<const SMDS_MeshNode*> & theNodes,
179 const double theTolerance,
180 TListOfListOfNodes & theGroupsOfNodes);
181 // Return list of group of nodes close to each other within theTolerance.
182 // Search among theNodes or in the whole mesh if theNodes is empty.
184 int SimplifyFace (const vector<const SMDS_MeshNode *> faceNodes,
185 vector<const SMDS_MeshNode *>& poly_nodes,
186 vector<int>& quantities) const;
187 // Split face, defined by <faceNodes>, into several faces by repeating nodes.
188 // Is used by MergeNodes()
190 void MergeNodes (TListOfListOfNodes & theNodeGroups);
191 // In each group, the cdr of nodes are substituted by the first one
194 void MergeEqualElements();
195 // Remove all but one of elements built on the same nodes.
196 // Return nb of successfully merged groups.
198 static bool CheckFreeBorderNodes(const SMDS_MeshNode* theNode1,
199 const SMDS_MeshNode* theNode2,
200 const SMDS_MeshNode* theNode3 = 0);
201 // Return true if the three nodes are on a free border
205 // for SewFreeBorder()
206 SEW_BORDER1_NOT_FOUND,
207 SEW_BORDER2_NOT_FOUND,
208 SEW_BOTH_BORDERS_NOT_FOUND,
210 SEW_VOLUMES_TO_SPLIT,
211 // for SewSideElements()
212 SEW_DIFF_NB_OF_ELEMENTS,
213 SEW_TOPO_DIFF_SETS_OF_ELEMENTS,
219 Sew_Error SewFreeBorder (const SMDS_MeshNode* theBorderFirstNode,
220 const SMDS_MeshNode* theBorderSecondNode,
221 const SMDS_MeshNode* theBorderLastNode,
222 const SMDS_MeshNode* theSide2FirstNode,
223 const SMDS_MeshNode* theSide2SecondNode,
224 const SMDS_MeshNode* theSide2ThirdNode = 0,
225 const bool theSide2IsFreeBorder = true,
226 const bool toCreatePolygons = false,
227 const bool toCreatePolyedrs = false);
228 // Sew the free border to the side2 by replacing nodes in
229 // elements on the free border with nodes of the elements
230 // of the side 2. If nb of links in the free border and
231 // between theSide2FirstNode and theSide2LastNode are different,
232 // additional nodes are inserted on a link provided that no
233 // volume elements share the splitted link.
234 // The side 2 is a free border if theSide2IsFreeBorder == true.
235 // Sewing is peformed between the given first, second and last
236 // nodes on the sides.
237 // theBorderFirstNode is merged with theSide2FirstNode.
238 // if (!theSide2IsFreeBorder) then theSide2SecondNode gives
239 // the last node on the side 2, which will be merged with
240 // theBorderLastNode.
241 // if (theSide2IsFreeBorder) then theSide2SecondNode will
242 // be merged with theBorderSecondNode.
243 // if (theSide2IsFreeBorder && theSide2ThirdNode == 0) then
244 // the 2 free borders are sewn link by link and no additional
245 // nodes are inserted.
246 // Return false, if sewing failed.
248 Sew_Error SewSideElements (std::set<const SMDS_MeshElement*>& theSide1,
249 std::set<const SMDS_MeshElement*>& theSide2,
250 const SMDS_MeshNode* theFirstNode1ToMerge,
251 const SMDS_MeshNode* theFirstNode2ToMerge,
252 const SMDS_MeshNode* theSecondNode1ToMerge,
253 const SMDS_MeshNode* theSecondNode2ToMerge);
254 // Sew two sides of a mesh. Nodes belonging to theSide1 are
255 // merged with nodes of elements of theSide2.
256 // Number of elements in theSide1 and in theSide2 must be
257 // equal and they should have similar node connectivity.
258 // The nodes to merge should belong to side s borders and
259 // the first node should be linked to the second.
261 void InsertNodesIntoLink(const SMDS_MeshElement* theFace,
262 const SMDS_MeshNode* theBetweenNode1,
263 const SMDS_MeshNode* theBetweenNode2,
264 std::list<const SMDS_MeshNode*>& theNodesToInsert,
265 const bool toCreatePoly = false);
266 // insert theNodesToInsert into theFace between theBetweenNode1 and theBetweenNode2.
267 // If toCreatePoly is true, replace theFace by polygon, else split theFace.
269 void UpdateVolumes (const SMDS_MeshNode* theBetweenNode1,
270 const SMDS_MeshNode* theBetweenNode2,
271 std::list<const SMDS_MeshNode*>& theNodesToInsert);
272 // insert theNodesToInsert into all volumes, containing link
273 // theBetweenNode1 - theBetweenNode2, between theBetweenNode1 and theBetweenNode2.
275 // static int SortQuadNodes (const SMDS_Mesh * theMesh,
276 // int theNodeIds[] );
277 // // Set 4 nodes of a quadrangle face in a good order.
278 // // Swap 1<->2 or 2<->3 nodes and correspondingly return
281 // static bool SortHexaNodes (const SMDS_Mesh * theMesh,
282 // int theNodeIds[] );
283 // // Set 8 nodes of a hexahedron in a good order.
284 // // Return success status
286 static void AddToSameGroups (const SMDS_MeshElement* elemToAdd,
287 const SMDS_MeshElement* elemInGroups,
288 SMESHDS_Mesh * aMesh);
289 // Add elemToAdd to the groups the elemInGroups belongs to
291 static const SMDS_MeshElement*
292 FindFaceInSet(const SMDS_MeshNode* n1,
293 const SMDS_MeshNode* n2,
294 const std::set<const SMDS_MeshElement*>& elemSet,
295 const std::set<const SMDS_MeshElement*>& avoidSet);
296 // Return a face having linked nodes n1 and n2 and which is
297 // - not in avoidSet,
298 // - in elemSet provided that !elemSet.empty()
300 int FindShape (const SMDS_MeshElement * theElem);
301 // Return an index of the shape theElem is on
302 // or zero if a shape not found
305 SMESH_Mesh * GetMesh() { return myMesh; }
307 SMESHDS_Mesh * GetMeshDS() { return myMesh->GetMeshDS(); }
309 const SMESH_DataMapOfElemPtrSequenceOfElemPtr& GetExtrusionHistory() const
310 { return myExtrusionHistory; }
316 SMESH_DataMapOfElemPtrSequenceOfElemPtr myExtrusionHistory;