VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/Common/DataModel/vtkCellIterator.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkCellIterator.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00015 
00040        }
00041 
00042      vtkIdList *pointIds = it->GetPointIds();
00043      /* Do screening on the point ids, maybe figure out scalar range and skip
00044         cells that do not lie in a certain range? */
00045 
00046      vtkPoints *points = it->GetPoints();
00047      /* Do work using the cell points, or ... */
00048 
00049      vtkGenericCell *cell = ...;
00050      it->GetCell(cell);
00051      /* ... do work with a vtkCell. */
00052      }
00053    it->Delete();
00054  }
00055  ~~~
00056 
00057  The example above pulls in bits of information as needed to filter out cells
00058  that aren't relevent. The least expensive lookups are performed first
00059  (cell type, then point ids, then points/full cell) to prevent wasted cycles
00060  fetching unnecessary data. Also note that at the end of the loop, the
00061  iterator must be deleted as these iterators are vtkObject subclasses.
00062 
00063     @par      Tests:
00064               @ref c2_vtk_t_vtkCellIterator "vtkCellIterator (Tests)"
00065 */
00066 
00067 #ifndef vtkCellIterator_h
00068 #define vtkCellIterator_h
00069 
00070 #include "vtkCommonDataModelModule.h" // For export macro
00071 #include "vtkObject.h"
00072 #include "vtkNew.h" // For vtkNew
00073 #include "vtkIdList.h" // For inline methods
00074 
00075 class vtkGenericCell;
00076 class vtkPoints;
00077 
00078 class VTKCOMMONDATAMODEL_EXPORT vtkCellIterator : public vtkObject
00079 {
00080 public:
00081   virtual void PrintSelf(ostream &os, vtkIndent indent);
00082   vtkAbstractTypeMacro(vtkCellIterator, vtkObject)
00083 
00085   void InitTraversal();
00086 
00088   void GoToNextCell();
00089 
00091   virtual bool IsDoneWithTraversal() = 0;
00092 
00096   int GetCellType();
00097 
00099   virtual vtkIdType GetCellId() = 0;
00100 
00103   vtkIdList *GetPointIds();
00104 
00108   vtkPoints *GetPoints();
00109 
00111   vtkIdList *GetFaces();
00112 
00116   void GetCell(vtkGenericCell *cell);
00117 
00120   vtkIdType GetNumberOfPoints();
00121 
00124   vtkIdType GetNumberOfFaces();
00125 
00126 protected:
00127   vtkCellIterator();
00128   ~vtkCellIterator();
00129 
00131   virtual void ResetToFirstCell() = 0;
00132 
00134   virtual void IncrementToNextCell() = 0;
00135 
00137   virtual void FetchCellType() = 0;
00138 
00141   virtual void FetchPointIds() = 0;
00142 
00145   virtual void FetchPoints() = 0;
00146 
00151   virtual void FetchFaces() { }
00152 
00153   int CellType;
00154   vtkPoints *Points;
00155   vtkIdList *PointIds;
00156   vtkIdList *Faces;
00157 
00158 private:
00159   vtkCellIterator(const vtkCellIterator &); // Not implemented.
00160   void operator=(const vtkCellIterator &);   // Not implemented.
00161 
00162   enum
00163     {
00164     UninitializedFlag = 0x0,
00165     CellTypeFlag = 0x1,
00166     PointIdsFlag = 0x2,
00167     PointsFlag = 0x4,
00168     FacesFlag = 0x8
00169     };
00170 
00171   void ResetCache()
00172   {
00173     this->CacheFlags = UninitializedFlag;
00174     this->ResetContainers();
00175   }
00176 
00177   void SetCache(unsigned char flags)
00178   {
00179     this->CacheFlags |= flags;
00180   }
00181 
00182   bool CheckCache(unsigned char flags)
00183   {
00184     return (this->CacheFlags & flags) == flags;
00185   }
00186 
00187   void ResetContainers();
00188 
00189   vtkNew<vtkPoints> PointsContainer;
00190   vtkNew<vtkIdList> PointIdsContainer;
00191   vtkNew<vtkIdList> FacesContainer;
00192   unsigned char CacheFlags;
00193 };
00194 
00195 //------------------------------------------------------------------------------
00196 inline void vtkCellIterator::InitTraversal()
00197 {
00198   this->ResetToFirstCell();
00199   this->ResetCache();
00200 }
00201 
00202 //------------------------------------------------------------------------------
00203 inline void vtkCellIterator::GoToNextCell()
00204 {
00205   this->IncrementToNextCell();
00206   this->ResetCache();
00207 }
00208 
00209 //------------------------------------------------------------------------------
00210 inline int vtkCellIterator::GetCellType()
00211 {
00212   if (!this->CheckCache(CellTypeFlag))
00213     {
00214     this->FetchCellType();
00215     this->SetCache(CellTypeFlag);
00216     }
00217   return this->CellType;
00218 }
00219 
00220 //------------------------------------------------------------------------------
00221 inline vtkIdList* vtkCellIterator::GetPointIds()
00222 {
00223   if (!this->CheckCache(PointIdsFlag))
00224     {
00225     this->FetchPointIds();
00226     this->SetCache(PointIdsFlag);
00227     }
00228   return this->PointIds;
00229 }
00230 
00231 //------------------------------------------------------------------------------
00232 inline vtkPoints* vtkCellIterator::GetPoints()
00233 {
00234   if (!this->CheckCache(PointsFlag))
00235     {
00236     this->FetchPoints();
00237     this->SetCache(PointsFlag);
00238     }
00239   return this->Points;
00240 }
00241 
00242 //------------------------------------------------------------------------------
00243 inline vtkIdList *vtkCellIterator::GetFaces()
00244 {
00245   if (!this->CheckCache(FacesFlag))
00246     {
00247     this->FetchFaces();
00248     this->SetCache(FacesFlag);
00249     }
00250   return this->Faces;
00251 }
00252 
00253 //------------------------------------------------------------------------------
00254 inline vtkIdType vtkCellIterator::GetNumberOfPoints()
00255 {
00256   if (!this->CheckCache(PointIdsFlag))
00257     {
00258     this->FetchPointIds();
00259     this->SetCache(PointIdsFlag);
00260     }
00261   return this->PointIds->GetNumberOfIds();
00262 }
00263 
00264 //------------------------------------------------------------------------------
00265 inline vtkIdType vtkCellIterator::GetNumberOfFaces()
00266 {
00267   if (!this->CheckCache(FacesFlag))
00268     {
00269     this->FetchFaces();
00270     this->SetCache(FacesFlag);
00271     }
00272   return this->Faces->GetNumberOfIds() != 0 ? this->Faces->GetId(0) : 0;
00273 }
00274 
00275 #endif //vtkCellIterator_h