Commit 8d7bd981 authored by Pierre NARVOR's avatar Pierre NARVOR
Browse files

[cuda/mapping] Added the DeviceMapping1D type with automatic type selection in the MappingType

parent 86c3d985
...@@ -34,10 +34,42 @@ struct DeviceMapping2D ...@@ -34,10 +34,42 @@ struct DeviceMapping2D
#endif //RTAC_CUDACC #endif //RTAC_CUDACC
}; };
}; //namespace cuda template <typename T>
}; //namespace rtac struct DeviceMapping1D
{
// Declaring input and output types to be compatible with other functors.
using InputT = float;
using OutputT = T;
namespace rtac { namespace cuda { cudaTextureObject_t data;
#ifdef RTAC_CUDACC // this cannot be used from host side because of the texture fetch
__device__ T operator()(float u) const {
return tex2D<T>(data, u, 0.0f);
}
#endif //RTAC_CUDACC
};
/**
* This is a convenience definition allowing to deduce a full DeviceMap type
* depending on the given FunctorT. Is used primarily in the Mapping type.
*/
template <typename T, class FunctorT>
struct device_map_type {
using FoutT = typename FunctorT::OutputT;
static_assert(std::is_same<float, FoutT>::value || std::is_same<float2, FoutT>::value,
"For a cuda::Mapping type, the output type of the optional functor must be either float or float2");
// Deducing DeviceMap type to use (1D or 2D), depending on the
// FunctorT::OutputT type.
using DeviceMapT = typename std::conditional<std::is_same<float, FoutT>::value,
DeviceMapping1D<T>,
DeviceMapping2D<T>>::type;
// Building final type.
using type = functors::FunctorCompound<DeviceMapT, FunctorT>;
};
/** /**
* Host side class with manage device side Device mapping data. This also * Host side class with manage device side Device mapping data. This also
...@@ -53,7 +85,7 @@ class Mapping ...@@ -53,7 +85,7 @@ class Mapping
using Ptr = std::shared_ptr<Mapping>; using Ptr = std::shared_ptr<Mapping>;
using ConstPtr = std::shared_ptr<const Mapping>; using ConstPtr = std::shared_ptr<const Mapping>;
using Texture = Texture2D<T>; using Texture = Texture2D<T>;
using DeviceMap = functors::FunctorCompound<DeviceMapping2D<T>, FunctorT>; using DeviceMap = typename device_map_type<T, FunctorT>::type;
protected: protected:
......
...@@ -4,8 +4,17 @@ ...@@ -4,8 +4,17 @@
#include <rtac_base/cuda/DeviceVector.h> #include <rtac_base/cuda/DeviceVector.h>
#include <rtac_base/cuda/HostVector.h> #include <rtac_base/cuda/HostVector.h>
#include <rtac_base/cuda/Mapping.h> #include <rtac_base/cuda/Mapping.h>
#include <rtac_base/cuda/functors.h>
using namespace rtac::cuda; using namespace rtac::cuda;
// This should fail successfully.
// using TypeTest0 = device_map_type<float, functors::Scaling<int>>;
// const TypeTest0 test0;
using TypeTest1 = device_map_type<float, functors::Scaling<float>>;
const TypeTest1 test1;
using TypeTest2 = device_map_type<float, functors::Scaling<float2>>;
const TypeTest2 test2;
// This Functor transforms pixel coordinates in normalized texture coordinates, // This Functor transforms pixel coordinates in normalized texture coordinates,
// given a size (width, height). // given a size (width, height).
struct NormalizerUV { struct NormalizerUV {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment