Salome HOME
Merge from V6_3_BR 15/07/2011
[modules/smesh.git] / src / SMDS / SMDS_VolumeTool.hxx
1 // Copyright (C) 2007-2011  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, 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   const SMDS_MeshVolume* Element() const;
66   // return element
67
68   int ID() const;
69   // return element ID
70
71   // -----------------------
72   // general info
73   // -----------------------
74
75   VolumeType GetVolumeType() const;
76
77   bool IsForward() const { return myVolForward; }
78   // Check volume orientation. can be changed by Inverse().
79   // See node order of forward volumes at the file bottom
80
81   void Inverse();
82   // Change nodes order as if the volume changes its orientation:
83   // top and bottom faces are reversed.
84   // Result of IsForward() and methods returning nodes change
85
86   const SMDS_MeshNode** GetNodes() { return myVolumeNodes; }
87   // Return array of volume nodes
88
89   int NbNodes() { return myVolumeNbNodes; }
90   // Return array of volume nodes
91
92   double GetSize() const;
93   // Return element volume
94
95   bool GetBaryCenter (double & X, double & Y, double & Z) const;
96
97   bool IsOut(double X, double Y, double Z, double tol);
98   // Classify a point
99
100   // -----------------------
101   // info on node connection
102   // -----------------------
103
104   bool IsLinked (const SMDS_MeshNode* theNode1,
105                  const SMDS_MeshNode* theNode2,
106                  const bool           theIgnoreMediumNodes=false) const;
107   // Return true if theNode1 is linked with theNode2.
108   // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
109
110   bool IsLinked (const int theNode1Index,
111                  const int theNode2Index,
112                  bool      theIgnoreMediumNodes=false) const;
113   // Return true if the node with theNode1Index is linked
114   // with the node with theNode2Index
115   // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
116
117   int GetNodeIndex(const SMDS_MeshNode* theNode) const;
118   // Return an index of theNode
119
120   int GetAllExistingEdges(std::vector<const SMDS_MeshElement*> & edges) const;
121   // Fill vector with boundary edges existing in the mesh
122
123   // -------------
124   // info on faces
125   // -------------
126
127   void SetExternalNormal ();
128   // Node order in faces  will be so that faces normals are external.
129
130   int NbFaces() const { return myNbFaces; }
131   // Return number of faces of the volume. In the following
132   // methods 0 <= faceIndex < NbFaces()
133
134   int NbFaceNodes( int faceIndex );
135   // Return number of nodes in the array of face nodes
136
137   const int* GetFaceNodesIndices( int faceIndex );
138   // Return the array of face nodes indices
139   // To comfort link iteration, the array
140   // length == NbFaceNodes( faceIndex ) + 1 and
141   // the last node index == the first one.
142   // NOTE: for the quadratic volume, node indoces are in the order the nodes encounter
143   // in face boundary and not the order they are in the mesh face
144
145   const SMDS_MeshNode** GetFaceNodes( int faceIndex );
146   // Return the array of face nodes.
147   // To comfort link iteration, the array
148   // length == NbFaceNodes( faceIndex ) + 1 and
149   // the last node == the first one.
150   // NOTE: for the quadratic volume, nodes are in the order they encounter in face boundary
151   // and not the order they are in the mesh face
152   // WARNING: do not modify the array, some methods
153   //          work basing on its contents
154
155   bool GetFaceNodes (int faceIndex,
156                      std::set<const SMDS_MeshNode*>& theFaceNodes );
157   // Return a set of face nodes.
158
159   bool IsFaceExternal( int faceIndex );
160   // Check normal orientation of a face.
161   // SetExternalNormal() is taken into account.
162
163   bool IsFreeFace(  int faceIndex, const SMDS_MeshElement** otherVol=0 );
164   // Check that all volumes built on the face nodes lays on one side
165   // otherVol returns another volume sharing the given facet
166
167   bool GetFaceNormal (int faceIndex, double & X, double & Y, double & Z);
168   // Return a normal to a face
169
170   bool GetFaceBaryCenter (int faceIndex, double & X, double & Y, double & Z);
171   // Return barycenter of a face
172
173   double GetFaceArea( int faceIndex );
174   // Return face area
175
176   int GetOppFaceIndex( int faceIndex ) const;
177   // Return index of the opposite face if it exists, else -1.
178
179   int GetFaceIndex( const std::set<const SMDS_MeshNode*>& theFaceNodes );
180   // Return index of a face formed by theFaceNodes.
181   // Return -1 if a face not found
182
183   //int GetFaceIndex( const std::set<int>& theFaceNodesIndices );
184   // Return index of a face formed by theFaceNodesIndices
185   // Return -1 if a face not found
186
187   int GetAllExistingFaces(std::vector<const SMDS_MeshElement*> & faces);
188   // Fill vector with boundary faces existing in the mesh
189
190   // ------------------------
191   // static methods for faces
192   // ------------------------
193
194   static VolumeType GetType(int nbNodes);
195   // return VolumeType by nb of nodes in a volume
196
197   static int NbFaces( VolumeType type );
198   // return nb of faces by volume type
199
200   static const int* GetFaceNodesIndices(VolumeType type,
201                                         int        faceIndex,
202                                         bool       external);
203   // Return the array of face nodes indices
204   // To comfort link iteration, the array
205   // length == NbFaceNodes( faceIndex ) + 1 and
206   // the last node index == the first one.
207
208   static int NbFaceNodes(VolumeType type,
209                          int        faceIndex );
210   // Return number of nodes in the array of face nodes
211
212   static int NbCornerNodes(VolumeType type);
213   // Useful to know nb of corner nodes of a quadratic volume
214
215 private:
216
217   bool setFace( int faceIndex );
218
219   const SMDS_MeshElement* myVolume;
220   const SMDS_VtkVolume*   myPolyedre;
221
222   bool                    myVolForward;
223   int                     myNbFaces;
224   int                     myVolumeNbNodes;
225   const SMDS_MeshNode**   myVolumeNodes;
226   std::vector< int >      myPolyIndices;
227
228   bool                    myExternalFaces;
229
230   int                     myCurFace;
231   int                     myFaceNbNodes;
232   int*                    myFaceNodeIndices;
233   const SMDS_MeshNode**   myFaceNodes;
234
235 };
236 #endif
237
238
239 ///////////////////////////////////////////////////////////////////////////
240 //
241 //                   ORDER OF NODES OF FORWARD ELEMENT
242 //
243 ///////////////////////////////////////////////////////////////////////////
244 /*
245 //           N3
246 //           +
247 //          /|\
248 //         / | \
249 //        /  |  \
250 //    N0 +---|---+ N1                TETRAHEDRON
251 //       \   |   /
252 //        \  |  /
253 //         \ | /
254 //          \|/
255 //           +
256 //           N2
257
258 //            + N4
259 //           /|\
260 //          / | \
261 //         /  |  \
262 //        /   |   \
263 //    N3 +---------+ N5
264 //       |    |    |
265 //       |    + N1 |
266 //       |   / \   |                PENTAHEDRON
267 //       |  /   \  |
268 //       | /     \ |
269 //       |/       \|
270 //    N0 +---------+ N2
271
272 //         N5+----------+N6
273 //          /|         /|
274 //         / |        / |
275 //        /  |       /  |
276 //     N4+----------+N7 |
277 //       |   |      |   |           HEXAHEDRON
278 //       |   |      |   |
279 //       |   |      |   |
280 //       | N1+------|---+N2
281 //       |  /       |  /
282 //       | /        | /
283 //       |/         |/
284 //     N0+----------+N3
285 //
286 */