Salome HOME
Merge with OCC_development_01
[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 class gp_Pnt;
45
46 class SMESH_MeshEditor {
47  public:
48
49   SMESH_MeshEditor( SMESH_Mesh* theMesh );
50
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
54
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
60
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
66
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
72
73   bool Reorient (const SMDS_MeshElement * theFace);
74   // Reverse the normal of theFace
75   // Return false if theFace is null
76
77
78   bool TriToQuad (std::set<const SMDS_MeshElement*> &  theElems,
79                   SMESH::Controls::NumericalFunctorPtr theCriterion,
80                   const double                         theMaxAngle);
81   // Fuse neighbour triangles into quadrangles.
82   // theCriterion is used to choose a neighbour to fuse with.
83   // theMaxAngle is a max angle between element normals at which
84   // fusion is still performed; theMaxAngle is mesured in radians.
85
86   bool QuadToTri (std::set<const SMDS_MeshElement*> &  theElems,
87                   SMESH::Controls::NumericalFunctorPtr theCriterion);
88   // Cut quadrangles into triangles.
89   // theCriterion is used to choose a diagonal to cut
90
91   bool QuadToTri (std::set<const SMDS_MeshElement*> & theElems,
92                   const bool                          the13Diag);
93   // Cut quadrangles into triangles
94
95
96   enum SmoothMethod { LAPLACIAN = 0, CENTROIDAL };
97
98   void Smooth (std::set<const SMDS_MeshElement*> & theElements,
99                std::set<const SMDS_MeshNode*> &    theFixedNodes,
100                const SmoothMethod                  theSmoothMethod,
101                const int                           theNbIterations,
102                double                              theTgtAspectRatio = 1.0);
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
110
111   void RotationSweep (std::set<const SMDS_MeshElement*> & theElements,
112                       const gp_Ax1&                       theAxis,
113                       const double                        theAngle,
114                       const int                           theNbSteps,
115                       const double                        theToler);
116   // Generate new elements by rotation of theElements around theAxis
117   // by theAngle by theNbSteps
118
119   void ExtrusionSweep (std::set<const SMDS_MeshElement*> & theElements,
120                        const gp_Vec&                       theStep,
121                        const int                           theNbSteps);
122   // Generate new elements by extrusion of theElements 
123   // by theStep by theNbSteps
124
125   int ExtrusionAlongTrack (std::set<const SMDS_MeshElement*> & theElements,
126                            SMESH_subMesh*                      theTrackPattern,
127                            const SMDS_MeshNode*                theNodeStart,
128                            const bool                          theHasAngles,
129                            std::list<double>&                  theAngles,
130                            const bool                          theHasRefPoint,
131                            const gp_Pnt&                       theRefPoint);
132   // Generate new elements by extrusion of theElements along path given by theTrackPattern,
133   // theHasAngles are the rotation angles, base point can be given by theRefPoint
134
135   void Transform (std::set<const SMDS_MeshElement*> & theElements,
136                   const gp_Trsf&                      theTrsf,
137                   const bool                          theCopy);
138   // Move or copy theElements applying theTrsf to their nodes
139
140   typedef std::list< std::list< const SMDS_MeshNode* > > TListOfListOfNodes;
141
142   void FindCoincidentNodes (std::set<const SMDS_MeshNode*> & theNodes,
143                             const double                     theTolerance,
144                             TListOfListOfNodes &             theGroupsOfNodes);
145   // Return list of group of nodes close to each other within theTolerance.
146   // Search among theNodes or in the whole mesh if theNodes is empty.
147
148   void MergeNodes (TListOfListOfNodes & theNodeGroups);
149   // In each group, the cdr of nodes are substituted by the first one
150   // in all elements.
151
152   void MergeEqualElements();
153   // Remove all but one of elements built on the same nodes.
154   // Return nb of successfully merged groups.
155
156   static bool CheckFreeBorderNodes(const SMDS_MeshNode* theNode1,
157                                    const SMDS_MeshNode* theNode2,
158                                    const SMDS_MeshNode* theNode3 = 0);
159   // Return true if the three nodes are on a free border
160
161   enum Sew_Error {
162     SEW_OK,
163     // for SewFreeBorder()
164     SEW_BORDER1_NOT_FOUND,
165     SEW_BORDER2_NOT_FOUND,
166     SEW_BOTH_BORDERS_NOT_FOUND,
167     SEW_BAD_SIDE_NODES,
168     SEW_VOLUMES_TO_SPLIT,
169     // for SewSideElements()
170     SEW_DIFF_NB_OF_ELEMENTS,
171     SEW_TOPO_DIFF_SETS_OF_ELEMENTS,
172     SEW_BAD_SIDE1_NODES,
173     SEW_BAD_SIDE2_NODES
174     };
175     
176
177   Sew_Error SewFreeBorder (const SMDS_MeshNode* theBorderFirstNode,
178                            const SMDS_MeshNode* theBorderSecondNode,
179                            const SMDS_MeshNode* theBorderLastNode,
180                            const SMDS_MeshNode* theSide2FirstNode,
181                            const SMDS_MeshNode* theSide2SecondNode,
182                            const SMDS_MeshNode* theSide2ThirdNode = 0,
183                            bool                 theSide2IsFreeBorder = true);
184   // Sew the free border to the side2 by replacing nodes in
185   // elements on the free border with nodes of the elements
186   // of the side 2. If nb of links in the free border and
187   // between theSide2FirstNode and theSide2LastNode are different,
188   // additional nodes are inserted on a link provided that no
189   // volume elements share the splitted link.
190   // The side 2 is a free border if theSide2IsFreeBorder == true.
191   // Sewing is peformed between the given first, second and last
192   // nodes on the sides.
193   // theBorderFirstNode is merged with theSide2FirstNode.
194   // if (!theSide2IsFreeBorder) then theSide2SecondNode gives
195   // the last node on the side 2, which will be merged with
196   // theBorderLastNode.
197   // if (theSide2IsFreeBorder) then theSide2SecondNode will
198   // be merged with theBorderSecondNode.
199   // if (theSide2IsFreeBorder && theSide2ThirdNode == 0) then
200   // the 2 free borders are sewn link by link and no additional
201   // nodes are inserted.
202   // Return false, if sewing failed.
203
204   Sew_Error SewSideElements (std::set<const SMDS_MeshElement*>& theSide1,
205                              std::set<const SMDS_MeshElement*>& theSide2,
206                              const SMDS_MeshNode*               theFirstNode1ToMerge,
207                              const SMDS_MeshNode*               theFirstNode2ToMerge,
208                              const SMDS_MeshNode*               theSecondNode1ToMerge,
209                              const SMDS_MeshNode*               theSecondNode2ToMerge);
210   // Sew two sides of a mesh. Nodes belonging to theSide1 are
211   // merged with nodes of elements of theSide2.
212   // Number of elements in theSide1 and in theSide2 must be
213   // equal and they should have similar node connectivity.
214   // The nodes to merge should belong to side s borders and
215   // the first node should be linked to the second.
216
217   void InsertNodesIntoLink(const SMDS_MeshElement*          theFace,
218                            const SMDS_MeshNode*             theBetweenNode1,
219                            const SMDS_MeshNode*             theBetweenNode2,
220                            std::list<const SMDS_MeshNode*>& theNodesToInsert);
221   // insert theNodesToInsert into theFace between theBetweenNode1
222   // and theBetweenNode2 and split theElement.
223
224   static int SortQuadNodes (const SMDS_Mesh * theMesh,
225                             int               theNodeIds[] );
226   // Set 4 nodes of a quadrangle face in a good order.
227   // Swap 1<->2 or 2<->3 nodes and correspondingly return
228   // 1 or 2 else 0.
229
230   static bool SortHexaNodes (const SMDS_Mesh * theMesh,
231                              int               theNodeIds[] );
232   // Set 8 nodes of a hexahedron in a good order.
233   // Return success status
234
235   static void AddToSameGroups (const SMDS_MeshElement* elemToAdd,
236                                const SMDS_MeshElement* elemInGroups,
237                                SMESHDS_Mesh *          aMesh);
238   // Add elemToAdd to the groups the elemInGroups belongs to
239
240   static const SMDS_MeshElement*
241     FindFaceInSet(const SMDS_MeshNode*                     n1,
242                   const SMDS_MeshNode*                     n2,
243                   const std::set<const SMDS_MeshElement*>& elemSet,
244                   const std::set<const SMDS_MeshElement*>& avoidSet);
245   // Return a face having linked nodes n1 and n2 and which is
246   // - not in avoidSet,
247   // - in elemSet provided that !elemSet.empty()
248
249   int FindShape (const SMDS_MeshElement * theElem);
250   // Return an index of the shape theElem is on
251   // or zero if a shape not found
252
253
254   SMESH_Mesh * GetMesh() { return myMesh; }
255
256   SMESHDS_Mesh * GetMeshDS() { return myMesh->GetMeshDS(); }
257
258
259  private:
260
261   SMESH_Mesh * myMesh;
262
263 };
264
265 #endif