VTK
vtkCellIterator.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkCellIterator.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
15
68#ifndef vtkCellIterator_h
69#define vtkCellIterator_h
70
71#include "vtkCommonDataModelModule.h" // For export macro
72#include "vtkCellType.h" // For VTK_EMPTY_CELL
73#include "vtkObject.h"
74#include "vtkNew.h" // For vtkNew
75#include "vtkIdList.h" // For inline methods
76
77class vtkGenericCell;
78class vtkPoints;
79
80class VTKCOMMONDATAMODEL_EXPORT vtkCellIterator : public vtkObject
81{
82public:
83 void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
85
86
89 void InitTraversal();
90
94 void GoToNextCell();
95
99 virtual bool IsDoneWithTraversal() = 0;
100
105 int GetCellType();
106
112
116 virtual vtkIdType GetCellId() = 0;
117
122 vtkIdList *GetPointIds();
123
129 vtkPoints *GetPoints();
130
135 vtkIdList *GetFaces();
136
143
148 vtkIdType GetNumberOfPoints();
149
154 vtkIdType GetNumberOfFaces();
155
156protected:
158 ~vtkCellIterator() VTK_OVERRIDE;
159
163 virtual void ResetToFirstCell() = 0;
164
168 virtual void IncrementToNextCell() = 0;
169
173 virtual void FetchCellType() = 0;
174
178 virtual void FetchPointIds() = 0;
179
183 virtual void FetchPoints() = 0;
184
191 virtual void FetchFaces() { }
192
197
198private:
199 vtkCellIterator(const vtkCellIterator &) VTK_DELETE_FUNCTION;
200 void operator=(const vtkCellIterator &) VTK_DELETE_FUNCTION;
201
202 enum
203 {
204 UninitializedFlag = 0x0,
205 CellTypeFlag = 0x1,
206 PointIdsFlag = 0x2,
207 PointsFlag = 0x4,
208 FacesFlag = 0x8
209 };
210
211 void ResetCache()
212 {
213 this->CacheFlags = UninitializedFlag;
214 this->CellType = VTK_EMPTY_CELL;
215 }
216
217 void SetCache(unsigned char flags)
218 {
219 this->CacheFlags |= flags;
220 }
221
222 bool CheckCache(unsigned char flags)
223 {
224 return (this->CacheFlags & flags) == flags;
225 }
226
227 vtkNew<vtkPoints> PointsContainer;
228 vtkNew<vtkIdList> PointIdsContainer;
229 vtkNew<vtkIdList> FacesContainer;
230 unsigned char CacheFlags;
231};
232
233//------------------------------------------------------------------------------
234inline void vtkCellIterator::InitTraversal()
235{
236 this->ResetToFirstCell();
237 this->ResetCache();
238}
239
240//------------------------------------------------------------------------------
242{
243 this->IncrementToNextCell();
244 this->ResetCache();
245}
246
247//------------------------------------------------------------------------------
249{
250 if (!this->CheckCache(CellTypeFlag))
251 {
252 this->FetchCellType();
253 this->SetCache(CellTypeFlag);
254 }
255 return this->CellType;
256}
257
258//------------------------------------------------------------------------------
260{
261 if (!this->CheckCache(PointIdsFlag))
262 {
263 this->FetchPointIds();
264 this->SetCache(PointIdsFlag);
265 }
266 return this->PointIds;
267}
268
269//------------------------------------------------------------------------------
271{
272 if (!this->CheckCache(PointsFlag))
273 {
274 this->FetchPoints();
275 this->SetCache(PointsFlag);
276 }
277 return this->Points;
278}
279
280//------------------------------------------------------------------------------
282{
283 if (!this->CheckCache(FacesFlag))
284 {
285 this->FetchFaces();
286 this->SetCache(FacesFlag);
287 }
288 return this->Faces;
289}
290
291//------------------------------------------------------------------------------
293{
294 if (!this->CheckCache(PointIdsFlag))
295 {
296 this->FetchPointIds();
297 this->SetCache(PointIdsFlag);
298 }
299 return this->PointIds->GetNumberOfIds();
300}
301
302//------------------------------------------------------------------------------
304{
305 switch (this->GetCellType())
306 {
307 case VTK_EMPTY_CELL:
308 case VTK_VERTEX:
309 case VTK_POLY_VERTEX:
310 case VTK_LINE:
311 case VTK_POLY_LINE:
312 case VTK_TRIANGLE:
314 case VTK_POLYGON:
315 case VTK_PIXEL:
316 case VTK_QUAD:
324 case VTK_CUBIC_LINE:
334 return 0;
335
336 case VTK_TETRA:
340 return 4;
341
342 case VTK_PYRAMID:
345 case VTK_WEDGE:
350 return 5;
351
352 case VTK_VOXEL:
353 case VTK_HEXAHEDRON:
359 return 6;
360
362 return 7;
363
365 return 8;
366
367 case VTK_POLYHEDRON: // Need to look these up
368 if (!this->CheckCache(FacesFlag))
369 {
370 this->FetchFaces();
371 this->SetCache(FacesFlag);
372 }
373 return this->Faces->GetNumberOfIds() != 0 ? this->Faces->GetId(0) : 0;
374
375 default:
376 vtkGenericWarningMacro("Unknown cell type: " << this->CellType);
377 break;
378 }
379
380 return 0;
381}
382
383#endif //vtkCellIterator_h
Efficient cell iterator for vtkDataSet topologies.
int GetCellDimension()
Get the current cell dimension (0, 1, 2, or 3).
virtual void FetchPoints()=0
Lookup the cell points in the data set and store them in this->Points.
void GetCell(vtkGenericCell *cell)
Write the current full cell information into the argument.
virtual void FetchPointIds()=0
Lookup the cell point ids in the data set and store them in this->PointIds.
vtkIdType GetNumberOfFaces()
Return the number of faces in the current cell.
vtkIdList * GetFaces()
Get the faces for a polyhedral cell.
vtkIdList * Faces
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkPoints * GetPoints()
Get the points in the current cell.
vtkAbstractTypeMacro(vtkCellIterator, vtkObject) void InitTraversal()
Reset to the first cell.
vtkIdList * PointIds
virtual void FetchCellType()=0
Lookup the cell type in the data set and store it in this->CellType.
vtkIdType GetNumberOfPoints()
Return the number of points in the current cell.
virtual void IncrementToNextCell()=0
Update internal state to point to the next cell.
virtual vtkIdType GetCellId()=0
Get the id of the current cell.
virtual void ResetToFirstCell()=0
Update internal state to point to the first cell.
vtkIdList * GetPointIds()
Get the ids of the points in the current cell.
int GetCellType()
Get the current cell type (e.g.
virtual void FetchFaces()
Lookup the cell faces in the data set and store them in this->Points.
void GoToNextCell()
Increment to next cell.
virtual bool IsDoneWithTraversal()=0
Returns false while the iterator is valid.
vtkPoints * Points
~vtkCellIterator() override
provides thread-safe access to cells
list of point or cell ids
Definition: vtkIdList.h:37
vtkIdType GetNumberOfIds()
Return the number of id's in the list.
Definition: vtkIdList.h:56
vtkIdType GetId(const vtkIdType i)
Return the id at location i.
Definition: vtkIdList.h:61
a simple class to control print indentation
Definition: vtkIndent.h:40
abstract base class for most VTK objects
Definition: vtkObject.h:60
represent and manipulate 3D points
Definition: vtkPoints.h:40
@ VTK_VOXEL
Definition: vtkCellType.h:56
@ VTK_QUADRATIC_HEXAHEDRON
Definition: vtkCellType.h:69
@ VTK_PARAMETRIC_SURFACE
Definition: vtkCellType.h:91
@ VTK_HIGHER_ORDER_TETRAHEDRON
Definition: vtkCellType.h:102
@ VTK_TRIANGLE_STRIP
Definition: vtkCellType.h:51
@ VTK_BIQUADRATIC_QUADRATIC_HEXAHEDRON
Definition: vtkCellType.h:77
@ VTK_HIGHER_ORDER_QUAD
Definition: vtkCellType.h:100
@ VTK_PYRAMID
Definition: vtkCellType.h:59
@ VTK_PIXEL
Definition: vtkCellType.h:53
@ VTK_QUADRATIC_WEDGE
Definition: vtkCellType.h:70
@ VTK_BIQUADRATIC_QUAD
Definition: vtkCellType.h:72
@ VTK_HIGHER_ORDER_WEDGE
Definition: vtkCellType.h:103
@ VTK_POLY_LINE
Definition: vtkCellType.h:49
@ VTK_TRIANGLE
Definition: vtkCellType.h:50
@ VTK_POLYGON
Definition: vtkCellType.h:52
@ VTK_EMPTY_CELL
Definition: vtkCellType.h:45
@ VTK_QUADRATIC_PYRAMID
Definition: vtkCellType.h:71
@ VTK_POLYHEDRON
Definition: vtkCellType.h:87
@ VTK_TRIQUADRATIC_HEXAHEDRON
Definition: vtkCellType.h:73
@ VTK_TETRA
Definition: vtkCellType.h:55
@ VTK_LINE
Definition: vtkCellType.h:48
@ VTK_CONVEX_POINT_SET
Definition: vtkCellType.h:84
@ VTK_PARAMETRIC_TRI_SURFACE
Definition: vtkCellType.h:92
@ VTK_PENTAGONAL_PRISM
Definition: vtkCellType.h:60
@ VTK_HIGHER_ORDER_TRIANGLE
Definition: vtkCellType.h:99
@ VTK_QUADRATIC_QUAD
Definition: vtkCellType.h:66
@ VTK_WEDGE
Definition: vtkCellType.h:58
@ VTK_PARAMETRIC_QUAD_SURFACE
Definition: vtkCellType.h:93
@ VTK_PARAMETRIC_CURVE
Definition: vtkCellType.h:90
@ VTK_HIGHER_ORDER_PYRAMID
Definition: vtkCellType.h:104
@ VTK_HEXAGONAL_PRISM
Definition: vtkCellType.h:61
@ VTK_PARAMETRIC_HEX_REGION
Definition: vtkCellType.h:95
@ VTK_QUADRATIC_LINEAR_WEDGE
Definition: vtkCellType.h:75
@ VTK_HEXAHEDRON
Definition: vtkCellType.h:57
@ VTK_CUBIC_LINE
Definition: vtkCellType.h:81
@ VTK_HIGHER_ORDER_HEXAHEDRON
Definition: vtkCellType.h:105
@ VTK_QUADRATIC_POLYGON
Definition: vtkCellType.h:67
@ VTK_QUAD
Definition: vtkCellType.h:54
@ VTK_QUADRATIC_TRIANGLE
Definition: vtkCellType.h:65
@ VTK_PARAMETRIC_TETRA_REGION
Definition: vtkCellType.h:94
@ VTK_QUADRATIC_EDGE
Definition: vtkCellType.h:64
@ VTK_QUADRATIC_TETRA
Definition: vtkCellType.h:68
@ VTK_HIGHER_ORDER_EDGE
Definition: vtkCellType.h:98
@ VTK_VERTEX
Definition: vtkCellType.h:46
@ VTK_POLY_VERTEX
Definition: vtkCellType.h:47
@ VTK_QUADRATIC_LINEAR_QUAD
Definition: vtkCellType.h:74
@ VTK_BIQUADRATIC_QUADRATIC_WEDGE
Definition: vtkCellType.h:76
@ VTK_HIGHER_ORDER_POLYGON
Definition: vtkCellType.h:101
@ VTK_BIQUADRATIC_TRIANGLE
Definition: vtkCellType.h:78
int vtkIdType
Definition: vtkType.h:287