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 
56 template <typename T>
57 class vtkDenseArray : public vtkTypedArray<T>
58 {
59 public:
60  static vtkDenseArray<T>* New();
62  void PrintSelf(ostream& os, vtkIndent indent) override;
63 
65  typedef typename vtkArray::DimensionT DimensionT;
66  typedef typename vtkArray::SizeT SizeT;
67 
68  // vtkArray API
69  bool IsDense() override;
70  const vtkArrayExtents& GetExtents() override;
71  SizeT GetNonNullSize() 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:
115  HeapMemoryBlock(const vtkArrayExtents& extents);
116  ~HeapMemoryBlock() override;
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 
177  T* GetStorage();
178 
179 protected:
180  vtkDenseArray();
181  ~vtkDenseArray() override;
182 
183 private:
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.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:38
vtkDenseArray()
Stores the current array extents (its size along each dimension)
MemoryBlock implementation that manages internally-allocated memory using new[] and delete[]...
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 & GetValueN(const SizeT n) override
Returns the n-th value stored in the array, where n is in the range [0, GetNonNullSize()).
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:67
virtual T * GetAddress()=0
Returns a pointer to the block of memory to be used for storage.
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()).
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:94
int vtkIdType
Definition: vtkType.h:332
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 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, GetNonNullSize()).
vtkArrayExtents::DimensionT DimensionT
Definition: vtkArray.h:74
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:39
bool IsDense() override
Returns true iff the underlying array storage is "dense", i.e.
StaticMemoryBlock(T *const storage)
const T & GetValue(CoordinateT i) override
Returns the value stored in the array at the given coordinates.
vtkArrayExtents::SizeT SizeT
Definition: vtkArray.h:75
static vtkDenseArray< T > * New()
vtkTemplateTypeMacro(vtkDenseArray< T >, vtkTypedArray< T >)
Contiguous storage for N-way arrays.
Definition: vtkDenseArray.h:57
Provides a type-specific interface to N-way arrays.
Definition: vtkTypedArray.h:58
vtkArray::CoordinateT CoordinateT
Definition: vtkDenseArray.h:64
vtkArray::SizeT SizeT
Definition: vtkDenseArray.h:66
vtkArrayExtents::CoordinateT CoordinateT
Definition: vtkArray.h:73
vtkArray::DimensionT DimensionT
Definition: vtkDenseArray.h:65
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.