-
-
Notifications
You must be signed in to change notification settings - Fork 286
/
display.c
241 lines (209 loc) · 6.74 KB
/
display.c
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/* Author: Adam Laza, GSoC 2016
* based on d.vect.thematic/area.c
*
*/
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <grass/gis.h>
#include <grass/symbol.h>
#include <grass/vector.h>
#include <grass/display.h>
#include <grass/colors.h>
#include <grass/dbmi.h>
#include <grass/glocale.h>
#include "plot.h"
#include "local_proto.h"
int display_lines(struct Map_info *Map, struct cat_list *Clist,
int chcat, const char *symbol_name, double size,
int default_width, dbCatValArray * cvarr, double *breaks,
int nbreaks, const struct color_rgb *colors, const struct
color_rgb *bcolor)
{
int ltype, line, nlines;
struct line_pnts *Points;
struct line_cats *Cats;
int n_points, n_lines, n_centroids, n_boundaries, n_faces;
RGBA_Color *primary_color, *secondary_color;
SYMBOL *Symb;
Symb = NULL;
double breakval = 0.0;
int cat;
dbCatVal *cv = NULL;
int i;
primary_color = G_malloc(sizeof(RGBA_Color));
primary_color->a = RGBA_COLOR_OPAQUE;
secondary_color = G_malloc(sizeof(RGBA_Color));
secondary_color->a = RGBA_COLOR_OPAQUE;
Points = Vect_new_line_struct();
Cats = Vect_new_cats_struct();
/* dynamic symbols for points */
Symb = S_read(symbol_name);
if (!Symb)
G_warning(_("Unable to read symbol <%s>, unable to display points"),
symbol_name);
else
S_stroke(Symb, size, 0.0, 0);
Vect_rewind(Map);
nlines = -1;
line = 0;
n_points = n_lines = 0;
n_centroids = n_boundaries = 0;
n_faces = 0;
while (TRUE) {
line++;
if (nlines > -1) {
if (line > nlines)
break;
ltype = Vect_read_line(Map, Points, Cats, line);
}
else {
ltype = Vect_read_next_line(Map, Points, Cats);
if (ltype == -1) {
G_fatal_error(_("Unable to read vector map"));
}
else if (ltype == -2) { /* EOF */
break;
}
}
cat = *Cats->cat;
if (cat >= 0) {
G_debug(3, "display line %d, cat %d", line, cat);
/* Get value of data for this area */
if (db_CatValArray_get_value(cvarr, cat, &cv) != DB_OK) {
G_debug(3, "No value found for cat %i", cat);
}
else {
db_CatValArray_get_value(cvarr, cat, &cv);
breakval = (cvarr->ctype == 2 ? cv->val.i : cv->val.d);
}
}
/* find out into which class breakval falls */
i = 0;
while (breakval > breaks[i] && i < nbreaks)
i++;
primary_color->r = colors[i].r;
primary_color->g = colors[i].g;
primary_color->b = colors[i].b;
if (bcolor != NULL) {
secondary_color->r = bcolor->r;
secondary_color->g = bcolor->g;
secondary_color->b = bcolor->b;
}
else
secondary_color->a = 0;
draw_line(ltype, line, Points, Cats, chcat, size, default_width,
Clist, Symb, primary_color, &n_points, &n_lines,
&n_centroids, &n_boundaries, &n_faces, secondary_color);
}
if (n_points > 0)
G_verbose_message(n_
("%d point plotted", "%d points plotted", n_points),
n_points);
if (n_lines > 0)
G_verbose_message(n_("%d line plotted", "%d lines plotted", n_lines),
n_lines);
if (n_centroids > 0)
G_verbose_message(n_
("%d centroid plotted", "%d centroids plotted",
n_centroids), n_centroids);
if (n_boundaries > 0)
G_verbose_message(n_
("%d boundary plotted", "%d boundaries plotted",
n_boundaries), n_boundaries);
if (n_faces > 0)
G_verbose_message(n_("%d face plotted", "%d faces plotted", n_faces),
n_faces);
Vect_destroy_line_struct(Points);
Vect_destroy_cats_struct(Cats);
G_free(primary_color);
return 0;
}
int draw_line(int ltype, int line,
const struct line_pnts *Points, const struct line_cats *Cats,
int chcat, double size, int default_width,
const struct cat_list *Clist, SYMBOL * Symb,
RGBA_Color * primary_color,
int *n_points, int *n_lines, int *n_centroids,
int *n_boundaries, int *n_faces, RGBA_Color * secondary_color)
{
/* double var_size, rotation; */
int i;
double x0, y0;
double *x, *y;
int found, cat;
/* rotation = 0.0;
var_size = size; */
cat = -1;
if (!ltype)
return 0;
if (Points->n_points == 0)
return 0;
found = FALSE;
if (chcat) {
for (i = 0; i < Cats->n_cats; i++) {
if (Cats->field[i] == Clist->field &&
Vect_cat_in_cat_list(Cats->cat[i], Clist)) {
found = TRUE;
break;
}
}
if (!found)
return 0;
}
else if (Clist->field > 0) {
for (i = 0; i < Cats->n_cats; i++) {
if (Cats->field[i] == Clist->field) {
found = TRUE;
break;
}
}
/* lines with no category will be displayed */
if (Cats->n_cats > 0 && !found)
return 0;
}
G_debug(3, "\tdisplay feature %d, cat %d", line, cat);
/* enough of the prep work, lets start plotting stuff */
x = Points->x;
y = Points->y;
if ((ltype & GV_POINTS)) {
x0 = x[0];
y0 = y[0];
/* skip if the point is outside of the display window */
/* xy < 0 tests make it go ever-so-slightly faster */
if (x0 > D_get_u_east() || x0 < D_get_u_west() ||
y0 < D_get_u_south() || y0 > D_get_u_north())
return 0;
D_line_width(default_width);
D_symbol2(Symb, x0, y0, primary_color, secondary_color);
}
else {
/* Plot the lines */
D_line_width(default_width);
D_RGB_color(primary_color->r, primary_color->g, primary_color->b);
if (Points->n_points == 1) /* line with one coor */
D_polydots_abs(x, y, Points->n_points);
else /* use different user defined render methods */
D_polyline_abs(x, y, Points->n_points);
}
switch (ltype) {
case GV_POINT:
(*n_points)++;
break;
case GV_LINE:
(*n_lines)++;
break;
case GV_CENTROID:
(*n_centroids)++;
break;
case GV_BOUNDARY:
(*n_boundaries)++;
break;
case GV_FACE:
(*n_faces)++;
break;
default:
break;
}
return 1;
}