contrib/gel/mrc/vpgl/vpgl_comp_rational_camera.h
Go to the documentation of this file.
00001 // This is gel/mrc/vpgl/vpgl_comp_rational_camera.h
00002 #ifndef vpgl_comp_rational_camera_h_
00003 #define vpgl_comp_rational_camera_h_
00004 //:
00005 // \file
00006 // \brief A composite rational camera model
00007 // \author Joseph Mundy
00008 // \date August 4, 2007
00009 //
00010 // Rational camera models often have positioning
00011 // errors that can be corrected by a rigid body transformation
00012 // of the image coordinate system. There also exist anamorphic image
00013 // formats that require anisotropic scaling of the image coordinates.
00014 // In order to support these image transformations, the rational camera
00015 // class is augmented by a five-parameter affine transformation
00016 // that includes: translation(2 dof); rotation(1 dof);
00017 // and scale in u and v (2 dof).
00018 //
00019 #include <vgl/vgl_fwd.h>
00020 #include <vcl_iostream.h>
00021 #include <vcl_string.h>
00022 #include <vnl/vnl_vector_fixed.h>
00023 #include <vnl/vnl_matrix_fixed.h>
00024 #include <vpgl/vpgl_rational_camera.h>
00025 
00026 //
00027 //--------------------=== composite rational camera ===---------------------------
00028 //
00029 template <class T>
00030 class vpgl_comp_rational_camera : public vpgl_rational_camera<T>
00031 {
00032  public:
00033   //: default constructor
00034   vpgl_comp_rational_camera();
00035 
00036   //: Constructor from a rational camera and an affine matrix
00037   vpgl_comp_rational_camera(vnl_matrix_fixed<T, 3,3> const& M,
00038                             vpgl_rational_camera<T> const& rcam);
00039 
00040   //: Constructor from translation only
00041   vpgl_comp_rational_camera(const T tu, const T tv,
00042                             vpgl_rational_camera<T> const& rcam);
00043 
00044   //: Constructor from translation rotation only (first rotate then translate)
00045   vpgl_comp_rational_camera(const T tu, const T tv, const T angle_in_radians,
00046                             vpgl_rational_camera<T> const& rcam);
00047 
00048   //: Constructor with all transform parameters (scale,then rotate,then trans)
00049   // Note, scale factors are non-negative
00050   vpgl_comp_rational_camera(const T tu, const T tv, const T angle_in_radians,
00051                             const T su, const T sv,
00052                             vpgl_rational_camera<T> const& rcam);
00053 
00054   //: Constructor, create from a camera file given by cam_path
00055   vpgl_comp_rational_camera(vcl_string cam_path);
00056 
00057   virtual ~vpgl_comp_rational_camera() {}
00058 
00059   //: Clone `this': creation of a new object and initialization
00060   //  See Prototype pattern
00061   virtual vpgl_comp_rational_camera<T>* clone(void) const;
00062 
00063         // Mutators/Accessors
00064 
00065   //: set the full affine transform matrix
00066   void set_transform(vnl_matrix_fixed<T, 3,3> const& M);
00067   //: set individual parameters
00068   void set_translation(const T tu, const T tv);
00069   void set_trans_rotation(const T tu, const T tv, const T angle_in_radians);
00070 
00071   //: note, scale factors su and sv are non-negative
00072   void set_all(const T tu, const T tv, const T angle_in_radians,
00073                const T su, const T sv);
00074 
00075   //: the full affine transform matrix
00076   vnl_matrix_fixed<T, 3,3> transform();
00077   //: image translation
00078   void translation(T& tu, T& tv);
00079   //: angle in radians
00080   T rotation_in_radians();
00081   //: image scale (note, scale factors are non-negative)
00082   void image_scale(T& su, T& sv);
00083 
00084   //: The generic camera interface. u represents image column, v image row.
00085   virtual void project(const T x, const T y, const T z, T& u, T& v) const;
00086 
00087         // Interface for vnl
00088 
00089   //: Project a world point onto the image
00090   virtual vnl_vector_fixed<T, 2> project(vnl_vector_fixed<T, 3> const& world_point) const;
00091 
00092         // Interface for vgl
00093 
00094   //: Project a world point onto the image
00095   virtual vgl_point_2d<T> project(vgl_point_3d<T> world_point) const;
00096 
00097 
00098   //: print the camera parameters
00099   virtual void print(vcl_ostream& s = vcl_cout) const;
00100   //: save to file (the affine map is after the end of the rational definition)
00101   bool save(vcl_string cam_path);
00102 
00103  protected:
00104   vnl_matrix_fixed<T, 3,3> matrix_;
00105 };
00106 
00107 //: Write to stream
00108 // \relatesalso vpgl_comp_rational_camera
00109 template <class T>
00110 vcl_ostream& operator<<(vcl_ostream& s, const vpgl_comp_rational_camera<T>& p);
00111 
00112 //: Read from stream
00113 // \relatesalso vpgl_comp_rational_camera
00114 template <class T>
00115 vcl_istream& operator>>(vcl_istream& is, vpgl_comp_rational_camera<T>& p);
00116 
00117 #define VPGL_COMP_RATIONAL_CAMERA_INSTANTIATE(T) extern "please include vgl/vpgl_comp_rational_camera.txx first"
00118 
00119 
00120 #endif // vpgl_comp_rational_camera_h_
00121