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 
51 #ifndef __vtkDenseArray_h
52 #define __vtkDenseArray_h
53 
54 #include "vtkArrayCoordinates.h"
55 #include "vtkObjectFactory.h"
56 #include "vtkTypedArray.h"
57 #include "vtkTypeTemplate.h"
58 
59 template<typename T>
61  public vtkTypeTemplate<vtkDenseArray<T>, vtkTypedArray<T> >
62 {
63 public:
64  static vtkDenseArray<T>* New();
65  void PrintSelf(ostream &os, vtkIndent indent);
66 
68  typedef typename vtkArray::DimensionT DimensionT;
69  typedef typename vtkArray::SizeT SizeT;
70 
71  // vtkArray API
72  bool IsDense();
73  const vtkArrayExtents& GetExtents();
75  void GetCoordinatesN(const SizeT n, vtkArrayCoordinates& coordinates);
76  vtkArray* DeepCopy();
77 
78  // vtkTypedArray API
79  const T& GetValue(CoordinateT i);
80  const T& GetValue(CoordinateT i, CoordinateT j);
81  const T& GetValue(CoordinateT i, CoordinateT j, CoordinateT k);
82  const T& GetValue(const vtkArrayCoordinates& coordinates);
83  const T& GetValueN(const SizeT n);
84  void SetValue(CoordinateT i, const T& value);
85  void SetValue(CoordinateT i, CoordinateT j, const T& value);
86  void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value);
87  void SetValue(const vtkArrayCoordinates& coordinates, const T& value);
88  void SetValueN(const SizeT n, const T& value);
89 
90  // vtkDenseArray API
91 
93 
97  {
98  public:
99  virtual ~MemoryBlock();
100  // Description:
101  // Returns a pointer to the block of memory to be used for storage.
102  virtual T* GetAddress() = 0;
103  };
105 
107 
111  public MemoryBlock
112  {
113  public:
114  HeapMemoryBlock(const vtkArrayExtents& extents);
115  virtual ~HeapMemoryBlock();
116  virtual T* GetAddress();
118 
119  private:
120  T* Storage;
121  };
122 
124 
127  public MemoryBlock
128  {
129  public:
130  StaticMemoryBlock(T* const storage);
131  virtual T* GetAddress();
133 
134  private:
135  T* Storage;
136  };
137 
151  void ExternalStorage(const vtkArrayExtents& extents, MemoryBlock* storage);
152 
154  void Fill(const T& value);
155 
158  T& operator[](const vtkArrayCoordinates& coordinates);
159 
162  const T* GetStorage() const;
163 
166  T* GetStorage();
167 
168 protected:
169  vtkDenseArray();
170  ~vtkDenseArray();
171 
172 private:
173  vtkDenseArray(const vtkDenseArray&); // Not implemented
174  void operator=(const vtkDenseArray&); // Not implemented
175 
176  void InternalResize(const vtkArrayExtents& extents);
177  void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label);
178  vtkStdString InternalGetDimensionLabel(DimensionT i);
179  inline vtkIdType MapCoordinates(CoordinateT i);
180  inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j);
181  inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j, CoordinateT k);
182  inline vtkIdType MapCoordinates(const vtkArrayCoordinates& coordinates);
183 
184  void Reconfigure(const vtkArrayExtents& extents, MemoryBlock* storage);
185 
186  typedef vtkDenseArray<T> ThisT;
187 
189  vtkArrayExtents Extents;
190 
192  std::vector<vtkStdString> DimensionLabels;
193 
195  MemoryBlock* Storage;
196 
198 
200  T* Begin;
201  T* End;
203 
205 
206  std::vector<vtkIdType> Offsets;
207  // Description:
208  // Stores the stride along each array dimension (used for fast lookups).
209  std::vector<vtkIdType> Strides;
210 };
212 
213 #include "vtkDenseArray.txx"
214 
215 #endif
216 
Stores coordinate into an N-way array.
Wrapper around vtkstd::string to keep symbols short.
Definition: vtkStdString.h:45
Provides the equivalent of vtkTypeMacro for use with template classes.
void SetValueN(const SizeT n, const T &value)
Stores the number of dimensions and valid coordinate ranges along each dimension for vtkArray...
const T * GetStorage() const
HeapMemoryBlock(const vtkArrayExtents &extents)
void ExternalStorage(const vtkArrayExtents &extents, MemoryBlock *storage)
void SetValue(CoordinateT i, const T &value)
Abstract interface for N-dimensional arrays.
Definition: vtkArray.h:68
virtual T * GetAddress()=0
int vtkIdType
Definition: vtkType.h:255
void GetCoordinatesN(const SizeT n, vtkArrayCoordinates &coordinates)
void Fill(const T &value)
vtkArrayExtents::DimensionT DimensionT
Definition: vtkArray.h:75
a simple class to control print indentation
Definition: vtkIndent.h:37
const T & GetValueN(const SizeT n)
StaticMemoryBlock(T *const storage)
const vtkArrayExtents & GetExtents()
vtkArrayExtents::SizeT SizeT
Definition: vtkArray.h:76
static vtkDenseArray< T > * New()
const T & GetValue(CoordinateT i)
vtkArray * DeepCopy()
Contiguous storage for N-way arrays.
Definition: vtkDenseArray.h:60
vtkArray::CoordinateT CoordinateT
Definition: vtkDenseArray.h:67
vtkArray::SizeT SizeT
Definition: vtkDenseArray.h:69
vtkArrayExtents::CoordinateT CoordinateT
Definition: vtkArray.h:74
vtkArray::DimensionT DimensionT
Definition: vtkDenseArray.h:68
void PrintSelf(ostream &os, vtkIndent indent)
SizeT GetNonNullSize()
T & operator[](const vtkArrayCoordinates &coordinates)