VTK  9.3.20240907
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
112#ifndef vtkCellArrayIterator_h
113#define vtkCellArrayIterator_h
114
115#include "vtkCommonDataModelModule.h" // For export macro
116#include "vtkObject.h"
117
118#include "vtkCellArray.h" // Needed for inline methods
119#include "vtkIdList.h" // Needed for inline methods
120#include "vtkSmartPointer.h" // For vtkSmartPointer
121
122#include <cassert> // for assert
123#include <type_traits> // for std::enable_if
124
125VTK_ABI_NAMESPACE_BEGIN
126class VTKCOMMONDATAMODEL_EXPORT vtkCellArrayIterator : public vtkObject
127{
128public:
130
134 void PrintSelf(ostream& os, vtkIndent indent) override;
137
141 vtkCellArray* GetCellArray() { return this->CellArray; }
142
149 void GoToCell(vtkIdType cellId)
150 {
151 this->CurrentCellId = cellId;
152 this->NumberOfCells = this->CellArray->GetNumberOfCells();
153 assert(cellId <= this->NumberOfCells);
154 }
155
161
169 void GetCellAtId(vtkIdType cellId, vtkIdType& numCellPts, vtkIdType const*& cellPts)
170 {
171 this->GoToCell(cellId);
172 this->GetCurrentCell(numCellPts, cellPts);
173 }
174 void GetCellAtId(vtkIdType cellId, vtkIdList* cellIds)
175 {
176 this->GoToCell(cellId);
177 this->GetCurrentCell(cellIds);
178 }
180 {
181 this->GoToCell(cellId);
182 return this->GetCurrentCell();
183 }
185
195 {
196 this->CurrentCellId = 0;
197 this->NumberOfCells = this->CellArray->GetNumberOfCells();
198 }
199
203 void GoToNextCell() { ++this->CurrentCellId; }
204
208 bool IsDoneWithTraversal() { return this->CurrentCellId >= this->NumberOfCells; }
209
213 vtkIdType GetCurrentCellId() const { return this->CurrentCellId; }
214
216
224 void GetCurrentCell(vtkIdType& cellSize, vtkIdType const*& cellPoints)
225 {
226 assert(this->CurrentCellId < this->NumberOfCells);
227 // Either refer to vtkCellArray storage buffer, or copy into local buffer
228 if (this->CellArray->IsStorageShareable())
229 {
230 this->CellArray->GetCellAtId(this->CurrentCellId, cellSize, cellPoints);
231 }
232 else // or copy into local iterator buffer.
233 {
234 this->CellArray->GetCellAtId(this->CurrentCellId, this->TempCell);
235 cellSize = this->TempCell->GetNumberOfIds();
236 cellPoints = this->TempCell->GetPointer(0);
237 }
238 }
240 {
241 assert(this->CurrentCellId < this->NumberOfCells);
242 this->CellArray->GetCellAtId(this->CurrentCellId, ids);
243 }
245 {
246 assert(this->CurrentCellId < this->NumberOfCells);
247 this->CellArray->GetCellAtId(this->CurrentCellId, this->TempCell);
248 return this->TempCell;
249 }
251
263 {
264 assert(this->CurrentCellId < this->NumberOfCells);
265 this->CellArray->ReplaceCellAtId(this->CurrentCellId, list);
266 }
267
274 {
275 assert(this->CurrentCellId < this->NumberOfCells);
276 this->CellArray->ReplaceCellAtId(this->CurrentCellId, npts, pts);
277 }
278
283 {
284 assert(this->CurrentCellId < this->NumberOfCells);
285 this->CellArray->ReverseCellAtId(this->CurrentCellId);
286 }
287
288 friend class vtkCellArray;
289
290protected:
292 ~vtkCellArrayIterator() override = default;
293
294 vtkSetMacro(CellArray, vtkCellArray*);
295
300
301private:
303 void operator=(const vtkCellArrayIterator&) = delete;
304};
305
306VTK_ABI_NAMESPACE_END
307#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
list of point or cell ids
Definition vtkIdList.h:133
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
Hold a reference to a vtkObjectBase instance.
int vtkIdType
Definition vtkType.h:315