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

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 
00008 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00009 All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without
00012 modification, are permitted provided that the following conditions are met:
00013 
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016 
00017  * Redistributions in binary form must reproduce the above copyright notice,
00018    this list of conditions and the following disclaimer in the documentation
00019    and/or other materials provided with the distribution.
00020 
00021  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00022    of any contributors may be used to endorse or promote products derived
00023    from this software without specific prior written permission.
00024 
00025  * Modified source versions must be plainly marked as such, and must not be
00026    misrepresented as being the original software.
00027 
00028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00029 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00031 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00032 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00033 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00034 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00035 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00036 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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;     //keep track of current insertion point
00228   int TraversalLocation;   //keep track of traversal position
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

Generated on Wed Nov 21 12:26:51 2001 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001