Change VectorMagnitude to work with any type of field

Previously, `VectorMagnitude` only worked with `Vec`s of size 2, 3, or
4. It now works with `Vec`s of any size. It also avoids a memory copy of
non-float types (although it does add a little arithmetic in the
computation).
This commit is contained in:
Kenneth Moreland 2023-02-03 14:17:48 -05:00
parent f916a5e1f3
commit d5ba7f4d59
2 changed files with 3 additions and 4 deletions

@ -24,3 +24,4 @@ fallback is used.
* `ParticleDensityNearestGridPoint`
* `PointAverage`
* `Probe`
* `VectorMagnitude`

@ -28,7 +28,7 @@ VTKM_CONT vtkm::cont::DataSet VectorMagnitude::DoExecute(const vtkm::cont::DataS
auto resolveType = [&](const auto& concrete) {
// use std::decay to remove const ref from the decltype of concrete.
using T = typename std::decay_t<decltype(concrete)>::ValueType;
using T = typename std::decay_t<decltype(concrete)>::ValueType::ComponentType;
using ReturnType = typename ::vtkm::detail::FloatingPointReturnType<T>::Type;
vtkm::cont::ArrayHandle<ReturnType> result;
@ -36,9 +36,7 @@ VTKM_CONT vtkm::cont::DataSet VectorMagnitude::DoExecute(const vtkm::cont::DataS
outArray = result;
};
const auto& field = this->GetFieldFromDataSet(inDataSet);
field.GetData()
.CastAndCallForTypesWithFloatFallback<vtkm::TypeListVecCommon, VTKM_DEFAULT_STORAGE_LIST>(
resolveType);
field.GetData().CastAndCallWithExtractedArray(resolveType);
return this->CreateResultField(
inDataSet, this->GetOutputFieldName(), field.GetAssociation(), outArray);