00001
00002 #include "xhrdplot.h"
00003
00004 static float linespacing;
00005
00006
00007
00008
00009
00010
00011 void initialize_graphics(float r_factor,
00012 bool b_flag,
00013 unsigned long& win,
00014 unsigned long& instr,
00015 unsigned long& colwin,
00016 unsigned long* c_index,
00017 unsigned long* c_energy,
00018 int& win_size,
00019 int& xorigin, int& yorigin)
00020 {
00021
00022
00023
00024
00025
00026 if (r_factor >= 1.0) {
00027 set_default_font("9x15");
00028 linespacing = 1.2;
00029 } else if (r_factor >= 0.8) {
00030 set_default_font("7x13");
00031 if (r_factor >= 0.9)
00032 linespacing = 1.15;
00033 else
00034 linespacing = 1.1;
00035 } else if (r_factor >= 0.65) {
00036 set_default_font("6x12");
00037 if (r_factor >= 0.725)
00038 linespacing = 1.05;
00039 else
00040 linespacing = 1.0;
00041 } else if (r_factor >= 0.5) {
00042 set_default_font("6x10");
00043 if (r_factor >= 0.575)
00044 linespacing = 1.05;
00045 else
00046 linespacing = 1.0;
00047 } else if (r_factor >= 0.4) {
00048 set_default_font("6x9");
00049 linespacing = 1.0;
00050 } else {
00051 set_default_font("5x8");
00052 linespacing = 1.0;
00053 }
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 int title = 27;
00065 int bottom = 0;
00066 if (r_factor <= 0.75) {
00067 title = 20;
00068 bottom = 20;
00069 }
00070
00071 xorigin = 0;
00072 yorigin = 0;
00073 int xsize = _R_(400);
00074 int ysize = _R_(400);
00075 win = lux_openwin(xorigin, yorigin, xsize, ysize);
00076 lux_set_window_name(win, "Starlab");
00077
00078 win_size = xsize;
00079
00080
00081
00082 if (r_factor <= 1)
00083 yorigin += ysize + title + bottom;
00084 else
00085 yorigin += ysize + 2*title + bottom;
00086
00087
00088
00089 ysize = _R_(260);
00090 if (r_factor <= 0.6) {
00091 xsize = (int) (xsize * 1.25);
00092 ysize = (int) (ysize * 1.1);
00093 }
00094 instr = lux_openwin(xorigin, yorigin, xsize, ysize);
00095 lux_set_window_name(instr, "Status & Commands");
00096
00097
00098
00099 if (r_factor <= 1.1 && r_factor > 0.75) {
00100 yorigin += ysize + title + bottom;
00101 } else {
00102 int edge = 3;
00103 if (r_factor <= 0.6) xsize = (int) (xsize / 1.25);
00104 xorigin += xsize + edge;
00105 yorigin = 0;
00106 }
00107 if (r_factor <= 0.6) {
00108 xsize = (int) (xsize * 1.25);
00109 ysize = (int) (ysize * 1.1);
00110 }
00111 if (r_factor <= 0.6) ysize = (int) (ysize * 1.1);
00112 colwin = lux_openwin(xorigin, yorigin, xsize, ysize);
00113 lux_set_window_name(colwin, "Color Scheme");
00114
00115 init_colors(win, c_energy, c_index, b_flag);
00116
00117 lux_set_noupdate(win);
00118 lux_set_bgcolor(win,c_energy[background_color]);
00119 lux_set_window_bgcolor(win,c_energy[background_color]);
00120 lux_set_color(win,c_energy[default_color]);
00121
00122 lux_set_noupdate(colwin);
00123 lux_set_bgcolor(colwin,c_energy[background_color]);
00124 lux_set_window_bgcolor(colwin,c_energy[background_color]);
00125 lux_set_color(colwin,c_energy[default_color]);
00126
00127 lux_set_noupdate(instr);
00128 lux_set_bgcolor(instr,c_energy[background_color]);
00129 lux_set_window_bgcolor(instr,c_energy[background_color]);
00130 lux_set_color(instr,c_energy[default_color]);
00131
00132 lux_setup_region(win, 1.0, 1.0, 8.0, 8.0);
00133
00134
00135
00136 if (r_factor <= 1.1 && r_factor > 0.75) {
00137 int edge = 3;
00138 xorigin += xsize + edge;
00139 yorigin = 0;
00140 } else
00141 yorigin += ysize + title + bottom;
00142 }
00143
00144
00145
00146 void project3d(float x, float y, float z, float& X, float& Y,
00147 float ct, float st, float cp, float sp,
00148 float vx, float vy, float vz, float& dv2)
00149 {
00150 float xp, yp, zp, xf, yf, zf;
00151
00152
00153 xp = ct*x + st*y;
00154 yp = -st*x + ct*y;
00155 zp = z;
00156
00157
00158 xf = cp*xp + sp*zp;
00159 yf = yp;
00160 zf = -sp*xp + cp*zp;
00161
00162
00163 X = yf; Y=zf;
00164 dv2 = (vx-xf)*(vx-xf) + (vy-yf)*(vy-yf) + (vz-zf)*(vz-zf);
00165 }
00166
00167 void project3d(float x, float y, float z, float& X, float& Y,
00168 float ct, float st, float cp, float sp)
00169 {
00170 float xp, yp, zp, xf, yf, zf;
00171
00172
00173 xp = ct*x + st*y;
00174 yp = -st*x + ct*y;
00175 zp = z;
00176
00177
00178 xf = cp*xp + sp*zp;
00179 yf = yp;
00180 zf = -sp*xp + cp*zp;
00181
00182
00183 X = yf; Y=zf;
00184 }
00185
00186 void draw3d_axis(unsigned long win, float lmax,
00187 float ct, float st, float cp, float sp)
00188 {
00189 float X[8], Y[8], Z[8], XP[8], YP[8], D[8], X0, Y0, Z0, dmax = 0.0;
00190 float xp,yp;
00191 int i, i0;
00192 static int od1[] = {1,2,4,3,5,6,8,7,1,2,4,3};
00193 static int od2[] = {2,4,3,1,6,8,7,5,5,6,8,7};
00194
00195 X0 = lmax; Y0 = 0.0; Z0 = 0.0;
00196 for (i=0;i<8;i++) {
00197 X[i] = lmax*((i&0x0001)?-1:1);
00198 Y[i] = lmax*((i&0x0002)?-1:1);
00199 Z[i] = lmax*((i&0x0004)?-1:1);
00200 project3d(X[i], Y[i], Z[i], XP[i], YP[i],
00201 ct, st, cp, sp,
00202 X0, Y0, Z0, D[i]);
00203 if (D[i] > dmax) {dmax = D[i]; i0 = i;}
00204 }
00205
00206 for (i=0;i<12;i++) {
00207 if (od1[i] == i0+1 || od2[i] == i0+1) lux_set_linestyle(win,1);
00208 else lux_set_linestyle(win,0);
00209 lux_draw_linef(win,XP[od1[i]-1],YP[od1[i]-1],XP[od2[i]-1],YP[od2[i]-1]);
00210 }
00211 lux_set_linestyle(win,0);
00212
00213
00214 project3d(0.0,-lmax*1.1,-lmax*1.1, xp, yp, ct,st,cp,sp);
00215 lux_draw_string(win, xp, yp, -0.5, "x", 0);
00216 project3d(-lmax*1.1,0.0,-lmax*1.1, xp, yp, ct,st,cp,sp);
00217 lux_draw_string(win, xp, yp, -0.5, "y", 0);
00218 project3d(-lmax*1.1,-lmax*1.1,0.0, xp, yp, ct,st,cp,sp);
00219 lux_draw_string(win, xp, yp, -0.5, "z", 0);
00220 }
00221
00222 void draw2d_axis(unsigned long win, float xmin, float xmax,
00223 float ymin, float ymax, int k)
00224 {
00225 lux_draw_axis(win);
00226
00227
00228
00229 switch (k) {
00230 case 3: lux_draw_string(win, (xmin+xmax)/2, ymin, -2.2, "x", 0); break;
00231 case 1: lux_draw_string(win, (xmin+xmax)/2, ymin, -2.2, "y", 0); break;
00232 case 2: lux_draw_string(win, (xmin+xmax)/2, ymin, -2.2, "z", 0); break;
00233 }
00234
00235
00236
00237 switch (k) {
00238 case 3: lux_draw_vstring(win, xmin, (ymin+ymax)/2,
00239 1.2, " y ", 0); break;
00240 case 1: lux_draw_vstring(win, xmin, (ymin+ymax)/2,
00241 1.2, " z ", 0); break;
00242 case 2: lux_draw_vstring(win, xmin, (ymin+ymax)/2,
00243 1.2, " x ", 0); break;
00244 }
00245 }
00246
00247
00248 void update_with_delay(unsigned long win, float t)
00249 {
00250 lux_update_fg(win);
00251 if (t > 0.0) lux_pause((int)(t*1000000.0));
00252 }
00253
00254
00255
00256 void show_instructions(unsigned long win, float r, char* buffer,
00257 int update)
00258 {
00259 float statusx, statusy;
00260 char s[255];
00261 int ptr = 0, len, line = 0;
00262
00263 lux_clear_window(win);
00264 lux_reconvert_rcoord(win,0,0,&statusx, &statusy);
00265 istrstream ins(buffer,strlen(buffer));
00266 while(ins.get(s,255,'\n')) {
00267 lux_draw_image_string(win, statusx, statusy,
00268 -(line+1)*linespacing, s, -1);
00269 ins.get(s[0]);
00270 line = line+1;
00271 }
00272 if (update) lux_update_fg(win);
00273 }
00274
00275
00276 void show_instructions(unsigned long win, float r, char* buffer,
00277 int line, int update)
00278 {
00279 float statusx, statusy;
00280 char s[255];
00281 int ptr = 0, len;
00282
00283 lux_reconvert_rcoord(win,0,0,&statusx, &statusy);
00284 istrstream ins(buffer,strlen(buffer));
00285 while(ins.get(s,255,'\n')) {
00286 lux_draw_string(win, statusx, statusy, -(line+1)*linespacing, s, -1);
00287 ins.get(s[0]);
00288 line = line+1;
00289 }
00290 if (update) lux_update_fg(win);
00291 }
00292
00293
00294 void show_main_instructions(unsigned long instr,float r,int d,int u)
00295 {
00296 if (d)
00297 show_instructions(instr, r,
00298 "Running in 3-D mode\n\
00299 d: dialog, R: rotate, i: idle, q: quit\n\
00300 p/P decrease/increase point size\n\
00301 t add/remove tracking\n\
00302 n/l show nodes and/or links\n\
00303 2 enter 2-D mode\n\
00304 x/y/k 2-D and change viewing axis\n\
00305 e toggle energy color\n\
00306 < > ^ V rotate left right up down\n\
00307 +/- change delay time (0: fastest)\n\
00308 z/Z zoom in or out \n\
00309 arrow/page shift in x, y, z\n\
00310 h/home restore origin to (0,0,0)\n\
00311 a resize to enclose all stars\n\
00312 ",u);
00313
00314 else
00315
00316 show_instructions(instr, r,
00317 "Running in 2-D mode\n\
00318 d: dialog, i: idle, q: quit\n\
00319 p/P decrease/increase point size\n\
00320 t add/remove tracking\n\
00321 n/l show nodes and/or links (r: root)\n\
00322 3 enter 3-D mode\n\
00323 x/y/k change viewing axis\n\
00324 o/O set origin using mouse\n\
00325 e toggle energy color\n\
00326 +/- change delay time (0: fastest)\n\
00327 z/Z zoom in or out \n\
00328 arrow shift horizontally/vertically\n\
00329 h/home restore origin to (0,0,0)\n\
00330 a resize to enclose all stars\n\
00331 ",u);
00332 }
00333
00334 void format_and_show_instructions(unsigned long co, float r,
00335 unsigned long *c_i, int index, int tab,
00336 char* cstring, int line, int u)
00337 {
00338 if (index > 0) lux_set_color(co, c_i[index]);
00339
00340 char temp[80], temp1[80];
00341 sprintf(temp, " ");
00342 for (int i = 0; i < tab; i++) strcat(temp, TAB);
00343 sprintf(temp1, "%d - %s", index, cstring);
00344 strcat(temp, temp1);
00345
00346 show_instructions(co, r, temp, line, u);
00347 }
00348
00349 void show_color_scheme(unsigned long co, unsigned long *c_e, unsigned long *c_i,
00350 float r, char ce, bool b_flag, int u)
00351 {
00352 lux_clear_window(co);
00353
00354 if (ce) {
00355 show_instructions(co, r, "Color by energy:\n",0,u);
00356 lux_set_color(co, c_e[default_color]);
00357 if (b_flag)
00358 show_instructions(co, r,
00359 " White = default (bound to cluster)\n",1,u);
00360 else
00361 show_instructions(co, r,
00362 " Black = default (bound to cluster)\n",1,u);
00363 lux_set_color(co, c_e[bound_single]);
00364 show_instructions(co, r, " Blue = bound to nearest neighbor\n",2,u);
00365 lux_set_color(co, c_e[bound_binary]);
00366 show_instructions(co, r, " Green = bound binary\n",3,u);
00367 lux_set_color(co, c_e[unbound_single]);
00368 show_instructions(co, r, " Red = unbound single star\n",4,u);
00369 lux_set_color(co, c_e[unbound_binary]);
00370 show_instructions(co, r, " Gold = unbound binary\n",5,u);
00371 lux_set_color(co, c_e[default_color]);
00372
00373 } else {
00374
00375 show_instructions(co, r, "Color by index:\n",0,u);
00376 lux_set_color(co, c_i[1]);
00377
00378 if (b_flag) {
00379 format_and_show_instructions(co, r, c_i, 1, 0, "white", 1, u);
00380 format_and_show_instructions(co, r, c_i, 2, 1, RV_COLOR2, 1, u);
00381 format_and_show_instructions(co, r, c_i, 3, 2, RV_COLOR3, 1, u);
00382 format_and_show_instructions(co, r, c_i, 4, 0, RV_COLOR4, 2, u);
00383 format_and_show_instructions(co, r, c_i, 5, 1, RV_COLOR5, 2, u);
00384 format_and_show_instructions(co, r, c_i, 6, 2, RV_COLOR6, 2, u);
00385 format_and_show_instructions(co, r, c_i, 7, 0, RV_COLOR7, 3, u);
00386 format_and_show_instructions(co, r, c_i, 8, 1, RV_COLOR8, 3, u);
00387 format_and_show_instructions(co, r, c_i, 9, 2, RV_COLOR9, 3, u);
00388 format_and_show_instructions(co, r, c_i, 10, 0, RV_COLORa, 4, u);
00389 format_and_show_instructions(co, r, c_i, 11, 1, RV_COLORb, 4, u);
00390 format_and_show_instructions(co, r, c_i, 12, 2, RV_COLORc, 4, u);
00391 format_and_show_instructions(co, r, c_i, 13, 0, RV_COLORd, 5, u);
00392 format_and_show_instructions(co, r, c_i, 14, 1, RV_COLORe, 5, u);
00393 format_and_show_instructions(co, r, c_i, 15, 2, RV_COLORf, 5, u);
00394 format_and_show_instructions(co, r, c_i, 16, 0, RV_COLORg, 6, u);
00395 } else {
00396 format_and_show_instructions(co, r, c_i, 1, 0, "black", 1, u);
00397 format_and_show_instructions(co, r, c_i, 2, 1, NV_COLOR2, 1, u);
00398 format_and_show_instructions(co, r, c_i, 3, 2, NV_COLOR3, 1, u);
00399 format_and_show_instructions(co, r, c_i, 4, 0, NV_COLOR4, 2, u);
00400 format_and_show_instructions(co, r, c_i, 5, 1, NV_COLOR5, 2, u);
00401 format_and_show_instructions(co, r, c_i, 6, 2, NV_COLOR6, 2, u);
00402 format_and_show_instructions(co, r, c_i, 7, 0, NV_COLOR7, 3, u);
00403 format_and_show_instructions(co, r, c_i, 8, 1, NV_COLOR8, 3, u);
00404 format_and_show_instructions(co, r, c_i, 9, 2, NV_COLOR9, 3, u);
00405 format_and_show_instructions(co, r, c_i, 10, 0, NV_COLORa, 4, u);
00406 format_and_show_instructions(co, r, c_i, 11, 1, NV_COLORb, 4, u);
00407 format_and_show_instructions(co, r, c_i, 12, 2, NV_COLORc, 4, u);
00408 format_and_show_instructions(co, r, c_i, 13, 0, NV_COLORd, 5, u);
00409 format_and_show_instructions(co, r, c_i, 14, 1, NV_COLORe, 5, u);
00410 format_and_show_instructions(co, r, c_i, 15, 2, NV_COLORf, 5, u);
00411 format_and_show_instructions(co, r, c_i, 16, 0, NV_COLORg, 6, u);
00412 }
00413 lux_set_color(co, c_i[default_color]);
00414 }
00415 }
00416
00417 void init_colors(unsigned long win, unsigned long *ce, unsigned long *ci,
00418 bool b_flag)
00419 {
00420
00421
00422
00423
00424 if (b_flag) {
00425
00426
00427
00428 ce[background_color] = ci[background_color]
00429 = lux_rgb_pixel(win, 0.0,0.0,0.0);
00430 ce[default_color] = ci[default_color]
00431 = lux_rgb_pixel(win, 1.0,1.0,1.0);
00432
00433
00434
00435 ce[bound_single] = lux_lookup_color(win, "deepskyblue");
00436 ce[bound_binary] = lux_lookup_color(win, "green");
00437 ce[unbound_single] = lux_lookup_color(win, "red");
00438 ce[unbound_binary] = lux_lookup_color(win, "goldenrod");
00439
00440
00441
00442 ci[2] = lux_lookup_color(win, RV_COLOR2);
00443 ci[3] = lux_lookup_color(win, RV_COLOR3);
00444 ci[4] = lux_lookup_color(win, RV_COLOR4);
00445 ci[5] = lux_lookup_color(win, RV_COLOR5);
00446 ci[6] = lux_lookup_color(win, RV_COLOR6);
00447 ci[7] = lux_lookup_color(win, RV_COLOR7);
00448 ci[8] = lux_lookup_color(win, RV_COLOR8);
00449 ci[9] = lux_lookup_color(win, RV_COLOR9);
00450 ci[10] = lux_lookup_color(win, RV_COLORa);
00451 ci[11] = lux_lookup_color(win, RV_COLORb);
00452 ci[12] = lux_lookup_color(win, RV_COLORc);
00453 ci[13] = lux_lookup_color(win, RV_COLORd);
00454 ci[14] = lux_lookup_color(win, RV_COLORe);
00455 ci[15] = lux_lookup_color(win, RV_COLORf);
00456 ci[16] = lux_lookup_color(win, RV_COLORg);
00457
00458 } else {
00459
00460 ce[background_color] = ci[background_color]
00461 = lux_rgb_pixel(win, 1.0,1.0,1.0);
00462 ce[default_color] = ci[default_color]
00463 = lux_rgb_pixel(win, 0.0,0.0,0.0);
00464
00465
00466
00467 ce[bound_single] = lux_lookup_color(win, "blue");
00468 ce[bound_binary] = lux_lookup_color(win, "limegreen");
00469 ce[unbound_single] = lux_lookup_color(win, "red");
00470 ce[unbound_binary] = lux_lookup_color(win, "goldenrod");
00471
00472
00473
00474 ci[2] = lux_lookup_color(win, NV_COLOR2);
00475 ci[3] = lux_lookup_color(win, NV_COLOR3);
00476 ci[4] = lux_lookup_color(win, NV_COLOR4);
00477 ci[5] = lux_lookup_color(win, NV_COLOR5);
00478 ci[6] = lux_lookup_color(win, NV_COLOR6);
00479 ci[7] = lux_lookup_color(win, NV_COLOR7);
00480 ci[8] = lux_lookup_color(win, NV_COLOR8);
00481 ci[9] = lux_lookup_color(win, NV_COLOR9);
00482 ci[10] = lux_lookup_color(win, NV_COLORa);
00483 ci[11] = lux_lookup_color(win, NV_COLORb);
00484 ci[12] = lux_lookup_color(win, NV_COLORc);
00485 ci[13] = lux_lookup_color(win, NV_COLORd);
00486 ci[14] = lux_lookup_color(win, NV_COLORe);
00487 ci[15] = lux_lookup_color(win, NV_COLORf);
00488 ci[16] = lux_lookup_color(win, NV_COLORg);
00489
00490 }
00491
00492
00493
00494 for (int ke = bound_single; ke <= unbound_binary; ke++)
00495 if (ce[ke] == ce[background_color]) ce[ke] = ce[default_color];
00496 for (int ki = 2; ki < 16; ki++)
00497 if (ci[ki] == ci[background_color]) ci[ki] = ci[default_color];
00498 }
00499
00500 void set_limits(float* origin, float lmax3d,
00501 int kx, float& xmin, float& xmax,
00502 int ky, float& ymin, float& ymax)
00503 {
00504 xmin = origin[kx] - lmax3d;
00505 xmax = origin[kx] + lmax3d;
00506 ymin = origin[ky] - lmax3d;
00507 ymax = origin[ky] + lmax3d;
00508 }
00509
00510 float interp_to_x(float r, float s, float rr, float ss, float x)
00511 {
00512 return s + (ss - s) * (x - r) / (rr - r);
00513 }
00514
00515
00516 float interp_to_y(float r, float s, float rr, float ss, float y)
00517 {
00518 return r + (rr - r) * (y - s) / (ss - s);
00519 }