VTK  9.5.2
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 "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_4_0
63#include "vtkIdList.h" // For inline methods
64#include "vtkIdTypeArray.h" // For inline methods
65#include "vtkNew.h" // For vtkNew
66#include "vtkObject.h"
67
68VTK_ABI_NAMESPACE_BEGIN
69class vtkGenericCell;
70class vtkPoints;
71
72class VTKCOMMONDATAMODEL_EXPORT vtkCellIterator : public vtkObject
73{
74public:
75 void PrintSelf(ostream& os, vtkIndent indent) override;
77
81 void InitTraversal();
82
86 void GoToNextCell();
87
91 virtual bool IsDoneWithTraversal() = 0;
92
97 int GetCellType();
98
104
108 virtual vtkIdType GetCellId() = 0;
109
115
122
128
134
139 VTK_DEPRECATED_IN_9_4_0("Please use GetCellFaces instead.")
141
148
154
160
161protected:
163 ~vtkCellIterator() override;
164
168 virtual void ResetToFirstCell() = 0;
169
173 virtual void IncrementToNextCell() = 0;
174
178 virtual void FetchCellType() = 0;
179
183 virtual void FetchPointIds() = 0;
184
188 virtual void FetchPoints() = 0;
189
196 virtual void FetchFaces() {}
197
202
203private:
204 vtkCellIterator(const vtkCellIterator&) = delete;
205 void operator=(const vtkCellIterator&) = delete;
206
207 enum
208 {
209 UninitializedFlag = 0x0,
210 CellTypeFlag = 0x1,
211 PointIdsFlag = 0x2,
212 PointsFlag = 0x4,
213 FacesFlag = 0x8
214 };
215
216 void ResetCache()
217 {
218 this->CacheFlags = UninitializedFlag;
219 this->CellType = VTK_EMPTY_CELL;
220 }
221
222 void SetCache(unsigned char flags) { this->CacheFlags |= flags; }
223
224 bool CheckCache(unsigned char flags) { return (this->CacheFlags & flags) == flags; }
225
226 vtkNew<vtkPoints> PointsContainer;
227 vtkNew<vtkIdList> PointIdsContainer;
228 vtkNew<vtkCellArray> FacesContainer;
229 vtkNew<vtkIdList> LegacyFacesContainer;
230 unsigned char CacheFlags;
231};
232
233//------------------------------------------------------------------------------
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(FacesFlag))
295 {
296 this->FetchFaces();
297 this->SetCache(FacesFlag);
298 }
299 // Export Legacy Format
301 this->Faces->ExportLegacyFormat(tmp);
302 this->LegacyFacesContainer->Initialize();
303 this->LegacyFacesContainer->InsertNextId(this->Faces->GetNumberOfCells());
304 for (vtkIdType idx = 0; idx < tmp->GetNumberOfValues(); ++idx)
305 {
306 this->LegacyFacesContainer->InsertNextId(tmp->GetValue(idx));
307 }
308 return this->LegacyFacesContainer;
309}
310
311//------------------------------------------------------------------------------
313{
314 if (!this->CheckCache(PointIdsFlag))
315 {
316 this->FetchPointIds();
317 this->SetCache(PointIdsFlag);
318 }
319 return this->PointIds->GetNumberOfIds();
320}
321
322//------------------------------------------------------------------------------
324{
325 switch (this->GetCellType())
326 {
327 case VTK_EMPTY_CELL:
328 case VTK_VERTEX:
329 case VTK_POLY_VERTEX:
330 case VTK_LINE:
331 case VTK_POLY_LINE:
332 case VTK_TRIANGLE:
334 case VTK_POLYGON:
335 case VTK_PIXEL:
336 case VTK_QUAD:
344 case VTK_CUBIC_LINE:
357 case VTK_BEZIER_CURVE:
360 return 0;
361
362 case VTK_TETRA:
368 return 4;
369
370 case VTK_PYRAMID:
374 case VTK_WEDGE:
380 case VTK_BEZIER_WEDGE:
381 return 5;
382
383 case VTK_VOXEL:
384 case VTK_HEXAHEDRON:
392 return 6;
393
395 return 7;
396
398 return 8;
399
400 case VTK_POLYHEDRON: // Need to look these up
401 if (!this->CheckCache(FacesFlag))
402 {
403 this->FetchFaces();
404 this->SetCache(FacesFlag);
405 }
406 return this->Faces->GetNumberOfCells();
407
408 default:
409 vtkGenericWarningMacro("Unknown cell type: " << this->CellType);
410 break;
411 }
412
413 return 0;
414}
415
416VTK_ABI_NAMESPACE_END
417#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.
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
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.
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 GetCellType() override
Implement the vtkCell API.
@ 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
#define VTK_DEPRECATED_IN_9_4_0(reason)
int vtkIdType
Definition vtkType.h:332