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 
125 #ifndef vtkDenseArray_h
126 #define vtkDenseArray_h
127 
128 #include "vtkArrayCoordinates.h"
129 #include "vtkObjectFactory.h"
130 #include "vtkTypedArray.h"
131 
132 template <typename T>
133 class vtkDenseArray : public vtkTypedArray<T>
134 {
135 public:
138  void PrintSelf(ostream& os, vtkIndent indent) override;
139 
142  typedef typename vtkArray::SizeT SizeT;
143 
144  // vtkArray API
145  bool IsDense() override;
146  const vtkArrayExtents& GetExtents() override;
147  SizeT GetNonNullSize() override;
148  void GetCoordinatesN(const SizeT n, vtkArrayCoordinates& coordinates) override;
149  vtkArray* DeepCopy() override;
150 
151  // vtkTypedArray API
152  const T& GetValue(CoordinateT i) override;
153  const T& GetValue(CoordinateT i, CoordinateT j) override;
154  const T& GetValue(CoordinateT i, CoordinateT j, CoordinateT k) override;
155  const T& GetValue(const vtkArrayCoordinates& coordinates) override;
156  const T& GetValueN(const SizeT n) override;
157  void SetValue(CoordinateT i, const T& value) override;
158  void SetValue(CoordinateT i, CoordinateT j, const T& value) override;
159  void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value) override;
160  void SetValue(const vtkArrayCoordinates& coordinates, const T& value) override;
161  void SetValueN(const SizeT n, const T& value) override;
162 
163  // vtkDenseArray API
164 
171  {
172  public:
173  virtual ~MemoryBlock();
175 
178  virtual T* GetAddress() = 0;
180  };
181 
183 
189  {
190  public:
192  ~HeapMemoryBlock() override;
193  T* GetAddress() override;
195 
196  private:
197  T* Storage;
198  };
199 
201 
205  {
206  public:
207  StaticMemoryBlock(T* const storage);
208  T* GetAddress() override;
210 
211  private:
212  T* Storage;
213  };
214 
231  void ExternalStorage(const vtkArrayExtents& extents, MemoryBlock* storage);
232 
236  void Fill(const T& value);
237 
241  T& operator[](const vtkArrayCoordinates& coordinates);
242 
247  const T* GetStorage() const;
248 
254 
255 protected:
257  ~vtkDenseArray() override;
258 
259 private:
260  vtkDenseArray(const vtkDenseArray&) = delete;
261  void operator=(const vtkDenseArray&) = delete;
262 
263  void InternalResize(const vtkArrayExtents& extents) override;
264  void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label) override;
265  vtkStdString InternalGetDimensionLabel(DimensionT i) override;
266  inline vtkIdType MapCoordinates(CoordinateT i);
267  inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j);
268  inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j, CoordinateT k);
269  inline vtkIdType MapCoordinates(const vtkArrayCoordinates& coordinates);
270 
271  void Reconfigure(const vtkArrayExtents& extents, MemoryBlock* storage);
272 
273  typedef vtkDenseArray<T> ThisT;
274 
278  vtkArrayExtents Extents;
279 
283  std::vector<vtkStdString> DimensionLabels;
284 
288  MemoryBlock* Storage;
289 
291 
295  T* Begin;
296  T* End;
298 
302  std::vector<vtkIdType> Offsets;
304 
307  std::vector<vtkIdType> Strides;
309 };
310 
311 #include "vtkDenseArray.txx"
312 
313 #endif
314 
315 // VTK-HeaderTest-Exclude: vtkDenseArray.h
vtkDenseArray::GetValue
const T & GetValue(const vtkArrayCoordinates &coordinates) override
Returns the value stored in the array at the given coordinates.
vtkDenseArray::GetValue
const T & GetValue(CoordinateT i, CoordinateT j, CoordinateT k) override
Returns the value stored in the array at the given coordinates.
vtkDenseArray::StaticMemoryBlock::StaticMemoryBlock
StaticMemoryBlock(T *const storage)
vtkArray::SizeT
vtkArrayExtents::SizeT SizeT
Definition: vtkArray.h:72
vtkDenseArray::SetValue
void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T &value) override
Overwrites the value stored in the array at the given coordinates.
vtkDenseArray::Fill
void Fill(const T &value)
Fills every element in the array with the given value.
vtkDenseArray::HeapMemoryBlock::~HeapMemoryBlock
~HeapMemoryBlock() override
vtkX3D::value
@ value
Definition: vtkX3D.h:226
vtkDenseArray::New
static vtkDenseArray< T > * New()
vtkIdType
int vtkIdType
Definition: vtkType.h:332
vtkDenseArray::GetStorage
const T * GetStorage() const
Returns a read-only reference to the underlying storage.
vtkTypedArray.h
vtkDenseArray::MemoryBlock
Strategy object that contains a block of memory to be used by vtkDenseArray for value storage.
Definition: vtkDenseArray.h:171
vtkDenseArray::~vtkDenseArray
~vtkDenseArray() override
Stores the current array extents (its size along each dimension)
vtkDenseArray::GetValueN
const T & GetValueN(const SizeT n) override
Returns the n-th value stored in the array, where n is in the range [0, GetNonNullSize()).
vtkDenseArray::DeepCopy
vtkArray * DeepCopy() override
Returns a new array that is a deep copy of this array.
vtkDenseArray
Contiguous storage for N-way arrays.
Definition: vtkDenseArray.h:134
vtkObjectFactory.h
vtkDenseArray::operator[]
T & operator[](const vtkArrayCoordinates &coordinates)
Returns a value by-reference, which is useful for performance and code-clarity.
vtkDenseArray::HeapMemoryBlock::GetAddress
T * GetAddress() override
Returns a pointer to the block of memory to be used for storage.
vtkDenseArray::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkDenseArray::SizeT
vtkArray::SizeT SizeT
Definition: vtkDenseArray.h:142
vtkArrayCoordinates.h
vtkDenseArray::StaticMemoryBlock
MemoryBlock implementation that manages a static (will not be freed) memory block.
Definition: vtkDenseArray.h:205
vtkDenseArray::vtkTemplateTypeMacro
vtkTemplateTypeMacro(vtkDenseArray< T >, vtkTypedArray< T >)
vtkDenseArray::StaticMemoryBlock::GetAddress
T * GetAddress() override
Returns a pointer to the block of memory to be used for storage.
vtkTypedArray
Provides a type-specific interface to N-way arrays.
Definition: vtkTypedArray.h:56
vtkDenseArray::GetValue
const T & GetValue(CoordinateT i) override
Returns the value stored in the array at the given coordinates.
vtkDenseArray::vtkDenseArray
vtkDenseArray()
Stores the current array extents (its size along each dimension)
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:113
vtkDenseArray::MemoryBlock::GetAddress
virtual T * GetAddress()=0
Returns a pointer to the block of memory to be used for storage.
vtkDenseArray::HeapMemoryBlock::HeapMemoryBlock
HeapMemoryBlock(const vtkArrayExtents &extents)
vtkDenseArray::HeapMemoryBlock
MemoryBlock implementation that manages internally-allocated memory using new[] and delete[].
Definition: vtkDenseArray.h:189
vtkDenseArray::SetValue
void SetValue(const vtkArrayCoordinates &coordinates, const T &value) override
Overwrites the value stored in the array at the given coordinates.
vtkDenseArray::IsDense
bool IsDense() override
Returns true iff the underlying array storage is "dense", i.e.
vtkArray
Abstract interface for N-dimensional arrays.
Definition: vtkArray.h:65
vtkDenseArray::GetNonNullSize
SizeT GetNonNullSize() override
Returns the number of non-null values stored in the array.
vtkDenseArray::GetExtents
const vtkArrayExtents & GetExtents() override
Returns the extents (the number of dimensions and size along each dimension) of the array.
vtkDenseArray::ExternalStorage
void ExternalStorage(const vtkArrayExtents &extents, MemoryBlock *storage)
Initializes the array to use an externally-allocated memory block.
vtkDenseArray::SetValue
void SetValue(CoordinateT i, CoordinateT j, const T &value) override
Overwrites the value stored in the array at the given coordinates.
vtkDenseArray::SetValueN
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()).
vtkDenseArray::GetStorage
T * GetStorage()
Returns a mutable reference to the underlying storage.
vtkDenseArray::DimensionT
vtkArray::DimensionT DimensionT
Definition: vtkDenseArray.h:141
vtkDenseArray::GetValue
const T & GetValue(CoordinateT i, CoordinateT j) override
Returns the value stored in the array at the given coordinates.
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:105
vtkDenseArray::MemoryBlock::~MemoryBlock
virtual ~MemoryBlock()
vtkArray::CoordinateT
vtkArrayExtents::CoordinateT CoordinateT
Definition: vtkArray.h:70
vtkDenseArray::GetCoordinatesN
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,...
vtkArrayExtents
Stores the number of dimensions and valid coordinate ranges along each dimension for vtkArray.
Definition: vtkArrayExtents.h:69
vtkDenseArray::CoordinateT
vtkArray::CoordinateT CoordinateT
Definition: vtkDenseArray.h:140
vtkArrayCoordinates
Stores coordinate into an N-way array.
Definition: vtkArrayCoordinates.h:52
vtkDenseArray::SetValue
void SetValue(CoordinateT i, const T &value) override
Overwrites the value stored in the array at the given coordinates.
vtkArray::DimensionT
vtkArrayExtents::DimensionT DimensionT
Definition: vtkArray.h:71