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

Common/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_COMMON_EXPORT vtkCellArray : public vtkObject
00049 {
00050 public:
00051   vtkTypeRevisionMacro(vtkCellArray,vtkObject);
00052 
00054   static vtkCellArray *New();
00055 
00057 
00058   int Allocate(const vtkIdType sz, const int ext=1000) 
00059     {return this->Ia->Allocate(sz,ext);}
00061 
00063 
00064   void Initialize() 
00065     {this->Ia->Initialize();}
00067 
00069 
00070   vtkIdType GetNumberOfCells() 
00071     {return this->NumberOfCells;}
00073 
00075 
00081   vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell)
00082     {return numCells*(1+maxPtsPerCell);}
00084 
00088   void InitTraversal() {this->TraversalLocation=0;};
00089 
00093   int GetNextCell(vtkIdType& npts, vtkIdType* &pts);
00094 
00096 
00097   vtkIdType GetSize() 
00098     {return this->Ia->GetSize();}
00100   
00102 
00105   vtkIdType GetNumberOfConnectivityEntries() 
00106     {return this->Ia->GetMaxId()+1;}
00108 
00111   void GetCell(vtkIdType loc, vtkIdType &npts, vtkIdType* &pts);
00112 
00114   vtkIdType InsertNextCell(vtkCell *cell);
00115 
00118   vtkIdType InsertNextCell(vtkIdType npts, vtkIdType* pts);
00119 
00122   vtkIdType InsertNextCell(vtkIdList *pts);
00123 
00128   vtkIdType InsertNextCell(int npts);
00129 
00132   void InsertCellPoint(vtkIdType id);
00133 
00136   void UpdateCellCount(int npts);
00137 
00139 
00141   vtkIdType GetInsertLocation(int npts)
00142     {return (this->InsertLocation - npts - 1);};
00144   
00146 
00147   vtkIdType GetTraversalLocation() 
00148     {return this->TraversalLocation;}
00149   void SetTraversalLocation(vtkIdType loc) 
00150     {this->TraversalLocation = loc;}
00152   
00154 
00156   vtkIdType GetTraversalLocation(vtkIdType npts) 
00157     {return(this->TraversalLocation-npts-1);}
00159   
00162   void ReverseCell(vtkIdType loc);
00163 
00165   void ReplaceCell(vtkIdType loc, int npts, vtkIdType *pts);
00166 
00169   int GetMaxCellSize();
00170 
00172 
00173   vtkIdType *GetPointer() 
00174     {return this->Ia->GetPointer(0);}
00176 
00180   vtkIdType *WritePointer(const vtkIdType ncells, const vtkIdType size);
00181 
00189   void SetCells(vtkIdType ncells, vtkIdTypeArray *cells);
00190   
00192   void DeepCopy(vtkCellArray *ca);
00193 
00195 
00196   vtkIdTypeArray* GetData() 
00197     {return this->Ia;}
00199 
00201   void Reset();
00202 
00204 
00205   void Squeeze() 
00206     {this->Ia->Squeeze();}
00208 
00215   unsigned long GetActualMemorySize();
00216   
00217 protected:
00218   vtkCellArray();
00219   ~vtkCellArray();
00220 
00221   vtkIdType NumberOfCells;
00222   vtkIdType InsertLocation;     //keep track of current insertion point
00223   vtkIdType TraversalLocation;   //keep track of traversal position
00224   vtkIdTypeArray *Ia;
00225 private:
00226   vtkCellArray(const vtkCellArray&);  // Not implemented.
00227   void operator=(const vtkCellArray&);  // Not implemented.
00228 };
00229 
00230 
00231 inline vtkIdType vtkCellArray::InsertNextCell(vtkIdType npts, vtkIdType* pts)
00232 {
00233   vtkIdType i = this->Ia->GetMaxId() + 1;
00234   vtkIdType *ptr = this->Ia->WritePointer(i, npts+1);
00235   
00236   for ( *ptr++ = npts, i = 0; i < npts; i++)
00237     {
00238     *ptr++ = *pts++;
00239     }
00240 
00241   this->NumberOfCells++;
00242   this->InsertLocation += npts + 1;
00243 
00244   return this->NumberOfCells - 1;
00245 }
00246 
00247 inline vtkIdType vtkCellArray::InsertNextCell(vtkIdList *pts)
00248 {
00249   vtkIdType npts = pts->GetNumberOfIds();
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->GetId(i);
00256     }
00257 
00258   this->NumberOfCells++;
00259   this->InsertLocation += npts + 1;
00260 
00261   return this->NumberOfCells - 1;
00262 }
00263 
00264 inline vtkIdType vtkCellArray::InsertNextCell(int npts)
00265 {
00266   this->InsertLocation = this->Ia->InsertNextValue(npts) + 1;
00267   this->NumberOfCells++;
00268 
00269   return this->NumberOfCells - 1;
00270 }
00271 
00272 inline void vtkCellArray::InsertCellPoint(vtkIdType id) 
00273 {
00274   this->Ia->InsertValue(this->InsertLocation++, id);
00275 }
00276 
00277 inline void vtkCellArray::UpdateCellCount(int npts) 
00278 {
00279   this->Ia->SetValue(this->InsertLocation-npts-1, npts);
00280 }
00281 
00282 inline vtkIdType vtkCellArray::InsertNextCell(vtkCell *cell)
00283 {
00284   int npts = cell->GetNumberOfPoints();
00285   vtkIdType i = this->Ia->GetMaxId() + 1;
00286   vtkIdType *ptr = this->Ia->WritePointer(i,npts+1);
00287   
00288   for ( *ptr++ = npts, i = 0; i < npts; i++)
00289     {
00290     *ptr++ = cell->PointIds->GetId(i);
00291     }
00292 
00293   this->NumberOfCells++;
00294   this->InsertLocation += npts + 1;
00295 
00296   return this->NumberOfCells - 1;
00297 }
00298 
00299 
00300 inline void vtkCellArray::Reset() 
00301 {
00302   this->NumberOfCells = 0;
00303   this->InsertLocation = 0;
00304   this->TraversalLocation = 0;
00305   this->Ia->Reset();
00306 }
00307 
00308 
00309 inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType* &pts)
00310 {
00311   if ( this->Ia->GetMaxId() >= 0 && 
00312   this->TraversalLocation <= this->Ia->GetMaxId() ) 
00313     {
00314     npts = this->Ia->GetValue(this->TraversalLocation++);
00315     pts = this->Ia->GetPointer(this->TraversalLocation);
00316     this->TraversalLocation += npts;
00317     return 1;
00318     }
00319   else
00320     {
00321     return 0;
00322     }
00323 }
00324 
00325 inline void vtkCellArray::GetCell(vtkIdType loc, vtkIdType &npts,
00326                                   vtkIdType* &pts)
00327 {
00328   npts=this->Ia->GetValue(loc++);
00329   pts=this->Ia->GetPointer(loc);
00330 }
00331 
00332 
00333 inline void vtkCellArray::ReverseCell(vtkIdType loc)
00334 {
00335   int i;
00336   vtkIdType tmp;
00337   vtkIdType npts=this->Ia->GetValue(loc);
00338   vtkIdType *pts=this->Ia->GetPointer(loc+1);
00339   for (i=0; i < (npts/2); i++) 
00340     {
00341     tmp = pts[i];
00342     pts[i] = pts[npts-i-1];
00343     pts[npts-i-1] = tmp;
00344     }
00345 }
00346 
00347 inline void vtkCellArray::ReplaceCell(vtkIdType loc, int npts, vtkIdType *pts)
00348 {
00349   vtkIdType *oldPts=this->Ia->GetPointer(loc+1);
00350   for (int i=0; i < npts; i++)
00351     {
00352     oldPts[i] = pts[i];
00353     }
00354 }
00355 
00356 inline vtkIdType *vtkCellArray::WritePointer(const vtkIdType ncells,
00357                                              const vtkIdType size)
00358 {
00359   this->NumberOfCells = ncells;
00360   this->InsertLocation = 0;
00361   this->TraversalLocation = 0;
00362   return this->Ia->WritePointer(0,size);
00363 }
00364 
00365 #endif