VTK  9.7.1
vtkCellIterator.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 
56 #ifndef vtkCellIterator_h
57 #define vtkCellIterator_h
58 
59 #include "vtkCellArray.h" // For inline methods
60 #include "vtkCellType.h" // For VTK_EMPTY_CELL
61 #include "vtkCommonDataModelModule.h" // For export macro
62 #include "vtkIdList.h" // For inline methods
63 #include "vtkIdTypeArray.h" // For inline methods
64 #include "vtkNew.h" // For vtkNew
65 #include "vtkObject.h"
66 
67 VTK_ABI_NAMESPACE_BEGIN
68 class vtkGenericCell;
69 class vtkPoints;
70 
71 class VTKCOMMONDATAMODEL_EXPORT vtkCellIterator : public vtkObject
72 {
73 public:
74  void PrintSelf(ostream& os, vtkIndent indent) override;
75  vtkAbstractTypeMacro(vtkCellIterator, vtkObject);
76 
80  void InitTraversal();
81 
85  void GoToNextCell();
86 
90  virtual bool IsDoneWithTraversal() = 0;
91 
96  int GetCellType();
97 
102  int GetCellDimension();
103 
107  virtual vtkIdType GetCellId() = 0;
108 
113  vtkIdList* GetPointIds();
114 
120  vtkPoints* GetPoints();
121 
126  vtkCellArray* GetCellFaces();
127 
132  vtkIdList* GetSerializedCellFaces();
133 
139  void GetCell(vtkGenericCell* cell);
140 
145  vtkIdType GetNumberOfPoints();
146 
151  vtkIdType GetNumberOfFaces();
152 
153 protected:
154  vtkCellIterator();
155  ~vtkCellIterator() override;
156 
160  virtual void ResetToFirstCell() = 0;
161 
165  virtual void IncrementToNextCell() = 0;
166 
170  virtual void FetchCellType() = 0;
171 
175  virtual void FetchPointIds() = 0;
176 
180  virtual void FetchPoints() = 0;
181 
188  virtual void FetchFaces() {}
189 
190  int CellType;
194 
195 private:
196  vtkCellIterator(const vtkCellIterator&) = delete;
197  void operator=(const vtkCellIterator&) = delete;
198 
199  enum
200  {
201  UninitializedFlag = 0x0,
202  CellTypeFlag = 0x1,
203  PointIdsFlag = 0x2,
204  PointsFlag = 0x4,
205  FacesFlag = 0x8
206  };
207 
208  void ResetCache()
209  {
210  this->CacheFlags = UninitializedFlag;
211  this->CellType = VTK_EMPTY_CELL;
212  }
213 
214  void SetCache(unsigned char flags) { this->CacheFlags |= flags; }
215 
216  bool CheckCache(unsigned char flags) { return (this->CacheFlags & flags) == flags; }
217 
218  vtkNew<vtkPoints> PointsContainer;
219  vtkNew<vtkIdList> PointIdsContainer;
220  vtkNew<vtkCellArray> FacesContainer;
221  vtkNew<vtkIdList> LegacyFacesContainer;
222  unsigned char CacheFlags;
223 };
224 
225 //------------------------------------------------------------------------------
227 {
228  this->ResetToFirstCell();
229  this->ResetCache();
230 }
231 
232 //------------------------------------------------------------------------------
234 {
235  this->IncrementToNextCell();
236  this->ResetCache();
237 }
238 
239 //------------------------------------------------------------------------------
241 {
242  if (!this->CheckCache(CellTypeFlag))
243  {
244  this->FetchCellType();
245  this->SetCache(CellTypeFlag);
246  }
247  return this->CellType;
248 }
249 
250 //------------------------------------------------------------------------------
252 {
253  if (!this->CheckCache(PointIdsFlag))
254  {
255  this->FetchPointIds();
256  this->SetCache(PointIdsFlag);
257  }
258  return this->PointIds;
259 }
260 
261 //------------------------------------------------------------------------------
263 {
264  if (!this->CheckCache(PointsFlag))
265  {
266  this->FetchPoints();
267  this->SetCache(PointsFlag);
268  }
269  return this->Points;
270 }
271 
272 //------------------------------------------------------------------------------
274 {
275  if (!this->CheckCache(FacesFlag))
276  {
277  this->FetchFaces();
278  this->SetCache(FacesFlag);
279  }
280  return this->Faces;
281 }
282 
283 //------------------------------------------------------------------------------
285 {
286  if (!this->CheckCache(FacesFlag))
287  {
288  this->FetchFaces();
289  this->SetCache(FacesFlag);
290  }
291  // Export Legacy Format
293  this->Faces->ExportLegacyFormat(tmp);
294  this->LegacyFacesContainer->Initialize();
295  this->LegacyFacesContainer->InsertNextId(this->Faces->GetNumberOfCells());
296  for (vtkIdType idx = 0; idx < tmp->GetNumberOfValues(); ++idx)
297  {
298  this->LegacyFacesContainer->InsertNextId(tmp->GetValue(idx));
299  }
300  return this->LegacyFacesContainer;
301 }
302 
303 //------------------------------------------------------------------------------
305 {
306  if (!this->CheckCache(PointIdsFlag))
307  {
308  this->FetchPointIds();
309  this->SetCache(PointIdsFlag);
310  }
311  return this->PointIds->GetNumberOfIds();
312 }
313 
314 //------------------------------------------------------------------------------
316 {
317  switch (this->GetCellType())
318  {
319  case VTK_EMPTY_CELL:
320  case VTK_VERTEX:
321  case VTK_POLY_VERTEX:
322  case VTK_LINE:
323  case VTK_POLY_LINE:
324  case VTK_TRIANGLE:
325  case VTK_TRIANGLE_STRIP:
326  case VTK_POLYGON:
327  case VTK_PIXEL:
328  case VTK_QUAD:
329  case VTK_QUADRATIC_EDGE:
331  case VTK_QUADRATIC_QUAD:
336  case VTK_CUBIC_LINE:
341  case VTK_LAGRANGE_CURVE:
344  case VTK_BEZIER_CURVE:
345  case VTK_BEZIER_TRIANGLE:
347  return 0;
348 
349  case VTK_TETRA:
350  case VTK_QUADRATIC_TETRA:
354  return 4;
355 
356  case VTK_PYRAMID:
360  case VTK_WEDGE:
361  case VTK_QUADRATIC_WEDGE:
365  case VTK_LAGRANGE_WEDGE:
366  case VTK_BEZIER_WEDGE:
367  return 5;
368 
369  case VTK_VOXEL:
370  case VTK_HEXAHEDRON:
377  return 6;
378 
380  return 7;
381 
382  case VTK_HEXAGONAL_PRISM:
383  return 8;
384 
385  case VTK_POLYHEDRON: // Need to look these up
386  if (!this->CheckCache(FacesFlag))
387  {
388  this->FetchFaces();
389  this->SetCache(FacesFlag);
390  }
391  return this->Faces->GetNumberOfCells();
392 
393  default:
394  vtkGenericWarningMacro("Unknown cell type: " << this->CellType);
395  break;
396  }
397 
398  return 0;
399 }
400 
401 VTK_ABI_NAMESPACE_END
402 #endif // vtkCellIterator_h
vtkIdType GetNumberOfFaces()
Return the number of faces in the current cell.
vtkIdType InsertNextId(vtkIdType id)
Add the id specified to the end of the list.
Definition: vtkIdList.h:292
vtkIdType GetNumberOfCells() const override
Get the number of cells in the array.
Definition: vtkCellArray.h:322
abstract base class for most VTK objects
Definition: vtkObject.h:52
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void Initialize()
Release memory and restore to unallocated state.
vtkPoints * Points
vtkCellArray * GetCellFaces()
Get the faces for a polyhedral cell.
ValueType GetValue(vtkIdType valueIdx) const
Get the value at valueIdx.
int vtkIdType
Definition: vtkType.h:363
void ExportLegacyFormat(vtkIdTypeArray *data)
Fill data with the old-style vtkCellArray data layout, e.g.
virtual void FetchCellType()=0
Lookup the cell type in the data set and store it in this->CellType.
virtual void ResetToFirstCell()=0
Update internal state to point to the first cell.
provides thread-safe access to cells
virtual void IncrementToNextCell()=0
Update internal state to point to the next cell.
vtkCellArray * Faces
vtkIdType GetNumberOfValues() const
Get the total number of values in the array.
void GoToNextCell()
Increment to next cell.
VTKIOCATALYSTCONDUIT_EXPORT int GetCellType(const std::string &shape)
Get vtk cell type from conduit shape name throw a runtime_error on unsupported type.
virtual void FetchPointIds()=0
Lookup the cell point ids in the data set and store them in this->PointIds.
a simple class to control print indentation
Definition: vtkIndent.h:28
list of point or cell ids
Definition: vtkIdList.h:25
vtkIdList * GetPointIds()
Get the ids of the points in the current cell.
virtual void FetchFaces()
Lookup the cell faces in the data set and store them in this->Faces.
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition: vtkIdList.h:76
vtkIdList * GetSerializedCellFaces()
Get a serialized view of the faces for a polyhedral cell.
object to represent cell connectivity
Definition: vtkCellArray.h:177
int GetCellType()
Get the current cell type (e.g.
void InitTraversal()
Reset to the first cell.
vtkPoints * GetPoints()
Get the points in the current cell.
virtual void FetchPoints()=0
Lookup the cell points in the data set and store them in this->Points.
Efficient cell iterator for vtkDataSet topologies.
vtkIdList * PointIds
represent and manipulate 3D points
Definition: vtkPoints.h:30
vtkIdType GetNumberOfPoints()
Return the number of points in the current cell.