VTK-m  2.0
ScatterUniform.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_ScatterUniform_h
11 #define vtk_m_worklet_ScatterUniform_h
12 
13 #include <vtkm/cont/ArrayHandle.h>
17 
18 namespace vtkm
19 {
20 namespace worklet
21 {
22 
23 namespace detail
24 {
25 
26 template <vtkm::IdComponent Modulus>
27 struct FunctorModulus
28 {
30  vtkm::IdComponent operator()(vtkm::Id index) const
31  {
32  return static_cast<vtkm::IdComponent>(index % Modulus);
33  }
34 };
35 
36 template <vtkm::IdComponent Divisor>
37 struct FunctorDiv
38 {
40  vtkm::Id operator()(vtkm::Id index) const { return index / Divisor; }
41 };
42 }
43 
52 template <vtkm::IdComponent NumOutputsPerInput>
53 struct ScatterUniform : internal::ScatterBase
54 {
55  VTKM_CONT ScatterUniform() = default;
56 
57  VTKM_CONT
58  vtkm::Id GetOutputRange(vtkm::Id inputRange) const { return inputRange * NumOutputsPerInput; }
59  VTKM_CONT
60  vtkm::Id GetOutputRange(vtkm::Id3 inputRange) const
61  {
62  return this->GetOutputRange(inputRange[0] * inputRange[1] * inputRange[2]);
63  }
64 
65  using OutputToInputMapType =
67  template <typename RangeType>
69  {
70  return OutputToInputMapType(detail::FunctorDiv<NumOutputsPerInput>(),
71  this->GetOutputRange(inputRange));
72  }
73 
74  using VisitArrayType =
76  template <typename RangeType>
77  VTKM_CONT VisitArrayType GetVisitArray(RangeType inputRange) const
78  {
79  return VisitArrayType(detail::FunctorModulus<NumOutputsPerInput>(),
80  this->GetOutputRange(inputRange));
81  }
82 };
83 }
84 } // namespace vtkm::worklet
85 
86 #endif //vtk_m_worklet_ScatterUniform_h
ArrayHandle.h
vtkm::worklet::ScatterUniform::GetOutputToInputMap
VTKM_CONT OutputToInputMapType GetOutputToInputMap(RangeType inputRange) const
Definition: ScatterUniform.h:68
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
ScatterBase.h
vtkm::worklet::ScatterUniform
A scatter that maps input to some constant numbers of output.
Definition: ScatterUniform.h:53
vtkm::worklet::ScatterUniform::GetVisitArray
VTKM_CONT VisitArrayType GetVisitArray(RangeType inputRange) const
Definition: ScatterUniform.h:77
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::ScatterUniform::VisitArrayType
vtkm::cont::ArrayHandleImplicit< detail::FunctorModulus< NumOutputsPerInput > > VisitArrayType
Definition: ScatterUniform.h:75
vtkm::worklet::ScatterUniform::ScatterUniform
VTKM_CONT ScatterUniform()=default
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::worklet::ScatterUniform::GetOutputRange
VTKM_CONT vtkm::Id GetOutputRange(vtkm::Id3 inputRange) const
Definition: ScatterUniform.h:60
vtkm::Vec< vtkm::Id, 3 >
ArrayHandleCounting.h
ArrayHandleImplicit.h
vtkm::worklet::ScatterUniform::GetOutputRange
VTKM_CONT vtkm::Id GetOutputRange(vtkm::Id inputRange) const
Definition: ScatterUniform.h:58
vtkm::worklet::ScatterUniform::OutputToInputMapType
vtkm::cont::ArrayHandleImplicit< detail::FunctorDiv< NumOutputsPerInput > > OutputToInputMapType
Definition: ScatterUniform.h:66
vtkm::cont::ArrayHandleImplicit
An ArrayHandle that computes values on the fly.
Definition: ArrayHandleImplicit.h:174