VTK
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 
65 #ifndef vtkCellIterator_h
66 #define vtkCellIterator_h
67 
68 #include "vtkCommonDataModelModule.h" // For export macro
69 #include "vtkCellType.h" // For VTK_EMPTY_CELL
70 #include "vtkObject.h"
71 #include "vtkNew.h" // For vtkNew
72 #include "vtkIdList.h" // For inline methods
73 
74 class vtkGenericCell;
75 class vtkPoints;
76 
77 class VTKCOMMONDATAMODEL_EXPORT vtkCellIterator : public vtkObject
78 {
79 public:
80  void PrintSelf(ostream& os, vtkIndent indent) override;
81  vtkAbstractTypeMacro(vtkCellIterator, vtkObject)
82 
83 
86  void InitTraversal();
87 
91  void GoToNextCell();
92 
96  virtual bool IsDoneWithTraversal() = 0;
97 
102  int GetCellType();
103 
108  int GetCellDimension();
109 
113  virtual vtkIdType GetCellId() = 0;
114 
119  vtkIdList *GetPointIds();
120 
126  vtkPoints *GetPoints();
127 
132  vtkIdList *GetFaces();
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)
215  {
216  this->CacheFlags |= flags;
217  }
218 
219  bool CheckCache(unsigned char flags)
220  {
221  return (this->CacheFlags & flags) == flags;
222  }
223 
224  vtkNew<vtkPoints> PointsContainer;
225  vtkNew<vtkIdList> PointIdsContainer;
226  vtkNew<vtkIdList> FacesContainer;
227  unsigned char CacheFlags;
228 };
229 
230 //------------------------------------------------------------------------------
231 inline void vtkCellIterator::InitTraversal()
232 {
233  this->ResetToFirstCell();
234  this->ResetCache();
235 }
236 
237 //------------------------------------------------------------------------------
239 {
240  this->IncrementToNextCell();
241  this->ResetCache();
242 }
243 
244 //------------------------------------------------------------------------------
246 {
247  if (!this->CheckCache(CellTypeFlag))
248  {
249  this->FetchCellType();
250  this->SetCache(CellTypeFlag);
251  }
252  return this->CellType;
253 }
254 
255 //------------------------------------------------------------------------------
257 {
258  if (!this->CheckCache(PointIdsFlag))
259  {
260  this->FetchPointIds();
261  this->SetCache(PointIdsFlag);
262  }
263  return this->PointIds;
264 }
265 
266 //------------------------------------------------------------------------------
268 {
269  if (!this->CheckCache(PointsFlag))
270  {
271  this->FetchPoints();
272  this->SetCache(PointsFlag);
273  }
274  return this->Points;
275 }
276 
277 //------------------------------------------------------------------------------
279 {
280  if (!this->CheckCache(FacesFlag))
281  {
282  this->FetchFaces();
283  this->SetCache(FacesFlag);
284  }
285  return this->Faces;
286 }
287 
288 //------------------------------------------------------------------------------
290 {
291  if (!this->CheckCache(PointIdsFlag))
292  {
293  this->FetchPointIds();
294  this->SetCache(PointIdsFlag);
295  }
296  return this->PointIds->GetNumberOfIds();
297 }
298 
299 //------------------------------------------------------------------------------
301 {
302  switch (this->GetCellType())
303  {
304  case VTK_EMPTY_CELL:
305  case VTK_VERTEX:
306  case VTK_POLY_VERTEX:
307  case VTK_LINE:
308  case VTK_POLY_LINE:
309  case VTK_TRIANGLE:
310  case VTK_TRIANGLE_STRIP:
311  case VTK_POLYGON:
312  case VTK_PIXEL:
313  case VTK_QUAD:
314  case VTK_QUADRATIC_EDGE:
316  case VTK_QUADRATIC_QUAD:
321  case VTK_CUBIC_LINE:
331  return 0;
332 
333  case VTK_TETRA:
334  case VTK_QUADRATIC_TETRA:
337  return 4;
338 
339  case VTK_PYRAMID:
342  case VTK_WEDGE:
343  case VTK_QUADRATIC_WEDGE:
347  return 5;
348 
349  case VTK_VOXEL:
350  case VTK_HEXAHEDRON:
356  return 6;
357 
359  return 7;
360 
361  case VTK_HEXAGONAL_PRISM:
362  return 8;
363 
364  case VTK_POLYHEDRON: // Need to look these up
365  if (!this->CheckCache(FacesFlag))
366  {
367  this->FetchFaces();
368  this->SetCache(FacesFlag);
369  }
370  return this->Faces->GetNumberOfIds() != 0 ? this->Faces->GetId(0) : 0;
371 
372  default:
373  vtkGenericWarningMacro("Unknown cell type: " << this->CellType);
374  break;
375  }
376 
377  return 0;
378 }
379 
380 #endif //vtkCellIterator_h
vtkIdType GetNumberOfFaces()
Return the number of faces in the current cell.
abstract base class for most VTK objects
Definition: vtkObject.h:53
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkIdType GetNumberOfIds()
Return the number of id's in the list.
Definition: vtkIdList.h:50
vtkPoints * Points
int vtkIdType
Definition: vtkType.h:345
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:33
list of point or cell ids
Definition: vtkIdList.h:30
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->Points.
vtkIdType GetId(const vtkIdType i)
Return the id at location i.
Definition: vtkIdList.h:55
int GetCellType()
Get the current cell type (e.g.
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:33
vtkIdType GetNumberOfPoints()
Return the number of points in the current cell.