core/vcsl/vcsl_coordinate_system.cxx
Go to the documentation of this file.
00001 // This is core/vcsl/vcsl_coordinate_system.cxx
00002 #include "vcsl_coordinate_system.h"
00003 #include <vcl_cassert.h>
00004 #include <vcsl/vcsl_axis.h>
00005 #include <vcsl/vcsl_unit.h> // for method vcsl_axis::unit()
00006 
00007 //---------------------------------------------------------------------------
00008 // Return the axis `i'
00009 // REQUIRE: valid_axis(i)
00010 //---------------------------------------------------------------------------
00011 vcsl_axis_sptr vcsl_coordinate_system::axis(int i) const
00012 {
00013   // require
00014   assert(valid_axis(i));
00015 
00016   return axes_[i];
00017 }
00018 
00019 //---------------------------------------------------------------------------
00020 // Convert `v', expressed with cs units, to standard units
00021 // REQUIRE: v.size()==dimensionality()
00022 //---------------------------------------------------------------------------
00023 vnl_vector<double>
00024 vcsl_coordinate_system::from_cs_to_standard_units(const vnl_vector<double> &v) const
00025 {
00026   vnl_vector<double> result(v.size());
00027 
00028   int j=0;
00029   vcl_vector<vcsl_axis_sptr>::const_iterator i;
00030   for (i=axes_.begin();i!=axes_.end();++i,++j)
00031     result.put(j,v.get(j)/(*i)->unit()->units_per_standard_unit()); // a vcsl_unit
00032 
00033   return result;
00034 }
00035 
00036 //---------------------------------------------------------------------------
00037 // Convert `v', expressed with standard units, to cs units
00038 // REQUIRE: v.size()==dimensionality()
00039 //---------------------------------------------------------------------------
00040 vnl_vector<double>
00041 vcsl_coordinate_system::from_standard_units_to_cs(const vnl_vector<double> &v) const
00042 {
00043   vnl_vector<double> result(v.size());
00044 
00045   int j=0;
00046   vcl_vector<vcsl_axis_sptr>::const_iterator i;
00047   for (i=axes_.begin();i!=axes_.end();++i,++j)
00048     result.put(j,v.get(j)*(*i)->unit()->units_per_standard_unit());
00049 
00050   return result;
00051 }