contrib/oxl/mvl/HomgOperator2D.h
Go to the documentation of this file.
00001 // This is oxl/mvl/HomgOperator2D.h
00002 #ifndef HomgOperator2D_h_
00003 #define HomgOperator2D_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief useful operators for the 2D homogeneous primitive classes
00010 //
00011 // \verbatim
00012 // Modifications
00013 //   221198 - Peter Vanroose - Added CrossRatio() and Conjugate()
00014 // \endverbatim
00015 
00016 #include <vcl_vector.h>
00017 class Homg2D;
00018 class HomgLine2D;
00019 class HomgPoint2D;
00020 class HomgLineSeg2D;
00021 
00022 class HomgOperator2D
00023 {
00024  public:
00025   static double dot(const Homg2D& a, const Homg2D& b);
00026   static void cross(const Homg2D& a, const Homg2D& b, Homg2D* a_cross_b);
00027   static void unitize(Homg2D* a);
00028 
00029   static double angle_between_oriented_lines (const HomgLine2D& line1, const HomgLine2D& line2);
00030   static double abs_angle (const HomgLine2D& line1, const HomgLine2D& line2);
00031 
00032   static double distance_squared (const HomgPoint2D& point1, const HomgPoint2D& point2);
00033   static double distance_squared (const HomgLineSeg2D& lineseg, const HomgLine2D& line);
00034   static double distance_squared (const HomgLineSeg2D& lineseg, const HomgPoint2D& line);
00035   static double distance (const HomgLineSeg2D& lineseg1, const HomgLineSeg2D& lineseg2, double OVERLAP_THRESH);
00036 
00037   static double perp_dist_squared (const HomgPoint2D& point, const HomgLine2D& line);
00038   static bool is_within_distance(const HomgPoint2D& p1, const HomgPoint2D& p2, double d) {
00039     return distance_squared(p1, p2) < d*d;
00040   }
00041 
00042   static double line_angle (const HomgLine2D& line);
00043 
00044   static HomgLine2D join (const HomgPoint2D& point1, const HomgPoint2D& point2);
00045   static HomgLine2D join_oriented (const HomgPoint2D& point1, const HomgPoint2D& point2);
00046   static HomgPoint2D intersection (const HomgLine2D& line1, const HomgLine2D& line2);
00047   static HomgLine2D perp_line_through_point (const HomgLine2D& line, const HomgPoint2D& point);
00048 
00049   static HomgPoint2D perp_projection (const HomgLine2D& line, const HomgPoint2D& point);
00050   static HomgPoint2D midpoint (const HomgPoint2D& p1, const HomgPoint2D& p2);
00051 
00052   // Clip to lineseg. The infinite line is clipped against the viewport with
00053   // lower left corner (x0,y0) and upper right corner (x1,y1)
00054   static HomgLineSeg2D clip_line_to_lineseg (const HomgLine2D& line,
00055                                              double x0, double y0,
00056                                              double x1, double y1);
00057 
00058   // "Intersect" a set of lines
00059   static HomgPoint2D lines_to_point(const vcl_vector<HomgLine2D>&);
00060 
00061   // cross ratio of four collinear points, or four concurrent lines
00062   static double CrossRatio(const Homg2D& p1, const Homg2D& p2,
00063                            const Homg2D& p3, const Homg2D& p4);
00064   static Homg2D Conjugate(const Homg2D& a, const Homg2D& b, const Homg2D& c,
00065                           double cr);
00066 };
00067 
00068 #endif // HomgOperator2D_h_