contrib/oxl/mvl/ImageMetric.h
Go to the documentation of this file.
00001 // This is oxl/mvl/ImageMetric.h
00002 #ifndef ImageMetric_h_
00003 #define ImageMetric_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Converting between image and metric coordinates
00010 //
00011 //    ImageMetric is the baseclass for classes that define how points in image
00012 //    coordinates are converted to conditioned frames.  For simple systems this
00013 //    will represent the mapping of the image plane to the unit square, but for
00014 //    a fully calibrated camera, for example, this might include corrections for
00015 //    radial lens distortion and other nonlinear effects.
00016 //
00017 //    The default implementation in this baseclass simply assumes an identity
00018 //    mapping between the two coordinate systems.
00019 //
00020 //    A general convention that is sometimes useful is that points in homogeneous
00021 //    coordinates have been conditioned, while nonhomogeneous primitives remain in
00022 //    image coordinates.
00023 //
00024 // \author
00025 //     Andrew W. Fitzgibbon, Oxford RRG, 17 Aug 96
00026 //
00027 // \verbatim
00028 //  Modifications
00029 //   22 Oct 2002 - Peter Vanroose - added vgl_homg_point_2d interface
00030 // \endverbatim
00031 //
00032 //-----------------------------------------------------------------------------
00033 
00034 #include <vnl/vnl_fwd.h>
00035 #include <vgl/vgl_fwd.h>
00036 #include <vcl_iosfwd.h>
00037 class HomgPoint2D;
00038 class HomgLineSeg2D;
00039 class HomgLine2D;
00040 class FMatrix;
00041 
00042 class ImageMetric
00043 {
00044  public:
00045   // Constructors/Destructors--------------------------------------------------
00046   ImageMetric() {}
00047   virtual ~ImageMetric() {}
00048   //ImageMetric(ImageMetric const& that); - use default
00049   //ImageMetric& operator=(ImageMetric const& that); - use default
00050 
00051   virtual vgl_homg_point_2d<double> homg_to_imagehomg(vgl_homg_point_2d<double> const&) const;
00052   virtual vgl_homg_point_2d<double> imagehomg_to_homg(vgl_homg_point_2d<double> const&) const;
00053 
00054   virtual HomgPoint2D homg_to_imagehomg(const HomgPoint2D&) const;
00055   virtual HomgPoint2D imagehomg_to_homg(const HomgPoint2D&) const;
00056 
00057   // The following virtuals may be overridden if desired.
00058   // By default they are implemented in terms of the previous two
00059   virtual vgl_point_2d<double> homg_to_image(vgl_homg_point_2d<double> const&) const;
00060   virtual vnl_double_2 homg_to_image(const HomgPoint2D&) const;
00061 
00062   virtual vgl_homg_point_2d<double> image_to_homg(vgl_point_2d<double> const&) const;
00063   virtual HomgPoint2D image_to_homg(const vnl_double_2&) const;
00064   virtual HomgPoint2D image_to_homg(double x, double y) const;
00065 
00066   virtual vgl_homg_line_2d<double> homg_to_image_line(vgl_homg_line_2d<double> const&) const;
00067   virtual vgl_homg_line_2d<double> image_to_homg_line(vgl_homg_line_2d<double> const&) const;
00068 
00069   virtual HomgLine2D homg_to_image_line(const HomgLine2D&) const;
00070   virtual HomgLine2D image_to_homg_line(const HomgLine2D&) const;
00071 
00072   virtual HomgLineSeg2D image_to_homg_line(const HomgLineSeg2D&) const;
00073   virtual vgl_line_segment_2d<double> image_to_homg_line(vgl_line_segment_2d<double> const& l) const;
00074   virtual HomgLineSeg2D homg_line_to_image(const HomgLineSeg2D&) const;
00075   virtual vgl_line_segment_2d<double> homg_line_to_image(vgl_line_segment_2d<double> const& l) const;
00076 
00077   virtual double perp_dist_squared(const HomgPoint2D&, const HomgLine2D&) const;
00078   virtual double perp_dist_squared(vgl_homg_point_2d<double> const&,
00079                                    vgl_homg_line_2d<double> const&) const;
00080   virtual HomgPoint2D perp_projection(const HomgLine2D & l, const HomgPoint2D & p) const;
00081   virtual vgl_homg_point_2d<double> perp_projection(vgl_homg_line_2d<double> const& l,
00082                                                     vgl_homg_point_2d<double> const& p) const;
00083   virtual double distance_squared(const HomgPoint2D&, const HomgPoint2D&) const;
00084   virtual double distance_squared(const HomgLineSeg2D& segment, const HomgLine2D& line) const;// ca_distance_squared_lineseg_to_line
00085   virtual double distance_squared(const vgl_homg_point_2d<double>&, const vgl_homg_point_2d<double>&) const;
00086   virtual double distance_squared(vgl_line_segment_2d<double> const& segment,
00087                                   vgl_homg_line_2d<double> const& line) const;
00088 
00089   virtual bool is_within_distance(const HomgPoint2D&, const HomgPoint2D&, double distance) const;
00090   virtual bool is_within_distance(vgl_homg_point_2d<double> const&,
00091                                   vgl_homg_point_2d<double> const&,
00092                                   double distance) const;
00093 
00094   // Data Access---------------------------------------------------------------
00095   virtual vnl_double_3x3 get_C() const;
00096   virtual vnl_double_3x3 get_C_inverse() const;
00097 
00098   virtual bool is_linear() const;
00099   virtual bool can_invert_distance() const;
00100   virtual double image_to_homg_distance(double image_distance) const;
00101   virtual double homg_to_image_distance(double image_distance) const;
00102 
00103   virtual vcl_ostream& print(vcl_ostream& s) const;
00104 
00105   // Data Control--------------------------------------------------------------
00106 
00107   // Static functions to condition/decondition image relations
00108   static FMatrix decondition(const FMatrix& F, const ImageMetric* c1, const ImageMetric* c2);
00109 
00110   inline friend vcl_ostream& operator<<(vcl_ostream& o, const ImageMetric& m) { return m.print(o); }
00111 };
00112 
00113 #endif // ImageMetric_h_