contrib/oxl/mvl/Homg2D.h
Go to the documentation of this file.
00001 // This is oxl/mvl/Homg2D.h
00002 #ifndef _Homg2D_h
00003 #define _Homg2D_h
00004 //:
00005 // \file
00006 // \brief Base class for 2D homogeneous features
00007 //
00008 // Base class for 2D homogeneous features.  This provides get/set.
00009 //
00010 // \author
00011 //   Paul Beardsley, 29.03.96
00012 //   Oxford University, UK
00013 //
00014 // \verbatim
00015 //  Modifications
00016 //   210297 AWF Switched to fixed-length vectors for speed.
00017 //   110397 Peter Vanroose - added operator==
00018 //   100904 Peter Vanroose - Inlined all 1-line methods in class decl
00019 // \endverbatim
00020 //
00021 //-----------------------------------------------------------------------------
00022 
00023 #include <mvl/Homg.h>
00024 #include <vnl/vnl_double_3.h>
00025 #include <vcl_cassert.h>
00026 
00027 class Homg2D : public vnl_double_3, public Homg
00028 {
00029  public:
00030 
00031   // Constructors/Initializers/Destructors-----------------------------------
00032 
00033   //: Default constructor
00034   Homg2D() {}
00035 
00036   //: Copy constructor
00037   Homg2D(const Homg2D& that) : vnl_double_3(that) {}
00038 
00039   //: Construct a Homg2D from three doubles.
00040   Homg2D(double px, double py, double pw) { set(px,py,pw); }
00041 
00042   //: Construct from 3-vector.
00043   Homg2D (const vnl_vector<double>& v) { set(v); }
00044 
00045   //: Construct from 3-vector.
00046   Homg2D (const vnl_vector_fixed<double,3>& v) { set(v[0], v[1], v[2]); }
00047 
00048   //: Destructor
00049  ~Homg2D() {}
00050 
00051   //: Assignment
00052   Homg2D& operator=(const Homg2D& that) {
00053     vnl_double_3::operator=(that);
00054     return *this;
00055   }
00056 
00057   // Data Access-------------------------------------------------------------
00058 
00059   vnl_double_3 get_vector() const { return vnl_double_3(x(),y(),w()); }
00060   vnl_double_3& asVector() { return *this; }
00061 
00062   //: Retrieve components.  Do not attempt to write into null pointers.
00063   void get(double *x_ptr, double *y_ptr, double *w_ptr) const
00064   {
00065     if (x_ptr) *x_ptr = (*this)[0];
00066     if (y_ptr) *y_ptr = (*this)[1];
00067     if (w_ptr) *w_ptr = (*this)[2];
00068   }
00069 
00070 // @{ ACCESS TO COMPONENTS: @}
00071 
00072   //: Return x
00073   inline double x() const { return (*this)[0]; }
00074   //: Return reference to x
00075   inline double& x() { return (*this)[0]; }
00076 
00077   //: Return y
00078   inline double y() const { return (*this)[1]; }
00079   //: Return reference to y
00080   inline double& y() { return (*this)[1]; }
00081 
00082   //: Return w
00083   inline double w() const { return (*this)[2]; }
00084   //: Return reference to w
00085   inline double& w() { return (*this)[2]; }
00086 
00087  private:
00088   //: deprecated
00089   double get_x() const { return (*this)[0]; }
00090   //: deprecated
00091   double get_y() const { return (*this)[1]; }
00092   //: deprecated
00093   double get_w() const { return (*this)[2]; }
00094  public:
00095 
00096   //: Set x,y,w.
00097   void set(double px, double py, double pw)
00098   {
00099     (*this)[0] = px;
00100     (*this)[1] = py;
00101     (*this)[2] = pw;
00102   }
00103 
00104   //: Set from vector
00105   void set(const vnl_vector_fixed<double,3>& v) { set(v[0],v[1],v[2]); }
00106 
00107   //: Set from vector
00108   void set(const vnl_vector<double>& v) { set(v[0],v[1],v[2]); }
00109 
00110   //: Set element.
00111   void set(unsigned int index, double v) {assert(index<=2); (*this)[index]=v;}
00112 };
00113 
00114 #endif // _Homg2D_h