VTK-m  2.0
worklet/ImageDifference.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 vtk_m_worklet_ImageDifference_h
11 #define vtk_m_worklet_ImageDifference_h
12 
13 #include <vtkm/VecTraits.h>
14 #include <vtkm/VectorAnalysis.h>
15 
16 #include <vtkm/cont/ArrayHandle.h>
18 
21 
22 namespace vtkm
23 {
24 namespace worklet
25 {
26 
28 {
29 public:
31  using ExecutionSignature = void(_2, _3, Boundary, _4, _5);
32  using InputDomain = _1;
33 
35  : ShiftRadius(radius)
36  , Threshold(threshold)
37  {
38  }
39 
40  template <typename InputFieldPortalType>
42  const vtkm::exec::FieldNeighborhood<InputFieldPortalType>& primaryNeighborhood,
43  const typename InputFieldPortalType::ValueType& secondary,
44  const vtkm::exec::BoundaryState& boundary,
45  typename InputFieldPortalType::ValueType& diff,
46  vtkm::FloatDefault& diffThreshold) const
47  {
48  using T = typename InputFieldPortalType::ValueType;
49 
50  auto minIndices = boundary.MinNeighborIndices(this->ShiftRadius);
51  auto maxIndices = boundary.MaxNeighborIndices(this->ShiftRadius);
52 
53  T minPixelDiff{};
54  vtkm::FloatDefault minPixelDiffThreshold = 10000.0f;
55  for (vtkm::IdComponent i = minIndices[0]; i <= maxIndices[0]; i++)
56  {
57  for (vtkm::IdComponent j = minIndices[1]; j <= maxIndices[1]; j++)
58  {
59  for (vtkm::IdComponent k = minIndices[2]; k <= maxIndices[2]; k++)
60  {
61  diff = vtkm::Abs(primaryNeighborhood.Get(i, j, k) - secondary);
62  diffThreshold = static_cast<vtkm::FloatDefault>(vtkm::Magnitude(diff));
63  if (diffThreshold < this->Threshold)
64  {
65  return;
66  }
67  if (diffThreshold < minPixelDiffThreshold)
68  {
69  minPixelDiffThreshold = diffThreshold;
70  minPixelDiff = diff;
71  }
72  }
73  }
74  }
75  diff = minPixelDiff;
76  diffThreshold = minPixelDiffThreshold;
77  }
78 
79 private:
82 };
83 
85 {
86 public:
88  using ExecutionSignature = void(_1, _2, _3, _4);
89  using InputDomain = _1;
90 
91  ImageDifference() = default;
92 
93  template <typename T, vtkm::IdComponent Size>
95  const vtkm::Vec<T, Size>& secondary,
96  vtkm::Vec<T, Size>& diff,
97  vtkm::FloatDefault& diffThreshold) const
98  {
99  diff = vtkm::Abs(primary - secondary);
100  diffThreshold = static_cast<vtkm::FloatDefault>(vtkm::Magnitude(diff));
101  }
102 };
103 
104 
105 } // vtkm::worklet
106 } // vtkm
107 
108 #endif // vtk_m_worklet_ImageDifference_h
vtkm::exec::BoundaryState
Provides a neighborhood's placement with respect to the mesh's boundary.
Definition: BoundaryState.h:31
ArrayHandle.h
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::exec::BoundaryState::MaxNeighborIndices
VTKM_EXEC vtkm::IdComponent3 MaxNeighborIndices(vtkm::IdComponent radius) const
Returns the minimum neighborhood indices that are within the bounds of the data.
Definition: BoundaryState.h:136
vtkm::worklet::ImageDifferenceNeighborhood::ExecutionSignature
void(_2, _3, Boundary, _4, _5) ExecutionSignature
Definition: worklet/ImageDifference.h:31
WorkletMapField.h
vtkm::worklet::WorkletMapField::FieldOut
A control signature tag for output fields.
Definition: WorkletMapField.h:60
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::worklet::WorkletNeighborhood::CellSetIn
A control signature tag for input connectivity.
Definition: WorkletNeighborhood.h:110
vtkm::worklet::WorkletNeighborhood::FieldOut
A control signature tag for output point fields.
Definition: WorkletNeighborhood.h:89
vtkm::worklet::ImageDifferenceNeighborhood
Definition: worklet/ImageDifference.h:27
vtkm::Magnitude
VTKM_EXEC_CONT detail::FloatingPointReturnType< T >::Type Magnitude(const T &x)
Returns the magnitude of a vector.
Definition: VectorAnalysis.h:100
vtkm::worklet::ImageDifferenceNeighborhood::Threshold
vtkm::FloatDefault Threshold
Definition: worklet/ImageDifference.h:81
WorkletPointNeighborhood.h
DeviceAdapterAlgorithm.h
vtkm::worklet::ImageDifference::operator()
VTKM_EXEC void operator()(const vtkm::Vec< T, Size > &primary, const vtkm::Vec< T, Size > &secondary, vtkm::Vec< T, Size > &diff, vtkm::FloatDefault &diffThreshold) const
Definition: worklet/ImageDifference.h:94
vtkm::worklet::ImageDifferenceNeighborhood::ImageDifferenceNeighborhood
ImageDifferenceNeighborhood(const vtkm::IdComponent &radius, const vtkm::FloatDefault &threshold)
Definition: worklet/ImageDifference.h:34
VectorAnalysis.h
vtkm::worklet::ImageDifferenceNeighborhood::InputDomain
_1 InputDomain
Definition: worklet/ImageDifference.h:32
vtkm::exec::FieldNeighborhood::Get
VTKM_EXEC ValueType Get(vtkm::IdComponent i, vtkm::IdComponent j, vtkm::IdComponent k) const
Definition: FieldNeighborhood.h:48
vtkm::worklet::ImageDifference
Definition: worklet/ImageDifference.h:84
vtkm::worklet::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
vtkm::worklet::ImageDifferenceNeighborhood::ControlSignature
void(CellSetIn, FieldInNeighborhood, FieldIn, FieldOut, FieldOut) ControlSignature
Definition: worklet/ImageDifference.h:30
vtkm::worklet::ImageDifferenceNeighborhood::operator()
VTKM_EXEC void operator()(const vtkm::exec::FieldNeighborhood< InputFieldPortalType > &primaryNeighborhood, const typename InputFieldPortalType::ValueType &secondary, const vtkm::exec::BoundaryState &boundary, typename InputFieldPortalType::ValueType &diff, vtkm::FloatDefault &diffThreshold) const
Definition: worklet/ImageDifference.h:41
vtkm::worklet::WorkletNeighborhood::FieldIn
A control signature tag for input point fields.
Definition: WorkletNeighborhood.h:77
vtkm::worklet::Threshold
Definition: worklet/Threshold.h:33
vtkm::worklet::WorkletNeighborhood::Boundary
The ExecutionSignature tag to query if the current iteration is inside the boundary.
Definition: WorkletNeighborhood.h:54
vtkm::Vec
A short fixed-length array.
Definition: Types.h:767
vtkm::FloatDefault
vtkm::Float32 FloatDefault
The floating point type to use when no other precision is specified.
Definition: Types.h:198
vtkm::worklet::ImageDifference::ControlSignature
void(FieldIn, FieldIn, FieldOut, FieldOut) ControlSignature
Definition: worklet/ImageDifference.h:87
vtkm::worklet::ImageDifference::ImageDifference
ImageDifference()=default
vtkm::exec::BoundaryState::MinNeighborIndices
VTKM_EXEC vtkm::IdComponent3 MinNeighborIndices(vtkm::IdComponent radius) const
Returns the minimum neighborhood indices that are within the bounds of the data.
Definition: BoundaryState.h:114
vtkm::worklet::WorkletNeighborhood::FieldInNeighborhood
A control signature tag for neighborhood input values.
Definition: WorkletNeighborhood.h:129
vtkm::worklet::WorkletPointNeighborhood
Definition: WorkletPointNeighborhood.h:27
vtkm::worklet::ImageDifference::InputDomain
_1 InputDomain
Definition: worklet/ImageDifference.h:89
vtkm::worklet::ImageDifferenceNeighborhood::ShiftRadius
vtkm::IdComponent ShiftRadius
Definition: worklet/ImageDifference.h:80
vtkm::worklet::ImageDifference::ExecutionSignature
void(_1, _2, _3, _4) ExecutionSignature
Definition: worklet/ImageDifference.h:88
vtkm::exec::FieldNeighborhood
Retrieves field values from a neighborhood.
Definition: FieldNeighborhood.h:36
VecTraits.h
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38