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();
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 inline void addWithPoly(const SMDS_MeshElement* el);
62 friend class SMDS_Mesh;
64 // methods to count NOT POLY elements
65 inline void remove(const SMDS_MeshElement* el);
66 inline void add (const SMDS_MeshElement* el);
67 inline int index(SMDSAbs_ElementType type, int nbNodes) const;
68 // methods to remove elements of ANY kind
69 inline void RemoveEdge(const SMDS_MeshElement* el);
70 inline void RemoveFace(const SMDS_MeshElement* el);
71 inline void RemoveVolume(const SMDS_MeshElement* el);
76 int myNbEdges , myNbQuadEdges ;
77 int myNbTriangles , myNbQuadTriangles ;
78 int myNbQuadrangles, myNbQuadQuadrangles;
81 int myNbTetras , myNbQuadTetras ;
82 int myNbHexas , myNbQuadHexas ;
83 int myNbPyramids, myNbQuadPyramids;
84 int myNbPrisms , myNbQuadPrisms ;
87 std::vector<int*> myNb; // pointers to myNb... fields
88 std::vector<int> myShift; // shift to get an index in myNb by elem->NbNodes()
91 inline SMDS_MeshInfo::SMDS_MeshInfo():
94 myNbEdges (0), myNbQuadEdges (0),
95 myNbTriangles (0), myNbQuadTriangles (0),
96 myNbQuadrangles(0), myNbQuadQuadrangles(0),
98 myNbTetras (0), myNbQuadTetras (0),
99 myNbHexas (0), myNbQuadHexas (0),
100 myNbPyramids(0), myNbQuadPyramids(0),
101 myNbPrisms (0), myNbQuadPrisms (0),
104 // Number of nodes in standard element types
133 // So to have a unique index for each type basing on nb of nodes, we use a shift:
134 myShift.resize(SMDSAbs_NbElementTypes, 0);
136 myShift[ SMDSAbs_Face ] = +8; // 3->11, 4->12, 6->14, 8->16
137 myShift[ SMDSAbs_Edge ] = -2; // 2->0, 4->2
138 myShift[ SMDSAbs_0DElement ] = +2; // 1->3
140 myNb.resize( index( SMDSAbs_Volume,20 ) + 1, NULL);
142 myNb[ index( SMDSAbs_Node,1 )] = & myNbNodes;
144 myNb[ index( SMDSAbs_0DElement,1 )] = & myNb0DElements;
146 myNb[ index( SMDSAbs_Edge,2 )] = & myNbEdges;
147 myNb[ index( SMDSAbs_Edge,4 )] = & myNbQuadEdges;
149 myNb[ index( SMDSAbs_Face,3 )] = & myNbTriangles;
150 myNb[ index( SMDSAbs_Face,4 )] = & myNbQuadrangles;
151 myNb[ index( SMDSAbs_Face,6 )] = & myNbQuadTriangles;
152 myNb[ index( SMDSAbs_Face,8 )] = & myNbQuadQuadrangles;
154 myNb[ index( SMDSAbs_Volume, 4)] = & myNbTetras;
155 myNb[ index( SMDSAbs_Volume, 5)] = & myNbPyramids;
156 myNb[ index( SMDSAbs_Volume, 6)] = & myNbPrisms;
157 myNb[ index( SMDSAbs_Volume, 8)] = & myNbHexas;
158 myNb[ index( SMDSAbs_Volume, 10)] = & myNbQuadTetras;
159 myNb[ index( SMDSAbs_Volume, 13)] = & myNbQuadPyramids;
160 myNb[ index( SMDSAbs_Volume, 15)] = & myNbQuadPrisms;
161 myNb[ index( SMDSAbs_Volume, 20)] = & myNbQuadHexas;
165 SMDS_MeshInfo::Clear()
166 { for ( int i=0; i<myNb.size(); ++i ) if ( myNb[i] ) (*myNb[i])=0;
167 myNbPolygons=myNbPolyhedrons=0;
171 SMDS_MeshInfo::index(SMDSAbs_ElementType type, int nbNodes) const
172 { return nbNodes + myShift[ type ]; }
174 inline void // remove
175 SMDS_MeshInfo::remove(const SMDS_MeshElement* el)
176 { --(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
179 SMDS_MeshInfo::add(const SMDS_MeshElement* el)
180 { ++(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
182 inline void // addWithPoly
183 SMDS_MeshInfo::addWithPoly(const SMDS_MeshElement* el)
186 ++( el->GetType()==SMDSAbs_Face ? myNbPolygons : myNbPolyhedrons );
190 inline void // RemoveEdge
191 SMDS_MeshInfo::RemoveEdge(const SMDS_MeshElement* el)
192 { if ( el->IsQuadratic() ) --myNbQuadEdges; else --myNbEdges; }
194 inline void // RemoveFace
195 SMDS_MeshInfo::RemoveFace(const SMDS_MeshElement* el)
196 { if ( el->IsPoly() ) --myNbPolygons; else remove( el ); }
198 inline void // RemoveVolume
199 SMDS_MeshInfo::RemoveVolume(const SMDS_MeshElement* el)
200 { if ( el->IsPoly() ) --myNbPolyhedrons; else remove( el ); }
202 inline int // NbEdges
203 SMDS_MeshInfo::NbEdges (SMDSAbs_ElementOrder order) const
204 { return order == ORDER_ANY ? myNbEdges+myNbQuadEdges : order == ORDER_LINEAR ? myNbEdges : myNbQuadEdges; }
206 inline int // NbFaces
207 SMDS_MeshInfo::NbFaces (SMDSAbs_ElementOrder order) const
208 { return NbTriangles(order)+NbQuadrangles(order)+(order == ORDER_QUADRATIC ? 0 : myNbPolygons); }
210 inline int // NbTriangles
211 SMDS_MeshInfo::NbTriangles (SMDSAbs_ElementOrder order) const
212 { return order == ORDER_ANY ? myNbTriangles+myNbQuadTriangles : order == ORDER_LINEAR ? myNbTriangles : myNbQuadTriangles; }
214 inline int // NbQuadrangles
215 SMDS_MeshInfo::NbQuadrangles(SMDSAbs_ElementOrder order) const
216 { return order == ORDER_ANY ? myNbQuadrangles+myNbQuadQuadrangles : order == ORDER_LINEAR ? myNbQuadrangles : myNbQuadQuadrangles; }
218 inline int // NbVolumes
219 SMDS_MeshInfo::NbVolumes (SMDSAbs_ElementOrder order) const
220 { return NbTetras(order) + NbHexas(order) + NbPyramids(order) + NbPrisms(order) + (order == ORDER_QUADRATIC ? 0 : myNbPolyhedrons); }
222 inline int // NbTetras
223 SMDS_MeshInfo::NbTetras (SMDSAbs_ElementOrder order) const
224 { return order == ORDER_ANY ? myNbTetras+myNbQuadTetras : order == ORDER_LINEAR ? myNbTetras : myNbQuadTetras; }
226 inline int // NbHexas
227 SMDS_MeshInfo::NbHexas (SMDSAbs_ElementOrder order) const
228 { return order == ORDER_ANY ? myNbHexas+myNbQuadHexas : order == ORDER_LINEAR ? myNbHexas : myNbQuadHexas; }
230 inline int // NbPyramids
231 SMDS_MeshInfo::NbPyramids(SMDSAbs_ElementOrder order) const
232 { return order == ORDER_ANY ? myNbPyramids+myNbQuadPyramids : order == ORDER_LINEAR ? myNbPyramids : myNbQuadPyramids; }
234 inline int // NbPrisms
235 SMDS_MeshInfo::NbPrisms (SMDSAbs_ElementOrder order) const
236 { return order == ORDER_ANY ? myNbPrisms+myNbQuadPrisms : order == ORDER_LINEAR ? myNbPrisms : myNbQuadPrisms; }
238 inline int // NbElements
239 SMDS_MeshInfo::NbElements(SMDSAbs_ElementType type) const
244 for ( int i=1+index( SMDSAbs_Node,1 ); i<myNb.size(); ++i ) if ( myNb[i] ) nb += *myNb[i];
245 nb += myNbPolygons + myNbPolyhedrons;
248 nb = myNbTetras+ myNbPyramids+ myNbPrisms+ myNbHexas+
249 myNbQuadTetras+ myNbQuadPyramids+ myNbQuadPrisms+ myNbQuadHexas+myNbPolyhedrons;
252 nb = myNbTriangles+ myNbQuadrangles+ myNbQuadTriangles+ myNbQuadQuadrangles + myNbPolygons;
255 nb = myNbEdges + myNbQuadEdges;
257 case SMDSAbs_0DElement:
269 SMDS_MeshInfo::NbEntities(SMDSAbs_EntityType type) const
272 case SMDSEntity_Node:
276 return myNb0DElements;
278 case SMDSEntity_Edge:
281 case SMDSEntity_Quad_Edge:
282 return myNbQuadEdges;
284 case SMDSEntity_Triangle:
285 return myNbTriangles;
287 case SMDSEntity_Quad_Triangle:
288 return myNbQuadTriangles;
290 case SMDSEntity_Quadrangle:
291 return myNbQuadrangles;
293 case SMDSEntity_Quad_Quadrangle:
294 return myNbQuadQuadrangles;
296 case SMDSEntity_Polygon:
299 case SMDSEntity_Tetra:
302 case SMDSEntity_Quad_Tetra:
303 return myNbQuadTetras;
305 case SMDSEntity_Pyramid:
308 case SMDSEntity_Quad_Pyramid:
309 return myNbQuadPyramids;
311 case SMDSEntity_Hexa:
314 case SMDSEntity_Quad_Hexa:
315 return myNbQuadHexas;
317 case SMDSEntity_Penta:
320 case SMDSEntity_Quad_Penta:
321 return myNbQuadPrisms;
323 case SMDSEntity_Polyhedra:
324 return myNbPolyhedrons;
326 case SMDSEntity_Quad_Polygon:
327 case SMDSEntity_Quad_Polyhedra: