Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/smesh.git] / src / SMDS / SMDS_VolumeTool.hxx
1 //  Copyright (C) 2007-2008  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 //  SMESH SMDS : implementaion of Salome mesh data structure
23 // File      : SMDS_VolumeTool.hxx
24 // Module    : SMESH
25 // Created   : Tue Jul 13 11:27:17 2004
26 // Author    : Edward AGAPOV (eap)
27 //
28 #ifndef SMDS_VolumeTool_HeaderFile
29 #define SMDS_VolumeTool_HeaderFile
30
31 #include "SMESH_SMDS.hxx"
32
33 class SMDS_MeshElement;
34 class SMDS_MeshNode;
35 class SMDS_PolyhedralVolumeOfNodes;
36 class SMDS_MeshVolume;
37
38 #include <vector>
39 #include <set>
40
41 // =========================================================================
42 //
43 // Class providing topological and other information about SMDS_MeshVolume:
44 // allows iteration on faces or, to be precise, on nodes of volume sides;
45 // provides info on nodes connection etc.
46 //
47 // =========================================================================
48
49 class SMDS_EXPORT SMDS_VolumeTool
50 {
51  public:
52
53   enum VolumeType { UNKNOWN = -1, TETRA = 0, PYRAM, PENTA, HEXA, QUAD_TETRA,
54                     QUAD_PYRAM, QUAD_PENTA, QUAD_HEXA, POLYHEDA };
55
56   SMDS_VolumeTool ();
57   ~SMDS_VolumeTool ();
58   SMDS_VolumeTool (const SMDS_MeshElement* theVolume);
59
60   bool Set (const SMDS_MeshElement* theVolume);
61   // Set volume.
62   // Return false if theVolume is not of type SMDSAbs_Volume
63
64   const SMDS_MeshVolume* Get() const;
65   // return element
66
67   int ID() const;
68   // return element ID
69
70   // -----------------------
71   // general info
72   // -----------------------
73
74   VolumeType GetVolumeType() const;
75
76   bool IsForward() const { return myVolForward; }
77   // Check volume orientation. can be changed by Inverse().
78   // See node order of forward volumes at the file bottom
79
80   void Inverse();
81   // Change nodes order as if the volume changes its orientation:
82   // top and bottom faces are reversed.
83   // Result of IsForward() and methods returning nodes change
84
85   const SMDS_MeshNode** GetNodes() { return myVolumeNodes; }
86   // Return array of volume nodes
87
88   int NbNodes() { return myVolumeNbNodes; }
89   // Return array of volume nodes
90
91   double GetSize() const;
92   // Return element volume
93
94   bool GetBaryCenter (double & X, double & Y, double & Z) const;
95
96
97   // -----------------------
98   // info on node connection
99   // -----------------------
100
101   bool IsLinked (const SMDS_MeshNode* theNode1,
102                  const SMDS_MeshNode* theNode2) const;
103   // Return true if theNode1 is linked with theNode2.
104
105   bool IsLinked (const int theNode1Index,
106                  const int theNode2Index) const;
107   // Return true if the node with theNode1Index is linked
108   // with the node with theNode2Index
109
110   int GetNodeIndex(const SMDS_MeshNode* theNode) const;
111   // Return an index of theNode
112
113   int GetAllExistingEdges(std::vector<const SMDS_MeshElement*> & edges) const;
114   // Fill vector with boundary edges existing in the mesh
115
116   // -------------
117   // info on faces
118   // -------------
119
120   void SetExternalNormal ();
121   // Node order in faces  will be so that faces normals are external.
122
123   int NbFaces() const { return myNbFaces; }
124   // Return number of faces of the volume. In the following
125   // methods 0 <= faceIndex < NbFaces()
126
127   int NbFaceNodes( int faceIndex );
128   // Return number of nodes in the array of face nodes
129
130   const int* GetFaceNodesIndices( int faceIndex );
131   // Return the array of face nodes indices
132   // To comfort link iteration, the array
133   // length == NbFaceNodes( faceIndex ) + 1 and
134   // the last node index == the first one.
135
136   const SMDS_MeshNode** GetFaceNodes( int faceIndex );
137   // Return the array of face nodes.
138   // To comfort link iteration, the array
139   // length == NbFaceNodes( faceIndex ) + 1 and
140   // the last node == the first one.
141   // WARNING: do not modify the array, some methods
142   //          work basing on its contents
143
144   bool GetFaceNodes (int faceIndex,
145                      std::set<const SMDS_MeshNode*>& theFaceNodes );
146   // Return a set of face nodes.
147
148   bool IsFaceExternal( int faceIndex );
149   // Check normal orientation of a face.
150   // SetExternalNormal() is taken into account.
151
152   bool IsFreeFace(  int faceIndex );
153   // Check that all volumes built on the face nodes lays on one side
154
155   bool GetFaceNormal (int faceIndex, double & X, double & Y, double & Z);
156   // Return a normal to a face
157
158   double GetFaceArea( int faceIndex );
159   // Return face area
160
161   int GetOppFaceIndex( int faceIndex ) const;
162   // Return index of the opposite face if it exists, else -1.
163
164   int GetFaceIndex( const std::set<const SMDS_MeshNode*>& theFaceNodes );
165   // Return index of a face formed by theFaceNodes.
166   // Return -1 if a face not found
167
168   //int GetFaceIndex( const std::set<int>& theFaceNodesIndices );
169   // Return index of a face formed by theFaceNodesIndices
170   // Return -1 if a face not found
171
172   int GetAllExistingFaces(std::vector<const SMDS_MeshElement*> & faces);
173   // Fill vector with boundary faces existing in the mesh
174
175   // ------------------------
176   // static methods for faces
177   // ------------------------
178
179   static VolumeType GetType(int nbNodes);
180   // return VolumeType by nb of nodes in a volume
181
182   static int NbFaces( VolumeType type );
183   // return nb of faces by volume type
184
185   static const int* GetFaceNodesIndices(VolumeType type,
186                                         int        faceIndex,
187                                         bool       external);
188   // Return the array of face nodes indices
189   // To comfort link iteration, the array
190   // length == NbFaceNodes( faceIndex ) + 1 and
191   // the last node index == the first one.
192
193   static int NbFaceNodes(VolumeType type,
194                          int        faceIndex );
195   // Return number of nodes in the array of face nodes
196
197   static int NbCornerNodes(VolumeType type);
198   // Useful to know nb of corner nodes of a quadratic volume
199
200 private:
201
202   bool setFace( int faceIndex );
203
204   const SMDS_MeshElement* myVolume;
205   const SMDS_PolyhedralVolumeOfNodes* myPolyedre;
206
207   bool                    myVolForward;
208   int                     myNbFaces;
209   int                     myVolumeNbNodes;
210   const SMDS_MeshNode**   myVolumeNodes;
211
212   bool                    myExternalFaces;
213
214   int                     myCurFace;
215   int                     myFaceNbNodes;
216   int*                    myFaceNodeIndices;
217   const SMDS_MeshNode**   myFaceNodes;
218
219 };
220 #endif
221
222
223 ///////////////////////////////////////////////////////////////////////////
224 //
225 //                   ORDER OF NODES OF FORWARD ELEMENT
226 //
227 ///////////////////////////////////////////////////////////////////////////
228 /*
229 //           N3
230 //           +
231 //          /|\
232 //         / | \
233 //        /  |  \
234 //    N0 +---|---+ N1                TETRAHEDRON
235 //       \   |   /
236 //        \  |  /
237 //         \ | /
238 //          \|/
239 //           +
240 //           N2
241
242 //            + N4
243 //           /|\
244 //          / | \
245 //         /  |  \
246 //        /   |   \
247 //    N3 +---------+ N5
248 //       |    |    |
249 //       |    + N1 |
250 //       |   / \   |                PENTAHEDRON
251 //       |  /   \  |
252 //       | /     \ |
253 //       |/       \|
254 //    N0 +---------+ N2
255
256 //         N5+----------+N6
257 //          /|         /|
258 //         / |        / |
259 //        /  |       /  |
260 //     N4+----------+N7 |
261 //       |   |      |   |           HEXAHEDRON
262 //       |   |      |   |
263 //       |   |      |   |
264 //       | N1+------|---+N2
265 //       |  /       |  /
266 //       | /        | /
267 //       |/         |/
268 //     N0+----------+N3
269 //
270 */