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