Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

dox/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 =========================================================================*/ 00044 #ifndef __vtkCellArray_h 00045 #define __vtkCellArray_h 00046 00047 #include "vtkObject.h" 00048 00049 #include "vtkIdTypeArray.h" // Needed for inline methods 00050 #include "vtkCell.h" // Needed for inline methods 00051 00052 class VTK_COMMON_EXPORT vtkCellArray : public vtkObject 00053 { 00054 public: 00055 vtkTypeRevisionMacro(vtkCellArray,vtkObject); 00056 00058 static vtkCellArray *New(); 00059 00061 00062 int Allocate(const vtkIdType sz, const int ext=1000) 00063 {return this->Ia->Allocate(sz,ext);} 00065 00067 00068 void Initialize() 00069 {this->Ia->Initialize();} 00071 00073 00074 vtkIdType GetNumberOfCells() 00075 {return this->NumberOfCells;} 00077 00079 00085 vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell) 00086 {return numCells*(1+maxPtsPerCell);} 00088 00092 void InitTraversal() {this->TraversalLocation=0;}; 00093 00097 int GetNextCell(vtkIdType& npts, vtkIdType* &pts); 00098 00100 00101 vtkIdType GetSize() 00102 {return this->Ia->GetSize();} 00104 00106 00109 vtkIdType GetNumberOfConnectivityEntries() 00110 {return this->Ia->GetMaxId()+1;} 00112 00115 void GetCell(vtkIdType loc, vtkIdType &npts, vtkIdType* &pts); 00116 00118 vtkIdType InsertNextCell(vtkCell *cell); 00119 00122 vtkIdType InsertNextCell(vtkIdType npts, vtkIdType* pts); 00123 00126 vtkIdType InsertNextCell(vtkIdList *pts); 00127 00132 vtkIdType InsertNextCell(int npts); 00133 00136 void InsertCellPoint(vtkIdType id); 00137 00140 void UpdateCellCount(int npts); 00141 00143 00145 vtkIdType GetInsertLocation(int npts) 00146 {return (this->InsertLocation - npts - 1);}; 00148 00150 00151 vtkIdType GetTraversalLocation() 00152 {return this->TraversalLocation;} 00153 void SetTraversalLocation(vtkIdType loc) 00154 {this->TraversalLocation = loc;} 00156 00158 00160 vtkIdType GetTraversalLocation(vtkIdType npts) 00161 {return(this->TraversalLocation-npts-1);} 00163 00166 void ReverseCell(vtkIdType loc); 00167 00169 void ReplaceCell(vtkIdType loc, int npts, vtkIdType *pts); 00170 00173 int GetMaxCellSize(); 00174 00176 00177 vtkIdType *GetPointer() 00178 {return this->Ia->GetPointer(0);} 00180 00184 vtkIdType *WritePointer(const vtkIdType ncells, const vtkIdType size); 00185 00193 void SetCells(vtkIdType ncells, vtkIdTypeArray *cells); 00194 00196 void DeepCopy(vtkCellArray *ca); 00197 00199 00200 vtkIdTypeArray* GetData() 00201 {return this->Ia;} 00203 00205 void Reset(); 00206 00208 00209 void Squeeze() 00210 {this->Ia->Squeeze();} 00212 00219 unsigned long GetActualMemorySize(); 00220 00221 protected: 00222 vtkCellArray(); 00223 ~vtkCellArray(); 00224 00225 vtkIdType NumberOfCells; 00226 vtkIdType InsertLocation; //keep track of current insertion point 00227 vtkIdType TraversalLocation; //keep track of traversal position 00228 vtkIdTypeArray *Ia; 00229 private: 00230 vtkCellArray(const vtkCellArray&); // Not implemented. 00231 void operator=(const vtkCellArray&); // Not implemented. 00232 }; 00233 00234 00235 inline vtkIdType vtkCellArray::InsertNextCell(vtkIdType npts, vtkIdType* pts) 00236 { 00237 vtkIdType i = this->Ia->GetMaxId() + 1; 00238 vtkIdType *ptr = this->Ia->WritePointer(i, npts+1); 00239 00240 for ( *ptr++ = npts, i = 0; i < npts; i++) 00241 { 00242 *ptr++ = *pts++; 00243 } 00244 00245 this->NumberOfCells++; 00246 this->InsertLocation += npts + 1; 00247 00248 return this->NumberOfCells - 1; 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 inline vtkIdType vtkCellArray::InsertNextCell(int npts) 00269 { 00270 this->InsertLocation = this->Ia->InsertNextValue(npts) + 1; 00271 this->NumberOfCells++; 00272 00273 return this->NumberOfCells - 1; 00274 } 00275 00276 inline void vtkCellArray::InsertCellPoint(vtkIdType id) 00277 { 00278 this->Ia->InsertValue(this->InsertLocation++, id); 00279 } 00280 00281 inline void vtkCellArray::UpdateCellCount(int npts) 00282 { 00283 this->Ia->SetValue(this->InsertLocation-npts-1, npts); 00284 } 00285 00286 inline vtkIdType vtkCellArray::InsertNextCell(vtkCell *cell) 00287 { 00288 int npts = cell->GetNumberOfPoints(); 00289 vtkIdType i = this->Ia->GetMaxId() + 1; 00290 vtkIdType *ptr = this->Ia->WritePointer(i,npts+1); 00291 00292 for ( *ptr++ = npts, i = 0; i < npts; i++) 00293 { 00294 *ptr++ = cell->PointIds->GetId(i); 00295 } 00296 00297 this->NumberOfCells++; 00298 this->InsertLocation += npts + 1; 00299 00300 return this->NumberOfCells - 1; 00301 } 00302 00303 00304 inline void vtkCellArray::Reset() 00305 { 00306 this->NumberOfCells = 0; 00307 this->InsertLocation = 0; 00308 this->TraversalLocation = 0; 00309 this->Ia->Reset(); 00310 } 00311 00312 00313 inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType* &pts) 00314 { 00315 if ( this->Ia->GetMaxId() >= 0 && 00316 this->TraversalLocation <= this->Ia->GetMaxId() ) 00317 { 00318 npts = this->Ia->GetValue(this->TraversalLocation++); 00319 pts = this->Ia->GetPointer(this->TraversalLocation); 00320 this->TraversalLocation += npts; 00321 return 1; 00322 } 00323 else 00324 { 00325 return 0; 00326 } 00327 } 00328 00329 inline void vtkCellArray::GetCell(vtkIdType loc, vtkIdType &npts, 00330 vtkIdType* &pts) 00331 { 00332 npts=this->Ia->GetValue(loc++); 00333 pts=this->Ia->GetPointer(loc); 00334 } 00335 00336 00337 inline void vtkCellArray::ReverseCell(vtkIdType loc) 00338 { 00339 int i; 00340 vtkIdType tmp; 00341 vtkIdType npts=this->Ia->GetValue(loc); 00342 vtkIdType *pts=this->Ia->GetPointer(loc+1); 00343 for (i=0; i < (npts/2); i++) 00344 { 00345 tmp = pts[i]; 00346 pts[i] = pts[npts-i-1]; 00347 pts[npts-i-1] = tmp; 00348 } 00349 } 00350 00351 inline void vtkCellArray::ReplaceCell(vtkIdType loc, int npts, vtkIdType *pts) 00352 { 00353 vtkIdType *oldPts=this->Ia->GetPointer(loc+1); 00354 for (int i=0; i < npts; i++) 00355 { 00356 oldPts[i] = pts[i]; 00357 } 00358 } 00359 00360 inline vtkIdType *vtkCellArray::WritePointer(const vtkIdType ncells, 00361 const vtkIdType size) 00362 { 00363 this->NumberOfCells = ncells; 00364 this->InsertLocation = 0; 00365 this->TraversalLocation = 0; 00366 return this->Ia->WritePointer(0,size); 00367 } 00368 00369 #endif