VTK  9.1.0
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
55#ifndef vtkDenseArray_h
56#define vtkDenseArray_h
57
58#include "vtkArrayCoordinates.h"
59#include "vtkObjectFactory.h"
60#include "vtkTypedArray.h"
61
62template <typename T>
64{
65public:
68 void PrintSelf(ostream& os, vtkIndent indent) override;
69
72 typedef typename vtkArray::SizeT SizeT;
73
74 // vtkArray API
75 bool IsDense() override;
76 const vtkArrayExtents& GetExtents() override;
78 void GetCoordinatesN(const SizeT n, vtkArrayCoordinates& coordinates) override;
79 vtkArray* DeepCopy() override;
80
81 // vtkTypedArray API
82 const T& GetValue(CoordinateT i) override;
83 const T& GetValue(CoordinateT i, CoordinateT j) override;
84 const T& GetValue(CoordinateT i, CoordinateT j, CoordinateT k) override;
85 const T& GetValue(const vtkArrayCoordinates& coordinates) override;
86 const T& GetValueN(const SizeT n) override;
87 void SetValue(CoordinateT i, const T& value) override;
88 void SetValue(CoordinateT i, CoordinateT j, const T& value) override;
89 void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value) override;
90 void SetValue(const vtkArrayCoordinates& coordinates, const T& value) override;
91 void SetValueN(const SizeT n, const T& value) override;
92
93 // vtkDenseArray API
94
101 {
102 public:
103 virtual ~MemoryBlock();
105
108 virtual T* GetAddress() = 0;
110 };
111
113
119 {
120 public:
123 T* GetAddress() override;
125
126 private:
127 T* Storage;
128 };
129
131
135 {
136 public:
137 StaticMemoryBlock(T* const storage);
138 T* GetAddress() override;
140
141 private:
142 T* Storage;
143 };
144
161 void ExternalStorage(const vtkArrayExtents& extents, MemoryBlock* storage);
162
166 void Fill(const T& value);
167
171 T& operator[](const vtkArrayCoordinates& coordinates);
172
177 const T* GetStorage() const;
178
184
185protected:
187 ~vtkDenseArray() override;
188
189private:
190 vtkDenseArray(const vtkDenseArray&) = delete;
191 void operator=(const vtkDenseArray&) = delete;
192
193 void InternalResize(const vtkArrayExtents& extents) override;
194 void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label) override;
195 vtkStdString InternalGetDimensionLabel(DimensionT i) override;
196 inline vtkIdType MapCoordinates(CoordinateT i);
197 inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j);
198 inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j, CoordinateT k);
199 inline vtkIdType MapCoordinates(const vtkArrayCoordinates& coordinates);
200
201 void Reconfigure(const vtkArrayExtents& extents, MemoryBlock* storage);
202
203 typedef vtkDenseArray<T> ThisT;
204
208 vtkArrayExtents Extents;
209
213 std::vector<vtkStdString> DimensionLabels;
214
218 MemoryBlock* Storage;
219
221
225 T* Begin;
226 T* End;
228
232 std::vector<vtkIdType> Offsets;
234
237 std::vector<vtkIdType> Strides;
239};
240
241#include "vtkDenseArray.txx"
242
243#endif
244
245// 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:65
vtkArrayExtents::SizeT SizeT
Definition: vtkArray.h:72
vtkArrayExtents::DimensionT DimensionT
Definition: vtkArray.h:71
vtkArrayExtents::CoordinateT CoordinateT
Definition: vtkArray.h:70
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.
Definition: vtkDenseArray.h:64
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 >)
vtkArray::DimensionT DimensionT
Definition: vtkDenseArray.h:71
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::SizeT SizeT
Definition: vtkDenseArray.h:72
vtkArray::CoordinateT CoordinateT
Definition: vtkDenseArray.h:70
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.
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:43
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
int vtkIdType
Definition: vtkType.h:332