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