1 //============================================================================
2 //  Copyright (c) Kitware, Inc.
3 //  All rights reserved.
4 //  See LICENSE.txt for details.
5 //  This software is distributed WITHOUT ANY WARRANTY; without even
6 //  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7 //  PURPOSE.  See the above copyright notice for more information.
8 //
9 //  Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
10 //  Copyright 2014 UT-Battelle, LLC.
11 //  Copyright 2014 Los Alamos National Security.
12 //
13 //  Under the terms of Contract DE-NA0003525 with NTESS,
14 //  the U.S. Government retains certain rights in this software.
15 //
16 //  Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
17 //  Laboratory (LANL), the U.S. Government retains certain rights in
18 //  this software.
19 //============================================================================
20 //  Copyright (c) 2016, Los Alamos National Security, LLC
21 //  All rights reserved.
22 //
23 //  Copyright 2016. Los Alamos National Security, LLC.
24 //  This software was produced under U.S. Government contract DE-AC52-06NA25396
25 //  for Los Alamos National Laboratory (LANL), which is operated by
26 //  Los Alamos National Security, LLC for the U.S. Department of Energy.
27 //  The U.S. Government has rights to use, reproduce, and distribute this
28 //  software.  NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
29 //  MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
30 //  USE OF THIS SOFTWARE.  If software is modified to produce derivative works,
31 //  such modified software should be clearly marked, so as not to confuse it
32 //  with the version available from LANL.
33 //
34 //  Additionally, redistribution and use in source and binary forms, with or
35 //  without modification, are permitted provided that the following conditions
36 //  are met:
37 //
38 //  1. Redistributions of source code must retain the above copyright notice,
39 //     this list of conditions and the following disclaimer.
40 //  2. Redistributions in binary form must reproduce the above copyright notice,
41 //     this list of conditions and the following disclaimer in the documentation
42 //     and/or other materials provided with the distribution.
43 //  3. Neither the name of Los Alamos National Security, LLC, Los Alamos
44 //     National Laboratory, LANL, the U.S. Government, nor the names of its
45 //     contributors may be used to endorse or promote products derived from
46 //     this software without specific prior written permission.
47 //
48 //  THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
49 //  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
50 //  BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
51 //  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
52 //  NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
53 //  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
54 //  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
55 //  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
56 //  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
57 //  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
58 //  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 //============================================================================
60 
61 //  This code is based on the algorithm presented in the paper:
62 //  “Parallel Peak Pruning for Scalable SMP Contour Tree Computation.”
63 //  Hamish Carr, Gunther Weber, Christopher Sewell, and James Ahrens.
64 //  Proceedings of the IEEE Symposium on Large Data Analysis and Visualization
65 //  (LDAV), October 2016, Baltimore, Maryland.
66 
67 #ifndef vtkm_worklet_contourtree_regular_to_candidate_h
68 #define vtkm_worklet_contourtree_regular_to_candidate_h
69 
70 #include "vtkm/worklet/contourtree/Types.h"
71 #include <vtkm/worklet/WorkletMapField.h>
72 
73 namespace vtkm
74 {
75 namespace worklet
76 {
77 namespace contourtree
78 {
79 
80 // Worklet for doing regular to candidate
81 class RegularToCandidate : public vtkm::worklet::WorkletMapField
82 {
83 public:
84   using ControlSignature = void(FieldIn<IdType> vertexId,       // (input) vertex id of candidate
85                                 WholeArrayIn<IdType> mergeArcs, // (input) merge arcs
86                                 WholeArrayIn<IdType> regularToCritical, // (input) sorting indices
87                                 FieldOut<IdType> sortVector); // (output) target for write back
88   using ExecutionSignature = _4(_1, _2, _3);
89   using InputDomain = _1;
90 
91   // Constructor
92   VTKM_EXEC_CONT
RegularToCandidate()93   RegularToCandidate() {}
94 
95   template <typename InFieldPortalType>
operator()96   VTKM_EXEC vtkm::Id operator()(const vtkm::Id& vertexID,
97                                 const InFieldPortalType& mergeArcs,
98                                 const InFieldPortalType& regularToCritical) const
99   {
100     vtkm::Id sortVector;
101 
102     // copy the mergeArc ID
103     vtkm::Id joinNeighbour = mergeArcs.Get(vertexID);
104 
105     // if it's the root vertex
106     if (joinNeighbour == NO_VERTEX_ASSIGNED)
107       // set it to the sentinel value
108       sortVector = NO_VERTEX_ASSIGNED;
109     else
110       // otherwise convert to a candidate ID & save
111       sortVector = regularToCritical.Get(joinNeighbour);
112     return sortVector;
113   }
114 }; // RegularToCandidate
115 }
116 }
117 }
118 
119 #endif
120