VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkDataArrayTemplate.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 =========================================================================*/ 00023 #ifndef __vtkDataArrayTemplate_h 00024 #define __vtkDataArrayTemplate_h 00025 00026 #include "vtkDataArray.h" 00027 00028 template <class T> 00029 class vtkDataArrayTemplateLookup; 00030 00031 template <class T> 00032 class VTK_COMMON_EXPORT vtkDataArrayTemplate: public vtkDataArray 00033 { 00034 public: 00035 typedef vtkDataArray Superclass; 00036 void PrintSelf(ostream& os, vtkIndent indent); 00037 00040 int Allocate(vtkIdType sz, vtkIdType ext=1000); 00041 00043 void Initialize(); 00044 00046 int GetDataTypeSize() { return static_cast<int>(sizeof(T)); } 00047 00049 void SetNumberOfTuples(vtkIdType number); 00050 00056 virtual void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source); 00057 00061 virtual void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source); 00062 00066 virtual vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray* source); 00067 00070 double* GetTuple(vtkIdType i); 00071 00073 00074 void GetTuple(vtkIdType i, double* tuple); 00075 void GetTupleValue(vtkIdType i, T* tuple); 00077 00079 00080 void SetTuple(vtkIdType i, const float* tuple); 00081 void SetTuple(vtkIdType i, const double* tuple); 00082 void SetTupleValue(vtkIdType i, const T* tuple); 00084 00086 00088 void InsertTuple(vtkIdType i, const float* tuple); 00089 void InsertTuple(vtkIdType i, const double* tuple); 00090 void InsertTupleValue(vtkIdType i, const T* tuple); 00092 00094 00096 vtkIdType InsertNextTuple(const float* tuple); 00097 vtkIdType InsertNextTuple(const double* tuple); 00098 vtkIdType InsertNextTupleValue(const T* tuple); 00100 00102 00104 void GetValueRange(T range[2], int comp) { 00105 this->ComputeRange(comp); 00106 range[0] = this->ValueRange[0]; 00107 range[1] = this->ValueRange[1]; } 00108 T *GetValueRange(int comp) { 00109 this->ComputeRange(comp); 00110 return this->ValueRange; } 00112 00114 void Squeeze() { this->ResizeAndExtend (this->MaxId+1, false); } 00115 00117 vtkIdType Capacity() { return this->Size; } 00118 00121 virtual int Resize(vtkIdType numTuples); 00122 00124 T GetValue(vtkIdType id) { return this->Array[id]; } 00125 00127 00129 void SetValue(vtkIdType id, T value) 00130 { this->Array[id] = value;}; 00132 00136 void SetNumberOfValues(vtkIdType number); 00137 00139 void InsertValue(vtkIdType id, T f); 00140 00142 void SetVariantValue(vtkIdType id, vtkVariant value); 00143 00146 vtkIdType InsertNextValue(T f); 00147 00149 00152 virtual void RemoveTuple(vtkIdType id); 00153 virtual void RemoveFirstTuple(); 00154 virtual void RemoveLastTuple(); 00156 00160 double GetComponent(vtkIdType i, int j); 00161 00166 void SetComponent(vtkIdType i, int j, double c); 00167 00171 virtual void InsertComponent(vtkIdType i, int j, double c); 00172 00174 00177 T* WritePointer(vtkIdType id, vtkIdType number); 00178 virtual void* WriteVoidPointer(vtkIdType id, vtkIdType number) 00179 { return this->WritePointer(id, number); } 00181 00183 00185 T* GetPointer(vtkIdType id) { return this->Array + id; } 00186 virtual void* GetVoidPointer(vtkIdType id) { return this->GetPointer(id); } 00188 00190 00191 void DeepCopy(vtkDataArray* da); 00192 void DeepCopy(vtkAbstractArray* aa) 00193 { this->Superclass::DeepCopy(aa); } 00195 00196 //BTX 00197 enum DeleteMethod 00198 { 00199 VTK_DATA_ARRAY_FREE, 00200 VTK_DATA_ARRAY_DELETE 00201 }; 00202 //ETX 00203 00205 00214 void SetArray(T* array, vtkIdType size, int save, int deleteMethod); 00215 void SetArray(T* array, vtkIdType size, int save) 00216 { this->SetArray(array, size, save, VTK_DATA_ARRAY_FREE); } 00217 virtual void SetVoidArray(void* array, vtkIdType size, int save) 00218 { this->SetArray(static_cast<T*>(array), size, save); } 00219 virtual void SetVoidArray(void* array, 00220 vtkIdType size, 00221 int save, 00222 int deleteMethod) 00223 { 00224 this->SetArray(static_cast<T*>(array), size, save, deleteMethod); 00225 } 00227 00231 virtual void ExportToVoidPointer(void *out_ptr); 00232 00234 virtual vtkArrayIterator* NewIterator(); 00235 00237 00238 virtual vtkIdType LookupValue(vtkVariant value); 00239 virtual void LookupValue(vtkVariant value, vtkIdList* ids); 00240 vtkIdType LookupValue(T value); 00241 void LookupValue(T value, vtkIdList* ids); 00243 00250 virtual void DataChanged(); 00251 00255 virtual void DataElementChanged(vtkIdType id); 00256 00260 virtual void ClearLookup(); 00261 00262 protected: 00263 vtkDataArrayTemplate(vtkIdType numComp); 00264 ~vtkDataArrayTemplate(); 00265 00266 T* Array; // pointer to data 00267 T ValueRange[2]; // range of the data 00268 T* ResizeAndExtend(vtkIdType sz, bool useExactSize); // function to resize data 00269 T* Realloc(vtkIdType sz); 00270 00271 int TupleSize; //used for data conversion 00272 double* Tuple; 00273 00274 int SaveUserArray; 00275 int DeleteMethod; 00276 00277 virtual void ComputeScalarRange(int comp); 00278 virtual void ComputeVectorRange(); 00279 private: 00280 vtkDataArrayTemplate(const vtkDataArrayTemplate&); // Not implemented. 00281 void operator=(const vtkDataArrayTemplate&); // Not implemented. 00282 00283 vtkDataArrayTemplateLookup<T>* Lookup; 00284 void UpdateLookup(); 00285 00286 void DeleteArray(); 00287 }; 00288 00289 #if !defined(VTK_NO_EXPLICIT_TEMPLATE_INSTANTIATION) 00290 # define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \ 00291 template class VTK_COMMON_EXPORT vtkDataArrayTemplate< T > 00292 #else 00293 # include "vtkDataArrayTemplateImplicit.txx" 00294 # define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) 00295 #endif 00296 00297 #endif // !defined(__vtkDataArrayTemplate_h) 00298 00299 // This portion must be OUTSIDE the include blockers. Each 00300 // vtkDataArray subclass uses this to give its instantiation of this 00301 // template a DLL interface. 00302 #if defined(VTK_DATA_ARRAY_TEMPLATE_TYPE) 00303 # if defined(VTK_BUILD_SHARED_LIBS) && defined(_MSC_VER) 00304 # pragma warning (push) 00305 # pragma warning (disable: 4091) // warning C4091: 'extern ' : 00306 // ignored on left of 'int' when no variable is declared 00307 # pragma warning (disable: 4231) // Compiler-specific extension warning. 00308 00309 // We need to disable warning 4910 and do an extern dllexport 00310 // anyway. When deriving vtkCharArray and other types from an 00311 // instantiation of this template the compiler does an explicit 00312 // instantiation of the base class. From outside the vtkCommon 00313 // library we block this using an extern dllimport instantiation. 00314 // For classes inside vtkCommon we should be able to just do an 00315 // extern instantiation, but VS 2008 complains about missing 00316 // definitions. We cannot do an extern dllimport inside vtkCommon 00317 // since the symbols are local to the dll. An extern dllexport 00318 // seems to be the only way to convince VS 2008 to do the right 00319 // thing, so we just disable the warning. 00320 # pragma warning (disable: 4910) // extern and dllexport incompatible 00321 00322 // Use an "extern explicit instantiation" to give the class a DLL 00323 // interface. This is a compiler-specific extension. 00324 extern VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(VTK_DATA_ARRAY_TEMPLATE_TYPE); 00325 # pragma warning (pop) 00326 # endif 00327 # undef VTK_DATA_ARRAY_TEMPLATE_TYPE 00328 #endif