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 vtkstd::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 00172 00175 void SetExtentsFromContents(); 00176 // Description: 00177 // Specify arbitrary array extents, without altering the contents of the array. Note 00178 // that the extents must be as-large-or-larger-than the extents of the actual values 00179 // stored in the array. The number of dimensions in the supplied extents must match the 00180 // number of dimensions currently stored in the array. 00181 void SetExtents(const vtkArrayExtents& extents); 00183 00185 00189 inline void AddValue(CoordinateT i, const T& value); 00190 inline void AddValue(CoordinateT i, CoordinateT j, const T& value); 00191 inline void AddValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value); 00192 void AddValue(const vtkArrayCoordinates& coordinates, const T& value); 00194 00201 bool Validate(); 00202 00203 protected: 00204 vtkSparseArray(); 00205 ~vtkSparseArray(); 00206 00207 private: 00208 vtkSparseArray(const vtkSparseArray&); // Not implemented 00209 void operator=(const vtkSparseArray&); // Not implemented 00210 00211 void InternalResize(const vtkArrayExtents& extents); 00212 void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label); 00213 vtkStdString InternalGetDimensionLabel(DimensionT i); 00214 00215 typedef vtkSparseArray<T> ThisT; 00216 00218 vtkArrayExtents Extents; 00219 00221 vtkstd::vector<vtkStdString> DimensionLabels; 00222 00226 vtkstd::vector<vtkstd::vector<CoordinateT> > Coordinates; 00227 00229 vtkstd::vector<T> Values; 00230 00232 00234 T NullValue; 00235 }; 00237 00238 #include "vtkSparseArray.txx" 00239 00240 #endif