vtk-m/vtkm/filter/Filter.hxx
Kenneth Moreland f8237a9d3a Make selection of fields to pass a field member variable
Previously you passed a FieldSelection to Filter::Execute to specify
which fields to pass from input to output. There is no real reason for
this as other information about input and output fields are member
variables to Filter. This moves field selection as a member variable as
well. (This should also help confusion when updating old code to new to
prevent users from mistaking field passing with input fields.

Also added a few convenience constructors to FieldSelection so that you
can call Field::SetFieldsToPass() with just the string of what you want
to pass.
2018-03-22 10:25:09 -06:00

120 lines
3.9 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.
//
// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#include <vtkm/filter/FieldMetadata.h>
#include <vtkm/filter/FilterTraits.h>
#include <vtkm/filter/PolicyDefault.h>
#include <vtkm/filter/Result.h>
#include <vtkm/filter/internal/ResolveFieldTypeAndExecute.h>
#include <vtkm/filter/internal/ResolveFieldTypeAndMap.h>
#include <vtkm/cont/Error.h>
#include <vtkm/cont/ErrorBadAllocation.h>
#include <vtkm/cont/ErrorExecution.h>
#include <vtkm/cont/Field.h>
#include <vtkm/cont/cuda/DeviceAdapterCuda.h>
#include <vtkm/cont/tbb/DeviceAdapterTBB.h>
namespace vtkm
{
namespace filter
{
//----------------------------------------------------------------------------
template <typename Derived>
inline VTKM_CONT Filter<Derived>::Filter()
: Tracker(vtkm::cont::GetGlobalRuntimeDeviceTracker())
, FieldsToPass(vtkm::filter::FieldSelection::MODE_ALL)
{
}
//----------------------------------------------------------------------------
template <typename Derived>
inline VTKM_CONT Filter<Derived>::~Filter()
{
}
//----------------------------------------------------------------------------
template <typename Derived>
inline VTKM_CONT vtkm::cont::DataSet Filter<Derived>::Execute(const vtkm::cont::DataSet& input)
{
return this->Execute(input, vtkm::filter::PolicyDefault());
}
//----------------------------------------------------------------------------
template <typename Derived>
template <typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet Filter<Derived>::Execute(
const vtkm::cont::DataSet& input,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy)
{
Derived* self = static_cast<Derived*>(this);
//self->DoPreExecute(input, policy, fieldSelection);
Result result = self->PrepareForExecution(input, policy);
//self->DoPostExecute(result.GetDataSet(), input, policy);
if (!result.IsValid())
{
throw vtkm::cont::ErrorExecution("Failed to execute filter.");
}
for (vtkm::IdComponent cc = 0; cc < input.GetNumberOfFields(); ++cc)
{
auto field = input.GetField(cc);
if (this->GetFieldsToPass().IsFieldSelected(field))
{
self->MapFieldOntoOutput(result, field, policy);
}
}
return result.GetDataSet();
}
//----------------------------------------------------------------------------
template <typename Derived>
inline VTKM_CONT vtkm::cont::MultiBlock Filter<Derived>::Execute(
const vtkm::cont::MultiBlock& input)
{
return this->Execute(input, vtkm::filter::PolicyDefault());
}
//----------------------------------------------------------------------------
template <typename Derived>
template <typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::MultiBlock Filter<Derived>::Execute(
const vtkm::cont::MultiBlock& input,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy)
{
// Derived* self = static_cast<Derived*>(this);
//self->DoPreExecute(input, policy, fieldSelection);
vtkm::cont::MultiBlock output;
for (auto& inDataSet : input)
{
vtkm::cont::DataSet outDataSet = this->Execute(inDataSet, policy);
output.AddBlock(outDataSet);
}
//self->DoPreExecute(output, input, policy);
return output;
}
}
}