VTK
vtkSparseArray.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkSparseArray.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 
71 #ifndef __vtkSparseArray_h
72 #define __vtkSparseArray_h
73 
74 #include "vtkArrayCoordinates.h"
75 #include "vtkArraySort.h"
76 #include "vtkObjectFactory.h"
77 #include "vtkTypeTemplate.h"
78 #include "vtkTypedArray.h"
79 
80 template<typename T>
82  public vtkTypeTemplate<vtkSparseArray<T>, vtkTypedArray<T> >
83 {
84 public:
85  static vtkSparseArray<T>* New();
86  void PrintSelf(ostream &os, vtkIndent indent);
87 
89  typedef typename vtkArray::DimensionT DimensionT;
90  typedef typename vtkArray::SizeT SizeT;
91 
92  // vtkArray API
93  bool IsDense();
94  const vtkArrayExtents& GetExtents();
96  void GetCoordinatesN(const SizeT n, vtkArrayCoordinates& coordinates);
97  vtkArray* DeepCopy();
98 
99  // vtkTypedArray API
100  const T& GetValue(CoordinateT i);
101  const T& GetValue(CoordinateT i, CoordinateT j);
102  const T& GetValue(CoordinateT i, CoordinateT j, CoordinateT k);
103  const T& GetValue(const vtkArrayCoordinates& coordinates);
104  const T& GetValueN(const SizeT n);
105  void SetValue(CoordinateT i, const T& value);
106  void SetValue(CoordinateT i, CoordinateT j, const T& value);
107  void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value);
108  void SetValue(const vtkArrayCoordinates& coordinates, const T& value);
109  void SetValueN(const SizeT n, const T& value);
110 
111  // vtkSparseArray API
112 
115  void SetNullValue(const T& value);
116 
119  const T& GetNullValue();
120 
124  void Clear();
125 
131  void Sort(const vtkArraySort& sort);
132 
134  vtkstd::vector<CoordinateT> GetUniqueCoordinates(DimensionT dimension);
135 
140  const CoordinateT* GetCoordinateStorage(DimensionT dimension) const;
141 
148 
153  const T* GetValueStorage() const;
154 
159  T* GetValueStorage();
160 
169  void ReserveStorage(const SizeT value_count);
170 
172 
175  void SetExtentsFromContents();
176  // Description:
177  // Specify arbitrary array extents, without altering the contents of the array. Note
178  // that the extents must be as-large-or-larger-than the extents of the actual values
179  // stored in the array. The number of dimensions in the supplied extents must match the
180  // number of dimensions currently stored in the array.
181  void SetExtents(const vtkArrayExtents& extents);
183 
185 
189  inline void AddValue(CoordinateT i, const T& value);
190  inline void AddValue(CoordinateT i, CoordinateT j, const T& value);
191  inline void AddValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value);
192  void AddValue(const vtkArrayCoordinates& coordinates, const T& value);
194 
201  bool Validate();
202 
203 protected:
204  vtkSparseArray();
205  ~vtkSparseArray();
206 
207 private:
208  vtkSparseArray(const vtkSparseArray&); // Not implemented
209  void operator=(const vtkSparseArray&); // Not implemented
210 
211  void InternalResize(const vtkArrayExtents& extents);
212  void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label);
213  vtkStdString InternalGetDimensionLabel(DimensionT i);
214 
215  typedef vtkSparseArray<T> ThisT;
216 
218  vtkArrayExtents Extents;
219 
221  vtkstd::vector<vtkStdString> DimensionLabels;
222 
226  vtkstd::vector<vtkstd::vector<CoordinateT> > Coordinates;
227 
229  vtkstd::vector<T> Values;
230 
232 
234  T NullValue;
235 };
237 
238 #include "vtkSparseArray.txx"
239 
240 #endif
Controls sorting of sparse array coordinates.
Definition: vtkArraySort.h:49
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.
const T & GetValue(CoordinateT i)
Stores the number of dimensions and valid coordinate ranges along each dimension for vtkArray...
Sparse, independent coordinate storage for N-way arrays.
void GetCoordinatesN(const SizeT n, vtkArrayCoordinates &coordinates)
Abstract interface for N-dimensional arrays.
Definition: vtkArray.h:68
vtkstd::vector< CoordinateT > GetUniqueCoordinates(DimensionT dimension)
void SetExtents(const vtkArrayExtents &extents)
vtkArray::DimensionT DimensionT
void SetNullValue(const T &value)
static vtkSparseArray< T > * New()
void Sort(const vtkArraySort &sort)
SizeT GetNonNullSize()
const T & GetNullValue()
vtkArrayExtents::DimensionT DimensionT
Definition: vtkArray.h:75
const T & GetValueN(const SizeT n)
void SetValue(CoordinateT i, const T &value)
a simple class to control print indentation
Definition: vtkIndent.h:37
const T * GetValueStorage() const
vtkArray::SizeT SizeT
vtkArrayExtents::SizeT SizeT
Definition: vtkArray.h:76
void SetValueN(const SizeT n, const T &value)
const CoordinateT * GetCoordinateStorage(DimensionT dimension) const
void SetExtentsFromContents()
vtkArray::CoordinateT CoordinateT
void AddValue(CoordinateT i, const T &value)
void ReserveStorage(const SizeT value_count)
void PrintSelf(ostream &os, vtkIndent indent)
const vtkArrayExtents & GetExtents()
vtkArrayExtents::CoordinateT CoordinateT
Definition: vtkArray.h:74
vtkArray * DeepCopy()