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 
53 #ifndef vtkCellArrayIterator_h
54 #define vtkCellArrayIterator_h
55 
56 #include "vtkCommonDataModelModule.h" // For export macro
57 #include "vtkObject.h"
58 
59 #include "vtkCellArray.h" // Needed for inline methods
60 #include "vtkIdList.h" // Needed for inline methods
61 #include "vtkSmartPointer.h" // For vtkSmartPointer
62 
63 #include <cassert> // for assert
64 #include <type_traits> // for std::enable_if
65 
66 VTK_ABI_NAMESPACE_BEGIN
67 class VTKCOMMONDATAMODEL_EXPORT vtkCellArrayIterator : public vtkObject
68 {
69 public:
71 
75  void PrintSelf(ostream& os, vtkIndent indent) override;
78 
82  vtkCellArray* GetCellArray() { return this->CellArray; }
83 
90  void GoToCell(vtkIdType cellId)
91  {
92  this->CurrentCellId = cellId;
93  this->NumberOfCells = this->CellArray->GetNumberOfCells();
94  assert(cellId <= this->NumberOfCells);
95  }
96 
102 
110  void GetCellAtId(vtkIdType cellId, vtkIdType& numCellPts, vtkIdType const*& cellPts)
111  {
112  this->GoToCell(cellId);
113  this->GetCurrentCell(numCellPts, cellPts);
114  }
115  void GetCellAtId(vtkIdType cellId, vtkIdList* cellIds)
116  {
117  this->GoToCell(cellId);
118  this->GetCurrentCell(cellIds);
119  }
121  {
122  this->GoToCell(cellId);
123  return this->GetCurrentCell();
124  }
126 
136  {
137  this->CurrentCellId = 0;
138  this->NumberOfCells = this->CellArray->GetNumberOfCells();
139  }
140 
144  void GoToNextCell() { ++this->CurrentCellId; }
145 
149  bool IsDoneWithTraversal() { return this->CurrentCellId >= this->NumberOfCells; }
150 
154  vtkIdType GetCurrentCellId() const { return this->CurrentCellId; }
155 
157 
165  void GetCurrentCell(vtkIdType& cellSize, vtkIdType const*& cellPoints)
166  {
167  assert(this->CurrentCellId < this->NumberOfCells);
168  // Either refer to vtkCellArray storage buffer, or copy into local buffer
169  if (this->CellArray->IsStorageShareable())
170  {
171  this->CellArray->GetCellAtId(this->CurrentCellId, cellSize, cellPoints);
172  }
173  else // or copy into local iterator buffer.
174  {
175  this->CellArray->GetCellAtId(this->CurrentCellId, this->TempCell);
176  cellSize = this->TempCell->GetNumberOfIds();
177  cellPoints = this->TempCell->GetPointer(0);
178  }
179  }
181  {
182  assert(this->CurrentCellId < this->NumberOfCells);
183  this->CellArray->GetCellAtId(this->CurrentCellId, ids);
184  }
186  {
187  assert(this->CurrentCellId < this->NumberOfCells);
188  this->CellArray->GetCellAtId(this->CurrentCellId, this->TempCell);
189  return this->TempCell;
190  }
192 
204  {
205  assert(this->CurrentCellId < this->NumberOfCells);
206  this->CellArray->ReplaceCellAtId(this->CurrentCellId, list);
207  }
208 
214  void ReplaceCurrentCell(vtkIdType npts, const vtkIdType* pts)
215  {
216  assert(this->CurrentCellId < this->NumberOfCells);
217  this->CellArray->ReplaceCellAtId(this->CurrentCellId, npts, pts);
218  }
219 
224  {
225  assert(this->CurrentCellId < this->NumberOfCells);
226  this->CellArray->ReverseCellAtId(this->CurrentCellId);
227  }
228 
229  friend class vtkCellArray;
230 
231 protected:
232  vtkCellArrayIterator() = default;
233  ~vtkCellArrayIterator() override = default;
234 
235  vtkSetMacro(CellArray, vtkCellArray*);
236 
241 
242 private:
244  void operator=(const vtkCellArrayIterator&) = delete;
245 };
246 
247 VTK_ABI_NAMESPACE_END
248 #endif // vtkCellArrayIterator_h
Encapsulate traversal logic for vtkCellArray.
vtkIdList * GetCurrentCell()
Returns the definition of the current cell during forward traversal.
bool IsDoneWithTraversal()
Returns true if the iterator has completed the traversal.
vtkNew< vtkIdList > TempCell
vtkSmartPointer< vtkCellArray > CellArray
static vtkCellArrayIterator * New()
Standard methods for instantiation, type information, and printing.
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.
vtkCellArray * GetCellArray()
Return the vtkCellArray object over which iteration is occurring.
void GoToCell(vtkIdType cellId)
Initialize the iterator to a specific cell.
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.
vtkIdType GetCurrentCellId() const
Returns the id of the current cell during forward iteration.
vtkIdList * GetCellAtId(vtkIdType cellId)
The following are methods supporting random access iteration.
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.
void GoToFirstCell()
The following are methods supporting forward iteration.
object to represent cell connectivity
Definition: vtkCellArray.h:176
friend class vtkCellArrayIterator
list of point or cell ids
Definition: vtkIdList.h:23
a simple class to control print indentation
Definition: vtkIndent.h:29
abstract base class for most VTK objects
Definition: vtkObject.h:52
int vtkIdType
Definition: vtkType.h:315