VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkSparseArray.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 00071 #ifndef __vtkSparseArray_h 00072 #define __vtkSparseArray_h 00073 00074 #include "vtkArrayCoordinates.h" 00075 #include "vtkArraySort.h" 00076 #include "vtkObjectFactory.h" 00077 #include "vtkTypeTemplate.h" 00078 #include "vtkTypedArray.h" 00079 00080 template<typename T> 00081 class vtkSparseArray : 00082 public vtkTypeTemplate<vtkSparseArray<T>, vtkTypedArray<T> > 00083 { 00084 public: 00085 static vtkSparseArray<T>* New(); 00086 void PrintSelf(ostream &os, vtkIndent indent); 00087 00088 typedef typename vtkArray::CoordinateT CoordinateT; 00089 typedef typename vtkArray::DimensionT DimensionT; 00090 typedef typename vtkArray::SizeT SizeT; 00091 00092 // vtkArray API 00093 bool IsDense(); 00094 const vtkArrayExtents& GetExtents(); 00095 SizeT GetNonNullSize(); 00096 void GetCoordinatesN(const SizeT n, vtkArrayCoordinates& coordinates); 00097 vtkArray* DeepCopy(); 00098 00099 // vtkTypedArray API 00100 const T& GetValue(CoordinateT i); 00101 const T& GetValue(CoordinateT i, CoordinateT j); 00102 const T& GetValue(CoordinateT i, CoordinateT j, CoordinateT k); 00103 const T& GetValue(const vtkArrayCoordinates& coordinates); 00104 const T& GetValueN(const SizeT n); 00105 void SetValue(CoordinateT i, const T& value); 00106 void SetValue(CoordinateT i, CoordinateT j, const T& value); 00107 void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value); 00108 void SetValue(const vtkArrayCoordinates& coordinates, const T& value); 00109 void SetValueN(const SizeT n, const T& value); 00110 00111 // vtkSparseArray API 00112 00115 void SetNullValue(const T& value); 00116 00119 const T& GetNullValue(); 00120 00124 void Clear(); 00125 00131 void Sort(const vtkArraySort& sort); 00132 00134 std::vector<CoordinateT> GetUniqueCoordinates(DimensionT dimension); 00135 00140 const CoordinateT* GetCoordinateStorage(DimensionT dimension) const; 00141 00147 CoordinateT* GetCoordinateStorage(DimensionT dimension); 00148 00153 const T* GetValueStorage() const; 00154 00159 T* GetValueStorage(); 00160 00169 void ReserveStorage(const SizeT value_count); 00170 00174 void SetExtentsFromContents(); 00180 void SetExtents(const vtkArrayExtents& extents); 00181 00183 00187 inline void AddValue(CoordinateT i, const T& value); 00188 inline void AddValue(CoordinateT i, CoordinateT j, const T& value); 00189 inline void AddValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value); 00190 void AddValue(const vtkArrayCoordinates& coordinates, const T& value); 00192 00199 bool Validate(); 00200 00201 protected: 00202 vtkSparseArray(); 00203 ~vtkSparseArray(); 00204 00205 private: 00206 vtkSparseArray(const vtkSparseArray&); // Not implemented 00207 void operator=(const vtkSparseArray&); // Not implemented 00208 00209 void InternalResize(const vtkArrayExtents& extents); 00210 void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label); 00211 vtkStdString InternalGetDimensionLabel(DimensionT i); 00212 00213 typedef vtkSparseArray<T> ThisT; 00214 00216 vtkArrayExtents Extents; 00217 00219 std::vector<vtkStdString> DimensionLabels; 00220 00224 std::vector<std::vector<CoordinateT> > Coordinates; 00225 00227 std::vector<T> Values; 00228 00230 00232 T NullValue; 00233 }; 00235 00236 #include "vtkSparseArray.txx" 00237 00238 #endif 00239 // VTK-HeaderTest-Exclude: vtkSparseArray.h