VTK
|
A macro for obtaining iterators to vtkDataArray data when the array implementation and type are unknown. More...
#include <vtkDataArrayIteratorMacro.h>
A macro for obtaining iterators to vtkDataArray data when the array implementation and type are unknown.
NOTE: This macro is deprecated and should not be used any longer. Use vtkArrayDispatch and the vtkGenericDataArray API instead of vtkDataArrayIteratorMacro and vtkTypedDataArrayIterator.
See vtkTemplateMacro. This macro is similar, but defines several additional typedefs and variables for safely iterating through data in a vtkAbstractArray container:
For the standard vtkDataArray implementations (which are subclasses of vtkAOSDataArrayTemplate), the iterators will simply be pointers to the raw memory of the array. This allows very fast iteration when possible, and permits compiler optimizations in the standard template library to occur (such as reducing std::copy to memmove).
For arrays that are subclasses of vtkTypedDataArray, a vtkTypedDataArrayIterator is used. Such iterators safely traverse the array using API calls and have pointer-like semantics, but add about a 35% performance overhead compared with iterating over the raw memory (measured by summing a vtkFloatArray containing 10M values on GCC 4.8.1 with -O3 optimization using both iterator types – see TestDataArrayIterators).
For arrays that are not subclasses of vtkTypedDataArray, there is no reliably safe way to iterate over the array elements. In such cases, this macro performs the legacy behavior of casting vtkAbstractArray::GetVoidPointer(...) to vtkDAValueType* to create the iterators.
To use this macro, create a templated worker function:
template <class iterator>=""> void myFunc(Iterator begin, Iterator end, ...) {...}
and then call the vtkDataArrayIteratorMacro inside of a switch statement using the above objects and typedefs as needed:
vtkAbstractArray *someArray = ...; switch (someArray->GetDataType()) { vtkDataArrayIteratorMacro(someArray, myFunc(vtkDABegin, vtkDAEnd, ...)); }