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 "vtkCommonDataModelModule.h" // For export macro 00031 #include "vtkObject.h" 00032 class vtkDataSet; 00033 class vtkCellArray; 00034 00035 class VTKCOMMONDATAMODEL_EXPORT vtkCellLinks : public vtkObject 00036 { 00037 public: 00038 00039 //BTX 00040 class Link { 00041 public: 00042 unsigned short ncells; 00043 vtkIdType *cells; 00044 }; 00045 //ETX 00046 00047 static vtkCellLinks *New(); 00048 vtkTypeMacro(vtkCellLinks,vtkObject); 00049 void PrintSelf(ostream& os, vtkIndent indent); 00050 00053 void Allocate(vtkIdType numLinks, vtkIdType ext=1000); 00054 00056 Link &GetLink(vtkIdType ptId) {return this->Array[ptId];}; 00057 00059 unsigned short GetNcells(vtkIdType ptId) { return this->Array[ptId].ncells;}; 00060 00062 void BuildLinks(vtkDataSet *data); 00063 00065 void BuildLinks(vtkDataSet *data, vtkCellArray *Connectivity); 00066 00068 vtkIdType *GetCells(vtkIdType ptId) {return this->Array[ptId].cells;}; 00069 00072 vtkIdType InsertNextPoint(int numLinks); 00073 00077 void InsertNextCellReference(vtkIdType ptId, vtkIdType cellId); 00078 00080 void DeletePoint(vtkIdType ptId); 00081 00085 void RemoveCellReference(vtkIdType cellId, vtkIdType ptId); 00086 00090 void AddCellReference(vtkIdType cellId, vtkIdType ptId); 00091 00094 void ResizeCellList(vtkIdType ptId, int size); 00095 00097 void Squeeze(); 00098 00100 void Reset(); 00101 00108 unsigned long GetActualMemorySize(); 00109 00112 void DeepCopy(vtkCellLinks *src); 00113 00114 protected: 00115 vtkCellLinks():Array(NULL),Size(0),MaxId(-1),Extend(1000) {}; 00116 ~vtkCellLinks(); 00117 00119 void IncrementLinkCount(vtkIdType ptId) { this->Array[ptId].ncells++;}; 00120 00121 void AllocateLinks(vtkIdType n); 00122 00124 00125 void InsertCellReference(vtkIdType ptId, unsigned short pos, 00126 vtkIdType cellId); 00128 00129 Link *Array; // pointer to data 00130 vtkIdType Size; // allocated size of data 00131 vtkIdType MaxId; // maximum index inserted thus far 00132 vtkIdType Extend; // grow array by this point 00133 Link *Resize(vtkIdType sz); // function to resize data 00134 private: 00135 vtkCellLinks(const vtkCellLinks&); // Not implemented. 00136 void operator=(const vtkCellLinks&); // Not implemented. 00137 }; 00138 00139 //---------------------------------------------------------------------------- 00140 inline void vtkCellLinks::InsertCellReference(vtkIdType ptId, 00141 unsigned short pos, 00142 vtkIdType cellId) 00143 { 00144 this->Array[ptId].cells[pos] = cellId; 00145 } 00146 00147 //---------------------------------------------------------------------------- 00148 inline void vtkCellLinks::DeletePoint(vtkIdType ptId) 00149 { 00150 this->Array[ptId].ncells = 0; 00151 delete [] this->Array[ptId].cells; 00152 this->Array[ptId].cells = NULL; 00153 } 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 //---------------------------------------------------------------------------- 00163 inline void vtkCellLinks::RemoveCellReference(vtkIdType cellId, vtkIdType ptId) 00164 { 00165 vtkIdType *cells=this->Array[ptId].cells; 00166 int ncells=this->Array[ptId].ncells; 00167 00168 for (int i=0; i < ncells; i++) 00169 { 00170 if (cells[i] == cellId) 00171 { 00172 for (int j=i; j < (ncells-1); j++) 00173 { 00174 cells[j] = cells[j+1]; 00175 } 00176 this->Array[ptId].ncells--; 00177 break; 00178 } 00179 } 00180 } 00181 00182 //---------------------------------------------------------------------------- 00183 inline void vtkCellLinks::AddCellReference(vtkIdType cellId, vtkIdType ptId) 00184 { 00185 this->Array[ptId].cells[this->Array[ptId].ncells++] = cellId; 00186 } 00187 00188 //---------------------------------------------------------------------------- 00189 inline void vtkCellLinks::ResizeCellList(vtkIdType ptId, int size) 00190 { 00191 int newSize; 00192 vtkIdType *cells; 00193 00194 newSize = this->Array[ptId].ncells + size; 00195 cells = new vtkIdType[newSize]; 00196 memcpy(cells, this->Array[ptId].cells, 00197 this->Array[ptId].ncells*sizeof(vtkIdType)); 00198 delete [] this->Array[ptId].cells; 00199 this->Array[ptId].cells = cells; 00200 } 00201 00202 #endif 00203