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.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
2016-01-19 14:59:31 +00:00
|
|
|
// Copyright 2014 UT-Battelle, LLC.
|
|
|
|
// Copyright 2014 Los Alamos National Security.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
2016-01-19 14:59:31 +00:00
|
|
|
// 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 FilterDataSetWithField<Derived>::FilterDataSetWithField()
|
|
|
|
: 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 FilterDataSetWithField<Derived>::~FilterDataSetWithField()
|
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 FilterDataSetWithField<Derived>::Execute(const vtkm::cont::DataSet& input,
|
|
|
|
const std::string& inFieldName)
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
return this->Execute(input, input.GetField(inFieldName), vtkm::filter::PolicyDefault());
|
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 FilterDataSetWithField<Derived>::Execute(const vtkm::cont::DataSet& input,
|
|
|
|
const vtkm::cont::Field& field)
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
return this->Execute(input, field, vtkm::filter::PolicyDefault());
|
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
|
2017-05-26 17:53:28 +00:00
|
|
|
FilterDataSetWithField<Derived>::Execute(const vtkm::cont::DataSet& input,
|
|
|
|
const vtkm::cont::CoordinateSystem& field)
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
return this->Execute(input, field, vtkm::filter::PolicyDefault());
|
2016-01-19 14:59:31 +00:00
|
|
|
}
|
|
|
|
|
2017-08-18 20:28:33 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
template <typename Derived>
|
2017-08-30 14:30:29 +00:00
|
|
|
inline VTKM_CONT std::vector<vtkm::filter::Result> FilterDataSetWithField<Derived>::Execute(
|
2017-08-18 20:28:33 +00:00
|
|
|
const vtkm::cont::MultiBlock& input,
|
|
|
|
const std::string& inFieldName)
|
|
|
|
{
|
2017-08-30 14:30:29 +00:00
|
|
|
std::vector<vtkm::filter::Result> results;
|
2017-08-18 20:28:33 +00:00
|
|
|
|
|
|
|
for (vtkm::Id j = 0; j < input.GetNumberOfBlocks(); j++)
|
|
|
|
{
|
2017-08-30 14:30:29 +00:00
|
|
|
vtkm::filter::Result result = this->Execute(
|
2017-08-18 20:28:33 +00:00
|
|
|
input.GetBlock(j), input.GetBlock(j).GetField(inFieldName), vtkm::filter::PolicyDefault());
|
|
|
|
results.push_back(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
template <typename Derived>
|
|
|
|
template <typename DerivedPolicy>
|
2017-08-30 14:30:29 +00:00
|
|
|
inline VTKM_CONT std::vector<vtkm::filter::Result> FilterDataSetWithField<Derived>::Execute(
|
2017-08-18 20:28:33 +00:00
|
|
|
const vtkm::cont::MultiBlock& input,
|
|
|
|
const std::string& inFieldName,
|
|
|
|
const vtkm::filter::PolicyBase<DerivedPolicy>& policy)
|
|
|
|
{
|
2017-08-30 14:30:29 +00:00
|
|
|
std::vector<vtkm::filter::Result> results;
|
2017-08-18 20:28:33 +00:00
|
|
|
|
|
|
|
for (vtkm::Id j = 0; j < input.GetNumberOfBlocks(); j++)
|
|
|
|
{
|
2017-08-30 14:30:29 +00:00
|
|
|
vtkm::filter::Result result =
|
2017-08-18 20:28:33 +00:00
|
|
|
this->Execute(input.GetBlock(j), input.GetBlock(j).GetField(inFieldName), policy);
|
|
|
|
results.push_back(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
FilterDataSetWithField<Derived>::Execute(const vtkm::cont::DataSet& input,
|
|
|
|
const std::string& inFieldName,
|
|
|
|
const vtkm::filter::PolicyBase<DerivedPolicy>& policy)
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
return this->Execute(input, input.GetField(inFieldName), policy);
|
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
|
|
|
FilterDataSetWithField<Derived>::Execute(const vtkm::cont::DataSet& input,
|
|
|
|
const vtkm::cont::Field& field,
|
|
|
|
const vtkm::filter::PolicyBase<DerivedPolicy>& policy)
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
|
|
|
return this->PrepareForExecution(input, field, policy);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
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
|
|
|
FilterDataSetWithField<Derived>::Execute(const vtkm::cont::DataSet& input,
|
|
|
|
const vtkm::cont::CoordinateSystem& field,
|
|
|
|
const vtkm::filter::PolicyBase<DerivedPolicy>& policy)
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
|
|
|
//we need to state that the field is actually a coordinate system, so that
|
|
|
|
//the filter uses the proper policy to convert the types.
|
|
|
|
return this->PrepareForExecution(input, field, policy);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
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 FilterDataSetWithField<Derived>::PrepareForExecution(
|
2017-05-26 17:53:28 +00:00
|
|
|
const vtkm::cont::DataSet& input,
|
|
|
|
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
|
|
|
{
|
2016-03-22 16:27:45 +00:00
|
|
|
vtkm::filter::FieldMetadata metaData(field);
|
2017-08-10 17:56:19 +00:00
|
|
|
Result result;
|
2016-03-22 16:27:45 +00:00
|
|
|
|
2017-08-10 17:56:19 +00:00
|
|
|
typedef internal::ResolveFieldTypeAndExecute<Derived, DerivedPolicy, Result> FunctorType;
|
2017-11-09 18:47:45 +00:00
|
|
|
FunctorType functor(static_cast<Derived*>(this), input, metaData, policy, result);
|
2017-05-18 14:29:41 +00:00
|
|
|
|
|
|
|
typedef vtkm::filter::FilterTraits<Derived> Traits;
|
2017-11-09 18:47:45 +00:00
|
|
|
vtkm::cont::CastAndCall(
|
|
|
|
vtkm::filter::ApplyPolicy(field, policy, Traits()), functor, this->Tracker);
|
2016-01-19 14:59:31 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
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 FilterDataSetWithField<Derived>::PrepareForExecution(
|
2017-05-26 17:53:28 +00:00
|
|
|
const vtkm::cont::DataSet& input,
|
|
|
|
const vtkm::cont::CoordinateSystem& field,
|
2017-05-18 14:29:41 +00:00
|
|
|
const vtkm::filter::PolicyBase<DerivedPolicy>& policy)
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
|
|
|
//We have a special signature just for CoordinateSystem, so that we can ask
|
|
|
|
//the policy for the storage types and value types just for coordinate systems
|
2016-03-22 16:27:45 +00:00
|
|
|
vtkm::filter::FieldMetadata metaData(field);
|
2016-01-19 14:59:31 +00:00
|
|
|
|
|
|
|
//determine the field type first
|
2017-08-10 17:56:19 +00:00
|
|
|
Result result;
|
|
|
|
typedef internal::ResolveFieldTypeAndExecute<Derived, DerivedPolicy, Result> FunctorType;
|
2017-11-09 18:47:45 +00:00
|
|
|
FunctorType functor(static_cast<Derived*>(this), input, metaData, policy, result);
|
2017-05-18 14:29:41 +00:00
|
|
|
|
|
|
|
typedef vtkm::filter::FilterTraits<Derived> Traits;
|
2017-11-09 18:47:45 +00:00
|
|
|
vtkm::cont::CastAndCall(
|
|
|
|
vtkm::filter::ApplyPolicy(field, policy, Traits()), functor, this->Tracker);
|
2016-01-19 14:59:31 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename Derived>
|
|
|
|
inline VTKM_CONT bool FilterDataSetWithField<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)
|
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 FilterDataSetWithField<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-10 17:56:19 +00:00
|
|
|
if (result.IsDataSetValid())
|
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-11-09 18:47:45 +00:00
|
|
|
FunctorType functor(static_cast<Derived*>(this), result, metaData, policy, valid);
|
2016-01-19 14:59:31 +00:00
|
|
|
|
2017-11-09 18:47:45 +00:00
|
|
|
vtkm::cont::CastAndCall(vtkm::filter::ApplyPolicy(field, policy), functor, this->Tracker);
|
2017-05-18 14:29:41 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|