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 
74 #ifndef vtkCellArrayIterator_h
75 #define vtkCellArrayIterator_h
76 
77 #include "vtkCommonDataModelModule.h" // For export macro
78 #include "vtkObject.h"
79 
80 #include "vtkCellArray.h" // Needed for inline methods
81 #include "vtkIdList.h" // Needed for inline methods
82 #include "vtkSmartPointer.h" // For vtkSmartPointer
83 
84 #include <cassert> // for assert
85 #include <type_traits> // for std::enable_if
86 
87 class VTKCOMMONDATAMODEL_EXPORT vtkCellArrayIterator : public vtkObject
88 {
89 public:
91 
95  void PrintSelf(ostream& os, vtkIndent indent) override;
98 
102  vtkCellArray* GetCellArray() { return this->CellArray; }
103 
110  void GoToCell(vtkIdType cellId)
111  {
112  this->CurrentCellId = cellId;
113  this->NumberOfCells = this->CellArray->GetNumberOfCells();
114  assert(cellId <= this->NumberOfCells);
115  }
116 
122 
130  void GetCellAtId(vtkIdType cellId, vtkIdType& numCellPts, vtkIdType const*& cellPts)
131  {
132  this->GoToCell(cellId);
133  this->GetCurrentCell(numCellPts, cellPts);
134  }
135  void GetCellAtId(vtkIdType cellId, vtkIdList* cellIds)
136  {
137  this->GoToCell(cellId);
138  this->GetCurrentCell(cellIds);
139  }
141  {
142  this->GoToCell(cellId);
143  return this->GetCurrentCell();
144  }
146 
156  {
157  this->CurrentCellId = 0;
158  this->NumberOfCells = this->CellArray->GetNumberOfCells();
159  }
160 
164  void GoToNextCell() { ++this->CurrentCellId; }
165 
169  bool IsDoneWithTraversal() { return this->CurrentCellId >= this->NumberOfCells; }
170 
174  vtkIdType GetCurrentCellId() const { return this->CurrentCellId; }
175 
177 
185  void GetCurrentCell(vtkIdType& cellSize, vtkIdType const*& cellPoints)
186  {
187  assert(this->CurrentCellId < this->NumberOfCells);
188  // Either refer to vtkCellArray storage buffer, or copy into local buffer
189  if (this->CellArray->IsStorageShareable())
190  {
191  this->CellArray->GetCellAtId(this->CurrentCellId, cellSize, cellPoints);
192  }
193  else // or copy into local iterator buffer.
194  {
195  this->CellArray->GetCellAtId(this->CurrentCellId, this->TempCell);
196  cellSize = this->TempCell->GetNumberOfIds();
197  cellPoints = this->TempCell->GetPointer(0);
198  }
199  }
201  {
202  assert(this->CurrentCellId < this->NumberOfCells);
203  this->CellArray->GetCellAtId(this->CurrentCellId, ids);
204  }
206  {
207  assert(this->CurrentCellId < this->NumberOfCells);
208  this->CellArray->GetCellAtId(this->CurrentCellId, this->TempCell);
209  return this->TempCell;
210  }
212 
224  {
225  assert(this->CurrentCellId < this->NumberOfCells);
226  this->CellArray->ReplaceCellAtId(this->CurrentCellId, list);
227  }
228 
234  void ReplaceCurrentCell(vtkIdType npts, const vtkIdType* pts)
235  {
236  assert(this->CurrentCellId < this->NumberOfCells);
237  this->CellArray->ReplaceCellAtId(this->CurrentCellId, npts, pts);
238  }
239 
244  {
245  assert(this->CurrentCellId < this->NumberOfCells);
246  this->CellArray->ReverseCellAtId(this->CurrentCellId);
247  }
248 
249  friend class vtkCellArray;
250 
251 protected:
252  vtkCellArrayIterator() = default;
253  ~vtkCellArrayIterator() override = default;
254 
255  vtkSetMacro(CellArray, vtkCellArray*);
256 
261 
262 private:
264  void operator=(const vtkCellArrayIterator&) = delete;
265 };
266 
267 #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:196
friend class vtkCellArrayIterator
list of point or cell ids
Definition: vtkIdList.h:43
a simple class to control print indentation
Definition: vtkIndent.h:49
abstract base class for most VTK objects
Definition: vtkObject.h:72
int vtkIdType
Definition: vtkType.h:332