VTK: Common/Core/vtkSparseArray.h Source File

| VTK 9.3.1

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
61 #ifndef vtkSparseArray_h
62 #define vtkSparseArray_h
63
64 #include "vtkArrayCoordinates.h"
65 #include "vtkArraySort.h"
66 #include "vtkObjectFactory.h"
67 #include "vtkTypedArray.h"
68
69 VTK_ABI_NAMESPACE_BEGIN
70 template <typename T>
71 class vtkSparseArray : public vtkTypedArray<T>
72 {
73 public:
74 vtkTemplateTypeMacro(vtkSparseArray<T>, vtkTypedArray<T>);
75 static vtkSparseArray<T>* New();
76 void PrintSelf(ostream& os, vtkIndent indent) override;
77
78 typedef typename vtkArray::CoordinateT CoordinateT;
79 typedef typename vtkArray::DimensionT DimensionT;
80 typedef typename vtkArray::SizeT SizeT;
81
82 // vtkArray API
83 bool IsDense() override;
84 const vtkArrayExtents& GetExtents() override;
85 SizeT GetNonNullSize() override;
86 void GetCoordinatesN(SizeT n, vtkArrayCoordinates& coordinates) override;
87 vtkArray* DeepCopy() override;
88
89 // vtkTypedArray API
90 const T& GetValue(CoordinateT i) override;
91 const T& GetValue(CoordinateT i, CoordinateT j) override;
92 const T& GetValue(CoordinateT i, CoordinateT j, CoordinateT k) override;
93 const T& GetValue(const vtkArrayCoordinates& coordinates) override;
94 const T& GetValueN(SizeT n) override;
95 void SetValue(CoordinateT i, const T& value) override;
96 void SetValue(CoordinateT i, CoordinateT j, const T& value) override;
97 void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value) override;
98 void SetValue(const vtkArrayCoordinates& coordinates, const T& value) override;
99 void SetValueN(SizeT n, const T& value) override;
100
101 // vtkSparseArray API
102
106 void SetNullValue(const T& value);
107
111 const T& GetNullValue();
112
117 void Clear();
118
125 void Sort(const vtkArraySort& sort);
126
130 std::vector<CoordinateT> GetUniqueCoordinates(DimensionT dimension);
131
138 const CoordinateT* GetCoordinateStorage(DimensionT dimension) const;
139
146 CoordinateT* GetCoordinateStorage(DimensionT dimension);
147
153 const T* GetValueStorage() const;
154
160 T* GetValueStorage();
161
170 void ReserveStorage(SizeT value_count);
171
176 void SetExtentsFromContents();
183 void SetExtents(const vtkArrayExtents& extents);
184
186
192 inline void AddValue(CoordinateT i, const T& value);
193 inline void AddValue(CoordinateT i, CoordinateT j, const T& value);
194 inline void AddValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value);
195 void AddValue(const vtkArrayCoordinates& coordinates, const T& value);
197
207 bool Validate();
208
209 protected:
210 vtkSparseArray();
211 ~vtkSparseArray() override;
212
213 private:
214 vtkSparseArray(const vtkSparseArray&) = delete;
215 void operator=(const vtkSparseArray&) = delete;
216
217 void InternalResize(const vtkArrayExtents& extents) override;
218 void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label) override;
219 vtkStdString InternalGetDimensionLabel(DimensionT i) override;
220
221 typedef vtkSparseArray<T> ThisT;
222
226 vtkArrayExtents Extents;
227
231 std::vector<std::string> DimensionLabels;
232
237 std::vector<std::vector<CoordinateT>> Coordinates;
238
242 std::vector<T> Values;
243
245
249 T NullValue;
251 };
252
253 VTK_ABI_NAMESPACE_END
254 #include "vtkSparseArray.txx"
255
256 #endif
257 // VTK-HeaderTest-Exclude: vtkSparseArray.h
vtkArrayCoordinates
Stores coordinate into an N-way array.
Definition: vtkArrayCoordinates.h:39
vtkArrayExtents
Stores the number of dimensions and valid coordinate ranges along each dimension for vtkArray.
Definition: vtkArrayExtents.h:56
vtkArraySort
Controls sorting of sparse array coordinates.
Definition: vtkArraySort.h:39
vtkArray
Abstract interface for N-dimensional arrays.
Definition: vtkArray.h:52
vtkArray::SizeT
vtkArrayExtents::SizeT SizeT
Definition: vtkArray.h:59
vtkArray::DimensionT
vtkArrayExtents::DimensionT DimensionT
Definition: vtkArray.h:58
vtkArray::CoordinateT
vtkArrayExtents::CoordinateT CoordinateT
Definition: vtkArray.h:57
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkSparseArray
Sparse, independent coordinate storage for N-way arrays.
Definition: vtkSparseArray.h:72
vtkSparseArray::vtkSparseArray
vtkSparseArray()
vtkSparseArray::SetExtents
void SetExtents(const vtkArrayExtents &extents)
Specify arbitrary array extents, without altering the contents of the array.
vtkSparseArray::GetValueN
const T & GetValueN(SizeT n) override
Returns the n-th value stored in the array, where n is in the range [0, GetNonNullSize()).
vtkSparseArray::ReserveStorage
void ReserveStorage(SizeT value_count)
Reserve storage for a specific number of values.
vtkSparseArray::SetValue
void SetValue(CoordinateT i, const T &value) override
Overwrites the value stored in the array at the given coordinates.
vtkSparseArray::AddValue
void AddValue(CoordinateT i, const T &value)
Adds a new non-null element to the array.
vtkSparseArray::Validate
bool Validate()
Validate the contents of the array, returning false if there are any problems.
vtkSparseArray::Sort
void Sort(const vtkArraySort &sort)
Sorts array values so that their coordinates appear in some well-defined order.
vtkSparseArray::SizeT
vtkArray::SizeT SizeT
Definition: vtkSparseArray.h:80
vtkSparseArray::SetNullValue
void SetNullValue(const T &value)
Set the value that will be returned by GetValue() for nullptr areas of the array.
vtkSparseArray::DeepCopy
vtkArray * DeepCopy() override
Returns a new array that is a deep copy of this array.
vtkSparseArray::GetNullValue
const T & GetNullValue()
Returns the value that will be returned by GetValue() for nullptr areas of the array.
vtkSparseArray::SetExtentsFromContents
void SetExtentsFromContents()
Update the array extents to match its contents, so that the extent along each dimension matches the m...
vtkSparseArray::AddValue
void AddValue(CoordinateT i, CoordinateT j, const T &value)
Adds a new non-null element to the array.
vtkSparseArray::SetValue
void SetValue(const vtkArrayCoordinates &coordinates, const T &value) override
Overwrites the value stored in the array at the given coordinates.
vtkSparseArray::GetValue
const T & GetValue(CoordinateT i, CoordinateT j) override
Returns the value stored in the array at the given coordinates.
vtkSparseArray::SetValue
void SetValue(CoordinateT i, CoordinateT j, const T &value) override
Overwrites the value stored in the array at the given coordinates.
vtkSparseArray::GetCoordinatesN
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,...
vtkSparseArray::New
static vtkSparseArray< T > * New()
vtkSparseArray::~vtkSparseArray
~vtkSparseArray() override
vtkSparseArray::DimensionT
vtkArray::DimensionT DimensionT
Definition: vtkSparseArray.h:79
vtkSparseArray::GetCoordinateStorage
const CoordinateT * GetCoordinateStorage(DimensionT dimension) const
Return a read-only reference to the underlying coordinate storage.
vtkSparseArray::GetNonNullSize
SizeT GetNonNullSize() override
Returns the number of non-null values stored in the array.
vtkSparseArray::AddValue
void AddValue(CoordinateT i, CoordinateT j, CoordinateT k, const T &value)
Adds a new non-null element to the array.
vtkSparseArray::GetValueStorage
const T * GetValueStorage() const
Return a read-only reference to the underlying value storage.
vtkSparseArray::AddValue
void AddValue(const vtkArrayCoordinates &coordinates, const T &value)
Adds a new non-null element to the array.
vtkSparseArray::Clear
void Clear()
Remove all non-null elements from the array, leaving the number of dimensions, the extent of each dim...
vtkSparseArray::GetValueStorage
T * GetValueStorage()
Return a mutable reference to the underlying value storage.
vtkSparseArray::vtkTemplateTypeMacro
vtkTemplateTypeMacro(vtkSparseArray< T >, vtkTypedArray< T >)
vtkSparseArray::GetValue
const T & GetValue(const vtkArrayCoordinates &coordinates) override
Returns the value stored in the array at the given coordinates.
vtkSparseArray::SetValue
void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T &value) override
Overwrites the value stored in the array at the given coordinates.
vtkSparseArray::GetCoordinateStorage
CoordinateT * GetCoordinateStorage(DimensionT dimension)
Return a mutable reference to the underlying coordinate storage.
vtkSparseArray::GetExtents
const vtkArrayExtents & GetExtents() override
Returns the extents (the number of dimensions and size along each dimension) of the array.
vtkSparseArray::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkSparseArray::SetValueN
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()).
vtkSparseArray::GetValue
const T & GetValue(CoordinateT i, CoordinateT j, CoordinateT k) override
Returns the value stored in the array at the given coordinates.
vtkSparseArray::GetValue
const T & GetValue(CoordinateT i) override
Returns the value stored in the array at the given coordinates.
vtkSparseArray::CoordinateT
vtkArray::CoordinateT CoordinateT
Definition: vtkSparseArray.h:78
vtkSparseArray::GetUniqueCoordinates
std::vector< CoordinateT > GetUniqueCoordinates(DimensionT dimension)
Returns the set of unique coordinates along the given dimension.
vtkSparseArray::IsDense
bool IsDense() override
Returns true iff the underlying array storage is "dense", i.e.
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:38
vtkTypedArray
Provides a type-specific interface to N-way arrays.
Definition: vtkTypedArray.h:43
vtkX3D::value
@ value
Definition: vtkX3D.h:220
vtkArrayCoordinates.h
vtkArraySort.h
vtkObjectFactory.h
vtkTypedArray.h