vcsl_displacement.cxx
Go to the documentation of this file.
1 // This is core/vcsl/vcsl_displacement.cxx
2 #include "vcsl_displacement.h"
3 #include <cassert>
4 #ifdef _MSC_VER
5 # include <vcl_msvc_warnings.h>
6 #endif
7 
8 //---------------------------------------------------------------------------
9 // Set the point for a static displacement
10 //---------------------------------------------------------------------------
12 {
13  point_.clear(); point_.push_back(new_point);
15 }
16 
17 //---------------------------------------------------------------------------
18 // Image of `v' by `this'
19 // REQUIRE: is_valid()
20 //---------------------------------------------------------------------------
22  double time) const
23 {
24  // require
25  assert(is_valid());
26  assert((is_2d()&&v.size()==2)||(is_3d()&&v.size()==3));
27 
28  vnl_vector<double> translation=vector_value(time);
29 
31 
32  if (mode_2d_)
33  {
34  result.put(0,v.get(0)-translation.get(0));
35  result.put(1,v.get(1)-translation.get(1));
36  result.put(2,0);
37  }
38  else
39  result=v-translation;
40 
42  result = q.rotate(result);
43 
44  if (mode_2d_)
45  {
46  vnl_vector<double> tmp(2);
47  tmp.put(0,result.get(0)+translation.get(0));
48  tmp.put(1,result.get(1)+translation.get(1));
49  return tmp;
50  }
51  else
52  return result+translation;
53 }
54 
55 //---------------------------------------------------------------------------
56 // Image of `v' by the inverse of `this'
57 // REQUIRE: is_valid()
58 // REQUIRE: is_invertible(time)
59 //---------------------------------------------------------------------------
61  double time) const
62 {
63  // require
64  assert(is_valid());
65  assert(is_invertible(time));
66  assert((is_2d()&&v.size()==2)||(is_3d()&&v.size()==3));
67 
68  vnl_vector<double> translation=vector_value(time);
69 
71 
72  if (mode_2d_)
73  {
74  result.put(0,v.get(0)-translation.get(0));
75  result.put(1,v.get(1)-translation.get(1));
76  result.put(2,0);
77  }
78  else
79  result=v-translation;
80 
82  result = q.conjugate().rotate(result);
83 
84  if (mode_2d_)
85  {
86  vnl_vector<double> tmp(2);
87  tmp.put(0,result.get(0)+translation.get(0));
88  tmp.put(1,result.get(1)+translation.get(1));
89  return tmp;
90  }
91  else
92  return result+translation;
93 }
94 
95 //---------------------------------------------------------------------------
96 // Compute the value of the vector at time `time'
97 //---------------------------------------------------------------------------
99 {
100  if (this->duration()==0) // static
101  return point_[0];
102  else
103  {
104  int i=matching_interval(time);
105  switch (interpolator_[i])
106  {
107  case vcsl_linear:
108  return lvi(point_[i],point_[i+1],i,time);
109  case vcsl_cubic:
110  assert(!"vcsl_cubic net yet implemented");
111  break;
112  case vcsl_spline:
113  assert(!"vcsl_spline net yet implemented");
114  break;
115  default:
116  assert(!"This is impossible");
117  break;
118  }
119  }
120  return vnl_vector<double>(); // never reached if asserts are in effect
121 }
unsigned int duration() const
Return the time duration.
vnl_vector< double > lvi(const vnl_vector< double > &v0, const vnl_vector< double > &v1, int index, double time) const
Linear interpolation on vnl_vectors.
bool mode_2d_
False if ‘this’ is a 3D rotation, true if ‘this’ is a 2D rotation.
std::vector< vcsl_interpolator > interpolator_
Affine rotation.
T get(unsigned int i) const
void set_static()
Empty the time clock and interpolators, thereby making the transf static.
#define v
bool is_invertible(double) const override
Is ‘this’ invertible at time ‘time’?.
Definition: vcsl_rotation.h:47
bool is_2d() const
Is ‘this’ a 2D rotation ?.
Definition: vcsl_rotation.h:60
vnl_quaternion< T > conjugate() const
vnl_vector< double > inverse(const vnl_vector< double > &v, double time) const override
Image of ‘v’ by the inverse of ‘this’.
bool is_valid() const override
Is ‘this’ correctly set ?.
vnl_vector< double > vector_value(double time) const
Compute the value of the vector at time ‘time’.
void put(size_t i, double const &v)
vnl_vector_fixed< T, 3 > rotate(vnl_vector_fixed< T, 3 > const &) const
int matching_interval(double time) const
Return the index of the beat inferior or equal to ‘time’.
bool is_3d() const
Is ‘this’ a 3D rotation ?.
Definition: vcsl_rotation.h:63
vnl_quaternion< double > quaternion(double time) const
Compute the value of the quaternion at time ‘time’.
list_of_vectors point_
Variation of the point of the axis along the time.
void put(unsigned int i, T const &v)
void set_static_point(vnl_vector< double > const &new_point)
Set the point for a static displacement.
vnl_vector< double > execute(const vnl_vector< double > &v, double time) const override
Image of ‘v’ by ‘this’.
double get(size_t i) const