VTK  9.4.20241123
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
155#ifndef vtkCellIterator_h
156#define vtkCellIterator_h
157
158#include "vtkCellArray.h" // For inline methods
159#include "vtkCellType.h" // For VTK_EMPTY_CELL
160#include "vtkCommonDataModelModule.h" // For export macro
161#include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_4_0
162#include "vtkIdList.h" // For inline methods
163#include "vtkIdTypeArray.h" // For inline methods
164#include "vtkNew.h" // For vtkNew
165#include "vtkObject.h"
166
167VTK_ABI_NAMESPACE_BEGIN
168class vtkGenericCell;
169class vtkPoints;
170
171class VTKCOMMONDATAMODEL_EXPORT vtkCellIterator : public vtkObject
172{
173public:
174 void PrintSelf(ostream& os, vtkIndent indent) override;
176
180 void InitTraversal();
181
185 void GoToNextCell();
186
190 virtual bool IsDoneWithTraversal() = 0;
191
196 int GetCellType();
197
203
207 virtual vtkIdType GetCellId() = 0;
208
213 vtkIdList* GetPointIds();
214
220 vtkPoints* GetPoints();
221
226 vtkCellArray* GetCellFaces();
227
232 vtkIdList* GetSerializedCellFaces();
233
238 VTK_DEPRECATED_IN_9_4_0("Please use GetCellFaces instead.")
239 vtkIdList* GetFaces();
240
246 void GetCell(vtkGenericCell* cell);
247
252 vtkIdType GetNumberOfPoints();
253
258 vtkIdType GetNumberOfFaces();
259
260protected:
262 ~vtkCellIterator() override;
263
267 virtual void ResetToFirstCell() = 0;
268
272 virtual void IncrementToNextCell() = 0;
273
277 virtual void FetchCellType() = 0;
278
282 virtual void FetchPointIds() = 0;
283
287 virtual void FetchPoints() = 0;
288
295 virtual void FetchFaces() {}
296
301
302private:
303 vtkCellIterator(const vtkCellIterator&) = delete;
304 void operator=(const vtkCellIterator&) = delete;
305
306 enum
307 {
308 UninitializedFlag = 0x0,
309 CellTypeFlag = 0x1,
310 PointIdsFlag = 0x2,
311 PointsFlag = 0x4,
312 FacesFlag = 0x8
313 };
314
315 void ResetCache()
316 {
317 this->CacheFlags = UninitializedFlag;
318 this->CellType = VTK_EMPTY_CELL;
319 }
320
321 void SetCache(unsigned char flags) { this->CacheFlags |= flags; }
322
323 bool CheckCache(unsigned char flags) { return (this->CacheFlags & flags) == flags; }
324
325 vtkNew<vtkPoints> PointsContainer;
326 vtkNew<vtkIdList> PointIdsContainer;
327 vtkNew<vtkCellArray> FacesContainer;
328 vtkNew<vtkIdList> LegacyFacesContainer;
329 unsigned char CacheFlags;
330};
331
332//------------------------------------------------------------------------------
334{
335 this->ResetToFirstCell();
336 this->ResetCache();
337}
338
339//------------------------------------------------------------------------------
341{
342 this->IncrementToNextCell();
343 this->ResetCache();
344}
345
346//------------------------------------------------------------------------------
348{
349 if (!this->CheckCache(CellTypeFlag))
350 {
351 this->FetchCellType();
352 this->SetCache(CellTypeFlag);
353 }
354 return this->CellType;
355}
356
357//------------------------------------------------------------------------------
359{
360 if (!this->CheckCache(PointIdsFlag))
361 {
362 this->FetchPointIds();
363 this->SetCache(PointIdsFlag);
364 }
365 return this->PointIds;
366}
367
368//------------------------------------------------------------------------------
370{
371 if (!this->CheckCache(PointsFlag))
372 {
373 this->FetchPoints();
374 this->SetCache(PointsFlag);
375 }
376 return this->Points;
377}
378
379//------------------------------------------------------------------------------
381{
382 if (!this->CheckCache(FacesFlag))
383 {
384 this->FetchFaces();
385 this->SetCache(FacesFlag);
386 }
387 return this->Faces;
388}
389
390//------------------------------------------------------------------------------
392{
393 if (!this->CheckCache(FacesFlag))
394 {
395 this->FetchFaces();
396 this->SetCache(FacesFlag);
397 }
398 // Export Legacy Format
400 this->Faces->ExportLegacyFormat(tmp);
401 this->LegacyFacesContainer->Initialize();
402 this->LegacyFacesContainer->InsertNextId(this->Faces->GetNumberOfCells());
403 for (vtkIdType idx = 0; idx < tmp->GetNumberOfValues(); ++idx)
404 {
405 this->LegacyFacesContainer->InsertNextId(tmp->GetValue(idx));
406 }
407 return this->LegacyFacesContainer;
408}
409
410//------------------------------------------------------------------------------
412{
413 if (!this->CheckCache(PointIdsFlag))
414 {
415 this->FetchPointIds();
416 this->SetCache(PointIdsFlag);
417 }
418 return this->PointIds->GetNumberOfIds();
419}
420
421//------------------------------------------------------------------------------
423{
424 switch (this->GetCellType())
425 {
426 case VTK_EMPTY_CELL:
427 case VTK_VERTEX:
428 case VTK_POLY_VERTEX:
429 case VTK_LINE:
430 case VTK_POLY_LINE:
431 case VTK_TRIANGLE:
433 case VTK_POLYGON:
434 case VTK_PIXEL:
435 case VTK_QUAD:
443 case VTK_CUBIC_LINE:
456 case VTK_BEZIER_CURVE:
459 return 0;
460
461 case VTK_TETRA:
467 return 4;
468
469 case VTK_PYRAMID:
473 case VTK_WEDGE:
479 case VTK_BEZIER_WEDGE:
480 return 5;
481
482 case VTK_VOXEL:
483 case VTK_HEXAHEDRON:
491 return 6;
492
494 return 7;
495
497 return 8;
498
499 case VTK_POLYHEDRON: // Need to look these up
500 if (!this->CheckCache(FacesFlag))
501 {
502 this->FetchFaces();
503 this->SetCache(FacesFlag);
504 }
505 return this->Faces->GetNumberOfCells();
506
507 default:
508 vtkGenericWarningMacro("Unknown cell type: " << this->CellType);
509 break;
510 }
511
512 return 0;
513}
514
515VTK_ABI_NAMESPACE_END
516#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.
Efficient cell iterator for vtkDataSet topologies.
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.
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.
provides thread-safe access to cells
list of point or cell ids
Definition vtkIdList.h:133
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition vtkIdList.h:159
void Initialize()
Release memory and restore to unallocated state.
vtkIdType InsertNextId(vtkIdType vtkid)
Add the id specified to the end of the list.
Definition vtkIdList.h:336
a simple class to control print indentation
Definition vtkIndent.h:108
Allocate and hold a VTK object.
Definition vtkNew.h:167
abstract base class for most VTK objects
Definition vtkObject.h:162
represent and manipulate 3D points
Definition vtkPoints.h:139
@ 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:315