vgl_homg_operators_1d.h
Go to the documentation of this file.
1 // This is core/vgl/algo/vgl_homg_operators_1d.h
2 #ifndef vgl_homg_operators_1d_h_
3 #define vgl_homg_operators_1d_h_
4 //:
5 // \file
6 // \brief 1D homogeneous functions
7 // \author Peter Vanroose, ESAT/PSI
8 // \date Nov. 1998
9 //
10 // vgl_homg_operators_1d implements one-dimensional homogeneous functions.
11 //
12 // \verbatim
13 // Modifications
14 // 3-Feb-07 Peter Vanroose - added get_vector()
15 // \endverbatim
16 //-----------------------------------------------------------------------------
17 
18 #include <vgl/vgl_homg_point_1d.h>
19 #include <vnl/vnl_fwd.h>
20 
21 //: 1D homogeneous functions
22 template <class T>
24 {
25  public:
26  //: get a vnl_vector_fixed representation of a homogeneous object
27  static vnl_vector_fixed<T,2> get_vector(vgl_homg_point_1d<T> const& p);
28 
29  //: cross ratio of four 1D points
30  // This number is projectively invariant, and it is the coordinate of p4
31  // in the reference frame where p2 is the origin (coordinate 0), p3 is
32  // the unity (coordinate 1) and p1 is the point at infinity.
33  // This cross ratio is often denoted as ((p1, p2; p3, p4)) (which also
34  // equals ((p3, p4; p1, p2)) or ((p2, p1; p4, p3)) or ((p4, p3; p2, p1)) )
35  // and is calculated as
36  // \verbatim
37  // p1 - p3 p2 - p3 (p1-p3)(p2-p4)
38  // ------- : -------- = --------------
39  // p1 - p4 p2 - p4 (p1-p4)(p2-p3)
40  // \endverbatim
41  // where pi are nonhomogeneous coordinates for the four points.
42  //
43  static double cross_ratio(const vgl_homg_point_1d<T>& a, const vgl_homg_point_1d<T>& b,
44  const vgl_homg_point_1d<T>& c, const vgl_homg_point_1d<T>& d);
45 
46  //: Calculate the projective conjugate point of three given points.
47  // Or more generally, the point with a given crossratio w.r.t. three other points:
48  // The cross ratio ((x1,x2;x3,answer)) is cr (default -1). When cr is -1,
49  // the returned value and x3 are conjugate points w.r.t. the pair (x1,x2).
50  // Because this function is transitive on coordinates, it is sufficient to
51  // implement it for 1-dimensional points, i.e., for scalars.
52  static T conjugate(T x1, T x2, T x3, double cr = -1);
53 
54  //: Calculate the projective conjugate point of three given points.
55  // Or more generally, the point with a given crossratio w.r.t. three other points:
56  // The cross ratio ((x1,x2;x3,answer)) is cr (default -1). When cr is -1,
57  // the returned value and x3 are conjugate points w.r.t. the pair (x1,x2).
59  const vgl_homg_point_1d<T>& b,
60  const vgl_homg_point_1d<T>& c,
61  double cr = -1);
62 
63  //: Dot product of two homogeneous points
64  static T dot(const vgl_homg_point_1d<T>& a, const vgl_homg_point_1d<T>& b);
65 
66  //: Cross product of two homogeneous points
67  static T cross(const vgl_homg_point_1d<T>& a, const vgl_homg_point_1d<T>& b);
68 
69  //: Normalize vgl_homg_point_1d<T> to unit magnitude
70  static void unitize(vgl_homg_point_1d<T>& a);
71 
72  //: Get the distance between the two points.
73  static T distance(const vgl_homg_point_1d<T>& point1, const vgl_homg_point_1d<T>& point2);
74 
75  //: Get the square of the distance between the two points.
76  static T distance_squared(const vgl_homg_point_1d<T>& point1, const vgl_homg_point_1d<T>& point2);
77 
78  //: True if the points are closer than Euclidean distance d.
79  static bool is_within_distance(const vgl_homg_point_1d<T>& p1, const vgl_homg_point_1d<T>& p2, T d)
80  {
81  return distance(p1, p2) < d;
82  }
83 
84  //: Return the midpoint of two homogeneous points
86 };
87 
88 //: Transform a point through a 2x2 projective transformation matrix
89 // \relatesalso vgl_homg_point_1d
90 template <class T>
91 vgl_homg_point_1d<T> operator*(vnl_matrix_fixed<T,2,2> const& m,
92  vgl_homg_point_1d<T> const& p);
93 
94 #define VGL_HOMG_OPERATORS_1D_INSTANTIATE(T) \
95  "Please #include <vgl/algo/vgl_homg_operators_1d.hxx>"
96 
97 #endif // vgl_homg_operators_1d_h_
static void unitize(vgl_homg_point_1d< T > &a)
Normalize vgl_homg_point_1d<T> to unit magnitude.
static T cross(const vgl_homg_point_1d< T > &a, const vgl_homg_point_1d< T > &b)
Cross product of two homogeneous points.
static T conjugate(T x1, T x2, T x3, double cr=-1)
Calculate the projective conjugate point of three given points.
static double cross_ratio(const vgl_homg_point_1d< T > &a, const vgl_homg_point_1d< T > &b, const vgl_homg_point_1d< T > &c, const vgl_homg_point_1d< T > &d)
cross ratio of four 1D points.
static bool is_within_distance(const vgl_homg_point_1d< T > &p1, const vgl_homg_point_1d< T > &p2, T d)
True if the points are closer than Euclidean distance d.
a point in homogeneous 1-D space, i.e., a homogeneous pair (x,w)
static vnl_vector_fixed< T, 2 > get_vector(vgl_homg_point_1d< T > const &p)
get a vnl_vector_fixed representation of a homogeneous object.
static T dot(const vgl_homg_point_1d< T > &a, const vgl_homg_point_1d< T > &b)
Dot product of two homogeneous points.
static T distance_squared(const vgl_homg_point_1d< T > &point1, const vgl_homg_point_1d< T > &point2)
Get the square of the distance between the two points.
1D homogeneous functions.
Definition: vgl_algo_fwd.h:27
vgl_homg_point_1d< T > operator *(vnl_matrix_fixed< T, 2, 2 > const &m, vgl_homg_point_1d< T > const &p)
Transform a point through a 2x2 projective transformation matrix.
Represents a homogeneous 1-D point, i.e., a homogeneous pair (x,w).
Definition: vgl_fwd.h:7
static T distance(const vgl_homg_point_1d< T > &point1, const vgl_homg_point_1d< T > &point2)
Get the distance between the two points.
static vgl_homg_point_1d< T > midpoint(const vgl_homg_point_1d< T > &p1, const vgl_homg_point_1d< T > &p2)
Return the midpoint of two homogeneous points.