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();
74  SizeT GetNonNullSize();
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();
101 
102 
103  virtual T* GetAddress() = 0;
104  };
106 
108 
112  public MemoryBlock
113  {
114  public:
115  HeapMemoryBlock(const vtkArrayExtents& extents);
116  virtual ~HeapMemoryBlock();
117  virtual T* GetAddress();
119 
120  private:
121  T* Storage;
122  };
123 
125 
128  public MemoryBlock
129  {
130  public:
131  StaticMemoryBlock(T* const storage);
132  virtual T* GetAddress();
134 
135  private:
136  T* Storage;
137  };
138 
152  void ExternalStorage(const vtkArrayExtents& extents, MemoryBlock* storage);
153 
155  void Fill(const T& value);
156 
159  T& operator[](const vtkArrayCoordinates& coordinates);
160 
163  const T* GetStorage() const;
164 
167  T* GetStorage();
168 
169 protected:
170  vtkDenseArray();
171  ~vtkDenseArray();
172 
173 private:
174  vtkDenseArray(const vtkDenseArray&); // Not implemented
175  void operator=(const vtkDenseArray&); // Not implemented
176 
177  void InternalResize(const vtkArrayExtents& extents);
178  void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label);
179  vtkStdString InternalGetDimensionLabel(DimensionT i);
180  inline vtkIdType MapCoordinates(CoordinateT i);
181  inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j);
182  inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j, CoordinateT k);
183  inline vtkIdType MapCoordinates(const vtkArrayCoordinates& coordinates);
184 
185  void Reconfigure(const vtkArrayExtents& extents, MemoryBlock* storage);
186 
187  typedef vtkDenseArray<T> ThisT;
188 
190  vtkArrayExtents Extents;
191 
193  std::vector<vtkStdString> DimensionLabels;
194 
196  MemoryBlock* Storage;
197 
199 
201  T* Begin;
202  T* End;
204 
206  std::vector<vtkIdType> Offsets;
208 
209  std::vector<vtkIdType> Strides;
210 };
212 
213 #include "vtkDenseArray.txx"
214 
215 #endif
216 
217 // VTK-HeaderTest-Exclude: vtkDenseArray.h
Stores coordinate into an N-way array.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:46
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:69
virtual T * GetAddress()=0
int vtkIdType
Definition: vtkType.h:247
void GetCoordinatesN(const SizeT n, vtkArrayCoordinates &coordinates)
void Fill(const T &value)
vtkArrayExtents::DimensionT DimensionT
Definition: vtkArray.h:76
a simple class to control print indentation
Definition: vtkIndent.h:38
const T & GetValueN(const SizeT n)
StaticMemoryBlock(T *const storage)
const vtkArrayExtents & GetExtents()
vtkArrayExtents::SizeT SizeT
Definition: vtkArray.h:77
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:75
vtkArray::DimensionT DimensionT
Definition: vtkDenseArray.h:68
void PrintSelf(ostream &os, vtkIndent indent)
SizeT GetNonNullSize()
T & operator[](const vtkArrayCoordinates &coordinates)