vtk-m2/vtkm/worklet/ThresholdPoints.h

106 lines
3.4 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.
// 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 2015 Sandia Corporation.
// Copyright 2015 UT-Battelle, LLC.
// Copyright 2015 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.
//============================================================================
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/ArrayHandle.h>
2017-05-18 14:51:24 +00:00
#include <vtkm/cont/DataSet.h>
2017-03-07 21:03:22 +00:00
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
namespace vtkm {
namespace worklet {
class ThresholdPoints
2017-03-07 21:03:22 +00:00
{
public:
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:
typedef void ControlSignature(CellSetIn cellset,
FieldInPoint<ScalarAll> scalars,
FieldOutPoint<BoolType> passFlags);
typedef _3 ExecutionSignature(_2);
2017-03-07 21:03:22 +00:00
VTKM_CONT
ThresholdPointField() : Predicate() { }
VTKM_CONT
explicit ThresholdPointField(const UnaryPredicate &predicate)
: Predicate(predicate)
{ }
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,
2017-03-07 21:03:22 +00:00
typename UnaryPredicate,
typename DeviceAdapter>
vtkm::cont::CellSetSingleType<> Run(
const CellSetType &cellSet,
const ScalarsArrayHandle &scalars,
2017-03-07 21:03:22 +00:00
const UnaryPredicate &predicate,
2017-03-28 22:07:56 +00:00
DeviceAdapter)
2017-03-07 21:03:22 +00:00
{
typedef typename vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter> DeviceAlgorithm;
vtkm::cont::ArrayHandle<bool> passFlags;
2017-03-07 21:03:22 +00:00
typedef ThresholdPointField<UnaryPredicate> ThresholdWorklet;
2017-03-07 21:03:22 +00:00
ThresholdWorklet worklet(predicate);
DispatcherMapTopology<ThresholdWorklet, DeviceAdapter> 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());
DeviceAlgorithm::CopyIf(indices, passFlags, pointIds);
2017-03-07 21:03:22 +00:00
// Make CellSetSingleType with VERTEX at each point id
vtkm::cont::CellSetSingleType< > outCellSet(cellSet.GetName());
outCellSet.Fill(cellSet.GetNumberOfPoints(),
2017-03-07 21:03:22 +00:00
vtkm::CellShapeTagVertex::Id,
1,
pointIds);
return outCellSet;
}
};
}
} // namespace vtkm::worklet
#endif // vtkm_m_worklet_ThresholdPoints_h