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