vcsl_translation.cxx
Go to the documentation of this file.
1 // This is core/vcsl/vcsl_translation.cxx
2 #include "vcsl_translation.h"
3 #include <cassert>
4 #ifdef _MSC_VER
5 # include <vcl_msvc_warnings.h>
6 #endif
7 
8 //---------------------------------------------------------------------------
9 // Is `this' invertible at time `time'?
10 // REQUIRE: valid_time(time)
11 //---------------------------------------------------------------------------
12 bool vcsl_translation::is_invertible(double time) const
13 {
14  // require
15  assert(valid_time(time));
16 
17  return true;
18 }
19 
20 //---------------------------------------------------------------------------
21 // Set the parameters of a static translation
22 //---------------------------------------------------------------------------
24 {
25  vector_.clear(); vector_.push_back(new_vector);
27 }
28 
29 //---------------------------------------------------------------------------
30 // Image of `v' by `this'
31 // REQUIRE: is_valid()
32 //---------------------------------------------------------------------------
34  double time) const
35 {
36  // require
37  assert(is_valid());
38 
39  vnl_vector<double> value=vector_value(time);
40  vnl_vector<double> result(v.size());
41  for (unsigned int i=0;i<v.size();++i)
42  result.put(i,v.get(i)+value.get(i));
43 
44  return result;
45 }
46 
47 //---------------------------------------------------------------------------
48 // Image of `v' by the inverse of `this'
49 // REQUIRE: is_valid()
50 // REQUIRE: is_invertible(time)
51 //---------------------------------------------------------------------------
53  double time) const
54 {
55  // require
56  assert(is_valid());
57  assert(is_invertible(time));
58 
59  vnl_vector<double> value=vector_value(time);
60  vnl_vector<double> result(v.size());
61  for (unsigned int i=0;i<v.size();++i)
62  result.put(i,v.get(i)-value.get(i));
63 
64  return result;
65 }
66 
67 //---------------------------------------------------------------------------
68 // Compute the value of the parameter at time `time'
69 //---------------------------------------------------------------------------
71 {
72  if (this->duration()==0) // static
73  return vector_[0];
74  else
75  {
76  int i=matching_interval(time);
77  switch (interpolator_[i])
78  {
79  case vcsl_linear:
80  return lvi(vector_[i],vector_[i+1],i,time);
81  case vcsl_cubic:
82  assert(!"vcsl_cubic net yet implemented");
83  break;
84  case vcsl_spline:
85  assert(!"vcsl_spline net yet implemented");
86  break;
87  default:
88  assert(!"This is impossible");
89  break;
90  }
91  }
92  return vnl_vector<double>(); // never reached if asserts are in effect
93 }
unsigned int duration() const
Return the time duration.
bool is_valid() const override
Is ‘this’ correctly set ?.
vnl_vector< double > lvi(const vnl_vector< double > &v0, const vnl_vector< double > &v1, int index, double time) const
Linear interpolation on vnl_vectors.
Translation transformation.
vnl_vector< double > vector_value(double time) const
Compute the value of the parameter at time ‘time’.
std::vector< vcsl_interpolator > interpolator_
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’.
void put(size_t i, double const &v)
vnl_vector< double > execute(const vnl_vector< double > &v, double time) const override
Image of ‘v’ by ‘this’.
int matching_interval(double time) const
Return the index of the beat inferior or equal to ‘time’.
bool valid_time(double time) const
Is ‘time’ between the two time bounds ?.
list_of_vectors vector_
Direction vector variation along the time.
double get(size_t i) const
bool is_invertible(double time) const override
Is ‘this’ invertible at time ‘time’?.