VTK
9.1.0
|
vtkDataArray code generator/dispatcher. More...
#include <vtkArrayDispatch.h>
Public Types | |
typedef vtkTypeList::Create< double, float > | Reals |
A TypeList containing all real ValueTypes. More... | |
typedef vtkTypeList::Unique< vtkTypeList::Create< char, int, long, longlong, short, signedchar, unsignedchar, unsignedint, unsignedlong, unsignedlonglong, unsignedshort, vtkIdType > >::Result | Integrals |
A Typelist containing all integral ValueTypes. More... | |
typedef vtkTypeList::Append< Reals, Integrals >::Result | AllTypes |
A Typelist containing all standard VTK array ValueTypes. More... | |
vtkDataArray code generator/dispatcher.
vtkArrayDispatch implements a mechanism for generating optimized code for multiple subclasses of vtkDataArray at once. Using a TypeList based approach (see vtkTypeList), a templated worker implementation is generated for a restricted or unrestricted set of vtkDataArray subclasses.
A more detailed description of this class and related tools can be found here.
The primary goals of this class are to simplify multi-array dispatch implementations, and provide tools to lower compilation time and binary size (i.e. avoiding 'template explosions').
vtkArrayDispatch is also intended to replace code that currently relies on the encapsulation-breaking vtkDataArray::GetVoidPointer method. Not all subclasses of vtkDataArray use the memory layout assumed by GetVoidPointer; calling this method on, e.g. a vtkSOADataArrayTemplate will trigger a deep copy of the array data into an AOS buffer. This is very inefficient and should be avoided.
The vtkDataArrayRange.h utilities are worth mentioning here, as they allow vtkArrayDispatch workers to operate on selected concrete subclasses for 'fast paths', yet fallback to using the slower vtkDataArray API for uncommon array types. This helps mitigate the "template explosion" issues that can result from instantiating a large worker functions for many array types.
These dispatchers extend the basic functionality of vtkTemplateMacro with the following features:
The basic Dispatch implementation will generate code paths for all arrays in the application-wide array list, and operates on a single array.
Dispatchers that start with Dispatch2 operate on 2 arrays simultaneously, while those that begin with Dispatch3 operate on 3 arrays.
To reduce compile time and binary size, the following dispatchers can be used to restrict the set of arrays that will be used. There are versions of these that operate on 1, 2, or 3 arrays:
Execution: There are three components to a dispatch: The dispatcher, the worker, and the array(s). They are combined like so:
For convenience, the dispatcher may be aliased to a shorter name, e.g.:
Return value: The Execute method of the dispatcher will return true if a code path matching the array arguments is found, or false if the arrays are not supported. If false is returned, the arrays will not be modified, and the worker will not be executed.
Workers: The dispatch requires a Worker functor that performs the work. For single array, the functor must be callable where the first parameter is an array object. For 2-array dispatch, the first two arguments must be (array1, array2). For 3-array dispatch, the first three arguments must be (array1, array2, array3). Workers are passed by reference, so stateful functors are permitted if additional input/output data is needed and not being passed as additional parameters to the Execute method.
A simple worker implementation for triple dispatch:
Note that optimized implementations (e.g. for AoS arrays vs SoA arrays) can be supported by providing overloads of operator() that have more restrictive template parameters.
A worker's operator() implementation can accept additional parameters that follow the arrays. These parameters are passed to the dispatcher during execution. For instance, this worker scales an array by a runtime-value, writing it into a second array:
Examples: See TestArrayDispatchers.cxx for examples of each dispatch type and ExampleDataArrayRangeDispatch.cxx for more real-world examples.
typedef vtkTypeList::Create<double, float> vtkArrayDispatch::Reals |
A TypeList containing all real ValueTypes.
Definition at line 227 of file vtkArrayDispatch.h.
typedef vtkTypeList::Unique<vtkTypeList::Create<char,int,long,longlong,short,signedchar,unsignedchar,unsignedint,unsignedlong,unsignedlonglong,unsignedshort,vtkIdType>>::Result vtkArrayDispatch::Integrals |
A Typelist containing all integral ValueTypes.
Definition at line 234 of file vtkArrayDispatch.h.
typedef vtkTypeList::Append<Reals,Integrals>::Result vtkArrayDispatch::AllTypes |
A Typelist containing all standard VTK array ValueTypes.
Definition at line 239 of file vtkArrayDispatch.h.