SALOME - SMESH
SMDS_MeshInfo.hxx
Go to the documentation of this file.
1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File : SMDS_MeshInfo.hxx
23 // Created : Mon Sep 24 18:32:41 2007
24 // Author : Edward AGAPOV (eap)
25 //
26 #ifndef SMDS_MeshInfo_HeaderFile
27 #define SMDS_MeshInfo_HeaderFile
28 
29 #ifdef __BORLANDC__
30 #pragma warn -8066
31 #pragma warn -8012
32 #endif
33 
34 using namespace std;
35 
36 #include "SMESH_SMDS.hxx"
37 
38 #include "SMDS_MeshElement.hxx"
39 
41 {
42 public:
43 
44  inline SMDS_MeshInfo();
45  inline void Clear();
46 
47  int NbNodes() const { return myNbNodes; }
48  inline int NbElements(SMDSAbs_ElementType type=SMDSAbs_All) const;
49  inline int NbEntities(SMDSAbs_EntityType type) const;
50 
51  int Nb0DElements() const { return myNb0DElements; }
52  inline int NbEdges (SMDSAbs_ElementOrder order = ORDER_ANY) const;
53  inline int NbFaces (SMDSAbs_ElementOrder order = ORDER_ANY) const;
54  inline int NbTriangles (SMDSAbs_ElementOrder order = ORDER_ANY) const;
55  inline int NbQuadrangles(SMDSAbs_ElementOrder order = ORDER_ANY) const;
56  int NbPolygons() const { return myNbPolygons; }
57 
58  inline int NbVolumes (SMDSAbs_ElementOrder order = ORDER_ANY) const;
59  inline int NbTetras (SMDSAbs_ElementOrder order = ORDER_ANY) const;
60  inline int NbHexas (SMDSAbs_ElementOrder order = ORDER_ANY) const;
61  inline int NbPyramids(SMDSAbs_ElementOrder order = ORDER_ANY) const;
62  inline int NbPrisms (SMDSAbs_ElementOrder order = ORDER_ANY) const;
63  int NbPolyhedrons() const { return myNbPolyhedrons; }
64 
65 private:
66  friend class SMDS_Mesh;
67 
68  // methods to count NOT POLY elements
69  inline void remove(const SMDS_MeshElement* el);
70  inline void add (const SMDS_MeshElement* el);
71  inline int index(SMDSAbs_ElementType type, int nbNodes) const;
72  // methods to remove elements of ANY kind
73  inline void RemoveEdge(const SMDS_MeshElement* el);
74  inline void RemoveFace(const SMDS_MeshElement* el);
75  inline void RemoveVolume(const SMDS_MeshElement* el);
76 
77  int myNbNodes;
78 
80  int myNbEdges , myNbQuadEdges ;
81  int myNbTriangles , myNbQuadTriangles ;
82  int myNbQuadrangles, myNbQuadQuadrangles;
84 
85  int myNbTetras , myNbQuadTetras ;
86  int myNbHexas , myNbQuadHexas ;
87  int myNbPyramids, myNbQuadPyramids;
88  int myNbPrisms , myNbQuadPrisms ;
90 
91  std::vector<int*> myNb; // pointers to myNb... fields
92  std::vector<int> myShift; // shift to get an index in myNb by elem->NbNodes()
93 };
94 
96  myNbNodes(0),
97  myNb0DElements(0),
98  myNbEdges (0), myNbQuadEdges (0),
99  myNbTriangles (0), myNbQuadTriangles (0),
100  myNbQuadrangles(0), myNbQuadQuadrangles(0),
101  myNbPolygons(0),
102  myNbTetras (0), myNbQuadTetras (0),
103  myNbHexas (0), myNbQuadHexas (0),
104  myNbPyramids(0), myNbQuadPyramids(0),
105  myNbPrisms (0), myNbQuadPrisms (0),
106  myNbPolyhedrons(0)
107 {
108  // Number of nodes in standard element types
109  // n v f e 0 n
110  // o o a d d o
111  // d l c g d
112  // e e e e
113  // s
114  // -----------------
115  // 0 *
116  // 1 . *
117  // 2 *
118  // 3 . *
119  // 4 * . .
120  // 5 *
121  // 6 * .
122  // 7
123  // 8 * .
124  // 9
125  // 10 *
126  // 11 *
127  // 12 *
128  // 13 *
129  // 14 *
130  // 15 *
131  // 16 *
132  // 17
133  // 18
134  // 19
135  // 20 *
136  //
137  // So to have a unique index for each type basing on nb of nodes, we use a shift:
138  myShift.resize(SMDSAbs_NbElementTypes, 0);
139 
140  myShift[ SMDSAbs_Face ] = +8; // 3->11, 4->12, 6->14, 8->16
141  myShift[ SMDSAbs_Edge ] = -2; // 2->0, 4->2
142  myShift[ SMDSAbs_0DElement ] = +2; // 1->3
143 
144  myNb.resize( index( SMDSAbs_Volume,20 ) + 1, NULL);
145 
146  myNb[ index( SMDSAbs_Node,1 )] = & myNbNodes;
147 
149 
150  myNb[ index( SMDSAbs_Edge,2 )] = & myNbEdges;
152 
157 
158  myNb[ index( SMDSAbs_Volume, 4)] = & myNbTetras;
160  myNb[ index( SMDSAbs_Volume, 6)] = & myNbPrisms;
161  myNb[ index( SMDSAbs_Volume, 8)] = & myNbHexas;
165  myNb[ index( SMDSAbs_Volume, 20)] = & myNbQuadHexas;
166 }
167 
168 inline void // Clear
170 { for ( unsigned int i=0; i<myNb.size(); ++i ) if ( myNb[i] ) (*myNb[i])=0;
172 }
173 
174 inline int // index
176 { return nbNodes + myShift[ type ]; }
177 
178 inline void // remove
180 { --(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
181 
182 inline void // add
184 { ++(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
185 
186 inline void // RemoveEdge
188 { if ( el->IsQuadratic() ) --myNbQuadEdges; else --myNbEdges; }
189 
190 inline void // RemoveFace
192 { if ( el->IsPoly() ) --myNbPolygons; else remove( el ); }
193 
194 inline void // RemoveVolume
196 { if ( el->IsPoly() ) --myNbPolyhedrons; else remove( el ); }
197 
198 inline int // NbEdges
200 { return order == ORDER_ANY ? myNbEdges+myNbQuadEdges : order == ORDER_LINEAR ? myNbEdges : myNbQuadEdges; }
201 
202 inline int // NbFaces
204 { return NbTriangles(order)+NbQuadrangles(order)+(order == ORDER_QUADRATIC ? 0 : myNbPolygons); }
205 
206 inline int // NbTriangles
209 
210 inline int // NbQuadrangles
213 
214 inline int // NbVolumes
216 { return NbTetras(order) + NbHexas(order) + NbPyramids(order) + NbPrisms(order) + (order == ORDER_QUADRATIC ? 0 : myNbPolyhedrons); }
217 
218 inline int // NbTetras
220 { return order == ORDER_ANY ? myNbTetras+myNbQuadTetras : order == ORDER_LINEAR ? myNbTetras : myNbQuadTetras; }
221 
222 inline int // NbHexas
224 { return order == ORDER_ANY ? myNbHexas+myNbQuadHexas : order == ORDER_LINEAR ? myNbHexas : myNbQuadHexas; }
225 
226 inline int // NbPyramids
229 
230 inline int // NbPrisms
232 { return order == ORDER_ANY ? myNbPrisms+myNbQuadPrisms : order == ORDER_LINEAR ? myNbPrisms : myNbQuadPrisms; }
233 
234 inline int // NbElements
236 {
237  int nb = 0;
238  switch (type) {
239  case SMDSAbs_All:
240  for (unsigned int i=1+index( SMDSAbs_Node,1 ); i<myNb.size(); ++i ) if ( myNb[i] ) nb += *myNb[i];
242  break;
243  case SMDSAbs_Volume:
246  break;
247  case SMDSAbs_Face:
249  break;
250  case SMDSAbs_Edge:
251  nb = myNbEdges + myNbQuadEdges;
252  break;
253  case SMDSAbs_0DElement:
254  nb = myNb0DElements;
255  break;
256  case SMDSAbs_Node:
257  nb = myNbNodes;
258  break;
259  default:;
260  }
261  return nb;
262 }
263 
264 int // NbEntities
266 {
267  switch (type) {
268  case SMDSEntity_Node:
269  return myNbNodes;
270  break;
271  case SMDSEntity_0D:
272  return myNb0DElements;
273  break;
274  case SMDSEntity_Edge:
275  return myNbEdges;
276  break;
278  return myNbQuadEdges;
279  break;
280  case SMDSEntity_Triangle:
281  return myNbTriangles;
282  break;
284  return myNbQuadTriangles;
285  break;
287  return myNbQuadrangles;
288  break;
290  return myNbQuadQuadrangles;
291  break;
292  case SMDSEntity_Polygon:
293  return myNbPolygons;
294  break;
295  case SMDSEntity_Tetra:
296  return myNbTetras;
297  break;
299  return myNbQuadTetras;
300  break;
301  case SMDSEntity_Pyramid:
302  return myNbPyramids;
303  break;
305  return myNbQuadPyramids;
306  break;
307  case SMDSEntity_Hexa:
308  return myNbHexas;
309  break;
311  return myNbQuadHexas;
312  break;
313  case SMDSEntity_Penta:
314  return myNbPrisms;
315  break;
317  return myNbQuadPrisms;
318  break;
320  return myNbPolyhedrons;
321  break;
324  default:
325  break;
326  }
327  return 0;
328 }
329 
330 #endif
void RemoveVolume(const SMDS_MeshElement *el)
int NbElements(SMDSAbs_ElementType type=SMDSAbs_All) const
int NbQuadrangles(SMDSAbs_ElementOrder order=ORDER_ANY) const
void RemoveEdge(const SMDS_MeshElement *el)
SMDSAbs_EntityType
int Nb0DElements() const
#define SMDS_EXPORT
Definition: SMESH_SMDS.hxx:36
int NbVolumes(SMDSAbs_ElementOrder order=ORDER_ANY) const
STL namespace.
int NbEdges(SMDSAbs_ElementOrder order=ORDER_ANY) const
int index(SMDSAbs_ElementType type, int nbNodes) const
void remove(const SMDS_MeshElement *el)
virtual SMDSAbs_ElementType GetType() const =0
Return the type of the current element.
SMDSAbs_ElementType
Type (node, edge, face or volume) of elements.
int NbFaces(SMDSAbs_ElementOrder order=ORDER_ANY) const
int NbTetras(SMDSAbs_ElementOrder order=ORDER_ANY) const
int NbNodes() const
int NbPyramids(SMDSAbs_ElementOrder order=ORDER_ANY) const
SMDSAbs_ElementOrder
std::vector< int > myShift
int NbPolyhedrons() const
virtual void RemoveVolume(const SMDS_MeshVolume *volume)
virtual bool IsPoly() const
Base class for elements.
void add(const SMDS_MeshElement *el)
int NbHexas(SMDSAbs_ElementOrder order=ORDER_ANY) const
virtual void RemoveEdge(const SMDS_MeshEdge *edge)
int NbPrisms(SMDSAbs_ElementOrder order=ORDER_ANY) const
std::vector< int * > myNb
virtual void RemoveFace(const SMDS_MeshFace *face)
void RemoveFace(const SMDS_MeshElement *el)
virtual bool IsQuadratic() const
int NbTriangles(SMDSAbs_ElementOrder order=ORDER_ANY) const
int NbEntities(SMDSAbs_EntityType type) const
virtual int NbNodes() const
int NbPolygons() const