//============================================================================ // 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. //============================================================================ #ifndef vtkm_m_worklet_ThresholdPoints_h #define vtkm_m_worklet_ThresholdPoints_h #include #include #include #include #include namespace vtkm { namespace worklet { class ThresholdPoints { public: struct BoolType : vtkm::ListTagBase { }; template class ThresholdPointField : public vtkm::worklet::WorkletVisitPointsWithCells { public: using ControlSignature = void(CellSetIn cellset, FieldInPoint scalars, FieldOutPoint passFlags); using ExecutionSignature = _3(_2); VTKM_CONT ThresholdPointField() : Predicate() { } VTKM_CONT explicit ThresholdPointField(const UnaryPredicate& predicate) : Predicate(predicate) { } template VTKM_EXEC bool operator()(const ScalarType& scalar) const { return this->Predicate(scalar); } private: UnaryPredicate Predicate; }; template vtkm::cont::CellSetSingleType<> Run(const CellSetType& cellSet, const ScalarsArrayHandle& scalars, const UnaryPredicate& predicate) { vtkm::cont::ArrayHandle passFlags; using ThresholdWorklet = ThresholdPointField; ThresholdWorklet worklet(predicate); DispatcherMapTopology dispatcher(worklet); dispatcher.Invoke(cellSet, scalars, passFlags); vtkm::cont::ArrayHandle pointIds; vtkm::cont::ArrayHandleCounting indices = vtkm::cont::make_ArrayHandleCounting(vtkm::Id(0), vtkm::Id(1), passFlags.GetNumberOfValues()); vtkm::cont::Algorithm::CopyIf(indices, passFlags, pointIds); // Make CellSetSingleType with VERTEX at each point id vtkm::cont::CellSetSingleType<> outCellSet(cellSet.GetName()); outCellSet.Fill(cellSet.GetNumberOfPoints(), vtkm::CellShapeTagVertex::Id, 1, pointIds); return outCellSet; } }; } } // namespace vtkm::worklet #endif // vtkm_m_worklet_ThresholdPoints_h