VTK-m  2.0
BranchCompiler.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 
54 #ifndef _BRANCHCOMPILER_H_
55 #define _BRANCHCOMPILER_H_
56 
57 #include <iomanip>
58 #include <iostream>
59 #include <vector>
61 
62 namespace vtkm
63 {
64 namespace worklet
65 {
66 namespace contourtree_distributed
67 {
68 
69 typedef std::tuple<vtkm::Id, vtkm::Id> Branch;
70 
72 { // class BranchCompiler
73 public:
74  std::vector<Branch> branches;
75 
76  void Parse(std::istream& in);
77  void Print(std::ostream& out) const;
78  void Load(const std::string& filename);
79 }; // class BranchCompiler
80 
81 inline void BranchCompiler::Parse(std::istream& in)
82 { // Parse()
83  // variables tracking the best & worst so far for this extent
85  // this is slightly tricky, since we don't know the range of the data type
86  // yet, but we can initialize to 0 for both floats and integers, then test on
87  // current branch
88  vtkm::Float64 highValue = 0;
89  vtkm::Float64 lowValue = 0;
92 
93  // values to read in
94  vtkm::Id nextBranch;
95  vtkm::Float64 nextValue;
96  vtkm::Id nextSupernode;
97 
98  while (true)
99  { // until stream goes bad
100  // read the next triple
101  in >> nextBranch >> nextValue >> nextSupernode;
102 
103  // test in the middle before processing
104  if (in.eof())
105  break;
106 
107  // test to see if the branch is different from the current one
108  if (nextBranch != currentBranch)
109  { // new branch
110  // special test for initial one
112  {
113  this->branches.push_back(std::make_tuple(highEnd, lowEnd));
114  }
115 
116  // set the high & low value ends to this one
117  highValue = nextValue;
118  lowValue = nextValue;
119  highEnd = nextSupernode;
120  lowEnd = nextSupernode;
121 
122  // and reset the branch ID
123  currentBranch = nextBranch;
124  } // new branch
125  else
126  { // existing branch
127  // test value with simulation of simplicity
128  if ((nextValue > highValue) || ((nextValue == highValue) && (nextSupernode > highEnd)))
129  { // new high end
130  highEnd = nextSupernode;
131  highValue = nextValue;
132  } // new high end
133  // test value with simulation of simplicity
134  else if ((nextValue < lowValue) || ((nextValue == lowValue) && (nextSupernode < lowEnd)))
135  { // new low end
136  lowEnd = nextSupernode;
137  lowValue = nextValue;
138  } // new low end
139  } // existing branch
140  } // until stream goes bad
141 
142  this->branches.push_back(std::make_tuple(highEnd, lowEnd));
143  std::sort(this->branches.begin(), this->branches.end());
144 } // Parse()
145 
146 inline void BranchCompiler::Print(std::ostream& out) const
147 {
148  for (auto it = std::begin(this->branches); it != std::end(this->branches); ++it)
149  {
150  Branch branch(*it);
151 
152  out << std::setw(12) << std::get<0>(branch) << std::setw(14) << std::get<1>(branch)
153  << std::endl;
154  }
155 }
156 
157 inline void BranchCompiler::Load(const std::string& filename)
158 {
159  this->branches.clear();
160 
161  std::ifstream in(filename);
162 
163  while (!in.eof())
164  {
165 
166  vtkm::Id highEnd, lowEnd;
167 
168  in >> highEnd >> lowEnd;
169 
170  if (in.fail())
171  break;
172 
173  this->branches.push_back(std::make_tuple(highEnd, lowEnd));
174  }
175 
176  std::sort(this->branches.begin(), this->branches.end());
177 }
178 
179 } // namespace contourtree_distributed
180 } // namespace worklet
181 } // namespace vtkm
182 
183 #endif
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::worklet::contourtree_distributed::Branch
std::tuple< vtkm::Id, vtkm::Id > Branch
Definition: BranchCompiler.h:69
vtkm::worklet::contourtree_distributed::BranchCompiler
Definition: BranchCompiler.h:71
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::contourtree_distributed::BranchCompiler::Load
void Load(const std::string &filename)
Definition: BranchCompiler.h:157
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::BranchCompiler::branches
std::vector< Branch > branches
Definition: BranchCompiler.h:74
vtkm::worklet::contourtree_distributed::BranchCompiler::Parse
void Parse(std::istream &in)
Definition: BranchCompiler.h:81
Types.h
vtkm::make_tuple
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT auto make_tuple(Ts &&... args) -> decltype(vtkm::MakeTuple(std::forward< Ts >(args)...))
Compatible with std::make_tuple for vtkm::Tuple.
Definition: Tuple.h:129
vtkm::worklet::contourtree_distributed::BranchCompiler::Print
void Print(std::ostream &out) const
Definition: BranchCompiler.h:146
vtkm::Float64
double Float64
Definition: Types.h:155
vtkm::worklet::contourtree_augmented::NO_SUCH_ELEMENT
constexpr vtkm::Id NO_SUCH_ELEMENT
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:73