1 // This is oxl/mvl/HomgOperator2D.h
2 #ifndef HomgOperator2D_h_
3 #define HomgOperator2D_h_
4 //:
5 // \file
6 // \brief useful operators for the 2D homogeneous primitive classes
7 //
8 // \verbatim
9 // Modifications
10 //   221198 - Peter Vanroose - Added CrossRatio() and Conjugate()
11 // \endverbatim
12 
13 #include <iostream>
14 #include <vector>
15 #ifdef _MSC_VER
16 #  include <vcl_msvc_warnings.h>
17 #endif
18 class Homg2D;
19 class HomgLine2D;
20 class HomgPoint2D;
21 class HomgLineSeg2D;
22 
23 class HomgOperator2D
24 {
25  public:
26   static double dot(const Homg2D& a, const Homg2D& b);
27   static void cross(const Homg2D& a, const Homg2D& b, Homg2D* a_cross_b);
28   static void unitize(Homg2D* a);
29 
30   static double angle_between_oriented_lines (const HomgLine2D& line1, const HomgLine2D& line2);
31   static double abs_angle (const HomgLine2D& line1, const HomgLine2D& line2);
32 
33   static double distance_squared (const HomgPoint2D& point1, const HomgPoint2D& point2);
34   static double distance_squared (const HomgLineSeg2D& lineseg, const HomgLine2D& line);
35   static double distance_squared (const HomgLineSeg2D& lineseg, const HomgPoint2D& line);
36   static double distance (const HomgLineSeg2D& lineseg1, const HomgLineSeg2D& lineseg2, double OVERLAP_THRESH);
37 
38   static double perp_dist_squared (const HomgPoint2D& point, const HomgLine2D& line);
is_within_distance(const HomgPoint2D & p1,const HomgPoint2D & p2,double d)39   static bool is_within_distance(const HomgPoint2D& p1, const HomgPoint2D& p2, double d) {
40     return distance_squared(p1, p2) < d*d;
41   }
42 
43   static double line_angle (const HomgLine2D& line);
44 
45   static HomgLine2D join (const HomgPoint2D& point1, const HomgPoint2D& point2);
46   static HomgLine2D join_oriented (const HomgPoint2D& point1, const HomgPoint2D& point2);
47   static HomgPoint2D intersection (const HomgLine2D& line1, const HomgLine2D& line2);
48   static HomgLine2D perp_line_through_point (const HomgLine2D& line, const HomgPoint2D& point);
49 
50   static HomgPoint2D perp_projection (const HomgLine2D& line, const HomgPoint2D& point);
51   static HomgPoint2D midpoint (const HomgPoint2D& p1, const HomgPoint2D& p2);
52 
53   // Clip to lineseg. The infinite line is clipped against the viewport with
54   // lower left corner (x0,y0) and upper right corner (x1,y1)
55   static HomgLineSeg2D clip_line_to_lineseg (const HomgLine2D& line,
56                                              double x0, double y0,
57                                              double x1, double y1);
58 
59   // "Intersect" a set of lines
60   static HomgPoint2D lines_to_point(const std::vector<HomgLine2D>&);
61 
62   // cross ratio of four collinear points, or four concurrent lines
63   static double CrossRatio(const Homg2D& p1, const Homg2D& p2,
64                            const Homg2D& p3, const Homg2D& p4);
65   static Homg2D Conjugate(const Homg2D& a, const Homg2D& b, const Homg2D& c,
66                           double cr);
67 };
68 
69 #endif // HomgOperator2D_h_
70