Salome HOME
NPAL18084: add a new simply sample of GEOM/SMESH. Correct error.
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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, QUAD_TETRA,
55                     QUAD_PYRAM, QUAD_PENTA, QUAD_HEXA, POLYHEDA };
56
57   SMDS_VolumeTool ();
58   ~SMDS_VolumeTool ();
59   SMDS_VolumeTool (const SMDS_MeshElement* theVolume);
60
61   bool Set (const SMDS_MeshElement* theVolume);
62   // Set volume.
63   // Return false if theVolume is not of type SMDSAbs_Volume
64
65   // -----------------------
66   // general info
67   // -----------------------
68
69   VolumeType GetVolumeType() const;
70
71   bool IsForward() const { return myVolForward; }
72   // Check volume orientation. can be changed by Inverse().
73   // See node order of forward volumes at the file bottom
74
75   void Inverse();
76   // Change nodes order as if the volume changes its orientation:
77   // top and bottom faces are reversed.
78   // Result of IsForward() and methods returning nodes change
79
80   const SMDS_MeshNode** GetNodes() { return myVolumeNodes; }
81   // Return array of volume nodes
82
83   int NbNodes() { return myVolumeNbNodes; }
84   // Return array of volume nodes
85
86   double GetSize() const;
87   // Return element volume
88
89   bool GetBaryCenter (double & X, double & Y, double & Z) const;
90
91
92   // -----------------------
93   // info on node connection
94   // -----------------------
95
96   bool IsLinked (const SMDS_MeshNode* theNode1,
97                  const SMDS_MeshNode* theNode2) const;
98   // Return true if theNode1 is linked with theNode2.
99
100   bool IsLinked (const int theNode1Index,
101                  const int theNode2Index) const;
102   // Return true if the node with theNode1Index is linked
103   // with the node with theNode2Index
104
105   int GetNodeIndex(const SMDS_MeshNode* theNode) const;
106   // Return an index of theNode
107
108   int GetAllExistingEdges(std::vector<const SMDS_MeshElement*> & edges) const;
109   // Fill vector with boundary edges existing in the mesh
110
111   // -------------
112   // info on faces
113   // -------------
114
115   void SetExternalNormal ();
116   // Node order in faces  will be so that faces normals are external.
117
118   int NbFaces() const { return myNbFaces; }
119   // Return number of faces of the volume. In the following
120   // methods 0 <= faceIndex < NbFaces()
121
122   int NbFaceNodes( int faceIndex );
123   // Return number of nodes in the array of face nodes
124
125   const int* GetFaceNodesIndices( int faceIndex );
126   // Return the array of face nodes indices
127   // To comfort link iteration, the array
128   // length == NbFaceNodes( faceIndex ) + 1 and
129   // the last node index == the first one.
130
131   const SMDS_MeshNode** GetFaceNodes( int faceIndex );
132   // Return the array of face nodes.
133   // To comfort link iteration, the array
134   // length == NbFaceNodes( faceIndex ) + 1 and
135   // the last node == the first one.
136   // WARNING: do not modify the array, some methods
137   //          work basing on its contents
138
139   bool GetFaceNodes (int faceIndex,
140                      std::set<const SMDS_MeshNode*>& theFaceNodes );
141   // Return a set of face nodes.
142
143   bool IsFaceExternal( int faceIndex );
144   // Check normal orientation of a face.
145   // SetExternalNormal() is taken into account.
146
147   bool IsFreeFace(  int faceIndex );
148   // Check that all volumes built on the face nodes lays on one side
149
150   bool GetFaceNormal (int faceIndex, double & X, double & Y, double & Z);
151   // Return a normal to a face
152
153   double GetFaceArea( int faceIndex );
154   // Return face area
155
156   int GetOppFaceIndex( int faceIndex ) const;
157   // Return index of the opposite face if it exists, else -1.
158
159   int GetFaceIndex( const std::set<const SMDS_MeshNode*>& theFaceNodes );
160   // Return index of a face formed by theFaceNodes.
161   // Return -1 if a face not found
162
163   //int GetFaceIndex( const std::set<int>& theFaceNodesIndices );
164   // Return index of a face formed by theFaceNodesIndices
165   // Return -1 if a face not found
166
167   int GetAllExistingFaces(std::vector<const SMDS_MeshElement*> & faces);
168   // Fill vector with boundary faces existing in the mesh
169
170   // ------------------------
171   // static methods for faces
172   // ------------------------
173
174   static VolumeType GetType(int nbNodes);
175   // return VolumeType by nb of nodes in a volume
176
177   static int NbFaces( VolumeType type );
178   // return nb of faces by volume type
179
180   static const int* GetFaceNodesIndices(VolumeType type,
181                                         int        faceIndex,
182                                         bool       external);
183   // Return the array of face nodes indices
184   // To comfort link iteration, the array
185   // length == NbFaceNodes( faceIndex ) + 1 and
186   // the last node index == the first one.
187
188   static int NbFaceNodes(VolumeType type,
189                          int        faceIndex );
190   // Return number of nodes in the array of face nodes
191
192   static int NbCornerNodes(VolumeType type);
193   // Useful to know nb of corner nodes of a quadratic volume
194
195 private:
196
197   bool setFace( int faceIndex );
198
199   const SMDS_MeshElement* myVolume;
200   const SMDS_PolyhedralVolumeOfNodes* myPolyedre;
201
202   bool                    myVolForward;
203   int                     myNbFaces;
204   int                     myVolumeNbNodes;
205   const SMDS_MeshNode**   myVolumeNodes;
206
207   bool                    myExternalFaces;
208
209   int                     myCurFace;
210   int                     myFaceNbNodes;
211   int*                    myFaceNodeIndices;
212   const SMDS_MeshNode**   myFaceNodes;
213
214 };
215 #endif
216
217
218 ///////////////////////////////////////////////////////////////////////////
219 //
220 //                   ORDER OF NODES OF FORWARD ELEMENT
221 //
222 ///////////////////////////////////////////////////////////////////////////
223 /*
224 //           N3
225 //           +
226 //          /|\
227 //         / | \
228 //        /  |  \
229 //    N0 +---|---+ N1                TETRAHEDRON
230 //       \   |   /
231 //        \  |  /
232 //         \ | /
233 //          \|/
234 //           +
235 //           N2
236
237 //            + N4
238 //           /|\
239 //          / | \
240 //         /  |  \
241 //        /   |   \
242 //    N3 +---------+ N5
243 //       |    |    |
244 //       |    + N1 |
245 //       |   / \   |                PENTAHEDRON
246 //       |  /   \  |
247 //       | /     \ |
248 //       |/       \|
249 //    N0 +---------+ N2
250
251 //         N5+----------+N6
252 //          /|         /|
253 //         / |        / |
254 //        /  |       /  |
255 //     N4+----------+N7 |
256 //       |   |      |   |           HEXAHEDRON
257 //       |   |      |   |
258 //       |   |      |   |
259 //       | N1+------|---+N2
260 //       |  /       |  /
261 //       | /        | /
262 //       |/         |/
263 //     N0+----------+N3
264 //
265 */