VTK
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
vtkSparseArray< T > Class Template Reference

Sparse, independent coordinate storage for N-way arrays. More...

#include <vtkSparseArray.h>

Inheritance diagram for vtkSparseArray< T >:
[legend]
Collaboration diagram for vtkSparseArray< T >:
[legend]

Public Types

typedef vtkArray::CoordinateT CoordinateT
 
typedef vtkArray::DimensionT DimensionT
 
typedef vtkArray::SizeT SizeT
 
- Public Types inherited from vtkTypeTemplate< vtkSparseArray< T >, vtkTypedArray< T > >
typedef vtkTypedArray< T > Superclass
 
- Public Types inherited from vtkTypedArray< T >
typedef vtkArray::CoordinateT CoordinateT
 
typedef vtkArray::SizeT SizeT
 
- Public Types inherited from vtkTypeTemplate< vtkTypedArray< T >, vtkArray >
typedef vtkArray Superclass
 
- Public Types inherited from vtkArray
enum  { DENSE = 0, SPARSE = 1 }
 
typedef vtkObject Superclass
 
typedef vtkArrayExtents::CoordinateT CoordinateT
 
typedef vtkArrayExtents::DimensionT DimensionT
 
typedef vtkArrayExtents::SizeT SizeT
 
- Public Types inherited from vtkObject
typedef vtkObjectBase Superclass
 

Public Member Functions

void PrintSelf (ostream &os, vtkIndent indent)
 
bool IsDense ()
 
const vtkArrayExtentsGetExtents ()
 
SizeT GetNonNullSize ()
 
void GetCoordinatesN (const SizeT n, vtkArrayCoordinates &coordinates)
 
vtkArrayDeepCopy ()
 
const T & GetValue (CoordinateT i)
 
const T & GetValue (CoordinateT i, CoordinateT j)
 
const T & GetValue (CoordinateT i, CoordinateT j, CoordinateT k)
 
const T & GetValue (const vtkArrayCoordinates &coordinates)
 
const T & GetValueN (const SizeT n)
 
void SetValue (CoordinateT i, const T &value)
 
void SetValue (CoordinateT i, CoordinateT j, const T &value)
 
void SetValue (CoordinateT i, CoordinateT j, CoordinateT k, const T &value)
 
void SetValue (const vtkArrayCoordinates &coordinates, const T &value)
 
void SetValueN (const SizeT n, const T &value)
 
void SetNullValue (const T &value)
 
const T & GetNullValue ()
 
void Clear ()
 
void Sort (const vtkArraySort &sort)
 
std::vector< CoordinateTGetUniqueCoordinates (DimensionT dimension)
 
const CoordinateTGetCoordinateStorage (DimensionT dimension) const
 
CoordinateTGetCoordinateStorage (DimensionT dimension)
 
const T * GetValueStorage () const
 
T * GetValueStorage ()
 
void ReserveStorage (const SizeT value_count)
 
void SetExtentsFromContents ()
 
void SetExtents (const vtkArrayExtents &extents)
 
bool Validate ()
 
void AddValue (CoordinateT i, const T &value)
 
void AddValue (CoordinateT i, CoordinateT j, const T &value)
 
void AddValue (CoordinateT i, CoordinateT j, CoordinateT k, const T &value)
 
void AddValue (const vtkArrayCoordinates &coordinates, const T &value)
 
- Public Member Functions inherited from vtkTypeTemplate< vtkSparseArray< T >, vtkTypedArray< T > >
vtkSparseArray< T > * NewInstance () const
 
- Public Member Functions inherited from vtkTypedArray< T >
void PrintSelf (ostream &os, vtkIndent indent)
 
virtual vtkVariant GetVariantValue (const vtkArrayCoordinates &coordinates)
 
virtual vtkVariant GetVariantValueN (const SizeT n)
 
virtual void SetVariantValue (const vtkArrayCoordinates &coordinates, const vtkVariant &value)
 
virtual void SetVariantValueN (const SizeT n, const vtkVariant &value)
 
