1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
/*
* Close down the graphics processing. This gets called only at driver
* termination time.
*/
#include <grass/gis.h>
#include "driverlib.h"
#include "htmlmap.h"
/* sreen dimensions defined in Graph_Set.c */
/* point in polygon test by Randolph Franklin */
/* http://www.ecse.rpi.edu/Homepages/wrf/ */
/* adapted for integer coordinates */
static int pnpoly(int npol, int *xp, int *yp, int x, int y)
{
int i, j, c = 0;
for (i = 0, j = npol - 1; i < npol; j = i++) {
if ((((yp[i] <= y) && (y < yp[j])) || ((yp[j] <= y) && (y < yp[i]))) &&
(x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i]))
c = !c;
}
return c;
}
void HTML_Graph_close(void)
{
struct MapPoly *poly, *test_poly;
int i;
int inside;
/*
* examine the list of polygons, if a polygon wholly exists inside of
* another polygon, then remove it.
*
*/
for (poly = html.head; poly != NULL; poly = poly->next_poly) {
for (test_poly = html.head; test_poly != NULL;
test_poly = test_poly->next_poly) {
if (poly == test_poly) {
continue; /* don't check ourselves */
}
inside = 1;
for (i = 0; i < poly->num_pts && inside; i++) {
inside =
pnpoly(test_poly->num_pts, test_poly->x_pts,
test_poly->y_pts, poly->x_pts[i], poly->y_pts[i]);
}
if (inside) {
poly->num_pts = 0; /* mark polygon as having no points */
break;
}
}
}
/*
* write any beginning prologue appropriate for the map type
*/
switch (html.type) {
case APACHE:
fprintf(html.output, "#base _base_\n#default _default_\n");
break;
case RAW:
break;
case CLIENT:
fprintf(html.output, "<MAP NAME=\"map\">\n");
break;
}
/*
* write the polygons in a specific format
*/
for (poly = html.head; poly != NULL; poly = poly->next_poly) {
if (poly->num_pts >= 3) {
switch (html.type) {
case APACHE:
fprintf(html.output, "poly %s", poly->url);
for (i = 0; i < poly->num_pts; i++) {
fprintf(html.output, " %d,%d", poly->x_pts[i],
poly->y_pts[i]);
}
fprintf(html.output, " %d,%d", poly->x_pts[0], poly->y_pts[0]);
fprintf(html.output, "\n");
break;
case RAW:
fprintf(html.output, "%s", poly->url);
for (i = 0; i < poly->num_pts; i++) {
fprintf(html.output, " %d %d", poly->x_pts[i],
poly->y_pts[i]);
}
fprintf(html.output, " %d %d", poly->x_pts[0], poly->y_pts[0]);
fprintf(html.output, "\n");
break;
case CLIENT:
fprintf(html.output,
"<AREA SHAPE=\"POLY\"\n HREF=\"%s\"\n ALT=\"%s\"\n "
"COORDS=\"",
poly->url, poly->url);
for (i = 0; i < poly->num_pts; i++) {
if (i > 0)
fprintf(html.output, ", ");
/*
* don't add newlines, which confuses the weak-minded
* i.e., ms internet exploder :-(
* was: if (i % 8 == 0 && i != 0) fprintf(html.output,"\n
* ");
*/
fprintf(html.output, "%d,%d", poly->x_pts[i],
poly->y_pts[i]);
}
fprintf(html.output, ", %d,%d", poly->x_pts[0], poly->y_pts[0]);
fprintf(html.output, "\">\n");
break;
}
}
}
/* final stuff, if needed */
switch (html.type) {
case APACHE:
break;
case RAW:
break;
case CLIENT:
fprintf(html.output,
"<AREA SHAPE=\"RECT\" NOHREF COORDS=\"%d,%d %d,%d\">\n", 0, 0,
screen_width, screen_height);
fprintf(html.output, "</MAP>\n");
break;
}
/*
* close file
*/
fclose(html.output);
}
|