VTK  9.4.20250114
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
111#ifndef vtkDenseArray_h
112#define vtkDenseArray_h
113
114#include "vtkArrayCoordinates.h"
115#include "vtkObjectFactory.h"
116#include "vtkTypedArray.h"
117
118VTK_ABI_NAMESPACE_BEGIN
119template <typename T>
121{
122public:
125 void PrintSelf(ostream& os, vtkIndent indent) override;
126
129 typedef typename vtkArray::SizeT SizeT;
130
131 // vtkArray API
132 bool IsDense() override;
133 const vtkArrayExtents& GetExtents() override;
135 void GetCoordinatesN(SizeT n, vtkArrayCoordinates& coordinates) override;
136 vtkArray* DeepCopy() override;
137
138 // vtkTypedArray API
139 const T& GetValue(CoordinateT i) override;
140 const T& GetValue(CoordinateT i, CoordinateT j) override;
141 const T& GetValue(CoordinateT i, CoordinateT j, CoordinateT k) override;
142 const T& GetValue(const vtkArrayCoordinates& coordinates) override;
143 const T& GetValueN(SizeT n) override;
144 void SetValue(CoordinateT i, const T& value) override;
145 void SetValue(CoordinateT i, CoordinateT j, const T& value) override;
146 void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value) override;
147 void SetValue(const vtkArrayCoordinates& coordinates, const T& value) override;
148 void SetValueN(SizeT n, const T& value) override;
149
150 // vtkDenseArray API
151
158 {
159 public:
160 virtual ~MemoryBlock();
162
165 virtual T* GetAddress() = 0;
167 };
168
170
176 {
177 public:
180 T* GetAddress() override;
182
183 private:
184 T* Storage;
185 };
186
188
192 {
193 public:
194 StaticMemoryBlock(T* storage);
195 T* GetAddress() override;
197
198 private:
199 T* Storage;
200 };
201
218 void ExternalStorage(const vtkArrayExtents& extents, MemoryBlock* storage);
219
223 void Fill(const T& value);
224
228 T& operator[](const vtkArrayCoordinates& coordinates);
229
234 const T* GetStorage() const;
235
241
242protected:
244 ~vtkDenseArray() override;
245
246private:
247 vtkDenseArray(const vtkDenseArray&) = delete;
248 void operator=(const vtkDenseArray&) = delete;
249
250 void InternalResize(const vtkArrayExtents& extents) override;
251 void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label) override;
252 vtkStdString InternalGetDimensionLabel(DimensionT i) override;
253 inline vtkIdType MapCoordinates(CoordinateT i);
254 inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j);
255 inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j, CoordinateT k);
256 inline vtkIdType MapCoordinates(const vtkArrayCoordinates& coordinates);
257
258 void Reconfigure(const vtkArrayExtents& extents, MemoryBlock* storage);
259
260 typedef vtkDenseArray<T> ThisT;
261
265 vtkArrayExtents Extents;
266
270 std::vector<std::string> DimensionLabels;
271
275 MemoryBlock* Storage;
276
278
282 T* Begin;
283 T* End;
285
289 std::vector<vtkIdType> Offsets;
291
294 std::vector<vtkIdType> Strides;
296};
297
298VTK_ABI_NAMESPACE_END
299#include "vtkDenseArray.txx"
300
301#endif
302
303// 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:108
Wrapper around std::string to keep symbols short.
Provides a type-specific interface to N-way arrays.
int vtkIdType
Definition vtkType.h:315