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