1 #ifndef ldpk_generic_radial_distortion_sdv 2 #define ldpk_generic_radial_distortion_sdv 8 #include <ldpk/ldpk_power_ct.h> 16 template <
class VEC2,
class MAT2,
int N>
21 typedef VEC2 vec2_type;
22 typedef MAT2 mat2_type;
29 for(
int i = 0;i < N;++i) _c[i] = 0.0;
48 double q(1.0),r2 = dotsq(p_dn);
51 for(
int i = 0;i < N;++i)
53 q += _c[i] * r2pow[i + 1];
55 return vec2_type(p_dn[0] * q,p_dn[1] * q);
59 mat2_type
jacobi(
const vec2_type& p_dn)
const 63 double r2 = dotsq(p_dn);
66 double qa(1.0),qb(0.0);
67 for(
int i = 0;i < N;++i)
69 qa += _c[i] * r2pow[i + 1];
70 qb += _c[i] * (2 * i + 2) * r2pow[i];
72 return mat2_type(qa) + mat2_type(
tensq(p_dn) * qb);
76 void derive(
double* dg,
int n_parameters,
const vec2_type& p_dn)
const 78 int size = 2 * n_parameters;
81 double r2 = dotsq(p_dn);
85 for(
int i = 0;i < N;++i)
87 dg[k++] = p_dn[0] * r2pow[i + 1];
88 dg[k++] = p_dn[1] * r2pow[i + 1];
93 std::cerr <<
"example_radial_distortion: n_parameters out of range" << std::endl;
95 std::ostream&
out(std::ostream& cout)
const 97 std::streamsize p = cout.precision();
99 for(
int i = 0;i < N;++i)
101 cout <<
" C(" << 2 * i + 2 <<
"): " << std::right << std::fixed << _c[i] <<
"\n";
mat2d tensq(const vec2d &a)
Tensor (dyadic) product square.
Definition: ldpk_vec2d.h:186
Base class for a distortion model with N parameters. You may find it useful to derive your own distor...
Definition: ldpk_generic_distortion_base.h:21
void check_range(int i) const
A derived class may check if the index is valid.
Definition: ldpk_generic_distortion_base.h:43
vec2_type operator()(const vec2_type &p_dn) const
Remove distortion. p_dn is a point in diagonally normalized coordinates.
Definition: ldpk_generic_radial_distortion.h:44
The namespace of (most of the) things related to the Lens Distortion Plugin Kit.
Definition: ldpk.h:19
Base class for distortion models.
A polynomial model with N coefficients for radially symmetric lenses. This class contains the model f...
Definition: ldpk_generic_radial_distortion.h:17
Computing N powers of a given number, where N is a compile-time constant.
Definition: ldpk_power_ct.h:33
mat2_type jacobi(const vec2_type &p_dn) const
Analytic version of the Jacobi-matrix, about 2.5 times faster than the base class version which uses ...
Definition: ldpk_generic_radial_distortion.h:59
void derive(double *dg, int n_parameters, const vec2_type &p_dn) const
Derivative with respect to distortion coefficients. dg points to an array with 2 * N Elements...
Definition: ldpk_generic_radial_distortion.h:76
void set_coeff(int i, double q)
Set coefficient c[i], 0 <= i < N.
Definition: ldpk_generic_radial_distortion.h:38
std::ostream & out(std::ostream &cout) const
The derived class implements a method for printing values inside 3DE4's matrix tool dialog...
Definition: ldpk_generic_radial_distortion.h:95
double get_coeff(int i) const
Get coefficient c[i], 0 <= i < N (i.e. coefficient power r^(2i))
Definition: ldpk_generic_radial_distortion.h:32