1 // Copyright (C) 2007-2010 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();
40 int NbNodes() const { return myNbNodes; }
41 inline int NbElements(SMDSAbs_ElementType type=SMDSAbs_All) const;
42 inline int NbEntities(SMDSAbs_EntityType type) const;
44 int Nb0DElements() const { return myNb0DElements; }
45 inline int NbEdges (SMDSAbs_ElementOrder order = ORDER_ANY) const;
46 inline int NbFaces (SMDSAbs_ElementOrder order = ORDER_ANY) const;
47 inline int NbTriangles (SMDSAbs_ElementOrder order = ORDER_ANY) const;
48 inline int NbQuadrangles(SMDSAbs_ElementOrder order = ORDER_ANY) const;
49 int NbPolygons() const { return myNbPolygons; }
51 inline int NbVolumes (SMDSAbs_ElementOrder order = ORDER_ANY) const;
52 inline int NbTetras (SMDSAbs_ElementOrder order = ORDER_ANY) const;
53 inline int NbHexas (SMDSAbs_ElementOrder order = ORDER_ANY) const;
54 inline int NbPyramids(SMDSAbs_ElementOrder order = ORDER_ANY) const;
55 inline int NbPrisms (SMDSAbs_ElementOrder order = ORDER_ANY) const;
56 int NbPolyhedrons() const { return myNbPolyhedrons; }
59 friend class SMDS_Mesh;
61 // methods to count NOT POLY elements
62 inline void remove(const SMDS_MeshElement* el);
63 inline void add (const SMDS_MeshElement* el);
64 inline int index(SMDSAbs_ElementType type, int nbNodes) const;
65 // methods to remove elements of ANY kind
66 inline void RemoveEdge(const SMDS_MeshElement* el);
67 inline void RemoveFace(const SMDS_MeshElement* el);
68 inline void RemoveVolume(const SMDS_MeshElement* el);
73 int myNbEdges , myNbQuadEdges ;
74 int myNbTriangles , myNbQuadTriangles ;
75 int myNbQuadrangles, myNbQuadQuadrangles;
78 int myNbTetras , myNbQuadTetras ;
79 int myNbHexas , myNbQuadHexas ;
80 int myNbPyramids, myNbQuadPyramids;
81 int myNbPrisms , myNbQuadPrisms ;
84 std::vector<int*> myNb; // pointers to myNb... fields
85 std::vector<int> myShift; // shift to get an index in myNb by elem->NbNodes()
88 inline SMDS_MeshInfo::SMDS_MeshInfo():
91 myNbEdges (0), myNbQuadEdges (0),
92 myNbTriangles (0), myNbQuadTriangles (0),
93 myNbQuadrangles(0), myNbQuadQuadrangles(0),
95 myNbTetras (0), myNbQuadTetras (0),
96 myNbHexas (0), myNbQuadHexas (0),
97 myNbPyramids(0), myNbQuadPyramids(0),
98 myNbPrisms (0), myNbQuadPrisms (0),
101 // Number of nodes in standard element types
130 // So to have a unique index for each type basing on nb of nodes, we use a shift:
131 myShift.resize(SMDSAbs_NbElementTypes, 0);
133 myShift[ SMDSAbs_Face ] = +8; // 3->11, 4->12, 6->14, 8->16
134 myShift[ SMDSAbs_Edge ] = -2; // 2->0, 4->2
135 myShift[ SMDSAbs_0DElement ] = +2; // 1->3
137 myNb.resize( index( SMDSAbs_Volume,20 ) + 1, NULL);
139 myNb[ index( SMDSAbs_Node,1 )] = & myNbNodes;
141 myNb[ index( SMDSAbs_0DElement,1 )] = & myNb0DElements;
143 myNb[ index( SMDSAbs_Edge,2 )] = & myNbEdges;
144 myNb[ index( SMDSAbs_Edge,4 )] = & myNbQuadEdges;
146 myNb[ index( SMDSAbs_Face,3 )] = & myNbTriangles;
147 myNb[ index( SMDSAbs_Face,4 )] = & myNbQuadrangles;
148 myNb[ index( SMDSAbs_Face,6 )] = & myNbQuadTriangles;
149 myNb[ index( SMDSAbs_Face,8 )] = & myNbQuadQuadrangles;
151 myNb[ index( SMDSAbs_Volume, 4)] = & myNbTetras;
152 myNb[ index( SMDSAbs_Volume, 5)] = & myNbPyramids;
153 myNb[ index( SMDSAbs_Volume, 6)] = & myNbPrisms;
154 myNb[ index( SMDSAbs_Volume, 8)] = & myNbHexas;
155 myNb[ index( SMDSAbs_Volume, 10)] = & myNbQuadTetras;
156 myNb[ index( SMDSAbs_Volume, 13)] = & myNbQuadPyramids;
157 myNb[ index( SMDSAbs_Volume, 15)] = & myNbQuadPrisms;
158 myNb[ index( SMDSAbs_Volume, 20)] = & myNbQuadHexas;
162 SMDS_MeshInfo::Clear()
163 { for ( int i=0; i<myNb.size(); ++i ) if ( myNb[i] ) (*myNb[i])=0;
164 myNbPolygons=myNbPolyhedrons=0;
168 SMDS_MeshInfo::index(SMDSAbs_ElementType type, int nbNodes) const
169 { return nbNodes + myShift[ type ]; }
171 inline void // remove
172 SMDS_MeshInfo::remove(const SMDS_MeshElement* el)
173 { --(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
176 SMDS_MeshInfo::add(const SMDS_MeshElement* el)
177 { ++(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
179 inline void // RemoveEdge
180 SMDS_MeshInfo::RemoveEdge(const SMDS_MeshElement* el)
181 { if ( el->IsQuadratic() ) --myNbQuadEdges; else --myNbEdges; }
183 inline void // RemoveFace
184 SMDS_MeshInfo::RemoveFace(const SMDS_MeshElement* el)
185 { if ( el->IsPoly() ) --myNbPolygons; else remove( el ); }
187 inline void // RemoveVolume
188 SMDS_MeshInfo::RemoveVolume(const SMDS_MeshElement* el)
189 { if ( el->IsPoly() ) --myNbPolyhedrons; else remove( el ); }
191 inline int // NbEdges
192 SMDS_MeshInfo::NbEdges (SMDSAbs_ElementOrder order) const
193 { return order == ORDER_ANY ? myNbEdges+myNbQuadEdges : order == ORDER_LINEAR ? myNbEdges : myNbQuadEdges; }
195 inline int // NbFaces
196 SMDS_MeshInfo::NbFaces (SMDSAbs_ElementOrder order) const
197 { return NbTriangles(order)+NbQuadrangles(order)+(order == ORDER_QUADRATIC ? 0 : myNbPolygons); }
199 inline int // NbTriangles
200 SMDS_MeshInfo::NbTriangles (SMDSAbs_ElementOrder order) const
201 { return order == ORDER_ANY ? myNbTriangles+myNbQuadTriangles : order == ORDER_LINEAR ? myNbTriangles : myNbQuadTriangles; }
203 inline int // NbQuadrangles
204 SMDS_MeshInfo::NbQuadrangles(SMDSAbs_ElementOrder order) const
205 { return order == ORDER_ANY ? myNbQuadrangles+myNbQuadQuadrangles : order == ORDER_LINEAR ? myNbQuadrangles : myNbQuadQuadrangles; }
207 inline int // NbVolumes
208 SMDS_MeshInfo::NbVolumes (SMDSAbs_ElementOrder order) const
209 { return NbTetras(order) + NbHexas(order) + NbPyramids(order) + NbPrisms(order) + (order == ORDER_QUADRATIC ? 0 : myNbPolyhedrons); }
211 inline int // NbTetras
212 SMDS_MeshInfo::NbTetras (SMDSAbs_ElementOrder order) const
213 { return order == ORDER_ANY ? myNbTetras+myNbQuadTetras : order == ORDER_LINEAR ? myNbTetras : myNbQuadTetras; }
215 inline int // NbHexas
216 SMDS_MeshInfo::NbHexas (SMDSAbs_ElementOrder order) const
217 { return order == ORDER_ANY ? myNbHexas+myNbQuadHexas : order == ORDER_LINEAR ? myNbHexas : myNbQuadHexas; }
219 inline int // NbPyramids
220 SMDS_MeshInfo::NbPyramids(SMDSAbs_ElementOrder order) const
221 { return order == ORDER_ANY ? myNbPyramids+myNbQuadPyramids : order == ORDER_LINEAR ? myNbPyramids : myNbQuadPyramids; }
223 inline int // NbPrisms
224 SMDS_MeshInfo::NbPrisms (SMDSAbs_ElementOrder order) const
225 { return order == ORDER_ANY ? myNbPrisms+myNbQuadPrisms : order == ORDER_LINEAR ? myNbPrisms : myNbQuadPrisms; }
227 inline int // NbElements
228 SMDS_MeshInfo::NbElements(SMDSAbs_ElementType type) const
233 for ( int i=1+index( SMDSAbs_Node,1 ); i<myNb.size(); ++i ) if ( myNb[i] ) nb += *myNb[i];
234 nb += myNbPolygons + myNbPolyhedrons;
237 nb = myNbTetras+ myNbPyramids+ myNbPrisms+ myNbHexas+
238 myNbQuadTetras+ myNbQuadPyramids+ myNbQuadPrisms+ myNbQuadHexas+myNbPolyhedrons;
241 nb = myNbTriangles+ myNbQuadrangles+ myNbQuadTriangles+ myNbQuadQuadrangles + myNbPolygons;
244 nb = myNbEdges + myNbQuadEdges;
246 case SMDSAbs_0DElement:
258 SMDS_MeshInfo::NbEntities(SMDSAbs_EntityType type) const
261 case SMDSEntity_Node:
265 return myNb0DElements;
267 case SMDSEntity_Edge:
270 case SMDSEntity_Quad_Edge:
271 return myNbQuadEdges;
273 case SMDSEntity_Triangle:
274 return myNbTriangles;
276 case SMDSEntity_Quad_Triangle:
277 return myNbQuadTriangles;
279 case SMDSEntity_Quadrangle:
280 return myNbQuadrangles;
282 case SMDSEntity_Quad_Quadrangle:
283 return myNbQuadQuadrangles;
285 case SMDSEntity_Polygon:
288 case SMDSEntity_Tetra:
291 case SMDSEntity_Quad_Tetra:
292 return myNbQuadTetras;
294 case SMDSEntity_Pyramid:
297 case SMDSEntity_Quad_Pyramid:
298 return myNbQuadPyramids;
300 case SMDSEntity_Hexa:
303 case SMDSEntity_Quad_Hexa:
304 return myNbQuadHexas;
306 case SMDSEntity_Penta:
309 case SMDSEntity_Quad_Penta:
310 return myNbQuadPrisms;
312 case SMDSEntity_Polyhedra:
313 return myNbPolyhedrons;
315 case SMDSEntity_Quad_Polygon:
316 case SMDSEntity_Quad_Polyhedra: