26 #if defined(OPENGL_X11) || defined(OPENGL_WINDOWS) 29 #elif defined(OPENGL_AQUA) 30 #include <OpenGL/gl.h> 31 #include <OpenGL/glu.h> 41 static float *Listcats;
42 static int Listnum = 0;
51 #define MAX_LEGEND 256 66 glPushAttrib(GL_VIEWPORT);
68 glMatrixMode(GL_PROJECTION);
78 glViewport(wl, wb, (wr - wl), (wt - wb));
80 gluOrtho2D(-0.5, (wr - wl) + 0.5, -0.5, (wt - wb) + 0.5);
81 glMatrixMode(GL_MODELVIEW);
96 glMatrixMode(GL_PROJECTION);
100 glMatrixMode(GL_MODELVIEW);
125 float curnum, step, start;
130 step = (highnum - lownum) / (
float)numvals;
134 start = step * (int)(1 + lownum / step);
135 if (start - lownum < .65 * step)
138 for (curnum = start; curnum < (highnum - .65 * step); curnum += step) {
139 vals[num++] = curnum;
156 float newnum, nextnum;
163 while (.5 * newnum > *num) {
164 nextnum = newnum / 10.;
166 if (.5 * newnum > *num)
168 if (.5 * newnum > *num)
174 while (2 * newnum <= *num) {
175 nextnum = newnum * 10.;
177 if (2 * newnum <= *num)
179 if (2 * newnum <= *num)
203 float *rangef,
int *pt)
205 GLint sl, sr, sb,
st;
207 int cat_labs = 0, cat_vals = 0, do_invert = 0, discrete = 0;
208 int is_fp, fprec, iprec;
238 if (mapset ==
NULL) {
239 G_warning(
_(
"Raster map <%s> not found"), name);
246 G_warning(
_(
"Unable to read color file of raster map <%s>"), name);
252 G_warning(
_(
"Unable to read category file of raster map <%s>"),
258 if (flags[4] && rangef[0] != -9999. && rangef[1] != -9999.) {
269 G_warning(
_(
"Unable to read fp range of raster map <%s>"),
274 if (flags[4] && rangef[0] != -9999.)
276 if (flags[4] && rangef[1] != -9999.)
281 G_warning(
_(
"Unable to read range of raster map <%s>"), name);
285 if (flags[4] && rangef[0] != -9999.)
287 if (flags[4] && rangef[1] != -9999.)
295 G_warning(
_(
"Range request error for legend"));
319 for (tmp = 1; tmp <
max; tmp *= 10, p1++) ;
321 for (tmp = -1; tmp >
min; tmp *= 10, p2++) ;
323 iprec = (p1 > p2 ? p1 : p2);
359 int i, k, lleg, horiz;
360 int red, green, blue;
362 DCELL tdcell, pdcell;
363 float vert1[2], vert2[2], vert3[2], vert4[2];
369 int labw, maxlabw, numlabs;
370 float labpos, labpt[3];
373 GLint wt, wb, wl, wr;
377 horiz = (sr - sl > st - sb);
381 numlabs = Listnum ? Listnum : max - min + 1;
383 if (is_fp && !Listnum) {
385 G_warning(
_(
"Unable to show discrete FP range (use list)"));
389 dividers = (
float *)
G_malloc(numlabs *
sizeof(
float));
394 labvals[numlabs + 1] = fmax;
401 if (cat_labs || cat_vals) {
402 for (k = 0; k < numlabs; k++) {
404 tdcell = discrete ? Listcats[k] : labvals[k];
408 if (cat_labs && !cat_vals) {
409 sprintf(buff,
"%s", cstr);
412 if (cat_labs && cat_vals) {
414 sprintf(buff,
"%.*lf) %s",
415 fprec, tdcell, cstr);
417 sprintf(buff,
"%.*lf", fprec, tdcell);
420 sprintf(buff,
"%.*lf", fprec, tdcell);
424 tcell = discrete ? Listnum ?
425 Listcats[k] : min + k : labvals[k];
426 if (cat_labs && !cat_vals)
429 if (cat_labs && cat_vals) {
432 sprintf(buff,
"%*d) %s", iprec, tcell, cstr);
434 sprintf(buff,
"%d", tcell);
437 sprintf(buff,
"%d", tcell);
441 if (labw > maxlabw) {
474 vert1[
X] = vert2[
X] = xoff;
475 vert1[
Y] = vert2[
Y] = yoff;
482 stab2 = vert2[
Y] = st - sb + yoff;
483 stab1 = vert1[
Y] = yoff;
485 vert1[
X] = vert2[
X] = sr - sl + xoff;
493 stab2 = vert2[
X] = sr - sl + xoff;
494 stab1 = vert1[
X] = xoff;
496 vert1[
Y] = vert2[
Y] = st - sb + yoff;
500 if (numlabs > lleg / 5)
501 G_warning(
_(
"Too many categories to show as discrete!"));
506 incr = do_invert ? -1 : 1;
507 for (k = 0, i = 0; k < lleg; k++) {
508 if (discrete && Listnum)
509 tdcell = Listcats[(int)((
float)k * numlabs / lleg)];
511 tcell = min + k * (max - min + 1) / lleg;
512 tdcell = fmin + k * (fmax - fmin) / lleg;
516 if (k == 0 || tdcell != pdcell) {
519 &red, &green, &blue, &colors);
537 dividers[i++] = *dv1;
567 vert1[
X] = vert2[
X] = 1. + xoff;
568 vert1[
Y] = vert4[
Y] = 1. + yoff;
569 vert3[
X] = vert4[
X] = sr - sl - 1. + xoff;
570 vert3[
Y] = vert2[
Y] = st - sb - 1. + yoff;
582 vert1[
X] = vert2[
X] = xoff;
583 vert1[
Y] = vert4[
Y] = yoff;
584 vert3[
X] = vert4[
X] = sr - sl + xoff;
585 vert3[
Y] = vert2[
Y] = st - sb + yoff;
601 for (k = 0; k < i; k++) {
602 *dv1 = *dv2 = dividers[k];
610 if (cat_labs || cat_vals) {
612 for (k = 0; k < numlabs; k++) {
614 if (discrete && Listnum) {
615 tdcell = Listcats[k];
616 labpos = (k + .5) / numlabs;
621 labpos = (tdcell - fmin) / (fmax - fmin);
625 if (discrete && Listnum) {
627 labpos = (k + .5) / numlabs;
630 tcell = discrete ? min + k : labvals[k];
631 labpos = (tcell - min + .5) / (max - min + 1);
635 labpos = 1. - labpos;
642 if (cat_labs && !cat_vals)
643 sprintf(buff,
"%s", cstr);
645 if (cat_labs && cat_vals) {
648 sprintf(buff,
"%.*lf) %s",
649 fprec, tdcell, cstr);
651 sprintf(buff,
"%*d) %s", iprec, tcell, cstr);
653 sprintf(buff,
"%.*lf", fprec, tdcell);
655 sprintf(buff,
"%d", tcell);
659 sprintf(buff,
"%.*lf", fprec, tdcell);
661 sprintf(buff,
"%d", tcell);
665 labpt[
X] = labpos * (sr - sl) + xoff -
676 labpt[
Y] = labpos * (st - sb) + yoff -
704 return (legend_list);
void gsd_end_legend_viewport(void)
ADD.
void do_label_display(GLuint, float *, const char *)
Display label.
#define RGB_TO_INT(r, g, b, i)
void gsd_popmatrix(void)
Pop the current matrix stack.
void G_free(void *)
Free allocated memory.
int gsd_get_txtheight(int size)
Get text height.
int Rast_read_range(const char *, const char *, struct Range *)
Read raster range (CELL)
void Rast_get_fp_range_min_max(const struct FPRange *, DCELL *, DCELL *)
Get minimum and maximum value from fp range.
void gsd_colormode(int)
Set color mode.
char * Rast_get_c_cat(CELL *, struct Categories *)
Get a raster category label (CELL)
void gsd_color_func(unsigned int)
Set current color.
char * Rast_get_d_cat(DCELL *, struct Categories *)
Get a raster category label (DCELL)
void gsd_endline(void)
End line.
void Rast_free_colors(struct Colors *)
Free color structure memory.
void GS_done_draw(void)
Draw done, swap buffers.
int Rast_get_d_color(const DCELL *, int *, int *, int *, struct Colors *)
Gets color from raster map (DCELL)
GLuint gsd_put_legend(const char *name, GLuint fontbase, int size, int *flags, float *rangef, int *pt)
Put legend.
void gsd_bgnlist(int, int)
ADD.
int Rast_read_fp_range(const char *, const char *, struct FPRange *)
Read floating-point range.
int Rast_get_c_color(const CELL *, int *, int *, int *, struct Colors *)
Gets color from raster map (CELL)
void gsd_linewidth(short)
Set width of rasterized lines.
int Rast_read_cats(const char *, const char *, struct Categories *)
Read raster category file.
int gsd_get_nice_range(float lownum, float highnum, int numvals, float *vals)
ADD.
int Rast_read_colors(const char *, const char *, struct Colors *)
Read color table of raster map.
void gsd_bgn_legend_viewport(GLint wl, GLint wb, GLint wr, GLint wt)
ADD.
void G_warning(const char *,...) __attribute__((format(printf
void gsd_endlist(void)
End list.
void Rast_free_cats(struct Categories *)
Free category structure memory.
void gsd_pushmatrix(void)
Push the current matrix stack.
const char * G_find_raster2(const char *, const char *)
Find a raster map (look but don't touch)
int gsd_makelist(void)
ADD.
int gsd_get_txtwidth(const char *, int)
Get text width.
void GS_set_draw(int)
Sets which buffer to draw to.
int get_txtxoffset(void)
Get text offset.
int Rast_map_is_fp(const char *, const char *)
Check if raster map is floating-point.
void gsd_bgnline(void)
Begin line.
int gsd_make_nice_number(float *num)
ADD.
void Rast_get_range_min_max(const struct Range *, CELL *, CELL *)
Get range min and max.