00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00027 _vtkIdList = vtkIdList::New();
00028 vtkUnstructuredGrid* grid = _mesh->getGrid();
00029 grid->GetCellPoints(_cellId, _vtkIdList);
00030 _nbNodes = _vtkIdList->GetNumberOfIds();
00031 switch (_type)
00032 {
00033 case SMDSEntity_Tetra:
00034 {
00035 this->exchange(1, 2);
00036 break;
00037 }
00038 case SMDSEntity_Pyramid:
00039 {
00040 this->exchange(1, 3);
00041 break;
00042 }
00043 case SMDSEntity_Penta:
00044 {
00045
00046
00047 break;
00048 }
00049 case SMDSEntity_Hexa:
00050 {
00051 this->exchange(1, 3);
00052 this->exchange(5, 7);
00053 break;
00054 }
00055 case SMDSEntity_Quad_Tetra:
00056 {
00057 this->exchange(1, 2);
00058 this->exchange(4, 6);
00059 this->exchange(8, 9);
00060 break;
00061 }
00062 case SMDSEntity_Quad_Pyramid:
00063 {
00064 this->exchange(1, 3);
00065 this->exchange(5, 8);
00066 this->exchange(6, 7);
00067 this->exchange(10, 12);
00068 break;
00069 }
00070 case SMDSEntity_Quad_Penta:
00071 {
00072
00073
00074
00075
00076
00077 break;
00078 }
00079 case SMDSEntity_Quad_Hexa:
00080 {
00081 MESSAGE("SMDS_VtkCellIterator Quad_Hexa");
00082 this->exchange(1, 3);
00083 this->exchange(5, 7);
00084 this->exchange(8, 11);
00085 this->exchange(9, 10);
00086 this->exchange(12, 15);
00087 this->exchange(13, 14);
00088 this->exchange(17, 19);
00089 break;
00090 }
00091 case SMDSEntity_Polyhedra:
00092 MESSAGE("SMDS_VtkCellIterator Polyhedra (iterate on actual nodes)");
00093 break;
00094 default:
00095 break;
00096 }
00097 }
00098
00099 SMDS_VtkCellIterator::~SMDS_VtkCellIterator()
00100 {
00101 _vtkIdList->Delete();
00102 }
00103
00104 bool SMDS_VtkCellIterator::more()
00105 {
00106 return (_index < _nbNodes);
00107 }
00108
00109 const SMDS_MeshElement* SMDS_VtkCellIterator::next()
00110 {
00111 vtkIdType id = _vtkIdList->GetId(_index++);
00112 return _mesh->FindNodeVtk(id);
00113 }
00114
00115 SMDS_VtkCellIteratorToUNV::SMDS_VtkCellIteratorToUNV(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType) :
00116 SMDS_VtkCellIterator()
00117 {
00118 _mesh = mesh;
00119 _cellId = vtkCellId;
00120 _index = 0;
00121 _type = aType;
00122
00123
00124 _vtkIdList = vtkIdList::New();
00125 vtkIdType* pts;
00126 vtkUnstructuredGrid* grid = _mesh->getGrid();
00127 grid->GetCellPoints((vtkIdType)_cellId, (vtkIdType&)_nbNodes, pts);
00128 _vtkIdList->SetNumberOfIds(_nbNodes);
00129 int *ids = 0;
00130 switch (_type)
00131 {
00132 case SMDSEntity_Quad_Edge:
00133 {
00134 static int id[] = { 0, 2, 1 };
00135 ids = id;
00136 break;
00137 }
00138 case SMDSEntity_Quad_Triangle:
00139 {
00140 static int id[] = { 0, 3, 1, 4, 2, 5 };
00141 ids = id;
00142 break;
00143 }
00144 case SMDSEntity_Quad_Quadrangle:
00145 {
00146 static int id[] = { 0, 4, 1, 5, 2, 6, 3, 7 };
00147 ids = id;
00148 break;
00149 }
00150 case SMDSEntity_Quad_Tetra:
00151 {
00152 static int id[] = { 0, 4, 1, 5, 2, 6, 7, 8, 9, 3 };
00153 ids = id;
00154 break;
00155 }
00156 case SMDSEntity_Quad_Pyramid:
00157 {
00158 static int id[] = { 0, 5, 1, 6, 2, 7, 3, 8, 9, 10, 11, 12, 4 };
00159 ids = id;
00160 break;
00161 }
00162 case SMDSEntity_Penta:
00163 {
00164 static int id[] = { 0, 2, 1, 3, 5, 4 };
00165 ids = id;
00166 break;
00167 }
00168 case SMDSEntity_Quad_Penta:
00169 {
00170 static int id[] = { 0, 8, 2, 7, 1, 6, 12, 14, 13, 3, 11, 5, 10, 4, 9 };
00171 ids = id;
00172 break;
00173 }
00174 case SMDSEntity_Quad_Hexa:
00175 {
00176 static int id[] = { 0, 8, 1, 9, 2, 10, 3, 11, 16, 17, 18, 19, 4, 12, 5, 13, 6, 14, 7, 15 };
00177 ids = id;
00178 break;
00179 }
00180 case SMDSEntity_Polygon:
00181 case SMDSEntity_Quad_Polygon:
00182 case SMDSEntity_Polyhedra:
00183 case SMDSEntity_Quad_Polyhedra:
00184 default:
00185 {
00186 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,
00187 25, 26, 27, 28, 29 };
00188 ids = id;
00189 break;
00190 }
00191 }
00192
00193 for (int i = 0; i < _nbNodes; i++)
00194 _vtkIdList->SetId(i, pts[ids[i]]);
00195 }
00196
00197 SMDS_VtkCellIteratorToUNV::~SMDS_VtkCellIteratorToUNV()
00198 {
00199 }
00200
00201 SMDS_VtkCellIteratorPolyH::SMDS_VtkCellIteratorPolyH(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType) :
00202 SMDS_VtkCellIterator()
00203 {
00204 _mesh = mesh;
00205 _cellId = vtkCellId;
00206 _index = 0;
00207 _type = aType;
00208
00209 _vtkIdList = vtkIdList::New();
00210 vtkUnstructuredGrid* grid = _mesh->getGrid();
00211 grid->GetCellPoints(_cellId, _vtkIdList);
00212 _nbNodes = _vtkIdList->GetNumberOfIds();
00213 switch (_type)
00214 {
00215 case SMDSEntity_Polyhedra:
00216 {
00217
00218 vtkIdType nFaces = 0;
00219 vtkIdType* ptIds = 0;
00220 grid->GetFaceStream(_cellId, nFaces, ptIds);
00221 int id = 0;
00222 _nbNodesInFaces = 0;
00223 for (int i = 0; i < nFaces; i++)
00224 {
00225 int nodesInFace = ptIds[id];
00226 _nbNodesInFaces += nodesInFace;
00227 id += (nodesInFace + 1);
00228 }
00229 _vtkIdList->SetNumberOfIds(_nbNodesInFaces);
00230 id = 0;
00231 int n = 0;
00232 for (int i = 0; i < nFaces; i++)
00233 {
00234 int nodesInFace = ptIds[id];
00235 for (int k = 1; k <= nodesInFace; k++)
00236 _vtkIdList->SetId(n++, ptIds[id + k]);
00237 id += (nodesInFace + 1);
00238 }
00239 break;
00240 }
00241 default:
00242 assert(0);
00243 }
00244 }
00245
00246 SMDS_VtkCellIteratorPolyH::~SMDS_VtkCellIteratorPolyH()
00247 {
00248 }
00249
00250 bool SMDS_VtkCellIteratorPolyH::more()
00251 {
00252 return (_index < _nbNodesInFaces);
00253 }