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