Salome HOME
0021347: [CEA 497] Visualisation into SMESH and VISU of hexagonal prism cells (MED_OC...
[modules/smesh.git] / src / SMDS / SMDS_MeshInfo.hxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File      : SMDS_MeshInfo.hxx
21 // Created   : Mon Sep 24 18:32:41 2007
22 // Author    : Edward AGAPOV (eap)
23 //
24 #ifndef SMDS_MeshInfo_HeaderFile
25 #define SMDS_MeshInfo_HeaderFile
26
27 using namespace std;
28
29 #include "SMESH_SMDS.hxx"
30
31 #include "SMDS_MeshElement.hxx"
32
33 class SMDS_EXPORT SMDS_MeshInfo
34 {
35 public:
36
37   inline SMDS_MeshInfo();
38   inline SMDS_MeshInfo& operator=(const SMDS_MeshInfo& other);
39   inline void Clear();
40
41   int NbNodes() const { return myNbNodes; }
42   inline int NbElements(SMDSAbs_ElementType type=SMDSAbs_All) const;
43   inline int NbEntities(SMDSAbs_EntityType  type) const;
44
45   int Nb0DElements() const { return myNb0DElements; }
46   inline int NbEdges      (SMDSAbs_ElementOrder order = ORDER_ANY) const;
47
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 NbBiQuadQuadrangles() const { return myNbBiQuadQuadrangles; }
52   int NbPolygons() const { return myNbPolygons; }
53
54   inline int NbVolumes (SMDSAbs_ElementOrder order = ORDER_ANY) const;
55   inline int NbTetras  (SMDSAbs_ElementOrder order = ORDER_ANY) const;
56   inline int NbHexas   (SMDSAbs_ElementOrder order = ORDER_ANY) const;
57   inline int NbPyramids(SMDSAbs_ElementOrder order = ORDER_ANY) const;
58   inline int NbPrisms  (SMDSAbs_ElementOrder order = ORDER_ANY) const;
59   inline int NbHexPrisms(SMDSAbs_ElementOrder order = ORDER_ANY) const;
60   int NbTriQuadHexas() const { return myNbTriQuadHexas; }
61   int NbPolyhedrons() const { return myNbPolyhedrons; }
62
63 protected:
64   inline void addWithPoly(const SMDS_MeshElement* el);
65
66 private:
67   friend class SMDS_Mesh;
68
69   // methods to count NOT POLY elements
70   inline void remove(const SMDS_MeshElement* el);
71   inline void add   (const SMDS_MeshElement* el);
72   inline int  index(SMDSAbs_ElementType type, int nbNodes) const;
73   // methods to remove elements of ANY kind
74   inline void RemoveEdge(const SMDS_MeshElement* el);
75   inline void RemoveFace(const SMDS_MeshElement* el);
76   inline void RemoveVolume(const SMDS_MeshElement* el);
77
78   int myNbNodes;
79
80   int myNb0DElements;
81   int myNbEdges      , myNbQuadEdges      ;
82   int myNbTriangles  , myNbQuadTriangles  ;
83   int myNbQuadrangles, myNbQuadQuadrangles, myNbBiQuadQuadrangles;
84   int myNbPolygons;
85
86   int myNbTetras  , myNbQuadTetras  ;
87   int myNbHexas   , myNbQuadHexas,    myNbTriQuadHexas;
88   int myNbPyramids, myNbQuadPyramids;
89   int myNbPrisms  , myNbQuadPrisms  ;
90   int myNbHexPrism;
91   int myNbPolyhedrons;
92
93   std::vector<int*> myNb; // pointers to myNb... fields
94   std::vector<int>  myShift; // shift to get an index in myNb by elem->NbNodes()
95 };
96
97 inline SMDS_MeshInfo::SMDS_MeshInfo():
98   myNbNodes      (0),
99   myNb0DElements (0),
100   myNbEdges      (0), myNbQuadEdges      (0),
101   myNbTriangles  (0), myNbQuadTriangles  (0),
102   myNbQuadrangles(0), myNbQuadQuadrangles(0), myNbBiQuadQuadrangles(0),
103   myNbPolygons   (0),
104   myNbTetras     (0), myNbQuadTetras  (0),
105   myNbHexas      (0), myNbQuadHexas   (0), myNbTriQuadHexas(0),
106   myNbPyramids   (0), myNbQuadPyramids(0),
107   myNbPrisms     (0), myNbQuadPrisms  (0),
108   myNbHexPrism   (0),
109   myNbPolyhedrons(0)
110 {
111   // Number of nodes in standard element types (. - actual nb, * - after the shift)
112   // n   v  f  e  0  n
113   // o   o  a  d  d  o
114   // d   l  c  g     d
115   // e      e  e     e
116   // s
117   // =================
118   // 0 ---------------  - DON't USE 0!!!
119   // 1            .  *
120   // 2         .
121   // 3      .     *
122   // 4   *  .  .
123   // 5   *
124   // 6   *  .
125   // 7         *
126   // 8   *  .
127   // 9      .  *
128   // 10  *
129   // 11
130   // 12  *
131   // 13  *
132   // 14
133   // 15  *
134   // 16     *
135   // 17     *
136   // 18
137   // 19     *
138   // 20  *
139   // 21     *
140   // 22     *
141   // 23
142   // 24
143   // 25
144   // 26
145   // 27  *
146   //
147   // So to have a unique index for each type basing on nb of nodes, we use a shift:
148   myShift.resize(SMDSAbs_NbElementTypes, 0);
149
150   myShift[ SMDSAbs_Face      ] = +13;// 3->16, 4->17, 6->19, 8->21, 9->22
151   myShift[ SMDSAbs_Edge      ] = +5; // 2->7, 4->9
152   myShift[ SMDSAbs_0DElement ] = +2; // 1->3
153
154   myNb.resize( index( SMDSAbs_Volume,27 ) + 1, NULL);
155
156   myNb[ index( SMDSAbs_Node,1 )] = & myNbNodes;
157
158   myNb[ index( SMDSAbs_0DElement,1 )] = & myNb0DElements;
159
160   myNb[ index( SMDSAbs_Edge,2 )] = & myNbEdges;
161   myNb[ index( SMDSAbs_Edge,4 )] = & myNbQuadEdges;
162
163   myNb[ index( SMDSAbs_Face,3 )] = & myNbTriangles;
164   myNb[ index( SMDSAbs_Face,4 )] = & myNbQuadrangles;
165   myNb[ index( SMDSAbs_Face,6 )] = & myNbQuadTriangles;
166   myNb[ index( SMDSAbs_Face,8 )] = & myNbQuadQuadrangles;
167   myNb[ index( SMDSAbs_Face,9 )] = & myNbBiQuadQuadrangles;
168
169   myNb[ index( SMDSAbs_Volume, 4)]  = & myNbTetras;
170   myNb[ index( SMDSAbs_Volume, 5)]  = & myNbPyramids;
171   myNb[ index( SMDSAbs_Volume, 6)]  = & myNbPrisms;
172   myNb[ index( SMDSAbs_Volume, 8)]  = & myNbHexas;
173   myNb[ index( SMDSAbs_Volume, 10)] = & myNbQuadTetras;  
174   myNb[ index( SMDSAbs_Volume, 12)] = & myNbHexPrism;
175   myNb[ index( SMDSAbs_Volume, 13)] = & myNbQuadPyramids;
176   myNb[ index( SMDSAbs_Volume, 15)] = & myNbQuadPrisms;  
177   myNb[ index( SMDSAbs_Volume, 20)] = & myNbQuadHexas;   
178   myNb[ index( SMDSAbs_Volume, 27)] = & myNbTriQuadHexas;   
179 }
180
181 inline SMDS_MeshInfo& // operator=
182 SMDS_MeshInfo::operator=(const SMDS_MeshInfo& other)
183 { for ( int i=0; i<myNb.size(); ++i ) if ( myNb[i] ) (*myNb[i])=(*other.myNb[i]);
184   myNbPolygons = other.myNbPolygons;
185   myNbPolyhedrons = other.myNbPolyhedrons;
186   return *this;
187 }
188
189 inline void // Clear
190 SMDS_MeshInfo::Clear()
191 { for ( int i=0; i<myNb.size(); ++i ) if ( myNb[i] ) (*myNb[i])=0;
192   myNbPolygons=myNbPolyhedrons=0;
193 }
194
195 inline int // index
196 SMDS_MeshInfo::index(SMDSAbs_ElementType type, int nbNodes) const
197 { return nbNodes + myShift[ type ]; }
198
199 inline void // remove
200 SMDS_MeshInfo::remove(const SMDS_MeshElement* el)
201 { --(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
202
203 inline void // add
204 SMDS_MeshInfo::add(const SMDS_MeshElement* el)
205 { ++(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
206
207 inline void // addWithPoly
208 SMDS_MeshInfo::addWithPoly(const SMDS_MeshElement* el)
209 {
210   if ( el->IsPoly() )
211     ++( el->GetType()==SMDSAbs_Face ? myNbPolygons : myNbPolyhedrons );
212   else
213     add(el);
214 }
215 inline void // RemoveEdge
216 SMDS_MeshInfo::RemoveEdge(const SMDS_MeshElement* el)
217 { if ( el->IsQuadratic() ) --myNbQuadEdges; else --myNbEdges; }
218
219 inline void // RemoveFace
220 SMDS_MeshInfo::RemoveFace(const SMDS_MeshElement* el)
221 { if ( el->IsPoly() ) --myNbPolygons; else remove( el ); }
222
223 inline void // RemoveVolume
224 SMDS_MeshInfo::RemoveVolume(const SMDS_MeshElement* el)
225 { if ( el->IsPoly() ) --myNbPolyhedrons; else remove( el ); }
226
227 inline int // NbEdges
228 SMDS_MeshInfo::NbEdges      (SMDSAbs_ElementOrder order) const
229 { return order == ORDER_ANY ? myNbEdges+myNbQuadEdges : order == ORDER_LINEAR ? myNbEdges : myNbQuadEdges; }
230
231 inline int // NbFaces
232 SMDS_MeshInfo::NbFaces      (SMDSAbs_ElementOrder order) const
233 { return NbTriangles(order)+NbQuadrangles(order)+(order == ORDER_QUADRATIC ? 0 : myNbPolygons); }
234
235 inline int // NbTriangles
236 SMDS_MeshInfo::NbTriangles  (SMDSAbs_ElementOrder order) const
237 { return order == ORDER_ANY ? myNbTriangles+myNbQuadTriangles : order == ORDER_LINEAR ? myNbTriangles : myNbQuadTriangles; }
238
239 inline int // NbQuadrangles
240 SMDS_MeshInfo::NbQuadrangles(SMDSAbs_ElementOrder order) const
241 { return order == ORDER_ANY ? myNbQuadrangles+myNbQuadQuadrangles+myNbBiQuadQuadrangles : order == ORDER_LINEAR ? myNbQuadrangles : myNbQuadQuadrangles+myNbBiQuadQuadrangles; }
242
243 inline int // NbVolumes
244 SMDS_MeshInfo::NbVolumes (SMDSAbs_ElementOrder order) const
245 { return NbTetras(order) + NbHexas(order) + NbPyramids(order) + NbPrisms(order) + NbHexPrisms(order) + (order == ORDER_QUADRATIC ? 0 : myNbPolyhedrons); }
246
247 inline int // NbTetras
248 SMDS_MeshInfo::NbTetras  (SMDSAbs_ElementOrder order) const
249 { return order == ORDER_ANY ? myNbTetras+myNbQuadTetras : order == ORDER_LINEAR ? myNbTetras : myNbQuadTetras; }
250
251 inline int // NbHexas
252 SMDS_MeshInfo::NbHexas   (SMDSAbs_ElementOrder order) const
253 { return order == ORDER_ANY ? myNbHexas+myNbQuadHexas+myNbTriQuadHexas : order == ORDER_LINEAR ? myNbHexas : myNbQuadHexas+myNbTriQuadHexas; }
254
255 inline int // NbPyramids
256 SMDS_MeshInfo::NbPyramids(SMDSAbs_ElementOrder order) const
257 { return order == ORDER_ANY ? myNbPyramids+myNbQuadPyramids : order == ORDER_LINEAR ? myNbPyramids : myNbQuadPyramids; }
258
259 inline int // NbPrisms
260 SMDS_MeshInfo::NbPrisms  (SMDSAbs_ElementOrder order) const
261 { return order == ORDER_ANY ? myNbPrisms+myNbQuadPrisms : order == ORDER_LINEAR ? myNbPrisms : myNbQuadPrisms; }
262
263 inline int // NbHexPrisms
264 SMDS_MeshInfo::NbHexPrisms  (SMDSAbs_ElementOrder order) const
265 { return order == ORDER_ANY ? myNbHexPrism : order == ORDER_LINEAR ? myNbHexPrism : 0; }
266
267 inline int // NbElements
268 SMDS_MeshInfo::NbElements(SMDSAbs_ElementType type) const
269
270   int nb = 0;
271   switch (type) {
272   case SMDSAbs_All:
273     for ( int i=1+index( SMDSAbs_Node,1 ); i<myNb.size(); ++i ) if ( myNb[i] ) nb += *myNb[i];
274     nb += myNbPolygons + myNbPolyhedrons;
275     break;
276   case SMDSAbs_Volume:
277     nb = myNbTetras+ myNbPyramids+ myNbPrisms+ myNbHexas+ myNbHexPrism+
278       myNbQuadTetras+ myNbQuadPyramids+ myNbQuadPrisms+ myNbQuadHexas+ myNbTriQuadHexas+
279       myNbPolyhedrons;
280     break;
281   case SMDSAbs_Face:
282     nb = myNbTriangles+ myNbQuadrangles+
283       myNbQuadTriangles+ myNbQuadQuadrangles+ myNbBiQuadQuadrangles+ myNbPolygons;
284     break;
285   case SMDSAbs_Edge:
286     nb = myNbEdges + myNbQuadEdges;
287     break;
288   case SMDSAbs_0DElement:
289     nb = myNb0DElements;
290     break;
291   case SMDSAbs_Node:
292     nb = myNbNodes;
293     break;
294   default:;
295   }
296   return nb;
297 }
298
299 int // NbEntities
300 SMDS_MeshInfo::NbEntities(SMDSAbs_EntityType type) const
301 {
302   switch (type) {
303   case SMDSEntity_Node:
304     return myNbNodes;
305     break;
306   case SMDSEntity_0D:
307     return myNb0DElements;
308     break;
309   case SMDSEntity_Edge:
310     return myNbEdges;
311     break;
312   case SMDSEntity_Quad_Edge:
313     return myNbQuadEdges;
314     break;
315   case SMDSEntity_Triangle:
316     return myNbTriangles;
317     break;
318   case SMDSEntity_Quad_Triangle:
319     return myNbQuadTriangles;
320     break;
321   case SMDSEntity_Quadrangle:
322     return myNbQuadrangles;
323     break;
324   case SMDSEntity_Quad_Quadrangle:
325     return myNbQuadQuadrangles;
326     break;
327   case SMDSEntity_BiQuad_Quadrangle:
328     return myNbBiQuadQuadrangles;
329     break;
330   case SMDSEntity_Polygon:
331     return myNbPolygons;
332     break;
333   case SMDSEntity_Tetra:
334     return myNbTetras;
335     break;
336   case SMDSEntity_Quad_Tetra:
337     return myNbQuadTetras;
338     break;
339   case SMDSEntity_Pyramid:
340     return myNbPyramids;
341     break;
342   case SMDSEntity_Quad_Pyramid:
343     return myNbQuadPyramids;
344     break;
345   case SMDSEntity_Hexa:
346     return myNbHexas;
347     break;
348   case SMDSEntity_Quad_Hexa:
349     return myNbQuadHexas;
350     break;
351   case SMDSEntity_TriQuad_Hexa:
352     return myNbTriQuadHexas;
353     break;
354   case SMDSEntity_Penta:
355     return myNbPrisms;
356     break;
357   case SMDSEntity_Quad_Penta:
358     return myNbQuadPrisms;
359     break;
360   case SMDSEntity_Hexagonal_Prism:
361     return myNbHexPrism;
362     break;
363   case SMDSEntity_Polyhedra:
364     return myNbPolyhedrons;
365     break;
366   case SMDSEntity_Quad_Polygon:
367   case SMDSEntity_Quad_Polyhedra:
368   default:
369   break;
370   }
371   return 0;
372 }
373
374 #endif