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

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