5#include <gtest/gtest.h>
22 const float fov = 150.0f * (
M_PI_F / 180.0f);
23 const float width = 36.0f;
24 const float height = 41.142857142857144f;
30 const float4 k_stereographic =
make_float4(-5.79e-02f, 0.0f, 9.48e-05f, -7.67e-06f);
34 const float4 k_rectilinear =
make_float4(-6.50e-02f, 0.0f, 8.32e-05f, -1.80e-06f);
36 const float4 parameters[]{k_equidistant, k_stereographic, k_rectilinear};
38 const std::pair<float, float> points[]{
50 for (
const float k0 : {0.0f, -1e-2f, -2e-2f, -5e-2f, -1e-1f}) {
51 for (
const float k2 : {0.0f, -1e-4f, 1e-4f, -2e-4f, 2e-4f}) {
52 for (
float4 k : parameters) {
54 for (
const std::pair<float, float> &pt : points) {
55 const float x = pt.first;
56 const float y = pt.second;
58 pt.first, pt.second, k0, k, fov, width, height);
60 EXPECT_NEAR(
len(direction), 1, 1
e-6) <<
"x: " <<
x << std::endl
61 <<
"y: " <<
y << std::endl
62 <<
"k0: " << k0 << std::endl
66 direction, k0, k, width, height);
68 EXPECT_NEAR(reprojection.
x,
x, 1
e-6) <<
"k0: " << k0 << std::endl
69 <<
"k1: " << k.x << std::endl
70 <<
"k2: " << k.y << std::endl
71 <<
"k3: " << k.z << std::endl
72 <<
"k4: " << k.w << std::endl;
73 EXPECT_NEAR(reprojection.
y,
y, 3
e-6) <<
"k0: " << k0 << std::endl
74 <<
"k1: " << k.x << std::endl
75 <<
"k2: " << k.y << std::endl
76 <<
"k3: " << k.z << std::endl
77 <<
"k4: " << k.w << std::endl;
90 const float width = 1.0f;
91 const float height = 1.0f;
95 const float k0 = 0.0f;
98 const float2 center{0.5f, 0.5f};
114 for (
const float2 &offset : offsets) {
115 const float2 point = center + offset;
117 point.
x, point.
y, k0, k_equidistant, fov, width, height);
118 EXPECT_NEAR(
len(direction), 1.0, 1
e-6);
120 const float2 point_mirror = center - offset;
122 point_mirror.
x, point_mirror.
y, k0, k_equidistant, fov, width, height);
123 EXPECT_NEAR(
len(direction_mirror), 1.0, 1
e-6);
125 EXPECT_NEAR(direction.
x, +direction_mirror.
x, 1
e-6)
126 <<
"offset: (" << offset.x <<
", " << offset.y <<
")";
127 EXPECT_NEAR(direction.
y, -direction_mirror.
y, 1
e-6)
128 <<
"offset: (" << offset.x <<
", " << offset.y <<
")";
130 EXPECT_NEAR(direction.
z, -direction_mirror.
z, 1
e-6)
131 <<
"offset: (" << offset.x <<
", " << offset.y <<
")";
143 const float k0 = 0.0f;
145 const float rad60 =
M_PI_F / 3.0f;
146 const float cos60 = 0.5f;
149 const float rad30 =
M_PI_F / 6.0f;
151 const float sin30 = 0.5f;
157 const std::pair<float2, float3> tests[]{
185 for (
auto [offset, direction] : tests) {
187 for (
const float scale : {1.0f, 0.5f, 2.0f, 0.25f, 4.0f, 0.125f, 8.0f, 0.0625f, 16.0f}) {
188 const float width = 1.0f / scale;
189 const float height = 1.0f / scale;
194 sensor.
x, sensor.
y, k0, k_equidistant, fov, width, height);
196 EXPECT_NEAR(direction.x, computed.
x, 1
e-6)
197 <<
"sensor: (" << sensor.
x <<
", " << sensor.
y <<
")" << std::endl
198 <<
"scale: " << scale;
199 EXPECT_NEAR(direction.y, computed.
y, 1
e-6)
200 <<
"sensor: (" << sensor.
x <<
", " << sensor.
y <<
")" << std::endl
201 <<
"scale: " << scale;
202 EXPECT_NEAR(direction.z, computed.
z, 1
e-6)
203 <<
"sensor: (" << sensor.
x <<
", " << sensor.
y <<
")" << std::endl
204 <<
"scale: " << scale;
207 direction, k0, k_equidistant, width, height);
209 EXPECT_NEAR(sensor.
x, reprojected.
x, 1
e-6) <<
"scale: " << scale;
210 EXPECT_NEAR(sensor.
y, reprojected.
y, 1
e-6) <<
"scale: " << scale;
298 static constexpr float lens = 15.0f;
368 const TypeParam test;
370 const float2 sensors[]{{0.5f, 0.5f},
381 for (
const float size : {36.0f, 24.0f, 6.0f *
M_PI_F}) {
382 const float width =
size;
383 const float height =
size;
385 size_t test_count = 0;
386 for (
const float2 &sensor : sensors) {
387 const float3 direction = TypeParam::sensor_to_direction(sensor, fov, width, height);
388 if (test.skip_invalid() &&
len(direction) < 0.9f) {
392 EXPECT_NEAR(
len(direction), 1.0, 1
e-6)
393 <<
"dir: (" << direction.
x <<
", " << direction.
y <<
", " << direction.
z <<
")"
395 <<
"fov: " << fov << std::endl
396 <<
"sensor: (" << sensor.x <<
", " << sensor.y <<
")" << std::endl;
397 const float2 projection = TypeParam::direction_to_sensor(direction, fov, width, height);
398 EXPECT_NEAR(sensor.x, projection.
x, test.threshold())
399 <<
"dir: (" << direction.
x <<
", " << direction.
y <<
", " << direction.
z <<
")"
401 <<
"fov: " << fov << std::endl
402 <<
"sensor: (" << sensor.x <<
", " << sensor.y <<
")" << std::endl;
403 EXPECT_NEAR(sensor.y, projection.
y, test.threshold())
404 <<
"dir: (" << direction.
x <<
", " << direction.
y <<
", " << direction.
z <<
")"
406 <<
"fov: " << fov << std::endl
407 <<
"sensor: (" << sensor.x <<
", " << sensor.y <<
")" << std::endl;
409 EXPECT_GE(test_count, 2) <<
"fov: " << fov << std::endl <<
"size: " <<
size << std::endl;
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
ccl_device float3 equiangular_cubemap_face_to_direction(float u, float v)
ccl_device float2 direction_to_mirrorball(float3 dir)
ccl_device float2 direction_to_fisheye_equidistant(const float3 dir, const float fov)
ccl_device_inline float3 fisheye_lens_polynomial_to_direction(float u, float v, float coeff0, const float4 coeffs, const float fov, const float width, const float height)
ccl_device float3 fisheye_equidistant_to_direction(float u, float v, float fov)
ccl_device float2 direction_to_fisheye_equisolid(const float3 dir, const float lens, const float width, const float height)
ccl_device_inline float3 fisheye_equisolid_to_direction(float u, float v, float lens, const float fov, const float width, const float height)
ccl_device float2 direction_to_fisheye_lens_polynomial(float3 dir, const float coeff0, const float4 coeffs, const float width, const float height)
ccl_device float3 mirrorball_to_direction(const float u, const float v)
ccl_device float2 direction_to_equiangular_cubemap_face(const float3 dir)
ccl_device float2 direction_to_equirectangular(const float3 dir)
ccl_device float3 equirectangular_to_direction(const float u, const float v)
CCL_NAMESPACE_BEGIN ccl_device float2 direction_to_spherical(const float3 dir)
ccl_device float3 spherical_to_direction(const float theta, const float phi)
#define CCL_NAMESPACE_END
CCL_NAMESPACE_BEGIN TEST(KernelCamera, FisheyeLensPolynomialRoundtrip)
Test fisheye_lens_polynomial_to_direction and its inverse direction_to_fisheye_lens_polynomial by che...
TYPED_TEST_SUITE(PanoramaProjection, MyTypes)
::testing::Types< Spherical, Equirectangular, FisheyeEquidistant, FisheyeEquisolid, MirrorBall, EquiangularCubemapFace > MyTypes
TYPED_TEST(PanoramaProjection, round_trip)
Test <projection>to_direction and its inverse direction_to<projection> by checking if sensor position...
The CommonValues struct contains information about the tests which is common across the different tes...
virtual bool skip_invalid() const
If skip_invalid returns true, invalid unprojections are ignored in the test.
virtual double threshold() const
Threshold for the reprojection error.
static float2 direction_to_sensor(const float3 &dir, const float fov, const float width, const float height)
static float3 sensor_to_direction(const float2 &sensor, const float fov, const float width, const float height)
static float2 direction_to_sensor(const float3 &dir, const float fov, const float width, const float height)
static float3 sensor_to_direction(const float2 &sensor, const float fov, const float width, const float height)
static float3 sensor_to_direction(const float2 &sensor, const float fov, const float width, const float height)
static float2 direction_to_sensor(const float3 &dir, const float fov, const float width, const float height)
bool skip_invalid() const override
If skip_invalid returns true, invalid unprojections are ignored in the test.
static float2 direction_to_sensor(const float3 &dir, const float fov, const float width, const float height)
static constexpr float lens
static float3 sensor_to_direction(const float2 &sensor, const float fov, const float width, const float height)
static float3 sensor_to_direction(const float2 &sensor, const float fov, const float width, const float height)
static float2 direction_to_sensor(const float3 &dir, const float fov, const float width, const float height)
static float2 direction_to_sensor(const float3 &dir, const float fov, const float width, const float height)
static float3 sensor_to_direction(const float2 &sensor, const float fov, const float width, const float height)