Add ArrayHandleDecorator
While working on #408 (closed), there are instances where it would be useful to have an array handle that can regenerate the (now removed) NumIndices
array from the Offsets
array, which is the "extended" scan of NumIndices
:
NumIndices: 3 2 5 1 3
Offsets: 0 3 5 10 11 14
This would be similar to ArrayHandleImplicit
, but it requires doing a lookup in another portal:
template <typename PortalT>
struct OffsetsToNumIndicesFunctor
{
using ValueType = typename PortalT::ValueType;
PortalT Portal;
ValueType operator()(vtkm::Id index)
{
return this->Portal(index + i) - this->Portal(index);
}
};
auto offsets = /* New style cell set explicit offsets */
auto numIndicesArray = vtkm::cont::make_ArrayHandleForward<OffsetsToNumIndicesFunctor>(offsets);
The ArrayHandleForward
would be templated on <Functor, InverseFunctor, ArrayHandle>
, and will construct the functors from the array handle's portals as needed, which will be used by an ArrayPortalForward
to defer reads/writes to the functors' logic.
Eventually this could be extended to take multiple input arrays, allowing more complex logic involving multiple lookups, but for now a single handle will be enough.
Edited by Allison Vacanti