VTK
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 
52 #ifndef vtkDenseArray_h
53 #define vtkDenseArray_h
54 
55 #include "vtkArrayCoordinates.h"
56 #include "vtkObjectFactory.h"
57 #include "vtkTypedArray.h"
58 
59 template<typename T>
60 class vtkDenseArray : public vtkTypedArray<T>
61 {
62 public:
63  static vtkDenseArray<T>* New();
65  void PrintSelf(ostream &os, vtkIndent indent) override;
66 
67  typedef typename vtkArray::CoordinateT CoordinateT;
68  typedef typename vtkArray::DimensionT DimensionT;
69  typedef typename vtkArray::SizeT SizeT;
70 
71  // vtkArray API
72  bool IsDense() override;
75  void GetCoordinatesN(const SizeT n, vtkArrayCoordinates& coordinates) override;
77 
78  // vtkTypedArray API
79  const T& GetValue(CoordinateT i) override;
82  const T& GetValue(const vtkArrayCoordinates& coordinates) override;
83  const T& GetValueN(const SizeT n) override;
84  void SetValue(CoordinateT i, const T& value) override;
85  void SetValue(CoordinateT i, CoordinateT j, const T& value) override;
86  void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value) override;
87  void SetValue(const vtkArrayCoordinates& coordinates, const T& value) override;
88  void SetValueN(const SizeT n, const T& value) override;
89 
90  // vtkDenseArray API
91 
98  {
99  public:
100  virtual ~MemoryBlock();
102 
105  virtual T* GetAddress() = 0;
106  };
108 
110 
116  public MemoryBlock
117  {
118  public:
119  HeapMemoryBlock(const vtkArrayExtents& extents);
120  ~HeapMemoryBlock() override;
121  T* GetAddress() override;
123 
124  private:
125  T* Storage;
126  };
127 
129 
133  public MemoryBlock
134  {
135  public:
136  StaticMemoryBlock(T* const storage);
137  T* GetAddress() override;
139 
140  private:
141  T* Storage;
142  };
143 
160  void ExternalStorage(const vtkArrayExtents& extents, MemoryBlock* storage);
161 
165  void Fill(const T& value);
166 
170  T& operator[](const vtkArrayCoordinates& coordinates);
171 
176  const T* GetStorage() const;
177 
182  T* GetStorage();
183 
184 protected:
185  vtkDenseArray();
186  ~vtkDenseArray() override;
187 
188 private:
189  vtkDenseArray(const vtkDenseArray&) = delete;
190  void operator=(const vtkDenseArray&) = delete;
191 
192  void InternalResize(const vtkArrayExtents& extents) override;
193  void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label) override;
194  vtkStdString InternalGetDimensionLabel(DimensionT i) override;
195  inline vtkIdType MapCoordinates(CoordinateT i);
196  inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j);
197  inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j, CoordinateT k);
198  inline vtkIdType MapCoordinates(const vtkArrayCoordinates& coordinates);
199 
200  void Reconfigure(const vtkArrayExtents& extents, MemoryBlock* storage);
201 
202  typedef vtkDenseArray<T> ThisT;
203 
207  vtkArrayExtents Extents;
208 
212  std::vector<vtkStdString> DimensionLabels;
213 
217  MemoryBlock* Storage;
218 
220 
224  T* Begin;
225  T* End;
227 
231  std::vector<vtkIdType> Offsets;
233 
236  std::vector<vtkIdType> Strides;
237 };
239 
240 #include "vtkDenseArray.txx"
241 
242 #endif
243 
244 // VTK-HeaderTest-Exclude: vtkDenseArray.h
vtkTypedArray::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkDenseArray::StaticMemoryBlock::StaticMemoryBlock
StaticMemoryBlock(T *const storage)
vtkArray::SizeT
vtkArrayExtents::SizeT SizeT
Definition: vtkArray.h:78
vtkDenseArray::Fill
void Fill(const T &value)
Fills every element in the array with the given value.
vtkDenseArray::HeapMemoryBlock::~HeapMemoryBlock
~HeapMemoryBlock() override
vtkX3D::value
Definition: vtkX3D.h:220
vtkDenseArray::New
static vtkDenseArray< T > * New()
vtkIdType
int vtkIdType
Definition: vtkType.h:347
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:97
vtkDenseArray::~vtkDenseArray
~vtkDenseArray() override
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:60
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.
vtkArrayCoordinates.h
vtkDenseArray::StaticMemoryBlock
MemoryBlock implementation that manages a static (will not be freed) memory block.
Definition: vtkDenseArray.h:132
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:58
vtkDenseArray::GetValue
const T & GetValue(CoordinateT i) override
Returns the value stored in the array at the given coordinates.
vtkDenseArray::vtkTemplateTypeMacro
vtkTemplateTypeMacro(vtkDenseArray< T >, vtkTypedArray< T >) void PrintSelf(ostream &os
vtkDenseArray::vtkDenseArray
vtkDenseArray()
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkDenseArray::override
vtkIndent indent override
Definition: vtkDenseArray.h:65
vtkDenseArray::HeapMemoryBlock::HeapMemoryBlock
HeapMemoryBlock(const vtkArrayExtents &extents)
vtkDenseArray::HeapMemoryBlock
MemoryBlock implementation that manages internally-allocated memory using new[] and delete[].
Definition: vtkDenseArray.h:115
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:70
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::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()).
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:40
vtkArray::CoordinateT
vtkArrayExtents::CoordinateT CoordinateT
Definition: vtkArray.h:76
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:74
vtkArrayCoordinates
Stores coordinate into an N-way array.
Definition: vtkArrayCoordinates.h:57
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:77