Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

vtkCellArray.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkCellArray.h,v $
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 "vtkObject.h"
00044 
00045 #include "vtkIdTypeArray.h" // Needed for inline methods
00046 #include "vtkCell.h" // Needed for inline methods
00047 
00048 class VTK_FILTERING_EXPORT vtkCellArray : public vtkObject
00049 {
00050 public:
00051   vtkTypeRevisionMacro(vtkCellArray,vtkObject);
00052   void PrintSelf(ostream& os, vtkIndent indent);
00053 
00055   static vtkCellArray *New();
00056 
00058 
00059   int Allocate(const vtkIdType sz, const int ext=1000) 
00060     {return this->Ia->Allocate(sz,ext);}
00062 
00064 
00065   void Initialize() 
00066     {this->Ia->Initialize();}
00068 
00070 
00071   vtkGetMacro(NumberOfCells, vtkIdType);
00073 
00075 
00077   vtkSetMacro(NumberOfCells, vtkIdType);
00079 
00081 
00087   vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell)
00088     {return numCells*(1+maxPtsPerCell);}
00090 
00094   void InitTraversal() {this->TraversalLocation=0;};
00095 
00099   int GetNextCell(vtkIdType& npts, vtkIdType* &pts);
00100 
00102 
00103   vtkIdType GetSize() 
00104     {return this->Ia->GetSize();}
00106   
00108 
00111   vtkIdType GetNumberOfConnectivityEntries() 
00112     {return this->Ia->GetMaxId()+1;}
00114 
00117   void GetCell(vtkIdType loc, vtkIdType &npts, vtkIdType* &pts);
00118 
00120   vtkIdType InsertNextCell(vtkCell *cell);
00121 
00124   vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts);
00125 
00128   vtkIdType InsertNextCell(vtkIdList *pts);
00129 
00134   vtkIdType InsertNextCell(int npts);
00135 
00138   void InsertCellPoint(vtkIdType id);
00139 
00142   void UpdateCellCount(int npts);
00143 
00145 
00147   vtkIdType GetInsertLocation(int npts)
00148     {return (this->InsertLocation - npts - 1);};
00150   
00152 
00153   vtkIdType GetTraversalLocation() 
00154     {return this->TraversalLocation;}
00155   void SetTraversalLocation(vtkIdType loc) 
00156     {this->TraversalLocation = loc;}
00158   
00160 
00162   vtkIdType GetTraversalLocation(vtkIdType npts) 
00163     {return(this->TraversalLocation-npts-1);}
00165   
00168   void ReverseCell(vtkIdType loc);
00169 
00171   void ReplaceCell(vtkIdType loc, int npts, const vtkIdType *pts);
00172 
00175   int GetMaxCellSize();
00176 
00178 
00179   vtkIdType *GetPointer() 
00180     {return this->Ia->GetPointer(0);}
00182 
00186   vtkIdType *WritePointer(const vtkIdType ncells, const vtkIdType size);
00187 
00195   void SetCells(vtkIdType ncells, vtkIdTypeArray *cells);
00196   
00198   void DeepCopy(vtkCellArray *ca);
00199 
00201 
00202   vtkIdTypeArray* GetData() 
00203     {return this->Ia;}
00205 
00207   void Reset();
00208 
00210 
00211   void Squeeze() 
00212     {this->Ia->Squeeze();}
00214 
00221   unsigned long GetActualMemorySize();
00222   
00223 protected:
00224   vtkCellArray();
00225   ~vtkCellArray();
00226 
00227   vtkIdType NumberOfCells;
00228   vtkIdType InsertLocation;     //keep track of current insertion point
00229   vtkIdType TraversalLocation;   //keep track of traversal position
00230   vtkIdTypeArray *Ia;
00231 
00232 private:
00233   vtkCellArray(const vtkCellArray&);  // Not implemented.
00234   void operator=(const vtkCellArray&);  // Not implemented.
00235 };
00236 
00237 
00238 //----------------------------------------------------------------------------
00239 inline vtkIdType vtkCellArray::InsertNextCell(vtkIdType npts,
00240                                               const vtkIdType* pts)
00241 {
00242   vtkIdType i = this->Ia->GetMaxId() + 1;
00243   vtkIdType *ptr = this->Ia->WritePointer(i, npts+1);
00244   
00245   for ( *ptr++ = npts, i = 0; i < npts; i++)
00246     {
00247     *ptr++ = *pts++;
00248     }
00249 
00250   this->NumberOfCells++;
00251   this->InsertLocation += npts + 1;
00252 
00253   return this->NumberOfCells - 1;
00254 }
00255 
00256 //----------------------------------------------------------------------------
00257 inline vtkIdType vtkCellArray::InsertNextCell(vtkIdList *pts)
00258 {
00259   vtkIdType npts = pts->GetNumberOfIds();
00260   vtkIdType i = this->Ia->GetMaxId() + 1;
00261   vtkIdType *ptr = this->Ia->WritePointer(i,npts+1);
00262   
00263   for ( *ptr++ = npts, i = 0; i < npts; i++)
00264     {
00265     *ptr++ = pts->GetId(i);
00266     }
00267 
00268   this->NumberOfCells++;
00269   this->InsertLocation += npts + 1;
00270 
00271   return this->NumberOfCells - 1;
00272 }
00273 
00274 //----------------------------------------------------------------------------
00275 inline vtkIdType vtkCellArray::InsertNextCell(int npts)
00276 {
00277   this->InsertLocation = this->Ia->InsertNextValue(npts) + 1;
00278   this->NumberOfCells++;
00279 
00280   return this->NumberOfCells - 1;
00281 }
00282 
00283 //----------------------------------------------------------------------------
00284 inline void vtkCellArray::InsertCellPoint(vtkIdType id) 
00285 {
00286   this->Ia->InsertValue(this->InsertLocation++, id);
00287 }
00288 
00289 //----------------------------------------------------------------------------
00290 inline void vtkCellArray::UpdateCellCount(int npts) 
00291 {
00292   this->Ia->SetValue(this->InsertLocation-npts-1, npts);
00293 }
00294 
00295 //----------------------------------------------------------------------------
00296 inline vtkIdType vtkCellArray::InsertNextCell(vtkCell *cell)
00297 {
00298   int npts = cell->GetNumberOfPoints();
00299   vtkIdType i = this->Ia->GetMaxId() + 1;
00300   vtkIdType *ptr = this->Ia->WritePointer(i,npts+1);
00301   
00302   for ( *ptr++ = npts, i = 0; i < npts; i++)
00303     {
00304     *ptr++ = cell->PointIds->GetId(i);
00305     }
00306 
00307   this->NumberOfCells++;
00308   this->InsertLocation += npts + 1;
00309 
00310   return this->NumberOfCells - 1;
00311 }
00312 
00313 //----------------------------------------------------------------------------
00314 inline void vtkCellArray::Reset() 
00315 {
00316   this->NumberOfCells = 0;
00317   this->InsertLocation = 0;
00318   this->TraversalLocation = 0;
00319   this->Ia->Reset();
00320 }
00321 
00322 //----------------------------------------------------------------------------
00323 inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType* &pts)
00324 {
00325   if ( this->Ia->GetMaxId() >= 0 && 
00326        this->TraversalLocation <= this->Ia->GetMaxId() ) 
00327     {
00328     npts = this->Ia->GetValue(this->TraversalLocation++);
00329     pts = this->Ia->GetPointer(this->TraversalLocation);
00330     this->TraversalLocation += npts;
00331     return 1;
00332     }
00333   else
00334     {
00335     return 0;
00336     }
00337 }
00338 
00339 //----------------------------------------------------------------------------
00340 inline void vtkCellArray::GetCell(vtkIdType loc, vtkIdType &npts,
00341                                   vtkIdType* &pts)
00342 {
00343   npts = this->Ia->GetValue(loc++);
00344   pts  = this->Ia->GetPointer(loc);
00345 }
00346 
00347 //----------------------------------------------------------------------------
00348 inline void vtkCellArray::ReverseCell(vtkIdType loc)
00349 {
00350   int i;
00351   vtkIdType tmp;
00352   vtkIdType npts=this->Ia->GetValue(loc);
00353   vtkIdType *pts=this->Ia->GetPointer(loc+1);
00354   for (i=0; i < (npts/2); i++) 
00355     {
00356     tmp = pts[i];
00357     pts[i] = pts[npts-i-1];
00358     pts[npts-i-1] = tmp;
00359     }
00360 }
00361 
00362 //----------------------------------------------------------------------------
00363 inline void vtkCellArray::ReplaceCell(vtkIdType loc, int npts,
00364                                       const vtkIdType *pts)
00365 {
00366   vtkIdType *oldPts=this->Ia->GetPointer(loc+1);
00367   for (int i=0; i < npts; i++)
00368     {
00369     oldPts[i] = pts[i];
00370     }
00371 }
00372 
00373 //----------------------------------------------------------------------------
00374 inline vtkIdType *vtkCellArray::WritePointer(const vtkIdType ncells,
00375                                              const vtkIdType size)
00376 {
00377   this->NumberOfCells = ncells;
00378   this->InsertLocation = 0;
00379   this->TraversalLocation = 0;
00380   return this->Ia->WritePointer(0,size);
00381 }
00382 
00383 #endif

Generated on Mon Jan 21 23:07:18 2008 for VTK by  doxygen 1.4.3-20050530