VTK-m  2.0
SetArcsSlideVertices.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_arcs_slide_vertices_h
54 #define vtk_m_worklet_contourtree_augmented_active_graph_set_arcs_slide_vertices_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  WholeArrayIn treeArcs, // (input) arcs from the tree
74  WholeArrayIn
75  meshExtrema, // (input) extrema from the mesh (i.e, pits or peaks depending on if we have a join or split tree)
76  WholeArrayIn treeFirstSuperchild, // (input) FirstSuperchild from the tree
77  WholeArrayIn treeSupernodes, // (input) supernodes from the tree
78  WholeArrayInOut treeSuperparents); // (input/output) superparents from the tree
79  typedef void ExecutionSignature(_1, InputIndex, _2, _3, _4, _5);
80  using InputDomain = _1;
81 
82  // Default Constructor
84  SetArcsSlideVertices(bool isJoinGraph, vtkm::Id nSupernodes, vtkm::Id nHypernodes)
85  : IsJoinGraph(isJoinGraph)
86  , NumSupernodes(nSupernodes)
87  , NumHypernodes(nHypernodes)
88  {
89  }
90 
91  template <typename InFieldPortalType, typename InOutFieldPortalType>
92  VTKM_EXEC void operator()(const InFieldPortalType& treeArcsPortal,
93  const vtkm::Id nodeID,
94  const InFieldPortalType& meshExtremaPortal,
95  const InFieldPortalType& treeFirstSuperchildPortal,
96  const InFieldPortalType& treeSupernodesPortal,
97  const InOutFieldPortalType& treeSuperparentsPortal) const
98  {
99  // ignore if the flag is already set
100  if (IsSupernode(treeArcsPortal.Get(nodeID)))
101  {
102  return;
103  }
104 
105  // start at the "top" end, retrieved from initial extremal array
106  vtkm::Id fromID = meshExtremaPortal.Get(nodeID);
107 
108  // get the "bottom" end from arcs array (it's a peak, so it's set already)
109  vtkm::Id toID = treeArcsPortal.Get(MaskedIndex(fromID));
110 
111  // loop to bottom or until to node is "below" this node
112  while (!NoSuchElement(toID) &&
113  (IsJoinGraph ? (MaskedIndex(toID) > MaskedIndex(nodeID))
114  : (MaskedIndex(toID) < MaskedIndex(nodeID))))
115  { // sliding loop
116  fromID = toID;
117  toID = treeArcsPortal.Get(MaskedIndex(fromID));
118  } // sliding loop
119 
120  // now we've found a hyperarc, we need to search to place ourselves on a superarc
121  // it's a binary search! first we get the hyperarc ID, which we've stored in superparents.
122  vtkm::Id hyperID = treeSuperparentsPortal.Get(MaskedIndex(fromID));
123  vtkm::Id leftSupernodeID = treeFirstSuperchildPortal.Get(hyperID);
124  vtkm::Id leftNodeID = treeSupernodesPortal.Get(leftSupernodeID);
125 
126  // the idea here is to compare the node ID against the node IDs for supernodes along the hyperarc
127  // however, the "low" end - i.e. the end to which it is pruned, is not stored explicitly.
128 
129  // for the join tree, then, we first test to see whether the node ID is lower than the lowest node
130  // ID along the hyperarc - i.e. of the lowest supernode in the range. Which means the left-hand end.
131 
132  // for the split tree, we want to test whether the node ID is higher than the highest node ID along
133  // the hyperarc. Because the supernodes & hypernodes are in reverse order in the arrays, this means
134  // that the highest node ID is still at the left-hand end
135 
136  // special case for the left-hand edge
137  if (IsJoinGraph ? (nodeID < leftNodeID) : (nodeID > leftNodeID))
138  { // below left hand end
139  treeSuperparentsPortal.Set(nodeID, leftSupernodeID);
140  } // below left hand end
141  else
142  { // not below the left hand end
143  vtkm::Id rightSupernodeID;
144  // the test depends on which tree we are computing
145  // because the ID numbers are in reverse order in the split tree
146  if (IsJoinGraph)
147  { // join graph
148  if (hyperID == NumHypernodes - 1)
149  rightSupernodeID = NumSupernodes - 1;
150  else
151  rightSupernodeID = treeFirstSuperchildPortal.Get(hyperID + 1) - 1;
152  } // join graph
153  else
154  { // split graph
155  if (hyperID == 0)
156  rightSupernodeID = NumSupernodes - 1;
157  else
158  rightSupernodeID = treeFirstSuperchildPortal.Get(hyperID - 1) - 1;
159  } // split graph
160 
161  // the right end is guaranteed to be the hypernode at the top, which is not
162  // being processed, so we now have a left & a right that span the vertex
163  // when they meet, they must both be higher than the node itself
164  while (leftSupernodeID != rightSupernodeID - 1)
165  { // binary search
166  vtkm::Id midSupernodeID = (leftSupernodeID + rightSupernodeID) / 2;
167  vtkm::Id midNodeID = treeSupernodesPortal.Get(midSupernodeID);
168  // this is NEVER equal, because nodeID cannot be a supernode
169  if (IsJoinGraph ? (midNodeID > nodeID) : (midNodeID < nodeID))
170  rightSupernodeID = midSupernodeID;
171  else
172  leftSupernodeID = midSupernodeID;
173  } // binary search
174 
175  // we have now found the supernode/arc to which the vertex belongs
176  treeSuperparentsPortal.Set(nodeID, rightSupernodeID);
177  } // not below the left hand end
178 
179  // In serial this worklet implements the following operation
180  /*
181  for (indexType nodeID = 0; nodeID < tree.Arcs.size(); nodeID++)
182  { // per node
183  // ignore if the flag is already set
184  if (IsSupernode(tree.Arcs[nodeID]))
185  continue;
186 
187  // start at the "top" end, retrieved from initial extremal array
188  vtkm::Id fromID = extrema[nodeID];
189 
190  // get the "bottom" end from arcs array (it's a peak, so it's set already)
191  vtkm::Id toID = tree.Arcs[MaskedIndex(fromID)];
192 
193  // loop to bottom or until to node is "below" this node
194  while (!NoSuchElement(toID) && (IsJoinGraph ?
195  (MaskedIndex(toID) > MaskedIndex(nodeID)): (MaskedIndex(toID) < MaskedIndex(nodeID))))
196  { // sliding loop
197  fromID = toID;
198  toID = tree.Arcs[MaskedIndex(fromID)];
199  } // sliding loop
200 
201  // now we've found a hyperarc, we need to search to place ourselves on a superarc
202  // it's a binary search! first we get the hyperarc ID, which we've stored in superparents.
203  indexType hyperID = tree.Superparents[MaskedIndex(fromID)];
204  indexType leftSupernodeID = tree.FirstSuperchild[hyperID];
205  indexType leftNodeID = tree.Supernodes[leftSupernodeID];
206 
207  // the idea here is to compare the node ID against the node IDs for supernodes along the hyperarc
208  // however, the "low" end - i.e. the end to which it is pruned, is not stored explicitly.
209 
210  // for the join tree, then, we first test to see whether the node ID is lower than the lowest node
211  // ID along the hyperarc - i.e. of the lowest supernode in the range. Which means the left-hand end.
212 
213  // for the split tree, we want to test whether the node ID is higher than the highest node ID along
214  // the hyperarc. Because the supernodes & hypernodes are in reverse order in the arrays, this means
215  // that the highest node ID is still at the left-hand end
216 
217  // special case for the left-hand edge
218  if (IsJoinGraph ? (nodeID < leftNodeID) : (nodeID > leftNodeID))
219  { // below left hand end
220  tree.Superparents[nodeID] = leftSupernodeID;
221  } // below left hand ned
222  else
223  { // not below the left hand end
224  vtkm::Id rightSupernodeID;
225  // the test depends on which tree we are computing
226  // because the ID numbers are in reverse order in the split tree
227  if (IsJoinGraph)
228  { // join graph
229  if (hyperID == NumHypernodes - 1)
230  rightSupernodeID = NumSupernodes - 1;
231  else
232  rightSupernodeID = tree.FirstSuperchild[hyperID + 1] - 1;
233  } // join graph
234  else
235  { // split graph
236  if (hyperID == 0)
237  rightSupernodeID = NumSupernodes - 1;
238  else
239  rightSupernodeID = tree.FirstSuperchild[hyperID - 1] - 1;
240  } // split graph
241 
242  // the right end is guaranteed to be the hypernode at the top, which is not
243  // being processed, so we now have a left & a right that span the vertex
244  // when they meet, they must both be higher than the node itself
245  while (leftSupernodeID != rightSupernodeID-1)
246  { // binary search
247  vtkm::Id midSupernodeID = (leftSupernodeID + rightSupernodeID) / 2;
248  // std::cout << "Mid Supernode ID: " << midSupernodeID << std::endl;
249  vtkm::Id midNodeID = tree.Supernodes[midSupernodeID];
250  // std::cout << "Mid Node ID: " << midNodeID << std::endl;
251  // this is NEVER equal, because nodeID cannot be a supernode
252  if (IsJoinGraph ? (midNodeID > nodeID) : (midNodeID < nodeID))
253  rightSupernodeID = midSupernodeID;
254  else
255  leftSupernodeID = midSupernodeID;
256  } // binary search
257 
258  // we have now found the supernode/arc to which the vertex belongs
259  tree.Superparents[nodeID] = rightSupernodeID;
260  } // not below the left hand end
261  } // per node
262  */
263  }
264 
265 private:
269 
270 }; // SetArcsSlideVertices
271 
272 } // namespace active_graph_inc
273 } // namespace contourtree_augmented
274 } // namespace worklet
275 } // namespace vtkm
276 
277 #endif
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_augmented::active_graph_inc::SetArcsSlideVertices::InputDomain
_1 InputDomain
Definition: SetArcsSlideVertices.h:80
WorkletMapField.h
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::worklet::contourtree_augmented::active_graph_inc::SetArcsSlideVertices::ControlSignature
void ControlSignature(WholeArrayIn treeArcs, WholeArrayIn meshExtrema, WholeArrayIn treeFirstSuperchild, WholeArrayIn treeSupernodes, WholeArrayInOut treeSuperparents)
Definition: SetArcsSlideVertices.h:72
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_augmented::active_graph_inc::SetArcsSlideVertices::SetArcsSlideVertices
VTKM_EXEC_CONT SetArcsSlideVertices(bool isJoinGraph, vtkm::Id nSupernodes, vtkm::Id nHypernodes)
Definition: SetArcsSlideVertices.h:84
vtkm::worklet::contourtree_augmented::active_graph_inc::SetArcsSlideVertices::operator()
VTKM_EXEC void operator()(const InFieldPortalType &treeArcsPortal, const vtkm::Id nodeID, const InFieldPortalType &meshExtremaPortal, const InFieldPortalType &treeFirstSuperchildPortal, const InFieldPortalType &treeSupernodesPortal, const InOutFieldPortalType &treeSuperparentsPortal) const
Definition: SetArcsSlideVertices.h:92
Types.h
vtkm::worklet::contourtree_augmented::active_graph_inc::SetArcsSlideVertices::NumHypernodes
vtkm::Id NumHypernodes
Definition: SetArcsSlideVertices.h:268
vtkm::worklet::contourtree_augmented::active_graph_inc::SetArcsSlideVertices::NumSupernodes
vtkm::Id NumSupernodes
Definition: SetArcsSlideVertices.h:267
vtkm::worklet::contourtree_augmented::active_graph_inc::SetArcsSlideVertices::ExecutionSignature
void ExecutionSignature(_1, InputIndex, _2, _3, _4, _5)
Definition: SetArcsSlideVertices.h:79
vtkm::worklet::contourtree_augmented::active_graph_inc::SetArcsSlideVertices::IsJoinGraph
bool IsJoinGraph
Definition: SetArcsSlideVertices.h:266
vtkm::worklet::contourtree_augmented::IsSupernode
VTKM_EXEC_CONT bool IsSupernode(vtkm::Id flaggedIndex)
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:109
vtkm::exec::arg::InputIndex
The ExecutionSignature tag to use to get the input index.
Definition: InputIndex.h:42
vtkm::worklet::contourtree_augmented::active_graph_inc::SetArcsSlideVertices
Definition: SetArcsSlideVertices.h:69
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38