VTK-m  2.0
TransferLeafChains_TransferToContourTree.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 #ifndef vtk_m_worklet_contourtree_augmented_contourtree_maker_inc_transfer_leaf_chains_transfer_to_contour_tree_h
54 #define vtk_m_worklet_contourtree_augmented_contourtree_maker_inc_transfer_leaf_chains_transfer_to_contour_tree_h
55 
58 
59 namespace vtkm
60 {
61 namespace worklet
62 {
63 namespace contourtree_augmented
64 {
65 namespace contourtree_maker_inc
66 {
67 
68 // Worklet to transfer leaf chains to contour tree"
69 // a. for leaves (tested by degree),
70 // i. we use inbound as the hyperarc
71 // ii. we use inwards as the superarc
72 // iii.we use self as the hyperparent
73 // b. for regular vertices pointing to a leaf (test by outbound's degree),
74 // i. we use outbound as the hyperparent
75 // ii. we use inwards as the superarc
76 // c. for all other vertics
77 // ignore
79 {
80 public:
81  typedef void ControlSignature(FieldIn activeSupernodes, // (input)
82  WholeArrayOut contourTreeHyperparents, // (output)
83  WholeArrayOut contourTreeHyperarcs, // (output)
84  WholeArrayOut contourTreeSuperarcs, // (output)
85  WholeArrayOut contourTreeWhenTransferred // (output)
86  );
87 
88  typedef void ExecutionSignature(_1, InputIndex, _2, _3, _4, _5);
89  using InputDomain = _1;
90 
91  // vtkm only allows 9 parameters for the operator so we need to do these inputs manually via the constructor
99  bool isJoin;
100 
101 
102  // Default Constructor
104  const bool IsJoin,
105  const IdArrayType& outdegree,
106  const IdArrayType& indegree,
107  const IdArrayType& outbound,
108  const IdArrayType& inbound,
109  const IdArrayType& inwards,
111  vtkm::cont::Token& token)
112  : NumIterations(nIterations)
113  , isJoin(IsJoin)
114  {
115  this->OutdegreePortal = outdegree.PrepareForInput(device, token);
116  this->IndegreePortal = indegree.PrepareForInput(device, token);
117  this->OutboundPortal = outbound.PrepareForInput(device, token);
118  this->InboundPortal = inbound.PrepareForInput(device, token);
119  this->InwardsPortal = inwards.PrepareForInput(device, token);
120  }
121 
122 
123  template <typename OutFieldPortalType>
124  VTKM_EXEC void operator()(const vtkm::Id& superID,
125  const vtkm::Id /*activeID*/, // FIXME: Remove unused parameter?
126  const OutFieldPortalType& contourTreeHyperparentsPortal,
127  const OutFieldPortalType& contourTreeHyperarcsPortal,
128  const OutFieldPortalType& contourTreeSuperarcsPortal,
129  const OutFieldPortalType& contourTreeWhenTransferredPortal) const
130  {
131  if ((this->OutdegreePortal.Get(superID) == 0) && (this->IndegreePortal.Get(superID) == 1))
132  { // a leaf
133  contourTreeHyperparentsPortal.Set(superID, superID | (this->isJoin ? 0 : IS_ASCENDING));
134  contourTreeHyperarcsPortal.Set(
135  superID, MaskedIndex(this->InboundPortal.Get(superID)) | (this->isJoin ? 0 : IS_ASCENDING));
136  contourTreeSuperarcsPortal.Set(
137  superID, MaskedIndex(this->InwardsPortal.Get(superID)) | (this->isJoin ? 0 : IS_ASCENDING));
138  contourTreeWhenTransferredPortal.Set(superID, this->NumIterations | IS_HYPERNODE);
139  } // a leaf
140  else
141  { // not a leaf
142  // retrieve the out neighbour
143  vtkm::Id outNeighbour = MaskedIndex(this->OutboundPortal.Get(superID));
144 
145  // test whether outneighbour is a leaf
146  if ((this->OutdegreePortal.Get(outNeighbour) != 0) ||
147  (this->IndegreePortal.Get(outNeighbour) != 1))
148  {
149  }
150  else
151  {
152  // set superarc, &c.
153  contourTreeSuperarcsPortal.Set(superID,
154  MaskedIndex(this->InwardsPortal.Get(superID)) |
155  (this->isJoin ? 0 : IS_ASCENDING));
156  contourTreeHyperparentsPortal.Set(superID,
157  outNeighbour | (this->isJoin ? 0 : IS_ASCENDING));
158  contourTreeWhenTransferredPortal.Set(superID, this->NumIterations | IS_SUPERNODE);
159  }
160  } // not a leaf
161 
162 
163  // In serial this worklet implements the following operation
164  /*
165  for (vtkm::Id activeID = 0; activeID < activeSupernodes.GetNumberOfValues(); activeID++)
166  { // per active supernode
167  // retrieve the supernode ID
168  vtkm::Id superID = activeSupernodes[activeID];
169 
170  // test for leaf
171  if ((outdegree[superID] == 0) && (indegree[superID] == 1))
172  { // a leaf
173  contourTree.hyperparents[superID] = superID | (isJoin ? 0 : IS_ASCENDING);
174  contourTree.hyperarcs[superID] = MaskedIndex(inbound[superID]) | (isJoin ? 0 : IS_ASCENDING);
175  contourTree.superarcs[superID] = MaskedIndex(inwards[superID]) | (isJoin ? 0 : IS_ASCENDING);
176  contourTree.whenTransferred[superID] = this->NumIterations | IS_HYPERNODE;
177  } // a leaf
178  else
179  { // not a leaf
180  // retrieve the out neighbour
181  vtkm::Id outNeighbour = MaskedIndex(outbound[superID]);
182 
183  // test whether outneighbour is a leaf
184  if ((outdegree[outNeighbour] != 0) || (indegree[outNeighbour] != 1))
185  continue;
186 
187  // set superarc, &c.
188  contourTree.superarcs[superID] = MaskedIndex(inwards[superID]) | (isJoin ? 0 : IS_ASCENDING);
189  contourTree.hyperparents[superID] = outNeighbour | (isJoin ? 0 : IS_ASCENDING);
190  contourTree.whenTransferred[superID] = this->NumIterations | IS_SUPERNODE;
191  } // not a leaf
192  } // per active supernode
193 
194  */
195  }
196 
197 }; // TransferLeafChains_TransferToContourTree
198 
199 } // namespace contourtree_maker_inc
200 } // namespace contourtree_augmented
201 } // namespace worklet
202 } // namespace vtkm
203 
204 #endif
vtkm::cont::ArrayHandle< vtkm::Id >
vtkm::worklet::contourtree_augmented::contourtree_maker_inc::TransferLeafChains_TransferToContourTree::OutboundPortal
IdPortalType OutboundPortal
Definition: TransferLeafChains_TransferToContourTree.h:95
vtkm::worklet::contourtree_augmented::contourtree_maker_inc::TransferLeafChains_TransferToContourTree::isJoin
bool isJoin
Definition: TransferLeafChains_TransferToContourTree.h:99
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
WorkletMapField.h
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::contourtree_maker_inc::TransferLeafChains_TransferToContourTree::ExecutionSignature
void ExecutionSignature(_1, InputIndex, _2, _3, _4, _5)
Definition: TransferLeafChains_TransferToContourTree.h:88
vtkm::worklet::contourtree_augmented::contourtree_maker_inc::TransferLeafChains_TransferToContourTree::NumIterations
vtkm::Id NumIterations
Definition: TransferLeafChains_TransferToContourTree.h:98
vtkm::worklet::contourtree_augmented::contourtree_maker_inc::TransferLeafChains_TransferToContourTree::InputDomain
_1 InputDomain
Definition: TransferLeafChains_TransferToContourTree.h:89
vtkm::worklet::contourtree_augmented::contourtree_maker_inc::TransferLeafChains_TransferToContourTree::operator()
VTKM_EXEC void operator()(const vtkm::Id &superID, const vtkm::Id, const OutFieldPortalType &contourTreeHyperparentsPortal, const OutFieldPortalType &contourTreeHyperarcsPortal, const OutFieldPortalType &contourTreeSuperarcsPortal, const OutFieldPortalType &contourTreeWhenTransferredPortal) const
Definition: TransferLeafChains_TransferToContourTree.h:124
vtkm::worklet::contourtree_augmented::contourtree_maker_inc::TransferLeafChains_TransferToContourTree::IndegreePortal
IdPortalType IndegreePortal
Definition: TransferLeafChains_TransferToContourTree.h:94
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::ReadPortalType
typename StorageType::ReadPortalType ReadPortalType
Definition: ArrayHandle.h:294
vtkm::worklet::contourtree_augmented::contourtree_maker_inc::TransferLeafChains_TransferToContourTree::ControlSignature
void ControlSignature(FieldIn activeSupernodes, WholeArrayOut contourTreeHyperparents, WholeArrayOut contourTreeHyperarcs, WholeArrayOut contourTreeSuperarcs, WholeArrayOut contourTreeWhenTransferred)
Definition: TransferLeafChains_TransferToContourTree.h:81
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::contourtree_maker_inc::TransferLeafChains_TransferToContourTree::InwardsPortal
IdPortalType InwardsPortal
Definition: TransferLeafChains_TransferToContourTree.h:97
vtkm::worklet::contourtree_augmented::contourtree_maker_inc::TransferLeafChains_TransferToContourTree
Definition: TransferLeafChains_TransferToContourTree.h:78
vtkm::worklet::contourtree_augmented::contourtree_maker_inc::TransferLeafChains_TransferToContourTree::InboundPortal
IdPortalType InboundPortal
Definition: TransferLeafChains_TransferToContourTree.h:96
vtkm::worklet::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
vtkm::worklet::contourtree_augmented::contourtree_maker_inc::TransferLeafChains_TransferToContourTree::TransferLeafChains_TransferToContourTree
TransferLeafChains_TransferToContourTree(const vtkm::Id nIterations, const bool IsJoin, const IdArrayType &outdegree, const IdArrayType &indegree, const IdArrayType &outbound, const IdArrayType &inbound, const IdArrayType &inwards, vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token)
Definition: TransferLeafChains_TransferToContourTree.h:103
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::IS_ASCENDING
constexpr vtkm::Id IS_ASCENDING
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:77
vtkm::worklet::contourtree_augmented::contourtree_maker_inc::TransferLeafChains_TransferToContourTree::IdPortalType
vtkm::cont::ArrayHandle< vtkm::Id >::ReadPortalType IdPortalType
Definition: TransferLeafChains_TransferToContourTree.h:92
vtkm::cont::DeviceAdapterId
Definition: DeviceAdapterTag.h:52
vtkm::exec::arg::InputIndex
The ExecutionSignature tag to use to get the input index.
Definition: InputIndex.h:42
vtkm::worklet::contourtree_augmented::contourtree_maker_inc::TransferLeafChains_TransferToContourTree::OutdegreePortal
IdPortalType OutdegreePortal
Definition: TransferLeafChains_TransferToContourTree.h:93
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