VTK-m  2.0
AttachmentSuperparentAndIndexComparator.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 // COMMENTS:
43 //
44 // A comparator that sorts supernode pairs by:
45 // 1. the superparent round
46 // 2. global regular Id
47 // 3. supernode Id (if any)
48 //
49 // We don't care about the orientation of the superarc for this comparator
50 //
51 // For duplicates, we assume that at MOST one (in fact, it should always be EXACTLY one)
52 // copy has a supernode Id set. This is because when we exchange between blocks, we set
53 // the supernode Id to NO_SUCH_ELEMENT. That way, only the copy that belongs on the block
54 // has the supernode Id set. We want to ensure that it appears at the beginning of the segment,
55 // and don't care about the ordering of any others.
56 //
57 //=======================================================================================
58 
59 
60 #ifndef vtk_m_worklet_contourtree_distributed_hierarchical_hyper_augmenter_attachment_superparent_and_index_comparator_h
61 #define vtk_m_worklet_contourtree_distributed_hierarchical_hyper_augmenter_attachment_superparent_and_index_comparator_h
62 
63 #include <vtkm/cont/ArrayHandle.h>
66 
67 namespace vtkm
68 {
69 namespace worklet
70 {
71 namespace contourtree_distributed
72 {
73 namespace hierarchical_augmenter
74 {
75 
76 
82 {
83 public:
84  using IdArrayPortalType =
86 
87  // constructor
88  VTKM_CONT
90  IdArrayPortalType globalRegularIdsPortal,
91  IdArrayPortalType supernodeIdsPortal)
92  : SuperparentsPortal(superparentsPortal)
93  , GlobalRegularIdsPortal(globalRegularIdsPortal)
94  , SupernodeIdsPortal(supernodeIdsPortal)
95  { // constructor
96  } // constructor
97 
98  // () operator - gets called to do comparison
99  VTKM_EXEC
100  bool operator()(const vtkm::Id& left, const vtkm::Id& right) const
101  { // operator()
102  // optimisation for sorts which compare an element with itself
103  // if the element compares with itself, always return false (it's not less than itself)
104  if (left == right)
105  {
106  return false;
107  }
108  // first comparison is on superparent WITHOUT ascending descending flag
110  vtkm::worklet::contourtree_augmented::MaskedIndex(this->SuperparentsPortal.Get(right)))
111  {
112  return true;
113  }
115  vtkm::worklet::contourtree_augmented::MaskedIndex(this->SuperparentsPortal.Get(right)))
116  {
117  return false;
118  }
119 
120  // second comparison is on global regular Id
121  if (this->GlobalRegularIdsPortal.Get(left) < this->GlobalRegularIdsPortal.Get(right))
122  {
124  }
125  if (this->GlobalRegularIdsPortal.Get(left) > this->GlobalRegularIdsPortal.Get(right))
126  {
128  }
129 
130  // it now depends on whether they have actual IDs (ie they are on this block anyway)
132  { // left does not exist
134  { // right does not exist
135  // neither exists: sort on input indices instead
136  return (left < right);
137  } // right does not exist
138  else
139  { // right does exist
140  // right exists but left doesn't - sort right lower
141  return false;
142  } // right does exist
143  } // left does not exist
144  else
145  { // left does exist
147  { // right does not exist
148  // left exists but right doesn't - sort left lower
149  return true;
150  } // right does not exist
151  else
152  { // right does exist
153  // both exist
154  return (this->SupernodeIdsPortal.Get(left) < this->SupernodeIdsPortal.Get(right));
155  } // right does exist
156  } // left does exist
157  } // operator()
158 
159 private:
163 }; // AttachmentSuperparentAndIndexComparatorImpl
164 
165 
171 {
172 public:
173  // constructor - takes vectors as parameters
174  VTKM_CONT
179  : Superparents(superparents)
180  , GlobalRegularIds(globalRegularIds)
181  , SupernodeIds(supernodeIds)
182  { // constructor
183  } // constructor
184 
188  {
190  this->Superparents.PrepareForInput(device, token),
191  this->GlobalRegularIds.PrepareForInput(device, token),
192  this->SupernodeIds.PrepareForInput(device, token));
193  }
194 
195 private:
202 }; // AttachmentSuperparentAndIndexComparator
203 
204 } // namespace hierarchical_augmenter
205 } // namespace contourtree_distributed
206 } // namespace worklet
207 } // namespace vtkm
208 
209 #endif
vtkm::worklet::contourtree_distributed::hierarchical_augmenter::AttachmentSuperparentAndIndexComparator::SupernodeIds
vtkm::worklet::contourtree_augmented::IdArrayType SupernodeIds
the supernode Id for tiebreak
Definition: AttachmentSuperparentAndIndexComparator.h:201
vtkm::worklet::contourtree_distributed::hierarchical_augmenter::AttachmentSuperparentAndIndexComparator::Superparents
vtkm::worklet::contourtree_augmented::IdArrayType Superparents
the superparent Id
Definition: AttachmentSuperparentAndIndexComparator.h:197
vtkm::cont::ArrayHandle< vtkm::Id >
vtkm::worklet::contourtree_augmented::IsAscending
VTKM_EXEC_CONT bool IsAscending(vtkm::Id flaggedIndex)
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:121
ArrayHandle.h
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
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_augmented::MaskedIndex
VTKM_EXEC_CONT vtkm::Id MaskedIndex(vtkm::Id flaggedIndex)
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:127
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::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
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::hierarchical_augmenter::AttachmentSuperparentAndIndexComparatorImpl::SuperparentsPortal
IdArrayPortalType SuperparentsPortal
Definition: AttachmentSuperparentAndIndexComparator.h:160
vtkm::worklet::contourtree_distributed::hierarchical_augmenter::AttachmentSuperparentAndIndexComparatorImpl
Implementation for a comparator that sorts supernode pairs by:
Definition: AttachmentSuperparentAndIndexComparator.h:81
vtkm::worklet::contourtree_distributed::hierarchical_augmenter::AttachmentSuperparentAndIndexComparatorImpl::SupernodeIdsPortal
IdArrayPortalType SupernodeIdsPortal
Definition: AttachmentSuperparentAndIndexComparator.h:162
vtkm::worklet::contourtree_distributed::hierarchical_augmenter::AttachmentSuperparentAndIndexComparator::GlobalRegularIds
vtkm::worklet::contourtree_augmented::IdArrayType GlobalRegularIds
the global rergular Id for tiebreak
Definition: AttachmentSuperparentAndIndexComparator.h:199
vtkm::worklet::contourtree_distributed::hierarchical_augmenter::AttachmentSuperparentAndIndexComparator::AttachmentSuperparentAndIndexComparator
VTKM_CONT AttachmentSuperparentAndIndexComparator(const vtkm::worklet::contourtree_augmented::IdArrayType superparents, const vtkm::worklet::contourtree_augmented::IdArrayType globalRegularIds, const vtkm::worklet::contourtree_augmented::IdArrayType supernodeIds)
Definition: AttachmentSuperparentAndIndexComparator.h:175
Types.h
vtkm::worklet::contourtree_distributed::hierarchical_augmenter::AttachmentSuperparentAndIndexComparatorImpl::GlobalRegularIdsPortal
IdArrayPortalType GlobalRegularIdsPortal
Definition: AttachmentSuperparentAndIndexComparator.h:161
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::worklet::contourtree_distributed::hierarchical_augmenter::AttachmentSuperparentAndIndexComparatorImpl::AttachmentSuperparentAndIndexComparatorImpl
VTKM_CONT AttachmentSuperparentAndIndexComparatorImpl(IdArrayPortalType superparentsPortal, IdArrayPortalType globalRegularIdsPortal, IdArrayPortalType supernodeIdsPortal)
Definition: AttachmentSuperparentAndIndexComparator.h:89
vtkm::worklet::contourtree_distributed::hierarchical_augmenter::AttachmentSuperparentAndIndexComparator
Execution object for a comparator that sorts supernode pairs by:
Definition: AttachmentSuperparentAndIndexComparator.h:170
vtkm::worklet::contourtree_distributed::hierarchical_augmenter::AttachmentSuperparentAndIndexComparator::PrepareForExecution
VTKM_CONT AttachmentSuperparentAndIndexComparatorImpl PrepareForExecution(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const
Create a AttachmentSuperparentAndIndexComparatorImpl object for use in the sort or worklet.
Definition: AttachmentSuperparentAndIndexComparator.h:187
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_distributed::hierarchical_augmenter::AttachmentSuperparentAndIndexComparatorImpl::operator()
VTKM_EXEC bool operator()(const vtkm::Id &left, const vtkm::Id &right) const
Definition: AttachmentSuperparentAndIndexComparator.h:100
ExecutionObjectBase.h
vtkm::worklet::contourtree_distributed::hierarchical_augmenter::AttachmentSuperparentAndIndexComparatorImpl::IdArrayPortalType
typename vtkm::worklet::contourtree_augmented::IdArrayType::ReadPortalType IdArrayPortalType
Definition: AttachmentSuperparentAndIndexComparator.h:85