VTK-m  2.0
MeshStructureContourTreeMesh.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 // This software is distributed WITHOUT ANY WARRANTY; without even
6 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7 // PURPOSE. See the above copyright notice for more information.
8 //
9 // Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
10 // Copyright 2014 UT-Battelle, LLC.
11 // Copyright 2014 Los Alamos National Security.
12 //
13 // Under the terms of Contract DE-NA0003525 with NTESS,
14 // the U.S. Government retains certain rights in this software.
15 //
16 // Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
17 // Laboratory (LANL), the U.S. Government retains certain rights in
18 // this software.
19 //============================================================================
20 // Copyright (c) 2018, The Regents of the University of California, through
21 // Lawrence Berkeley National Laboratory (subject to receipt of any required approvals
22 // from the U.S. Dept. of Energy). All rights reserved.
23 //
24 // Redistribution and use in source and binary forms, with or without modification,
25 // are permitted provided that the following conditions are met:
26 //
27 // (1) Redistributions of source code must retain the above copyright notice, this
28 // list of conditions and the following disclaimer.
29 //
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 //
34 // (3) Neither the name of the University of California, Lawrence Berkeley National
35 // Laboratory, U.S. Dept. of Energy nor the names of its contributors may be
36 // used to endorse or promote products derived from this software without
37 // specific prior written permission.
38 //
39 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
40 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
41 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
42 // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
43 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
45 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
46 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
47 // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
48 // OF THE POSSIBILITY OF SUCH DAMAGE.
49 //
50 //=============================================================================
51 //
52 // This code is an extension of the algorithm presented in the paper:
53 // Parallel Peak Pruning for Scalable SMP Contour Tree Computation.
54 // Hamish Carr, Gunther Weber, Christopher Sewell, and James Ahrens.
55 // Proceedings of the IEEE Symposium on Large Data Analysis and Visualization
56 // (LDAV), October 2016, Baltimore, Maryland.
57 //
58 // The PPP2 algorithm and software were jointly developed by
59 // Hamish Carr (University of Leeds), Gunther H. Weber (LBNL), and
60 // Oliver Ruebel (LBNL)
61 //==============================================================================
62 
63 #ifndef vtk_m_worklet_contourtree_augmented_mesh_dem_triangulation_contourtree_mesh_execution_obect_mesh_structure_h
64 #define vtk_m_worklet_contourtree_augmented_mesh_dem_triangulation_contourtree_mesh_execution_obect_mesh_structure_h
65 
66 #include <vtkm/Pair.h>
67 #include <vtkm/Types.h>
68 #include <vtkm/cont/ArrayHandle.h>
70 
71 
72 
73 //Define namespace alias for the freudenthal types to make the code a bit more readable
75 
76 namespace vtkm
77 {
78 namespace worklet
79 {
80 namespace contourtree_augmented
81 {
82 namespace mesh_dem_contourtree_mesh_inc
83 {
84 
85 // Worklet for computing the sort indices from the sort order
87 {
88 public:
90 
91  // Default constucture. Needed for the CUDA built to work
94  : GetMax(false)
95  {
96  }
97 
98  // Main constructure used in the code
99  VTKM_CONT
101  const cpp2_ns::IdArrayType neighborOffsets,
102  const vtkm::Id maxNeighbors,
103  bool getMax,
105  vtkm::cont::Token& token)
106  : MaxNeighbors(maxNeighbors)
107  , GetMax(getMax)
108  {
109  this->NeighborConnectivityPortal = neighborConnectivity.PrepareForInput(device, token);
110  this->NeighborOffsetsPortal = neighborOffsets.PrepareForInput(device, token);
111  }
112 
113  VTKM_EXEC
115  {
116  return this->NeighborOffsetsPortal.GetNumberOfValues() - 1;
117  }
118 
119  VTKM_EXEC
121 
122  VTKM_EXEC
123  inline vtkm::Id GetNeighbourIndex(vtkm::Id sortIndex, vtkm::Id neighborNo) const
124  { // GetNeighbourIndex
125  return NeighborConnectivityPortal.Get(NeighborOffsetsPortal.Get(sortIndex) + neighborNo);
126  } // GetNeighbourIndex
127 
128  // sets outgoing paths for saddles
129  VTKM_EXEC
130  inline vtkm::Id GetExtremalNeighbour(vtkm::Id sortIndex) const
131  { // GetExtremalNeighbour()
132  vtkm::Id neighborsBeginIndex = NeighborOffsetsPortal.Get(sortIndex);
133  vtkm::Id neighborsEndIndex = NeighborOffsetsPortal.Get(sortIndex + 1) - 1;
134  vtkm::Id neighborsBegin = NeighborConnectivityPortal.Get(neighborsBeginIndex);
135  vtkm::Id neighborsEnd = NeighborConnectivityPortal.Get(neighborsEndIndex);
136 
137  if (neighborsBeginIndex == neighborsEndIndex + 1)
138  { // Empty list of neighbors, this should never happen
139  return sortIndex | TERMINAL_ELEMENT;
140  }
141  else
142  {
143  vtkm::Id ret;
144  if (this->GetMax)
145  {
146  ret = neighborsEnd;
147  if (ret < sortIndex)
148  ret = sortIndex | TERMINAL_ELEMENT;
149  }
150  else
151  {
152  ret = neighborsBegin;
153  if (ret > sortIndex)
154  ret = sortIndex | TERMINAL_ELEMENT;
155  }
156  return ret;
157  }
158  } // GetExtremalNeighbour()
159 
160  // NOTE/FIXME: The following also iterates over all values and could be combined with GetExtremalNeighbour(). However, the
161  // results are needed at different places and splitting the two functions leads to a cleaner design
162  VTKM_EXEC
164  vtkm::Id sortIndex,
165  bool getMaxComponents) const
166  { // GetNeighbourComponentsMaskAndDegree()
167  vtkm::Id neighborsBeginIndex = NeighborOffsetsPortal.Get(sortIndex);
168  vtkm::Id neighborsEndIndex = NeighborOffsetsPortal.Get(sortIndex + 1);
169  vtkm::Id numNeighbours = neighborsEndIndex - neighborsBeginIndex;
170  vtkm::Id outDegree = 0;
171  vtkm::Id neighborComponentMask = 0;
172  vtkm::Id currNeighbour = 0;
173  for (vtkm::Id nbrNo = 0; nbrNo < numNeighbours; ++nbrNo)
174  {
175  currNeighbour = NeighborConnectivityPortal.Get(neighborsBeginIndex + nbrNo);
176  if ((getMaxComponents && (currNeighbour > sortIndex)) ||
177  (!getMaxComponents && (currNeighbour < sortIndex)))
178  {
179  ++outDegree;
180  neighborComponentMask |= vtkm::Id{ 1 } << nbrNo;
181  }
182  }
183  return vtkm::Pair<vtkm::Id, vtkm::Id>{ neighborComponentMask, outDegree };
184  } // GetNeighbourComponentsMaskAndDegree()
185 
186 private:
190  bool GetMax;
191 
192 }; // ExecutionObjec_MeshStructure_3Dt
193 
194 } // namespace mesh_dem_2d_freudenthal_inc
195 } // namespace contourtree_augmented
196 } // namespace worklet
197 } // namespace vtkm
198 
199 #endif
vtkm::cont::ArrayHandle< vtkm::Id >
ArrayHandle.h
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
Types.h
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::MeshStructureContourTreeMesh::GetNeighbourIndex
VTKM_EXEC vtkm::Id GetNeighbourIndex(vtkm::Id sortIndex, vtkm::Id neighborNo) const
Definition: MeshStructureContourTreeMesh.h:123
vtkm::cont::ArrayHandle::PrepareForInput
VTKM_CONT ReadPortalType PrepareForInput(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const
Prepares this array to be used as an input to an operation in the execution environment.
Definition: ArrayHandle.h:574
Pair.h
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::MeshStructureContourTreeMesh::MeshStructureContourTreeMesh
VTKM_CONT MeshStructureContourTreeMesh(const cpp2_ns::IdArrayType neighborConnectivity, const cpp2_ns::IdArrayType neighborOffsets, const vtkm::Id maxNeighbors, bool getMax, vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token)
Definition: MeshStructureContourTreeMesh.h:100
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::MeshStructureContourTreeMesh::GetMaxNumberOfNeighbours
VTKM_EXEC vtkm::Id GetMaxNumberOfNeighbours() const
Definition: MeshStructureContourTreeMesh.h:120
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::MeshStructureContourTreeMesh::GetMax
bool GetMax
Definition: MeshStructureContourTreeMesh.h:190
vtkm::worklet::contourtree_augmented
Definition: BuildChainsWorklet.h:63
vtkm::worklet::contourtree_augmented::TERMINAL_ELEMENT
constexpr vtkm::Id TERMINAL_ELEMENT
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:74
vtkm::cont::ArrayHandle< vtkm::Id >::ReadPortalType
typename StorageType::ReadPortalType ReadPortalType
Definition: ArrayHandle.h:294
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::MeshStructureContourTreeMesh::NeighborConnectivityPortal
IdArrayPortalType NeighborConnectivityPortal
Definition: MeshStructureContourTreeMesh.h:187
vtkm::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::MeshStructureContourTreeMesh::GetNeighbourComponentsMaskAndDegree
VTKM_EXEC vtkm::Pair< vtkm::Id, vtkm::Id > GetNeighbourComponentsMaskAndDegree(vtkm::Id sortIndex, bool getMaxComponents) const
Definition: MeshStructureContourTreeMesh.h:163
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::MeshStructureContourTreeMesh::GetNumberOfVertices
VTKM_EXEC vtkm::Id GetNumberOfVertices() const
Definition: MeshStructureContourTreeMesh.h:114
Types.h
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::MeshStructureContourTreeMesh
Definition: MeshStructureContourTreeMesh.h:86
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::MeshStructureContourTreeMesh::MaxNeighbors
vtkm::Id MaxNeighbors
Definition: MeshStructureContourTreeMesh.h:189
vtkm::cont::DeviceAdapterId
Definition: DeviceAdapterTag.h:52
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::MeshStructureContourTreeMesh::NeighborOffsetsPortal
IdArrayPortalType NeighborOffsetsPortal
Definition: MeshStructureContourTreeMesh.h:188
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::MeshStructureContourTreeMesh::IdArrayPortalType
typename cpp2_ns::IdArrayType::ReadPortalType IdArrayPortalType
Definition: MeshStructureContourTreeMesh.h:89
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::MeshStructureContourTreeMesh::MeshStructureContourTreeMesh
VTKM_EXEC_CONT MeshStructureContourTreeMesh()
Definition: MeshStructureContourTreeMesh.h:93
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::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::MeshStructureContourTreeMesh::GetExtremalNeighbour
VTKM_EXEC vtkm::Id GetExtremalNeighbour(vtkm::Id sortIndex) const
Definition: MeshStructureContourTreeMesh.h:130