VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkCellArray.h 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 =========================================================================*/ 00040 #ifndef __vtkCellArray_h 00041 #define __vtkCellArray_h 00042 00043 #include "vtkObject.h" 00044 00045 #include "vtkIdTypeArray.h" // Needed for inline methods 00046 #include "vtkCell.h" // Needed for inline methods 00047 00048 class VTK_FILTERING_EXPORT vtkCellArray : public vtkObject 00049 { 00050 public: 00051 vtkTypeMacro(vtkCellArray,vtkObject); 00052 void PrintSelf(ostream& os, vtkIndent indent); 00053 00055 static vtkCellArray *New(); 00056 00058 00059 int Allocate(const vtkIdType sz, const int ext=1000) 00060 {return this->Ia->Allocate(sz,ext);} 00062 00064 void 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 00101 int GetNextCell(vtkIdList *pts); 00102 00104 00105 vtkIdType GetSize() 00106 {return this->Ia->GetSize();} 00108 00110 00113 vtkIdType GetNumberOfConnectivityEntries() 00114 {return this->Ia->GetMaxId()+1;} 00116 00119 void GetCell(vtkIdType loc, vtkIdType &npts, vtkIdType* &pts); 00120 00123 void GetCell(vtkIdType loc, vtkIdList* pts); 00124 00126 vtkIdType InsertNextCell(vtkCell *cell); 00127 00130 vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts); 00131 00134 vtkIdType InsertNextCell(vtkIdList *pts); 00135 00140 vtkIdType InsertNextCell(int npts); 00141 00144 void InsertCellPoint(vtkIdType id); 00145 00148 void UpdateCellCount(int npts); 00149 00151 00153 vtkIdType GetInsertLocation(int npts) 00154 {return (this->InsertLocation - npts - 1);}; 00156 00158 00159 vtkIdType GetTraversalLocation() 00160 {return this->TraversalLocation;} 00161 void SetTraversalLocation(vtkIdType loc) 00162 {this->TraversalLocation = loc;} 00164 00166 00168 vtkIdType GetTraversalLocation(vtkIdType npts) 00169 {return(this->TraversalLocation-npts-1);} 00171 00174 void ReverseCell(vtkIdType loc); 00175 00177 void ReplaceCell(vtkIdType loc, int npts, const vtkIdType *pts); 00178 00181 int GetMaxCellSize(); 00182 00184 00185 vtkIdType *GetPointer() 00186 {return this->Ia->GetPointer(0);} 00188 00192 vtkIdType *WritePointer(const vtkIdType ncells, const vtkIdType size); 00193 00201 void SetCells(vtkIdType ncells, vtkIdTypeArray *cells); 00202 00204 void DeepCopy(vtkCellArray *ca); 00205 00207 00208 vtkIdTypeArray* GetData() 00209 {return this->Ia;} 00211 00213 void Reset(); 00214 00216 00217 void Squeeze() 00218 {this->Ia->Squeeze();} 00220 00227 unsigned long GetActualMemorySize(); 00228 00229 protected: 00230 vtkCellArray(); 00231 ~vtkCellArray(); 00232 00233 vtkIdType NumberOfCells; 00234 vtkIdType InsertLocation; //keep track of current insertion point 00235 vtkIdType TraversalLocation; //keep track of traversal position 00236 vtkIdTypeArray *Ia; 00237 00238 private: 00239 vtkCellArray(const vtkCellArray&); // Not implemented. 00240 void operator=(const vtkCellArray&); // Not implemented. 00241 }; 00242 00243 00244 //---------------------------------------------------------------------------- 00245 inline vtkIdType vtkCellArray::InsertNextCell(vtkIdType npts, 00246 const vtkIdType* pts) 00247 { 00248 vtkIdType i = this->Ia->GetMaxId() + 1; 00249 vtkIdType *ptr = this->Ia->WritePointer(i, npts+1); 00250 00251 for ( *ptr++ = npts, i = 0; i < npts; i++) 00252 { 00253 *ptr++ = *pts++; 00254 } 00255 00256 this->NumberOfCells++; 00257 this->InsertLocation += npts + 1; 00258 00259 return this->NumberOfCells - 1; 00260 } 00261 00262 //---------------------------------------------------------------------------- 00263 inline vtkIdType vtkCellArray::InsertNextCell(int npts) 00264 { 00265 this->InsertLocation = this->Ia->InsertNextValue(npts) + 1; 00266 this->NumberOfCells++; 00267 00268 return this->NumberOfCells - 1; 00269 } 00270 00271 //---------------------------------------------------------------------------- 00272 inline void vtkCellArray::InsertCellPoint(vtkIdType id) 00273 { 00274 this->Ia->InsertValue(this->InsertLocation++, id); 00275 } 00276 00277 //---------------------------------------------------------------------------- 00278 inline void vtkCellArray::UpdateCellCount(int npts) 00279 { 00280 this->Ia->SetValue(this->InsertLocation-npts-1, npts); 00281 } 00282 00283 //---------------------------------------------------------------------------- 00284 inline vtkIdType vtkCellArray::InsertNextCell(vtkIdList *pts) 00285 { 00286 return this->InsertNextCell(pts->GetNumberOfIds(), pts->GetPointer(0)); 00287 } 00288 00289 //---------------------------------------------------------------------------- 00290 inline vtkIdType vtkCellArray::InsertNextCell(vtkCell *cell) 00291 { 00292 return this->InsertNextCell(cell->GetNumberOfPoints(), 00293 cell->PointIds->GetPointer(0)); 00294 } 00295 00296 //---------------------------------------------------------------------------- 00297 inline void vtkCellArray::Reset() 00298 { 00299 this->NumberOfCells = 0; 00300 this->InsertLocation = 0; 00301 this->TraversalLocation = 0; 00302 this->Ia->Reset(); 00303 } 00304 00305 //---------------------------------------------------------------------------- 00306 inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType* &pts) 00307 { 00308 if ( this->Ia->GetMaxId() >= 0 && 00309 this->TraversalLocation <= this->Ia->GetMaxId() ) 00310 { 00311 npts = this->Ia->GetValue(this->TraversalLocation++); 00312 pts = this->Ia->GetPointer(this->TraversalLocation); 00313 this->TraversalLocation += npts; 00314 return 1; 00315 } 00316 npts=0; 00317 pts=0; 00318 return 0; 00319 } 00320 00321 //---------------------------------------------------------------------------- 00322 inline void vtkCellArray::GetCell(vtkIdType loc, vtkIdType &npts, 00323 vtkIdType* &pts) 00324 { 00325 npts = this->Ia->GetValue(loc++); 00326 pts = this->Ia->GetPointer(loc); 00327 } 00328 00329 //---------------------------------------------------------------------------- 00330 inline void vtkCellArray::ReverseCell(vtkIdType loc) 00331 { 00332 int i; 00333 vtkIdType tmp; 00334 vtkIdType npts=this->Ia->GetValue(loc); 00335 vtkIdType *pts=this->Ia->GetPointer(loc+1); 00336 for (i=0; i < (npts/2); i++) 00337 { 00338 tmp = pts[i]; 00339 pts[i] = pts[npts-i-1]; 00340 pts[npts-i-1] = tmp; 00341 } 00342 } 00343 00344 //---------------------------------------------------------------------------- 00345 inline void vtkCellArray::ReplaceCell(vtkIdType loc, int npts, 00346 const vtkIdType *pts) 00347 { 00348 vtkIdType *oldPts=this->Ia->GetPointer(loc+1); 00349 for (int i=0; i < npts; i++) 00350 { 00351 oldPts[i] = pts[i]; 00352 } 00353 } 00354 00355 //---------------------------------------------------------------------------- 00356 inline vtkIdType *vtkCellArray::WritePointer(const vtkIdType ncells, 00357 const vtkIdType size) 00358 { 00359 this->NumberOfCells = ncells; 00360 this->InsertLocation = 0; 00361 this->TraversalLocation = 0; 00362 return this->Ia->WritePointer(0,size); 00363 } 00364 00365 #endif