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