VTK  9.0.3
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 
65 #ifndef vtkCellArrayIterator_h
66 #define vtkCellArrayIterator_h
67 
68 #include "vtkCommonDataModelModule.h" // For export macro
69 #include "vtkObject.h"
70 
71 #include "vtkCellArray.h" // Needed for inline methods
72 #include "vtkIdList.h" // Needed for inline methods
73 #include "vtkSmartPointer.h" // For vtkSmartPointer
74 
75 #include <cassert> // for assert
76 #include <type_traits> // for std::enable_if
77 
78 class VTKCOMMONDATAMODEL_EXPORT vtkCellArrayIterator : public vtkObject
79 {
80 public:
82 
86  void PrintSelf(ostream& os, vtkIndent indent) override;
89 
93  vtkCellArray* GetCellArray() { return this->CellArray; }
94 
101  void GoToCell(vtkIdType cellId)
102  {
103  this->CurrentCellId = cellId;
104  this->NumberOfCells = this->CellArray->GetNumberOfCells();
105  assert(cellId <= this->NumberOfCells);
106  }
107 
121  void GetCellAtId(vtkIdType cellId, vtkIdType& numCellPts, vtkIdType const*& cellPts)
122  {
123  this->GoToCell(cellId);
124  this->GetCurrentCell(numCellPts, cellPts);
125  }
126  void GetCellAtId(vtkIdType cellId, vtkIdList* cellIds)
127  {
128  this->GoToCell(cellId);
129  this->GetCurrentCell(cellIds);
130  }
132  {
133  this->GoToCell(cellId);
134  return this->GetCurrentCell();
135  }
137 
147  {
148  this->CurrentCellId = 0;
149  this->NumberOfCells = this->CellArray->GetNumberOfCells();
150  }
151 
155  void GoToNextCell() { ++this->CurrentCellId; }
156 
160  bool IsDoneWithTraversal() { return this->CurrentCellId >= this->NumberOfCells; }
161 
165  vtkIdType GetCurrentCellId() const { return this->CurrentCellId; }
166 
168 
176  void GetCurrentCell(vtkIdType& cellSize, vtkIdType const*& cellPoints)
177  {
178  assert(this->CurrentCellId < this->NumberOfCells);
179  // Either refer to vtkCellArray storage buffer, or copy into local buffer
180  if (this->CellArray->IsStorageShareable())
181  {
182  this->CellArray->GetCellAtId(this->CurrentCellId, cellSize, cellPoints);
183  }
184  else // or copy into local iterator buffer.
185  {
186  this->CellArray->GetCellAtId(this->CurrentCellId, this->TempCell);
187  cellSize = this->TempCell->GetNumberOfIds();
188  cellPoints = this->TempCell->GetPointer(0);
189  }
190  }
192  {
193  assert(this->CurrentCellId < this->NumberOfCells);
194  this->CellArray->GetCellAtId(this->CurrentCellId, ids);
195  }
197  {
198  assert(this->CurrentCellId < this->NumberOfCells);
199  this->CellArray->GetCellAtId(this->CurrentCellId, this->TempCell);
200  return this->TempCell;
201  }
203 
215  {
216  assert(this->CurrentCellId < this->NumberOfCells);
217  this->CellArray->ReplaceCellAtId(this->CurrentCellId, list);
218  }
219 
225  void ReplaceCurrentCell(vtkIdType npts, const vtkIdType* pts)
226  {
227  assert(this->CurrentCellId < this->NumberOfCells);
228  this->CellArray->ReplaceCellAtId(this->CurrentCellId, npts, pts);
229  }
230 
235  {
236  assert(this->CurrentCellId < this->NumberOfCells);
237  this->CellArray->ReverseCellAtId(this->CurrentCellId);
238  }
239 
240  friend class vtkCellArray;
241 
242 protected:
243  vtkCellArrayIterator() = default;
244  ~vtkCellArrayIterator() override = default;
245 
246  vtkSetMacro(CellArray, vtkCellArray*);
247 
252 
253 private:
255  void operator=(const vtkCellArrayIterator&) = delete;
256 };
257 
258 #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
static vtkCellArrayIterator * New()
void GetCurrentCell(vtkIdList *ids)
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)
vtkCellArray * GetCellArray()
Return the vtkCellArray object over which iteration is occuring.
void GoToCell(vtkIdType cellId)
Intialize 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)
void GetCurrentCell(vtkIdType &cellSize, vtkIdType const *&cellPoints)
Returns the definition of the current cell during forward traversal.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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:180
friend class vtkCellArrayIterator
list of point or cell ids
Definition: vtkIdList.h:31
a simple class to control print indentation
Definition: vtkIndent.h:34
abstract base class for most VTK objects
Definition: vtkObject.h:54
int vtkIdType
Definition: vtkType.h:338