contrib/gel/mrc/vpgl/vpgl_poly_radial_distortion.h
Go to the documentation of this file.
00001 // This is gel/mrc/vpgl/vpgl_poly_radial_distortion.h
00002 #ifndef vpgl_poly_radial_distortion_h_
00003 #define vpgl_poly_radial_distortion_h_
00004 //:
00005 // \file
00006 // \brief A class for polynomial radial lens distortions.
00007 // \author Matt Leotta
00008 // \date Aug 19, 2005
00009 //
00010 //   A radial lens distortion is a 2D warping of the image plane that is radial symmetric
00011 //   about some center of distortion.  It is assumed that the map is
00012 //   bijective, though a closed form solution for the inverse may not exist in general.
00013 //   A default iterative solver is implemented to solve
00014 
00015 #include "vpgl_radial_distortion.h"
00016 #include <vgl/vgl_point_2d.h>
00017 #include <vcl_vector.h>
00018 #include <vcl_cassert.h>
00019 
00020 //: A class for nth order polynomial radial lens distortion
00021 template <class T, int n>
00022 class vpgl_poly_radial_distortion : public vpgl_radial_distortion<T>
00023 {
00024  public:
00025   //: Constructor
00026   vpgl_poly_radial_distortion<T,n>(const vgl_point_2d<T>& center, const T* k)
00027    : vpgl_radial_distortion<T>(center,true)
00028   {
00029     set_coefficients(k);
00030   }
00031 
00032   //: Constructor
00033   vpgl_poly_radial_distortion<T,n>(const vgl_point_2d<T>& center,
00034                                    const vgl_point_2d<T>& distorted_center,
00035                                    const T* k)
00036    : vpgl_radial_distortion<T>(center,distorted_center,true)
00037   {
00038     set_coefficients(k);
00039   }
00040 
00041   //: Constructor
00042   vpgl_poly_radial_distortion<T,n>(const vgl_point_2d<T>& center,
00043                                    const vcl_vector<T>& k)
00044    : vpgl_radial_distortion<T>(center)
00045   {
00046     set_coefficients(k);
00047   }
00048 
00049   //: Constructor
00050   vpgl_poly_radial_distortion<T,n>(const vgl_point_2d<T>& center,
00051                                    const vgl_point_2d<T>& distorted_center,
00052                                    const vcl_vector<T>& k)
00053    : vpgl_radial_distortion<T>(center, distorted_center)
00054   {
00055     set_coefficients(k);
00056   }
00057 
00058   void set_coefficients(const vcl_vector<T>& k)
00059   {
00060     assert(k.size() == n);
00061     T* coptr = coefficients_;
00062     for (unsigned int i=0; i<n; ++i, ++coptr)
00063       *coptr = k[i];
00064   }
00065 
00066   void set_coefficients(const T* k)
00067   {
00068     const T* kptr = k;
00069     T* coptr = coefficients_;
00070     for (unsigned int i=0; i<n; ++i, ++kptr, ++coptr)
00071       *coptr = *kptr;
00072   };
00073 
00074   //: Distort a radial length
00075   virtual T distort_radius( T radius ) const;
00076 
00077   //: Compute the derivative of the distort_radius function
00078   virtual T distort_radius_deriv( T radius ) const;
00079 
00080  protected:
00081   //: The coefficients of the nth-order polynomial
00082   T coefficients_[n];
00083 };
00084 
00085 
00086 #endif // vpgl_poly_radial_distortion_h_