VTK  9.3.0
vtkCellIterator.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3
65#ifndef vtkCellIterator_h
66#define vtkCellIterator_h
67
68#include "vtkCellType.h" // For VTK_EMPTY_CELL
69#include "vtkCommonDataModelModule.h" // For export macro
70#include "vtkIdList.h" // For inline methods
71#include "vtkNew.h" // For vtkNew
72#include "vtkObject.h"
73
74VTK_ABI_NAMESPACE_BEGIN
75class vtkGenericCell;
76class vtkPoints;
77
78class VTKCOMMONDATAMODEL_EXPORT vtkCellIterator : public vtkObject
79{
80public:
81 void PrintSelf(ostream& os, vtkIndent indent) override;
83
87 void InitTraversal();
88
92 void GoToNextCell();
93
97 virtual bool IsDoneWithTraversal() = 0;
98
103 int GetCellType();
104
110
114 virtual vtkIdType GetCellId() = 0;
115
120 vtkIdList* GetPointIds();
121
127 vtkPoints* GetPoints();
128
133 vtkIdList* GetFaces();
134
141
146 vtkIdType GetNumberOfPoints();
147
152 vtkIdType GetNumberOfFaces();
153
154protected:
157
161 virtual void ResetToFirstCell() = 0;
162
166 virtual void IncrementToNextCell() = 0;
167
171 virtual void FetchCellType() = 0;
172
176 virtual void FetchPointIds() = 0;
177
181 virtual void FetchPoints() = 0;
182
189 virtual void FetchFaces() {}
190
195
196private:
197 vtkCellIterator(const vtkCellIterator&) = delete;
198 void operator=(const vtkCellIterator&) = delete;
199
200 enum
201 {
202 UninitializedFlag = 0x0,
203 CellTypeFlag = 0x1,
204 PointIdsFlag = 0x2,
205 PointsFlag = 0x4,
206 FacesFlag = 0x8
207 };
208
209 void ResetCache()
210 {
211 this->CacheFlags = UninitializedFlag;
212 this->CellType = VTK_EMPTY_CELL;
213 }
214
215 void SetCache(unsigned char flags) { this->CacheFlags |= flags; }
216
217 bool CheckCache(unsigned char flags) { return (this->CacheFlags & flags) == flags; }
218
219 vtkNew<vtkPoints> PointsContainer;
220 vtkNew<vtkIdList> PointIdsContainer;
221 vtkNew<vtkIdList> FacesContainer;
222 unsigned char CacheFlags;
223};
224
225//------------------------------------------------------------------------------
227{
228 this->ResetToFirstCell();
229 this->ResetCache();
230}
231
232//------------------------------------------------------------------------------
234{
235 this->IncrementToNextCell();
236 this->ResetCache();
237}
238
239//------------------------------------------------------------------------------
241{
242 if (!this->CheckCache(CellTypeFlag))
243 {
244 this->FetchCellType();
245 this->SetCache(CellTypeFlag);
246 }
247 return this->CellType;
248}
249
250//------------------------------------------------------------------------------
252{
253 if (!this->CheckCache(PointIdsFlag))
254 {
255 this->FetchPointIds();
256 this->SetCache(PointIdsFlag);
257 }
258 return this->PointIds;
259}
260
261//------------------------------------------------------------------------------
263{
264 if (!this->CheckCache(PointsFlag))
265 {
266 this->FetchPoints();
267 this->SetCache(PointsFlag);
268 }
269 return this->Points;
270}
271
272//------------------------------------------------------------------------------
274{
275 if (!this->CheckCache(FacesFlag))
276 {
277 this->FetchFaces();
278 this->SetCache(FacesFlag);
279 }
280 return this->Faces;
281}
282
283//------------------------------------------------------------------------------
285{
286 if (!this->CheckCache(PointIdsFlag))
287 {
288 this->FetchPointIds();
289 this->SetCache(PointIdsFlag);
290 }
291 return this->PointIds->GetNumberOfIds();
292}
293
294//------------------------------------------------------------------------------
296{
297 switch (this->GetCellType())
298 {
299 case VTK_EMPTY_CELL:
300 case VTK_VERTEX:
301 case VTK_POLY_VERTEX:
302 case VTK_LINE:
303 case VTK_POLY_LINE:
304 case VTK_TRIANGLE:
306 case VTK_POLYGON:
307 case VTK_PIXEL:
308 case VTK_QUAD:
316 case VTK_CUBIC_LINE:
329 case VTK_BEZIER_CURVE:
332 return 0;
333
334 case VTK_TETRA:
340 return 4;
341
342 case VTK_PYRAMID:
346 case VTK_WEDGE:
352 case VTK_BEZIER_WEDGE:
353 return 5;
354
355 case VTK_VOXEL:
356 case VTK_HEXAHEDRON:
364 return 6;
365
367 return 7;
368
370 return 8;
371
372 case VTK_POLYHEDRON: // Need to look these up
373 if (!this->CheckCache(FacesFlag))
374 {
375 this->FetchFaces();
376 this->SetCache(FacesFlag);
377 }
378 return this->Faces->GetNumberOfIds() != 0 ? this->Faces->GetId(0) : 0;
379
380 default:
381 vtkGenericWarningMacro("Unknown cell type: " << this->CellType);
382 break;
383 }
384
385 return 0;
386}
387
388VTK_ABI_NAMESPACE_END
389#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.
void InitTraversal()
Reset to the first cell.
vtkAbstractTypeMacro(vtkCellIterator, vtkObject)
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.
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->Faces.
void GoToNextCell()
Increment to next cell.
virtual bool IsDoneWithTraversal()=0
Returns false while the iterator is valid.
~vtkCellIterator() override
provides thread-safe access to cells
list of point or cell ids
Definition vtkIdList.h:32
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition vtkIdList.h:58
vtkIdType GetId(vtkIdType i)
Return the id at location i.
Definition vtkIdList.h:63
a simple class to control print indentation
Definition vtkIndent.h:38
Allocate and hold a VTK object.
Definition vtkNew.h:60
abstract base class for most VTK objects
Definition vtkObject.h:58
represent and manipulate 3D points
Definition vtkPoints.h:38
@ VTK_VOXEL
Definition vtkCellType.h:48
@ VTK_QUADRATIC_HEXAHEDRON
Definition vtkCellType.h:61
@ VTK_PARAMETRIC_SURFACE
Definition vtkCellType.h:84
@ VTK_HIGHER_ORDER_TETRAHEDRON
Definition vtkCellType.h:95
@ VTK_TRIANGLE_STRIP
Definition vtkCellType.h:43
@ VTK_BIQUADRATIC_QUADRATIC_HEXAHEDRON
Definition vtkCellType.h:70
@ VTK_LAGRANGE_CURVE
@ VTK_HIGHER_ORDER_QUAD
Definition vtkCellType.h:93
@ VTK_PYRAMID
Definition vtkCellType.h:51
@ VTK_PIXEL
Definition vtkCellType.h:45
@ VTK_QUADRATIC_WEDGE
Definition vtkCellType.h:62
@ VTK_BEZIER_WEDGE
@ VTK_BIQUADRATIC_QUAD
Definition vtkCellType.h:64
@ VTK_HIGHER_ORDER_WEDGE
Definition vtkCellType.h:96
@ VTK_LAGRANGE_QUADRILATERAL
@ VTK_POLY_LINE
Definition vtkCellType.h:41
@ VTK_TRIQUADRATIC_PYRAMID
Definition vtkCellType.h:66
@ VTK_TRIANGLE
Definition vtkCellType.h:42
@ VTK_BEZIER_TRIANGLE
@ VTK_POLYGON
Definition vtkCellType.h:44
@ VTK_EMPTY_CELL
Definition vtkCellType.h:37
@ VTK_QUADRATIC_PYRAMID
Definition vtkCellType.h:63
@ VTK_POLYHEDRON
Definition vtkCellType.h:80
@ VTK_TRIQUADRATIC_HEXAHEDRON
Definition vtkCellType.h:65
@ VTK_TETRA
Definition vtkCellType.h:47
@ VTK_LINE
Definition vtkCellType.h:40
@ VTK_CONVEX_POINT_SET
Definition vtkCellType.h:77
@ VTK_BEZIER_HEXAHEDRON
@ VTK_PARAMETRIC_TRI_SURFACE
Definition vtkCellType.h:85
@ VTK_LAGRANGE_WEDGE
@ VTK_LAGRANGE_HEXAHEDRON
@ VTK_PENTAGONAL_PRISM
Definition vtkCellType.h:52
@ VTK_HIGHER_ORDER_TRIANGLE
Definition vtkCellType.h:92
@ VTK_QUADRATIC_QUAD
Definition vtkCellType.h:58
@ VTK_WEDGE
Definition vtkCellType.h:50
@ VTK_PARAMETRIC_QUAD_SURFACE
Definition vtkCellType.h:86
@ VTK_LAGRANGE_TETRAHEDRON
@ VTK_PARAMETRIC_CURVE
Definition vtkCellType.h:83
@ VTK_BEZIER_CURVE
@ VTK_HIGHER_ORDER_PYRAMID
Definition vtkCellType.h:97
@ VTK_HEXAGONAL_PRISM
Definition vtkCellType.h:53
@ VTK_PARAMETRIC_HEX_REGION
Definition vtkCellType.h:88
@ VTK_BEZIER_QUADRILATERAL
@ VTK_QUADRATIC_LINEAR_WEDGE
Definition vtkCellType.h:68
@ VTK_HEXAHEDRON
Definition vtkCellType.h:49
@ VTK_CUBIC_LINE
Definition vtkCellType.h:74
@ VTK_LAGRANGE_TRIANGLE
@ VTK_HIGHER_ORDER_HEXAHEDRON
Definition vtkCellType.h:98
@ VTK_QUADRATIC_POLYGON
Definition vtkCellType.h:59
@ VTK_QUAD
Definition vtkCellType.h:46
@ VTK_QUADRATIC_TRIANGLE
Definition vtkCellType.h:57
@ VTK_PARAMETRIC_TETRA_REGION
Definition vtkCellType.h:87
@ VTK_QUADRATIC_EDGE
Definition vtkCellType.h:56
@ VTK_QUADRATIC_TETRA
Definition vtkCellType.h:60
@ VTK_HIGHER_ORDER_EDGE
Definition vtkCellType.h:91
@ VTK_BEZIER_TETRAHEDRON
@ VTK_VERTEX
Definition vtkCellType.h:38
@ VTK_POLY_VERTEX
Definition vtkCellType.h:39
@ VTK_QUADRATIC_LINEAR_QUAD
Definition vtkCellType.h:67
@ VTK_BIQUADRATIC_QUADRATIC_WEDGE
Definition vtkCellType.h:69
@ VTK_HIGHER_ORDER_POLYGON
Definition vtkCellType.h:94
@ VTK_BIQUADRATIC_TRIANGLE
Definition vtkCellType.h:71
int vtkIdType
Definition vtkType.h:315