2016-01-19 14:59:31 +00:00
|
|
|
//============================================================================
|
|
|
|
// 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 Sandia Corporation.
|
|
|
|
// Copyright 2014 UT-Battelle, LLC.
|
|
|
|
// Copyright 2014 Los Alamos National Security.
|
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
|
|
|
// 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>
|
2016-05-05 18:42:46 +00:00
|
|
|
#include <vtkm/filter/PolicyDefault.h>
|
2016-01-19 14:59:31 +00:00
|
|
|
|
|
|
|
#include <vtkm/filter/internal/ResolveFieldTypeAndExecute.h>
|
|
|
|
#include <vtkm/filter/internal/ResolveFieldTypeAndMap.h>
|
|
|
|
|
|
|
|
#include <vtkm/cont/Error.h>
|
2017-01-09 21:15:32 +00:00
|
|
|
#include <vtkm/cont/ErrorBadAllocation.h>
|
2016-01-19 14:59:31 +00:00
|
|
|
#include <vtkm/cont/ErrorExecution.h>
|
|
|
|
|
|
|
|
#include <vtkm/cont/cuda/DeviceAdapterCuda.h>
|
|
|
|
#include <vtkm/cont/tbb/DeviceAdapterTBB.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace filter
|
|
|
|
{
|
2016-01-19 14:59:31 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <class Derived>
|
|
|
|
inline VTKM_CONT FilterDataSet<Derived>::FilterDataSet()
|
|
|
|
: OutputFieldName()
|
|
|
|
, CellSetIndex(0)
|
|
|
|
, CoordinateSystemIndex(0)
|
|
|
|
, Tracker(vtkm::cont::GetGlobalRuntimeDeviceTracker())
|
2017-02-23 16:54:41 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <class Derived>
|
|
|
|
inline VTKM_CONT FilterDataSet<Derived>::~FilterDataSet()
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename Derived>
|
2017-08-10 17:56:19 +00:00
|
|
|
inline VTKM_CONT Result FilterDataSet<Derived>::Execute(const vtkm::cont::DataSet& input)
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
2016-11-23 21:05:16 +00:00
|
|
|
return this->Execute(input, vtkm::filter::PolicyDefault());
|
2016-01-19 14:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename Derived>
|
|
|
|
template <typename DerivedPolicy>
|
2017-08-10 17:56:19 +00:00
|
|
|
inline VTKM_CONT Result
|
2017-05-26 17:53:28 +00:00
|
|
|
FilterDataSet<Derived>::Execute(const vtkm::cont::DataSet& input,
|
|
|
|
const vtkm::filter::PolicyBase<DerivedPolicy>& policy)
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
|
|
|
return this->PrepareForExecution(input, policy);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
template <typename Derived, typename DerivedPolicy>
|
2016-08-17 20:13:51 +00:00
|
|
|
struct FilterDataSetPrepareForExecutionFunctor
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
2017-08-10 17:56:19 +00:00
|
|
|
vtkm::filter::Result Result;
|
2017-05-18 14:29:41 +00:00
|
|
|
Derived* Self;
|
|
|
|
const vtkm::cont::DataSet& Input;
|
|
|
|
const vtkm::filter::PolicyBase<DerivedPolicy>& Policy;
|
2016-08-17 20:13:51 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-26 17:53:28 +00:00
|
|
|
FilterDataSetPrepareForExecutionFunctor(Derived* self,
|
|
|
|
const vtkm::cont::DataSet& input,
|
2017-05-18 14:29:41 +00:00
|
|
|
const vtkm::filter::PolicyBase<DerivedPolicy>& policy)
|
|
|
|
: Self(self)
|
|
|
|
, Input(input)
|
|
|
|
, Policy(policy)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Device>
|
|
|
|
VTKM_CONT bool operator()(Device)
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
2016-08-17 20:13:51 +00:00
|
|
|
this->Result = this->Self->DoExecute(this->Input, this->Policy, Device());
|
2017-08-24 18:25:45 +00:00
|
|
|
return this->Result.IsValid();
|
2016-01-19 14:59:31 +00:00
|
|
|
}
|
2017-01-10 18:10:38 +00:00
|
|
|
|
|
|
|
private:
|
2017-05-18 14:29:41 +00:00
|
|
|
void operator=(FilterDataSetPrepareForExecutionFunctor<Derived, DerivedPolicy>&) = delete;
|
2016-08-17 20:13:51 +00:00
|
|
|
};
|
|
|
|
} // namespace detail
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename Derived>
|
|
|
|
template <typename DerivedPolicy>
|
2017-08-10 17:56:19 +00:00
|
|
|
inline VTKM_CONT Result
|
2017-05-26 17:53:28 +00:00
|
|
|
FilterDataSet<Derived>::PrepareForExecution(const vtkm::cont::DataSet& input,
|
|
|
|
const vtkm::filter::PolicyBase<DerivedPolicy>& policy)
|
2016-08-17 20:13:51 +00:00
|
|
|
{
|
|
|
|
// When we move to C++11, this could probably be an anonymous class
|
2017-05-18 14:29:41 +00:00
|
|
|
detail::FilterDataSetPrepareForExecutionFunctor<Derived, DerivedPolicy> functor(
|
|
|
|
static_cast<Derived*>(this), input, policy);
|
2016-08-17 20:13:51 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::TryExecute(functor, this->Tracker, typename DerivedPolicy::DeviceAdapterList());
|
2016-01-19 14:59:31 +00:00
|
|
|
|
2016-08-17 20:13:51 +00:00
|
|
|
return functor.Result;
|
2016-01-19 14:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename Derived>
|
2017-08-10 17:56:19 +00:00
|
|
|
inline VTKM_CONT bool FilterDataSet<Derived>::MapFieldOntoOutput(Result& result,
|
2017-05-18 14:29:41 +00:00
|
|
|
const vtkm::cont::Field& field)
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
2016-11-23 21:05:16 +00:00
|
|
|
return this->MapFieldOntoOutput(result, field, vtkm::filter::PolicyDefault());
|
2016-01-19 14:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename Derived>
|
|
|
|
template <typename DerivedPolicy>
|
|
|
|
inline VTKM_CONT bool FilterDataSet<Derived>::MapFieldOntoOutput(
|
2017-08-10 17:56:19 +00:00
|
|
|
Result& result,
|
2017-05-26 17:53:28 +00:00
|
|
|
const vtkm::cont::Field& field,
|
2017-05-18 14:29:41 +00:00
|
|
|
const vtkm::filter::PolicyBase<DerivedPolicy>& policy)
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
|
|
|
bool valid = false;
|
2017-08-24 18:25:45 +00:00
|
|
|
if (result.IsValid())
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
2016-03-22 16:27:45 +00:00
|
|
|
vtkm::filter::FieldMetadata metaData(field);
|
2017-05-18 14:29:41 +00:00
|
|
|
typedef internal::ResolveFieldTypeAndMap<Derived, DerivedPolicy> FunctorType;
|
2017-05-26 17:53:28 +00:00
|
|
|
FunctorType functor(
|
|
|
|
static_cast<Derived*>(this), result, metaData, policy, this->Tracker, valid);
|
2016-01-19 14:59:31 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
typedef vtkm::filter::FilterTraits<Derived> Traits;
|
|
|
|
vtkm::cont::CastAndCall(vtkm::filter::ApplyPolicy(field, policy, Traits()), functor);
|
|
|
|
}
|
2016-01-19 14:59:31 +00:00
|
|
|
|
|
|
|
//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
|
2017-08-10 17:56:19 +00:00
|
|
|
//added to the Result that was passed in.
|
2016-01-19 14:59:31 +00:00
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|