vtk-m/vtkm/worklet/ThresholdPoints.h

90 lines
2.6 KiB
C
Raw Normal View History

2017-03-07 21:03:22 +00:00
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
2019-04-15 23:24:21 +00:00
//
2017-03-07 21:03:22 +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.
//============================================================================
2017-03-08 23:04:12 +00:00
#ifndef vtkm_m_worklet_ThresholdPoints_h
#define vtkm_m_worklet_ThresholdPoints_h
2017-03-07 21:03:22 +00:00
#include <vtkm/worklet/DispatcherMapTopology.h>
#include <vtkm/worklet/WorkletMapTopology.h>
#include <vtkm/cont/Algorithm.h>
2017-03-07 21:03:22 +00:00
#include <vtkm/cont/ArrayHandle.h>
2017-05-18 14:51:24 +00:00
#include <vtkm/cont/DataSet.h>
2017-03-07 21:03:22 +00:00
2017-05-18 14:29:41 +00:00
namespace vtkm
{
namespace worklet
{
2017-03-07 21:03:22 +00:00
class ThresholdPoints
2017-03-07 21:03:22 +00:00
{
public:
2017-05-18 14:29:41 +00:00
struct BoolType : vtkm::ListTagBase<bool>
{
};
2017-03-07 21:03:22 +00:00
template <typename UnaryPredicate>
class ThresholdPointField : public vtkm::worklet::WorkletMapCellToPoint
2017-03-07 21:03:22 +00:00
{
public:
using ControlSignature = void(CellSetIn cellset, FieldInPoint scalars, FieldOutPoint passFlags);
using ExecutionSignature = _3(_2);
2017-03-07 21:03:22 +00:00
VTKM_CONT
2017-05-18 14:29:41 +00:00
ThresholdPointField()
: Predicate()
{
}
2017-03-07 21:03:22 +00:00
VTKM_CONT
2017-05-18 14:29:41 +00:00
explicit ThresholdPointField(const UnaryPredicate& predicate)
2017-03-07 21:03:22 +00:00
: Predicate(predicate)
2017-05-18 14:29:41 +00:00
{
}
2017-03-07 21:03:22 +00:00
2017-05-18 14:29:41 +00:00
template <typename ScalarType>
VTKM_EXEC bool operator()(const ScalarType& scalar) const
2017-03-07 21:03:22 +00:00
{
return this->Predicate(scalar);
2017-03-07 21:03:22 +00:00
}
private:
UnaryPredicate Predicate;
};
template <typename CellSetType, typename ScalarsArrayHandle, typename UnaryPredicate>
vtkm::cont::CellSetSingleType<> Run(const CellSetType& cellSet,
const ScalarsArrayHandle& scalars,
const UnaryPredicate& predicate)
2017-03-07 21:03:22 +00:00
{
vtkm::cont::ArrayHandle<bool> passFlags;
2018-02-22 13:29:13 +00:00
using ThresholdWorklet = ThresholdPointField<UnaryPredicate>;
2017-03-07 21:03:22 +00:00
ThresholdWorklet worklet(predicate);
DispatcherMapTopology<ThresholdWorklet> dispatcher(worklet);
dispatcher.Invoke(cellSet, scalars, passFlags);
2017-03-07 21:03:22 +00:00
vtkm::cont::ArrayHandle<vtkm::Id> pointIds;
vtkm::cont::ArrayHandleCounting<vtkm::Id> indices =
vtkm::cont::make_ArrayHandleCounting(vtkm::Id(0), vtkm::Id(1), passFlags.GetNumberOfValues());
vtkm::cont::Algorithm::CopyIf(indices, passFlags, pointIds);
2017-03-07 21:03:22 +00:00
// Make CellSetSingleType with VERTEX at each point id
2017-05-18 14:29:41 +00:00
vtkm::cont::CellSetSingleType<> outCellSet(cellSet.GetName());
outCellSet.Fill(cellSet.GetNumberOfPoints(), vtkm::CellShapeTagVertex::Id, 1, pointIds);
2017-03-07 21:03:22 +00:00
return outCellSet;
}
};
}
} // namespace vtkm::worklet
#endif // vtkm_m_worklet_ThresholdPoints_h