vtk-m/vtkm/filter/Mask.hxx

96 lines
2.7 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.
2019-04-15 23:24:21 +00:00
//
2017-03-21 22:11:06 +00:00
// 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.
//============================================================================
#ifndef vtk_m_filter_Mask_hxx
#define vtk_m_filter_Mask_hxx
2017-03-21 22:11:06 +00:00
namespace
{
2017-05-18 14:29:41 +00:00
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);
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
{
}
//-----------------------------------------------------------------------------
template <typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet Mask::DoExecute(const vtkm::cont::DataSet& input,
vtkm::filter::PolicyBase<DerivedPolicy> policy)
2017-03-21 22:11:06 +00:00
{
const vtkm::cont::DynamicCellSet& cells = input.GetCellSet();
vtkm::cont::DynamicCellSet cellOut;
CallWorklet workletCaller(this->Stride, cellOut, this->Worklet);
vtkm::filter::ApplyPolicyCellSet(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.SetCellSet(cellOut);
return output;
2017-03-21 22:11:06 +00:00
}
//-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy>
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,
vtkm::filter::PolicyBase<DerivedPolicy>)
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));
}
else
{
return false;
2017-03-21 22:11:06 +00:00
}
result.AddField(output);
return true;
2017-03-21 22:11:06 +00:00
}
}
}
#endif