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