VTK  9.2.6
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 class VTKCOMMONDATAMODEL_EXPORT vtkCellArrayIterator : public vtkObject
138 {
139 public:
141 
145  void PrintSelf(ostream& os, vtkIndent indent) override;
148 
152  vtkCellArray* GetCellArray() { return this->CellArray; }
153 
160  void GoToCell(vtkIdType cellId)
161  {
162  this->CurrentCellId = cellId;
163  this->NumberOfCells = this->CellArray->GetNumberOfCells();
164  assert(cellId <= this->NumberOfCells);
165  }
166 
172 
180  void GetCellAtId(vtkIdType cellId, vtkIdType& numCellPts, vtkIdType const*& cellPts)
181  {
182  this->GoToCell(cellId);
183  this->GetCurrentCell(numCellPts, cellPts);
184  }
185  void GetCellAtId(vtkIdType cellId, vtkIdList* cellIds)
186  {
187  this->GoToCell(cellId);
188  this->GetCurrentCell(cellIds);
189  }
191  {
192  this->GoToCell(cellId);
193  return this->GetCurrentCell();
194  }
196 
206  {
207  this->CurrentCellId = 0;
208  this->NumberOfCells = this->CellArray->GetNumberOfCells();
209  }
210 
214  void GoToNextCell() { ++this->CurrentCellId; }
215 
219  bool IsDoneWithTraversal() { return this->CurrentCellId >= this->NumberOfCells; }
220 
224  vtkIdType GetCurrentCellId() const { return this->CurrentCellId; }
225 
227 
235  void GetCurrentCell(vtkIdType& cellSize, vtkIdType const*& cellPoints)
236  {
237  assert(this->CurrentCellId < this->NumberOfCells);
238  // Either refer to vtkCellArray storage buffer, or copy into local buffer
239  if (this->CellArray->IsStorageShareable())
240  {
241  this->CellArray->GetCellAtId(this->CurrentCellId, cellSize, cellPoints);
242  }
243  else // or copy into local iterator buffer.
244  {
245  this->CellArray->GetCellAtId(this->CurrentCellId, this->TempCell);
246  cellSize = this->TempCell->GetNumberOfIds();
247  cellPoints = this->TempCell->GetPointer(0);
248  }
249  }
251  {
252  assert(this->CurrentCellId < this->NumberOfCells);
253  this->CellArray->GetCellAtId(this->CurrentCellId, ids);
254  }
256  {
257  assert(this->CurrentCellId < this->NumberOfCells);
258  this->CellArray->GetCellAtId(this->CurrentCellId, this->TempCell);
259  return this->TempCell;
260  }
262 
274  {
275  assert(this->CurrentCellId < this->NumberOfCells);
276  this->CellArray->ReplaceCellAtId(this->CurrentCellId, list);
277  }
278 
284  void ReplaceCurrentCell(vtkIdType npts, const vtkIdType* pts)
285  {
286  assert(this->CurrentCellId < this->NumberOfCells);
287  this->CellArray->ReplaceCellAtId(this->CurrentCellId, npts, pts);
288  }
289 
294  {
295  assert(this->CurrentCellId < this->NumberOfCells);
296  this->CellArray->ReverseCellAtId(this->CurrentCellId);
297  }
298 
299  friend class vtkCellArray;
300 
301 protected:
302  vtkCellArrayIterator() = default;
303  ~vtkCellArrayIterator() override = default;
304 
305  vtkSetMacro(CellArray, vtkCellArray*);
306 
311 
312 private:
314  void operator=(const vtkCellArrayIterator&) = delete;
315 };
316 
317 #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:296
friend class vtkCellArrayIterator
list of point or cell ids
Definition: vtkIdList.h:143
a simple class to control print indentation
Definition: vtkIndent.h:119
abstract base class for most VTK objects
Definition: vtkObject.h:82
int vtkIdType
Definition: vtkType.h:332