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