Merge topic 'mir-interp-any-field'

29ecbbb00 Map fields of any type in MIRFilter

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Li-Ta Lo <ollie@lanl.gov>
Merge-request: !2977
This commit is contained in:
Kenneth Moreland 2023-02-03 18:48:14 +00:00 committed by Kitware Robot
commit 5173f65176
3 changed files with 29 additions and 11 deletions

@ -16,3 +16,4 @@ updated.
* `ClipWithField`
* `ClipWithImplicitFunction`
* `Contour`
* `MIRFilter`

@ -55,16 +55,15 @@ VTKM_CONT bool MIRFilter::DoMapField(
if (field.IsPointField())
{
vtkm::cont::UnknownArrayHandle output = field.GetData().NewInstanceBasic();
auto resolve = [&](const auto& concrete) {
using T = typename std::decay_t<decltype(concrete)>::ValueType;
vtkm::cont::ArrayHandle<T> outputArray;
using T = typename std::decay_t<decltype(concrete)>::ValueType::ComponentType;
auto outputArray = output.ExtractArrayFromComponents<T>(vtkm::CopyFlag::Off);
vtkm::worklet::DestructPointWeightList destructWeightList;
this->Invoke(destructWeightList, MIRIDs, MIRWeights, concrete, outputArray);
result.AddPointField(field.GetName(), outputArray);
};
field.GetData()
.CastAndCallForTypesWithFloatFallback<vtkm::TypeListField, VTKM_DEFAULT_STORAGE_LIST>(
resolve);
field.GetData().CastAndCallWithExtractedArray(resolve);
result.AddPointField(field.GetName(), output);
return true;
}
else if (field.IsCellField())

@ -2377,19 +2377,37 @@ struct DestructPointWeightList : public vtkm::worklet::WorkletMapField
using ExecutionSignature = void(_1, _2, _3, _4);
using InputDomain = _1;
template <typename PID, typename PW, typename OV, typename NV>
VTKM_EXEC void operator()(const PID& pids, const PW& pws, const OV& ov, NV& newVals) const
VTKM_EXEC void operator()(const PID& pointIDs,
const PW& pointWeights,
const OV& originalVals,
NV& newVal) const
{
VTKM_ASSERT(pids[0] != -1);
newVals = static_cast<NV>(ov.Get(pids[0]) * pws[0]);
// This code assumes that originalVals and newVals come from ArrayHandleRecombineVec.
// This means that they will have Vec-like values that support Vec operations. It also
// means that operations have to be component-wise.
VTKM_ASSERT(pointIDs[0] != -1);
using WeightType = typename PW::ComponentType;
using ValueType = typename NV::ComponentType;
auto originalVal = originalVals.Get(pointIDs[0]);
for (vtkm::IdComponent cIndex = 0; cIndex < newVal.GetNumberOfComponents(); ++cIndex)
{
newVal[cIndex] =
static_cast<ValueType>(static_cast<WeightType>(originalVal[cIndex]) * pointWeights[0]);
}
for (vtkm::IdComponent i = 1; i < 8; i++)
{
if (pids[i] == vtkm::Id(-1))
if (pointIDs[i] == vtkm::Id(-1))
{
break;
}
else
{
newVals += static_cast<NV>(ov.Get(pids[i]) * pws[i]);
originalVal = originalVals.Get(pointIDs[i]);
for (vtkm::IdComponent cIndex = 0; cIndex < newVal.GetNumberOfComponents(); ++cIndex)
{
newVal[cIndex] +=
static_cast<ValueType>(static_cast<WeightType>(originalVal[cIndex]) * pointWeights[i]);
}
}
}
}