Add CastAndCallScalarField and CastAndCallVecField to NewFilterField

These methods somewhat simplify doing the `CastAndCall` from an
`UnknownArrayhandle` that comes from an input field.

The motivation for this change is for the User's guide, where I am
having a chicken-and-egg problem of wanting to describe how to make a
simple filter implementation without having to go into details about
`UnknownArrayHandle`.
This commit is contained in:
Kenneth Moreland 2022-01-24 11:23:41 -07:00
parent c181cc08a9
commit 72065024aa
2 changed files with 50 additions and 3 deletions

@ -142,6 +142,54 @@ protected:
}
}
template <typename Functor, typename... Args>
VTKM_CONT void CastAndCallScalarField(const vtkm::cont::UnknownArrayHandle& fieldArray,
Functor&& functor,
Args&&... args) const
{
fieldArray
.CastAndCallForTypesWithFloatFallback<vtkm::TypeListFieldScalar, VTKM_DEFAULT_STORAGE_LIST>(
std::forward<Functor>(functor), std::forward<Args>(args)...);
}
template <typename Functor, typename... Args>
VTKM_CONT void CastAndCallScalarField(const vtkm::cont::Field& field,
Functor&& functor,
Args&&... args) const
{
this->CastAndCallScalarField(
field.GetData(), std::forward<Functor>(functor), std::forward<Args>(args)...);
}
private:
template <vtkm::IdComponent VecSize>
struct ScalarToVec
{
template <typename T>
using type = vtkm::Vec<T, VecSize>;
};
protected:
template <vtkm::IdComponent VecSize, typename Functor, typename... Args>
VTKM_CONT void CastAndCallVecField(const vtkm::cont::UnknownArrayHandle& fieldArray,
Functor&& functor,
Args&&... args) const
{
using VecList =
vtkm::ListTransform<vtkm::TypeListFieldScalar, ScalarToVec<VecSize>::template type>;
fieldArray.CastAndCallForTypesWithFloatFallback<VecList, VTKM_DEFAULT_STORAGE_LIST>(
std::forward<Functor>(functor), std::forward<Args>(args)...);
}
template <vtkm::IdComponent VecSize, typename Functor, typename... Args>
VTKM_CONT void CastAndCallVecField(const vtkm::cont::Field& field,
Functor&& functor,
Args&&... args) const
{
this->CastAndCallVecField<VecSize>(
field.GetData(), std::forward<Functor>(functor), std::forward<Args>(args)...);
}
private:
void ResizeIfNeeded(size_t index_st);

@ -147,7 +147,7 @@ VTKM_CONT vtkm::cont::DataSet ThresholdPoints::DoExecute(const vtkm::cont::DataS
vtkm::cont::CellSetSingleType<> outCellSet;
vtkm::worklet::ThresholdPoints worklet;
auto ResolveType = [&, this](const auto& concrete) {
auto resolveType = [&, this](const auto& concrete) {
switch (this->ThresholdType)
{
case THRESHOLD_BELOW:
@ -170,8 +170,7 @@ VTKM_CONT vtkm::cont::DataSet ThresholdPoints::DoExecute(const vtkm::cont::DataS
}
};
const auto& fieldArray = field.GetData();
fieldArray.CastAndCallForTypes<vtkm::TypeListScalarAll, VTKM_DEFAULT_STORAGE_LIST>(ResolveType);
this->CastAndCallScalarField(field, resolveType);
// create the output dataset
vtkm::cont::DataSet output;