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