5
* PlotProfile(profile,letter,min,max)
7
* struct Profile profile; - profile structure
8
* int min, - min cell-file value
9
* max; - max cell-file calue
11
* PURPOSE: To plot a profile in the currently chosen on-screen window.
12
* The profile's length is scaled to fit along the x-axis. The profile
13
* is scaled to fit the maximum and minimum cell-file values (instead of
14
* the maximum and minimum profile values) on the y-axis.
18
* 1) assumes that R_open_driver has already been called.
20
* 2) assumes that the profile structure has been both initialized by
21
* a call to InitProfile, and filled with data by a call to ExtractProfile.
25
* 10560 Arrowhead Drive
26
* Fairfax, Virginia 22030
31
#include <grass/raster.h>
32
#include <grass/display.h>
37
#define YAXIS_END 0.77
38
#define XAXIS_END 0.95
39
#define TEXT_HEIGHT 0.11
40
#define TEXT_COLUMN 0.07
42
double _get_cat(UCAT *, int);
44
int PlotProfile(struct Profile profile, char *letter, int min, int max)
46
struct ProfileNode *ptr;
51
i, t, b, l, r, tt, tb, tl, tr, height, width, x_line[3], y_line[3];
52
double yoffset, xoffset, xscale, yscale;
54
/* get current graphics window coordinates */
55
D_get_screen_window(&t, &b, &l, &r);
56
R_set_window(t, b, l, r);
58
/* erase current graphics window to black */
59
R_standard_color(D_translate_color(DEFAULT_BG_COLOR));
62
/* create axis lines */
65
x_line[0] = x_line[1] = l + (int)(ORIGIN_X * width);
66
x_line[2] = l + (int)(XAXIS_END * width);
67
y_line[0] = b - (int)(YAXIS_END * height);
68
y_line[1] = y_line[2] = b - (int)(ORIGIN_Y * height);
69
R_standard_color(D_translate_color(DEFAULT_FG_COLOR));
71
/* figure scaling factors and offsets for profile line */
72
xscale = ((double)(x_line[2] - x_line[1]) / ((double)profile.count));
73
yscale = ((double)(y_line[1] - y_line[0])) / ((double)(max - min));
74
yoffset = (double)(y_line[1]);
75
xoffset = (double)x_line[1];
79
R_move_abs((int)xoffset, (int)yoffset);
80
for (i = 0; i <= profile.count; i++) {
84
R_cont_abs((int)(xoffset + xscale * i),
85
(int)(yoffset - yscale * _get_cat(&ptr->cat, min)));
86
R_cont_abs((int)(xoffset + xscale * (i + 1.0)),
87
(int)(yoffset - yscale * _get_cat(&ptr->cat, min)));
90
R_cont_abs((int)(xoffset + xscale * i),
91
(int)(yoffset - yscale * _get_cat(&ptr->cat, min)));
94
R_standard_color(D_translate_color("red"));
95
R_polyline_abs(x_line, y_line, 3);
97
/* loop until coordinate text is sized correctly to fit in window */
98
text_height = TEXT_HEIGHT * (b - t);
99
text_width = text_height * 0.8;
100
R_standard_color(D_translate_color(DEFAULT_FG_COLOR));
102
if (G_projection() == PROJECTION_LL)
103
sprintf(txt_buf, "%s: From (%10.6f,%10.6f) to (%10.6f,%10.6f)",
104
letter, profile.e1, profile.n1, profile.e2, profile.n2);
106
sprintf(txt_buf, "%s: From (%10.2f,%10.2f) to (%10.2f,%10.2f)",
107
letter, profile.e1, profile.n1, profile.e2, profile.n2);
111
R_get_text_box(txt_buf, &tt, &tb, &tl, &tr);
112
if ((tr - tl) >= (r - l)) {
115
R_text_size(text_width, text_height);
121
R_move_abs((int)(l + 0.5 * (r - l) - .5 * (tr - tl)),
122
(int)(t + .12 * (b - t)));
125
/* set text size for y-axis labels */
126
text_height = TEXT_HEIGHT * (b - t);
127
text_width = text_height * 0.8;
128
R_text_size(text_width, text_height);
130
/* plot y-axis label (bottom) */
131
sprintf(txt_buf, "%d", min);
132
R_get_text_box(txt_buf, &tt, &tb, &tl, &tr);
133
R_move_abs((int)(l + TEXT_COLUMN * (r - l) - .5 * (tr - tl)),
134
(int)(yoffset + .5 * (tb - tt)));
137
/* plot y-axis label (top) */
138
sprintf(txt_buf, "%d", max);
139
R_get_text_box(txt_buf, &tt, &tb, &tl, &tr);
140
R_move_abs((int)(l + TEXT_COLUMN * (r - l) - .5 * (tr - tl)),
141
(int)(y_line[0] + .5 * (tb - tt)));
149
double _get_cat(UCAT * theCat, int min)
151
switch (theCat->type) {
153
if (theCat->val.c >= min)
154
return (double)(theCat->val.c - (double)min);
158
if (theCat->val.f >= min)
159
return (double)(theCat->val.f - (double)min);
163
if (theCat->val.d >= min)
164
return (theCat->val.d - (double)min);
167
default: /* Shouldn't happen */
172
/* vim: set softtabstop=4 shiftwidth=4 expandtab: */