VTK  9.1.0
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 
171 
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
vtkCellArrayIterator::GoToNextCell
void GoToNextCell()
Advance the forward iterator to the next cell.
Definition: vtkCellArrayIterator.h:214
vtkCellArrayIterator::ReplaceCurrentCell
void ReplaceCurrentCell(vtkIdType npts, const vtkIdType *pts)
Replace the current cell with the ids in pts.
Definition: vtkCellArrayIterator.h:284
vtkCellArrayIterator::CurrentCellId
vtkIdType CurrentCellId
Definition: vtkCellArrayIterator.h:309
vtkCellArrayIterator::~vtkCellArrayIterator
~vtkCellArrayIterator() override=default
vtkCellArrayIterator::GetCurrentCell
void GetCurrentCell(vtkIdList *ids)
Returns the definition of the current cell during forward traversal.
Definition: vtkCellArrayIterator.h:250
vtkCellArrayIterator::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instantiation, type information, and printing.
vtkIdType
int vtkIdType
Definition: vtkType.h:332
vtkCellArrayIterator::ReverseCurrentCell
void ReverseCurrentCell()
Reverses the order of the point ids in the current cell.
Definition: vtkCellArrayIterator.h:293
vtkCellArrayIterator::GetCurrentCell
vtkIdList * GetCurrentCell()
Returns the definition of the current cell during forward traversal.
Definition: vtkCellArrayIterator.h:255
vtkCellArray.h
vtkCellArrayIterator::GetCurrentCellId
vtkIdType GetCurrentCellId() const
Returns the id of the current cell during forward iteration.
Definition: vtkCellArrayIterator.h:224
vtkSmartPointer< vtkCellArray >
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:82
vtkCellArrayIterator::NumberOfCells
vtkIdType NumberOfCells
Definition: vtkCellArrayIterator.h:310
vtkCellArrayIterator::GetCellArray
vtkCellArray * GetCellArray()
Return the vtkCellArray object over which iteration is occuring.
Definition: vtkCellArrayIterator.h:152
vtkCellArrayIterator::GoToCell
void GoToCell(vtkIdType cellId)
Intialize the iterator to a specific cell.
Definition: vtkCellArrayIterator.h:160
vtkCellArrayIterator
Encapsulate traversal logic for vtkCellArray.
Definition: vtkCellArrayIterator.h:138
vtkCellArrayIterator::IsDoneWithTraversal
bool IsDoneWithTraversal()
Returns true if the iterator has completed the traversal.
Definition: vtkCellArrayIterator.h:219
vtkCellArray::vtkCellArrayIterator
friend class vtkCellArrayIterator
Definition: vtkCellArray.h:1264
vtkCellArrayIterator::vtkCellArrayIterator
vtkCellArrayIterator()=default
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:113
vtkCellArray
object to represent cell connectivity
Definition: vtkCellArray.h:290
vtkSmartPointer.h
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:140
vtkNew< vtkIdList >
vtkCellArrayIterator::ReplaceCurrentCell
void ReplaceCurrentCell(vtkIdList *list)
Specialized methods for performing operations on the vtkCellArray.
Definition: vtkCellArrayIterator.h:273
vtkCellArrayIterator::GetCurrentCell
void GetCurrentCell(vtkIdType &cellSize, vtkIdType const *&cellPoints)
Returns the definition of the current cell during forward traversal.
Definition: vtkCellArrayIterator.h:235
vtkCellArrayIterator::GoToFirstCell
void GoToFirstCell()
The following are methods supporting forward iteration.
Definition: vtkCellArrayIterator.h:205
vtkObject.h
vtkCellArrayIterator::GetCellAtId
void GetCellAtId(vtkIdType cellId, vtkIdType &numCellPts, vtkIdType const *&cellPts)
The following are methods supporting random access iteration.
Definition: vtkCellArrayIterator.h:180
vtkCellArrayIterator::New
static vtkCellArrayIterator * New()
Standard methods for instantiation, type information, and printing.
vtkCellArrayIterator::GetCellAtId
void GetCellAtId(vtkIdType cellId, vtkIdList *cellIds)
The following are methods supporting random access iteration.
Definition: vtkCellArrayIterator.h:185
vtkCellArrayIterator::GetCellAtId
vtkIdList * GetCellAtId(vtkIdType cellId)
The following are methods supporting random access iteration.
Definition: vtkCellArrayIterator.h:190
vtkCellArrayIterator::CellArray
vtkSmartPointer< vtkCellArray > CellArray
Definition: vtkCellArrayIterator.h:305
vtkIdList.h
vtkCellArrayIterator::TempCell
vtkNew< vtkIdList > TempCell
Definition: vtkCellArrayIterator.h:308