VTK
dox/Common/vtkSparseArray.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkSparseArray.h
00005   
00006 -------------------------------------------------------------------------
00007   Copyright 2008 Sandia Corporation.
00008   Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009   the U.S. Government retains certain rights in this software.
00010 -------------------------------------------------------------------------
00011 
00012   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00013   All rights reserved.
00014   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00015 
00016      This software is distributed WITHOUT ANY WARRANTY; without even
00017      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00018      PURPOSE.  See the above copyright notice for more information.
00019 
00020 =========================================================================*/
00021 
00071 #ifndef __vtkSparseArray_h
00072 #define __vtkSparseArray_h
00073 
00074 #include "vtkArrayCoordinates.h"
00075 #include "vtkArraySort.h"
00076 #include "vtkObjectFactory.h"
00077 #include "vtkTypeTemplate.h"
00078 #include "vtkTypedArray.h"
00079 
00080 template<typename T>
00081 class vtkSparseArray :
00082   public vtkTypeTemplate<vtkSparseArray<T>, vtkTypedArray<T> >
00083 {
00084 public:
00085   static vtkSparseArray<T>* New();
00086   void PrintSelf(ostream &os, vtkIndent indent);
00087 
00088   // vtkArray API 
00089   bool IsDense();
00090   const vtkArrayExtents& GetExtents();
00091   vtkIdType GetNonNullSize();
00092   void GetCoordinatesN(const vtkIdType n, vtkArrayCoordinates& coordinates);
00093   vtkArray* DeepCopy();
00094     
00095   // vtkTypedArray API
00096   const T& GetValue(vtkIdType i);
00097   const T& GetValue(vtkIdType i, vtkIdType j);
00098   const T& GetValue(vtkIdType i, vtkIdType j, vtkIdType k);
00099   const T& GetValue(const vtkArrayCoordinates& coordinates);
00100   const T& GetValueN(const vtkIdType n);
00101   void SetValue(vtkIdType i, const T& value);
00102   void SetValue(vtkIdType i, vtkIdType j, const T& value);
00103   void SetValue(vtkIdType i, vtkIdType j, vtkIdType k, const T& value);
00104   void SetValue(const vtkArrayCoordinates& coordinates, const T& value);
00105   void SetValueN(const vtkIdType n, const T& value);
00106 
00107   // vtkSparseArray API
00108 
00111   void SetNullValue(const T& value);
00112 
00115   const T& GetNullValue();
00116 
00120   void Clear();
00121 
00127   void Sort(const vtkArraySort& sort);
00128 
00130   vtkstd::vector<vtkIdType> GetUniqueCoordinates(vtkIdType dimension); 
00131 
00136   const vtkIdType* GetCoordinateStorage(vtkIdType dimension) const;
00137  
00143   vtkIdType* GetCoordinateStorage(vtkIdType dimension);
00144   
00149   const T* GetValueStorage() const;
00150   
00155   T* GetValueStorage();
00156   
00165   void ReserveStorage(const vtkIdType value_count);
00166 
00168 
00171   void SetExtentsFromContents();
00172   // Description:
00173   // Specify arbitrary array extents, without altering the contents of the array.  Note
00174   // that the extents must be as-large-or-larger-than the extents of the actual values
00175   // stored in the array.  The number of dimensions in the supplied extents must match the
00176   // number of dimensions currently stored in the array.
00177   void SetExtents(const vtkArrayExtents& extents);
00179   
00181 
00185   inline void AddValue(vtkIdType i, const T& value);
00186   inline void AddValue(vtkIdType i, vtkIdType j, const T& value);
00187   inline void AddValue(vtkIdType i, vtkIdType j, vtkIdType k, const T& value);
00188   void AddValue(const vtkArrayCoordinates& coordinates, const T& value);
00190 
00197   bool Validate();
00198 
00199 protected:
00200   vtkSparseArray();
00201   ~vtkSparseArray();
00202 
00203 private:
00204   vtkSparseArray(const vtkSparseArray&); // Not implemented
00205   void operator=(const vtkSparseArray&); // Not implemented
00206 
00207   void InternalResize(const vtkArrayExtents& extents);
00208   void InternalSetDimensionLabel(vtkIdType i, const vtkStdString& label);
00209   vtkStdString InternalGetDimensionLabel(vtkIdType i);
00210 
00211   typedef vtkSparseArray<T> ThisT;
00212 
00214   vtkArrayExtents Extents;
00215   
00217   vtkstd::vector<vtkStdString> DimensionLabels;
00218 
00222   vtkstd::vector<vtkstd::vector<vtkIdType> > Coordinates;
00223   
00225   vtkstd::vector<T> Values;
00226 
00229   T NullValue;
00230 };
00231 
00232 #include "vtkSparseArray.txx"
00233 
00234 #endif
00235