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

vtkCellLinks.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkCellLinks.h,v $
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 =========================================================================*/
00037 #ifndef __vtkCellLinks_h
00038 #define __vtkCellLinks_h
00039 
00040 #include "vtkObject.h"
00041 class vtkDataSet;
00042 class vtkCellArray;
00043 
00044 class VTK_FILTERING_EXPORT vtkCellLinks : public vtkObject 
00045 {
00046 public:
00047 
00048   //BTX
00049   class Link {
00050   public:
00051     unsigned short ncells;
00052     vtkIdType *cells;
00053   };
00054   //ETX
00055 
00056   static vtkCellLinks *New();
00057   vtkTypeRevisionMacro(vtkCellLinks,vtkObject);
00058   void PrintSelf(ostream& os, vtkIndent indent);
00059 
00062   void Allocate(vtkIdType numLinks, vtkIdType ext=1000);
00063 
00065   Link &GetLink(vtkIdType ptId) {return this->Array[ptId];};
00066 
00068   unsigned short GetNcells(vtkIdType ptId) { return this->Array[ptId].ncells;};
00069 
00071   void BuildLinks(vtkDataSet *data);
00072 
00074   void BuildLinks(vtkDataSet *data, vtkCellArray *Connectivity);
00075 
00077   vtkIdType *GetCells(vtkIdType ptId) {return this->Array[ptId].cells;};
00078 
00081   vtkIdType InsertNextPoint(int numLinks);
00082 
00086   void InsertNextCellReference(vtkIdType ptId, vtkIdType cellId);
00087 
00089   void DeletePoint(vtkIdType ptId);
00090 
00094   void RemoveCellReference(vtkIdType cellId, vtkIdType ptId);
00095 
00099   void AddCellReference(vtkIdType cellId, vtkIdType ptId);
00100 
00103   void ResizeCellList(vtkIdType ptId, int size);
00104 
00106   void Squeeze();
00107 
00109   void Reset();
00110 
00117   unsigned long GetActualMemorySize();
00118   
00121   void DeepCopy(vtkCellLinks *src);
00122 
00123 protected:
00124   vtkCellLinks():Array(NULL),Size(0),MaxId(-1),Extend(1000) {};
00125   ~vtkCellLinks();
00126 
00128   void IncrementLinkCount(vtkIdType ptId) { this->Array[ptId].ncells++;};
00129 
00130   void AllocateLinks(vtkIdType n);
00131 
00133 
00134   void InsertCellReference(vtkIdType ptId, unsigned short pos,
00135                            vtkIdType cellId);
00137 
00138   Link *Array;   // pointer to data
00139   vtkIdType Size;       // allocated size of data
00140   vtkIdType MaxId;     // maximum index inserted thus far
00141   vtkIdType Extend;     // grow array by this point
00142   Link *Resize(vtkIdType sz);  // function to resize data
00143 private:
00144   vtkCellLinks(const vtkCellLinks&);  // Not implemented.
00145   void operator=(const vtkCellLinks&);  // Not implemented.
00146 };
00147 
00148 //----------------------------------------------------------------------------
00149 inline void vtkCellLinks::InsertCellReference(vtkIdType ptId,
00150                                               unsigned short pos,
00151                                               vtkIdType cellId) 
00152 {
00153   this->Array[ptId].cells[pos] = cellId;
00154 }
00155 
00156 //----------------------------------------------------------------------------
00157 inline void vtkCellLinks::DeletePoint(vtkIdType ptId)
00158 {
00159   this->Array[ptId].ncells = 0;
00160   delete [] this->Array[ptId].cells;
00161   this->Array[ptId].cells = NULL;
00162 }
00163 
00164 //----------------------------------------------------------------------------
00165 inline void vtkCellLinks::InsertNextCellReference(vtkIdType ptId,
00166                                                   vtkIdType cellId) 
00167 {
00168   this->Array[ptId].cells[this->Array[ptId].ncells++] = cellId;
00169 }
00170 
00171 //----------------------------------------------------------------------------
00172 inline void vtkCellLinks::RemoveCellReference(vtkIdType cellId, vtkIdType ptId)
00173 {
00174   vtkIdType *cells=this->Array[ptId].cells;
00175   int ncells=this->Array[ptId].ncells;
00176 
00177   for (int i=0; i < ncells; i++)
00178     {
00179     if (cells[i] == cellId)
00180       {
00181       for (int j=i; j < (ncells-1); j++)
00182         {
00183         cells[j] = cells[j+1];
00184         }
00185       this->Array[ptId].ncells--;
00186       break;
00187       }
00188     }
00189 }
00190 
00191 //----------------------------------------------------------------------------
00192 inline void vtkCellLinks::AddCellReference(vtkIdType cellId, vtkIdType ptId)
00193 {
00194   this->Array[ptId].cells[this->Array[ptId].ncells++] = cellId;
00195 }
00196 
00197 //----------------------------------------------------------------------------
00198 inline void vtkCellLinks::ResizeCellList(vtkIdType ptId, int size)
00199 {
00200   int newSize;
00201   vtkIdType *cells;
00202   
00203   newSize = this->Array[ptId].ncells + size;
00204   cells = new vtkIdType[newSize];
00205   memcpy(cells, this->Array[ptId].cells,
00206          this->Array[ptId].ncells*sizeof(vtkIdType));
00207   delete [] this->Array[ptId].cells;
00208   this->Array[ptId].cells = cells;
00209 }
00210 
00211 #endif
00212