core/vcsl/vcsl_spatial_transformation.h
Go to the documentation of this file.
00001 // This is core/vcsl/vcsl_spatial_transformation.h
00002 #ifndef vcsl_spatial_transformation_h_
00003 #define vcsl_spatial_transformation_h_
00004 //:
00005 // \file
00006 // \author François BERTEL
00007 // \brief Transformation between 2 spatial coordinate systems
00008 //
00009 // \verbatim
00010 //  Modifications
00011 //   2000/06/28 François BERTEL Creation. Adapted from IUE
00012 //   2001/04/10 Ian Scott (Manchester) Converted perceps header to doxygen
00013 //   2002/01/22 Peter Vanroose - added lmi() as it is used in vcsl_matrix.cxx
00014 //   2002/01/22 Peter Vanroose - return type of lqi(), lvi(), execute() and inverse() changed to non-ptr
00015 //   2002/01/28 Peter Vanroose - vcl_vector members beat_ and interpolator_ changed to non-ptr
00016 //   2004/09/10 Peter Vanroose - Added explicit copy constructor (ref_count !)
00017 //   2004/09/17 Peter Vanroose - made beat() and interpolators() non-virtual: they just return a member and should not be overloaded
00018 // \endverbatim
00019 
00020 #include <vcsl/vcsl_spatial_transformation_sptr.h>
00021 
00022 #include <vbl/vbl_ref_count.h>
00023 #include <vcl_vector.h>
00024 #include <vnl/vnl_vector.h>
00025 #include <vnl/vnl_quaternion.h>
00026 
00027 typedef vcl_vector<double> list_of_scalars;
00028 typedef vcl_vector<vnl_vector<double> > list_of_vectors;
00029 
00030 enum vcsl_interpolator
00031 {
00032   vcsl_linear,
00033   vcsl_cubic,
00034   vcsl_spline
00035 };
00036 
00037 //: Transformation between 2 spatial coordinate systems
00038 // A spatial transformation can be static or dynamic
00039 class vcsl_spatial_transformation : public vbl_ref_count
00040 {
00041   //***************************************************************************
00042   // Constructors/Destructor
00043   //***************************************************************************
00044 
00045  protected:
00046   // Default constructor. Do nothing
00047   vcsl_spatial_transformation() {}
00048 
00049  public:
00050   // Copy constructor
00051   vcsl_spatial_transformation(vcsl_spatial_transformation const& x)
00052     : vbl_ref_count(), beat_(x.beat_), interpolator_(x.interpolator_) {}
00053 
00054   // Destructor. Do nothing
00055   virtual ~vcsl_spatial_transformation() {}
00056 
00057   //***************************************************************************
00058   // Status report
00059   //***************************************************************************
00060 
00061   //: Return the list of time clocks
00062   vcl_vector<double> beat() const { return beat_; }
00063 
00064   //: Return the time duration
00065   unsigned int duration() const { return (unsigned int)(beat_.size()); }
00066 
00067   //: Return the list of interpolators
00068   vcl_vector<vcsl_interpolator> interpolators() const { return interpolator_; }
00069 
00070   //: Is `time' between the two time bounds ?
00071   bool valid_time(double time) const;
00072 
00073   //: Is `this' invertible at time `time'?
00074   //  REQUIRE: valid_time(time)
00075   virtual bool is_invertible(double time) const=0;
00076 
00077   //: Is `this' correctly set ?
00078   virtual bool is_valid() const
00079   { return (duration()==0&&interpolator_.size()==0) ||
00080            (duration()==interpolator_.size()+1); }
00081 
00082   //***************************************************************************
00083   // Basic operations
00084   //***************************************************************************
00085 
00086   //: Return the index of the beat inferior or equal to `time'
00087   //  REQUIRE: valid_time(time)
00088   int matching_interval(double time) const;
00089 
00090   //: Image of `v' by `this'
00091   //  REQUIRE: is_valid()
00092   virtual vnl_vector<double> execute(const vnl_vector<double> &v,
00093                                      double time) const=0;
00094 
00095   //: Image of `v' by the inverse of `this'
00096   //  REQUIRE: is_invertible(time)
00097   //  REQUIRE: is_valid()
00098   virtual vnl_vector<double> inverse(const vnl_vector<double> &v,
00099                                      double time) const=0;
00100 
00101   //***************************************************************************
00102   // Status setting
00103   //***************************************************************************
00104 
00105   //: Set the list of time clocks
00106   void set_beat(vcl_vector<double> const& new_beat) { beat_=new_beat; }
00107 
00108   //: Set the list of interpolators
00109   void set_interpolators(vcl_vector<vcsl_interpolator> const& i) { interpolator_=i; }
00110 
00111   //: Empty the time clock and interpolators, thereby making the transf static
00112   void set_static();
00113 
00114   //***************************************************************************
00115   // Interpolators
00116   //***************************************************************************
00117 
00118   //: Linear interpolation on scalar values
00119   double lsi(double v0,
00120              double v1,
00121              int index,
00122              double time) const;
00123 
00124   //: Linear interpolation on vnl_vectors
00125   vnl_vector<double> lvi(const vnl_vector<double> &v0,
00126                          const vnl_vector<double> &v1,
00127                          int index,
00128                          double time) const;
00129 
00130   //: Linear interpolation on vnl_matrices
00131   vnl_matrix<double> lmi(const vnl_matrix<double> &m0,
00132                          const vnl_matrix<double> &m1,
00133                          int index,
00134                          double time) const;
00135 
00136   //: Linear interpolation on quaternions
00137   vnl_quaternion<double> lqi(const vnl_quaternion<double> &v0,
00138                              const vnl_quaternion<double> &v1,
00139                              int index,
00140                              double time) const;
00141 
00142  protected:
00143   //: List of time clocks
00144   vcl_vector<double> beat_;
00145   vcl_vector<vcsl_interpolator> interpolator_;
00146 };
00147 
00148 #endif // vcsl_spatial_transformation_h_