VTK  9.3.0
vtkCellArrayIterator.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
62#ifndef vtkCellArrayIterator_h
63#define vtkCellArrayIterator_h
64
65#include "vtkCommonDataModelModule.h" // For export macro
66#include "vtkObject.h"
67
68#include "vtkCellArray.h" // Needed for inline methods
69#include "vtkIdList.h" // Needed for inline methods
70#include "vtkSmartPointer.h" // For vtkSmartPointer
71
72#include <cassert> // for assert
73#include <type_traits> // for std::enable_if
74
75VTK_ABI_NAMESPACE_BEGIN
76class VTKCOMMONDATAMODEL_EXPORT vtkCellArrayIterator : public vtkObject
77{
78public:
80
84 void PrintSelf(ostream& os, vtkIndent indent) override;
87
91 vtkCellArray* GetCellArray() { return this->CellArray; }
92
99 void GoToCell(vtkIdType cellId)
100 {
101 this->CurrentCellId = cellId;
102 this->NumberOfCells = this->CellArray->GetNumberOfCells();
103 assert(cellId <= this->NumberOfCells);
104 }
105
111
119 void GetCellAtId(vtkIdType cellId, vtkIdType& numCellPts, vtkIdType const*& cellPts)
120 {
121 this->GoToCell(cellId);
122 this->GetCurrentCell(numCellPts, cellPts);
123 }
124 void GetCellAtId(vtkIdType cellId, vtkIdList* cellIds)
125 {
126 this->GoToCell(cellId);
127 this->GetCurrentCell(cellIds);
128 }
130 {
131 this->GoToCell(cellId);
132 return this->GetCurrentCell();
133 }
135
145 {
146 this->CurrentCellId = 0;
147 this->NumberOfCells = this->CellArray->GetNumberOfCells();
148 }
149
153 void GoToNextCell() { ++this->CurrentCellId; }
154
158 bool IsDoneWithTraversal() { return this->CurrentCellId >= this->NumberOfCells; }
159
163 vtkIdType GetCurrentCellId() const { return this->CurrentCellId; }
164
166
174 void GetCurrentCell(vtkIdType& cellSize, vtkIdType const*& cellPoints)
175 {
176 assert(this->CurrentCellId < this->NumberOfCells);
177 // Either refer to vtkCellArray storage buffer, or copy into local buffer
178 if (this->CellArray->IsStorageShareable())
179 {
180 this->CellArray->GetCellAtId(this->CurrentCellId, cellSize, cellPoints);
181 }
182 else // or copy into local iterator buffer.
183 {
184 this->CellArray->GetCellAtId(this->CurrentCellId, this->TempCell);
185 cellSize = this->TempCell->GetNumberOfIds();
186 cellPoints = this->TempCell->GetPointer(0);
187 }
188 }
190 {
191 assert(this->CurrentCellId < this->NumberOfCells);
192 this->CellArray->GetCellAtId(this->CurrentCellId, ids);
193 }
195 {
196 assert(this->CurrentCellId < this->NumberOfCells);
197 this->CellArray->GetCellAtId(this->CurrentCellId, this->TempCell);
198 return this->TempCell;
199 }
201
213 {
214 assert(this->CurrentCellId < this->NumberOfCells);
215 this->CellArray->ReplaceCellAtId(this->CurrentCellId, list);
216 }
217
224 {
225 assert(this->CurrentCellId < this->NumberOfCells);
226 this->CellArray->ReplaceCellAtId(this->CurrentCellId, npts, pts);
227 }
228
233 {
234 assert(this->CurrentCellId < this->NumberOfCells);
235 this->CellArray->ReverseCellAtId(this->CurrentCellId);
236 }
237
238 friend class vtkCellArray;
239
240protected:
242 ~vtkCellArrayIterator() override = default;
243
245
250
251private:
253 void operator=(const vtkCellArrayIterator&) = delete;
254};
255
256VTK_ABI_NAMESPACE_END
257#endif // vtkCellArrayIterator_h
Encapsulate traversal logic for vtkCellArray.
bool IsDoneWithTraversal()
Returns true if the iterator has completed the traversal.
vtkNew< vtkIdList > TempCell
vtkSmartPointer< vtkCellArray > CellArray
void GetCurrentCell(vtkIdList *ids)
Returns the definition of the current cell during forward traversal.
void ReplaceCurrentCell(vtkIdType npts, const vtkIdType *pts)
Replace the current cell with the ids in pts.
~vtkCellArrayIterator() override=default
void GetCellAtId(vtkIdType cellId, vtkIdList *cellIds)
The following are methods supporting random access iteration.
void GoToCell(vtkIdType cellId)
Initialize the iterator to a specific cell.
vtkIdList * GetCellAtId(vtkIdType cellId)
The following are methods supporting random access iteration.
void GoToNextCell()
Advance the forward iterator to the next cell.
void GetCellAtId(vtkIdType cellId, vtkIdType &numCellPts, vtkIdType const *&cellPts)
The following are methods supporting random access iteration.
void ReverseCurrentCell()
Reverses the order of the point ids in the current cell.
vtkIdList * GetCurrentCell()
Returns the definition of the current cell during forward traversal.
vtkIdType GetCurrentCellId() const
Returns the id of the current cell during forward iteration.
vtkCellArray * GetCellArray()
Return the vtkCellArray object over which iteration is occurring.
void GetCurrentCell(vtkIdType &cellSize, vtkIdType const *&cellPoints)
Returns the definition of the current cell during forward traversal.
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instantiation, type information, and printing.
vtkCellArrayIterator()=default
void ReplaceCurrentCell(vtkIdList *list)
Specialized methods for performing operations on the vtkCellArray.
static vtkCellArrayIterator * New()
Standard methods for instantiation, type information, and printing.
void GoToFirstCell()
The following are methods supporting forward iteration.
object to represent cell connectivity
friend class vtkCellArrayIterator
list of point or cell ids
Definition vtkIdList.h:32
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
Hold a reference to a vtkObjectBase instance.
int vtkIdType
Definition vtkType.h:315