2015-04-13 20:43:18 +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.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Copyright 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
2015-04-13 20:43:18 +00:00
|
|
|
// Copyright 2015 UT-Battelle, LLC.
|
2015-05-21 12:09:22 +00:00
|
|
|
// Copyright 2015 Los Alamos National Security.
|
2015-04-13 20:43:18 +00:00
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
2015-04-13 20:43:18 +00:00
|
|
|
// the U.S. Government retains certain rights in this software.
|
|
|
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
|
|
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
|
|
|
// this software.
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
#ifndef vtk_m_cont_ArrayHandleTransform_h
|
|
|
|
#define vtk_m_cont_ArrayHandleTransform_h
|
|
|
|
|
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
2017-01-09 21:15:32 +00:00
|
|
|
#include <vtkm/cont/ErrorBadType.h>
|
|
|
|
#include <vtkm/cont/ErrorInternal.h>
|
2018-09-08 17:07:06 +00:00
|
|
|
#include <vtkm/cont/ExecutionAndControlObjectBase.h>
|
2018-09-05 16:07:23 +00:00
|
|
|
#include <vtkm/cont/RuntimeDeviceTracker.h>
|
2015-04-13 20:43:18 +00:00
|
|
|
|
2018-10-30 13:49:41 +00:00
|
|
|
#include <vtkm/cont/serial/internal/DeviceAdapterRuntimeDetectorSerial.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
|
|
|
namespace internal
|
|
|
|
{
|
2015-09-22 14:11:51 +00:00
|
|
|
|
|
|
|
/// Tag used in place of an inverse functor.
|
2017-05-18 14:29:41 +00:00
|
|
|
struct NullFunctorType
|
|
|
|
{
|
|
|
|
};
|
2015-09-22 14:11:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace vtkm::cont::internal
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace exec
|
|
|
|
{
|
|
|
|
namespace internal
|
|
|
|
{
|
2015-09-22 14:11:51 +00:00
|
|
|
|
2017-08-16 15:34:21 +00:00
|
|
|
using NullFunctorType = vtkm::cont::internal::NullFunctorType;
|
2015-09-22 14:11:51 +00:00
|
|
|
|
2015-04-13 20:43:18 +00:00
|
|
|
/// \brief An array portal that transforms a value from another portal.
|
|
|
|
///
|
2017-05-26 17:53:28 +00:00
|
|
|
template <typename ValueType_,
|
|
|
|
typename PortalType_,
|
|
|
|
typename FunctorType_,
|
2017-05-18 14:29:41 +00:00
|
|
|
typename InverseFunctorType_ = NullFunctorType>
|
2016-12-19 19:39:17 +00:00
|
|
|
class VTKM_ALWAYS_EXPORT ArrayPortalTransform;
|
2015-09-22 14:11:51 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ValueType_, typename PortalType_, typename FunctorType_>
|
|
|
|
class VTKM_ALWAYS_EXPORT
|
|
|
|
ArrayPortalTransform<ValueType_, PortalType_, FunctorType_, NullFunctorType>
|
2015-04-13 20:43:18 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-08-16 15:34:21 +00:00
|
|
|
using PortalType = PortalType_;
|
|
|
|
using ValueType = ValueType_;
|
|
|
|
using FunctorType = FunctorType_;
|
2015-04-13 20:43:18 +00:00
|
|
|
|
2016-08-02 15:26:29 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
ArrayPortalTransform(const PortalType& portal = PortalType(),
|
|
|
|
const FunctorType& functor = FunctorType())
|
|
|
|
: Portal(portal)
|
|
|
|
, Functor(functor)
|
|
|
|
{
|
|
|
|
}
|
2015-04-13 20:43:18 +00:00
|
|
|
|
2016-08-02 15:26:29 +00:00
|
|
|
/// Copy constructor for any other ArrayPortalTransform with an iterator
|
2015-04-27 14:13:11 +00:00
|
|
|
/// type that can be copied to this iterator type. This allows us to do any
|
|
|
|
/// type casting that the iterators do (like the non-const to const cast).
|
2015-04-13 20:43:18 +00:00
|
|
|
///
|
2016-08-02 15:26:29 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2017-05-18 14:29:41 +00:00
|
|
|
template <class OtherV, class OtherP, class OtherF>
|
|
|
|
VTKM_EXEC_CONT ArrayPortalTransform(const ArrayPortalTransform<OtherV, OtherP, OtherF>& src)
|
|
|
|
: Portal(src.GetPortal())
|
|
|
|
, Functor(src.GetFunctor())
|
|
|
|
{
|
|
|
|
}
|
2015-04-13 20:43:18 +00:00
|
|
|
|
2016-08-02 15:26:29 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Id GetNumberOfValues() const { return this->Portal.GetNumberOfValues(); }
|
2015-04-13 20:43:18 +00:00
|
|
|
|
2016-08-02 15:26:29 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
ValueType Get(vtkm::Id index) const { return this->Functor(this->Portal.Get(index)); }
|
2015-04-13 20:43:18 +00:00
|
|
|
|
2017-01-31 19:13:45 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void Set(vtkm::Id vtkmNotUsed(index), const ValueType& vtkmNotUsed(value)) const
|
2017-01-31 19:13:45 +00:00
|
|
|
{
|
2017-02-02 15:04:35 +00:00
|
|
|
#if !(defined(VTKM_MSVC) && defined(VTKM_CUDA))
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_ASSERT(false &&
|
|
|
|
"Cannot write to read-only transform array. (No inverse transform given.)");
|
2017-02-02 15:04:35 +00:00
|
|
|
#endif
|
2017-01-31 19:13:45 +00:00
|
|
|
}
|
|
|
|
|
2016-08-02 15:26:29 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
const PortalType& GetPortal() const { return this->Portal; }
|
2015-04-13 20:43:18 +00:00
|
|
|
|
2016-08-02 15:26:29 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
const FunctorType& GetFunctor() const { return this->Functor; }
|
2015-04-13 20:43:18 +00:00
|
|
|
|
2015-09-22 14:11:51 +00:00
|
|
|
protected:
|
2015-04-13 20:43:18 +00:00
|
|
|
PortalType Portal;
|
|
|
|
FunctorType Functor;
|
|
|
|
};
|
|
|
|
|
2017-05-26 17:53:28 +00:00
|
|
|
template <typename ValueType_,
|
|
|
|
typename PortalType_,
|
|
|
|
typename FunctorType_,
|
2017-05-18 14:29:41 +00:00
|
|
|
typename InverseFunctorType_>
|
|
|
|
class VTKM_ALWAYS_EXPORT ArrayPortalTransform
|
|
|
|
: public ArrayPortalTransform<ValueType_, PortalType_, FunctorType_, NullFunctorType>
|
2015-09-22 14:11:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-08-16 15:34:21 +00:00
|
|
|
using Superclass = ArrayPortalTransform<ValueType_, PortalType_, FunctorType_, NullFunctorType>;
|
|
|
|
using PortalType = PortalType_;
|
|
|
|
using ValueType = ValueType_;
|
|
|
|
using FunctorType = FunctorType_;
|
|
|
|
using InverseFunctorType = InverseFunctorType_;
|
2015-09-22 14:11:51 +00:00
|
|
|
|
2016-08-02 15:26:29 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
ArrayPortalTransform(const PortalType& portal = PortalType(),
|
|
|
|
const FunctorType& functor = FunctorType(),
|
|
|
|
const InverseFunctorType& inverseFunctor = InverseFunctorType())
|
|
|
|
: Superclass(portal, functor)
|
|
|
|
, InverseFunctor(inverseFunctor)
|
|
|
|
{
|
|
|
|
}
|
2015-09-22 14:11:51 +00:00
|
|
|
|
2016-08-02 15:26:29 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2017-05-18 14:29:41 +00:00
|
|
|
template <class OtherV, class OtherP, class OtherF, class OtherInvF>
|
|
|
|
VTKM_EXEC_CONT ArrayPortalTransform(
|
|
|
|
const ArrayPortalTransform<OtherV, OtherP, OtherF, OtherInvF>& src)
|
|
|
|
: Superclass(src)
|
|
|
|
, InverseFunctor(src.GetInverseFunctor())
|
|
|
|
{
|
|
|
|
}
|
2015-09-22 14:11:51 +00:00
|
|
|
|
2016-08-02 15:26:29 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void Set(vtkm::Id index, const ValueType& value) const
|
|
|
|
{
|
|
|
|
return this->Portal.Set(index, this->InverseFunctor(value));
|
2015-09-22 14:11:51 +00:00
|
|
|
}
|
|
|
|
|
2016-08-02 15:26:29 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
const InverseFunctorType& GetInverseFunctor() const { return this->InverseFunctor; }
|
2015-09-22 14:11:51 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
InverseFunctorType InverseFunctor;
|
|
|
|
};
|
2015-04-27 14:13:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace vtkm::exec::internal
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
2015-04-27 14:13:11 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace internal
|
|
|
|
{
|
2015-04-27 14:13:11 +00:00
|
|
|
|
2018-09-08 17:07:06 +00:00
|
|
|
template <typename ProvidedFunctorType, typename FunctorIsExecContObject>
|
2018-09-05 16:07:23 +00:00
|
|
|
struct TransformFunctorManagerImpl;
|
|
|
|
|
2018-09-08 17:07:06 +00:00
|
|
|
template <typename ProvidedFunctorType>
|
|
|
|
struct TransformFunctorManagerImpl<ProvidedFunctorType, std::false_type>
|
2018-09-05 16:07:23 +00:00
|
|
|
{
|
2018-09-08 17:07:06 +00:00
|
|
|
VTKM_STATIC_ASSERT_MSG(!vtkm::cont::internal::IsExecutionObjectBase<ProvidedFunctorType>::value,
|
|
|
|
"Must use an ExecutionAndControlObject instead of an ExecutionObject.");
|
|
|
|
|
2018-09-05 16:07:23 +00:00
|
|
|
ProvidedFunctorType Functor;
|
2018-09-08 17:07:06 +00:00
|
|
|
using FunctorType = ProvidedFunctorType;
|
2018-09-05 16:07:23 +00:00
|
|
|
|
|
|
|
TransformFunctorManagerImpl() = default;
|
|
|
|
|
|
|
|
VTKM_CONT
|
|
|
|
TransformFunctorManagerImpl(const ProvidedFunctorType& functor)
|
|
|
|
: Functor(functor)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT
|
2018-09-08 17:07:06 +00:00
|
|
|
ProvidedFunctorType PrepareForControl() const { return this->Functor; }
|
|
|
|
|
|
|
|
template <typename Device>
|
|
|
|
VTKM_CONT ProvidedFunctorType PrepareForExecution(Device) const
|
|
|
|
{
|
|
|
|
return this->Functor;
|
|
|
|
}
|
2018-09-05 16:07:23 +00:00
|
|
|
};
|
|
|
|
|
2018-09-08 17:07:06 +00:00
|
|
|
template <typename ProvidedFunctorType>
|
|
|
|
struct TransformFunctorManagerImpl<ProvidedFunctorType, std::true_type>
|
2018-09-05 16:07:23 +00:00
|
|
|
{
|
2018-09-08 17:07:06 +00:00
|
|
|
VTKM_IS_EXECUTION_AND_CONTROL_OBJECT(ProvidedFunctorType);
|
|
|
|
|
2018-09-05 16:07:23 +00:00
|
|
|
ProvidedFunctorType Functor;
|
2018-09-08 17:07:06 +00:00
|
|
|
// using FunctorType = decltype(std::declval<ProvidedFunctorType>().PrepareForControl());
|
|
|
|
using FunctorType = decltype(Functor.PrepareForControl());
|
2018-09-05 16:07:23 +00:00
|
|
|
|
|
|
|
TransformFunctorManagerImpl() = default;
|
|
|
|
|
|
|
|
VTKM_CONT
|
|
|
|
TransformFunctorManagerImpl(const ProvidedFunctorType& functor)
|
|
|
|
: Functor(functor)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT
|
2018-09-08 17:07:06 +00:00
|
|
|
auto PrepareForControl() const -> decltype(this->Functor.PrepareForControl())
|
|
|
|
{
|
|
|
|
return this->Functor.PrepareForControl();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Device>
|
|
|
|
VTKM_CONT auto PrepareForExecution(Device device) const
|
|
|
|
-> decltype(this->Functor.PrepareForExecution(device))
|
|
|
|
{
|
|
|
|
return this->Functor.PrepareForExecution(device);
|
|
|
|
}
|
2018-09-05 16:07:23 +00:00
|
|
|
};
|
|
|
|
|
2018-09-08 17:07:06 +00:00
|
|
|
template <typename ProvidedFunctorType>
|
2018-09-05 16:07:23 +00:00
|
|
|
struct TransformFunctorManager
|
|
|
|
: TransformFunctorManagerImpl<
|
|
|
|
ProvidedFunctorType,
|
2018-09-08 17:07:06 +00:00
|
|
|
typename vtkm::cont::internal::IsExecutionAndControlObjectBase<ProvidedFunctorType>::type>
|
2018-09-05 16:07:23 +00:00
|
|
|
{
|
|
|
|
using Superclass = TransformFunctorManagerImpl<
|
|
|
|
ProvidedFunctorType,
|
2018-09-08 17:07:06 +00:00
|
|
|
typename vtkm::cont::internal::IsExecutionAndControlObjectBase<ProvidedFunctorType>::type>;
|
2018-09-05 16:07:23 +00:00
|
|
|
using FunctorType = typename Superclass::FunctorType;
|
|
|
|
|
|
|
|
VTKM_CONT TransformFunctorManager() = default;
|
|
|
|
|
|
|
|
VTKM_CONT TransformFunctorManager(const TransformFunctorManager& other) = default;
|
|
|
|
|
|
|
|
VTKM_CONT TransformFunctorManager(const ProvidedFunctorType& functor)
|
|
|
|
: Superclass(functor)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ValueType>
|
|
|
|
using TransformedValueType = decltype(std::declval<FunctorType>()(ValueType{}));
|
|
|
|
};
|
|
|
|
|
2017-05-30 14:00:01 +00:00
|
|
|
template <typename ArrayHandleType,
|
2017-05-26 17:53:28 +00:00
|
|
|
typename FunctorType,
|
2017-05-18 14:29:41 +00:00
|
|
|
typename InverseFunctorType = NullFunctorType>
|
|
|
|
struct VTKM_ALWAYS_EXPORT StorageTagTransform
|
|
|
|
{
|
2018-09-05 16:07:23 +00:00
|
|
|
using FunctorManager = TransformFunctorManager<FunctorType>;
|
|
|
|
using ValueType =
|
|
|
|
typename FunctorManager::template TransformedValueType<typename ArrayHandleType::ValueType>;
|
2017-05-18 14:29:41 +00:00
|
|
|
};
|
2015-04-13 20:43:18 +00:00
|
|
|
|
2017-05-30 14:00:01 +00:00
|
|
|
template <typename ArrayHandleType, typename FunctorType>
|
|
|
|
class Storage<typename StorageTagTransform<ArrayHandleType, FunctorType>::ValueType,
|
|
|
|
StorageTagTransform<ArrayHandleType, FunctorType>>
|
2015-04-13 20:43:18 +00:00
|
|
|
{
|
2018-09-05 16:07:23 +00:00
|
|
|
using FunctorManager = TransformFunctorManager<FunctorType>;
|
|
|
|
|
2015-04-13 20:43:18 +00:00
|
|
|
public:
|
2017-08-16 15:34:21 +00:00
|
|
|
using ValueType = typename StorageTagTransform<ArrayHandleType, FunctorType>::ValueType;
|
2015-04-13 20:43:18 +00:00
|
|
|
|
2015-09-30 19:47:16 +00:00
|
|
|
// This is meant to be invalid. Because Transform arrays are read only, you
|
|
|
|
// should only be able to use the const version.
|
|
|
|
struct PortalType
|
|
|
|
{
|
2017-08-16 15:34:21 +00:00
|
|
|
using ValueType = void*;
|
|
|
|
using IteratorType = void*;
|
2015-09-30 19:47:16 +00:00
|
|
|
};
|
|
|
|
|
2017-08-16 15:34:21 +00:00
|
|
|
using PortalConstType =
|
|
|
|
vtkm::exec::internal::ArrayPortalTransform<ValueType,
|
|
|
|
typename ArrayHandleType::PortalConstControl,
|
2018-09-05 16:07:23 +00:00
|
|
|
typename FunctorManager::FunctorType>;
|
2015-04-13 20:43:18 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
Storage()
|
|
|
|
: Valid(false)
|
|
|
|
{
|
|
|
|
}
|
2015-04-13 20:43:18 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
Storage(const ArrayHandleType& array, const FunctorType& functor = FunctorType())
|
|
|
|
: Array(array)
|
|
|
|
, Functor(functor)
|
|
|
|
, Valid(true)
|
|
|
|
{
|
|
|
|
}
|
2015-04-13 20:43:18 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
PortalType GetPortal()
|
|
|
|
{
|
2018-09-05 16:07:23 +00:00
|
|
|
throw vtkm::cont::ErrorBadType(
|
|
|
|
"ArrayHandleTransform is read only. Cannot get writable portal.");
|
2015-04-13 20:43:18 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
PortalConstType GetPortalConst() const
|
|
|
|
{
|
2016-04-20 21:41:14 +00:00
|
|
|
VTKM_ASSERT(this->Valid);
|
2019-03-15 19:59:02 +00:00
|
|
|
vtkm::cont::ScopedRuntimeDeviceTracker trackerScope;
|
|
|
|
vtkm::cont::GetRuntimeDeviceTracker().ForceDevice(vtkm::cont::DeviceAdapterTagSerial());
|
2018-09-08 17:07:06 +00:00
|
|
|
return PortalConstType(this->Array.GetPortalConstControl(), this->Functor.PrepareForControl());
|
2015-04-13 20:43:18 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Id GetNumberOfValues() const
|
|
|
|
{
|
2016-04-20 21:41:14 +00:00
|
|
|
VTKM_ASSERT(this->Valid);
|
2015-04-13 20:43:18 +00:00
|
|
|
return this->Array.GetNumberOfValues();
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void Allocate(vtkm::Id vtkmNotUsed(numberOfValues))
|
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorBadType("ArrayHandleTransform is read only. It cannot be allocated.");
|
2015-04-13 20:43:18 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void Shrink(vtkm::Id vtkmNotUsed(numberOfValues))
|
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorBadType("ArrayHandleTransform is read only. It cannot shrink.");
|
2015-04-13 20:43:18 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void ReleaseResources()
|
|
|
|
{
|
2015-04-13 20:43:18 +00:00
|
|
|
// This request is ignored since it is asking to release the resources
|
|
|
|
// of the delegate array, which may be used elsewhere. Should the behavior
|
|
|
|
// be different?
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
const ArrayHandleType& GetArray() const
|
|
|
|
{
|
2016-04-20 21:41:14 +00:00
|
|
|
VTKM_ASSERT(this->Valid);
|
2015-04-13 20:43:18 +00:00
|
|
|
return this->Array;
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2018-09-05 16:07:23 +00:00
|
|
|
const FunctorManager& GetFunctor() const { return this->Functor; }
|
2015-09-29 14:36:11 +00:00
|
|
|
|
2015-04-13 20:43:18 +00:00
|
|
|
private:
|
|
|
|
ArrayHandleType Array;
|
2018-09-05 16:07:23 +00:00
|
|
|
FunctorManager Functor;
|
2015-04-13 20:43:18 +00:00
|
|
|
bool Valid;
|
|
|
|
};
|
|
|
|
|
2017-05-30 14:00:01 +00:00
|
|
|
template <typename ArrayHandleType, typename FunctorType, typename InverseFunctorType>
|
|
|
|
class Storage<
|
|
|
|
typename StorageTagTransform<ArrayHandleType, FunctorType, InverseFunctorType>::ValueType,
|
|
|
|
StorageTagTransform<ArrayHandleType, FunctorType, InverseFunctorType>>
|
2015-09-22 14:11:51 +00:00
|
|
|
{
|
2018-09-05 16:07:23 +00:00
|
|
|
using FunctorManager = TransformFunctorManager<FunctorType>;
|
|
|
|
using InverseFunctorManager = TransformFunctorManager<InverseFunctorType>;
|
|
|
|
|
2015-09-22 14:11:51 +00:00
|
|
|
public:
|
2017-08-16 15:34:21 +00:00
|
|
|
using ValueType =
|
|
|
|
typename StorageTagTransform<ArrayHandleType, FunctorType, InverseFunctorType>::ValueType;
|
2015-09-22 14:11:51 +00:00
|
|
|
|
2017-08-16 15:34:21 +00:00
|
|
|
using PortalType =
|
|
|
|
vtkm::exec::internal::ArrayPortalTransform<ValueType,
|
|
|
|
typename ArrayHandleType::PortalControl,
|
2018-09-05 16:07:23 +00:00
|
|
|
typename FunctorManager::FunctorType,
|
|
|
|
typename InverseFunctorManager::FunctorType>;
|
2017-08-16 15:34:21 +00:00
|
|
|
using PortalConstType =
|
|
|
|
vtkm::exec::internal::ArrayPortalTransform<ValueType,
|
|
|
|
typename ArrayHandleType::PortalConstControl,
|
2018-09-05 16:07:23 +00:00
|
|
|
typename FunctorManager::FunctorType,
|
|
|
|
typename InverseFunctorManager::FunctorType>;
|
2015-09-22 14:11:51 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
Storage()
|
|
|
|
: Valid(false)
|
|
|
|
{
|
|
|
|
}
|
2015-09-22 14:11:51 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-26 17:53:28 +00:00
|
|
|
Storage(const ArrayHandleType& array,
|
|
|
|
const FunctorType& functor,
|
2017-05-18 14:29:41 +00:00
|
|
|
const InverseFunctorType& inverseFunctor)
|
|
|
|
: Array(array)
|
|
|
|
, Functor(functor)
|
|
|
|
, InverseFunctor(inverseFunctor)
|
|
|
|
, Valid(true)
|
|
|
|
{
|
|
|
|
}
|
2015-09-22 14:11:51 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
PortalType GetPortal()
|
|
|
|
{
|
2016-04-20 21:41:14 +00:00
|
|
|
VTKM_ASSERT(this->Valid);
|
2019-03-15 19:59:02 +00:00
|
|
|
vtkm::cont::ScopedRuntimeDeviceTracker trackerScope;
|
|
|
|
vtkm::cont::GetRuntimeDeviceTracker().ForceDevice(vtkm::cont::DeviceAdapterTagSerial());
|
2018-09-05 16:07:23 +00:00
|
|
|
return PortalType(this->Array.GetPortalControl(),
|
2018-09-08 17:07:06 +00:00
|
|
|
this->Functor.PrepareForControl(),
|
|
|
|
this->InverseFunctor.PrepareForControl());
|
2015-09-22 14:11:51 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
PortalConstType GetPortalConst() const
|
|
|
|
{
|
2016-04-20 21:41:14 +00:00
|
|
|
VTKM_ASSERT(this->Valid);
|
2019-03-15 19:59:02 +00:00
|
|
|
vtkm::cont::ScopedRuntimeDeviceTracker trackerScope;
|
|
|
|
vtkm::cont::GetRuntimeDeviceTracker().ForceDevice(vtkm::cont::DeviceAdapterTagSerial());
|
2018-09-05 16:07:23 +00:00
|
|
|
return PortalConstType(this->Array.GetPortalConstControl(),
|
2018-09-08 17:07:06 +00:00
|
|
|
this->Functor.PrepareForControl(),
|
|
|
|
this->InverseFunctor.PrepareForControl());
|
2015-09-22 14:11:51 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Id GetNumberOfValues() const
|
|
|
|
{
|
2016-04-20 21:41:14 +00:00
|
|
|
VTKM_ASSERT(this->Valid);
|
2015-09-22 14:11:51 +00:00
|
|
|
return this->Array.GetNumberOfValues();
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void Allocate(vtkm::Id numberOfValues)
|
|
|
|
{
|
2015-09-22 14:11:51 +00:00
|
|
|
this->Array.Allocate(numberOfValues);
|
|
|
|
this->Valid = true;
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void Shrink(vtkm::Id numberOfValues) { this->Array.Shrink(numberOfValues); }
|
2015-09-22 14:11:51 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void ReleaseResources()
|
|
|
|
{
|
2015-09-22 14:11:51 +00:00
|
|
|
this->Array.ReleaseResources();
|
|
|
|
this->Valid = false;
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
const ArrayHandleType& GetArray() const
|
|
|
|
{
|
2016-04-20 21:41:14 +00:00
|
|
|
VTKM_ASSERT(this->Valid);
|
2015-09-22 14:11:51 +00:00
|
|
|
return this->Array;
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2018-09-05 16:07:23 +00:00
|
|
|
const FunctorManager& GetFunctor() const { return this->Functor; }
|
2015-09-22 14:11:51 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2018-09-05 16:07:23 +00:00
|
|
|
const InverseFunctorManager& GetInverseFunctor() const { return this->InverseFunctor; }
|
2015-09-22 14:11:51 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
ArrayHandleType Array;
|
2018-09-05 16:07:23 +00:00
|
|
|
FunctorManager Functor;
|
|
|
|
InverseFunctorManager InverseFunctor;
|
2015-09-22 14:11:51 +00:00
|
|
|
bool Valid;
|
|
|
|
};
|
|
|
|
|
2017-05-30 14:00:01 +00:00
|
|
|
template <typename ArrayHandleType, typename FunctorType, typename Device>
|
|
|
|
class ArrayTransfer<typename StorageTagTransform<ArrayHandleType, FunctorType>::ValueType,
|
|
|
|
StorageTagTransform<ArrayHandleType, FunctorType>,
|
|
|
|
Device>
|
2015-04-13 20:43:18 +00:00
|
|
|
{
|
2017-08-16 15:34:21 +00:00
|
|
|
using StorageTag = StorageTagTransform<ArrayHandleType, FunctorType>;
|
2018-09-08 17:07:06 +00:00
|
|
|
using FunctorManager = TransformFunctorManager<FunctorType>;
|
2015-04-13 20:43:18 +00:00
|
|
|
|
|
|
|
public:
|
2017-08-16 15:34:21 +00:00
|
|
|
using ValueType = typename StorageTagTransform<ArrayHandleType, FunctorType>::ValueType;
|
|
|
|
using StorageType = vtkm::cont::internal::Storage<ValueType, StorageTag>;
|
2015-04-13 20:43:18 +00:00
|
|
|
|
2017-08-16 15:34:21 +00:00
|
|
|
using PortalControl = typename StorageType::PortalType;
|
|
|
|
using PortalConstControl = typename StorageType::PortalConstType;
|
2015-04-13 20:43:18 +00:00
|
|
|
|
2015-09-30 19:47:16 +00:00
|
|
|
//meant to be an invalid writeable execution portal
|
2017-08-16 15:34:21 +00:00
|
|
|
using PortalExecution = typename StorageType::PortalType;
|
|
|
|
using PortalConstExecution = vtkm::exec::internal::ArrayPortalTransform<
|
2017-05-26 17:53:28 +00:00
|
|
|
ValueType,
|
|
|
|
typename ArrayHandleType::template ExecutionTypes<Device>::PortalConst,
|
2018-09-05 16:07:23 +00:00
|
|
|
typename FunctorManager::FunctorType>;
|
2015-04-13 20:43:18 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
ArrayTransfer(StorageType* storage)
|
|
|
|
: Array(storage->GetArray())
|
|
|
|
, Functor(storage->GetFunctor())
|
|
|
|
{
|
|
|
|
}
|
2015-04-13 20:43:18 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Id GetNumberOfValues() const { return this->Array.GetNumberOfValues(); }
|
2015-04-13 20:43:18 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
PortalConstExecution PrepareForInput(bool vtkmNotUsed(updateData))
|
|
|
|
{
|
2018-09-08 17:07:06 +00:00
|
|
|
return PortalConstExecution(this->Array.PrepareForInput(Device()),
|
|
|
|
this->Functor.PrepareForExecution(Device()));
|
2015-04-13 20:43:18 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
PortalExecution PrepareForInPlace(bool& vtkmNotUsed(updateData))
|
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorBadType("ArrayHandleTransform read only. "
|
|
|
|
"Cannot be used for in-place operations.");
|
2015-04-13 20:43:18 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
PortalExecution PrepareForOutput(vtkm::Id vtkmNotUsed(numberOfValues))
|
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorBadType("ArrayHandleTransform read only. Cannot be used as output.");
|
2015-04-13 20:43:18 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void RetrieveOutputData(StorageType* vtkmNotUsed(storage)) const
|
|
|
|
{
|
2017-01-09 21:15:32 +00:00
|
|
|
throw vtkm::cont::ErrorInternal(
|
2017-05-18 14:29:41 +00:00
|
|
|
"ArrayHandleTransform read only. "
|
2018-01-30 00:24:31 +00:00
|
|
|
"There should be no occurrence of the ArrayHandle trying to pull "
|
2017-05-18 14:29:41 +00:00
|
|
|
"data from the execution environment.");
|
2015-04-13 20:43:18 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void Shrink(vtkm::Id vtkmNotUsed(numberOfValues))
|
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorBadType("ArrayHandleTransform read only. Cannot shrink.");
|
2015-04-13 20:43:18 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void ReleaseResources() { this->Array.ReleaseResourcesExecution(); }
|
2015-04-13 20:43:18 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
ArrayHandleType Array;
|
2018-09-05 16:07:23 +00:00
|
|
|
FunctorManager Functor;
|
2015-04-13 20:43:18 +00:00
|
|
|
};
|
|
|
|
|
2017-05-30 14:00:01 +00:00
|
|
|
template <typename ArrayHandleType,
|
2017-05-26 17:53:28 +00:00
|
|
|
typename FunctorType,
|
|
|
|
typename InverseFunctorType,
|
2017-05-18 14:29:41 +00:00
|
|
|
typename Device>
|
2017-05-30 14:00:01 +00:00
|
|
|
class ArrayTransfer<
|
|
|
|
typename StorageTagTransform<ArrayHandleType, FunctorType, InverseFunctorType>::ValueType,
|
|
|
|
StorageTagTransform<ArrayHandleType, FunctorType, InverseFunctorType>,
|
|
|
|
Device>
|
2015-09-22 14:11:51 +00:00
|
|
|
{
|
2017-08-16 15:34:21 +00:00
|
|
|
using StorageTag = StorageTagTransform<ArrayHandleType, FunctorType, InverseFunctorType>;
|
2018-09-08 17:07:06 +00:00
|
|
|
using FunctorManager = TransformFunctorManager<FunctorType>;
|
|
|
|
using InverseFunctorManager = TransformFunctorManager<InverseFunctorType>;
|
2015-09-22 14:11:51 +00:00
|
|
|
|
|
|
|
public:
|
2017-08-16 15:34:21 +00:00
|
|
|
using ValueType = typename StorageTagTransform<ArrayHandleType, FunctorType>::ValueType;
|
|
|
|
using StorageType = vtkm::cont::internal::Storage<ValueType, StorageTag>;
|
2015-09-22 14:11:51 +00:00
|
|
|
|
2017-08-16 15:34:21 +00:00
|
|
|
using PortalControl = typename StorageType::PortalType;
|
|
|
|
using PortalConstControl = typename StorageType::PortalConstType;
|
2015-09-22 14:11:51 +00:00
|
|
|
|
2017-08-16 15:34:21 +00:00
|
|
|
using PortalExecution = vtkm::exec::internal::ArrayPortalTransform<
|
2017-05-26 17:53:28 +00:00
|
|
|
ValueType,
|
|
|
|
typename ArrayHandleType::template ExecutionTypes<Device>::Portal,
|
2018-09-05 16:07:23 +00:00
|
|
|
typename FunctorManager::FunctorType,
|
|
|
|
typename InverseFunctorManager::FunctorType>;
|
2017-08-16 15:34:21 +00:00
|
|
|
using PortalConstExecution = vtkm::exec::internal::ArrayPortalTransform<
|
2017-05-26 17:53:28 +00:00
|
|
|
ValueType,
|
|
|
|
typename ArrayHandleType::template ExecutionTypes<Device>::PortalConst,
|
2018-09-05 16:07:23 +00:00
|
|
|
typename FunctorManager::FunctorType,
|
|
|
|
typename InverseFunctorManager::FunctorType>;
|
2015-09-22 14:11:51 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
ArrayTransfer(StorageType* storage)
|
|
|
|
: Array(storage->GetArray())
|
|
|
|
, Functor(storage->GetFunctor())
|
|
|
|
, InverseFunctor(storage->GetInverseFunctor())
|
|
|
|
{
|
|
|
|
}
|
2015-09-22 14:11:51 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Id GetNumberOfValues() const { return this->Array.GetNumberOfValues(); }
|
2015-09-22 14:11:51 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
PortalConstExecution PrepareForInput(bool vtkmNotUsed(updateData))
|
|
|
|
{
|
2018-09-05 16:07:23 +00:00
|
|
|
return PortalConstExecution(this->Array.PrepareForInput(Device()),
|
2018-09-08 17:07:06 +00:00
|
|
|
this->Functor.PrepareForExecution(Device()),
|
|
|
|
this->InverseFunctor.PrepareForExecution(Device()));
|
2015-09-22 14:11:51 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
PortalExecution PrepareForInPlace(bool& vtkmNotUsed(updateData))
|
|
|
|
{
|
2018-09-05 16:07:23 +00:00
|
|
|
return PortalExecution(this->Array.PrepareForInPlace(Device()),
|
2018-09-08 17:07:06 +00:00
|
|
|
this->Functor.PrepareForExecution(Device()),
|
|
|
|
this->InverseFunctor.PrepareForExecution(Device()));
|
2015-09-22 14:11:51 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
PortalExecution PrepareForOutput(vtkm::Id numberOfValues)
|
|
|
|
{
|
2018-09-05 16:07:23 +00:00
|
|
|
return PortalExecution(this->Array.PrepareForOutput(numberOfValues, Device()),
|
2018-09-08 17:07:06 +00:00
|
|
|
this->Functor.PrepareForExecution(Device()),
|
|
|
|
this->InverseFunctor.PrepareForExecution(Device()));
|
2015-09-22 14:11:51 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void RetrieveOutputData(StorageType* vtkmNotUsed(storage)) const
|
|
|
|
{
|
2015-09-22 14:11:51 +00:00
|
|
|
// Implementation of this method should be unnecessary. The internal
|
|
|
|
// array handle should automatically retrieve the output data as necessary.
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void Shrink(vtkm::Id numberOfValues) { this->Array.Shrink(numberOfValues); }
|
2015-09-22 14:11:51 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void ReleaseResources() { this->Array.ReleaseResourcesExecution(); }
|
2015-09-22 14:11:51 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
ArrayHandleType Array;
|
2018-09-05 16:07:23 +00:00
|
|
|
FunctorManager Functor;
|
|
|
|
InverseFunctorManager InverseFunctor;
|
2015-09-22 14:11:51 +00:00
|
|
|
};
|
|
|
|
|
2015-04-13 20:43:18 +00:00
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
/// \brief Implicitly transform values of one array to another with a functor.
|
|
|
|
///
|
|
|
|
/// ArrayHandleTransforms is a specialization of ArrayHandle. It takes a
|
|
|
|
/// delegate array handle and makes a new handle that calls a given unary
|
|
|
|
/// functor with the element at a given index and returns the result of the
|
|
|
|
/// functor as the value of this array at that position. This transformation is
|
|
|
|
/// done on demand. That is, rather than make a new copy of the array with new
|
|
|
|
/// values, the transformation is done as values are read from the array. Thus,
|
|
|
|
/// the functor operator should work in both the control and execution
|
|
|
|
/// environments.
|
|
|
|
///
|
2017-05-30 14:00:01 +00:00
|
|
|
template <typename ArrayHandleType,
|
2017-05-26 17:53:28 +00:00
|
|
|
typename FunctorType,
|
2017-05-18 14:29:41 +00:00
|
|
|
typename InverseFunctorType = internal::NullFunctorType>
|
2015-09-22 14:11:51 +00:00
|
|
|
class ArrayHandleTransform;
|
|
|
|
|
2017-05-30 14:00:01 +00:00
|
|
|
template <typename ArrayHandleType, typename FunctorType>
|
|
|
|
class ArrayHandleTransform<ArrayHandleType, FunctorType, internal::NullFunctorType>
|
|
|
|
: public vtkm::cont::ArrayHandle<
|
|
|
|
typename internal::StorageTagTransform<ArrayHandleType, FunctorType>::ValueType,
|
|
|
|
internal::StorageTagTransform<ArrayHandleType, FunctorType>>
|
2015-04-13 20:43:18 +00:00
|
|
|
{
|
|
|
|
// If the following line gives a compile error, then the ArrayHandleType
|
|
|
|
// template argument is not a valid ArrayHandle type.
|
|
|
|
VTKM_IS_ARRAY_HANDLE(ArrayHandleType);
|
|
|
|
|
2015-09-20 06:28:11 +00:00
|
|
|
public:
|
2015-10-21 19:36:27 +00:00
|
|
|
VTKM_ARRAY_HANDLE_SUBCLASS(
|
2017-05-26 17:53:28 +00:00
|
|
|
ArrayHandleTransform,
|
2017-05-30 14:00:01 +00:00
|
|
|
(ArrayHandleTransform<ArrayHandleType, FunctorType>),
|
|
|
|
(vtkm::cont::ArrayHandle<
|
|
|
|
typename internal::StorageTagTransform<ArrayHandleType, FunctorType>::ValueType,
|
|
|
|
internal::StorageTagTransform<ArrayHandleType, FunctorType>>));
|
2015-09-20 06:28:11 +00:00
|
|
|
|
|
|
|
private:
|
2017-08-16 15:34:21 +00:00
|
|
|
using StorageType = vtkm::cont::internal::Storage<ValueType, StorageTag>;
|
2015-04-13 20:43:18 +00:00
|
|
|
|
2015-10-21 19:36:27 +00:00
|
|
|
public:
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
ArrayHandleTransform(const ArrayHandleType& handle, const FunctorType& functor = FunctorType())
|
|
|
|
: Superclass(StorageType(handle, functor))
|
|
|
|
{
|
|
|
|
}
|
2015-04-13 20:43:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// make_ArrayHandleTransform is convenience function to generate an
|
|
|
|
/// ArrayHandleTransform. It takes in an ArrayHandle and a functor
|
|
|
|
/// to apply to each element of the Handle.
|
2017-05-30 14:00:01 +00:00
|
|
|
template <typename HandleType, typename FunctorType>
|
|
|
|
VTKM_CONT vtkm::cont::ArrayHandleTransform<HandleType, FunctorType> make_ArrayHandleTransform(
|
2017-05-26 17:53:28 +00:00
|
|
|
HandleType handle,
|
|
|
|
FunctorType functor)
|
2015-04-13 20:43:18 +00:00
|
|
|
{
|
2017-05-30 14:00:01 +00:00
|
|
|
return ArrayHandleTransform<HandleType, FunctorType>(handle, functor);
|
2015-04-13 20:43:18 +00:00
|
|
|
}
|
|
|
|
|
2015-09-22 14:11:51 +00:00
|
|
|
// ArrayHandleTransform with inverse functors enabled (no need to subclass from
|
|
|
|
// ArrayHandleTransform without inverse functors: nothing to inherit).
|
2017-05-30 14:00:01 +00:00
|
|
|
template <typename ArrayHandleType, typename FunctorType, typename InverseFunctorType>
|
2015-09-22 14:11:51 +00:00
|
|
|
class ArrayHandleTransform
|
2017-05-18 14:29:41 +00:00
|
|
|
: public vtkm::cont::ArrayHandle<
|
2017-05-30 14:00:01 +00:00
|
|
|
typename internal::StorageTagTransform<ArrayHandleType, FunctorType, InverseFunctorType>::
|
|
|
|
ValueType,
|
|
|
|
internal::StorageTagTransform<ArrayHandleType, FunctorType, InverseFunctorType>>
|
2015-09-22 14:11:51 +00:00
|
|
|
{
|
|
|
|
VTKM_IS_ARRAY_HANDLE(ArrayHandleType);
|
|
|
|
|
|
|
|
public:
|
|
|
|
VTKM_ARRAY_HANDLE_SUBCLASS(
|
2017-05-18 14:29:41 +00:00
|
|
|
ArrayHandleTransform,
|
2017-05-30 14:00:01 +00:00
|
|
|
(ArrayHandleTransform<ArrayHandleType, FunctorType, InverseFunctorType>),
|
2017-05-18 14:29:41 +00:00
|
|
|
(vtkm::cont::ArrayHandle<
|
2017-05-30 14:00:01 +00:00
|
|
|
typename internal::StorageTagTransform<ArrayHandleType, FunctorType, InverseFunctorType>::
|
|
|
|
ValueType,
|
|
|
|
internal::StorageTagTransform<ArrayHandleType, FunctorType, InverseFunctorType>>));
|
2015-09-22 14:11:51 +00:00
|
|
|
|
|
|
|
private:
|
2017-08-16 15:34:21 +00:00
|
|
|
using StorageType = vtkm::cont::internal::Storage<ValueType, StorageTag>;
|
2015-09-22 14:11:51 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
public:
|
2017-05-26 17:53:28 +00:00
|
|
|
ArrayHandleTransform(const ArrayHandleType& handle,
|
|
|
|
const FunctorType& functor = FunctorType(),
|
2017-05-18 14:29:41 +00:00
|
|
|
const InverseFunctorType& inverseFunctor = InverseFunctorType())
|
|
|
|
: Superclass(StorageType(handle, functor, inverseFunctor))
|
|
|
|
{
|
|
|
|
}
|
2015-09-22 14:11:51 +00:00
|
|
|
};
|
|
|
|
|
2017-05-30 14:00:01 +00:00
|
|
|
template <typename HandleType, typename FunctorType, typename InverseFunctorType>
|
|
|
|
VTKM_CONT vtkm::cont::ArrayHandleTransform<HandleType, FunctorType, InverseFunctorType>
|
2015-09-22 14:11:51 +00:00
|
|
|
make_ArrayHandleTransform(HandleType handle, FunctorType functor, InverseFunctorType inverseFunctor)
|
|
|
|
{
|
2017-05-30 14:00:01 +00:00
|
|
|
return ArrayHandleTransform<HandleType, FunctorType, InverseFunctorType>(
|
2017-05-26 17:53:28 +00:00
|
|
|
handle, functor, inverseFunctor);
|
2015-09-22 14:11:51 +00:00
|
|
|
}
|
2015-04-13 20:43:18 +00:00
|
|
|
}
|
2017-05-30 14:00:01 +00:00
|
|
|
|
2015-04-13 20:43:18 +00:00
|
|
|
} // namespace vtkm::cont
|
|
|
|
|
2018-06-08 15:56:40 +00:00
|
|
|
//=============================================================================
|
|
|
|
// Specializations of serialization related classes
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
|
|
|
|
|
|
|
template <typename AH, typename Functor, typename InvFunctor>
|
2019-02-28 18:15:27 +00:00
|
|
|
struct SerializableTypeString<vtkm::cont::ArrayHandleTransform<AH, Functor, InvFunctor>>
|
2018-06-08 15:56:40 +00:00
|
|
|
{
|
|
|
|
static VTKM_CONT const std::string& Get()
|
|
|
|
{
|
2019-02-28 18:15:27 +00:00
|
|
|
static std::string name = "AH_Transform<" + SerializableTypeString<AH>::Get() + "," +
|
|
|
|
SerializableTypeString<Functor>::Get() + "," + SerializableTypeString<InvFunctor>::Get() +
|
|
|
|
">";
|
2018-06-08 15:56:40 +00:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename AH, typename Functor>
|
2019-02-28 18:15:27 +00:00
|
|
|
struct SerializableTypeString<vtkm::cont::ArrayHandleTransform<AH, Functor>>
|
2018-06-08 15:56:40 +00:00
|
|
|
{
|
|
|
|
static VTKM_CONT const std::string& Get()
|
|
|
|
{
|
2019-02-28 18:15:27 +00:00
|
|
|
static std::string name = "AH_Transform<" + SerializableTypeString<AH>::Get() + "," +
|
|
|
|
SerializableTypeString<Functor>::Get() + ">";
|
2018-06-08 15:56:40 +00:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename AH, typename Functor, typename InvFunctor>
|
2019-02-28 18:15:27 +00:00
|
|
|
struct SerializableTypeString<vtkm::cont::ArrayHandle<
|
2018-06-08 15:56:40 +00:00
|
|
|
typename vtkm::cont::internal::StorageTagTransform<AH, Functor, InvFunctor>::ValueType,
|
|
|
|
vtkm::cont::internal::StorageTagTransform<AH, Functor, InvFunctor>>>
|
2019-02-28 18:15:27 +00:00
|
|
|
: SerializableTypeString<vtkm::cont::ArrayHandleTransform<AH, Functor, InvFunctor>>
|
2018-06-08 15:56:40 +00:00
|
|
|
{
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} // vtkm::cont
|
|
|
|
|
2019-02-05 16:02:29 +00:00
|
|
|
namespace mangled_diy_namespace
|
2018-06-08 15:56:40 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
template <typename AH, typename Functor>
|
|
|
|
struct Serialization<vtkm::cont::ArrayHandleTransform<AH, Functor>>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
using Type = vtkm::cont::ArrayHandleTransform<AH, Functor>;
|
|
|
|
using BaseType = vtkm::cont::ArrayHandle<typename Type::ValueType, typename Type::StorageTag>;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static VTKM_CONT void save(BinaryBuffer& bb, const BaseType& obj)
|
|
|
|
{
|
|
|
|
auto storage = obj.GetStorage();
|
2019-02-05 16:02:29 +00:00
|
|
|
vtkmdiy::save(bb, storage.GetArray());
|
|
|
|
vtkmdiy::save(bb, storage.GetFunctor());
|
2018-06-08 15:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static VTKM_CONT void load(BinaryBuffer& bb, BaseType& obj)
|
|
|
|
{
|
|
|
|
AH array;
|
2019-02-05 16:02:29 +00:00
|
|
|
vtkmdiy::load(bb, array);
|
2018-06-08 15:56:40 +00:00
|
|
|
Functor functor;
|
2019-02-05 16:02:29 +00:00
|
|
|
vtkmdiy::load(bb, functor);
|
2018-06-08 15:56:40 +00:00
|
|
|
obj = vtkm::cont::make_ArrayHandleTransform(array, functor);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename AH, typename Functor, typename InvFunctor>
|
|
|
|
struct Serialization<vtkm::cont::ArrayHandleTransform<AH, Functor, InvFunctor>>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
using Type = vtkm::cont::ArrayHandleTransform<AH, Functor, InvFunctor>;
|
|
|
|
using BaseType = vtkm::cont::ArrayHandle<typename Type::ValueType, typename Type::StorageTag>;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static VTKM_CONT void save(BinaryBuffer& bb, const BaseType& obj)
|
|
|
|
{
|
|
|
|
auto storage = obj.GetStorage();
|
2019-02-05 16:02:29 +00:00
|
|
|
vtkmdiy::save(bb, storage.GetArray());
|
|
|
|
vtkmdiy::save(bb, storage.GetFunctor());
|
|
|
|
vtkmdiy::save(bb, storage.GetInverseFunctor());
|
2018-06-08 15:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static VTKM_CONT void load(BinaryBuffer& bb, BaseType& obj)
|
|
|
|
{
|
|
|
|
AH array;
|
2019-02-05 16:02:29 +00:00
|
|
|
vtkmdiy::load(bb, array);
|
2018-06-08 15:56:40 +00:00
|
|
|
Functor functor;
|
2019-02-05 16:02:29 +00:00
|
|
|
vtkmdiy::load(bb, functor);
|
2018-06-08 15:56:40 +00:00
|
|
|
InvFunctor invFunctor;
|
2019-02-05 16:02:29 +00:00
|
|
|
vtkmdiy::load(bb, invFunctor);
|
2018-06-08 15:56:40 +00:00
|
|
|
obj = vtkm::cont::make_ArrayHandleTransform(array, functor, invFunctor);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename AH, typename Functor, typename InvFunctor>
|
|
|
|
struct Serialization<vtkm::cont::ArrayHandle<
|
|
|
|
typename vtkm::cont::internal::StorageTagTransform<AH, Functor, InvFunctor>::ValueType,
|
|
|
|
vtkm::cont::internal::StorageTagTransform<AH, Functor, InvFunctor>>>
|
|
|
|
: Serialization<vtkm::cont::ArrayHandleTransform<AH, Functor, InvFunctor>>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
} // diy
|
|
|
|
|
2015-04-13 20:43:18 +00:00
|
|
|
#endif //vtk_m_cont_ArrayHandleTransform_h
|