vpgl_poly_radial_distortion.h
Go to the documentation of this file.
1 // This is core/vpgl/vpgl_poly_radial_distortion.h
2 #ifndef vpgl_poly_radial_distortion_h_
3 #define vpgl_poly_radial_distortion_h_
4 //:
5 // \file
6 // \brief A class for polynomial radial lens distortions.
7 // \author Matt Leotta
8 // \date Aug 19, 2005
9 //
10 // A radial lens distortion is a 2D warping of the image plane that is radial symmetric
11 // about some center of distortion. It is assumed that the map is
12 // bijective, though a closed form solution for the inverse may not exist in general.
13 // A default iterative solver is implemented to solve
14 
15 #include <vector>
16 #include "vpgl_radial_distortion.h"
17 #include <vgl/vgl_point_2d.h>
18 #ifdef _MSC_VER
19 # include <vcl_msvc_warnings.h>
20 #endif
21 #include <cassert>
22 
23 //: A class for nth order polynomial radial lens distortion
24 template <class T, int n>
26 {
27  public:
28  //: Constructor
31  {
33  }
34 
35  //: Constructor
38  const T* k)
40  {
42  }
43 
44  //: Constructor
46  const std::vector<T>& k)
48  {
50  }
51 
52  //: Constructor
55  const std::vector<T>& k)
57  {
59  }
60 
61  void set_coefficients(const std::vector<T>& k)
62  {
63  assert(k.size() == n);
64  T* coptr = coefficients_;
65  for (unsigned int i=0; i<n; ++i, ++coptr)
66  *coptr = k[i];
67  }
68 
69  void set_coefficients(const T* k)
70  {
71  if ( k == nullptr ) return;
72  const T* kptr = k;
73  T* coptr = coefficients_;
74  for (unsigned int i=0; i<n; ++i, ++kptr, ++coptr)
75  *coptr = *kptr;
76  };
77 
78  //: Read-only coefficient accessor
79  T coefficient( unsigned int i ) const
80  {
81  assert( i < n );
82  return this->coefficients_[i];
83  }
84 
85  //: Read-write coefficient accessor
86  T& coefficient( unsigned int i )
87  {
88  assert( i < n );
89  return this->coefficients_[i];
90  }
91 
92  //: Distort a radial length
93  T distort_radius( T radius ) const override;
94 
95  //: Compute the derivative of the distort_radius function
96  T distort_radius_deriv( T radius ) const override;
97 
98  protected:
99  //: The coefficients of the nth-order polynomial
101 };
102 
103 
104 #endif // vpgl_poly_radial_distortion_h_
T coefficients_[n]
The coefficients of the nth-order polynomial.
A base class for radial lens distortions.
vgl_point_2d< T > distorted_center() const
Returns the center of distortion in the distorted image.
T distort_radius(T radius) const override
Distort a radial length.
vgl_point_2d< T > center() const
Returns the center of distortion.
A class for nth order polynomial radial lens distortion.
T coefficient(unsigned int i) const
Read-only coefficient accessor.
An abstract base class for radial lens distortions.
void set_coefficients(const std::vector< T > &k)
T & coefficient(unsigned int i)
Read-write coefficient accessor.
T distort_radius_deriv(T radius) const override
Compute the derivative of the distort_radius function.