VTK  9.2.5
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
78class VTKCOMMONDATAMODEL_EXPORT vtkCellArrayIterator : public vtkObject
79{
80public:
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
113
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
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
242protected:
244 ~vtkCellArrayIterator() override = default;
245
246 vtkSetMacro(CellArray, vtkCellArray*);
247
252
253private:
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
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.
void GoToCell(vtkIdType cellId)
Initialize the iterator to a specific cell.
vtkIdList * GetCellAtId(vtkIdType cellId)
The following are methods supporting random access iteration.
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.
vtkIdList * GetCurrentCell()
Returns the definition of the current cell during forward traversal.
vtkIdType GetCurrentCellId() const
Returns the id of the current cell during forward iteration.
vtkCellArray * GetCellArray()
Return the vtkCellArray object over which iteration is occurring.
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.
static vtkCellArrayIterator * New()
Standard methods for instantiation, type information, and printing.
void GoToFirstCell()
The following are methods supporting forward iteration.
object to represent cell connectivity
Definition: vtkCellArray.h:187
list of point or cell ids
Definition: vtkIdList.h:34
a simple class to control print indentation
Definition: vtkIndent.h:40
Allocate and hold a VTK object.
Definition: vtkNew.h:62
abstract base class for most VTK objects
Definition: vtkObject.h:63
Hold a reference to a vtkObjectBase instance.
int vtkIdType
Definition: vtkType.h:332