core/vcsl/vcsl_rotation.h
Go to the documentation of this file.
00001 // This is core/vcsl/vcsl_rotation.h
00002 #ifndef vcsl_rotation_h_
00003 #define vcsl_rotation_h_
00004 //:
00005 // \file
00006 // \brief Rotation transformation (either 2D or 3D)
00007 // \author François BERTEL
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 - return type of quaternion(), execute() and inverse() changed to non-ptr
00014 //   2002/01/28 Peter Vanroose - vcl_vector members angle_ and axis_ changed to non-ptr
00015 //   2004/09/17 Peter Vanroose - made angle() non-virtual - it just returns a member and should not be overloaded
00016 // \endverbatim
00017 
00018 #include <vcsl/vcsl_spatial_transformation.h>
00019 #include <vcsl/vcsl_rotation_sptr.h>
00020 #include <vnl/vnl_quaternion.h>
00021 
00022 //: Rotation transformation (either 2D or 3D).
00023 // A rotation rotates a point around an axis passing through the origin.
00024 // For a more general rotation (affine rotation or displacement), see
00025 // the derived class \b vcsl_displacement
00026 class vcsl_rotation
00027   : public vcsl_spatial_transformation
00028 {
00029  public:
00030   //***************************************************************************
00031   // Constructors/Destructor
00032   //***************************************************************************
00033 
00034   //: Default constructor. Sets 3D rotation mode
00035   vcsl_rotation() : mode_2d_(false) {}
00036 
00037   // Destructor
00038   virtual ~vcsl_rotation() {}
00039 
00040   //***************************************************************************
00041   // Status report
00042   //***************************************************************************
00043 
00044   //: Is `this' invertible at time `time'?
00045   //  REQUIRE: valid_time(time)
00046   // Pure virtual function of vcsl_spatial_transformation
00047   virtual bool is_invertible(double /*time*/) const { return true; }
00048 
00049   //: Is `this' correctly set ?
00050   // Virtual function of vcsl_spatial_transformation
00051   virtual bool is_valid() const
00052   { return vcsl_spatial_transformation::is_valid() &&
00053           this->duration()==axis_.size() &&
00054           this->duration()==angle_.size(); }
00055 
00056   //: Are `new_vector' a list of unit vectors ?
00057   bool are_unit_axes(list_of_vectors const& new_axis) const;
00058 
00059   //: Is `this' a 2D rotation ?
00060   bool is_2d() const { return mode_2d_; }
00061 
00062   //: Is `this' a 3D rotation ?
00063   bool is_3d() const { return !mode_2d_; }
00064 
00065   //***************************************************************************
00066   // Status setting
00067   //***************************************************************************
00068 
00069   //: Set `this' as a 2D rotation
00070   void set_2d() { mode_2d_=true; }
00071 
00072   //: Set `this' as a 3D rotation
00073   void set_3d() { mode_2d_=false; }
00074 
00075   //***************************************************************************
00076   // Transformation parameters
00077   //***************************************************************************
00078 
00079   //: Set the parameters of a static 2D rotation
00080   void set_static_2d(double new_angle);
00081 
00082   //: Set the parameters of a static rotation
00083   void set_static(double new_angle, vnl_vector<double> const& new_axis);
00084 
00085   //: Set the angle variation along the time in radians
00086   void set_angle(list_of_scalars const& new_angle) { angle_=new_angle; }
00087 
00088   //: Return the angle variation along the time in radians
00089   list_of_scalars angle() const { return angle_; }
00090 
00091   //: Set the direction vector variation along the time
00092   //  REQUIRE: are_unit_vectors(new_vector)
00093   void set_axis(list_of_vectors const& new_axis);
00094 
00095   //: Return the direction variation along the time
00096   list_of_vectors axis() const { return axis_; }
00097 
00098   //***************************************************************************
00099   // Basic operations
00100   //***************************************************************************
00101 
00102   //: Image of `v' by `this'
00103   //  REQUIRE: is_valid()
00104   //  REQUIRE: (is_2d()&&v.size()==2)||(is_3d()&&v.size()==3)
00105   // Pure virtual function of vcsl_spatial_transformation
00106   virtual vnl_vector<double> execute(const vnl_vector<double> &v,
00107                                      double time) const;
00108 
00109   //: Image of `v' by the inverse of `this'
00110   //  REQUIRE: is_valid()
00111   //  REQUIRE: is_invertible(time)
00112   //  REQUIRE (is_2d()&&v.size()==2)||(is_3d()&&v.size()==3)
00113   // Pure virtual function of vcsl_spatial_transformation
00114   virtual vnl_vector<double> inverse(const vnl_vector<double> &v,
00115                                      double time) const;
00116 
00117  protected:
00118   //: Compute the value of the quaternion at time `time'
00119   vnl_quaternion<double> quaternion(double time) const;
00120 
00121   //: False if `this' is a 3D rotation, true if `this' is a 2D rotation
00122   bool mode_2d_;
00123 
00124   //: Angle variation along the time in radians
00125   list_of_scalars angle_;
00126 
00127   //: Direction vector variation along the time
00128   list_of_vectors axis_;
00129 };
00130 
00131 #endif // vcsl_rotation_h_