1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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;
37 class SMDS_MeshVolume;
43 // =========================================================================
45 // Class providing topological and other information about SMDS_MeshVolume:
46 // allows iteration on faces or, to be precise, on nodes of volume sides;
47 // provides info on nodes connection etc.
49 // =========================================================================
51 class SMDS_EXPORT SMDS_VolumeTool
55 enum VolumeType { UNKNOWN = -1, TETRA = 0, PYRAM, PENTA, HEXA,
56 HEX_PRISM, QUAD_TETRA, QUAD_PYRAM, QUAD_PENTA, QUAD_HEXA,
57 POLYHEDA, NB_VOLUME_TYPES }; // to keep synchronised with GetSize()!
61 SMDS_VolumeTool (const SMDS_MeshElement* theVolume,
62 const bool ignoreCentralNodes=true);
64 bool Set (const SMDS_MeshElement* theVolume,
65 const bool ignoreCentralNodes=true);
67 // Return false if theVolume is not of type SMDSAbs_Volume.
68 // ignoreCentralNodes makes skip nodes at face centers when returning
69 // nodes of faces of SMDSEntity_TriQuad_Hexa
71 const SMDS_MeshVolume* Element() const;
77 bool IsPoly() const { return myPolyedre; }
79 // -----------------------
81 // -----------------------
83 VolumeType GetVolumeType() const;
85 bool IsForward() const { return myVolForward; }
86 // Check volume orientation. can be changed by Inverse().
87 // See node order of forward volumes at the file bottom
90 // Change nodes order as if the volume changes its orientation:
91 // top and bottom faces are reversed.
92 // Result of IsForward() and methods returning nodes change
94 const SMDS_MeshNode** GetNodes() { return &myVolumeNodes[0]; }
95 // Return array of volume nodes
97 int NbNodes() { return myVolumeNodes.size(); }
98 // Return array of volume nodes
100 double GetSize() const;
101 // Return element volume
103 bool GetBaryCenter (double & X, double & Y, double & Z) const;
105 bool IsOut(double X, double Y, double Z, double tol) const;
108 // -----------------------
109 // info on node connection
110 // -----------------------
112 bool IsLinked (const SMDS_MeshNode* theNode1,
113 const SMDS_MeshNode* theNode2,
114 const bool theIgnoreMediumNodes=false) const;
115 // Return true if theNode1 is linked with theNode2.
116 // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
118 bool IsLinked (const int theNode1Index,
119 const int theNode2Index,
120 bool theIgnoreMediumNodes=false) const;
121 // Return true if the node with theNode1Index is linked
122 // with the node with theNode2Index
123 // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
125 int GetNodeIndex(const SMDS_MeshNode* theNode) const;
126 // Return an index of theNode
128 int GetAllExistingEdges(std::vector<const SMDS_MeshElement*> & edges) const;
129 // Fill vector with boundary edges existing in the mesh
131 double MinLinearSize2() const;
132 // Return minimal square distance between connected corner nodes
134 double MaxLinearSize2() const;
135 // Return maximal square distance between connected corner nodes
140 // For all elements, 0-th face is bottom based on the first nodes.
141 // For prismatic elements (tetra,hexa,prisms), 1-th face is a top one.
142 // For all elements, side faces follow order of bottom nodes
144 void SetExternalNormal ();
145 // Node order in faces will be so that faces normals are external.
147 int NbFaces() const { return myNbFaces; }
148 // Return number of faces of the volume. In the following
149 // methods 0 <= faceIndex < NbFaces()
151 int NbFaceNodes( int faceIndex ) const;
152 // Return number of nodes in the array of face nodes
154 const int* GetFaceNodesIndices( int faceIndex ) const;
155 // Return the array of face nodes indices
156 // To comfort link iteration, the array
157 // length == NbFaceNodes( faceIndex ) + 1 and
158 // the last node index == the first one, except for
159 // SMDSEntity_TriQuad_Hexa at ignoreCentralNodes==false.
160 // NOTE: for the quadratic volume, node indices are in the order the nodes encounter
161 // in face boundary and not the order they are in the mesh face
163 const SMDS_MeshNode** GetFaceNodes( int faceIndex ) const;
164 // Return the array of face nodes.
165 // To comfort link iteration, the array
166 // length == NbFaceNodes( faceIndex ) + 1 and
167 // the last node == the first one, except for
168 // SMDSEntity_TriQuad_Hexa at ignoreCentralNodes==false.
169 // NOTE: for the quadratic volume, nodes are in the order they encounter in face boundary
170 // and not the order they are in the mesh face
171 // WARNING: do not modify the array, some methods
172 // work basing on its contents
174 bool GetFaceNodes (int faceIndex,
175 std::set<const SMDS_MeshNode*>& theFaceNodes ) const;
176 // Return a set of face nodes.
178 bool IsFaceExternal( int faceIndex ) const;
179 // Check normal orientation of a face.
180 // SetExternalNormal() is taken into account.
182 bool IsFreeFace( int faceIndex, const SMDS_MeshElement** otherVol=0 ) const;
183 // Fast check that only one volume is built on nodes of a given face
184 // otherVol returns another volume sharing the given facet
186 bool IsFreeFaceAdv( int faceIndex, const SMDS_MeshElement** otherVol=0 ) const;
187 // Thorough check that all volumes built on the face nodes lays on one side
188 // otherVol returns another volume sharing the given facet
190 bool GetFaceNormal (int faceIndex, double & X, double & Y, double & Z) const;
191 // Return a normal to a face
193 bool GetFaceBaryCenter (int faceIndex, double & X, double & Y, double & Z) const;
194 // Return barycenter of a face
196 double GetFaceArea( int faceIndex ) const;
199 int GetOppFaceIndex( int faceIndex ) const;
200 // Return index of the opposite face if it exists, else -1.
202 int GetCenterNodeIndex( int faceIndex ) const;
203 // Return index of the node located at face center of a quadratic element like HEX27
205 int GetFaceIndex( const std::set<const SMDS_MeshNode*>& theFaceNodes,
206 const int theFaceIndexHint=-1) const;
207 // Return index of a face formed by theFaceNodes.
208 // Return -1 if a face not found
210 //int GetFaceIndex( const std::set<int>& theFaceNodesIndices );
211 // Return index of a face formed by theFaceNodesIndices
212 // Return -1 if a face not found
214 int GetAllExistingFaces(std::vector<const SMDS_MeshElement*> & faces) const;
215 // Fill vector with boundary faces existing in the mesh
217 // ------------------------
218 // static methods for faces
219 // ------------------------
221 static VolumeType GetType(int nbNodes);
222 // return VolumeType by nb of nodes in a volume
224 static int NbFaces( VolumeType type );
225 // return nb of faces by volume type
227 static const int* GetFaceNodesIndices(VolumeType type,
230 // Return the array of face nodes indices
231 // To comfort link iteration, the array
232 // length == NbFaceNodes( faceIndex ) + 1 and
233 // the last node index == the first one.
234 // Nodes at face centers of SMDSEntity_TriQuad_Hexa are ignored
236 static int NbFaceNodes(VolumeType type, int faceIndex );
237 // Return number of nodes in the array of face nodes
238 // Nodes at face centers of SMDSEntity_TriQuad_Hexa are ignored
240 static int NbCornerNodes(VolumeType type);
241 // Useful to know nb of corner nodes of a quadratic volume
243 static int GetOppFaceIndexOfHex( int faceIndex );
244 // Return index of the opposite face of the hexahedron
248 bool setFace( int faceIndex ) const;
250 bool projectNodesToNormal( int faceIndex, double& minProj, double& maxProj ) const;
252 const SMDS_MeshElement* myVolume;
253 const SMDS_VtkVolume* myPolyedre;
254 bool myIgnoreCentralNodes;
258 std::vector<const SMDS_MeshNode*> myVolumeNodes;
259 std::vector< int > myPolyIndices; // of a myCurFace
260 std::vector< int > myPolyQuantities;
261 std::vector< int > myPolyFacetOri; // -1-in, +1-out, 0-undef
263 typedef std::pair<int,int> Link;
264 std::map<Link, int> myFwdLinks; // used in IsFaceExternal() to find out myPolyFacetOri
266 mutable bool myExternalFaces;
268 mutable const int* myAllFacesNodeIndices_F;
269 mutable const int* myAllFacesNodeIndices_RE;
270 mutable const int* myAllFacesNbNodes;
271 mutable int myMaxFaceNbNodes;
279 std::vector<const SMDS_MeshNode*> myNodes;
281 mutable Facet myCurFace;
287 ///////////////////////////////////////////////////////////////////////////
289 // ORDER OF NODES OF FORWARD ELEMENT
291 ///////////////////////////////////////////////////////////////////////////
298 // N0 +---|---+ N1 TETRAHEDRON
314 // | / \ | PENTAHEDRON
324 // N4+----------+N7 |
325 // | | | | HEXAHEDRON
328 // | N1+------|---+N2