virtual void CopyValue (vtkArray *source, const vtkArrayCoordinates &source_coordinates, const vtkArrayCoordinates &target_coordinates)
 
virtual void CopyValue (vtkArray *source, const SizeT source_index, const vtkArrayCoordinates &target_coordinates)
 
virtual void CopyValue (vtkArray *source, const vtkArrayCoordinates &source_coordinates, const SizeT target_index)
 
- Public Member Functions inherited from vtkTypeTemplate< vtkTypedArray< T >, vtkArray >
vtkTypedArray< T > * NewInstance () const
 
- Public Member Functions inherited from vtkArray
vtkArrayNewInstance () const
 
const vtkArrayRange GetExtent (DimensionT dimension)
 
DimensionT GetDimensions ()
 
SizeT GetSize ()
 
void SetName (const vtkStdString &name)
 
vtkStdString GetName ()
 
void SetDimensionLabel (DimensionT i, const vtkStdString &label)
 
vtkStdString GetDimensionLabel (DimensionT i)
 
void Resize (const CoordinateT i)
 
void Resize (const CoordinateT i, const CoordinateT j)
 
void Resize (const CoordinateT i, const CoordinateT j, const CoordinateT k)
 
void Resize (const vtkArrayRange &i)
 
void Resize (const vtkArrayRange &i, const vtkArrayRange &j)
 
void Resize (const vtkArrayRange &i, const vtkArrayRange &j, const vtkArrayRange &k)
 
void Resize (const vtkArrayExtents &extents)
 
vtkVariant GetVariantValue (CoordinateT i)
 
vtkVariant GetVariantValue (CoordinateT i, CoordinateT j)
 
vtkVariant GetVariantValue (CoordinateT i, CoordinateT j, CoordinateT k)
 
void SetVariantValue (CoordinateT i, const vtkVariant &value)
 
void SetVariantValue (CoordinateT i, CoordinateT j, const vtkVariant &value)
 
void SetVariantValue (CoordinateT i, CoordinateT j, CoordinateT k, const vtkVariant &value)
 
- Public Member Functions inherited from vtkObject
vtkObjectNewInstance () const
 
virtual void DebugOn ()
 
virtual void DebugOff ()
 
bool GetDebug ()
 
void SetDebug (bool debugFlag)
 
virtual void Modified ()
 
virtual unsigned long GetMTime ()
 
unsigned long AddObserver (unsigned long event, vtkCommand *, float priority=0.0f)
 
unsigned long AddObserver (const char *event, vtkCommand *, float priority=0.0f)
 
vtkCommandGetCommand (unsigned long tag)
 
void RemoveObserver (vtkCommand *)
 
void RemoveObservers (unsigned long event, vtkCommand *)
 
void RemoveObservers (const char *event, vtkCommand *)
 
int HasObserver (unsigned long event, vtkCommand *)
 
int HasObserver (const char *event, vtkCommand *)
 
void RemoveObserver (unsigned long tag)
 
void RemoveObservers (unsigned long event)
 
void RemoveObservers (const char *event)
 
void RemoveAllObservers ()
 
int HasObserver (unsigned long event)
 
int HasObserver (const char *event)
 
template<class U , class T >
unsigned long AddObserver (unsigned long event, U observer, void(T::*callback)(), float priority=0.0f)
 
template<class U , class T >
unsigned long AddObserver (unsigned long event, U observer, void(T::*callback)(vtkObject *, unsigned long, void *), float priority=0.0f)
 
template<class U , class T >
unsigned long AddObserver (unsigned long event, U observer, bool(T::*callback)(vtkObject *, unsigned long, void *), float priority=0.0f)
 
int InvokeEvent (unsigned long event, void *callData)
 
int InvokeEvent (const char *event, void *callData)
 
int InvokeEvent (unsigned long event)
 
int InvokeEvent (const char *event)
 
- Public Member Functions inherited from vtkObjectBase
const char * GetClassName () const
 
virtual void Delete ()
 
virtual void FastDelete ()
 
void Print (ostream &os)
 
virtual void Register (vtkObjectBase *o)
 
