24 #include <grass/config.h>
26 #if defined(OPENGL_X11) || defined(OPENGL_WINDOWS)
29 #elif defined(OPENGL_AQUA)
30 #include <OpenGL/gl.h>
31 #include <OpenGL/glu.h>
34 #include <grass/gis.h>
35 #include <grass/glocale.h>
36 #include <grass/gstypes.h>
40 static float *Listcats;
41 static int Listnum = 0;
50 #define MAX_LEGEND 256
65 glPushAttrib(GL_VIEWPORT);
67 glMatrixMode(GL_PROJECTION);
77 glViewport(wl, wb, (wr - wl), (wt - wb));
79 gluOrtho2D(-0.5, (wr - wl) + 0.5, -0.5, (wt - wb) + 0.5);
80 glMatrixMode(GL_MODELVIEW);
95 glMatrixMode(GL_PROJECTION);
99 glMatrixMode(GL_MODELVIEW);
124 float curnum, step, start;
129 step = (highnum - lownum) / (
float)numvals;
133 start = step * (
int)(1 + lownum / step);
134 if (start - lownum < .65 * step)
137 for (curnum = start; curnum < (highnum - .65 * step); curnum += step) {
138 vals[num++] = curnum;
155 float newnum, nextnum;
162 while (.5 * newnum > *num) {
163 nextnum = newnum / 10.;
165 if (.5 * newnum > *num)
167 if (.5 * newnum > *num)
173 while (2 * newnum <= *num) {
174 nextnum = newnum * 10.;
176 if (2 * newnum <= *num)
178 if (2 * newnum <= *num)
202 float *rangef,
int *pt)
204 GLint sl, sr, sb, st;
206 int cat_labs = 0, cat_vals = 0, do_invert = 0, discrete = 0;
207 int is_fp, fprec, iprec;
208 struct Categories cats;
210 struct FPRange fp_range;
212 struct Colors colors;
237 if (mapset ==
NULL) {
238 G_warning(_(
"Raster map <%s> not found"), name);
245 G_warning(_(
"Unable to read color file of raster map <%s>"), name);
251 G_warning(_(
"Unable to read category file of raster map <%s>"),
257 if (flags[4] && rangef[0] != -9999. && rangef[1] != -9999.) {
268 G_warning(_(
"Unable to read fp range of raster map <%s>"),
273 if (flags[4] && rangef[0] != -9999.)
275 if (flags[4] && rangef[1] != -9999.)
280 G_warning(_(
"Unable to read range of raster map <%s>"), name);
284 if (flags[4] && rangef[0] != -9999.)
286 if (flags[4] && rangef[1] != -9999.)
294 G_warning(_(
"Range request error for legend"));
318 for (tmp = 1; tmp <
max; tmp *= 10, p1++) ;
320 for (tmp = -1; tmp >
min; tmp *= 10, p2++) ;
322 iprec = (p1 > p2 ? p1 : p2);
358 int i, k, lleg, horiz;
359 int red, green, blue;
361 DCELL tdcell, pdcell;
362 float vert1[2], vert2[2], vert3[2], vert4[2];
368 int labw, maxlabw, numlabs;
369 float labpos, labpt[3];
372 GLint wt, wb, wl, wr;
376 horiz = (sr - sl > st - sb);
380 numlabs = Listnum ? Listnum : max - min + 1;
382 if (is_fp && !Listnum) {
384 G_warning(_(
"Unable to show discrete FP range (use list)"));
388 dividers = (
float *)G_malloc(numlabs *
sizeof(
float));
393 labvals[numlabs + 1] = fmax;
400 if (cat_labs || cat_vals) {
401 for (k = 0; k < numlabs; k++) {
403 tdcell = discrete ? Listcats[k] : labvals[k];
407 if (cat_labs && !cat_vals) {
411 if (cat_labs && cat_vals) {
414 fprec, tdcell, cstr);
416 sprintf(buff,
"%.*lf", fprec, tdcell);
419 sprintf(buff,
"%.*lf", fprec, tdcell);
423 tcell = discrete ? Listnum ?
424 Listcats[k] : min + k : labvals[k];
425 if (cat_labs && !cat_vals)
428 if (cat_labs && cat_vals) {
431 sprintf(buff,
"%*d) %s", iprec, tcell, cstr);
440 if (labw > maxlabw) {
473 vert1[
X] = vert2[
X] = xoff;
474 vert1[
Y] = vert2[
Y] = yoff;
481 stab2 = vert2[
Y] = st - sb + yoff;
482 stab1 = vert1[
Y] = yoff;
484 vert1[
X] = vert2[
X] = sr - sl + xoff;
492 stab2 = vert2[
X] = sr - sl + xoff;
493 stab1 = vert1[
X] = xoff;
495 vert1[
Y] = vert2[
Y] = st - sb + yoff;
499 if (numlabs > lleg / 5)
500 G_warning(_(
"Too many categories to show as discrete!"));
505 incr = do_invert ? -1 : 1;
506 for (k = 0, i = 0; k < lleg; k++) {
507 if (discrete && Listnum)
508 tdcell = Listcats[(
int)((
float)k * numlabs / lleg)];
510 tcell = min + k * (max - min + 1) / lleg;
511 tdcell = fmin + k * (fmax - fmin) / lleg;
515 if (k == 0 || tdcell != pdcell) {
518 &red, &green, &blue, &colors);
520 G_get_color((CELL) tdcell, &red, &green, &blue, &colors);
536 dividers[i++] = *dv1;
566 vert1[
X] = vert2[
X] = 1. + xoff;
567 vert1[
Y] = vert4[
Y] = 1. + yoff;
568 vert3[
X] = vert4[
X] = sr - sl - 1. + xoff;
569 vert3[
Y] = vert2[
Y] = st - sb - 1. + yoff;
581 vert1[
X] = vert2[
X] = xoff;
582 vert1[
Y] = vert4[
Y] = yoff;
583 vert3[
X] = vert4[
X] = sr - sl + xoff;
584 vert3[
Y] = vert2[
Y] = st - sb + yoff;
600 for (k = 0; k < i; k++) {
601 *dv1 = *dv2 = dividers[k];
609 if (cat_labs || cat_vals) {
611 for (k = 0; k < numlabs; k++) {
613 if (discrete && Listnum) {
614 tdcell = Listcats[k];
615 labpos = (k + .5) / numlabs;
620 labpos = (tdcell - fmin) / (fmax - fmin);
624 if (discrete && Listnum) {
626 labpos = (k + .5) / numlabs;
629 tcell = discrete ? min + k : labvals[k];
630 labpos = (tcell - min + .5) / (max - min + 1);
634 labpos = 1. - labpos;
641 if (cat_labs && !cat_vals)
644 if (cat_labs && cat_vals) {
648 fprec, tdcell, cstr);
650 sprintf(buff,
"%*d) %s", iprec, tcell, cstr);
652 sprintf(buff,
"%.*lf", fprec, tdcell);
658 sprintf(buff,
"%.*lf", fprec, tdcell);
664 labpt[
X] = labpos * (sr - sl) + xoff -
675 labpt[
Y] = labpos * (st - sb) + yoff -
703 return (legend_list);
void gsd_end_legend_viewport(void)
ADD.
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
void G_free(void *buf)
Free allocated memory.
void gsd_endlist(void)
End list.
#define RGB_TO_INT(r, g, b, i)
void do_label_display(GLuint fontbase, float *lab_pos, const char *txt)
Display label.
int G_free_colors(struct Colors *colors)
free color structure memory
int gsd_makelist(void)
ADD.
void GS_done_draw(void)
Draw done, swap buffers.
void gsd_colormode(int cm)
Set color mode.
void gsd_color_func(unsigned int col)
Set current color.
int G_read_colors(const char *name, const char *mapset, struct Colors *colors)
read map layer color table
int G_read_range(const char *name, const char *mapset, struct Range *range)
read raster range
int G_read_cats(const char *name, const char *mapset, struct Categories *pcats)
read raster category file
int G_raster_map_is_fp(const char *name, const char *mapset)
Check if raster map is floating-point.
int G_get_d_raster_color(const DCELL *rast, int *red, int *grn, int *blu, struct Colors *colors)
Gets color for a DCELL raster.
void gsd_pushmatrix(void)
Push the current matrix stack.
int G_free_cats(struct Categories *pcats)
free category structure memory
int gsd_get_txtheight(int size)
Get text height.
int G_get_range_min_max(const struct Range *range, CELL *min, CELL *max)
get range min and max
void gsd_bgnlist(int listno, int do_draw)
ADD.
char * G_get_cat(CELL num, struct Categories *pcats)
get a category label
char * G_find_cell2(const char *name, const char *mapset)
find a raster map (look but don't touch)
void gsd_endline(void)
End line.
int G_get_color(CELL n, int *red, int *grn, int *blu, struct Colors *colors)
Get a category color.
int get_txtxoffset(void)
Get text offset.
char * G_get_d_raster_cat(DCELL *rast, struct Categories *pcats)
given a DCELL value val Returns pointer to a string describing category.
GLuint gsd_put_legend(const char *name, GLuint fontbase, int size, int *flags, float *rangef, int *pt)
Put legend.
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G_get_fp_range_min_max(const struct FPRange *range, DCELL *min, DCELL *max)
Extract the min/max from the range structure r. If the range structure has no defined min/max (first!...
int gsd_get_nice_range(float lownum, float highnum, int numvals, float *vals)
ADD.
void gsd_bgn_legend_viewport(GLint wl, GLint wb, GLint wr, GLint wt)
ADD.
void gsd_linewidth(short n)
Set width of rasterized lines.
int G_read_fp_range(const char *name, const char *mapset, struct FPRange *drange)
Read the floating point range file f_range. This file is written in binary using XDR format...
void gsd_popmatrix(void)
Pop the current matrix stack.
void gsd_bgnline(void)
Begin line.
int gsd_get_txtwidth(const char *s, int size)
Get text width.
void GS_set_draw(int where)
Sets which buffer to draw to.
int gsd_make_nice_number(float *num)
ADD.