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