VTK-m  2.0
CollapseBranchesWorklet.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_filter_scalar_topology_worklet_branch_decomposition_hierarchical_volumetric_branch_decomposer_CollapseBranchesWorklet_h
47 #define vtk_m_filter_scalar_topology_worklet_branch_decomposition_hierarchical_volumetric_branch_decomposer_CollapseBranchesWorklet_h
48 
51 
52 namespace vtkm
53 {
54 namespace worklet
55 {
56 namespace scalar_topology
57 {
58 namespace hierarchical_volumetric_branch_decomposer
59 {
60 
62 {
63 public:
65  using ControlSignature = void(
66  FieldIn bestUpSupernode,
67  FieldIn bestDownSupernode,
68  // Execution objects from the hierarchical tree to use the FindRegularByGlobal function
69  ExecObject findRegularByGlobal,
70  // Execution objects from the hierarchical tree to use the FindSuperArcBetweenNodes, function
71  ExecObject findSuperArcBetweenNodes,
72  WholeArrayIn hierarchicalTreeRegular2supernode,
73  WholeArrayIn hierarchicalTreeWhichRound,
74  WholeArrayInOut branchRoot);
75  using ExecutionSignature = void(InputIndex, _1, _2, _3, _4, _5, _6, _7);
76  using InputDomain = _1;
77 
81 
83  template <typename ExecObjectType1,
84  typename ExecObjectType2,
85  typename InFieldPortalType,
86  typename InOutFieldPortalType>
88  const vtkm::Id& supernode, // iteration index
89  const vtkm::Id& bestUpSupernodeId, // bestUpSupernode[supernode]
90  const vtkm::Id& bestDownSupernodeId, // bestDownSupernode[supernode]
91  const ExecObjectType1& findRegularByGlobal, // Execution object to call FindRegularByGlobal
92  const ExecObjectType2&
93  findSuperArcBetweenNodes, // Execution object to call FindSuperArcBetweenNodes
94  const InFieldPortalType& hierarchicalTreeRegular2supernodePortal,
95  const InFieldPortalType& hierarchicalTreeWhichRoundPortal,
96  const InOutFieldPortalType& branchRootPortal) const
97  {
98  // per supernode
99  // For each supernode, convert the best up into a superarc ID
100  // Note that the superarc may not belong to this rank, and that the superarc might be oriented either direction
101  // So we search for the best up global ID in the hierarchical tree
102  // If it does not exist, then this superarc does not belong to the rank, and can be ignored
103  // If it does exist and is a downwards superarc, we now have the correct ID
104  // If it does exist and is an upwards superarc, then the current supernode must have an ascending arc to it, and we're done
105  // Also do the same for the best down, then for each supernode, point the higher numbered at the lower
106 
107  // if there is no best up, we're at an upper leaf and will not connect up two superarcs anyway, so we can skip the supernode
109  {
110  return;
111  }
112 
113  // Search for the regular ID of the best up supernode
114  vtkm::Id bestUpLocalRegularId = findRegularByGlobal.FindRegularByGlobal(bestUpSupernodeId);
115 
116  // test to see whether it exists in this rank's hierarchical tree.
117  if (vtkm::worklet::contourtree_augmented::NoSuchElement(bestUpLocalRegularId))
118  {
119  return;
120  }
121 
122  // do the same for the best down
123  // Search for the regular ID of the best down supernode
124  vtkm::Id bestDownLocalRegularId = findRegularByGlobal.FindRegularByGlobal(bestDownSupernodeId);
125 
126  // test to see whether it exists in this rank's hierarchical tree.
127  if (vtkm::worklet::contourtree_augmented::NoSuchElement(bestDownLocalRegularId))
128  {
129  return;
130  }
131 
132  // Convert regular to super ID
133  vtkm::Id bestUpLocalSupernodeId =
134  hierarchicalTreeRegular2supernodePortal.Get(bestUpLocalRegularId);
135  vtkm::Id bestDownLocalSupernodeId =
136  hierarchicalTreeRegular2supernodePortal.Get(bestDownLocalRegularId);
137 
138  // local variable for the superarc IDs
139  vtkm::Id bestUpSuperarc =
140  findSuperArcBetweenNodes.FindSuperArcBetweenNodes(bestUpLocalSupernodeId, supernode);
141  vtkm::Id bestDownSuperarc =
142  findSuperArcBetweenNodes.FindSuperArcBetweenNodes(bestDownLocalSupernodeId, supernode);
143 
144  // right: we now know the local IDs of both. Take the more junior and point it at the more senior - i.e. always orient inbound
145  // at the root supernode, the virtual root superarc will not be used, so we compare round/iteration/ID of the two superarcs anyway
146  // WARNING: it might appear that there is potential for loops in the algorithm &/or write collisions
147  // but there isn't because our superarcs are *ALWAYS* oriented inwards, as long as the test is correct ;->
148 
149  // so to find seniority, &c., we retrieve round number.
150  // we don't need the iteration number, because a higher iteration (more senior) always has a higher ID for the same round
151  vtkm::Id bestUpRound = hierarchicalTreeWhichRoundPortal.Get(bestUpSuperarc);
152  vtkm::Id bestDownRound = hierarchicalTreeWhichRoundPortal.Get(bestDownSuperarc);
153 
154  // more senior rounds are higher numbered
155  if ((bestUpRound > bestDownRound) ||
156  // within each round, more senior iterations are higher numbered
157  ((bestUpRound == bestDownRound) && (bestUpSuperarc > bestDownSuperarc)))
158  { // up is more senior
159  branchRootPortal.Set(bestDownSuperarc, bestUpSuperarc);
160  } // up is more senior
161  else // all other cases, go the opposite way - NB: assumes we will never have the same superarc twice
162  { // down is more senior
163  branchRootPortal.Set(bestUpSuperarc, bestDownSuperarc);
164  } // down is more senior
165 
166  /*
167  // This worklet implements the following loop.
168  for (vtkm::Id supernode = 0; supernode < hierarchicalTree.supernodes.size(); supernode++)
169  { // per supernode
170  // For each supernode, convert the best up into a superarc ID
171  // Note that the superarc may not belong to this rank, and that the superarc might be oriented either direction
172  // So we search for the best up global ID in the hierarchical tree
173  // If it does not exist, then this superarc does not belong to the rank, and can be ignored
174  // If it does exist and is a downwards superarc, we now have the correct ID
175  // If it does exist and is an upwards superarc, then the current supernode must have an ascending arc to it, and we're done
176  // Also do the same for the best down, then for each supernode, point the higher numbered at the lower
177 
178  vtkm::Id bestUpSupernodeID = bestUpSupernode[supernode];
179 
180  // if there is no best up, we're at an upper leaf and will not connect up two superarcs anyway, so we can skip the supernode
181  if (noSuchElement(bestUpSupernodeID))
182  continue;
183 
184  // Search for the regular ID of the best up supernode
185  vtkm::Id bestUpLocalRegularID = hierarchicalTree.FindRegularByGlobal(bestUpSupernodeID);
186 
187  // test to see whether it exists in this rank's hierarchical tree.
188  if (noSuchElement(bestUpLocalRegularID))
189  continue;
190 
191  // do the same for the best down
192  vtkm::Id bestDownSupernodeID = bestDownSupernode[supernode];
193 
194  // Search for the regular ID of the best down supernode
195  vtkm::Id bestDownLocalRegularID = hierarchicalTree.FindRegularByGlobal(bestDownSupernodeID);
196 
197  // test to see whether it exists in this rank's hierarchical tree.
198  if (noSuchElement(bestDownLocalRegularID))
199  continue;
200 
201  // Convert regular to super ID
202  vtkm::Id bestUpLocalSupernodeID = hierarchicalTree.regular2supernode[bestUpLocalRegularID];
203 
204  vtkm::Id bestDownLocalSupernodeID = hierarchicalTree.regular2supernode[bestDownLocalRegularID];
205 
206  // local variable for the superarc IDs
207  vtkm::Id bestUpSuperarc = hierarchicalTree.FindSuperArcBetweenNodes(bestUpLocalSupernodeID, supernode);
208 
209  vtkm::Id bestDownSuperarc = hierarchicalTree.FindSuperArcBetweenNodes(bestDownLocalSupernodeID, supernode);
210 
211  // right: we now know the local IDs of both. Take the more junior and point it at the more senior - i.e. always orient inbound
212  // at the root supernode, the virtual root superarc will not be used, so we compare round/iteration/ID of the two superarcs anyway
213  // WARNING: it might appear that there is potential for loops in the algorithm &/or write collisions
214  // but there isn't because our superarcs are *ALWAYS* oriented inwards, as long as the test is correct ;->
215 
216  // so to find seniority, &c., we retrieve round number.
217  // we don't need the iteration number, because a higher iteration (more senior) always has a higher ID for the same round
218  vtkm::Id bestUpRound = hierarchicalTree.whichRound[bestUpSuperarc];
219  vtkm::Id bestDownRound = hierarchicalTree.whichRound[bestDownSuperarc];
220 
221  // more senior rounds are higher numbered
222  if ( (bestUpRound > bestDownRound) ||
223  // within each round, more senior iterations are higher numbered
224  ( (bestUpRound == bestDownRound) && (bestUpSuperarc > bestDownSuperarc) ))
225  { // up is more senior
226  branchRoot[bestDownSuperarc] = bestUpSuperarc;
227  } // up is more senior
228  else // all other cases, go the opposite way - NB: assumes we will never have the same superarc twice
229  { // down is more senior
230  branchRoot[bestUpSuperarc] = bestDownSuperarc;
231  } // down is more senior
232  } // per supernode
233  */
234  } // operator()()
235 
236 
237 }; // CollapseBranchesWorklet
238 
239 } // namespace hierarchical_volumetric_branch_decomposer
240 } // namespace scalar_topology
241 } // namespace worklet
242 } // namespace vtkm
243 
244 #endif
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::CollapseBranchesWorklet::CollapseBranchesWorklet
VTKM_EXEC_CONT CollapseBranchesWorklet()
Default Constructor.
Definition: CollapseBranchesWorklet.h:80
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::scalar_topology::hierarchical_volumetric_branch_decomposer::CollapseBranchesWorklet::ExecutionSignature
void(InputIndex, _1, _2, _3, _4, _5, _6, _7) ExecutionSignature
Definition: CollapseBranchesWorklet.h:75
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::CollapseBranchesWorklet::operator()
VTKM_EXEC void operator()(const vtkm::Id &supernode, const vtkm::Id &bestUpSupernodeId, const vtkm::Id &bestDownSupernodeId, const ExecObjectType1 &findRegularByGlobal, const ExecObjectType2 &findSuperArcBetweenNodes, const InFieldPortalType &hierarchicalTreeRegular2supernodePortal, const InFieldPortalType &hierarchicalTreeWhichRoundPortal, const InOutFieldPortalType &branchRootPortal) const
operator() of the workelt
Definition: CollapseBranchesWorklet.h:87
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::CollapseBranchesWorklet::ControlSignature
void(FieldIn bestUpSupernode, FieldIn bestDownSupernode, ExecObject findRegularByGlobal, ExecObject findSuperArcBetweenNodes, WholeArrayIn hierarchicalTreeRegular2supernode, WholeArrayIn hierarchicalTreeWhichRound, WholeArrayInOut branchRoot) ControlSignature
Control signature for the worklet.
Definition: CollapseBranchesWorklet.h:74
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::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::CollapseBranchesWorklet::InputDomain
_1 InputDomain
Definition: CollapseBranchesWorklet.h:76
Types.h
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::CollapseBranchesWorklet
Definition: CollapseBranchesWorklet.h:61
vtkm::exec::arg::InputIndex
The ExecutionSignature tag to use to get the input index.
Definition: InputIndex.h:42
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38