virtual void UnRegister (vtkObjectBase *o)
 
void SetReferenceCount (int)
 
void PrintRevisions (ostream &)
 
virtual void PrintHeader (ostream &os, vtkIndent indent)
 
virtual void PrintTrailer (ostream &os, vtkIndent indent)
 
int GetReferenceCount ()
 

Static Public Member Functions

static vtkSparseArray< T > * New ()
 
- Static Public Member Functions inherited from vtkTypeTemplate< vtkSparseArray< T >, vtkTypedArray< T > >
static vtkSparseArray< T > * SafeDownCast (vtkObjectBase *o)
 
- Static Public Member Functions inherited from vtkTypeTemplate< vtkTypedArray< T >, vtkArray >
static vtkTypedArray< T > * SafeDownCast (vtkObjectBase *o)
 
- Static Public Member Functions inherited from vtkArray
static int IsTypeOf (const char *type)
 
static vtkArraySafeDownCast (vtkObjectBase *o)
 
static vtkArrayCreateArray (int StorageType, int ValueType)
 
- Static Public Member Functions inherited from vtkObject
static int IsTypeOf (const char *type)
 
static vtkObjectSafeDownCast (vtkObjectBase *o)
 
static vtkObjectNew ()
 
static void BreakOnError ()
 
static void SetGlobalWarningDisplay (int val)
 
static void GlobalWarningDisplayOn ()
 
static void GlobalWarningDisplayOff ()
 
static int GetGlobalWarningDisplay ()
 
- Static Public Member Functions inherited from vtkObjectBase
static int IsTypeOf (const char *name)
 
static vtkObjectBaseNew ()
 

Protected Member Functions

 vtkSparseArray ()
 
 ~vtkSparseArray ()
 
- Protected Member Functions inherited from vtkTypeTemplate< vtkSparseArray< T >, vtkTypedArray< T > >
virtual vtkObjectBaseNewInstanceInternal () const
 
virtual int IsA (const char *type)
 
 vtkTypeTemplate ()
 
- Protected Member Functions inherited from vtkTypedArray< T >
 vtkTypedArray ()
 
 ~vtkTypedArray ()
 
- Protected Member Functions inherited from vtkTypeTemplate< vtkTypedArray< T >, vtkArray >
 vtkTypeTemplate ()
 
- Protected Member Functions inherited from vtkArray
 vtkArray ()
 
 ~vtkArray ()
 
- Protected Member Functions inherited from vtkObject
 vtkObject ()
 
virtual ~vtkObject ()
 
virtual void RegisterInternal (vtkObjectBase *, int check)
 
virtual void UnRegisterInternal (vtkObjectBase *, int check)
 
void InternalGrabFocus (vtkCommand *mouseEvents, vtkCommand *keypressEvents=NULL)
 
void InternalReleaseFocus ()
 
- Protected Member Functions inherited from vtkObjectBase
 vtkObjectBase ()
 
virtual ~vtkObjectBase ()
 
virtual void CollectRevisions (ostream &)
 
virtual void ReportReferences (vtkGarbageCollector *)
 
 vtkObjectBase (const vtkObjectBase &)
 
void operator= (const vtkObjectBase &)
 

Additional Inherited Members

- Static Protected Member Functions inherited from vtkTypeTemplate< vtkSparseArray< T >, vtkTypedArray< T > >
static int IsTypeOf (const char *type)
 
- Static Protected Member Functions inherited from vtkTypeTemplate< vtkTypedArray< T >, vtkArray >
static int IsTypeOf (const char *type)
 
- Protected Attributes inherited from vtkObject
bool Debug
 
vtkTimeStamp MTime
 
vtkSubjectHelper * SubjectHelper
 
- Protected Attributes inherited from vtkObjectBase
vtkAtomicInt32 ReferenceCount
 
vtkWeakPointerBase ** WeakPointers
 

Detailed Description

template<typename T>
class vtkSparseArray< T >

Sparse, independent coordinate storage for N-way arrays.

vtkSparseArray is a concrete vtkArray implementation that stores values using sparse independent coordinate storage. This means that the array stores the complete set of coordinates and the value for each non-null value in the array. While this approach requires slightly more storage than other sparse storage schemes (such as Compressed-Row or Compressed-Column), it is easier and more efficient to work with when implementing algorithms, and it generalizes well for arbitrary numbers of dimensions.

In addition to the value retrieval and update methods provided by vtkTypedArray, vtkSparseArray provides methods to:

Get and set a special 'null' value that will be returned when retrieving values for undefined coordinates.

Clear the contents of the array so that every set of coordinates is undefined.

Sort the array contents so that value coordinates can be visited in a specific order.

Retrieve pointers to the value- and coordinate-storage memory blocks.

Reserve storage for a specific number of non-null values, for efficiency when the number of non-null values is known in advance.

Recompute the array extents so that they bound the largest set of non-NULL values along each dimension.

Specify arbitrary array extents.

Add values to the array in amortized-constant time.

Validate that the array does not contain duplicate coordinates.

See also
vtkArray, vtkTypedArray, vtkDenseArray
Thanks:
Developed by Timothy M. Shead (tshea.nosp@m.d@sa.nosp@m.ndia..nosp@m.gov) at Sandia National Laboratories.
Examples:
vtkSparseArray (Examples)
Tests:
vtkSparseArray (Tests)

Definition at line 81 of file vtkSparseArray.h.

Member Typedef Documentation

template<typename T>
typedef vtkArray::CoordinateT vtkSparseArray< T >::CoordinateT

Definition at line 88 of file vtkSparseArray.h.

template<typename T>
typedef vtkArray::DimensionT vtkSparseArray< T >::DimensionT

Definition at line 89 of file vtkSparseArray.h.

template<typename T>
typedef vtkArray::SizeT vtkSparseArray< T >::SizeT

Definition at line 90 of file vtkSparseArray.h.

Constructor & Destructor Documentation

template<typename T>
vtkSparseArray< T >::vtkSparseArray ( )
protected
template<typename T>
vtkSparseArray< T >::~vtkSparseArray ( )
protected

Member Function Documentation

template<typename T>
static vtkSparseArray<T>* vtkSparseArray< T >::New ( )
static
template<typename T>
void vtkSparseArray< T >::PrintSelf ( ostream &  os,
vtkIndent  indent 
)
virtual

Methods invoked by print to print information about the object including superclasses. Typically not called by the user (use Print() instead) but used in the hierarchical print process to combine the output of several classes.

Reimplemented from vtkArray.

template<typename T>
bool vtkSparseArray< T >::IsDense ( )
virtual

Returns true iff the underlying array storage is "dense", i.e. that GetSize() and GetNonNullSize() will always return the same value. If not, the array is "sparse".

Implements vtkArray.

template<typename T>
const vtkArrayExtents& vtkSparseArray< T >::GetExtents ( )
virtual

Returns the extents (the number of dimensions and size along each dimension) of the array.

Implements vtkArray.

template<typename T>
SizeT vtkSparseArray< T >::GetNonNullSize ( )
virtual

Returns the number of non-null values stored in the array. Note that this value will equal GetSize() for dense arrays, and will be less-than-or-equal to GetSize() for sparse arrays.

Implements vtkArray.

template<typename T>
void vtkSparseArray< T >::GetCoordinatesN ( const SizeT  n,
vtkArrayCoordinates coordinates 
)
virtual

Returns the coordinates of the n-th value in the array, where n is in the range [0, GetNonNullSize()). Note that the order in which coordinates are visited is undefined, but is guaranteed to match the order in which values are visited using vtkTypedArray::GetValueN() and vtkTypedArray::SetValueN().

Implements vtkArray.

template<typename T>
vtkArray* vtkSparseArray< T >::DeepCopy ( )
virtual

Returns a new array that is a deep copy of this array.

Implements vtkArray.

template<typename T>
const T& vtkSparseArray< T >::GetValue ( CoordinateT  i)
virtual

