VTK  9.3.0
vtkDenseArray.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
41#ifndef vtkDenseArray_h
42#define vtkDenseArray_h
43
44#include "vtkArrayCoordinates.h"
45#include "vtkObjectFactory.h"
46#include "vtkTypedArray.h"
47
48VTK_ABI_NAMESPACE_BEGIN
49template <typename T>
51{
52public:
55 void PrintSelf(ostream& os, vtkIndent indent) override;
56
59 typedef typename vtkArray::SizeT SizeT;
60
61 // vtkArray API
62 bool IsDense() override;
63 const vtkArrayExtents& GetExtents() override;
65 void GetCoordinatesN(SizeT n, vtkArrayCoordinates& coordinates) override;
66 vtkArray* DeepCopy() override;
67
68 // vtkTypedArray API
69 const T& GetValue(CoordinateT i) override;
70 const T& GetValue(CoordinateT i, CoordinateT j) override;
71 const T& GetValue(CoordinateT i, CoordinateT j, CoordinateT k) override;
72 const T& GetValue(const vtkArrayCoordinates& coordinates) override;
73 const T& GetValueN(SizeT n) override;
74 void SetValue(CoordinateT i, const T& value) override;
75 void SetValue(CoordinateT i, CoordinateT j, const T& value) override;
76 void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value) override;
77 void SetValue(const vtkArrayCoordinates& coordinates, const T& value) override;
78 void SetValueN(SizeT n, const T& value) override;
79
80 // vtkDenseArray API
81
88 {
89 public:
90 virtual ~MemoryBlock();
92
95 virtual T* GetAddress() = 0;
97 };
98
100
106 {
107 public:
110 T* GetAddress() override;
112
113 private:
114 T* Storage;
115 };
116
118
122 {
123 public:
124 StaticMemoryBlock(T* storage);
125 T* GetAddress() override;
127
128 private:
129 T* Storage;
130 };
131
148 void ExternalStorage(const vtkArrayExtents& extents, MemoryBlock* storage);
149
153 void Fill(const T& value);
154
158 T& operator[](const vtkArrayCoordinates& coordinates);
159
164 const T* GetStorage() const;
165
171
172protected:
174 ~vtkDenseArray() override;
175
176private:
177 vtkDenseArray(const vtkDenseArray&) = delete;
178 void operator=(const vtkDenseArray&) = delete;
179
180 void InternalResize(const vtkArrayExtents& extents) override;
181 void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label) override;
182 vtkStdString InternalGetDimensionLabel(DimensionT i) override;
183 inline vtkIdType MapCoordinates(CoordinateT i);
184 inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j);
185 inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j, CoordinateT k);
186 inline vtkIdType MapCoordinates(const vtkArrayCoordinates& coordinates);
187
188 void Reconfigure(const vtkArrayExtents& extents, MemoryBlock* storage);
189
190 typedef vtkDenseArray<T> ThisT;
191
195 vtkArrayExtents Extents;
196
200 std::vector<std::string> DimensionLabels;
201
205 MemoryBlock* Storage;
206
208
212 T* Begin;
213 T* End;
215
219 std::vector<vtkIdType> Offsets;
221
224 std::vector<vtkIdType> Strides;
226};
227
228VTK_ABI_NAMESPACE_END
229#include "vtkDenseArray.txx"
230
231#endif
232
233// VTK-HeaderTest-Exclude: vtkDenseArray.h
Stores coordinate into an N-way array.
Stores the number of dimensions and valid coordinate ranges along each dimension for vtkArray.
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
MemoryBlock implementation that manages internally-allocated memory using new[] and delete[].
T * GetAddress() override
Returns a pointer to the block of memory to be used for storage.
HeapMemoryBlock(const vtkArrayExtents &extents)
Strategy object that contains a block of memory to be used by vtkDenseArray for value storage.
virtual T * GetAddress()=0
Returns a pointer to the block of memory to be used for storage.
MemoryBlock implementation that manages a static (will not be freed) memory block.
T * GetAddress() override
Returns a pointer to the block of memory to be used for storage.
Contiguous storage for N-way arrays.
const T & GetValue(CoordinateT i, CoordinateT j, CoordinateT k) override
Returns the value stored in the array at the given coordinates.
vtkTemplateTypeMacro(vtkDenseArray< T >, vtkTypedArray< T >)
vtkArray::DimensionT DimensionT
SizeT GetNonNullSize() override
Returns the number of non-null values stored in the array.
const vtkArrayExtents & GetExtents() override
Returns the extents (the number of dimensions and size along each dimension) of the array.
void SetValue(CoordinateT i, const T &value) override
Overwrites the value stored in the array at the given coordinates.
T * GetStorage()
Returns a mutable reference to the underlying storage.
static vtkDenseArray< T > * New()
~vtkDenseArray() override
Stores the current array extents (its size along each dimension)
const T * GetStorage() const
Returns a read-only reference to the underlying storage.
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,...
bool IsDense() override
Returns true iff the underlying array storage is "dense", i.e.
void ExternalStorage(const vtkArrayExtents &extents, MemoryBlock *storage)
Initializes the array to use an externally-allocated memory block.
vtkDenseArray()
Stores the current array extents (its size along each dimension)
void Fill(const T &value)
Fills every element in the array with the given value.
const T & GetValue(CoordinateT i) override
Returns the value stored in the array at the given coordinates.
const T & GetValueN(SizeT n) override
Returns the n-th value stored in the array, where n is in the range [0, GetNonNullSize()).
T & operator[](const vtkArrayCoordinates &coordinates)
Returns a value by-reference, which is useful for performance and code-clarity.
const T & GetValue(const vtkArrayCoordinates &coordinates) override
Returns the value stored in the array at the given coordinates.
vtkArray::SizeT SizeT
vtkArray::CoordinateT CoordinateT
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkArray * DeepCopy() override
Returns a new array that is a deep copy of this array.
void SetValue(CoordinateT i, CoordinateT j, const T &value) override
Overwrites 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 SetValue(const vtkArrayCoordinates &coordinates, const T &value) override
Overwrites the value stored in the array at the given coordinates.
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 T & GetValue(CoordinateT i, CoordinateT j) override
Returns the value stored in the array at the given coordinates.
a simple class to control print indentation
Definition vtkIndent.h:38
Wrapper around std::string to keep symbols short.
Provides a type-specific interface to N-way arrays.
int vtkIdType
Definition vtkType.h:315