3
#include "orthophoto.h"
5
/* TODO: replace with imagery lib I_compute_georef_equations() */
7
static int floating_exception;
8
static void catch(int);
9
static double determinant(double, double, double, double, double,
10
double, double, double, double);
12
/* find coefficients A,B,C for e2 = A + B*e1 + C*n1
13
* also compute the reverse equations
15
* return 0 if no points
19
* method is least squares.
20
* the least squares problem reduces to solving the following
21
* system of equations for A,B,C
23
* s0*A + s1*B + s2*C = x0
24
* s1*A + s3*B + s4*C = x1
25
* s2*A + s4*B + s5*C = x2
29
* | x0 s1 s2 | | s0 x0 s2 | | s0 s1 x0 |
30
* | x1 s3 s4 | | s1 x1 s4 | | s1 s3 x1 |
31
* | x2 s4 s5 | | s2 x2 s5 | | s2 s4 x2 |
32
* A = ------------ B = ------------ C = ------------
33
* | s0 s1 s2 | | s0 s1 s2 | | s0 s1 s2 |
34
* | s1 s3 s4 | | s1 s3 s4 | | s1 s3 s4 |
35
* | s2 s4 s5 | | s2 s4 s5 | | s2 s4 s5 |
40
I_compute_ref_equations(struct Ortho_Photo_Points *cp, double E12[3],
41
double N12[3], double E21[3], double N21[3])
43
double s0, s1, s2, s3, s4, s5;
50
s0 = s1 = s2 = s3 = s4 = s5 = 0.0;
51
for (i = 0; i < cp->count; i++) {
52
if (cp->status[i] <= 0)
57
s3 += cp->e1[i] * cp->e1[i];
58
s4 += cp->e1[i] * cp->n1[i];
59
s5 += cp->n1[i] * cp->n1[i];
64
floating_exception = 0;
65
sigfpe = signal(SIGFPE, catch);
69
for (i = 0; i < cp->count; i++) {
70
if (cp->status[i] <= 0)
73
x1 += cp->e1[i] * cp->e2[i];
74
x2 += cp->n1[i] * cp->e2[i];
77
det = determinant(s0, s1, s2, s1, s3, s4, s2, s4, s5);
79
signal(SIGFPE, sigfpe);
82
E12[0] = determinant(x0, s1, s2, x1, s3, s4, x2, s4, s5) / det;
83
E12[1] = determinant(s0, x0, s2, s1, x1, s4, s2, x2, s5) / det;
84
E12[2] = determinant(s0, s1, x0, s1, s3, x1, s2, s4, x2) / det;
88
for (i = 0; i < cp->count; i++) {
89
if (cp->status[i] <= 0)
92
x1 += cp->e1[i] * cp->n2[i];
93
x2 += cp->n1[i] * cp->n2[i];
96
det = determinant(s0, s1, s2, s1, s3, s4, s2, s4, s5);
98
signal(SIGFPE, sigfpe);
101
N12[0] = determinant(x0, s1, s2, x1, s3, s4, x2, s4, s5) / det;
102
N12[1] = determinant(s0, x0, s2, s1, x1, s4, s2, x2, s5) / det;
103
N12[2] = determinant(s0, s1, x0, s1, s3, x1, s2, s4, x2) / det;
105
/* the inverse equations */
107
s0 = s1 = s2 = s3 = s4 = s5 = 0.0;
108
for (i = 0; i < cp->count; i++) {
109
if (cp->status[i] <= 0)
114
s3 += cp->e2[i] * cp->e2[i];
115
s4 += cp->e2[i] * cp->n2[i];
116
s5 += cp->n2[i] * cp->n2[i];
121
for (i = 0; i < cp->count; i++) {
122
if (cp->status[i] <= 0)
125
x1 += cp->e2[i] * cp->e1[i];
126
x2 += cp->n2[i] * cp->e1[i];
129
det = determinant(s0, s1, s2, s1, s3, s4, s2, s4, s5);
131
signal(SIGFPE, sigfpe);
134
E21[0] = determinant(x0, s1, s2, x1, s3, s4, x2, s4, s5) / det;
135
E21[1] = determinant(s0, x0, s2, s1, x1, s4, s2, x2, s5) / det;
136
E21[2] = determinant(s0, s1, x0, s1, s3, x1, s2, s4, x2) / det;
140
for (i = 0; i < cp->count; i++) {
141
if (cp->status[i] <= 0)
144
x1 += cp->e2[i] * cp->n1[i];
145
x2 += cp->n2[i] * cp->n1[i];
148
det = determinant(s0, s1, s2, s1, s3, s4, s2, s4, s5);
150
signal(SIGFPE, sigfpe);
153
N21[0] = determinant(x0, s1, s2, x1, s3, s4, x2, s4, s5) / det;
154
N21[1] = determinant(s0, x0, s2, s1, x1, s4, s2, x2, s5) / det;
155
N21[2] = determinant(s0, s1, x0, s1, s3, x1, s2, s4, x2) / det;
157
signal(SIGFPE, sigfpe);
158
return floating_exception ? -1 : 1;
161
static double determinant(double a, double b, double c, double d,
162
double e, double f, double g, double h, double i)
164
/* compute determinant of 3x3 matrix
169
return a * (e * i - f * h) - b * (d * i - f * g) + c * (d * h - e * g);
172
static void catch(int n)
174
floating_exception = 1;