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