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 "vtkObject.h"
72 #include "vtkNew.h" // For vtkNew
73 #include "vtkIdList.h" // For inline methods
74 
75 class vtkGenericCell;
76 class vtkPoints;
77 
78 class VTKCOMMONDATAMODEL_EXPORT vtkCellIterator : public vtkObject
79 {
80 public:
81  virtual void PrintSelf(ostream &os, vtkIndent indent);
82  vtkAbstractTypeMacro(vtkCellIterator, vtkObject)
83 
85  void InitTraversal();
86 
88  void GoToNextCell();
89 
91  virtual bool IsDoneWithTraversal() = 0;
92 
96  int GetCellType();
97 
99  virtual vtkIdType GetCellId() = 0;
100 
103  vtkIdList *GetPointIds();
104 
108  vtkPoints *GetPoints();
109 
111  vtkIdList *GetFaces();
112 
116  void GetCell(vtkGenericCell *cell);
117 
120  vtkIdType GetNumberOfPoints();
121 
124  vtkIdType GetNumberOfFaces();
125 
126 protected:
127  vtkCellIterator();
128  ~vtkCellIterator();
129 
131  virtual void ResetToFirstCell() = 0;
132 
134  virtual void IncrementToNextCell() = 0;
135 
137  virtual void FetchCellType() = 0;
138 
141  virtual void FetchPointIds() = 0;
142 
145  virtual void FetchPoints() = 0;
146 
151  virtual void FetchFaces() { }
152 
153  int CellType;
154  vtkPoints *Points;
155  vtkIdList *PointIds;
156  vtkIdList *Faces;
157 
158 private:
159  vtkCellIterator(const vtkCellIterator &); // Not implemented.
160  void operator=(const vtkCellIterator &); // Not implemented.
161 
162  enum
163  {
164  UninitializedFlag = 0x0,
165  CellTypeFlag = 0x1,
166  PointIdsFlag = 0x2,
167  PointsFlag = 0x4,
168  FacesFlag = 0x8
169  };
170 
171  void ResetCache()
172  {
173  this->CacheFlags = UninitializedFlag;
174  this->ResetContainers();
175  }
176 
177  void SetCache(unsigned char flags)
178  {
179  this->CacheFlags |= flags;
180  }
181 
182  bool CheckCache(unsigned char flags)
183  {
184  return (this->CacheFlags & flags) == flags;
185  }
186 
187  void ResetContainers();
188 
189  vtkNew<vtkPoints> PointsContainer;
190  vtkNew<vtkIdList> PointIdsContainer;
191  vtkNew<vtkIdList> FacesContainer;
192  unsigned char CacheFlags;
193 };
194 
195 //------------------------------------------------------------------------------
196 inline void vtkCellIterator::InitTraversal()
197 {
198  this->ResetToFirstCell();
199  this->ResetCache();
200 }
201 
202 //------------------------------------------------------------------------------
203 inline void vtkCellIterator::GoToNextCell()
204 {
205  this->IncrementToNextCell();
206  this->ResetCache();
207 }
208 
209 //------------------------------------------------------------------------------
210 inline int vtkCellIterator::GetCellType()
211 {
212  if (!this->CheckCache(CellTypeFlag))
213  {
214  this->FetchCellType();
215  this->SetCache(CellTypeFlag);
216  }
217  return this->CellType;
218 }
219 
220 //------------------------------------------------------------------------------
221 inline vtkIdList* vtkCellIterator::GetPointIds()
222 {
223  if (!this->CheckCache(PointIdsFlag))
224  {
225  this->FetchPointIds();
226  this->SetCache(PointIdsFlag);
227  }
228  return this->PointIds;
229 }
230 
231 //------------------------------------------------------------------------------
232 inline vtkPoints* vtkCellIterator::GetPoints()
233 {
234  if (!this->CheckCache(PointsFlag))
235  {
236  this->FetchPoints();
237  this->SetCache(PointsFlag);
238  }
239  return this->Points;
240 }
241 
242 //------------------------------------------------------------------------------
243 inline vtkIdList *vtkCellIterator::GetFaces()
244 {
245  if (!this->CheckCache(FacesFlag))
246  {
247  this->FetchFaces();
248  this->SetCache(FacesFlag);
249  }
250  return this->Faces;
251 }
252 
253 //------------------------------------------------------------------------------
254 inline vtkIdType vtkCellIterator::GetNumberOfPoints()
255 {
256  if (!this->CheckCache(PointIdsFlag))
257  {
258  this->FetchPointIds();
259  this->SetCache(PointIdsFlag);
260  }
261  return this->PointIds->GetNumberOfIds();
262 }
263 
264 //------------------------------------------------------------------------------
265 inline vtkIdType vtkCellIterator::GetNumberOfFaces()
266 {
267  if (!this->CheckCache(FacesFlag))
268  {
269  this->FetchFaces();
270  this->SetCache(FacesFlag);
271  }
272  return this->Faces->GetNumberOfIds() != 0 ? this->Faces->GetId(0) : 0;
273 }
274 
275 #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()