core/vpgl/algo/vpgl_ray.h
Go to the documentation of this file.
00001 // This is core/vpgl/algo/vpgl_ray.h
00002 #ifndef vpgl_ray_h_
00003 #define vpgl_ray_h_
00004 //:
00005 // \file
00006 // \brief Methods for computing the camera ray direction at a given 3-d point and other operations on camera rays
00007 // \author J. L. Mundy
00008 // \date Dec 22, 2007
00009 
00010 #include <vpgl/vpgl_rational_camera.h>
00011 #include <vgl/algo/vgl_rotation_3d.h>
00012 #include <vpgl/vpgl_local_rational_camera.h>
00013 #include <vpgl/vpgl_perspective_camera.h>
00014 #include <vpgl/vpgl_generic_camera.h>
00015 #include <vnl/vnl_double_3.h>
00016 #include <vgl/vgl_point_3d.h>
00017 #include <vgl/vgl_vector_3d.h>
00018 #include <vgl/vgl_ray_3d.h>
00019 
00020 class vpgl_ray
00021 {
00022  public:
00023   //: Generic camera interfaces (pointer for abstract class)
00024   // Solves using back-project so will work for any camera
00025   // The ray direction assumes the camera is in the positive half-space
00026   // of the x-y plane. This assumption is necessary since some cameras
00027   // don't have a natural center of projection (e.g. rational cameras).
00028 
00029        // === vnl interface ===
00030 
00031   //: compute the ray at a given 3-d point
00032   static  bool ray(const vpgl_camera<double>* cam,
00033                    vnl_double_3 const& point_3d,
00034                    vnl_double_3& ray);
00035 
00036        // === vgl interface ===
00037 
00038   //: compute the ray at a given 3-d point
00039   static bool ray(const vpgl_camera<double>*  cam,
00040                   vgl_point_3d<double> const& point_3d,
00041                   vgl_vector_3d<double>& ray);
00042 
00043   //: vgl interface, origin_z defines an x-y plane wherein lies the ray origin
00044   static bool ray(const vpgl_camera<double>*  cam,
00045                   vgl_point_3d<double> const& point_3d,
00046                   double origin_z,
00047                   vgl_ray_3d<double>& ray);
00048 
00049             // +++ concrete rational camera interfaces +++
00050 
00051        // === vnl interface ===
00052 
00053   //: compute the ray at a given 3-d point
00054   static bool ray(vpgl_rational_camera<double> const& rcam,
00055                   vnl_double_3 const& point_3d,
00056                   vnl_double_3& ray);
00057 
00058        // === vgl interface ===
00059 
00060   //: compute the ray at a given 3-d point
00061   static bool ray(vpgl_rational_camera<double> const& rcam,
00062                   vgl_point_3d<double> const& point_3d,
00063                   vgl_vector_3d<double>& ray);
00064 
00065   //: compute the ray at a given 3-d point
00066   static bool ray(vpgl_rational_camera<double> const& rcam,
00067                   vgl_point_3d<double> const& point_3d,
00068                   vgl_ray_3d<double>& ray);
00069 
00070   //: compute a ray in local Cartesian coordinates at a given (u, v)
00071   static bool ray(vpgl_local_rational_camera<double> const& lrcam,
00072                   const double u, const double v,
00073                   vgl_point_3d<double>& origin, vgl_vector_3d<double>& dir);
00074 
00075   //: compute a ray in local Cartesian coordinates at a given (u, v)
00076   static bool ray(vpgl_local_rational_camera<double> const& lrcam,
00077                   const double u, const double v,
00078                   vgl_ray_3d<double>& ray);
00079 
00080   //: compute a ray in local Cartesian coordinates for a local rational cam
00081   static bool plane_ray(vpgl_local_rational_camera<double> const& lrcam,
00082                         const vgl_point_2d<double> image_point1,
00083                         const vgl_point_2d<double> image_point2,
00084                         vgl_plane_3d<double>& plane);
00085   // ====== projective camera =====
00086   static bool ray(vpgl_proj_camera<double> const& cam,
00087                   vgl_point_3d<double> const& world_pt,
00088                   vgl_ray_3d<double>& ray);
00089 
00090   static bool principal_ray(vpgl_proj_camera<double> const& cam,
00091                             vgl_ray_3d<double>& pray);
00092 
00093   // ====== perspective camera =====
00094   static bool ray(vpgl_perspective_camera<double> const& cam,
00095                   vgl_point_3d<double> const& world_pt,
00096                   vgl_ray_3d<double>& ray);
00097 
00098   static bool principal_ray(vpgl_perspective_camera<double> const& cam,
00099                             vgl_ray_3d<double>& pray) {
00100     vpgl_proj_camera<double> const* procam =
00101       static_cast<vpgl_proj_camera<double> const* >(&cam);
00102     return  vpgl_ray::principal_ray(*procam, pray);
00103   }
00104 
00105   // ====== generic camera =====
00106   static bool ray(vpgl_generic_camera<double> const& cam,
00107                   vgl_point_3d<double> const& world_pt,
00108                   vgl_ray_3d<double>& ray);
00109 
00110 
00111   // ====== operations on rotation matrices with respect to camera rays ======
00112 
00113     //: angle(radians) between principal ray of one rotation and the principal ray of a second rotation
00114   // Rotations \p r0 and \p r1 are expressed as vgl_rotation<T>
00115   static double angle_between_rays(vgl_rotation_3d<double> const& r0, vgl_rotation_3d<double> const& r1);
00116 
00117   //: the rotation about the principal ray required to go from \p r0 to \p r1
00118   static double rot_about_ray(vgl_rotation_3d<double> const& r0, vgl_rotation_3d<double> const& r1);
00119 
00120   //: the rotation required to point the principal ray in a given direction, starting with the identity camera (principal ray in z direction)
00121   static vgl_rotation_3d<double> rot_to_point_ray(vgl_vector_3d<double> const& ray_dir);
00122   //: define the principal ray in spherical coordinates (in degrees, azimuth [0 360], elevation [0, 180], x axis = (0, 90), y axis = (90, 90, z axis = (0, 0)).
00123   static vgl_rotation_3d<double> rot_to_point_ray(double azimuth, double elevation);
00124  private:
00125   //: constructor/destructor private - static methods only
00126   vpgl_ray();
00127   ~vpgl_ray();
00128 };
00129 
00130 #endif // vpgl_ray_h_