mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-19 18:45:43 +00:00
546dd608e1
By default, the `FilterDataSet` class will iterate over all fields and use `CastAndCall` on each one to call the subclass' mapping function with the appropriate array type. This only works if the array is of a known type. If it is not `CastAndCall` throws an exception. However, having the entire filter exception out just because one field cannot be converted does not make sense. Instead, catch the exception, log a warning, and drop the field.
82 lines
2.7 KiB
C++
82 lines
2.7 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.
|
|
//============================================================================
|
|
|
|
#include <vtkm/filter/FieldMetadata.h>
|
|
#include <vtkm/filter/FilterTraits.h>
|
|
#include <vtkm/filter/PolicyDefault.h>
|
|
|
|
#include <vtkm/cont/ErrorBadType.h>
|
|
#include <vtkm/cont/Logging.h>
|
|
|
|
#include <vtkm/filter/internal/ResolveFieldTypeAndExecute.h>
|
|
#include <vtkm/filter/internal/ResolveFieldTypeAndMap.h>
|
|
|
|
namespace vtkm
|
|
{
|
|
namespace filter
|
|
{
|
|
|
|
//----------------------------------------------------------------------------
|
|
template <typename Derived>
|
|
inline VTKM_CONT FilterDataSet<Derived>::FilterDataSet()
|
|
: CoordinateSystemIndex(0)
|
|
{
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
template <typename Derived>
|
|
inline VTKM_CONT FilterDataSet<Derived>::~FilterDataSet()
|
|
{
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
template <typename Derived>
|
|
template <typename DerivedPolicy>
|
|
inline VTKM_CONT vtkm::cont::DataSet FilterDataSet<Derived>::PrepareForExecution(
|
|
const vtkm::cont::DataSet& input,
|
|
vtkm::filter::PolicyBase<DerivedPolicy> policy)
|
|
{
|
|
return (static_cast<Derived*>(this))->DoExecute(input, policy);
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
template <typename Derived>
|
|
template <typename DerivedPolicy>
|
|
inline VTKM_CONT bool FilterDataSet<Derived>::MapFieldOntoOutput(
|
|
vtkm::cont::DataSet& result,
|
|
const vtkm::cont::Field& field,
|
|
vtkm::filter::PolicyBase<DerivedPolicy> policy)
|
|
{
|
|
bool valid = false;
|
|
|
|
vtkm::filter::FieldMetadata metaData(field);
|
|
using FunctorType = internal::ResolveFieldTypeAndMap<Derived, DerivedPolicy>;
|
|
FunctorType functor(static_cast<Derived*>(this), result, metaData, policy, valid);
|
|
|
|
try
|
|
{
|
|
vtkm::cont::CastAndCall(vtkm::filter::ApplyPolicyFieldNotActive(field, policy), functor);
|
|
}
|
|
catch (vtkm::cont::ErrorBadType& error)
|
|
{
|
|
VTKM_LOG_S(vtkm::cont::LogLevel::Warn,
|
|
"Failed to map field " << field.GetName()
|
|
<< " because it is an unknown type. Cast error:\n"
|
|
<< error.GetMessage());
|
|
}
|
|
|
|
//the bool valid will be modified by the map algorithm to hold if the
|
|
//mapping occurred or not. If the mapping was good a new field has been
|
|
//added to the result that was passed in.
|
|
return valid;
|
|
}
|
|
}
|
|
}
|