VTK  9.2.20230327
vtkCellArrayIterator.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkCellArrayIterator.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
124 #ifndef vtkCellArrayIterator_h
125 #define vtkCellArrayIterator_h
126 
127 #include "vtkCommonDataModelModule.h" // For export macro
128 #include "vtkObject.h"
129 
130 #include "vtkCellArray.h" // Needed for inline methods
131 #include "vtkIdList.h" // Needed for inline methods
132 #include "vtkSmartPointer.h" // For vtkSmartPointer
133 
134 #include <cassert> // for assert
135 #include <type_traits> // for std::enable_if
136 
137 VTK_ABI_NAMESPACE_BEGIN
138 class VTKCOMMONDATAMODEL_EXPORT vtkCellArrayIterator : public vtkObject
139 {
140 public:
142 
146  void PrintSelf(ostream& os, vtkIndent indent) override;
149 
153  vtkCellArray* GetCellArray() { return this->CellArray; }
154 
161  void GoToCell(vtkIdType cellId)
162  {
163  this->CurrentCellId = cellId;
164  this->NumberOfCells = this->CellArray->GetNumberOfCells();
165  assert(cellId <= this->NumberOfCells);
166  }
167 
173 
181  void GetCellAtId(vtkIdType cellId, vtkIdType& numCellPts, vtkIdType const*& cellPts)
182  {
183  this->GoToCell(cellId);
184  this->GetCurrentCell(numCellPts, cellPts);
185  }
186  void GetCellAtId(vtkIdType cellId, vtkIdList* cellIds)
187  {
188  this->GoToCell(cellId);
189  this->GetCurrentCell(cellIds);
190  }
192  {
193  this->GoToCell(cellId);
194  return this->GetCurrentCell();
195  }
197 
207  {
208  this->CurrentCellId = 0;
209  this->NumberOfCells = this->CellArray->GetNumberOfCells();
210  }
211 
215  void GoToNextCell() { ++this->CurrentCellId; }
216 
220  bool IsDoneWithTraversal() { return this->CurrentCellId >= this->NumberOfCells; }
221 
225  vtkIdType GetCurrentCellId() const { return this->CurrentCellId; }
226 
228 
236  void GetCurrentCell(vtkIdType& cellSize, vtkIdType const*& cellPoints)
237  {
238  assert(this->CurrentCellId < this->NumberOfCells);
239  // Either refer to vtkCellArray storage buffer, or copy into local buffer
240  if (this->CellArray->IsStorageShareable())
241  {
242  this->CellArray->GetCellAtId(this->CurrentCellId, cellSize, cellPoints);
243  }
244  else // or copy into local iterator buffer.
245  {
246  this->CellArray->GetCellAtId(this->CurrentCellId, this->TempCell);
247  cellSize = this->TempCell->GetNumberOfIds();
248  cellPoints = this->TempCell->GetPointer(0);
249  }
250  }
252  {
253  assert(this->CurrentCellId < this->NumberOfCells);
254  this->CellArray->GetCellAtId(this->CurrentCellId, ids);
255  }
257  {
258  assert(this->CurrentCellId < this->NumberOfCells);
259  this->CellArray->GetCellAtId(this->CurrentCellId, this->TempCell);
260  return this->TempCell;
261  }
263 
275  {
276  assert(this->CurrentCellId < this->NumberOfCells);
277  this->CellArray->ReplaceCellAtId(this->CurrentCellId, list);
278  }
279 
285  void ReplaceCurrentCell(vtkIdType npts, const vtkIdType* pts)
286  {
287  assert(this->CurrentCellId < this->NumberOfCells);
288  this->CellArray->ReplaceCellAtId(this->CurrentCellId, npts, pts);
289  }
290 
295  {
296  assert(this->CurrentCellId < this->NumberOfCells);
297  this->CellArray->ReverseCellAtId(this->CurrentCellId);
298  }
299 
300  friend class vtkCellArray;
301 
302 protected:
303  vtkCellArrayIterator() = default;
304  ~vtkCellArrayIterator() override = default;
305 
306  vtkSetMacro(CellArray, vtkCellArray*);
307 
312 
313 private:
315  void operator=(const vtkCellArrayIterator&) = delete;
316 };
317 
318 VTK_ABI_NAMESPACE_END
319 #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:297
friend class vtkCellArrayIterator
list of point or cell ids
Definition: vtkIdList.h:144
a simple class to control print indentation
Definition: vtkIndent.h:120
abstract base class for most VTK objects
Definition: vtkObject.h:83
int vtkIdType
Definition: vtkType.h:327