mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Map fields of any type in MIRFilter
Use the ability to extract array components to handle any array in the map field.
This commit is contained in:
parent
9978397fc8
commit
29ecbbb005
@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user