contrib/oxl/mvl/HomgPoint2D.h
Go to the documentation of this file.
00001 // This is oxl/mvl/HomgPoint2D.h
00002 #ifndef HomgPoint2D_h_
00003 #define HomgPoint2D_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Homogeneous 3-vector for a 2D point
00010 //
00011 // A class to hold a homogeneous 3-vector for a 2D point.
00012 //
00013 // \verbatim
00014 //  Modifications:
00015 //   Peter Vanroose - 11 Mar 97 - added operator==
00016 // \endverbatim
00017 //
00018 
00019 #include <vcl_iosfwd.h>
00020 #include <vnl/vnl_double_2.h>
00021 #include <vnl/vnl_double_3.h>
00022 #include <mvl/Homg2D.h>
00023 
00024 class HomgPoint2D : public Homg2D
00025 {
00026  public:
00027   // Constructors/Initializers/Destructors-----------------------------------
00028 
00029   HomgPoint2D () {}
00030   HomgPoint2D (const HomgPoint2D& that): Homg2D(that) {}
00031   HomgPoint2D (double px, double py, double pw = 1.0): Homg2D(px,py,pw) {}
00032   HomgPoint2D (const vnl_double_3& vector_ptr): Homg2D(vector_ptr) {}
00033 
00034   HomgPoint2D& operator=(const HomgPoint2D& that)
00035   {
00036     Homg2D::operator=(that);
00037     return *this;
00038   }
00039 
00040   // Operations------------------------------------------------------------
00041 
00042   //: Return true iff the point is the point at infinity.
00043   //  If tol == 0, w() must be exactly 0.
00044   //  Otherwise, tol is used as tolerance value (default: 1e-12),
00045   //  and $|w| <= \mbox{tol} \times min(|x|,|y|)$ is checked.
00046   inline bool ideal(double tol = 1e-12) const {
00047 #define mvl_abs(x) ((x)<0?-(x):(x))
00048     return mvl_abs(w()) <= tol*mvl_abs(x()) && mvl_abs(w()) <= tol*mvl_abs(y());
00049 #undef mvl_abs
00050   }
00051 
00052   bool get_nonhomogeneous(double& px, double& py) const;
00053   vnl_double_2 get_double2() const;
00054   inline vnl_double_2 get_nonhomogeneous() const { return get_double2(); }
00055 
00056   bool rescale_w(double new_w = 1.0);
00057   HomgPoint2D get_unitized() const;
00058 
00059   // Utility Methods---------------------------------------------------------
00060   static HomgPoint2D read(vcl_istream&, bool is_homogeneous = false);
00061 };
00062 
00063 vcl_istream& operator>>(vcl_istream& is, HomgPoint2D& p);
00064 vcl_ostream& operator<<(vcl_ostream& s, const HomgPoint2D& );
00065 
00066 #endif // HomgPoint2D_h_