vcsl_matrix.cxx
Go to the documentation of this file.
1 // This is core/vcsl/vcsl_matrix.cxx
2 #include <cmath>
3 #include <iostream>
4 #include "vcsl_matrix.h"
5 #include <cassert>
6 #ifdef _MSC_VER
7 # include <vcl_msvc_warnings.h>
8 #endif
9 
10 //---------------------------------------------------------------------------
11 // Is `this' invertible at time `time'?
12 // REQUIRE: valid_time(time)
13 //---------------------------------------------------------------------------
14 bool vcsl_matrix::is_invertible(double time) const
15 {
16  // require
17  assert(valid_time(time));
18 
19  return true;
20 }
21 
22 //---------------------------------------------------------------------------
23 // Set the parameters of a static translation
24 //---------------------------------------------------------------------------
26 {
27  matrix_.clear(); matrix_.push_back(new_matrix);
29 }
30 
31 //---------------------------------------------------------------------------
32 // Image of `v' by `this'
33 // REQUIRE: is_valid()
34 //---------------------------------------------------------------------------
36  double time) const
37 {
38  // require
39  assert(is_valid());
40  assert(v.size()==3);
41 
42  vnl_vector_fixed<double,4> temp(v(0),v(1),v(2),1.0);
43 
44  vnl_matrix<double> value=matrix_value(time,true);
45  return value*temp;
46 }
47 
48 //---------------------------------------------------------------------------
49 // Image of `v' by the inverse of `this'
50 // REQUIRE: is_valid()
51 // REQUIRE: is_invertible(time)
52 //---------------------------------------------------------------------------
54  double time) const
55 {
56  assert(is_valid());
57  assert(v.size()==3);
58 
59  vnl_vector_fixed<double,4> temp(v(0),v(1),v(2),1.0);
60 
61  vnl_matrix<double> value=matrix_value(time,false);
62  return value*temp;
63 }
64 
65 //---------------------------------------------------------------------------
66 // Compute the value of the parameter at time `time'
67 //---------------------------------------------------------------------------
68 
69 vnl_matrix<double> vcsl_matrix::matrix_value(double time, bool type) const
70 {
71  if (this->duration()==0) // static
72  return param_to_matrix(matrix_[0],type);
73 
74  else
75  {
76  int i=matching_interval(time);
77  switch (interpolator_[i])
78  {
79  case vcsl_linear:
80  return lmi(param_to_matrix(matrix_[i],type),param_to_matrix(matrix_[i+1],type),i,time);
81  case vcsl_cubic:
82  assert(!"vcsl_cubic not yet implemented");
83  break;
84  case vcsl_spline:
85  assert(!"vcsl_spline not yet implemented");
86  break;
87  default:
88  assert(!"This is impossible");
89  break;
90  }
91  }
92  return vnl_matrix<double>(); // never reached if asserts are in effect
93 }
94 
96 {
97  int coef =1;
98  if (type) coef = -1;
99 
100  vnl_matrix<double> T(3, 4, 0.0);
101  T(0,0) = 1.0; T(1,1) = 1.0; T(2,2) = 1.0;
102  T(0,3) = -coef*from->xl; T(1,3) = -coef*from->yl; T(2,3) = -coef*from->zl;
103  std::cout << "Translation:\n" << T;
104  // Rotation matrix (Extrinsic parameters)
105  double co = std::cos(coef*from->omega), so = std::sin(coef*from->omega);
106  double cp = std::cos(coef*from->phi), sp = std::sin(coef*from->phi);
107  double ck = std::cos(coef*from->kappa), sk = std::sin(coef*from->kappa);
108  vnl_matrix<double> R(4, 4, 0.0);
109  R(0,0) = cp*ck; R(0,1) = so*sp*ck+co*sk; R(0,2) = -co*sp*ck+so*sk;
110  R(1,0) = -cp*sk; R(1,1) = -so*sp*sk+co*ck; R(1,2) = co*sp*sk+so*ck;
111  R(2,0) = sp; R(2,1) = -so*cp; R(2,2) = co*cp;
112  R(3,0)=R(3,1)=R(3,2)=R(0,3)=R(1,3)=R(2,3)=0;
113  R(3,3)=1;
114  std::cout << "Rotation:\n" << R;
115 
116  if (type)
117  return T*R;
118  else
119  {
120  vnl_matrix<double> temp(3,3);
121  for (int i=0;i<3;i++)
122  for (int j=0;j<3;j++)
123  temp(i,j)=R(i,j);
124  return temp*T;
125  }
126 }
unsigned int duration() const
Return the time duration.
vnl_matrix< double > lmi(const vnl_matrix< double > &m0, const vnl_matrix< double > &m1, int index, double time) const
Linear interpolation on vnl_matrices.
std::vector< vcsl_interpolator > interpolator_
vnl_vector< double > execute(const vnl_vector< double > &v, double time) const override
Image of ‘v’ by ‘this’.
Definition: vcsl_matrix.cxx:35
void set_static()
Empty the time clock and interpolators, thereby making the transf static.
#define v
vnl_vector< double > inverse(const vnl_vector< double > &v, double time) const override
Image of ‘v’ by the inverse of ‘this’.
Definition: vcsl_matrix.cxx:53
bool is_invertible(double time) const override
Is ‘this’ invertible at time ‘time’?.
Definition: vcsl_matrix.cxx:14
vnl_matrix< double > param_to_matrix(const vcsl_matrix_param_sptr &from, bool type) const
Definition: vcsl_matrix.cxx:95
int matching_interval(double time) const
Return the index of the beat inferior or equal to ‘time’.
A coordinate transformation specified by a transformation matrix.
bool valid_time(double time) const
Is ‘time’ between the two time bounds ?.
bool is_valid() const override
Is ‘this’ correctly set ?.
Definition: vcsl_matrix.h:50
list_of_vcsl_matrix_param_sptr matrix_
Definition: vcsl_matrix.h:76
vnl_matrix< double > matrix_value(double time, bool type) const
Definition: vcsl_matrix.cxx:69