1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMDS : implementaion of Salome mesh data structure
24 // File : SMDS_VolumeTool.hxx
26 // Created : Tue Jul 13 11:27:17 2004
27 // Author : Edward AGAPOV (eap)
29 #ifndef SMDS_VolumeTool_HeaderFile
30 #define SMDS_VolumeTool_HeaderFile
32 #include "SMESH_SMDS.hxx"
34 class SMDS_MeshElement;
36 class SMDS_PolyhedralVolumeOfNodes;
37 class SMDS_MeshVolume;
42 // =========================================================================
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.
48 // =========================================================================
50 class SMDS_EXPORT SMDS_VolumeTool
54 enum VolumeType { UNKNOWN = -1, TETRA = 0, PYRAM, PENTA, HEXA, QUAD_TETRA,
55 QUAD_PYRAM, QUAD_PENTA, QUAD_HEXA, POLYHEDA };
59 SMDS_VolumeTool (const SMDS_MeshElement* theVolume);
61 bool Set (const SMDS_MeshElement* theVolume);
63 // Return false if theVolume is not of type SMDSAbs_Volume
65 const SMDS_MeshVolume* Element() const;
71 // -----------------------
73 // -----------------------
75 VolumeType GetVolumeType() const;
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
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
86 const SMDS_MeshNode** GetNodes() { return myVolumeNodes; }
87 // Return array of volume nodes
89 int NbNodes() { return myVolumeNbNodes; }
90 // Return array of volume nodes
92 double GetSize() const;
93 // Return element volume
95 bool GetBaryCenter (double & X, double & Y, double & Z) const;
97 bool IsOut(double X, double Y, double Z, double tol);
100 // -----------------------
101 // info on node connection
102 // -----------------------
104 bool IsLinked (const SMDS_MeshNode* theNode1,
105 const SMDS_MeshNode* theNode2) const;
106 // Return true if theNode1 is linked with theNode2.
108 bool IsLinked (const int theNode1Index,
109 const int theNode2Index) const;
110 // Return true if the node with theNode1Index is linked
111 // with the node with theNode2Index
113 int GetNodeIndex(const SMDS_MeshNode* theNode) const;
114 // Return an index of theNode
116 int GetAllExistingEdges(std::vector<const SMDS_MeshElement*> & edges) const;
117 // Fill vector with boundary edges existing in the mesh
123 void SetExternalNormal ();
124 // Node order in faces will be so that faces normals are external.
126 int NbFaces() const { return myNbFaces; }
127 // Return number of faces of the volume. In the following
128 // methods 0 <= faceIndex < NbFaces()
130 int NbFaceNodes( int faceIndex );
131 // Return number of nodes in the array of face nodes
133 const int* GetFaceNodesIndices( int faceIndex );
134 // Return the array of face nodes indices
135 // To comfort link iteration, the array
136 // length == NbFaceNodes( faceIndex ) + 1 and
137 // the last node index == the first one.
139 const SMDS_MeshNode** GetFaceNodes( int faceIndex );
140 // Return the array of face nodes.
141 // To comfort link iteration, the array
142 // length == NbFaceNodes( faceIndex ) + 1 and
143 // the last node == the first one.
144 // WARNING: do not modify the array, some methods
145 // work basing on its contents
147 bool GetFaceNodes (int faceIndex,
148 std::set<const SMDS_MeshNode*>& theFaceNodes );
149 // Return a set of face nodes.
151 bool IsFaceExternal( int faceIndex );
152 // Check normal orientation of a face.
153 // SetExternalNormal() is taken into account.
155 bool IsFreeFace( int faceIndex );
156 // Check that all volumes built on the face nodes lays on one side
158 bool GetFaceNormal (int faceIndex, double & X, double & Y, double & Z);
159 // Return a normal to a face
161 double GetFaceArea( int faceIndex );
164 int GetOppFaceIndex( int faceIndex ) const;
165 // Return index of the opposite face if it exists, else -1.
167 int GetFaceIndex( const std::set<const SMDS_MeshNode*>& theFaceNodes );
168 // Return index of a face formed by theFaceNodes.
169 // Return -1 if a face not found
171 //int GetFaceIndex( const std::set<int>& theFaceNodesIndices );
172 // Return index of a face formed by theFaceNodesIndices
173 // Return -1 if a face not found
175 int GetAllExistingFaces(std::vector<const SMDS_MeshElement*> & faces);
176 // Fill vector with boundary faces existing in the mesh
178 // ------------------------
179 // static methods for faces
180 // ------------------------
182 static VolumeType GetType(int nbNodes);
183 // return VolumeType by nb of nodes in a volume
185 static int NbFaces( VolumeType type );
186 // return nb of faces by volume type
188 static const int* GetFaceNodesIndices(VolumeType type,
191 // Return the array of face nodes indices
192 // To comfort link iteration, the array
193 // length == NbFaceNodes( faceIndex ) + 1 and
194 // the last node index == the first one.
196 static int NbFaceNodes(VolumeType type,
198 // Return number of nodes in the array of face nodes
200 static int NbCornerNodes(VolumeType type);
201 // Useful to know nb of corner nodes of a quadratic volume
205 bool setFace( int faceIndex );
207 const SMDS_MeshElement* myVolume;
208 const SMDS_PolyhedralVolumeOfNodes* myPolyedre;
213 const SMDS_MeshNode** myVolumeNodes;
214 std::vector< int > myPolyIndices;
216 bool myExternalFaces;
220 int* myFaceNodeIndices;
221 const SMDS_MeshNode** myFaceNodes;
227 ///////////////////////////////////////////////////////////////////////////
229 // ORDER OF NODES OF FORWARD ELEMENT
231 ///////////////////////////////////////////////////////////////////////////
238 // N0 +---|---+ N1 TETRAHEDRON
254 // | / \ | PENTAHEDRON
264 // N4+----------+N7 |
265 // | | | | HEXAHEDRON
268 // | N1+------|---+N2