2019-04-15 23:24:21 +00:00
|
|
|
//============================================================================
|
2015-11-07 11:57:16 +00:00
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
|
|
|
//
|
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
2019-04-15 23:24:21 +00:00
|
|
|
//============================================================================
|
2015-11-07 11:57:16 +00:00
|
|
|
#ifndef vtk_m_worklet_ScatterUniform_h
|
|
|
|
#define vtk_m_worklet_ScatterUniform_h
|
|
|
|
|
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
|
|
|
#include <vtkm/cont/ArrayHandleCounting.h>
|
|
|
|
#include <vtkm/cont/ArrayHandleImplicit.h>
|
2019-05-15 14:16:12 +00:00
|
|
|
#include <vtkm/worklet/internal/ScatterBase.h>
|
2015-11-07 11:57:16 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace worklet
|
|
|
|
{
|
2015-11-07 11:57:16 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace detail
|
|
|
|
{
|
2015-11-07 11:57:16 +00:00
|
|
|
|
Move Scatter from Worklet to Dispatcher
Previously, when a Worklet needed a scatter, the scatter object was
stored in the Worklet object. That was problematic because that means
the Scatter, which is a control object, was shoved into the execution
environment.
To prevent that, move the Scatter into the Dispatcher object. The
worklet still declares a ScatterType alias, but no longer has a
GetScatter method. Instead, the Dispatcher now takes a Scatter object in
its constructor. If using the default scatter (ScatterIdentity), the
default constructor is used. If using another type of Scatter that
requires data to set up its state, then the caller of the worklet needs
to provide that to the dispatcher. For convenience, worklets are
encouraged to have a MakeScatter method to help construct a proper
scatter object.
2018-04-27 04:43:51 +00:00
|
|
|
template <vtkm::IdComponent Modulus>
|
2015-11-07 11:57:16 +00:00
|
|
|
struct FunctorModulus
|
|
|
|
{
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2015-11-07 11:57:16 +00:00
|
|
|
vtkm::IdComponent operator()(vtkm::Id index) const
|
|
|
|
{
|
Move Scatter from Worklet to Dispatcher
Previously, when a Worklet needed a scatter, the scatter object was
stored in the Worklet object. That was problematic because that means
the Scatter, which is a control object, was shoved into the execution
environment.
To prevent that, move the Scatter into the Dispatcher object. The
worklet still declares a ScatterType alias, but no longer has a
GetScatter method. Instead, the Dispatcher now takes a Scatter object in
its constructor. If using the default scatter (ScatterIdentity), the
default constructor is used. If using another type of Scatter that
requires data to set up its state, then the caller of the worklet needs
to provide that to the dispatcher. For convenience, worklets are
encouraged to have a MakeScatter method to help construct a proper
scatter object.
2018-04-27 04:43:51 +00:00
|
|
|
return static_cast<vtkm::IdComponent>(index % Modulus);
|
2015-11-07 11:57:16 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
Move Scatter from Worklet to Dispatcher
Previously, when a Worklet needed a scatter, the scatter object was
stored in the Worklet object. That was problematic because that means
the Scatter, which is a control object, was shoved into the execution
environment.
To prevent that, move the Scatter into the Dispatcher object. The
worklet still declares a ScatterType alias, but no longer has a
GetScatter method. Instead, the Dispatcher now takes a Scatter object in
its constructor. If using the default scatter (ScatterIdentity), the
default constructor is used. If using another type of Scatter that
requires data to set up its state, then the caller of the worklet needs
to provide that to the dispatcher. For convenience, worklets are
encouraged to have a MakeScatter method to help construct a proper
scatter object.
2018-04-27 04:43:51 +00:00
|
|
|
template <vtkm::IdComponent Divisor>
|
2015-11-07 11:57:16 +00:00
|
|
|
struct FunctorDiv
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_EXEC_CONT
|
Move Scatter from Worklet to Dispatcher
Previously, when a Worklet needed a scatter, the scatter object was
stored in the Worklet object. That was problematic because that means
the Scatter, which is a control object, was shoved into the execution
environment.
To prevent that, move the Scatter into the Dispatcher object. The
worklet still declares a ScatterType alias, but no longer has a
GetScatter method. Instead, the Dispatcher now takes a Scatter object in
its constructor. If using the default scatter (ScatterIdentity), the
default constructor is used. If using another type of Scatter that
requires data to set up its state, then the caller of the worklet needs
to provide that to the dispatcher. For convenience, worklets are
encouraged to have a MakeScatter method to help construct a proper
scatter object.
2018-04-27 04:43:51 +00:00
|
|
|
vtkm::Id operator()(vtkm::Id index) const { return index / Divisor; }
|
2017-05-18 14:29:41 +00:00
|
|
|
};
|
2015-11-07 11:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief A scatter that maps input to some constant numbers of output.
|
|
|
|
///
|
|
|
|
/// The \c Scatter classes are responsible for defining how much output is
|
|
|
|
/// generated based on some sized input. \c ScatterUniform establishes a 1 to N
|
|
|
|
/// mapping from input to output. That is, every input element generates N
|
|
|
|
/// elements associated with it where N is the same for every input. The output
|
|
|
|
/// elements are grouped by the input associated.
|
|
|
|
///
|
Move Scatter from Worklet to Dispatcher
Previously, when a Worklet needed a scatter, the scatter object was
stored in the Worklet object. That was problematic because that means
the Scatter, which is a control object, was shoved into the execution
environment.
To prevent that, move the Scatter into the Dispatcher object. The
worklet still declares a ScatterType alias, but no longer has a
GetScatter method. Instead, the Dispatcher now takes a Scatter object in
its constructor. If using the default scatter (ScatterIdentity), the
default constructor is used. If using another type of Scatter that
requires data to set up its state, then the caller of the worklet needs
to provide that to the dispatcher. For convenience, worklets are
encouraged to have a MakeScatter method to help construct a proper
scatter object.
2018-04-27 04:43:51 +00:00
|
|
|
template <vtkm::IdComponent NumOutputsPerInput>
|
2019-05-15 14:16:12 +00:00
|
|
|
struct ScatterUniform : internal::ScatterBase
|
2015-11-07 11:57:16 +00:00
|
|
|
{
|
Move Scatter from Worklet to Dispatcher
Previously, when a Worklet needed a scatter, the scatter object was
stored in the Worklet object. That was problematic because that means
the Scatter, which is a control object, was shoved into the execution
environment.
To prevent that, move the Scatter into the Dispatcher object. The
worklet still declares a ScatterType alias, but no longer has a
GetScatter method. Instead, the Dispatcher now takes a Scatter object in
its constructor. If using the default scatter (ScatterIdentity), the
default constructor is used. If using another type of Scatter that
requires data to set up its state, then the caller of the worklet needs
to provide that to the dispatcher. For convenience, worklets are
encouraged to have a MakeScatter method to help construct a proper
scatter object.
2018-04-27 04:43:51 +00:00
|
|
|
VTKM_CONT ScatterUniform() = default;
|
2015-11-07 11:57:16 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
Move Scatter from Worklet to Dispatcher
Previously, when a Worklet needed a scatter, the scatter object was
stored in the Worklet object. That was problematic because that means
the Scatter, which is a control object, was shoved into the execution
environment.
To prevent that, move the Scatter into the Dispatcher object. The
worklet still declares a ScatterType alias, but no longer has a
GetScatter method. Instead, the Dispatcher now takes a Scatter object in
its constructor. If using the default scatter (ScatterIdentity), the
default constructor is used. If using another type of Scatter that
requires data to set up its state, then the caller of the worklet needs
to provide that to the dispatcher. For convenience, worklets are
encouraged to have a MakeScatter method to help construct a proper
scatter object.
2018-04-27 04:43:51 +00:00
|
|
|
vtkm::Id GetOutputRange(vtkm::Id inputRange) const { return inputRange * NumOutputsPerInput; }
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2015-11-07 11:57:16 +00:00
|
|
|
vtkm::Id GetOutputRange(vtkm::Id3 inputRange) const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
return this->GetOutputRange(inputRange[0] * inputRange[1] * inputRange[2]);
|
2015-11-07 11:57:16 +00:00
|
|
|
}
|
|
|
|
|
Move Scatter from Worklet to Dispatcher
Previously, when a Worklet needed a scatter, the scatter object was
stored in the Worklet object. That was problematic because that means
the Scatter, which is a control object, was shoved into the execution
environment.
To prevent that, move the Scatter into the Dispatcher object. The
worklet still declares a ScatterType alias, but no longer has a
GetScatter method. Instead, the Dispatcher now takes a Scatter object in
its constructor. If using the default scatter (ScatterIdentity), the
default constructor is used. If using another type of Scatter that
requires data to set up its state, then the caller of the worklet needs
to provide that to the dispatcher. For convenience, worklets are
encouraged to have a MakeScatter method to help construct a proper
scatter object.
2018-04-27 04:43:51 +00:00
|
|
|
using OutputToInputMapType =
|
|
|
|
vtkm::cont::ArrayHandleImplicit<detail::FunctorDiv<NumOutputsPerInput>>;
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename RangeType>
|
|
|
|
VTKM_CONT OutputToInputMapType GetOutputToInputMap(RangeType inputRange) const
|
2015-11-07 11:57:16 +00:00
|
|
|
{
|
Move Scatter from Worklet to Dispatcher
Previously, when a Worklet needed a scatter, the scatter object was
stored in the Worklet object. That was problematic because that means
the Scatter, which is a control object, was shoved into the execution
environment.
To prevent that, move the Scatter into the Dispatcher object. The
worklet still declares a ScatterType alias, but no longer has a
GetScatter method. Instead, the Dispatcher now takes a Scatter object in
its constructor. If using the default scatter (ScatterIdentity), the
default constructor is used. If using another type of Scatter that
requires data to set up its state, then the caller of the worklet needs
to provide that to the dispatcher. For convenience, worklets are
encouraged to have a MakeScatter method to help construct a proper
scatter object.
2018-04-27 04:43:51 +00:00
|
|
|
return OutputToInputMapType(detail::FunctorDiv<NumOutputsPerInput>(),
|
2015-11-07 11:57:16 +00:00
|
|
|
this->GetOutputRange(inputRange));
|
|
|
|
}
|
|
|
|
|
Move Scatter from Worklet to Dispatcher
Previously, when a Worklet needed a scatter, the scatter object was
stored in the Worklet object. That was problematic because that means
the Scatter, which is a control object, was shoved into the execution
environment.
To prevent that, move the Scatter into the Dispatcher object. The
worklet still declares a ScatterType alias, but no longer has a
GetScatter method. Instead, the Dispatcher now takes a Scatter object in
its constructor. If using the default scatter (ScatterIdentity), the
default constructor is used. If using another type of Scatter that
requires data to set up its state, then the caller of the worklet needs
to provide that to the dispatcher. For convenience, worklets are
encouraged to have a MakeScatter method to help construct a proper
scatter object.
2018-04-27 04:43:51 +00:00
|
|
|
using VisitArrayType =
|
|
|
|
vtkm::cont::ArrayHandleImplicit<detail::FunctorModulus<NumOutputsPerInput>>;
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename RangeType>
|
|
|
|
VTKM_CONT VisitArrayType GetVisitArray(RangeType inputRange) const
|
2015-11-07 11:57:16 +00:00
|
|
|
{
|
Move Scatter from Worklet to Dispatcher
Previously, when a Worklet needed a scatter, the scatter object was
stored in the Worklet object. That was problematic because that means
the Scatter, which is a control object, was shoved into the execution
environment.
To prevent that, move the Scatter into the Dispatcher object. The
worklet still declares a ScatterType alias, but no longer has a
GetScatter method. Instead, the Dispatcher now takes a Scatter object in
its constructor. If using the default scatter (ScatterIdentity), the
default constructor is used. If using another type of Scatter that
requires data to set up its state, then the caller of the worklet needs
to provide that to the dispatcher. For convenience, worklets are
encouraged to have a MakeScatter method to help construct a proper
scatter object.
2018-04-27 04:43:51 +00:00
|
|
|
return VisitArrayType(detail::FunctorModulus<NumOutputsPerInput>(),
|
2015-11-07 11:57:16 +00:00
|
|
|
this->GetOutputRange(inputRange));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} // namespace vtkm::worklet
|
|
|
|
|
|
|
|
#endif //vtk_m_worklet_ScatterUniform_h
|