VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkCellLinks.h 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_FILTERING_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 vtkTypeMacro(vtkCellLinks,vtkObject); 00048 void PrintSelf(ostream& os, vtkIndent indent); 00049 00052 void Allocate(vtkIdType numLinks, vtkIdType ext=1000); 00053 00055 Link &GetLink(vtkIdType ptId) {return this->Array[ptId];}; 00056 00058 unsigned short GetNcells(vtkIdType ptId) { return this->Array[ptId].ncells;}; 00059 00061 void BuildLinks(vtkDataSet *data); 00062 00064 void BuildLinks(vtkDataSet *data, vtkCellArray *Connectivity); 00065 00067 vtkIdType *GetCells(vtkIdType ptId) {return this->Array[ptId].cells;}; 00068 00071 vtkIdType InsertNextPoint(int numLinks); 00072 00076 void InsertNextCellReference(vtkIdType ptId, vtkIdType cellId); 00077 00079 void DeletePoint(vtkIdType ptId); 00080 00084 void RemoveCellReference(vtkIdType cellId, vtkIdType ptId); 00085 00089 void AddCellReference(vtkIdType cellId, vtkIdType ptId); 00090 00093 void ResizeCellList(vtkIdType ptId, int size); 00094 00096 void Squeeze(); 00097 00099 void Reset(); 00100 00107 unsigned long GetActualMemorySize(); 00108 00111 void DeepCopy(vtkCellLinks *src); 00112 00113 protected: 00114 vtkCellLinks():Array(NULL),Size(0),MaxId(-1),Extend(1000) {}; 00115 ~vtkCellLinks(); 00116 00118 void IncrementLinkCount(vtkIdType ptId) { this->Array[ptId].ncells++;}; 00119 00120 void AllocateLinks(vtkIdType n); 00121 00123 00124 void InsertCellReference(vtkIdType ptId, unsigned short pos, 00125 vtkIdType cellId); 00127 00128 Link *Array; // pointer to data 00129 vtkIdType Size; // allocated size of data 00130 vtkIdType MaxId; // maximum index inserted thus far 00131 vtkIdType Extend; // grow array by this point 00132 Link *Resize(vtkIdType sz); // function to resize data 00133 private: 00134 vtkCellLinks(const vtkCellLinks&); // Not implemented. 00135 void operator=(const vtkCellLinks&); // Not implemented. 00136 }; 00137 00138 //---------------------------------------------------------------------------- 00139 inline void vtkCellLinks::InsertCellReference(vtkIdType ptId, 00140 unsigned short pos, 00141 vtkIdType cellId) 00142 { 00143 this->Array[ptId].cells[pos] = cellId; 00144 } 00145 00146 //---------------------------------------------------------------------------- 00147 inline void vtkCellLinks::DeletePoint(vtkIdType ptId) 00148 { 00149 this->Array[ptId].ncells = 0; 00150 delete [] this->Array[ptId].cells; 00151 this->Array[ptId].cells = NULL; 00152 } 00153 00154 //---------------------------------------------------------------------------- 00155 inline void vtkCellLinks::InsertNextCellReference(vtkIdType ptId, 00156 vtkIdType cellId) 00157 { 00158 this->Array[ptId].cells[this->Array[ptId].ncells++] = cellId; 00159 } 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 //---------------------------------------------------------------------------- 00182 inline void vtkCellLinks::AddCellReference(vtkIdType cellId, vtkIdType ptId) 00183 { 00184 this->Array[ptId].cells[this->Array[ptId].ncells++] = cellId; 00185 } 00186 00187 //---------------------------------------------------------------------------- 00188 inline void vtkCellLinks::ResizeCellList(vtkIdType ptId, int size) 00189 { 00190 int newSize; 00191 vtkIdType *cells; 00192 00193 newSize = this->Array[ptId].ncells + size; 00194 cells = new vtkIdType[newSize]; 00195 memcpy(cells, this->Array[ptId].cells, 00196 this->Array[ptId].ncells*sizeof(vtkIdType)); 00197 delete [] this->Array[ptId].cells; 00198 this->Array[ptId].cells = cells; 00199 } 00200 00201 #endif 00202