VTK  9.1.0
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 
85 #ifndef vtkSparseArray_h
86 #define vtkSparseArray_h
87 
88 #include "vtkArrayCoordinates.h"
89 #include "vtkArraySort.h"
90 #include "vtkObjectFactory.h"
91 #include "vtkTypedArray.h"
92 
93 template <typename T>
94 class vtkSparseArray : public vtkTypedArray<T>
95 {
96 public:
99  void PrintSelf(ostream& os, vtkIndent indent) override;
100 
103  typedef typename vtkArray::SizeT SizeT;
104 
105  // vtkArray API
106  bool IsDense() override;
107  const vtkArrayExtents& GetExtents() override;
108  SizeT GetNonNullSize() override;
109  void GetCoordinatesN(const SizeT n, vtkArrayCoordinates& coordinates) override;
110  vtkArray* DeepCopy() override;
111 
112  // vtkTypedArray API
113  const T& GetValue(CoordinateT i) override;
114  const T& GetValue(CoordinateT i, CoordinateT j) override;
115  const T& GetValue(CoordinateT i, CoordinateT j, CoordinateT k) override;
116  const T& GetValue(const vtkArrayCoordinates& coordinates) override;
117  const T& GetValueN(const SizeT n) override;
118  void SetValue(CoordinateT i, const T& value) override;
119  void SetValue(CoordinateT i, CoordinateT j, const T& value) override;
120  void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value) override;
121  void SetValue(const vtkArrayCoordinates& coordinates, const T& value) override;
122  void SetValueN(const SizeT n, const T& value) override;
123 
124  // vtkSparseArray API
125 
129  void SetNullValue(const T& value);
130 
134  const T& GetNullValue();
135 
140  void Clear();
141 
148  void Sort(const vtkArraySort& sort);
149 
153  std::vector<CoordinateT> GetUniqueCoordinates(DimensionT dimension);
154 
161  const CoordinateT* GetCoordinateStorage(DimensionT dimension) const;
162 
170 
176  const T* GetValueStorage() const;
177 
184 
193  void ReserveStorage(const SizeT value_count);
194 
206  void SetExtents(const vtkArrayExtents& extents);
207 
209 
215  inline void AddValue(CoordinateT i, const T& value);
216  inline void AddValue(CoordinateT i, CoordinateT j, const T& value);
217  inline void AddValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value);
218  void AddValue(const vtkArrayCoordinates& coordinates, const T& value);
220 
230  bool Validate();
231 
232 protected:
234  ~vtkSparseArray() override;
235 
236 private:
237  vtkSparseArray(const vtkSparseArray&) = delete;
238  void operator=(const vtkSparseArray&) = delete;
239 
240  void InternalResize(const vtkArrayExtents& extents) override;
241  void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label) override;
242  vtkStdString InternalGetDimensionLabel(DimensionT i) override;
243 
244  typedef vtkSparseArray<T> ThisT;
245 
249  vtkArrayExtents Extents;
250 
254  std::vector<vtkStdString> DimensionLabels;
255 
260  std::vector<std::vector<CoordinateT>> Coordinates;
261 
265  std::vector<T> Values;
266 
268 
272  T NullValue;
274 };
275 
276 #include "vtkSparseArray.txx"
277 
278 #endif
279 // VTK-HeaderTest-Exclude: vtkSparseArray.h
vtkSparseArray::AddValue
void AddValue(const vtkArrayCoordinates &coordinates, const T &value)
Adds a new non-null element to the array.
vtkSparseArray::Sort
void Sort(const vtkArraySort &sort)
Sorts array values so that their coordinates appear in some well-defined order.
vtkSparseArray::SetExtents
void SetExtents(const vtkArrayExtents &extents)
Specify arbitrary array extents, without altering the contents of the array.
vtkArray::SizeT
vtkArrayExtents::SizeT SizeT
Definition: vtkArray.h:72
vtkSparseArray::Clear
void Clear()
Remove all non-null elements from the array, leaving the number of dimensions, the extent of each dim...
vtkSparseArray::IsDense
bool IsDense() override
Returns true iff the underlying array storage is "dense", i.e.
vtkX3D::value
@ value
Definition: vtkX3D.h:226
vtkArraySort
Controls sorting of sparse array coordinates.
Definition: vtkArraySort.h:52
vtkSparseArray::GetValueStorage
const T * GetValueStorage() const
Return a read-only reference to the underlying value storage.
vtkSparseArray::New
static vtkSparseArray< T > * New()
vtkTypedArray.h
vtkSparseArray::GetValueStorage
T * GetValueStorage()
Return a mutable reference to the underlying value storage.
vtkSparseArray::GetValue
const T & GetValue(CoordinateT i, CoordinateT j) override
Returns 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.
vtkObjectFactory.h
vtkSparseArray::GetNullValue
const T & GetNullValue()
Returns the value that will be returned by GetValue() for nullptr areas of the array.
vtkSparseArray::GetCoordinateStorage
const CoordinateT * GetCoordinateStorage(DimensionT dimension) const
Return a read-only reference to the underlying coordinate storage.
vtkSparseArray::DimensionT
vtkArray::DimensionT DimensionT
Definition: vtkSparseArray.h:102
vtkSparseArray::AddValue
void AddValue(CoordinateT i, CoordinateT j, CoordinateT k, const T &value)
Adds a new non-null element to the array.
vtkSparseArray::vtkTemplateTypeMacro
vtkTemplateTypeMacro(vtkSparseArray< T >, vtkTypedArray< T >)
vtkSparseArray::GetCoordinatesN
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,...
vtkSparseArray::GetExtents
const vtkArrayExtents & GetExtents() override
Returns the extents (the number of dimensions and size along each dimension) of the array.
vtkArrayCoordinates.h
vtkSparseArray::GetUniqueCoordinates
std::vector< CoordinateT > GetUniqueCoordinates(DimensionT dimension)
Returns the set of unique coordinates along the given dimension.
vtkSparseArray::DeepCopy
vtkArray * DeepCopy() override
Returns a new array that is a deep copy of this array.
vtkSparseArray::AddValue
void AddValue(CoordinateT i, const T &value)
Adds a new non-null element to the array.
vtkTypedArray
Provides a type-specific interface to N-way arrays.
Definition: vtkTypedArray.h:56
vtkSparseArray::~vtkSparseArray
~vtkSparseArray() override
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:113
vtkSparseArray::SetValue
void SetValue(CoordinateT i, const T &value) override
Overwrites the value stored in the array at the given coordinates.
vtkSparseArray::GetValue
const T & GetValue(const vtkArrayCoordinates &coordinates) override
Returns the value stored in the array at the given coordinates.
vtkSparseArray::vtkSparseArray
vtkSparseArray()
vtkSparseArray::SetNullValue
void SetNullValue(const T &value)
Set the value that will be returned by GetValue() for nullptr areas of the array.
vtkArray
Abstract interface for N-dimensional arrays.
Definition: vtkArray.h:65
vtkSparseArray
Sparse, independent coordinate storage for N-way arrays.
Definition: vtkSparseArray.h:95
vtkSparseArray::ReserveStorage
void ReserveStorage(const SizeT value_count)
Reserve storage for a specific number of values.
vtkSparseArray::GetValueN
const T & GetValueN(const SizeT n) override
Returns the n-th value stored in the array, where n is in the range [0, GetNonNullSize()).
vtkSparseArray::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkSparseArray::CoordinateT
vtkArray::CoordinateT CoordinateT
Definition: vtkSparseArray.h:101
vtkSparseArray::SizeT
vtkArray::SizeT SizeT
Definition: vtkSparseArray.h:103
vtkSparseArray::Validate
bool Validate()
Validate the contents of the array, returning false if there are any problems.
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::SetExtentsFromContents
void SetExtentsFromContents()
Update the array extents to match its contents, so that the extent along each dimension matches the m...
vtkSparseArray::SetValueN
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()).
vtkArraySort.h
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:105
vtkArray::CoordinateT
vtkArrayExtents::CoordinateT CoordinateT
Definition: vtkArray.h:70
vtkSparseArray::GetNonNullSize
SizeT GetNonNullSize() override
Returns the number of non-null values stored in the array.
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::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.
vtkArrayExtents
Stores the number of dimensions and valid coordinate ranges along each dimension for vtkArray.
Definition: vtkArrayExtents.h:69
vtkArrayCoordinates
Stores coordinate into an N-way array.
Definition: vtkArrayCoordinates.h:52
vtkArray::DimensionT
vtkArrayExtents::DimensionT DimensionT
Definition: vtkArray.h:71
vtkSparseArray::SetValue
void SetValue(CoordinateT i, CoordinateT j, const T &value) override
Overwrites the value stored in the array at the given coordinates.