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 
68 #ifndef vtkCellIterator_h
69 #define vtkCellIterator_h
70 
71 #include "vtkCellType.h" // For VTK_EMPTY_CELL
72 #include "vtkCommonDataModelModule.h" // For export macro
73 #include "vtkIdList.h" // For inline methods
74 #include "vtkNew.h" // For vtkNew
75 #include "vtkObject.h"
76 
77 class vtkGenericCell;
78 class vtkPoints;
79 
80 class VTKCOMMONDATAMODEL_EXPORT vtkCellIterator : public vtkObject
81 {
82 public:
83  void PrintSelf(ostream& os, vtkIndent indent) override;
84  vtkAbstractTypeMacro(vtkCellIterator, vtkObject);
85 
89  void InitTraversal();
90 
94  void GoToNextCell();
95 
99  virtual bool IsDoneWithTraversal() = 0;
100 
105  int GetCellType();
106 
111  int GetCellDimension();
112 
116  virtual vtkIdType GetCellId() = 0;
117 
122  vtkIdList* GetPointIds();
123 
129  vtkPoints* GetPoints();
130 
135  vtkIdList* GetFaces();
136 
142  void GetCell(vtkGenericCell* cell);
143 
148  vtkIdType GetNumberOfPoints();
149 
154  vtkIdType GetNumberOfFaces();
155 
156 protected:
157  vtkCellIterator();
158  ~vtkCellIterator() override;
159 
163  virtual void ResetToFirstCell() = 0;
164 
168  virtual void IncrementToNextCell() = 0;
169 
173  virtual void FetchCellType() = 0;
174 
178  virtual void FetchPointIds() = 0;
179 
183  virtual void FetchPoints() = 0;
184 
191  virtual void FetchFaces() {}
192 
193  int CellType;
197 
198 private:
199  vtkCellIterator(const vtkCellIterator&) = delete;
200  void operator=(const vtkCellIterator&) = delete;
201 
202  enum
203  {
204  UninitializedFlag = 0x0,
205  CellTypeFlag = 0x1,
206  PointIdsFlag = 0x2,
207  PointsFlag = 0x4,
208  FacesFlag = 0x8
209  };
210 
211  void ResetCache()
212  {
213  this->CacheFlags = UninitializedFlag;
214  this->CellType = VTK_EMPTY_CELL;
215  }
216 
217  void SetCache(unsigned char flags) { this->CacheFlags |= flags; }
218 
219  bool CheckCache(unsigned char flags) { return (this->CacheFlags & flags) == flags; }
220 
221  vtkNew<vtkPoints> PointsContainer;
222  vtkNew<vtkIdList> PointIdsContainer;
223  vtkNew<vtkIdList> FacesContainer;
224  unsigned char CacheFlags;
225 };
226 
227 //------------------------------------------------------------------------------
229 {
230  this->ResetToFirstCell();
231  this->ResetCache();
232 }
233 
234 //------------------------------------------------------------------------------
236 {
237  this->IncrementToNextCell();
238  this->ResetCache();
239 }
240 
241 //------------------------------------------------------------------------------
243 {
244  if (!this->CheckCache(CellTypeFlag))
245  {
246  this->FetchCellType();
247  this->SetCache(CellTypeFlag);
248  }
249  return this->CellType;
250 }
251 
252 //------------------------------------------------------------------------------
254 {
255  if (!this->CheckCache(PointIdsFlag))
256  {
257  this->FetchPointIds();
258  this->SetCache(PointIdsFlag);
259  }
260  return this->PointIds;
261 }
262 
263 //------------------------------------------------------------------------------
265 {
266  if (!this->CheckCache(PointsFlag))
267  {
268  this->FetchPoints();
269  this->SetCache(PointsFlag);
270  }
271  return this->Points;
272 }
273 
274 //------------------------------------------------------------------------------
276 {
277  if (!this->CheckCache(FacesFlag))
278  {
279  this->FetchFaces();
280  this->SetCache(FacesFlag);
281  }
282  return this->Faces;
283 }
284 
285 //------------------------------------------------------------------------------
287 {
288  if (!this->CheckCache(PointIdsFlag))
289  {
290  this->FetchPointIds();
291  this->SetCache(PointIdsFlag);
292  }
293  return this->PointIds->GetNumberOfIds();
294 }
295 
296 //------------------------------------------------------------------------------
298 {
299  switch (this->GetCellType())
300  {
301  case VTK_EMPTY_CELL:
302  case VTK_VERTEX:
303  case VTK_POLY_VERTEX:
304  case VTK_LINE:
305  case VTK_POLY_LINE:
306  case VTK_TRIANGLE:
307  case VTK_TRIANGLE_STRIP:
308  case VTK_POLYGON:
309  case VTK_PIXEL:
310  case VTK_QUAD:
311  case VTK_QUADRATIC_EDGE:
313  case VTK_QUADRATIC_QUAD:
318  case VTK_CUBIC_LINE:
328  case VTK_LAGRANGE_CURVE:
331  case VTK_BEZIER_CURVE:
332  case VTK_BEZIER_TRIANGLE:
334  return 0;
335 
336  case VTK_TETRA:
337  case VTK_QUADRATIC_TETRA:
342  return 4;
343 
344  case VTK_PYRAMID:
348  case VTK_WEDGE:
349  case VTK_QUADRATIC_WEDGE:
353  case VTK_LAGRANGE_WEDGE:
354  case VTK_BEZIER_WEDGE:
355  return 5;
356 
357  case VTK_VOXEL:
358  case VTK_HEXAHEDRON:
366  return 6;
367 
369  return 7;
370 
371  case VTK_HEXAGONAL_PRISM:
372  return 8;
373 
374  case VTK_POLYHEDRON: // Need to look these up
375  if (!this->CheckCache(FacesFlag))
376  {
377  this->FetchFaces();
378  this->SetCache(FacesFlag);
379  }
380  return this->Faces->GetNumberOfIds() != 0 ? this->Faces->GetId(0) : 0;
381 
382  default:
383  vtkGenericWarningMacro("Unknown cell type: " << this->CellType);
384  break;
385  }
386 
387  return 0;
388 }
389 
390 #endif // vtkCellIterator_h
vtkIdType GetNumberOfFaces()
Return the number of faces in the current cell.
abstract base class for most VTK objects
Definition: vtkObject.h:62
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkPoints * Points
int vtkIdType
Definition: vtkType.h:332
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.
void GoToNextCell()
Increment to next cell.
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:39
list of point or cell ids
Definition: vtkIdList.h:33
vtkIdList * GetPointIds()
Get the ids of the points in the current cell.
vtkIdList * GetFaces()
Get the faces for a polyhedral 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:60
int GetCellType(const Ioss::ElementTopology *topology)
Returns VTK celltype for a Ioss topology element.
vtkIdType GetId(const vtkIdType i)
Return the id at location i.
Definition: vtkIdList.h:65
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.
vtkIdList * Faces
Efficient cell iterator for vtkDataSet topologies.
vtkIdList * PointIds
represent and manipulate 3D points
Definition: vtkPoints.h:39
vtkIdType GetNumberOfPoints()
Return the number of points in the current cell.