core/vpgl/algo/vpgl_ray_intersect.h
Go to the documentation of this file.
00001 // This is core/vpgl/algo/vpgl_ray_intersect.h
00002 #ifndef vpgl_ray_intersect_h_
00003 #define vpgl_ray_intersect_h_
00004 //:
00005 // \file
00006 // \brief Find the 3-d point closest to the intersection of rays from >= 2 cameras
00007 // \author J. L. Mundy
00008 // \date July 30, 2007
00009 //
00010 // given a sequence of image points (image_pts[i]), as viewed through a
00011 // corresponding sequence of cameras (cams[i]), this class attempts to
00012 // find the point in space (intersection_vert), such that the cumulative
00013 // error of the image of intersection_vert wrt each image_pts[i] is
00014 // minimized.  More precisely, it finds intersection_vert for which the
00015 // following quantity is attempted to be minimized (for n cameras and
00016 // image points):
00017 //
00018 // $\sqrt(\sum_{i=1}^{n}(  (u_i-image_pts[i][1])^2
00019 //                       + (v_i-image_pts[i][2])^2))$
00020 //
00021 //  where (u_i, v_i) is the image of intersection_vert through
00022 //  camera cams[i], and image_pts[i][1 and 2] are the "u" and "v"
00023 //  coordinates of image_pts[i].
00024 //
00025 
00026 #include <vcl_vector.h>
00027 #include <vnl/vnl_fwd.h>
00028 #include <vnl/vnl_least_squares_function.h>
00029 #include <vgl/vgl_point_2d.h>
00030 #include <vgl/vgl_point_3d.h>
00031 #include <vpgl/vpgl_camera.h>
00032 //
00033 //:
00034 // The image offsets of rational cameras typically must be adjusted to
00035 // compensate for errors in geographic alignment. This algorithm finds
00036 // a set of minimum translations that registers the input set of images.
00037 // After registration, the images have geographically corresponding rational
00038 // cameras. That is, a visible 3-d point will project into its corresponding
00039 // image location in all the images.
00040 
00041 class vpgl_ray_intersect_lsqr : public vnl_least_squares_function
00042 {
00043  public:
00044   //: Constructor
00045   vpgl_ray_intersect_lsqr(vcl_vector<vpgl_camera<double>* > const& cams,
00046                           vcl_vector<vgl_point_2d<double> > const& image_pts,
00047                           unsigned num_residuals);
00048 
00049   //: Destructor
00050   virtual ~vpgl_ray_intersect_lsqr() {}
00051 
00052   //: The main function.
00053   //  Given the parameter vector x, compute the vector of residuals fx.
00054   //  fx has been sized appropriately before the call.
00055   virtual void f(vnl_vector<double> const& intersection_point,
00056                  vnl_vector<double>& image_errors);
00057 
00058 #if 0
00059   //: Called after each LM iteration to print debugging etc.
00060   virtual void trace(int iteration, vnl_vector<double> const& x, vnl_vector<double> const& fx);
00061 #endif
00062 
00063  protected:
00064   vpgl_ray_intersect_lsqr();//not valid
00065   vcl_vector<vpgl_camera<double>* > f_cameras_; //cameras
00066   vcl_vector<vgl_point_2d<double> > f_image_pts_; //image points
00067 };
00068 
00069 class vpgl_ray_intersect
00070 {
00071  public:
00072 
00073   vpgl_ray_intersect(unsigned dim);
00074   ~vpgl_ray_intersect() {}
00075 
00076   //: Intersect the rays. return false if intersection fails
00077   // Note image points are not homogeneous because require
00078   // finite points to measure projection error
00079   bool intersect(vcl_vector<vpgl_camera<double>* > const& cams,
00080                  vcl_vector<vgl_point_2d<double> > const& image_pts,
00081                  vgl_point_3d<double> const& initial_intersection,
00082                  vgl_point_3d<double>& intersection);
00083 
00084  protected:
00085   //members
00086   unsigned dim_;
00087   vcl_vector<vpgl_camera<double>* > f_cameras_; //cameras
00088   vcl_vector<vgl_point_2d<double> > f_image_pts_; //image points
00089 };
00090 
00091 
00092 #endif // vpgl_ray_intersect_h_