Salome HOME
7ef925f1727885f6bdec22135e3f04e5f5eb4270
[modules/smesh.git] / src / SMDS / SMDS_MeshInfo.hxx
1 // File      : SMDS_MeshInfo.hxx
2 // Created   : Mon Sep 24 18:32:41 2007
3 // Author    : Edward AGAPOV (eap)
4
5 #ifndef SMDS_MeshInfo_HeaderFile
6 #define SMDS_MeshInfo_HeaderFile
7
8 using namespace std;
9
10 #include "SMESH_SMDS.hxx"
11
12 #include "SMDS_MeshElement.hxx"
13
14 class SMDS_EXPORT SMDS_MeshInfo
15 {
16 public:
17
18   inline SMDS_MeshInfo();
19   inline void Clear();
20
21   int NbNodes() const { return myNbNodes; }
22
23   inline int NbEdges      (SMDSAbs_ElementOrder order = ORDER_ANY) const;
24   inline int NbFaces      (SMDSAbs_ElementOrder order = ORDER_ANY) const;
25   inline int NbTriangles  (SMDSAbs_ElementOrder order = ORDER_ANY) const;
26   inline int NbQuadrangles(SMDSAbs_ElementOrder order = ORDER_ANY) const;
27   int NbPolygons() const { return myNbPolygons; }
28
29   inline int NbVolumes (SMDSAbs_ElementOrder order = ORDER_ANY) const;
30   inline int NbTetras  (SMDSAbs_ElementOrder order = ORDER_ANY) const;
31   inline int NbHexas   (SMDSAbs_ElementOrder order = ORDER_ANY) const;
32   inline int NbPyramids(SMDSAbs_ElementOrder order = ORDER_ANY) const;
33   inline int NbPrisms  (SMDSAbs_ElementOrder order = ORDER_ANY) const;
34   int NbPolyhedrons() const { return myNbPolyhedrons; }
35
36 private:
37   friend class SMDS_Mesh;
38
39   // methods to count NOT POLY elements
40   inline void remove(const SMDS_MeshElement* el);
41   inline void add   (const SMDS_MeshElement* el);
42   inline int  index(SMDSAbs_ElementType type, int nbNodes);
43   // methods to remove elements of ANY kind
44   inline void RemoveEdge(const SMDS_MeshElement* el);
45   inline void RemoveFace(const SMDS_MeshElement* el);
46   inline void RemoveVolume(const SMDS_MeshElement* el);
47
48   int myNbNodes;
49
50   int myNbEdges      , myNbQuadEdges      ;
51   int myNbTriangles  , myNbQuadTriangles  ;
52   int myNbQuadrangles, myNbQuadQuadrangles;
53   int myNbPolygons;
54
55   int myNbTetras  , myNbQuadTetras  ;
56   int myNbHexas   , myNbQuadHexas   ;
57   int myNbPyramids, myNbQuadPyramids;
58   int myNbPrisms  , myNbQuadPrisms  ;
59   int myNbPolyhedrons;
60
61   std::vector<int*> myNb; // pointers to myNb... fields
62   std::vector<int>  myShift; // shift to get an index in myNb by elem->NbNodes()
63 };
64
65 inline SMDS_MeshInfo::SMDS_MeshInfo():
66   myNbNodes(0),
67   myNbEdges      (0), myNbQuadEdges      (0),
68   myNbTriangles  (0), myNbQuadTriangles  (0),
69   myNbQuadrangles(0), myNbQuadQuadrangles(0),
70   myNbPolygons(0),
71   myNbTetras  (0), myNbQuadTetras  (0),
72   myNbHexas   (0), myNbQuadHexas   (0),
73   myNbPyramids(0), myNbQuadPyramids(0),
74   myNbPrisms  (0), myNbQuadPrisms  (0),
75   myNbPolyhedrons(0)
76 {
77   // Number of nodes in standard element types
78   // n   v  f  e
79   // o   o  a  d
80   // d   l  c  g
81   // e      e  e
82   // -----------
83   // 1      
84   // 2         *
85   // 3      *
86   // 4   *  *  *
87   // 5   *  
88   // 6   *  *
89   // 7      
90   // 8   *  *
91   // 9      
92   // 10  *  
93   // 11     
94   // 12     
95   // 13  *  
96   // 14     
97   // 15  *  
98   // 16     
99   // 17     
100   // 18     
101   // 19     
102   // 20  *
103   //
104   // So to have a unique index for each type basing on nb of nodes, we use a shift:
105   myShift.resize(SMDSAbs_Volume + 1, 0);
106   myShift[ SMDSAbs_Face ] = +8; // 3->11, 4->12, 6->14, 8->16
107   myShift[ SMDSAbs_Edge ] = -2; // 2->0, 4->2
108
109   myNb.resize( index( SMDSAbs_Volume,20 ) + 1, NULL);
110   myNb[ index( SMDSAbs_Node,1 )] = & myNbNodes;
111
112   myNb[ index( SMDSAbs_Edge,2 )] = & myNbEdges;
113   myNb[ index( SMDSAbs_Edge,4 )] = & myNbQuadEdges;
114
115   myNb[ index( SMDSAbs_Face,3 )] = & myNbTriangles;
116   myNb[ index( SMDSAbs_Face,4 )] = & myNbQuadrangles;
117   myNb[ index( SMDSAbs_Face,6 )] = & myNbQuadTriangles;
118   myNb[ index( SMDSAbs_Face,8 )] = & myNbQuadQuadrangles;
119
120   myNb[ index( SMDSAbs_Volume, 4)]  = & myNbTetras;
121   myNb[ index( SMDSAbs_Volume, 5)]  = & myNbPyramids;
122   myNb[ index( SMDSAbs_Volume, 6)]  = & myNbPrisms;
123   myNb[ index( SMDSAbs_Volume, 8)]  = & myNbHexas;
124   myNb[ index( SMDSAbs_Volume, 10)] = & myNbQuadTetras;  
125   myNb[ index( SMDSAbs_Volume, 13)] = & myNbQuadPyramids;
126   myNb[ index( SMDSAbs_Volume, 15)] = & myNbQuadPrisms;  
127   myNb[ index( SMDSAbs_Volume, 20)] = & myNbQuadHexas;   
128 }
129 inline void // Clear
130 SMDS_MeshInfo::Clear()
131 { for ( int i=0; i<myNb.size(); ++i ) if ( myNb[i] ) (*myNb[i])=0; }
132
133 inline int // index
134 SMDS_MeshInfo::index(SMDSAbs_ElementType type, int nbNodes)
135 { return nbNodes + myShift[ type ]; }
136
137 inline void // remove
138 SMDS_MeshInfo::remove(const SMDS_MeshElement* el)
139 { --(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
140
141 inline void // add
142 SMDS_MeshInfo::add(const SMDS_MeshElement* el)
143 { ++(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
144
145 inline void // RemoveEdge
146 SMDS_MeshInfo::RemoveEdge(const SMDS_MeshElement* el)
147 { if ( el->IsQuadratic() ) --myNbQuadEdges; else --myNbEdges; }
148
149 inline void // RemoveFace
150 SMDS_MeshInfo::RemoveFace(const SMDS_MeshElement* el)
151 { if ( el->IsPoly() ) --myNbPolygons; else remove( el ); }
152
153 inline void // RemoveVolume
154 SMDS_MeshInfo::RemoveVolume(const SMDS_MeshElement* el)
155 { if ( el->IsPoly() ) --myNbPolyhedrons; else remove( el ); }
156
157 inline int // NbEdges
158 SMDS_MeshInfo::NbEdges      (SMDSAbs_ElementOrder order) const
159 { return order == ORDER_ANY ? myNbEdges+myNbQuadEdges : order == ORDER_LINEAR ? myNbEdges : myNbQuadEdges; }
160
161 inline int // NbFaces
162 SMDS_MeshInfo::NbFaces      (SMDSAbs_ElementOrder order) const
163 { return NbTriangles(order)+NbQuadrangles(order)+(order == ORDER_QUADRATIC ? 0 : myNbPolygons); }
164
165 inline int // NbTriangles
166 SMDS_MeshInfo::NbTriangles  (SMDSAbs_ElementOrder order) const
167 { return order == ORDER_ANY ? myNbTriangles+myNbQuadTriangles : order == ORDER_LINEAR ? myNbTriangles : myNbQuadTriangles; }
168
169 inline int // NbQuadrangles
170 SMDS_MeshInfo::NbQuadrangles(SMDSAbs_ElementOrder order) const
171 { return order == ORDER_ANY ? myNbQuadrangles+myNbQuadQuadrangles : order == ORDER_LINEAR ? myNbQuadrangles : myNbQuadQuadrangles; }
172
173 inline int // NbVolumes
174 SMDS_MeshInfo::NbVolumes (SMDSAbs_ElementOrder order) const
175 { return NbTetras(order) + NbHexas(order) + NbPyramids(order) + NbPrisms(order) + (order == ORDER_QUADRATIC ? 0 : myNbPolyhedrons); }
176
177 inline int // NbTetras
178 SMDS_MeshInfo::NbTetras  (SMDSAbs_ElementOrder order) const
179 { return order == ORDER_ANY ? myNbTetras+myNbQuadTetras : order == ORDER_LINEAR ? myNbTetras : myNbQuadTetras; }
180
181 inline int // NbHexas
182 SMDS_MeshInfo::NbHexas   (SMDSAbs_ElementOrder order) const
183 { return order == ORDER_ANY ? myNbHexas+myNbQuadHexas : order == ORDER_LINEAR ? myNbHexas : myNbQuadHexas; }
184
185 inline int // NbPyramids
186 SMDS_MeshInfo::NbPyramids(SMDSAbs_ElementOrder order) const
187 { return order == ORDER_ANY ? myNbPyramids+myNbQuadPyramids : order == ORDER_LINEAR ? myNbPyramids : myNbQuadPyramids; }
188
189 inline int // NbPrisms
190 SMDS_MeshInfo::NbPrisms  (SMDSAbs_ElementOrder order) const
191 { return order == ORDER_ANY ? myNbPrisms+myNbQuadPrisms : order == ORDER_LINEAR ? myNbPrisms : myNbQuadPrisms; }
192
193 #endif