• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

dox/Filtering/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 =========================================================================*/
00037 #ifndef __vtkCellArray_h
00038 #define __vtkCellArray_h
00039 
00040 #include "vtkObject.h"
00041 
00042 #include "vtkIdTypeArray.h" // Needed for inline methods
00043 #include "vtkCell.h" // Needed for inline methods
00044 
00045 class VTK_FILTERING_EXPORT vtkCellArray : public vtkObject
00046 {
00047 public:
00048   vtkTypeRevisionMacro(vtkCellArray,vtkObject);
00049   void PrintSelf(ostream& os, vtkIndent indent);
00050 
00052   static vtkCellArray *New();
00053 
00055 
00056   int Allocate(const vtkIdType sz, const int ext=1000) 
00057     {return this->Ia->Allocate(sz,ext);}
00059 
00061 
00062   void Initialize() 
00063     {this->Ia->Initialize();}
00065 
00067 
00068   vtkGetMacro(NumberOfCells, vtkIdType);
00070 
00072 
00074   vtkSetMacro(NumberOfCells, vtkIdType);
00076 
00078 
00084   vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell)
00085     {return numCells*(1+maxPtsPerCell);}
00087 
00091   void InitTraversal() {this->TraversalLocation=0;};
00092 
00096   int GetNextCell(vtkIdType& npts, vtkIdType* &pts);
00097 
00099 
00100   vtkIdType GetSize() 
00101     {return this->Ia->GetSize();}
00103   
00105 
00108   vtkIdType GetNumberOfConnectivityEntries() 
00109     {return this->Ia->GetMaxId()+1;}
00111 
00114   void GetCell(vtkIdType loc, vtkIdType &npts, vtkIdType* &pts);
00115 
00117   vtkIdType InsertNextCell(vtkCell *cell);
00118 
00121   vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts);
00122 
00125   vtkIdType InsertNextCell(vtkIdList *pts);
00126 
00131   vtkIdType InsertNextCell(int npts);
00132 
00135   void InsertCellPoint(vtkIdType id);
00136 
00139   void UpdateCellCount(int npts);
00140 
00142 
00144   vtkIdType GetInsertLocation(int npts)
00145     {return (this->InsertLocation - npts - 1);};
00147   
00149 
00150   vtkIdType GetTraversalLocation() 
00151     {return this->TraversalLocation;}
00152   void SetTraversalLocation(vtkIdType loc) 
00153     {this->TraversalLocation = loc;}
00155   
00157 
00159   vtkIdType GetTraversalLocation(vtkIdType npts) 
00160     {return(this->TraversalLocation-npts-1);}
00162   
00165   void ReverseCell(vtkIdType loc);
00166 
00168   void ReplaceCell(vtkIdType loc, int npts, const vtkIdType *pts);
00169 
00172   int GetMaxCellSize();
00173 
00175 
00176   vtkIdType *GetPointer() 
00177     {return this->Ia->GetPointer(0);}
00179 
00183   vtkIdType *WritePointer(const vtkIdType ncells, const vtkIdType size);
00184 
00192   void SetCells(vtkIdType ncells, vtkIdTypeArray *cells);
00193   
00195   void DeepCopy(vtkCellArray *ca);
00196 
00198 
00199   vtkIdTypeArray* GetData() 
00200     {return this->Ia;}
00202 
00204   void Reset();
00205 
00207 
00208   void Squeeze() 
00209     {this->Ia->Squeeze();}
00211 
00218   unsigned long GetActualMemorySize();
00219   
00220 protected:
00221   vtkCellArray();
00222   ~vtkCellArray();
00223 
00224   vtkIdType NumberOfCells;
00225   vtkIdType InsertLocation;     //keep track of current insertion point
00226   vtkIdType TraversalLocation;   //keep track of traversal position
00227   vtkIdTypeArray *Ia;
00228 
00229 private:
00230   vtkCellArray(const vtkCellArray&);  // Not implemented.
00231   void operator=(const vtkCellArray&);  // Not implemented.
00232 };
00233 
00234 
00235 //----------------------------------------------------------------------------
00236 inline vtkIdType vtkCellArray::InsertNextCell(vtkIdType npts,
00237                                               const vtkIdType* pts)
00238 {
00239   vtkIdType i = this->Ia->GetMaxId() + 1;
00240   vtkIdType *ptr = this->Ia->WritePointer(i, npts+1);
00241   
00242   for ( *ptr++ = npts, i = 0; i < npts; i++)
00243     {
00244     *ptr++ = *pts++;
00245     }
00246 
00247   this->NumberOfCells++;
00248   this->InsertLocation += npts + 1;
00249 
00250   return this->NumberOfCells - 1;
00251 }
00252 
00253 //----------------------------------------------------------------------------
00254 inline vtkIdType vtkCellArray::InsertNextCell(vtkIdList *pts)
00255 {
00256   vtkIdType npts = pts->GetNumberOfIds();
00257   vtkIdType i = this->Ia->GetMaxId() + 1;
00258   vtkIdType *ptr = this->Ia->WritePointer(i,npts+1);
00259   
00260   for ( *ptr++ = npts, i = 0; i < npts; i++)
00261     {
00262     *ptr++ = pts->GetId(i);
00263     }
00264 
00265   this->NumberOfCells++;
00266   this->InsertLocation += npts + 1;
00267 
00268   return this->NumberOfCells - 1;
00269 }
00270 
00271 //----------------------------------------------------------------------------
00272 inline vtkIdType vtkCellArray::InsertNextCell(int npts)
00273 {
00274   this->InsertLocation = this->Ia->InsertNextValue(npts) + 1;
00275   this->NumberOfCells++;
00276 
00277   return this->NumberOfCells - 1;
00278 }
00279 
00280 //----------------------------------------------------------------------------
00281 inline void vtkCellArray::InsertCellPoint(vtkIdType id) 
00282 {
00283   this->Ia->InsertValue(this->InsertLocation++, id);
00284 }
00285 
00286 //----------------------------------------------------------------------------
00287 inline void vtkCellArray::UpdateCellCount(int npts) 
00288 {
00289   this->Ia->SetValue(this->InsertLocation-npts-1, npts);
00290 }
00291 
00292 //----------------------------------------------------------------------------
00293 inline vtkIdType vtkCellArray::InsertNextCell(vtkCell *cell)
00294 {
00295   vtkIdType npts = cell->GetNumberOfPoints();
00296   vtkIdType i = this->Ia->GetMaxId() + 1;
00297   vtkIdType *ptr = this->Ia->WritePointer(i,npts+1);
00298   
00299   for ( *ptr++ = npts, i = 0; i < npts; i++)
00300     {
00301     *ptr++ = cell->PointIds->GetId(i);
00302     }
00303 
00304   this->NumberOfCells++;
00305   this->InsertLocation += npts + 1;
00306 
00307   return this->NumberOfCells - 1;
00308 }
00309 
00310 //----------------------------------------------------------------------------
00311 inline void vtkCellArray::Reset() 
00312 {
00313   this->NumberOfCells = 0;
00314   this->InsertLocation = 0;
00315   this->TraversalLocation = 0;
00316   this->Ia->Reset();
00317 }
00318 
00319 //----------------------------------------------------------------------------
00320 inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType* &pts)
00321 {
00322   if ( this->Ia->GetMaxId() >= 0 && 
00323        this->TraversalLocation <= this->Ia->GetMaxId() ) 
00324     {
00325     npts = this->Ia->GetValue(this->TraversalLocation++);
00326     pts = this->Ia->GetPointer(this->TraversalLocation);
00327     this->TraversalLocation += npts;
00328     return 1;
00329     }
00330   else
00331     {
00332     return 0;
00333     }
00334 }
00335 
00336 //----------------------------------------------------------------------------
00337 inline void vtkCellArray::GetCell(vtkIdType loc, vtkIdType &npts,
00338                                   vtkIdType* &pts)
00339 {
00340   npts = this->Ia->GetValue(loc++);
00341   pts  = this->Ia->GetPointer(loc);
00342 }
00343 
00344 //----------------------------------------------------------------------------
00345 inline void vtkCellArray::ReverseCell(vtkIdType loc)
00346 {
00347   int i;
00348   vtkIdType tmp;
00349   vtkIdType npts=this->Ia->GetValue(loc);
00350   vtkIdType *pts=this->Ia->GetPointer(loc+1);
00351   for (i=0; i < (npts/2); i++) 
00352     {
00353     tmp = pts[i];
00354     pts[i] = pts[npts-i-1];
00355     pts[npts-i-1] = tmp;
00356     }
00357 }
00358 
00359 //----------------------------------------------------------------------------
00360 inline void vtkCellArray::ReplaceCell(vtkIdType loc, int npts,
00361                                       const vtkIdType *pts)
00362 {
00363   vtkIdType *oldPts=this->Ia->GetPointer(loc+1);
00364   for (int i=0; i < npts; i++)
00365     {
00366     oldPts[i] = pts[i];
00367     }
00368 }
00369 
00370 //----------------------------------------------------------------------------
00371 inline vtkIdType *vtkCellArray::WritePointer(const vtkIdType ncells,
00372                                              const vtkIdType size)
00373 {
00374   this->NumberOfCells = ncells;
00375   this->InsertLocation = 0;
00376   this->TraversalLocation = 0;
00377   return this->Ia->WritePointer(0,size);
00378 }
00379 
00380 #endif

Generated by  doxygen 1.7.1