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 
78 #ifndef vtkSparseArray_h
79 #define vtkSparseArray_h
80 
81 #include "vtkArrayCoordinates.h"
82 #include "vtkArraySort.h"
83 #include "vtkObjectFactory.h"
84 #include "vtkTypedArray.h"
85 
86 template <typename T>
87 class vtkSparseArray : public vtkTypedArray<T>
88 {
89 public:
92  void PrintSelf(ostream& os, vtkIndent indent) override;
93 
95  typedef typename vtkArray::DimensionT DimensionT;
96  typedef typename vtkArray::SizeT SizeT;
97 
98  // vtkArray API
99  bool IsDense() override;
100  const vtkArrayExtents& GetExtents() override;
101  SizeT GetNonNullSize() override;
102  void GetCoordinatesN(const SizeT n, vtkArrayCoordinates& coordinates) override;
103  vtkArray* DeepCopy() override;
104 
105  // vtkTypedArray API
106  const T& GetValue(CoordinateT i) override;
107  const T& GetValue(CoordinateT i, CoordinateT j) override;
108  const T& GetValue(CoordinateT i, CoordinateT j, CoordinateT k) override;
109  const T& GetValue(const vtkArrayCoordinates& coordinates) override;
110  const T& GetValueN(const SizeT n) override;
111  void SetValue(CoordinateT i, const T& value) override;
112  void SetValue(CoordinateT i, CoordinateT j, const T& value) override;
113  void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value) override;
114  void SetValue(const vtkArrayCoordinates& coordinates, const T& value) override;
115  void SetValueN(const SizeT n, const T& value) override;
116 
117  // vtkSparseArray API
118 
122  void SetNullValue(const T& value);
123 
127  const T& GetNullValue();
128 
133  void Clear();
134 
141  void Sort(const vtkArraySort& sort);
142 
146  std::vector<CoordinateT> GetUniqueCoordinates(DimensionT dimension);
147 
154  const CoordinateT* GetCoordinateStorage(DimensionT dimension) const;
155 
163 
169  const T* GetValueStorage() const;
170 
177 
186  void ReserveStorage(const SizeT value_count);
187 
199  void SetExtents(const vtkArrayExtents& extents);
200 
202 
208  inline void AddValue(CoordinateT i, const T& value);
209  inline void AddValue(CoordinateT i, CoordinateT j, const T& value);
210  inline void AddValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value);
211  void AddValue(const vtkArrayCoordinates& coordinates, const T& value);
213 
223  bool Validate();
224 
225 protected:
227  ~vtkSparseArray() override;
228 
229 private:
230  vtkSparseArray(const vtkSparseArray&) = delete;
231  void operator=(const vtkSparseArray&) = delete;
232 
233  void InternalResize(const vtkArrayExtents& extents) override;
234  void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label) override;
235  vtkStdString InternalGetDimensionLabel(DimensionT i) override;
236 
237  typedef vtkSparseArray<T> ThisT;
238 
242  vtkArrayExtents Extents;
243 
247  std::vector<vtkStdString> DimensionLabels;
248 
253  std::vector<std::vector<CoordinateT>> Coordinates;
254 
258  std::vector<T> Values;
259 
261 
265  T NullValue;
267 };
268 
269 #include "vtkSparseArray.txx"
270 
271 #endif
272 // 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:55
Abstract interface for N-dimensional arrays.
Definition: vtkArray.h:68
vtkArrayExtents::SizeT SizeT
Definition: vtkArray.h:75
vtkArrayExtents::DimensionT DimensionT
Definition: vtkArray.h:74
vtkArrayExtents::CoordinateT CoordinateT
Definition: vtkArray.h:73
a simple class to control print indentation
Definition: vtkIndent.h:49
Sparse, independent coordinate storage for N-way arrays.
void SetExtents(const vtkArrayExtents &extents)
Specify arbitrary array extents, without altering the contents of the array.
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.
static vtkSparseArray< T > * New()
~vtkSparseArray() override
const T & GetValueN(const SizeT n) override
Returns the n-th value stored in the array, where n is in the range [0, GetNonNullSize()).
vtkArray::DimensionT DimensionT
const CoordinateT * GetCoordinateStorage(DimensionT dimension) const
Return a read-only reference to the underlying coordinate storage.
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()).
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.
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,...
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.
void ReserveStorage(const SizeT value_count)
Reserve storage for a specific number of values.
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.
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:48
Provides a type-specific interface to N-way arrays.
Definition: vtkTypedArray.h:59
@ value
Definition: vtkX3D.h:226