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