VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/Common/DataModel/vtkCellArray.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkCellArray.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 =========================================================================*/
00040 #ifndef vtkCellArray_h
00041 #define vtkCellArray_h
00042 
00043 #include "vtkCommonDataModelModule.h" // For export macro
00044 #include "vtkObject.h"
00045 
00046 #include "vtkIdTypeArray.h" // Needed for inline methods
00047 #include "vtkCell.h" // Needed for inline methods
00048 
00049 class VTKCOMMONDATAMODEL_EXPORT vtkCellArray : public vtkObject
00050 {
00051 public:
00052   vtkTypeMacro(vtkCellArray,vtkObject);
00053   void PrintSelf(ostream& os, vtkIndent indent);
00054 
00056   static vtkCellArray *New();
00057 
00059 
00060   int Allocate(const vtkIdType sz, const int ext=1000)
00061     {return this->Ia->Allocate(sz,ext);}
00063 
00065   void Initialize();
00066 
00068 
00069   vtkGetMacro(NumberOfCells, vtkIdType);
00071 
00073 
00075   vtkSetMacro(NumberOfCells, vtkIdType);
00077 
00079 
00085   vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell)
00086     {return numCells*(1+maxPtsPerCell);}
00088 
00092   void InitTraversal() {this->TraversalLocation=0;};
00093 
00098   int GetNextCell(vtkIdType& npts, vtkIdType* &pts);
00099 
00103   int GetNextCell(vtkIdList *pts);
00104 
00106 
00107   vtkIdType GetSize()
00108     {return this->Ia->GetSize();}
00110 
00112 
00115   vtkIdType GetNumberOfConnectivityEntries()
00116     {return this->Ia->GetMaxId()+1;}
00118 
00121   void GetCell(vtkIdType loc, vtkIdType &npts, vtkIdType* &pts);
00122 
00125   void GetCell(vtkIdType loc, vtkIdList* pts);
00126 
00128   vtkIdType InsertNextCell(vtkCell *cell);
00129 
00132   vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts);
00133 
00136   vtkIdType InsertNextCell(vtkIdList *pts);
00137 
00142   vtkIdType InsertNextCell(int npts);
00143 
00146   void InsertCellPoint(vtkIdType id);
00147 
00150   void UpdateCellCount(int npts);
00151 
00153 
00155   vtkIdType GetInsertLocation(int npts)
00156     {return (this->InsertLocation - npts - 1);};
00158 
00160 
00161   vtkIdType GetTraversalLocation()
00162     {return this->TraversalLocation;}
00163   void SetTraversalLocation(vtkIdType loc)
00164     {this->TraversalLocation = loc;}
00166 
00168 
00170   vtkIdType GetTraversalLocation(vtkIdType npts)
00171     {return(this->TraversalLocation-npts-1);}
00173 
00176   void ReverseCell(vtkIdType loc);
00177 
00179   void ReplaceCell(vtkIdType loc, int npts, const vtkIdType *pts);
00180 
00183   int GetMaxCellSize();
00184 
00186 
00187   vtkIdType *GetPointer()
00188     {return this->Ia->GetPointer(0);}
00190 
00194   vtkIdType *WritePointer(const vtkIdType ncells, const vtkIdType size);
00195 
00203   void SetCells(vtkIdType ncells, vtkIdTypeArray *cells);
00204 
00206   void DeepCopy(vtkCellArray *ca);
00207 
00209 
00210   vtkIdTypeArray* GetData()
00211     {return this->Ia;}
00213 
00215   void Reset();
00216 
00218 
00219   void Squeeze()
00220     {this->Ia->Squeeze();}
00222 
00229   unsigned long GetActualMemorySize();
00230 
00231 protected:
00232   vtkCellArray();
00233   ~vtkCellArray();
00234 
00235   vtkIdType NumberOfCells;
00236   vtkIdType InsertLocation;     //keep track of current insertion point
00237   vtkIdType TraversalLocation;   //keep track of traversal position
00238   vtkIdTypeArray *Ia;
00239 
00240 private:
00241   vtkCellArray(const vtkCellArray&);  // Not implemented.
00242   void operator=(const vtkCellArray&);  // Not implemented.
00243 };
00244 
00245 
00246 //----------------------------------------------------------------------------
00247 inline vtkIdType vtkCellArray::InsertNextCell(vtkIdType npts,
00248                                               const vtkIdType* pts)
00249 {
00250   vtkIdType i = this->Ia->GetMaxId() + 1;
00251   vtkIdType *ptr = this->Ia->WritePointer(i, npts+1);
00252 
00253   for ( *ptr++ = npts, i = 0; i < npts; i++)
00254     {
00255     *ptr++ = *pts++;
00256     }
00257 
00258   this->NumberOfCells++;
00259   this->InsertLocation += npts + 1;
00260 
00261   return this->NumberOfCells - 1;
00262 }
00263 
00264 //----------------------------------------------------------------------------
00265 inline vtkIdType vtkCellArray::InsertNextCell(int npts)
00266 {
00267   this->InsertLocation = this->Ia->InsertNextValue(npts) + 1;
00268   this->NumberOfCells++;
00269 
00270   return this->NumberOfCells - 1;
00271 }
00272 
00273 //----------------------------------------------------------------------------
00274 inline void vtkCellArray::InsertCellPoint(vtkIdType id)
00275 {
00276   this->Ia->InsertValue(this->InsertLocation++, id);
00277 }
00278 
00279 //----------------------------------------------------------------------------
00280 inline void vtkCellArray::UpdateCellCount(int npts)
00281 {
00282   this->Ia->SetValue(this->InsertLocation-npts-1, npts);
00283 }
00284 
00285 //----------------------------------------------------------------------------
00286 inline vtkIdType vtkCellArray::InsertNextCell(vtkIdList *pts)
00287 {
00288   return this->InsertNextCell(pts->GetNumberOfIds(), pts->GetPointer(0));
00289 }
00290 
00291 //----------------------------------------------------------------------------
00292 inline vtkIdType vtkCellArray::InsertNextCell(vtkCell *cell)
00293 {
00294   return this->InsertNextCell(cell->GetNumberOfPoints(),
00295                               cell->PointIds->GetPointer(0));
00296 }
00297 
00298 //----------------------------------------------------------------------------
00299 inline void vtkCellArray::Reset()
00300 {
00301   this->NumberOfCells = 0;
00302   this->InsertLocation = 0;
00303   this->TraversalLocation = 0;
00304   this->Ia->Reset();
00305 }
00306 
00307 //----------------------------------------------------------------------------
00308 inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType* &pts)
00309 {
00310   if ( this->Ia->GetMaxId() >= 0 &&
00311        this->TraversalLocation <= this->Ia->GetMaxId() )
00312     {
00313     npts = this->Ia->GetValue(this->TraversalLocation++);
00314     pts = this->Ia->GetPointer(this->TraversalLocation);
00315     this->TraversalLocation += npts;
00316     return 1;
00317     }
00318   npts=0;
00319   pts=0;
00320   return 0;
00321 }
00322 
00323 //----------------------------------------------------------------------------
00324 inline void vtkCellArray::GetCell(vtkIdType loc, vtkIdType &npts,
00325                                   vtkIdType* &pts)
00326 {
00327   npts = this->Ia->GetValue(loc++);
00328   pts  = this->Ia->GetPointer(loc);
00329 }
00330 
00331 //----------------------------------------------------------------------------
00332 inline void vtkCellArray::ReverseCell(vtkIdType loc)
00333 {
00334   int i;
00335   vtkIdType tmp;
00336   vtkIdType npts=this->Ia->GetValue(loc);
00337   vtkIdType *pts=this->Ia->GetPointer(loc+1);
00338   for (i=0; i < (npts/2); i++)
00339     {
00340     tmp = pts[i];
00341     pts[i] = pts[npts-i-1];
00342     pts[npts-i-1] = tmp;
00343     }
00344 }
00345 
00346 //----------------------------------------------------------------------------
00347 inline void vtkCellArray::ReplaceCell(vtkIdType loc, int npts,
00348                                       const vtkIdType *pts)
00349 {
00350   vtkIdType *oldPts=this->Ia->GetPointer(loc+1);
00351   for (int i=0; i < npts; i++)
00352     {
00353     oldPts[i] = pts[i];
00354     }
00355 }
00356 
00357 //----------------------------------------------------------------------------
00358 inline vtkIdType *vtkCellArray::WritePointer(const vtkIdType ncells,
00359                                              const vtkIdType size)
00360 {
00361   this->NumberOfCells = ncells;
00362   this->InsertLocation = 0;
00363   this->TraversalLocation = 0;
00364   return this->Ia->WritePointer(0,size);
00365 }
00366 
00367 #endif