1 #include "testlib/testlib_test.h"
2 #include <vsph/vsph_unit_sphere.h>
3 #include <vsph/vsph_sph_point_2d.h>
4 #include <vsph/vsph_sph_box_2d.h>
5 #include <vsph/vsph_utils.h>
6 #include "vgl/vgl_polygon.h"
7 #include <bpgl/bpgl_camera_utils.h>
8 #include "vpl/vpl.h"
9
10
test_utils()11 static void test_utils()
12 {
13 unsigned ni = 1280, nj = 720;
14 auto nid = static_cast<double>(ni), njd = static_cast<double>(nj);
15 double heading = 180.0, tilt = 90.0, roll =0.0, altitude = 1.0;
16 double top_fov = 10.0;
17 double right_fov = 17.47;
18 vpgl_perspective_camera<double> cam =
19 bpgl_camera_utils::camera_from_kml(ni, nj, right_fov, top_fov,altitude,
20 heading, tilt, roll);
21
22 double elevation = 0.0, azimuth = 0.0;
23 // ============== test ray direction on unit sphere ======
24 vsph_utils::ray_spherical_coordinates(cam, 640.0, 360.0, elevation,
25 azimuth, "degrees");
26 double er = std::fabs(elevation - (180.0-tilt));
27 er += std::fabs(azimuth - (90.0 -heading));
28 TEST_NEAR("ray spherical coordinates", er, 0.0, 0.001);
29
30 // ================= test project poly onto sphere =======
31 // remove roll for poly angle tests
32 roll = 0.0;
33 vpgl_perspective_camera<double> cam0 =
34 bpgl_camera_utils::camera_from_kml(nid, njd, right_fov, top_fov,
35 altitude, heading, tilt, roll);
36
37 vgl_point_2d<double> p0(640.0, 0.0), p1(1280.0, 0.0);
38 vgl_point_2d<double> p2(1280.0, 360.0), p3(640.0, 360.0);//<==principal pt
39 std::vector<vgl_point_2d<double> > sheet;
40 sheet.push_back(p0); sheet.push_back(p1);
41 sheet.push_back(p2); sheet.push_back(p3);
42 vgl_polygon<double> image_poly, sph_poly;
43 image_poly.push_back(sheet);
44 std::cout << "in image\n" << image_poly << '\n';
45 sph_poly =
46 vsph_utils::project_poly_onto_unit_sphere(cam0, image_poly, "degrees");
47 std::cout << "on sphere\n" << sph_poly << '\n';
48 vgl_point_2d<double> sp0 = sph_poly[0][0];
49 vgl_point_2d<double> sp2 = sph_poly[0][2];
50 vgl_point_2d<double> sp3 = sph_poly[0][3];
51 //x is elevation and y is azimuth
52 double t_fov = std::fabs(sp0.x()-sp3.x());
53 double r_fov = std::fabs(sp2.y()-sp3.y());
54 // shouldn't expect exact recovery since focal length is
55 // the average of top and right fov
56 er = std::fabs(t_fov-top_fov) + std::fabs(r_fov-right_fov);
57 TEST_NEAR("spherical polygon ", er, 0.0, 1.0);//1 degree
58 }
59
60 TESTMAIN(test_utils);
61