VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkDenseArray.h 00005 00006 ------------------------------------------------------------------------- 00007 Copyright 2008 Sandia Corporation. 00008 Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00009 the U.S. Government retains certain rights in this software. 00010 ------------------------------------------------------------------------- 00011 00012 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00013 All rights reserved. 00014 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00015 00016 This software is distributed WITHOUT ANY WARRANTY; without even 00017 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00018 PURPOSE. See the above copyright notice for more information. 00019 00020 =========================================================================*/ 00021 00051 #ifndef __vtkDenseArray_h 00052 #define __vtkDenseArray_h 00053 00054 #include "vtkArrayCoordinates.h" 00055 #include "vtkObjectFactory.h" 00056 #include "vtkTypedArray.h" 00057 #include "vtkTypeTemplate.h" 00058 00059 template<typename T> 00060 class vtkDenseArray : 00061 public vtkTypeTemplate<vtkDenseArray<T>, vtkTypedArray<T> > 00062 { 00063 public: 00064 static vtkDenseArray<T>* New(); 00065 void PrintSelf(ostream &os, vtkIndent indent); 00066 00067 typedef typename vtkArray::CoordinateT CoordinateT; 00068 typedef typename vtkArray::DimensionT DimensionT; 00069 typedef typename vtkArray::SizeT SizeT; 00070 00071 // vtkArray API 00072 bool IsDense(); 00073 const vtkArrayExtents& GetExtents(); 00074 SizeT GetNonNullSize(); 00075 void GetCoordinatesN(const SizeT n, vtkArrayCoordinates& coordinates); 00076 vtkArray* DeepCopy(); 00077 00078 // vtkTypedArray API 00079 const T& GetValue(CoordinateT i); 00080 const T& GetValue(CoordinateT i, CoordinateT j); 00081 const T& GetValue(CoordinateT i, CoordinateT j, CoordinateT k); 00082 const T& GetValue(const vtkArrayCoordinates& coordinates); 00083 const T& GetValueN(const SizeT n); 00084 void SetValue(CoordinateT i, const T& value); 00085 void SetValue(CoordinateT i, CoordinateT j, const T& value); 00086 void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value); 00087 void SetValue(const vtkArrayCoordinates& coordinates, const T& value); 00088 void SetValueN(const SizeT n, const T& value); 00089 00090 // vtkDenseArray API 00091 00093 00096 class MemoryBlock 00097 { 00098 public: 00099 virtual ~MemoryBlock(); 00100 // Description: 00101 // Returns a pointer to the block of memory to be used for storage. 00102 virtual T* GetAddress() = 0; 00103 }; 00105 00107 00110 class HeapMemoryBlock : 00111 public MemoryBlock 00112 { 00113 public: 00114 HeapMemoryBlock(const vtkArrayExtents& extents); 00115 virtual ~HeapMemoryBlock(); 00116 virtual T* GetAddress(); 00118 00119 private: 00120 T* Storage; 00121 }; 00122 00124 00126 class StaticMemoryBlock : 00127 public MemoryBlock 00128 { 00129 public: 00130 StaticMemoryBlock(T* const storage); 00131 virtual T* GetAddress(); 00133 00134 private: 00135 T* Storage; 00136 }; 00137 00151 void ExternalStorage(const vtkArrayExtents& extents, MemoryBlock* storage); 00152 00154 void Fill(const T& value); 00155 00158 T& operator[](const vtkArrayCoordinates& coordinates); 00159 00162 const T* GetStorage() const; 00163 00166 T* GetStorage(); 00167 00168 protected: 00169 vtkDenseArray(); 00170 ~vtkDenseArray(); 00171 00172 private: 00173 vtkDenseArray(const vtkDenseArray&); // Not implemented 00174 void operator=(const vtkDenseArray&); // Not implemented 00175 00176 void InternalResize(const vtkArrayExtents& extents); 00177 void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label); 00178 vtkStdString InternalGetDimensionLabel(DimensionT i); 00179 inline vtkIdType MapCoordinates(CoordinateT i); 00180 inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j); 00181 inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j, CoordinateT k); 00182 inline vtkIdType MapCoordinates(const vtkArrayCoordinates& coordinates); 00183 00184 void Reconfigure(const vtkArrayExtents& extents, MemoryBlock* storage); 00185 00186 typedef vtkDenseArray<T> ThisT; 00187 00189 vtkArrayExtents Extents; 00190 00192 std::vector<vtkStdString> DimensionLabels; 00193 00195 MemoryBlock* Storage; 00196 00198 00200 T* Begin; 00201 T* End; 00203 00205 00206 std::vector<vtkIdType> Offsets; 00207 // Description: 00208 // Stores the stride along each array dimension (used for fast lookups). 00209 std::vector<vtkIdType> Strides; 00210 }; 00212 00213 #include "vtkDenseArray.txx" 00214 00215 #endif 00216