VTK-m  2.0
MeshExtrema.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_meshextrema_h
54 #define vtk_m_worklet_contourtree_augmented_meshextrema_h
55 
56 #include <iomanip>
57 
58 // local includes
59 #include <vtkm/cont/Algorithm.h>
61 #include <vtkm/cont/Invoker.h>
66 
67 
69 
71 
72 namespace vtkm
73 {
74 namespace worklet
75 {
76 namespace contourtree_augmented
77 {
78 
80 { // MeshExtrema
81 public:
83  // arrays for peaks & pits
88 
89  // constructor
90  VTKM_CONT
91  MeshExtrema(vtkm::Id meshSize);
92 
93  // routine to initialise the array before chaining
94  template <class MeshType>
95  void SetStarts(MeshType& mesh, bool isMaximal);
96 
97  // routine that computes regular chains in a merge tree
98  VTKM_CONT
99  void BuildRegularChains(bool isMaximal);
100 
101  // debug routine
102  VTKM_CONT
103  void DebugPrint(const char* message, const char* fileName, long lineNum);
104 
105 }; // MeshExtrema
106 
107 
109  : Peaks()
110  , Pits()
111  , NumVertices(meshSize)
112  , NumLogSteps(0)
113 { // MeshExrema
114  // Compute the number of log steps required in this pass
115  NumLogSteps = 1;
116  for (vtkm::Id shifter = NumVertices; shifter != 0; shifter >>= 1)
117  this->NumLogSteps++;
118 
119  // Allocate memory for the peaks and pits
122  // TODO Check if we really need to set the Peaks and pits to zero or whether it is enough to allocate them
124  vtkm::cont::Algorithm::Copy(constZeroArray, Peaks);
125  vtkm::cont::Algorithm::Copy(constZeroArray, Pits);
126 } // MeshExtrema
127 
128 
129 inline void MeshExtrema::BuildRegularChains(bool isMaximal)
130 { // BuildRegularChains()
131  // Create vertex index array -- note, this is a fancy vtk-m array, i.e, the full array
132  // is not actually allocated but the array only acts like a sequence of numbers
133  vtkm::cont::ArrayHandleIndex vertexIndexArray(NumVertices);
134  IdArrayType& extrema = isMaximal ? Peaks : Pits;
135 
136  // Create the PointerDoubling worklet and corresponding dispatcher
138 
139  // Iterate to perform pointer-doubling to build chains to extrema (i.e., maxima or minima)
140  // depending on whether we are computing a JoinTree or a SplitTree
141  for (vtkm::Id logStep = 0; logStep < this->NumLogSteps; logStep++)
142  {
143  this->Invoke(pointerDoubler,
144  vertexIndexArray, // input
145  extrema); // output. Update whole extrema array during pointer doubling
146  }
147  DebugPrint("Regular Chains Built", __FILE__, __LINE__);
148 } // BuildRegularChains()
149 
150 template <class MeshType>
151 inline void MeshExtrema::SetStarts(MeshType& mesh, bool isMaximal)
152 {
153  mesh.SetPrepareForExecutionBehavior(isMaximal);
154  mesh_extrema_inc_ns::SetStarts setStartsWorklet;
155  vtkm::cont::ArrayHandleIndex sortIndexArray(mesh.NumVertices);
156  if (isMaximal)
157  {
158  this->Invoke(setStartsWorklet,
159  sortIndexArray, // input
160  mesh, // input
161  Peaks); // output
162  }
163  else
164  {
165  this->Invoke(setStartsWorklet,
166  sortIndexArray, // input
167  mesh, // input
168  Pits); // output
169  }
170  DebugPrint("Regular Starts Set", __FILE__, __LINE__);
171 }
172 
173 
174 // debug routine
175 inline void MeshExtrema::DebugPrint(const char* message, const char* fileName, long lineNum)
176 { // DebugPrint()
177 #ifdef DEBUG_PRINT
178  std::cout << "---------------------------" << std::endl;
179  std::cout << std::setw(30) << std::left << fileName << ":" << std::right << std::setw(4)
180  << lineNum << std::endl;
181  std::cout << std::left << std::string(message) << std::endl;
182  std::cout << "Mesh Extrema Contain: " << std::endl;
183  std::cout << "---------------------------" << std::endl;
184  std::cout << std::endl;
185 
187  PrintIndices("Peaks", Peaks);
188  PrintIndices("Pits", Pits);
189 #else
190  // Prevent unused parameter warning
191  (void)message;
192  (void)fileName;
193  (void)lineNum;
194 #endif
195 } // DebugPrint()
196 
197 
198 } // namespace contourtree_augmented
199 } // worklet
200 } // vtkm
201 
202 #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::worklet::contourtree_augmented::MeshExtrema::MeshExtrema
VTKM_CONT MeshExtrema(vtkm::Id meshSize)
Definition: MeshExtrema.h:108
vtkm::worklet::contourtree_augmented::MeshExtrema::BuildRegularChains
VTKM_CONT void BuildRegularChains(bool isMaximal)
Definition: MeshExtrema.h:129
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
SortIndices.h
vtkm::worklet::contourtree_augmented::MeshExtrema::Invoke
vtkm::cont::Invoker Invoke
Definition: MeshExtrema.h:82
vtkm::cont::ArrayHandle::Allocate
VTKM_CONT void Allocate(vtkm::Id numberOfValues, vtkm::CopyFlag preserve, vtkm::cont::Token &token) const
Allocates an array large enough to hold the given number of values.
Definition: ArrayHandle.h:465
vtkm::worklet::contourtree_augmented::mesh_extrema_inc
Definition: meshextrema/PointerDoubling.h:65
vtkm::worklet::contourtree_augmented::MeshExtrema::SetStarts
void SetStarts(MeshType &mesh, bool isMaximal)
Definition: MeshExtrema.h:151
vtkm::worklet::contourtree_augmented::MeshExtrema::Pits
IdArrayType Pits
Definition: MeshExtrema.h:85
vtkm::worklet::contourtree_augmented::MeshExtrema
Definition: MeshExtrema.h:79
ArrayHandleConstant.h
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
Invoker.h
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::contourtree_augmented::mesh_extrema_inc::PointerDoubling
Definition: meshextrema/PointerDoubling.h:73
Algorithm.h
SetStarts.h
vtkm::cont::Invoker
Allows launching any worklet without a dispatcher.
Definition: Invoker.h:41
Types.h
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::ArrayHandleConstant
An array handle with a constant value.
Definition: ArrayHandleConstant.h:63
PointerDoubling.h
vtkm::worklet::contourtree_augmented::MeshExtrema::NumLogSteps
vtkm::Id NumLogSteps
Definition: MeshExtrema.h:87
vtkm::worklet::contourtree_augmented::mesh_extrema_inc::SetStarts
Definition: SetStarts.h:69
vtkm::worklet::contourtree_augmented::MeshExtrema::DebugPrint
VTKM_CONT void DebugPrint(const char *message, const char *fileName, long lineNum)
Definition: MeshExtrema.h:175
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::MeshExtrema::NumVertices
vtkm::Id NumVertices
Definition: MeshExtrema.h:86
vtkm::worklet::contourtree_augmented::MeshExtrema::Peaks
IdArrayType Peaks
Definition: MeshExtrema.h:84
vtkm::cont::ArrayHandleIndex
An implicit array handle containing the its own indices.
Definition: ArrayHandleIndex.h:54