Salome HOME
correct previous integration (Porting to Python 2.6)
[modules/smesh.git] / src / SMDS / SMDS_MeshInfo.hxx
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 using namespace std;
30
31 #include "SMESH_SMDS.hxx"
32
33 #include "SMDS_MeshElement.hxx"
34
35 class SMDS_EXPORT SMDS_MeshInfo
36 {
37 public:
38
39   inline SMDS_MeshInfo();
40   inline void Clear();
41
42   int NbNodes() const { return myNbNodes; }
43   inline int NbElements(SMDSAbs_ElementType type=SMDSAbs_All) const;
44   inline int NbEntities(SMDSAbs_EntityType  type) const;
45
46   int Nb0DElements() const { return myNb0DElements; }
47   inline int NbEdges      (SMDSAbs_ElementOrder order = ORDER_ANY) const;
48   inline int NbFaces      (SMDSAbs_ElementOrder order = ORDER_ANY) const;
49   inline int NbTriangles  (SMDSAbs_ElementOrder order = ORDER_ANY) const;
50   inline int NbQuadrangles(SMDSAbs_ElementOrder order = ORDER_ANY) const;
51   int NbPolygons() const { return myNbPolygons; }
52
53   inline int NbVolumes (SMDSAbs_ElementOrder order = ORDER_ANY) const;
54   inline int NbTetras  (SMDSAbs_ElementOrder order = ORDER_ANY) const;
55   inline int NbHexas   (SMDSAbs_ElementOrder order = ORDER_ANY) const;
56   inline int NbPyramids(SMDSAbs_ElementOrder order = ORDER_ANY) const;
57   inline int NbPrisms  (SMDSAbs_ElementOrder order = ORDER_ANY) const;
58   int NbPolyhedrons() const { return myNbPolyhedrons; }
59
60 private:
61   friend class SMDS_Mesh;
62
63   // methods to count NOT POLY elements
64   inline void remove(const SMDS_MeshElement* el);
65   inline void add   (const SMDS_MeshElement* el);
66   inline int  index(SMDSAbs_ElementType type, int nbNodes) const;
67   // methods to remove elements of ANY kind
68   inline void RemoveEdge(const SMDS_MeshElement* el);
69   inline void RemoveFace(const SMDS_MeshElement* el);
70   inline void RemoveVolume(const SMDS_MeshElement* el);
71
72   int myNbNodes;
73
74   int myNb0DElements;
75   int myNbEdges      , myNbQuadEdges      ;
76   int myNbTriangles  , myNbQuadTriangles  ;
77   int myNbQuadrangles, myNbQuadQuadrangles;
78   int myNbPolygons;
79
80   int myNbTetras  , myNbQuadTetras  ;
81   int myNbHexas   , myNbQuadHexas   ;
82   int myNbPyramids, myNbQuadPyramids;
83   int myNbPrisms  , myNbQuadPrisms  ;
84   int myNbPolyhedrons;
85
86   std::vector<int*> myNb; // pointers to myNb... fields
87   std::vector<int>  myShift; // shift to get an index in myNb by elem->NbNodes()
88 };
89
90 inline SMDS_MeshInfo::SMDS_MeshInfo():
91   myNbNodes(0),
92   myNb0DElements(0),
93   myNbEdges      (0), myNbQuadEdges      (0),
94   myNbTriangles  (0), myNbQuadTriangles  (0),
95   myNbQuadrangles(0), myNbQuadQuadrangles(0),
96   myNbPolygons(0),
97   myNbTetras  (0), myNbQuadTetras  (0),
98   myNbHexas   (0), myNbQuadHexas   (0),
99   myNbPyramids(0), myNbQuadPyramids(0),
100   myNbPrisms  (0), myNbQuadPrisms  (0),
101   myNbPolyhedrons(0)
102 {
103   // Number of nodes in standard element types
104   // n   v  f  e  0  n
105   // o   o  a  d  d  o
106   // d   l  c  g     d
107   // e      e  e     e
108   // s
109   // -----------------
110   // 0         *
111   // 1            .  *
112   // 2         *
113   // 3      .     *
114   // 4   *  .  .
115   // 5   *
116   // 6   *  .
117   // 7
118   // 8   *  .
119   // 9
120   // 10  *
121   // 11     *
122   // 12     *
123   // 13  *
124   // 14     *
125   // 15  *
126   // 16     *
127   // 17
128   // 18
129   // 19
130   // 20  *
131   //
132   // So to have a unique index for each type basing on nb of nodes, we use a shift:
133   myShift.resize(SMDSAbs_NbElementTypes, 0);
134
135   myShift[ SMDSAbs_Face      ] = +8; // 3->11, 4->12, 6->14, 8->16
136   myShift[ SMDSAbs_Edge      ] = -2; // 2->0, 4->2
137   myShift[ SMDSAbs_0DElement ] = +2; // 1->3
138
139   myNb.resize( index( SMDSAbs_Volume,20 ) + 1, NULL);
140
141   myNb[ index( SMDSAbs_Node,1 )] = & myNbNodes;
142
143   myNb[ index( SMDSAbs_0DElement,1 )] = & myNb0DElements;
144
145   myNb[ index( SMDSAbs_Edge,2 )] = & myNbEdges;
146   myNb[ index( SMDSAbs_Edge,4 )] = & myNbQuadEdges;
147
148   myNb[ index( SMDSAbs_Face,3 )] = & myNbTriangles;
149   myNb[ index( SMDSAbs_Face,4 )] = & myNbQuadrangles;
150   myNb[ index( SMDSAbs_Face,6 )] = & myNbQuadTriangles;
151   myNb[ index( SMDSAbs_Face,8 )] = & myNbQuadQuadrangles;
152
153   myNb[ index( SMDSAbs_Volume, 4)]  = & myNbTetras;
154   myNb[ index( SMDSAbs_Volume, 5)]  = & myNbPyramids;
155   myNb[ index( SMDSAbs_Volume, 6)]  = & myNbPrisms;
156   myNb[ index( SMDSAbs_Volume, 8)]  = & myNbHexas;
157   myNb[ index( SMDSAbs_Volume, 10)] = & myNbQuadTetras;  
158   myNb[ index( SMDSAbs_Volume, 13)] = & myNbQuadPyramids;
159   myNb[ index( SMDSAbs_Volume, 15)] = & myNbQuadPrisms;  
160   myNb[ index( SMDSAbs_Volume, 20)] = & myNbQuadHexas;   
161 }
162
163 inline void // Clear
164 SMDS_MeshInfo::Clear()
165 { for ( int i=0; i<myNb.size(); ++i ) if ( myNb[i] ) (*myNb[i])=0;
166   myNbPolygons=myNbPolyhedrons=0;
167 }
168
169 inline int // index
170 SMDS_MeshInfo::index(SMDSAbs_ElementType type, int nbNodes) const
171 { return nbNodes + myShift[ type ]; }
172
173 inline void // remove
174 SMDS_MeshInfo::remove(const SMDS_MeshElement* el)
175 { --(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
176
177 inline void // add
178 SMDS_MeshInfo::add(const SMDS_MeshElement* el)
179 { ++(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
180
181 inline void // RemoveEdge
182 SMDS_MeshInfo::RemoveEdge(const SMDS_MeshElement* el)
183 { if ( el->IsQuadratic() ) --myNbQuadEdges; else --myNbEdges; }
184
185 inline void // RemoveFace
186 SMDS_MeshInfo::RemoveFace(const SMDS_MeshElement* el)
187 { if ( el->IsPoly() ) --myNbPolygons; else remove( el ); }
188
189 inline void // RemoveVolume
190 SMDS_MeshInfo::RemoveVolume(const SMDS_MeshElement* el)
191 { if ( el->IsPoly() ) --myNbPolyhedrons; else remove( el ); }
192
193 inline int // NbEdges
194 SMDS_MeshInfo::NbEdges      (SMDSAbs_ElementOrder order) const
195 { return order == ORDER_ANY ? myNbEdges+myNbQuadEdges : order == ORDER_LINEAR ? myNbEdges : myNbQuadEdges; }
196
197 inline int // NbFaces
198 SMDS_MeshInfo::NbFaces      (SMDSAbs_ElementOrder order) const
199 { return NbTriangles(order)+NbQuadrangles(order)+(order == ORDER_QUADRATIC ? 0 : myNbPolygons); }
200
201 inline int // NbTriangles
202 SMDS_MeshInfo::NbTriangles  (SMDSAbs_ElementOrder order) const
203 { return order == ORDER_ANY ? myNbTriangles+myNbQuadTriangles : order == ORDER_LINEAR ? myNbTriangles : myNbQuadTriangles; }
204
205 inline int // NbQuadrangles
206 SMDS_MeshInfo::NbQuadrangles(SMDSAbs_ElementOrder order) const
207 { return order == ORDER_ANY ? myNbQuadrangles+myNbQuadQuadrangles : order == ORDER_LINEAR ? myNbQuadrangles : myNbQuadQuadrangles; }
208
209 inline int // NbVolumes
210 SMDS_MeshInfo::NbVolumes (SMDSAbs_ElementOrder order) const
211 { return NbTetras(order) + NbHexas(order) + NbPyramids(order) + NbPrisms(order) + (order == ORDER_QUADRATIC ? 0 : myNbPolyhedrons); }
212
213 inline int // NbTetras
214 SMDS_MeshInfo::NbTetras  (SMDSAbs_ElementOrder order) const
215 { return order == ORDER_ANY ? myNbTetras+myNbQuadTetras : order == ORDER_LINEAR ? myNbTetras : myNbQuadTetras; }
216
217 inline int // NbHexas
218 SMDS_MeshInfo::NbHexas   (SMDSAbs_ElementOrder order) const
219 { return order == ORDER_ANY ? myNbHexas+myNbQuadHexas : order == ORDER_LINEAR ? myNbHexas : myNbQuadHexas; }
220
221 inline int // NbPyramids
222 SMDS_MeshInfo::NbPyramids(SMDSAbs_ElementOrder order) const
223 { return order == ORDER_ANY ? myNbPyramids+myNbQuadPyramids : order == ORDER_LINEAR ? myNbPyramids : myNbQuadPyramids; }
224
225 inline int // NbPrisms
226 SMDS_MeshInfo::NbPrisms  (SMDSAbs_ElementOrder order) const
227 { return order == ORDER_ANY ? myNbPrisms+myNbQuadPrisms : order == ORDER_LINEAR ? myNbPrisms : myNbQuadPrisms; }
228
229 inline int // NbElements
230 SMDS_MeshInfo::NbElements(SMDSAbs_ElementType type) const
231
232   int nb = 0;
233   switch (type) {
234   case SMDSAbs_All:
235     for ( int i=1+index( SMDSAbs_Node,1 ); i<myNb.size(); ++i ) if ( myNb[i] ) nb += *myNb[i];
236     nb += myNbPolygons + myNbPolyhedrons;
237     break;
238   case SMDSAbs_Volume:
239     nb = myNbTetras+ myNbPyramids+ myNbPrisms+ myNbHexas+
240       myNbQuadTetras+ myNbQuadPyramids+ myNbQuadPrisms+ myNbQuadHexas+myNbPolyhedrons;
241     break;
242   case SMDSAbs_Face:
243     nb = myNbTriangles+ myNbQuadrangles+ myNbQuadTriangles+ myNbQuadQuadrangles + myNbPolygons;
244     break;
245   case SMDSAbs_Edge:
246     nb = myNbEdges + myNbQuadEdges;
247     break;
248   case SMDSAbs_0DElement:
249     nb = myNb0DElements;
250     break;
251   case SMDSAbs_Node:
252     nb = myNbNodes;
253     break;
254   default:;
255   }
256   return nb;
257 }
258
259 int // NbEntities
260 SMDS_MeshInfo::NbEntities(SMDSAbs_EntityType  type) const
261 {
262   switch (type) {
263   case SMDSEntity_Node:
264     return myNbNodes;
265     break;
266   case SMDSEntity_0D:
267     return myNb0DElements;
268     break;
269   case SMDSEntity_Edge:
270     return myNbEdges;
271     break;
272   case SMDSEntity_Quad_Edge:
273     return myNbQuadEdges;
274     break;
275   case SMDSEntity_Triangle:
276     return myNbTriangles;
277     break;
278   case SMDSEntity_Quad_Triangle:
279     return myNbQuadTriangles;
280     break;
281   case SMDSEntity_Quadrangle:
282     return myNbQuadrangles;
283     break;
284   case SMDSEntity_Quad_Quadrangle:
285     return myNbQuadQuadrangles;
286     break;
287   case SMDSEntity_Polygon:
288     return myNbPolygons;
289     break;
290   case SMDSEntity_Tetra:
291     return myNbTetras;
292     break;
293   case SMDSEntity_Quad_Tetra:
294     return myNbQuadTetras;
295     break;
296   case SMDSEntity_Pyramid:
297     return myNbPyramids;
298     break;
299   case SMDSEntity_Quad_Pyramid:
300     return myNbQuadPyramids;
301     break;
302   case SMDSEntity_Hexa:
303     return myNbHexas;
304     break;
305   case SMDSEntity_Quad_Hexa:
306     return myNbQuadHexas;
307     break;
308   case SMDSEntity_Penta:
309     return myNbPrisms;
310     break;
311   case SMDSEntity_Quad_Penta:
312     return myNbQuadPrisms;
313     break;
314   case SMDSEntity_Polyhedra:
315     return myNbPolyhedrons;
316     break;
317   case SMDSEntity_Quad_Polygon:
318   case SMDSEntity_Quad_Polyhedra:
319   default:
320   break;
321   }
322   return 0;
323 }
324
325 #endif