core/vcsl/vcsl_scale.cxx
Go to the documentation of this file.
00001 // This is core/vcsl/vcsl_scale.cxx
00002 #include "vcsl_scale.h"
00003 #include <vcl_cassert.h>
00004 
00005 //---------------------------------------------------------------------------
00006 // Is `this' invertible at time `time'?
00007 // REQUIRE: valid_time(time)
00008 //---------------------------------------------------------------------------
00009 bool vcsl_scale::is_invertible(double time) const
00010 {
00011   // require
00012   assert(valid_time(time));
00013 
00014   return ((this->duration()==0)&&(scale_[0]!=0.0))||(scale_value(time)!=0.0);
00015 }
00016 
00017 //---------------------------------------------------------------------------
00018 // Set the scale value of a static scale
00019 //---------------------------------------------------------------------------
00020 void vcsl_scale::set_static(double new_scale)
00021 {
00022   scale_.clear();
00023   scale_.push_back(new_scale);
00024   vcsl_spatial_transformation::set_static();
00025 }
00026 
00027 //---------------------------------------------------------------------------
00028 // Image of `v' by `this'
00029 // REQUIRE: is_valid()
00030 //---------------------------------------------------------------------------
00031 vnl_vector<double> vcsl_scale::execute(const vnl_vector<double> &v,
00032                                        double time) const
00033 {
00034   // require
00035   assert(is_valid());
00036 
00037   double value=scale_value(time);
00038   vnl_vector<double> result(v.size());
00039   for (unsigned int i=0;i<v.size();++i)
00040     result.put(i,value*v.get(i));
00041 
00042   return result;
00043 }
00044 
00045 //---------------------------------------------------------------------------
00046 // Image of `v' by the inverse of `this'
00047 // REQUIRE: is_valid()
00048 // REQUIRE: is_invertible(time)
00049 //---------------------------------------------------------------------------
00050 vnl_vector<double> vcsl_scale::inverse(const vnl_vector<double> &v,
00051                                        double time) const
00052 {
00053   // require
00054   assert(is_valid());
00055   assert(is_invertible(time));
00056 
00057   double value=scale_value(time);
00058   vnl_vector<double> result(v.size());
00059   for (unsigned int i=0;i<v.size();++i)
00060     result.put(i,v.get(i)/value);
00061 
00062   return result;
00063 }
00064 
00065 //---------------------------------------------------------------------------
00066 // Compute the value of the parameter at time `time'
00067 //---------------------------------------------------------------------------
00068 double vcsl_scale::scale_value(double time) const
00069 {
00070   if (this->duration()==0) // static
00071     return scale_[0];
00072   else
00073   {
00074     int i=matching_interval(time);
00075     switch (interpolator_[i])
00076     {
00077      case vcsl_linear:
00078       return lsi(scale_[i],scale_[i+1],i,time);
00079      case vcsl_cubic:
00080       assert(!"vcsl_cubic net yet implemented");
00081       break;
00082      case vcsl_spline:
00083       assert(!"vcsl_spline net yet implemented");
00084       break;
00085      default:
00086       assert(!"This is impossible");
00087       break;
00088     }
00089   }
00090   return 0.0; // never reached if asserts are in effect
00091 }