Salome HOME
Replace oe by ?
[modules/smesh.git] / src / SMDS / SMDS_VtkCellIterator.cxx
1 #include "SMDS_VtkCellIterator.hxx"
2 #include "utilities.h"
3
4 SMDS_VtkCellIterator::SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType) :
5   _mesh(mesh), _cellId(vtkCellId), _index(0), _type(aType)
6 {
7   //MESSAGE("SMDS_VtkCellIterator " << _type);
8   _vtkIdList = vtkIdList::New();
9   vtkUnstructuredGrid* grid = _mesh->getGrid();
10   grid->GetCellPoints(_cellId, _vtkIdList);
11   _nbNodes = _vtkIdList->GetNumberOfIds();
12   switch (_type)
13   {
14     case SMDSEntity_Tetra:
15       {
16         this->exchange(1, 2);
17         break;
18       }
19     case SMDSEntity_Pyramid:
20       {
21         this->exchange(1, 3);
22         break;
23       }
24     case SMDSEntity_Penta:
25       {
26         //this->exchange(1, 2);
27         //this->exchange(4, 5);
28         break;
29       }
30     case SMDSEntity_Hexa:
31       {
32         this->exchange(1, 3);
33         this->exchange(5, 7);
34         break;
35       }
36     case SMDSEntity_Quad_Tetra:
37       {
38         this->exchange(1, 2);
39         this->exchange(4, 6);
40         this->exchange(8, 9);
41         break;
42       }
43     case SMDSEntity_Quad_Pyramid:
44       {
45         this->exchange(1, 3);
46         this->exchange(5, 8);
47         this->exchange(6, 7);
48         this->exchange(10, 12);
49         break;
50       }
51     case SMDSEntity_Quad_Penta:
52       {
53         //this->exchange(1, 2);
54         //this->exchange(4, 5);
55         //this->exchange(6, 8);
56         //this->exchange(9, 11);
57         //this->exchange(13, 14);
58         break;
59       }
60     case SMDSEntity_Quad_Hexa:
61       {
62         MESSAGE("SMDS_VtkCellIterator Quad_Hexa");
63         this->exchange(1, 3);
64         this->exchange(5, 7);
65         this->exchange(8, 11);
66         this->exchange(9, 10);
67         this->exchange(12, 15);
68         this->exchange(13, 14);
69         this->exchange(17, 19);
70         break;
71       }
72     case SMDSEntity_Polyhedra:
73       MESSAGE("SMDS_VtkCellIterator Polyhedra (iterate on actual nodes)");
74       break;
75     default:
76       break;
77   }
78 }
79
80 SMDS_VtkCellIterator::~SMDS_VtkCellIterator()
81 {
82   _vtkIdList->Delete();
83 }
84
85 bool SMDS_VtkCellIterator::more()
86 {
87   return (_index < _nbNodes);
88 }
89
90 const SMDS_MeshElement* SMDS_VtkCellIterator::next()
91 {
92   vtkIdType id = _vtkIdList->GetId(_index++);
93   return _mesh->FindNodeVtk(id);
94 }
95
96 SMDS_VtkCellIteratorToUNV::SMDS_VtkCellIteratorToUNV(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType) :
97   SMDS_VtkCellIterator()
98 {
99   _mesh = mesh;
100   _cellId = vtkCellId;
101   _index = 0;
102   _type = aType;
103   //MESSAGE("SMDS_VtkCellInterlacedIterator (UNV)" << _type);
104
105   _vtkIdList = vtkIdList::New();
106   vtkIdType* pts;
107   vtkUnstructuredGrid* grid = _mesh->getGrid();
108   grid->GetCellPoints((vtkIdType)_cellId, (vtkIdType&)_nbNodes, pts);
109   _vtkIdList->SetNumberOfIds(_nbNodes);
110   int *ids = 0;
111   switch (_type)
112   {
113     case SMDSEntity_Quad_Edge:
114       {
115         static int id[] = { 0, 2, 1 };
116         ids = id;
117         break;
118       }
119     case SMDSEntity_Quad_Triangle:
120       {
121         static int id[] = { 0, 3, 1, 4, 2, 5 };
122         ids = id;
123         break;
124       }
125     case SMDSEntity_Quad_Quadrangle:
126       {
127         static int id[] = { 0, 4, 1, 5, 2, 6, 3, 7 };
128         ids = id;
129         break;
130       }
131     case SMDSEntity_Quad_Tetra:
132       {
133         static int id[] = { 0, 4, 1, 5, 2, 6, 7, 8, 9, 3 };
134         ids = id;
135         break;
136       }
137     case SMDSEntity_Quad_Pyramid:
138       {
139         static int id[] = { 0, 5, 1, 6, 2, 7, 3, 8, 9, 10, 11, 12, 4 };
140         ids = id;
141         break;
142       }
143     case SMDSEntity_Penta:
144       {
145         static int id[] = { 0, 2, 1, 3, 5, 4 };
146         ids = id;
147         break;
148       }
149     case SMDSEntity_Quad_Penta:
150       {
151         static int id[] = { 0, 8, 2, 7, 1, 6, 12, 14, 13, 3, 11, 5, 10, 4, 9 };
152         ids = id;
153         break;
154       }
155     case SMDSEntity_Quad_Hexa:
156       {
157         static int id[] = { 0, 8, 1, 9, 2, 10, 3, 11, 16, 17, 18, 19, 4, 12, 5, 13, 6, 14, 7, 15 };
158         ids = id;
159         break;
160       }
161     case SMDSEntity_Polygon:
162     case SMDSEntity_Quad_Polygon:
163     case SMDSEntity_Polyhedra:
164     case SMDSEntity_Quad_Polyhedra:
165     default:
166       {
167         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,
168                             25, 26, 27, 28, 29 };
169         ids = id;
170         break;
171       }
172   }
173   //MESSAGE("_nbNodes " << _nbNodes);
174   for (int i = 0; i < _nbNodes; i++)
175     _vtkIdList->SetId(i, pts[ids[i]]);
176 }
177
178 SMDS_VtkCellIteratorToUNV::~SMDS_VtkCellIteratorToUNV()
179 {
180 }
181
182 SMDS_VtkCellIteratorPolyH::SMDS_VtkCellIteratorPolyH(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType) :
183   SMDS_VtkCellIterator()
184 {
185   _mesh = mesh;
186   _cellId = vtkCellId;
187   _index = 0;
188   _type = aType;
189   //MESSAGE("SMDS_VtkCellIteratorPolyH " << _type);
190   _vtkIdList = vtkIdList::New();
191   vtkUnstructuredGrid* grid = _mesh->getGrid();
192   grid->GetCellPoints(_cellId, _vtkIdList);
193   _nbNodes = _vtkIdList->GetNumberOfIds();
194   switch (_type)
195   {
196     case SMDSEntity_Polyhedra:
197       {
198         //MESSAGE("SMDS_VtkCellIterator Polyhedra");
199         vtkIdType nFaces = 0;
200         vtkIdType* ptIds = 0;
201         grid->GetFaceStream(_cellId, nFaces, ptIds);
202         int id = 0;
203         _nbNodesInFaces = 0;
204         for (int i = 0; i < nFaces; i++)
205           {
206             int nodesInFace = ptIds[id]; // nodeIds in ptIds[id+1 .. id+nodesInFace]
207             _nbNodesInFaces += nodesInFace;
208             id += (nodesInFace + 1);
209           }
210         _vtkIdList->SetNumberOfIds(_nbNodesInFaces);
211         id = 0;
212         int n = 0;
213         for (int i = 0; i < nFaces; i++)
214           {
215             int nodesInFace = ptIds[id]; // nodeIds in ptIds[id+1 .. id+nodesInFace]
216             for (int k = 1; k <= nodesInFace; k++)
217               _vtkIdList->SetId(n++, ptIds[id + k]);
218             id += (nodesInFace + 1);
219           }
220         break;
221       }
222     default:
223       assert(0);
224   }
225 }
226
227 SMDS_VtkCellIteratorPolyH::~SMDS_VtkCellIteratorPolyH()
228 {
229 }
230
231 bool SMDS_VtkCellIteratorPolyH::more()
232 {
233   return (_index < _nbNodesInFaces);
234 }