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
75#ifndef vtkSparseArray_h
76#define vtkSparseArray_h
77
78#include "vtkArrayCoordinates.h"
79#include "vtkArraySort.h"
80#include "vtkObjectFactory.h"
81#include "vtkTypedArray.h"
82
83template <typename T>
85{
86public:
89 void PrintSelf(ostream& os, vtkIndent indent) override;
90
93 typedef typename vtkArray::SizeT SizeT;
94
95 // vtkArray API
96 bool IsDense() override;
97 const vtkArrayExtents& GetExtents() override;
99 void GetCoordinatesN(const SizeT n, vtkArrayCoordinates& coordinates) override;
100 vtkArray* DeepCopy() override;
101
102 // vtkTypedArray API
103 const T& GetValue(CoordinateT i) override;
104 const T& GetValue(CoordinateT i, CoordinateT j) override;
105 const T& GetValue(CoordinateT i, CoordinateT j, CoordinateT k) override;
106 const T& GetValue(const vtkArrayCoordinates& coordinates) override;
107 const T& GetValueN(const SizeT n) override;
108 void SetValue(CoordinateT i, const T& value) override;
109 void SetValue(CoordinateT i, CoordinateT j, const T& value) override;
110 void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value) override;
111 void SetValue(const vtkArrayCoordinates& coordinates, const T& value) override;
112 void SetValueN(const SizeT n, const T& value) override;
113
114 // vtkSparseArray API
115
119 void SetNullValue(const T& value);
120
124 const T& GetNullValue();
125
130 void Clear();
131
138 void Sort(const vtkArraySort& sort);
139
143 std::vector<CoordinateT> GetUniqueCoordinates(DimensionT dimension);
144
152
160
166 const T* GetValueStorage() const;
167
174
183 void ReserveStorage(const SizeT value_count);
184
196 void SetExtents(const vtkArrayExtents& extents);
197
199
205 inline void AddValue(CoordinateT i, const T& value);
206 inline void AddValue(CoordinateT i, CoordinateT j, const T& value);
207 inline void AddValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value);
208 void AddValue(const vtkArrayCoordinates& coordinates, const T& value);
210
220 bool Validate();
221
222protected:
224 ~vtkSparseArray() override;
225
226private:
227 vtkSparseArray(const vtkSparseArray&) = delete;
228 void operator=(const vtkSparseArray&) = delete;
229
230 void InternalResize(const vtkArrayExtents& extents) override;
231 void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label) override;
232 vtkStdString InternalGetDimensionLabel(DimensionT i) override;
233
234 typedef vtkSparseArray<T> ThisT;
235
239 vtkArrayExtents Extents;
240
244 std::vector<vtkStdString> DimensionLabels;
245
250 std::vector<std::vector<CoordinateT>> Coordinates;
251
255 std::vector<T> Values;
256
258
262 T NullValue;
264};
265
266#include "vtkSparseArray.txx"
267
268#endif
269// 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:52
Abstract interface for N-dimensional arrays.
Definition: vtkArray.h:65
vtkArrayExtents::SizeT SizeT
Definition: vtkArray.h:72
vtkArrayExtents::DimensionT DimensionT
Definition: vtkArray.h:71
vtkArrayExtents::CoordinateT CoordinateT
Definition: vtkArray.h:70
a simple class to control print indentation
Definition: vtkIndent.h:43
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 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.
~vtkSparseArray() override
T * GetValueStorage()
Return a mutable reference to the underlying value storage.
vtkArray::DimensionT DimensionT
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()).
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.
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,...
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 ReserveStorage(const SizeT value_count)
Reserve storage for a specific number of values.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
const vtkArrayExtents & GetExtents() override
Returns the extents (the number of dimensions and size along each dimension) of the array.
vtkArray::CoordinateT CoordinateT
const T & GetValueN(const SizeT n) override
Returns the n-th value stored in the array, where n is in the range [0, GetNonNullSize()).
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:45
Provides a type-specific interface to N-way arrays.
Definition: vtkTypedArray.h:56
@ value
Definition: vtkX3D.h:226