Salome HOME
Fix PAL8562: rpath (rpath-link) option needs parameter - directory to search shared...
[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 * theElement);
74   // Reverse theElement orientation
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   enum Extrusion_Error {
125     EXTR_OK,
126     EXTR_NO_ELEMENTS, 
127     EXTR_PATH_NOT_EDGE,
128     EXTR_BAD_PATH_SHAPE,
129     EXTR_BAD_STARTING_NODE,
130     EXTR_BAD_ANGLES_NUMBER,
131     EXTR_CANT_GET_TANGENT
132     };
133   
134   Extrusion_Error ExtrusionAlongTrack (std::set<const SMDS_MeshElement*> & theElements,
135                                        SMESH_subMesh*                      theTrackPattern,
136                                        const SMDS_MeshNode*                theNodeStart,
137                                        const bool                          theHasAngles,
138                                        std::list<double>&                  theAngles,
139                                        const bool                          theHasRefPoint,
140                                        const gp_Pnt&                       theRefPoint);
141   // Generate new elements by extrusion of theElements along path given by theTrackPattern,
142   // theHasAngles are the rotation angles, base point can be given by theRefPoint
143
144   void Transform (std::set<const SMDS_MeshElement*> & theElements,
145                   const gp_Trsf&                      theTrsf,
146                   const bool                          theCopy);
147   // Move or copy theElements applying theTrsf to their nodes
148
149   typedef std::list< std::list< const SMDS_MeshNode* > > TListOfListOfNodes;
150
151   void FindCoincidentNodes (std::set<const SMDS_MeshNode*> & theNodes,
152                             const double                     theTolerance,
153                             TListOfListOfNodes &             theGroupsOfNodes);
154   // Return list of group of nodes close to each other within theTolerance.
155   // Search among theNodes or in the whole mesh if theNodes is empty.
156
157   void MergeNodes (TListOfListOfNodes & theNodeGroups);
158   // In each group, the cdr of nodes are substituted by the first one
159   // in all elements.
160
161   void MergeEqualElements();
162   // Remove all but one of elements built on the same nodes.
163   // Return nb of successfully merged groups.
164
165   static bool CheckFreeBorderNodes(const SMDS_MeshNode* theNode1,
166                                    const SMDS_MeshNode* theNode2,
167                                    const SMDS_MeshNode* theNode3 = 0);
168   // Return true if the three nodes are on a free border
169
170   enum Sew_Error {
171     SEW_OK,
172     // for SewFreeBorder()
173     SEW_BORDER1_NOT_FOUND,
174     SEW_BORDER2_NOT_FOUND,
175     SEW_BOTH_BORDERS_NOT_FOUND,
176     SEW_BAD_SIDE_NODES,
177     SEW_VOLUMES_TO_SPLIT,
178     // for SewSideElements()
179     SEW_DIFF_NB_OF_ELEMENTS,
180     SEW_TOPO_DIFF_SETS_OF_ELEMENTS,
181     SEW_BAD_SIDE1_NODES,
182     SEW_BAD_SIDE2_NODES
183     };
184     
185
186   Sew_Error SewFreeBorder (const SMDS_MeshNode* theBorderFirstNode,
187                            const SMDS_MeshNode* theBorderSecondNode,
188                            const SMDS_MeshNode* theBorderLastNode,
189                            const SMDS_MeshNode* theSide2FirstNode,
190                            const SMDS_MeshNode* theSide2SecondNode,
191                            const SMDS_MeshNode* theSide2ThirdNode = 0,
192                            bool                 theSide2IsFreeBorder = true);
193   // Sew the free border to the side2 by replacing nodes in
194   // elements on the free border with nodes of the elements
195   // of the side 2. If nb of links in the free border and
196   // between theSide2FirstNode and theSide2LastNode are different,
197   // additional nodes are inserted on a link provided that no
198   // volume elements share the splitted link.
199   // The side 2 is a free border if theSide2IsFreeBorder == true.
200   // Sewing is peformed between the given first, second and last
201   // nodes on the sides.
202   // theBorderFirstNode is merged with theSide2FirstNode.
203   // if (!theSide2IsFreeBorder) then theSide2SecondNode gives
204   // the last node on the side 2, which will be merged with
205   // theBorderLastNode.
206   // if (theSide2IsFreeBorder) then theSide2SecondNode will
207   // be merged with theBorderSecondNode.
208   // if (theSide2IsFreeBorder && theSide2ThirdNode == 0) then
209   // the 2 free borders are sewn link by link and no additional
210   // nodes are inserted.
211   // Return false, if sewing failed.
212
213   Sew_Error SewSideElements (std::set<const SMDS_MeshElement*>& theSide1,
214                              std::set<const SMDS_MeshElement*>& theSide2,
215                              const SMDS_MeshNode*               theFirstNode1ToMerge,
216                              const SMDS_MeshNode*               theFirstNode2ToMerge,
217                              const SMDS_MeshNode*               theSecondNode1ToMerge,
218                              const SMDS_MeshNode*               theSecondNode2ToMerge);
219   // Sew two sides of a mesh. Nodes belonging to theSide1 are
220   // merged with nodes of elements of theSide2.
221   // Number of elements in theSide1 and in theSide2 must be
222   // equal and they should have similar node connectivity.
223   // The nodes to merge should belong to side s borders and
224   // the first node should be linked to the second.
225
226   void InsertNodesIntoLink(const SMDS_MeshElement*          theFace,
227                            const SMDS_MeshNode*             theBetweenNode1,
228                            const SMDS_MeshNode*             theBetweenNode2,
229                            std::list<const SMDS_MeshNode*>& theNodesToInsert);
230   // insert theNodesToInsert into theFace between theBetweenNode1
231   // and theBetweenNode2 and split theElement.
232
233   static int SortQuadNodes (const SMDS_Mesh * theMesh,
234                             int               theNodeIds[] );
235   // Set 4 nodes of a quadrangle face in a good order.
236   // Swap 1<->2 or 2<->3 nodes and correspondingly return
237   // 1 or 2 else 0.
238
239   static bool SortHexaNodes (const SMDS_Mesh * theMesh,
240                              int               theNodeIds[] );
241   // Set 8 nodes of a hexahedron in a good order.
242   // Return success status
243
244   static void AddToSameGroups (const SMDS_MeshElement* elemToAdd,
245                                const SMDS_MeshElement* elemInGroups,
246                                SMESHDS_Mesh *          aMesh);
247   // Add elemToAdd to the groups the elemInGroups belongs to
248
249   static const SMDS_MeshElement*
250     FindFaceInSet(const SMDS_MeshNode*                     n1,
251                   const SMDS_MeshNode*                     n2,
252                   const std::set<const SMDS_MeshElement*>& elemSet,
253                   const std::set<const SMDS_MeshElement*>& avoidSet);
254   // Return a face having linked nodes n1 and n2 and which is
255   // - not in avoidSet,
256   // - in elemSet provided that !elemSet.empty()
257
258   int FindShape (const SMDS_MeshElement * theElem);
259   // Return an index of the shape theElem is on
260   // or zero if a shape not found
261
262
263   SMESH_Mesh * GetMesh() { return myMesh; }
264
265   SMESHDS_Mesh * GetMeshDS() { return myMesh->GetMeshDS(); }
266
267
268  private:
269
270   SMESH_Mesh * myMesh;
271
272 };
273
274 #endif