vtkCellArray.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00050 #ifndef __vtkCellArray_h
00051 #define __vtkCellArray_h
00052
00053 #include "vtkObject.h"
00054
00055 #include "vtkIdTypeArray.h"
00056 #include "vtkCell.h"
00057
00058 class VTK_FILTERING_EXPORT vtkCellArray : public vtkObject
00059 {
00060 public:
00061 vtkTypeRevisionMacro(vtkCellArray,vtkObject);
00062 void PrintSelf(ostream& os, vtkIndent indent);
00063
00065 static vtkCellArray *New();
00066
00068
00069 int Allocate(const vtkIdType sz, const int ext=1000)
00070 {return this->Ia->Allocate(sz,ext);}
00072
00074
00075 void Initialize()
00076 {this->Ia->Initialize();}
00078
00080
00081 vtkIdType GetNumberOfCells()
00082 {return this->NumberOfCells;}
00084
00086
00092 vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell)
00093 {return numCells*(1+maxPtsPerCell);}
00095
00099 void InitTraversal() {this->TraversalLocation=0;};
00100
00104 int GetNextCell(vtkIdType& npts, vtkIdType* &pts);
00105
00107
00108 vtkIdType GetSize()
00109 {return this->Ia->GetSize();}
00111
00113
00116 vtkIdType GetNumberOfConnectivityEntries()
00117 {return this->Ia->GetMaxId()+1;}
00119
00122 void GetCell(vtkIdType loc, vtkIdType &npts, vtkIdType* &pts);
00123
00125 vtkIdType InsertNextCell(vtkCell *cell);
00126
00129 vtkIdType InsertNextCell(vtkIdType npts, vtkIdType* pts);
00130
00133 vtkIdType InsertNextCell(vtkIdList *pts);
00134
00139 vtkIdType InsertNextCell(int npts);
00140
00143 void InsertCellPoint(vtkIdType id);
00144
00147 void UpdateCellCount(int npts);
00148
00150
00152 vtkIdType GetInsertLocation(int npts)
00153 {return (this->InsertLocation - npts - 1);};
00155
00157
00158 vtkIdType GetTraversalLocation()
00159 {return this->TraversalLocation;}
00160 void SetTraversalLocation(vtkIdType loc)
00161 {this->TraversalLocation = loc;}
00163
00165
00167 vtkIdType GetTraversalLocation(vtkIdType npts)
00168 {return(this->TraversalLocation-npts-1);}
00170
00173 void ReverseCell(vtkIdType loc);
00174
00176 void ReplaceCell(vtkIdType loc, int npts, vtkIdType *pts);
00177
00180 int GetMaxCellSize();
00181
00183
00184 vtkIdType *GetPointer()
00185 {return this->Ia->GetPointer(0);}
00187
00191 vtkIdType *WritePointer(const vtkIdType ncells, const vtkIdType size);
00192
00200 void SetCells(vtkIdType ncells, vtkIdTypeArray *cells);
00201
00203 void DeepCopy(vtkCellArray *ca);
00204
00206
00207 vtkIdTypeArray* GetData()
00208 {return this->Ia;}
00210
00212 void Reset();
00213
00215
00216 void Squeeze()
00217 {this->Ia->Squeeze();}
00219
00226 unsigned long GetActualMemorySize();
00227
00228 protected:
00229 vtkCellArray();
00230 ~vtkCellArray();
00231
00232 vtkIdType NumberOfCells;
00233 vtkIdType InsertLocation;
00234 vtkIdType TraversalLocation;
00235 vtkIdTypeArray *Ia;
00236 private:
00237 vtkCellArray(const vtkCellArray&);
00238 void operator=(const vtkCellArray&);
00239 };
00240
00241
00242 inline vtkIdType vtkCellArray::InsertNextCell(vtkIdType npts, vtkIdType* pts)
00243 {
00244 vtkIdType i = this->Ia->GetMaxId() + 1;
00245 vtkIdType *ptr = this->Ia->WritePointer(i, npts+1);
00246
00247 for ( *ptr++ = npts, i = 0; i < npts; i++)
00248 {
00249 *ptr++ = *pts++;
00250 }
00251
00252 this->NumberOfCells++;
00253 this->InsertLocation += npts + 1;
00254
00255 return this->NumberOfCells - 1;
00256 }
00257
00258 inline vtkIdType vtkCellArray::InsertNextCell(vtkIdList *pts)
00259 {
00260 vtkIdType npts = pts->GetNumberOfIds();
00261 vtkIdType i = this->Ia->GetMaxId() + 1;
00262 vtkIdType *ptr = this->Ia->WritePointer(i,npts+1);
00263
00264 for ( *ptr++ = npts, i = 0; i < npts; i++)
00265 {
00266 *ptr++ = pts->GetId(i);
00267 }
00268
00269 this->NumberOfCells++;
00270 this->InsertLocation += npts + 1;
00271
00272 return this->NumberOfCells - 1;
00273 }
00274
00275 inline vtkIdType vtkCellArray::InsertNextCell(int npts)
00276 {
00277 this->InsertLocation = this->Ia->InsertNextValue(npts) + 1;
00278 this->NumberOfCells++;
00279
00280 return this->NumberOfCells - 1;
00281 }
00282
00283 inline void vtkCellArray::InsertCellPoint(vtkIdType id)
00284 {
00285 this->Ia->InsertValue(this->InsertLocation++, id);
00286 }
00287
00288 inline void vtkCellArray::UpdateCellCount(int npts)
00289 {
00290 this->Ia->SetValue(this->InsertLocation-npts-1, npts);
00291 }
00292
00293 inline vtkIdType vtkCellArray::InsertNextCell(vtkCell *cell)
00294 {
00295 int 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 inline void vtkCellArray::GetCell(vtkIdType loc, vtkIdType &npts,
00337 vtkIdType* &pts)
00338 {
00339 npts=this->Ia->GetValue(loc++);
00340 pts=this->Ia->GetPointer(loc);
00341 }
00342
00343
00344 inline void vtkCellArray::ReverseCell(vtkIdType loc)
00345 {
00346 int i;
00347 vtkIdType tmp;
00348 vtkIdType npts=this->Ia->GetValue(loc);
00349 vtkIdType *pts=this->Ia->GetPointer(loc+1);
00350 for (i=0; i < (npts/2); i++)
00351 {
00352 tmp = pts[i];
00353 pts[i] = pts[npts-i-1];
00354 pts[npts-i-1] = tmp;
00355 }
00356 }
00357
00358 inline void vtkCellArray::ReplaceCell(vtkIdType loc, int npts, 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 inline vtkIdType *vtkCellArray::WritePointer(const vtkIdType ncells,
00368 const vtkIdType size)
00369 {
00370 this->NumberOfCells = ncells;
00371 this->InsertLocation = 0;
00372 this->TraversalLocation = 0;
00373 return this->Ia->WritePointer(0,size);
00374 }
00375
00376 #endif