contrib/oxl/mvl/HomgMetric.h
Go to the documentation of this file.
00001 // This is oxl/mvl/HomgMetric.h
00002 #ifndef HomgMetric_h_
00003 #define HomgMetric_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Measurements on homogeneous coordinates
00010 //
00011 //    HomgMetric is a class that allows measurements to be made between
00012 //    homogeneous primitives.  If attached to an ImageMetric (q.v.), uses
00013 //    that, otherwise uses HomgOperator2D.
00014 //
00015 //    HomgMetric is an ImageMetric pointer, it behaves just like one, and
00016 //    {\em does not} have responsibility for memory management, no more
00017 //    than any other pointer.
00018 //
00019 // \author
00020 //     Andrew W. Fitzgibbon, Oxford RRG, 28 Jan 97
00021 //
00022 // \verbatim
00023 // Modifications
00024 //    22 Oct 2002 - Peter Vanroose - added vgl_homg_point_2d interface
00025 // \endverbatim
00026 //
00027 //-----------------------------------------------------------------------------
00028 
00029 #include <vnl/vnl_fwd.h>
00030 #include <vgl/vgl_fwd.h>
00031 #include <vcl_iosfwd.h>
00032 
00033 class ImageMetric;
00034 class HomgPoint2D;
00035 class HomgLine2D;
00036 class HomgLineSeg2D;
00037 class FMatrix;
00038 class TriTensor;
00039 class HMatrix2D;
00040 class PMatrix;
00041 
00042 class HomgMetric
00043 {
00044   // Data Members--------------------------------------------------------------
00045   const ImageMetric* metric_;
00046  public:
00047   // Constructors/Destructors--------------------------------------------------
00048 
00049   HomgMetric() : metric_(0) {}
00050   HomgMetric(const ImageMetric* metric);
00051 
00052   // HomgMetric(const HomgMetric& that); - use default
00053   ~HomgMetric();
00054   // HomgMetric& operator=(const HomgMetric& that); - use default
00055 
00056   // Operations----------------------------------------------------------------
00057 
00058   // ** Conversion to/from homogeneous coordinates
00059   vgl_point_2d<double> homg_to_image(vgl_homg_point_2d<double> const&) const;
00060   vnl_double_2 homg_to_image(const HomgPoint2D&) const;
00061   void homg_to_image(const HomgPoint2D&, double* ix, double* iy) const;
00062   void homg_to_image(vgl_homg_point_2d<double> const&, double& ix, double& iy) const;
00063 
00064   vgl_homg_point_2d<double> image_to_homg(vgl_point_2d<double> const&) const;
00065   HomgPoint2D image_to_homg(const vnl_double_2&) const;
00066   HomgPoint2D image_to_homg(double x, double y) const;
00067 
00068   HomgPoint2D homg_to_imagehomg(const HomgPoint2D&) const;
00069   HomgPoint2D imagehomg_to_homg(const HomgPoint2D&) const;
00070 
00071   vgl_homg_point_2d<double> homg_to_imagehomg(vgl_homg_point_2d<double> const&) const;
00072   vgl_homg_point_2d<double> imagehomg_to_homg(vgl_homg_point_2d<double> const&) const;
00073 
00074   HomgLine2D homg_to_image_line(const HomgLine2D&) const;
00075   HomgLine2D image_to_homg_line(const HomgLine2D&) const;
00076 
00077   vgl_homg_line_2d<double> homg_to_image_line(vgl_homg_line_2d<double> const&) const;
00078   vgl_homg_line_2d<double> image_to_homg_line(vgl_homg_line_2d<double> const&) const;
00079 
00080   HomgLineSeg2D image_to_homg_line(const HomgLineSeg2D&) const;
00081   HomgLineSeg2D homg_line_to_image(const HomgLineSeg2D&) const;
00082 
00083   // ** Measurements
00084   double perp_dist_squared(const HomgPoint2D&, const HomgLine2D&) const;
00085   double perp_dist_squared(vgl_homg_point_2d<double> const& p,
00086                            vgl_homg_line_2d<double> const& l) const;
00087   HomgPoint2D perp_projection(const HomgLine2D& l, const HomgPoint2D& p) const;
00088   vgl_homg_point_2d<double> perp_projection(vgl_homg_line_2d<double> const& l,
00089                                             vgl_homg_point_2d<double> const& p) const;
00090 
00091   double distance_squared(double x1, double y1, double x2, double y2) const;
00092   double distance_squared(const HomgPoint2D&, const HomgPoint2D&) const;
00093   double distance_squared(vgl_homg_point_2d<double> const&,
00094                           vgl_homg_point_2d<double> const&) const;
00095   double distance_squared(const HomgLineSeg2D& segment, const HomgLine2D& line) const;
00096   double distance_squared(vgl_line_segment_2d<double> const& segment,
00097                           vgl_homg_line_2d<double> const& line) const;
00098 
00099   bool is_within_distance(const HomgPoint2D&, const HomgPoint2D&, double distance) const;
00100   bool is_within_distance(vgl_homg_point_2d<double> const&,
00101                           vgl_homg_point_2d<double> const&,
00102                           double distance) const;
00103 
00104   // ** Speedups available for certain systems.
00105   bool is_linear() const;
00106   vnl_double_3x3 get_C() const;
00107   vnl_double_3x3 get_C_inverse() const;
00108 
00109   bool can_invert_distance() const;
00110   double image_to_homg_distance(double image_distance) const;
00111   double homg_to_image_distance(double homg_distance) const;
00112 
00113   double image_to_homg_distance_sqr(double image_distance) const;
00114   double homg_to_image_distance_sqr(double homg_distance) const;
00115 
00116   vcl_ostream& print(vcl_ostream&) const;
00117 
00118   operator const ImageMetric* () const { return metric_; }
00119 
00120   // Static functions to condition/decondition image relations-----------------
00121   static PMatrix homg_to_image_P(const PMatrix&, const HomgMetric& c);
00122   static PMatrix image_to_homg_P(const PMatrix&, const HomgMetric& c);
00123 
00124   static FMatrix homg_to_image_F(const FMatrix&, const HomgMetric& c1, const HomgMetric& c2);
00125   static FMatrix image_to_homg_F(const FMatrix&, const HomgMetric& c1, const HomgMetric& c2);
00126 
00127   static TriTensor homg_to_image_T(const TriTensor&, const HomgMetric& c1, const HomgMetric& c2, const HomgMetric& c3);
00128   static TriTensor image_to_homg_T(const TriTensor&, const HomgMetric& c1, const HomgMetric& c2, const HomgMetric& c3);
00129 
00130   static HMatrix2D homg_to_image_H(const HMatrix2D&, const HomgMetric& c1, const HomgMetric& c2);
00131   static HMatrix2D image_to_homg_H(const HMatrix2D&, const HomgMetric& c1, const HomgMetric& c2);
00132 };
00133 
00134 inline vcl_ostream& operator<<(vcl_ostream& s, const HomgMetric& h) { return h.print(s); }
00135 
00136 #endif // HomgMetric_h_