VTK  9.2.20220703
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 
128 #ifndef vtkDenseArray_h
129 #define vtkDenseArray_h
130 
131 #include "vtkArrayCoordinates.h"
132 #include "vtkObjectFactory.h"
133 #include "vtkTypedArray.h"
134 
135 template <typename T>
136 class vtkDenseArray : public vtkTypedArray<T>
137 {
138 public:
141  void PrintSelf(ostream& os, vtkIndent indent) override;
142 
145  typedef typename vtkArray::SizeT SizeT;
146 
147  // vtkArray API
148  bool IsDense() override;
149  const vtkArrayExtents& GetExtents() override;
150  SizeT GetNonNullSize() override;
151  void GetCoordinatesN(const SizeT n, vtkArrayCoordinates& coordinates) override;
152  vtkArray* DeepCopy() override;
153 
154  // vtkTypedArray API
155  const T& GetValue(CoordinateT i) override;
156  const T& GetValue(CoordinateT i, CoordinateT j) override;
157  const T& GetValue(CoordinateT i, CoordinateT j, CoordinateT k) override;
158  const T& GetValue(const vtkArrayCoordinates& coordinates) override;
159  const T& GetValueN(const SizeT n) override;
160  void SetValue(CoordinateT i, const T& value) override;
161  void SetValue(CoordinateT i, CoordinateT j, const T& value) override;
162  void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value) override;
163  void SetValue(const vtkArrayCoordinates& coordinates, const T& value) override;
164  void SetValueN(const SizeT n, const T& value) override;
165 
166  // vtkDenseArray API
167 
174  {
175  public:
176  virtual ~MemoryBlock();
178 
181  virtual T* GetAddress() = 0;
183  };
184 
186 
192  {
193  public:
195  ~HeapMemoryBlock() override;
196  T* GetAddress() override;
198 
199  private:
200  T* Storage;
201  };
202 
204 
208  {
209  public:
210  StaticMemoryBlock(T* const storage);
211  T* GetAddress() override;
213 
214  private:
215  T* Storage;
216  };
217 
234  void ExternalStorage(const vtkArrayExtents& extents, MemoryBlock* storage);
235 
239  void Fill(const T& value);
240 
244  T& operator[](const vtkArrayCoordinates& coordinates);
245 
250  const T* GetStorage() const;
251 
257 
258 protected:
260  ~vtkDenseArray() override;
261 
262 private:
263  vtkDenseArray(const vtkDenseArray&) = delete;
264  void operator=(const vtkDenseArray&) = delete;
265 
266  void InternalResize(const vtkArrayExtents& extents) override;
267  void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label) override;
268  vtkStdString InternalGetDimensionLabel(DimensionT i) override;
269  inline vtkIdType MapCoordinates(CoordinateT i);
270  inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j);
271  inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j, CoordinateT k);
272  inline vtkIdType MapCoordinates(const vtkArrayCoordinates& coordinates);
273 
274  void Reconfigure(const vtkArrayExtents& extents, MemoryBlock* storage);
275 
276  typedef vtkDenseArray<T> ThisT;
277 
281  vtkArrayExtents Extents;
282 
286  std::vector<vtkStdString> DimensionLabels;
287 
291  MemoryBlock* Storage;
292 
294 
298  T* Begin;
299  T* End;
301 
305  std::vector<vtkIdType> Offsets;
307 
310  std::vector<vtkIdType> Strides;
312 };
313 
314 #include "vtkDenseArray.txx"
315 
316 #endif
317 
318 // 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::SizeT SizeT
Definition: vtkArray.h:75
vtkArrayExtents::DimensionT DimensionT
Definition: vtkArray.h:74
vtkArrayExtents::CoordinateT CoordinateT
Definition: vtkArray.h:73
MemoryBlock implementation that manages internally-allocated memory using new[] and delete[].
HeapMemoryBlock(const vtkArrayExtents &extents)
T * GetAddress() override
Returns a pointer to the block of memory to be used for storage.
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.
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
SizeT GetNonNullSize() override
Returns the number of non-null values stored in the array.
void SetValue(CoordinateT i, const T &value) override
Overwrites 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.
~vtkDenseArray() override
Stores the current array extents (its size along each dimension)
T * GetStorage()
Returns a mutable reference to the underlying storage.
const T & GetValue(CoordinateT i, CoordinateT j, CoordinateT k) override
Returns the value stored in the array at the given coordinates.
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.
vtkArray * DeepCopy() override
Returns a new array that is a deep copy of this array.
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.
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(CoordinateT i, CoordinateT j) override
Returns the value stored in the array at the given coordinates.
vtkArray::SizeT SizeT
const T * GetStorage() const
Returns a read-only reference to the underlying storage.
const vtkArrayExtents & GetExtents() override
Returns the extents (the number of dimensions and size along each dimension) of the array.
vtkArray::CoordinateT CoordinateT
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(const vtkArrayCoordinates &coordinates) override
Returns the value stored in the array at the given coordinates.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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.
static vtkDenseArray< T > * New()
const T & GetValue(CoordinateT i) override
Returns the value stored in the array at the given coordinates.
a simple class to control print indentation
Definition: vtkIndent.h:119
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:108
Provides a type-specific interface to N-way arrays.
Definition: vtkTypedArray.h:59
@ value
Definition: vtkX3D.h:226
int vtkIdType
Definition: vtkType.h:325