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