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