Salome HOME
Update of CheckDone
[modules/smesh.git] / src / SMDS / SMDS_VolumeTool.hxx
1 // Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH SMDS : implementation of Salome mesh data structure
24 // File      : SMDS_VolumeTool.hxx
25 // Module    : SMESH
26 // Created   : Tue Jul 13 11:27:17 2004
27 // Author    : Edward AGAPOV (eap)
28 //
29 #ifndef SMDS_VolumeTool_HeaderFile
30 #define SMDS_VolumeTool_HeaderFile
31
32 #include "SMESH_SMDS.hxx"
33
34 #include <smIdType.hxx>
35
36 class SMDS_MeshElement;
37 class SMDS_MeshNode;
38 class SMDS_MeshVolume;
39
40 #include <vector>
41 #include <set>
42 #include <map>
43
44 // =========================================================================
45 //
46 // Class providing topological and other information about SMDS_MeshVolume:
47 // allows iteration on faces or, to be precise, on nodes of volume sides;
48 // provides info on nodes connection etc.
49 //
50 // =========================================================================
51
52 class SMDS_EXPORT SMDS_VolumeTool
53 {
54  public:
55
56   enum VolumeType { UNKNOWN = -1, TETRA = 0, PYRAM, PENTA, HEXA,
57                     HEX_PRISM, QUAD_TETRA, QUAD_PYRAM, QUAD_PENTA, QUAD_HEXA,
58                     POLYHEDA, NB_VOLUME_TYPES }; // to keep synchronised with GetSize()!
59
60   SMDS_VolumeTool ();
61   ~SMDS_VolumeTool ();
62   SMDS_VolumeTool( const SMDS_MeshElement* theVolume,
63                    const bool              ignoreCentralNodes = true);
64
65   bool Set( const SMDS_MeshElement*                  theVolume,
66             const bool                               ignoreCentralNodes = true,
67             const std::vector<const SMDS_MeshNode*>* nodes = 0);
68   // Set volume.
69   // Return false if theVolume is not of type SMDSAbs_Volume.
70   // ignoreCentralNodes makes skip nodes at face centers when returning
71   // nodes of faces of SMDSEntity_TriQuad_Hexa.
72   // alternative nodes can be provided
73
74   const SMDS_MeshVolume* Element() const;
75   // return element
76
77   smIdType ID() const;
78   // return element ID
79
80   bool IsPoly() const { return myPolyedre; }
81
82   // -----------------------
83   // general info
84   // -----------------------
85
86   VolumeType GetVolumeType() const;
87
88   bool IsForward() const { return myVolForward; }
89   // Check volume orientation. can be changed by Inverse().
90   // See node order of forward volumes at the file bottom
91
92   void Inverse();
93   // Change nodes order as if the volume changes its orientation:
94   // top and bottom faces are reversed.
95   // Result of IsForward() and methods returning nodes change
96
97   const SMDS_MeshNode** GetNodes() const { return (const SMDS_MeshNode**) &myVolumeNodes[0]; }
98   // Return array of volume nodes
99
100   int NbNodes() const { return (int) myVolumeNodes.size(); }
101   // Return array of volume nodes
102
103   double GetSize() const;
104   // Return element volume
105
106   bool GetBaryCenter (double & X, double & Y, double & Z) const;
107
108   bool IsOut(double X, double Y, double Z, double tol) const;
109   // Classify a point
110
111   // -----------------------
112   // info on node connection
113   // -----------------------
114
115   bool IsLinked (const SMDS_MeshNode* theNode1,
116                  const SMDS_MeshNode* theNode2,
117                  const bool           theIgnoreMediumNodes=false) const;
118   // Return true if theNode1 is linked with theNode2.
119   // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
120
121   bool IsLinked (const int theNode1Index,
122                  const int theNode2Index,
123                  bool      theIgnoreMediumNodes=false) const;
124   // Return true if the node with theNode1Index is linked
125   // with the node with theNode2Index
126   // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
127
128   int GetNodeIndex(const SMDS_MeshNode* theNode) const;
129   // Return an index of theNode
130
131   int GetAllExistingEdges(std::vector<const SMDS_MeshElement*> & edges) const;
132   // Fill vector with boundary edges existing in the mesh
133
134   double MinLinearSize2() const;
135   // Return minimal square distance between connected corner nodes
136
137   double MaxLinearSize2() const;
138   // Return maximal square distance between connected corner nodes
139
140   // -------------
141   // info on faces
142   // -------------
143   // For all elements, 0-th face is bottom based on the first nodes.
144   // For prismatic elements (tetra,hexa,prisms), 1-th face is a top one.
145   // For all elements, side faces follow order of bottom nodes
146
147   void SetExternalNormal ();
148   // Node order in faces  will be so that faces normals are external.
149
150   int NbFaces() const { return myNbFaces; }
151   // Return number of faces of the volume. In the following
152   // methods 0 <= faceIndex < NbFaces()
153
154   int NbFaceNodes( int faceIndex ) const;
155   // Return number of nodes in the array of face nodes
156
157   const int* GetFaceNodesIndices( int faceIndex ) const;
158   // Return the array of face nodes indices
159   // To comfort link iteration, the array
160   // length == NbFaceNodes( faceIndex ) + 1 and
161   // the last node index == the first one, except for
162   // SMDSEntity_TriQuad_Hexa at ignoreCentralNodes==false.
163   // NOTE: for the quadratic volume, node indices are in the order the nodes encounter
164   // in face boundary and not the order they are in the mesh face
165
166   const SMDS_MeshNode** GetFaceNodes( int faceIndex ) const;
167   // Return the array of face nodes.
168   // To comfort link iteration, the array
169   // length == NbFaceNodes( faceIndex ) + 1 and
170   // the last node == the first one, except for
171   // SMDSEntity_TriQuad_Hexa at ignoreCentralNodes==false.
172   // NOTE: for the quadratic volume, nodes are in the order they encounter in face boundary
173   // and not the order they are in the mesh face
174   // WARNING: do not modify the array, some methods
175   //          work basing on its contents
176
177   bool GetFaceNodes (int faceIndex,
178                      std::set<const SMDS_MeshNode*>& theFaceNodes ) const;
179   // Return a set of face nodes.
180
181   bool IsFaceExternal( int faceIndex ) const;
182   // Check normal orientation of a face.
183   // SetExternalNormal() is taken into account.
184
185   bool IsFreeFace(  int faceIndex, const SMDS_MeshElement** otherVol=0 ) const;
186   // Fast check that only one volume is built on nodes of a given face
187   // otherVol returns another volume sharing the given facet
188
189   bool IsFreeFaceAdv(  int faceIndex, const SMDS_MeshElement** otherVol=0 ) const;
190   // Thorough check that all volumes built on the face nodes lays on one side
191   // otherVol returns another volume sharing the given facet
192
193   bool GetFaceNormal (int faceIndex, double & X, double & Y, double & Z) const;
194   // Return a normal to a face
195
196   bool GetFaceBaryCenter (int faceIndex, double & X, double & Y, double & Z) const;
197   // Return barycenter of a face
198
199   double GetFaceArea( int faceIndex ) const;
200   // Return face area
201
202   int GetOppFaceIndex( int faceIndex ) const;
203   // Return index of the opposite face if it exists, else -1.
204
205   int GetCenterNodeIndex( int faceIndex ) const;
206   // Return index of the node located at face center of a quadratic element like HEX27
207
208   int GetFaceIndex( const std::set<const SMDS_MeshNode*>& theFaceNodes,
209                     const int                             theFaceIndexHint=-1) const;
210   // Return index of a face formed by theFaceNodes.
211   // Return -1 if a face not found
212
213   //int GetFaceIndex( const std::set<int>& theFaceNodesIndices );
214   // Return index of a face formed by theFaceNodesIndices
215   // Return -1 if a face not found
216
217   int GetAllExistingFaces(std::vector<const SMDS_MeshElement*> & faces) const;
218   // Fill vector with boundary faces existing in the mesh
219
220   // ------------------------
221   // static methods for faces
222   // ------------------------
223
224   static VolumeType GetType(int nbNodes);
225   // return VolumeType by nb of nodes in a volume
226
227   static int NbFaces( VolumeType type );
228   // return nb of faces by volume type
229
230   static const int* GetFaceNodesIndices(VolumeType type,
231                                         int        faceIndex,
232                                         bool       external);
233   // Return the array of face nodes indices
234   // To comfort link iteration, the array
235   // length == NbFaceNodes( faceIndex ) + 1 and
236   // the last node index == the first one.
237   // Nodes at face centers of SMDSEntity_TriQuad_Hexa are ignored
238
239   static int NbFaceNodes(VolumeType type, int faceIndex );
240   // Return number of nodes in the array of face nodes
241   // Nodes at face centers of SMDSEntity_TriQuad_Hexa are ignored
242
243   static int NbCornerNodes(VolumeType type);
244   // Useful to know nb of corner nodes of a quadratic volume
245
246   static int GetOppFaceIndexOfHex( int faceIndex );
247   // Return index of the opposite face of the hexahedron
248
249  private:
250
251   bool setFace( int faceIndex ) const;
252
253   bool projectNodesToNormal( int     faceIndex,
254                              double& minProj,
255                              double& maxProj,
256                              double* normal = 0) const;
257
258   const SMDS_MeshElement* myVolume;
259   const SMDS_MeshVolume*  myPolyedre;
260   bool                    myIgnoreCentralNodes;
261
262   bool                    myVolForward;
263   int                     myNbFaces;
264   std::vector<const SMDS_MeshNode*> myVolumeNodes;
265   std::vector< int >      myPolyIndices; // of a myCurFace
266   std::vector<int>        myPolyQuantities;
267   std::vector< int >      myPolyFacetOri; // -1-in, +1-out, 0-undef
268
269   typedef std::pair<int,int> Link;
270   std::map<Link, int>     myFwdLinks; // used in IsFaceExternal() to find out myPolyFacetOri
271
272   mutable bool            myExternalFaces;
273
274   mutable const int*      myAllFacesNodeIndices_F;
275   mutable const int*      myAllFacesNodeIndices_RE;
276   mutable const int*      myAllFacesNbNodes;
277   mutable int             myMaxFaceNbNodes;
278
279   struct SaveFacet;
280   struct Facet
281   {
282     int                   myIndex;
283     int                   myNbNodes;
284     int*                  myNodeIndices;
285     std::vector<const SMDS_MeshNode*> myNodes;
286   };
287   mutable Facet           myCurFace;
288
289 };
290 #endif
291
292
293 ///////////////////////////////////////////////////////////////////////////
294 //
295 //                   ORDER OF NODES OF FORWARD ELEMENT
296 //
297 ///////////////////////////////////////////////////////////////////////////
298 /*
299 //           N3
300 //           +
301 //          /|\
302 //         / | \
303 //        /  |  \
304 //    N0 +---|---+ N1                TETRAHEDRON
305 //       \   |   /
306 //        \  |  /
307 //         \ | /
308 //          \|/
309 //           +
310 //           N2
311
312 //            + N4
313 //           /|\
314 //          / | \
315 //         /  |  \
316 //        /   |   \
317 //    N3 +---------+ N5
318 //       |    |    |
319 //       |    + N1 |
320 //       |   / \   |                PENTAHEDRON
321 //       |  /   \  |
322 //       | /     \ |
323 //       |/       \|
324 //    N0 +---------+ N2
325
326 //         N5+----------+N6
327 //          /|         /|
328 //         / |        / |
329 //        /  |       /  |
330 //     N4+----------+N7 |
331 //       |   |      |   |           HEXAHEDRON
332 //       |   |      |   |
333 //       |   |      |   |
334 //       | N1+------|---+N2
335 //       |  /       |  /
336 //       | /        | /
337 //       |/         |/
338 //     N0+----------+N3
339 //
340 */