00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00037 #ifndef __vtkCellArray_h
00038 #define __vtkCellArray_h
00039
00040 #include "vtkObject.h"
00041
00042 #include "vtkIdTypeArray.h"
00043 #include "vtkCell.h"
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 void Initialize();
00062
00064
00065 vtkGetMacro(NumberOfCells, vtkIdType);
00067
00069
00071 vtkSetMacro(NumberOfCells, vtkIdType);
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, const 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, const 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;
00223 vtkIdType TraversalLocation;
00224 vtkIdTypeArray *Ia;
00225
00226 private:
00227 vtkCellArray(const vtkCellArray&);
00228 void operator=(const vtkCellArray&);
00229 };
00230
00231
00232
00233 inline vtkIdType vtkCellArray::InsertNextCell(vtkIdType npts,
00234 const vtkIdType* pts)
00235 {
00236 vtkIdType i = this->Ia->GetMaxId() + 1;
00237 vtkIdType *ptr = this->Ia->WritePointer(i, npts+1);
00238
00239 for ( *ptr++ = npts, i = 0; i < npts; i++)
00240 {
00241 *ptr++ = *pts++;
00242 }
00243
00244 this->NumberOfCells++;
00245 this->InsertLocation += npts + 1;
00246
00247 return this->NumberOfCells - 1;
00248 }
00249
00250
00251 inline vtkIdType vtkCellArray::InsertNextCell(vtkIdList *pts)
00252 {
00253 vtkIdType npts = pts->GetNumberOfIds();
00254 vtkIdType i = this->Ia->GetMaxId() + 1;
00255 vtkIdType *ptr = this->Ia->WritePointer(i,npts+1);
00256
00257 for ( *ptr++ = npts, i = 0; i < npts; i++)
00258 {
00259 *ptr++ = pts->GetId(i);
00260 }
00261
00262 this->NumberOfCells++;
00263 this->InsertLocation += npts + 1;
00264
00265 return this->NumberOfCells - 1;
00266 }
00267
00268
00269 inline vtkIdType vtkCellArray::InsertNextCell(int npts)
00270 {
00271 this->InsertLocation = this->Ia->InsertNextValue(npts) + 1;
00272 this->NumberOfCells++;
00273
00274 return this->NumberOfCells - 1;
00275 }
00276
00277
00278 inline void vtkCellArray::InsertCellPoint(vtkIdType id)
00279 {
00280 this->Ia->InsertValue(this->InsertLocation++, id);
00281 }
00282
00283
00284 inline void vtkCellArray::UpdateCellCount(int npts)
00285 {
00286 this->Ia->SetValue(this->InsertLocation-npts-1, npts);
00287 }
00288
00289
00290 inline vtkIdType vtkCellArray::InsertNextCell(vtkCell *cell)
00291 {
00292 vtkIdType npts = cell->GetNumberOfPoints();
00293 vtkIdType i = this->Ia->GetMaxId() + 1;
00294 vtkIdType *ptr = this->Ia->WritePointer(i,npts+1);
00295
00296 for ( *ptr++ = npts, i = 0; i < npts; i++)
00297 {
00298 *ptr++ = cell->PointIds->GetId(i);
00299 }
00300
00301 this->NumberOfCells++;
00302 this->InsertLocation += npts + 1;
00303
00304 return this->NumberOfCells - 1;
00305 }
00306
00307
00308 inline void vtkCellArray::Reset()
00309 {
00310 this->NumberOfCells = 0;
00311 this->InsertLocation = 0;
00312 this->TraversalLocation = 0;
00313 this->Ia->Reset();
00314 }
00315
00316
00317 inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType* &pts)
00318 {
00319 if ( this->Ia->GetMaxId() >= 0 &&
00320 this->TraversalLocation <= this->Ia->GetMaxId() )
00321 {
00322 npts = this->Ia->GetValue(this->TraversalLocation++);
00323 pts = this->Ia->GetPointer(this->TraversalLocation);
00324 this->TraversalLocation += npts;
00325 return 1;
00326 }
00327 else
00328 {
00329 return 0;
00330 }
00331 }
00332
00333
00334 inline void vtkCellArray::GetCell(vtkIdType loc, vtkIdType &npts,
00335 vtkIdType* &pts)
00336 {
00337 npts = this->Ia->GetValue(loc++);
00338 pts = this->Ia->GetPointer(loc);
00339 }
00340
00341
00342 inline void vtkCellArray::ReverseCell(vtkIdType loc)
00343 {
00344 int i;
00345 vtkIdType tmp;
00346 vtkIdType npts=this->Ia->GetValue(loc);
00347 vtkIdType *pts=this->Ia->GetPointer(loc+1);
00348 for (i=0; i < (npts/2); i++)
00349 {
00350 tmp = pts[i];
00351 pts[i] = pts[npts-i-1];
00352 pts[npts-i-1] = tmp;
00353 }
00354 }
00355
00356
00357 inline void vtkCellArray::ReplaceCell(vtkIdType loc, int npts,
00358 const vtkIdType *pts)
00359 {
00360 vtkIdType *oldPts=this->Ia->GetPointer(loc+1);
00361 for (int i=0; i < npts; i++)
00362 {
00363 oldPts[i] = pts[i];
00364 }
00365 }
00366
00367
00368 inline vtkIdType *vtkCellArray::WritePointer(const vtkIdType ncells,
00369 const vtkIdType size)
00370 {
00371 this->NumberOfCells = ncells;
00372 this->InsertLocation = 0;
00373 this->TraversalLocation = 0;
00374 return this->Ia->WritePointer(0,size);
00375 }
00376
00377 #endif