VTK  9.0.1
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;
87  static vtkCellArrayIterator* New();
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
vtkCellArrayIterator::GoToNextCell
void GoToNextCell()
Advance the forward iterator to the next cell.
Definition: vtkCellArrayIterator.h:155
vtkCellArrayIterator::ReplaceCurrentCell
void ReplaceCurrentCell(vtkIdType npts, const vtkIdType *pts)
Replace the current cell with the ids in pts.
Definition: vtkCellArrayIterator.h:225
vtkCellArrayIterator::CurrentCellId
vtkIdType CurrentCellId
Definition: vtkCellArrayIterator.h:250
vtkCellArrayIterator::GetCurrentCell
void GetCurrentCell(vtkIdList *ids)
Definition: vtkCellArrayIterator.h:191
vtkIdType
int vtkIdType
Definition: vtkType.h:338
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkCellArrayIterator::ReverseCurrentCell
void ReverseCurrentCell()
Reverses the order of the point ids in the current cell.
Definition: vtkCellArrayIterator.h:234
vtkCellArrayIterator::GetCurrentCell
vtkIdList * GetCurrentCell()
Definition: vtkCellArrayIterator.h:196
vtkCellArray.h
vtkCellArrayIterator::GetCurrentCellId
vtkIdType GetCurrentCellId() const
Returns the id of the current cell during forward iteration.
Definition: vtkCellArrayIterator.h:165
vtkSmartPointer< vtkCellArray >
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkCellArrayIterator::NumberOfCells
vtkIdType NumberOfCells
Definition: vtkCellArrayIterator.h:251
vtkCellArrayIterator::GetCellArray
vtkCellArray * GetCellArray()
Return the vtkCellArray object over which iteration is occuring.
Definition: vtkCellArrayIterator.h:93
vtkCellArrayIterator::GoToCell
void GoToCell(vtkIdType cellId)
Intialize the iterator to a specific cell.
Definition: vtkCellArrayIterator.h:101
vtkCellArrayIterator
Encapsulate traversal logic for vtkCellArray.
Definition: vtkCellArrayIterator.h:78
vtkCellArrayIterator::IsDoneWithTraversal
bool IsDoneWithTraversal()
Returns true if the iterator has completed the traversal.
Definition: vtkCellArrayIterator.h:160
vtkCellArray::vtkCellArrayIterator
friend class vtkCellArrayIterator
Definition: vtkCellArray.h:1108
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkCellArray
object to represent cell connectivity
Definition: vtkCellArray.h:179
vtkSmartPointer.h
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:30
vtkNew< vtkIdList >
vtkObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkCellArrayIterator::ReplaceCurrentCell
void ReplaceCurrentCell(vtkIdList *list)
Specialized methods for performing operations on the vtkCellArray.
Definition: vtkCellArrayIterator.h:214
vtkCellArrayIterator::GetCurrentCell
void GetCurrentCell(vtkIdType &cellSize, vtkIdType const *&cellPoints)
Returns the definition of the current cell during forward traversal.
Definition: vtkCellArrayIterator.h:176
vtkCellArrayIterator::GoToFirstCell
void GoToFirstCell()
The following are methods supporting forward iteration.
Definition: vtkCellArrayIterator.h:146
vtkObject.h
vtkCellArrayIterator::GetCellAtId
void GetCellAtId(vtkIdType cellId, vtkIdType &numCellPts, vtkIdType const *&cellPts)
The following are methods supporting random access iteration.
Definition: vtkCellArrayIterator.h:121
vtkCellArrayIterator::GetCellAtId
void GetCellAtId(vtkIdType cellId, vtkIdList *cellIds)
Definition: vtkCellArrayIterator.h:126
vtkCellArrayIterator::GetCellAtId
vtkIdList * GetCellAtId(vtkIdType cellId)
Definition: vtkCellArrayIterator.h:131
vtkCellArrayIterator::CellArray
vtkSmartPointer< vtkCellArray > CellArray
Definition: vtkCellArrayIterator.h:246
vtkIdList.h
vtkCellArrayIterator::TempCell
vtkNew< vtkIdList > TempCell
Definition: vtkCellArrayIterator.h:249