VTK-m  2.0
FindBoundaryTreeSuperarcsSuperarcToWorklet.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_distributed_bract_maker_find_boundary_tree_superacrs_superarc_to_worklet_h
54 #define vtk_m_worklet_contourtree_distributed_bract_maker_find_boundary_tree_superacrs_superarc_to_worklet_h
55 
58 
59 namespace vtkm
60 {
61 namespace worklet
62 {
63 namespace contourtree_distributed
64 {
65 namespace bract_maker
66 {
67 
71 {
72 public:
73  using ControlSignature = void(WholeArrayIn bractVertexSuperset, // input
74  WholeArrayIn boundaryIndices, // input
75  WholeArrayIn boundaryTreeId, // input
76  WholeArrayIn contourtreeSuperparents, // input
77  WholeArrayIn contourtreeHyperparents, // input
78  WholeArrayIn contourtreeHyperarcs, // input
79  WholeArrayIn contourtreeSupernodes, // input
80  WholeArrayIn meshSortOrder, // input
81  WholeArrayOut treeToSuperset, // output
82  FieldOut bractSuperarcs // output
83  );
84  using ExecutionSignature = _10(InputIndex, _1, _2, _3, _4, _5, _6, _7, _8, _9);
85  using InputDomain = _1;
86 
87  // Default Constructor
90 
91  template <typename InFieldPortalType,
92  typename MeshSortOrderPortalType,
93  typename OutFieldPortalType>
95  const InFieldPortalType& bractVertexSupersetPortal,
96  const InFieldPortalType& boundaryIndicesPortal,
97  const InFieldPortalType& boundaryTreeIdPortal,
98  const InFieldPortalType& contourtreeSuperparentsPortal,
99  const InFieldPortalType& contourtreeHyperparentsPortal,
100  const InFieldPortalType& contourtreeHyperarcsPortal,
101  const InFieldPortalType& contourtreeSupernodesPortal,
102  const MeshSortOrderPortalType& meshSortOrderPortal,
103  const OutFieldPortalType& treeToSupersetPortal) const
104  {
105  // find the sort order, super- and hyper- parent
106  // vtkm::Id fromIndex = bractVertexSupersetPortal.Get(from);
107  vtkm::Id fromSort = boundaryIndicesPortal.Get(from);
108  vtkm::Id fromSuper = contourtreeSuperparentsPortal.Get(fromSort);
109  vtkm::Id fromHyper = contourtreeHyperparentsPortal.Get(fromSuper);
110 
111  // also allocate space for the from, with index, &c.
113  // vtkm::Id toIndex = vtkm::worklet::contourtree_augmented::NO_SUCH_ELEMENT; // set but not used
117 
118  // for any vertex OTHER than the one at the RHE, set these variables
119  if (from != bractVertexSupersetPortal.GetNumberOfValues() - 1)
120  { // not RHE
121  to = from + 1;
122  // toIndex = bractVertexSupersetPortal.Get(to); // set but not used
123  toSort = boundaryIndicesPortal.Get(to);
124  toSuper = contourtreeSuperparentsPortal.Get(toSort);
125  toHyper = contourtreeHyperparentsPortal.Get(toSuper);
126  } // not RHE
127 
128  // while we are here, we want to establish the mapping from the contour tree ID to the superset ID
129  // so we test whether the node is a supernode, by seeing if it's sort ID matches its superparent
130  // In the original code this was done last. We do this here first, because the values for
131  // bractSuperarcs are set by return statements, so we don't reach the end of the function
132  // and reordering the operation should be no problem.
133  if (contourtreeSupernodesPortal.Get(fromSuper) == fromSort)
134  { // supernode
135  treeToSupersetPortal.Set(fromSuper, from);
136  } // supernode
137 
138  // the easy case - there is a "hyper-neighbour" to link to
139  if (fromHyper == toHyper)
140  { // hyperparents match
141  return to; // same as bractSuperarcs.WritePortal().Set(from, to);
142  } // hyperparents match
143  // the rest: we're at the RHE of a hyperarc and need to connect onwards
144  else
145  { // hyperparents do not match
146  // retrieve the hypertarget
147  vtkm::Id hyperTarget = contourtreeHyperarcsPortal.Get(fromHyper);
148 
149  // if it's non-existent, we're at the root, in which case our from vertex becomes the root
151  { // root vertex
152  // same as bractSuperarcs.WritePortal().Set(from, NO_SUCH_ELEMENT)
154  } // root vertex
155  // otherwise it points to a supernode
156  else
157  { // not root vertex
158  // check whether the target will be in the BRACT
159  vtkm::Id regularTargetId = meshSortOrderPortal.Get(contourtreeSupernodesPortal.Get(
161  // now look up the ID in the BRACT
162  vtkm::Id bract_id = boundaryTreeIdPortal.Get(regularTargetId);
163 
164  // if it is not in the tree, then this node becomes the root
166  {
167  // same as bractSuperarcs.WritePortal().Set(from, NO_SUCH_ELEMENT)
169  }
170  // otherwise, we use the ID just retrieved
171  else
172  {
173  // same as // same as bractSuperarcs.WritePortal().Set(from, bract_it)
174  return bract_id;
175  }
176  } // not root vertex
177  } // hyperparents do not match
178 
179  // In serial this worklet implements the following operation
180  /*
181  for (indexType from = 0; from < bractVertexSuperset.size(); from++)
182  { // per vertex in boundary tree
183  // find the sort order, super- and hyper- parent
184  indexType fromIndex = bractVertexSuperset[from], fromSort = boundaryIndices[from];
185  indexType fromSuper = contourTree->superparents[fromSort], fromHyper = contourTree->hyperparents[fromSuper];
186 
187  // also allocate space for the from, with index, &c.
188  indexType to = NO_SUCH_ELEMENT, toIndex = NO_SUCH_ELEMENT, toSort = NO_SUCH_ELEMENT;
189  indexType toSuper = NO_SUCH_ELEMENT, toHyper = NO_SUCH_ELEMENT;
190 
191  // for any vertex OTHER than the one at the RHE, set these variables
192  if (from != bractVertexSuperset.size() - 1)
193  { // not RHE
194  to = from + 1;
195  toIndex = bractVertexSuperset[to];
196  toSort = boundaryIndices[to];
197  toSuper = contourTree->superparents[toSort];
198  toHyper = contourTree->hyperparents[toSuper];
199  } // not RHE
200 
201  // the easy case - there is a "hyper-neighbour" to link to
202  if (fromHyper == toHyper)
203  { // hyperparents match
204  bract->superarcs[from] = to;
205  } // hyperparents match
206  else
207  // the rest: we're at the RHE of a hyperarc and need to connect onwards
208  { // hyperparents do not match
209  // retrieve the hypertarget
210  indexType hyperTarget = contourTree->hyperarcs[fromHyper];
211 
212  // if it's non-existent, we're at the root, in which case our from vertex becomes the root
213  if (noSuchElement(hyperTarget))
214  { // root vertex
215  bract->superarcs[from] = NO_SUCH_ELEMENT;
216  } // root vertex
217  // otherwise it points to a supernode
218  else
219  { // not root vertex
220  // check whether the target will be in the BRACT
221  indexType regularTargetID = mesh->SortOrder(contourTree->supernodes[maskedIndex(hyperTarget)]);
222 
223  // now look up the ID in the BRACT
224  indexType BRACTID = boundaryTreeID[regularTargetID];
225 
226  // if it is not in the tree, then this node becomes the root
227  if (noSuchElement(BRACTID))
228  bract->superarcs[from] = NO_SUCH_ELEMENT;
229  // otherwise, we use the ID just retrieved
230  else
231  bract->superarcs[from] = BRACTID;
232 
233  } // not root vertex
234 
235  } // hyperparents do not match
236 
237  // while we are here, we want to establish the mapping from the contour tree ID to the superset ID
238  // so we test whether the node is a supernode, by seeing if it's sort ID matches its superparent
239  if (contourTree->supernodes[fromSuper] == fromSort)
240  { // supernode
241  tree2Superset[fromSuper] = from;
242  } // supernode
243  } // per vertex in boundary tree
244  */
245  } // operator()()
246 
247 }; // FindBoundaryTreeSuperarcsSuperarcToWorklet
248 
249 
250 } // namespace bract_maker
251 } // namespace contourtree_distributed
252 } // namespace worklet
253 } // namespace vtkm
254 
255 #endif
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm::worklet::contourtree_distributed::bract_maker::FindBoundaryTreeSuperarcsSuperarcToWorklet::FindBoundaryTreeSuperarcsSuperarcToWorklet
VTKM_EXEC_CONT FindBoundaryTreeSuperarcsSuperarcToWorklet()
Definition: FindBoundaryTreeSuperarcsSuperarcToWorklet.h:89
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::WorkletMapField::FieldOut
A control signature tag for output fields.
Definition: WorkletMapField.h:60
vtkm::worklet::contourtree_distributed::bract_maker::FindBoundaryTreeSuperarcsSuperarcToWorklet
Compute the superarc "to" for every bract node Part of the BoundaryRestrictedAugmentedContourTree....
Definition: FindBoundaryTreeSuperarcsSuperarcToWorklet.h:70
vtkm::worklet::contourtree_distributed::bract_maker::FindBoundaryTreeSuperarcsSuperarcToWorklet::InputDomain
_1 InputDomain
Definition: FindBoundaryTreeSuperarcsSuperarcToWorklet.h:85
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::worklet::contourtree_distributed::bract_maker::FindBoundaryTreeSuperarcsSuperarcToWorklet::ExecutionSignature
_10(InputIndex, _1, _2, _3, _4, _5, _6, _7, _8, _9) ExecutionSignature
Definition: FindBoundaryTreeSuperarcsSuperarcToWorklet.h:84
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::bract_maker::FindBoundaryTreeSuperarcsSuperarcToWorklet::operator()
VTKM_EXEC vtkm::Id operator()(const vtkm::Id &from, const InFieldPortalType &bractVertexSupersetPortal, const InFieldPortalType &boundaryIndicesPortal, const InFieldPortalType &boundaryTreeIdPortal, const InFieldPortalType &contourtreeSuperparentsPortal, const InFieldPortalType &contourtreeHyperparentsPortal, const InFieldPortalType &contourtreeHyperarcsPortal, const InFieldPortalType &contourtreeSupernodesPortal, const MeshSortOrderPortalType &meshSortOrderPortal, const OutFieldPortalType &treeToSupersetPortal) const
Definition: FindBoundaryTreeSuperarcsSuperarcToWorklet.h:94
vtkm::worklet::contourtree_distributed::bract_maker::FindBoundaryTreeSuperarcsSuperarcToWorklet::ControlSignature
void(WholeArrayIn bractVertexSuperset, WholeArrayIn boundaryIndices, WholeArrayIn boundaryTreeId, WholeArrayIn contourtreeSuperparents, WholeArrayIn contourtreeHyperparents, WholeArrayIn contourtreeHyperarcs, WholeArrayIn contourtreeSupernodes, WholeArrayIn meshSortOrder, WholeArrayOut treeToSuperset, FieldOut bractSuperarcs) ControlSignature
Definition: FindBoundaryTreeSuperarcsSuperarcToWorklet.h:83
Types.h
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