VTK-m  2.0
ScatterCounting.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 #ifndef vtk_m_worklet_ScatterCounting_h
11 #define vtk_m_worklet_ScatterCounting_h
12 
14 #include <vtkm/worklet/vtkm_worklet_export.h>
15 
17 
18 #include <sstream>
19 
20 namespace vtkm
21 {
22 namespace worklet
23 {
24 
25 namespace detail
26 {
27 
28 struct ScatterCountingBuilder;
29 
30 } // namespace detail
31 
44 struct VTKM_WORKLET_EXPORT ScatterCounting : internal::ScatterBase
45 {
46  using CountTypes = vtkm::List<vtkm::Int64,
49  vtkm::Int8,
50  vtkm::UInt64,
54 
63  vtkm::cont::DeviceAdapterId device = vtkm::cont::DeviceAdapterTagAny(),
64  bool saveInputToOutputMap = false)
65  {
66  this->BuildArrays(countArray, device, saveInputToOutputMap);
67  }
69  bool saveInputToOutputMap)
70  {
71  this->BuildArrays(countArray, vtkm::cont::DeviceAdapterTagAny(), saveInputToOutputMap);
72  }
73 
75 
76  template <typename RangeType>
78  {
79  return this->OutputToInputMap;
80  }
81 
83  template <typename RangeType>
85  {
86  return this->VisitArray;
87  }
88 
89  VTKM_CONT
90  vtkm::Id GetOutputRange(vtkm::Id inputRange) const
91  {
92  if (inputRange != this->InputRange)
93  {
94  std::stringstream msg;
95  msg << "ScatterCounting initialized with input domain of size " << this->InputRange
96  << " but used with a worklet invoke of size " << inputRange << std::endl;
97  throw vtkm::cont::ErrorBadValue(msg.str());
98  }
99  return this->VisitArray.GetNumberOfValues();
100  }
101  VTKM_CONT
103  {
104  return this->GetOutputRange(inputRange[0] * inputRange[1] * inputRange[2]);
105  }
106 
107  VTKM_CONT
108  OutputToInputMapType GetOutputToInputMap() const { return this->OutputToInputMap; }
109 
113  VTKM_CONT
114  vtkm::cont::ArrayHandle<vtkm::Id> GetInputToOutputMap() const { return this->InputToOutputMap; }
115 
116 private:
121 
122  friend struct detail::ScatterCountingBuilder;
123 
124  VTKM_CONT void BuildArrays(const vtkm::cont::UnknownArrayHandle& countArray,
126  bool saveInputToOutputMap);
127 };
128 }
129 } // namespace vtkm::worklet
130 
131 #endif //vtk_m_worklet_ScatterCounting_h
vtkm::worklet::ScatterCounting::GetOutputToInputMap
VTKM_CONT OutputToInputMapType GetOutputToInputMap() const
Definition: ScatterCounting.h:108
vtkm::cont::ArrayHandle< vtkm::Id >
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
ScatterBase.h
vtkm::cont::UnknownArrayHandle
An ArrayHandle of an unknown value type and storage.
Definition: UnknownArrayHandle.h:406
vtkm::worklet::ScatterCounting::GetVisitArray
VTKM_CONT VisitArrayType GetVisitArray(RangeType) const
Definition: ScatterCounting.h:84
vtkm::Int16
int16_t Int16
Definition: Types.h:158
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::ScatterCounting::InputToOutputMap
vtkm::cont::ArrayHandle< vtkm::Id > InputToOutputMap
Definition: ScatterCounting.h:118
vtkm::worklet::ScatterCounting
A scatter that maps input to some numbers of output.
Definition: ScatterCounting.h:44
vtkm::worklet::ScatterCounting::GetInputToOutputMap
VTKM_CONT vtkm::cont::ArrayHandle< vtkm::Id > GetInputToOutputMap() const
This array will not be valid unless explicitly instructed to be saved.
Definition: ScatterCounting.h:114
UnknownArrayHandle.h
vtkm::Int8
int8_t Int8
Definition: Types.h:156
vtkm::worklet::ScatterCounting::GetOutputRange
VTKM_CONT vtkm::Id GetOutputRange(vtkm::Id inputRange) const
Definition: ScatterCounting.h:90
vtkm::worklet::ScatterCounting::GetOutputToInputMap
VTKM_CONT OutputToInputMapType GetOutputToInputMap(RangeType) const
Definition: ScatterCounting.h:77
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::worklet::ScatterCounting::VisitArray
VisitArrayType VisitArray
Definition: ScatterCounting.h:120
vtkm::UInt8
uint8_t UInt8
Definition: Types.h:157
vtkm::cont::DeviceAdapterId
Definition: DeviceAdapterTag.h:52
vtkm::Vec< vtkm::Id, 3 >
vtkm::worklet::ScatterCounting::ScatterCounting
VTKM_CONT ScatterCounting(const vtkm::cont::UnknownArrayHandle &countArray, vtkm::cont::DeviceAdapterId device=vtkm::cont::DeviceAdapterTagAny(), bool saveInputToOutputMap=false)
Construct a ScatterCounting object using an array of counts for the number of outputs for each input.
Definition: ScatterCounting.h:62
vtkm::UInt32
uint32_t UInt32
Definition: Types.h:161
vtkm::cont::ErrorBadValue
This class is thrown when a VTKm function or method encounters an invalid value that inhibits progres...
Definition: ErrorBadValue.h:25
vtkm::worklet::ScatterCounting::GetOutputRange
VTKM_CONT vtkm::Id GetOutputRange(vtkm::Id3 inputRange) const
Definition: ScatterCounting.h:102
vtkm::List
Definition: List.h:34
vtkm::Int32
int32_t Int32
Definition: Types.h:160
vtkm::worklet::ScatterCounting::ScatterCounting
VTKM_CONT ScatterCounting(const vtkm::cont::UnknownArrayHandle &countArray, bool saveInputToOutputMap)
Definition: ScatterCounting.h:68
vtkm::worklet::ScatterCounting::InputRange
vtkm::Id InputRange
Definition: ScatterCounting.h:117
vtkm::UInt16
uint16_t UInt16
Definition: Types.h:159
vtkm::worklet::ScatterCounting::OutputToInputMap
OutputToInputMapType OutputToInputMap
Definition: ScatterCounting.h:119