Back to index

salome-smesh  6.5.0
SMDS_MeshInfo.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  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 #include <vector>
00028 using namespace std;
00029 
00030 #include "SMESH_SMDS.hxx"
00031 
00032 #include "SMDS_MeshElement.hxx"
00033 
00034 class SMDS_EXPORT SMDS_MeshInfo
00035 {
00036 public:
00037 
00038   inline SMDS_MeshInfo();
00039   inline SMDS_MeshInfo& operator=(const SMDS_MeshInfo& other);
00040   inline void Clear();
00041 
00042   int NbNodes() const { return myNbNodes; }
00043   inline int NbElements(SMDSAbs_ElementType type=SMDSAbs_All) const;
00044   inline int NbEntities(SMDSAbs_EntityType  type) const;
00045 
00046   int Nb0DElements() const { return myNb0DElements; }
00047   inline int NbEdges      (SMDSAbs_ElementOrder order = ORDER_ANY) const;
00048 
00049   inline int NbFaces      (SMDSAbs_ElementOrder order = ORDER_ANY) const;
00050   inline int NbTriangles  (SMDSAbs_ElementOrder order = ORDER_ANY) const;
00051   inline int NbQuadrangles(SMDSAbs_ElementOrder order = ORDER_ANY) const;
00052   int NbBiQuadQuadrangles() const { return myNbBiQuadQuadrangles; }
00053   int NbPolygons() const { return myNbPolygons; }
00054 
00055   inline int NbVolumes (SMDSAbs_ElementOrder order = ORDER_ANY) const;
00056   inline int NbTetras  (SMDSAbs_ElementOrder order = ORDER_ANY) const;
00057   inline int NbHexas   (SMDSAbs_ElementOrder order = ORDER_ANY) const;
00058   inline int NbPyramids(SMDSAbs_ElementOrder order = ORDER_ANY) const;
00059   inline int NbPrisms  (SMDSAbs_ElementOrder order = ORDER_ANY) const;
00060   inline int NbHexPrisms(SMDSAbs_ElementOrder order = ORDER_ANY) const;
00061   int NbTriQuadHexas() const { return myNbTriQuadHexas; }
00062   int NbPolyhedrons() const { return myNbPolyhedrons; }
00063 
00064 protected:
00065   inline void addWithPoly(const SMDS_MeshElement* el);
00066   inline void setNb(const SMDSAbs_EntityType geomType, const int nb);
00067 
00068 private:
00069   friend class SMDS_Mesh;
00070 
00071   // methods to count NOT POLY elements
00072   inline void remove(const SMDS_MeshElement* el);
00073   inline void add   (const SMDS_MeshElement* el);
00074   inline int  index(SMDSAbs_ElementType type, int nbNodes) const;
00075   // methods to remove elements of ANY kind
00076   inline void RemoveEdge(const SMDS_MeshElement* el);
00077   inline void RemoveFace(const SMDS_MeshElement* el);
00078   inline void RemoveVolume(const SMDS_MeshElement* el);
00079 
00080   int myNbNodes;
00081 
00082   int myNb0DElements;
00083   int myNbEdges      , myNbQuadEdges      ;
00084   int myNbTriangles  , myNbQuadTriangles  ;
00085   int myNbQuadrangles, myNbQuadQuadrangles, myNbBiQuadQuadrangles;
00086   int myNbPolygons;
00087 
00088   int myNbTetras  , myNbQuadTetras  ;
00089   int myNbHexas   , myNbQuadHexas,    myNbTriQuadHexas;
00090   int myNbPyramids, myNbQuadPyramids;
00091   int myNbPrisms  , myNbQuadPrisms  ;
00092   int myNbHexPrism;
00093   int myNbPolyhedrons;
00094 
00095   std::vector<int*> myNb; // pointers to myNb... fields
00096   std::vector<int>  myShift; // shift to get an index in myNb by elem->NbNodes()
00097 };
00098 
00099 inline SMDS_MeshInfo::SMDS_MeshInfo():
00100   myNbNodes      (0),
00101   myNb0DElements (0),
00102   myNbEdges      (0), myNbQuadEdges      (0),
00103   myNbTriangles  (0), myNbQuadTriangles  (0),
00104   myNbQuadrangles(0), myNbQuadQuadrangles(0), myNbBiQuadQuadrangles(0),
00105   myNbPolygons   (0),
00106   myNbTetras     (0), myNbQuadTetras  (0),
00107   myNbHexas      (0), myNbQuadHexas   (0), myNbTriQuadHexas(0),
00108   myNbPyramids   (0), myNbQuadPyramids(0),
00109   myNbPrisms     (0), myNbQuadPrisms  (0),
00110   myNbHexPrism   (0),
00111   myNbPolyhedrons(0)
00112 {
00113   // Number of nodes in standard element types (. - actual nb, * - after the shift)
00114   // n   v  f  e  0  n
00115   // o   o  a  d  d  o
00116   // d   l  c  g     d
00117   // e      e  e     e
00118   // s
00119   // =================
00120   // 0 ---------------  - DON't USE 0!!!
00121   // 1            .  *
00122   // 2         .
00123   // 3      .     *
00124   // 4   *  .  .
00125   // 5   *
00126   // 6   *  .
00127   // 7         *
00128   // 8   *  .
00129   // 9      .  *
00130   // 10  *
00131   // 11
00132   // 12  *
00133   // 13  *
00134   // 14
00135   // 15  *
00136   // 16     *
00137   // 17     *
00138   // 18
00139   // 19     *
00140   // 20  *
00141   // 21     *
00142   // 22     *
00143   // 23
00144   // 24
00145   // 25
00146   // 26
00147   // 27  *
00148   //
00149   // So to have a unique index for each type basing on nb of nodes, we use a shift:
00150   myShift.resize(SMDSAbs_NbElementTypes, 0);
00151 
00152   myShift[ SMDSAbs_Face      ] = +13;// 3->16, 4->17, 6->19, 8->21, 9->22
00153   myShift[ SMDSAbs_Edge      ] = +5; // 2->7, 4->9
00154   myShift[ SMDSAbs_0DElement ] = +2; // 1->3
00155 
00156   myNb.resize( index( SMDSAbs_Volume,27 ) + 1, NULL);
00157 
00158   myNb[ index( SMDSAbs_Node,1 )] = & myNbNodes;
00159 
00160   myNb[ index( SMDSAbs_0DElement,1 )] = & myNb0DElements;
00161 
00162   myNb[ index( SMDSAbs_Edge,2 )] = & myNbEdges;
00163   myNb[ index( SMDSAbs_Edge,4 )] = & myNbQuadEdges;
00164 
00165   myNb[ index( SMDSAbs_Face,3 )] = & myNbTriangles;
00166   myNb[ index( SMDSAbs_Face,4 )] = & myNbQuadrangles;
00167   myNb[ index( SMDSAbs_Face,6 )] = & myNbQuadTriangles;
00168   myNb[ index( SMDSAbs_Face,8 )] = & myNbQuadQuadrangles;
00169   myNb[ index( SMDSAbs_Face,9 )] = & myNbBiQuadQuadrangles;
00170 
00171   myNb[ index( SMDSAbs_Volume, 4)]  = & myNbTetras;
00172   myNb[ index( SMDSAbs_Volume, 5)]  = & myNbPyramids;
00173   myNb[ index( SMDSAbs_Volume, 6)]  = & myNbPrisms;
00174   myNb[ index( SMDSAbs_Volume, 8)]  = & myNbHexas;
00175   myNb[ index( SMDSAbs_Volume, 10)] = & myNbQuadTetras;  
00176   myNb[ index( SMDSAbs_Volume, 12)] = & myNbHexPrism;
00177   myNb[ index( SMDSAbs_Volume, 13)] = & myNbQuadPyramids;
00178   myNb[ index( SMDSAbs_Volume, 15)] = & myNbQuadPrisms;  
00179   myNb[ index( SMDSAbs_Volume, 20)] = & myNbQuadHexas;   
00180   myNb[ index( SMDSAbs_Volume, 27)] = & myNbTriQuadHexas;   
00181 }
00182 
00183 inline SMDS_MeshInfo& // operator=
00184 SMDS_MeshInfo::operator=(const SMDS_MeshInfo& other)
00185 { for ( int i=0; i<myNb.size(); ++i ) if ( myNb[i] ) (*myNb[i])=(*other.myNb[i]);
00186   myNbPolygons = other.myNbPolygons;
00187   myNbPolyhedrons = other.myNbPolyhedrons;
00188   return *this;
00189 }
00190 
00191 inline void // Clear
00192 SMDS_MeshInfo::Clear()
00193 { for ( int i=0; i<myNb.size(); ++i ) if ( myNb[i] ) (*myNb[i])=0;
00194   myNbPolygons=myNbPolyhedrons=0;
00195 }
00196 
00197 inline int // index
00198 SMDS_MeshInfo::index(SMDSAbs_ElementType type, int nbNodes) const
00199 { return nbNodes + myShift[ type ]; }
00200 
00201 inline void // remove
00202 SMDS_MeshInfo::remove(const SMDS_MeshElement* el)
00203 { --(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
00204 
00205 inline void // add
00206 SMDS_MeshInfo::add(const SMDS_MeshElement* el)
00207 { ++(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
00208 
00209 inline void // addWithPoly
00210 SMDS_MeshInfo::addWithPoly(const SMDS_MeshElement* el)
00211 {
00212   if ( el->IsPoly() )
00213     ++( el->GetType()==SMDSAbs_Face ? myNbPolygons : myNbPolyhedrons );
00214   else
00215     add(el);
00216 }
00217 inline void // RemoveEdge
00218 SMDS_MeshInfo::RemoveEdge(const SMDS_MeshElement* el)
00219 { if ( el->IsQuadratic() ) --myNbQuadEdges; else --myNbEdges; }
00220 
00221 inline void // RemoveFace
00222 SMDS_MeshInfo::RemoveFace(const SMDS_MeshElement* el)
00223 { if ( el->IsPoly() ) --myNbPolygons; else remove( el ); }
00224 
00225 inline void // RemoveVolume
00226 SMDS_MeshInfo::RemoveVolume(const SMDS_MeshElement* el)
00227 { if ( el->IsPoly() ) --myNbPolyhedrons; else remove( el ); }
00228 
00229 inline int // NbEdges
00230 SMDS_MeshInfo::NbEdges      (SMDSAbs_ElementOrder order) const
00231 { return order == ORDER_ANY ? myNbEdges+myNbQuadEdges : order == ORDER_LINEAR ? myNbEdges : myNbQuadEdges; }
00232 
00233 inline int // NbFaces
00234 SMDS_MeshInfo::NbFaces      (SMDSAbs_ElementOrder order) const
00235 { return NbTriangles(order)+NbQuadrangles(order)+(order == ORDER_QUADRATIC ? 0 : myNbPolygons); }
00236 
00237 inline int // NbTriangles
00238 SMDS_MeshInfo::NbTriangles  (SMDSAbs_ElementOrder order) const
00239 { return order == ORDER_ANY ? myNbTriangles+myNbQuadTriangles : order == ORDER_LINEAR ? myNbTriangles : myNbQuadTriangles; }
00240 
00241 inline int // NbQuadrangles
00242 SMDS_MeshInfo::NbQuadrangles(SMDSAbs_ElementOrder order) const
00243 { return order == ORDER_ANY ? myNbQuadrangles+myNbQuadQuadrangles+myNbBiQuadQuadrangles : order == ORDER_LINEAR ? myNbQuadrangles : myNbQuadQuadrangles+myNbBiQuadQuadrangles; }
00244 
00245 inline int // NbVolumes
00246 SMDS_MeshInfo::NbVolumes (SMDSAbs_ElementOrder order) const
00247 { return NbTetras(order) + NbHexas(order) + NbPyramids(order) + NbPrisms(order) + NbHexPrisms(order) + (order == ORDER_QUADRATIC ? 0 : myNbPolyhedrons); }
00248 
00249 inline int // NbTetras
00250 SMDS_MeshInfo::NbTetras  (SMDSAbs_ElementOrder order) const
00251 { return order == ORDER_ANY ? myNbTetras+myNbQuadTetras : order == ORDER_LINEAR ? myNbTetras : myNbQuadTetras; }
00252 
00253 inline int // NbHexas
00254 SMDS_MeshInfo::NbHexas   (SMDSAbs_ElementOrder order) const
00255 { return order == ORDER_ANY ? myNbHexas+myNbQuadHexas+myNbTriQuadHexas : order == ORDER_LINEAR ? myNbHexas : myNbQuadHexas+myNbTriQuadHexas; }
00256 
00257 inline int // NbPyramids
00258 SMDS_MeshInfo::NbPyramids(SMDSAbs_ElementOrder order) const
00259 { return order == ORDER_ANY ? myNbPyramids+myNbQuadPyramids : order == ORDER_LINEAR ? myNbPyramids : myNbQuadPyramids; }
00260 
00261 inline int // NbPrisms
00262 SMDS_MeshInfo::NbPrisms  (SMDSAbs_ElementOrder order) const
00263 { return order == ORDER_ANY ? myNbPrisms+myNbQuadPrisms : order == ORDER_LINEAR ? myNbPrisms : myNbQuadPrisms; }
00264 
00265 inline int // NbHexPrisms
00266 SMDS_MeshInfo::NbHexPrisms  (SMDSAbs_ElementOrder order) const
00267 { return order == ORDER_ANY ? myNbHexPrism : order == ORDER_LINEAR ? myNbHexPrism : 0; }
00268 
00269 inline int // NbElements
00270 SMDS_MeshInfo::NbElements(SMDSAbs_ElementType type) const
00271 { 
00272   int nb = 0;
00273   switch (type) {
00274   case SMDSAbs_All:
00275     for ( int i=1+index( SMDSAbs_Node,1 ); i<myNb.size(); ++i ) if ( myNb[i] ) nb += *myNb[i];
00276     nb += myNbPolygons + myNbPolyhedrons;
00277     break;
00278   case SMDSAbs_Volume:
00279     nb = myNbTetras+ myNbPyramids+ myNbPrisms+ myNbHexas+ myNbHexPrism+
00280       myNbQuadTetras+ myNbQuadPyramids+ myNbQuadPrisms+ myNbQuadHexas+ myNbTriQuadHexas+
00281       myNbPolyhedrons;
00282     break;
00283   case SMDSAbs_Face:
00284     nb = myNbTriangles+ myNbQuadrangles+
00285       myNbQuadTriangles+ myNbQuadQuadrangles+ myNbBiQuadQuadrangles+ myNbPolygons;
00286     break;
00287   case SMDSAbs_Edge:
00288     nb = myNbEdges + myNbQuadEdges;
00289     break;
00290   case SMDSAbs_0DElement:
00291     nb = myNb0DElements;
00292     break;
00293   case SMDSAbs_Node:
00294     nb = myNbNodes;
00295     break;
00296   default:;
00297   }
00298   return nb;
00299 }
00300 
00301 int // NbEntities
00302 SMDS_MeshInfo::NbEntities(SMDSAbs_EntityType type) const
00303 {
00304   switch (type) {
00305   case SMDSEntity_Node:             return myNbNodes;
00306   case SMDSEntity_0D:               return myNb0DElements;
00307   case SMDSEntity_Edge:             return myNbEdges;
00308   case SMDSEntity_Quad_Edge:        return myNbQuadEdges;
00309   case SMDSEntity_Triangle:         return myNbTriangles;
00310   case SMDSEntity_Quad_Triangle:    return myNbQuadTriangles;
00311   case SMDSEntity_Quadrangle:       return myNbQuadrangles;
00312   case SMDSEntity_Quad_Quadrangle:  return myNbQuadQuadrangles;
00313   case SMDSEntity_BiQuad_Quadrangle:return myNbBiQuadQuadrangles;
00314   case SMDSEntity_Polygon:          return myNbPolygons;
00315   case SMDSEntity_Tetra:            return myNbTetras;
00316   case SMDSEntity_Quad_Tetra:       return myNbQuadTetras;
00317   case SMDSEntity_Pyramid:          return myNbPyramids;
00318   case SMDSEntity_Quad_Pyramid:     return myNbQuadPyramids;
00319   case SMDSEntity_Hexa:             return myNbHexas;
00320   case SMDSEntity_Quad_Hexa:        return myNbQuadHexas;
00321   case SMDSEntity_TriQuad_Hexa:     return myNbTriQuadHexas;
00322   case SMDSEntity_Penta:            return myNbPrisms;
00323   case SMDSEntity_Quad_Penta:       return myNbQuadPrisms;
00324   case SMDSEntity_Hexagonal_Prism:  return myNbHexPrism;
00325   case SMDSEntity_Polyhedra:        return myNbPolyhedrons;
00326   case SMDSEntity_Quad_Polygon:
00327   case SMDSEntity_Quad_Polyhedra:
00328     break;
00329   }
00330   return 0;
00331 }
00332 
00333 void // set
00334 SMDS_MeshInfo::setNb(const SMDSAbs_EntityType geomType, const int nb)
00335 {
00336   switch (geomType) {
00337   case SMDSEntity_Node:             myNbNodes             = nb; break;
00338   case SMDSEntity_0D:               myNb0DElements        = nb; break;
00339   case SMDSEntity_Edge:             myNbEdges             = nb; break;
00340   case SMDSEntity_Quad_Edge:        myNbQuadEdges         = nb; break;
00341   case SMDSEntity_Triangle:         myNbTriangles         = nb; break;
00342   case SMDSEntity_Quad_Triangle:    myNbQuadTriangles     = nb; break;
00343   case SMDSEntity_Quadrangle:       myNbQuadrangles       = nb; break;
00344   case SMDSEntity_Quad_Quadrangle:  myNbQuadQuadrangles   = nb; break;
00345   case SMDSEntity_BiQuad_Quadrangle:myNbBiQuadQuadrangles = nb; break;
00346   case SMDSEntity_Polygon:          myNbPolygons          = nb; break;
00347   case SMDSEntity_Tetra:            myNbTetras            = nb; break;
00348   case SMDSEntity_Quad_Tetra:       myNbQuadTetras        = nb; break;
00349   case SMDSEntity_Pyramid:          myNbPyramids          = nb; break;
00350   case SMDSEntity_Quad_Pyramid:     myNbQuadPyramids      = nb; break;
00351   case SMDSEntity_Hexa:             myNbHexas             = nb; break;
00352   case SMDSEntity_Quad_Hexa:        myNbQuadHexas         = nb; break;
00353   case SMDSEntity_TriQuad_Hexa:     myNbTriQuadHexas      = nb; break;
00354   case SMDSEntity_Penta:            myNbPrisms            = nb; break;
00355   case SMDSEntity_Quad_Penta:       myNbQuadPrisms        = nb; break;
00356   case SMDSEntity_Hexagonal_Prism:  myNbHexPrism          = nb; break;
00357   case SMDSEntity_Polyhedra:        myNbPolyhedrons       = nb; break;
00358   case SMDSEntity_Quad_Polygon:
00359   case SMDSEntity_Quad_Polyhedra:
00360     break;
00361   }
00362 }
00363 
00364 #endif