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