1 // Copyright (C) 2007-2020 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, or (at your option) any later version.
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"
34 class SMDS_EXPORT SMDS_MeshInfo
38 inline SMDS_MeshInfo();
39 inline SMDS_MeshInfo& operator=(const SMDS_MeshInfo& other);
42 inline int NbElements(SMDSAbs_ElementType type=SMDSAbs_All) const;
43 inline int NbElements(SMDSAbs_EntityType type) const { return NbEntities(type); }
44 inline int NbElements(SMDSAbs_GeometryType type) const { return NbElementsOfGeom(type); }
46 inline int NbEntities(SMDSAbs_EntityType type) const;
47 inline int NbElementsOfGeom(SMDSAbs_GeometryType geom) const;
49 int NbNodes() const { return myNbNodes; }
50 int Nb0DElements() const { return myNb0DElements; }
51 int NbBalls() const { return myNbBalls; }
52 inline int NbEdges (SMDSAbs_ElementOrder order = ORDER_ANY) const;
54 inline int NbFaces (SMDSAbs_ElementOrder order = ORDER_ANY) const;
55 inline int NbTriangles (SMDSAbs_ElementOrder order = ORDER_ANY) const;
56 inline int NbQuadrangles(SMDSAbs_ElementOrder order = ORDER_ANY) const;
57 int NbBiQuadTriangles() const { return myNbBiQuadTriangles; }
58 int NbBiQuadQuadrangles() const { return myNbBiQuadQuadrangles; }
59 inline int NbPolygons(SMDSAbs_ElementOrder order = ORDER_ANY) const;
61 inline int NbVolumes (SMDSAbs_ElementOrder order = ORDER_ANY) const;
62 inline int NbTetras (SMDSAbs_ElementOrder order = ORDER_ANY) const;
63 inline int NbHexas (SMDSAbs_ElementOrder order = ORDER_ANY) const;
64 inline int NbPyramids(SMDSAbs_ElementOrder order = ORDER_ANY) const;
65 inline int NbPrisms (SMDSAbs_ElementOrder order = ORDER_ANY) const;
66 inline int NbHexPrisms(SMDSAbs_ElementOrder order = ORDER_ANY) const;
67 int NbTriQuadHexas() const { return myNbTriQuadHexas; }
68 int NbQuadPrisms() const { return myNbQuadPrisms; }
69 int NbBiQuadPrisms() const { return myNbBiQuadPrisms; }
70 int NbPolyhedrons() const { return myNbPolyhedrons; }
73 inline void addWithPoly(const SMDS_MeshElement* el);
74 inline void setNb(const SMDSAbs_EntityType geomType, const int nb);
77 friend class SMDS_Mesh;
79 // methods to count NOT POLY elements
80 inline void remove(const SMDS_MeshElement* el);
81 inline void add (const SMDS_MeshElement* el);
82 inline int index(SMDSAbs_ElementType type, int nbNodes) const;
83 // methods to remove elements of ANY kind
84 inline void RemoveEdge(const SMDS_MeshElement* el);
85 inline void RemoveFace(const SMDS_MeshElement* el);
86 inline void RemoveVolume(const SMDS_MeshElement* el);
92 int myNbEdges , myNbQuadEdges ;
93 int myNbTriangles , myNbQuadTriangles, myNbBiQuadTriangles ;
94 int myNbQuadrangles, myNbQuadQuadrangles, myNbBiQuadQuadrangles;
95 int myNbPolygons , myNbQuadPolygons;
97 int myNbTetras , myNbQuadTetras ;
98 int myNbHexas , myNbQuadHexas, myNbTriQuadHexas;
99 int myNbPyramids, myNbQuadPyramids;
100 int myNbPrisms , myNbQuadPrisms, myNbBiQuadPrisms;
104 std::vector<int*> myNb; // pointers to myNb... fields
105 std::vector<int> myShift; // shift to get an index in myNb by elem->NbNodes()
108 inline SMDS_MeshInfo::SMDS_MeshInfo():
112 myNbEdges (0), myNbQuadEdges (0),
113 myNbTriangles (0), myNbQuadTriangles (0), myNbBiQuadTriangles(0),
114 myNbQuadrangles(0), myNbQuadQuadrangles(0), myNbBiQuadQuadrangles(0),
115 myNbPolygons (0), myNbQuadPolygons (0),
116 myNbTetras (0), myNbQuadTetras (0),
117 myNbHexas (0), myNbQuadHexas (0), myNbTriQuadHexas(0),
118 myNbPyramids (0), myNbQuadPyramids(0),
119 myNbPrisms (0), myNbQuadPrisms (0), myNbBiQuadPrisms(0),
123 // Number of nodes in standard element types (. - actual nb, * - after the shift)
129 // ====================
130 // 0 ------------------ - DON't USE 0!!!
163 // So to have a unique index for each type basing on nb of nodes, we use a shift:
164 myShift.resize(SMDSAbs_NbElementTypes, 0);
166 myShift[ SMDSAbs_Face ] = +22;// 3->25, 4->26, etc.
167 myShift[ SMDSAbs_Edge ] = +14;// 2->16, 3->17
168 myShift[ SMDSAbs_0DElement ] = +2; // 1->3
169 myShift[ SMDSAbs_Ball ] = +1; // 1->2
171 myNb.resize( index( SMDSAbs_Face,9 ) + 1, NULL);
173 myNb[ index( SMDSAbs_Node,1 )] = & myNbNodes;
174 myNb[ index( SMDSAbs_0DElement,1 )] = & myNb0DElements;
175 myNb[ index( SMDSAbs_Ball,1 )] = & myNbBalls;
177 myNb[ index( SMDSAbs_Edge,2 )] = & myNbEdges;
178 myNb[ index( SMDSAbs_Edge,3 )] = & myNbQuadEdges;
180 myNb[ index( SMDSAbs_Face,3 )] = & myNbTriangles;
181 myNb[ index( SMDSAbs_Face,4 )] = & myNbQuadrangles;
182 myNb[ index( SMDSAbs_Face,6 )] = & myNbQuadTriangles;
183 myNb[ index( SMDSAbs_Face,7 )] = & myNbBiQuadTriangles;
184 myNb[ index( SMDSAbs_Face,8 )] = & myNbQuadQuadrangles;
185 myNb[ index( SMDSAbs_Face,9 )] = & myNbBiQuadQuadrangles;
187 myNb[ index( SMDSAbs_Volume, 4)] = & myNbTetras;
188 myNb[ index( SMDSAbs_Volume, 5)] = & myNbPyramids;
189 myNb[ index( SMDSAbs_Volume, 6)] = & myNbPrisms;
190 myNb[ index( SMDSAbs_Volume, 8)] = & myNbHexas;
191 myNb[ index( SMDSAbs_Volume, 10)] = & myNbQuadTetras;
192 myNb[ index( SMDSAbs_Volume, 12)] = & myNbHexPrism;
193 myNb[ index( SMDSAbs_Volume, 13)] = & myNbQuadPyramids;
194 myNb[ index( SMDSAbs_Volume, 15)] = & myNbQuadPrisms;
195 myNb[ index( SMDSAbs_Volume, 18)] = & myNbBiQuadPrisms;
196 myNb[ index( SMDSAbs_Volume, 20)] = & myNbQuadHexas;
197 myNb[ index( SMDSAbs_Volume, 27)] = & myNbTriQuadHexas;
200 inline SMDS_MeshInfo& // operator=
201 SMDS_MeshInfo::operator=(const SMDS_MeshInfo& other)
202 { for ( size_t i=0; i<myNb.size(); ++i ) if ( myNb[i] ) (*myNb[i])=(*other.myNb[i]);
203 myNbPolygons = other.myNbPolygons;
204 myNbQuadPolygons = other.myNbQuadPolygons;
205 myNbPolyhedrons = other.myNbPolyhedrons;
210 SMDS_MeshInfo::Clear()
211 { for ( size_t i=0; i<myNb.size(); ++i ) if ( myNb[i] ) (*myNb[i])=0;
212 myNbPolygons=myNbQuadPolygons=myNbPolyhedrons=0;
216 SMDS_MeshInfo::index(SMDSAbs_ElementType type, int nbNodes) const
217 { return nbNodes + myShift[ type ]; }
219 inline void // remove
220 SMDS_MeshInfo::remove(const SMDS_MeshElement* el)
221 { --(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
224 SMDS_MeshInfo::add(const SMDS_MeshElement* el)
225 { ++(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
227 inline void // addWithPoly
228 SMDS_MeshInfo::addWithPoly(const SMDS_MeshElement* el) {
229 switch ( el->GetEntityType() ) {
230 case SMDSEntity_Polygon: ++myNbPolygons; break;
231 case SMDSEntity_Quad_Polygon: ++myNbQuadPolygons; break;
232 case SMDSEntity_Polyhedra: ++myNbPolyhedrons; break;
236 inline void // RemoveEdge
237 SMDS_MeshInfo::RemoveEdge(const SMDS_MeshElement* el)
238 { if ( el->IsQuadratic() ) --myNbQuadEdges; else --myNbEdges; }
240 inline void // RemoveFace
241 SMDS_MeshInfo::RemoveFace(const SMDS_MeshElement* el) {
242 switch ( el->GetEntityType() ) {
243 case SMDSEntity_Polygon: --myNbPolygons; break;
244 case SMDSEntity_Quad_Polygon: --myNbQuadPolygons; break;
249 inline void // RemoveVolume
250 SMDS_MeshInfo::RemoveVolume(const SMDS_MeshElement* el)
251 { if ( el->IsPoly() ) --myNbPolyhedrons; else remove( el ); }
253 inline int // NbEdges
254 SMDS_MeshInfo::NbEdges (SMDSAbs_ElementOrder order) const
255 { return order == ORDER_ANY ? myNbEdges+myNbQuadEdges : order == ORDER_LINEAR ? myNbEdges : myNbQuadEdges; }
257 inline int // NbFaces
258 SMDS_MeshInfo::NbFaces (SMDSAbs_ElementOrder order) const
259 { return NbTriangles(order)+NbQuadrangles(order)+(order == ORDER_ANY ? myNbPolygons+myNbQuadPolygons : order == ORDER_LINEAR ? myNbPolygons : myNbQuadPolygons ); }
261 inline int // NbTriangles
262 SMDS_MeshInfo::NbTriangles (SMDSAbs_ElementOrder order) const
263 { return order == ORDER_ANY ? myNbTriangles+myNbQuadTriangles+myNbBiQuadTriangles : order == ORDER_LINEAR ? myNbTriangles : myNbQuadTriangles+myNbBiQuadTriangles; }
265 inline int // NbQuadrangles
266 SMDS_MeshInfo::NbQuadrangles(SMDSAbs_ElementOrder order) const
267 { return order == ORDER_ANY ? myNbQuadrangles+myNbQuadQuadrangles+myNbBiQuadQuadrangles : order == ORDER_LINEAR ? myNbQuadrangles : myNbQuadQuadrangles+myNbBiQuadQuadrangles; }
269 inline int // NbPolygons
270 SMDS_MeshInfo::NbPolygons(SMDSAbs_ElementOrder order) const
271 { return order == ORDER_ANY ? myNbPolygons+myNbQuadPolygons : order == ORDER_LINEAR ? myNbPolygons : myNbQuadPolygons; }
273 inline int // NbVolumes
274 SMDS_MeshInfo::NbVolumes (SMDSAbs_ElementOrder order) const
275 { return NbTetras(order) + NbHexas(order) + NbPyramids(order) + NbPrisms(order) + NbHexPrisms(order) + (order == ORDER_QUADRATIC ? 0 : myNbPolyhedrons); }
277 inline int // NbTetras
278 SMDS_MeshInfo::NbTetras (SMDSAbs_ElementOrder order) const
279 { return order == ORDER_ANY ? myNbTetras+myNbQuadTetras : order == ORDER_LINEAR ? myNbTetras : myNbQuadTetras; }
281 inline int // NbHexas
282 SMDS_MeshInfo::NbHexas (SMDSAbs_ElementOrder order) const
283 { return order == ORDER_ANY ? myNbHexas+myNbQuadHexas+myNbTriQuadHexas : order == ORDER_LINEAR ? myNbHexas : myNbQuadHexas+myNbTriQuadHexas; }
285 inline int // NbPyramids
286 SMDS_MeshInfo::NbPyramids(SMDSAbs_ElementOrder order) const
287 { return order == ORDER_ANY ? myNbPyramids+myNbQuadPyramids : order == ORDER_LINEAR ? myNbPyramids : myNbQuadPyramids; }
289 inline int // NbPrisms
290 SMDS_MeshInfo::NbPrisms (SMDSAbs_ElementOrder order) const
291 { return order == ORDER_ANY ? myNbPrisms+myNbQuadPrisms+myNbBiQuadPrisms: order == ORDER_LINEAR ? myNbPrisms : myNbQuadPrisms+myNbBiQuadPrisms; }
293 inline int // NbHexPrisms
294 SMDS_MeshInfo::NbHexPrisms (SMDSAbs_ElementOrder order) const
295 { return order == ORDER_ANY ? myNbHexPrism : order == ORDER_LINEAR ? myNbHexPrism : 0; }
297 inline int // NbElements
298 SMDS_MeshInfo::NbElements(SMDSAbs_ElementType type) const
303 for ( size_t i=1+index( SMDSAbs_Node,1 ); i<myNb.size(); ++i ) if ( myNb[i] ) nb += *myNb[i];
304 nb += myNbPolygons + myNbQuadPolygons + myNbPolyhedrons;
307 nb = ( myNbTetras+ myNbPyramids+ myNbPrisms+ myNbHexas+ myNbHexPrism+
308 myNbQuadTetras+ myNbQuadPyramids+ myNbQuadPrisms+ myNbBiQuadPrisms + myNbQuadHexas+ myNbTriQuadHexas+
312 nb = ( myNbTriangles+ myNbQuadrangles+
313 myNbQuadTriangles+ myNbBiQuadTriangles+
314 myNbQuadQuadrangles+ myNbBiQuadQuadrangles+ myNbPolygons+ myNbQuadPolygons );
317 nb = myNbEdges + myNbQuadEdges;
322 case SMDSAbs_0DElement:
333 inline int // NbEntities
334 SMDS_MeshInfo::NbEntities(SMDSAbs_EntityType type) const
337 case SMDSEntity_Node: return myNbNodes;
338 case SMDSEntity_Edge: return myNbEdges;
339 case SMDSEntity_Quad_Edge: return myNbQuadEdges;
340 case SMDSEntity_Triangle: return myNbTriangles;
341 case SMDSEntity_Quad_Triangle: return myNbQuadTriangles;
342 case SMDSEntity_BiQuad_Triangle: return myNbBiQuadTriangles;
343 case SMDSEntity_Quadrangle: return myNbQuadrangles;
344 case SMDSEntity_Quad_Quadrangle: return myNbQuadQuadrangles;
345 case SMDSEntity_BiQuad_Quadrangle:return myNbBiQuadQuadrangles;
346 case SMDSEntity_Polygon: return myNbPolygons;
347 case SMDSEntity_Tetra: return myNbTetras;
348 case SMDSEntity_Quad_Tetra: return myNbQuadTetras;
349 case SMDSEntity_Pyramid: return myNbPyramids;
350 case SMDSEntity_Quad_Pyramid: return myNbQuadPyramids;
351 case SMDSEntity_Hexa: return myNbHexas;
352 case SMDSEntity_Quad_Hexa: return myNbQuadHexas;
353 case SMDSEntity_TriQuad_Hexa: return myNbTriQuadHexas;
354 case SMDSEntity_Penta: return myNbPrisms;
355 case SMDSEntity_Quad_Penta: return myNbQuadPrisms;
356 case SMDSEntity_BiQuad_Penta: return myNbBiQuadPrisms;
357 case SMDSEntity_Hexagonal_Prism: return myNbHexPrism;
358 case SMDSEntity_Polyhedra: return myNbPolyhedrons;
359 case SMDSEntity_0D: return myNb0DElements;
360 case SMDSEntity_Ball: return myNbBalls;
361 case SMDSEntity_Quad_Polygon: return myNbQuadPolygons;
362 case SMDSEntity_Quad_Polyhedra:
363 case SMDSEntity_Last:
369 inline int // NbElementsOfGeom
370 SMDS_MeshInfo::NbElementsOfGeom(SMDSAbs_GeometryType geom) const
374 case SMDSGeom_POINT: return myNb0DElements;
376 case SMDSGeom_EDGE: return (myNbEdges +
379 case SMDSGeom_TRIANGLE: return (myNbTriangles +
381 myNbBiQuadTriangles );
382 case SMDSGeom_QUADRANGLE: return (myNbQuadrangles +
383 myNbQuadQuadrangles +
384 myNbBiQuadQuadrangles );
385 case SMDSGeom_POLYGON: return (myNbPolygons + myNbQuadPolygons );
387 case SMDSGeom_TETRA: return (myNbTetras +
389 case SMDSGeom_PYRAMID: return (myNbPyramids +
391 case SMDSGeom_HEXA: return (myNbHexas +
394 case SMDSGeom_PENTA: return (myNbPrisms +
397 case SMDSGeom_HEXAGONAL_PRISM: return myNbHexPrism;
398 case SMDSGeom_POLYHEDRA: return myNbPolyhedrons;
400 case SMDSGeom_BALL: return myNbBalls;
409 SMDS_MeshInfo::setNb(const SMDSAbs_EntityType geomType, const int nb)
412 case SMDSEntity_Node: myNbNodes = nb; break;
413 case SMDSEntity_0D: myNb0DElements = nb; break;
414 case SMDSEntity_Ball: myNbBalls = nb; break;
415 case SMDSEntity_BiQuad_Quadrangle:myNbBiQuadQuadrangles = nb; break;
416 case SMDSEntity_BiQuad_Triangle: myNbBiQuadTriangles = nb; break;
417 case SMDSEntity_Edge: myNbEdges = nb; break;
418 case SMDSEntity_Hexa: myNbHexas = nb; break;
419 case SMDSEntity_Hexagonal_Prism: myNbHexPrism = nb; break;
420 case SMDSEntity_Penta: myNbPrisms = nb; break;
421 case SMDSEntity_Polygon: myNbPolygons = nb; break;
422 case SMDSEntity_Polyhedra: myNbPolyhedrons = nb; break;
423 case SMDSEntity_Pyramid: myNbPyramids = nb; break;
424 case SMDSEntity_Quad_Edge: myNbQuadEdges = nb; break;
425 case SMDSEntity_Quad_Hexa: myNbQuadHexas = nb; break;
426 case SMDSEntity_Quad_Penta: myNbQuadPrisms = nb; break;
427 case SMDSEntity_BiQuad_Penta: myNbBiQuadPrisms = nb; break;
428 case SMDSEntity_Quad_Pyramid: myNbQuadPyramids = nb; break;
429 case SMDSEntity_Quad_Quadrangle: myNbQuadQuadrangles = nb; break;
430 case SMDSEntity_Quad_Tetra: myNbQuadTetras = nb; break;
431 case SMDSEntity_Quad_Triangle: myNbQuadTriangles = nb; break;
432 case SMDSEntity_Quadrangle: myNbQuadrangles = nb; break;
433 case SMDSEntity_Tetra: myNbTetras = nb; break;
434 case SMDSEntity_TriQuad_Hexa: myNbTriQuadHexas = nb; break;
435 case SMDSEntity_Triangle: myNbTriangles = nb; break;
436 case SMDSEntity_Quad_Polygon: myNbQuadPolygons = nb; break;
437 case SMDSEntity_Quad_Polyhedra:
438 case SMDSEntity_Last: