VTK
Public Types | Public Member Functions | Public Attributes | List of all members
vtkDataArrayAccessor< ArrayT > Class Template Reference

Efficient templated access to vtkDataArray. More...

#include <vtkDataArrayAccessor.h>

Public Types

typedef ArrayT ArrayType
 
typedef ArrayType::ValueType APIType
 

Public Member Functions

 vtkDataArrayAccessor (ArrayType *array)
 
APIType Get (vtkIdType tupleIdx, int compIdx) const
 
void Set (vtkIdType tupleIdx, int compIdx, APIType val) const
 
void Insert (vtkIdType tupleIdx, int compIdx, APIType val) const
 
void Get (vtkIdType tupleIdx, APIType *tuple) const
 
void Set (vtkIdType tupleIdx, const APIType *tuple) const
 
void Insert (vtkIdType tupleIdx, const APIType *tuple) const
 

Public Attributes

ArrayTypeArray
 

Detailed Description

template<typename ArrayT>
class vtkDataArrayAccessor< ArrayT >

Efficient templated access to vtkDataArray.

vtkDataArrayAccessor provides access to data stored in a vtkDataArray. It is intended to be used in conjunction with vtkArrayDispatcher.

A more detailed description of this class and related tools can be found here.

The goal of this helper template is to allow developers to write a single templated worker function that will generates code to use the efficient typed APIs provided by vtkGenericDataArray when the array type is known, but fallback to the slower vtkDataArray virtual double API if needed.

This can be used to reduce template-explosion issues by restricting the vtkArrayDispatch call to only dispatch a few common cases/array types, and route all other arrays through a slower implementation using vtkDataArray's API. With vtkDataArrayAccessor, a single templated worker function can be used to generate both.

Note that while this interface provides both component-wise and tuple access, the tuple methods are discouraged as they are significantly slower as they copy data into a temporary array, and prevent many advanced compiler optimizations that are possible when using the component accessors. In other words, prefer the methods that operate on a single component instead of an entire tuple when performance matters.

A standard usage pattern of this class would be:

// vtkArrayDispatch worker struct:
struct Worker
{
// Templated worker function:
template <typename ArrayT>
void operator()(ArrayT *array)
{
// The accessor:
// The data type used by ArrayT's API, use this for
// temporary/intermediate results:
// Do work using accessor to set/get values....
}
};
// Usage:
Worker worker;
vtkDataArray *array = ...;
if (!vtkArrayDispatch::Dispatch::Execute(array, worker))
{
// Dispatch failed: unknown array type. Fallback to vtkDataArray API:
worker(array);
}

We define Worker::operator() as the templated worker function, restricting all data accesses to go through the 'accessor' object (methods like GetNumberOfTuples, GetNumberOfComponents, etc should be called on the array itself).

This worker is passed into an array dispatcher, which tests 'array' to see if it can figure out the array subclass. If it does, Worker is instantiated with ArrayT set to the array's subclass, resulting in efficient code. If Dispatch::Execute returns false (meaning the array type is not recognized), the worker is executed using the vtkDataArray pointer. While slower, this ensures that less-common cases will still be handled – all from one worker function template.

.SEE ALSO vtkArrayDispatch

Definition at line 101 of file vtkDataArrayAccessor.h.

Member Typedef Documentation

template<typename ArrayT>
typedef ArrayT vtkDataArrayAccessor< ArrayT >::ArrayType

Definition at line 103 of file vtkDataArrayAccessor.h.

template<typename ArrayT>
typedef ArrayType::ValueType vtkDataArrayAccessor< ArrayT >::APIType

Definition at line 104 of file vtkDataArrayAccessor.h.

Constructor & Destructor Documentation

template<typename ArrayT>
vtkDataArrayAccessor< ArrayT >::vtkDataArrayAccessor ( ArrayType array)
inline

Definition at line 108 of file vtkDataArrayAccessor.h.

Member Function Documentation

template<typename ArrayT>
APIType vtkDataArrayAccessor< ArrayT >::Get ( vtkIdType  tupleIdx,
int  compIdx 
) const
inline

Definition at line 110 of file vtkDataArrayAccessor.h.

template<typename ArrayT>
void vtkDataArrayAccessor< ArrayT >::Set ( vtkIdType  tupleIdx,
int  compIdx,
APIType  val 
) const
inline

Definition at line 115 of file vtkDataArrayAccessor.h.

template<typename ArrayT>
void vtkDataArrayAccessor< ArrayT >::Insert ( vtkIdType  tupleIdx,
int  compIdx,
APIType  val 
) const
inline

Definition at line 120 of file vtkDataArrayAccessor.h.

template<typename ArrayT>
void vtkDataArrayAccessor< ArrayT >::Get ( vtkIdType  tupleIdx,
APIType tuple 
) const
inline

Definition at line 125 of file vtkDataArrayAccessor.h.

template<typename ArrayT>
void vtkDataArrayAccessor< ArrayT >::Set ( vtkIdType  tupleIdx,
const APIType tuple 
) const
inline

Definition at line 130 of file vtkDataArrayAccessor.h.

template<typename ArrayT>
void vtkDataArrayAccessor< ArrayT >::Insert ( vtkIdType  tupleIdx,
const APIType tuple 
) const
inline

Definition at line 135 of file vtkDataArrayAccessor.h.

Member Data Documentation

template<typename ArrayT>
ArrayType* vtkDataArrayAccessor< ArrayT >::Array

Definition at line 106 of file vtkDataArrayAccessor.h.


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