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