1 // Copyright (C) 2010-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SMDS_MeshCell.hxx"
21 #include "utilities.h"
23 int SMDS_MeshCell::nbCells = 0;
25 SMDS_MeshCell::SMDS_MeshCell() :
32 SMDS_MeshCell::~SMDS_MeshCell()
36 //================================================================================
38 * \brief Return VTKCellType corresponding to SMDSAbs_EntityType
40 //================================================================================
42 VTKCellType SMDS_MeshCell::toVtkType (SMDSAbs_EntityType smdsType)
44 static std::vector< VTKCellType > vtkTypes;
45 if ( vtkTypes.empty() )
47 vtkTypes.resize( SMDSEntity_Last+1, VTK_EMPTY_CELL );
48 vtkTypes[ SMDSEntity_Node ] = VTK_VERTEX;
49 vtkTypes[ SMDSEntity_0D ] = VTK_VERTEX;
50 vtkTypes[ SMDSEntity_Edge ] = VTK_LINE;
51 vtkTypes[ SMDSEntity_Quad_Edge ] = VTK_QUADRATIC_EDGE;
52 vtkTypes[ SMDSEntity_Triangle ] = VTK_TRIANGLE;
53 vtkTypes[ SMDSEntity_Quad_Triangle ] = VTK_QUADRATIC_TRIANGLE;
54 vtkTypes[ SMDSEntity_Quadrangle ] = VTK_QUAD;
55 vtkTypes[ SMDSEntity_Quad_Quadrangle ] = VTK_QUADRATIC_QUAD;
56 vtkTypes[ SMDSEntity_BiQuad_Quadrangle ] = VTK_BIQUADRATIC_QUAD;
57 vtkTypes[ SMDSEntity_Polygon ] = VTK_POLYGON;
58 //vtkTypes[ SMDSEntity_Quad_Polygon ] = ;
59 vtkTypes[ SMDSEntity_Tetra ] = VTK_TETRA;
60 vtkTypes[ SMDSEntity_Quad_Tetra ] = VTK_QUADRATIC_TETRA;
61 vtkTypes[ SMDSEntity_Pyramid ] = VTK_PYRAMID;
62 vtkTypes[ SMDSEntity_Quad_Pyramid ] = VTK_QUADRATIC_PYRAMID;
63 vtkTypes[ SMDSEntity_Hexa ] = VTK_HEXAHEDRON;
64 vtkTypes[ SMDSEntity_Quad_Hexa ] = VTK_QUADRATIC_HEXAHEDRON;
65 vtkTypes[ SMDSEntity_TriQuad_Hexa ] = VTK_TRIQUADRATIC_HEXAHEDRON;
66 vtkTypes[ SMDSEntity_Penta ] = VTK_WEDGE;
67 vtkTypes[ SMDSEntity_Quad_Penta ] = VTK_QUADRATIC_WEDGE;
68 vtkTypes[ SMDSEntity_Hexagonal_Prism ] = VTK_HEXAGONAL_PRISM;
69 vtkTypes[ SMDSEntity_Polyhedra ] = VTK_POLYHEDRON;
70 //vtkTypes[ SMDSEntity_Quad_Polyhedra ] = ;
71 vtkTypes[ SMDSEntity_Ball ] = VTK_POLY_VERTEX;
73 return vtkTypes[ smdsType ];
76 //================================================================================
78 * \brief Return indices to transform cell connectivity from SMDS to VTK
79 * Usage: vtkIDs[i] = smdsIDs[ indices[ i ]]
81 //================================================================================
83 const std::vector< int >& SMDS_MeshCell::toVtkOrder(SMDSAbs_EntityType smdsType)
85 static std::vector< std::vector< int > > toVtkInterlaces;
86 if ( toVtkInterlaces.empty() )
88 toVtkInterlaces.resize( SMDSEntity_Last+1 );
90 // const int ids[] = {0};
91 // toVtkInterlaces[SMDSEntity_0D].assign( &ids[0], &ids[0]+1 );
92 // toVtkInterlaces[SMDSEntity_Node].assign( &ids[0], &ids[0]+1 );
95 // const int ids[] = {0,1};
96 // toVtkInterlaces[SMDSEntity_Edge].assign( &ids[0], &ids[0]+2 );
99 // const int ids[] = {0,1,2};
100 // toVtkInterlaces[SMDSEntity_Quad_Edge].assign( &ids[0], &ids[0]+3 );
103 // const int ids[] = {0,1,2};
104 // toVtkInterlaces[SMDSEntity_Triangle].assign( &ids[0], &ids[0]+3 );
107 // const int ids[] = {0,1,2,3,4,5};
108 // toVtkInterlaces[SMDSEntity_Quad_Triangle].assign( &ids[0], &ids[0]+6 );
111 // const int ids[] = {0,1,2,3};
112 // toVtkInterlaces[SMDSEntity_Quadrangle].assign( &ids[0], &ids[0]+4 );
115 // const int ids[] = {0,1,2,3,4,5,6,7};
116 // toVtkInterlaces[SMDSEntity_Quad_Quadrangle].assign( &ids[0], &ids[0]+8 );
119 // const int ids[] = {0,1,2,3,4,5,6,7,8};
120 // toVtkInterlaces[SMDSEntity_BiQuad_Quadrangle].assign( &ids[0], &ids[0]+9 );
123 const int ids[] = {0,2,1,3};
124 toVtkInterlaces[SMDSEntity_Tetra].assign( &ids[0], &ids[0]+4 );
127 const int ids[] = {0,2,1,3,6,5,4,7,9,8};
128 toVtkInterlaces[SMDSEntity_Quad_Tetra].assign( &ids[0], &ids[0]+10 );
131 const int ids[] = {0,3,2,1,4};
132 toVtkInterlaces[SMDSEntity_Pyramid].assign( &ids[0], &ids[0]+5 );
135 const int ids[] = {0,3,2,1,4,8,7,6,5,9,12,11,10};
136 toVtkInterlaces[SMDSEntity_Quad_Pyramid].assign( &ids[0], &ids[0]+13 );
139 const int ids[] = {0,3,2,1,4,7,6,5};
140 toVtkInterlaces[SMDSEntity_Hexa].assign( &ids[0], &ids[0]+8 );
143 const int ids[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17};
144 toVtkInterlaces[SMDSEntity_Quad_Hexa].assign( &ids[0], &ids[0]+20 );
147 const int ids[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17, 21,23,24,22,20,25,26};
148 toVtkInterlaces[SMDSEntity_TriQuad_Hexa].assign( &ids[0], &ids[0]+27 );
151 const int ids[] = {0,1,2,3,4,5};
152 toVtkInterlaces[SMDSEntity_Penta].assign( &ids[0], &ids[0]+6 );
155 const int ids[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14};
156 toVtkInterlaces[SMDSEntity_Quad_Penta].assign( &ids[0], &ids[0]+15 );
159 const int ids[] = {0,5,4,3,2,1,6,11,10,9,8,7};
160 toVtkInterlaces[SMDSEntity_Hexagonal_Prism].assign( &ids[0], &ids[0]+12 );
163 return toVtkInterlaces[smdsType];
166 //================================================================================
168 * \brief Return indices to reverse an SMDS cell of given type
169 * Usage: reverseIDs[i] = forwardIDs[ indices[ i ]]
171 //================================================================================
173 const std::vector<int>& SMDS_MeshCell::reverseSmdsOrder(SMDSAbs_EntityType smdsType)
175 static std::vector< std::vector< int > > reverseInterlaces;
176 if ( reverseInterlaces.empty() )
178 reverseInterlaces.resize( SMDSEntity_Last+1 );
180 const int ids[] = {0};
181 reverseInterlaces[SMDSEntity_0D].assign( &ids[0], &ids[0]+1 );
182 reverseInterlaces[SMDSEntity_Node].assign( &ids[0], &ids[0]+1 );
183 reverseInterlaces[SMDSEntity_Ball].assign( &ids[0], &ids[0]+1 );
186 const int ids[] = {1,0};
187 reverseInterlaces[SMDSEntity_Edge].assign( &ids[0], &ids[0]+2 );
190 const int ids[] = {1,0,2};
191 reverseInterlaces[SMDSEntity_Quad_Edge].assign( &ids[0], &ids[0]+3 );
194 const int ids[] = {0,2,1};
195 reverseInterlaces[SMDSEntity_Triangle].assign( &ids[0], &ids[0]+3 );
198 const int ids[] = {0,2,1,5,4,3};
199 reverseInterlaces[SMDSEntity_Quad_Triangle].assign( &ids[0], &ids[0]+6 );
202 const int ids[] = {0,3,2,1};
203 reverseInterlaces[SMDSEntity_Quadrangle].assign( &ids[0], &ids[0]+4 );
206 const int ids[] = {0,3,2,1,7,6,5,4};
207 reverseInterlaces[SMDSEntity_Quad_Quadrangle].assign( &ids[0], &ids[0]+8 );
210 const int ids[] = {0,3,2,1,7,6,5,4,8};
211 reverseInterlaces[SMDSEntity_BiQuad_Quadrangle].assign( &ids[0], &ids[0]+9 );
214 const int ids[] = {0,2,1,3};
215 reverseInterlaces[SMDSEntity_Tetra].assign( &ids[0], &ids[0]+4 );
218 const int ids[] = {0,2,1,3,6,5,4,7,9,8};
219 reverseInterlaces[SMDSEntity_Quad_Tetra].assign( &ids[0], &ids[0]+10 );
222 const int ids[] = {0,3,2,1,4};
223 reverseInterlaces[SMDSEntity_Pyramid].assign( &ids[0], &ids[0]+5 );
226 const int ids[] = {0,3,2,1,4,8,7,6,5,9,12,11,10};
227 reverseInterlaces[SMDSEntity_Quad_Pyramid].assign( &ids[0], &ids[0]+13 );
230 const int ids[] = {0,3,2,1,4,7,6,5};
231 reverseInterlaces[SMDSEntity_Hexa].assign( &ids[0], &ids[0]+8 );
234 const int ids[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17};
235 reverseInterlaces[SMDSEntity_Quad_Hexa].assign( &ids[0], &ids[0]+20 );
238 const int ids[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17, 20,24,23,22,21,25,26};
239 reverseInterlaces[SMDSEntity_TriQuad_Hexa].assign( &ids[0], &ids[0]+27 );
242 const int ids[] = {0,2,1,3,5,4};
243 reverseInterlaces[SMDSEntity_Penta].assign( &ids[0], &ids[0]+6 );
246 const int ids[] = {0,2,1,3,5,4, 8,7,6,11,10,9,12,14,13};
247 reverseInterlaces[SMDSEntity_Quad_Penta].assign( &ids[0], &ids[0]+15 );
250 const int ids[] = {0,5,4,3,2,1,6,11,10,9,8,7};
251 reverseInterlaces[SMDSEntity_Hexagonal_Prism].assign( &ids[0], &ids[0]+12 );
254 return reverseInterlaces[smdsType];
257 //================================================================================
259 * \brief Return indices to set nodes of a quadratic 1D or 2D element in interlaced order
260 * Usage: interlacedIDs[i] = smdsIDs[ indices[ i ]]
262 //================================================================================
264 const std::vector<int>& SMDS_MeshCell::interlacedSmdsOrder(SMDSAbs_EntityType smdsType)
266 static std::vector< std::vector< int > > interlace;
267 if ( interlace.empty() )
269 interlace.resize( SMDSEntity_Last+1 );
271 const int ids[] = {0,2,1};
272 interlace[SMDSEntity_Quad_Edge].assign( &ids[0], &ids[0]+3 );
275 const int ids[] = {0,3,1,4,2,5};
276 interlace[SMDSEntity_Quad_Triangle].assign( &ids[0], &ids[0]+6 );
279 const int ids[] = {0,4,1,5,2,6,3,7,8};
280 interlace[SMDSEntity_Quad_Quadrangle].assign( &ids[0], &ids[0]+8 );
281 interlace[SMDSEntity_BiQuad_Quadrangle].assign( &ids[0], &ids[0]+9 );
284 return interlace[smdsType];
287 //================================================================================
289 * \brief Return SMDSAbs_EntityType corresponding to VTKCellType
291 //================================================================================
293 SMDSAbs_EntityType SMDS_MeshCell::toSmdsType(VTKCellType vtkType)
295 static std::vector< SMDSAbs_EntityType > smdsTypes;
296 if ( smdsTypes.empty() )
298 smdsTypes.resize( VTK_NUMBER_OF_CELL_TYPES, SMDSEntity_Last );
299 for ( int iSMDS = 0; iSMDS < SMDSEntity_Last; ++iSMDS )
300 smdsTypes[ toVtkType( SMDSAbs_EntityType( iSMDS ))] = SMDSAbs_EntityType( iSMDS );
302 return smdsTypes[ vtkType ];
305 //================================================================================
307 * \brief Return SMDSAbs_ElementType by SMDSAbs_GeometryType
309 //================================================================================
311 SMDSAbs_ElementType SMDS_MeshCell::toSmdsType(SMDSAbs_GeometryType geomType)
313 switch ( geomType ) {
314 case SMDSGeom_POINT: return SMDSAbs_0DElement;
316 case SMDSGeom_EDGE: return SMDSAbs_Edge;
318 case SMDSGeom_TRIANGLE:
319 case SMDSGeom_QUADRANGLE:
320 case SMDSGeom_POLYGON: return SMDSAbs_Face;
323 case SMDSGeom_PYRAMID:
326 case SMDSGeom_HEXAGONAL_PRISM:
327 case SMDSGeom_POLYHEDRA: return SMDSAbs_Volume;
329 case SMDSGeom_BALL: return SMDSAbs_Ball;
331 case SMDSGeom_NONE: ;
336 //================================================================================
338 * \brief Return SMDSAbs_ElementType by SMDSAbs_EntityType
340 //================================================================================
342 SMDSAbs_ElementType SMDS_MeshCell::toSmdsType(SMDSAbs_EntityType entityType)
344 switch ( entityType ) {
345 case SMDSEntity_Node: return SMDSAbs_Node;
347 case SMDSEntity_0D: return SMDSAbs_0DElement;
349 case SMDSEntity_Edge:
350 case SMDSEntity_Quad_Edge: return SMDSAbs_Edge;
352 case SMDSEntity_Triangle:
353 case SMDSEntity_Quad_Triangle:
354 case SMDSEntity_Quadrangle:
355 case SMDSEntity_Quad_Quadrangle:
356 case SMDSEntity_BiQuad_Quadrangle:
357 case SMDSEntity_Polygon:
358 case SMDSEntity_Quad_Polygon: return SMDSAbs_Face;
360 case SMDSEntity_Tetra:
361 case SMDSEntity_Quad_Tetra:
362 case SMDSEntity_Pyramid:
363 case SMDSEntity_Quad_Pyramid:
364 case SMDSEntity_Hexa:
365 case SMDSEntity_Quad_Hexa:
366 case SMDSEntity_TriQuad_Hexa:
367 case SMDSEntity_Penta:
368 case SMDSEntity_Quad_Penta:
369 case SMDSEntity_Hexagonal_Prism:
370 case SMDSEntity_Polyhedra:
371 case SMDSEntity_Quad_Polyhedra: return SMDSAbs_Volume;
373 case SMDSEntity_Ball: return SMDSAbs_Ball;
375 case SMDSEntity_Last:;
381 //================================================================================
383 * \brief Return indices to transform cell connectivity from VTK to SMDS
384 * Usage: smdsIDs[i] = vtkIDs[ indices[ i ]]
386 //================================================================================
388 const std::vector<int>& SMDS_MeshCell::fromVtkOrder(SMDSAbs_EntityType smdsType)
390 static std::vector< std::vector<int> > fromVtkInterlaces;
391 if ( fromVtkInterlaces.empty() )
393 fromVtkInterlaces.resize( SMDSEntity_Last+1 );
394 for ( int iSMDS = 0; iSMDS < SMDSEntity_Last; ++iSMDS )
396 const std::vector<int> & toVtk = toVtkOrder( SMDSAbs_EntityType( iSMDS ));
397 std::vector<int> & toSmds = fromVtkInterlaces[ iSMDS ];
398 toSmds.resize( toVtk.size() );
399 for ( size_t i = 0; i < toVtk.size(); ++i )
400 toSmds[ toVtk[i] ] = i;
403 return fromVtkInterlaces[ smdsType ];
406 //================================================================================
408 * \brief Return indices to transform cell connectivity from SMDS to VTK
409 * Usage: vtkIDs[i] = smdsIDs[ indices[ i ]]
411 //================================================================================
413 const std::vector<int>& SMDS_MeshCell::toVtkOrder(VTKCellType vtkType)
415 return toVtkOrder( toSmdsType( vtkType ));
418 //================================================================================
420 * \brief Return indices to transform cell connectivity from VTK to SMDS
421 * Usage: smdsIDs[i] = vtkIDs[ indices[ i ]]
423 //================================================================================
425 const std::vector<int>& SMDS_MeshCell::fromVtkOrder(VTKCellType vtkType)
427 return fromVtkOrder( toSmdsType( vtkType ));