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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239
|
/*
* Display bar graphs aranged by unique id and by non-unique group id.
* Continuously reads a new data set and updates the display.
*
* Very slow on a 486Dx2/66 with 16MB and a LB Tseng ET4000 (not a W32).
*
* Based on a cut up of the GLUT example/scube.c which rotates a cube
* above a checker board with shadows, lighting etc.
*
* I reused the scube code for lighting and colors.
*
* (c) Copyright 1999, Michael Hamilton, Gentoo South Pacific Limited
*
* You have the same rights as stated in the original SGI copyright.
* (see below).
*
* See gr_monitor.1 man page for usage.
*/
/* ---- ORIGINAL scube.c stuff: */
/* Copyright (c) Mark J. Kilgard, 1994. */
/**
* (c) Copyright 1993, 1994, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
/*
* 1992 David G Yu -- Silicon Graphics Computer Systems
*/
/* ---- End of original scube.c stuff. */
#define VERSION_STRING "Gr_Monitor Version 0.80"
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <time.h>
#include <sys/ioctl.h>
#include <pwd.h>
#ifdef linux
#include <termcap.h>
#endif
#include <termios.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <ctype.h>
#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include <stdarg.h>
#include <GL/gl.h>
#include <GL/glut.h>
#include "dataset.h"
#define DEBUG_MIN 1
#define DEBUG_MAX 3
#define ROTATION 6
#define PER_ROW 12
#define START_ANGLE 50
#define START_X 0
#define START_Y -3
#define START_DOLLY -9
#define FONT_SCALE 0.002
#define ROW_GAP 3.0
#define CRAM_FACTOR 0.25
#define GR_GATHER_COMMAND "GR_GATHER_COMMAND"
#define GATHER_PROC BINDIR "/gr_gather"
#define GATHER_FREE BINDIR "/gr_free"
#define GATHER_RUP BINDIR "/gr_rup"
#define MAX_LINE 10000
#define MAX_VALUES 200
#define MAX_TEXT 79
#define MAX_CONTROLLABLE 10
#define WIN_WIDTH 600 /* Default */
#define WIN_HEIGHT 400 /* Default */
/* glFrustum settings for perspective */
#define CLIP_LEFT -1.0 /* Maps to window edges */
#define CLIP_RIGHT 1.0 /* Ditto */
#define CLIP_BOTTOM -0.6 /* Ditto */
#define CLIP_TOP 1.26 /* Ditto */
#define CLIP_NEAR 1.0 /* Front clipping plane */
#define CLIP_FAR 500.0 /* Back clipping plane */
static char key_help[][50] = {
"exit: ESC",
"echo help to tty: ?",
"graphs per row +/-: p/P",
"adjust zoom +/-: a/A",
"rotate +/-: x/X y/Y z/Z",
"translate +/-: i/I j/J k/K",
"toggle rotation: r",
"select bar type: 0..9",
"scale selected +/-: s/S",
"scale selected 1.0: n",
"toggle selected: o",
"toggle lighting: l or L",
"toggle fog: f",
"toggle halt: h",
"step thru halt: SPACE"
""
};
static int key_menu;
static int debug = 0;
static int num_items;
static int useRGB = 1;
static int useLighting = 1;
static int useFog = 0;
static int useDB = 1;
static int isvisible = 1;
static int halted = 0;
static int skip = 1;
static int cram = 0;
static int per_row = 0;
static int gap = ROW_GAP;
static float cram_factor = CRAM_FACTOR;
static int rotate = 0;
static int rotate_y = 0;
static int rotate_x = 1;
static int rotate_z = 0;
static int rotate_angle = START_ANGLE;
static int trans_y = START_Y;
static int trans_x = START_X;
static int trans_z = START_DOLLY;
static float zoom_horz = 1.0;
static float zoom_vert = 1.0;
static int hide_value[MAX_CONTROLLABLE] = {
0,0,0,0,0, 0,0,0,0,0
};
static float scale_value[MAX_CONTROLLABLE] = {
0.8, 0.8, 0.8, 0.8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8
};
static int value_index = 0;
static int use_stdin = 0;
static int sleep_seconds = 5;
static FILE *inputfp = NULL;
void *font = GLUT_STROKE_ROMAN;
void *fonts[] = {GLUT_STROKE_ROMAN, GLUT_STROKE_MONO_ROMAN};
#define GREY 0
#define RED 1
#define GREEN 2
#define BLUE 3
#define CYAN 4
#define MAGENTA 5
#define YELLOW 6
#define BLACK 7
static float materialColor[8][4] =
{
{0.8, 0.8, 0.8, 1.0},
{0.8, 0.0, 0.0, 1.0},
{0.0, 0.8, 0.0, 1.0},
{0.0, 0.0, 0.8, 1.0},
{0.0, 0.8, 0.8, 1.0},
{0.8, 0.0, 0.8, 1.0},
{0.8, 0.8, 0.0, 1.0},
{0.0, 0.0, 0.0, 0.4},
};
static float lightPos[4] =
{2.0, 4.0, 2.0, 1.0};
static float lightDir[4] =
{-2.0, -4.0, -2.0, 1.0};
static float lightAmb[4] =
{0.2, 0.2, 0.2, 1.0};
static float lightDiff[4] =
{0.8, 0.8, 0.8, 1.0};
static float lightSpec[4] =
{0.4, 0.4, 0.4, 1.0};
static float groundPlane[4] =
{0.0, 1.0, 0.0, 1.499};
static float backPlane[4] =
{0.0, 0.0, 1.0, 0.899};
static float fogColor[4] =
{0.0, 0.0, 0.0, 0.0};
static float fogIndex[1] =
{0.0};
static char *windowNameRGBDB = "Display RGB Double buffered";
static char *windowNameRGB = "Display RGB Single buffered";
static char *windowNameIndexDB = "Display Color DB Double buffered";
static char *windowNameIndex = "Display Color DB Single buffered";
static float cube_vertexes[6][4][4] =
{
{
{-1.0, -1.0, -1.0, 1.0},
{-1.0, -1.0, 1.0, 1.0},
{-1.0, 1.0, 1.0, 1.0},
{-1.0, 1.0, -1.0, 1.0}},
{
{1.0, 1.0, 1.0, 1.0},
{1.0, -1.0, 1.0, 1.0},
{1.0, -1.0, -1.0, 1.0},
{1.0, 1.0, -1.0, 1.0}},
{
{-1.0, -1.0, -1.0, 1.0},
{1.0, -1.0, -1.0, 1.0},
{1.0, -1.0, 1.0, 1.0},
{-1.0, -1.0, 1.0, 1.0}},
{
{1.0, 1.0, 1.0, 1.0},
{1.0, 1.0, -1.0, 1.0},
{-1.0, 1.0, -1.0, 1.0},
{-1.0, 1.0, 1.0, 1.0}},
{
{-1.0, -1.0, -1.0, 1.0},
{-1.0, 1.0, -1.0, 1.0},
{1.0, 1.0, -1.0, 1.0},
{1.0, -1.0, -1.0, 1.0}},
{
{1.0, 1.0, 1.0, 1.0},
{-1.0, 1.0, 1.0, 1.0},
{-1.0, -1.0, 1.0, 1.0},
{1.0, -1.0, 1.0, 1.0}}
};
static float cube_normals[6][4] =
{
{-1.0, 0.0, 0.0, 0.0},
{1.0, 0.0, 0.0, 0.0},
{0.0, -1.0, 0.0, 0.0},
{0.0, 1.0, 0.0, 0.0},
{0.0, 0.0, -1.0, 0.0},
{0.0, 0.0, 1.0, 0.0}
};
void projection(float, float);
void display(Dataset *);
int is_data_ready(FILE *inputfp)
{
/* For select(2). */
struct timeval tv;
fd_set in;
/* Non-blocking read */
tv.tv_sec = 0;
tv.tv_usec = 0;
FD_ZERO(&in);
FD_SET(fileno(inputfp), &in);
return select(16, &in, 0, 0, &tv) > 0 && !feof(inputfp);
}
Dataset *get_data(FILE *inputfp,
int prev_values) {
static Dataset *data_set = NULL;
Dataset *new_set = NULL;
int i, j;
int id, group_size;
char group[MAX_TEXT];
static char line[MAX_LINE], *upto;
if ((prev_values || !is_data_ready(inputfp)) && data_set) {
if (debug >= DEBUG_MAX) fputs("Returning old data.\n", stderr);
return data_set;
}
/* Data is ready or we have no existing data-set */
new_set = getDataset(inputfp);
if (new_set != NULL) {
if (data_set != NULL) {
freeDataset(data_set);
}
data_set = new_set;
}
if (cram) {
}
return data_set;
}
void do_update(void)
{
static int first_time_thru = 1;
static int count = 0;
static char title[MAX_TEXT];
int num_items;
int num_values;
Dataset *data_set = get_data(inputfp, halted);
if (first_time_thru) {
first_time_thru = 0;
if (per_row == 0) {
if (data_set->groupCount > 0) {
per_row = data_set->groups[0]->itemCount;
/*printf("%d\n", per_row);*/
}
if (per_row < PER_ROW) {
per_row = PER_ROW;
}
}
}
++count;
if (skip && !halted) {
while (is_data_ready(inputfp)) { /* Skip over data until we are up to date */
++count;
if (debug >= DEBUG_MIN) {
fprintf(stderr,
"Can't render fast enough - skipping over data set %d.\n",
count);
}
data_set = get_data(inputfp, halted);
}
}
if (data_set) {
if (debug >= DEBUG_MAX) fprintf(stderr, "Displaying set %s.\n", data_set->id) ;
glutSetWindowTitle(data_set->id);
glutSetIconTitle(data_set->id);
}
if (isvisible && data_set) {
if (debug >= DEBUG_MAX) fputs("Displaying.\n", stderr) ;
display(data_set);
/* glutPostRedisplay(); */
if (debug >= DEBUG_MAX) fprintf(stderr, "Done (%d).\n", count) ;
}
}
void do_idle(void)
{
/* Only update if there's new data. */
if (rotate || (!halted && is_data_ready(inputfp))) {
if (debug >= DEBUG_MAX) fputs("Update display during idle time.\n", stderr);
do_update();
}
else {
sleep(1);
}
}
void key_help_to_stdout(void)
{
int i;
puts("\nKey Summary.\n");
for (i = 0; *(key_help[i]); i++) {
puts(key_help[i]);
}
}
void
keyboard(unsigned char ch, int x, int y)
{
int update = 1; /* Most commands need a display update */
switch (ch) {
case 27: /* escape */
exit(0);
break;
case 'L':
case 'l':
useLighting = !useLighting;
useLighting ? glEnable(GL_LIGHTING) : glDisable(GL_LIGHTING);
glutPostRedisplay();
update = 0;
break;
case 'F':
case 'f':
useFog = !useFog;
useFog ? glEnable(GL_FOG) : glDisable(GL_FOG);
glutPostRedisplay();
update = 0;
break;
case 'R':
case 'r':
rotate = !rotate;
break;
case 's':
scale_value[value_index] += 0.2;
break;
case 'S':
scale_value[value_index] -= 0.2;
if (scale_value[value_index] < 0) scale_value[value_index] = 0.0;
break;
case 'n':
case 'N':
scale_value[value_index] = 1.0;
break;
case 'o':
case 'O':
hide_value[value_index] = !hide_value[value_index];
break;
case 'i':
trans_x = 1 ;
break;
case 'I':
trans_x = -1 ;
break;
case 'j':
trans_y = 1;
break;
case 'J':
trans_y = -1;
break;
case 'k':
trans_z = 1;
break;
case 'K':
trans_z = -1;
break;
case 'x':
rotate_x = 1 ;
break;
case 'X':
rotate_x = -1 ;
break;
case 'y':
rotate_y = 1;
break;
case 'Y':
rotate_y = -1;
break;
case 'z':
rotate_z = 1;
break;
case 'Z':
rotate_z = -1;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
value_index = ch - '0';
update = 0;
break;
case 'p':
per_row++;
break;
case 'P':
if (per_row > 1) per_row--;
break;
case 'a':
zoom_vert -= 0.1;
zoom_horz -= 0.1;
break;
case 'A':
zoom_vert += 0.1;
zoom_horz += 0.1;
break;
case 'H':
case 'h':
halted = !halted;
if (halted) update = 0;
break;
case ' ':
update = 1;
break;
case '?':
key_help_to_stdout();
break;
default:
/*printf("key %d\n", ch); */
break;
}
if (update) {
if (debug >= DEBUG_MAX) fputs("Update display after keypress.\n", stderr);
do_update();
}
}
void strokePrintf(const char *format, ...)
{
va_list ap;
static char buf[1000];
int i;
va_start (ap, format);
vsprintf (buf, format, ap);
glPushMatrix();
for (i = 0; i < strlen(buf); i++) {
glutStrokeCharacter(font, buf[i]);
}
glPopMatrix();
}
void
buildColormap(void)
{
if (useRGB) {
return;
} else {
int mapSize = 1 << glutGet(GLUT_WINDOW_BUFFER_SIZE);
int rampSize = mapSize / 8;
int entry;
int i;
for (entry = 0; entry < mapSize; ++entry) {
int hue = entry / rampSize;
GLfloat val = (entry % rampSize) * (1.0 / (rampSize - 1));
GLfloat red, green, blue;
red = (hue == 0 || hue == 1 || hue == 5 || hue == 6) ? val : 0;
green = (hue == 0 || hue == 2 || hue == 4 || hue == 6) ? val : 0;
blue = (hue == 0 || hue == 3 || hue == 4 || hue == 5) ? val : 0;
glutSetColor(entry, red, green, blue);
}
for (i = 0; i < 8; ++i) {
materialColor[i][0] = i * rampSize + 0.2 * (rampSize - 1);
materialColor[i][1] = i * rampSize + 0.8 * (rampSize - 1);
materialColor[i][2] = i * rampSize + 1.0 * (rampSize - 1);
materialColor[i][3] = 0.0;
}
fogIndex[0] = -0.2 * (rampSize - 1);
}
}
static void
setColor(int c)
{
if (useLighting) {
if (useRGB) {
glMaterialfv(GL_FRONT_AND_BACK,
GL_AMBIENT_AND_DIFFUSE, &materialColor[c][0]);
} else {
glMaterialfv(GL_FRONT_AND_BACK,
GL_COLOR_INDEXES, &materialColor[c][0]);
}
} else {
if (useRGB) {
glColor4fv(&materialColor[c][0]);
} else {
glIndexf(materialColor[c][1]);
}
}
}
static void
drawBar(int color, float height)
{
int i, j;
/* printf("hieght=%f\n", height); */
setColor(color);
for (i = 0; i < 6; ++i) {
glNormal3fv(&cube_normals[i][0]);
glBegin(GL_POLYGON);
for (j = 0; j < 4; j++) {
if (cube_vertexes[i][j][1] >= 0) {
glVertex4f(cube_vertexes[i][j][0],
height,
// height == 0 ? 0.00001 : height,
cube_vertexes[i][j][2],
cube_vertexes[i][j][3]
);
}
else {
glVertex4fv(&cube_vertexes[i][j][0]);
}
}
glEnd();
}
}
drawIDname( char *id )
{
while (*(id) == ' ') ++id; /* Skip spaces */
if (debug > DEBUG_MAX) {
fprintf(stderr, "draw %s\n", id);
}
setColor(BLACK);
glPushMatrix();
glTranslatef(-0.3, -0.65, 0.7);
glScalef(FONT_SCALE,1.0,FONT_SCALE);
glRotatef(-90, 1.0, 0.0, 0.0);
strokePrintf("%s", id);
glPopMatrix();
}
void
drawOneItem(Item *item)
{
int i;
drawIDname(item->id);
glPushMatrix();
glTranslatef(0.0, -0.66, 0.0);
glScalef(0.3, 0.1, 0.3);
for (i = 0; i < item->dataCount; i++) {
if (i >= MAX_CONTROLLABLE || !hide_value[i]) {
/* draw bar */
if (i < MAX_CONTROLLABLE && scale_value[i] != 1.0) {
drawBar(i + 1, item->datums[i]->value * scale_value[i]);
}
else {
drawBar(i + 1, item->datums[i]->value); /* draw bar */
}
}
glTranslatef(0.0, 0.0, -3.33);
}
glPopMatrix();
}
drawValueName( char *bname, int num )
{
setColor(BLACK);
glPushMatrix();
glTranslatef(-1.4, -0.65, -num);
glScalef(FONT_SCALE*1.5,1.0,FONT_SCALE*1.5);
glRotatef(-90, 1.0, 0.0, 0.0);
strokePrintf("%s", bname);
glPopMatrix();
}
drawGname( char *group, int length )
{
setColor(RED);
glPushMatrix();
glTranslatef((length + 0.5)/2.0 - 2.0, -0.65, 1.3);
glScalef(FONT_SCALE*2,1.0,FONT_SCALE*2);
glRotatef(-90, 1.0, 0.0, 0.0);
strokePrintf("%s", group);
glPopMatrix();
}
void
drawBase(char *gname, int length, Item *item)
{
int i, j;
int num_values = item->dataCount;
drawGname(gname, length);
for (i = 0; i < num_values; i++) {
drawValueName(item->datums[i]->name, i);
}
glPushMatrix();
/* printf("length=%d\n",length); */
glTranslatef(-0.5, -1.0, -(num_values - 1));
glScalef(1.0, 0.3, 1.0);
setColor(GREY);
for (i = 0; i < 6; ++i) {
glNormal3fv(&cube_normals[i][0]);
glBegin(GL_POLYGON);
for (j = 0; j < 4; j++) {
glVertex4f((cube_vertexes[i][j][0] >= 0) ? (length + 0.5) : cube_vertexes[i][j][0],
cube_vertexes[i][j][1],
(cube_vertexes[i][j][2] >= 0) ? (num_values + 0.5) : cube_vertexes[i][j][2],
cube_vertexes[i][j][3]
);
}
glEnd();
}
glPopMatrix();
}
void showData (Dataset *data_set)
{
int num_groups = data_set->groupCount;
int num_values = 0;
int num_drawn;
int step;
char last_group[MAX_TEXT];
float location;
glPushMatrix();
glTranslatef(-(per_row / 2 + 1), 0.0, 0.0);
num_drawn = 0;
step = 0;
while (num_drawn < num_groups) {
int i;
int num_in_group = data_set->groups[num_drawn]->itemCount;
drawBase(data_set->groups[num_drawn]->id, num_in_group, data_set->groups[num_drawn]->items[0]);
for (i = 0; i < num_in_group; i++) {
int new_num_values = data_set->groups[num_drawn]->items[i]->dataCount;
if (new_num_values > num_values) {
num_values = new_num_values;
}
drawOneItem(data_set->groups[num_drawn]->items[i]);
glTranslatef(1, 0.0, 0.0);
step++;
}
num_drawn++;
if (num_drawn < num_groups) {
if (step > per_row || step + data_set->groups[num_drawn]->itemCount > per_row
&& (!cram
|| (step > (1 - cram_factor) * per_row)
|| (step + data_set->groups[num_drawn]->itemCount > per_row * (1 + cram_factor)))
) {
glTranslatef(-step, 0.0, -(num_values + gap));
step = 0;
} else {
glTranslatef(3, 0.0, 0.0);
step += 3;
}
}
}
glPopMatrix();
}
void
display(Dataset *data_set)
{
projection(zoom_horz, zoom_vert);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (trans_x || trans_y || trans_z) {
glTranslatef(trans_x, trans_y, trans_z);
trans_x = trans_y = trans_z = 0;
}
if (rotate || rotate_x || rotate_y || rotate_z) {
glRotatef(rotate_angle, rotate_x, rotate_y, rotate_z);
rotate_angle = ROTATION;
rotate_x = rotate_y = rotate_z = 0;
if (rotate) rotate_y = 1;
}
/* Draw bars */
showData(data_set);
glDepthMask(GL_TRUE);
if (useRGB) {
glDisable(GL_BLEND);
} else {
glDisable(GL_POLYGON_STIPPLE);
}
if (useFog) {
glEnable(GL_FOG);
}
glutSwapBuffers();
}
void
visible(int state)
{
isvisible = state == GLUT_VISIBLE ;
}
void
fog_select(int fog)
{
glFogf(GL_FOG_MODE, fog);
glutPostRedisplay();
}
void
menu_select(int mode)
{
switch (mode) {
case 1:
halted = 0;
break;
case 2:
halted = 1;
break;
case 3:
useFog = !useFog;
useFog ? glEnable(GL_FOG) : glDisable(GL_FOG);
glutPostRedisplay();
break;
case 4:
useLighting = !useLighting;
useLighting ? glEnable(GL_LIGHTING) : glDisable(GL_LIGHTING);
glutPostRedisplay();
break;
case 5:
exit(0);
break;
}
}
void do_nothing(int choice)
{
/* Dummy for key_help menu */
}
void projection(float zoom_horz, float zoom_vert)
{
static float last_h = 0;
static float last_v = 0;
if (zoom_horz != last_h || zoom_vert != last_v) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(CLIP_LEFT * zoom_horz, CLIP_RIGHT * zoom_horz, CLIP_BOTTOM * zoom_vert, CLIP_TOP * zoom_vert, CLIP_NEAR, CLIP_FAR);
glMatrixMode(GL_MODELVIEW);
last_h = zoom_horz;
last_v = zoom_vert;
}
}
void gl_setup(int argc, char **argv, int width, int height) {
int fog_menu, i;
char *name;
glutInitWindowSize(width, height);
glutInit(&argc, argv);
/* choose visual */
if (useRGB) {
if (useDB) {
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
name = windowNameRGBDB;
} else {
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
name = windowNameRGB;
}
} else {
if (useDB) {
glutInitDisplayMode(GLUT_DOUBLE | GLUT_INDEX | GLUT_DEPTH);
name = windowNameIndexDB;
} else {
glutInitDisplayMode(GLUT_SINGLE | GLUT_INDEX | GLUT_DEPTH);
name = windowNameIndex;
}
}
glutCreateWindow(name);
buildColormap();
glutKeyboardFunc(keyboard);
glutDisplayFunc(do_update);
glutVisibilityFunc(visible);
key_menu = glutCreateMenu(do_nothing);
for (i = 0; *(key_help[i]); i++) {
glutAddMenuEntry(key_help[i], 0);
}
glutAttachMenu(GLUT_MIDDLE_BUTTON);
fog_menu = glutCreateMenu(fog_select);
glutAddMenuEntry("Linear fog", GL_LINEAR);
glutAddMenuEntry("Exp fog", GL_EXP);
glutAddMenuEntry("Exp^2 fog", GL_EXP2);
glutCreateMenu(menu_select);
glutAddSubMenu("Key summary", key_menu);
glutAddMenuEntry("Unfreeze", 1);
glutAddMenuEntry("Freeze", 2);
glutAddMenuEntry("Toggle fog", 3);
glutAddMenuEntry("Toggle lighting", 4);
glutAddSubMenu("Fog type", fog_menu);
glutAddMenuEntry("Quit", 5);
glutAttachMenu(GLUT_RIGHT_BUTTON);
/* setup context */
projection(zoom_horz, zoom_vert);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -3.0);
glEnable(GL_DEPTH_TEST);
if (useLighting) {
glEnable(GL_LIGHTING);
}
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmb);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiff);
glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpec);
/*
* glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, lightDir);
* glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 80);
* glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 25);
*/
glEnable(GL_NORMALIZE);
if (useFog) {
glEnable(GL_FOG);
}
glFogfv(GL_FOG_COLOR, fogColor);
glFogfv(GL_FOG_INDEX, fogIndex);
glFogf(GL_FOG_MODE, GL_EXP);
glFogf(GL_FOG_DENSITY, 0.5);
glFogf(GL_FOG_START, CLIP_NEAR);
glFogf(GL_FOG_END, CLIP_FAR);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glShadeModel(GL_SMOOTH);
glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
#if 0
if (useLogo) {
glPolygonStipple((const GLubyte *) sgiPattern);
} else {
glPolygonStipple((const GLubyte *) shadowPattern);
}
#endif
glClearColor(0.0, 0.0, 0.0, 1);
glClearIndex(0);
glClearDepth(1);
}
void usage(void)
{
puts("");
puts("gather | display [options]");
puts(" ");
puts("Options:");
puts(" -t proc|free|rup|<cmd> type of data to gather or command to exec.");
puts(" -host host rsh gather on host.");
puts(" -witdh n pixals.");
puts(" -height n pixals.");
puts(" -perrow n data sets per row.");
puts(" -cram x (x * perrow) <= in row or in row <= ((1 + x) * perrow)");
puts(" -gap x gap between rows in floating point.");
puts(" -angle n starting tilt toward or away from you.");
puts(" -dolly n starting viewing distance from origin.");
puts(" -zoom x zoom factor horizontal and vertical.");
puts(" -zhorz x horizontal zoom factor.");
puts(" -zvert x vertical zoom factor.");
puts(" -geometry window size and location");
puts(" -color take over color map");
puts(" -nolight disable lighting");
puts(" -fog enable fog effects");
puts(" -onebuf disable double buffering");
puts(" -rotate enable rotation");
puts(" -stdin take input from stdin");
puts(" -host h rsh gather on host");
puts(" -sleep n sleep seconds between updates.");
puts(" -noskip don't skip data even if it comes in too fast.");
puts(" -verbose all feedback/debugging output to stderr enabled.");
puts(" -v report skipped data due to it arriving too fast.");
puts("");
}
int
main(int argc, char **argv)
{
int width = WIN_WIDTH, height = WIN_HEIGHT;
int i;
char hostname[MAX_TEXT] = "";
char *gather_type = GATHER_PROC;
/* process commmand line args */
for (i = 1; i < argc; ++i) {
if (!strcmp("-c", argv[i])) {
useRGB = !useRGB;
} else if (!strcmp("-color", argv[i])) {
useRGB = !useRGB;
} else if (!strcmp("-nolight", argv[i])) {
useLighting = !useLighting;
} else if (!strcmp("-fog", argv[i])) {
useFog = !useFog;
} else if (!strcmp("-onebuf", argv[i])) {
useDB = !useDB;
} else if (!strcmp("-rotate", argv[i])) {
rotate = 1;
} else if (!strcmp("-width", argv[i])) {
width = strtol(argv[++i],NULL,0);
} else if (!strcmp("-height", argv[i])) {
height = strtol(argv[++i],NULL,0);
} else if (!strcmp("-perrow", argv[i])) {
per_row = strtol(argv[++i],NULL,0);
} else if (!strcmp("-cram", argv[i])) {
cram = 1;
cram_factor = strtod(argv[++i],NULL);
} else if (!strcmp("-angle", argv[i])) {
rotate_angle = strtol(argv[++i],NULL,0);
} else if (!strcmp("-dolly", argv[i])) {
trans_z = strtol(argv[++i],NULL,0);
} else if (!strcmp("-gap", argv[i])) {
gap = strtod(argv[++i],NULL);
} else if (!strcmp("-stdin", argv[i])) {
use_stdin = 1;
} else if (!strcmp("-host", argv[i])) {
strcpy(hostname, argv[++i]);
} else if (!strcmp("-sleep", argv[i])) {
sleep_seconds = strtod(argv[++i],NULL);
if (sleep_seconds == 0) {
halted = 1;
}
} else if (!strcmp("-noskip", argv[i])) {
skip = 0;
} else if (!strcmp("-zoom", argv[i])) {
zoom_horz = zoom_vert = strtod(argv[++i],NULL);
} else if (!strcmp("-zvert", argv[i])) {
zoom_vert = zoom_vert = strtod(argv[++i],NULL);
} else if (!strcmp("-zhorz", argv[i])) {
zoom_horz = strtod(argv[++i],NULL);
} else if (!strcmp("-verbose", argv[i])
|| !strcmp("-debug", argv[i])) {
debug = DEBUG_MAX;
} else if (!strcmp("-v", argv[i])) {
debug = DEBUG_MIN;
} else if (!strcmp("-t", argv[i])) {
gather_type = argv[++i];
if (!strcmp("proc", gather_type)) {
gather_type = GATHER_PROC;
}
else if (!strcmp("free", gather_type)) {
gather_type = GATHER_FREE;
}
else if (!strcmp("rup", gather_type)) {
gather_type = GATHER_RUP;
}
} else {
usage();
}
}
if (use_stdin) {
inputfp = stdin;
}
else {
char *cmd = getenv(GR_GATHER_COMMAND);
char command[MAX_LINE];
strcpy(command, cmd ? cmd : gather_type);
if (sleep_seconds) {
sprintf(command, "%s -sleep %d", command, sleep_seconds);
}
if (*hostname) {
char rsh[MAX_LINE];
sprintf(rsh, "rsh -n %s '%s'", hostname, command);
inputfp = popen(rsh, "r");
} else {
inputfp = popen(command, "r");
}
}
puts(VERSION_STRING);
puts("Press the middle mouse button for key summary.");
puts("Starting up...");
sleep(2); /* Give the data gatherer a chance
* to warm up.
*/
/* loop, collecting process info and sleeping */
gl_setup(argc, argv, width, height);
glutIdleFunc(do_idle);
glutMainLoop();
}
/*
* Normal end of execution.
*/
void
end(void)
{
exit(0);
}
/*
* SIGTSTP catcher.
*/
void
stop(void)
{
exit(0);
}
|