core/vpgl/algo/vpgl_camera_convert.h
Go to the documentation of this file.
00001 // This is core/vpgl/algo/vpgl_camera_convert.h
00002 #ifndef vpgl_camera_convert_h_
00003 #define vpgl_camera_convert_h_
00004 //:
00005 // \file
00006 // \brief Several routines for converting camera types
00007 // \author J.L. Mundy
00008 // \date July 18, 2005
00009 //
00010 // Should template this class.
00011 
00012 #include <vcl_vector.h>
00013 #include <vgl/vgl_fwd.h>
00014 #include <vnl/vnl_fwd.h>
00015 #include <vpgl/vpgl_calibration_matrix.h>
00016 #include <vpgl/vpgl_perspective_camera.h>
00017 #include <vpgl/vpgl_proj_camera.h>
00018 #include <vpgl/vpgl_affine_camera.h>
00019 #include <vpgl/vpgl_rational_camera.h>
00020 #include <vpgl/vpgl_local_rational_camera.h>
00021 #include <vpgl/vpgl_generic_camera.h>
00022 #include <vpgl/file_formats/vpgl_geo_camera.h>
00023 #include <vgl/algo/vgl_h_matrix_3d.h>
00024 
00025 //: Basic least squares solution for a general projective camera given corresponding world and image points.
00026 class vpgl_proj_camera_convert
00027 {
00028  public:
00029   //:Find a projective camera that best approximates the rational camera at the world center (lon (deg), lat (deg), elev (meters) )
00030   static  bool convert(vpgl_rational_camera<double> const& rat_cam,
00031                        vgl_point_3d<double> const& world_center,
00032                        vpgl_proj_camera<double>& camera);
00033 
00034   //:An auxiliary matrix that transforms (normalizes) world points prior to projection by a projective camera.  (lon, lat, elevation)->[-1, 1].
00035   static vgl_h_matrix_3d<double>
00036     norm_trans(vpgl_rational_camera<double> const& rat_cam);
00037 
00038  private:
00039   //:default constructor (is private)
00040   vpgl_proj_camera_convert();
00041 };
00042 
00043 
00044 //:Various methods for computing a perspective camera
00045 class vpgl_perspective_camera_convert
00046 {
00047  public:
00048 
00049   //: Convert from a rational camera
00050   // Put the resulting camera into camera, return true if successful.
00051   // The approximation volume defines the region of space (lon (deg), lat (deg), elev (meters))
00052   //  where the perspective approximation is valid. Norm trans is a pre-multiplication
00053   // of the perspective camera to account for scaling the lon, lat and elevation
00054   // to the range [-1, 1]
00055   static bool convert( vpgl_rational_camera<double> const& rat_cam,
00056                        vgl_box_3d<double> const& approximation_volume,
00057                        vpgl_perspective_camera<double>& camera,
00058                        vgl_h_matrix_3d<double>& norm_trans);
00059 
00060   //: Convert from rational camera using a local Euclidean coordinate system.
00061   static bool convert_local( vpgl_rational_camera<double> const& rat_cam,
00062                              vgl_box_3d<double> const& approximation_volume,
00063                              vpgl_perspective_camera<double>& camera,
00064                              vgl_h_matrix_3d<double>& norm_trans);
00065 
00066  private:
00067   vpgl_perspective_camera_convert();
00068 };
00069 
00070 //:Various methods for converting to a generic camera
00071 class vpgl_generic_camera_convert
00072 {
00073  public:
00074 
00075   //: Convert a local rational camera to a generic camera
00076   static bool convert( vpgl_local_rational_camera<double> const& rat_cam,
00077                        int ni, int nj,
00078                        vpgl_generic_camera<double> & gen_cam, unsigned level = 0);
00079 
00080   //: Convert a local rational camera to a generic camera, using user-specified z bounds
00081   //  Note that the z values are relative to the local coordinate system
00082   static bool convert( vpgl_local_rational_camera<double> const& rat_cam,
00083                        int ni, int nj,
00084                        vpgl_generic_camera<double> & gen_cam,
00085                        double local_z_min, double local_z_max, unsigned level = 0);
00086 
00087   //: Convert a proj_camera to a generic camera
00088   static bool convert( vpgl_proj_camera<double> const& prj_cam,
00089                        int ni, int nj,
00090                        vpgl_generic_camera<double> & gen_cam, unsigned level = 0);
00091 
00092   //: Convert a perspective_camera to a generic camera
00093   static bool convert( vpgl_perspective_camera<double> const& per_cam,
00094                        int ni, int nj,
00095                        vpgl_generic_camera<double> & gen_cam, unsigned level = 0);
00096 #if 0
00097   {
00098     vpgl_perspective_camera<double> nc_cam(per_cam);
00099     vpgl_proj_camera<double>* prj_cam_ptr =
00100       dynamic_cast<vpgl_proj_camera<double>*>(&nc_cam);
00101     if (!prj_cam_ptr) return false;
00102     return convert(*prj_cam_ptr, ni, nj, gen_cam,level);
00103   }
00104 #endif
00105 
00106   static bool convert_with_margin( vpgl_perspective_camera<double> const& per_cam,
00107                                    int ni, int nj,
00108                                    vpgl_generic_camera<double> & gen_cam, int margin, unsigned level = 0);
00109 
00110   //: Convert an affine_camera to a generic camera
00111   static bool convert( vpgl_affine_camera<double> const& aff_cam,
00112                        int ni, int nj, vpgl_generic_camera<double> & gen_cam, unsigned level = 0);
00113 
00114   //::convert an abstract camera to generic camera
00115   static bool convert( vpgl_camera_double_sptr const& camera, int ni, int nj,
00116                        vpgl_generic_camera<double> & gen_cam, unsigned level = 0);
00117 
00118   //: Convert a geocam (transformtaion matrix read from a geotiff header + an lvcs) to a generic camera
00119   static bool convert( vpgl_geo_camera& geocam, int ni, int nj, double height,
00120                        vpgl_generic_camera<double> & gen_cam, unsigned level = 0);
00121 
00122   // === utility methods ===
00123  private:
00124   //: interpolate rays to fill next higher resolution pyramid layer
00125   static bool
00126     upsample_rays(vcl_vector<vgl_ray_3d<double> > const& ray_nbrs,
00127                   vgl_ray_3d<double> const& ray,
00128                   vcl_vector<vgl_ray_3d<double> >& interp_rays);
00129   //: interpolate a span of rays base on a linear interpolation. n_grid is the step distance from r1. r0 and r1 are one unit apart.
00130   static vgl_ray_3d<double> interp_pair(vgl_ray_3d<double> const& r0,
00131                                         vgl_ray_3d<double> const& r1,
00132                                         double n_grid);
00133   vpgl_generic_camera_convert();
00134 };
00135 
00136 #endif // vpgl_camera_convert_h_