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