00001 #include "brct_structure_estimator.h"
00002 #include <vnl/vnl_inverse.h>
00003 #include "brct_algos.h"
00004
00005 brct_structure_estimator::brct_structure_estimator(vnl_double_3x4 &P)
00006 {
00007 A_.set_identity();
00008
00009
00010 Q_.set_identity();
00011
00012 P_ = P;
00013 }
00014
00015 bugl_gaussian_point_3d<double> brct_structure_estimator::forward(
00016 bugl_gaussian_point_3d<double>& state,
00017 bugl_gaussian_point_2d<double>& observe)
00018 {
00019 vnl_double_3 Y(state.x(), state.y(), state.z());
00020
00021 Y = A_*Y;
00022
00023 vnl_double_3x3 Q = A_*state.get_covariant_matrix()*A_.transpose() + Q_;
00024
00025 vnl_double_2x3 H = get_H_matrix(Y);
00026 vnl_double_2 z_pred = brct_algos::projection_3d_point(P_, Y);
00027 vnl_matrix_fixed<double, 3, 2> G = Q*H.transpose()*
00028 vnl_inverse(H*Q*H.transpose() + observe.get_covariant_matrix());
00029 vnl_double_3x3 I;
00030 I.set_identity();
00031 Q = (I - G*H)*Q;
00032 state.set_covariant_matrix(Q);
00033
00034 vnl_double_2 z(observe.x(), observe.y());
00035 Y = Y + G*(z - z_pred);
00036
00037 return bugl_gaussian_point_3d<double> (Y[0], Y[1], Y[2], Q);
00038 }
00039
00040 vnl_double_2x3 brct_structure_estimator::get_H_matrix(vnl_double_3& Y)
00041 {
00042 vnl_double_2x3 H;
00043
00044 double t = 0;
00045 for (int k=0; k<3; k++)
00046 t += P_[2][k]*Y[k];
00047 t+=P_[2][3];
00048
00049
00050 for (int i=0; i<2; i++){
00051 double t1 = 0;
00052 for (int k = 0; k<3; k++)
00053 t1 += P_[i][k]*Y[k];
00054 t1+= P_[i][3];
00055
00056 for (int j=0; j<3; j++)
00057 H[i][j] = P_[i][j] / t - P_[2][j]* t1 / t/t;
00058 }
00059
00060 return H;
00061 }
00062