VTK  9.6.1
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
55
56#ifndef vtkCellIterator_h
57#define vtkCellIterator_h
58
59#include "vtkCellArray.h" // For inline methods
60#include "vtkCellType.h" // For VTK_EMPTY_CELL
61#include "vtkCommonDataModelModule.h" // For export macro
62#include "vtkIdList.h" // For inline methods
63#include "vtkIdTypeArray.h" // For inline methods
64#include "vtkNew.h" // For vtkNew
65#include "vtkObject.h"
66
67VTK_ABI_NAMESPACE_BEGIN
68class vtkGenericCell;
69class vtkPoints;
70
71class VTKCOMMONDATAMODEL_EXPORT vtkCellIterator : public vtkObject
72{
73public:
74 void PrintSelf(ostream& os, vtkIndent indent) override;
76
80 void InitTraversal();
81
85 void GoToNextCell();
86
90 virtual bool IsDoneWithTraversal() = 0;
91
96 int GetCellType();
97
103
107 virtual vtkIdType GetCellId() = 0;
108
114
121
127
133
140
146
152
153protected:
156
160 virtual void ResetToFirstCell() = 0;
161
165 virtual void IncrementToNextCell() = 0;
166
170 virtual void FetchCellType() = 0;
171
175 virtual void FetchPointIds() = 0;
176
180 virtual void FetchPoints() = 0;
181
188 virtual void FetchFaces() {}
189
194
195private:
196 vtkCellIterator(const vtkCellIterator&) = delete;
197 void operator=(const vtkCellIterator&) = delete;
198
199 enum
200 {
201 UninitializedFlag = 0x0,
202 CellTypeFlag = 0x1,
203 PointIdsFlag = 0x2,
204 PointsFlag = 0x4,
205 FacesFlag = 0x8
206 };
207
208 void ResetCache()
209 {
210 this->CacheFlags = UninitializedFlag;
211 this->CellType = VTK_EMPTY_CELL;
212 }
213
214 void SetCache(unsigned char flags) { this->CacheFlags |= flags; }
215
216 bool CheckCache(unsigned char flags) { return (this->CacheFlags & flags) == flags; }
217
218 vtkNew<vtkPoints> PointsContainer;
219 vtkNew<vtkIdList> PointIdsContainer;
220 vtkNew<vtkCellArray> FacesContainer;
221 vtkNew<vtkIdList> LegacyFacesContainer;
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(FacesFlag))
287 {
288 this->FetchFaces();
289 this->SetCache(FacesFlag);
290 }
291 // Export Legacy Format
293 this->Faces->ExportLegacyFormat(tmp);
294 this->LegacyFacesContainer->Initialize();
295 this->LegacyFacesContainer->InsertNextId(this->Faces->GetNumberOfCells());
296 for (vtkIdType idx = 0; idx < tmp->GetNumberOfValues(); ++idx)
297 {
298 this->LegacyFacesContainer->InsertNextId(tmp->GetValue(idx));
299 }
300 return this->LegacyFacesContainer;
301}
302
303//------------------------------------------------------------------------------
305{
306 if (!this->CheckCache(PointIdsFlag))
307 {
308 this->FetchPointIds();
309 this->SetCache(PointIdsFlag);
310 }
311 return this->PointIds->GetNumberOfIds();
312}
313
314//------------------------------------------------------------------------------
316{
317 switch (this->GetCellType())
318 {
319 case VTK_EMPTY_CELL:
320 case VTK_VERTEX:
321 case VTK_POLY_VERTEX:
322 case VTK_LINE:
323 case VTK_POLY_LINE:
324 case VTK_TRIANGLE:
326 case VTK_POLYGON:
327 case VTK_PIXEL:
328 case VTK_QUAD:
336 case VTK_CUBIC_LINE:
349 case VTK_BEZIER_CURVE:
352 return 0;
353
354 case VTK_TETRA:
360 return 4;
361
362 case VTK_PYRAMID:
366 case VTK_WEDGE:
372 case VTK_BEZIER_WEDGE:
373 return 5;
374
375 case VTK_VOXEL:
376 case VTK_HEXAHEDRON:
384 return 6;
385
387 return 7;
388
390 return 8;
391
392 case VTK_POLYHEDRON: // Need to look these up
393 if (!this->CheckCache(FacesFlag))
394 {
395 this->FetchFaces();
396 this->SetCache(FacesFlag);
397 }
398 return this->Faces->GetNumberOfCells();
399
400 default:
401 vtkGenericWarningMacro("Unknown cell type: " << this->CellType);
402 break;
403 }
404
405 return 0;
406}
407
408VTK_ABI_NAMESPACE_END
409#endif // vtkCellIterator_h
object to represent cell connectivity
vtkIdType GetNumberOfCells() const override
Get the number of cells in the array.
void ExportLegacyFormat(vtkIdTypeArray *data)
Fill data with the old-style vtkCellArray data layout, e.g.
int GetCellDimension()
Get the current cell dimension (0, 1, 2, or 3).
vtkIdList * GetSerializedCellFaces()
Get a serialized view of the faces for a polyhedral cell.
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.
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
vtkCellArray * GetCellFaces()
Get the faces for a polyhedral cell.
virtual void FetchCellType()=0
Lookup the cell type in the data set and store it in this->CellType.
vtkCellArray * Faces
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:24
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition vtkIdList.h:50
a simple class to control print indentation
Definition vtkIndent.h:29
Allocate and hold a VTK object.
Definition vtkNew.h:58
represent and manipulate 3D points
Definition vtkPoints.h:30
int GetNumberOfFaces() override
Implement the vtkCell API.
int GetCellType() override
Implement the vtkCell API.
@ VTK_VOXEL
Definition vtkCellType.h:47
@ VTK_QUADRATIC_HEXAHEDRON
Definition vtkCellType.h:60
@ VTK_PARAMETRIC_SURFACE
Definition vtkCellType.h:83
@ VTK_HIGHER_ORDER_TETRAHEDRON
Definition vtkCellType.h:94
@ VTK_TRIANGLE_STRIP
Definition vtkCellType.h:42
@ VTK_BIQUADRATIC_QUADRATIC_HEXAHEDRON
Definition vtkCellType.h:69
@ VTK_LAGRANGE_CURVE
@ VTK_HIGHER_ORDER_QUAD
Definition vtkCellType.h:92
@ VTK_PYRAMID
Definition vtkCellType.h:50
@ VTK_PIXEL
Definition vtkCellType.h:44
@ VTK_QUADRATIC_WEDGE
Definition vtkCellType.h:61
@ VTK_BEZIER_WEDGE
@ VTK_BIQUADRATIC_QUAD
Definition vtkCellType.h:63
@ VTK_HIGHER_ORDER_WEDGE
Definition vtkCellType.h:95
@ VTK_LAGRANGE_QUADRILATERAL
@ VTK_POLY_LINE
Definition vtkCellType.h:40
@ VTK_TRIQUADRATIC_PYRAMID
Definition vtkCellType.h:65
@ VTK_TRIANGLE
Definition vtkCellType.h:41
@ VTK_BEZIER_TRIANGLE
@ VTK_POLYGON
Definition vtkCellType.h:43
@ VTK_EMPTY_CELL
Definition vtkCellType.h:36
@ VTK_QUADRATIC_PYRAMID
Definition vtkCellType.h:62
@ VTK_POLYHEDRON
Definition vtkCellType.h:79
@ VTK_TRIQUADRATIC_HEXAHEDRON
Definition vtkCellType.h:64
@ VTK_TETRA
Definition vtkCellType.h:46
@ VTK_LINE
Definition vtkCellType.h:39
@ VTK_CONVEX_POINT_SET
Definition vtkCellType.h:76
@ VTK_BEZIER_HEXAHEDRON
@ VTK_PARAMETRIC_TRI_SURFACE
Definition vtkCellType.h:84
@ VTK_LAGRANGE_WEDGE
@ VTK_LAGRANGE_HEXAHEDRON
@ VTK_PENTAGONAL_PRISM
Definition vtkCellType.h:51
@ VTK_HIGHER_ORDER_TRIANGLE
Definition vtkCellType.h:91
@ VTK_QUADRATIC_QUAD
Definition vtkCellType.h:57
@ VTK_WEDGE
Definition vtkCellType.h:49
@ VTK_PARAMETRIC_QUAD_SURFACE
Definition vtkCellType.h:85
@ VTK_LAGRANGE_TETRAHEDRON
@ VTK_PARAMETRIC_CURVE
Definition vtkCellType.h:82
@ VTK_BEZIER_CURVE
@ VTK_HIGHER_ORDER_PYRAMID
Definition vtkCellType.h:96
@ VTK_HEXAGONAL_PRISM
Definition vtkCellType.h:52
@ VTK_PARAMETRIC_HEX_REGION
Definition vtkCellType.h:87
@ VTK_BEZIER_QUADRILATERAL
@ VTK_QUADRATIC_LINEAR_WEDGE
Definition vtkCellType.h:67
@ VTK_HEXAHEDRON
Definition vtkCellType.h:48
@ VTK_CUBIC_LINE
Definition vtkCellType.h:73
@ VTK_LAGRANGE_TRIANGLE
@ VTK_HIGHER_ORDER_HEXAHEDRON
Definition vtkCellType.h:97
@ VTK_QUADRATIC_POLYGON
Definition vtkCellType.h:58
@ VTK_QUAD
Definition vtkCellType.h:45
@ VTK_QUADRATIC_TRIANGLE
Definition vtkCellType.h:56
@ VTK_PARAMETRIC_TETRA_REGION
Definition vtkCellType.h:86
@ VTK_QUADRATIC_EDGE
Definition vtkCellType.h:55
@ VTK_QUADRATIC_TETRA
Definition vtkCellType.h:59
@ VTK_HIGHER_ORDER_EDGE
Definition vtkCellType.h:90
@ VTK_BEZIER_TETRAHEDRON
@ VTK_VERTEX
Definition vtkCellType.h:37
@ VTK_POLY_VERTEX
Definition vtkCellType.h:38
@ VTK_QUADRATIC_LINEAR_QUAD
Definition vtkCellType.h:66
@ VTK_BIQUADRATIC_QUADRATIC_WEDGE
Definition vtkCellType.h:68
@ VTK_HIGHER_ORDER_POLYGON
Definition vtkCellType.h:93
@ VTK_BIQUADRATIC_TRIANGLE
Definition vtkCellType.h:70
virtual int GetNumberOfPoints()=0
Return the number of corner points that compose the cell.
int vtkIdType
Definition vtkType.h:368