VTK  9.3.20240418
vtkSparseArray.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-FileCopyrightText: Copyright 2008 Sandia Corporation
3 // SPDX-License-Identifier: LicenseRef-BSD-3-Clause-Sandia-USGov
4 
71 #ifndef vtkSparseArray_h
72 #define vtkSparseArray_h
73 
74 #include "vtkArrayCoordinates.h"
75 #include "vtkArraySort.h"
76 #include "vtkObjectFactory.h"
77 #include "vtkTypedArray.h"
78 
79 VTK_ABI_NAMESPACE_BEGIN
80 template <typename T>
81 class vtkSparseArray : public vtkTypedArray<T>
82 {
83 public:
86  void PrintSelf(ostream& os, vtkIndent indent) override;
87 
89  typedef typename vtkArray::DimensionT DimensionT;
90  typedef typename vtkArray::SizeT SizeT;
91 
92  // vtkArray API
93  bool IsDense() override;
94  const vtkArrayExtents& GetExtents() override;
95  SizeT GetNonNullSize() override;
96  void GetCoordinatesN(SizeT n, vtkArrayCoordinates& coordinates) override;
97  vtkArray* DeepCopy() override;
98 
99  // vtkTypedArray API
100  const T& GetValue(CoordinateT i) override;
101  const T& GetValue(CoordinateT i, CoordinateT j) override;
102  const T& GetValue(CoordinateT i, CoordinateT j, CoordinateT k) override;
103  const T& GetValue(const vtkArrayCoordinates& coordinates) override;
104  const T& GetValueN(SizeT n) override;
105  void SetValue(CoordinateT i, const T& value) override;
106  void SetValue(CoordinateT i, CoordinateT j, const T& value) override;
107  void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value) override;
108  void SetValue(const vtkArrayCoordinates& coordinates, const T& value) override;
109  void SetValueN(SizeT n, const T& value) 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 
157 
163  const T* GetValueStorage() const;
164 
171 
180  void ReserveStorage(SizeT value_count);
181 
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:
221  ~vtkSparseArray() override;
222 
223 private:
224  vtkSparseArray(const vtkSparseArray&) = delete;
225  void operator=(const vtkSparseArray&) = delete;
226 
227  void InternalResize(const vtkArrayExtents& extents) override;
228  void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label) override;
229  vtkStdString InternalGetDimensionLabel(DimensionT i) override;
230 
231  typedef vtkSparseArray<T> ThisT;
232 
236  vtkArrayExtents Extents;
237 
241  std::vector<std::string> DimensionLabels;
242 
247  std::vector<std::vector<CoordinateT>> Coordinates;
248 
252  std::vector<T> Values;
253 
255 
259  T NullValue;
261 };
262 
263 VTK_ABI_NAMESPACE_END
264 #include "vtkSparseArray.txx"
265 
266 #endif
267 // VTK-HeaderTest-Exclude: vtkSparseArray.h
Stores coordinate into an N-way array.
Stores the number of dimensions and valid coordinate ranges along each dimension for vtkArray.
Controls sorting of sparse array coordinates.
Definition: vtkArraySort.h:39
Abstract interface for N-dimensional arrays.
Definition: vtkArray.h:52
vtkArrayExtents::SizeT SizeT
Definition: vtkArray.h:59
vtkArrayExtents::DimensionT DimensionT
Definition: vtkArray.h:58
vtkArrayExtents::CoordinateT CoordinateT
Definition: vtkArray.h:57
a simple class to control print indentation
Definition: vtkIndent.h:108
Sparse, independent coordinate storage for N-way arrays.
void SetExtents(const vtkArrayExtents &extents)
Specify arbitrary array extents, without altering the contents of the array.
const T & GetValueN(SizeT n) override
Returns the n-th value stored in the array, where n is in the range [0, GetNonNullSize()).
void ReserveStorage(SizeT value_count)
Reserve storage for a specific number of values.
void SetValue(CoordinateT i, const T &value) override
Overwrites the value stored in the array at the given coordinates.
void AddValue(CoordinateT i, const T &value)
Adds a new non-null element to the array.
bool Validate()
Validate the contents of the array, returning false if there are any problems.
void Sort(const vtkArraySort &sort)
Sorts array values so that their coordinates appear in some well-defined order.
vtkArray::SizeT SizeT
void SetNullValue(const T &value)
Set the value that will be returned by GetValue() for nullptr areas of the array.
vtkArray * DeepCopy() override
Returns a new array that is a deep copy of this array.
const T & GetNullValue()
Returns the value that will be returned by GetValue() for nullptr areas of the array.
void SetExtentsFromContents()
Update the array extents to match its contents, so that the extent along each dimension matches the m...
void AddValue(CoordinateT i, CoordinateT j, const T &value)
Adds a new non-null element to the array.
void SetValue(const vtkArrayCoordinates &coordinates, const T &value) override
Overwrites the value stored in the array at the given coordinates.
const T & GetValue(CoordinateT i, CoordinateT j) override
Returns the value stored in the array at the given coordinates.
void SetValue(CoordinateT i, CoordinateT j, const T &value) override
Overwrites the value stored in the array at the given coordinates.
void GetCoordinatesN(SizeT n, vtkArrayCoordinates &coordinates) override
Returns the coordinates of the n-th value in the array, where n is in the range [0,...
static vtkSparseArray< T > * New()
~vtkSparseArray() override
vtkArray::DimensionT DimensionT
const CoordinateT * GetCoordinateStorage(DimensionT dimension) const
Return a read-only reference to the underlying coordinate storage.
SizeT GetNonNullSize() override
Returns the number of non-null values stored in the array.
void AddValue(CoordinateT i, CoordinateT j, CoordinateT k, const T &value)
Adds a new non-null element to the array.
const T * GetValueStorage() const
Return a read-only reference to the underlying value storage.
void AddValue(const vtkArrayCoordinates &coordinates, const T &value)
Adds a new non-null element to the array.
void Clear()
Remove all non-null elements from the array, leaving the number of dimensions, the extent of each dim...
T * GetValueStorage()
Return a mutable reference to the underlying value storage.
vtkTemplateTypeMacro(vtkSparseArray< T >, vtkTypedArray< T >)
const T & GetValue(const vtkArrayCoordinates &coordinates) override
Returns the value stored in the array at the given coordinates.
void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T &value) override
Overwrites the value stored in the array at the given coordinates.
CoordinateT * GetCoordinateStorage(DimensionT dimension)
Return a mutable reference to the underlying coordinate storage.
const vtkArrayExtents & GetExtents() override
Returns the extents (the number of dimensions and size along each dimension) of the array.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetValueN(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 & GetValue(CoordinateT i, CoordinateT j, CoordinateT k) override
Returns 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.
vtkArray::CoordinateT CoordinateT
std::vector< CoordinateT > GetUniqueCoordinates(DimensionT dimension)
Returns the set of unique coordinates along the given dimension.
bool IsDense() override
Returns true iff the underlying array storage is "dense", i.e.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:78
Provides a type-specific interface to N-way arrays.
Definition: vtkTypedArray.h:43
@ value
Definition: vtkX3D.h:220