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