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.
|
|
|
|
//
|
|
|
|
// Copyright 2015 Sandia Corporation.
|
|
|
|
// 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
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
|
|
|
// 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>
|
|
|
|
#include <vtkm/cont/ErrorControlBadType.h>
|
|
|
|
#include <vtkm/cont/ErrorControlInternal.h>
|
|
|
|
|
2015-09-22 14:11:51 +00:00
|
|
|
namespace vtkm {
|
|
|
|
namespace cont {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
/// Tag used in place of an inverse functor.
|
|
|
|
struct NullFunctorType {};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace vtkm::cont::internal
|
|
|
|
|
2015-04-13 20:43:18 +00:00
|
|
|
namespace vtkm {
|
2015-04-27 14:13:11 +00:00
|
|
|
namespace exec {
|
2015-04-13 20:43:18 +00:00
|
|
|
namespace internal {
|
2015-09-22 14:11:51 +00:00
|
|
|
|
|
|
|
typedef vtkm::cont::internal::NullFunctorType NullFunctorType;
|
|
|
|
|
2015-04-13 20:43:18 +00:00
|
|
|
/// \brief An array portal that transforms a value from another portal.
|
|
|
|
///
|
2015-09-22 14:11:51 +00:00
|
|
|
template<typename ValueType_, typename PortalType_, typename FunctorType_,
|
|
|
|
typename InverseFunctorType_=NullFunctorType>
|
2016-08-02 15:26:29 +00:00
|
|
|
class ArrayPortalTransform;
|
2015-09-22 14:11:51 +00:00
|
|
|
|
2015-04-13 20:43:18 +00:00
|
|
|
template<typename ValueType_, typename PortalType_, typename FunctorType_>
|
2016-08-02 15:26:29 +00:00
|
|
|
class ArrayPortalTransform<ValueType_,PortalType_,FunctorType_,NullFunctorType>
|
2015-04-13 20:43:18 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef PortalType_ PortalType;
|
|
|
|
typedef ValueType_ ValueType;
|
|
|
|
typedef FunctorType_ FunctorType;
|
|
|
|
|
2016-08-02 15:26:29 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2015-09-22 14:11:51 +00:00
|
|
|
VTKM_EXEC_CONT_EXPORT
|
2016-08-02 15:26:29 +00:00
|
|
|
ArrayPortalTransform(const PortalType &portal = PortalType(),
|
2015-04-13 20:43:18 +00:00
|
|
|
const FunctorType &functor = FunctorType())
|
2015-04-23 15:07:26 +00:00
|
|
|
: 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
|
|
|
///
|
|
|
|
template<class OtherV, class OtherP, class OtherF>
|
2016-08-02 15:26:29 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2015-09-22 14:11:51 +00:00
|
|
|
VTKM_EXEC_CONT_EXPORT
|
2016-08-02 15:26:29 +00:00
|
|
|
ArrayPortalTransform(const ArrayPortalTransform<OtherV,OtherP,OtherF> &src)
|
2015-04-13 20:43:18 +00:00
|
|
|
: Portal(src.GetPortal()),
|
|
|
|
Functor(src.GetFunctor())
|
|
|
|
{ }
|
|
|
|
|
2016-08-02 15:26:29 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2015-04-13 20:43:18 +00:00
|
|
|
VTKM_EXEC_CONT_EXPORT
|
2015-04-23 15:07:26 +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
|
|
|
|
VTKM_EXEC_CONT_EXPORT
|
2015-04-13 20:43:18 +00:00
|
|
|
ValueType Get(vtkm::Id index) const {
|
|
|
|
return this->Functor(this->Portal.Get(index));
|
|
|
|
}
|
|
|
|
|
2016-08-02 15:26:29 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2015-04-13 20:43:18 +00:00
|
|
|
VTKM_EXEC_CONT_EXPORT
|
|
|
|
const PortalType &GetPortal() const { return this->Portal; }
|
|
|
|
|
2016-08-02 15:26:29 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2015-04-13 20:43:18 +00:00
|
|
|
VTKM_EXEC_CONT_EXPORT
|
|
|
|
const FunctorType &GetFunctor() const { return this->Functor; }
|
|
|
|
|
2015-09-22 14:11:51 +00:00
|
|
|
protected:
|
2015-04-13 20:43:18 +00:00
|
|
|
PortalType Portal;
|
|
|
|
FunctorType Functor;
|
|
|
|
};
|
|
|
|
|
2015-09-22 14:11:51 +00:00
|
|
|
template<typename ValueType_, typename PortalType_,
|
|
|
|
typename FunctorType_, typename InverseFunctorType_>
|
2016-08-02 15:26:29 +00:00
|
|
|
class ArrayPortalTransform : public ArrayPortalTransform<ValueType_,PortalType_,FunctorType_,NullFunctorType>
|
2015-09-22 14:11:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-08-02 15:26:29 +00:00
|
|
|
typedef ArrayPortalTransform<ValueType_,PortalType_,FunctorType_,NullFunctorType> Superclass;
|
2015-09-22 14:11:51 +00:00
|
|
|
typedef PortalType_ PortalType;
|
|
|
|
typedef ValueType_ ValueType;
|
|
|
|
typedef FunctorType_ FunctorType;
|
|
|
|
typedef InverseFunctorType_ InverseFunctorType;
|
|
|
|
|
2016-08-02 15:26:29 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2015-09-22 14:11:51 +00:00
|
|
|
VTKM_EXEC_CONT_EXPORT
|
2016-08-02 15:26:29 +00:00
|
|
|
ArrayPortalTransform(const PortalType &portal = PortalType(),
|
|
|
|
const FunctorType &functor = FunctorType(),
|
2015-09-22 14:11:51 +00:00
|
|
|
const InverseFunctorType& inverseFunctor = InverseFunctorType())
|
|
|
|
: Superclass(portal,functor), InverseFunctor(inverseFunctor)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
template<class OtherV, class OtherP, class OtherF, class OtherInvF>
|
2016-08-02 15:26:29 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2015-09-22 14:11:51 +00:00
|
|
|
VTKM_EXEC_CONT_EXPORT
|
2016-08-02 15:26:29 +00:00
|
|
|
ArrayPortalTransform(const ArrayPortalTransform<OtherV,OtherP,OtherF,OtherInvF> &src)
|
2015-09-22 14:11:51 +00:00
|
|
|
: Superclass(src), InverseFunctor(src.GetInverseFunctor())
|
|
|
|
{ }
|
|
|
|
|
2016-08-02 15:26:29 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
|
|
VTKM_EXEC_CONT_EXPORT
|
2015-09-22 14:11:51 +00:00
|
|
|
void Set(vtkm::Id index, const ValueType& value) const {
|
|
|
|
return this->Portal.Set(index,this->InverseFunctor(value));
|
|
|
|
}
|
|
|
|
|
2016-08-02 15:26:29 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2015-09-22 14:11:51 +00:00
|
|
|
VTKM_EXEC_CONT_EXPORT
|
|
|
|
const InverseFunctorType &GetInverseFunctor() const {
|
|
|
|
return this->InverseFunctor; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
InverseFunctorType InverseFunctor;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-04-27 14:13:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace vtkm::exec::internal
|
|
|
|
|
|
|
|
|
|
|
|
namespace vtkm {
|
|
|
|
namespace cont {
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
2015-09-22 14:11:51 +00:00
|
|
|
template<typename ValueType, typename ArrayHandleType, typename FunctorType,
|
|
|
|
typename InverseFunctorType=NullFunctorType>
|
|
|
|
struct StorageTagTransform {};
|
2015-04-13 20:43:18 +00:00
|
|
|
|
|
|
|
template<typename T, typename ArrayHandleType, typename FunctorType>
|
2015-09-22 14:11:51 +00:00
|
|
|
class Storage<T, StorageTagTransform<T, ArrayHandleType, FunctorType, NullFunctorType > >
|
2015-04-13 20:43:18 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef T ValueType;
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
typedef void *ValueType;
|
|
|
|
typedef void *IteratorType;
|
|
|
|
};
|
|
|
|
|
2016-08-02 15:26:29 +00:00
|
|
|
typedef vtkm::exec::internal::ArrayPortalTransform<
|
2015-04-13 20:43:18 +00:00
|
|
|
ValueType, typename ArrayHandleType::PortalConstControl, FunctorType>
|
|
|
|
PortalConstType;
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
Storage() : Valid(false) { }
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
Storage(const ArrayHandleType &array,
|
|
|
|
const FunctorType &functor = FunctorType())
|
|
|
|
: Array(array), Functor(functor), Valid(true) { }
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
PortalType GetPortal() {
|
2016-04-20 21:41:14 +00:00
|
|
|
VTKM_ASSERT(this->Valid);
|
2015-04-13 20:43:18 +00:00
|
|
|
return PortalType(this->Array.GetPortalControl(),
|
|
|
|
this->Functor);
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
2015-04-23 15:07:26 +00:00
|
|
|
PortalConstType GetPortalConst() const {
|
2016-04-20 21:41:14 +00:00
|
|
|
VTKM_ASSERT(this->Valid);
|
2015-04-13 20:43:18 +00:00
|
|
|
return PortalConstType(this->Array.GetPortalConstControl(),
|
|
|
|
this->Functor);
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void Allocate(vtkm::Id vtkmNotUsed(numberOfValues)) {
|
|
|
|
throw vtkm::cont::ErrorControlBadType(
|
|
|
|
"ArrayHandleTransform is read only. It cannot be allocated.");
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void Shrink(vtkm::Id vtkmNotUsed(numberOfValues)) {
|
|
|
|
throw vtkm::cont::ErrorControlBadType(
|
|
|
|
"ArrayHandleTransform is read only. It cannot shrink.");
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void ReleaseResources() {
|
|
|
|
// 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?
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-09-29 14:36:11 +00:00
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
const FunctorType &GetFunctor() const {
|
|
|
|
return this->Functor;
|
|
|
|
}
|
|
|
|
|
2015-04-13 20:43:18 +00:00
|
|
|
private:
|
|
|
|
ArrayHandleType Array;
|
|
|
|
FunctorType Functor;
|
|
|
|
bool Valid;
|
|
|
|
};
|
|
|
|
|
2015-09-22 14:11:51 +00:00
|
|
|
template<typename T, typename ArrayHandleType, typename FunctorType,
|
|
|
|
typename InverseFunctorType>
|
|
|
|
class Storage<T,
|
|
|
|
StorageTagTransform<T, ArrayHandleType, FunctorType, InverseFunctorType> >
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef T ValueType;
|
|
|
|
|
2016-08-02 15:26:29 +00:00
|
|
|
typedef vtkm::exec::internal::ArrayPortalTransform<ValueType,
|
2015-09-22 14:11:51 +00:00
|
|
|
typename ArrayHandleType::PortalControl, FunctorType, InverseFunctorType>
|
|
|
|
PortalType;
|
2016-08-02 15:26:29 +00:00
|
|
|
typedef vtkm::exec::internal::ArrayPortalTransform<ValueType,
|
2015-09-22 14:11:51 +00:00
|
|
|
typename ArrayHandleType::PortalConstControl,FunctorType,InverseFunctorType>
|
|
|
|
PortalConstType;
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
Storage() : Valid(false) { }
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
Storage(const ArrayHandleType &array,
|
|
|
|
const FunctorType &functor,
|
|
|
|
const InverseFunctorType &inverseFunctor)
|
|
|
|
: Array(array), Functor(functor), InverseFunctor(inverseFunctor), Valid(true) { }
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
PortalType GetPortal() {
|
2016-04-20 21:41:14 +00:00
|
|
|
VTKM_ASSERT(this->Valid);
|
2015-09-22 14:11:51 +00:00
|
|
|
return PortalType(this->Array.GetPortalControl(),
|
|
|
|
this->Functor,
|
|
|
|
this->InverseFunctor);
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
PortalConstType GetPortalConst() const {
|
2016-04-20 21:41:14 +00:00
|
|
|
VTKM_ASSERT(this->Valid);
|
2015-09-22 14:11:51 +00:00
|
|
|
return PortalConstType(this->Array.GetPortalConstControl(),
|
|
|
|
this->Functor,
|
|
|
|
this->InverseFunctor);
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void Allocate(vtkm::Id numberOfValues) {
|
|
|
|
this->Array.Allocate(numberOfValues);
|
|
|
|
this->Valid = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void Shrink(vtkm::Id numberOfValues) {
|
|
|
|
this->Array.Shrink(numberOfValues);
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void ReleaseResources() {
|
|
|
|
this->Array.ReleaseResources();
|
|
|
|
this->Valid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
const FunctorType &GetFunctor() const {
|
|
|
|
return this->Functor;
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
const InverseFunctorType &GetInverseFunctor() const {
|
|
|
|
return this->InverseFunctor;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ArrayHandleType Array;
|
|
|
|
FunctorType Functor;
|
|
|
|
InverseFunctorType InverseFunctor;
|
|
|
|
bool Valid;
|
|
|
|
};
|
|
|
|
|
2015-04-13 20:43:18 +00:00
|
|
|
template<typename T,
|
|
|
|
typename ArrayHandleType,
|
|
|
|
typename FunctorType,
|
|
|
|
typename Device>
|
|
|
|
class ArrayTransfer<
|
|
|
|
T, StorageTagTransform<T,ArrayHandleType,FunctorType>, Device>
|
|
|
|
{
|
|
|
|
typedef StorageTagTransform<T,ArrayHandleType,FunctorType> StorageTag;
|
|
|
|
typedef vtkm::cont::internal::Storage<T, StorageTag> StorageType;
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef T ValueType;
|
|
|
|
|
|
|
|
typedef typename StorageType::PortalType PortalControl;
|
|
|
|
typedef typename StorageType::PortalConstType PortalConstControl;
|
|
|
|
|
2015-09-30 19:47:16 +00:00
|
|
|
//meant to be an invalid writeable execution portal
|
|
|
|
typedef typename StorageType::PortalType PortalExecution;
|
2016-08-02 15:26:29 +00:00
|
|
|
typedef vtkm::exec::internal::ArrayPortalTransform<
|
2015-04-13 20:43:18 +00:00
|
|
|
ValueType,
|
|
|
|
typename ArrayHandleType::template ExecutionTypes<Device>::PortalConst,
|
|
|
|
FunctorType> PortalConstExecution;
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
2015-09-29 14:36:11 +00:00
|
|
|
ArrayTransfer(StorageType *storage)
|
|
|
|
: Array(storage->GetArray()), Functor(storage->GetFunctor()) { }
|
2015-04-13 20:43:18 +00:00
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
vtkm::Id GetNumberOfValues() const {
|
|
|
|
return this->Array.GetNumberOfValues();
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
2015-05-01 04:01:02 +00:00
|
|
|
PortalConstExecution PrepareForInput(bool vtkmNotUsed(updateData)) {
|
2015-09-29 14:36:11 +00:00
|
|
|
return PortalConstExecution(this->Array.PrepareForInput(Device()), this->Functor);
|
2015-04-13 20:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
2015-05-01 04:01:02 +00:00
|
|
|
PortalExecution PrepareForInPlace(bool &vtkmNotUsed(updateData)) {
|
2015-04-13 20:43:18 +00:00
|
|
|
throw vtkm::cont::ErrorControlBadType(
|
|
|
|
"ArrayHandleTransform read only. "
|
|
|
|
"Cannot be used for in-place operations.");
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
2015-05-01 04:01:02 +00:00
|
|
|
PortalExecution PrepareForOutput(vtkm::Id vtkmNotUsed(numberOfValues)) {
|
2015-04-13 20:43:18 +00:00
|
|
|
throw vtkm::cont::ErrorControlBadType(
|
|
|
|
"ArrayHandleTransform read only. Cannot be used as output.");
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
2015-05-01 04:01:02 +00:00
|
|
|
void RetrieveOutputData(StorageType *vtkmNotUsed(storage)) const {
|
2015-04-13 20:43:18 +00:00
|
|
|
throw vtkm::cont::ErrorControlInternal(
|
|
|
|
"ArrayHandleTransform read only. "
|
|
|
|
"There should be no occurance of the ArrayHandle trying to pull "
|
|
|
|
"data from the execution environment.");
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void Shrink(vtkm::Id vtkmNotUsed(numberOfValues)) {
|
|
|
|
throw vtkm::cont::ErrorControlBadType(
|
|
|
|
"ArrayHandleTransform read only. Cannot shrink.");
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void ReleaseResources() {
|
|
|
|
this->Array.ReleaseResourcesExecution();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ArrayHandleType Array;
|
2015-09-29 14:36:11 +00:00
|
|
|
FunctorType Functor;
|
2015-04-13 20:43:18 +00:00
|
|
|
};
|
|
|
|
|
2015-09-22 14:11:51 +00:00
|
|
|
template<typename T,
|
|
|
|
typename ArrayHandleType,
|
|
|
|
typename FunctorType,
|
|
|
|
typename InverseFunctorType,
|
|
|
|
typename Device>
|
|
|
|
class ArrayTransfer<
|
|
|
|
T, StorageTagTransform<T,ArrayHandleType,FunctorType,InverseFunctorType>,
|
|
|
|
Device>
|
|
|
|
{
|
|
|
|
typedef StorageTagTransform<T,ArrayHandleType,
|
|
|
|
FunctorType,InverseFunctorType> StorageTag;
|
|
|
|
typedef vtkm::cont::internal::Storage<T, StorageTag> StorageType;
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef T ValueType;
|
|
|
|
|
|
|
|
typedef typename StorageType::PortalType PortalControl;
|
|
|
|
typedef typename StorageType::PortalConstType PortalConstControl;
|
|
|
|
|
2016-08-02 15:26:29 +00:00
|
|
|
typedef vtkm::exec::internal::ArrayPortalTransform<
|
2015-09-22 14:11:51 +00:00
|
|
|
ValueType,
|
|
|
|
typename ArrayHandleType::template ExecutionTypes<Device>::Portal,
|
|
|
|
FunctorType, InverseFunctorType> PortalExecution;
|
2016-08-02 15:26:29 +00:00
|
|
|
typedef vtkm::exec::internal::ArrayPortalTransform<
|
2015-09-22 14:11:51 +00:00
|
|
|
ValueType,
|
|
|
|
typename ArrayHandleType::template ExecutionTypes<Device>::PortalConst,
|
|
|
|
FunctorType, InverseFunctorType> PortalConstExecution;
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
ArrayTransfer(StorageType *storage)
|
|
|
|
: Array(storage->GetArray()),
|
|
|
|
Functor(storage->GetFunctor()),
|
|
|
|
InverseFunctor(storage->GetInverseFunctor()) { }
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
vtkm::Id GetNumberOfValues() const {
|
|
|
|
return this->Array.GetNumberOfValues();
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
PortalConstExecution PrepareForInput(bool vtkmNotUsed(updateData)) {
|
|
|
|
return PortalConstExecution(this->Array.PrepareForInput(Device()),this->Functor,this->InverseFunctor);
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
PortalExecution PrepareForInPlace(bool &vtkmNotUsed(updateData)) {
|
|
|
|
return PortalExecution(this->Array.PrepareForInPlace(Device()),this->Functor,this->InverseFunctor);
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
PortalExecution PrepareForOutput(vtkm::Id numberOfValues) {
|
|
|
|
return PortalExecution(this->Array.PrepareForOutput(numberOfValues,
|
|
|
|
Device()),this->Functor,this->InverseFunctor);
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void RetrieveOutputData(StorageType *vtkmNotUsed(storage)) const {
|
|
|
|
// Implementation of this method should be unnecessary. The internal
|
|
|
|
// array handle should automatically retrieve the output data as necessary.
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void Shrink(vtkm::Id numberOfValues) {
|
|
|
|
this->Array.Shrink(numberOfValues);
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void ReleaseResources() {
|
|
|
|
this->Array.ReleaseResourcesExecution();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ArrayHandleType Array;
|
|
|
|
FunctorType Functor;
|
|
|
|
InverseFunctorType InverseFunctor;
|
|
|
|
};
|
|
|
|
|
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.
|
|
|
|
///
|
2015-09-22 14:11:51 +00:00
|
|
|
template <typename T,
|
|
|
|
typename ArrayHandleType,
|
|
|
|
typename FunctorType,
|
|
|
|
typename InverseFunctorType=internal::NullFunctorType>
|
|
|
|
class ArrayHandleTransform;
|
|
|
|
|
2015-10-21 19:36:27 +00:00
|
|
|
template <typename T,
|
2015-04-24 00:45:24 +00:00
|
|
|
typename ArrayHandleType,
|
|
|
|
typename FunctorType>
|
2015-09-22 14:11:51 +00:00
|
|
|
class ArrayHandleTransform<T,ArrayHandleType,FunctorType,internal::NullFunctorType>
|
2015-04-13 20:43:18 +00:00
|
|
|
: public vtkm::cont::ArrayHandle<
|
2015-10-21 19:36:27 +00:00
|
|
|
T, internal::StorageTagTransform<T, 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(
|
|
|
|
ArrayHandleTransform,
|
|
|
|
(ArrayHandleTransform<T,ArrayHandleType,FunctorType>),
|
|
|
|
(vtkm::cont::ArrayHandle<
|
|
|
|
T, internal::StorageTagTransform<T, ArrayHandleType, FunctorType> >));
|
2015-09-20 06:28:11 +00:00
|
|
|
|
|
|
|
private:
|
2015-09-22 14:11:51 +00:00
|
|
|
typedef vtkm::cont::internal::Storage<T, StorageTag> StorageType;
|
2015-04-13 20:43:18 +00:00
|
|
|
|
2015-10-21 19:36:27 +00:00
|
|
|
public:
|
2015-09-20 06:28:11 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-04-13 20:43:18 +00:00
|
|
|
ArrayHandleTransform(const ArrayHandleType &handle,
|
|
|
|
const FunctorType &functor = FunctorType())
|
|
|
|
: Superclass(StorageType(handle, functor)) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
/// 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.
|
|
|
|
|
|
|
|
template <typename T, typename HandleType, typename FunctorType>
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
vtkm::cont::ArrayHandleTransform<T, HandleType, FunctorType>
|
|
|
|
make_ArrayHandleTransform(HandleType handle, FunctorType functor)
|
|
|
|
{
|
|
|
|
return ArrayHandleTransform<T,HandleType,FunctorType>(handle,functor);
|
|
|
|
}
|
|
|
|
|
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).
|
|
|
|
template <typename T,
|
|
|
|
typename ArrayHandleType,
|
|
|
|
typename FunctorType,
|
|
|
|
typename InverseFunctorType>
|
|
|
|
class ArrayHandleTransform
|
|
|
|
: public vtkm::cont::ArrayHandle<
|
|
|
|
T,
|
|
|
|
internal::StorageTagTransform<T, ArrayHandleType, FunctorType,
|
|
|
|
InverseFunctorType> >
|
|
|
|
{
|
|
|
|
VTKM_IS_ARRAY_HANDLE(ArrayHandleType);
|
|
|
|
|
|
|
|
public:
|
|
|
|
VTKM_ARRAY_HANDLE_SUBCLASS(
|
|
|
|
ArrayHandleTransform,
|
|
|
|
(ArrayHandleTransform<T,ArrayHandleType,FunctorType,InverseFunctorType>),
|
|
|
|
(vtkm::cont::ArrayHandle<
|
|
|
|
T, internal::StorageTagTransform<T, ArrayHandleType, FunctorType,
|
|
|
|
InverseFunctorType> >));
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef vtkm::cont::internal::Storage<T, StorageTag> StorageType;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ArrayHandleTransform(const ArrayHandleType &handle,
|
|
|
|
const FunctorType &functor = FunctorType(),
|
|
|
|
const InverseFunctorType &inverseFunctor = InverseFunctorType())
|
|
|
|
: Superclass(StorageType(handle, functor, inverseFunctor)) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T, typename HandleType, typename FunctorType, typename InverseFunctorType>
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
vtkm::cont::ArrayHandleTransform<T, HandleType, FunctorType, InverseFunctorType>
|
|
|
|
make_ArrayHandleTransform(HandleType handle, FunctorType functor, InverseFunctorType inverseFunctor)
|
|
|
|
{
|
|
|
|
return ArrayHandleTransform<T,HandleType,FunctorType,InverseFunctorType>(handle,functor,inverseFunctor);
|
|
|
|
}
|
2015-04-13 20:43:18 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
} // namespace vtkm::cont
|
|
|
|
|
|
|
|
#endif //vtk_m_cont_ArrayHandleTransform_h
|