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 
46 #ifndef vtkDenseArray_h
47 #define vtkDenseArray_h
48 
49 #include "vtkArrayCoordinates.h"
50 #include "vtkObjectFactory.h"
51 #include "vtkTypedArray.h"
52 
53 template<typename T>
54 class vtkDenseArray : public vtkTypedArray<T>
55 {
56 public:
57  static vtkDenseArray<T>* New();
59  void PrintSelf(ostream &os, vtkIndent indent) override;
60 
61  typedef typename vtkArray::CoordinateT CoordinateT;
62  typedef typename vtkArray::DimensionT DimensionT;
63  typedef typename vtkArray::SizeT SizeT;
64 
65  // vtkArray API
66  bool IsDense() override;
69  void GetCoordinatesN(const SizeT n, vtkArrayCoordinates& coordinates) override;
71 
72  // vtkTypedArray API
73  const T& GetValue(CoordinateT i) override;
76  const T& GetValue(const vtkArrayCoordinates& coordinates) override;
77  const T& GetValueN(const SizeT n) override;
78  void SetValue(CoordinateT i, const T& value) override;
79  void SetValue(CoordinateT i, CoordinateT j, const T& value) override;
80  void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value) override;
81  void SetValue(const vtkArrayCoordinates& coordinates, const T& value) override;
82  void SetValueN(const SizeT n, const T& value) override;
83 
84  // vtkDenseArray API
85 
92  {
93  public:
94  virtual ~MemoryBlock();
96 
99  virtual T* GetAddress() = 0;
100  };
102 
104 
110  public MemoryBlock
111  {
112  public:
113  HeapMemoryBlock(const vtkArrayExtents& extents);
114  ~HeapMemoryBlock() override;
115  T* GetAddress() override;
117 
118  private:
119  T* Storage;
120  };
121 
123 
127  public MemoryBlock
128  {
129  public:
130  StaticMemoryBlock(T* const storage);
131  T* GetAddress() override;
133 
134  private:
135  T* Storage;
136  };
137 
154  void ExternalStorage(const vtkArrayExtents& extents, MemoryBlock* storage);
155 
159  void Fill(const T& value);
160 
164  T& operator[](const vtkArrayCoordinates& coordinates);
165 
170  const T* GetStorage() const;
171 
176  T* GetStorage();
177 
178 protected:
179  vtkDenseArray();
180  ~vtkDenseArray() override;
181 
182 private:
183  vtkDenseArray(const vtkDenseArray&) = delete;
184  void operator=(const vtkDenseArray&) = delete;
185 
186  void InternalResize(const vtkArrayExtents& extents) override;
187  void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label) override;
188  vtkStdString InternalGetDimensionLabel(DimensionT i) override;
189  inline vtkIdType MapCoordinates(CoordinateT i);
190  inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j);
191  inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j, CoordinateT k);
192  inline vtkIdType MapCoordinates(const vtkArrayCoordinates& coordinates);
193 
194  void Reconfigure(const vtkArrayExtents& extents, MemoryBlock* storage);
195 
196  typedef vtkDenseArray<T> ThisT;
197 
201  vtkArrayExtents Extents;
202 
206  std::vector<vtkStdString> DimensionLabels;
207 
211  MemoryBlock* Storage;
212 
214 
218  T* Begin;
219  T* End;
221 
225  std::vector<vtkIdType> Offsets;
227 
230  std::vector<vtkIdType> Strides;
231 };
233 
234 #include "vtkDenseArray.txx"
235 
236 #endif
237 
238 // VTK-HeaderTest-Exclude: vtkDenseArray.h
Stores coordinate into an N-way array.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:34
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()).
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:64
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.
const T * GetStorage() const
Returns a read-only reference to the underlying storage.
Strategy object that contains a block of memory to be used by vtkDenseArray for value storage.
Definition: vtkDenseArray.h:91
int vtkIdType
Definition: vtkType.h:345
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,...
vtkArrayExtents::DimensionT DimensionT
Definition: vtkArray.h:71
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:33
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:72
vtkTemplateTypeMacro(vtkDenseArray< T >, vtkTypedArray< T >) void PrintSelf(ostream &os
static vtkDenseArray< T > * New()
vtkIndent indent override
Definition: vtkDenseArray.h:59
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
Contiguous storage for N-way arrays.
Definition: vtkDenseArray.h:54
Provides a type-specific interface to N-way arrays.
Definition: vtkTypedArray.h:55
vtkArrayExtents::CoordinateT CoordinateT
Definition: vtkArray.h:70
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.