VTK  9.2.6
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 
69 #ifndef vtkSparseArray_h
70 #define vtkSparseArray_h
71 
72 #include "vtkArrayCoordinates.h"
73 #include "vtkArraySort.h"
74 #include "vtkObjectFactory.h"
75 #include "vtkTypedArray.h"
76 
77 template <typename T>
78 class vtkSparseArray : public vtkTypedArray<T>
79 {
80 public:
82  static vtkSparseArray<T>* New();
83  void PrintSelf(ostream& os, vtkIndent indent) override;
84 
86  typedef typename vtkArray::DimensionT DimensionT;
87  typedef typename vtkArray::SizeT SizeT;
88 
89  // vtkArray API
90  bool IsDense() override;
91  const vtkArrayExtents& GetExtents() override;
92  SizeT GetNonNullSize() override;
93  void GetCoordinatesN(const SizeT n, vtkArrayCoordinates& coordinates) override;
94  vtkArray* DeepCopy() override;
95 
96  // vtkTypedArray API
97  const T& GetValue(CoordinateT i) override;
98  const T& GetValue(CoordinateT i, CoordinateT j) override;
99  const T& GetValue(CoordinateT i, CoordinateT j, CoordinateT k) override;
100  const T& GetValue(const vtkArrayCoordinates& coordinates) override;
101  const T& GetValueN(const SizeT n) override;
102  void SetValue(CoordinateT i, const T& value) override;
103  void SetValue(CoordinateT i, CoordinateT j, const T& value) override;
104  void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value) override;
105  void SetValue(const vtkArrayCoordinates& coordinates, const T& value) override;
106  void SetValueN(const SizeT n, const T& value) override;
107 
108  // vtkSparseArray API
109 
113  void SetNullValue(const T& value);
114 
118  const T& GetNullValue();
119 
124  void Clear();
125 
132  void Sort(const vtkArraySort& sort);
133 
137  std::vector<CoordinateT> GetUniqueCoordinates(DimensionT dimension);
138 
145  const CoordinateT* GetCoordinateStorage(DimensionT dimension) const;
146 
153  CoordinateT* GetCoordinateStorage(DimensionT dimension);
154 
160  const T* GetValueStorage() const;
161 
167  T* GetValueStorage();
168 
177  void ReserveStorage(const SizeT value_count);
178 
183  void SetExtentsFromContents();
190  void SetExtents(const vtkArrayExtents& extents);
191 
193 
199  inline void AddValue(CoordinateT i, const T& value);
200  inline void AddValue(CoordinateT i, CoordinateT j, const T& value);
201  inline void AddValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value);
202  void AddValue(const vtkArrayCoordinates& coordinates, const T& value);
204 
214  bool Validate();
215 
216 protected:
217  vtkSparseArray();
218  ~vtkSparseArray() override;
219 
220 private:
221  vtkSparseArray(const vtkSparseArray&) = delete;
222  void operator=(const vtkSparseArray&) = delete;
223 
224  void InternalResize(const vtkArrayExtents& extents) override;
225  void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label) override;
226  vtkStdString InternalGetDimensionLabel(DimensionT i) override;
227 
228  typedef vtkSparseArray<T> ThisT;
229 
233  vtkArrayExtents Extents;
234 
238  std::vector<vtkStdString> DimensionLabels;
239 
244  std::vector<std::vector<CoordinateT>> Coordinates;
245 
249  std::vector<T> Values;
250 
252 
256  T NullValue;
258 };
259 
260 #include "vtkSparseArray.txx"
261 
262 #endif
263 // 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:38
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:67
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 nullptr areas of the array. ...
static vtkSparseArray< T > * New()
vtkTemplateTypeMacro(vtkSparseArray< T >, vtkTypedArray< T >)
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 nullptr areas of the array.
vtkArrayExtents::DimensionT DimensionT
Definition: vtkArray.h:74
a simple class to control print indentation
Definition: vtkIndent.h:39
~vtkSparseArray() override
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:75
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.
bool Validate()
Validate the contents of the array, returning false if there are any problems.
vtkArrayExtents::CoordinateT CoordinateT
Definition: vtkArray.h:73
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.