VTK-m  2.0
worklet/ContourTreeUniform.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) 2016, Los Alamos National Security, LLC
11 // All rights reserved.
12 //
13 // Copyright 2016. Los Alamos National Security, LLC.
14 // This software was produced under U.S. Government contract DE-AC52-06NA25396
15 // for Los Alamos National Laboratory (LANL), which is operated by
16 // Los Alamos National Security, LLC for the U.S. Department of Energy.
17 // The U.S. Government has rights to use, reproduce, and distribute this
18 // software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
19 // MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
20 // USE OF THIS SOFTWARE. If software is modified to produce derivative works,
21 // such modified software should be clearly marked, so as not to confuse it
22 // with the version available from LANL.
23 //
24 // Additionally, redistribution and use in source and binary forms, with or
25 // without modification, are permitted provided that the following conditions
26 // are met:
27 //
28 // 1. Redistributions of source code must retain the above copyright notice,
29 // this list of conditions and the following disclaimer.
30 // 2. Redistributions in binary form must reproduce the above copyright notice,
31 // this list of conditions and the following disclaimer in the documentation
32 // and/or other materials provided with the distribution.
33 // 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
34 // National Laboratory, LANL, the U.S. Government, nor the names of its
35 // contributors may be used to endorse or promote products derived from
36 // this software without specific prior written permission.
37 //
38 // THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
39 // CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
40 // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
41 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
42 // NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
43 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
45 // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
46 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
47 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
48 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49 //============================================================================
50 
51 // This code is based on the algorithm presented in the paper:
52 // “Parallel Peak Pruning for Scalable SMP Contour Tree Computation.”
53 // Hamish Carr, Gunther Weber, Christopher Sewell, and James Ahrens.
54 // Proceedings of the IEEE Symposium on Large Data Analysis and Visualization
55 // (LDAV), October 2016, Baltimore, Maryland.
56 
57 #ifndef vtk_m_worklet_ContourTreeUniform_h
58 #define vtk_m_worklet_ContourTreeUniform_h
59 
60 #include <vtkm/Math.h>
61 #include <vtkm/cont/ArrayHandle.h>
63 #include <vtkm/cont/Field.h>
66 
67 // For numerous functions inside contourTree GCC is able to determine if i is
68 // always greater than j ( or vice-versa ) and optimizes those call sites.
69 // But when it does these optimizations is presumes that i and j will not
70 // overflow and emits a Wstrict-overflow warning
71 #ifdef VTKM_GCC
72 #pragma GCC diagnostic push
73 #pragma GCC diagnostic ignored "-Wstrict-overflow"
74 #endif
75 
81 
82 const bool JOIN = true;
83 const bool SPLIT = false;
84 const bool JOIN_3D = true;
85 const bool SPLIT_3D = false;
86 
87 namespace vtkm
88 {
89 namespace worklet
90 {
91 
93 {
94 public:
95  template <typename FieldType, typename StorageType>
97  const vtkm::Id nRows,
98  const vtkm::Id nCols,
100  {
101  vtkm::Id nSlices = 1;
102 
103  // Build the mesh and fill in the values
105 
106  // Initialize the join tree so that all arcs point to maxima
108  fieldArray, nRows, nCols, nSlices, JOIN);
109  mesh.SetStarts(joinTree.extrema, JOIN);
110  joinTree.BuildRegularChains();
111 
112  // Create the active topology graph from the regular graph
113  contourtree::ChainGraph<FieldType, StorageType> joinGraph(fieldArray, joinTree.extrema, JOIN);
114  mesh.SetSaddleStarts(joinGraph, JOIN);
115 
116  // Call join graph to finish computation
117  joinGraph.Compute(joinTree.saddles);
118 
119  // Initialize the split tree so that all arcs point to maxima
121  fieldArray, nRows, nCols, nSlices, SPLIT);
122  mesh.SetStarts(splitTree.extrema, SPLIT);
123  splitTree.BuildRegularChains();
124 
125  // Create the active topology graph from the regular graph
127  fieldArray, splitTree.extrema, SPLIT);
128  mesh.SetSaddleStarts(splitGraph, SPLIT);
129 
130  // Call split graph to finish computation
131  splitGraph.Compute(splitTree.saddles);
132 
133  // Now compute the contour tree
135  fieldArray, joinTree, splitTree, joinGraph, splitGraph);
136 
137  contourTree.CollectSaddlePeak(saddlePeak);
138  }
139 };
140 
142 {
143 public:
144  template <typename FieldType, typename StorageType>
146  const vtkm::Id nRows,
147  const vtkm::Id nCols,
148  const vtkm::Id nSlices,
150  {
151  // Build the mesh and fill in the values
153  fieldArray, nRows, nCols, nSlices);
154 
155  // Initialize the join tree so that all arcs point to maxima
157  fieldArray, nRows, nCols, nSlices, JOIN_3D);
158  mesh.SetStarts(joinTree.extrema, JOIN_3D);
159  joinTree.BuildRegularChains();
160 
161  // Create the active topology graph from the regular graph
163  fieldArray, joinTree.extrema, JOIN_3D);
164  mesh.SetSaddleStarts(joinGraph, JOIN_3D);
165 
166  // Call join graph to finish computation
167  joinGraph.Compute(joinTree.saddles);
168 
169  // Initialize the split tree so that all arcs point to maxima
171  fieldArray, nRows, nCols, nSlices, SPLIT_3D);
172  mesh.SetStarts(splitTree.extrema, SPLIT_3D);
173  splitTree.BuildRegularChains();
174 
175  // Create the active topology graph from the regular graph
177  fieldArray, splitTree.extrema, SPLIT_3D);
178  mesh.SetSaddleStarts(splitGraph, SPLIT_3D);
179 
180  // Call split graph to finish computation
181  splitGraph.Compute(splitTree.saddles);
182 
183  // Now compute the contour tree
185  fieldArray, joinTree, splitTree, joinGraph, splitGraph);
186 
187  contourTree.CollectSaddlePeak(saddlePeak);
188  }
189 };
190 }
191 } // namespace vtkm::worklet
192 
193 #ifdef VTKM_GCC
194 #pragma GCC diagnostic pop
195 #endif
196 
197 #endif // vtk_m_worklet_ContourTreeUniform_h
ContourTree.h
vtkm::worklet::contourtree::ChainGraph
Definition: ChainGraph.h:127
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:283
ArrayHandle.h
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
MergeTree.h
WorkletMapField.h
JOIN
const bool JOIN
Definition: worklet/ContourTreeUniform.h:82
ChainGraph.h
vtkm::worklet::contourtree::MergeTree
Definition: MergeTree.h:126
vtkm::worklet::ContourTreeMesh3D::Run
void Run(const vtkm::cont::ArrayHandle< FieldType, StorageType > fieldArray, const vtkm::Id nRows, const vtkm::Id nCols, const vtkm::Id nSlices, vtkm::cont::ArrayHandle< vtkm::Pair< vtkm::Id, vtkm::Id >> &saddlePeak)
Definition: worklet/ContourTreeUniform.h:145
vtkm::worklet::contourtree::Mesh3D_DEM_Triangulation::SetStarts
void SetStarts(vtkm::cont::ArrayHandle< vtkm::Id > &chains, bool descending)
Definition: Mesh3D_DEM_Triangulation.h:160
vtkm::worklet::ContourTreeMesh2D
Definition: worklet/ContourTreeUniform.h:92
vtkm::worklet::contourtree::Mesh3D_DEM_Triangulation::SetSaddleStarts
void SetSaddleStarts(ChainGraph< T, StorageType > &mergeGraph, bool descending)
Definition: Mesh3D_DEM_Triangulation.h:180
vtkm::worklet::contourtree::Mesh3D_DEM_Triangulation
Definition: Mesh3D_DEM_Triangulation.h:102
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
DispatcherMapField.h
vtkm::worklet::contourtree::MergeTree::extrema
vtkm::cont::ArrayHandle< vtkm::Id > extrema
Definition: MergeTree.h:142
vtkm::worklet::contourtree::Mesh2D_DEM_Triangulation::SetSaddleStarts
void SetSaddleStarts(ChainGraph< T, StorageType > &mergeGraph, bool descending)
Definition: Mesh2D_DEM_Triangulation.h:166
vtkm::worklet::contourtree::MergeTree::saddles
vtkm::cont::ArrayHandle< vtkm::Id > saddles
Definition: MergeTree.h:145
Mesh3D_DEM_Triangulation.h
vtkm::worklet::contourtree::Mesh2D_DEM_Triangulation::SetStarts
void SetStarts(vtkm::cont::ArrayHandle< vtkm::Id > &chains, bool descending)
Definition: Mesh2D_DEM_Triangulation.h:128
vtkm::worklet::contourtree::ChainGraph::Compute
void Compute(vtkm::cont::ArrayHandle< vtkm::Id > &saddles)
Definition: ChainGraph.h:240
Math.h
SPLIT_3D
const bool SPLIT_3D
Definition: worklet/ContourTreeUniform.h:85
JOIN_3D
const bool JOIN_3D
Definition: worklet/ContourTreeUniform.h:84
vtkm::worklet::ContourTreeMesh2D::Run
void Run(const vtkm::cont::ArrayHandle< FieldType, StorageType > fieldArray, const vtkm::Id nRows, const vtkm::Id nCols, vtkm::cont::ArrayHandle< vtkm::Pair< vtkm::Id, vtkm::Id >> &saddlePeak)
Definition: worklet/ContourTreeUniform.h:96
vtkm::worklet::ContourTreeMesh3D
Definition: worklet/ContourTreeUniform.h:141
vtkm::worklet::contourtree::Mesh2D_DEM_Triangulation
Definition: Mesh2D_DEM_Triangulation.h:102
SPLIT
const bool SPLIT
Definition: worklet/ContourTreeUniform.h:83
vtkm::worklet::contourtree::ContourTree
Definition: ContourTree.h:163
Mesh2D_DEM_Triangulation.h
ArrayHandleCounting.h
Field.h
vtkm::worklet::contourtree::ContourTree::CollectSaddlePeak
void CollectSaddlePeak(vtkm::cont::ArrayHandle< vtkm::Pair< vtkm::Id, vtkm::Id >> &saddlePeak)
Definition: ContourTree.h:863
vtkm::worklet::contourtree::MergeTree::BuildRegularChains
void BuildRegularChains()
Definition: MergeTree.h:201
vtkm::Pair
A vtkm::Pair is essentially the same as an STL pair object except that the methods (constructors and ...
Definition: Pair.h:29