Version: 6.3.1

src/SMDS/SMDS_MeshInfo.hxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // File      : SMDS_MeshInfo.hxx
00021 // Created   : Mon Sep 24 18:32:41 2007
00022 // Author    : Edward AGAPOV (eap)
00023 //
00024 #ifndef SMDS_MeshInfo_HeaderFile
00025 #define SMDS_MeshInfo_HeaderFile
00026 
00027 using namespace std;
00028 
00029 #include "SMESH_SMDS.hxx"
00030 
00031 #include "SMDS_MeshElement.hxx"
00032 
00033 class SMDS_EXPORT SMDS_MeshInfo
00034 {
00035 public:
00036 
00037   inline SMDS_MeshInfo();
00038   inline void Clear();
00039 
00040   int NbNodes() const { return myNbNodes; }
00041   inline int NbElements(SMDSAbs_ElementType type=SMDSAbs_All) const;
00042   inline int NbEntities(SMDSAbs_EntityType  type) const;
00043 
00044   int Nb0DElements() const { return myNb0DElements; }
00045   inline int NbEdges      (SMDSAbs_ElementOrder order = ORDER_ANY) const;
00046   inline int NbFaces      (SMDSAbs_ElementOrder order = ORDER_ANY) const;
00047   inline int NbTriangles  (SMDSAbs_ElementOrder order = ORDER_ANY) const;
00048   inline int NbQuadrangles(SMDSAbs_ElementOrder order = ORDER_ANY) const;
00049   int NbPolygons() const { return myNbPolygons; }
00050 
00051   inline int NbVolumes (SMDSAbs_ElementOrder order = ORDER_ANY) const;
00052   inline int NbTetras  (SMDSAbs_ElementOrder order = ORDER_ANY) const;
00053   inline int NbHexas   (SMDSAbs_ElementOrder order = ORDER_ANY) const;
00054   inline int NbPyramids(SMDSAbs_ElementOrder order = ORDER_ANY) const;
00055   inline int NbPrisms  (SMDSAbs_ElementOrder order = ORDER_ANY) const;
00056   int NbPolyhedrons() const { return myNbPolyhedrons; }
00057 
00058 private:
00059   friend class SMDS_Mesh;
00060 
00061   // methods to count NOT POLY elements
00062   inline void remove(const SMDS_MeshElement* el);
00063   inline void add   (const SMDS_MeshElement* el);
00064   inline int  index(SMDSAbs_ElementType type, int nbNodes) const;
00065   // methods to remove elements of ANY kind
00066   inline void RemoveEdge(const SMDS_MeshElement* el);
00067   inline void RemoveFace(const SMDS_MeshElement* el);
00068   inline void RemoveVolume(const SMDS_MeshElement* el);
00069 
00070   int myNbNodes;
00071 
00072   int myNb0DElements;
00073   int myNbEdges      , myNbQuadEdges      ;
00074   int myNbTriangles  , myNbQuadTriangles  ;
00075   int myNbQuadrangles, myNbQuadQuadrangles;
00076   int myNbPolygons;
00077 
00078   int myNbTetras  , myNbQuadTetras  ;
00079   int myNbHexas   , myNbQuadHexas   ;
00080   int myNbPyramids, myNbQuadPyramids;
00081   int myNbPrisms  , myNbQuadPrisms  ;
00082   int myNbPolyhedrons;
00083 
00084   std::vector<int*> myNb; // pointers to myNb... fields
00085   std::vector<int>  myShift; // shift to get an index in myNb by elem->NbNodes()
00086 };
00087 
00088 inline SMDS_MeshInfo::SMDS_MeshInfo():
00089   myNbNodes(0),
00090   myNb0DElements(0),
00091   myNbEdges      (0), myNbQuadEdges      (0),
00092   myNbTriangles  (0), myNbQuadTriangles  (0),
00093   myNbQuadrangles(0), myNbQuadQuadrangles(0),
00094   myNbPolygons(0),
00095   myNbTetras  (0), myNbQuadTetras  (0),
00096   myNbHexas   (0), myNbQuadHexas   (0),
00097   myNbPyramids(0), myNbQuadPyramids(0),
00098   myNbPrisms  (0), myNbQuadPrisms  (0),
00099   myNbPolyhedrons(0)
00100 {
00101   // Number of nodes in standard element types
00102   // n   v  f  e  0  n
00103   // o   o  a  d  d  o
00104   // d   l  c  g     d
00105   // e      e  e     e
00106   // s
00107   // -----------------
00108   // 0         *
00109   // 1            .  *
00110   // 2         *
00111   // 3      .     *
00112   // 4   *  .  .
00113   // 5   *
00114   // 6   *  .
00115   // 7
00116   // 8   *  .
00117   // 9
00118   // 10  *
00119   // 11     *
00120   // 12     *
00121   // 13  *
00122   // 14     *
00123   // 15  *
00124   // 16     *
00125   // 17
00126   // 18
00127   // 19
00128   // 20  *
00129   //
00130   // So to have a unique index for each type basing on nb of nodes, we use a shift:
00131   myShift.resize(SMDSAbs_NbElementTypes, 0);
00132 
00133   myShift[ SMDSAbs_Face      ] = +8; // 3->11, 4->12, 6->14, 8->16
00134   myShift[ SMDSAbs_Edge      ] = -2; // 2->0, 4->2
00135   myShift[ SMDSAbs_0DElement ] = +2; // 1->3
00136 
00137   myNb.resize( index( SMDSAbs_Volume,20 ) + 1, NULL);
00138 
00139   myNb[ index( SMDSAbs_Node,1 )] = & myNbNodes;
00140 
00141   myNb[ index( SMDSAbs_0DElement,1 )] = & myNb0DElements;
00142 
00143   myNb[ index( SMDSAbs_Edge,2 )] = & myNbEdges;
00144   myNb[ index( SMDSAbs_Edge,4 )] = & myNbQuadEdges;
00145 
00146   myNb[ index( SMDSAbs_Face,3 )] = & myNbTriangles;
00147   myNb[ index( SMDSAbs_Face,4 )] = & myNbQuadrangles;
00148   myNb[ index( SMDSAbs_Face,6 )] = & myNbQuadTriangles;
00149   myNb[ index( SMDSAbs_Face,8 )] = & myNbQuadQuadrangles;
00150 
00151   myNb[ index( SMDSAbs_Volume, 4)]  = & myNbTetras;
00152   myNb[ index( SMDSAbs_Volume, 5)]  = & myNbPyramids;
00153   myNb[ index( SMDSAbs_Volume, 6)]  = & myNbPrisms;
00154   myNb[ index( SMDSAbs_Volume, 8)]  = & myNbHexas;
00155   myNb[ index( SMDSAbs_Volume, 10)] = & myNbQuadTetras;  
00156   myNb[ index( SMDSAbs_Volume, 13)] = & myNbQuadPyramids;
00157   myNb[ index( SMDSAbs_Volume, 15)] = & myNbQuadPrisms;  
00158   myNb[ index( SMDSAbs_Volume, 20)] = & myNbQuadHexas;   
00159 }
00160 
00161 inline void // Clear
00162 SMDS_MeshInfo::Clear()
00163 { for ( int i=0; i<myNb.size(); ++i ) if ( myNb[i] ) (*myNb[i])=0;
00164   myNbPolygons=myNbPolyhedrons=0;
00165 }
00166 
00167 inline int // index
00168 SMDS_MeshInfo::index(SMDSAbs_ElementType type, int nbNodes) const
00169 { return nbNodes + myShift[ type ]; }
00170 
00171 inline void // remove
00172 SMDS_MeshInfo::remove(const SMDS_MeshElement* el)
00173 { --(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
00174 
00175 inline void // add
00176 SMDS_MeshInfo::add(const SMDS_MeshElement* el)
00177 { ++(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
00178 
00179 inline void // RemoveEdge
00180 SMDS_MeshInfo::RemoveEdge(const SMDS_MeshElement* el)
00181 { if ( el->IsQuadratic() ) --myNbQuadEdges; else --myNbEdges; }
00182 
00183 inline void // RemoveFace
00184 SMDS_MeshInfo::RemoveFace(const SMDS_MeshElement* el)
00185 { if ( el->IsPoly() ) --myNbPolygons; else remove( el ); }
00186 
00187 inline void // RemoveVolume
00188 SMDS_MeshInfo::RemoveVolume(const SMDS_MeshElement* el)
00189 { if ( el->IsPoly() ) --myNbPolyhedrons; else remove( el ); }
00190 
00191 inline int // NbEdges
00192 SMDS_MeshInfo::NbEdges      (SMDSAbs_ElementOrder order) const
00193 { return order == ORDER_ANY ? myNbEdges+myNbQuadEdges : order == ORDER_LINEAR ? myNbEdges : myNbQuadEdges; }
00194 
00195 inline int // NbFaces
00196 SMDS_MeshInfo::NbFaces      (SMDSAbs_ElementOrder order) const
00197 { return NbTriangles(order)+NbQuadrangles(order)+(order == ORDER_QUADRATIC ? 0 : myNbPolygons); }
00198 
00199 inline int // NbTriangles
00200 SMDS_MeshInfo::NbTriangles  (SMDSAbs_ElementOrder order) const
00201 { return order == ORDER_ANY ? myNbTriangles+myNbQuadTriangles : order == ORDER_LINEAR ? myNbTriangles : myNbQuadTriangles; }
00202 
00203 inline int // NbQuadrangles
00204 SMDS_MeshInfo::NbQuadrangles(SMDSAbs_ElementOrder order) const
00205 { return order == ORDER_ANY ? myNbQuadrangles+myNbQuadQuadrangles : order == ORDER_LINEAR ? myNbQuadrangles : myNbQuadQuadrangles; }
00206 
00207 inline int // NbVolumes
00208 SMDS_MeshInfo::NbVolumes (SMDSAbs_ElementOrder order) const
00209 { return NbTetras(order) + NbHexas(order) + NbPyramids(order) + NbPrisms(order) + (order == ORDER_QUADRATIC ? 0 : myNbPolyhedrons); }
00210 
00211 inline int // NbTetras
00212 SMDS_MeshInfo::NbTetras  (SMDSAbs_ElementOrder order) const
00213 { return order == ORDER_ANY ? myNbTetras+myNbQuadTetras : order == ORDER_LINEAR ? myNbTetras : myNbQuadTetras; }
00214 
00215 inline int // NbHexas
00216 SMDS_MeshInfo::NbHexas   (SMDSAbs_ElementOrder order) const
00217 { return order == ORDER_ANY ? myNbHexas+myNbQuadHexas : order == ORDER_LINEAR ? myNbHexas : myNbQuadHexas; }
00218 
00219 inline int // NbPyramids
00220 SMDS_MeshInfo::NbPyramids(SMDSAbs_ElementOrder order) const
00221 { return order == ORDER_ANY ? myNbPyramids+myNbQuadPyramids : order == ORDER_LINEAR ? myNbPyramids : myNbQuadPyramids; }
00222 
00223 inline int // NbPrisms
00224 SMDS_MeshInfo::NbPrisms  (SMDSAbs_ElementOrder order) const
00225 { return order == ORDER_ANY ? myNbPrisms+myNbQuadPrisms : order == ORDER_LINEAR ? myNbPrisms : myNbQuadPrisms; }
00226 
00227 inline int // NbElements
00228 SMDS_MeshInfo::NbElements(SMDSAbs_ElementType type) const
00229 { 
00230   int nb = 0;
00231   switch (type) {
00232   case SMDSAbs_All:
00233     for ( int i=1+index( SMDSAbs_Node,1 ); i<myNb.size(); ++i ) if ( myNb[i] ) nb += *myNb[i];
00234     nb += myNbPolygons + myNbPolyhedrons;
00235     break;
00236   case SMDSAbs_Volume:
00237     nb = myNbTetras+ myNbPyramids+ myNbPrisms+ myNbHexas+
00238       myNbQuadTetras+ myNbQuadPyramids+ myNbQuadPrisms+ myNbQuadHexas+myNbPolyhedrons;
00239     break;
00240   case SMDSAbs_Face:
00241     nb = myNbTriangles+ myNbQuadrangles+ myNbQuadTriangles+ myNbQuadQuadrangles + myNbPolygons;
00242     break;
00243   case SMDSAbs_Edge:
00244     nb = myNbEdges + myNbQuadEdges;
00245     break;
00246   case SMDSAbs_0DElement:
00247     nb = myNb0DElements;
00248     break;
00249   case SMDSAbs_Node:
00250     nb = myNbNodes;
00251     break;
00252   default:;
00253   }
00254   return nb;
00255 }
00256 
00257 int // NbEntities
00258 SMDS_MeshInfo::NbEntities(SMDSAbs_EntityType  type) const
00259 {
00260   switch (type) {
00261   case SMDSEntity_Node:
00262     return myNbNodes;
00263     break;
00264   case SMDSEntity_0D:
00265     return myNb0DElements;
00266     break;
00267   case SMDSEntity_Edge:
00268     return myNbEdges;
00269     break;
00270   case SMDSEntity_Quad_Edge:
00271     return myNbQuadEdges;
00272     break;
00273   case SMDSEntity_Triangle:
00274     return myNbTriangles;
00275     break;
00276   case SMDSEntity_Quad_Triangle:
00277     return myNbQuadTriangles;
00278     break;
00279   case SMDSEntity_Quadrangle:
00280     return myNbQuadrangles;
00281     break;
00282   case SMDSEntity_Quad_Quadrangle:
00283     return myNbQuadQuadrangles;
00284     break;
00285   case SMDSEntity_Polygon:
00286     return myNbPolygons;
00287     break;
00288   case SMDSEntity_Tetra:
00289     return myNbTetras;
00290     break;
00291   case SMDSEntity_Quad_Tetra:
00292     return myNbQuadTetras;
00293     break;
00294   case SMDSEntity_Pyramid:
00295     return myNbPyramids;
00296     break;
00297   case SMDSEntity_Quad_Pyramid:
00298     return myNbQuadPyramids;
00299     break;
00300   case SMDSEntity_Hexa:
00301     return myNbHexas;
00302     break;
00303   case SMDSEntity_Quad_Hexa:
00304     return myNbQuadHexas;
00305     break;
00306   case SMDSEntity_Penta:
00307     return myNbPrisms;
00308     break;
00309   case SMDSEntity_Quad_Penta:
00310     return myNbQuadPrisms;
00311     break;
00312   case SMDSEntity_Polyhedra:
00313     return myNbPolyhedrons;
00314     break;
00315   case SMDSEntity_Quad_Polygon:
00316   case SMDSEntity_Quad_Polyhedra:
00317   default:
00318   break;
00319   }
00320   return 0;
00321 }
00322 
00323 #endif
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS