VTK-m  2.0
InnerJoin.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 
11 #ifndef vtk_m_worklet_connectivity_InnerJoin_h
12 #define vtk_m_worklet_connectivity_InnerJoin_h
13 
14 #include <vtkm/cont/Algorithm.h>
19 
20 namespace vtkm
21 {
22 namespace worklet
23 {
24 namespace connectivity
25 {
26 class InnerJoin
27 {
28 public:
30  {
31  using ControlSignature =
32  void(FieldIn, FieldIn, FieldIn, WholeArrayIn, FieldOut, FieldOut, FieldOut);
33  using ExecutionSignature = void(_1, _2, _3, VisitIndex, _4, _5, _6, _7);
34  using InputDomain = _1;
35 
37 
38  // TODO: type trait for array portal?
39  template <typename KeyType, typename ValueType1, typename InPortalType, typename ValueType2>
40  VTKM_EXEC void operator()(KeyType key,
41  ValueType1 value1,
42  vtkm::Id lowerBounds,
43  vtkm::Id visitIndex,
44  const InPortalType& value2,
45  vtkm::Id& keyOut,
46  ValueType1& value1Out,
47  ValueType2& value2Out) const
48  {
49  auto v2 = value2.Get(lowerBounds + visitIndex);
50  keyOut = key;
51  value1Out = value1;
52  value2Out = v2;
53  }
54  };
55 
57 
58  // TODO: not mutating input keys and values?
59  template <typename Key, typename Value1, typename Value2>
60  static void Run(vtkm::cont::ArrayHandle<Key>& key1,
67  {
68  Algorithm::SortByKey(key1, value1);
69  Algorithm::SortByKey(key2, value2);
70 
73  Algorithm::LowerBounds(key2, key1, lbs);
74  Algorithm::UpperBounds(key2, key1, ubs);
75 
77  Algorithm::Transform(ubs, lbs, counts, vtkm::Subtract());
78 
79  vtkm::worklet::ScatterCounting scatter{ counts };
81  mergeDisp.Invoke(key1, value1, lbs, value2, keyOut, value1Out, value2Out);
82  }
83 };
84 
85 class Renumber
86 {
87 public:
88  static void Run(vtkm::cont::ArrayHandle<vtkm::Id>& componentsInOut)
89  {
90  using Algorithm = vtkm::cont::Algorithm;
91 
92  // FIXME: we should be able to apply findRoot to each pixel and use some kind
93  // of atomic operation to get the number of unique components without the
94  // cost of copying and sorting. This might be able to be extended to also
95  // work for the renumbering (replacing InnerJoin) through atomic increment.
96  vtkm::cont::ArrayHandle<vtkm::Id> uniqueComponents;
97  Algorithm::Copy(componentsInOut, uniqueComponents);
98  Algorithm::Sort(uniqueComponents);
99  Algorithm::Unique(uniqueComponents);
100 
102  Algorithm::Copy(vtkm::cont::ArrayHandleIndex(componentsInOut.GetNumberOfValues()), ids);
103 
105  Algorithm::Copy(vtkm::cont::ArrayHandleIndex(uniqueComponents.GetNumberOfValues()),
106  uniqueColor);
107 
110  InnerJoin::Run(componentsInOut,
111  ids,
112  uniqueComponents,
113  uniqueColor,
114  cellColors,
115  pixelIdsOut,
116  componentsInOut);
117 
118  Algorithm::SortByKey(pixelIdsOut, componentsInOut);
119  }
120 };
121 }
122 }
123 } // vtkm::worklet::connectivity
124 
125 #endif //vtk_m_worklet_connectivity_InnerJoin_h
vtkm::worklet::connectivity::Renumber::Run
static void Run(vtkm::cont::ArrayHandle< vtkm::Id > &componentsInOut)
Definition: InnerJoin.h:88
vtkm::cont::ArrayHandle::GetNumberOfValues
VTKM_CONT vtkm::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:448
vtkm::cont::Algorithm::SortByKey
static VTKM_CONT void SortByKey(vtkm::cont::DeviceAdapterId devId, vtkm::cont::ArrayHandle< T, StorageT > &keys, vtkm::cont::ArrayHandle< U, StorageU > &values)
Definition: Algorithm.h:993
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:283
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::Subtract
Definition: Types.h:242
WorkletMapField.h
vtkm::worklet::WorkletMapField::FieldOut
A control signature tag for output fields.
Definition: WorkletMapField.h:60
vtkm::cont::Algorithm::UpperBounds
static VTKM_CONT void UpperBounds(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, CIn > &input, const vtkm::cont::ArrayHandle< T, CVal > &values, vtkm::cont::ArrayHandle< vtkm::Id, COut > &output)
Definition: Algorithm.h:1091
vtkm::cont::Algorithm::LowerBounds
static VTKM_CONT void LowerBounds(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, CIn > &input, const vtkm::cont::ArrayHandle< T, CVal > &values, vtkm::cont::ArrayHandle< vtkm::Id, COut > &output)
Definition: Algorithm.h:604
vtkm::worklet::connectivity::InnerJoin::Merge::InputDomain
_1 InputDomain
Definition: InnerJoin.h:34
vtkm::worklet::connectivity::InnerJoin::Merge::operator()
VTKM_EXEC void operator()(KeyType key, ValueType1 value1, vtkm::Id lowerBounds, vtkm::Id visitIndex, const InPortalType &value2, vtkm::Id &keyOut, ValueType1 &value1Out, ValueType2 &value2Out) const
Definition: InnerJoin.h:40
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
DispatcherMapField.h
vtkm::worklet::connectivity::InnerJoin::Merge::ControlSignature
void(FieldIn, FieldIn, FieldIn, WholeArrayIn, FieldOut, FieldOut, FieldOut) ControlSignature
Definition: InnerJoin.h:32
ScatterCounting.h
vtkm::worklet::ScatterCounting
A scatter that maps input to some numbers of output.
Definition: ScatterCounting.h:44
vtkm::worklet::DispatcherMapField
Dispatcher for worklets that inherit from WorkletMapField.
Definition: DispatcherMapField.h:25
Algorithm.h
vtkm::worklet::connectivity::InnerJoin::Merge
Definition: InnerJoin.h:29
vtkm::worklet::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
ArrayHandleIndex.h
vtkm::worklet::connectivity::Renumber
Definition: InnerJoin.h:85
vtkm::worklet::connectivity::InnerJoin::Merge::ExecutionSignature
void(_1, _2, _3, VisitIndex, _4, _5, _6, _7) ExecutionSignature
Definition: InnerJoin.h:33
vtkm::cont::Algorithm
Definition: Algorithm.h:385
vtkm::cont::Algorithm::Transform
static VTKM_CONT void Transform(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, StorageT > &input1, const vtkm::cont::ArrayHandle< U, StorageU > &input2, vtkm::cont::ArrayHandle< V, StorageV > &output, BinaryFunctor binaryFunctor)
Definition: Algorithm.h:1037
vtkm::worklet::connectivity::InnerJoin
Definition: InnerJoin.h:26
vtkm::exec::arg::VisitIndex
The ExecutionSignature tag to use to get the visit index.
Definition: VisitIndex.h:43
vtkm::worklet::connectivity::InnerJoin::Run
static void Run(vtkm::cont::ArrayHandle< Key > &key1, vtkm::cont::ArrayHandle< Value1 > &value1, vtkm::cont::ArrayHandle< Key > &key2, vtkm::cont::ArrayHandle< Value2 > &value2, vtkm::cont::ArrayHandle< Key > &keyOut, vtkm::cont::ArrayHandle< Value1 > &value1Out, vtkm::cont::ArrayHandle< Value2 > &value2Out)
Definition: InnerJoin.h:60
vtkm::cont::ArrayHandleIndex
An implicit array handle containing the its own indices.
Definition: ArrayHandleIndex.h:54
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38