Salome HOME
IMP 0020089: Take into account 0D elements (MED_POINT1)
[modules/smesh.git] / src / SMDS / SMDS_MeshInfo.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File      : SMDS_MeshInfo.hxx
23 // Created   : Mon Sep 24 18:32:41 2007
24 // Author    : Edward AGAPOV (eap)
25 //
26 #ifndef SMDS_MeshInfo_HeaderFile
27 #define SMDS_MeshInfo_HeaderFile
28
29 using namespace std;
30
31 #include "SMESH_SMDS.hxx"
32
33 #include "SMDS_MeshElement.hxx"
34
35 class SMDS_EXPORT SMDS_MeshInfo
36 {
37 public:
38
39   inline SMDS_MeshInfo();
40   inline void Clear();
41
42   int NbNodes() const { return myNbNodes; }
43   inline int NbElements(SMDSAbs_ElementType type=SMDSAbs_All) const;
44
45   int Nb0DElements() const { return myNb0DElements; }
46   inline int NbEdges      (SMDSAbs_ElementOrder order = ORDER_ANY) const;
47   inline int NbFaces      (SMDSAbs_ElementOrder order = ORDER_ANY) const;
48   inline int NbTriangles  (SMDSAbs_ElementOrder order = ORDER_ANY) const;
49   inline int NbQuadrangles(SMDSAbs_ElementOrder order = ORDER_ANY) const;
50   int NbPolygons() const { return myNbPolygons; }
51
52   inline int NbVolumes (SMDSAbs_ElementOrder order = ORDER_ANY) const;
53   inline int NbTetras  (SMDSAbs_ElementOrder order = ORDER_ANY) const;
54   inline int NbHexas   (SMDSAbs_ElementOrder order = ORDER_ANY) const;
55   inline int NbPyramids(SMDSAbs_ElementOrder order = ORDER_ANY) const;
56   inline int NbPrisms  (SMDSAbs_ElementOrder order = ORDER_ANY) const;
57   int NbPolyhedrons() const { return myNbPolyhedrons; }
58
59 private:
60   friend class SMDS_Mesh;
61
62   // methods to count NOT POLY elements
63   inline void remove(const SMDS_MeshElement* el);
64   inline void add   (const SMDS_MeshElement* el);
65   inline int  index(SMDSAbs_ElementType type, int nbNodes) const;
66   // methods to remove elements of ANY kind
67   inline void RemoveEdge(const SMDS_MeshElement* el);
68   inline void RemoveFace(const SMDS_MeshElement* el);
69   inline void RemoveVolume(const SMDS_MeshElement* el);
70
71   int myNbNodes;
72
73   int myNb0DElements;
74   int myNbEdges      , myNbQuadEdges      ;
75   int myNbTriangles  , myNbQuadTriangles  ;
76   int myNbQuadrangles, myNbQuadQuadrangles;
77   int myNbPolygons;
78
79   int myNbTetras  , myNbQuadTetras  ;
80   int myNbHexas   , myNbQuadHexas   ;
81   int myNbPyramids, myNbQuadPyramids;
82   int myNbPrisms  , myNbQuadPrisms  ;
83   int myNbPolyhedrons;
84
85   std::vector<int*> myNb; // pointers to myNb... fields
86   std::vector<int>  myShift; // shift to get an index in myNb by elem->NbNodes()
87 };
88
89 inline SMDS_MeshInfo::SMDS_MeshInfo():
90   myNbNodes(0),
91   myNb0DElements(0),
92   myNbEdges      (0), myNbQuadEdges      (0),
93   myNbTriangles  (0), myNbQuadTriangles  (0),
94   myNbQuadrangles(0), myNbQuadQuadrangles(0),
95   myNbPolygons(0),
96   myNbTetras  (0), myNbQuadTetras  (0),
97   myNbHexas   (0), myNbQuadHexas   (0),
98   myNbPyramids(0), myNbQuadPyramids(0),
99   myNbPrisms  (0), myNbQuadPrisms  (0),
100   myNbPolyhedrons(0)
101 {
102   // Number of nodes in standard element types
103   // n   v  f  e  0
104   // o   o  a  d  d
105   // d   l  c  g
106   // e      e  e
107   // --------------
108   // 1            *
109   // 2         *
110   // 3      *
111   // 4   *  *  *
112   // 5   *
113   // 6   *  *
114   // 7
115   // 8   *  *
116   // 9
117   // 10  *
118   // 11
119   // 12
120   // 13  *
121   // 14
122   // 15  *
123   // 16
124   // 17
125   // 18
126   // 19
127   // 20  *
128   //
129   // So to have a unique index for each type basing on nb of nodes, we use a shift:
130   myShift.resize(SMDSAbs_Volume + 1, 0);
131   myShift[ SMDSAbs_Face ] = +8; // 3->11, 4->12, 6->14, 8->16
132   myShift[ SMDSAbs_Edge ] = -2; // 2->0, 4->2
133
134   myNb.resize( index( SMDSAbs_Volume,20 ) + 1, NULL);
135   myNb[ index( SMDSAbs_Node,1 )] = & myNbNodes;
136
137   myNb[ index( SMDSAbs_0DElement,1 )] = & myNb0DElements;
138
139   myNb[ index( SMDSAbs_Edge,2 )] = & myNbEdges;
140   myNb[ index( SMDSAbs_Edge,4 )] = & myNbQuadEdges;
141
142   myNb[ index( SMDSAbs_Face,3 )] = & myNbTriangles;
143   myNb[ index( SMDSAbs_Face,4 )] = & myNbQuadrangles;
144   myNb[ index( SMDSAbs_Face,6 )] = & myNbQuadTriangles;
145   myNb[ index( SMDSAbs_Face,8 )] = & myNbQuadQuadrangles;
146
147   myNb[ index( SMDSAbs_Volume, 4)]  = & myNbTetras;
148   myNb[ index( SMDSAbs_Volume, 5)]  = & myNbPyramids;
149   myNb[ index( SMDSAbs_Volume, 6)]  = & myNbPrisms;
150   myNb[ index( SMDSAbs_Volume, 8)]  = & myNbHexas;
151   myNb[ index( SMDSAbs_Volume, 10)] = & myNbQuadTetras;  
152   myNb[ index( SMDSAbs_Volume, 13)] = & myNbQuadPyramids;
153   myNb[ index( SMDSAbs_Volume, 15)] = & myNbQuadPrisms;  
154   myNb[ index( SMDSAbs_Volume, 20)] = & myNbQuadHexas;   
155 }
156 inline void // Clear
157 SMDS_MeshInfo::Clear()
158 { for ( int i=0; i<myNb.size(); ++i ) if ( myNb[i] ) (*myNb[i])=0;
159   myNbPolygons=myNbPolyhedrons=0;
160 }
161 inline int // index
162 SMDS_MeshInfo::index(SMDSAbs_ElementType type, int nbNodes) const
163 { return nbNodes + myShift[ type ]; }
164
165 inline void // remove
166 SMDS_MeshInfo::remove(const SMDS_MeshElement* el)
167 { --(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
168
169 inline void // add
170 SMDS_MeshInfo::add(const SMDS_MeshElement* el)
171 { ++(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
172
173 inline void // RemoveEdge
174 SMDS_MeshInfo::RemoveEdge(const SMDS_MeshElement* el)
175 { if ( el->IsQuadratic() ) --myNbQuadEdges; else --myNbEdges; }
176
177 inline void // RemoveFace
178 SMDS_MeshInfo::RemoveFace(const SMDS_MeshElement* el)
179 { if ( el->IsPoly() ) --myNbPolygons; else remove( el ); }
180
181 inline void // RemoveVolume
182 SMDS_MeshInfo::RemoveVolume(const SMDS_MeshElement* el)
183 { if ( el->IsPoly() ) --myNbPolyhedrons; else remove( el ); }
184
185 inline int // NbEdges
186 SMDS_MeshInfo::NbEdges      (SMDSAbs_ElementOrder order) const
187 { return order == ORDER_ANY ? myNbEdges+myNbQuadEdges : order == ORDER_LINEAR ? myNbEdges : myNbQuadEdges; }
188
189 inline int // NbFaces
190 SMDS_MeshInfo::NbFaces      (SMDSAbs_ElementOrder order) const
191 { return NbTriangles(order)+NbQuadrangles(order)+(order == ORDER_QUADRATIC ? 0 : myNbPolygons); }
192
193 inline int // NbTriangles
194 SMDS_MeshInfo::NbTriangles  (SMDSAbs_ElementOrder order) const
195 { return order == ORDER_ANY ? myNbTriangles+myNbQuadTriangles : order == ORDER_LINEAR ? myNbTriangles : myNbQuadTriangles; }
196
197 inline int // NbQuadrangles
198 SMDS_MeshInfo::NbQuadrangles(SMDSAbs_ElementOrder order) const
199 { return order == ORDER_ANY ? myNbQuadrangles+myNbQuadQuadrangles : order == ORDER_LINEAR ? myNbQuadrangles : myNbQuadQuadrangles; }
200
201 inline int // NbVolumes
202 SMDS_MeshInfo::NbVolumes (SMDSAbs_ElementOrder order) const
203 { return NbTetras(order) + NbHexas(order) + NbPyramids(order) + NbPrisms(order) + (order == ORDER_QUADRATIC ? 0 : myNbPolyhedrons); }
204
205 inline int // NbTetras
206 SMDS_MeshInfo::NbTetras  (SMDSAbs_ElementOrder order) const
207 { return order == ORDER_ANY ? myNbTetras+myNbQuadTetras : order == ORDER_LINEAR ? myNbTetras : myNbQuadTetras; }
208
209 inline int // NbHexas
210 SMDS_MeshInfo::NbHexas   (SMDSAbs_ElementOrder order) const
211 { return order == ORDER_ANY ? myNbHexas+myNbQuadHexas : order == ORDER_LINEAR ? myNbHexas : myNbQuadHexas; }
212
213 inline int // NbPyramids
214 SMDS_MeshInfo::NbPyramids(SMDSAbs_ElementOrder order) const
215 { return order == ORDER_ANY ? myNbPyramids+myNbQuadPyramids : order == ORDER_LINEAR ? myNbPyramids : myNbQuadPyramids; }
216
217 inline int // NbPrisms
218 SMDS_MeshInfo::NbPrisms  (SMDSAbs_ElementOrder order) const
219 { return order == ORDER_ANY ? myNbPrisms+myNbQuadPrisms : order == ORDER_LINEAR ? myNbPrisms : myNbQuadPrisms; }
220
221 inline int // NbElements
222 SMDS_MeshInfo::NbElements(SMDSAbs_ElementType type) const
223
224   int nb = 0;
225   switch (type) {
226   case SMDSAbs_All:
227     for ( int i=1+index( SMDSAbs_Node,1 ); i<myNb.size(); ++i ) if ( myNb[i] ) nb += *myNb[i];
228     nb += myNbPolygons + myNbPolyhedrons;
229     break;
230   case SMDSAbs_Volume:
231     nb = myNbTetras+ myNbPyramids+ myNbPrisms+ myNbHexas+
232       myNbQuadTetras+ myNbQuadPyramids+ myNbQuadPrisms+ myNbQuadHexas+myNbPolyhedrons;
233     break;
234   case SMDSAbs_Face:
235     nb = myNbTriangles+ myNbQuadrangles+ myNbQuadTriangles+ myNbQuadQuadrangles + myNbPolygons;
236     break;
237   case SMDSAbs_Edge:
238     nb = myNbEdges + myNbQuadEdges;
239     break;
240   case SMDSAbs_Node:
241     nb = myNbNodes;
242   default:;
243   }
244   return nb;
245 }
246 #endif