Salome HOME
0020128: EDF SMESH 926 : Quadratic conversion of BLSURF mesh
[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   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 myNbEdges      , myNbQuadEdges      ;
73   int myNbTriangles  , myNbQuadTriangles  ;
74   int myNbQuadrangles, myNbQuadQuadrangles;
75   int myNbPolygons;
76
77   int myNbTetras  , myNbQuadTetras  ;
78   int myNbHexas   , myNbQuadHexas   ;
79   int myNbPyramids, myNbQuadPyramids;
80   int myNbPrisms  , myNbQuadPrisms  ;
81   int myNbPolyhedrons;
82
83   std::vector<int*> myNb; // pointers to myNb... fields
84   std::vector<int>  myShift; // shift to get an index in myNb by elem->NbNodes()
85 };
86
87 inline SMDS_MeshInfo::SMDS_MeshInfo():
88   myNbNodes(0),
89   myNbEdges      (0), myNbQuadEdges      (0),
90   myNbTriangles  (0), myNbQuadTriangles  (0),
91   myNbQuadrangles(0), myNbQuadQuadrangles(0),
92   myNbPolygons(0),
93   myNbTetras  (0), myNbQuadTetras  (0),
94   myNbHexas   (0), myNbQuadHexas   (0),
95   myNbPyramids(0), myNbQuadPyramids(0),
96   myNbPrisms  (0), myNbQuadPrisms  (0),
97   myNbPolyhedrons(0)
98 {
99   // Number of nodes in standard element types
100   // n   v  f  e
101   // o   o  a  d
102   // d   l  c  g
103   // e      e  e
104   // -----------
105   // 1      
106   // 2         *
107   // 3      *
108   // 4   *  *  *
109   // 5   *  
110   // 6   *  *
111   // 7      
112   // 8   *  *
113   // 9      
114   // 10  *  
115   // 11     
116   // 12     
117   // 13  *  
118   // 14     
119   // 15  *  
120   // 16     
121   // 17     
122   // 18     
123   // 19     
124   // 20  *
125   //
126   // So to have a unique index for each type basing on nb of nodes, we use a shift:
127   myShift.resize(SMDSAbs_Volume + 1, 0);
128   myShift[ SMDSAbs_Face ] = +8; // 3->11, 4->12, 6->14, 8->16
129   myShift[ SMDSAbs_Edge ] = -2; // 2->0, 4->2
130
131   myNb.resize( index( SMDSAbs_Volume,20 ) + 1, NULL);
132   myNb[ index( SMDSAbs_Node,1 )] = & myNbNodes;
133
134   myNb[ index( SMDSAbs_Edge,2 )] = & myNbEdges;
135   myNb[ index( SMDSAbs_Edge,4 )] = & myNbQuadEdges;
136
137   myNb[ index( SMDSAbs_Face,3 )] = & myNbTriangles;
138   myNb[ index( SMDSAbs_Face,4 )] = & myNbQuadrangles;
139   myNb[ index( SMDSAbs_Face,6 )] = & myNbQuadTriangles;
140   myNb[ index( SMDSAbs_Face,8 )] = & myNbQuadQuadrangles;
141
142   myNb[ index( SMDSAbs_Volume, 4)]  = & myNbTetras;
143   myNb[ index( SMDSAbs_Volume, 5)]  = & myNbPyramids;
144   myNb[ index( SMDSAbs_Volume, 6)]  = & myNbPrisms;
145   myNb[ index( SMDSAbs_Volume, 8)]  = & myNbHexas;
146   myNb[ index( SMDSAbs_Volume, 10)] = & myNbQuadTetras;  
147   myNb[ index( SMDSAbs_Volume, 13)] = & myNbQuadPyramids;
148   myNb[ index( SMDSAbs_Volume, 15)] = & myNbQuadPrisms;  
149   myNb[ index( SMDSAbs_Volume, 20)] = & myNbQuadHexas;   
150 }
151 inline void // Clear
152 SMDS_MeshInfo::Clear()
153 { for ( int i=0; i<myNb.size(); ++i ) if ( myNb[i] ) (*myNb[i])=0;
154   myNbPolygons=myNbPolyhedrons=0;
155 }
156 inline int // index
157 SMDS_MeshInfo::index(SMDSAbs_ElementType type, int nbNodes) const
158 { return nbNodes + myShift[ type ]; }
159
160 inline void // remove
161 SMDS_MeshInfo::remove(const SMDS_MeshElement* el)
162 { --(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
163
164 inline void // add
165 SMDS_MeshInfo::add(const SMDS_MeshElement* el)
166 { ++(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
167
168 inline void // RemoveEdge
169 SMDS_MeshInfo::RemoveEdge(const SMDS_MeshElement* el)
170 { if ( el->IsQuadratic() ) --myNbQuadEdges; else --myNbEdges; }
171
172 inline void // RemoveFace
173 SMDS_MeshInfo::RemoveFace(const SMDS_MeshElement* el)
174 { if ( el->IsPoly() ) --myNbPolygons; else remove( el ); }
175
176 inline void // RemoveVolume
177 SMDS_MeshInfo::RemoveVolume(const SMDS_MeshElement* el)
178 { if ( el->IsPoly() ) --myNbPolyhedrons; else remove( el ); }
179
180 inline int // NbEdges
181 SMDS_MeshInfo::NbEdges      (SMDSAbs_ElementOrder order) const
182 { return order == ORDER_ANY ? myNbEdges+myNbQuadEdges : order == ORDER_LINEAR ? myNbEdges : myNbQuadEdges; }
183
184 inline int // NbFaces
185 SMDS_MeshInfo::NbFaces      (SMDSAbs_ElementOrder order) const
186 { return NbTriangles(order)+NbQuadrangles(order)+(order == ORDER_QUADRATIC ? 0 : myNbPolygons); }
187
188 inline int // NbTriangles
189 SMDS_MeshInfo::NbTriangles  (SMDSAbs_ElementOrder order) const
190 { return order == ORDER_ANY ? myNbTriangles+myNbQuadTriangles : order == ORDER_LINEAR ? myNbTriangles : myNbQuadTriangles; }
191
192 inline int // NbQuadrangles
193 SMDS_MeshInfo::NbQuadrangles(SMDSAbs_ElementOrder order) const
194 { return order == ORDER_ANY ? myNbQuadrangles+myNbQuadQuadrangles : order == ORDER_LINEAR ? myNbQuadrangles : myNbQuadQuadrangles; }
195
196 inline int // NbVolumes
197 SMDS_MeshInfo::NbVolumes (SMDSAbs_ElementOrder order) const
198 { return NbTetras(order) + NbHexas(order) + NbPyramids(order) + NbPrisms(order) + (order == ORDER_QUADRATIC ? 0 : myNbPolyhedrons); }
199
200 inline int // NbTetras
201 SMDS_MeshInfo::NbTetras  (SMDSAbs_ElementOrder order) const
202 { return order == ORDER_ANY ? myNbTetras+myNbQuadTetras : order == ORDER_LINEAR ? myNbTetras : myNbQuadTetras; }
203
204 inline int // NbHexas
205 SMDS_MeshInfo::NbHexas   (SMDSAbs_ElementOrder order) const
206 { return order == ORDER_ANY ? myNbHexas+myNbQuadHexas : order == ORDER_LINEAR ? myNbHexas : myNbQuadHexas; }
207
208 inline int // NbPyramids
209 SMDS_MeshInfo::NbPyramids(SMDSAbs_ElementOrder order) const
210 { return order == ORDER_ANY ? myNbPyramids+myNbQuadPyramids : order == ORDER_LINEAR ? myNbPyramids : myNbQuadPyramids; }
211
212 inline int // NbPrisms
213 SMDS_MeshInfo::NbPrisms  (SMDSAbs_ElementOrder order) const
214 { return order == ORDER_ANY ? myNbPrisms+myNbQuadPrisms : order == ORDER_LINEAR ? myNbPrisms : myNbQuadPrisms; }
215
216 inline int // NbElements
217 SMDS_MeshInfo::NbElements(SMDSAbs_ElementType type) const
218
219   int nb = 0;
220   switch (type) {
221   case SMDSAbs_All:
222     for ( int i=1+index( SMDSAbs_Node,1 ); i<myNb.size(); ++i ) if ( myNb[i] ) nb += *myNb[i];
223     nb += myNbPolygons + myNbPolyhedrons;
224     break;
225   case SMDSAbs_Volume:
226     nb = myNbTetras+ myNbPyramids+ myNbPrisms+ myNbHexas+
227       myNbQuadTetras+ myNbQuadPyramids+ myNbQuadPrisms+ myNbQuadHexas+myNbPolyhedrons;
228     break;
229   case SMDSAbs_Face:
230     nb = myNbTriangles+ myNbQuadrangles+ myNbQuadTriangles+ myNbQuadQuadrangles + myNbPolygons;
231     break;
232   case SMDSAbs_Edge:
233     nb = myNbEdges + myNbQuadEdges;
234     break;
235   case SMDSAbs_Node:
236     nb = myNbNodes;
237   default:;
238   }
239   return nb;
240 }
241 #endif