Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Pierre NARVOR
rtac_base
Commits
8d7bd981
Commit
8d7bd981
authored
Oct 27, 2021
by
Pierre NARVOR
Browse files
[cuda/mapping] Added the DeviceMapping1D type with automatic type selection in the MappingType
parent
86c3d985
Changes
2
Hide whitespace changes
Inline
Side-by-side
cuda/include/rtac_base/cuda/Mapping.h
View file @
8d7bd981
...
...
@@ -34,10 +34,42 @@ struct DeviceMapping2D
#endif //RTAC_CUDACC
};
};
//namespace cuda
};
//namespace rtac
template
<
typename
T
>
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.0
f
);
}
#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
...
...
@@ -53,7 +85,7 @@ class Mapping
using
Ptr
=
std
::
shared_ptr
<
Mapping
>
;
using
ConstPtr
=
std
::
shared_ptr
<
const
Mapping
>
;
using
Texture
=
Texture2D
<
T
>
;
using
DeviceMap
=
functors
::
FunctorCompound
<
DeviceMapping2D
<
T
>
,
FunctorT
>
;
using
DeviceMap
=
typename
device_map_type
<
T
,
FunctorT
>
::
type
;
protected:
...
...
cuda/tests/mapping/src/mapping_test.h
View file @
8d7bd981
...
...
@@ -4,8 +4,17 @@
#include <rtac_base/cuda/DeviceVector.h>
#include <rtac_base/cuda/HostVector.h>
#include <rtac_base/cuda/Mapping.h>
#include <rtac_base/cuda/functors.h>
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,
// given a size (width, height).
struct
NormalizerUV
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment