VTK  9.2.6
vtkDenseArray.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkDenseArray.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
49#ifndef vtkDenseArray_h
50#define vtkDenseArray_h
51
52#include "vtkArrayCoordinates.h"
53#include "vtkObjectFactory.h"
54#include "vtkTypedArray.h"
55
56template <typename T>
58{
59public:
62 void PrintSelf(ostream& os, vtkIndent indent) override;
63
66 typedef typename vtkArray::SizeT SizeT;
67
68 // vtkArray API
69 bool IsDense() override;
70 const vtkArrayExtents& GetExtents() override;
72 void GetCoordinatesN(const SizeT n, vtkArrayCoordinates& coordinates) override;
73 vtkArray* DeepCopy() override;
74
75 // vtkTypedArray API
76 const T& GetValue(CoordinateT i) override;
77 const T& GetValue(CoordinateT i, CoordinateT j) override;
78 const T& GetValue(CoordinateT i, CoordinateT j, CoordinateT k) override;
79 const T& GetValue(const vtkArrayCoordinates& coordinates) override;
80 const T& GetValueN(const SizeT n) override;
81 void SetValue(CoordinateT i, const T& value) override;
82 void SetValue(CoordinateT i, CoordinateT j, const T& value) override;
83 void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value) override;
84 void SetValue(const vtkArrayCoordinates& coordinates, const T& value) override;
85 void SetValueN(const SizeT n, const T& value) override;
86
87 // vtkDenseArray API
88
95 {
96 public:
97 virtual ~MemoryBlock();
99
102 virtual T* GetAddress() = 0;
104 };
105
107
113 {
114 public:
117 T* GetAddress() override;
119
120 private:
121 T* Storage;
122 };
123
125
129 {
130 public:
131 StaticMemoryBlock(T* const storage);
132 T* GetAddress() override;
134
135 private:
136 T* Storage;
137 };
138
155 void ExternalStorage(const vtkArrayExtents& extents, MemoryBlock* storage);
156
160 void Fill(const T& value);
161
165 T& operator[](const vtkArrayCoordinates& coordinates);
166
171 const T* GetStorage() const;
172
178
179protected:
181 ~vtkDenseArray() override;
182
183private:
184 vtkDenseArray(const vtkDenseArray&) = delete;
185 void operator=(const vtkDenseArray&) = delete;
186
187 void InternalResize(const vtkArrayExtents& extents) override;
188 void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label) override;
189 vtkStdString InternalGetDimensionLabel(DimensionT i) override;
190 inline vtkIdType MapCoordinates(CoordinateT i);
191 inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j);
192 inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j, CoordinateT k);
193 inline vtkIdType MapCoordinates(const vtkArrayCoordinates& coordinates);
194
195 void Reconfigure(const vtkArrayExtents& extents, MemoryBlock* storage);
196
197 typedef vtkDenseArray<T> ThisT;
198
202 vtkArrayExtents Extents;
203
207 std::vector<vtkStdString> DimensionLabels;
208
212 MemoryBlock* Storage;
213
215
219 T* Begin;
220 T* End;
222
226 std::vector<vtkIdType> Offsets;
228
231 std::vector<vtkIdType> Strides;
233};
234
235#include "vtkDenseArray.txx"
236
237#endif
238
239// 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:68
vtkArrayExtents::DimensionT DimensionT
Definition vtkArray.h:74
vtkArrayExtents::SizeT SizeT
Definition vtkArray.h:75
vtkArrayExtents::CoordinateT CoordinateT
Definition vtkArray.h:73
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.
StaticMemoryBlock(T *const storage)
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.
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()).
vtkTemplateTypeMacro(vtkDenseArray< T >, vtkTypedArray< T >)
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.
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 & GetValueN(const SizeT n) override
Returns 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.
T & operator[](const vtkArrayCoordinates &coordinates)
Returns a value by-reference, which is useful for performance and code-clarity.
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,...
const T & GetValue(const vtkArrayCoordinates &coordinates) override
Returns the value stored in the array at the given coordinates.
vtkArray::DimensionT DimensionT
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkArray::CoordinateT CoordinateT
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.
vtkArray::SizeT SizeT
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:40
Wrapper around std::string to keep symbols short.
Provides a type-specific interface to N-way arrays.
int vtkIdType
Definition vtkType.h:332