vpgl_poly_radial_distortion.hxx
Go to the documentation of this file.
1 // This is core/vpgl/vpgl_poly_radial_distortion.hxx
2 #ifndef vpgl_poly_radial_distortion_hxx_
3 #define vpgl_poly_radial_distortion_hxx_
4 //:
5 // \file
6 
8 
9 // The templated helper functions are a metaprogram which allows the
10 // compiler to create a closed form (no loops) expression for polynomial
11 // evaluation of any order. For very large n loops may be more efficient
12 // but for lens distortion the order is usually small.
13 
14 template <class T, int n>
16  static inline T val(const T& radius, const T* k)
17  {
18  return ((*k)+vpgl_poly_helper<T,n-1>::val(radius, k+1))*radius;
19  }
20 };
21 
22 template <class T>
23 struct vpgl_poly_helper<T,1>{
24  static inline T val(const T& radius, const T* k)
25  {
26  return (*k)*radius;
27  }
28 };
29 
30 
31 //: Distort a radial length
32 template <class T, int n>
33 T
35 {
36  return 1 + vpgl_poly_helper<T,n>::val(radius, coefficients_);
37 }
38 
39 
40 //====================================================================
41 
42 
43 template <class T, int n>
45  static inline T val(const T& radius, const T* k, unsigned int p)
46  {
47  return p*(*k) + vpgl_poly_deriv_helper<T,n-1>::val(radius, k+1, p+1)*radius;
48  }
49 };
50 
51 
52 template <class T>
54  static inline T val(const T& /*radius*/, const T* k, unsigned int p)
55  {
56  return p*(*k);
57  }
58 };
59 
60 //: Compute the derivative of the distort_radius function
61 template <class T, int n>
62 T
64 {
65  return vpgl_poly_deriv_helper<T,n>::val(radius, coefficients_, 1);
66 }
67 
68 
69 // Code for easy instantiation.
70 #undef vpgl_POLY_RADIAL_DISTORTION_INSTANTIATE
71 #define vpgl_POLY_RADIAL_DISTORTION_INSTANTIATE(T,n) \
72 template class vpgl_poly_radial_distortion<T,n>
73 
74 #endif // vpgl_poly_radial_distortion_hxx_
T distort_radius(T radius) const override
Distort a radial length.
static T val(const T &radius, const T *k)
A class for polynomial radial lens distortions.
static T val(const T &, const T *k, unsigned int p)
T distort_radius_deriv(T radius) const override
Compute the derivative of the distort_radius function.
static T val(const T &radius, const T *k)
static T val(const T &radius, const T *k, unsigned int p)