1 // This is oxl/mvl/HomgPoint2D.h 2 #ifndef HomgPoint2D_h_ 3 #define HomgPoint2D_h_ 4 //: 5 // \file 6 // \brief Homogeneous 3-vector for a 2D point 7 // 8 // A class to hold a homogeneous 3-vector for a 2D point. 9 // 10 // \verbatim 11 // Modifications: 12 // Peter Vanroose - 11 Mar 97 - added operator== 13 // \endverbatim 14 // 15 16 #include <iostream> 17 #include <iosfwd> 18 #ifdef _MSC_VER 19 # include <vcl_msvc_warnings.h> 20 #endif 21 #include <vnl/vnl_double_2.h> 22 #include <vnl/vnl_double_3.h> 23 #include <mvl/Homg2D.h> 24 25 class HomgPoint2D : public Homg2D 26 { 27 public: 28 // Constructors/Initializers/Destructors----------------------------------- 29 30 HomgPoint2D () = default; 31 HomgPoint2D (const HomgPoint2D& that) = default; Homg2D(px,py,pw)32 HomgPoint2D (double px, double py, double pw = 1.0): Homg2D(px,py,pw) {} HomgPoint2D(const vnl_double_3 & vector_ptr)33 HomgPoint2D (const vnl_double_3& vector_ptr): Homg2D(vector_ptr) {} 34 35 HomgPoint2D& operator=(const HomgPoint2D& that) = default; 36 37 // Operations------------------------------------------------------------ 38 39 //: Return true iff the point is the point at infinity. 40 // If tol == 0, w() must be exactly 0. 41 // Otherwise, tol is used as tolerance value (default: 1e-12), 42 // and $|w| <= \mbox{tol} \times min(|x|,|y|)$ is checked. 43 inline bool ideal(double tol = 1e-12) const { 44 #define mvl_abs(x) ((x)<0?-(x):(x)) 45 return mvl_abs(w()) <= tol*mvl_abs(x()) && mvl_abs(w()) <= tol*mvl_abs(y()); 46 #undef mvl_abs 47 } 48 49 bool get_nonhomogeneous(double& px, double& py) const; 50 vnl_double_2 get_double2() const; get_nonhomogeneous()51 inline vnl_double_2 get_nonhomogeneous() const { return get_double2(); } 52 53 bool rescale_w(double new_w = 1.0); 54 HomgPoint2D get_unitized() const; 55 56 // Utility Methods--------------------------------------------------------- 57 static HomgPoint2D read(std::istream&, bool is_homogeneous = false); 58 }; 59 60 std::istream& operator>>(std::istream& is, HomgPoint2D& p); 61 std::ostream& operator<<(std::ostream& s, const HomgPoint2D& ); 62 63 #endif // HomgPoint2D_h_ 64