Common/vtkCellArray.h Source File

Main Page Class Hierarchy Alphabetical List Compound List File List Compound 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   Language:  C++
    00006
    00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
    00008   All rights reserved.
    00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
    00010
    00011      This software is distributed WITHOUT ANY WARRANTY; without even
    00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
    00013      PURPOSE.  See the above copyright notice for more information.
    00014
    00015 =========================================================================*/
    00058 #ifndef __vtkCellArray_h
    00059 #define __vtkCellArray_h
    00060
    00061 #include "vtkObject.h"
    00062
    00063 #include "vtkIdTypeArray.h" // Needed for inline methods
    00064 #include "vtkCell.h" // Needed for inline methods
    00065
    00066 class VTK_COMMON_EXPORT vtkCellArray : public vtkObject
    00067 {
    00068 public:
    00069   vtkTypeRevisionMacro(vtkCellArray,vtkObject);
    00070
    00072   static vtkCellArray *New();
    00073
    00075
    00076   int Allocate(const vtkIdType sz, const int ext=1000)
    00077     {return this->Ia->Allocate(sz,ext);}
    00079
    00081
    00082   void Initialize()
    00083     {this->Ia->Initialize();}
    00085
    00087
    00088   vtkIdType GetNumberOfCells()
    00089     {return this->NumberOfCells;}
    00091
    00093
    00099   vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell)
    00100     {return numCells*(1+maxPtsPerCell);}
    00102
    00106   void InitTraversal() {this->TraversalLocation=0;};
    00107
    00111   int GetNextCell(vtkIdType& npts, vtkIdType* &pts);
    00112
    00114
    00115   vtkIdType GetSize()
    00116     {return this->Ia->GetSize();}
    00118
    00120
    00123   vtkIdType GetNumberOfConnectivityEntries()
    00124     {return this->Ia->GetMaxId()+1;}
    00126
    00129   void GetCell(vtkIdType loc, vtkIdType &npts, vtkIdType* &pts);
    00130
    00132   vtkIdType InsertNextCell(vtkCell *cell);
    00133
    00136   vtkIdType InsertNextCell(vtkIdType npts, vtkIdType* pts);
    00137
    00140   vtkIdType InsertNextCell(vtkIdList *pts);
    00141
    00146   vtkIdType InsertNextCell(int npts);
    00147
    00150   void InsertCellPoint(vtkIdType id);
    00151
    00154   void UpdateCellCount(int npts);
    00155
    00157
    00159   vtkIdType GetInsertLocation(int npts)
    00160     {return (this->InsertLocation - npts - 1);};
    00162
    00164
    00165   vtkIdType GetTraversalLocation()
    00166     {return this->TraversalLocation;}
    00167   void SetTraversalLocation(vtkIdType loc)
    00168     {this->TraversalLocation = loc;}
    00170
    00172
    00174   vtkIdType GetTraversalLocation(vtkIdType npts)
    00175     {return(this->TraversalLocation-npts-1);}
    00177
    00180   void ReverseCell(vtkIdType loc);
    00181
    00183   void ReplaceCell(vtkIdType loc, int npts, vtkIdType *pts);
    00184
    00187   int GetMaxCellSize();
    00188
    00190
    00191   vtkIdType *GetPointer()
    00192     {return this->Ia->GetPointer(0);}
    00194
    00198   vtkIdType *WritePointer(const vtkIdType ncells, const vtkIdType size);
    00199
    00207   void SetCells(vtkIdType ncells, vtkIdTypeArray *cells);
    00208
    00210   void DeepCopy(vtkCellArray *ca);
    00211
    00213
    00214   vtkIdTypeArray* GetData()
    00215     {return this->Ia;}
    00217
    00219   void Reset();
    00220
    00222
    00223   void Squeeze()
    00224     {this->Ia->Squeeze();}
    00226
    00233   unsigned long GetActualMemorySize();
    00234
    00235 protected:
    00236   vtkCellArray();
    00237   ~vtkCellArray();
    00238
    00239   vtkIdType NumberOfCells;
    00240   vtkIdType InsertLocation;     //keep track of current insertion point
    00241   vtkIdType TraversalLocation;   //keep track of traversal position
    00242   vtkIdTypeArray *Ia;
    00243 private:
    00244   vtkCellArray(const vtkCellArray&);  // Not implemented.
    00245   void operator=(const vtkCellArray&);  // Not implemented.
    00246 };
    00247
    00248
    00249 inline vtkIdType vtkCellArray::InsertNextCell(vtkIdType npts, vtkIdType* pts)
    00250 {
    00251   vtkIdType i = this->Ia->GetMaxId() + 1;
    00252   vtkIdType *ptr = this->Ia->WritePointer(i, npts+1);
    00253
    00254   for ( *ptr++ = npts, i = 0; i < npts; i++)
    00255     {
    00256     *ptr++ = *pts++;
    00257     }
    00258
    00259   this->NumberOfCells++;
    00260   this->InsertLocation += npts + 1;
    00261
    00262   return this->NumberOfCells - 1;
    00263 }
    00264
    00265 inline vtkIdType vtkCellArray::InsertNextCell(vtkIdList *pts)
    00266 {
    00267   vtkIdType npts = pts->GetNumberOfIds();
    00268   vtkIdType i = this->Ia->GetMaxId() + 1;
    00269   vtkIdType *ptr = this->Ia->WritePointer(i,npts+1);
    00270
    00271   for ( *ptr++ = npts, i = 0; i < npts; i++)
    00272     {
    00273     *ptr++ = pts->GetId(i);
    00274     }
    00275
    00276   this->NumberOfCells++;
    00277   this->InsertLocation += npts + 1;
    00278
    00279   return this->NumberOfCells - 1;
    00280 }
    00281
    00282 inline vtkIdType vtkCellArray::InsertNextCell(int npts)
    00283 {
    00284   this->InsertLocation = this->Ia->InsertNextValue(npts) + 1;
    00285   this->NumberOfCells++;
    00286
    00287   return this->NumberOfCells - 1;
    00288 }
    00289
    00290 inline void vtkCellArray::InsertCellPoint(vtkIdType id)
    00291 {
    00292   this->Ia->InsertValue(this->InsertLocation++, id);
    00293 }
    00294
    00295 inline void vtkCellArray::UpdateCellCount(int npts)
    00296 {
    00297   this->Ia->SetValue(this->InsertLocation-npts-1, npts);
    00298 }
    00299
    00300 inline vtkIdType vtkCellArray::InsertNextCell(vtkCell *cell)
    00301 {
    00302   int npts = cell->GetNumberOfPoints();
    00303   vtkIdType i = this->Ia->GetMaxId() + 1;
    00304   vtkIdType *ptr = this->Ia->WritePointer(i,npts+1);
    00305
    00306   for ( *ptr++ = npts, i = 0; i < npts; i++)
    00307     {
    00308     *ptr++ = cell->PointIds->GetId(i);
    00309     }
    00310
    00311   this->NumberOfCells++;
    00312   this->InsertLocation += npts + 1;
    00313
    00314   return this->NumberOfCells - 1;
    00315 }
    00316
    00317
    00318 inline void vtkCellArray::Reset()
    00319 {
    00320   this->NumberOfCells = 0;
    00321   this->InsertLocation = 0;
    00322   this->TraversalLocation = 0;
    00323   this->Ia->Reset();
    00324 }
    00325
    00326
    00327 inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType* &pts)
    00328 {
    00329   if ( this->Ia->GetMaxId() >= 0 &&
    00330   this->TraversalLocation <= this->Ia->GetMaxId() )
    00331     {
    00332     npts = this->Ia->GetValue(this->TraversalLocation++);
    00333     pts = this->Ia->GetPointer(this->TraversalLocation);
    00334     this->TraversalLocation += npts;
    00335     return 1;
    00336     }
    00337   else
    00338     {
    00339     return 0;
    00340     }
    00341 }
    00342
    00343 inline void vtkCellArray::GetCell(vtkIdType loc, vtkIdType &npts,
    00344                                   vtkIdType* &pts)
    00345 {
    00346   npts=this->Ia->GetValue(loc++);
    00347   pts=this->Ia->GetPointer(loc);
    00348 }
    00349
    00350
    00351 inline void vtkCellArray::ReverseCell(vtkIdType loc)
    00352 {
    00353   int i;
    00354   vtkIdType tmp;
    00355   vtkIdType npts=this->Ia->GetValue(loc);
    00356   vtkIdType *pts=this->Ia->GetPointer(loc+1);
    00357   for (i=0; i < (npts/2); i++)
    00358     {
    00359     tmp = pts[i];
    00360     pts[i] = pts[npts-i-1];
    00361     pts[npts-i-1] = tmp;
    00362     }
    00363 }
    00364
    00365 inline void vtkCellArray::ReplaceCell(vtkIdType loc, int npts, vtkIdType *pts)
    00366 {
    00367   vtkIdType *oldPts=this->Ia->GetPointer(loc+1);
    00368   for (int i=0; i < npts; i++)
    00369     {
    00370     oldPts[i] = pts[i];
    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