VTK-m  2.0
SetSuperArcsSetTreeSuperarcs.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 //
42 // This code is an extension of the algorithm presented in the paper:
43 // Parallel Peak Pruning for Scalable SMP Contour Tree Computation.
44 // Hamish Carr, Gunther Weber, Christopher Sewell, and James Ahrens.
45 // Proceedings of the IEEE Symposium on Large Data Analysis and Visualization
46 // (LDAV), October 2016, Baltimore, Maryland.
47 //
48 // The PPP2 algorithm and software were jointly developed by
49 // Hamish Carr (University of Leeds), Gunther H. Weber (LBNL), and
50 // Oliver Ruebel (LBNL)
51 //==============================================================================
52 
53 #ifndef vtk_m_worklet_contourtree_augmented_active_graph_set_super_arcs_set_tree_superarcs_h
54 #define vtk_m_worklet_contourtree_augmented_active_graph_set_super_arcs_set_tree_superarcs_h
55 
58 
59 namespace vtkm
60 {
61 namespace worklet
62 {
63 namespace contourtree_augmented
64 {
65 namespace active_graph_inc
66 {
67 
68 // Worklet for computing the sort indices from the sort order
70 {
71 public:
72  typedef void ControlSignature(
73  FieldIn treeSupernodes, // (input) supernodes of the tree
74  WholeArrayIn hyperarcs, // (input) hyperarcs from the active graph
75  WholeArrayIn treeHyperparents, // (input) hyperparents from the tree
76  WholeArrayIn superId, // (input) superID from the active graph
77  WholeArrayIn hyperId, // (input) hyperID from the active graph
78  WholeArrayOut treeSuperarcs, // (output) superarcs from the tree
79  WholeArrayOut treeFirstSuperchild); // (output) FirstSuperchild from the tree
80  typedef void ExecutionSignature(_1, InputIndex, _2, _3, _4, _5, _6, _7);
81  using InputDomain = _1;
82 
83  // Default Constructor
86 
87  template <typename InFieldPortalType, typename OutFieldPortalType>
88  VTKM_EXEC void operator()(const vtkm::Id& /*graphVertex*/, // FIXME: Remove unused parameter?
89  const vtkm::Id supernode,
90  const InFieldPortalType& hyperarcsPortal,
91  const InFieldPortalType& treeHyperparentsPortal,
92  const InFieldPortalType& superIDPortal,
93  const InFieldPortalType& hyperIDPortal,
94  const OutFieldPortalType& treeSuperarcsPortal,
95  const OutFieldPortalType& treeFirstSuperchildPortal) const
96  {
97  // retrieve the hyperparent (which is still a graph index, not a hypernode index)
98  vtkm::Id hyperparent = treeHyperparentsPortal.Get(supernode);
99 
100  // work out whether we have the first (closest to saddle) supernode on the hyperarc
101  bool firstSupernode = false;
102  if (supernode == 0)
103  { // end of the array
104  firstSupernode = true;
105  } // end of the array
106  else
107  { // the general case
108  // retrieve the previous supernode ID & hyperarc ID
109  vtkm::Id prevHyperparent = treeHyperparentsPortal.Get(supernode - 1);
110 
111  // now that we have the two hyperarcs, compare them
112  firstSupernode = (hyperparent != prevHyperparent);
113  } // the general case
114 
115  // now we can set the superarcs
116  // the last in the segment retrieves the hyperarc, masks out the flags, then does a reverse lookup
117  // to find the position in the supernode index
118  if (firstSupernode)
119  { // first supernode
120  // this needs to point to the supernode at the "bottom" end of the hyperarc
121  vtkm::Id prunesTo = hyperarcsPortal.Get(hyperparent);
122 
123  if (NoSuchElement(prunesTo))
124  treeSuperarcsPortal.Set(supernode, (vtkm::Id)NO_SUCH_ELEMENT);
125  else
126  treeSuperarcsPortal.Set(supernode, superIDPortal.Get(MaskedIndex(prunesTo)));
127 
128  // we also need to set the first superchild for the hypergraph
129  treeFirstSuperchildPortal.Set(hyperIDPortal.Get(hyperparent), supernode);
130  } // first supernode
131  // all others just point to their neighbour
132  else
133  { // not first
134  treeSuperarcsPortal.Set(supernode, supernode - 1);
135  } // not first
136 
137  // In serial this worklet implements the following operation
138  /*
139  // Each supernode points to its neighbour in the list, except at the end of segments
140  for (indexType supernode = 0; supernode < nSupernodes; supernode++)
141  { // per supernode
142  // retrieve the actual supernode ID in the graph
143  indexType graphIndex = tree.Supernodes[supernode];
144  // retrieve the hyperparent (which is still a graph index, not a hypernode index)
145  indexType hyperparent = tree.hyperparents[supernode];
146 
147  // work out whether we have the first (closest to saddle) supernode on the hyperarc
148  bool firstSupernode = false;
149  if (supernode == 0)
150  { // end of the array
151  firstSupernode = true;
152  } // end of the array
153  else
154  { // the general case
155  // retrieve the previous supernode ID & hyperarc ID
156  indexType prevHyperparent = tree.hyperparents[supernode-1];
157 
158  // now that we have the two hyperarcs, compare them
159  firstSupernode = (hyperparent != prevHyperparent);
160  } // the general case
161 
162  // now we can set the superarcs
163  // the last in the segment retrieves the hyperarc, masks out the flags, then does a reverse lookup
164  // to find the position in the supernode index
165  if (firstSupernode)
166  { // first supernode
167  // this needs to point to the supernode at the "bottom" end of the hyperarc
168  indexType prunesTo = hyperarcs[hyperparent];
169 
170  if (NoSuchElement(prunesTo))
171  tree.superarcs[supernode] = NO_SUCH_ELEMENT;
172  else
173  tree.superarcs[supernode] = superID[MaskedIndex(prunesTo)];
174 
175  // we also need to set the first superchild for the hypergraph
176  tree.FirstSuperchild[hyperID[hyperparent]] = supernode;
177  } // first supernode
178  // all others just point to their neighbour
179  else
180  { // not first
181  tree.superarcs[supernode] = supernode-1;
182  } // not first
183  } // per supernode
184 
185  */
186  }
187 
188 }; // SetSuperArcsSetTreeSuperarcs
189 
190 } // namespace active_graph_inc
191 } // namespace contourtree_augmented
192 } // namespace worklet
193 } // namespace vtkm
194 
195 #endif
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
WorkletMapField.h
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::worklet::contourtree_augmented::active_graph_inc::SetSuperArcsSetTreeSuperarcs::operator()
VTKM_EXEC void operator()(const vtkm::Id &, const vtkm::Id supernode, const InFieldPortalType &hyperarcsPortal, const InFieldPortalType &treeHyperparentsPortal, const InFieldPortalType &superIDPortal, const InFieldPortalType &hyperIDPortal, const OutFieldPortalType &treeSuperarcsPortal, const OutFieldPortalType &treeFirstSuperchildPortal) const
Definition: SetSuperArcsSetTreeSuperarcs.h:88
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::active_graph_inc::SetSuperArcsSetTreeSuperarcs
Definition: SetSuperArcsSetTreeSuperarcs.h:69
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::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
Types.h
vtkm::worklet::contourtree_augmented::active_graph_inc::SetSuperArcsSetTreeSuperarcs::InputDomain
_1 InputDomain
Definition: SetSuperArcsSetTreeSuperarcs.h:81
vtkm::worklet::contourtree_augmented::active_graph_inc::SetSuperArcsSetTreeSuperarcs::ControlSignature
void ControlSignature(FieldIn treeSupernodes, WholeArrayIn hyperarcs, WholeArrayIn treeHyperparents, WholeArrayIn superId, WholeArrayIn hyperId, WholeArrayOut treeSuperarcs, WholeArrayOut treeFirstSuperchild)
Definition: SetSuperArcsSetTreeSuperarcs.h:72
vtkm::worklet::contourtree_augmented::active_graph_inc::SetSuperArcsSetTreeSuperarcs::ExecutionSignature
void ExecutionSignature(_1, InputIndex, _2, _3, _4, _5, _6, _7)
Definition: SetSuperArcsSetTreeSuperarcs.h:80
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
vtkm::worklet::contourtree_augmented::active_graph_inc::SetSuperArcsSetTreeSuperarcs::SetSuperArcsSetTreeSuperarcs
VTKM_EXEC_CONT SetSuperArcsSetTreeSuperarcs()
Definition: SetSuperArcsSetTreeSuperarcs.h:85