VTK-m  2.0
worklet/ExtractPoints.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_ExtractPoints_h
11 #define vtkm_m_worklet_ExtractPoints_h
12 
13 #include <vtkm/cont/Algorithm.h>
14 #include <vtkm/cont/ArrayCopy.h>
15 #include <vtkm/cont/ArrayHandle.h>
17 #include <vtkm/cont/Invoker.h>
18 
19 #include <vtkm/ImplicitFunction.h>
20 
22 
23 namespace vtkm
24 {
25 namespace worklet
26 {
27 
29 {
30 public:
32  // Worklet to identify points within volume of interest
34  {
35  public:
36  using ControlSignature = void(CellSetIn cellset,
37  FieldInPoint coordinates,
38  ExecObject function,
39  FieldOutPoint passFlags);
40  using ExecutionSignature = _4(_2, _3);
41 
42  VTKM_CONT
43  explicit ExtractPointsByVOI(bool extractInside)
44  : passValue(extractInside)
45  , failValue(!extractInside)
46  {
47  }
48 
49  template <typename ImplicitFunction>
50  VTKM_EXEC bool operator()(const vtkm::Vec3f_64& coordinate,
51  const ImplicitFunction& function) const
52  {
53  bool pass = passValue;
54  vtkm::Float64 value = function.Value(coordinate);
55  if (value > 0)
56  {
57  pass = failValue;
58  }
59  return pass;
60  }
61 
62  private:
63  bool passValue;
64  bool failValue;
65  };
66 
68  // Extract points by id creates new cellset of vertex cells
69  template <typename CellSetType>
70  vtkm::cont::CellSetSingleType<> Run(const CellSetType& cellSet,
71  const vtkm::cont::ArrayHandle<vtkm::Id>& pointIds)
72  {
73  vtkm::cont::ArrayCopy(pointIds, this->ValidPointIds);
74 
75  // Make CellSetSingleType with VERTEX at each point id
77  outCellSet.Fill(
78  cellSet.GetNumberOfPoints(), vtkm::CellShapeTagVertex::Id, 1, this->ValidPointIds);
79 
80  return outCellSet;
81  }
82 
84  // Extract points by implicit function
85  template <typename CellSetType, typename CoordinateType, typename ImplicitFunction>
86  vtkm::cont::CellSetSingleType<> Run(const CellSetType& cellSet,
87  const CoordinateType& coordinates,
88  const ImplicitFunction& implicitFunction,
89  bool extractInside)
90  {
91  // Worklet output will be a boolean passFlag array
93 
94  ExtractPointsByVOI worklet(extractInside);
95  vtkm::cont::Invoker invoke;
96  invoke(worklet, cellSet, coordinates, implicitFunction, passFlags);
97 
100  vtkm::cont::Algorithm::CopyIf(indices, passFlags, this->ValidPointIds);
101 
102  // Make CellSetSingleType with VERTEX at each point id
104  outCellSet.Fill(
105  cellSet.GetNumberOfPoints(), vtkm::CellShapeTagVertex::Id, 1, this->ValidPointIds);
106 
107  return outCellSet;
108  }
109 
110 private:
112 };
113 }
114 } // namespace vtkm::worklet
115 
116 #endif // vtkm_m_worklet_ExtractPoints_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< vtkm::Id >
ArrayHandle.h
vtkm::worklet::ExtractPoints::ValidPointIds
vtkm::cont::ArrayHandle< vtkm::Id > ValidPointIds
Definition: worklet/ExtractPoints.h:111
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::worklet::ExtractPoints::ExtractPointsByVOI::ExtractPointsByVOI
VTKM_CONT ExtractPointsByVOI(bool extractInside)
Definition: worklet/ExtractPoints.h:43
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::ExtractPoints::ExtractPointsByVOI::failValue
bool failValue
Definition: worklet/ExtractPoints.h:64
vtkm::worklet::ExtractPoints::ExtractPointsByVOI
Definition: worklet/ExtractPoints.h:33
vtkm::cont::CellSetSingleType
Definition: CastAndCall.h:34
Invoker.h
CoordinateSystem.h
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
ArrayCopy.h
vtkm::worklet::ExtractPoints
Definition: worklet/ExtractPoints.h:28
vtkm::worklet::WorkletVisitPointsWithCells
Base class for worklets that map from Cells to Points.
Definition: WorkletMapTopology.h:274
Algorithm.h
vtkm::worklet::ExtractPoints::Run
vtkm::cont::CellSetSingleType Run(const CellSetType &cellSet, const vtkm::cont::ArrayHandle< vtkm::Id > &pointIds)
Definition: worklet/ExtractPoints.h:70
vtkm::cont::ArrayHandleCounting< vtkm::Id >
vtkm::cont::Invoker
Allows launching any worklet without a dispatcher.
Definition: Invoker.h:41
vtkm::cont::ArrayCopy
void ArrayCopy(const SourceArrayType &source, DestArrayType &destination)
Does a deep copy from one array to another array.
Definition: ArrayCopy.h:142
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::worklet::ExtractPoints::ExtractPointsByVOI::ControlSignature
void(CellSetIn cellset, FieldInPoint coordinates, ExecObject function, FieldOutPoint passFlags) ControlSignature
Definition: worklet/ExtractPoints.h:39
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
ImplicitFunction.h
vtkm::worklet::ExtractPoints::Run
vtkm::cont::CellSetSingleType Run(const CellSetType &cellSet, const CoordinateType &coordinates, const ImplicitFunction &implicitFunction, bool extractInside)
Definition: worklet/ExtractPoints.h:86
vtkm::worklet::WorkletVisitPointsWithCells::FieldInPoint
FieldInVisit FieldInPoint
Definition: WorkletMapTopology.h:280
vtkm::Vec< vtkm::Float64, 3 >
vtkm::worklet::ExtractPoints::ExtractPointsByVOI::ExecutionSignature
_4(_2, _3) ExecutionSignature
Definition: worklet/ExtractPoints.h:40
vtkm::worklet::WorkletVisitPointsWithCells::FieldOutPoint
FieldOut FieldOutPoint
Definition: WorkletMapTopology.h:282
vtkm::Float64
double Float64
Definition: Types.h:155
vtkm::worklet::ExtractPoints::ExtractPointsByVOI::operator()
VTKM_EXEC bool operator()(const vtkm::Vec3f_64 &coordinate, const ImplicitFunction &function) const
Definition: worklet/ExtractPoints.h:50
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::ExtractPoints::ExtractPointsByVOI::passValue
bool passValue
Definition: worklet/ExtractPoints.h:63