Returns the value stored in the array at the given coordinates. Note that the number of dimensions in the supplied coordinates must match the number of dimensions in the array.

Implements vtkTypedArray< T >.

template<typename T>
const T& vtkSparseArray< T >::GetValue ( CoordinateT  i,
CoordinateT  j 
)
virtual

Returns the value stored in the array at the given coordinates. Note that the number of dimensions in the supplied coordinates must match the number of dimensions in the array.

Implements vtkTypedArray< T >.

template<typename T>
const T& vtkSparseArray< T >::GetValue ( CoordinateT  i,
CoordinateT  j,
CoordinateT  k 
)
virtual

Returns the value stored in the array at the given coordinates. Note that the number of dimensions in the supplied coordinates must match the number of dimensions in the array.

Implements vtkTypedArray< T >.

template<typename T>
const T& vtkSparseArray< T >::GetValue ( const vtkArrayCoordinates coordinates)
virtual

Returns the value stored in the array at the given coordinates. Note that the number of dimensions in the supplied coordinates must match the number of dimensions in the array.

Implements vtkTypedArray< T >.

template<typename T>
const T& vtkSparseArray< T >::GetValueN ( const SizeT  n)
virtual

Returns the n-th value stored in the array, where n is in the range [0, GetNonNullSize()). This is useful for efficiently visiting every value in the array. Note that the order in which values are visited is undefined, but is guaranteed to match the order used by vtkArray::GetCoordinatesN().

Implements vtkTypedArray< T >.

template<typename T>
void vtkSparseArray< T >::SetValue ( CoordinateT  i,
const T &  value 
)
virtual

Overwrites the value stored in the array at the given coordinates. Note that the number of dimensions in the supplied coordinates must match the number of dimensions in the array.

Implements vtkTypedArray< T >.

template<typename T>
void vtkSparseArray< T >::SetValue ( CoordinateT  i,
CoordinateT  j,
const T &  value 
)
virtual

Overwrites the value stored in the array at the given coordinates. Note that the number of dimensions in the supplied coordinates must match the number of dimensions in the array.

Implements vtkTypedArray< T >.

template<typename T>
void vtkSparseArray< T >::SetValue ( CoordinateT  i,
CoordinateT  j,
CoordinateT  k,
const T &  value 
)
virtual

Overwrites the value stored in the array at the given coordinates. Note that the number of dimensions in the supplied coordinates must match the number of dimensions in the array.

Implements vtkTypedArray< T >.

template<typename T>
void vtkSparseArray< T >::SetValue ( const vtkArrayCoordinates coordinates,
const T &  value 
)
virtual

Overwrites the value stored in the array at the given coordinates. Note that the number of dimensions in the supplied coordinates must match the number of dimensions in the array.

Implements vtkTypedArray< T >.

template<typename T>
void vtkSparseArray< T >::SetValueN ( const SizeT  n,
const T &  value 
)
virtual

Overwrites the n-th value stored in the array, where n is in the range [0, GetNonNullSize()). This is useful for efficiently visiting every value in the array. Note that the order in which values are visited is undefined, but is guaranteed to match the order used by vtkArray::GetCoordinatesN().

Implements vtkTypedArray< T >.

template<typename T>
void vtkSparseArray< T >::SetNullValue ( const T &  value)

Set the value that will be returned by GetValue() for NULL areas of the array.

template<typename T>
const T& vtkSparseArray< T >::GetNullValue ( )

Returns the value that will be returned by GetValue() for NULL areas of the array.

template<typename T>
void vtkSparseArray< T >::Clear ( )

Remove all non-null elements from the array, leaving the number of dimensions, the extent of each dimension, and the label for each dimension unchanged.

template<typename T>
void vtkSparseArray< T >::Sort ( const vtkArraySort sort)

Sorts array values so that their coordinates appear in some well-defined order. The supplied vtkArraySort object controls which dimensions are sorted, and in what order, and should contain one-or-more sort dimensions, up to the number of dimensions stored in the array.

template<typename T>
std::vector<CoordinateT> vtkSparseArray< T >::GetUniqueCoordinates ( DimensionT  dimension)

