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 
40  }
41 
42  vtkIdList *pointIds = it->GetPointIds();
43  /* Do screening on the point ids, maybe figure out scalar range and skip
44  cells that do not lie in a certain range? */
45 
46  vtkPoints *points = it->GetPoints();
47  /* Do work using the cell points, or ... */
48 
49  vtkGenericCell *cell = ...;
50  it->GetCell(cell);
51  /* ... do work with a vtkCell. */
52  }
53  it->Delete();
54  }
55  ~~~
56 
57  The example above pulls in bits of information as needed to filter out cells
58  that aren't relevent. The least expensive lookups are performed first
59  (cell type, then point ids, then points/full cell) to prevent wasted cycles
60  fetching unnecessary data. Also note that at the end of the loop, the
61  iterator must be deleted as these iterators are vtkObject subclasses.
62 
63  @par Tests:
64  @ref c2_vtk_t_vtkCellIterator "vtkCellIterator (Tests)"
65 */
66 
67 #ifndef vtkCellIterator_h
68 #define vtkCellIterator_h
69 
70 #include "vtkCommonDataModelModule.h" // For export macro
71 #include "vtkCellType.h" // For VTK_EMPTY_CELL
72 #include "vtkObject.h"
73 #include "vtkNew.h" // For vtkNew
74 #include "vtkIdList.h" // For inline methods
75 
76 class vtkGenericCell;
77 class vtkPoints;
78 
79 class VTKCOMMONDATAMODEL_EXPORT vtkCellIterator : public vtkObject
80 {
81 public:
82  virtual void PrintSelf(ostream &os, vtkIndent indent);
83  vtkAbstractTypeMacro(vtkCellIterator, vtkObject)
84 
86  void InitTraversal();
87 
89  void GoToNextCell();
90 
92  virtual bool IsDoneWithTraversal() = 0;
93 
97  int GetCellType();
98 
100  virtual vtkIdType GetCellId() = 0;
101 
104  vtkIdList *GetPointIds();
105 
109  vtkPoints *GetPoints();
110 
112  vtkIdList *GetFaces();
113 
117  void GetCell(vtkGenericCell *cell);
118 
121  vtkIdType GetNumberOfPoints();
122 
125  vtkIdType GetNumberOfFaces();
126 
127 protected:
128  vtkCellIterator();
129  ~vtkCellIterator();
130 
132  virtual void ResetToFirstCell() = 0;
133 
135  virtual void IncrementToNextCell() = 0;
136 
138  virtual void FetchCellType() = 0;
139 
142  virtual void FetchPointIds() = 0;
143 
146  virtual void FetchPoints() = 0;
147 
152  virtual void FetchFaces() { }
153 
154  int CellType;
155  vtkPoints *Points;
156  vtkIdList *PointIds;
157  vtkIdList *Faces;
158 
159 private:
160  vtkCellIterator(const vtkCellIterator &); // Not implemented.
161  void operator=(const vtkCellIterator &); // Not implemented.
162 
163  enum
164  {
165  UninitializedFlag = 0x0,
166  CellTypeFlag = 0x1,
167  PointIdsFlag = 0x2,
168  PointsFlag = 0x4,
169  FacesFlag = 0x8
170  };
171 
172  void ResetCache()
173  {
174  this->CacheFlags = UninitializedFlag;
175  this->CellType = VTK_EMPTY_CELL;
176  }
177 
178  void SetCache(unsigned char flags)
179  {
180  this->CacheFlags |= flags;
181  }
182 
183  bool CheckCache(unsigned char flags)
184  {
185  return (this->CacheFlags & flags) == flags;
186  }
187 
188  vtkNew<vtkPoints> PointsContainer;
189  vtkNew<vtkIdList> PointIdsContainer;
190  vtkNew<vtkIdList> FacesContainer;
191  unsigned char CacheFlags;
192 };
193 
194 //------------------------------------------------------------------------------
195 inline void vtkCellIterator::InitTraversal()
196 {
197  this->ResetToFirstCell();
198  this->ResetCache();
199 }
200 
201 //------------------------------------------------------------------------------
202 inline void vtkCellIterator::GoToNextCell()
203 {
204  this->IncrementToNextCell();
205  this->ResetCache();
206 }
207 
208 //------------------------------------------------------------------------------
209 inline int vtkCellIterator::GetCellType()
210 {
211  if (!this->CheckCache(CellTypeFlag))
212  {
213  this->FetchCellType();
214  this->SetCache(CellTypeFlag);
215  }
216  return this->CellType;
217 }
218 
219 //------------------------------------------------------------------------------
220 inline vtkIdList* vtkCellIterator::GetPointIds()
221 {
222  if (!this->CheckCache(PointIdsFlag))
223  {
224  this->FetchPointIds();
225  this->SetCache(PointIdsFlag);
226  }
227  return this->PointIds;
228 }
229 
230 //------------------------------------------------------------------------------
231 inline vtkPoints* vtkCellIterator::GetPoints()
232 {
233  if (!this->CheckCache(PointsFlag))
234  {
235  this->FetchPoints();
236  this->SetCache(PointsFlag);
237  }
238  return this->Points;
239 }
240 
241 //------------------------------------------------------------------------------
242 inline vtkIdList *vtkCellIterator::GetFaces()
243 {
244  if (!this->CheckCache(FacesFlag))
245  {
246  this->FetchFaces();
247  this->SetCache(FacesFlag);
248  }
249  return this->Faces;
250 }
251 
252 //------------------------------------------------------------------------------
253 inline vtkIdType vtkCellIterator::GetNumberOfPoints()
254 {
255  if (!this->CheckCache(PointIdsFlag))
256  {
257  this->FetchPointIds();
258  this->SetCache(PointIdsFlag);
259  }
260  return this->PointIds->GetNumberOfIds();
261 }
262 
263 //------------------------------------------------------------------------------
264 inline vtkIdType vtkCellIterator::GetNumberOfFaces()
265 {
266  if (!this->CheckCache(FacesFlag))
267  {
268  this->FetchFaces();
269  this->SetCache(FacesFlag);
270  }
271  return this->Faces->GetNumberOfIds() != 0 ? this->Faces->GetId(0) : 0;
272 }
273 
274 #endif //vtkCellIterator_h
provides thread-safe access to cells
list of point or cell ids
Definition: vtkIdList.h:35
represent and manipulate 3D points
Definition: vtkPoints.h:38
virtual void Delete()