vtk-m/vtkm/filter/Probe.hxx
Kenneth Moreland 7be44c847f Enable setting invalid value in probe filter
Initially, the probe filter would simply not set a value if a sample was
outside the input `DataSet`. This is not great as the memory could be
left uninitalized and lead to unpredictable results. The testing
compared these invalid results to 0, which seemed to work but is
probably unstable.

This was partially fixed by a previous change that consolidated to
mapping of cell data with a general routine that permuted data. However,
the fix did not extend to point data in the input, and it was not
possible to specify a particular invalid value.

This change specifically updates the probe filter so that invalid values
are set to a user-specified value.
2020-06-03 15:29:37 -06:00

103 lines
3.4 KiB
C++

//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_filter_Probe_hxx
#define vtk_m_filter_Probe_hxx
#include <vtkm/filter/Probe.h>
#include <vtkm/filter/MapFieldPermutation.h>
#include <vtkm/cont/internal/CastInvalidValue.h>
namespace vtkm
{
namespace filter
{
VTKM_CONT
inline void Probe::SetGeometry(const vtkm::cont::DataSet& geometry)
{
this->Geometry = vtkm::cont::DataSet();
this->Geometry.SetCellSet(geometry.GetCellSet());
this->Geometry.AddCoordinateSystem(geometry.GetCoordinateSystem());
}
VTKM_CONT
inline const vtkm::cont::DataSet& Probe::GetGeometry() const
{
return this->Geometry;
}
template <typename DerivedPolicy>
VTKM_CONT inline vtkm::cont::DataSet Probe::DoExecute(
const vtkm::cont::DataSet& input,
vtkm::filter::PolicyBase<DerivedPolicy> policy)
{
this->Worklet.Run(vtkm::filter::ApplyPolicyCellSet(input.GetCellSet(), policy, *this),
input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()),
this->Geometry.GetCoordinateSystem().GetData());
auto output = this->Geometry;
auto hpf = this->Worklet.GetHiddenPointsField();
auto hcf = this->Worklet.GetHiddenCellsField(
vtkm::filter::ApplyPolicyCellSet(output.GetCellSet(), policy, *this));
output.AddField(vtkm::cont::make_FieldPoint("HIDDEN", hpf));
output.AddField(vtkm::cont::make_FieldCell("HIDDEN", hcf));
return output;
}
template <typename DerivedPolicy>
VTKM_CONT inline bool Probe::MapFieldOntoOutput(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field,
vtkm::filter::PolicyBase<DerivedPolicy> policy)
{
if (field.IsFieldPoint())
{
// If the field is a point field, then we need to do a custom interpolation of the points.
// In this case, we need to call the superclass's MapFieldOntoOutput, which will in turn
// call our DoMapField.
return this->FilterDataSet<Probe>::MapFieldOntoOutput(result, field, policy);
}
else if (field.IsFieldCell())
{
return vtkm::filter::MapFieldPermutation(
field, this->Worklet.GetCellIds(), result, this->InvalidValue);
}
else if (field.IsFieldGlobal())
{
result.AddField(field);
return true;
}
else
{
return false;
}
}
template <typename T, typename StorageType, typename DerivedPolicy>
VTKM_CONT inline bool Probe::DoMapField(vtkm::cont::DataSet& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy>)
{
VTKM_ASSERT(fieldMeta.IsPointField());
auto fieldArray =
this->Worklet.ProcessPointField(input,
vtkm::cont::internal::CastInvalidValue<T>(this->InvalidValue),
typename DerivedPolicy::AllCellSetList());
result.AddField(fieldMeta.AsField(fieldArray));
return true;
}
}
} // vtkm::filter
#endif