VTK  9.3.0
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 "vtkCellType.h" // For VTK_EMPTY_CELL
60 #include "vtkCommonDataModelModule.h" // For export macro
61 #include "vtkIdList.h" // For inline methods
62 #include "vtkNew.h" // For vtkNew
63 #include "vtkObject.h"
64 
65 VTK_ABI_NAMESPACE_BEGIN
66 class vtkGenericCell;
67 class vtkPoints;
68 
69 class VTKCOMMONDATAMODEL_EXPORT vtkCellIterator : public vtkObject
70 {
71 public:
72  void PrintSelf(ostream& os, vtkIndent indent) override;
74 
78  void InitTraversal();
79 
83  void GoToNextCell();
84 
88  virtual bool IsDoneWithTraversal() = 0;
89 
94  int GetCellType();
95 
101 
105  virtual vtkIdType GetCellId() = 0;
106 
111  vtkIdList* GetPointIds();
112 
118  vtkPoints* GetPoints();
119 
124  vtkIdList* GetFaces();
125 
131  void GetCell(vtkGenericCell* cell);
132 
137  vtkIdType GetNumberOfPoints();
138 
143  vtkIdType GetNumberOfFaces();
144 
145 protected:
147  ~vtkCellIterator() override;
148 
152  virtual void ResetToFirstCell() = 0;
153 
157  virtual void IncrementToNextCell() = 0;
158 
162  virtual void FetchCellType() = 0;
163 
167  virtual void FetchPointIds() = 0;
168 
172  virtual void FetchPoints() = 0;
173 
180  virtual void FetchFaces() {}
181 
182  int CellType;
186 
187 private:
188  vtkCellIterator(const vtkCellIterator&) = delete;
189  void operator=(const vtkCellIterator&) = delete;
190 
191  enum
192  {
193  UninitializedFlag = 0x0,
194  CellTypeFlag = 0x1,
195  PointIdsFlag = 0x2,
196  PointsFlag = 0x4,
197  FacesFlag = 0x8
198  };
199 
200  void ResetCache()
201  {
202  this->CacheFlags = UninitializedFlag;
203  this->CellType = VTK_EMPTY_CELL;
204  }
205 
206  void SetCache(unsigned char flags) { this->CacheFlags |= flags; }
207 
208  bool CheckCache(unsigned char flags) { return (this->CacheFlags & flags) == flags; }
209 
210  vtkNew<vtkPoints> PointsContainer;
211  vtkNew<vtkIdList> PointIdsContainer;
212  vtkNew<vtkIdList> FacesContainer;
213  unsigned char CacheFlags;
214 };
215 
216 //------------------------------------------------------------------------------
218 {
219  this->ResetToFirstCell();
220  this->ResetCache();
221 }
222 
223 //------------------------------------------------------------------------------
225 {
226  this->IncrementToNextCell();
227  this->ResetCache();
228 }
229 
230 //------------------------------------------------------------------------------
232 {
233  if (!this->CheckCache(CellTypeFlag))
234  {
235  this->FetchCellType();
236  this->SetCache(CellTypeFlag);
237  }
238  return this->CellType;
239 }
240 
241 //------------------------------------------------------------------------------
243 {
244  if (!this->CheckCache(PointIdsFlag))
245  {
246  this->FetchPointIds();
247  this->SetCache(PointIdsFlag);
248  }
249  return this->PointIds;
250 }
251 
252 //------------------------------------------------------------------------------
254 {
255  if (!this->CheckCache(PointsFlag))
256  {
257  this->FetchPoints();
258  this->SetCache(PointsFlag);
259  }
260  return this->Points;
261 }
262 
263 //------------------------------------------------------------------------------
265 {
266  if (!this->CheckCache(FacesFlag))
267  {
268  this->FetchFaces();
269  this->SetCache(FacesFlag);
270  }
271  return this->Faces;
272 }
273 
274 //------------------------------------------------------------------------------
276 {
277  if (!this->CheckCache(PointIdsFlag))
278  {
279  this->FetchPointIds();
280  this->SetCache(PointIdsFlag);
281  }
282  return this->PointIds->GetNumberOfIds();
283 }
284 
285 //------------------------------------------------------------------------------
287 {
288  switch (this->GetCellType())
289  {
290  case VTK_EMPTY_CELL:
291  case VTK_VERTEX:
292  case VTK_POLY_VERTEX:
293  case VTK_LINE:
294  case VTK_POLY_LINE:
295  case VTK_TRIANGLE:
296  case VTK_TRIANGLE_STRIP:
297  case VTK_POLYGON:
298  case VTK_PIXEL:
299  case VTK_QUAD:
300  case VTK_QUADRATIC_EDGE:
302  case VTK_QUADRATIC_QUAD:
307  case VTK_CUBIC_LINE:
317  case VTK_LAGRANGE_CURVE:
320  case VTK_BEZIER_CURVE:
321  case VTK_BEZIER_TRIANGLE:
323  return 0;
324 
325  case VTK_TETRA:
326  case VTK_QUADRATIC_TETRA:
331  return 4;
332 
333  case VTK_PYRAMID:
337  case VTK_WEDGE:
338  case VTK_QUADRATIC_WEDGE:
342  case VTK_LAGRANGE_WEDGE:
343  case VTK_BEZIER_WEDGE:
344  return 5;
345 
346  case VTK_VOXEL:
347  case VTK_HEXAHEDRON:
355  return 6;
356 
358  return 7;
359 
360  case VTK_HEXAGONAL_PRISM:
361  return 8;
362 
363  case VTK_POLYHEDRON: // Need to look these up
364  if (!this->CheckCache(FacesFlag))
365  {
366  this->FetchFaces();
367  this->SetCache(FacesFlag);
368  }
369  return this->Faces->GetNumberOfIds() != 0 ? this->Faces->GetId(0) : 0;
370 
371  default:
372  vtkGenericWarningMacro("Unknown cell type: " << this->CellType);
373  break;
374  }
375 
376  return 0;
377 }
378 
379 VTK_ABI_NAMESPACE_END
380 #endif // vtkCellIterator_h
Efficient cell iterator for vtkDataSet topologies.
int GetCellDimension()
Get the current cell dimension (0, 1, 2, or 3).
virtual void FetchPoints()=0
Lookup the cell points in the data set and store them in this->Points.
void GetCell(vtkGenericCell *cell)
Write the current full cell information into the argument.
virtual void FetchPointIds()=0
Lookup the cell point ids in the data set and store them in this->PointIds.
vtkIdType GetNumberOfFaces()
Return the number of faces in the current cell.
vtkIdList * GetFaces()
Get the faces for a polyhedral cell.
void InitTraversal()
Reset to the first cell.
vtkAbstractTypeMacro(vtkCellIterator, vtkObject)
vtkIdList * Faces
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkPoints * GetPoints()
Get the points in the current cell.
vtkIdList * PointIds
virtual void FetchCellType()=0
Lookup the cell type in the data set and store it in this->CellType.
vtkIdType GetNumberOfPoints()
Return the number of points in the current cell.
virtual void IncrementToNextCell()=0
Update internal state to point to the next cell.
virtual vtkIdType GetCellId()=0
Get the id of the current cell.
virtual void ResetToFirstCell()=0
Update internal state to point to the first cell.
vtkIdList * GetPointIds()
Get the ids of the points in the current cell.
int GetCellType()
Get the current cell type (e.g.
virtual void FetchFaces()
Lookup the cell faces in the data set and store them in this->Faces.
void GoToNextCell()
Increment to next cell.
virtual bool IsDoneWithTraversal()=0
Returns false while the iterator is valid.
vtkPoints * Points
~vtkCellIterator() override
provides thread-safe access to cells
list of point or cell ids
Definition: vtkIdList.h:23
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition: vtkIdList.h:49
vtkIdType GetId(vtkIdType i)
Return the id at location i.
Definition: vtkIdList.h:54
a simple class to control print indentation
Definition: vtkIndent.h:29
abstract base class for most VTK objects
Definition: vtkObject.h:52
represent and manipulate 3D points
Definition: vtkPoints.h:29
int GetCellType(const Ioss::ElementTopology *topology)
Returns VTK celltype for a Ioss topology element.
@ VTK_VOXEL
Definition: vtkCellType.h:48
@ VTK_QUADRATIC_HEXAHEDRON
Definition: vtkCellType.h:61
@ VTK_PARAMETRIC_SURFACE
Definition: vtkCellType.h:84
@ VTK_HIGHER_ORDER_TETRAHEDRON
Definition: vtkCellType.h:95
@ VTK_TRIANGLE_STRIP
Definition: vtkCellType.h:43
@ VTK_BIQUADRATIC_QUADRATIC_HEXAHEDRON
Definition: vtkCellType.h:70
@ VTK_LAGRANGE_CURVE
Definition: vtkCellType.h:101
@ VTK_HIGHER_ORDER_QUAD
Definition: vtkCellType.h:93
@ VTK_PYRAMID
Definition: vtkCellType.h:51
@ VTK_PIXEL
Definition: vtkCellType.h:45
@ VTK_QUADRATIC_WEDGE
Definition: vtkCellType.h:62
@ VTK_BEZIER_WEDGE
Definition: vtkCellType.h:115
@ VTK_BIQUADRATIC_QUAD
Definition: vtkCellType.h:64
@ VTK_HIGHER_ORDER_WEDGE
Definition: vtkCellType.h:96
@ VTK_LAGRANGE_QUADRILATERAL
Definition: vtkCellType.h:103
@ VTK_POLY_LINE
Definition: vtkCellType.h:41
@ VTK_TRIQUADRATIC_PYRAMID
Definition: vtkCellType.h:66
@ VTK_TRIANGLE
Definition: vtkCellType.h:42
@ VTK_BEZIER_TRIANGLE
Definition: vtkCellType.h:111
@ VTK_POLYGON
Definition: vtkCellType.h:44
@ VTK_EMPTY_CELL
Definition: vtkCellType.h:37
@ VTK_QUADRATIC_PYRAMID
Definition: vtkCellType.h:63
@ VTK_POLYHEDRON
Definition: vtkCellType.h:80
@ VTK_TRIQUADRATIC_HEXAHEDRON
Definition: vtkCellType.h:65
@ VTK_TETRA
Definition: vtkCellType.h:47
@ VTK_LINE
Definition: vtkCellType.h:40
@ VTK_CONVEX_POINT_SET
Definition: vtkCellType.h:77
@ VTK_BEZIER_HEXAHEDRON
Definition: vtkCellType.h:114
@ VTK_PARAMETRIC_TRI_SURFACE
Definition: vtkCellType.h:85
@ VTK_LAGRANGE_WEDGE
Definition: vtkCellType.h:106
@ VTK_LAGRANGE_HEXAHEDRON
Definition: vtkCellType.h:105
@ VTK_PENTAGONAL_PRISM
Definition: vtkCellType.h:52
@ VTK_HIGHER_ORDER_TRIANGLE
Definition: vtkCellType.h:92
@ VTK_QUADRATIC_QUAD
Definition: vtkCellType.h:58
@ VTK_WEDGE
Definition: vtkCellType.h:50
@ VTK_PARAMETRIC_QUAD_SURFACE
Definition: vtkCellType.h:86
@ VTK_LAGRANGE_TETRAHEDRON
Definition: vtkCellType.h:104
@ VTK_PARAMETRIC_CURVE
Definition: vtkCellType.h:83
@ VTK_BEZIER_CURVE
Definition: vtkCellType.h:110
@ VTK_HIGHER_ORDER_PYRAMID
Definition: vtkCellType.h:97
@ VTK_HEXAGONAL_PRISM
Definition: vtkCellType.h:53
@ VTK_PARAMETRIC_HEX_REGION
Definition: vtkCellType.h:88
@ VTK_BEZIER_QUADRILATERAL
Definition: vtkCellType.h:112
@ VTK_QUADRATIC_LINEAR_WEDGE
Definition: vtkCellType.h:68
@ VTK_HEXAHEDRON
Definition: vtkCellType.h:49
@ VTK_CUBIC_LINE
Definition: vtkCellType.h:74
@ VTK_LAGRANGE_TRIANGLE
Definition: vtkCellType.h:102
@ VTK_HIGHER_ORDER_HEXAHEDRON
Definition: vtkCellType.h:98
@ VTK_QUADRATIC_POLYGON
Definition: vtkCellType.h:59
@ VTK_QUAD
Definition: vtkCellType.h:46
@ VTK_QUADRATIC_TRIANGLE
Definition: vtkCellType.h:57
@ VTK_PARAMETRIC_TETRA_REGION
Definition: vtkCellType.h:87
@ VTK_QUADRATIC_EDGE
Definition: vtkCellType.h:56
@ VTK_QUADRATIC_TETRA
Definition: vtkCellType.h:60
@ VTK_HIGHER_ORDER_EDGE
Definition: vtkCellType.h:91
@ VTK_BEZIER_TETRAHEDRON
Definition: vtkCellType.h:113
@ VTK_VERTEX
Definition: vtkCellType.h:38
@ VTK_POLY_VERTEX
Definition: vtkCellType.h:39
@ VTK_QUADRATIC_LINEAR_QUAD
Definition: vtkCellType.h:67
@ VTK_BIQUADRATIC_QUADRATIC_WEDGE
Definition: vtkCellType.h:69
@ VTK_HIGHER_ORDER_POLYGON
Definition: vtkCellType.h:94
@ VTK_BIQUADRATIC_TRIANGLE
Definition: vtkCellType.h:71
int vtkIdType
Definition: vtkType.h:315