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();
95  SizeT GetNonNullSize();
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  std::vector<CoordinateT> GetUniqueCoordinates(DimensionT dimension);
135 
140  const CoordinateT* GetCoordinateStorage(DimensionT dimension) const;
141 
147  CoordinateT* GetCoordinateStorage(DimensionT dimension);
148 
153  const T* GetValueStorage() const;
154 
159  T* GetValueStorage();
160 
169  void ReserveStorage(const SizeT value_count);
170 
174  void SetExtentsFromContents();
180  void SetExtents(const vtkArrayExtents& extents);
181 
183 
187  inline void AddValue(CoordinateT i, const T& value);
188  inline void AddValue(CoordinateT i, CoordinateT j, const T& value);
189  inline void AddValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value);
190  void AddValue(const vtkArrayCoordinates& coordinates, const T& value);
192 
199  bool Validate();
200 
201 protected:
202  vtkSparseArray();
203  ~vtkSparseArray();
204 
205 private:
206  vtkSparseArray(const vtkSparseArray&); // Not implemented
207  void operator=(const vtkSparseArray&); // Not implemented
208 
209  void InternalResize(const vtkArrayExtents& extents);
210  void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label);
211  vtkStdString InternalGetDimensionLabel(DimensionT i);
212 
213  typedef vtkSparseArray<T> ThisT;
214 
216  vtkArrayExtents Extents;
217 
219  std::vector<vtkStdString> DimensionLabels;
220 
224  std::vector<std::vector<CoordinateT> > Coordinates;
225 
227  std::vector<T> Values;
228 
230 
232  T NullValue;
233 };
235 
236 #include "vtkSparseArray.txx"
237 
238 #endif
239 // VTK-HeaderTest-Exclude: vtkSparseArray.h
Controls sorting of sparse array coordinates.
Definition: vtkArraySort.h:53
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.
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:69
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:76
const T & GetValueN(const SizeT n)
void SetValue(CoordinateT i, const T &value)
a simple class to control print indentation
Definition: vtkIndent.h:38
const T * GetValueStorage() const
vtkArray::SizeT SizeT
vtkArrayExtents::SizeT SizeT
Definition: vtkArray.h:77
std::vector< CoordinateT > GetUniqueCoordinates(DimensionT dimension)
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:75
vtkArray * DeepCopy()