Salome HOME
52566]: TC7.5.0: Empty group of Balls at Diameter Equal to filter
[modules/smesh.git] / src / SMDS / SMDS_VolumeTool.hxx
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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,
55                     HEX_PRISM, QUAD_TETRA, QUAD_PYRAM, QUAD_PENTA, QUAD_HEXA,
56                     POLYHEDA, NB_VOLUME_TYPES }; // to keep synchronised with GetSize()!
57
58   SMDS_VolumeTool ();
59   ~SMDS_VolumeTool ();
60   SMDS_VolumeTool (const SMDS_MeshElement* theVolume,
61                    const bool              ignoreCentralNodes=true);
62
63   bool Set (const SMDS_MeshElement* theVolume,
64             const bool              ignoreCentralNodes=true);
65   // Set volume.
66   // Return false if theVolume is not of type SMDSAbs_Volume.
67   // ignoreCentralNodes makes skip nodes at face centers when returning
68   // nodes of faces of SMDSEntity_TriQuad_Hexa
69
70   const SMDS_MeshVolume* Element() const;
71   // return element
72
73   int ID() const;
74   // return element ID
75
76   bool IsPoly() const { return myPolyedre; }
77
78   // -----------------------
79   // general info
80   // -----------------------
81
82   VolumeType GetVolumeType() const;
83
84   bool IsForward() const { return myVolForward; }
85   // Check volume orientation. can be changed by Inverse().
86   // See node order of forward volumes at the file bottom
87
88   void Inverse();
89   // Change nodes order as if the volume changes its orientation:
90   // top and bottom faces are reversed.
91   // Result of IsForward() and methods returning nodes change
92
93   const SMDS_MeshNode** GetNodes() { return myVolumeNodes; }
94   // Return array of volume nodes
95
96   int NbNodes() { return myVolumeNbNodes; }
97   // Return array of volume nodes
98
99   double GetSize() const;
100   // Return element volume
101
102   bool GetBaryCenter (double & X, double & Y, double & Z) const;
103
104   bool IsOut(double X, double Y, double Z, double tol) const;
105   // Classify a point
106
107   // -----------------------
108   // info on node connection
109   // -----------------------
110
111   bool IsLinked (const SMDS_MeshNode* theNode1,
112                  const SMDS_MeshNode* theNode2,
113                  const bool           theIgnoreMediumNodes=false) const;
114   // Return true if theNode1 is linked with theNode2.
115   // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
116
117   bool IsLinked (const int theNode1Index,
118                  const int theNode2Index,
119                  bool      theIgnoreMediumNodes=false) const;
120   // Return true if the node with theNode1Index is linked
121   // with the node with theNode2Index
122   // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
123
124   int GetNodeIndex(const SMDS_MeshNode* theNode) const;
125   // Return an index of theNode
126
127   int GetAllExistingEdges(std::vector<const SMDS_MeshElement*> & edges) const;
128   // Fill vector with boundary edges existing in the mesh
129
130   double MinLinearSize2() const;
131   // Return minimal square distance between connected corner nodes
132
133   double MaxLinearSize2() const;
134   // Return maximal square distance between connected corner nodes
135
136   // -------------
137   // info on faces
138   // -------------
139   // For all elements, 0-th face is bottom based on the first nodes.
140   // For prismatic elements (tetra,hexa,prisms), 1-th face is a top one.
141   // For all elements, side faces follow order of bottom nodes
142
143   void SetExternalNormal ();
144   // Node order in faces  will be so that faces normals are external.
145
146   int NbFaces() const { return myNbFaces; }
147   // Return number of faces of the volume. In the following
148   // methods 0 <= faceIndex < NbFaces()
149
150   int NbFaceNodes( int faceIndex ) const;
151   // Return number of nodes in the array of face nodes
152
153   const int* GetFaceNodesIndices( int faceIndex ) const;
154   // Return the array of face nodes indices
155   // To comfort link iteration, the array
156   // length == NbFaceNodes( faceIndex ) + 1 and
157   // the last node index == the first one, except for
158   // SMDSEntity_TriQuad_Hexa at ignoreCentralNodes==false.
159   // NOTE: for the quadratic volume, node indices are in the order the nodes encounter
160   // in face boundary and not the order they are in the mesh face
161
162   const SMDS_MeshNode** GetFaceNodes( int faceIndex ) const;
163   // Return the array of face nodes.
164   // To comfort link iteration, the array
165   // length == NbFaceNodes( faceIndex ) + 1 and
166   // the last node == the first one, except for
167   // SMDSEntity_TriQuad_Hexa at ignoreCentralNodes==false.
168   // NOTE: for the quadratic volume, nodes are in the order they encounter in face boundary
169   // and not the order they are in the mesh face
170   // WARNING: do not modify the array, some methods
171   //          work basing on its contents
172
173   bool GetFaceNodes (int faceIndex,
174                      std::set<const SMDS_MeshNode*>& theFaceNodes ) const;
175   // Return a set of face nodes.
176
177   bool IsFaceExternal( int faceIndex ) const;
178   // Check normal orientation of a face.
179   // SetExternalNormal() is taken into account.
180
181   bool IsFreeFace(  int faceIndex, const SMDS_MeshElement** otherVol=0 ) const;
182   // Fast check that only one volume is built on nodes of a given face
183   // otherVol returns another volume sharing the given facet
184
185   bool IsFreeFaceAdv(  int faceIndex, const SMDS_MeshElement** otherVol=0 ) const;
186   // Thorough check that all volumes built on the face nodes lays on one side
187   // otherVol returns another volume sharing the given facet
188
189   bool GetFaceNormal (int faceIndex, double & X, double & Y, double & Z) const;
190   // Return a normal to a face
191
192   bool GetFaceBaryCenter (int faceIndex, double & X, double & Y, double & Z) const;
193   // Return barycenter of a face
194
195   double GetFaceArea( int faceIndex ) const;
196   // Return face area
197
198   int GetOppFaceIndex( int faceIndex ) const;
199   // Return index of the opposite face if it exists, else -1.
200
201   int GetCenterNodeIndex( int faceIndex ) const;
202   // Return index of the node located at face center of a quadratic element like HEX27
203
204   int GetFaceIndex( const std::set<const SMDS_MeshNode*>& theFaceNodes,
205                     const int                             theFaceIndexHint=-1) const;
206   // Return index of a face formed by theFaceNodes.
207   // Return -1 if a face not found
208
209   //int GetFaceIndex( const std::set<int>& theFaceNodesIndices );
210   // Return index of a face formed by theFaceNodesIndices
211   // Return -1 if a face not found
212
213   int GetAllExistingFaces(std::vector<const SMDS_MeshElement*> & faces) const;
214   // Fill vector with boundary faces existing in the mesh
215
216   // ------------------------
217   // static methods for faces
218   // ------------------------
219
220   static VolumeType GetType(int nbNodes);
221   // return VolumeType by nb of nodes in a volume
222
223   static int NbFaces( VolumeType type );
224   // return nb of faces by volume type
225
226   static const int* GetFaceNodesIndices(VolumeType type,
227                                         int        faceIndex,
228                                         bool       external);
229   // Return the array of face nodes indices
230   // To comfort link iteration, the array
231   // length == NbFaceNodes( faceIndex ) + 1 and
232   // the last node index == the first one.
233   // Nodes at face centers of SMDSEntity_TriQuad_Hexa are ignored
234
235   static int NbFaceNodes(VolumeType type, int faceIndex );
236   // Return number of nodes in the array of face nodes
237   // Nodes at face centers of SMDSEntity_TriQuad_Hexa are ignored
238
239   static int NbCornerNodes(VolumeType type);
240   // Useful to know nb of corner nodes of a quadratic volume
241
242   static int GetOppFaceIndexOfHex( int faceIndex );
243   // Return index of the opposite face of the hexahedron
244
245 private:
246
247   bool setFace( int faceIndex ) const;
248
249   const SMDS_MeshElement* myVolume;
250   const SMDS_VtkVolume*   myPolyedre;
251   bool                    myIgnoreCentralNodes;
252
253   bool                    myVolForward;
254   int                     myNbFaces;
255   int                     myVolumeNbNodes;
256   const SMDS_MeshNode**   myVolumeNodes;
257   std::vector< int >      myPolyIndices;
258
259   mutable bool                    myExternalFaces;
260
261   mutable const int*              myAllFacesNodeIndices_F;
262   mutable const int*              myAllFacesNodeIndices_RE;
263   mutable const int*              myAllFacesNbNodes;
264   mutable int                     myMaxFaceNbNodes;
265
266   mutable int                     myCurFace;
267   mutable int                     myFaceNbNodes;
268   mutable int*                    myFaceNodeIndices;
269   mutable const SMDS_MeshNode**   myFaceNodes;
270
271 };
272 #endif
273
274
275 ///////////////////////////////////////////////////////////////////////////
276 //
277 //                   ORDER OF NODES OF FORWARD ELEMENT
278 //
279 ///////////////////////////////////////////////////////////////////////////
280 /*
281 //           N3
282 //           +
283 //          /|\
284 //         / | \
285 //        /  |  \
286 //    N0 +---|---+ N1                TETRAHEDRON
287 //       \   |   /
288 //        \  |  /
289 //         \ | /
290 //          \|/
291 //           +
292 //           N2
293
294 //            + N4
295 //           /|\
296 //          / | \
297 //         /  |  \
298 //        /   |   \
299 //    N3 +---------+ N5
300 //       |    |    |
301 //       |    + N1 |
302 //       |   / \   |                PENTAHEDRON
303 //       |  /   \  |
304 //       | /     \ |
305 //       |/       \|
306 //    N0 +---------+ N2
307
308 //         N5+----------+N6
309 //          /|         /|
310 //         / |        / |
311 //        /  |       /  |
312 //     N4+----------+N7 |
313 //       |   |      |   |           HEXAHEDRON
314 //       |   |      |   |
315 //       |   |      |   |
316 //       | N1+------|---+N2
317 //       |  /       |  /
318 //       | /        | /
319 //       |/         |/
320 //     N0+----------+N3
321 //
322 */