VTK-m  2.0
FindGoverningSaddlesWorklet.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 
54 #ifndef vtk_m_worklet_contourtree_augmented_active_graph_find_governing_saddles_worklet_h
55 #define vtk_m_worklet_contourtree_augmented_active_graph_find_governing_saddles_worklet_h
56 
59 
60 
61 namespace vtkm
62 {
63 namespace worklet
64 {
65 namespace contourtree_augmented
66 {
67 namespace active_graph_inc
68 {
69 
70 
71 // Worklet for computing the sort indices from the sort order
73 {
74 public:
75  typedef void ControlSignature(FieldIn edgeNo, // (input) edge number
76  WholeArrayInOut edgeSorter, // (input/output) edge sorter
77  WholeArrayIn edgeFar, // (input) edge far
78  WholeArrayIn edgeNear, // (input) edge near
79  WholeArrayOut hyperarcs, // (output) hyperarcs
80  WholeArrayOut outdegree); // (output) outdegree
81  typedef void ExecutionSignature(_1, _2, _3, _4, _5, _6);
82  using InputDomain = _1;
83 
84  // Default Constructor
87 
88  template <typename InOutFieldPortalType, typename InFieldPortalType, typename OutFieldPortalType>
89  VTKM_EXEC void operator()(const vtkm::Id& edgeNo,
90  const InOutFieldPortalType& edgeSorterPortal,
91  const InFieldPortalType& edgeFarPortal,
92  const InFieldPortalType& edgeNearPortal,
93  const OutFieldPortalType& hyperarcsPortal,
94  const OutFieldPortalType& outdegreePortal) const
95  {
96  // default to true
97  bool isBestSaddleEdge = true;
98  // retrieve the edge ID
99  vtkm::Id edge = edgeSorterPortal.Get(edgeNo);
100 
101  // edge no. 0 is always best, so skip it
102  if (edgeNo != 0)
103  { // edge != 0
104  // retrieve the previous edge
105  vtkm::Id prevEdge = edgeSorterPortal.Get(edgeNo - 1);
106  // if the previous edge has the same far end
107  if (edgeFarPortal.Get(prevEdge) == edgeFarPortal.Get(edge))
108  isBestSaddleEdge = false;
109  } // edge != 0
110 
111  if (isBestSaddleEdge)
112  { // found an extremum
113  // retrieve the near end as the saddle
114  vtkm::Id saddle = edgeNearPortal.Get(edge);
115  // and the far end as the extremum
116  vtkm::Id extreme = edgeFarPortal.Get(edge);
117 
118  // we can now set the hyperarc for the extremum
119  // we do this by setting it to point to the saddle
120  // and setting it's IS_HYPERNODE and IS_SUPERNODE flags
121  hyperarcsPortal.Set(extreme, saddle | IS_HYPERNODE | IS_SUPERNODE);
122 
123  // and set the outdegree to 0
124  outdegreePortal.Set(extreme, 0);
125 
126  // NEW! NEW! NEW!
127  // we now also know that the lower end is a supernode
128  // so we set it's flag as well - this allows us to identify real saddles
129  // versus mere candidates
130  // NB: there may be write collisions, but they are all setting the
131  // flag on, so the collision is acceptable
132  hyperarcsPortal.Set(saddle, hyperarcsPortal.Get(saddle) | IS_SUPERNODE);
133  } // found a extremum
134 
135  // This worklet implements the following from the OpenMP version
136  /*for (indexType edgeNo = 0; edgeNo < edgeSorter.size(); edgeNo++)
137  { // per edge
138  // default to true
139  bool isBestSaddleEdge = true;
140  // retrieve the edge ID
141  indexType edge = edgeSorter[edgeNo];
142 
143  // edge no. 0 is always best, so skip it
144  if (edgeNo != 0)
145  { // edge != 0
146  // retrieve the previous edge
147  indexType prevEdge = edgeSorter[edgeNo-1];
148  // if the previous edge has the same far end
149  if (edgeFar[prevEdge] == edgeFar[edge])
150  isBestSaddleEdge = false;
151  } // edge != 0
152 
153  if (isBestSaddleEdge)
154  { // found an extremum
155  // retrieve the near end as the saddle
156  indexType saddle = edgeNear[edge];
157  // and the far end as the extremum
158  indexType extreme = edgeFar[edge];
159 
160  // we can now set the hyperarc for the extremum
161  // we do this by setting it to point to the saddle
162  // and setting it's IS_HYPERNODE and IS_SUPERNODE flags
163  hyperarcs[extreme] = saddle | IS_HYPERNODE | IS_SUPERNODE;
164 
165  // and set the outdegree to 0
166  outdegree[extreme] = 0;
167 
168  // NEW! NEW! NEW!
169  // we now also know that the lower end is a supernode
170  // so we set it's flag as well - this allows us to identify real saddles
171  // versus mere candidates
172  // NB: there may be write collisions, but they are all setting the
173  // flag on, so the collision is acceptable
174  hyperarcs[saddle] |= IS_SUPERNODE;
175  } // found a extremum
176  } // per edge */
177  }
178 }; // FindGoverningSaddlesWorklet
179 
180 
181 } // namespace active_graph_inc
182 } // namespace contourtree_augmented
183 } // namespace worklet
184 } // namespace vtkm
185 
186 #endif
vtkm::worklet::contourtree_augmented::active_graph_inc::FindGoverningSaddlesWorklet::ExecutionSignature
void ExecutionSignature(_1, _2, _3, _4, _5, _6)
Definition: FindGoverningSaddlesWorklet.h:81
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::FindGoverningSaddlesWorklet
Definition: FindGoverningSaddlesWorklet.h:72
WorkletMapField.h
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::worklet::contourtree_augmented::active_graph_inc::FindGoverningSaddlesWorklet::operator()
VTKM_EXEC void operator()(const vtkm::Id &edgeNo, const InOutFieldPortalType &edgeSorterPortal, const InFieldPortalType &edgeFarPortal, const InFieldPortalType &edgeNearPortal, const OutFieldPortalType &hyperarcsPortal, const OutFieldPortalType &outdegreePortal) const
Definition: FindGoverningSaddlesWorklet.h:89
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
vtkm::worklet::contourtree_augmented::active_graph_inc::FindGoverningSaddlesWorklet::FindGoverningSaddlesWorklet
VTKM_EXEC_CONT FindGoverningSaddlesWorklet()
Definition: FindGoverningSaddlesWorklet.h:86
Types.h
vtkm::worklet::contourtree_augmented::IS_SUPERNODE
constexpr vtkm::Id IS_SUPERNODE
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:75
vtkm::worklet::contourtree_augmented::active_graph_inc::FindGoverningSaddlesWorklet::InputDomain
_1 InputDomain
Definition: FindGoverningSaddlesWorklet.h:82
vtkm::worklet::contourtree_augmented::active_graph_inc::FindGoverningSaddlesWorklet::ControlSignature
void ControlSignature(FieldIn edgeNo, WholeArrayInOut edgeSorter, WholeArrayIn edgeFar, WholeArrayIn edgeNear, WholeArrayOut hyperarcs, WholeArrayOut outdegree)
Definition: FindGoverningSaddlesWorklet.h:75
vtkm::worklet::contourtree_augmented::IS_HYPERNODE
constexpr vtkm::Id IS_HYPERNODE
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:76
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38