vcsl_scale.cxx
Go to the documentation of this file.
1 // This is core/vcsl/vcsl_scale.cxx
2 #include "vcsl_scale.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_scale::is_invertible(double time) const
13 {
14  // require
15  assert(valid_time(time));
16 
17  return ((this->duration()==0)&&(scale_[0]!=0.0))||(scale_value(time)!=0.0);
18 }
19 
20 //---------------------------------------------------------------------------
21 // Set the scale value of a static scale
22 //---------------------------------------------------------------------------
23 void vcsl_scale::set_static(double new_scale)
24 {
25  scale_.clear();
26  scale_.push_back(new_scale);
28 }
29 
30 //---------------------------------------------------------------------------
31 // Image of `v' by `this'
32 // REQUIRE: is_valid()
33 //---------------------------------------------------------------------------
35  double time) const
36 {
37  // require
38  assert(is_valid());
39 
40  double value=scale_value(time);
41  vnl_vector<double> result(v.size());
42  for (unsigned int i=0;i<v.size();++i)
43  result.put(i,value*v.get(i));
44 
45  return result;
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  // require
57  assert(is_valid());
58  assert(is_invertible(time));
59 
60  double value=scale_value(time);
61  vnl_vector<double> result(v.size());
62  for (unsigned int i=0;i<v.size();++i)
63  result.put(i,v.get(i)/value);
64 
65  return result;
66 }
67 
68 //---------------------------------------------------------------------------
69 // Compute the value of the parameter at time `time'
70 //---------------------------------------------------------------------------
71 double vcsl_scale::scale_value(double time) const
72 {
73  if (this->duration()==0) // static
74  return scale_[0];
75  else
76  {
77  int i=matching_interval(time);
78  switch (interpolator_[i])
79  {
80  case vcsl_linear:
81  return lsi(scale_[i],scale_[i+1],i,time);
82  case vcsl_cubic:
83  assert(!"vcsl_cubic net yet implemented");
84  break;
85  case vcsl_spline:
86  assert(!"vcsl_spline net yet implemented");
87  break;
88  default:
89  assert(!"This is impossible");
90  break;
91  }
92  }
93  return 0.0; // never reached if asserts are in effect
94 }
unsigned int duration() const
Return the time duration.
vnl_vector< double > inverse(const vnl_vector< double > &v, double time) const override
Image of ‘v’ by the inverse of ‘this’.
Definition: vcsl_scale.cxx:53
bool is_invertible(double time) const override
Is ‘this’ invertible at time ‘time’?.
Definition: vcsl_scale.cxx:12
double lsi(double v0, double v1, int index, double time) const
Linear interpolation on scalar values.
double scale_value(double time) const
Compute the value of the parameter at time ‘time’.
Definition: vcsl_scale.cxx:71
std::vector< vcsl_interpolator > interpolator_
std::vector< double > scale_
Scale variation along the time.
Definition: vcsl_scale.h:88
void set_static()
Empty the time clock and interpolators, thereby making the transf static.
#define v
vnl_vector< double > execute(const vnl_vector< double > &v, double time) const override
Image of ‘v’ by ‘this’.
Definition: vcsl_scale.cxx:34
void put(size_t i, double const &v)
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 ?.
Scale transformation.
bool is_valid() const override
Is ‘this’ correctly set ?.
Definition: vcsl_scale.h:47