6
#include <grass/raster.h>
8
#include "local_proto.h"
14
int top, bottom, left, right;
17
static int uparrow(struct box *, int);
18
static int downarrow(struct box *, int);
19
static int pick(int, int);
20
static int done(void);
21
static int cancel_which(void);
22
static int inbox(struct box *, int, int);
23
static int dotext(char *, int, int, int, int, int, int);
24
static int compute_transformation(void);
25
static int to_file(void);
26
static int askfile(void);
27
static int to_printer(void);
28
static int do_report(FILE *);
29
static int printcentered(FILE *, char *, int);
30
static int show_point(int, int);
33
static struct box more, less, report;
34
static int height, size, edge, nlines;
35
static int curp, first_point;
37
static double *xres, *yres, *gnd;
39
static int xmax, ymax, gmax;
43
sprintf (buf, "%3d ", n)
44
#define FMT1(buf,xres,yres,gnd) \
45
sprintf (buf, "%5.1f %5.1f %6.1f ", xres,yres,gnd)
46
#define LHEAD1 " error "
47
#define LHEAD2 " # col row target"
49
#define FMT2(buf,e1,n1,e2,n2) \
50
sprintf (buf, "%9.1f %9.1f %9.1f %9.1f ", e1,n1,e2,n2)
51
#define RHEAD1 " image target"
52
#define RHEAD2 " east north east north"
54
#define BACKGROUND GREY
59
static Objects objects[] = {
60
MENU("DONE", done, &use),
61
MENU("PRINT", to_printer, &use),
62
MENU("FILE", to_file, &use),
63
INFO(" Double click on point to be included/excluded ", &use),
73
int top, bottom, left, right, width, middle, nums;
75
/* to give user a response of some sort */
76
Menu_msg("Preparing analysis ...");
79
* build a popup window at center of the screen.
80
* 35% the height and wide enough to hold the report
84
/* height of 1 line, based on NLINES taking up 35% vertical space */
85
height = (.35 * (SCREEN_BOTTOM - SCREEN_TOP)) / NLINES + 1;
87
/* size of text, 80% of line height */
89
size = tsize - 2; /* fudge for computing pixels width of text */
91
/* indent for the text */
92
edge = .1 * height + 1;
94
/* determine the length, in chars, of printed line */
96
nums = strlen(buf) * size;
97
FMT1(buf, 0.0, 0.0, 0.0);
100
FMT2(buf, 0.0, 0.0, 0.0, 0.0);
103
/* width is for max chars plus sidecar for more/less */
104
width = len * size + nums + 2 * height;
105
if ((SCREEN_RIGHT - SCREEN_LEFT) < width)
106
width = SCREEN_RIGHT - SCREEN_LEFT;
109
/* define the window */
110
bottom = VIEW_MENU->top - 1;
111
top = bottom - height * NLINES;
115
right = left + width;
116
middle += left + nums;
119
/* save what is under this area, so it can be restored */
120
R_panel_save(tempfile1, top, bottom + 1, left, right + 1);
123
/* fill it with white */
124
R_standard_color(BACKGROUND);
125
R_box_abs(left, top, right, bottom);
127
right -= 2 * height; /* reduce it to exclude sidecar */
129
/* print messages in message area */
130
R_text_size(tsize, tsize);
133
/* setup the more/less boxes in the sidecar */
134
R_standard_color(BLACK);
136
less.bottom = top + 2 * height;
138
less.right = right + 2 * height;
139
Outline_box(less.top, less.bottom, less.left, less.right);
141
more.top = bottom - 2 * height;
142
more.bottom = bottom;
144
more.right = right + 2 * height;
145
Outline_box(more.top, more.bottom, more.left, more.right);
148
* top two lines are for column labels
149
* last two line is for overall rms error.
154
/* allocate predicted values */
155
xres = (double *)G_calloc(group.points.count, sizeof(double));
156
yres = (double *)G_calloc(group.points.count, sizeof(double));
157
gnd = (double *)G_calloc(group.points.count, sizeof(double));
159
/* compute transformation for the first time */
160
compute_transformation();
163
/* put head on the report */
165
dotext(LHEAD1, cury, cury + height, left, middle, 0, BLACK);
166
dotext(RHEAD1, cury, cury + height, middle, right - 1, 0, BLACK);
168
dotext(LHEAD2, cury, cury + height, left, middle, 0, BLACK);
169
dotext(RHEAD2, cury, cury + height, middle, right - 1, 0, BLACK);
171
R_move_abs(left, cury - 1);
172
R_cont_abs(right, cury - 1);
174
/* isolate the sidecar */
175
R_move_abs(right, top);
176
R_cont_abs(right, bottom);
178
/* define report box */
181
report.right = right;
186
R_text_size(tsize, tsize);
189
cury = top + 2 * height;
191
if (line >= nlines || curp >= group.points.count)
194
if (group.equation_stat > 0 && group.points.status[curp] > 0) {
196
FMT1(buf, xres[curp], yres[curp], gnd[curp]);
197
if (curp == xmax || curp == ymax || curp == gmax)
199
dotext(buf, cury, cury + height, nums, middle, 0, color);
201
else if (group.points.status[curp] > 0)
202
dotext("?", cury, cury + height, nums, middle, 1, BLACK);
204
dotext("not used", cury, cury + height, nums, middle, 1,
208
dotext(buf, cury, cury + height, left, nums, 0, BLACK);
210
group.points.e1[curp],
211
group.points.n1[curp],
212
group.points.e2[curp], group.points.n2[curp]);
213
dotext(buf, cury, cury + height, middle, right - 1, 0, BLACK);
218
report.bottom = cury;
219
downarrow(&more, curp < group.points.count ? BLACK : BACKGROUND);
220
uparrow(&less, first_point > 0 ? BLACK : BACKGROUND);
221
R_standard_color(BACKGROUND);
222
R_box_abs(left, cury, right - 1, bottom);
223
if (group.equation_stat < 0) {
225
strcpy(buf, "Poorly placed control points");
227
else if (group.equation_stat == 0) {
229
strcpy(buf, "No active control points");
233
sprintf(buf, "Overall rms error: %.2f", rms);
235
dotext(buf, bottom - height, bottom, left, right - 1, 0, color);
236
R_standard_color(BLACK);
237
R_move_abs(left, bottom - height);
238
R_cont_abs(right - 1, bottom - height);
242
if (Input_pointer(objects) < 0)
246
/* all done. restore what was under the window */
247
right += 2 * height; /* move it back over the sidecar */
248
R_standard_color(BACKGROUND);
249
R_box_abs(left, top, right, bottom);
250
R_panel_restore(tempfile1);
251
R_panel_delete(tempfile1);
257
I_put_control_points(group.name, &group.points);
259
return 0; /* return but don't QUIT */
263
static int uparrow(struct box *box, int color)
265
R_standard_color(color);
266
Uparrow(box->top + edge, box->bottom - edge, box->left + edge,
272
static int downarrow(struct box *box, int color)
274
R_standard_color(color);
275
Downarrow(box->top + edge, box->bottom - edge, box->left + edge,
281
static int pick(int x, int y)
288
if (inbox(&more, x, y)) {
289
if (curp >= group.points.count)
295
if (inbox(&less, x, y)) {
296
if (first_point == 0)
298
first_point -= nlines;
304
if (!inbox(&report, x, y)) {
308
n = (y - report.top) / height;
309
if (n == cur) { /* second click! */
310
group.points.status[first_point + n] =
311
!group.points.status[first_point + n];
312
compute_transformation();
313
show_point(first_point + n, 1);
319
show_point(first_point + n, 0);
320
R_standard_color(RED);
321
Outline_box((report.top + n * height) + 1, report.top + (n + 1) * height,
322
report.left, report.right - 1);
325
return 0; /* ignore first click */
329
static int done(void)
335
static int cancel_which(void)
338
R_standard_color(BACKGROUND);
339
Outline_box((report.top + which * height) + 1,
340
report.top + (which + 1) * height, report.left,
342
show_point(first_point + which, 1);
349
static int inbox(struct box *box, int x, int y)
351
return (x > box->left && x < box->right && y > box->top &&
355
static int dotext(char *text,
356
int top, int bottom, int left, int right, int centered,
359
R_standard_color(BACKGROUND);
360
R_box_abs(left, top, right, bottom);
361
R_standard_color(color);
362
R_move_abs(left + 1 + edge, bottom - 1 - edge);
364
R_move_rel((right - left - strlen(text) * size) / 2, 0);
365
R_set_window(top, bottom, left, right); /* for text clipping */
367
R_set_window(SCREEN_TOP, SCREEN_BOTTOM, SCREEN_LEFT, SCREEN_RIGHT);
372
static int compute_transformation(void)
375
double d, d1, d2, sum;
376
double e1, e2, n1, n2;
377
double xval, yval, gval;
379
xmax = ymax = gmax = 0;
380
xval = yval = gval = 0.0;
383
if (group.equation_stat <= 0)
386
/* compute the row,col error plus ground error
387
* keep track of largest and second largest error
392
for (n = 0; n < group.points.count; n++) {
393
if (group.points.status[n] <= 0)
396
I_georef(group.points.e2[n], group.points.n2[n], &e1, &n1, group.E21,
398
I_georef(group.points.e1[n], group.points.n1[n], &e2, &n2, group.E12,
401
if ((d = xres[n] = e1 - group.points.e1[n]) < 0)
408
if ((d = yres[n] = n1 - group.points.n1[n]) < 0)
415
/* compute ground error (ie along diagonal) */
416
d1 = e2 - group.points.e2[n];
417
d2 = n2 - group.points.n2[n];
418
d = d1 * d1 + d2 * d2;
419
sum += d; /* add it to rms sum, before taking sqrt */
422
if (d > gval) { /* is this one the max? */
428
/* compute overall rms error */
430
rms = sqrt(sum / count);
435
static int to_file(void)
441
if (Input_other(askfile, "Keyboard") < 0) {
445
fd = fopen(buf, "w");
447
sprintf(msg, "** Unable to create file %s\n", buf);
449
Curses_write_window(PROMPT_WINDOW, 2, 1, msg);
454
sprintf(msg, "Report saved in file %s\n", buf);
455
Curses_write_window(PROMPT_WINDOW, 2, 1, msg);
460
static int askfile(void)
462
char file[GNAME_MAX];
465
Curses_prompt_gets("Enter file to hold report: ", file);
469
if (G_index(file, '/'))
472
sprintf(buf, "%s/%s", G_home(), file);
473
if (access(buf, 0) != 0)
475
sprintf(buf, "** %s already exists. choose another file", file);
477
Curses_write_window(PROMPT_WINDOW, 2, 1, buf);
483
static int to_printer(void)
488
Menu_msg("sending report to printer ...");
490
fd = popen("lpr", "w");
496
static int do_report(FILE * fd)
502
fprintf(fd, "LOCATION: %-20s GROUP: %-20s MAPSET: %s\n\n",
503
G_location(), group.name, G_mapset());
504
fprintf(fd, "%15sAnalysis of control point registration\n\n", "");
505
fprintf(fd, "%s %s\n", LHEAD1, RHEAD1);
506
fprintf(fd, "%s %s\n", LHEAD2, RHEAD2);
508
FMT1(buf, 0.0, 0.0, 0.0);
511
for (n = 0; n < group.points.count; n++) {
513
fprintf(fd, "%s", buf);
514
if (group.equation_stat > 0 && group.points.status[n] > 0) {
515
FMT1(buf, xres[n], yres[n], gnd[n]);
516
fprintf(fd, "%s", buf);
518
else if (group.points.status[n] > 0)
519
printcentered(fd, "?", width);
521
printcentered(fd, "not used", width);
524
group.points.n1[n], group.points.e2[n], group.points.n2[n]);
525
fprintf(fd, " %s\n", buf);
528
if (group.equation_stat < 0)
529
fprintf(fd, "Poorly place control points\n");
530
else if (group.equation_stat == 0)
531
fprintf(fd, "No active control points\n");
533
fprintf(fd, "Overall rms error: %.2f\n", rms);
538
static int printcentered(FILE * fd, char *buf, int width)
545
n = (width - len) / 2;
547
for (i = 0; i < n; i++)
549
fprintf(fd, "%s", buf);
557
static int show_point(int n, int true_color)
560
R_standard_color(ORANGE);
561
else if (group.points.status[n])
562
R_standard_color(GREEN);
564
R_standard_color(RED);
565
display_one_point(VIEW_MAP1, group.points.e1[n], group.points.n1[n]);