29#define M(row, col) m->v[(((row) - 1) * (m->n)) + (col) - 1]
47static int calcls(
struct Control_Points *,
struct MATRIX *,
double *,
double *,
50static double tps_base_func(
const double x1,
const double y1,
const double x2,
52static int solvemat(
struct MATRIX *,
double *,
double *,
double *,
double *);
69 double dist, *
pe, *
pn;
81 *e = E[0] + e1 * E[1] + n1 * E[2];
82 *n =
N[0] + e1 *
N[1] + n1 *
N[2];
84 for (i = 0,
j = 0; i <
cp->count; i++) {
85 if (
cp->status[i] > 0) {
87 dist = tps_base_func(e1, n1,
pe[i],
pn[i]);
89 *e += E[
j + 3] * dist;
90 *n +=
N[
j + 3] * dist;
112 double xmax, xmin, ymax, ymin;
121 if (
cp->status[i] > 0)
131 xmin = xmax =
cp->e1[0];
132 ymin = ymax =
cp->n1[0];
136 for (i = 0; i <
cp->count; i++) {
137 if (
cp->status[i] > 0) {
141 xmax =
MAX(xmax,
xx);
142 xmin =
MIN(xmin,
xx);
143 ymax =
MAX(ymax,
yy);
144 ymin =
MIN(ymin,
yy);
167 xmin = xmax =
cp->e2[0];
168 ymin = ymax =
cp->n2[0];
171 for (i = 0; i <
cp->count; i++) {
172 if (
cp->status[i] > 0) {
176 xmax =
MAX(xmax,
xx);
177 xmin =
MIN(xmin,
xx);
178 ymax =
MAX(ymax,
yy);
179 ymin =
MIN(ymin,
yy);
204 G_message(
_(
"Calculating forward transformation coefficients"));
221 G_message(
_(
"Calculating backward transformation coefficients"));
254 if (
cp->status[i] > 0)
265 "I_compute_georef_equations_tps()");
269 "I_compute_georef_equations_tps()");
273 "I_compute_georef_equations_tps()");
279 "I_compute_georef_equations_tps()");
283 "I_compute_georef_equations_tps()");
285 status = calcls(
cp, &
m, a,
b, *E, *
N);
303 double b[],
double E[],
313 for (i = 1; i <=
m->n; i++) {
314 for (
j = i;
j <=
m->n;
j++) {
319 a[i - 1] =
b[i - 1] = 0.0;
325 for (n = 0; n <
cp->count; n++) {
326 if (
cp->status[n] > 0) {
346 for (n = 0; n <
cp->count; n++) {
347 if (
cp->status[n] > 0) {
351 for (o = 0; o <= n; o++) {
352 if (
cp->status[o] > 0) {
354 M(i + 3,
j + 3) = tps_base_func(
cp->e1[n],
cp->n1[n],
355 cp->e1[o],
cp->n1[o]);
358 M(
j + 3, i + 3) =
M(i + 3,
j + 3);
374 return solvemat(
m, a,
b, E,
N);
396static int solvemat(
struct MATRIX *
m,
double a[],
double b[],
double E[],
403 for (i = 1; i <=
m->n; i++) {
411 for (
i2 = i + 1;
i2 <=
m->n;
i2++) {
429 for (
j2 = 1;
j2 <=
m->n;
j2++) {
436 a[
imark - 1] = a[i - 1];
447 for (
i2 = 1;
i2 <=
m->n;
i2++) {
452 a[
i2 - 1] -= factor * a[i - 1];
453 b[
i2 - 1] -= factor *
b[i - 1];
462 for (i = 1; i <=
m->n; i++) {
463 E[i - 1] = a[i - 1] /
M(i, i);
464 N[i - 1] =
b[i - 1] /
M(i, i);
470static double tps_base_func(
const double x1,
const double y1,
const double x2,
476 if ((x1 == x2) && (y1 == y2))
479 dist = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
481 return dist *
log(dist) * 0.5;
void G_percent(long, long, int)
Print percent complete messages.
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_message(const char *,...) __attribute__((format(printf
int I_georef_tps(double e1, double n1, double *e, double *n, double *E, double *N, struct Control_Points *cp, int fwd)
int I_compute_georef_equations_tps(struct Control_Points *cp, double **E12tps, double **N12tps, double **E21tps, double **N21tps)