//============================================================================ // 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 #include #include #include #include #include #include #include #include #include namespace vtkm { namespace filter { //---------------------------------------------------------------------------- template inline VTKM_CONT FilterDataSet::FilterDataSet() : OutputFieldName() , CellSetIndex(0) , CoordinateSystemIndex(0) , Tracker(vtkm::cont::GetGlobalRuntimeDeviceTracker()) { } //---------------------------------------------------------------------------- template inline VTKM_CONT FilterDataSet::~FilterDataSet() { } //----------------------------------------------------------------------------- template inline VTKM_CONT ResultDataSet FilterDataSet::Execute(const vtkm::cont::DataSet& input) { return this->Execute(input, vtkm::filter::PolicyDefault()); } //----------------------------------------------------------------------------- template template inline VTKM_CONT ResultDataSet FilterDataSet::Execute(const vtkm::cont::DataSet& input, const vtkm::filter::PolicyBase& policy) { return this->PrepareForExecution(input, policy); } //----------------------------------------------------------------------------- namespace detail { template struct FilterDataSetPrepareForExecutionFunctor { vtkm::filter::ResultDataSet Result; Derived* Self; const vtkm::cont::DataSet& Input; const vtkm::filter::PolicyBase& Policy; VTKM_CONT FilterDataSetPrepareForExecutionFunctor(Derived* self, const vtkm::cont::DataSet& input, const vtkm::filter::PolicyBase& policy) : Self(self) , Input(input) , Policy(policy) { } template VTKM_CONT bool operator()(Device) { this->Result = this->Self->DoExecute(this->Input, this->Policy, Device()); return this->Result.IsValid(); } private: void operator=(FilterDataSetPrepareForExecutionFunctor&) = delete; }; } // namespace detail template template inline VTKM_CONT ResultDataSet FilterDataSet::PrepareForExecution(const vtkm::cont::DataSet& input, const vtkm::filter::PolicyBase& policy) { // When we move to C++11, this could probably be an anonymous class detail::FilterDataSetPrepareForExecutionFunctor functor( static_cast(this), input, policy); vtkm::cont::TryExecute(functor, this->Tracker, typename DerivedPolicy::DeviceAdapterList()); return functor.Result; } //----------------------------------------------------------------------------- template inline VTKM_CONT bool FilterDataSet::MapFieldOntoOutput(ResultDataSet& result, const vtkm::cont::Field& field) { return this->MapFieldOntoOutput(result, field, vtkm::filter::PolicyDefault()); } //----------------------------------------------------------------------------- template template inline VTKM_CONT bool FilterDataSet::MapFieldOntoOutput( ResultDataSet& result, const vtkm::cont::Field& field, const vtkm::filter::PolicyBase& policy) { bool valid = false; if (result.IsValid()) { vtkm::filter::FieldMetadata metaData(field); typedef internal::ResolveFieldTypeAndMap FunctorType; FunctorType functor( static_cast(this), result, metaData, policy, this->Tracker, valid); typedef vtkm::filter::FilterTraits Traits; vtkm::cont::CastAndCall(vtkm::filter::ApplyPolicy(field, policy, Traits()), functor); } //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 ResultDataSet that was passed in. return valid; } } }