Back to index

salome-smesh  6.5.0
SMDS_VtkCellIterator.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_VtkCellIterator.hxx"
00021 #include "utilities.h"
00022 
00023 SMDS_VtkCellIterator::SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType) :
00024   _mesh(mesh), _cellId(vtkCellId), _index(0), _type(aType)
00025 {
00026   vtkUnstructuredGrid* grid = _mesh->getGrid();
00027   _vtkIdList = vtkIdList::New();
00028   const std::vector<int>& interlace = SMDS_MeshCell::fromVtkOrder( aType );
00029   if ( interlace.empty() )
00030   {
00031     grid->GetCellPoints(_cellId, _vtkIdList);
00032     _nbNodes = _vtkIdList->GetNumberOfIds();
00033   }
00034   else
00035   {
00036     vtkIdType npts, *pts;
00037     grid->GetCellPoints( _cellId, npts, pts );
00038     _vtkIdList->SetNumberOfIds( _nbNodes = npts );
00039     for (int i = 0; i < _nbNodes; i++)
00040       _vtkIdList->SetId(i, pts[interlace[i]]);
00041   }
00042 }
00043 
00044 SMDS_VtkCellIterator::~SMDS_VtkCellIterator()
00045 {
00046   _vtkIdList->Delete();
00047 }
00048 
00049 bool SMDS_VtkCellIterator::more()
00050 {
00051   return (_index < _nbNodes);
00052 }
00053 
00054 const SMDS_MeshElement* SMDS_VtkCellIterator::next()
00055 {
00056   vtkIdType id = _vtkIdList->GetId(_index++);
00057   return _mesh->FindNodeVtk(id);
00058 }
00059 
00060 SMDS_VtkCellIteratorToUNV::SMDS_VtkCellIteratorToUNV(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType) :
00061   SMDS_VtkCellIterator()
00062 {
00063   _mesh = mesh;
00064   _cellId = vtkCellId;
00065   _index = 0;
00066   _type = aType;
00067   //MESSAGE("SMDS_VtkCellInterlacedIterator (UNV)" << _type);
00068 
00069   _vtkIdList = vtkIdList::New();
00070   vtkIdType* pts;
00071   vtkUnstructuredGrid* grid = _mesh->getGrid();
00072   grid->GetCellPoints((vtkIdType)_cellId, (vtkIdType&)_nbNodes, pts);
00073   _vtkIdList->SetNumberOfIds(_nbNodes);
00074   int *ids = 0;
00075   switch (_type)
00076   {
00077     case SMDSEntity_Quad_Edge:
00078       {
00079         static int id[] = { 0, 2, 1 };
00080         ids = id;
00081         break;
00082       }
00083     case SMDSEntity_Quad_Triangle:
00084       {
00085         static int id[] = { 0, 3, 1, 4, 2, 5 };
00086         ids = id;
00087         break;
00088       }
00089     case SMDSEntity_Quad_Quadrangle:
00090     case SMDSEntity_BiQuad_Quadrangle:
00091       {
00092         static int id[] = { 0, 4, 1, 5, 2, 6, 3, 7 };
00093         ids = id;
00094         _nbNodes = 8;
00095         break;
00096       }
00097     case SMDSEntity_Quad_Tetra:
00098       {
00099         static int id[] = { 0, 4, 1, 5, 2, 6, 7, 8, 9, 3 };
00100         ids = id;
00101         break;
00102       }
00103     case SMDSEntity_Quad_Pyramid:
00104       {
00105         static int id[] = { 0, 5, 1, 6, 2, 7, 3, 8, 9, 10, 11, 12, 4 };
00106         ids = id;
00107         break;
00108       }
00109     case SMDSEntity_Penta:
00110       {
00111         static int id[] = { 0, 2, 1, 3, 5, 4 };
00112         ids = id;
00113         break;
00114       }
00115     case SMDSEntity_Quad_Penta:
00116       {
00117         static int id[] = { 0, 8, 2, 7, 1, 6, 12, 14, 13, 3, 11, 5, 10, 4, 9 };
00118         ids = id;
00119         break;
00120       }
00121     case SMDSEntity_Quad_Hexa:
00122     case SMDSEntity_TriQuad_Hexa:
00123       {
00124         static int id[] = { 0, 8, 1, 9, 2, 10, 3, 11, 16, 17, 18, 19, 4, 12, 5, 13, 6, 14, 7, 15 };
00125         ids = id;
00126         _nbNodes = 20;
00127         break;
00128       }
00129     case SMDSEntity_Polygon:
00130     case SMDSEntity_Quad_Polygon:
00131     case SMDSEntity_Polyhedra:
00132     case SMDSEntity_Quad_Polyhedra:
00133     default:
00134       {
00135         // static int id[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
00136         //                     25, 26, 27, 28, 29 };
00137         // ids = id;
00138         // break;
00139       }
00140   }
00141   if ( ids )
00142     for (int i = 0; i < _nbNodes; i++)
00143       _vtkIdList->SetId(i, pts[ids[i]]);
00144   else
00145     for (int i = 0; i < _nbNodes; i++)
00146       _vtkIdList->SetId(i, pts[i]);
00147 }
00148 
00149 SMDS_VtkCellIteratorToUNV::~SMDS_VtkCellIteratorToUNV()
00150 {
00151 }
00152 
00153 SMDS_VtkCellIteratorPolyH::SMDS_VtkCellIteratorPolyH(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType) :
00154   SMDS_VtkCellIterator()
00155 {
00156   _mesh = mesh;
00157   _cellId = vtkCellId;
00158   _index = 0;
00159   _type = aType;
00160   //MESSAGE("SMDS_VtkCellIteratorPolyH " << _type);
00161   _vtkIdList = vtkIdList::New();
00162   vtkUnstructuredGrid* grid = _mesh->getGrid();
00163   grid->GetCellPoints(_cellId, _vtkIdList);
00164   _nbNodes = _vtkIdList->GetNumberOfIds();
00165   switch (_type)
00166   {
00167     case SMDSEntity_Polyhedra:
00168       {
00169         //MESSAGE("SMDS_VtkCellIterator Polyhedra");
00170         vtkIdType nFaces = 0;
00171         vtkIdType* ptIds = 0;
00172         grid->GetFaceStream(_cellId, nFaces, ptIds);
00173         int id = 0;
00174         _nbNodesInFaces = 0;
00175         for (int i = 0; i < nFaces; i++)
00176           {
00177             int nodesInFace = ptIds[id]; // nodeIds in ptIds[id+1 .. id+nodesInFace]
00178             _nbNodesInFaces += nodesInFace;
00179             id += (nodesInFace + 1);
00180           }
00181         _vtkIdList->SetNumberOfIds(_nbNodesInFaces);
00182         id = 0;
00183         int n = 0;
00184         for (int i = 0; i < nFaces; i++)
00185           {
00186             int nodesInFace = ptIds[id]; // nodeIds in ptIds[id+1 .. id+nodesInFace]
00187             for (int k = 1; k <= nodesInFace; k++)
00188               _vtkIdList->SetId(n++, ptIds[id + k]);
00189             id += (nodesInFace + 1);
00190           }
00191         break;
00192       }
00193     default:
00194       assert(0);
00195   }
00196 }
00197 
00198 SMDS_VtkCellIteratorPolyH::~SMDS_VtkCellIteratorPolyH()
00199 {
00200 }
00201 
00202 bool SMDS_VtkCellIteratorPolyH::more()
00203 {
00204   return (_index < _nbNodesInFaces);
00205 }