VTK  9.2.6
vtkCellIterator.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkCellIterator.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 
77 #ifndef vtkCellIterator_h
78 #define vtkCellIterator_h
79 
80 #include "vtkCellType.h" // For VTK_EMPTY_CELL
81 #include "vtkCommonDataModelModule.h" // For export macro
82 #include "vtkIdList.h" // For inline methods
83 #include "vtkNew.h" // For vtkNew
84 #include "vtkObject.h"
85 
86 class vtkGenericCell;
87 class vtkPoints;
88 
89 class VTKCOMMONDATAMODEL_EXPORT vtkCellIterator : public vtkObject
90 {
91 public:
92  void PrintSelf(ostream& os, vtkIndent indent) override;
94 
98  void InitTraversal();
99 
103  void GoToNextCell();
104 
108  virtual bool IsDoneWithTraversal() = 0;
109 
114  int GetCellType();
115 
121 
125  virtual vtkIdType GetCellId() = 0;
126 
131  vtkIdList* GetPointIds();
132 
138  vtkPoints* GetPoints();
139 
144  vtkIdList* GetFaces();
145 
151  void GetCell(vtkGenericCell* cell);
152 
157  vtkIdType GetNumberOfPoints();
158 
163  vtkIdType GetNumberOfFaces();
164 
165 protected:
167  ~vtkCellIterator() override;
168 
172  virtual void ResetToFirstCell() = 0;
173 
177  virtual void IncrementToNextCell() = 0;
178 
182  virtual void FetchCellType() = 0;
183 
187  virtual void FetchPointIds() = 0;
188 
192  virtual void FetchPoints() = 0;
193 
200  virtual void FetchFaces() {}
201 
202  int CellType;
206 
207 private:
208  vtkCellIterator(const vtkCellIterator&) = delete;
209  void operator=(const vtkCellIterator&) = delete;
210 
211  enum
212  {
213  UninitializedFlag = 0x0,
214  CellTypeFlag = 0x1,
215  PointIdsFlag = 0x2,
216  PointsFlag = 0x4,
217  FacesFlag = 0x8
218  };
219 
220  void ResetCache()
221  {
222  this->CacheFlags = UninitializedFlag;
223  this->CellType = VTK_EMPTY_CELL;
224  }
225 
226  void SetCache(unsigned char flags) { this->CacheFlags |= flags; }
227 
228  bool CheckCache(unsigned char flags) { return (this->CacheFlags & flags) == flags; }
229 
230  vtkNew<vtkPoints> PointsContainer;
231  vtkNew<vtkIdList> PointIdsContainer;
232  vtkNew<vtkIdList> FacesContainer;
233  unsigned char CacheFlags;
234 };
235 
236 //------------------------------------------------------------------------------
238 {
239  this->ResetToFirstCell();
240  this->ResetCache();
241 }
242 
243 //------------------------------------------------------------------------------
245 {
246  this->IncrementToNextCell();
247  this->ResetCache();
248 }
249 
250 //------------------------------------------------------------------------------
252 {
253  if (!this->CheckCache(CellTypeFlag))
254  {
255  this->FetchCellType();
256  this->SetCache(CellTypeFlag);
257  }
258  return this->CellType;
259 }
260 
261 //------------------------------------------------------------------------------
263 {
264  if (!this->CheckCache(PointIdsFlag))
265  {
266  this->FetchPointIds();
267  this->SetCache(PointIdsFlag);
268  }
269  return this->PointIds;
270 }
271 
272 //------------------------------------------------------------------------------
274 {
275  if (!this->CheckCache(PointsFlag))
276  {
277  this->FetchPoints();
278  this->SetCache(PointsFlag);
279  }
280  return this->Points;
281 }
282 
283 //------------------------------------------------------------------------------
285 {
286  if (!this->CheckCache(FacesFlag))
287  {
288  this->FetchFaces();
289  this->SetCache(FacesFlag);
290  }
291  return this->Faces;
292 }
293 
294 //------------------------------------------------------------------------------
296 {
297  if (!this->CheckCache(PointIdsFlag))
298  {
299  this->FetchPointIds();
300  this->SetCache(PointIdsFlag);
301  }
302  return this->PointIds->GetNumberOfIds();
303 }
304 
305 //------------------------------------------------------------------------------
307 {
308  switch (this->GetCellType())
309  {
310  case VTK_EMPTY_CELL:
311  case VTK_VERTEX:
312  case VTK_POLY_VERTEX:
313  case VTK_LINE:
314  case VTK_POLY_LINE:
315  case VTK_TRIANGLE:
316  case VTK_TRIANGLE_STRIP:
317  case VTK_POLYGON:
318  case VTK_PIXEL:
319  case VTK_QUAD:
320  case VTK_QUADRATIC_EDGE:
322  case VTK_QUADRATIC_QUAD:
327  case VTK_CUBIC_LINE:
337  case VTK_LAGRANGE_CURVE:
340  case VTK_BEZIER_CURVE:
341  case VTK_BEZIER_TRIANGLE:
343  return 0;
344 
345  case VTK_TETRA:
346  case VTK_QUADRATIC_TETRA:
351  return 4;
352 
353  case VTK_PYRAMID:
357  case VTK_WEDGE:
358  case VTK_QUADRATIC_WEDGE:
362  case VTK_LAGRANGE_WEDGE:
363  case VTK_BEZIER_WEDGE:
364  return 5;
365 
366  case VTK_VOXEL:
367  case VTK_HEXAHEDRON:
375  return 6;
376 
378  return 7;
379 
380  case VTK_HEXAGONAL_PRISM:
381  return 8;
382 
383  case VTK_POLYHEDRON: // Need to look these up
384  if (!this->CheckCache(FacesFlag))
385  {
386  this->FetchFaces();
387  this->SetCache(FacesFlag);
388  }
389  return this->Faces->GetNumberOfIds() != 0 ? this->Faces->GetId(0) : 0;
390 
391  default:
392  vtkGenericWarningMacro("Unknown cell type: " << this->CellType);
393  break;
394  }
395 
396  return 0;
397 }
398 
399 #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:43
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition: vtkIdList.h:69
vtkIdType GetId(const vtkIdType i)
Return the id at location i.
Definition: vtkIdList.h:74
a simple class to control print indentation
Definition: vtkIndent.h:49
abstract base class for most VTK objects
Definition: vtkObject.h:72
represent and manipulate 3D points
Definition: vtkPoints.h:49
int GetCellType(const Ioss::ElementTopology *topology)
Returns VTK celltype for a Ioss topology element.
@ VTK_VOXEL
Definition: vtkCellType.h:57
@ VTK_QUADRATIC_HEXAHEDRON
Definition: vtkCellType.h:70
@ VTK_PARAMETRIC_SURFACE
Definition: vtkCellType.h:93
@ VTK_HIGHER_ORDER_TETRAHEDRON
Definition: vtkCellType.h:104
@ VTK_TRIANGLE_STRIP
Definition: vtkCellType.h:52
@ VTK_BIQUADRATIC_QUADRATIC_HEXAHEDRON
Definition: vtkCellType.h:79
@ VTK_LAGRANGE_CURVE
Definition: vtkCellType.h:110
@ VTK_HIGHER_ORDER_QUAD
Definition: vtkCellType.h:102
@ VTK_PYRAMID
Definition: vtkCellType.h:60
@ VTK_PIXEL
Definition: vtkCellType.h:54
@ VTK_QUADRATIC_WEDGE
Definition: vtkCellType.h:71
@ VTK_BEZIER_WEDGE
Definition: vtkCellType.h:124
@ VTK_BIQUADRATIC_QUAD
Definition: vtkCellType.h:73
@ VTK_HIGHER_ORDER_WEDGE
Definition: vtkCellType.h:105
@ VTK_LAGRANGE_QUADRILATERAL
Definition: vtkCellType.h:112
@ VTK_POLY_LINE
Definition: vtkCellType.h:50
@ VTK_TRIQUADRATIC_PYRAMID
Definition: vtkCellType.h:75
@ VTK_TRIANGLE
Definition: vtkCellType.h:51
@ VTK_BEZIER_TRIANGLE
Definition: vtkCellType.h:120
@ VTK_POLYGON
Definition: vtkCellType.h:53
@ VTK_EMPTY_CELL
Definition: vtkCellType.h:46
@ VTK_QUADRATIC_PYRAMID
Definition: vtkCellType.h:72
@ VTK_POLYHEDRON
Definition: vtkCellType.h:89
@ VTK_TRIQUADRATIC_HEXAHEDRON
Definition: vtkCellType.h:74
@ VTK_TETRA
Definition: vtkCellType.h:56
@ VTK_LINE
Definition: vtkCellType.h:49
@ VTK_CONVEX_POINT_SET
Definition: vtkCellType.h:86
@ VTK_BEZIER_HEXAHEDRON
Definition: vtkCellType.h:123
@ VTK_PARAMETRIC_TRI_SURFACE
Definition: vtkCellType.h:94
@ VTK_LAGRANGE_WEDGE
Definition: vtkCellType.h:115
@ VTK_LAGRANGE_HEXAHEDRON
Definition: vtkCellType.h:114
@ VTK_PENTAGONAL_PRISM
Definition: vtkCellType.h:61
@ VTK_HIGHER_ORDER_TRIANGLE
Definition: vtkCellType.h:101
@ VTK_QUADRATIC_QUAD
Definition: vtkCellType.h:67
@ VTK_WEDGE
Definition: vtkCellType.h:59
@ VTK_PARAMETRIC_QUAD_SURFACE
Definition: vtkCellType.h:95
@ VTK_LAGRANGE_TETRAHEDRON
Definition: vtkCellType.h:113
@ VTK_PARAMETRIC_CURVE
Definition: vtkCellType.h:92
@ VTK_BEZIER_CURVE
Definition: vtkCellType.h:119
@ VTK_HIGHER_ORDER_PYRAMID
Definition: vtkCellType.h:106
@ VTK_HEXAGONAL_PRISM
Definition: vtkCellType.h:62
@ VTK_PARAMETRIC_HEX_REGION
Definition: vtkCellType.h:97
@ VTK_BEZIER_QUADRILATERAL
Definition: vtkCellType.h:121
@ VTK_QUADRATIC_LINEAR_WEDGE
Definition: vtkCellType.h:77
@ VTK_HEXAHEDRON
Definition: vtkCellType.h:58
@ VTK_CUBIC_LINE
Definition: vtkCellType.h:83
@ VTK_LAGRANGE_TRIANGLE
Definition: vtkCellType.h:111
@ VTK_HIGHER_ORDER_HEXAHEDRON
Definition: vtkCellType.h:107
@ VTK_QUADRATIC_POLYGON
Definition: vtkCellType.h:68
@ VTK_QUAD
Definition: vtkCellType.h:55
@ VTK_QUADRATIC_TRIANGLE
Definition: vtkCellType.h:66
@ VTK_PARAMETRIC_TETRA_REGION
Definition: vtkCellType.h:96
@ VTK_QUADRATIC_EDGE
Definition: vtkCellType.h:65
@ VTK_QUADRATIC_TETRA
Definition: vtkCellType.h:69
@ VTK_HIGHER_ORDER_EDGE
Definition: vtkCellType.h:100
@ VTK_BEZIER_TETRAHEDRON
Definition: vtkCellType.h:122
@ VTK_VERTEX
Definition: vtkCellType.h:47
@ VTK_POLY_VERTEX
Definition: vtkCellType.h:48
@ VTK_QUADRATIC_LINEAR_QUAD
Definition: vtkCellType.h:76
@ VTK_BIQUADRATIC_QUADRATIC_WEDGE
Definition: vtkCellType.h:78
@ VTK_HIGHER_ORDER_POLYGON
Definition: vtkCellType.h:103
@ VTK_BIQUADRATIC_TRIANGLE
Definition: vtkCellType.h:80
int vtkIdType
Definition: vtkType.h:332