contrib/oxl/mvl/HomgLine2D.h
Go to the documentation of this file.
00001 // This is oxl/mvl/HomgLine2D.h
00002 #ifndef HomgLine2D_h_
00003 #define HomgLine2D_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 
00008 //--------------------------------------------------------------
00009 //:
00010 // \file
00011 // \brief Homogeneous 3-vector for a 2D line
00012 //
00013 // A class to hold a homogeneous 3-vector for a 2D line.
00014 //
00015 // \verbatim
00016 //  Modifications:
00017 //   Peter Vanroose - 11 Mar 97 - added operator==
00018 // \endverbatim
00019 
00020 #include <vcl_iosfwd.h>
00021 #include <mvl/Homg2D.h>
00022 
00023 class HomgLineSeg2D;
00024 class HomgPoint2D;
00025 
00026 class HomgLine2D : public Homg2D
00027 {
00028  public:
00029 
00030   HomgLine2D () {}
00031   HomgLine2D (const HomgLine2D& that): Homg2D(that) {}
00032   HomgLine2D (double px, double py, double pw): Homg2D (px, py, pw) {}
00033   explicit HomgLine2D (const vnl_double_3& vector_ptr): Homg2D (vector_ptr) {}
00034  ~HomgLine2D () {}
00035 
00036   HomgLine2D& operator=(const HomgLine2D& that)
00037   {
00038     Homg2D::operator=(that);
00039     return *this;
00040   }
00041 
00042   //: Return true iff the line is the line at infinity.
00043   //  If tol == 0, x() and y() must be exactly 0.
00044   //  Otherwise, tol is used as tolerance value (default: 1e-12),
00045   //  and $max(|x|,|y|) <= \mbox{tol} \times |w|$ is checked.
00046   inline bool ideal(double tol = 1e-12) const {
00047 #define mvl_abs(x) ((x)<0?-(x):(x))
00048     return mvl_abs(x()) <= tol*mvl_abs(w()) && mvl_abs(y()) <= tol*mvl_abs(w());
00049 #undef mvl_abs
00050   }
00051 
00052   // Clip the infinite line to the given bounding box and return
00053   HomgLineSeg2D clip(int x0, int y0, int x1, int y1) const;
00054 
00055   // Return 2 points on the line.
00056   void get_2_points_on_line(HomgPoint2D* p1, HomgPoint2D* p2) const;
00057 };
00058 
00059 vcl_ostream& operator<<(vcl_ostream& s, const HomgLine2D& );
00060 
00061 #endif // HomgLine2D_h_