VTK-m  2.0
FindSuperparentForNecessaryNodesWorklet.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 // Copyright (c) 2018, The Regents of the University of California, through
11 // Lawrence Berkeley National Laboratory (subject to receipt of any required approvals
12 // from the U.S. Dept. of Energy). All rights reserved.
13 //
14 // Redistribution and use in source and binary forms, with or without modification,
15 // are permitted provided that the following conditions are met:
16 //
17 // (1) Redistributions of source code must retain the above copyright notice, this
18 // list of conditions and the following disclaimer.
19 //
20 // (2) Redistributions in binary form must reproduce the above copyright notice,
21 // this list of conditions and the following disclaimer in the documentation
22 // and/or other materials provided with the distribution.
23 //
24 // (3) Neither the name of the University of California, Lawrence Berkeley National
25 // Laboratory, U.S. Dept. of Energy nor the names of its contributors may be
26 // used to endorse or promote products derived from this software without
27 // specific prior written permission.
28 //
29 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
30 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32 // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
36 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
37 // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
38 // OF THE POSSIBILITY OF SUCH DAMAGE.
39 //
40 //=============================================================================
41 // The PPP2 algorithm and software were jointly developed by
42 // Hamish Carr (University of Leeds), Gunther H. Weber (LBNL), and
43 // Oliver Ruebel (LBNL)
44 //==============================================================================
45 
46 #ifndef vtk_m_worklet_contourtree_distributed_hierarchical_augmenter_find_superparent_for_necessary_nodes_worklet_h
47 #define vtk_m_worklet_contourtree_distributed_hierarchical_augmenter_find_superparent_for_necessary_nodes_worklet_h
48 
51 
52 namespace vtkm
53 {
54 namespace worklet
55 {
56 namespace contourtree_distributed
57 {
58 namespace hierarchical_augmenter
59 {
60 
64 {
65 public:
67  using ControlSignature = void(
68  FieldIn baseTreeRegularNodeGlobalIds, // input domain
69  FieldIn baseTreeSuperparents, // input
70  FieldIn baseTreeDataValues, // input
71  WholeArrayIn baseTreeSuperarcs, // input
72  WholeArrayIn newSupernodeIds, // input
73  // Execution objects from the AugmentedTree to use the FindRegularByGlobal
74  // and FindSuperArcForUnknownNode for the hierarchical tree.
75  ExecObject findRegularByGlobal,
76  ExecObject findSuperArcForUnknownNode,
77  // Output arrays to populate
78  FieldOut regularSuperparents, // output
79  FieldOut regularNodesNeeded // output
80  );
81  using ExecutionSignature = void(InputIndex, _1, _2, _3, _4, _5, _6, _7, _8, _9);
82  using InputDomain = _1;
83 
87 
89  template <typename InFieldPortalType,
90  typename FieldType,
91  typename ExecObjectType1,
92  typename ExecObjectType2>
94  const vtkm::Id& regularNode, // InputIndex a.k.a out loop index
95  const vtkm::Id& globalRegularId, // same as baseTree->regularNodeGlobalIDs[regularNode];
96  const vtkm::Id& oldSuperparent, // same as baseTree->superparents[regularNode];
97  const FieldType& dataValue, // same as baseTree->dataValues[regularNode]
98  const InFieldPortalType& baseTreeSuperarcsPortal,
99  const InFieldPortalType& newSupernodeIdsPortal,
100  const ExecObjectType1& findRegularByGlobal, // Execution object to call FindRegularByGlobal
101  const ExecObjectType2&
102  findSuperArcForUnknownNode, // Execution object to call FindSuperArcForUnknownNode
103  vtkm::Id&
104  regularSuperparentsValue, // same as regularSuperparents[regularNode] = ... (set on output)
105  vtkm::Id&
106  regularNodesNeededValue // same as regularNodesNeeded[regularNode] = ... (set on output)
107  ) const
108  {
109  // per regular node
110  // retrieve the index (globalRegularId set on input)
111  // first check to see if it is already present (newRegularId set on input)
112  vtkm::Id newRegularId = findRegularByGlobal.FindRegularByGlobal(globalRegularId);
113 
114  // if it fails this test, then it's already in tree
116  { // not yet in tree
117  // since it's not in the tree, we want to find where it belongs
118  // to do so, we need to find an "above" and "below" node for it. Since it exists in the old tree, it belongs to a superarc, and we
119  // can use the ends of the superarc as above and below to do the searching
120  // oldSuperparent set on Input vtkm::Id oldSuperparent = baseTree->superparents[regularNode];
121  vtkm::Id oldSuperarc = baseTreeSuperarcsPortal.Get(oldSuperparent);
122 
123  // break the superarc into the flag and the target
124  // NOTE that we do not test for NO_SUCH_ELEMENT as all attachment points and the root are guaranteed to be present already,
125  // and have therefore been excluded by the if statement already
126  vtkm::Id oldSuperTarget = vtkm::worklet::contourtree_augmented::MaskedIndex(oldSuperarc);
127  bool ascendingSuperarc = vtkm::worklet::contourtree_augmented::IsAscending(oldSuperarc);
128 
129  // convert both from and to into new supernode IDs
130  vtkm::Id newSuperparent = newSupernodeIdsPortal.Get(oldSuperparent);
131  vtkm::Id newSuperTarget = newSupernodeIdsPortal.Get(oldSuperTarget);
132 
133  // retrieve the data value (dataValue set on input)
134  // now test and retrieve, with above = target if ascending, &c.
135  if (ascendingSuperarc)
136  {
137  regularSuperparentsValue = findSuperArcForUnknownNode.FindSuperArcForUnknownNode(
138  globalRegularId, dataValue, newSuperTarget, newSuperparent);
139  }
140  else
141  {
142  regularSuperparentsValue = findSuperArcForUnknownNode.FindSuperArcForUnknownNode(
143  globalRegularId, dataValue, newSuperparent, newSuperTarget);
144  }
145  // either way, we set the index array to the index
146  regularNodesNeededValue = regularNode;
147  } // not yet in tree
148  // Set to NO_SUCH_ELEMENT by default. By doing this in the worklet we an avoid having to
149  // initialize the output arrays first and we can use FieldIn instead of FieldInOut
150  else
151  {
154  }
155 
156  // In serial this worklet implements the following operation
157  /*
158  // now loop, finding the superparent for each node needed
159  for (vtkm::Id regularNode = 0; regularNode < baseTree->regularNodeGlobalIDs.size(); regularNode++)
160  { // per regular node
161  // retrieve the index
162  vtkm::Id globalRegularID = baseTree->regularNodeGlobalIDs[regularNode];
163 
164  // first check to see if it is already present
165  vtkm::Id newRegularID = augmentedTree->FindRegularByGlobal(globalRegularID);
166 
167  // if it fails this test, then it's already in tree
168  if (noSuchElement(newRegularID))
169  { // not yet in tree
170  // std::cout << "Not yet in tree" << std::endl;
171  // since it's not in the tree, we want to find where it belongs
172  // to do so, we need to find an "above" and "below" node for it. Since it exists in the old tree, it belongs to a superarc, and we
173  // can use the ends of the superarc as above and below to do the searching
174  vtkm::Id oldSuperparent = baseTree->superparents[regularNode];
175  vtkm::Id oldSuperarc = baseTree->superarcs[oldSuperparent];
176 
177  // break the superarc into the flag and the target
178  // NOTE that we do not test for NO_SUCH_ELEMENT as all attachment points and the root are guaranteed to be present already,
179  // and have therefore been excluded by the if statement already
180  vtkm::Id oldSuperTarget = maskedIndex(oldSuperarc);
181  bool ascendingSuperarc = isAscending(oldSuperarc);
182 
183  // convert both from and to into new supernode IDs
184  vtkm::Id newSuperparent = newSupernodeIDs[oldSuperparent];
185  vtkm::Id newSuperTarget = newSupernodeIDs[oldSuperTarget];
186 
187  // retrieve the data value
188  dataType dataValue = baseTree->dataValues[regularNode];
189 
190  // now test and retrieve, with above = target if ascending, &c.
191  if (ascendingSuperarc)
192  regularSuperparents[regularNode] = augmentedTree->FindSuperArcForUnknownNode(globalRegularID, dataValue, newSuperTarget, newSuperparent);
193  else
194  regularSuperparents[regularNode] = augmentedTree->FindSuperArcForUnknownNode(globalRegularID, dataValue, newSuperparent, newSuperTarget);
195 
196  // either way, we set the index array to the index
197  regularNodesNeeded[regularNode] = regularNode;
198  } // not yet in tree
199  } // per regular node
200  */
201  } // operator()()
202 
203 }; // FindSuperparentForNecessaryNodesWorklet
204 
205 } // namespace hierarchical_augmenter
206 } // namespace contourtree_distributed
207 } // namespace worklet
208 } // namespace vtkm
209 
210 #endif
vtkm::worklet::contourtree_distributed::hierarchical_augmenter::FindSuperparentForNecessaryNodesWorklet
Worklet used in HierarchicalAugmenter::CopyBaseRegularStructure for finding the superparent for each ...
Definition: FindSuperparentForNecessaryNodesWorklet.h:63
vtkm::worklet::contourtree_augmented::IsAscending
VTKM_EXEC_CONT bool IsAscending(vtkm::Id flaggedIndex)
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:121
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::contourtree_distributed::hierarchical_augmenter::FindSuperparentForNecessaryNodesWorklet::FindSuperparentForNecessaryNodesWorklet
VTKM_EXEC_CONT FindSuperparentForNecessaryNodesWorklet()
Default Constructor.
Definition: FindSuperparentForNecessaryNodesWorklet.h:86
WorkletMapField.h
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::worklet::WorkletMapField::FieldOut
A control signature tag for output fields.
Definition: WorkletMapField.h:60
vtkm::worklet::contourtree_augmented::MaskedIndex
VTKM_EXEC_CONT vtkm::Id MaskedIndex(vtkm::Id flaggedIndex)
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:127
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::contourtree_augmented::NoSuchElement
VTKM_EXEC_CONT bool NoSuchElement(vtkm::Id flaggedIndex)
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:97
vtkm::worklet::contourtree_distributed::hierarchical_augmenter::FindSuperparentForNecessaryNodesWorklet::InputDomain
_1 InputDomain
Definition: FindSuperparentForNecessaryNodesWorklet.h:82
vtkm::worklet::contourtree_distributed::hierarchical_augmenter::FindSuperparentForNecessaryNodesWorklet::ControlSignature
void(FieldIn baseTreeRegularNodeGlobalIds, FieldIn baseTreeSuperparents, FieldIn baseTreeDataValues, WholeArrayIn baseTreeSuperarcs, WholeArrayIn newSupernodeIds, ExecObject findRegularByGlobal, ExecObject findSuperArcForUnknownNode, FieldOut regularSuperparents, FieldOut regularNodesNeeded) ControlSignature
Control signature for the worklet.
Definition: FindSuperparentForNecessaryNodesWorklet.h:80
vtkm::worklet::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
vtkm::worklet::contourtree_distributed::hierarchical_augmenter::FindSuperparentForNecessaryNodesWorklet::ExecutionSignature
void(InputIndex, _1, _2, _3, _4, _5, _6, _7, _8, _9) ExecutionSignature
Definition: FindSuperparentForNecessaryNodesWorklet.h:81
Types.h
vtkm::worklet::contourtree_distributed::hierarchical_augmenter::FindSuperparentForNecessaryNodesWorklet::operator()
VTKM_EXEC void operator()(const vtkm::Id &regularNode, const vtkm::Id &globalRegularId, const vtkm::Id &oldSuperparent, const FieldType &dataValue, const InFieldPortalType &baseTreeSuperarcsPortal, const InFieldPortalType &newSupernodeIdsPortal, const ExecObjectType1 &findRegularByGlobal, const ExecObjectType2 &findSuperArcForUnknownNode, vtkm::Id &regularSuperparentsValue, vtkm::Id &regularNodesNeededValue) const
operator() of the workelt
Definition: FindSuperparentForNecessaryNodesWorklet.h:93
vtkm::exec::arg::InputIndex
The ExecutionSignature tag to use to get the input index.
Definition: InputIndex.h:42
vtkm::worklet::contourtree_augmented::NO_SUCH_ELEMENT
constexpr vtkm::Id NO_SUCH_ELEMENT
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:73
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38