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;
47 inline int NbFaces (SMDSAbs_ElementOrder order = ORDER_ANY) const;
48 inline int NbTriangles (SMDSAbs_ElementOrder order = ORDER_ANY) const;
49 inline int NbQuadrangles(SMDSAbs_ElementOrder order = ORDER_ANY) const;
50 int NbPolygons() const { return myNbPolygons; }
52 inline int NbVolumes (SMDSAbs_ElementOrder order = ORDER_ANY) const;
53 inline int NbTetras (SMDSAbs_ElementOrder order = ORDER_ANY) const;
54 inline int NbHexas (SMDSAbs_ElementOrder order = ORDER_ANY) const;
55 inline int NbPyramids(SMDSAbs_ElementOrder order = ORDER_ANY) const;
56 inline int NbPrisms (SMDSAbs_ElementOrder order = ORDER_ANY) const;
57 int NbPolyhedrons() const { return myNbPolyhedrons; }
60 inline void addWithPoly(const SMDS_MeshElement* el);
63 friend class SMDS_Mesh;
65 // methods to count NOT POLY elements
66 inline void remove(const SMDS_MeshElement* el);
67 inline void add (const SMDS_MeshElement* el);
68 inline int index(SMDSAbs_ElementType type, int nbNodes) const;
69 // methods to remove elements of ANY kind
70 inline void RemoveEdge(const SMDS_MeshElement* el);
71 inline void RemoveFace(const SMDS_MeshElement* el);
72 inline void RemoveVolume(const SMDS_MeshElement* el);
77 int myNbEdges , myNbQuadEdges ;
78 int myNbTriangles , myNbQuadTriangles ;
79 int myNbQuadrangles, myNbQuadQuadrangles;
82 int myNbTetras , myNbQuadTetras ;
83 int myNbHexas , myNbQuadHexas ;
84 int myNbPyramids, myNbQuadPyramids;
85 int myNbPrisms , myNbQuadPrisms ;
88 std::vector<int*> myNb; // pointers to myNb... fields
89 std::vector<int> myShift; // shift to get an index in myNb by elem->NbNodes()
92 inline SMDS_MeshInfo::SMDS_MeshInfo():
95 myNbEdges (0), myNbQuadEdges (0),
96 myNbTriangles (0), myNbQuadTriangles (0),
97 myNbQuadrangles(0), myNbQuadQuadrangles(0),
99 myNbTetras (0), myNbQuadTetras (0),
100 myNbHexas (0), myNbQuadHexas (0),
101 myNbPyramids(0), myNbQuadPyramids(0),
102 myNbPrisms (0), myNbQuadPrisms (0),
105 // Number of nodes in standard element types (. - actual nb, * - after the shift)
112 // 0 - DON't USE 0!!!
134 // So to have a unique index for each type basing on nb of nodes, we use a shift:
135 myShift.resize(SMDSAbs_NbElementTypes, 0);
137 myShift[ SMDSAbs_Face ] = +8; // 3->11, 4->12, 6->14, 8->16
138 myShift[ SMDSAbs_Edge ] = +5; // 2->7, 4->9
139 myShift[ SMDSAbs_0DElement ] = +2; // 1->3
141 myNb.resize( index( SMDSAbs_Volume,20 ) + 1, NULL);
143 myNb[ index( SMDSAbs_Node,1 )] = & myNbNodes;
145 myNb[ index( SMDSAbs_0DElement,1 )] = & myNb0DElements;
147 myNb[ index( SMDSAbs_Edge,2 )] = & myNbEdges;
148 myNb[ index( SMDSAbs_Edge,4 )] = & myNbQuadEdges;
150 myNb[ index( SMDSAbs_Face,3 )] = & myNbTriangles;
151 myNb[ index( SMDSAbs_Face,4 )] = & myNbQuadrangles;
152 myNb[ index( SMDSAbs_Face,6 )] = & myNbQuadTriangles;
153 myNb[ index( SMDSAbs_Face,8 )] = & myNbQuadQuadrangles;
155 myNb[ index( SMDSAbs_Volume, 4)] = & myNbTetras;
156 myNb[ index( SMDSAbs_Volume, 5)] = & myNbPyramids;
157 myNb[ index( SMDSAbs_Volume, 6)] = & myNbPrisms;
158 myNb[ index( SMDSAbs_Volume, 8)] = & myNbHexas;
159 myNb[ index( SMDSAbs_Volume, 10)] = & myNbQuadTetras;
160 myNb[ index( SMDSAbs_Volume, 13)] = & myNbQuadPyramids;
161 myNb[ index( SMDSAbs_Volume, 15)] = & myNbQuadPrisms;
162 myNb[ index( SMDSAbs_Volume, 20)] = & myNbQuadHexas;
165 inline SMDS_MeshInfo& // operator=
166 SMDS_MeshInfo::operator=(const SMDS_MeshInfo& other)
167 { for ( int i=0; i<myNb.size(); ++i ) if ( myNb[i] ) (*myNb[i])=(*other.myNb[i]);
168 myNbPolygons = other.myNbPolygons;
169 myNbPolyhedrons = other.myNbPolyhedrons;
174 SMDS_MeshInfo::Clear()
175 { for ( int i=0; i<myNb.size(); ++i ) if ( myNb[i] ) (*myNb[i])=0;
176 myNbPolygons=myNbPolyhedrons=0;
180 SMDS_MeshInfo::index(SMDSAbs_ElementType type, int nbNodes) const
181 { return nbNodes + myShift[ type ]; }
183 inline void // remove
184 SMDS_MeshInfo::remove(const SMDS_MeshElement* el)
185 { --(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
188 SMDS_MeshInfo::add(const SMDS_MeshElement* el)
189 { ++(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
191 inline void // addWithPoly
192 SMDS_MeshInfo::addWithPoly(const SMDS_MeshElement* el)
195 ++( el->GetType()==SMDSAbs_Face ? myNbPolygons : myNbPolyhedrons );
199 inline void // RemoveEdge
200 SMDS_MeshInfo::RemoveEdge(const SMDS_MeshElement* el)
201 { if ( el->IsQuadratic() ) --myNbQuadEdges; else --myNbEdges; }
203 inline void // RemoveFace
204 SMDS_MeshInfo::RemoveFace(const SMDS_MeshElement* el)
205 { if ( el->IsPoly() ) --myNbPolygons; else remove( el ); }
207 inline void // RemoveVolume
208 SMDS_MeshInfo::RemoveVolume(const SMDS_MeshElement* el)
209 { if ( el->IsPoly() ) --myNbPolyhedrons; else remove( el ); }
211 inline int // NbEdges
212 SMDS_MeshInfo::NbEdges (SMDSAbs_ElementOrder order) const
213 { return order == ORDER_ANY ? myNbEdges+myNbQuadEdges : order == ORDER_LINEAR ? myNbEdges : myNbQuadEdges; }
215 inline int // NbFaces
216 SMDS_MeshInfo::NbFaces (SMDSAbs_ElementOrder order) const
217 { return NbTriangles(order)+NbQuadrangles(order)+(order == ORDER_QUADRATIC ? 0 : myNbPolygons); }
219 inline int // NbTriangles
220 SMDS_MeshInfo::NbTriangles (SMDSAbs_ElementOrder order) const
221 { return order == ORDER_ANY ? myNbTriangles+myNbQuadTriangles : order == ORDER_LINEAR ? myNbTriangles : myNbQuadTriangles; }
223 inline int // NbQuadrangles
224 SMDS_MeshInfo::NbQuadrangles(SMDSAbs_ElementOrder order) const
225 { return order == ORDER_ANY ? myNbQuadrangles+myNbQuadQuadrangles : order == ORDER_LINEAR ? myNbQuadrangles : myNbQuadQuadrangles; }
227 inline int // NbVolumes
228 SMDS_MeshInfo::NbVolumes (SMDSAbs_ElementOrder order) const
229 { return NbTetras(order) + NbHexas(order) + NbPyramids(order) + NbPrisms(order) + (order == ORDER_QUADRATIC ? 0 : myNbPolyhedrons); }
231 inline int // NbTetras
232 SMDS_MeshInfo::NbTetras (SMDSAbs_ElementOrder order) const
233 { return order == ORDER_ANY ? myNbTetras+myNbQuadTetras : order == ORDER_LINEAR ? myNbTetras : myNbQuadTetras; }
235 inline int // NbHexas
236 SMDS_MeshInfo::NbHexas (SMDSAbs_ElementOrder order) const
237 { return order == ORDER_ANY ? myNbHexas+myNbQuadHexas : order == ORDER_LINEAR ? myNbHexas : myNbQuadHexas; }
239 inline int // NbPyramids
240 SMDS_MeshInfo::NbPyramids(SMDSAbs_ElementOrder order) const
241 { return order == ORDER_ANY ? myNbPyramids+myNbQuadPyramids : order == ORDER_LINEAR ? myNbPyramids : myNbQuadPyramids; }
243 inline int // NbPrisms
244 SMDS_MeshInfo::NbPrisms (SMDSAbs_ElementOrder order) const
245 { return order == ORDER_ANY ? myNbPrisms+myNbQuadPrisms : order == ORDER_LINEAR ? myNbPrisms : myNbQuadPrisms; }
247 inline int // NbElements
248 SMDS_MeshInfo::NbElements(SMDSAbs_ElementType type) const
253 for ( int i=1+index( SMDSAbs_Node,1 ); i<myNb.size(); ++i ) if ( myNb[i] ) nb += *myNb[i];
254 nb += myNbPolygons + myNbPolyhedrons;
257 nb = myNbTetras+ myNbPyramids+ myNbPrisms+ myNbHexas+
258 myNbQuadTetras+ myNbQuadPyramids+ myNbQuadPrisms+ myNbQuadHexas+myNbPolyhedrons;
261 nb = myNbTriangles+ myNbQuadrangles+ myNbQuadTriangles+ myNbQuadQuadrangles + myNbPolygons;
264 nb = myNbEdges + myNbQuadEdges;
266 case SMDSAbs_0DElement:
278 SMDS_MeshInfo::NbEntities(SMDSAbs_EntityType type) const
281 case SMDSEntity_Node:
285 return myNb0DElements;
287 case SMDSEntity_Edge:
290 case SMDSEntity_Quad_Edge:
291 return myNbQuadEdges;
293 case SMDSEntity_Triangle:
294 return myNbTriangles;
296 case SMDSEntity_Quad_Triangle:
297 return myNbQuadTriangles;
299 case SMDSEntity_Quadrangle:
300 return myNbQuadrangles;
302 case SMDSEntity_Quad_Quadrangle:
303 return myNbQuadQuadrangles;
305 case SMDSEntity_Polygon:
308 case SMDSEntity_Tetra:
311 case SMDSEntity_Quad_Tetra:
312 return myNbQuadTetras;
314 case SMDSEntity_Pyramid:
317 case SMDSEntity_Quad_Pyramid:
318 return myNbQuadPyramids;
320 case SMDSEntity_Hexa:
323 case SMDSEntity_Quad_Hexa:
324 return myNbQuadHexas;
326 case SMDSEntity_Penta:
329 case SMDSEntity_Quad_Penta:
330 return myNbQuadPrisms;
332 case SMDSEntity_Polyhedra:
333 return myNbPolyhedrons;
335 case SMDSEntity_Quad_Polygon:
336 case SMDSEntity_Quad_Polyhedra: