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
32#ifndef vtkDenseArray_h
33#define vtkDenseArray_h
34
35#include "vtkArrayCoordinates.h"
36#include "vtkObjectFactory.h"
37#include "vtkTypedArray.h"
38
39VTK_ABI_NAMESPACE_BEGIN
40template <typename T>
42{
43public:
46 void PrintSelf(ostream& os, vtkIndent indent) override;
47
50 typedef typename vtkArray::SizeT SizeT;
51
52 // vtkArray API
53 bool IsDense() override;
54 const vtkArrayExtents& GetExtents() override;
56 void GetCoordinatesN(SizeT n, vtkArrayCoordinates& coordinates) override;
57 vtkArray* DeepCopy() override;
58
59 // vtkTypedArray API
60 const T& GetValue(CoordinateT i) override;
61 const T& GetValue(CoordinateT i, CoordinateT j) override;
62 const T& GetValue(CoordinateT i, CoordinateT j, CoordinateT k) override;
63 const T& GetValue(const vtkArrayCoordinates& coordinates) override;
64 const T& GetValueN(SizeT n) override;
65 void SetValue(CoordinateT i, const T& value) override;
66 void SetValue(CoordinateT i, CoordinateT j, const T& value) override;
67 void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value) override;
68 void SetValue(const vtkArrayCoordinates& coordinates, const T& value) override;
69 void SetValueN(SizeT n, const T& value) override;
70
71 // vtkDenseArray API
72
79 {
80 public:
81 virtual ~MemoryBlock();
83
86 virtual T* GetAddress() = 0;
88 };
89
91
97 {
98 public:
101 T* GetAddress() override;
103
104 private:
105 T* Storage;
106 };
107
109
113 {
114 public:
115 StaticMemoryBlock(T* storage);
116 T* GetAddress() override;
118
119 private:
120 T* Storage;
121 };
122
139 void ExternalStorage(const vtkArrayExtents& extents, MemoryBlock* storage);
140
144 void Fill(const T& value);
145
149 T& operator[](const vtkArrayCoordinates& coordinates);
150
155 const T* GetStorage() const;
156
162
163protected:
165 ~vtkDenseArray() override;
166
167private:
168 vtkDenseArray(const vtkDenseArray&) = delete;
169 void operator=(const vtkDenseArray&) = delete;
170
171 void InternalResize(const vtkArrayExtents& extents) override;
172 void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label) override;
173 vtkStdString InternalGetDimensionLabel(DimensionT i) override;
174 inline vtkIdType MapCoordinates(CoordinateT i);
175 inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j);
176 inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j, CoordinateT k);
177 inline vtkIdType MapCoordinates(const vtkArrayCoordinates& coordinates);
178
179 void Reconfigure(const vtkArrayExtents& extents, MemoryBlock* storage);
180
181 typedef vtkDenseArray<T> ThisT;
182
186 vtkArrayExtents Extents;
187
191 std::vector<std::string> DimensionLabels;
192
196 MemoryBlock* Storage;
197
199
203 T* Begin;
204 T* End;
206
210 std::vector<vtkIdType> Offsets;
212
215 std::vector<vtkIdType> Strides;
217};
218
219VTK_ABI_NAMESPACE_END
220#include "vtkDenseArray.txx"
221
222#endif
223
224// 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:29
Wrapper around std::string to keep symbols short.
Provides a type-specific interface to N-way arrays.
int vtkIdType
Definition vtkType.h:315