VTK
vtkSparseArray.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkSparseArray.h
5 
6 -------------------------------------------------------------------------
7  Copyright 2008 Sandia Corporation.
8  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9  the U.S. Government retains certain rights in this software.
10 -------------------------------------------------------------------------
11 
12  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
13  All rights reserved.
14  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
15 
16  This software is distributed WITHOUT ANY WARRANTY; without even
17  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18  PURPOSE. See the above copyright notice for more information.
19 
20 =========================================================================*/
21 
72 #ifndef vtkSparseArray_h
73 #define vtkSparseArray_h
74 
75 #include "vtkArrayCoordinates.h"
76 #include "vtkArraySort.h"
77 #include "vtkObjectFactory.h"
78 #include "vtkTypedArray.h"
79 
80 template<typename T>
81 class vtkSparseArray : public vtkTypedArray<T>
82 {
83 public:
85  static vtkSparseArray<T>* New();
86  void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE;
87 
89  typedef typename vtkArray::DimensionT DimensionT;
90  typedef typename vtkArray::SizeT SizeT;
91 
92  // vtkArray API
93  bool IsDense() VTK_OVERRIDE;
94  const vtkArrayExtents& GetExtents() VTK_OVERRIDE;
95  SizeT GetNonNullSize() VTK_OVERRIDE;
96  void GetCoordinatesN(const SizeT n, vtkArrayCoordinates& coordinates) VTK_OVERRIDE;
97  vtkArray* DeepCopy() VTK_OVERRIDE;
98 
99  // vtkTypedArray API
100  const T& GetValue(CoordinateT i) VTK_OVERRIDE;
101  const T& GetValue(CoordinateT i, CoordinateT j) VTK_OVERRIDE;
102  const T& GetValue(CoordinateT i, CoordinateT j, CoordinateT k) VTK_OVERRIDE;
103  const T& GetValue(const vtkArrayCoordinates& coordinates) VTK_OVERRIDE;
104  const T& GetValueN(const SizeT n) VTK_OVERRIDE;
105  void SetValue(CoordinateT i, const T& value) VTK_OVERRIDE;
106  void SetValue(CoordinateT i, CoordinateT j, const T& value) VTK_OVERRIDE;
107  void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value) VTK_OVERRIDE;
108  void SetValue(const vtkArrayCoordinates& coordinates, const T& value) VTK_OVERRIDE;
109  void SetValueN(const SizeT n, const T& value) VTK_OVERRIDE;
110 
111  // vtkSparseArray API
112 
116  void SetNullValue(const T& value);
117 
121  const T& GetNullValue();
122 
127  void Clear();
128 
135  void Sort(const vtkArraySort& sort);
136 
140  std::vector<CoordinateT> GetUniqueCoordinates(DimensionT dimension);
141 
148  const CoordinateT* GetCoordinateStorage(DimensionT dimension) const;
149 
156  CoordinateT* GetCoordinateStorage(DimensionT dimension);
157 
163  const T* GetValueStorage() const;
164 
170  T* GetValueStorage();
171 
180  void ReserveStorage(const SizeT value_count);
181 
186  void SetExtentsFromContents();
193  void SetExtents(const vtkArrayExtents& extents);
194 
196 
202  inline void AddValue(CoordinateT i, const T& value);
203  inline void AddValue(CoordinateT i, CoordinateT j, const T& value);
204  inline void AddValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value);
205  void AddValue(const vtkArrayCoordinates& coordinates, const T& value);
207 
217  bool Validate();
218 
219 protected:
220  vtkSparseArray();
221  ~vtkSparseArray() VTK_OVERRIDE;
222 
223 private:
224  vtkSparseArray(const vtkSparseArray&) VTK_DELETE_FUNCTION;
225  void operator=(const vtkSparseArray&) VTK_DELETE_FUNCTION;
226 
227  void InternalResize(const vtkArrayExtents& extents) VTK_OVERRIDE;
228  void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label) VTK_OVERRIDE;
229  vtkStdString InternalGetDimensionLabel(DimensionT i) VTK_OVERRIDE;
230 
231  typedef vtkSparseArray<T> ThisT;
232 
236  vtkArrayExtents Extents;
237 
241  std::vector<vtkStdString> DimensionLabels;
242 
247  std::vector<std::vector<CoordinateT> > Coordinates;
248 
252  std::vector<T> Values;
253 
255 
259  T NullValue;
260 };
262 
263 #include "vtkSparseArray.txx"
264 
265 #endif
266 // VTK-HeaderTest-Exclude: vtkSparseArray.h
Controls sorting of sparse array coordinates.
Definition: vtkArraySort.h:54
Stores coordinate into an N-way array.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:47
Stores the number of dimensions and valid coordinate ranges along each dimension for vtkArray...
Sparse, independent coordinate storage for N-way arrays.
Abstract interface for N-dimensional arrays.
Definition: vtkArray.h:70
void SetExtents(const vtkArrayExtents &extents)
Specify arbitrary array extents, without altering the contents of the array.
vtkArray::DimensionT DimensionT
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetNullValue(const T &value)
Set the value that will be returned by GetValue() for NULL areas of the array.
void Sort(const vtkArraySort &sort)
Sorts array values so that their coordinates appear in some well-defined order.
const T & GetValueN(const SizeT n) override
Returns the n-th value stored in the array, where n is in the range [0, GetNonNullSize()).
void SetValueN(const SizeT n, const T &value) override
Overwrites the n-th value stored in the array, where n is in the range [0, GetNonNullSize()).
const T & GetNullValue()
Returns the value that will be returned by GetValue() for NULL areas of the array.
vtkArrayExtents::DimensionT DimensionT
Definition: vtkArray.h:77
vtkTemplateTypeMacro(vtkSparseArray< T >, vtkTypedArray< T >) static vtkSparseArray< T > *New()
a simple class to control print indentation
Definition: vtkIndent.h:39
bool IsDense() override
Returns true iff the underlying array storage is "dense", i.e.
const T * GetValueStorage() const
Return a read-only reference to the underlying value storage.
vtkArray::SizeT SizeT
vtkArrayExtents::SizeT SizeT
Definition: vtkArray.h:78
void GetCoordinatesN(const SizeT n, vtkArrayCoordinates &coordinates) override
Returns the coordinates of the n-th value in the array, where n is in the range [0, GetNonNullSize()).
std::vector< CoordinateT > GetUniqueCoordinates(DimensionT dimension)
Returns the set of unique coordinates along the given dimension.
const CoordinateT * GetCoordinateStorage(DimensionT dimension) const
Return a read-only reference to the underlying coordinate storage.
void Clear()
Remove all non-null elements from the array, leaving the number of dimensions, the extent of each dim...
void SetExtentsFromContents()
Update the array extents to match its contents, so that the extent along each dimension matches the m...
vtkArray::CoordinateT CoordinateT
const vtkArrayExtents & GetExtents() override
Returns the extents (the number of dimensions and size along each dimension) of the array...
void AddValue(CoordinateT i, const T &value)
Adds a new non-null element to the array.
Provides a type-specific interface to N-way arrays.
Definition: vtkTypedArray.h:58
SizeT GetNonNullSize() override
Returns the number of non-null values stored in the array.
void ReserveStorage(const SizeT value_count)
Reserve storage for a specific number of values.
vtkArray * DeepCopy() override
Returns a new array that is a deep copy of this array.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
bool Validate()
Validate the contents of the array, returning false if there are any problems.
vtkArrayExtents::CoordinateT CoordinateT
Definition: vtkArray.h:76
void SetValue(CoordinateT i, const T &value) override
Overwrites the value stored in the array at the given coordinates.
const T & GetValue(CoordinateT i) override
Returns the value stored in the array at the given coordinates.