Returns the set of unique coordinates along the given dimension.

template<typename T>
const CoordinateT* vtkSparseArray< T >::GetCoordinateStorage ( DimensionT  dimension) const

Return a read-only reference to the underlying coordinate storage. Coordinates for each dimension are stored contiguously as a one-dimensional array. The ordering of coordinates within the array depends on the order in which values were added to the array.

template<typename T>
CoordinateT* vtkSparseArray< T >::GetCoordinateStorage ( DimensionT  dimension)

Return a mutable reference to the underlying coordinate storage. Coordinates for each dimension are stored contiguously as a one-dimensional array. The ordering of coordinates within the array depends on the order in which values were added to the array, and any subsequent sorting. Use at your own risk!

template<typename T>
const T* vtkSparseArray< T >::GetValueStorage ( ) const

Return a read-only reference to the underlying value storage. Values are stored contiguously, but in arbitrary order. Use GetCoordinateStorage() if you need to get the corresponding coordinates for a value.

template<typename T>
T* vtkSparseArray< T >::GetValueStorage ( )

Return a mutable reference to the underlying value storage. Values are stored contiguously, but in arbitrary order. Use GetCoordinateStorage() if you need to get the corresponding coordinates for a value. Use at your own risk!

template<typename T>
void vtkSparseArray< T >::ReserveStorage ( const SizeT  value_count)

Reserve storage for a specific number of values. This is useful for reading external data using GetCoordinateStorage() and GetValueStorage(), when the total number of non-NULL values in the array can be determined in advance. Note that after calling ReserveStorage(), all coordinates and values will be undefined, so you must ensure that every set of coordinates and values is overwritten. It is the caller's responsibility to ensure that duplicate coordinates are not inserted into the array.

template<typename T>
void vtkSparseArray< T >::SetExtentsFromContents ( )

Update the array extents to match its contents, so that the extent along each dimension matches the maximum index value along that dimension.

template<typename T>
void vtkSparseArray< T >::SetExtents ( const vtkArrayExtents extents)

Specify arbitrary array extents, without altering the contents of the array. Note that the extents must be as-large-or-larger-than the extents of the actual values stored in the array. The number of dimensions in the supplied extents must match the number of dimensions currently stored in the array.

template<typename T>
void vtkSparseArray< T >::AddValue ( CoordinateT  i,
const T &  value 
)
inline

Adds a new non-null element to the array. Does not test to see if an element with matching coordinates already exists. Useful for providing fast initialization of the array as long as the caller is prepared to guarantee that no duplicate coordinates are ever used.

template<typename T>
void vtkSparseArray< T >::AddValue ( CoordinateT  i,
CoordinateT  j,
const T &  value 
)
inline

Adds a new non-null element to the array. Does not test to see if an element with matching coordinates already exists. Useful for providing fast initialization of the array as long as the caller is prepared to guarantee that no duplicate coordinates are ever used.

template<typename T>
void vtkSparseArray< T >::AddValue ( CoordinateT  i,
CoordinateT  j,
CoordinateT  k,
const T &  value 
)
inline

Adds a new non-null element to the array. Does not test to see if an element with matching coordinates already exists. Useful for providing fast initialization of the array as long as the caller is prepared to guarantee that no duplicate coordinates are ever used.

template<typename T>
void vtkSparseArray< T >::AddValue ( const vtkArrayCoordinates coordinates,
const T &  value 
)

Adds a new non-null element to the array. Does not test to see if an element with matching coordinates already exists. Useful for providing fast initialization of the array as long as the caller is prepared to guarantee that no duplicate coordinates are ever used.

template<typename T>
bool vtkSparseArray< T >::Validate ( )

Validate the contents of the array, returning false if there are any problems. Potential problems include duplicate coordinates, which can be introduced into the array either through AddValue() or direct access to coordinates storage; and coordinates out-of-bounds given the current array extents. Note that Validate() is a heavyweight O(N log N) operation that is intended for temporary use during debugging.


The documentation for this class was generated from the following file: