Salome HOME
FindCoincidentNodes() now accepts a set on nodes to search between; AddToSameGroup...
[modules/smesh.git] / src / SMESH / SMESH_MeshEditor.hxx
1 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 // File      : SMESH_MeshEditor.hxx
25 // Created   : Mon Apr 12 14:56:19 2004
26 // Author    : Edward AGAPOV (eap)
27 // Module    : SMESH
28
29
30 #ifndef SMESH_MeshEditor_HeaderFile
31 #define SMESH_MeshEditor_HeaderFile
32
33 #include "SMESH_Mesh.hxx"
34 #include "SMESH_Controls.hxx"
35
36 #include <list>
37 #include <map>
38
39 class SMDS_MeshElement;
40 class SMDS_MeshFace;
41 class SMDS_MeshNode;
42 class gp_Ax1;
43 class gp_Vec;
44
45 class SMESH_MeshEditor {
46  public:
47
48   SMESH_MeshEditor( SMESH_Mesh* theMesh );
49
50   bool Remove (const std::list< int >& theElemIDs, const bool isNodes);
51   // Remove a node or an element.
52   // Modify a compute state of sub-meshes which become empty
53
54   bool InverseDiag (const SMDS_MeshElement * theTria1,
55                     const SMDS_MeshElement * theTria2 );
56   // Replace two neighbour triangles with ones built on the same 4 nodes
57   // but having other common link.
58   // Return False if args are improper
59
60   bool InverseDiag (const SMDS_MeshNode * theNode1,
61                     const SMDS_MeshNode * theNode2 );
62   // Replace two neighbour triangles sharing theNode1-theNode2 link
63   // with ones built on the same 4 nodes but having other common link.
64   // Return false if proper faces not found
65
66   bool DeleteDiag (const SMDS_MeshNode * theNode1,
67                    const SMDS_MeshNode * theNode2 );
68   // Replace two neighbour triangles sharing theNode1-theNode2 link
69   // with a quadrangle built on the same 4 nodes.
70   // Return false if proper faces not found
71
72   bool Reorient (const SMDS_MeshElement * theFace);
73   // Reverse the normal of theFace
74   // Return false if theFace is null
75
76
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.
84
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
89
90   bool QuadToTri (std::set<const SMDS_MeshElement*> & theElems,
91                   const bool                          the13Diag);
92   // Cut quadrangles into triangles
93
94
95   enum SmoothMethod { LAPLACIAN = 0, CENTROIDAL };
96
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   // Smooth theElements using theSmoothMethod during theNbIterations
103   // or until a worst element has aspect ratio <= theTgtAspectRatio.
104   // Aspect Ratio varies in range [1.0, inf].
105   // If theElements is empty, the whole mesh is smoothed.
106   // theFixedNodes contains additionally fixed nodes. Nodes built
107   // on edges and boundary nodes are always fixed.
108
109
110   void RotationSweep (std::set<const SMDS_MeshElement*> & theElements,
111                       const gp_Ax1&                       theAxis,
112                       const double                        theAngle,
113                       const int                           theNbSteps,
114                       const double                        theToler);
115   // Generate new elements by rotation of theElements around theAxis
116   // by theAngle by theNbSteps
117
118   void ExtrusionSweep (std::set<const SMDS_MeshElement*> & theElements,
119                        const gp_Vec&                       theStep,
120                        const int                           theNbSteps);
121   // Generate new elements by extrusion of theElements 
122   // by theStep by theNbSteps
123
124
125   void Transform (std::set<const SMDS_MeshElement*> & theElements,
126                   const gp_Trsf&                      theTrsf,
127                   const bool                          theCopy);
128   // Move or copy theElements applying theTrsf to their nodes
129
130
131   typedef std::list< std::list< const SMDS_MeshNode* > > TListOfListOfNodes;
132
133   void FindCoincidentNodes (std::set<const SMDS_MeshNode*> & theNodes,
134                             const double                     theTolerance,
135                             TListOfListOfNodes &             theGroupsOfNodes);
136   // Return list of group of nodes close to each other within theTolerance.
137   // Search among theNodes or in the whole mesh if theNodes is empty.
138
139   void MergeNodes (TListOfListOfNodes & theNodeGroups);
140   // In each group, the cdr of nodes are substituted by the first one
141   // in all elements.
142
143   void MergeEqualElements();
144   // Remove all but one of elements built on the same nodes.
145   // Return nb of successfully merged groups.
146
147   static bool CheckFreeBorderNodes(const SMDS_MeshNode* theNode1,
148                                    const SMDS_MeshNode* theNode2,
149                                    const SMDS_MeshNode* theNode3 = 0);
150   // Return true if the three nodes are on a free border
151
152   enum Sew_Error {
153     SEW_OK,
154     // for SewFreeBorder()
155     SEW_BORDER1_NOT_FOUND,
156     SEW_BORDER2_NOT_FOUND,
157     SEW_BOTH_BORDERS_NOT_FOUND,
158     SEW_BAD_SIDE_NODES,
159     SEW_VOLUMES_TO_SPLIT,
160     // for SewSideElements()
161     SEW_DIFF_NB_OF_ELEMENTS,
162     SEW_TOPO_DIFF_SETS_OF_ELEMENTS,
163     SEW_BAD_SIDE1_NODES,
164     SEW_BAD_SIDE2_NODES
165     };
166     
167
168   Sew_Error SewFreeBorder (const SMDS_MeshNode* theBorderFirstNode,
169                            const SMDS_MeshNode* theBorderSecondNode,
170                            const SMDS_MeshNode* theBorderLastNode,
171                            const SMDS_MeshNode* theSide2FirstNode,
172                            const SMDS_MeshNode* theSide2SecondNode,
173                            const SMDS_MeshNode* theSide2ThirdNode = 0,
174                            bool                 theSide2IsFreeBorder = true);
175   // Sew the free border to the side2 by replacing nodes in
176   // elements on the free border with nodes of the elements
177   // of the side 2. If nb of links in the free border and
178   // between theSide2FirstNode and theSide2LastNode are different,
179   // additional nodes are inserted on a link provided that no
180   // volume elements share the splitted link.
181   // The side 2 is a free border if theSide2IsFreeBorder == true.
182   // Sewing is peformed between the given first, second and last
183   // nodes on the sides.
184   // theBorderFirstNode is merged with theSide2FirstNode.
185   // if (!theSide2IsFreeBorder) then theSide2SecondNode gives
186   // the last node on the side 2, which will be merged with
187   // theBorderLastNode.
188   // if (theSide2IsFreeBorder) then theSide2SecondNode will
189   // be merged with theBorderSecondNode.
190   // if (theSide2IsFreeBorder && theSide2ThirdNode == 0) then
191   // the 2 free borders are sewn link by link and no additional
192   // nodes are inserted.
193   // Return false, if sewing failed.
194
195   Sew_Error SewSideElements (std::set<const SMDS_MeshElement*>& theSide1,
196                              std::set<const SMDS_MeshElement*>& theSide2,
197                              const SMDS_MeshNode*               theFirstNode1ToMerge,
198                              const SMDS_MeshNode*               theFirstNode2ToMerge,
199                              const SMDS_MeshNode*               theSecondNode1ToMerge,
200                              const SMDS_MeshNode*               theSecondNode2ToMerge);
201   // Sew two sides of a mesh. Nodes belonging to theSide1 are
202   // merged with nodes of elements of theSide2.
203   // Number of elements in theSide1 and in theSide2 must be
204   // equal and they should have similar node connectivity.
205   // The nodes to merge should belong to side s borders and
206   // the first node should be linked to the second.
207
208   void InsertNodesIntoLink(const SMDS_MeshElement*          theFace,
209                            const SMDS_MeshNode*             theBetweenNode1,
210                            const SMDS_MeshNode*             theBetweenNode2,
211                            std::list<const SMDS_MeshNode*>& theNodesToInsert);
212   // insert theNodesToInsert into theFace between theBetweenNode1
213   // and theBetweenNode2 and split theElement.
214
215   static int SortQuadNodes (const SMDS_Mesh * theMesh,
216                             int               theNodeIds[] );
217   // Set 4 nodes of a quadrangle face in a good order.
218   // Swap 1<->2 or 2<->3 nodes and correspondingly return
219   // 1 or 2 else 0.
220
221   static bool SortHexaNodes (const SMDS_Mesh * theMesh,
222                              int               theNodeIds[] );
223   // Set 8 nodes of a hexahedron in a good order.
224   // Return success status
225
226   static void AddToSameGroups (const SMDS_MeshElement* elemToAdd,
227                                const SMDS_MeshElement* elemInGroups,
228                                SMESHDS_Mesh *          aMesh);
229   // Add elemToAdd to the groups the elemInGroups belongs to
230
231   int FindShape (const SMDS_MeshElement * theElem);
232   // Return an index of the shape theElem is on
233   // or zero if a shape not found
234
235
236   SMESH_Mesh * GetMesh() { return myMesh; }
237
238   SMESHDS_Mesh * GetMeshDS() { return myMesh->GetMeshDS(); }
239
240
241  private:
242
243   SMESH_Mesh * myMesh;
244
245 };
246
247 #endif