contrib/oxl/mvl/Homg3D.h
Go to the documentation of this file.
00001 // This is oxl/mvl/Homg3D.h
00002 #ifndef Homg3D_h_
00003 #define Homg3D_h_
00004 //:
00005 // \file
00006 // \brief Base class for 3D homogeneous features
00007 //
00008 // Base class for 3D homogeneous features.
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 #include <mvl/Homg.h>
00023 #include <vnl/vnl_double_4.h>
00024 #include <vnl/vnl_vector.h>
00025 #include <vcl_cassert.h>
00026 
00027 class Homg3D : public Homg
00028 {
00029  public:
00030 
00031   // Constructors/Initializers/Destructors-------------------------------------
00032 
00033   Homg3D() {}
00034   Homg3D(const Homg3D& that):homg_vector_(that.homg_vector_) {}
00035   Homg3D(double px, double py, double pz, double pw = 1): homg_vector_(px,py,pz,pw) {}
00036   Homg3D(const vnl_vector<double>& v): homg_vector_(v) { }
00037   Homg3D(const vnl_vector_fixed<double,4>& v): homg_vector_(v) { }
00038  ~Homg3D() {}
00039 
00040   Homg3D& operator=(const Homg3D& that) { homg_vector_ = that.homg_vector_; return *this; }
00041   // default ok. nope, egcs chokes
00042 
00043   // Data Access---------------------------------------------------------------
00044 
00045   vnl_double_4 get_vector() const { return vnl_double_4(x(),y(),z(),w()); }
00046   vnl_double_4& asVector() { return homg_vector_; }
00047 
00048   // get x,y,z,w.  Do not try to fill null pointers.
00049   void get(double *x_ptr, double *y_ptr, double *z_ptr, double *w_ptr) const
00050   {
00051     if (x_ptr) *x_ptr = x();
00052     if (x_ptr) *y_ptr = y();
00053     if (x_ptr) *z_ptr = z();
00054     if (x_ptr) *w_ptr = w();
00055   }
00056 
00057   //: Get x.
00058   inline double x() const { return homg_vector_[0]; }
00059 
00060   //: Get y.
00061   inline double y() const { return homg_vector_[1]; }
00062 
00063   //: Get z.
00064   inline double z() const { return homg_vector_[2]; }
00065 
00066   //: Get w.
00067   inline double w() const { return homg_vector_[3]; }
00068 
00069  private:
00070   //: deprecated
00071   double get_x() const { return homg_vector_[0]; }
00072   //: deprecated
00073   double get_y() const { return homg_vector_[1]; }
00074   //: deprecated
00075   double get_z() const { return homg_vector_[2]; }
00076   //: deprecated
00077   double get_w() const { return homg_vector_[3]; }
00078  public:
00079 
00080   //: Set x,y,z,w.
00081   void set(double px, double py, double pz, double pw = 1) {
00082     homg_vector_[0] = px;
00083     homg_vector_[1] = py;
00084     homg_vector_[2] = pz;
00085     homg_vector_[3] = pw;
00086   }
00087 
00088   //: Set from vector
00089   void set(const vnl_vector_fixed<double,4>& v) { set(v[0],v[1],v[2],v[3]); }
00090 
00091   //: Set from vector
00092   void set(const vnl_vector<double>& v) { set(v[0],v[1],v[2],v[3]); }
00093 
00094   //: Set element.
00095   void set(unsigned int idx, double v) { assert(idx<=3); homg_vector_[idx]=v; }
00096 
00097   // Utility Methods-----------------------------------------------------------
00098   bool operator==(Homg3D const& p) const { return homg_vector_ == p.get_vector(); }
00099 
00100   // INTERNALS-----------------------------------------------------------------
00101  protected:
00102   // Data Members--------------------------------------------------------------
00103   vnl_double_4 homg_vector_;
00104 };
00105 
00106 #endif // Homg3D_h_