1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMDS_MeshInfo.hxx
23 // Created : Mon Sep 24 18:32:41 2007
24 // Author : Edward AGAPOV (eap)
26 #ifndef SMDS_MeshInfo_HeaderFile
27 #define SMDS_MeshInfo_HeaderFile
31 #include "SMESH_SMDS.hxx"
33 #include "SMDS_MeshElement.hxx"
35 class SMDS_EXPORT SMDS_MeshInfo
39 inline SMDS_MeshInfo();
42 int NbNodes() const { return myNbNodes; }
44 inline int NbEdges (SMDSAbs_ElementOrder order = ORDER_ANY) const;
45 inline int NbFaces (SMDSAbs_ElementOrder order = ORDER_ANY) const;
46 inline int NbTriangles (SMDSAbs_ElementOrder order = ORDER_ANY) const;
47 inline int NbQuadrangles(SMDSAbs_ElementOrder order = ORDER_ANY) const;
48 int NbPolygons() const { return myNbPolygons; }
50 inline int NbVolumes (SMDSAbs_ElementOrder order = ORDER_ANY) const;
51 inline int NbTetras (SMDSAbs_ElementOrder order = ORDER_ANY) const;
52 inline int NbHexas (SMDSAbs_ElementOrder order = ORDER_ANY) const;
53 inline int NbPyramids(SMDSAbs_ElementOrder order = ORDER_ANY) const;
54 inline int NbPrisms (SMDSAbs_ElementOrder order = ORDER_ANY) const;
55 int NbPolyhedrons() const { return myNbPolyhedrons; }
58 friend class SMDS_Mesh;
60 // methods to count NOT POLY elements
61 inline void remove(const SMDS_MeshElement* el);
62 inline void add (const SMDS_MeshElement* el);
63 inline int index(SMDSAbs_ElementType type, int nbNodes);
64 // methods to remove elements of ANY kind
65 inline void RemoveEdge(const SMDS_MeshElement* el);
66 inline void RemoveFace(const SMDS_MeshElement* el);
67 inline void RemoveVolume(const SMDS_MeshElement* el);
71 int myNbEdges , myNbQuadEdges ;
72 int myNbTriangles , myNbQuadTriangles ;
73 int myNbQuadrangles, myNbQuadQuadrangles;
76 int myNbTetras , myNbQuadTetras ;
77 int myNbHexas , myNbQuadHexas ;
78 int myNbPyramids, myNbQuadPyramids;
79 int myNbPrisms , myNbQuadPrisms ;
82 std::vector<int*> myNb; // pointers to myNb... fields
83 std::vector<int> myShift; // shift to get an index in myNb by elem->NbNodes()
86 inline SMDS_MeshInfo::SMDS_MeshInfo():
88 myNbEdges (0), myNbQuadEdges (0),
89 myNbTriangles (0), myNbQuadTriangles (0),
90 myNbQuadrangles(0), myNbQuadQuadrangles(0),
92 myNbTetras (0), myNbQuadTetras (0),
93 myNbHexas (0), myNbQuadHexas (0),
94 myNbPyramids(0), myNbQuadPyramids(0),
95 myNbPrisms (0), myNbQuadPrisms (0),
98 // Number of nodes in standard element types
125 // So to have a unique index for each type basing on nb of nodes, we use a shift:
126 myShift.resize(SMDSAbs_Volume + 1, 0);
127 myShift[ SMDSAbs_Face ] = +8; // 3->11, 4->12, 6->14, 8->16
128 myShift[ SMDSAbs_Edge ] = -2; // 2->0, 4->2
130 myNb.resize( index( SMDSAbs_Volume,20 ) + 1, NULL);
131 myNb[ index( SMDSAbs_Node,1 )] = & myNbNodes;
133 myNb[ index( SMDSAbs_Edge,2 )] = & myNbEdges;
134 myNb[ index( SMDSAbs_Edge,4 )] = & myNbQuadEdges;
136 myNb[ index( SMDSAbs_Face,3 )] = & myNbTriangles;
137 myNb[ index( SMDSAbs_Face,4 )] = & myNbQuadrangles;
138 myNb[ index( SMDSAbs_Face,6 )] = & myNbQuadTriangles;
139 myNb[ index( SMDSAbs_Face,8 )] = & myNbQuadQuadrangles;
141 myNb[ index( SMDSAbs_Volume, 4)] = & myNbTetras;
142 myNb[ index( SMDSAbs_Volume, 5)] = & myNbPyramids;
143 myNb[ index( SMDSAbs_Volume, 6)] = & myNbPrisms;
144 myNb[ index( SMDSAbs_Volume, 8)] = & myNbHexas;
145 myNb[ index( SMDSAbs_Volume, 10)] = & myNbQuadTetras;
146 myNb[ index( SMDSAbs_Volume, 13)] = & myNbQuadPyramids;
147 myNb[ index( SMDSAbs_Volume, 15)] = & myNbQuadPrisms;
148 myNb[ index( SMDSAbs_Volume, 20)] = & myNbQuadHexas;
151 SMDS_MeshInfo::Clear()
152 { for ( int i=0; i<myNb.size(); ++i ) if ( myNb[i] ) (*myNb[i])=0; }
155 SMDS_MeshInfo::index(SMDSAbs_ElementType type, int nbNodes)
156 { return nbNodes + myShift[ type ]; }
158 inline void // remove
159 SMDS_MeshInfo::remove(const SMDS_MeshElement* el)
160 { --(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
163 SMDS_MeshInfo::add(const SMDS_MeshElement* el)
164 { ++(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
166 inline void // RemoveEdge
167 SMDS_MeshInfo::RemoveEdge(const SMDS_MeshElement* el)
168 { if ( el->IsQuadratic() ) --myNbQuadEdges; else --myNbEdges; }
170 inline void // RemoveFace
171 SMDS_MeshInfo::RemoveFace(const SMDS_MeshElement* el)
172 { if ( el->IsPoly() ) --myNbPolygons; else remove( el ); }
174 inline void // RemoveVolume
175 SMDS_MeshInfo::RemoveVolume(const SMDS_MeshElement* el)
176 { if ( el->IsPoly() ) --myNbPolyhedrons; else remove( el ); }
178 inline int // NbEdges
179 SMDS_MeshInfo::NbEdges (SMDSAbs_ElementOrder order) const
180 { return order == ORDER_ANY ? myNbEdges+myNbQuadEdges : order == ORDER_LINEAR ? myNbEdges : myNbQuadEdges; }
182 inline int // NbFaces
183 SMDS_MeshInfo::NbFaces (SMDSAbs_ElementOrder order) const
184 { return NbTriangles(order)+NbQuadrangles(order)+(order == ORDER_QUADRATIC ? 0 : myNbPolygons); }
186 inline int // NbTriangles
187 SMDS_MeshInfo::NbTriangles (SMDSAbs_ElementOrder order) const
188 { return order == ORDER_ANY ? myNbTriangles+myNbQuadTriangles : order == ORDER_LINEAR ? myNbTriangles : myNbQuadTriangles; }
190 inline int // NbQuadrangles
191 SMDS_MeshInfo::NbQuadrangles(SMDSAbs_ElementOrder order) const
192 { return order == ORDER_ANY ? myNbQuadrangles+myNbQuadQuadrangles : order == ORDER_LINEAR ? myNbQuadrangles : myNbQuadQuadrangles; }
194 inline int // NbVolumes
195 SMDS_MeshInfo::NbVolumes (SMDSAbs_ElementOrder order) const
196 { return NbTetras(order) + NbHexas(order) + NbPyramids(order) + NbPrisms(order) + (order == ORDER_QUADRATIC ? 0 : myNbPolyhedrons); }
198 inline int // NbTetras
199 SMDS_MeshInfo::NbTetras (SMDSAbs_ElementOrder order) const
200 { return order == ORDER_ANY ? myNbTetras+myNbQuadTetras : order == ORDER_LINEAR ? myNbTetras : myNbQuadTetras; }
202 inline int // NbHexas
203 SMDS_MeshInfo::NbHexas (SMDSAbs_ElementOrder order) const
204 { return order == ORDER_ANY ? myNbHexas+myNbQuadHexas : order == ORDER_LINEAR ? myNbHexas : myNbQuadHexas; }
206 inline int // NbPyramids
207 SMDS_MeshInfo::NbPyramids(SMDSAbs_ElementOrder order) const
208 { return order == ORDER_ANY ? myNbPyramids+myNbQuadPyramids : order == ORDER_LINEAR ? myNbPyramids : myNbQuadPyramids; }
210 inline int // NbPrisms
211 SMDS_MeshInfo::NbPrisms (SMDSAbs_ElementOrder order) const
212 { return order == ORDER_ANY ? myNbPrisms+myNbQuadPrisms : order == ORDER_LINEAR ? myNbPrisms : myNbQuadPrisms; }