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 =========================================================================*/
00068 #ifndef __vtkCellArray_h
00069 #define __vtkCellArray_h
00070 
00071 #include "vtkIdTypeArray.h"
00072 #include "vtkCell.h"
00073 
00074 class VTK_COMMON_EXPORT vtkCellArray : public vtkObject
00075 {
00076 public:
00077   vtkTypeMacro(vtkCellArray,vtkObject);
00078 
00080   static vtkCellArray *New();
00081 
00083 
00084   int Allocate(const vtkIdType sz, const int ext=1000) 
00085     {return this->Ia->Allocate(sz,ext);}
00087 
00089 
00090   void Initialize() 
00091     {this->Ia->Initialize();}
00093 
00095 
00096   vtkIdType GetNumberOfCells() 
00097     {return this->NumberOfCells;}
00099 
00101 
00107   vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell)
00108     {return numCells*(1+maxPtsPerCell);}
00110 
00114   void InitTraversal() {this->TraversalLocation=0;};
00115 
00119   int GetNextCell(vtkIdType& npts, vtkIdType* &pts);
00120 
00122 
00123   vtkIdType GetSize() 
00124     {return this->Ia->GetSize();}
00126   
00128 
00131   vtkIdType GetNumberOfConnectivityEntries() 
00132     {return this->Ia->GetMaxId()+1;}
00134 
00137   void GetCell(vtkIdType loc, vtkIdType &npts, vtkIdType* &pts);
00138 
00140   vtkIdType InsertNextCell(vtkCell *cell);
00141 
00144   vtkIdType InsertNextCell(vtkIdType npts, vtkIdType* pts);
00145 
00148   vtkIdType InsertNextCell(vtkIdList *pts);
00149 
00154   vtkIdType InsertNextCell(int npts);
00155 
00158   void InsertCellPoint(vtkIdType id);
00159 
00162   void UpdateCellCount(int npts);
00163 
00165 
00167   vtkIdType GetInsertLocation(int npts)
00168     {return (this->InsertLocation - npts - 1);};
00170   
00172 
00173   vtkIdType GetTraversalLocation() 
00174     {return this->TraversalLocation;}
00175   void SetTraversalLocation(vtkIdType loc) 
00176     {this->TraversalLocation = loc;}
00178   
00180 
00182   vtkIdType GetTraversalLocation(vtkIdType npts) 
00183     {return(this->TraversalLocation-npts-1);}
00185   
00188   void ReverseCell(vtkIdType loc);
00189 
00191   void ReplaceCell(vtkIdType loc, int npts, vtkIdType *pts);
00192 
00195   int GetMaxCellSize();
00196 
00198 
00199   vtkIdType *GetPointer() 
00200     {return this->Ia->GetPointer(0);}
00202 
00206   vtkIdType *WritePointer(const vtkIdType ncells, const vtkIdType size);
00207 
00215   void SetCells(vtkIdType ncells, vtkIdTypeArray *cells);
00216   
00218   void DeepCopy(vtkCellArray *ca);
00219 
00221 
00222   vtkDataArray *GetData() 
00223     {return this->Ia;}
00225 
00227   void Reset();
00228 
00230 
00231   void Squeeze() 
00232     {this->Ia->Squeeze();}
00234 
00241   unsigned long GetActualMemorySize();
00242   
00243 protected:
00244   vtkCellArray();
00245   ~vtkCellArray();
00246 
00247   vtkIdType NumberOfCells;
00248   vtkIdType InsertLocation;     //keep track of current insertion point
00249   vtkIdType TraversalLocation;   //keep track of traversal position
00250   vtkIdTypeArray *Ia;
00251 private:
00252   vtkCellArray(const vtkCellArray&);  // Not implemented.
00253   void operator=(const vtkCellArray&);  // Not implemented.
00254 };
00255 
00256 
00257 inline vtkIdType vtkCellArray::InsertNextCell(vtkIdType npts, vtkIdType* pts)
00258 {
00259   vtkIdType i = this->Ia->GetMaxId() + 1;
00260   vtkIdType *ptr = this->Ia->WritePointer(i, npts+1);
00261   
00262   for ( *ptr++ = npts, i = 0; i < npts; i++)
00263     {
00264     *ptr++ = *pts++;
00265     }
00266 
00267   this->NumberOfCells++;
00268   this->InsertLocation += npts + 1;
00269 
00270   return this->NumberOfCells - 1;
00271 }
00272 
00273 inline vtkIdType vtkCellArray::InsertNextCell(vtkIdList *pts)
00274 {
00275   vtkIdType npts = pts->GetNumberOfIds();
00276   vtkIdType i = this->Ia->GetMaxId() + 1;
00277   vtkIdType *ptr = this->Ia->WritePointer(i,npts+1);
00278   
00279   for ( *ptr++ = npts, i = 0; i < npts; i++)
00280     {
00281     *ptr++ = pts->GetId(i);
00282     }
00283 
00284   this->NumberOfCells++;
00285   this->InsertLocation += npts + 1;
00286 
00287   return this->NumberOfCells - 1;
00288 }
00289 
00290 inline vtkIdType vtkCellArray::InsertNextCell(int npts)
00291 {
00292   this->InsertLocation = this->Ia->InsertNextValue(npts) + 1;
00293   this->NumberOfCells++;
00294 
00295   return this->NumberOfCells - 1;
00296 }
00297 
00298 inline void vtkCellArray::InsertCellPoint(vtkIdType id) 
00299 {
00300   this->Ia->InsertValue(this->InsertLocation++, id);
00301 }
00302 
00303 inline void vtkCellArray::UpdateCellCount(int npts) 
00304 {
00305   this->Ia->SetValue(this->InsertLocation-npts-1, npts);
00306 }
00307 
00308 inline vtkIdType vtkCellArray::InsertNextCell(vtkCell *cell)
00309 {
00310   int npts = cell->GetNumberOfPoints();
00311   vtkIdType i = this->Ia->GetMaxId() + 1;
00312   vtkIdType *ptr = this->Ia->WritePointer(i,npts+1);
00313   
00314   for ( *ptr++ = npts, i = 0; i < npts; i++)
00315     {
00316     *ptr++ = cell->PointIds->GetId(i);
00317     }
00318 
00319   this->NumberOfCells++;
00320   this->InsertLocation += npts + 1;
00321 
00322   return this->NumberOfCells - 1;
00323 }
00324 
00325 
00326 inline void vtkCellArray::Reset() 
00327 {
00328   this->NumberOfCells = 0;
00329   this->InsertLocation = 0;
00330   this->TraversalLocation = 0;
00331   this->Ia->Reset();
00332 }
00333 
00334 
00335 inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType* &pts)
00336 {
00337   if ( this->Ia->GetMaxId() >= 0 && 
00338   this->TraversalLocation <= this->Ia->GetMaxId() ) 
00339     {
00340     npts = this->Ia->GetValue(this->TraversalLocation++);
00341     pts = this->Ia->GetPointer(this->TraversalLocation);
00342     this->TraversalLocation += npts;
00343     return 1;
00344     }
00345   else
00346     {
00347     return 0;
00348     }
00349 }
00350 
00351 inline void vtkCellArray::GetCell(vtkIdType loc, vtkIdType &npts,
00352                                   vtkIdType* &pts)
00353 {
00354   npts=this->Ia->GetValue(loc++);
00355   pts=this->Ia->GetPointer(loc);
00356 }
00357 
00358 
00359 inline void vtkCellArray::ReverseCell(vtkIdType loc)
00360 {
00361   int i;
00362   vtkIdType tmp;
00363   vtkIdType npts=this->Ia->GetValue(loc);
00364   vtkIdType *pts=this->Ia->GetPointer(loc+1);
00365   for (i=0; i < (npts/2); i++) 
00366     {
00367     tmp = pts[i];
00368     pts[i] = pts[npts-i-1];
00369     pts[npts-i-1] = tmp;
00370     }
00371 }
00372 
00373 inline void vtkCellArray::ReplaceCell(vtkIdType loc, int npts, vtkIdType *pts)
00374 {
00375   vtkIdType *oldPts=this->Ia->GetPointer(loc+1);
00376   for (int i=0; i < npts; i++)
00377     {
00378     oldPts[i] = pts[i];
00379     }
00380 }
00381 
00382 inline vtkIdType *vtkCellArray::WritePointer(const vtkIdType ncells,
00383                                              const vtkIdType size)
00384 {
00385   this->NumberOfCells = ncells;
00386   this->InsertLocation = 0;
00387   this->TraversalLocation = 0;
00388   return this->Ia->WritePointer(0,size);
00389 }
00390 
00391 #endif

Generated on Thu Mar 28 14:19:14 2002 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001