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