Back to index

salome-smesh  6.5.0
SMDS_VolumeTool.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SMESH SMDS : implementaion of Salome mesh data structure
00024 // File      : SMDS_VolumeTool.hxx
00025 // Module    : SMESH
00026 // Created   : Tue Jul 13 11:27:17 2004
00027 // Author    : Edward AGAPOV (eap)
00028 //
00029 #ifndef SMDS_VolumeTool_HeaderFile
00030 #define SMDS_VolumeTool_HeaderFile
00031 
00032 #include "SMESH_SMDS.hxx"
00033 
00034 class SMDS_MeshElement;
00035 class SMDS_MeshNode;
00036 class SMDS_VtkVolume;
00037 class SMDS_MeshVolume;
00038 
00039 #include <vector>
00040 #include <set>
00041 
00042 // =========================================================================
00043 //
00044 // Class providing topological and other information about SMDS_MeshVolume:
00045 // allows iteration on faces or, to be precise, on nodes of volume sides;
00046 // provides info on nodes connection etc.
00047 //
00048 // =========================================================================
00049 
00050 class SMDS_EXPORT SMDS_VolumeTool
00051 {
00052  public:
00053 
00054   enum VolumeType { UNKNOWN = -1, TETRA = 0, PYRAM, PENTA, HEXA,
00055                     HEX_PRISM, QUAD_TETRA, QUAD_PYRAM, QUAD_PENTA, QUAD_HEXA,
00056                     POLYHEDA, NB_VOLUME_TYPES }; // to keep synchronised with GetSize()!
00057 
00058   SMDS_VolumeTool ();
00059   ~SMDS_VolumeTool ();
00060   SMDS_VolumeTool (const SMDS_MeshElement* theVolume,
00061                    const bool              ignoreCentralNodes=true);
00062 
00063   bool Set (const SMDS_MeshElement* theVolume,
00064             const bool              ignoreCentralNodes=true);
00065   // Set volume.
00066   // Return false if theVolume is not of type SMDSAbs_Volume.
00067   // ignoreCentralNodes makes skip nodes at face centers when returning
00068   // nodes of faces of SMDSEntity_TriQuad_Hexa
00069 
00070   const SMDS_MeshVolume* Element() const;
00071   // return element
00072 
00073   int ID() const;
00074   // return element ID
00075 
00076   // -----------------------
00077   // general info
00078   // -----------------------
00079 
00080   VolumeType GetVolumeType() const;
00081 
00082   bool IsForward() const { return myVolForward; }
00083   // Check volume orientation. can be changed by Inverse().
00084   // See node order of forward volumes at the file bottom
00085 
00086   void Inverse();
00087   // Change nodes order as if the volume changes its orientation:
00088   // top and bottom faces are reversed.
00089   // Result of IsForward() and methods returning nodes change
00090 
00091   const SMDS_MeshNode** GetNodes() { return myVolumeNodes; }
00092   // Return array of volume nodes
00093 
00094   int NbNodes() { return myVolumeNbNodes; }
00095   // Return array of volume nodes
00096 
00097   double GetSize() const;
00098   // Return element volume
00099 
00100   bool GetBaryCenter (double & X, double & Y, double & Z) const;
00101 
00102   bool IsOut(double X, double Y, double Z, double tol) const;
00103   // Classify a point
00104 
00105   // -----------------------
00106   // info on node connection
00107   // -----------------------
00108 
00109   bool IsLinked (const SMDS_MeshNode* theNode1,
00110                  const SMDS_MeshNode* theNode2,
00111                  const bool           theIgnoreMediumNodes=false) const;
00112   // Return true if theNode1 is linked with theNode2.
00113   // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
00114 
00115   bool IsLinked (const int theNode1Index,
00116                  const int theNode2Index,
00117                  bool      theIgnoreMediumNodes=false) const;
00118   // Return true if the node with theNode1Index is linked
00119   // with the node with theNode2Index
00120   // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
00121 
00122   int GetNodeIndex(const SMDS_MeshNode* theNode) const;
00123   // Return an index of theNode
00124 
00125   int GetAllExistingEdges(std::vector<const SMDS_MeshElement*> & edges) const;
00126   // Fill vector with boundary edges existing in the mesh
00127 
00128   double MinLinearSize2() const;
00129   // Return minimal square distance between connected corner nodes
00130 
00131   // -------------
00132   // info on faces
00133   // -------------
00134   // For all elements, 0-th face is bottom based on the first nodes.
00135   // For prismatic elements (tetra,hexa,prisms), 1-th face is a top one.
00136   // For all elements, side faces follow order of bottom nodes
00137 
00138   void SetExternalNormal ();
00139   // Node order in faces  will be so that faces normals are external.
00140 
00141   int NbFaces() const { return myNbFaces; }
00142   // Return number of faces of the volume. In the following
00143   // methods 0 <= faceIndex < NbFaces()
00144 
00145   int NbFaceNodes( int faceIndex ) const;
00146   // Return number of nodes in the array of face nodes
00147 
00148   const int* GetFaceNodesIndices( int faceIndex ) const;
00149   // Return the array of face nodes indices
00150   // To comfort link iteration, the array
00151   // length == NbFaceNodes( faceIndex ) + 1 and
00152   // the last node index == the first one, except for
00153   // SMDSEntity_TriQuad_Hexa at ignoreCentralNodes==false.
00154   // NOTE: for the quadratic volume, node indices are in the order the nodes encounter
00155   // in face boundary and not the order they are in the mesh face
00156 
00157   const SMDS_MeshNode** GetFaceNodes( int faceIndex ) const;
00158   // Return the array of face nodes.
00159   // To comfort link iteration, the array
00160   // length == NbFaceNodes( faceIndex ) + 1 and
00161   // the last node == the first one, except for
00162   // SMDSEntity_TriQuad_Hexa at ignoreCentralNodes==false.
00163   // NOTE: for the quadratic volume, nodes are in the order they encounter in face boundary
00164   // and not the order they are in the mesh face
00165   // WARNING: do not modify the array, some methods
00166   //          work basing on its contents
00167 
00168   bool GetFaceNodes (int faceIndex,
00169                      std::set<const SMDS_MeshNode*>& theFaceNodes ) const;
00170   // Return a set of face nodes.
00171 
00172   bool IsFaceExternal( int faceIndex ) const;
00173   // Check normal orientation of a face.
00174   // SetExternalNormal() is taken into account.
00175 
00176   bool IsFreeFace(  int faceIndex, const SMDS_MeshElement** otherVol=0 ) const;
00177   // Check that all volumes built on the face nodes lays on one side
00178   // otherVol returns another volume sharing the given facet
00179 
00180   bool GetFaceNormal (int faceIndex, double & X, double & Y, double & Z) const;
00181   // Return a normal to a face
00182 
00183   bool GetFaceBaryCenter (int faceIndex, double & X, double & Y, double & Z) const;
00184   // Return barycenter of a face
00185 
00186   double GetFaceArea( int faceIndex ) const;
00187   // Return face area
00188 
00189   int GetOppFaceIndex( int faceIndex ) const;
00190   // Return index of the opposite face if it exists, else -1.
00191 
00192   int GetCenterNodeIndex( int faceIndex ) const;
00193   // Return index of the node located at face center of a quadratic element like HEX27
00194 
00195   int GetFaceIndex( const std::set<const SMDS_MeshNode*>& theFaceNodes ) const;
00196   // Return index of a face formed by theFaceNodes.
00197   // Return -1 if a face not found
00198 
00199   //int GetFaceIndex( const std::set<int>& theFaceNodesIndices );
00200   // Return index of a face formed by theFaceNodesIndices
00201   // Return -1 if a face not found
00202 
00203   int GetAllExistingFaces(std::vector<const SMDS_MeshElement*> & faces) const;
00204   // Fill vector with boundary faces existing in the mesh
00205 
00206   // ------------------------
00207   // static methods for faces
00208   // ------------------------
00209 
00210   static VolumeType GetType(int nbNodes);
00211   // return VolumeType by nb of nodes in a volume
00212 
00213   static int NbFaces( VolumeType type );
00214   // return nb of faces by volume type
00215 
00216   static const int* GetFaceNodesIndices(VolumeType type,
00217                                         int        faceIndex,
00218                                         bool       external);
00219   // Return the array of face nodes indices
00220   // To comfort link iteration, the array
00221   // length == NbFaceNodes( faceIndex ) + 1 and
00222   // the last node index == the first one.
00223   // Nodes at face centers of SMDSEntity_TriQuad_Hexa are ignored
00224 
00225   static int NbFaceNodes(VolumeType type, int faceIndex );
00226   // Return number of nodes in the array of face nodes
00227   // Nodes at face centers of SMDSEntity_TriQuad_Hexa are ignored
00228 
00229   static int NbCornerNodes(VolumeType type);
00230   // Useful to know nb of corner nodes of a quadratic volume
00231 
00232 private:
00233 
00234   bool setFace( int faceIndex ) const;
00235 
00236   const SMDS_MeshElement* myVolume;
00237   const SMDS_VtkVolume*   myPolyedre;
00238   bool                    myIgnoreCentralNodes;
00239 
00240   bool                    myVolForward;
00241   int                     myNbFaces;
00242   int                     myVolumeNbNodes;
00243   const SMDS_MeshNode**   myVolumeNodes;
00244   std::vector< int >      myPolyIndices;
00245 
00246   mutable bool                    myExternalFaces;
00247 
00248   mutable const int*              myAllFacesNodeIndices_F;
00249   mutable const int*              myAllFacesNodeIndices_RE;
00250   mutable const int*              myAllFacesNbNodes;
00251   mutable int                     myMaxFaceNbNodes;
00252 
00253   mutable int                     myCurFace;
00254   mutable int                     myFaceNbNodes;
00255   mutable int*                    myFaceNodeIndices;
00256   mutable const SMDS_MeshNode**   myFaceNodes;
00257 
00258 };
00259 #endif
00260 
00261 
00263 //
00264 //                   ORDER OF NODES OF FORWARD ELEMENT
00265 //
00267 /*
00268 //           N3
00269 //           +
00270 //          /|\
00271 //         / | \
00272 //        /  |  \
00273 //    N0 +---|---+ N1                TETRAHEDRON
00274 //       \   |   /
00275 //        \  |  /
00276 //         \ | /
00277 //          \|/
00278 //           +
00279 //           N2
00280 
00281 //            + N4
00282 //           /|\
00283 //          / | \
00284 //         /  |  \
00285 //        /   |   \
00286 //    N3 +---------+ N5
00287 //       |    |    |
00288 //       |    + N1 |
00289 //       |   / \   |                PENTAHEDRON
00290 //       |  /   \  |
00291 //       | /     \ |
00292 //       |/       \|
00293 //    N0 +---------+ N2
00294 
00295 //         N5+----------+N6
00296 //          /|         /|
00297 //         / |        / |
00298 //        /  |       /  |
00299 //     N4+----------+N7 |
00300 //       |   |      |   |           HEXAHEDRON
00301 //       |   |      |   |
00302 //       |   |      |   |
00303 //       | N1+------|---+N2
00304 //       |  /       |  /
00305 //       | /        | /
00306 //       |/         |/
00307 //     N0+----------+N3
00308 //
00309 */