VTK  9.3.0
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
52#ifndef vtkSparseArray_h
53#define vtkSparseArray_h
54
55#include "vtkArrayCoordinates.h"
56#include "vtkArraySort.h"
57#include "vtkObjectFactory.h"
58#include "vtkTypedArray.h"
59
60VTK_ABI_NAMESPACE_BEGIN
61template <typename T>
63{
64public:
67 void PrintSelf(ostream& os, vtkIndent indent) override;
68
71 typedef typename vtkArray::SizeT SizeT;
72
73 // vtkArray API
74 bool IsDense() override;
75 const vtkArrayExtents& GetExtents() override;
77 void GetCoordinatesN(SizeT n, vtkArrayCoordinates& coordinates) override;
78 vtkArray* DeepCopy() override;
79
80 // vtkTypedArray API
81 const T& GetValue(CoordinateT i) override;
82 const T& GetValue(CoordinateT i, CoordinateT j) override;
83 const T& GetValue(CoordinateT i, CoordinateT j, CoordinateT k) override;
84 const T& GetValue(const vtkArrayCoordinates& coordinates) override;
85 const T& GetValueN(SizeT n) override;
86 void SetValue(CoordinateT i, const T& value) override;
87 void SetValue(CoordinateT i, CoordinateT j, const T& value) override;
88 void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value) override;
89 void SetValue(const vtkArrayCoordinates& coordinates, const T& value) override;
90 void SetValueN(SizeT n, const T& value) override;
91
92 // vtkSparseArray API
93
97 void SetNullValue(const T& value);
98
102 const T& GetNullValue();
103
108 void Clear();
109
116 void Sort(const vtkArraySort& sort);
117
121 std::vector<CoordinateT> GetUniqueCoordinates(DimensionT dimension);
122
130
138
144 const T* GetValueStorage() const;
145
152
161 void ReserveStorage(SizeT value_count);
162
174 void SetExtents(const vtkArrayExtents& extents);
175
177
183 inline void AddValue(CoordinateT i, const T& value);
184 inline void AddValue(CoordinateT i, CoordinateT j, const T& value);
185 inline void AddValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value);
186 void AddValue(const vtkArrayCoordinates& coordinates, const T& value);
188
198 bool Validate();
199
200protected:
202 ~vtkSparseArray() override;
203
204private:
205 vtkSparseArray(const vtkSparseArray&) = delete;
206 void operator=(const vtkSparseArray&) = delete;
207
208 void InternalResize(const vtkArrayExtents& extents) override;
209 void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label) override;
210 vtkStdString InternalGetDimensionLabel(DimensionT i) override;
211
212 typedef vtkSparseArray<T> ThisT;
213
217 vtkArrayExtents Extents;
218
222 std::vector<std::string> DimensionLabels;
223
228 std::vector<std::vector<CoordinateT>> Coordinates;
229
233 std::vector<T> Values;
234
236
240 T NullValue;
242};
243
244VTK_ABI_NAMESPACE_END
245#include "vtkSparseArray.txx"
246
247#endif
248// 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.
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:29
Sparse, independent coordinate storage for N-way arrays.
void SetExtents(const vtkArrayExtents &extents)
Specify arbitrary array extents, without altering the contents of the array.
std::vector< CoordinateT > GetUniqueCoordinates(DimensionT dimension)
Returns the set of unique coordinates along the given dimension.
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.
static vtkSparseArray< T > * New()
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.
const T & GetValue(CoordinateT i, CoordinateT j, CoordinateT k) override
Returns the value stored in the array at the given coordinates.
vtkArray::SizeT SizeT
void SetNullValue(const T &value)
Set 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...
CoordinateT * GetCoordinateStorage(DimensionT dimension)
Return a mutable reference to the underlying coordinate storage.
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 * GetValueStorage() const
Return a read-only reference to the underlying value storage.
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,...
~vtkSparseArray() override
T * GetValueStorage()
Return a mutable reference to the underlying value storage.
vtkArray::DimensionT DimensionT
const T & GetValue(CoordinateT i) override
Returns the value stored in the array at the given coordinates.
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 & GetValueN(SizeT n) override
Returns the n-th value stored in the array, where n is in the range [0, GetNonNullSize()).
void AddValue(const vtkArrayCoordinates &coordinates, const T &value)
Adds a new non-null element to the array.
vtkArray * DeepCopy() override
Returns a new array that is a deep copy of this array.
void Clear()
Remove all non-null elements from the array, leaving the number of dimensions, the extent of each dim...
const T & GetValue(CoordinateT i, CoordinateT j) override
Returns the value stored in the array at the given coordinates.
const T & GetNullValue()
Returns the value that will be returned by GetValue() for nullptr areas of the array.
const T & GetValue(const vtkArrayCoordinates &coordinates) override
Returns the value stored in the array at the given coordinates.
const CoordinateT * GetCoordinateStorage(DimensionT dimension) const
Return a read-only reference to the underlying coordinate storage.
vtkTemplateTypeMacro(vtkSparseArray< T >, vtkTypedArray< T >)
void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T &value) override
Overwrites the value stored in the array at the given coordinates.
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 vtkArrayExtents & GetExtents() override
Returns the extents (the number of dimensions and size along each dimension) of the array.
vtkArray::CoordinateT CoordinateT
bool IsDense() override
Returns true iff the underlying array storage is "dense", i.e.
Wrapper around std::string to keep symbols short.
Provides a type-specific interface to N-way arrays.