1 // This is bbas/bpgl/bpgl_reg_fundamental_matrix.hxx
2 #ifndef bpgl_reg_fundamental_matrix_hxx_
3 #define bpgl_reg_fundamental_matrix_hxx_
4 //:
5 // \file
6
7 #include "bpgl_reg_fundamental_matrix.h"
8 #include <vnl/vnl_fwd.h>
9 #include <vgl/vgl_point_2d.h>
10
11 //---------------------------------
12 template <class T>
bpgl_reg_fundamental_matrix()13 bpgl_reg_fundamental_matrix<T>::bpgl_reg_fundamental_matrix() :
14 vpgl_fundamental_matrix<T>()
15 {
16 vnl_matrix_fixed<T,3,3> default_matrix( (T)0 );
17 default_matrix(0,1) = default_matrix(0,2) = (T)1;
18 default_matrix(1,0) = default_matrix(2,0) = -(T)1;
19 vpgl_fundamental_matrix<T>::set_matrix( default_matrix );
20 }
21
22
23 //---------------------------------
24 template <class T>
bpgl_reg_fundamental_matrix(const vgl_point_2d<T> & pr,const vgl_point_2d<T> & pl)25 bpgl_reg_fundamental_matrix<T>::bpgl_reg_fundamental_matrix(
26 const vgl_point_2d<T>& pr,
27 const vgl_point_2d<T>& pl ) :
28 vpgl_fundamental_matrix<T>()
29 {
30 set_from_points( pr, pl );
31 }
32
33 //---------------------------------
34 template <class T>
bpgl_reg_fundamental_matrix(const vpgl_fundamental_matrix<T> & fm)35 bpgl_reg_fundamental_matrix<T>::bpgl_reg_fundamental_matrix(
36 const vpgl_fundamental_matrix<T>& fm )
37 {
38 set_from_params( fm.get_matrix()(0,2), fm.get_matrix()(2,1) );
39 }
40
41
42 //---------------------------------
43 template <class T>
set_from_points(const vgl_point_2d<T> & pr,const vgl_point_2d<T> & pl)44 bool bpgl_reg_fundamental_matrix<T>::set_from_points(
45 const vgl_point_2d<T>& pr,
46 const vgl_point_2d<T>& pl )
47 {
48 T ex = pl.x() - pr.x();
49 T ey = pl.y() - pr.y();
50 if ( ex == 0 && ey == 0 ) return false;
51 vnl_matrix_fixed<T,3,3> fm( (T)0 );
52 fm.put( 0, 2, ey );
53 fm.put( 1, 2, -ex );
54 fm.put( 2, 0, -ey );
55 fm.put( 2, 1, ex );
56 vpgl_fundamental_matrix<T>::set_matrix( fm );
57 return true;
58 }
59
60
61 //---------------------------------
62 template <class T>
set_from_params(T a,T b)63 void bpgl_reg_fundamental_matrix<T>::set_from_params( T a, T b )
64 {
65 vnl_matrix_fixed<T,3,3> fm( (T)0 );
66 fm.put( 0, 2, a );
67 fm.put( 1, 2, -b );
68 fm.put( 2, 0, -a );
69 fm.put( 2, 1, b );
70 vpgl_fundamental_matrix<T>::set_matrix( fm );
71 };
72
73
74 // Code for easy instantiation.
75 #undef BPGL_REG_FUNDAMENTAL_MATRIX_INSTANTIATE
76 #define BPGL_REG_FUNDAMENTAL_MATRIX_INSTANTIATE(T) \
77 template class bpgl_reg_fundamental_matrix<T >
78
79 #endif // bpgl_reg_fundamental_matrix_hxx_
80