VTK-m  2.0
augmented/MergeTree.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 vtk_m_worklet_contourtree_augmented_mergetree_h
55 #define vtk_m_worklet_contourtree_augmented_mergetree_h
56 
57 #include <iomanip>
58 
59 // local includes
63 
64 
65 //VTKM includes
66 #include <vtkm/Types.h>
67 #include <vtkm/cont/Algorithm.h>
69 
70 namespace vtkm
71 {
72 namespace worklet
73 {
74 namespace contourtree_augmented
75 {
76 
77 class MergeTree
78 { // class MergeTree
79 public:
80  // whether it is join or split tree
81  bool IsJoinTree;
82 
83  // VECTORS INDEXED ON N = SIZE OF DATA
84 
85  // the list of nodes is implicit
86 
87  // vector of (regular) arcs in the merge tree
89 
90  // vector storing which superarc owns each node
92 
93  // VECTORS INDEXED ON T = SIZE OF TREE
94 
95  // vector storing the list of supernodes by ID
96  // WARNING: THESE ARE NOT SORTED BY INDEX
97  // Instead, they are sorted by hyperarc, secondarily on index
99 
100  // vector of superarcs in the merge tree
101  // stored as supernode indices
103 
104  // vector of Hyperarcs to which each supernode/arc belongs
106 
107  // VECTORS INDEXED ON H = SIZE OF HYPERTREE
108 
109  // vector of sort indices for the hypernodes
111 
112  // vector of Hyperarcs in the merge tree
113  // NOTE: These are supernode IDs, not hypernode IDs
114  // because not all Hyperarcs lead to hypernodes
116 
117  // vector to find the first child superarc
119 
120  // ROUTINES
121 
122  // creates merge tree (empty)
123  MergeTree(vtkm::Id meshSize, bool isJoinTree);
124 
125  // debug routine
126  void DebugPrint(const char* message, const char* fileName, long lineNum);
127 
128  // debug routine for printing the tree for contourtree meshes
129  template <typename FieldType>
130  void DebugPrintTree(const char* message,
131  const char* fileName,
132  long lineNum,
133  const ContourTreeMesh<FieldType>& mesh);
134  // debug routine for printing the tree for regular meshes
135  template <typename MeshType>
136  void DebugPrintTree(const char* message,
137  const char* fileName,
138  long lineNum,
139  const MeshType& mesh);
140 
141 
142 }; // class MergeTree
143 
144 
145 // creates merge tree (empty)
146 inline MergeTree::MergeTree(vtkm::Id meshSize, bool isJoinTree)
147  : IsJoinTree(isJoinTree)
148  , Supernodes()
149  , Superarcs()
150  , Hyperparents()
151  , Hypernodes()
152  , Hyperarcs()
153  , FirstSuperchild()
154 { // MergeTree()
155  // Allocate the arcs array
156  // TODO it should be sufficient to just allocate arcs without initializing it with 0s
157  vtkm::cont::ArrayHandleConstant<vtkm::Id> meshSizeNullArray(0, meshSize);
158  vtkm::cont::Algorithm::Copy(meshSizeNullArray, this->Arcs);
159 
160  // Initialize the superparents with NO_SUCH_ELEMENT
162  vtkm::cont::Algorithm::Copy(noSuchElementArray, this->Superparents);
163 
164 } // MergeTree()
165 
166 
167 // debug routine
168 inline void MergeTree::DebugPrint(const char* message, const char* fileName, long lineNum)
169 { // DebugPrint()
170 #ifdef DEBUG_PRINT
171  std::cout << "---------------------------" << std::endl;
172  std::cout << std::setw(30) << std::left << fileName << ":" << std::right << std::setw(4)
173  << lineNum << std::endl;
174  std::cout << std::left << std::string(message) << std::endl;
175  std::cout << "Merge Tree Contains: " << std::endl;
176  std::cout << "---------------------------" << std::endl;
177  std::cout << std::endl;
178 
180  PrintIndices("Arcs", this->Arcs);
181  PrintIndices("Superparents", this->Superparents);
182  std::cout << std::endl;
184  PrintIndices("Supernodes", this->Supernodes);
185  PrintIndices("Superarcs", this->Superarcs);
186  PrintIndices("Hyperparents", this->Hyperparents);
187  std::cout << std::endl;
189  PrintIndices("Hypernodes", this->Hypernodes);
190  PrintIndices("Hyperarcs", this->Hyperarcs);
191  PrintIndices("First Superchild", FirstSuperchild);
192  std::cout << std::endl;
193 #else
194  // Prevent unused parameter warning
195  (void)message;
196  (void)fileName;
197  (void)lineNum;
198 #endif
199 } // DebugPrint()
200 
201 
202 template <typename FieldType>
203 inline void MergeTree::DebugPrintTree(const char* message,
204  const char* fileName,
205  long lineNum,
206  const ContourTreeMesh<FieldType>& mesh)
207 {
208  (void)mesh; // prevent unused parameter warning
209  std::cout << std::setw(30) << std::left << fileName << ":" << std::right << std::setw(4)
210  << lineNum << std::endl;
211  std::cout << std::left << std::string(message) << std::endl;
212  std::cout << "MergeTree::DebugPrintTree not implemented for ContourTreeMesh" << std::endl;
213 }
214 
215 
216 
217 template <typename MeshType>
218 inline void MergeTree::DebugPrintTree(const char* message,
219  const char* fileName,
220  long lineNum,
221  const MeshType& mesh)
222 { //PrintMergeTree()
223 #ifdef DEBUG_PRINT
224  std::cout << "---------------------------" << std::endl;
225  std::cout << std::setw(30) << std::left << fileName << ":" << std::right << std::setw(4)
226  << lineNum << std::endl;
227  std::cout << std::left << std::string(message) << std::endl;
228  if (this->IsJoinTree)
229  {
230  std::cout << "Join Tree:" << std::endl;
231  }
232  else
233  {
234  std::cout << "Split Tree:" << std::endl;
235  }
236  std::cout << "---------------------------" << std::endl;
237  std::cout << std::endl;
238 
239  std::cout << "==========" << std::endl;
240 
241  for (vtkm::Id entry = 0; entry < mesh.NumVertices; entry++)
242  {
243  vtkm::Id sortIndex = vtkm::cont::ArrayGetValue(entry, mesh.SortIndices);
244  vtkm::Id arc = vtkm::cont::ArrayGetValue(sortIndex, this->Arcs);
245  if (NoSuchElement(arc))
246  {
247  std::cout << "-1" << std::endl;
248  }
249  else
250  {
251  std::cout << vtkm::cont::ArrayGetValue(arc, mesh.SortOrder) << std::endl;
252  }
253  if (mesh.MeshSize[2] == 1)
254  { // 2D Mesh
255  if ((entry % mesh.MeshSize[0]) == (mesh.MeshSize[0] - 1))
256  {
257  std::cout << std::endl;
258  }
259  }
260  else
261  { // 3D Mesh
262  if ((entry % (mesh.MeshSize[0] * mesh.MeshSize[1])) ==
263  (mesh.MeshSize[0] * mesh.MeshSize[1] - 1))
264  {
265  std::cout << std::endl;
266  }
267  }
268  }
269  std::cout << std::endl;
270 #else
271  // Prevent unused parameter warning
272  (void)message;
273  (void)fileName;
274  (void)lineNum;
275  (void)mesh;
276 #endif
277 } // PrintMergeTree()
278 
279 } // namespace contourtree_augmented
280 } // worklet
281 } // vtkm
282 
283 #endif
vtkm::cont::ArrayHandle::GetNumberOfValues
VTKM_CONT vtkm::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:448
vtkm::cont::ArrayHandle< vtkm::Id >
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::worklet::contourtree_augmented::MergeTree::Arcs
IdArrayType Arcs
Definition: augmented/MergeTree.h:88
Types.h
vtkm::worklet::contourtree_augmented::MergeTree::DebugPrintTree
void DebugPrintTree(const char *message, const char *fileName, long lineNum, const ContourTreeMesh< FieldType > &mesh)
Definition: augmented/MergeTree.h:203
ArrayHandleConstant.h
vtkm::cont::ArrayGetValue
VTKM_CONT T ArrayGetValue(vtkm::Id id, const vtkm::cont::ArrayHandle< T, S > &data)
Obtain a small set of values from an ArrayHandle with minimal device transfers.
Definition: ArrayGetValues.h:264
vtkm::cont::Algorithm::Copy
static VTKM_CONT bool Copy(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, CIn > &input, vtkm::cont::ArrayHandle< U, COut > &output)
Definition: Algorithm.h:410
PrintVectors.h
vtkm::worklet::contourtree_augmented::MergeTree::Supernodes
IdArrayType Supernodes
Definition: augmented/MergeTree.h:98
vtkm::worklet::contourtree_augmented::ContourTreeMesh
Definition: ContourTreeMesh.h:129
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::contourtree_augmented::MergeTree::IsJoinTree
bool IsJoinTree
Definition: augmented/MergeTree.h:81
vtkm::worklet::contourtree_augmented::NoSuchElement
VTKM_EXEC_CONT bool NoSuchElement(vtkm::Id flaggedIndex)
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:97
ContourTreeMesh.h
vtkm::worklet::contourtree_augmented::MergeTree::Hyperarcs
IdArrayType Hyperarcs
Definition: augmented/MergeTree.h:115
Algorithm.h
vtkm::worklet::contourtree_augmented::MergeTree::DebugPrint
void DebugPrint(const char *message, const char *fileName, long lineNum)
Definition: augmented/MergeTree.h:168
vtkm::worklet::contourtree_augmented::MergeTree::Hypernodes
IdArrayType Hypernodes
Definition: augmented/MergeTree.h:110
Types.h
vtkm::cont::ArrayHandleConstant
An array handle with a constant value.
Definition: ArrayHandleConstant.h:63
vtkm::worklet::contourtree_augmented::MergeTree::Superarcs
IdArrayType Superarcs
Definition: augmented/MergeTree.h:102
vtkm::worklet::contourtree_augmented::MergeTree::MergeTree
MergeTree(vtkm::Id meshSize, bool isJoinTree)
Definition: augmented/MergeTree.h:146
vtkm::worklet::contourtree_augmented::MergeTree::Superparents
IdArrayType Superparents
Definition: augmented/MergeTree.h:91
vtkm::worklet::contourtree_augmented::MergeTree
Definition: augmented/MergeTree.h:77
vtkm::worklet::contourtree_augmented::PrintIndices
void PrintIndices(std::string label, const vtkm::cont::ArrayHandle< T > &iVec, vtkm::Id nIndices=-1, std::ostream &outStream=std::cout)
Definition: augmented/PrintVectors.h:253
vtkm::worklet::contourtree_augmented::PrintHeader
void PrintHeader(vtkm::Id howMany, std::ostream &outStream=std::cout)
Definition: augmented/PrintVectors.h:151
vtkm::worklet::contourtree_augmented::MergeTree::Hyperparents
IdArrayType Hyperparents
Definition: augmented/MergeTree.h:105
vtkm::worklet::contourtree_augmented::MergeTree::FirstSuperchild
IdArrayType FirstSuperchild
Definition: augmented/MergeTree.h:118
vtkm::worklet::contourtree_augmented::NO_SUCH_ELEMENT
constexpr vtkm::Id NO_SUCH_ELEMENT
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:73