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_VtkCellIterator.hxx"
21 #include "utilities.h"
23 SMDS_VtkCellIterator::SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType) :
24 _mesh(mesh), _cellId(vtkCellId), _index(0), _type(aType)
26 vtkUnstructuredGrid* grid = _mesh->getGrid();
27 _vtkIdList = vtkIdList::New();
28 const std::vector<int>& interlace = SMDS_MeshCell::fromVtkOrder( aType );
29 if ( interlace.empty() )
31 grid->GetCellPoints(_cellId, _vtkIdList);
32 _nbNodes = _vtkIdList->GetNumberOfIds();
37 grid->GetCellPoints( _cellId, npts, pts );
38 _vtkIdList->SetNumberOfIds( _nbNodes = npts );
39 for (int i = 0; i < _nbNodes; i++)
40 _vtkIdList->SetId(i, pts[interlace[i]]);
44 SMDS_VtkCellIterator::~SMDS_VtkCellIterator()
49 bool SMDS_VtkCellIterator::more()
51 return (_index < _nbNodes);
54 const SMDS_MeshElement* SMDS_VtkCellIterator::next()
56 vtkIdType id = _vtkIdList->GetId(_index++);
57 return _mesh->FindNodeVtk(id);
60 SMDS_VtkCellIteratorToUNV::SMDS_VtkCellIteratorToUNV(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType) :
61 SMDS_VtkCellIterator()
67 //MESSAGE("SMDS_VtkCellInterlacedIterator (UNV)" << _type);
69 _vtkIdList = vtkIdList::New();
71 vtkUnstructuredGrid* grid = _mesh->getGrid();
72 grid->GetCellPoints((vtkIdType)_cellId, (vtkIdType&)_nbNodes, pts);
73 _vtkIdList->SetNumberOfIds(_nbNodes);
77 case SMDSEntity_Quad_Edge:
79 static int id[] = { 0, 2, 1 };
83 case SMDSEntity_Quad_Triangle:
85 static int id[] = { 0, 3, 1, 4, 2, 5 };
89 case SMDSEntity_Quad_Quadrangle:
90 case SMDSEntity_BiQuad_Quadrangle:
92 static int id[] = { 0, 4, 1, 5, 2, 6, 3, 7 };
97 case SMDSEntity_Quad_Tetra:
99 static int id[] = { 0, 4, 1, 5, 2, 6, 7, 8, 9, 3 };
103 case SMDSEntity_Quad_Pyramid:
105 static int id[] = { 0, 5, 1, 6, 2, 7, 3, 8, 9, 10, 11, 12, 4 };
109 case SMDSEntity_Penta:
111 static int id[] = { 0, 2, 1, 3, 5, 4 };
115 case SMDSEntity_Quad_Penta:
117 static int id[] = { 0, 8, 2, 7, 1, 6, 12, 14, 13, 3, 11, 5, 10, 4, 9 };
121 case SMDSEntity_Quad_Hexa:
122 case SMDSEntity_TriQuad_Hexa:
124 static int id[] = { 0, 8, 1, 9, 2, 10, 3, 11, 16, 17, 18, 19, 4, 12, 5, 13, 6, 14, 7, 15 };
129 case SMDSEntity_Polygon:
130 case SMDSEntity_Quad_Polygon:
131 case SMDSEntity_Polyhedra:
132 case SMDSEntity_Quad_Polyhedra:
135 // 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,
136 // 25, 26, 27, 28, 29 };
142 for (int i = 0; i < _nbNodes; i++)
143 _vtkIdList->SetId(i, pts[ids[i]]);
145 for (int i = 0; i < _nbNodes; i++)
146 _vtkIdList->SetId(i, pts[i]);
149 SMDS_VtkCellIteratorToUNV::~SMDS_VtkCellIteratorToUNV()
153 SMDS_VtkCellIteratorPolyH::SMDS_VtkCellIteratorPolyH(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType) :
154 SMDS_VtkCellIterator()
160 //MESSAGE("SMDS_VtkCellIteratorPolyH " << _type);
161 _vtkIdList = vtkIdList::New();
162 vtkUnstructuredGrid* grid = _mesh->getGrid();
163 grid->GetCellPoints(_cellId, _vtkIdList);
164 _nbNodes = _vtkIdList->GetNumberOfIds();
167 case SMDSEntity_Polyhedra:
169 //MESSAGE("SMDS_VtkCellIterator Polyhedra");
170 vtkIdType nFaces = 0;
171 vtkIdType* ptIds = 0;
172 grid->GetFaceStream(_cellId, nFaces, ptIds);
175 for (int i = 0; i < nFaces; i++)
177 int nodesInFace = ptIds[id]; // nodeIds in ptIds[id+1 .. id+nodesInFace]
178 _nbNodesInFaces += nodesInFace;
179 id += (nodesInFace + 1);
181 _vtkIdList->SetNumberOfIds(_nbNodesInFaces);
184 for (int i = 0; i < nFaces; i++)
186 int nodesInFace = ptIds[id]; // nodeIds in ptIds[id+1 .. id+nodesInFace]
187 for (int k = 1; k <= nodesInFace; k++)
188 _vtkIdList->SetId(n++, ptIds[id + k]);
189 id += (nodesInFace + 1);
198 SMDS_VtkCellIteratorPolyH::~SMDS_VtkCellIteratorPolyH()
202 bool SMDS_VtkCellIteratorPolyH::more()
204 return (_index < _nbNodesInFaces);