00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00064 #ifndef __vtkCellArray_h
00065 #define __vtkCellArray_h
00066
00067 #include "vtkIntArray.h"
00068 #include "vtkCell.h"
00069
00070 class VTK_EXPORT vtkCellArray : public vtkObject
00071 {
00072 public:
00073 vtkTypeMacro(vtkCellArray,vtkObject);
00074
00076 static vtkCellArray *New();
00077
00079 int Allocate(const int sz, const int ext=1000)
00080 {return this->Ia->Allocate(sz,ext);}
00081
00083 void Initialize()
00084 {this->Ia->Initialize();}
00085
00087 int GetNumberOfCells()
00088 {return this->NumberOfCells;}
00089
00096 int EstimateSize(int numCells, int maxPtsPerCell)
00097 {return numCells*(1+maxPtsPerCell);}
00098
00102 void InitTraversal() {this->TraversalLocation=0;};
00103
00107 int GetNextCell(int& npts, int* &pts);
00108
00110 int GetSize()
00111 {return this->Ia->GetSize();}
00112
00116 int GetNumberOfConnectivityEntries()
00117 {return this->Ia->GetMaxId()+1;}
00118
00121 void GetCell(int loc, int &npts, int* &pts);
00122
00124 int InsertNextCell(vtkCell *cell);
00125
00128 int InsertNextCell(int npts, int* pts);
00129
00132 int InsertNextCell(vtkIdList *pts);
00133
00138 int InsertNextCell(int npts);
00139
00142 void InsertCellPoint(int id);
00143
00146 void UpdateCellCount(int npts);
00147
00150 int GetInsertLocation(int npts) {return (this->InsertLocation - npts - 1);};
00151
00153 int GetTraversalLocation()
00154 {return this->TraversalLocation;}
00155 void SetTraversalLocation(int loc)
00156 {this->TraversalLocation = loc;}
00157
00160 int GetTraversalLocation(int npts)
00161 {return(this->TraversalLocation-npts-1);}
00162
00165 void ReverseCell(int loc);
00166
00168 void ReplaceCell(int loc, int npts, int *pts);
00169
00172 int GetMaxCellSize();
00173
00175 int *GetPointer()
00176 {return this->Ia->GetPointer(0);}
00177
00181 int *WritePointer(const int ncells, const int size);
00182
00190 void SetCells(int ncells, vtkIntArray *cells);
00191
00193 void DeepCopy(vtkCellArray *ca);
00194
00196 vtkDataArray *GetData()
00197 {return this->Ia;}
00198
00200 void Reset();
00201
00203 void Squeeze()
00204 {this->Ia->Squeeze();}
00205
00212 unsigned long GetActualMemorySize();
00213
00214 #ifndef VTK_REMOVE_LEGACY_CODE
00215
00216 int InsertNextCell(vtkIdList &pts);
00217 #endif
00218
00219 protected:
00220 vtkCellArray();
00221 vtkCellArray (const int sz, const int ext=1000);
00222 ~vtkCellArray();
00223 vtkCellArray(const vtkCellArray&) {};
00224 void operator=(const vtkCellArray&) {};
00225
00226 int NumberOfCells;
00227 int InsertLocation;
00228 int TraversalLocation;
00229 vtkIntArray *Ia;
00230 };
00231
00232
00233 inline int vtkCellArray::InsertNextCell(int npts, int* pts)
00234 {
00235 int i = this->Ia->GetMaxId() + 1;
00236 int *ptr = this->Ia->WritePointer(i,npts+1);
00237
00238 for ( *ptr++ = npts, i = 0; i < npts; i++)
00239 {
00240 *ptr++ = *pts++;
00241 }
00242
00243 this->NumberOfCells++;
00244 this->InsertLocation += npts + 1;
00245
00246 return this->NumberOfCells - 1;
00247 }
00248
00249 inline int vtkCellArray::InsertNextCell(vtkIdList *pts)
00250 {
00251 int npts = pts->GetNumberOfIds();
00252 int i = this->Ia->GetMaxId() + 1;
00253 int *ptr = this->Ia->WritePointer(i,npts+1);
00254
00255 for ( *ptr++ = npts, i = 0; i < npts; i++)
00256 {
00257 *ptr++ = pts->GetId(i);
00258 }
00259
00260 this->NumberOfCells++;
00261 this->InsertLocation += npts + 1;
00262
00263 return this->NumberOfCells - 1;
00264 }
00265
00266 inline int vtkCellArray::InsertNextCell(int npts)
00267 {
00268 this->InsertLocation = this->Ia->InsertNextValue(npts) + 1;
00269 this->NumberOfCells++;
00270
00271 return this->NumberOfCells - 1;
00272 }
00273
00274 inline void vtkCellArray::InsertCellPoint(int id)
00275 {
00276 this->Ia->InsertValue(this->InsertLocation++,id);
00277 }
00278
00279 inline void vtkCellArray::UpdateCellCount(int npts)
00280 {
00281 this->Ia->SetValue(this->InsertLocation-npts-1, npts);
00282 }
00283
00284 inline int vtkCellArray::InsertNextCell(vtkCell *cell)
00285 {
00286 int npts = cell->GetNumberOfPoints();
00287 int i = this->Ia->GetMaxId() + 1;
00288 int *ptr = this->Ia->WritePointer(i,npts+1);
00289
00290 for ( *ptr++ = npts, i = 0; i < npts; i++)
00291 {
00292 *ptr++ = cell->PointIds->GetId(i);
00293 }
00294
00295 this->NumberOfCells++;
00296 this->InsertLocation += npts + 1;
00297
00298 return this->NumberOfCells - 1;
00299 }
00300
00301
00302 inline void vtkCellArray::Reset()
00303 {
00304 this->NumberOfCells = 0;
00305 this->InsertLocation = 0;
00306 this->TraversalLocation = 0;
00307 this->Ia->Reset();
00308 }
00309
00310
00311 inline int vtkCellArray::GetNextCell(int& npts, int* &pts)
00312 {
00313 if ( this->Ia->GetMaxId() >= 0 &&
00314 this->TraversalLocation <= this->Ia->GetMaxId() )
00315 {
00316 npts = this->Ia->GetValue(this->TraversalLocation++);
00317 pts = this->Ia->GetPointer(this->TraversalLocation);
00318 this->TraversalLocation += npts;
00319 return 1;
00320 }
00321 else
00322 {
00323 return 0;
00324 }
00325 }
00326
00327 inline void vtkCellArray::GetCell(int loc, int &npts, int* &pts)
00328 {
00329 npts=this->Ia->GetValue(loc++); pts=this->Ia->GetPointer(loc);
00330 }
00331
00332
00333 inline void vtkCellArray::ReverseCell(int loc)
00334 {
00335 int i, tmp;
00336 int npts=this->Ia->GetValue(loc);
00337 int *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 inline void vtkCellArray::ReplaceCell(int loc, int npts, int *pts)
00347 {
00348 int *oldPts=this->Ia->GetPointer(loc+1);
00349 for (int i=0; i < npts; i++)
00350 {
00351 oldPts[i] = pts[i];
00352 }
00353 }
00354
00355 inline int *vtkCellArray::WritePointer(const int ncells, const int size)
00356 {
00357 this->NumberOfCells = ncells;
00358 this->InsertLocation = 0;
00359 this->TraversalLocation = 0;
00360 return this->Ia->WritePointer(0,size);
00361 }
00362
00363 #endif