VTK-m  2.0
SuperArcVolumetricComparatorIndirectGlobalIdComparator.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 // SuperArcVolumetricComparatorIndirectGlobalID.h - a comparator for sorting superarcs by volume
43 // Has to take a flag for high end vs. low end sorting
44 // Also, this version takes supernode IDs rather than global IDs, so has an extra indirection
45 //
46 //=======================================================================================
47 //
48 // COMMENTS:
49 //
50 // A comparator that sorts superarc pairs by:
51 // 1. ID of low end vertex
52 // 2. volumetric measure at low end
53 // 3. global index of upper end, OR
54 //
55 // the same for the higher end.
56 //
57 // Notice that 2. only applies if two edges share a lower end and have the same volume.
58 // We then look at the index at the upper end to see which is "furthest" from the low end
59 //
60 //=======================================================================================
61 
62 #ifndef vtk_m_filter_scalar_topology_worklet_branch_decomposition_hierarchical_volumetric_branch_decomposer_SuperarcVolumetricComparatorIndirectGlobalIdComparator_h
63 #define vtk_m_filter_scalar_topology_worklet_branch_decomposition_hierarchical_volumetric_branch_decomposer_SuperarcVolumetricComparatorIndirectGlobalIdComparator_h
64 
65 #include <vtkm/cont/ArrayHandle.h>
68 
69 namespace vtkm
70 {
71 namespace worklet
72 {
73 namespace scalar_topology
74 {
75 namespace hierarchical_volumetric_branch_decomposer
76 {
77 
80 {
81 public:
82  using IdArrayPortalType =
86 
87  // constructor
88  VTKM_CONT
90  IdArrayPortalType weightPortal,
91  EdgePairArrayPortalType superarcListPortal,
92  IdArrayPortalType globalIdPortal,
93  bool pairsAtLowEnd)
94  : WeightPortal(weightPortal)
95  , SuperarcListPortal(superarcListPortal)
96  , GlobalIdPortal(globalIdPortal)
97  , PairsAtLowEnd(pairsAtLowEnd)
98  { // constructor
99  } // constructor
100 
101  // () operator - gets called to do comparison
102  VTKM_EXEC
103  bool operator()(const vtkm::Id& left, const vtkm::Id& right) const
104  { // operator()
105  // get local references to the edge details
108 
109  if (this->PairsAtLowEnd)
110  { // pairs at low end
111  // test by low end ID
112  if (edgeLeft.first < edgeRight.first)
113  {
114  return true;
115  }
116  if (edgeLeft.first > edgeRight.first)
117  {
118  return false;
119  }
120 
121  // test by volumetric measure
122  vtkm::Id weightLeft = this->WeightPortal.Get(left);
123  vtkm::Id weightRight = this->WeightPortal.Get(right);
124  if (weightLeft < weightRight)
125  return true;
126  if (weightLeft > weightRight)
127  return false;
128 
129  // test by the global ID - we were past a supernode ID, so there's an
130  // extra level of indirection
131  vtkm::Id globalIdLeftEdgeSecond = this->GlobalIdPortal.Get(edgeLeft.second);
132  vtkm::Id globalIdRightEdgeSecond = this->GlobalIdPortal.Get(edgeRight.second);
133  if (globalIdLeftEdgeSecond < globalIdRightEdgeSecond)
134  {
135  return true;
136  }
137  if (globalIdLeftEdgeSecond > globalIdRightEdgeSecond)
138  {
139  return false;
140  }
141 
142  // fallback
143  return false;
144  } // pairs at low end
145  else
146  { // pairs at high end
147  // test by high end ID
148  if (edgeLeft.second < edgeRight.second)
149  {
150  return true;
151  }
152  if (edgeLeft.second > edgeRight.second)
153  {
154  return false;
155  }
156 
157  // test by volumetric measure
158  vtkm::Id weightLeft = this->WeightPortal.Get(left);
159  vtkm::Id weightRight = this->WeightPortal.Get(right);
160  if (weightLeft < weightRight)
161  {
162  return true;
163  }
164  if (weightLeft > weightRight)
165  {
166  return false;
167  }
168 
169  // test by the global ID - we were past a supernode ID, so there's an
170  // extra level of indirection
171  // Note the reversal from above - we want the greatest difference, not
172  // the greatest value
173  vtkm::Id globalIdLeftEdgeFirst = this->GlobalIdPortal.Get(edgeLeft.first);
174  vtkm::Id globalIdRightEdgeFirst = this->GlobalIdPortal.Get(edgeRight.first);
175  if (globalIdLeftEdgeFirst > globalIdRightEdgeFirst)
176  {
177  return true;
178  }
179  if (globalIdLeftEdgeFirst < globalIdRightEdgeFirst)
180  {
181  return false;
182  }
183 
184  // fallback
185  return false;
186  } // pairs at high end
187  } // operator()
188 
189 private:
194 }; // SuperArcVolumetricComparatorIndirectGlobalIdComparatorImpl
195 
196 
206 {
207 public:
208  // constructor - takes vectors as parameters
209  VTKM_CONT
214  bool pairsAtLowEnd)
215  : Weight(weight)
216  , SuperarcList(superarcList)
217  , GlobalId(globalId)
218  , PairsAtLowEnd(pairsAtLowEnd)
219  { // constructor
220  } // constructor
221 
225  {
227  this->Weight.PrepareForInput(device, token),
228  this->SuperarcList.PrepareForInput(device, token),
229  this->GlobalId.PrepareForInput(device, token),
230  this->PairsAtLowEnd);
231  }
232 
233 private:
238 }; // SuperArcVolumetricComparatorIndirectGlobalIdComparator
239 
240 } // namespace hierarchical_volumetric_branch_decomposer
241 } // namespace scalar_topology
242 } // namespace worklet
243 } // namespace vtkm
244 
245 #endif
vtkm::cont::ArrayHandle< vtkm::Id >
ArrayHandle.h
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::SuperArcVolumetricComparatorIndirectGlobalIdComparator::GlobalId
vtkm::worklet::contourtree_augmented::IdArrayType GlobalId
Definition: SuperArcVolumetricComparatorIndirectGlobalIdComparator.h:236
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::SuperArcVolumetricComparatorIndirectGlobalIdComparatorImpl::PairsAtLowEnd
bool PairsAtLowEnd
Definition: SuperArcVolumetricComparatorIndirectGlobalIdComparator.h:193
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::scalar_topology::hierarchical_volumetric_branch_decomposer::SuperArcVolumetricComparatorIndirectGlobalIdComparator::PairsAtLowEnd
bool PairsAtLowEnd
Definition: SuperArcVolumetricComparatorIndirectGlobalIdComparator.h:237
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::SuperArcVolumetricComparatorIndirectGlobalIdComparatorImpl::WeightPortal
IdArrayPortalType WeightPortal
Definition: SuperArcVolumetricComparatorIndirectGlobalIdComparator.h:190
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::scalar_topology::hierarchical_volumetric_branch_decomposer::SuperArcVolumetricComparatorIndirectGlobalIdComparatorImpl
Implementation of the comparator for the SuperArcVolumetricComparatorIndirectGlobalId ExecutionObject...
Definition: SuperArcVolumetricComparatorIndirectGlobalIdComparator.h:79
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::SuperArcVolumetricComparatorIndirectGlobalIdComparatorImpl::EdgePairArrayPortalType
typename vtkm::worklet::contourtree_augmented::EdgePairArray::ReadPortalType EdgePairArrayPortalType
Definition: SuperArcVolumetricComparatorIndirectGlobalIdComparator.h:85
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::SuperArcVolumetricComparatorIndirectGlobalIdComparatorImpl::SuperarcListPortal
EdgePairArrayPortalType SuperarcListPortal
Definition: SuperArcVolumetricComparatorIndirectGlobalIdComparator.h:191
vtkm::cont::ArrayHandle< vtkm::Id >::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::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::SuperArcVolumetricComparatorIndirectGlobalIdComparatorImpl::SuperArcVolumetricComparatorIndirectGlobalIdComparatorImpl
VTKM_CONT SuperArcVolumetricComparatorIndirectGlobalIdComparatorImpl(IdArrayPortalType weightPortal, EdgePairArrayPortalType superarcListPortal, IdArrayPortalType globalIdPortal, bool pairsAtLowEnd)
Definition: SuperArcVolumetricComparatorIndirectGlobalIdComparator.h:89
vtkm::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::SuperArcVolumetricComparatorIndirectGlobalIdComparatorImpl::IdArrayPortalType
typename vtkm::worklet::contourtree_augmented::IdArrayType::ReadPortalType IdArrayPortalType
Definition: SuperArcVolumetricComparatorIndirectGlobalIdComparator.h:83
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::SuperArcVolumetricComparatorIndirectGlobalIdComparatorImpl::operator()
VTKM_EXEC bool operator()(const vtkm::Id &left, const vtkm::Id &right) const
Definition: SuperArcVolumetricComparatorIndirectGlobalIdComparator.h:103
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::SuperArcVolumetricComparatorIndirectGlobalIdComparatorImpl::GlobalIdPortal
IdArrayPortalType GlobalIdPortal
Definition: SuperArcVolumetricComparatorIndirectGlobalIdComparator.h:192
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::SuperArcVolumetricComparatorIndirectGlobalIdComparator::PrepareForExecution
VTKM_CONT SuperArcVolumetricComparatorIndirectGlobalIdComparatorImpl PrepareForExecution(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const
Create a SuperArcVolumetricComparatorIndirectGlobalIdComparatorImpl object for use in the sort or wor...
Definition: SuperArcVolumetricComparatorIndirectGlobalIdComparator.h:224
vtkm::Pair::first
FirstType first
The pair's first object.
Definition: Pair.h:50
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::SuperArcVolumetricComparatorIndirectGlobalIdComparator::SuperArcVolumetricComparatorIndirectGlobalIdComparator
VTKM_CONT SuperArcVolumetricComparatorIndirectGlobalIdComparator(const vtkm::worklet::contourtree_augmented::IdArrayType &weight, const vtkm::worklet::contourtree_augmented::EdgePairArray &superarcList, const vtkm::worklet::contourtree_augmented::IdArrayType &globalId, bool pairsAtLowEnd)
Definition: SuperArcVolumetricComparatorIndirectGlobalIdComparator.h:210
Types.h
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::SuperArcVolumetricComparatorIndirectGlobalIdComparator::Weight
vtkm::worklet::contourtree_augmented::IdArrayType Weight
Definition: SuperArcVolumetricComparatorIndirectGlobalIdComparator.h:234
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::scalar_topology::hierarchical_volumetric_branch_decomposer::SuperArcVolumetricComparatorIndirectGlobalIdComparator::SuperarcList
vtkm::worklet::contourtree_augmented::EdgePairArray SuperarcList
Definition: SuperArcVolumetricComparatorIndirectGlobalIdComparator.h:235
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::SuperArcVolumetricComparatorIndirectGlobalIdComparator
Execution object for Compartor used in HierarchicalVolumetricBranchDecomposer<FieldType>::LocalBestUp...
Definition: SuperArcVolumetricComparatorIndirectGlobalIdComparator.h:204
ExecutionObjectBase.h
vtkm::Pair
A vtkm::Pair is essentially the same as an STL pair object except that the methods (constructors and ...
Definition: Pair.h:29
vtkm::Pair::second
SecondType second
The pair's second object.
Definition: Pair.h:55