VTK-m  2.0
EdgePeakComparator.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) 2016, Los Alamos National Security, LLC
11 // All rights reserved.
12 //
13 // Copyright 2016. Los Alamos National Security, LLC.
14 // This software was produced under U.S. Government contract DE-AC52-06NA25396
15 // for Los Alamos National Laboratory (LANL), which is operated by
16 // Los Alamos National Security, LLC for the U.S. Department of Energy.
17 // The U.S. Government has rights to use, reproduce, and distribute this
18 // software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
19 // MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
20 // USE OF THIS SOFTWARE. If software is modified to produce derivative works,
21 // such modified software should be clearly marked, so as not to confuse it
22 // with the version available from LANL.
23 //
24 // Additionally, redistribution and use in source and binary forms, with or
25 // without modification, are permitted provided that the following conditions
26 // are met:
27 //
28 // 1. Redistributions of source code must retain the above copyright notice,
29 // this list of conditions and the following disclaimer.
30 // 2. Redistributions in binary form must reproduce the above copyright notice,
31 // this list of conditions and the following disclaimer in the documentation
32 // and/or other materials provided with the distribution.
33 // 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
34 // National Laboratory, LANL, the U.S. Government, nor the names of its
35 // contributors may be used to endorse or promote products derived from
36 // this software without specific prior written permission.
37 //
38 // THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
39 // CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
40 // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
41 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
42 // NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
43 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
45 // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
46 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
47 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
48 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49 //============================================================================
50 
51 // This code is based on the algorithm presented in the paper:
52 // “Parallel Peak Pruning for Scalable SMP Contour Tree Computation.”
53 // Hamish Carr, Gunther Weber, Christopher Sewell, and James Ahrens.
54 // Proceedings of the IEEE Symposium on Large Data Analysis and Visualization
55 // (LDAV), October 2016, Baltimore, Maryland.
56 
57 //=======================================================================================
58 //
59 // COMMENTS:
60 //
61 // A comparator that sorts edges by:
62 // i. the chain maximum for the upper end of the edge
63 // this clusters all edges together that lead to the chain maximum
64 // ii. the index of the low end of the edge
65 // this sorts the edges for the chain max by the low end
66 //
67 // Any vector needed by the functor for lookup purposes will be passed as a parameter to
68 // the constructor and saved, with the actual function call being the operator ()
69 //
70 //=======================================================================================
71 
72 #ifndef vtkm_worklet_contourtree_edge_peak_comparator_h
73 #define vtkm_worklet_contourtree_edge_peak_comparator_h
74 
75 #include <vtkm/cont/ArrayHandle.h>
77 
78 namespace vtkm
79 {
80 namespace worklet
81 {
82 namespace contourtree
83 {
84 
85 // Comparator for edges to sort governing saddles high
86 template <typename T, typename StorageType>
88 {
89 public:
92 
93  VTKM_CONT
95  IdArrayType valueIndex,
96  IdArrayType edgeFar,
97  IdArrayType edgeNear,
98  IdArrayType arcArray,
99  bool isJoinGraph)
100  : Values(values)
101  , ValueIndex(valueIndex)
102  , EdgeFar(edgeFar)
103  , EdgeNear(edgeNear)
104  , ArcArray(arcArray)
105  , IsJoinGraph(isJoinGraph)
106  {
107  }
108 
115 
117  {
118  public:
121 
122  VTKM_CONT
124  IdPortalType valueIndex,
125  IdPortalType edgeFar,
126  IdPortalType edgeNear,
127  IdPortalType arcArray,
128  bool isJoinGraph)
129  : Values(values)
130  , ValueIndex(valueIndex)
131  , EdgeFar(edgeFar)
132  , EdgeNear(edgeNear)
133  , ArcArray(arcArray)
134  , IsJoinGraph(isJoinGraph)
135  {
136  }
137 
144 
145  VTKM_EXEC
146  bool operator()(const vtkm::Id& i, const vtkm::Id& j) const
147  {
148  // first compare the far end
149  if (this->EdgeFar.Get(i) < this->EdgeFar.Get(j))
150  return true ^ this->IsJoinGraph;
151  if (this->EdgeFar.Get(j) < this->EdgeFar.Get(i))
152  return false ^ this->IsJoinGraph;
153 
154  // the compare the values of the low end
155  vtkm::Id valueIndex1 = this->ValueIndex.Get(this->EdgeNear.Get(i));
156  vtkm::Id valueIndex2 = this->ValueIndex.Get(this->EdgeNear.Get(j));
157 
158  if (this->Values.Get(valueIndex1) < this->Values.Get(valueIndex2))
159  return true ^ this->IsJoinGraph;
160  if (this->Values.Get(valueIndex2) < this->Values.Get(valueIndex1))
161  return false ^ this->IsJoinGraph;
162 
163  // finally compare the indices
164  if (valueIndex1 < valueIndex2)
165  return true ^ this->IsJoinGraph;
166  if (valueIndex2 < valueIndex1)
167  return false ^ this->IsJoinGraph;
168 
169  if (i < j)
170  return false ^ this->IsJoinGraph;
171  if (j < i)
172  return true ^ this->IsJoinGraph;
173 
174  // fallback can happen when multiple paths end at same extremum
175  return false; //true ^ graph.isJoinGraph;
176  }
177  };
178 
180  vtkm::cont::Token& token) const
181  {
182  return ExecObject(this->Values.PrepareForInput(device, token),
183  this->ValueIndex.PrepareForInput(device, token),
184  this->EdgeFar.PrepareForInput(device, token),
185  this->EdgeNear.PrepareForInput(device, token),
186  this->ArcArray.PrepareForInput(device, token),
187  this->IsJoinGraph);
188  }
189 }; // EdgePeakComparator
190 }
191 }
192 }
193 
194 #endif
vtkm::cont::ArrayHandle< T, StorageType >
ArrayHandle.h
vtkm::worklet::contourtree::EdgePeakComparator
Definition: EdgePeakComparator.h:87
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::EdgePeakComparator::ExecObject::EdgeNear
IdPortalType EdgeNear
Definition: EdgePeakComparator.h:141
vtkm::worklet::contourtree::EdgePeakComparator::Values
ValueArrayType Values
Definition: EdgePeakComparator.h:109
vtkm::worklet::contourtree::EdgePeakComparator::ExecObject::IsJoinGraph
bool IsJoinGraph
Definition: EdgePeakComparator.h:143
vtkm::worklet::contourtree::EdgePeakComparator::ExecObject::EdgeFar
IdPortalType EdgeFar
Definition: EdgePeakComparator.h:140
vtkm::worklet::contourtree::EdgePeakComparator::ArcArray
IdArrayType ArcArray
Definition: EdgePeakComparator.h:113
vtkm::cont::ArrayHandle::PrepareForInput
VTKM_CONT ReadPortalType PrepareForInput(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const
Prepares this array to be used as an input to an operation in the execution environment.
Definition: ArrayHandle.h:574
vtkm::worklet::contourtree::EdgePeakComparator::ExecObject::Values
ValuePortalType Values
Definition: EdgePeakComparator.h:138
vtkm::worklet::contourtree::EdgePeakComparator::EdgeNear
IdArrayType EdgeNear
Definition: EdgePeakComparator.h:112
vtkm::worklet::contourtree::EdgePeakComparator::IsJoinGraph
bool IsJoinGraph
Definition: EdgePeakComparator.h:114
vtkm::cont::ArrayHandle< T, StorageType >::ReadPortalType
typename StorageType::ReadPortalType ReadPortalType
Definition: ArrayHandle.h:294
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
vtkm::worklet::contourtree::EdgePeakComparator::ExecObject
Definition: EdgePeakComparator.h:116
vtkm::worklet::contourtree::EdgePeakComparator::ValueIndex
IdArrayType ValueIndex
Definition: EdgePeakComparator.h:110
vtkm::worklet::contourtree::EdgePeakComparator::ExecObject::IdPortalType
typename IdArrayType::ReadPortalType IdPortalType
Definition: EdgePeakComparator.h:120
vtkm::worklet::contourtree::EdgePeakComparator::PrepareForExecution
VTKM_CONT ExecObject PrepareForExecution(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const
Definition: EdgePeakComparator.h:179
vtkm::worklet::contourtree::EdgePeakComparator::ExecObject::ArcArray
IdPortalType ArcArray
Definition: EdgePeakComparator.h:142
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::worklet::contourtree::EdgePeakComparator::ExecObject::ValuePortalType
typename ValueArrayType::ReadPortalType ValuePortalType
Definition: EdgePeakComparator.h:119
vtkm::cont::ExecutionObjectBase
Base ExecutionObjectBase for execution objects to inherit from so that you can use an arbitrary objec...
Definition: ExecutionObjectBase.h:31
vtkm::cont::DeviceAdapterId
Definition: DeviceAdapterTag.h:52
vtkm::worklet::contourtree::EdgePeakComparator::ExecObject::ExecObject
VTKM_CONT ExecObject(ValuePortalType values, IdPortalType valueIndex, IdPortalType edgeFar, IdPortalType edgeNear, IdPortalType arcArray, bool isJoinGraph)
Definition: EdgePeakComparator.h:123
vtkm::worklet::contourtree::EdgePeakComparator::EdgeFar
IdArrayType EdgeFar
Definition: EdgePeakComparator.h:111
vtkm::worklet::contourtree::EdgePeakComparator::ExecObject::operator()
VTKM_EXEC bool operator()(const vtkm::Id &i, const vtkm::Id &j) const
Definition: EdgePeakComparator.h:146
vtkm::worklet::contourtree::EdgePeakComparator::EdgePeakComparator
VTKM_CONT EdgePeakComparator(ValueArrayType values, IdArrayType valueIndex, IdArrayType edgeFar, IdArrayType edgeNear, IdArrayType arcArray, bool isJoinGraph)
Definition: EdgePeakComparator.h:94
ExecutionObjectBase.h
vtkm::worklet::contourtree::EdgePeakComparator::ExecObject::ValueIndex
IdPortalType ValueIndex
Definition: EdgePeakComparator.h:139