VTK-m  2.0
LocalBestUpDownByVolumeWorklet.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 // The PPP2 algorithm and software were jointly developed by
42 // Hamish Carr (University of Leeds), Gunther H. Weber (LBNL), and
43 // Oliver Ruebel (LBNL)
44 //==============================================================================
45 
46 #ifndef vtk_m_filter_scalar_topology_worklet_branch_decomposition_hierarchical_volumetric_branch_decomposer_LocalBestUpDownByVolumeWorklet_h
47 #define vtk_m_filter_scalar_topology_worklet_branch_decomposition_hierarchical_volumetric_branch_decomposer_LocalBestUpDownByVolumeWorklet_h
48 
51 
52 namespace vtkm
53 {
54 namespace worklet
55 {
56 namespace scalar_topology
57 {
58 namespace hierarchical_volumetric_branch_decomposer
59 {
60 
63 
69 template <bool IsDown>
71 {
72 public:
74  using ControlSignature = void(
75  WholeArrayIn actualSuperacrs,
76  WholeArrayIn superarcList, // superarc list
77  FieldIn
78  permutedUpDownVolume, // upVolumne if IsDown==True, or downVolume if IsDown==False. These are swapped as IsDown refers to the output arrays
79  WholeArrayIn hierarchicalTreeRegularNodeGlobalIds,
80  WholeArrayIn hierarchicalTreeSupernodes,
81  WholeArrayInOut
82  bestUpDownSupernode, // bestUpSupernode if IsDown==False, or bestDownSupernode if IsDown==True
83  WholeArrayInOut
84  bestUpDownVolume // bestUpVolume if IsDown==False, or bestDownVolume if IsDown==True
85  );
86  // TODO: Check if we need WholeArrayInOut here for the output arrays or if WholeArrayOut is sufficient
87  using ExecutionSignature = void(InputIndex, _1, _2, _3, _4, _5, _6, _7);
88  using InputDomain = _1;
89 
92  LocalBestUpDownByVolumeWorklet(const vtkm::Id numActualSuperarcs)
93  : NumberActualSuperarcs(numActualSuperarcs)
94  {
95  }
96 
98  template <typename InFieldPortalType1,
99  typename InFieldPortalType2,
100  typename InFieldPortalType3,
101  typename InFieldPortalType4,
102  typename OutFieldPortalType1,
103  typename OutFieldPortalType2>
104  VTKM_EXEC void operator()(const vtkm::Id& actualSuperarcIndex,
105  const InFieldPortalType1& actualSuperarcsPortal,
106  const InFieldPortalType2& superarcListPortal,
107  const vtkm::Id& upDownVolumeValue, // upDownVolume[superarcID]
108  const InFieldPortalType3& hierarchicalTreeRegularNodeGlobalIdsPortal,
109  const InFieldPortalType4& hierarchicalTreeSupernodesPortal,
110  const OutFieldPortalType1& bestUpDownSupernodePortal,
111  const OutFieldPortalType2& bestUpDownVolumePortal) const
112  {
113  // per actual superarc
114  vtkm::Id superarcId = actualSuperarcsPortal.Get(actualSuperarcIndex);
115  const vtkm::worklet::contourtree_augmented::EdgePair& edge = superarcListPortal.Get(superarcId);
116 
117  if (IsDown)
118  {
119  // if it's the last one
120  if (actualSuperarcIndex == NumberActualSuperarcs - 1)
121  { // last in array
122  bestUpDownSupernodePortal.Set(edge.second,
123  hierarchicalTreeRegularNodeGlobalIdsPortal.Get(
124  hierarchicalTreeSupernodesPortal.Get(edge.first)));
125  bestUpDownVolumePortal.Set(edge.second, upDownVolumeValue);
126  } // last in array
127  else
128  { // not the last one
130  superarcListPortal.Get(actualSuperarcsPortal.Get(actualSuperarcIndex + 1));
131  // if the next edge belongs to another, we're the highest
132  if (nextEdge.second != edge.second)
133  { // last in group
134  bestUpDownSupernodePortal.Set(edge.second,
135  hierarchicalTreeRegularNodeGlobalIdsPortal.Get(
136  hierarchicalTreeSupernodesPortal.Get(edge.first)));
137  bestUpDownVolumePortal.Set(edge.second, upDownVolumeValue);
138  } // last in group
139  } // not the last one
140  } // if(this->IsDown)
141  else // Processing the Up arrays. This is essentiall the same, but we need to use the lower end of the edge instead
142  {
143  // if it's the last one
144  if (actualSuperarcIndex == NumberActualSuperarcs - 1)
145  { // last in array
146  bestUpDownSupernodePortal.Set(edge.first,
147  hierarchicalTreeRegularNodeGlobalIdsPortal.Get(
148  hierarchicalTreeSupernodesPortal.Get(edge.second)));
149  bestUpDownVolumePortal.Set(edge.first, upDownVolumeValue);
150  } // last in array
151  else
152  { // not the last one
154  superarcListPortal.Get(actualSuperarcsPortal.Get(actualSuperarcIndex + 1));
155  // if the next edge belongs to another, we're the highest
156  if (nextEdge.first != edge.first)
157  { // best in group
158  bestUpDownSupernodePortal.Set(edge.first,
159  hierarchicalTreeRegularNodeGlobalIdsPortal.Get(
160  hierarchicalTreeSupernodesPortal.Get(edge.second)));
161  bestUpDownVolumePortal.Set(edge.first, upDownVolumeValue);
162  } // best in group
163  } // not the last one
164  } // else (if(this->isDown))
165  /*
166  // This worklet implements the following loop. Depending on whether we are working with the Up- or DownVolumes
167  // This function implements one of the following logic
168  // II B 2. Per vertex, best superarc writes to the best downward array
169  for (vtkm::Id actualSuperarc = 0; actualSuperarc < nActualSuperarcs; actualSuperarc++)
170  { // per actual superarc
171  vtkm::Id superarcID = actualSuperarcs[actualSuperarc];
172  Edge &edge = superarcList[superarcID];
173  // if it's the last one
174  if (actualSuperarc == nActualSuperarcs-1)
175  { // last in array
176  bestDownSupernode[edge.high] = hierarchicalTree.regularNodeGlobalIDs[hierarchicalTree.supernodes[edge.low]];
177  bestDownVolume[edge.high] = upVolume[superarcID];
178  } // last in array
179  else
180  { // not the last one
181  Edge &nextEdge = superarcList[actualSuperarcs[actualSuperarc+1]];
182  // if the next edge belongs to another, we're the highest
183  if (nextEdge.high != edge.high)
184  { // last in group
185  bestDownSupernode[edge.high] = hierarchicalTree.regularNodeGlobalIDs[hierarchicalTree.supernodes[edge.low]];
186  bestDownVolume[edge.high] = upVolume[superarcID];
187  } // last in group
188  } // not the last one
189  } // per actual superarc
190  */
191  /* // Or in the Up case we have. THe main difference is the we either use the Up or Down Volume and
192  // and we following here the low end of the edge and top end of the edge in the other case
193 
194  for (vtkm::Id actualSuperarc = 0; actualSuperarc < nActualSuperarcs; actualSuperarc++)
195  { // per actual superarc
196  vtkm::Id superarcID = actualSuperarcs[actualSuperarc];
197  Edge &edge = superarcList[superarcID];
198  // if it's the last one
199  if (actualSuperarc == nActualSuperarcs-1)
200  { // last in array
201  bestUpSupernode[edge.low] = hierarchicalTree.regularNodeGlobalIDs[hierarchicalTree.supernodes[edge.high]];
202  bestUpVolume[edge.low] = downVolume[superarcID];
203  } // last in array
204  else
205  { // not the last one
206  Edge &nextEdge = superarcList[actualSuperarcs[actualSuperarc+1]];
207  // if the next edge belongs to another, we're the highest
208  if (nextEdge.low != edge.low)
209  { // best in group
210  bestUpSupernode[edge.low] = hierarchicalTree.regularNodeGlobalIDs[hierarchicalTree.supernodes[edge.high]];
211  bestUpVolume[edge.low] = downVolume[superarcID];
212  } // best in group
213  } // not the last one
214 
215  } // per actual superarc
216  */
217  } // operator()()
218 
219 private:
221 
222 }; // LocalBestUpDownByVolumeWorklet
223 
224 } // namespace hierarchical_volumetric_branch_decomposer
225 } // namespace scalar_topology
226 } // namespace worklet
227 } // namespace vtkm
228 
229 #endif
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::LocalBestUpDownByVolumeWorklet::NumberActualSuperarcs
vtkm::Id NumberActualSuperarcs
Definition: LocalBestUpDownByVolumeWorklet.h:220
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::LocalBestUpDownByVolumeWorklet::LocalBestUpDownByVolumeWorklet
VTKM_EXEC_CONT LocalBestUpDownByVolumeWorklet(const vtkm::Id numActualSuperarcs)
Default Constructor.
Definition: LocalBestUpDownByVolumeWorklet.h:92
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_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::LocalBestUpDownByVolumeWorklet::ControlSignature
void(WholeArrayIn actualSuperacrs, WholeArrayIn superarcList, FieldIn permutedUpDownVolume, WholeArrayIn hierarchicalTreeRegularNodeGlobalIds, WholeArrayIn hierarchicalTreeSupernodes, WholeArrayInOut bestUpDownSupernode, WholeArrayInOut bestUpDownVolume) ControlSignature
Control signature for the worklet.
Definition: LocalBestUpDownByVolumeWorklet.h:85
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::LocalBestUpDownByVolumeWorklet
Worklet used in HierarchicalAugmenter::CopyBaseRegularStructure for finding the superparent for each ...
Definition: LocalBestUpDownByVolumeWorklet.h:70
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
vtkm::Pair::first
FirstType first
The pair's first object.
Definition: Pair.h:50
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::LocalBestUpDownByVolumeWorklet::operator()
VTKM_EXEC void operator()(const vtkm::Id &actualSuperarcIndex, const InFieldPortalType1 &actualSuperarcsPortal, const InFieldPortalType2 &superarcListPortal, const vtkm::Id &upDownVolumeValue, const InFieldPortalType3 &hierarchicalTreeRegularNodeGlobalIdsPortal, const InFieldPortalType4 &hierarchicalTreeSupernodesPortal, const OutFieldPortalType1 &bestUpDownSupernodePortal, const OutFieldPortalType2 &bestUpDownVolumePortal) const
operator() of the workelt
Definition: LocalBestUpDownByVolumeWorklet.h:104
Types.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::exec::arg::InputIndex
The ExecutionSignature tag to use to get the input index.
Definition: InputIndex.h:42
vtkm::Pair::second
SecondType second
The pair's second object.
Definition: Pair.h:55
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::LocalBestUpDownByVolumeWorklet::InputDomain
_1 InputDomain
Definition: LocalBestUpDownByVolumeWorklet.h:88
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38
vtkm::worklet::scalar_topology::hierarchical_volumetric_branch_decomposer::LocalBestUpDownByVolumeWorklet::ExecutionSignature
void(InputIndex, _1, _2, _3, _4, _5, _6, _7) ExecutionSignature
Definition: LocalBestUpDownByVolumeWorklet.h:87