diff --git a/src/math_functions.cpp b/src/math_functions.cpp index 72fb85ae8..8a36f7b92 100644 --- a/src/math_functions.cpp +++ b/src/math_functions.cpp @@ -103,36 +103,17 @@ void calc_pn_c(int n, double x, double pnx[]) { } -double evaluate_legendre_c(int n, const double data[], double x, int flag) { +double evaluate_legendre_c(int n, const double data[], double x) { double pnx[n + 1]; double val = 0.0; calc_pn_c(n, x, pnx); - - if (flag == 1) { - for (int l = 0; l <= n; l++) { - val += (l + 0.5) * data[l] * pnx[l]; - } - } else if (flag == 2) { // if flag is 2, we don't apply any normalization - for (int l = 0; l <= n; l++) { - val += data[l] * pnx[l]; - } + for (int l = 0; l <= n; l++) { + val += (l + 0.5) * data[l] * pnx[l]; } - return val; } -void calc_norm_pn_c(int l, double zmin, double zmax, double norm_vec[]) { - // =========================================================================== - // Set up the normalization vector for FET Pn reconstruction - double d = zmax - zmin; - - for (int i = 0; i <= l; i++) { - norm_vec[i] = (2 * i + 1)/d; - } -} - - void calc_rn_c(int n, const double uvw[3], double rn[]){ // rn[] is assumed to have already been allocated to the correct size @@ -634,34 +615,6 @@ void calc_zn_rad_c(int n, double rho, double zn_rad[]) { } -void calc_norm_zn_rad_c(int n, double r, double norm_vec[]) { - // =========================================================================== - // Set up the normalization vector for FET Zn Radial only reconstruction - int index; - - for (int i = 0; i <= n; i+=2) { - index = int(i/2); - norm_vec[index] = (i + 1)/(PI * r * r); - } -} - - -double evaluate_zernike_rad_c(int n, const double data[], double r) { - // data here is already normalized outside this function - double rnr[n / 2 + 1]; - double val = 0.0; - calc_zn_rad_c(n, r, rnr); - int index; - - for (int i = 0; i <= n; i+= 2) { - index = int(i/2); - val += data[index] * rnr[index]; - } - - return val; -} - - void rotate_angle_c(double uvw[3], double mu, double* phi) { // Copy original directional cosines double u0 = uvw[0]; // original cosine in x direction diff --git a/src/math_functions.h b/src/math_functions.h index 30e210e50..e0ecad60e 100644 --- a/src/math_functions.h +++ b/src/math_functions.h @@ -53,27 +53,11 @@ extern "C" void calc_pn_c(int n, double x, double pnx[]); //! @param data The polynomial expansion coefficient data; without the (2l+1)/2 //! factor. //! @param x The value to evaluate at; x is expected to be within [-1,1] -//! @param flag A flag of which method to calculate Legendre polynomials. 1 for -//! default (2l+1)/2; 2 for custom normalized coefficients //! @return The requested Legendre polynomials of order 0 to n (inclusive) //! evaluated at x //============================================================================== -extern "C" double evaluate_legendre_c(int n, const double data[], double x, int flag = 1); - -//============================================================================== -//! Evaluate the normalization vector when reconstructing functional expansion -//! from Legendre polynomials. -//! -//! The normalization is (2 * l + 1)/(zmax - zmin) -//! -//! @param l The maximum order requested -//! @param zmin The minimum location of 1-d domain -//! @param zmax The maximum location of 1-d domain -//! @param norm_vec The requested normalization of order 0 to n (inclusive) -//============================================================================== - -extern "C" void calc_norm_pn_c(int l, double zmin, double zmax, double norm_vec[]); +extern "C" double evaluate_legendre_c(int n, const double data[], double x); //============================================================================== //! Calculate the n-th order real spherical harmonics for a given angle (in @@ -85,7 +69,6 @@ extern "C" void calc_norm_pn_c(int l, double zmin, double zmax, double norm_vec[ //! evaluated at uvw. //============================================================================== - extern "C" void calc_rn_c(int n, const double uvw[3], double rn[]); //============================================================================== @@ -109,13 +92,18 @@ extern "C" void calc_rn_c(int n, const double uvw[3], double rn[]); extern "C" void calc_zn_c(int n, double rho, double phi, double zn[]); //============================================================================== -//! Calculate only the even order components of n-th order modified Zernike -//! polynomial moment with azimuthal dependency m = 0 for a given radial (rho) -//! location on the unit disk. +//! Calculate only the even radial components of n-th order modified Zernike +//! polynomial moment with azimuthal dependency m = 0 for a given angle +//! (rho, theta) location on the unit disk. //! //! Since m = 0, n could only be even orders. Z_q0 = R_q0 //! -//! See calc_zn_c for methodology. +//! This procedure uses the modified Kintner's method for calculating Zernike +//! polynomials as outlined in Chong, C. W., Raveendran, P., & Mukundan, +//! R. (2003). A comparative analysis of algorithms for fast computation of +//! Zernike moments. Pattern Recognition, 36(3), 731-742. +//! The normalization of the polynomials is such that the integral of Z_pq^2 +//! over the unit disk is exactly pi. //! //! @param n The maximum order requested //! @param rho The radial parameter to specify location on the unit disk @@ -126,33 +114,6 @@ extern "C" void calc_zn_c(int n, double rho, double phi, double zn[]); extern "C" void calc_zn_rad_c(int n, double rho, double zn_rad[]); -//============================================================================== -//! Evaluate the normalization vector when reconstructing functional expansion -//! from radial only Zernike polynomials. -//! -//! The normalization is (2 * l + 1)/(zmax - zmin) -//! -//! @param n The maximum order requested -//! @param r The radius of the disk -//! @param norm_vec The requested normalization of even orders from 0 to n -//============================================================================== - -extern "C" void calc_norm_zn_rad_c(int n, double r, double norm_vec[]); - -//============================================================================== -//! Find the value of f(x) given a set of even order Zernike coefficients and -//! the value of x if there is only radial dependency. -//! -//! @param n The maximum order of the expansion -//! @param data The overall polynomial expansion coefficient data; -//! normalization should be considered by users -//! @param r The value to evaluate at; r is expected to be within [0,1] -//! @return The requested Zernike polynomials of order 0 to n (inclusive) -//! evaluated at r -//============================================================================== - -extern "C" double evaluate_zernike_rad_c(int n, const double data[], double r); - //============================================================================== //! Rotate the direction cosines through a polar angle whose cosine is mu and //! through an azimuthal angle sampled uniformly.