Back to index

salome-smesh  6.5.0
SMDS_MeshCell.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2010-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "SMDS_MeshCell.hxx"
00021 #include "utilities.h"
00022 
00023 int SMDS_MeshCell::nbCells = 0;
00024 
00025 SMDS_MeshCell::SMDS_MeshCell() :
00026   SMDS_MeshElement(-1)
00027 {
00028   nbCells++;
00029   myVtkID = -1;
00030 }
00031 
00032 SMDS_MeshCell::~SMDS_MeshCell()
00033 {
00034   nbCells--;
00035 }
00036 //================================================================================
00040 //================================================================================
00041 
00042 VTKCellType SMDS_MeshCell::toVtkType (SMDSAbs_EntityType smdsType)
00043 {
00044   static std::vector< VTKCellType > vtkTypes;
00045   if ( vtkTypes.empty() )
00046   {
00047     vtkTypes.resize( SMDSEntity_Last+1, VTK_EMPTY_CELL );
00048     vtkTypes[ SMDSEntity_Node ]              = VTK_VERTEX;
00049     vtkTypes[ SMDSEntity_0D ]                = VTK_VERTEX; //VTK_POLY_VERTEX; // ??
00050     vtkTypes[ SMDSEntity_Edge ]              = VTK_LINE;
00051     vtkTypes[ SMDSEntity_Quad_Edge ]         = VTK_QUADRATIC_EDGE;
00052     vtkTypes[ SMDSEntity_Triangle ]          = VTK_TRIANGLE;
00053     vtkTypes[ SMDSEntity_Quad_Triangle ]     = VTK_QUADRATIC_TRIANGLE;
00054     vtkTypes[ SMDSEntity_Quadrangle ]        = VTK_QUAD;
00055     vtkTypes[ SMDSEntity_Quad_Quadrangle ]   = VTK_QUADRATIC_QUAD;
00056     vtkTypes[ SMDSEntity_BiQuad_Quadrangle ] = VTK_BIQUADRATIC_QUAD;
00057     vtkTypes[ SMDSEntity_Polygon ]           = VTK_POLYGON;
00058     //vtkTypes[ SMDSEntity_Quad_Polygon ]      = ;
00059     vtkTypes[ SMDSEntity_Tetra ]             = VTK_TETRA;
00060     vtkTypes[ SMDSEntity_Quad_Tetra ]        = VTK_QUADRATIC_TETRA;
00061     vtkTypes[ SMDSEntity_Pyramid ]           = VTK_PYRAMID;
00062     vtkTypes[ SMDSEntity_Quad_Pyramid ]      = VTK_QUADRATIC_PYRAMID;
00063     vtkTypes[ SMDSEntity_Hexa ]              = VTK_HEXAHEDRON;
00064     vtkTypes[ SMDSEntity_Quad_Hexa ]         = VTK_QUADRATIC_HEXAHEDRON;
00065     vtkTypes[ SMDSEntity_TriQuad_Hexa ]      = VTK_TRIQUADRATIC_HEXAHEDRON;
00066     vtkTypes[ SMDSEntity_Penta ]             = VTK_WEDGE;
00067     vtkTypes[ SMDSEntity_Quad_Penta ]        = VTK_QUADRATIC_WEDGE;
00068     vtkTypes[ SMDSEntity_Hexagonal_Prism ]   = VTK_HEXAGONAL_PRISM;
00069     vtkTypes[ SMDSEntity_Polyhedra ]         = VTK_POLYHEDRON;
00070     //vtkTypes[ SMDSEntity_Quad_Polyhedra ]    = ;
00071   }
00072   return vtkTypes[ smdsType ];
00073 }
00074 
00075 //================================================================================
00080 //================================================================================
00081 
00082 const std::vector< int >& SMDS_MeshCell::toVtkOrder(SMDSAbs_EntityType smdsType)
00083 {
00084   static std::vector< std::vector< int > > toVtkInterlaces;
00085   if ( toVtkInterlaces.empty() )
00086   {
00087     toVtkInterlaces.resize( SMDSEntity_Last+1 );
00088     // {
00089     //   const int ids[] = {0};
00090     //   toVtkInterlaces[SMDSEntity_0D].assign( &ids[0], &ids[0]+1 );
00091     //   toVtkInterlaces[SMDSEntity_Node].assign( &ids[0], &ids[0]+1 );
00092     // }
00093     // {
00094     //   const int ids[] = {0,1};
00095     //   toVtkInterlaces[SMDSEntity_Edge].assign( &ids[0], &ids[0]+2 );
00096     // }
00097     // {
00098     //   const int ids[] = {0,1,2};
00099     //   toVtkInterlaces[SMDSEntity_Quad_Edge].assign( &ids[0], &ids[0]+3 );
00100     // }
00101     // {
00102     //   const int ids[] = {0,1,2};
00103     //   toVtkInterlaces[SMDSEntity_Triangle].assign( &ids[0], &ids[0]+3 );
00104     // }
00105     // {
00106     //   const int ids[] = {0,1,2,3,4,5};
00107     //   toVtkInterlaces[SMDSEntity_Quad_Triangle].assign( &ids[0], &ids[0]+6 );
00108     // }
00109     // {
00110     //   const int ids[] = {0,1,2,3};
00111     //   toVtkInterlaces[SMDSEntity_Quadrangle].assign( &ids[0], &ids[0]+4 );
00112     // }
00113     // {
00114     //   const int ids[] = {0,1,2,3,4,5,6,7};
00115     //   toVtkInterlaces[SMDSEntity_Quad_Quadrangle].assign( &ids[0], &ids[0]+8 );
00116     // }
00117     // {
00118     //   const int ids[] = {0,1,2,3,4,5,6,7,8};
00119     //   toVtkInterlaces[SMDSEntity_BiQuad_Quadrangle].assign( &ids[0], &ids[0]+9 );
00120     // }
00121     {
00122       const int ids[] = {0,2,1,3};
00123       toVtkInterlaces[SMDSEntity_Tetra].assign( &ids[0], &ids[0]+4 );
00124     }
00125     {
00126       const int ids[] = {0,2,1,3,6,5,4,7,9,8};
00127       toVtkInterlaces[SMDSEntity_Quad_Tetra].assign( &ids[0], &ids[0]+10 );
00128     }
00129     {
00130       const int ids[] = {0,3,2,1,4};
00131       toVtkInterlaces[SMDSEntity_Pyramid].assign( &ids[0], &ids[0]+5 );
00132     }
00133     {
00134       const int ids[] = {0,3,2,1,4,8,7,6,5,9,12,11,10};
00135       toVtkInterlaces[SMDSEntity_Quad_Pyramid].assign( &ids[0], &ids[0]+13 );
00136     }
00137     {
00138       const int ids[] = {0,3,2,1,4,7,6,5};
00139       toVtkInterlaces[SMDSEntity_Hexa].assign( &ids[0], &ids[0]+8 );
00140     }
00141     {
00142       const int ids[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17};
00143       toVtkInterlaces[SMDSEntity_Quad_Hexa].assign( &ids[0], &ids[0]+20 );
00144     }
00145     {
00146       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};
00147       toVtkInterlaces[SMDSEntity_TriQuad_Hexa].assign( &ids[0], &ids[0]+27 );
00148     }
00149     {
00150       const int ids[] = {0,1,2,3,4,5};
00151       toVtkInterlaces[SMDSEntity_Penta].assign( &ids[0], &ids[0]+6 );
00152     }
00153     {
00154       const int ids[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14};
00155       toVtkInterlaces[SMDSEntity_Quad_Penta].assign( &ids[0], &ids[0]+15 );
00156     }
00157     {
00158       const int ids[] = {0,5,4,3,2,1,6,11,10,9,8,7};
00159       toVtkInterlaces[SMDSEntity_Hexagonal_Prism].assign( &ids[0], &ids[0]+12 );
00160     }
00161   }
00162   return toVtkInterlaces[smdsType];
00163 }
00164 
00165 //================================================================================
00170 //================================================================================
00171 
00172 const std::vector<int>& SMDS_MeshCell::reverseSmdsOrder(SMDSAbs_EntityType smdsType)
00173 {
00174   static std::vector< std::vector< int > > reverseInterlaces;
00175   if ( reverseInterlaces.empty() )
00176   {
00177     reverseInterlaces.resize( SMDSEntity_Last+1 );
00178     {
00179       const int ids[] = {0};
00180       reverseInterlaces[SMDSEntity_0D].assign( &ids[0], &ids[0]+1 );
00181       reverseInterlaces[SMDSEntity_Node].assign( &ids[0], &ids[0]+1 );
00182     }
00183     {
00184       const int ids[] = {1,0};
00185       reverseInterlaces[SMDSEntity_Edge].assign( &ids[0], &ids[0]+2 );
00186     }
00187     {
00188       const int ids[] = {1,0,2};
00189       reverseInterlaces[SMDSEntity_Quad_Edge].assign( &ids[0], &ids[0]+3 );
00190     }
00191     {
00192       const int ids[] = {0,2,1};
00193       reverseInterlaces[SMDSEntity_Triangle].assign( &ids[0], &ids[0]+3 );
00194     }
00195     {
00196       const int ids[] = {0,2,1,5,4,3};
00197       reverseInterlaces[SMDSEntity_Quad_Triangle].assign( &ids[0], &ids[0]+6 );
00198     }
00199     {
00200       const int ids[] = {0,3,2,1};
00201       reverseInterlaces[SMDSEntity_Quadrangle].assign( &ids[0], &ids[0]+4 );
00202     }
00203     {
00204       const int ids[] = {0,3,2,1,7,6,5,4};
00205       reverseInterlaces[SMDSEntity_Quad_Quadrangle].assign( &ids[0], &ids[0]+8 );
00206     }
00207     {
00208       const int ids[] = {0,3,2,1,7,6,5,4,8};
00209       reverseInterlaces[SMDSEntity_BiQuad_Quadrangle].assign( &ids[0], &ids[0]+9 );
00210     }
00211     {
00212       const int ids[] = {0,2,1,3};
00213       reverseInterlaces[SMDSEntity_Tetra].assign( &ids[0], &ids[0]+4 );
00214     }
00215     {
00216       const int ids[] = {0,2,1,3,6,5,4,7,9,8};
00217       reverseInterlaces[SMDSEntity_Quad_Tetra].assign( &ids[0], &ids[0]+10 );
00218     }
00219     {
00220       const int ids[] = {0,3,2,1,4};
00221       reverseInterlaces[SMDSEntity_Pyramid].assign( &ids[0], &ids[0]+5 );
00222     }
00223     {
00224       const int ids[] = {0,3,2,1,4,8,7,6,5,9,12,11,10};
00225       reverseInterlaces[SMDSEntity_Quad_Pyramid].assign( &ids[0], &ids[0]+13 );
00226     }
00227     {
00228       const int ids[] = {0,3,2,1,4,7,6,5};
00229       reverseInterlaces[SMDSEntity_Hexa].assign( &ids[0], &ids[0]+8 );
00230     }
00231     {
00232       const int ids[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17};
00233       reverseInterlaces[SMDSEntity_Quad_Hexa].assign( &ids[0], &ids[0]+20 );
00234     }
00235     {
00236       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};
00237       reverseInterlaces[SMDSEntity_TriQuad_Hexa].assign( &ids[0], &ids[0]+27 );
00238     }
00239     {
00240       const int ids[] = {0,2,1,3,5,4};
00241       reverseInterlaces[SMDSEntity_Penta].assign( &ids[0], &ids[0]+6 );
00242     }
00243     {
00244       const int ids[] = {0,2,1,3,5,4, 8,7,6,11,10,9,12,14,13};
00245       reverseInterlaces[SMDSEntity_Quad_Penta].assign( &ids[0], &ids[0]+15 );
00246     }
00247     {
00248       const int ids[] = {0,5,4,3,2,1,6,11,10,9,8,7};
00249       reverseInterlaces[SMDSEntity_Hexagonal_Prism].assign( &ids[0], &ids[0]+12 );
00250     }
00251   }
00252   return reverseInterlaces[smdsType];
00253 }
00254 
00255 //================================================================================
00260 //================================================================================
00261 
00262 const std::vector<int>& SMDS_MeshCell::interlacedSmdsOrder(SMDSAbs_EntityType smdsType)
00263 {
00264   static std::vector< std::vector< int > > interlace;
00265   if ( interlace.empty() )
00266   {
00267     interlace.resize( SMDSEntity_Last+1 );
00268     {
00269       const int ids[] = {0,2,1};
00270       interlace[SMDSEntity_Quad_Edge].assign( &ids[0], &ids[0]+3 );
00271     }
00272     {
00273       const int ids[] = {0,3,1,4,2,5};
00274       interlace[SMDSEntity_Quad_Triangle].assign( &ids[0], &ids[0]+6 );
00275     }
00276     {
00277       const int ids[] = {0,4,1,5,2,6,3,7,8};
00278       interlace[SMDSEntity_Quad_Quadrangle].assign( &ids[0], &ids[0]+8 );
00279       interlace[SMDSEntity_BiQuad_Quadrangle].assign( &ids[0], &ids[0]+9 );
00280     }
00281   }
00282   return interlace[smdsType];
00283 }
00284 
00285 //================================================================================
00289 //================================================================================
00290 
00291 SMDSAbs_EntityType SMDS_MeshCell::toSmdsType(VTKCellType vtkType)
00292 {
00293   static std::vector< SMDSAbs_EntityType > smdsTypes;
00294   if ( smdsTypes.empty() )
00295   {
00296     smdsTypes.resize( VTK_NUMBER_OF_CELL_TYPES, SMDSEntity_Last );
00297     for ( int iSMDS = 0; iSMDS < SMDSEntity_Last; ++iSMDS )
00298       smdsTypes[ toVtkType( SMDSAbs_EntityType( iSMDS ))] = SMDSAbs_EntityType( iSMDS );
00299   }
00300   return smdsTypes[ vtkType ];
00301 }
00302 
00303 //================================================================================
00308 //================================================================================
00309 
00310 const std::vector<int>& SMDS_MeshCell::fromVtkOrder(SMDSAbs_EntityType smdsType)
00311 {
00312   static std::vector< std::vector<int> > fromVtkInterlaces;
00313   if ( fromVtkInterlaces.empty() )
00314   {
00315     fromVtkInterlaces.resize( SMDSEntity_Last+1 );
00316     for ( int iSMDS = 0; iSMDS < SMDSEntity_Last; ++iSMDS )
00317     {
00318       const std::vector<int> & toVtk = toVtkOrder( SMDSAbs_EntityType( iSMDS ));
00319       std::vector<int> &      toSmds = fromVtkInterlaces[ iSMDS ];
00320       toSmds.resize( toVtk.size() );
00321       for ( size_t i = 0; i < toVtk.size(); ++i )
00322         toSmds[ toVtk[i] ] = i;
00323     }
00324   }
00325   return fromVtkInterlaces[ smdsType ];
00326 }
00327 
00328 //================================================================================
00333 //================================================================================
00334 
00335 const std::vector<int>& SMDS_MeshCell::toVtkOrder(VTKCellType vtkType)
00336 {
00337   return toVtkOrder( toSmdsType( vtkType ));
00338 }
00339 
00340 //================================================================================
00345 //================================================================================
00346 
00347 const std::vector<int>& SMDS_MeshCell::fromVtkOrder(VTKCellType vtkType)
00348 {
00349   return fromVtkOrder( toSmdsType( vtkType ));
00350 }