1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SMDS_MeshInfo.hxx
21 // Created : Mon Sep 24 18:32:41 2007
22 // Author : Edward AGAPOV (eap)
24 #ifndef SMDS_MeshInfo_HeaderFile
25 #define SMDS_MeshInfo_HeaderFile
29 #include "SMESH_SMDS.hxx"
31 #include "SMDS_MeshElement.hxx"
33 class SMDS_EXPORT SMDS_MeshInfo
37 inline SMDS_MeshInfo();
38 inline SMDS_MeshInfo& operator=(const SMDS_MeshInfo& other);
41 int NbNodes() const { return myNbNodes; }
42 inline int NbElements(SMDSAbs_ElementType type=SMDSAbs_All) const;
43 inline int NbEntities(SMDSAbs_EntityType type) const;
45 int Nb0DElements() const { return myNb0DElements; }
46 inline int NbEdges (SMDSAbs_ElementOrder order = ORDER_ANY) const;
48 inline int NbFaces (SMDSAbs_ElementOrder order = ORDER_ANY) const;
49 inline int NbTriangles (SMDSAbs_ElementOrder order = ORDER_ANY) const;
50 inline int NbQuadrangles(SMDSAbs_ElementOrder order = ORDER_ANY) const;
51 int NbBiQuadQuadrangles() const { return myNbBiQuadQuadrangles; }
52 int NbPolygons() const { return myNbPolygons; }
54 inline int NbVolumes (SMDSAbs_ElementOrder order = ORDER_ANY) const;
55 inline int NbTetras (SMDSAbs_ElementOrder order = ORDER_ANY) const;
56 inline int NbHexas (SMDSAbs_ElementOrder order = ORDER_ANY) const;
57 inline int NbPyramids(SMDSAbs_ElementOrder order = ORDER_ANY) const;
58 inline int NbPrisms (SMDSAbs_ElementOrder order = ORDER_ANY) const;
59 inline int NbHexPrisms(SMDSAbs_ElementOrder order = ORDER_ANY) const;
60 int NbTriQuadHexas() const { return myNbTriQuadHexas; }
61 int NbPolyhedrons() const { return myNbPolyhedrons; }
64 inline void addWithPoly(const SMDS_MeshElement* el);
67 friend class SMDS_Mesh;
69 // methods to count NOT POLY elements
70 inline void remove(const SMDS_MeshElement* el);
71 inline void add (const SMDS_MeshElement* el);
72 inline int index(SMDSAbs_ElementType type, int nbNodes) const;
73 // methods to remove elements of ANY kind
74 inline void RemoveEdge(const SMDS_MeshElement* el);
75 inline void RemoveFace(const SMDS_MeshElement* el);
76 inline void RemoveVolume(const SMDS_MeshElement* el);
81 int myNbEdges , myNbQuadEdges ;
82 int myNbTriangles , myNbQuadTriangles ;
83 int myNbQuadrangles, myNbQuadQuadrangles, myNbBiQuadQuadrangles;
86 int myNbTetras , myNbQuadTetras ;
87 int myNbHexas , myNbQuadHexas, myNbTriQuadHexas;
88 int myNbPyramids, myNbQuadPyramids;
89 int myNbPrisms , myNbQuadPrisms ;
93 std::vector<int*> myNb; // pointers to myNb... fields
94 std::vector<int> myShift; // shift to get an index in myNb by elem->NbNodes()
97 inline SMDS_MeshInfo::SMDS_MeshInfo():
100 myNbEdges (0), myNbQuadEdges (0),
101 myNbTriangles (0), myNbQuadTriangles (0),
102 myNbQuadrangles(0), myNbQuadQuadrangles(0), myNbBiQuadQuadrangles(0),
104 myNbTetras (0), myNbQuadTetras (0),
105 myNbHexas (0), myNbQuadHexas (0), myNbTriQuadHexas(0),
106 myNbPyramids (0), myNbQuadPyramids(0),
107 myNbPrisms (0), myNbQuadPrisms (0),
111 // Number of nodes in standard element types (. - actual nb, * - after the shift)
118 // 0 --------------- - DON't USE 0!!!
147 // So to have a unique index for each type basing on nb of nodes, we use a shift:
148 myShift.resize(SMDSAbs_NbElementTypes, 0);
150 myShift[ SMDSAbs_Face ] = +13;// 3->16, 4->17, 6->19, 8->21, 9->22
151 myShift[ SMDSAbs_Edge ] = +5; // 2->7, 4->9
152 myShift[ SMDSAbs_0DElement ] = +2; // 1->3
154 myNb.resize( index( SMDSAbs_Volume,27 ) + 1, NULL);
156 myNb[ index( SMDSAbs_Node,1 )] = & myNbNodes;
158 myNb[ index( SMDSAbs_0DElement,1 )] = & myNb0DElements;
160 myNb[ index( SMDSAbs_Edge,2 )] = & myNbEdges;
161 myNb[ index( SMDSAbs_Edge,4 )] = & myNbQuadEdges;
163 myNb[ index( SMDSAbs_Face,3 )] = & myNbTriangles;
164 myNb[ index( SMDSAbs_Face,4 )] = & myNbQuadrangles;
165 myNb[ index( SMDSAbs_Face,6 )] = & myNbQuadTriangles;
166 myNb[ index( SMDSAbs_Face,8 )] = & myNbQuadQuadrangles;
167 myNb[ index( SMDSAbs_Face,9 )] = & myNbBiQuadQuadrangles;
169 myNb[ index( SMDSAbs_Volume, 4)] = & myNbTetras;
170 myNb[ index( SMDSAbs_Volume, 5)] = & myNbPyramids;
171 myNb[ index( SMDSAbs_Volume, 6)] = & myNbPrisms;
172 myNb[ index( SMDSAbs_Volume, 8)] = & myNbHexas;
173 myNb[ index( SMDSAbs_Volume, 10)] = & myNbQuadTetras;
174 myNb[ index( SMDSAbs_Volume, 12)] = & myNbHexPrism;
175 myNb[ index( SMDSAbs_Volume, 13)] = & myNbQuadPyramids;
176 myNb[ index( SMDSAbs_Volume, 15)] = & myNbQuadPrisms;
177 myNb[ index( SMDSAbs_Volume, 20)] = & myNbQuadHexas;
178 myNb[ index( SMDSAbs_Volume, 27)] = & myNbTriQuadHexas;
181 inline SMDS_MeshInfo& // operator=
182 SMDS_MeshInfo::operator=(const SMDS_MeshInfo& other)
183 { for ( int i=0; i<myNb.size(); ++i ) if ( myNb[i] ) (*myNb[i])=(*other.myNb[i]);
184 myNbPolygons = other.myNbPolygons;
185 myNbPolyhedrons = other.myNbPolyhedrons;
190 SMDS_MeshInfo::Clear()
191 { for ( int i=0; i<myNb.size(); ++i ) if ( myNb[i] ) (*myNb[i])=0;
192 myNbPolygons=myNbPolyhedrons=0;
196 SMDS_MeshInfo::index(SMDSAbs_ElementType type, int nbNodes) const
197 { return nbNodes + myShift[ type ]; }
199 inline void // remove
200 SMDS_MeshInfo::remove(const SMDS_MeshElement* el)
201 { --(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
204 SMDS_MeshInfo::add(const SMDS_MeshElement* el)
205 { ++(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
207 inline void // addWithPoly
208 SMDS_MeshInfo::addWithPoly(const SMDS_MeshElement* el)
211 ++( el->GetType()==SMDSAbs_Face ? myNbPolygons : myNbPolyhedrons );
215 inline void // RemoveEdge
216 SMDS_MeshInfo::RemoveEdge(const SMDS_MeshElement* el)
217 { if ( el->IsQuadratic() ) --myNbQuadEdges; else --myNbEdges; }
219 inline void // RemoveFace
220 SMDS_MeshInfo::RemoveFace(const SMDS_MeshElement* el)
221 { if ( el->IsPoly() ) --myNbPolygons; else remove( el ); }
223 inline void // RemoveVolume
224 SMDS_MeshInfo::RemoveVolume(const SMDS_MeshElement* el)
225 { if ( el->IsPoly() ) --myNbPolyhedrons; else remove( el ); }
227 inline int // NbEdges
228 SMDS_MeshInfo::NbEdges (SMDSAbs_ElementOrder order) const
229 { return order == ORDER_ANY ? myNbEdges+myNbQuadEdges : order == ORDER_LINEAR ? myNbEdges : myNbQuadEdges; }
231 inline int // NbFaces
232 SMDS_MeshInfo::NbFaces (SMDSAbs_ElementOrder order) const
233 { return NbTriangles(order)+NbQuadrangles(order)+(order == ORDER_QUADRATIC ? 0 : myNbPolygons); }
235 inline int // NbTriangles
236 SMDS_MeshInfo::NbTriangles (SMDSAbs_ElementOrder order) const
237 { return order == ORDER_ANY ? myNbTriangles+myNbQuadTriangles : order == ORDER_LINEAR ? myNbTriangles : myNbQuadTriangles; }
239 inline int // NbQuadrangles
240 SMDS_MeshInfo::NbQuadrangles(SMDSAbs_ElementOrder order) const
241 { return order == ORDER_ANY ? myNbQuadrangles+myNbQuadQuadrangles+myNbBiQuadQuadrangles : order == ORDER_LINEAR ? myNbQuadrangles : myNbQuadQuadrangles+myNbBiQuadQuadrangles; }
243 inline int // NbVolumes
244 SMDS_MeshInfo::NbVolumes (SMDSAbs_ElementOrder order) const
245 { return NbTetras(order) + NbHexas(order) + NbPyramids(order) + NbPrisms(order) + NbHexPrisms(order) + (order == ORDER_QUADRATIC ? 0 : myNbPolyhedrons); }
247 inline int // NbTetras
248 SMDS_MeshInfo::NbTetras (SMDSAbs_ElementOrder order) const
249 { return order == ORDER_ANY ? myNbTetras+myNbQuadTetras : order == ORDER_LINEAR ? myNbTetras : myNbQuadTetras; }
251 inline int // NbHexas
252 SMDS_MeshInfo::NbHexas (SMDSAbs_ElementOrder order) const
253 { return order == ORDER_ANY ? myNbHexas+myNbQuadHexas+myNbTriQuadHexas : order == ORDER_LINEAR ? myNbHexas : myNbQuadHexas+myNbTriQuadHexas; }
255 inline int // NbPyramids
256 SMDS_MeshInfo::NbPyramids(SMDSAbs_ElementOrder order) const
257 { return order == ORDER_ANY ? myNbPyramids+myNbQuadPyramids : order == ORDER_LINEAR ? myNbPyramids : myNbQuadPyramids; }
259 inline int // NbPrisms
260 SMDS_MeshInfo::NbPrisms (SMDSAbs_ElementOrder order) const
261 { return order == ORDER_ANY ? myNbPrisms+myNbQuadPrisms : order == ORDER_LINEAR ? myNbPrisms : myNbQuadPrisms; }
263 inline int // NbHexPrisms
264 SMDS_MeshInfo::NbHexPrisms (SMDSAbs_ElementOrder order) const
265 { return order == ORDER_ANY ? myNbHexPrism : order == ORDER_LINEAR ? myNbHexPrism : 0; }
267 inline int // NbElements
268 SMDS_MeshInfo::NbElements(SMDSAbs_ElementType type) const
273 for ( int i=1+index( SMDSAbs_Node,1 ); i<myNb.size(); ++i ) if ( myNb[i] ) nb += *myNb[i];
274 nb += myNbPolygons + myNbPolyhedrons;
277 nb = myNbTetras+ myNbPyramids+ myNbPrisms+ myNbHexas+ myNbHexPrism+
278 myNbQuadTetras+ myNbQuadPyramids+ myNbQuadPrisms+ myNbQuadHexas+ myNbTriQuadHexas+
282 nb = myNbTriangles+ myNbQuadrangles+
283 myNbQuadTriangles+ myNbQuadQuadrangles+ myNbBiQuadQuadrangles+ myNbPolygons;
286 nb = myNbEdges + myNbQuadEdges;
288 case SMDSAbs_0DElement:
300 SMDS_MeshInfo::NbEntities(SMDSAbs_EntityType type) const
303 case SMDSEntity_Node:
307 return myNb0DElements;
309 case SMDSEntity_Edge:
312 case SMDSEntity_Quad_Edge:
313 return myNbQuadEdges;
315 case SMDSEntity_Triangle:
316 return myNbTriangles;
318 case SMDSEntity_Quad_Triangle:
319 return myNbQuadTriangles;
321 case SMDSEntity_Quadrangle:
322 return myNbQuadrangles;
324 case SMDSEntity_Quad_Quadrangle:
325 return myNbQuadQuadrangles;
327 case SMDSEntity_BiQuad_Quadrangle:
328 return myNbBiQuadQuadrangles;
330 case SMDSEntity_Polygon:
333 case SMDSEntity_Tetra:
336 case SMDSEntity_Quad_Tetra:
337 return myNbQuadTetras;
339 case SMDSEntity_Pyramid:
342 case SMDSEntity_Quad_Pyramid:
343 return myNbQuadPyramids;
345 case SMDSEntity_Hexa:
348 case SMDSEntity_Quad_Hexa:
349 return myNbQuadHexas;
351 case SMDSEntity_TriQuad_Hexa:
352 return myNbTriQuadHexas;
354 case SMDSEntity_Penta:
357 case SMDSEntity_Quad_Penta:
358 return myNbQuadPrisms;
360 case SMDSEntity_Hexagonal_Prism:
363 case SMDSEntity_Polyhedra:
364 return myNbPolyhedrons;
366 case SMDSEntity_Quad_Polygon:
367 case SMDSEntity_Quad_Polyhedra: