VTK-m  2.0
worklet/ThresholdPoints.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtkm_m_worklet_ThresholdPoints_h
11 #define vtkm_m_worklet_ThresholdPoints_h
12 
13 #include <vtkm/cont/Algorithm.h>
14 #include <vtkm/cont/ArrayHandle.h>
15 #include <vtkm/cont/Invoker.h>
16 
18 
19 namespace vtkm
20 {
21 namespace worklet
22 {
23 
25 {
26 public:
27  template <typename UnaryPredicate>
29  {
30  public:
31  using ControlSignature = void(CellSetIn cellset, FieldInPoint scalars, FieldOutPoint passFlags);
32  using ExecutionSignature = _3(_2);
33 
34  VTKM_CONT
36  : Predicate()
37  {
38  }
39 
40  VTKM_CONT
41  explicit ThresholdPointField(const UnaryPredicate& predicate)
42  : Predicate(predicate)
43  {
44  }
45 
46  template <typename ScalarType>
47  VTKM_EXEC bool operator()(const ScalarType& scalar) const
48  {
49  return this->Predicate(scalar);
50  }
51 
52  private:
53  UnaryPredicate Predicate;
54  };
55 
56  template <typename CellSetType, typename ScalarsArrayHandle, typename UnaryPredicate>
57  vtkm::cont::CellSetSingleType<> Run(const CellSetType& cellSet,
58  const ScalarsArrayHandle& scalars,
59  const UnaryPredicate& predicate)
60  {
62 
63  using ThresholdWorklet = ThresholdPointField<UnaryPredicate>;
64 
65  ThresholdWorklet worklet(predicate);
66  vtkm::cont::Invoker invoker;
67  invoker(worklet, cellSet, scalars, passFlags);
68 
72  vtkm::cont::Algorithm::CopyIf(indices, passFlags, pointIds);
73 
74  // Make CellSetSingleType with VERTEX at each point id
76  outCellSet.Fill(cellSet.GetNumberOfPoints(), vtkm::CellShapeTagVertex::Id, 1, pointIds);
77 
78  return outCellSet;
79  }
80 };
81 }
82 } // namespace vtkm::worklet
83 
84 #endif // vtkm_m_worklet_ThresholdPoints_h
vtkm::cont::ArrayHandle::GetNumberOfValues
VTKM_CONT vtkm::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:448
vtkm::cont::ArrayHandle< bool >
ArrayHandle.h
vtkm::worklet::ThresholdPoints::ThresholdPointField::Predicate
UnaryPredicate Predicate
Definition: worklet/ThresholdPoints.h:53
vtkm::worklet::ThresholdPoints::ThresholdPointField::operator()
VTKM_EXEC bool operator()(const ScalarType &scalar) const
Definition: worklet/ThresholdPoints.h:47
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::cont::make_ArrayHandleCounting
VTKM_CONT vtkm::cont::ArrayHandleCounting< CountingValueType > make_ArrayHandleCounting(CountingValueType start, CountingValueType step, vtkm::Id length)
A convenience function for creating an ArrayHandleCounting.
Definition: ArrayHandleCounting.h:151
vtkm::worklet::ThresholdPoints
Definition: worklet/ThresholdPoints.h:24
vtkm::cont::CellSetSingleType
Definition: CastAndCall.h:34
Invoker.h
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::WorkletVisitPointsWithCells
Base class for worklets that map from Cells to Points.
Definition: WorkletMapTopology.h:274
Algorithm.h
vtkm::cont::ArrayHandleCounting< vtkm::Id >
vtkm::cont::Invoker
Allows launching any worklet without a dispatcher.
Definition: Invoker.h:41
vtkm::cont::Algorithm::CopyIf
static VTKM_CONT void CopyIf(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, CIn > &input, const vtkm::cont::ArrayHandle< U, CStencil > &stencil, vtkm::cont::ArrayHandle< T, COut > &output)
Definition: Algorithm.h:435
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::worklet::ThresholdPoints::ThresholdPointField::ThresholdPointField
VTKM_CONT ThresholdPointField(const UnaryPredicate &predicate)
Definition: worklet/ThresholdPoints.h:41
vtkm::worklet::ThresholdPoints::ThresholdPointField::ControlSignature
void(CellSetIn cellset, FieldInPoint scalars, FieldOutPoint passFlags) ControlSignature
Definition: worklet/ThresholdPoints.h:31
vtkm::worklet::WorkletVisitPointsWithCells::FieldInPoint
FieldInVisit FieldInPoint
Definition: WorkletMapTopology.h:280
vtkm::worklet::ThresholdPoints::ThresholdPointField
Definition: worklet/ThresholdPoints.h:28
vtkm::worklet::WorkletVisitPointsWithCells::FieldOutPoint
FieldOut FieldOutPoint
Definition: WorkletMapTopology.h:282
vtkm::worklet::ThresholdPoints::ThresholdPointField::ExecutionSignature
_3(_2) ExecutionSignature
Definition: worklet/ThresholdPoints.h:32
vtkm::worklet::ThresholdPoints::ThresholdPointField::ThresholdPointField
VTKM_CONT ThresholdPointField()
Definition: worklet/ThresholdPoints.h:35
vtkm::cont::CellSetSingleType::Fill
VTKM_CONT void Fill(vtkm::Id numPoints, vtkm::UInt8 shapeId, vtkm::IdComponent numberOfPointsPerCell, const vtkm::cont::ArrayHandle< vtkm::Id, ConnectivityStorageTag > &connectivity)
Definition: CellSetSingleType.h:186
WorkletMapTopology.h
vtkm::worklet::ThresholdPoints::Run
vtkm::cont::CellSetSingleType Run(const CellSetType &cellSet, const ScalarsArrayHandle &scalars, const UnaryPredicate &predicate)
Definition: worklet/ThresholdPoints.h:57