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

Common/vtkCellLinks.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkCellLinks.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 =========================================================================*/
00031 #ifndef __vtkCellLinks_h
00032 #define __vtkCellLinks_h
00033 
00034 #include "vtkObject.h"
00035 class vtkDataSet;
00036 class vtkCellArray;
00037 
00038 class VTK_COMMON_EXPORT vtkCellLinks : public vtkObject 
00039 {
00040 public:
00041 
00042   //BTX
00043   class Link {
00044   public:
00045     unsigned short ncells;
00046     vtkIdType *cells;
00047   };
00048   //ETX
00049 
00050   static vtkCellLinks *New();
00051   vtkTypeRevisionMacro(vtkCellLinks,vtkObject);
00052 
00055   void Allocate(vtkIdType numLinks, vtkIdType ext=1000);
00056 
00058   Link &GetLink(vtkIdType ptId) {return this->Array[ptId];};
00059 
00061   unsigned short GetNcells(vtkIdType ptId) { return this->Array[ptId].ncells;};
00062 
00064   void BuildLinks(vtkDataSet *data);
00065 
00067   void BuildLinks(vtkDataSet *data, vtkCellArray *Connectivity);
00068 
00070   vtkIdType *GetCells(vtkIdType ptId) {return this->Array[ptId].cells;};
00071 
00074   vtkIdType InsertNextPoint(int numLinks);
00075 
00079   void InsertNextCellReference(vtkIdType ptId, vtkIdType cellId);
00080 
00082   void DeletePoint(vtkIdType ptId);
00083 
00087   void RemoveCellReference(vtkIdType cellId, vtkIdType ptId);
00088 
00092   void AddCellReference(vtkIdType cellId, vtkIdType ptId);
00093 
00096   void ResizeCellList(vtkIdType ptId, int size);
00097 
00099   void Squeeze();
00100 
00102   void Reset();
00103 
00110   unsigned long GetActualMemorySize();
00111   
00114   void DeepCopy(vtkCellLinks *src);
00115 
00116 protected:
00117   vtkCellLinks():Array(NULL),Size(0),MaxId(-1),Extend(1000) {};
00118   ~vtkCellLinks();
00119 
00121   void IncrementLinkCount(vtkIdType ptId) { this->Array[ptId].ncells++;};
00122 
00123   void AllocateLinks(vtkIdType n);
00124 
00126 
00127   void InsertCellReference(vtkIdType ptId, unsigned short pos,
00128                            vtkIdType cellId);
00130 
00131   Link *Array;   // pointer to data
00132   vtkIdType Size;       // allocated size of data
00133   vtkIdType MaxId;     // maximum index inserted thus far
00134   vtkIdType Extend;     // grow array by this point
00135   Link *Resize(vtkIdType sz);  // function to resize data
00136 private:
00137   vtkCellLinks(const vtkCellLinks&);  // Not implemented.
00138   void operator=(const vtkCellLinks&);  // Not implemented.
00139 };
00140 
00141 
00142 inline void vtkCellLinks::InsertCellReference(vtkIdType ptId,
00143                                               unsigned short pos,
00144                                               vtkIdType cellId) 
00145 {
00146   this->Array[ptId].cells[pos] = cellId;
00147 }
00148 
00149 inline void vtkCellLinks::DeletePoint(vtkIdType ptId)
00150 {
00151   this->Array[ptId].ncells = 0;
00152   delete [] this->Array[ptId].cells;
00153   this->Array[ptId].cells = NULL;
00154 }
00155 
00156 inline void vtkCellLinks::InsertNextCellReference(vtkIdType ptId,
00157                                                   vtkIdType cellId) 
00158 {
00159   this->Array[ptId].cells[this->Array[ptId].ncells++] = cellId;
00160 }
00161 
00162 inline void vtkCellLinks::RemoveCellReference(vtkIdType cellId, vtkIdType ptId)
00163 {
00164   vtkIdType *cells=this->Array[ptId].cells;
00165   int ncells=this->Array[ptId].ncells;
00166 
00167   for (int i=0; i < ncells; i++)
00168     {
00169     if (cells[i] == cellId)
00170       {
00171       for (int j=i; j < (ncells-1); j++)
00172         {
00173         cells[j] = cells[j+1];
00174         }
00175       this->Array[ptId].ncells--;
00176       break;
00177       }
00178     }
00179 }
00180 
00181 inline void vtkCellLinks::AddCellReference(vtkIdType cellId, vtkIdType ptId)
00182 {
00183   this->Array[ptId].cells[this->Array[ptId].ncells++] = cellId;
00184 }
00185 
00186 inline void vtkCellLinks::ResizeCellList(vtkIdType ptId, int size)
00187 {
00188   int newSize;
00189   vtkIdType *cells;
00190   
00191   newSize = this->Array[ptId].ncells + size;
00192   cells = new vtkIdType[newSize];
00193   memcpy(cells, this->Array[ptId].cells,
00194          this->Array[ptId].ncells*sizeof(vtkIdType));
00195   delete [] this->Array[ptId].cells;
00196   this->Array[ptId].cells = cells;
00197 }
00198 
00199 #endif
00200