1 #include <iostream>
2 #include "testlib/testlib_test.h"
3 // not used? #include <vcl_compiler.h>
4 #include "vgl/vgl_homg_point_2d.h"
5 #include "vpgl/vpgl_calibration_matrix.h"
6 #include "vnl/vnl_fwd.h"
7 
8 static void
test_calibration_matrix()9 test_calibration_matrix()
10 {
11   double focal_length = 3;
12   vgl_homg_point_2d<double> principal_point(20, 30, 2);
13   double x_scale = 2;
14   double y_scale = 2;
15   double skew = 0;
16   vpgl_calibration_matrix<double> K1(focal_length, principal_point, x_scale, y_scale, skew);
17 
18   // Test equality of constructors.
19   vnl_matrix_fixed<double, 3, 3> M(0.0);
20   double scale_factor = -100;
21   M(0, 0) = scale_factor * x_scale * focal_length;
22   M(1, 1) = scale_factor * y_scale * focal_length;
23   M(2, 2) = scale_factor;
24   M(0, 2) = scale_factor * 10;
25   M(1, 2) = scale_factor * 15;
26   vpgl_calibration_matrix<double> K1b(M);
27 
28   TEST_NEAR("test equality of constructors 1", K1.get_matrix() == K1b.get_matrix(), true, 1e-06);
29   TEST_NEAR("test equality of constructors 2",
30             K1.focal_length() * K1.x_scale() == K1b.focal_length() * K1b.x_scale() && K1.skew() == K1b.skew(),
31             true,
32             1e-06);
33 
34   // Test the focal length setter.
35   focal_length = 5;
36   vpgl_calibration_matrix<double> K2(focal_length, principal_point, x_scale, y_scale, skew);
37   K1.set_focal_length(focal_length);
38   TEST_NEAR("test focal length setter", K1.get_matrix() == K2.get_matrix(), true, 1e-06);
39 
40   // Test the skew setter.
41   skew = 2;
42   vpgl_calibration_matrix<double> K3(focal_length, principal_point, x_scale, y_scale, skew);
43   K1.set_skew(skew);
44   TEST_NEAR("test skew setter", K1.get_matrix() == K3.get_matrix(), true, 1e-06);
45 
46   // Test the x scale setter.
47   x_scale = 6;
48   vpgl_calibration_matrix<double> K4(focal_length, principal_point, x_scale, y_scale, skew);
49   K1.set_x_scale(x_scale);
50   TEST_NEAR("test x_scale setter", K1.get_matrix() == K4.get_matrix(), true, 1e-06);
51 
52   // Test the principal point setter.
53   principal_point.set(17, 100);
54   vpgl_calibration_matrix<double> K5(focal_length, principal_point, x_scale, y_scale, skew);
55   K1.set_principal_point(principal_point);
56   TEST_NEAR("test principal point setter", K1.get_matrix() == K5.get_matrix(), true, 1e-06);
57 
58   // Test the y scale setter.
59   y_scale = 6;
60   vpgl_calibration_matrix<double> K6(focal_length, principal_point, x_scale, y_scale, skew);
61   K1.set_y_scale(y_scale);
62   TEST_NEAR("test y_scale setter", K1.get_matrix() == K6.get_matrix(), true, 1e-06);
63 }
64 
65 TESTMAIN(test_calibration_matrix);
66