vtk-m/vtkm/filter/Mask.hxx

107 lines
3.3 KiB
C++
Raw Normal View History

2017-03-21 22:11:06 +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 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
2017-03-21 22:11:06 +00:00
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-NA0003525 with NTESS,
2017-03-21 22:11:06 +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.
//============================================================================
namespace
{
2017-05-18 14:29:41 +00:00
template <typename DeviceTag>
struct CallWorklet
{
vtkm::Id Stride;
vtkm::cont::DynamicCellSet& Output;
vtkm::worklet::Mask& Worklet;
CallWorklet(vtkm::Id stride, vtkm::cont::DynamicCellSet& output, vtkm::worklet::Mask& worklet)
: Stride(stride)
, Output(output)
, Worklet(worklet)
2017-05-18 14:29:41 +00:00
{
}
template <typename CellSetType>
void operator()(const CellSetType& cells) const
2017-03-21 22:11:06 +00:00
{
this->Output = this->Worklet.Run(cells, this->Stride, DeviceTag());
2017-03-21 22:11:06 +00:00
}
};
} // end anon namespace
2017-03-21 22:11:06 +00:00
2017-05-18 14:29:41 +00:00
namespace vtkm
{
namespace filter
{
2017-03-21 22:11:06 +00:00
//-----------------------------------------------------------------------------
2017-05-18 14:29:41 +00:00
inline VTKM_CONT Mask::Mask()
: vtkm::filter::FilterDataSet<Mask>()
, Stride(1)
, CompactPoints(false)
2017-03-21 22:11:06 +00:00
{
}
//-----------------------------------------------------------------------------
2017-05-18 14:29:41 +00:00
template <typename DerivedPolicy, typename DeviceAdapter>
inline VTKM_CONT vtkm::cont::DataSet Mask::DoExecute(
const vtkm::cont::DataSet& input,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
2017-05-18 14:29:41 +00:00
const DeviceAdapter&)
2017-03-21 22:11:06 +00:00
{
2017-05-18 14:29:41 +00:00
const vtkm::cont::DynamicCellSet& cells = input.GetCellSet(this->GetActiveCellSetIndex());
vtkm::cont::DynamicCellSet cellOut;
CallWorklet<DeviceAdapter> workletCaller(this->Stride, cellOut, this->Worklet);
vtkm::filter::ApplyPolicy(cells, policy).CastAndCall(workletCaller);
2017-03-21 22:11:06 +00:00
// create the output dataset
vtkm::cont::DataSet output;
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
output.AddCellSet(cellOut);
return output;
2017-03-21 22:11:06 +00:00
}
//-----------------------------------------------------------------------------
2017-05-18 14:29:41 +00:00
template <typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
inline VTKM_CONT bool Mask::DoMapField(vtkm::cont::DataSet& result,
2017-05-18 14:29:41 +00:00
const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>&,
const DeviceAdapter& device)
2017-03-21 22:11:06 +00:00
{
vtkm::cont::Field output;
2017-05-18 14:29:41 +00:00
if (fieldMeta.IsPointField())
2017-03-21 22:11:06 +00:00
{
output = fieldMeta.AsField(input); // pass through
2017-03-21 22:11:06 +00:00
}
else if (fieldMeta.IsCellField())
2017-03-21 22:11:06 +00:00
{
output = fieldMeta.AsField(this->Worklet.ProcessCellField(input, device));
}
else
{
return false;
2017-03-21 22:11:06 +00:00
}
result.AddField(output);
return true;
2017-03-21 22:11:06 +00:00
}
}
}