core/vgl/algo/vgl_homg_operators_1d.h
Go to the documentation of this file.
00001 // This is core/vgl/algo/vgl_homg_operators_1d.h
00002 #ifndef vgl_homg_operators_1d_h_
00003 #define vgl_homg_operators_1d_h_
00004 //:
00005 // \file
00006 // \brief  1D homogeneous functions
00007 // \author Peter Vanroose, ESAT/PSI
00008 // \date   Nov. 1998
00009 //
00010 // vgl_homg_operators_1d implements one-dimensional homogeneous functions.
00011 //
00012 // \verbatim
00013 // Modifications
00014 //    3-Feb-07 Peter Vanroose - added get_vector()
00015 // \endverbatim
00016 //-----------------------------------------------------------------------------
00017 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00018 #pragma interface
00019 #endif
00020 
00021 #include <vgl/vgl_homg_point_1d.h>
00022 #include <vnl/vnl_fwd.h>
00023 
00024 //: 1D homogeneous functions
00025 template <class T>
00026 class vgl_homg_operators_1d
00027 {
00028  public:
00029   //: get a vnl_vector_fixed representation of a homogeneous object
00030   static vnl_vector_fixed<T,2> get_vector(vgl_homg_point_1d<T> const& p);
00031 
00032   //: cross ratio of four 1D points
00033   // This number is projectively invariant, and it is the coordinate of p4
00034   // in the reference frame where p2 is the origin (coordinate 0), p3 is
00035   // the unity (coordinate 1) and p1 is the point at infinity.
00036   // This cross ratio is often denoted as ((p1, p2; p3, p4)) (which also
00037   // equals ((p3, p4; p1, p2)) or ((p2, p1; p4, p3)) or ((p4, p3; p2, p1)) )
00038   // and is calculated as
00039   //  \verbatim
00040   //                      p1 - p3   p2 - p3      (p1-p3)(p2-p4)
00041   //                      ------- : --------  =  --------------
00042   //                      p1 - p4   p2 - p4      (p1-p4)(p2-p3)
00043   // \endverbatim
00044   // where pi are nonhomogeneous coordinates for the four points.
00045   //
00046   static double cross_ratio(const vgl_homg_point_1d<T>& a, const vgl_homg_point_1d<T>& b,
00047                             const vgl_homg_point_1d<T>& c, const vgl_homg_point_1d<T>& d);
00048 
00049   //: Calculate the projective conjugate point of three given points.
00050   // Or more generally, the point with a given crossratio w.r.t. three other points:
00051   // The cross ratio ((x1,x2;x3,answer)) is cr (default -1). When cr is -1,
00052   // the returned value and x3 are conjugate points w.r.t. the pair (x1,x2).
00053   // Because this function is transitive on coordinates, it is sufficient to
00054   // implement it for 1-dimensional points, i.e., for scalars.
00055   static T conjugate(T x1, T x2, T x3, double cr = -1);
00056 
00057   //: Calculate the projective conjugate point of three given points.
00058   // Or more generally, the point with a given crossratio w.r.t. three other points:
00059   // The cross ratio ((x1,x2;x3,answer)) is cr (default -1). When cr is -1,
00060   // the returned value and x3 are conjugate points w.r.t. the pair (x1,x2).
00061   static vgl_homg_point_1d<T> conjugate(const vgl_homg_point_1d<T>& a,
00062                                         const vgl_homg_point_1d<T>& b,
00063                                         const vgl_homg_point_1d<T>& c,
00064                                         double cr = -1);
00065 
00066   //: Dot product of two homogeneous points
00067   static T dot(const vgl_homg_point_1d<T>& a, const vgl_homg_point_1d<T>& b);
00068 
00069   //: Cross product of two homogeneous points
00070   static T cross(const vgl_homg_point_1d<T>& a, const vgl_homg_point_1d<T>& b);
00071 
00072   //: Normalize vgl_homg_point_1d<T> to unit magnitude
00073   static void unitize(vgl_homg_point_1d<T>& a);
00074 
00075   //: Get the distance between the two points.
00076   static T distance(const vgl_homg_point_1d<T>& point1, const vgl_homg_point_1d<T>& point2);
00077 
00078   //: Get the square of the distance between the two points.
00079   static T distance_squared(const vgl_homg_point_1d<T>& point1, const vgl_homg_point_1d<T>& point2);
00080 
00081   //: True if the points are closer than Euclidean distance d.
00082   static bool is_within_distance(const vgl_homg_point_1d<T>& p1, const vgl_homg_point_1d<T>& p2, T d)
00083   {
00084     return distance(p1, p2) < d;
00085   }
00086 
00087   //: Return the midpoint of two homogeneous points
00088   static vgl_homg_point_1d<T> midpoint(const vgl_homg_point_1d<T>& p1, const vgl_homg_point_1d<T>& p2);
00089 };
00090 
00091 //: Transform a point through a 2x2 projective transformation matrix
00092 // \relatesalso vgl_homg_point_1d
00093 template <class T>
00094 vgl_homg_point_1d<T> operator*(vnl_matrix_fixed<T,2,2> const& m,
00095                                vgl_homg_point_1d<T> const& p);
00096 
00097 #define VGL_HOMG_OPERATORS_1D_INSTANTIATE(T) \
00098         "Please #include <vgl/algo/vgl_homg_operators_1d.txx>"
00099 
00100 #endif // vgl_homg_operators_1d_h_