00001
00002 #include "vcsl_matrix.h"
00003 #include <vcl_cassert.h>
00004 #include <vcl_cmath.h>
00005 #include <vcl_iostream.h>
00006
00007
00008
00009
00010
00011 bool vcsl_matrix::is_invertible(double time) const
00012 {
00013
00014 assert(valid_time(time));
00015
00016 return true;
00017 }
00018
00019
00020
00021
00022 void vcsl_matrix::set_static( vcsl_matrix_param_sptr new_matrix)
00023 {
00024 matrix_.clear(); matrix_.push_back(new_matrix);
00025 vcsl_spatial_transformation::set_static();
00026 }
00027
00028
00029
00030
00031
00032 vnl_vector<double> vcsl_matrix::execute(const vnl_vector<double> &v,
00033 double time) const
00034 {
00035
00036 assert(is_valid());
00037 assert(v.size()==3);
00038
00039 vnl_vector_fixed<double,4> temp(v(0),v(1),v(2),1.0);
00040
00041 vnl_matrix<double> value=matrix_value(time,true);
00042 return value*temp;
00043 }
00044
00045
00046
00047
00048
00049
00050 vnl_vector<double> vcsl_matrix::inverse(const vnl_vector<double> &v,
00051 double time) const
00052 {
00053 assert(is_valid());
00054 assert(v.size()==3);
00055
00056 vnl_vector_fixed<double,4> temp(v(0),v(1),v(2),1.0);
00057
00058 vnl_matrix<double> value=matrix_value(time,false);
00059 return value*temp;
00060 }
00061
00062
00063
00064
00065
00066 vnl_matrix<double> vcsl_matrix::matrix_value(double time, bool type) const
00067 {
00068 if (this->duration()==0)
00069 return param_to_matrix(matrix_[0],type);
00070
00071 else
00072 {
00073 int i=matching_interval(time);
00074 switch (interpolator_[i])
00075 {
00076 case vcsl_linear:
00077 return lmi(param_to_matrix(matrix_[i],type),param_to_matrix(matrix_[i+1],type),i,time);
00078 case vcsl_cubic:
00079 assert(!"vcsl_cubic not yet implemented");
00080 break;
00081 case vcsl_spline:
00082 assert(!"vcsl_spline not yet implemented");
00083 break;
00084 default:
00085 assert(!"This is impossible");
00086 break;
00087 }
00088 }
00089 return vnl_matrix<double>();
00090 }
00091
00092 vnl_matrix<double> vcsl_matrix::param_to_matrix(vcsl_matrix_param_sptr from,bool type ) const
00093 {
00094 int coef =1;
00095 if (type) coef = -1;
00096
00097 vnl_matrix<double> T(3, 4, 0.0);
00098 T(0,0) = 1.0; T(1,1) = 1.0; T(2,2) = 1.0;
00099 T(0,3) = -coef*from->xl; T(1,3) = -coef*from->yl; T(2,3) = -coef*from->zl;
00100 vcl_cout << "Translation:\n" << T;
00101
00102 double co = vcl_cos(coef*from->omega), so = vcl_sin(coef*from->omega);
00103 double cp = vcl_cos(coef*from->phi), sp = vcl_sin(coef*from->phi);
00104 double ck = vcl_cos(coef*from->kappa), sk = vcl_sin(coef*from->kappa);
00105 vnl_matrix<double> R(4, 4, 0.0);
00106 R(0,0) = cp*ck; R(0,1) = so*sp*ck+co*sk; R(0,2) = -co*sp*ck+so*sk;
00107 R(1,0) = -cp*sk; R(1,1) = -so*sp*sk+co*ck; R(1,2) = co*sp*sk+so*ck;
00108 R(2,0) = sp; R(2,1) = -so*cp; R(2,2) = co*cp;
00109 R(3,0)=R(3,1)=R(3,2)=R(0,3)=R(1,3)=R(2,3)=0;
00110 R(3,3)=1;
00111 vcl_cout << "Rotation:\n" << R;
00112
00113 if (type)
00114 return T*R;
00115 else
00116 {
00117 vnl_matrix<double> temp(3,3);
00118 for (int i=0;i<3;i++)
00119 for (int j=0;j<3;j++)
00120 temp(i,j)=R(i,j);
00121 return temp*T;
00122 }
00123 }