VTK-m  2.2
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 
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 {
49  vtkm::Int8,
54 
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::ScatterCounting
ScatterCounting(const vtkm::cont::UnknownArrayHandle &countArray, bool saveInputToOutputMap)
Definition: ScatterCounting.h:68
VTKM_WORKLET_EXPORT
#define VTKM_WORKLET_EXPORT
Definition: vtkm_worklet_export.h:44
vtkm::cont::ArrayHandle< vtkm::Id >
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::worklet::ScatterCounting::GetOutputRange
vtkm::Id GetOutputRange(vtkm::Id3 inputRange) const
Definition: ScatterCounting.h:102
ScatterBase.h
vtkm::cont::UnknownArrayHandle
An ArrayHandle of an unknown value type and storage.
Definition: UnknownArrayHandle.h:430
vtkm::worklet::ScatterCounting::GetOutputToInputMap
OutputToInputMapType GetOutputToInputMap(RangeType) const
Definition: ScatterCounting.h:77
vtkm::worklet::ScatterCounting::GetOutputRange
vtkm::Id GetOutputRange(vtkm::Id inputRange) const
Definition: ScatterCounting.h:90
vtkm::Int16
int16_t Int16
Base type to use for 16-bit signed integer numbers.
Definition: Types.h:173
vtkm::worklet::ScatterCounting::GetOutputToInputMap
OutputToInputMapType GetOutputToInputMap() const
Definition: ScatterCounting.h:108
vtkm::worklet::ScatterCounting::GetInputToOutputMap
vtkm::cont::ArrayHandle< vtkm::Id > GetInputToOutputMap() const
This array will not be valid unless explicitly instructed to be saved.
Definition: ScatterCounting.h:114
vtkm::worklet::ScatterCounting::InputToOutputMap
vtkm::cont::ArrayHandle< vtkm::Id > InputToOutputMap
Definition: ScatterCounting.h:118
vtkm::worklet::ScatterCounting::ScatterCounting
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::worklet::ScatterCounting
A scatter that maps input to some numbers of output.
Definition: ScatterCounting.h:44
UnknownArrayHandle.h
vtkm::Int8
int8_t Int8
Base type to use for 8-bit signed integer numbers.
Definition: Types.h:165
vtkm_worklet_export.h
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::Int64
signed long long Int64
Base type to use for 64-bit signed integer numbers.
Definition: Types.h:204
vtkm::cont::DeviceAdapterTagAny
Tag for a device adapter used to specify that any device may be used for an operation.
Definition: DeviceAdapterTag.h:180
vtkm::worklet::ScatterCounting::VisitArray
VisitArrayType VisitArray
Definition: ScatterCounting.h:120
vtkm::UInt8
uint8_t UInt8
Base type to use for 8-bit unsigned integer numbers.
Definition: Types.h:169
vtkm::cont::DeviceAdapterId
An object used to specify a device.
Definition: DeviceAdapterTag.h:58
vtkm::Vec< vtkm::Id, 3 >
vtkm::UInt32
uint32_t UInt32
Base type to use for 32-bit unsigned integer numbers.
Definition: Types.h:185
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::UInt64
unsigned long long UInt64
Base type to use for 64-bit signed integer numbers.
Definition: Types.h:207
vtkm::List
A template used to hold a list of types.
Definition: List.h:39
vtkm::Int32
int32_t Int32
Base type to use for 32-bit signed integer numbers.
Definition: Types.h:181
vtkm::worklet::ScatterCounting::InputRange
vtkm::Id InputRange
Definition: ScatterCounting.h:117
vtkm::UInt16
uint16_t UInt16
Base type to use for 16-bit unsigned integer numbers.
Definition: Types.h:177
vtkm::worklet::ScatterCounting::GetVisitArray
VisitArrayType GetVisitArray(RangeType) const
Definition: ScatterCounting.h:84
vtkm::worklet::ScatterCounting::OutputToInputMap
OutputToInputMapType OutputToInputMap
Definition: ScatterCounting.h:119