VTK  9.3.1
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 
39 VTK_ABI_NAMESPACE_BEGIN
40 template <typename T>
41 class vtkDenseArray : public vtkTypedArray<T>
42 {
43 public:
44  static vtkDenseArray<T>* New();
46  void PrintSelf(ostream& os, vtkIndent indent) override;
47 
49  typedef typename vtkArray::DimensionT DimensionT;
50  typedef typename vtkArray::SizeT SizeT;
51 
52  // vtkArray API
53  bool IsDense() override;
54  const vtkArrayExtents& GetExtents() override;
55  SizeT GetNonNullSize() 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:
99  HeapMemoryBlock(const vtkArrayExtents& extents);
100  ~HeapMemoryBlock() override;
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 
161  T* GetStorage();
162 
163 protected:
164  vtkDenseArray();
165  ~vtkDenseArray() override;
166 
167 private:
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 
219 VTK_ABI_NAMESPACE_END
220 #include "vtkDenseArray.txx"
221 
222 #endif
223 
224 // VTK-HeaderTest-Exclude: vtkDenseArray.h
Stores coordinate into an N-way array.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:28
vtkDenseArray()
Stores the current array extents (its size along each dimension)
MemoryBlock implementation that manages internally-allocated memory using new[] and delete[]...
Definition: vtkDenseArray.h:96
Stores the number of dimensions and valid coordinate ranges along each dimension for vtkArray...
~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.
HeapMemoryBlock(const vtkArrayExtents &extents)
void ExternalStorage(const vtkArrayExtents &extents, MemoryBlock *storage)
Initializes the array to use an externally-allocated memory block.
Abstract interface for N-dimensional arrays.
Definition: vtkArray.h:51
virtual T * GetAddress()=0
Returns a pointer to the block of memory to be used for storage.
void SetValue(CoordinateT i, const T &value) override
Overwrites the value stored in the array at the given coordinates.
Strategy object that contains a block of memory to be used by vtkDenseArray for value storage...
Definition: vtkDenseArray.h:78
int vtkIdType
Definition: vtkType.h:315
vtkArray * DeepCopy() override
Returns a new array that is a deep copy of this array.
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 Fill(const T &value)
Fills every element in the array with the given value.
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()).
vtkArrayExtents::DimensionT DimensionT
Definition: vtkArray.h:58
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
T * GetAddress() override
Returns a pointer to the block of memory to be used for storage.
a simple class to control print indentation
Definition: vtkIndent.h:28
bool IsDense() override
Returns true iff the underlying array storage is "dense", i.e.
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()).
vtkArrayExtents::SizeT SizeT
Definition: vtkArray.h:59
static vtkDenseArray< T > * New()
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, GetNonNullSize()).
vtkTemplateTypeMacro(vtkDenseArray< T >, vtkTypedArray< T >)
Contiguous storage for N-way arrays.
Definition: vtkDenseArray.h:41
Provides a type-specific interface to N-way arrays.
Definition: vtkTypedArray.h:42
vtkArray::CoordinateT CoordinateT
Definition: vtkDenseArray.h:48
vtkArray::SizeT SizeT
Definition: vtkDenseArray.h:50
vtkArrayExtents::CoordinateT CoordinateT
Definition: vtkArray.h:57
vtkArray::DimensionT DimensionT
Definition: vtkDenseArray.h:49
T * GetAddress() override
Returns a pointer to the block of memory to be used for storage.
T & operator[](const vtkArrayCoordinates &coordinates)
Returns a value by-reference, which is useful for performance and code-clarity.
MemoryBlock implementation that manages a static (will not be freed) memory block.