/* * Function: get_drz_position_free * The function transforms distorted coordinates image to undistorted * image coordinates. The size of the input and output image are free. * * Parameters: * @param in_point - the coordinates in the distorted frame * @param drzcoeffs - the drizzle coefficients * @param pix_in - the image dimension of the distorted frame * @param pix_out - the image dimension of the distorted frame * * Returns: * @return: ou_point - the coordinates in the undistorted frame */ d_point get_drz_position_free(d_point in_point, gsl_matrix *drzcoeffs, px_point pix_in, px_point pix_out) { d_point ou_point; double xr, yr; double xn, yn; // transform the input coos into the drizzle system xr = in_point.x - ((double)(pix_in.x/2)+1.0); yr = in_point.y - ((double)(pix_in.y/2)+1.0); // ou_point.x = evaln(xr,yr,drzcoeffs,0); // ou_point.y = evaln(xr,yr,drzcoeffs,1); // get the undistorted coos in the drizzle system xn = evaln(xr,yr,drzcoeffs,0); yn = evaln(xr,yr,drzcoeffs,1); // transform back into the image system, // assuming identical image dimensions ou_point.x = xn + ((double)(pix_out.x/2)+1.0); ou_point.y = yn + ((double)(pix_out.y/2)+1.0); // return the undistorted coos return ou_point; }
static inline_macro int drizzle_polynomial(void* state, const double xd, const double yd, const integer_t n, const double* xin /*[n]*/, const double* yin /*[n]*/, /* Output parameters */ double* xout, double* yout, struct driz_error_t* error) { struct mapping_param_t* m = (struct mapping_param_t*)state; double xdoff, ydoff; integer_t i; bool_t new_reference; /* Check for the presence of "refpix" additional information in the coefficients. If it is, set a flag and offset again */ if (m->coeff_type > COEFF_OFFSET / 2) { new_reference = TRUE; m->coeff_type -= COEFF_OFFSET; xdoff = m->xcen - m->x_coeffs[m->num_coeffs - 1] + 1.0; ydoff = m->ycen - m->y_coeffs[m->num_coeffs - 1] + 1.0; m->num_coeffs--; } else { new_reference = FALSE; xdoff = 2.0; ydoff = 2.0; } if (m->coeff_type == 3) { for (i = 0; i < n; ++i) { xout[i] = eval3(xin[i] + xdoff, yin[i] + ydoff, m->x_coeffs) - xdoff; yout[i] = eval3(xin[i] + xdoff, yin[i] + ydoff, m->y_coeffs) - ydoff; } } else if (m->coeff_type == 4) { for (i = 0; i < n; ++i) { xout[i] = eval4(xin[i] + xdoff, yin[i] + ydoff, m->x_coeffs) - xdoff; yout[i] = eval4(xin[i] + xdoff, yin[i] + ydoff, m->y_coeffs) - ydoff; } } else if (m->coeff_type == 5) { for (i = 0; i < n; ++i) { xout[i] = eval5(xin[i] + xdoff, yin[i] + ydoff, m->x_coeffs) - xdoff; yout[i] = eval5(xin[i] + xdoff, yin[i] + ydoff, m->y_coeffs) - ydoff; } } else if (m->coeff_type >= 6 || m->coeff_type == 1 || m->coeff_type == 2) { for (i = 0; i < n; ++i) { if (evaln(xin[i] + xdoff, yin[i] + ydoff, m->x_coeffs, m->coeff_type, &xout[i], error) || evaln(xin[i] + xdoff, yin[i] + ydoff, m->y_coeffs, m->coeff_type, &yout[i], error)) return 1; xout[i] -= xdoff; yout[i] -= ydoff; } } else if (m->coeff_type == -3) { for (i = 0; i < n; ++i) { rad3(xin[i] + xdoff, yin[i] + ydoff, m->x_coeffs, &xout[i], &yout[i]); xout[i] -= xdoff; yout[i] -= ydoff; } } else { driz_error_format_message(error, "Invalid coefficient type %d", m->coeff_type); return 1; } if (new_reference) { m->coeff_type += COEFF_OFFSET; m->num_coeffs++; } return 0; }