Changeset 834 for trunk/vizservers
- Timestamp:
- Dec 27, 2007, 9:06:49 AM (17 years ago)
- Location:
- trunk/vizservers/nanovis
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/vizservers/nanovis/Command.cpp
r829 r834 1 2 /* 3 * ---------------------------------------------------------------------- 4 * Command.cpp 5 * 6 * This modules creates the Tcl interface to the nanovis server. 7 * The communication protocol of the server is the Tcl language. 8 * Commands given to the server by clients are executed in a 9 * safe interpreter and the resulting image rendered offscreen 10 * is returned as BMP-formatted image data. 11 * 12 * ====================================================================== 13 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 14 * Michael McLennan <mmclennan@purdue.edu> 15 * Purdue Rendering and Perceptualization Lab (PURPL) 16 * 17 * Copyright (c) 2004-2006 Purdue Research Foundation 18 * 19 * See the file "license.terms" for information on usage and 20 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 21 * ====================================================================== 22 */ 23 24 1 25 #include "Command.h" 2 3 26 4 27 #include "nanovis.h" … … 34 57 // EXTERN DECLARATIONS 35 58 // in Nv.cpp 59 36 60 extern VolumeRenderer* g_vol_render; 37 61 extern PointSetRenderer* g_pointset_renderer; … … 54 78 extern Camera* cam; 55 79 56 extern char *def_transfunc;57 extern Tcl_HashTable tftable;58 80 extern float live_diffuse; 59 81 extern float live_specular; … … 69 91 extern Rappture::Outcome load_volume_stream(int index, std::iostream& fin); 70 92 extern Rappture::Outcome load_volume_stream2(int index, std::iostream& fin); 71 extern void load_volume(int index, int width, int height, int depth, int n_component, float* data, double vmin, double vmax, 72 double nzero_min); 73 extern TransferFunction* get_transfunc(char *name); 74 extern void resize_offscreen_buffer(int w, int h); 75 extern void offscreen_buffer_capture(); 93 extern void load_volume(int index, int width, int height, int depth, 94 int n_component, float* data, double vmin, double vmax, 95 double nzero_min); 96 97 extern TransferFunction* nv_get_transfunc(const char *name); 98 extern TransferFunction* nv_set_transfunc(const char *name, int nSlots, 99 float *data); 100 101 extern void nv_resize_offscreen_buffer(int w, int h); 102 extern void nv_offscreen_buffer_capture(); 76 103 extern void bmp_header_add_int(unsigned char* header, int& pos, int data); 77 104 extern void bmp_write(const char* cmd); 78 105 extern void bmp_write_to_file(); 79 extern void display(); 80 extern void display_offscreen_buffer(); 81 extern void read_screen(); 82 extern int renderLegend(int ivol, int width, int height, const char* volArg); 106 extern void nv_display(); 107 extern void nv_display_offscreen_buffer(); 108 extern void nv_read_screen(); 109 extern int nv_render_legend(TransferFunction *tf, double min, double max, 110 int width, int height, const char* volArg); 83 111 84 112 // Tcl interpreter for incoming messages 85 Tcl_Interp *interp; 86 Tcl_DString cmdbuffer; 87 88 static int ScreenShotCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])); 89 static int CameraCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])); 90 static int CutplaneCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])); 91 static int LegendCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])); 92 static int ScreenCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])); 93 static int TransfuncCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])); 94 static int UpCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])); 95 static int VolumeCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])); 96 97 static int PlaneNewCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])); 98 static int PlaneLinkCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])); 99 static int PlaneEnableCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])); 100 101 static int GridCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])); 102 static int AxisCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])); 103 104 static int GetVolumeIndices _ANSI_ARGS_((Tcl_Interp *interp, int argc, CONST84 char *argv[], vector<int>* vectorPtr)); 105 static int GetIndices(Tcl_Interp *interp, int argc, CONST84 char *argv[], vector<int>* vectorPtr); 106 static int GetAxis _ANSI_ARGS_((Tcl_Interp *interp, char *str, int *valPtr)); 107 static int GetColor _ANSI_ARGS_((Tcl_Interp *interp, char *str, float *rgbPtr)); 108 113 static Tcl_Interp *interp; 114 static Tcl_DString cmdbuffer; 115 116 // default transfer function 117 static const char def_transfunc[] = "transfunc define default {\n\ 118 0.0 1 1 1\n\ 119 0.2 1 1 0\n\ 120 0.4 0 1 0\n\ 121 0.6 0 1 1\n\ 122 0.8 0 0 1\n\ 123 1.0 1 0 1\n\ 124 } {\n\ 125 0.00 1.0\n\ 126 0.05 0.0\n\ 127 0.15 0.0\n\ 128 0.20 1.0\n\ 129 0.25 0.0\n\ 130 0.35 0.0\n\ 131 0.40 1.0\n\ 132 0.45 0.0\n\ 133 0.55 0.0\n\ 134 0.60 1.0\n\ 135 0.65 0.0\n\ 136 0.75 0.0\n\ 137 0.80 1.0\n\ 138 0.85 0.0\n\ 139 0.95 0.0\n\ 140 1.00 1.0\n\ 141 }"; 142 143 static Tcl_CmdProc AxisCmd; 144 static Tcl_CmdProc CameraCmd; 145 static Tcl_CmdProc CutplaneCmd; 146 static Tcl_CmdProc GridCmd; 147 static Tcl_CmdProc LegendCmd; 148 static Tcl_CmdProc PlaneEnableCmd; 149 static Tcl_CmdProc PlaneLinkCmd; 150 static Tcl_CmdProc PlaneNewCmd; 151 static Tcl_CmdProc ScreenCmd; 152 static Tcl_CmdProc ScreenShotCmd; 153 static Tcl_CmdProc TransfuncCmd; 154 static Tcl_CmdProc UniRect2dCmd; 155 static Tcl_CmdProc UpCmd; 156 static Tcl_CmdProc VolumeCmd; 157 158 static int GetVolumeIndices(Tcl_Interp *interp, int argc, const char *argv[], 159 vector<int>* vectorPtr); 160 static int GetVolume(Tcl_Interp *interp, const char *string, 161 Volume **volPtrPtr); 162 static int GetVolumeIndex(Tcl_Interp *interp, const char *string, 163 int *indexPtr); 164 static int GetHeightMap(Tcl_Interp *interp, const char *string, 165 HeightMap **hmPtrPtr); 166 static int GetIndices(Tcl_Interp *interp, int argc, const char *argv[], 167 vector<int>* vectorPtr); 168 static int GetAxis(Tcl_Interp *interp, const char *string, int *valPtr); 169 static int GetColor(Tcl_Interp *interp, const char *string, float *rgbPtr); 170 static int FillBufferFromStdin(Tcl_Interp *interp, Rappture::Buffer &buf, 171 int nBytes); 172 static HeightMap *CreateHeightMap(ClientData clientData, Tcl_Interp *interp, 173 int argc, const char *argv[]); 174 175 176 static int 177 GetFloat(Tcl_Interp *interp, const char *string, float *valuePtr) 178 { 179 double value; 180 181 if (Tcl_GetDouble(interp, string, &value) != TCL_OK) { 182 return TCL_ERROR; 183 } 184 *valuePtr = (float)value; 185 } 109 186 110 187 /* … … 121 198 * ---------------------------------------------------------------------- 122 199 */ 123 static int CameraCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]) 124 { 125 if (argc < 2) { 126 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 127 " option arg arg...\"", (char*)NULL); 128 return TCL_ERROR; 129 } 130 131 char c = *argv[1]; 132 if (c == 'a' && strcmp(argv[1],"angle") == 0) { 200 static int 201 CameraCmd(ClientData cdata, Tcl_Interp *interp, int argc, const char *argv[]) 202 { 203 if (argc < 2) { 204 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 205 " option arg arg...\"", (char*)NULL); 206 return TCL_ERROR; 207 } 208 209 char c = argv[1][0]; 210 if ((c == 'a') && (strcmp(argv[1],"angle") == 0)) { 133 211 if (argc != 5) { 134 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 135 " angle xangle yangle zangle\"", (char*)NULL); 136 return TCL_ERROR; 137 } 138 212 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 213 " angle xangle yangle zangle\"", (char*)NULL); 214 return TCL_ERROR; 215 } 139 216 double xangle, yangle, zangle; 140 if (Tcl_GetDouble(interp, argv[2], &xangle) != TCL_OK) { 141 return TCL_ERROR; 142 } 143 if (Tcl_GetDouble(interp, argv[3], &yangle) != TCL_OK) { 144 return TCL_ERROR; 145 } 146 if (Tcl_GetDouble(interp, argv[4], &zangle) != TCL_OK) { 147 return TCL_ERROR; 148 } 149 cam->rotate(xangle, yangle, zangle); 150 151 return TCL_OK; 152 } 153 else if (c == 'a' && strcmp(argv[1],"aim") == 0) { 217 if ((Tcl_GetDouble(interp, argv[2], &xangle) != TCL_OK) || 218 (Tcl_GetDouble(interp, argv[3], &yangle) != TCL_OK) || 219 (Tcl_GetDouble(interp, argv[4], &zangle) != TCL_OK)) { 220 return TCL_ERROR; 221 } 222 cam->rotate(xangle, yangle, zangle); 223 } else if ((c == 'a') && (strcmp(argv[1], "aim") == 0)) { 154 224 if (argc != 5) { 155 156 " aim x y z\"", (char*)NULL);157 158 } 159 225 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 226 " aim x y z\"", (char*)NULL); 227 return TCL_ERROR; 228 } 229 160 230 double x0, y0, z0; 161 if (Tcl_GetDouble(interp, argv[2], &x0) != TCL_OK) { 162 return TCL_ERROR; 163 } 164 if (Tcl_GetDouble(interp, argv[3], &y0) != TCL_OK) { 165 return TCL_ERROR; 166 } 167 if (Tcl_GetDouble(interp, argv[4], &z0) != TCL_OK) { 168 return TCL_ERROR; 169 } 170 cam->aim(x0, y0, z0); 171 172 return TCL_OK; 173 } 174 else if (c == 'z' && strcmp(argv[1],"zoom") == 0) { 231 if ((Tcl_GetDouble(interp, argv[2], &x0) != TCL_OK) || 232 (Tcl_GetDouble(interp, argv[3], &y0) != TCL_OK) || 233 (Tcl_GetDouble(interp, argv[4], &z0) != TCL_OK)) { 234 return TCL_ERROR; 235 } 236 cam->aim(x0, y0, z0); 237 } else if ((c == 'z') && (strcmp(argv[1],"zoom") == 0)) { 175 238 if (argc != 3) { 176 177 " zoom factor\"", (char*)NULL);178 179 } 180 239 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 240 " zoom factor\"", (char*)NULL); 241 return TCL_ERROR; 242 } 243 181 244 double zoom; 182 183 184 185 245 if (Tcl_GetDouble(interp, argv[2], &zoom) != TCL_OK) { 246 return TCL_ERROR; 247 } 248 186 249 live_obj_z = -2.5/zoom; 187 cam->move(live_obj_x, live_obj_y, live_obj_z); 188 189 return TCL_OK; 190 } 191 250 cam->move(live_obj_x, live_obj_y, live_obj_z); 251 } else { 192 252 Tcl_AppendResult(interp, "bad option \"", argv[1], 193 "\": should be aim, angle, or zoom", (char*)NULL); 194 return TCL_ERROR; 253 "\": should be aim, angle, or zoom", (char*)NULL); 254 return TCL_ERROR; 255 } 256 return TCL_OK; 195 257 } 196 258 197 259 static int 198 ScreenShotCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]) 260 ScreenShotCmd(ClientData cdata, Tcl_Interp *interp, int argc, 261 const char *argv[]) 199 262 { 200 263 int old_win_width = win_width; … … 202 265 203 266 #ifdef XINETD 204 resize_offscreen_buffer(1024, 1024);267 nv_resize_offscreen_buffer(1024, 1024); 205 268 cam->set_screen_size(30, 90, 1024 - 60, 1024 - 120); 206 offscreen_buffer_capture(); //enable offscreen render207 display();269 nv_offscreen_buffer_capture(); //enable offscreen render 270 nv_display(); 208 271 209 272 // INSOO 210 273 // TBD 211 274 Volume* vol = volume[0]; 212 TransferFunction* tf = g_vol_render->get_volume_shading(vol);213 if (tf)214 {275 TransferFunction* tf; 276 tf = g_vol_render->get_volume_shading(vol); 277 if (tf != NULL) { 215 278 float data[512]; 279 216 280 for (int i=0; i < 256; i++) { 217 281 data[i] = data[i+256] = (float)(i/255.0); 218 282 } 219 283 Texture2D* plane = new Texture2D(256, 2, GL_FLOAT, GL_LINEAR, 1, data); 220 g_color_table_renderer->render(1024, 1024, plane, tf, vol->range_min(), vol->range_max()); 284 g_color_table_renderer->render(1024, 1024, plane, tf, vol->range_min(), 285 vol->range_max()); 221 286 delete plane; 222 287 } 223 224 read_screen(); 288 nv_read_screen(); 225 289 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 226 227 290 bmp_write("nv>screenshot -bytes"); 228 229 resize_offscreen_buffer(old_win_width, old_win_height); 291 nv_resize_offscreen_buffer(old_win_width, old_win_height); 230 292 #endif 231 232 return TCL_OK; 293 return TCL_OK; 233 294 } 234 295 … … 247 308 * are updated. 248 309 * ---------------------------------------------------------------------- 249 */ 250 310 */ 251 311 static int 252 CutplaneCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]) 312 CutplaneCmd(ClientData cdata, Tcl_Interp *interp, int argc, 313 const char *argv[]) 253 314 { 254 315 if (argc < 2) { … … 258 319 } 259 320 260 char c = *argv[1];261 if ( c == 's' && strcmp(argv[1],"state") == 0) {321 char c = argv[1][0]; 322 if ((c == 's') && (strcmp(argv[1],"state") == 0)) { 262 323 if (argc < 4) { 263 324 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], … … 280 341 return TCL_ERROR; 281 342 } 282 283 vector<int>::iterator iter = ivol.begin(); 284 while (iter != ivol.end()) { 285 if (state) { 343 if (state) { 344 vector<int>::iterator iter; 345 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 286 346 volume[*iter]->enable_cutplane(axis); 287 } else { 347 } 348 } else { 349 vector<int>::iterator iter; 350 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 288 351 volume[*iter]->disable_cutplane(axis); 289 } 290 ++iter; 291 } 292 return TCL_OK; 293 } 294 else if (c == 'p' && strcmp(argv[1],"position") == 0) { 352 } 353 } 354 } else if ((c == 'p') && (strcmp(argv[1],"position") == 0)) { 295 355 if (argc < 4) { 296 356 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], … … 299 359 } 300 360 301 doublerelval;302 if ( Tcl_GetDouble(interp, argv[2], &relval) != TCL_OK) {361 float relval; 362 if (GetFloat(interp, argv[2], &relval) != TCL_OK) { 303 363 return TCL_ERROR; 304 364 } 305 365 // keep this just inside the volume so it doesn't disappear 306 if (relval < 0.01) { relval = 0.01; } 307 if (relval > 0.99) { relval = 0.99; } 366 if (relval < 0.01f) { 367 relval = 0.01f; 368 } else if (relval > 0.99f) { 369 relval = 0.99f; 370 } 308 371 309 372 int axis; 310 if (GetAxis(interp, (char*)argv[3], &axis) != TCL_OK) {373 if (GetAxis(interp, argv[3], &axis) != TCL_OK) { 311 374 return TCL_ERROR; 312 375 } 313 376 314 377 vector<int> ivol; 315 if (GetVolumeIndices(interp, argc -4, argv+4, &ivol) != TCL_OK) {378 if (GetVolumeIndices(interp, argc - 4, argv + 4, &ivol) != TCL_OK) { 316 379 return TCL_ERROR; 317 380 } 318 319 vector<int>::iterator iter = ivol.begin(); 320 while (iter != ivol.end()) { 321 volume[*iter]->move_cutplane(axis, (float)relval); 322 ++iter; 323 } 324 return TCL_OK; 325 } 326 327 Tcl_AppendResult(interp, "bad option \"", argv[1], 328 "\": should be position or state", (char*)NULL); 329 return TCL_ERROR; 330 } 331 381 vector<int>::iterator iter; 382 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 383 volume[*iter]->move_cutplane(axis, relval); 384 } 385 } else { 386 Tcl_AppendResult(interp, "bad option \"", argv[1], 387 "\": should be position or state", (char*)NULL); 388 return TCL_ERROR; 389 } 390 return TCL_OK; 391 } 332 392 333 393 /* … … 343 403 */ 344 404 static int 345 LegendCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84char *argv[])405 LegendCmd(ClientData cdata, Tcl_Interp *interp, int argc, const char *argv[]) 346 406 { 347 407 if (argc != 4) { … … 351 411 } 352 412 353 TransferFunction *tf = NULL; 354 int ivol; 355 if (Tcl_GetInt(interp, argv[1], &ivol) != TCL_OK) { 413 Volume *vol; 414 if (GetVolume(interp, argv[1], &vol) != TCL_OK) { 356 415 return TCL_ERROR; 357 416 } 358 359 if (ivol < n_volumes) { 360 tf = g_vol_render->get_volume_shading(volume[ivol]); 361 } 417 TransferFunction *tf; 418 tf = g_vol_render->get_volume_shading(vol); 362 419 if (tf == NULL) { 363 Tcl_AppendResult(interp, "transfer function not defined for volume ", argv[1], (char*)NULL); 420 Tcl_AppendResult(interp, "no transfer function defined for volume \"", 421 argv[1], "\"", (char*)NULL); 364 422 return TCL_ERROR; 365 423 } … … 375 433 return TCL_ERROR; 376 434 } 377 378 renderLegend(ivol, width, height, argv[1]); 379 435 nv_render_legend(tf, vol->range_min(), vol->range_max(), width, height, 436 argv[1]); 380 437 return TCL_OK; 381 438 } … … 391 448 */ 392 449 static int 393 ScreenCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84char *argv[])450 ScreenCmd(ClientData cdata, Tcl_Interp *interp, int argc, const char *argv[]) 394 451 { 395 452 int w, h; … … 406 463 return TCL_ERROR; 407 464 } 408 resize_offscreen_buffer(w, h); 409 465 nv_resize_offscreen_buffer(w, h); 410 466 return TCL_OK; 411 467 } … … 422 478 */ 423 479 static int 424 TransfuncCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]) 425 { 426 if (argc < 2) { 427 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 428 " option arg arg...\"", (char*)NULL); 429 return TCL_ERROR; 430 } 431 432 char c = *argv[1]; 433 if (c == 'd' && strcmp(argv[1],"define") == 0) { 480 TransfuncCmd(ClientData cdata, Tcl_Interp *interp, int argc, 481 const char *argv[]) 482 { 483 if (argc < 2) { 484 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 485 " option arg arg...\"", (char*)NULL); 486 return TCL_ERROR; 487 } 488 489 char c = argv[1][0]; 490 if ((c == 'd') && (strcmp(argv[1],"define") == 0)) { 434 491 if (argc != 5) { 435 436 argv[1]," define name colormap alphamap\"", (char*)NULL);492 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 493 " define name colormap alphamap\"", (char*)NULL); 437 494 return TCL_ERROR; 438 495 } … … 440 497 // decode the data and store in a series of fields 441 498 Rappture::Field1D rFunc, gFunc, bFunc, wFunc; 442 int cmapc, wmapc, i, j; 443 char **cmapv, **wmapv; 444 445 if (Tcl_SplitList(interp, argv[3], &cmapc, (const char***)&cmapv) != TCL_OK) { 499 int cmapc, wmapc, i; 500 const char **cmapv; 501 const char **wmapv; 502 503 wmapv = cmapv = NULL; 504 if (Tcl_SplitList(interp, argv[3], &cmapc, &cmapv) != TCL_OK) { 446 505 return TCL_ERROR; 447 506 } 448 if (cmapc % 4 != 0) { 449 Tcl_Free((char*)cmapv); 450 Tcl_AppendResult(interp, "bad colormap in transfunc: should be ", 507 if ((cmapc % 4) != 0) { 508 Tcl_AppendResult(interp, "bad colormap in transfunc: should be ", 451 509 "{ v r g b ... }", (char*)NULL); 452 return TCL_ERROR; 453 } 454 455 if (Tcl_SplitList(interp, argv[4], &wmapc, (const char***)&wmapv) != TCL_OK) { 456 return TCL_ERROR; 457 } 458 if (wmapc % 2 != 0) { 459 Tcl_Free((char*)cmapv); 460 Tcl_Free((char*)wmapv); 461 Tcl_AppendResult(interp, "bad alphamap in transfunc: should be ", 462 "{ v w ... }", (char*)NULL); 463 return TCL_ERROR; 464 } 465 510 Tcl_Free((char*)cmapv); 511 return TCL_ERROR; 512 } 513 514 if (Tcl_SplitList(interp, argv[4], &wmapc, &wmapv) != TCL_OK) { 515 Tcl_Free((char*)cmapv); 516 return TCL_ERROR; 517 } 518 if ((wmapc % 2) != 0) { 519 Tcl_AppendResult(interp, "wrong # elements in alphamap: should be ", 520 " { v w ... }", (char*)NULL); 521 Tcl_Free((char*)cmapv); 522 Tcl_Free((char*)wmapv); 523 return TCL_ERROR; 524 } 466 525 for (i=0; i < cmapc; i += 4) { 526 int j; 467 527 double vals[4]; 528 468 529 for (j=0; j < 4; j++) { 469 530 if (Tcl_GetDouble(interp, cmapv[i+j], &vals[j]) != TCL_OK) { 470 471 472 531 Tcl_Free((char*)cmapv); 532 Tcl_Free((char*)wmapv); 533 return TCL_ERROR; 473 534 } 474 if (vals[j] < 0 || vals[j] > 1) { 475 Tcl_Free((char*)cmapv); 476 Tcl_Free((char*)wmapv); 477 Tcl_AppendResult(interp, "bad value \"", cmapv[i+j], 535 if ((vals[j] < 0.0) || (vals[j] > 1.0)) { 536 Tcl_AppendResult(interp, "bad value \"", cmapv[i+j], 478 537 "\": should be in the range 0-1", (char*)NULL); 479 return TCL_ERROR; 538 Tcl_Free((char*)cmapv); 539 Tcl_Free((char*)wmapv); 540 return TCL_ERROR; 480 541 } 481 542 } … … 484 545 bFunc.define(vals[0], vals[3]); 485 546 } 486 487 547 for (i=0; i < wmapc; i += 2) { 488 548 double vals[2]; 549 int j; 550 489 551 for (j=0; j < 2; j++) { 490 552 if (Tcl_GetDouble(interp, wmapv[i+j], &vals[j]) != TCL_OK) { 491 492 493 553 Tcl_Free((char*)cmapv); 554 Tcl_Free((char*)wmapv); 555 return TCL_ERROR; 494 556 } 495 if (vals[j] < 0 || vals[j] > 1) { 496 Tcl_Free((char*)cmapv); 497 Tcl_Free((char*)wmapv); 498 Tcl_AppendResult(interp, "bad value \"", wmapv[i+j], 557 if ((vals[j] < 0.0) || (vals[j] > 1.0)) { 558 Tcl_AppendResult(interp, "bad value \"", wmapv[i+j], 499 559 "\": should be in the range 0-1", (char*)NULL); 500 return TCL_ERROR; 560 Tcl_Free((char*)cmapv); 561 Tcl_Free((char*)wmapv); 562 return TCL_ERROR; 501 563 } 502 564 } … … 518 580 519 581 // find or create this transfer function 520 int newEntry;521 Tcl_HashEntry *entryPtr;522 582 TransferFunction *tf; 523 524 entryPtr = Tcl_CreateHashEntry(&tftable, argv[2], &newEntry); 525 if (newEntry) { 526 tf = new TransferFunction(nslots, data); 527 Tcl_SetHashValue(entryPtr, (ClientData)tf); 528 } else { 529 tf = (TransferFunction*)Tcl_GetHashValue(entryPtr); 530 tf->update(data); 531 } 532 533 return TCL_OK; 534 } 535 536 537 Tcl_AppendResult(interp, "bad option \"", argv[1], 538 "\": should be define", (char*)NULL); 539 return TCL_ERROR; 583 tf = nv_get_transfunc(argv[2]); 584 if (tf != NULL) { 585 tf->update(data); 586 } else { 587 tf = nv_set_transfunc(argv[2], nslots, data); 588 } 589 } else { 590 Tcl_AppendResult(interp, "bad option \"", argv[1], 591 "\": should be define", (char*)NULL); 592 return TCL_ERROR; 593 } 594 return TCL_OK; 540 595 } 541 596 … … 550 605 */ 551 606 static int 552 UpCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84char *argv[])607 UpCmd(ClientData cdata, Tcl_Interp *interp, int argc, const char *argv[]) 553 608 { 554 609 if (argc != 2) { … … 559 614 560 615 int sign = 1; 616 561 617 char *axisName = (char*)argv[1]; 562 618 if (*axisName == '-') { … … 569 625 return TCL_ERROR; 570 626 } 571 572 627 updir = (axis+1)*sign; 573 574 628 return TCL_OK; 575 629 } … … 591 645 * ---------------------------------------------------------------------- 592 646 */ 593 594 647 static int 595 VolumeCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84char *argv[])648 VolumeCmd(ClientData cdata, Tcl_Interp *interp, int argc, const char *argv[]) 596 649 { 597 650 if (argc < 2) { … … 601 654 } 602 655 603 char c = *argv[1];604 if ( c == 'a' && strcmp(argv[1],"axis") == 0) {656 char c = argv[1][0]; 657 if ((c == 'a') && (strcmp(argv[1],"axis") == 0)) { 605 658 if (argc < 3) { 606 659 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], … … 608 661 return TCL_ERROR; 609 662 } 610 c = *argv[2];611 if ( c == 'l' && strcmp(argv[2],"label") == 0) {663 c = argv[2][0]; 664 if ((c == 'l') && (strcmp(argv[2],"label") == 0)) { 612 665 if (argc < 4) { 613 666 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], … … 622 675 623 676 vector<int> ivol; 624 if (GetVolumeIndices(interp, argc -5, argv+5, &ivol) != TCL_OK) {625 return TCL_ERROR; 626 } 627 628 vector<int>::iterator iter = ivol.begin();629 while (iter != ivol.end()) {677 if (GetVolumeIndices(interp, argc - 5, argv + 5, &ivol) != TCL_OK) { 678 return TCL_ERROR; 679 } 680 681 vector<int>::iterator iter; 682 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 630 683 volume[*iter]->set_label(axis, (char*)argv[4]); 631 ++iter; 632 } 633 return TCL_OK; 634 } 635 636 Tcl_AppendResult(interp, "bad option \"", argv[2], 637 "\": should be label", (char*)NULL); 638 return TCL_ERROR; 639 } 640 else if (c == 'd' && strcmp(argv[1],"data") == 0) { 684 } 685 } else { 686 Tcl_AppendResult(interp, "bad option \"", argv[2], 687 "\": should be label", (char*)NULL); 688 return TCL_ERROR; 689 } 690 } else if ((c == 'd') && (strcmp(argv[1],"data") == 0)) { 641 691 if (argc < 3) { 642 692 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], … … 644 694 return TCL_ERROR; 645 695 } 646 c = *argv[2];647 if ( c == 's' && strcmp(argv[2],"state") == 0) {696 c = argv[2][0]; 697 if ((c == 's') && (strcmp(argv[2],"state") == 0)) { 648 698 if (argc < 4) { 649 699 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], … … 651 701 return TCL_ERROR; 652 702 } 653 654 703 int state; 655 704 if (Tcl_GetBoolean(interp, argv[3], &state) != TCL_OK) { 656 705 return TCL_ERROR; 657 706 } 658 659 707 vector<int> ivol; 660 708 if (GetVolumeIndices(interp, argc-4, argv+4, &ivol) != TCL_OK) { 661 709 return TCL_ERROR; 662 710 } 663 664 vector<int>::iterator iter = ivol.begin(); 665 while (iter != ivol.end()) { 666 if (state) { 711 if (state) { 712 vector<int>::iterator iter; 713 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 667 714 volume[*iter]->enable_data(); 668 } else { 715 } 716 } else { 717 vector<int>::iterator iter; 718 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 669 719 volume[*iter]->disable_data(); 670 } 671 ++iter; 672 } 673 return TCL_OK; 674 } 675 else if (c == 'f' && strcmp(argv[2],"follows") == 0) { 720 } 721 } 722 } else if (c == 'f' && strcmp(argv[2],"follows") == 0) { 676 723 printf("Data Loading\n"); 677 724 //fflush(stdout); … … 689 736 int totalsize = nbytes; 690 737 char buffer[8096]; 691 while (nbytes > 0) 692 { 693 int chunk = (sizeof(buffer) < nbytes) ? sizeof(buffer) : nbytes; 694 int status = fread(buffer, 1, chunk, stdin); 738 while (nbytes > 0) { 739 int chunk, status; 740 741 chunk = (sizeof(buffer) < nbytes) ? sizeof(buffer) : nbytes; 742 status = fread(buffer, 1, chunk, stdin); 695 743 //printf("Begin Reading [%d Read : %d Left]\n", status, nbytes - status); 696 744 fflush(stdout); … … 705 753 } 706 754 } 707 708 755 err = Rappture::encoding::decode(buf,RPENC_Z|RPENC_B64|RPENC_HDR); 709 756 if (err) { … … 721 768 #ifdef _LOCAL_ZINC_TEST_ 722 769 //FILE* fp = fopen("/home/nanohub/vrinside/nv/data/HOON/QDWL_100_100_50_strain_8000i.nd_zatom_12_1", "rb"); 723 FILE* fp = fopen("/home/nanohub/vrinside/nv/data/HOON/GaAs_AlGaAs_2QD_B4.nd_zc_1_wf", "rb");724 unsigned char* b = (unsigned char*) malloc(buf.size()); 725 if (fp == 0) 726 {770 FILE* fp; 771 772 fp = fopen("/home/nanohub/vrinside/nv/data/HOON/GaAs_AlGaAs_2QD_B4.nd_zc_1_wf", "rb"); 773 if (fp == NULL) { 727 774 printf("cannot open the file\n"); 728 775 fflush(stdout); 729 776 return TCL_ERROR; 730 777 } 778 unsigned char* b = (unsigned char*)malloc(buf.size()); 731 779 fread(b, buf.size(), 1, fp); 732 780 fclose(fp); 733 781 #endif 734 735 736 782 printf("Checking header[%s]\n", header); 737 783 fflush(stdout); 738 if (!strcmp(header, "<HDR>")) 739 { 784 if (strcmp(header, "<HDR>") == 0) { 740 785 Volume* vol = NULL; 741 786 … … 754 799 printf("finish loading\n"); 755 800 fflush(stdout); 756 if (vol) 757 { 758 while (n_volumes <= n) 759 { 801 if (vol) { 802 while (n_volumes <= n) { 760 803 volume.push_back((Volume*) NULL); 761 804 n_volumes++; 762 805 } 763 806 764 if (volume[n] != NULL) 765 { 807 if (volume[n] != NULL) { 766 808 delete volume[n]; 767 809 volume[n] = NULL; … … 775 817 volume[n] = vol; 776 818 } 777 }778 819 #ifdef __TEST_CODE__ 779 else if (!strcmp(header, "<FET>")) 780 { 820 } else if (strcmp(header, "<FET>") == 0) { 781 821 printf("FET loading...\n"); 782 822 fflush(stdout); … … 789 829 return TCL_ERROR; 790 830 } 791 }792 831 #endif 793 else 794 { 832 } else { 795 833 printf("OpenDX loading...\n"); 796 834 fflush(stdout); … … 814 852 // appear at all. 815 853 // 816 if (volume[n]) 817 { 854 if (volume[n] != NULL) { 818 855 volume[n]->set_n_slice(256-n); 819 856 volume[n]->disable_cutplane(0); … … 821 858 volume[n]->disable_cutplane(2); 822 859 823 g_vol_render->add_volume(volume[n], get_transfunc("default")); 824 } 825 826 return TCL_OK; 827 } 828 Tcl_AppendResult(interp, "bad option \"", argv[2], 829 "\": should be follows or state", (char*)NULL); 830 return TCL_ERROR; 831 } 832 else if (c == 'o' && strcmp(argv[1],"outline") == 0) { 860 g_vol_render->add_volume(volume[n],nv_get_transfunc("default")); 861 } 862 } else { 863 Tcl_AppendResult(interp, "bad option \"", argv[2], 864 "\": should be follows or state", (char*)NULL); 865 return TCL_ERROR; 866 } 867 } else if (c == 'o' && strcmp(argv[1],"outline") == 0) { 833 868 if (argc < 3) { 834 869 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], … … 836 871 return TCL_ERROR; 837 872 } 838 c = *argv[2];839 if ( c == 's' && strcmp(argv[2],"state") == 0) {873 c = argv[2][0]; 874 if ((c == 's') && (strcmp(argv[2],"state") == 0)) { 840 875 if (argc < 3) { 841 876 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], … … 848 883 return TCL_ERROR; 849 884 } 850 851 885 vector<int> ivol; 852 886 if (GetVolumeIndices(interp, argc-4, argv+4, &ivol) != TCL_OK) { 853 887 return TCL_ERROR; 854 888 } 855 856 vector<int>::iterator iter = ivol.begin(); 857 while (iter != ivol.end()) { 858 if (state) { 889 if (state) { 890 vector<int>::iterator iter; 891 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 859 892 volume[*iter]->enable_outline(); 860 } else { 893 } 894 } else { 895 vector<int>::iterator iter; 896 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 861 897 volume[*iter]->disable_outline(); 898 } 899 } 900 } else if (c == 'v' && strcmp(argv[2],"visible") == 0) { 901 int ivisible; 902 903 if (Tcl_GetBoolean(interp, argv[3], &ivisible) != TCL_OK) { 904 return TCL_ERROR; 905 } 906 if (!ivisible) { 907 for (int i = 0; i < n_volumes; ++i) { 908 if (volume[i]) { 909 volume[i]->disable_outline(); 910 } 862 911 } 863 ++iter; 864 } 865 return TCL_OK; 866 } 867 else if (c == 'v' && strcmp(argv[2],"visible") == 0) { 868 if (argv[3] == "false") 869 { 870 for (int i = 0; i < n_volumes; ++i) 871 { 872 if (volume[i]) volume[i]->disable_outline(); 912 } else { 913 for (int i = 0; i < n_volumes; ++i) { 914 if (volume[i]) { 915 volume[i]->enable_outline(); 916 } 873 917 } 874 918 } 875 else if (argv[3] == "true") 876 { 877 for (int i = 0; i < n_volumes; ++i) 878 { 879 if (volume[i]) volume[i]->enable_outline(); 880 } 881 } 882 883 return TCL_OK; 884 } 885 else if (c == 'c' && strcmp(argv[2],"color") == 0) { 919 } else if ((c == 'c') && (strcmp(argv[2],"color") == 0)) { 886 920 if (argc < 3) { 887 921 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], … … 889 923 return TCL_ERROR; 890 924 } 891 892 925 float rgb[3]; 893 if (GetColor(interp, (char*) argv[3], rgb) != TCL_OK) { 894 return TCL_ERROR; 895 } 896 926 if (GetColor(interp, argv[3], rgb) != TCL_OK) { 927 return TCL_ERROR; 928 } 897 929 vector<int> ivol; 898 if (GetVolumeIndices(interp, argc-4, argv+4, &ivol) != TCL_OK) { 899 return TCL_ERROR; 900 } 901 902 vector<int>::iterator iter = ivol.begin(); 903 while (iter != ivol.end()) { 930 if (GetVolumeIndices(interp, argc - 4, argv + 4, &ivol) != TCL_OK) { 931 return TCL_ERROR; 932 } 933 vector<int>::iterator iter; 934 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 904 935 volume[*iter]->set_outline_color(rgb); 905 ++iter; 906 } 907 return TCL_OK; 908 } 909 910 Tcl_AppendResult(interp, "bad option \"", argv[2], 911 "\": should be color or state", (char*)NULL); 912 return TCL_ERROR; 913 } 914 else if (c == 's' && strcmp(argv[1],"shading") == 0) { 936 } 937 } else { 938 Tcl_AppendResult(interp, "bad option \"", argv[2], 939 "\": should be color or state", (char*)NULL); 940 return TCL_ERROR; 941 } 942 } else if ((c == 's') && (strcmp(argv[1],"shading") == 0)) { 915 943 if (argc < 3) { 916 944 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], … … 918 946 return TCL_ERROR; 919 947 } 920 c = *argv[2];921 if ( c == 't' && strcmp(argv[2],"transfunc") == 0) {948 c = argv[2][0]; 949 if ((c == 't') && (strcmp(argv[2],"transfunc") == 0)) { 922 950 if (argc < 4) { 923 951 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], … … 925 953 return TCL_ERROR; 926 954 } 927 928 TransferFunction *tf = get_transfunc((char*)argv[3]);955 TransferFunction *tf; 956 tf = nv_get_transfunc(argv[3]); 929 957 if (tf == NULL) { 930 958 Tcl_AppendResult(interp, "transfer function \"", argv[3], … … 932 960 return TCL_ERROR; 933 961 } 934 935 962 vector<int> ivol; 936 963 if (GetVolumeIndices(interp, argc-4, argv+4, &ivol) != TCL_OK) { 937 964 return TCL_ERROR; 938 965 } 939 940 vector<int>::iterator iter = ivol.begin(); 941 while (iter != ivol.end()) { 966 vector<int>::iterator iter; 967 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 942 968 g_vol_render->shade_volume(volume[*iter], tf); 943 ++iter; 944 } 945 return TCL_OK; 946 } 947 else if (c == 'd' && strcmp(argv[2],"diffuse") == 0) { 969 } 970 } else if ((c == 'd') && (strcmp(argv[2], "diffuse") == 0)) { 948 971 if (argc < 4) { 949 972 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], … … 952 975 } 953 976 954 double dval; 955 if (Tcl_GetDouble(interp, argv[3], &dval) != TCL_OK) { 956 return TCL_ERROR; 957 } 958 977 float diffuse; 978 if (GetFloat(interp, argv[3], &diffuse) != TCL_OK) { 979 return TCL_ERROR; 980 } 959 981 vector<int> ivol; 960 982 if (GetVolumeIndices(interp, argc-4, argv+4, &ivol) != TCL_OK) { 961 983 return TCL_ERROR; 962 984 } 963 964 vector<int>::iterator iter = ivol.begin(); 965 while (iter != ivol.end()) { 966 volume[*iter]->set_diffuse((float)dval); 967 ++iter; 968 } 969 return TCL_OK; 970 } 971 else if (c == 'o' && strcmp(argv[2],"opacity") == 0) { 985 vector<int>::iterator iter; 986 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 987 volume[*iter]->set_diffuse(diffuse); 988 } 989 } else if ((c == 'o') && (strcmp(argv[2], "opacity") == 0)) { 972 990 if (argc < 4) { 973 991 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], … … 975 993 return TCL_ERROR; 976 994 } 977 978 double dval; 979 if (Tcl_GetDouble(interp, argv[3], &dval) != TCL_OK) { 980 return TCL_ERROR; 981 } 982 995 float opacity; 996 if (GetFloat(interp, argv[3], &opacity) != TCL_OK) { 997 return TCL_ERROR; 998 } 983 999 vector<int> ivol; 984 1000 if (GetVolumeIndices(interp, argc-4, argv+4, &ivol) != TCL_OK) { 985 1001 return TCL_ERROR; 986 1002 } 987 988 vector<int>::iterator iter = ivol.begin(); 989 while (iter != ivol.end()) { 990 volume[*iter]->set_opacity_scale((float)dval); 991 ++iter; 992 } 993 return TCL_OK; 994 } 995 else if (c == 's' && strcmp(argv[2],"specular") == 0) { 1003 vector<int>::iterator iter; 1004 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1005 volume[*iter]->set_opacity_scale(opacity); 1006 } 1007 } else if ((c == 's') && (strcmp(argv[2], "specular") == 0)) { 996 1008 if (argc < 4) { 997 1009 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], … … 999 1011 return TCL_ERROR; 1000 1012 } 1001 1002 double dval; 1003 if (Tcl_GetDouble(interp, argv[3], &dval) != TCL_OK) { 1004 return TCL_ERROR; 1005 } 1006 1013 float specular; 1014 if (GetFloat(interp, argv[3], &specular) != TCL_OK) { 1015 return TCL_ERROR; 1016 } 1007 1017 vector<int> ivol; 1008 1018 if (GetVolumeIndices(interp, argc-4, argv+4, &ivol) != TCL_OK) { 1009 1019 return TCL_ERROR; 1010 1020 } 1011 1012 vector<int>::iterator iter = ivol.begin(); 1013 while (iter != ivol.end()) { 1014 volume[*iter]->set_specular((float)dval); 1015 ++iter; 1016 } 1017 return TCL_OK; 1018 } 1019 Tcl_AppendResult(interp, "bad option \"", argv[2], 1020 "\": should be diffuse, opacity, specular, or transfunc", (char*)NULL); 1021 return TCL_ERROR; 1022 } 1023 else if (c == 's' && strcmp(argv[1],"state") == 0) { 1021 vector<int>::iterator iter; 1022 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1023 volume[*iter]->set_specular(specular); 1024 } 1025 } else { 1026 Tcl_AppendResult(interp, "bad option \"", argv[2], "\": should be ", 1027 "diffuse, opacity, specular, or transfunc", (char*)NULL); 1028 return TCL_ERROR; 1029 } 1030 } else if ((c == 's') && (strcmp(argv[1], "state") == 0)) { 1024 1031 if (argc < 3) { 1025 1032 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], … … 1027 1034 return TCL_ERROR; 1028 1035 } 1029 1030 1036 int state; 1031 1037 if (Tcl_GetBoolean(interp, argv[2], &state) != TCL_OK) { 1032 1038 return TCL_ERROR; 1033 1039 } 1034 1035 1040 vector<int> ivol; 1036 1041 if (GetVolumeIndices(interp, argc-3, argv+3, &ivol) != TCL_OK) { 1037 1042 return TCL_ERROR; 1038 1043 } 1039 1040 vector<int>::iterator iter = ivol.begin(); 1041 while (iter != ivol.end()) { 1042 if (state) { 1043 volume[*iter]->enable(); 1044 } else { 1045 volume[*iter]->disable(); 1046 } 1047 ++iter; 1048 } 1049 return TCL_OK; 1050 } 1051 else if (c == 't' && strcmp(argv[1],"test2") == 0) { 1044 if (state) { 1045 vector<int>::iterator iter; 1046 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1047 volume[*iter]->enable(); 1048 } 1049 } else { 1050 vector<int>::iterator iter; 1051 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1052 volume[*iter]->disable(); 1053 } 1054 } 1055 } else if ((c == 't') && (strcmp(argv[1],"test2") == 0)) { 1052 1056 volume[1]->disable_data(); 1053 1057 volume[1]->disable(); 1054 1058 return TCL_OK; 1055 } 1056 1057 Tcl_AppendResult(interp, "bad option \"", argv[1], 1058 "\": should be data, outline, shading, or state", (char*)NULL); 1059 return TCL_ERROR; 1060 } 1061 1062 1063 int HeightMapCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])) 1064 { 1065 if (argc < 2) 1066 { 1067 { 1068 srand( (unsigned)time( NULL ) ); 1069 int size = 20 * 20; 1070 float sigma = 5.0f; 1071 float mean = exp(0.0f) / (sigma * sqrt(2.0f)); 1072 float* data = (float*) malloc(sizeof(float) * size); 1073 1074 float x; 1075 for (int i = 0; i < size; ++i) 1076 { 1077 x = - 10 + i%20; 1078 data[i] = exp(- (x * x)/(2 * sigma * sigma)) / (sigma * sqrt(2.0f)) / mean; 1079 } 1080 1081 HeightMap* heightMap = new HeightMap(); 1082 heightMap->setHeight(0, 0, 1, 1, 20, 20, data); 1083 heightMap->setColorMap(get_transfunc("default")); 1084 heightMap->setVisible(true); 1085 heightMap->setLineContourVisible(true); 1086 g_heightMap.push_back(heightMap); 1087 } 1088 1089 return TCL_OK; 1090 } 1091 1092 char c = *argv[1]; 1093 if (c == 'd' && strcmp(argv[1],"data") == 0) 1094 { 1059 } else { 1060 Tcl_AppendResult(interp, "bad option \"", argv[1], "\": should be ", 1061 "data, outline, shading, or state", (char*)NULL); 1062 return TCL_ERROR; 1063 } 1064 return TCL_OK; 1065 } 1066 1067 static int 1068 HeightMapCmd(ClientData cdata, Tcl_Interp *interp, int argc, 1069 const char *argv[]) 1070 { 1071 fprintf(stderr, "in heightmap command\n"); 1072 fflush(stderr); 1073 if (argc < 2) { 1074 srand((unsigned)time(NULL)); 1075 int size = 20 * 20; 1076 double sigma = 5.0; 1077 double mean = exp(0.0) / (sigma * sqrt(2.0)); 1078 float* data = (float*) malloc(sizeof(float) * size); 1079 1080 float x; 1081 for (int i = 0; i < size; ++i) { 1082 x = - 10 + i%20; 1083 data[i] = exp(- (x * x)/(2 * sigma * sigma)) / 1084 (sigma * sqrt(2.0)) / mean; 1085 } 1086 HeightMap* heightMap = new HeightMap(); 1087 heightMap->setHeight(0.0f, 0.0f, 1.0f, 1.0f, 20, 20, data); 1088 heightMap->setColorMap(nv_get_transfunc("default")); 1089 heightMap->setVisible(true); 1090 heightMap->setLineContourVisible(true); 1091 g_heightMap.push_back(heightMap); 1092 return TCL_OK; 1093 } 1094 1095 char c = argv[1][0]; 1096 if ((c == 'c') && (strcmp(argv[1], "create") == 0)) { 1097 HeightMap *hMap; 1098 1099 /* heightmap create xmin ymin xmax ymax xnum ynum values */ 1100 hMap = CreateHeightMap(cdata, interp, argc - 2, argv + 2); 1101 if (hMap == NULL) { 1102 return TCL_ERROR; 1103 } 1104 g_heightMap.push_back(hMap); 1105 /* FIXME: Convert this file to use Tcl_CmdObjProc */ 1106 sprintf(interp->result, "%d", g_heightMap.size() - 1); 1107 return TCL_OK; 1108 } else if ((c == 'd') && (strcmp(argv[1],"data") == 0)) { 1109 fprintf(stderr, "heightmap data\n"); 1110 fflush(stderr); 1111 //bytes 1112 char c; 1113 c = argv[2][0]; 1114 if ((c == 'v') && (strcmp(argv[2],"visible") == 0)) { 1115 int ivisible; 1116 vector<int> indices; 1117 1118 if (Tcl_GetBoolean(interp, argv[3], &ivisible) != TCL_OK) { 1119 return TCL_ERROR; 1120 } 1121 if (GetIndices(interp, argc-4, argv+4, &indices) != TCL_OK) { 1122 return TCL_ERROR; 1123 } 1124 bool visible; 1125 visible = (bool)ivisible; 1126 for (int i = 0; i < indices.size(); ++i) { 1127 if ((indices[i] < g_heightMap.size()) && 1128 (g_heightMap[indices[i]] != NULL)) { 1129 g_heightMap[indices[i]]->setVisible(visible); 1130 } 1131 } 1132 } else if ((c == 'f') && (strcmp(argv[2],"follows") == 0)) { 1133 Rappture::Buffer buf; 1134 int nBytes; 1135 1136 fprintf(stderr, "in data follows\n"); 1137 fflush(stderr); 1138 if (Tcl_GetInt(interp, argv[3], &nBytes) != TCL_OK) { 1139 return TCL_ERROR; 1140 } 1141 fprintf(stderr, "expecting %d bytes\n", nBytes); 1142 fflush(stderr); 1143 if (FillBufferFromStdin(interp, buf, nBytes) != TCL_OK) { 1144 return TCL_ERROR; 1145 } 1146 if (Tcl_Eval(interp, buf.bytes()) != TCL_OK) { 1147 fprintf(stderr, "error in command: %s\n", 1148 Tcl_GetStringResult(interp)); 1149 fflush(stderr); 1150 return TCL_ERROR; 1151 } 1152 } else { 1153 Tcl_AppendResult(interp, "unknown option \"", argv[2], "\": ", 1154 "should be visible or follows", (char *)NULL); 1155 return TCL_ERROR; 1156 } 1157 } else if ((c == 'l') && (strcmp(argv[1], "linecontour") == 0)) { 1095 1158 //bytes 1096 1159 vector<int> indices; 1097 if (strcmp(argv[2],"visible") == 0) 1098 { 1099 bool visible = !strcmp(argv[3], "true"); 1100 1101 if (GetIndices(interp, argc-4, argv+4, &indices) != TCL_OK) 1102 { 1103 return TCL_ERROR; 1104 } 1105 1106 for (int i = 0; i < indices.size(); ++i) 1107 { 1108 if ((indices[i] < g_heightMap.size()) && (g_heightMap[indices[i]] != NULL)) 1109 { 1110 g_heightMap[indices[i]]->setVisible(visible); 1111 } 1112 } 1113 return TCL_OK; 1114 } 1115 else if (c == 'f' && strcmp(argv[2],"follows") == 0) { 1116 int nbytes; 1117 if (Tcl_GetInt(interp, argv[3], &nbytes) != TCL_OK) { 1118 return TCL_ERROR; 1119 } 1120 } 1121 } 1122 else if (c == 'l' && (strcmp(argv[1], "linecontour") == 0)) 1123 { 1124 //bytes 1125 vector<int> indices; 1126 if (strcmp(argv[2],"visible") == 0) 1127 { 1128 1129 bool visible = !(strcmp("true", argv[3])); 1130 printf("heightmap linecontour visible %s\n", (visible)?"true":"false"); 1131 if (GetIndices(interp, argc-4, argv+4, &indices) != TCL_OK) 1132 { 1133 return TCL_ERROR; 1134 } 1135 1136 for (int i = 0; i < indices.size(); ++i) 1137 { 1138 printf("heightmap index %d\n"); 1139 if ((indices[i] < g_heightMap.size()) && (g_heightMap[indices[i]] != NULL)) 1140 { 1141 printf("heightmap index %d visible applied\n"); 1160 char c; 1161 c = argv[2][0]; 1162 if ((c == 'v') && (strcmp(argv[2],"visible") == 0)) { 1163 int ivisible; 1164 bool visible; 1165 1166 if (Tcl_GetBoolean(interp, argv[3], &ivisible) != TCL_OK) { 1167 return TCL_ERROR; 1168 } 1169 visible = (bool)ivisible; 1170 if (GetIndices(interp, argc-4, argv+4, &indices) != TCL_OK) { 1171 return TCL_ERROR; 1172 } 1173 for (int i = 0; i < indices.size(); ++i) { 1174 if ((indices[i] < g_heightMap.size()) && 1175 (g_heightMap[indices[i]] != NULL)) { 1142 1176 g_heightMap[indices[i]]->setLineContourVisible(visible); 1143 1177 } 1144 1178 } 1145 return TCL_OK; 1146 } 1147 else if (strcmp(argv[2],"color") == 0) 1148 { 1149 double r, g, b; 1150 if ((Tcl_GetDouble(interp, argv[3], &r) == TCL_OK) && 1151 (Tcl_GetDouble(interp, argv[4], &g) == TCL_OK) && 1152 (Tcl_GetDouble(interp, argv[5], &b) == TCL_OK)) { 1153 r = r / 255.0; 1154 g = g / 255.0; 1155 b = b / 255.0; 1156 } 1157 else 1158 { 1159 return TCL_ERROR; 1160 } 1161 1179 } else if ((c == 'c') && (strcmp(argv[2],"color") == 0)) { 1180 float r, g, b; 1181 if ((GetFloat(interp, argv[3], &r) != TCL_OK) || 1182 (GetFloat(interp, argv[4], &g) != TCL_OK) || 1183 (GetFloat(interp, argv[5], &b) != TCL_OK)) { 1184 return TCL_ERROR; 1185 } 1162 1186 vector<int> indices; 1163 if (GetIndices(interp, argc-6, argv+6, &indices) != TCL_OK) 1164 { 1165 return TCL_ERROR; 1166 } 1167 for (int i = 0; i < indices.size(); ++i) 1168 { 1169 if ((indices[i] < g_heightMap.size()) && (g_heightMap[indices[i]] != NULL)) 1170 { 1187 if (GetIndices(interp, argc-6, argv+6, &indices) != TCL_OK) { 1188 return TCL_ERROR; 1189 } 1190 for (int i = 0; i < indices.size(); ++i) { 1191 if ((indices[i] < g_heightMap.size()) && 1192 (g_heightMap[indices[i]] != NULL)) { 1171 1193 g_heightMap[indices[i]]->setLineContourColor(r, g, b); 1172 1194 } 1173 1195 } 1174 1175 return TCL_OK; 1176 } 1177 } 1178 else if (c == 't' && (strcmp(argv[1], "transfunc") == 0)) 1179 { 1180 TransferFunction *tf = get_transfunc((char*)argv[2]); 1196 } else { 1197 Tcl_AppendResult(interp, "unknown option \"", argv[2], "\": ", 1198 "should be visible or color", (char *)NULL); 1199 return TCL_ERROR; 1200 } 1201 } else if ((c == 't') && (strcmp(argv[1], "transfunc") == 0)) { 1202 TransferFunction *tf; 1203 1204 tf = nv_get_transfunc(argv[2]); 1181 1205 if (tf == NULL) { 1182 Tcl_AppendResult(interp, "transfer function \"", argv[ 3],1206 Tcl_AppendResult(interp, "transfer function \"", argv[2], 1183 1207 "\" is not defined", (char*)NULL); 1184 1208 return TCL_ERROR; 1185 1209 } 1186 1187 1210 vector<int> indices; 1188 if (GetVolumeIndices(interp, argc - 3, argv + 3, &indices) != TCL_OK) 1189 { 1190 for (int i = 0; i < indices.size(); ++i) 1191 { 1192 if ((indices[i] < g_heightMap.size()) && (g_heightMap[indices[i]] != NULL)) 1193 { 1194 g_heightMap[indices[i]]->setColorMap(tf); 1195 } 1196 } 1197 } 1198 return TCL_OK; 1199 } 1200 1201 Tcl_AppendResult(interp, "bad option \"", argv[1], 1202 "\": should be data, outline, shading, or state", (char*)NULL); 1203 return TCL_ERROR; 1204 } 1205 1206 int GridCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])) 1207 { 1208 char c = *argv[1]; 1209 if (c == 'v' && strcmp(argv[1],"visible") == 0) 1210 { 1211 if (strcmp(argv[2],"true") == 0) 1212 { 1213 g_grid->setVisible(true); 1214 return TCL_OK; 1215 } 1216 else if (strcmp(argv[2],"false") == 0) 1217 { 1218 g_grid->setVisible(false); 1219 return TCL_OK; 1220 } 1221 } 1222 else if (c == 'l' && strcmp(argv[1],"linecount") == 0) 1223 { 1211 if (GetIndices(interp, argc - 3, argv + 3, &indices) != TCL_OK) { 1212 return TCL_ERROR; 1213 } 1214 for (int i = 0; i < indices.size(); ++i) { 1215 if ((indices[i] < g_heightMap.size()) && 1216 (g_heightMap[indices[i]] != NULL)) { 1217 g_heightMap[indices[i]]->setColorMap(tf); 1218 } 1219 } 1220 } else if ((c == 'l') && (strcmp(argv[1], "legend") == 0)) { 1221 if (argc != 5) { 1222 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1223 " legend index width height\"", (char*)NULL); 1224 return TCL_ERROR; 1225 } 1226 HeightMap *hMap; 1227 if (GetHeightMap(interp, argv[2], &hMap) != TCL_OK) { 1228 return TCL_ERROR; 1229 } 1230 TransferFunction *tf; 1231 tf = hMap->getColorMap(); 1232 if (tf == NULL) { 1233 Tcl_AppendResult(interp, 1234 "no transfer function defined for heightmap \"", 1235 argv[1], "\"", (char*)NULL); 1236 return TCL_ERROR; 1237 } 1238 int width, height; 1239 if ((Tcl_GetInt(interp, argv[3], &width) != TCL_OK) || 1240 (Tcl_GetInt(interp, argv[4], &height) != TCL_OK)) { 1241 return TCL_ERROR; 1242 } 1243 nv_render_legend(tf, hMap->range_min(), hMap->range_max(), 1244 width, height, argv[1]); 1245 } else { 1246 Tcl_AppendResult(interp, "bad option \"", argv[1], 1247 "\": should be data, linecontour, legend, or transfunc", (char*)NULL); 1248 return TCL_ERROR; 1249 } 1250 return TCL_OK; 1251 } 1252 1253 static int 1254 GridCmd(ClientData cdata, Tcl_Interp *interp, int argc, const char *argv[]) 1255 { 1256 char c = argv[1][0]; 1257 if ((c == 'v') && (strcmp(argv[1],"visible") == 0)) { 1258 int ivisible; 1259 1260 if (Tcl_GetBoolean(interp, argv[2], &ivisible) != TCL_OK) { 1261 return TCL_ERROR; 1262 } 1263 g_grid->setVisible((bool)ivisible); 1264 } else if ((c == 'l') && (strcmp(argv[1],"linecount") == 0)) { 1224 1265 int x, y, z; 1225 1266 1226 if ((Tcl_GetInt(interp, argv[2], &x) == TCL_OK) && 1227 (Tcl_GetInt(interp, argv[3], &y) == TCL_OK) && 1228 (Tcl_GetInt(interp, argv[4], &z) == TCL_OK)) { 1229 1230 if (g_grid) g_grid->setGridLineCount(x, y, z); 1231 1232 return TCL_OK; 1233 } 1234 } 1235 else if (c == 'a' && strcmp(argv[1],"axiscolor") == 0) 1236 { 1237 int r, g, b; 1238 if ((Tcl_GetInt(interp, argv[2], &r) == TCL_OK) && 1239 (Tcl_GetInt(interp, argv[3], &g) == TCL_OK) && 1240 (Tcl_GetInt(interp, argv[4], &b) == TCL_OK)) { 1241 1242 if (g_grid) g_grid->setAxisColor(r / 255.0f, g / 255.0f, b / 255.0f); 1243 return TCL_OK; 1244 } 1245 } 1246 else if (c == 'l' && strcmp(argv[1],"linecolor") == 0) 1247 { 1248 int r, g, b; 1249 if ((Tcl_GetInt(interp, argv[2], &r) == TCL_OK) && 1250 (Tcl_GetInt(interp, argv[3], &g) == TCL_OK) && 1251 (Tcl_GetInt(interp, argv[4], &b) == TCL_OK)) { 1252 1253 if (g_grid) g_grid->setGridLineColor(r / 255.0f, g / 255.0f, b / 255.0f); 1254 return TCL_OK; 1255 } 1256 } 1257 else if (c == 'm') 1258 { 1259 if (strcmp(argv[1],"minmax") == 0) 1260 { 1261 double x1, y1, z1, x2, y2, z2; 1262 if ((Tcl_GetDouble(interp, argv[2], &x1) == TCL_OK) && 1263 (Tcl_GetDouble(interp, argv[3], &y1) == TCL_OK) && 1264 (Tcl_GetDouble(interp, argv[4], &z1) == TCL_OK) && 1265 (Tcl_GetDouble(interp, argv[5], &x2) == TCL_OK) && 1266 (Tcl_GetDouble(interp, argv[6], &y2) == TCL_OK) && 1267 (Tcl_GetDouble(interp, argv[7], &z2) == TCL_OK)) { 1268 1269 if (g_grid) g_grid->setMinMax(Vector3(x1, y1, z1), Vector3(x2, y2, z2)); 1270 1271 return TCL_OK; 1272 } 1273 } 1274 } 1275 else if (c == 'a' && strcmp(argv[1],"axisname") == 0) 1276 { 1277 int axisID = 0; 1278 if (!strcmp(argv[2], "x")) axisID = 0; 1279 if (!strcmp(argv[2], "y")) axisID = 1; 1280 if (!strcmp(argv[2], "z")) axisID = 2; 1281 1282 if (g_grid) g_grid->setAxisName(axisID, argv[3]); 1283 return TCL_OK; 1284 } 1285 1286 Tcl_AppendResult(interp, "bad option \"", argv[1], 1287 "\": should be data, outline, shading, or state", (char*)NULL); 1288 return TCL_ERROR; 1289 } 1290 1291 1292 int AxisCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])) 1267 if ((Tcl_GetInt(interp, argv[2], &x) != TCL_OK) || 1268 (Tcl_GetInt(interp, argv[3], &y) != TCL_OK) || 1269 (Tcl_GetInt(interp, argv[4], &z) != TCL_OK)) { 1270 return TCL_ERROR; 1271 } 1272 if (g_grid) { 1273 g_grid->setGridLineCount(x, y, z); 1274 } 1275 } else if ((c == 'a') && (strcmp(argv[1],"axiscolor") == 0)) { 1276 float r, g, b; 1277 if ((GetFloat(interp, argv[2], &r) != TCL_OK) || 1278 (GetFloat(interp, argv[3], &g) != TCL_OK) || 1279 (GetFloat(interp, argv[4], &b) != TCL_OK)) { 1280 return TCL_ERROR; 1281 } 1282 if (g_grid) { 1283 g_grid->setAxisColor(r, g, b); 1284 } 1285 } else if ((c == 'l') && (strcmp(argv[1],"linecolor") == 0)) { 1286 float r, g, b; 1287 if ((GetFloat(interp, argv[2], &r) != TCL_OK) || 1288 (GetFloat(interp, argv[3], &g) != TCL_OK) || 1289 (GetFloat(interp, argv[4], &b) != TCL_OK)) { 1290 return TCL_ERROR; 1291 } 1292 if (g_grid) { 1293 g_grid->setGridLineColor(r, g, b); 1294 } 1295 } else if ((c == 'm') && (strcmp(argv[1],"minmax") == 0)) { 1296 double x1, y1, z1, x2, y2, z2; 1297 if ((Tcl_GetDouble(interp, argv[2], &x1) != TCL_OK) || 1298 (Tcl_GetDouble(interp, argv[3], &y1) != TCL_OK) || 1299 (Tcl_GetDouble(interp, argv[4], &z1) != TCL_OK) || 1300 (Tcl_GetDouble(interp, argv[5], &x2) != TCL_OK) || 1301 (Tcl_GetDouble(interp, argv[6], &y2) != TCL_OK) || 1302 (Tcl_GetDouble(interp, argv[7], &z2) != TCL_OK)) { 1303 return TCL_ERROR; 1304 } 1305 if (g_grid) { 1306 g_grid->setMinMax(Vector3(x1, y1, z1), Vector3(x2, y2, z2)); 1307 } 1308 } else if ((c == 'a') && (strcmp(argv[1],"axisname") == 0)) { 1309 int axisId; 1310 if (GetAxis(interp, argv[2], &axisId) != TCL_OK) { 1311 return TCL_ERROR; 1312 } 1313 if (g_grid) { 1314 g_grid->setAxisName(axisId, argv[3]); 1315 } 1316 } else { 1317 Tcl_AppendResult(interp, "bad option \"", argv[1], 1318 "\": should be data, outline, shading, or state", 1319 (char*)NULL); 1320 return TCL_ERROR; 1321 } 1322 return TCL_OK; 1323 } 1324 1325 static int 1326 AxisCmd(ClientData cdata, Tcl_Interp *interp, int argc, const char *argv[]) 1293 1327 { 1294 1328 if (argc < 2) { … … 1297 1331 return TCL_ERROR; 1298 1332 } 1299 1300 char c = *argv[1]; 1301 if (c == 'v' && strcmp(argv[1],"visible") == 0) 1302 { 1303 if (strcmp(argv[2],"true") == 0) 1304 { 1305 axis_on = true; 1306 } 1307 else if (strcmp(argv[2],"false") == 0) 1308 { 1309 axis_on = false; 1310 } 1311 1312 return TCL_OK; 1313 } 1314 1315 Tcl_AppendResult(interp, "bad option \"", argv[1], 1316 "\": should be data, outline, shading, or state", (char*)NULL); 1317 return TCL_ERROR; 1318 } 1319 1333 char c = argv[1][0]; 1334 if ((c == 'v') && (strcmp(argv[1],"visible") == 0)) { 1335 int ivisible; 1336 1337 if (Tcl_GetBoolean(interp, argv[2], &ivisible) != TCL_OK) { 1338 return TCL_ERROR; 1339 } 1340 axis_on = (bool)ivisible; 1341 } else { 1342 Tcl_AppendResult(interp, "bad axis option \"", argv[1], 1343 "\": should be visible", (char*)NULL); 1344 return TCL_ERROR; 1345 } 1346 return TCL_OK; 1347 } 1320 1348 1321 1349 /* 1322 1350 * ---------------------------------------------------------------------- 1323 * FUNCTION: Get VolumeIndices()1351 * FUNCTION: GetHeightMap 1324 1352 * 1325 1353 * Used internally to decode a series of volume index values and … … 1333 1361 */ 1334 1362 static int 1335 GetVolumeIndices(Tcl_Interp *interp, int argc, CONST84 char *argv[], 1363 GetHeightMap(Tcl_Interp *interp, const char *string, HeightMap **hmPtrPtr) 1364 { 1365 int mapIndex; 1366 if (Tcl_GetInt(interp, string, &mapIndex) != TCL_OK) { 1367 return TCL_ERROR; 1368 } 1369 if ((mapIndex < 0) || (mapIndex >= g_heightMap.size()) || 1370 (g_heightMap[mapIndex] == NULL)) { 1371 Tcl_AppendResult(interp, "invalid heightmap index \"", string, "\"", 1372 (char *)NULL); 1373 return TCL_ERROR; 1374 } 1375 *hmPtrPtr = g_heightMap[mapIndex]; 1376 return TCL_OK; 1377 } 1378 1379 /* 1380 * ---------------------------------------------------------------------- 1381 * FUNCTION: GetVolumeIndex 1382 * 1383 * Used internally to decode a series of volume index values and 1384 * store then in the specified vector. If there are no volume index 1385 * arguments, this means "all volumes" to most commands, so all 1386 * active volume indices are stored in the vector. 1387 * 1388 * Updates pushes index values into the vector. Returns TCL_OK or 1389 * TCL_ERROR to indicate an error. 1390 * ---------------------------------------------------------------------- 1391 */ 1392 static int 1393 GetVolumeIndex(Tcl_Interp *interp, const char *string, int *indexPtr) 1394 { 1395 int ivol; 1396 if (Tcl_GetInt(interp, string, &ivol) != TCL_OK) { 1397 return TCL_ERROR; 1398 } 1399 if ((ivol < 0) || (ivol >= volume.size())) { 1400 Tcl_AppendResult(interp, "bad volume index \"", string, 1401 "\"", (char*)NULL); 1402 return TCL_ERROR; 1403 } 1404 *indexPtr = ivol; 1405 return TCL_OK; 1406 } 1407 1408 /* 1409 * ---------------------------------------------------------------------- 1410 * FUNCTION: GetVolume 1411 * 1412 * Used internally to decode a series of volume index values and 1413 * store then in the specified vector. If there are no volume index 1414 * arguments, this means "all volumes" to most commands, so all 1415 * active volume indices are stored in the vector. 1416 * 1417 * Updates pushes index values into the vector. Returns TCL_OK or 1418 * TCL_ERROR to indicate an error. 1419 * ---------------------------------------------------------------------- 1420 */ 1421 static int 1422 GetVolume(Tcl_Interp *interp, const char *string, Volume **volPtrPtr) 1423 { 1424 int ivol; 1425 if (GetVolumeIndex(interp, string, &ivol) != TCL_OK) { 1426 return TCL_ERROR; 1427 } 1428 if (volume[ivol] == NULL) { 1429 Tcl_AppendResult(interp, "no volume defined for index \"", string, 1430 "\"", (char*)NULL); 1431 return TCL_ERROR; 1432 } 1433 *volPtrPtr = volume[ivol]; 1434 return TCL_OK; 1435 } 1436 1437 /* 1438 * ---------------------------------------------------------------------- 1439 * FUNCTION: GetVolumeIndices() 1440 * 1441 * Used internally to decode a series of volume index values and 1442 * store then in the specified vector. If there are no volume index 1443 * arguments, this means "all volumes" to most commands, so all 1444 * active volume indices are stored in the vector. 1445 * 1446 * Updates pushes index values into the vector. Returns TCL_OK or 1447 * TCL_ERROR to indicate an error. 1448 * ---------------------------------------------------------------------- 1449 */ 1450 static int 1451 GetVolumeIndices(Tcl_Interp *interp, int argc, const char *argv[], 1336 1452 vector<int>* vectorPtr) 1337 1453 { … … 1345 1461 int ivol; 1346 1462 for (int n=0; n < argc; n++) { 1347 if (Tcl_GetInt(interp, argv[n], &ivol) != TCL_OK) { 1348 return TCL_ERROR; 1349 } 1350 if (ivol < 0 || ivol >= volume.size()) { 1351 Tcl_AppendResult(interp, "bad volume index \"", argv[n], 1352 "\"", (char*)NULL); 1353 return TCL_ERROR; 1354 } 1463 if (GetVolumeIndex(interp, argv[n], &ivol) != TCL_OK) { 1464 return TCL_ERROR; 1465 } 1355 1466 if (volume[ivol] != NULL) { 1356 1467 vectorPtr->push_back(ivol); … … 1361 1472 } 1362 1473 1363 1364 1474 static int 1365 GetIndices(Tcl_Interp *interp, int argc, CONST84char *argv[],1475 GetIndices(Tcl_Interp *interp, int argc, const char *argv[], 1366 1476 vector<int>* vectorPtr) 1367 1477 { … … 1388 1498 */ 1389 1499 static int 1390 GetAxis(Tcl_Interp *interp, char *str, int *valPtr) 1391 { 1392 if (strcmp(str,"x") == 0) { 1393 *valPtr = 0; 1394 return TCL_OK; 1395 } 1396 else if (strcmp(str,"y") == 0) { 1397 *valPtr = 1; 1398 return TCL_OK; 1399 } 1400 else if (strcmp(str,"z") == 0) { 1401 *valPtr = 2; 1402 return TCL_OK; 1403 } 1404 Tcl_AppendResult(interp, "bad axis \"", str, 1405 "\": should be x, y, or z", (char*)NULL); 1500 GetAxis(Tcl_Interp *interp, const char *string, int *valPtr) 1501 { 1502 if (string[1] == '\0') { 1503 if (string[0] == 'x') { 1504 *valPtr = 0; 1505 return TCL_OK; 1506 } else if (string[0] == 'y') { 1507 *valPtr = 1; 1508 return TCL_OK; 1509 } else if (string[0] == 'z') { 1510 *valPtr = 2; 1511 return TCL_OK; 1512 } 1513 /*FALLTHRU*/ 1514 } 1515 Tcl_AppendResult(interp, "bad axis \"", string, 1516 "\": should be x, y, or z", (char*)NULL); 1406 1517 return TCL_ERROR; 1407 1518 } … … 1418 1529 */ 1419 1530 static int 1420 GetColor(Tcl_Interp *interp, char *str, float *rgbPtr) 1421 { 1422 int rgbc; 1423 char **rgbv; 1424 if (Tcl_SplitList(interp, str, &rgbc, (const char***)&rgbv) != TCL_OK) { 1531 GetColor(Tcl_Interp *interp, const char *string, float *rgbPtr) 1532 { 1533 int argc; 1534 const char **argv; 1535 1536 if (Tcl_SplitList(interp, string, &argc, &argv) != TCL_OK) { 1425 1537 return TCL_ERROR; 1426 1538 } 1427 if ( rgbc != 3) {1428 Tcl_AppendResult(interp, "bad color \"", str ,1429 "\": should be {R G B} as double values 0-1", (char*)NULL);1539 if (argc != 3) { 1540 Tcl_AppendResult(interp, "bad color \"", string, 1541 "\": should list of R G B values 0.0 - 1.0", (char*)NULL); 1430 1542 return TCL_ERROR; 1431 1543 } 1432 1433 double rval, gval, bval; 1434 if (Tcl_GetDouble(interp, rgbv[0], &rval) != TCL_OK) {1435 Tcl_Free((char*) rgbv);1544 if ((GetFloat(interp, argv[0], rgbPtr + 0) != TCL_OK) || 1545 (GetFloat(interp, argv[1], rgbPtr + 1) != TCL_OK) || 1546 (GetFloat(interp, argv[2], rgbPtr + 2) != TCL_OK)) { 1547 Tcl_Free((char*)argv); 1436 1548 return TCL_ERROR; 1437 1549 } 1438 if (Tcl_GetDouble(interp, rgbv[1], &gval) != TCL_OK) { 1439 Tcl_Free((char*)rgbv); 1440 return TCL_ERROR; 1441 } 1442 if (Tcl_GetDouble(interp, rgbv[2], &bval) != TCL_OK) { 1443 Tcl_Free((char*)rgbv); 1444 return TCL_ERROR; 1445 } 1446 Tcl_Free((char*)rgbv); 1447 1448 rgbPtr[0] = (float)rval; 1449 rgbPtr[1] = (float)gval; 1450 rgbPtr[2] = (float)bval; 1451 1550 Tcl_Free((char*)argv); 1452 1551 return TCL_OK; 1453 1552 } … … 1455 1554 1456 1555 static int 1457 PlaneNewCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])) 1458 { 1459 fprintf(stderr, "load plane for 2D visualization command\n"); 1460 1461 int index, w, h; 1462 1463 if (argc != 4) { 1464 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1465 " plane_index w h \"", (char*)NULL); 1466 return TCL_ERROR; 1467 } 1468 if (Tcl_GetInt(interp, argv[1], &index) != TCL_OK) { 1469 return TCL_ERROR; 1470 } 1471 if (Tcl_GetInt(interp, argv[2], &w) != TCL_OK) { 1472 return TCL_ERROR; 1473 } 1474 if (Tcl_GetInt(interp, argv[3], &h) != TCL_OK) { 1475 return TCL_ERROR; 1476 } 1477 1478 //Now read w*h*4 bytes. The server expects the plane to be a stream of floats 1479 char* tmp = new char[int(w*h*sizeof(float))]; 1480 bzero(tmp, w*h*4); 1481 int status = read(0, tmp, w*h*sizeof(float)); 1482 if (status <= 0){ 1483 exit(0); 1484 } 1485 1486 plane[index] = new Texture2D(w, h, GL_FLOAT, GL_LINEAR, 1, (float*)tmp); 1487 1488 delete[] tmp; 1489 return TCL_OK; 1490 } 1491 1492 1493 static 1494 int PlaneLinkCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])) 1495 { 1496 fprintf(stderr, "link the plane to the 2D renderer command\n"); 1497 1498 int plane_index, tf_index; 1499 1500 if (argc != 3) { 1501 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1502 " plane_index tf_index \"", (char*)NULL); 1503 return TCL_ERROR; 1504 } 1505 if (Tcl_GetInt(interp, argv[1], &plane_index) != TCL_OK) { 1506 return TCL_ERROR; 1507 } 1508 if (Tcl_GetInt(interp, argv[2], &tf_index) != TCL_OK) { 1509 return TCL_ERROR; 1510 } 1511 1512 //plane_render->add_plane(plane[plane_index], tf[tf_index]); 1513 1514 return TCL_OK; 1556 PlaneNewCmd(ClientData cdata, Tcl_Interp *interp, int argc, 1557 const char *argv[]) 1558 { 1559 fprintf(stderr, "load plane for 2D visualization command\n"); 1560 1561 int index, w, h; 1562 1563 if (argc != 4) { 1564 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1565 " plane_index w h \"", (char*)NULL); 1566 return TCL_ERROR; 1567 } 1568 if (Tcl_GetInt(interp, argv[1], &index) != TCL_OK) { 1569 return TCL_ERROR; 1570 } 1571 if (Tcl_GetInt(interp, argv[2], &w) != TCL_OK) { 1572 return TCL_ERROR; 1573 } 1574 if (Tcl_GetInt(interp, argv[3], &h) != TCL_OK) { 1575 return TCL_ERROR; 1576 } 1577 1578 //Now read w*h*4 bytes. The server expects the plane to be a stream of floats 1579 char* tmp = new char[int(w*h*sizeof(float))]; 1580 if (tmp == NULL) { 1581 Tcl_AppendResult(interp, "can't allocate stream data", (char *)NULL); 1582 return TCL_ERROR; 1583 } 1584 bzero(tmp, w*h*4); 1585 int status = read(0, tmp, w*h*sizeof(float)); 1586 if (status <= 0) { 1587 exit(0); // Bail out on read error? Should log the 1588 // error and return a non-zero exit status. 1589 } 1590 plane[index] = new Texture2D(w, h, GL_FLOAT, GL_LINEAR, 1, (float*)tmp); 1591 delete[] tmp; 1592 return TCL_OK; 1593 } 1594 1595 1596 static int PlaneLinkCmd(ClientData cdata, Tcl_Interp *interp, int argc, 1597 const char *argv[]) 1598 { 1599 fprintf(stderr, "link the plane to the 2D renderer command\n"); 1600 1601 int plane_index, tf_index; 1602 1603 if (argc != 3) { 1604 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1605 " plane_index tf_index \"", (char*)NULL); 1606 return TCL_ERROR; 1607 } 1608 if (Tcl_GetInt(interp, argv[1], &plane_index) != TCL_OK) { 1609 return TCL_ERROR; 1610 } 1611 if (Tcl_GetInt(interp, argv[2], &tf_index) != TCL_OK) { 1612 return TCL_ERROR; 1613 } 1614 //plane_render->add_plane(plane[plane_index], tf[tf_index]); 1615 return TCL_OK; 1515 1616 } 1516 1617 1517 1618 //Enable a 2D plane for render 1518 1619 //The plane_index is the index mantained in the 2D plane renderer 1519 static 1520 int PlaneEnableCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])) 1521 { 1522 fprintf(stderr, "enable a plane so the 2D renderer can render it command\n"); 1523 1524 int plane_index, mode; 1525 1526 if (argc != 3) { 1527 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1528 " plane_index mode \"", (char*)NULL); 1529 return TCL_ERROR; 1530 } 1531 if (Tcl_GetInt(interp, argv[1], &plane_index) != TCL_OK) { 1532 return TCL_ERROR; 1533 } 1534 if (Tcl_GetInt(interp, argv[2], &mode) != TCL_OK) { 1535 return TCL_ERROR; 1536 } 1537 1538 if(mode==0) 1539 plane_render->set_active_plane(-1); 1540 else 1620 static int PlaneEnableCmd(ClientData cdata, Tcl_Interp *interp, int argc, 1621 const char *argv[]) 1622 { 1623 fprintf(stderr,"enable a plane so the 2D renderer can render it command\n"); 1624 1625 if (argc != 3) { 1626 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1627 " plane_index mode \"", (char*)NULL); 1628 return TCL_ERROR; 1629 } 1630 int plane_index; 1631 if (Tcl_GetInt(interp, argv[1], &plane_index) != TCL_OK) { 1632 return TCL_ERROR; 1633 } 1634 int mode; 1635 if (Tcl_GetInt(interp, argv[2], &mode) != TCL_OK) { 1636 return TCL_ERROR; 1637 } 1638 if (mode == 0) { 1639 plane_index = -1; 1640 } 1541 1641 plane_render->set_active_plane(plane_index); 1542 1543 return TCL_OK; 1544 } 1545 1546 1547 voidinitTcl()1642 return TCL_OK; 1643 } 1644 1645 1646 void 1647 initTcl() 1548 1648 { 1549 1649 interp = Tcl_CreateInterp(); … … 1591 1691 // get screenshot 1592 1692 Tcl_CreateCommand(interp, "screenshot", ScreenShotCmd, 1693 (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); 1694 1695 Tcl_CreateCommand(interp, "unirect2d", UniRect2dCmd, 1593 1696 (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); 1594 1697 … … 1605 1708 } 1606 1709 1607 void xinetd_listen() 1608 { 1609 1710 1711 void 1712 xinetd_listen() 1713 { 1610 1714 int flags = fcntl(0, F_GETFL, 0); 1611 1715 fcntl(0, F_SETFL, flags & ~O_NONBLOCK); … … 1650 1754 // back to original flags during command evaluation... 1651 1755 fcntl(0, F_SETFL, flags & ~O_NONBLOCK); 1652 1653 1756 status = Tcl_Eval(interp, Tcl_DStringValue(&cmdbuffer)); 1654 1757 Tcl_DStringSetLength(&cmdbuffer, 0); … … 1671 1774 // 1672 1775 // INSOO 1673 offscreen_buffer_capture(); //enable offscreen render1674 1675 display();1776 nv_offscreen_buffer_capture(); //enable offscreen render 1777 1778 nv_display(); 1676 1779 1677 1780 // INSOO 1678 1781 #ifdef XINETD 1679 read_screen();1782 nv_read_screen(); 1680 1783 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 1681 1784 #else 1682 display_offscreen_buffer(); //display the final rendering on screen1683 read_screen();1785 nv_display_offscreen_buffer(); //display the final rendering on screen 1786 nv_read_screen(); 1684 1787 glutSwapBuffers(); 1685 1788 #endif … … 1698 1801 1699 1802 1803 /* 1804 * ----------------------------------------------------------------------- 1805 * 1806 * FillBufferFromStdin -- 1807 * 1808 * Read the requested number of bytes from standard input into the given 1809 * buffer. The buffer is then decompressed and decoded. 1810 * 1811 * ----------------------------------------------------------------------- 1812 */ 1813 static int 1814 FillBufferFromStdin(Tcl_Interp *interp, Rappture::Buffer &buf, int nBytes) 1815 { 1816 char buffer[8096]; 1817 1818 while (nBytes > 0) { 1819 int chunk, nRead; 1820 1821 chunk = (sizeof(buffer) < nBytes) ? sizeof(buffer) : nBytes; 1822 nRead = fread(buffer, 1, chunk, stdin); 1823 if (ferror(stdin) && feof(stdin)) { 1824 Tcl_AppendResult(interp, 1825 "data unpacking failed: unexpected EOF", 1826 (char*)NULL); 1827 return TCL_ERROR; 1828 } 1829 buf.append(buffer, nRead); 1830 nBytes -= nRead; 1831 } 1832 if (strncmp("@@RP-ENC", buf.bytes(), 8) == 0) { 1833 Rappture::Outcome err; 1834 1835 err = Rappture::encoding::decode(buf, RPENC_Z|RPENC_B64|RPENC_HDR); 1836 buf.append("\0", 1); 1837 fflush(stderr); 1838 if (err) { 1839 printf("ERROR -- DECODING\n"); 1840 fflush(stdout); 1841 Tcl_AppendResult(interp, err.remark().c_str(), (char*)NULL); 1842 return TCL_ERROR; 1843 } 1844 } 1845 return TCL_OK; 1846 } 1847 1848 /* 1849 * ----------------------------------------------------------------------- 1850 * 1851 * CreateHeightMap -- 1852 * 1853 * Creates a heightmap from the given the data. The format of the data 1854 * should be as follows: 1855 * 1856 * xMin, xMax, xNum, yMin, yMax, yNum, heights... 1857 * 1858 * xNum and yNum must be integer values, all others are real numbers. 1859 * The number of heights must be xNum * yNum; 1860 * 1861 * ----------------------------------------------------------------------- 1862 */ 1863 static HeightMap * 1864 CreateHeightMap(ClientData clientData, Tcl_Interp *interp, int argc, 1865 const char *argv[]) 1866 { 1867 float xMin, yMin, xMax, yMax; 1868 int xNum, yNum; 1869 1870 if (argc != 7) { 1871 Tcl_AppendResult(interp, 1872 "wrong # of values: should be xMin yMin xMax yMax xNum yNum heights", 1873 (char *)NULL); 1874 return NULL; 1875 } 1876 if ((GetFloat(interp, argv[0], &xMin) != TCL_OK) || 1877 (GetFloat(interp, argv[1], &yMin) != TCL_OK) || 1878 (GetFloat(interp, argv[2], &xMax) != TCL_OK) || 1879 (GetFloat(interp, argv[3], &yMax) != TCL_OK) || 1880 (Tcl_GetInt(interp, argv[4], &xNum) != TCL_OK) || 1881 (Tcl_GetInt(interp, argv[5], &yNum) != TCL_OK)) { 1882 return NULL; 1883 } 1884 int nValues; 1885 const char **elem; 1886 if (Tcl_SplitList(interp, argv[6], &nValues, &elem) != TCL_OK) { 1887 return NULL; 1888 } 1889 if ((xNum <= 0) || (yNum <= 0)) { 1890 Tcl_AppendResult(interp, "bad number of x or y values", (char *)NULL); 1891 goto error; 1892 } 1893 if (nValues != (xNum * yNum)) { 1894 Tcl_AppendResult(interp, "wrong # of heights", (char *)NULL); 1895 goto error; 1896 } 1897 1898 float *heights; 1899 heights = new float[nValues]; 1900 if (heights == NULL) { 1901 Tcl_AppendResult(interp, "can't allocate array of heights", 1902 (char *)NULL); 1903 goto error; 1904 } 1905 1906 int i; 1907 for (i = 0; i < nValues; i++) { 1908 if (GetFloat(interp, elem[i], heights + i) != TCL_OK) { 1909 delete [] heights; 1910 goto error; 1911 } 1912 } 1913 HeightMap* hMap; 1914 hMap = new HeightMap(); 1915 hMap->setHeight(xMin, yMin, xMax, yMax, xNum, yNum, heights); 1916 hMap->setColorMap(nv_get_transfunc("default")); 1917 hMap->setVisible(true); 1918 hMap->setLineContourVisible(true); 1919 1920 Tcl_Free((char *)elem); 1921 delete [] heights; 1922 return hMap; 1923 error: 1924 Tcl_Free((char *)elem); 1925 return NULL; 1926 } 1927 1928 /* 1929 * This command should be Tcl procedure instead of a C command. The reason 1930 * for this that 1) we are using a safe interpreter so we would need a master 1931 * interpreter to load the Tcl environment properly (including our "unirect2d" 1932 * procedure). And 2) the way nanovis is currently deployed, doesn't make it 1933 * easy to add new directories for procedures, since it's loaded into /tmp. 1934 * 1935 * Ideally, the "unirect2d" proc would do a rundimentary parsing of the data 1936 * to verify the structure and then pass it to the appropiate Tcl command 1937 * (heightmap, volume, etc). Our C command always creates a heightmap. 1938 */ 1939 static int 1940 UniRect2dCmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[]) 1941 { 1942 int xNum, yNum, zNum; 1943 float xMin, yMin, xMax, yMax; 1944 float *zValues; 1945 1946 fprintf(stderr, "in unirect2d command\n"); 1947 fflush(stderr); 1948 if ((argc & 0x01) == 0) { 1949 Tcl_AppendResult(interp, 1950 "wrong number of arguments: should be key-value pairs", 1951 (char *)NULL); 1952 return TCL_ERROR; 1953 } 1954 xNum = yNum = zNum = 0; 1955 xMin = yMin = xMax = yMax = 0.0f; 1956 int i; 1957 for (i = 1; i < argc; i += 2) { 1958 if (strcmp(argv[i], "xmin") == 0) { 1959 if (GetFloat(interp, argv[i+1], &xMin) != TCL_OK) { 1960 return TCL_ERROR; 1961 } 1962 } else if (strcmp(argv[i], "xmax") == 0) { 1963 if (GetFloat(interp, argv[i+1], &xMax) != TCL_OK) { 1964 return TCL_ERROR; 1965 } 1966 } else if (strcmp(argv[i], "xnum") == 0) { 1967 if (Tcl_GetInt(interp, argv[i+1], &xNum) != TCL_OK) { 1968 return TCL_ERROR; 1969 } 1970 if (xNum <= 0) { 1971 Tcl_AppendResult(interp, "bad xnum value: must be > 0", 1972 (char *)NULL); 1973 return TCL_ERROR; 1974 } 1975 } else if (strcmp(argv[i], "ymin") == 0) { 1976 if (GetFloat(interp, argv[i+1], &yMin) != TCL_OK) { 1977 return TCL_ERROR; 1978 } 1979 } else if (strcmp(argv[i], "ymax") == 0) { 1980 if (GetFloat(interp, argv[i+1], &yMax) != TCL_OK) { 1981 return TCL_ERROR; 1982 } 1983 } else if (strcmp(argv[i], "ynum") == 0) { 1984 if (Tcl_GetInt(interp, argv[i+1], &yNum) != TCL_OK) { 1985 return TCL_ERROR; 1986 } 1987 if (yNum <= 0) { 1988 Tcl_AppendResult(interp, "bad ynum value: must be > 0", 1989 (char *)NULL); 1990 return TCL_ERROR; 1991 } 1992 } else if (strcmp(argv[i], "zvalues") == 0) { 1993 const char **zlist; 1994 1995 if (Tcl_SplitList(interp, argv[i+1], &zNum, &zlist) != TCL_OK) { 1996 return TCL_ERROR; 1997 } 1998 int j; 1999 zValues = new float[zNum]; 2000 for (j = 0; j < zNum; j++) { 2001 if (GetFloat(interp, zlist[j], zValues + j) != TCL_OK) { 2002 Tcl_Free((char *)zlist); 2003 return TCL_ERROR; 2004 } 2005 } 2006 Tcl_Free((char *)zlist); 2007 } else { 2008 Tcl_AppendResult(interp, "unknown key \"", argv[i], 2009 "\": should be xmin, xmax, xnum, ymin, ymax, ynum, or zvalues", 2010 (char *)NULL); 2011 return TCL_ERROR; 2012 } 2013 } 2014 if (zValues == NULL) { 2015 Tcl_AppendResult(interp, "missing \"zvalues\" key", (char *)NULL); 2016 return TCL_ERROR; 2017 } 2018 fprintf(stderr, "xnum=%d, ynum=%d, znum=%d\n", xNum, yNum, zNum); 2019 fflush(stderr); 2020 if (zNum != (xNum * yNum)) { 2021 Tcl_AppendResult(interp, "wrong number of z values must be xnum*ynum", 2022 (char *)NULL); 2023 return TCL_ERROR; 2024 } 2025 2026 HeightMap* hMap; 2027 hMap = new HeightMap(); 2028 hMap->setHeight(xMin, yMin, xMax, yMax, xNum, yNum, zValues); 2029 hMap->setColorMap(nv_get_transfunc("default")); 2030 hMap->setVisible(true); 2031 hMap->setLineContourVisible(true); 2032 g_heightMap.push_back(hMap); 2033 delete [] zValues; 2034 return TCL_OK; 2035 } 2036 -
trunk/vizservers/nanovis/HeightMap.cpp
r820 r834 66 66 cgGLEnableProfile(CG_PROFILE_FP30); 67 67 68 fprintf(stderr, "set texture param id=%d\n", _colorMap->id); 69 fflush(stderr); 68 70 cgGLSetTextureParameter(_tf, _colorMap->id); 69 71 cgGLEnableTextureParameter(_tf); … … 81 83 ::glTexCoordPointer(3, GL_FLOAT, 12, 0); 82 84 83 glDrawElements(GL_TRIANGLES, _indexCount, GL_UNSIGNED_INT, _indexBuffer); 85 glDrawElements(GL_TRIANGLES, _indexCount, GL_UNSIGNED_INT, 86 _indexBuffer); 84 87 glBindBuffer(GL_ARRAY_BUFFER, 0); 85 88 … … 199 202 reset(); 200 203 201 float min = heights[0].y,max = heights[0].y;204 _vmin = heights[0].y, _vmax = heights[0].y; 202 205 int count = xCount * yCount; 203 206 for (int i = 0; i < count; ++i) 204 207 { 205 if (min > heights[i].y) min = heights[i].y; 206 if (max < heights[i].y) max = heights[i].y; 207 } 208 208 if (_vmin > heights[i].y) { 209 _vmin = heights[i].y; 210 } else if (_vmax < heights[i].y) { 211 _vmax = heights[i].y; 212 } 213 } 209 214 210 215 Vector3* texcoord = (Vector3*) malloc(count * sizeof(Vector3)); … … 256 261 reset(); 257 262 258 float min = heights[0],max = heights[0];263 _vmin = heights[0], _vmax = heights[0]; 259 264 int count = xCount * yCount; 260 for (int i = 0; i < count; ++i) 261 { 262 if (min > heights[i]) min = heights[i]; 263 if (max < heights[i]) max = heights[i]; 264 } 265 265 for (int i = 0; i < count; ++i) { 266 if (_vmin > heights[i]) { 267 _vmin = heights[i]; 268 } else if (_vmax < heights[i]) { 269 _vmax = heights[i]; 270 } 271 } 266 272 //_scale.x = endX - startX; 267 273 //_scale.y = (endY - startY) / _scale.x; … … 269 275 270 276 Vector3* texcoord = (Vector3*) malloc(count * sizeof(Vector3)); 271 for (int i = 0; i < count; ++i) 272 { 273 texcoord[i].set(0, 0, heights[i]); 277 for (int i = 0; i < count; ++i) { 278 texcoord[i].set(0, 0, heights[i]); 274 279 } 275 280 … … 344 349 _colorMap = colorMap; 345 350 } 351 -
trunk/vizservers/nanovis/HeightMap.h
r820 r834 30 30 31 31 Vector3 _scale; 32 33 double _vmin; // minimum (unscaled) value in data 34 double _vmax; // maximum (unscaled) value in data 35 32 36 33 37 public : … … 67 71 68 72 /** 69 *@brief Define a color map for color shading of heigh map73 *@brief Define a color map for color shading of heightmap 70 74 */ 71 75 void setColorMap(TransferFunction* colorMap); 76 77 /** 78 *@brief Get the color map defined for shading of this heightmap 79 */ 80 TransferFunction *getColorMap(void); 72 81 73 82 /** … … 90 99 */ 91 100 void setLineContourColor(float r, float g, float b); 101 102 double range_min(void); 103 double range_max(void); 92 104 }; 93 105 … … 113 125 _contourColor.z = b; 114 126 } 127 128 inline TransferFunction * 129 HeightMap::getColorMap() 130 { 131 return _colorMap; 132 } 133 134 inline double 135 HeightMap::range_min() 136 { 137 return _vmin; 138 } 139 140 inline double 141 HeightMap::range_max() 142 { 143 return _vmax; 144 } 115 145 #endif -
trunk/vizservers/nanovis/nanovis.cpp
r829 r834 1 1 2 /* 2 3 * ---------------------------------------------------------------------- … … 28 29 #include <signal.h> 29 30 30 31 31 #include "Nv.h" 32 32 #include "PointSetRenderer.h" … … 55 55 #include "Grid.h" 56 56 57 //#define _LOCAL_ZINC_TEST_ 57 58 58 59 // R2 headers … … 74 75 // color table for built-in transfer function editor 75 76 float color_table[256][4]; 76 77 // default transfer function78 char *def_transfunc = "transfunc define default {\n\79 0.0 1 1 1\n\80 0.2 1 1 0\n\81 0.4 0 1 0\n\82 0.6 0 1 1\n\83 0.8 0 0 1\n\84 1.0 1 0 1\n\85 } {\n\86 0.00 1.0\n\87 0.05 0.0\n\88 0.15 0.0\n\89 0.20 1.0\n\90 0.25 0.0\n\91 0.35 0.0\n\92 0.40 1.0\n\93 0.45 0.0\n\94 0.55 0.0\n\95 0.60 1.0\n\96 0.65 0.0\n\97 0.75 0.0\n\98 0.80 1.0\n\99 0.85 0.0\n\100 0.95 0.0\n\101 1.00 1.0\n\102 }";103 77 104 78 /* … … 130 104 void load_volume(int index, int width, int height, int depth, int n_component, float* data, double vmin, double vmax, 131 105 double nzero_min); 132 TransferFunction* get_transfunc(char *name);133 voidresize_offscreen_buffer(int w, int h);134 void offscreen_buffer_capture();135 void bmp_header_add_int(unsigned char* header, int& pos, int data);106 extern TransferFunction* nv_get_transfunc(const char *name); 107 extern void nv_resize_offscreen_buffer(int w, int h); 108 extern void nv_offscreen_buffer_capture(void); 109 static void bmp_header_add_int(unsigned char* header, int& pos, int data); 136 110 void bmp_write(const char* cmd); 137 111 void bmp_write_to_file(); 138 void display();139 voiddisplay_offscreen_buffer();140 voidread_screen();112 extern void nv_display(void); 113 extern void nv_display_offscreen_buffer(); 114 extern void nv_read_screen(); 141 115 142 116 //ParticleSystem* psys; … … 160 134 161 135 // maps transfunc name to TransferFunction object 162 Tcl_HashTable tftable;136 static Tcl_HashTable tftable; 163 137 164 138 // pointers to 2D planes, currently handle up 10 … … 200 174 int win_width = NPIX; //size of the render window 201 175 int win_height = NPIX; //size of the render window 202 203 176 204 177 //image based flow visualization variables … … 236 209 237 210 int renderMode = RM_VOLUME; 238 239 240 211 241 212 /* … … 295 266 } 296 267 268 /* 269 * FIXME: Move the DX-related routines into their own dx.cpp file. 270 */ 297 271 /* Load a 3D vector field from a dx-format file 298 272 */ … … 837 811 else if (sscanf(start, "object %d class array type float rank 1 shape 3 items %d data follows", &dummy, &nxy) == 2) { 838 812 isrect = 0; 813 839 814 double xx, yy, zz; 840 815 for (int i=0; i < nxy; i++) { … … 1203 1178 * width, height and depth: number of points in each dimension 1204 1179 */ 1205 void load_volume(int index, int width, int height, int depth, 1206 int n_component, float* data, double vmin, double vmax, double nzero_min) 1180 void 1181 load_volume(int index, int width, int height, int depth, int n_component, 1182 float* data, double vmin, double vmax, double nzero_min) 1207 1183 { 1208 1184 while (n_volumes <= index) { … … 1217 1193 1218 1194 volume[index] = new Volume(0.f, 0.f, 0.f, width, height, depth, 1., 1219 1195 n_component, data, vmin, vmax, nzero_min); 1220 1196 assert(volume[index]!=0); 1221 1197 } 1222 1198 1223 // get a colormap 1D texture by name1199 // Gets a colormap 1D texture by name. 1224 1200 TransferFunction* 1225 get_transfunc(char *name) { 1226 Tcl_HashEntry *entryPtr; 1227 entryPtr = Tcl_FindHashEntry(&tftable, name); 1228 if (entryPtr) { 1229 return (TransferFunction*)Tcl_GetHashValue(entryPtr); 1230 } 1231 return NULL; 1201 nv_get_transfunc(const char *name) 1202 { 1203 Tcl_HashEntry *hPtr; 1204 1205 hPtr = Tcl_FindHashEntry(&tftable, name); 1206 if (hPtr == NULL) { 1207 return NULL; 1208 } 1209 return (TransferFunction*)Tcl_GetHashValue(hPtr); 1210 } 1211 1212 // Creates of updates a colormap 1D texture by name. 1213 TransferFunction* 1214 nv_set_transfunc(const char *name, int nSlots, float *data) 1215 { 1216 int isNew; 1217 Tcl_HashEntry *hPtr; 1218 TransferFunction *tf; 1219 1220 hPtr = Tcl_CreateHashEntry(&tftable, name, &isNew); 1221 if (isNew) { 1222 tf = new TransferFunction(nSlots, data); 1223 Tcl_SetHashValue(hPtr, (ClientData)tf); 1224 } else { 1225 tf = (TransferFunction*)Tcl_GetHashValue(hPtr); 1226 tf->update(data); 1227 } 1228 return tf; 1232 1229 } 1233 1230 1234 1231 1235 1232 //Update the transfer function using local GUI in the non-server mode 1236 void update_tf_texture() 1237 { 1238 glutSetWindow(render_window); 1239 1240 //fprintf(stderr, "tf update\n"); 1241 TransferFunction *tf = get_transfunc("default"); 1242 if (tf == NULL) return; 1243 1244 float data[256*4]; 1245 for(int i=0; i<256; i++) 1246 { 1247 data[4*i+0] = color_table[i][0]; 1248 data[4*i+1] = color_table[i][1]; 1249 data[4*i+2] = color_table[i][2]; 1250 data[4*i+3] = color_table[i][3]; 1251 //fprintf(stderr, "(%f,%f,%f,%f) ", data[4*i+0], data[4*i+1], data[4*i+2], data[4*i+3]); 1252 } 1253 1254 tf->update(data); 1255 1233 void 1234 update_tf_texture() 1235 { 1236 glutSetWindow(render_window); 1237 1238 //fprintf(stderr, "tf update\n"); 1239 TransferFunction *tf = nv_get_transfunc("default"); 1240 if (tf == NULL) { 1241 return; 1242 } 1243 1244 float data[256*4]; 1245 for(int i=0; i<256; i++) { 1246 data[4*i+0] = color_table[i][0]; 1247 data[4*i+1] = color_table[i][1]; 1248 data[4*i+2] = color_table[i][2]; 1249 data[4*i+3] = color_table[i][3]; 1250 //fprintf(stderr, "(%f,%f,%f,%f) ", data[4*i+0], data[4*i+1], data[4*i+2], data[4*i+3]); 1251 } 1252 1253 tf->update(data); 1254 1256 1255 #ifdef EVENTLOG 1257 float param[3] = {0,0,0};1258 Event* tmp = new Event(EVENT_ROTATE, param, NvGetTimeInterval());1259 tmp->write(event_log);1260 delete tmp;1256 float param[3] = {0,0,0}; 1257 Event* tmp = new Event(EVENT_ROTATE, param, NvGetTimeInterval()); 1258 tmp->write(event_log); 1259 delete tmp; 1261 1260 #endif 1262 1261 } 1263 1262 1264 1265 int renderLegend(int ivol, int width, int height, const char* volArg) 1266 { 1267 TransferFunction *tf = NULL; 1268 1269 if (ivol < n_volumes) { 1270 tf = g_vol_render->get_volume_shading(volume[ivol]); 1271 } 1272 1273 if (tf == NULL) { 1274 return TCL_ERROR; 1275 } 1276 1263 int 1264 nv_render_legend( 1265 TransferFunction *tf, 1266 double min, double max, 1267 int width, int height, 1268 const char* volArg) 1269 { 1277 1270 int old_width = win_width; 1278 1271 int old_height = win_height; 1279 1272 1280 1273 plane_render->set_screen_size(width, height); 1281 resize_offscreen_buffer(width, height);1274 nv_resize_offscreen_buffer(width, height); 1282 1275 1283 1276 // generate data for the legend … … 1290 1283 plane_render->set_active_plane(index); 1291 1284 1292 offscreen_buffer_capture();1285 nv_offscreen_buffer_capture(); 1293 1286 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear screen 1294 1287 plane_render->render(); … … 1300 1293 std::ostringstream result; 1301 1294 result << "nv>legend " << volArg; 1302 result << " " << volume[ivol]->range_min();1303 result << " " << volume[ivol]->range_max();1295 result << " " << min; 1296 result << " " << max; 1304 1297 bmp_write(result.str().c_str()); 1305 1298 write(0, "\n", 1); 1306 1299 1307 1300 plane_render->remove_plane(index); 1308 resize_offscreen_buffer(old_width, old_height);1301 nv_resize_offscreen_buffer(old_width, old_height); 1309 1302 1310 1303 return TCL_OK; … … 1312 1305 1313 1306 //initialize frame buffer objects for offscreen rendering 1314 void init_offscreen_buffer() 1315 { 1316 1317 //initialize final fbo for final display 1318 glGenFramebuffersEXT(1, &final_fbo); 1319 glGenTextures(1, &final_color_tex); 1320 glGenRenderbuffersEXT(1, &final_depth_rb); 1321 1322 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo); 1323 1324 //initialize final color texture 1325 glBindTexture(GL_TEXTURE_2D, final_color_tex); 1326 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1327 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1307 void 1308 init_offscreen_buffer() 1309 { 1310 GLenum status; 1311 1312 //initialize final fbo for final display 1313 glGenFramebuffersEXT(1, &final_fbo); 1314 glGenTextures(1, &final_color_tex); 1315 glGenRenderbuffersEXT(1, &final_depth_rb); 1316 1317 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo); 1318 1319 //initialize final color texture 1320 glBindTexture(GL_TEXTURE_2D, final_color_tex); 1321 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1322 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1328 1323 #ifdef NV40 1329 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, win_width, win_height, 0,1330 1324 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, win_width, win_height, 0, 1325 GL_RGB, GL_INT, NULL); 1331 1326 #else 1332 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, win_width, win_height, 0,1333 1327 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, win_width, win_height, 0, 1328 GL_RGB, GL_INT, NULL); 1334 1329 #endif 1335 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,1336 1337 1338 1339 // initialize final depth renderbuffer1340 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, final_depth_rb);1341 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,1342 1343 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,1344 1345 1346 1347 // Check framebuffer completeness at the end of initialization.1348 CHECK_FRAMEBUFFER_STATUS();1349 assert(glGetError()==0);1330 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, 1331 GL_COLOR_ATTACHMENT0_EXT, 1332 GL_TEXTURE_2D, final_color_tex, 0); 1333 1334 // initialize final depth renderbuffer 1335 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, final_depth_rb); 1336 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, 1337 GL_DEPTH_COMPONENT24, win_width, win_height); 1338 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, 1339 GL_DEPTH_ATTACHMENT_EXT, 1340 GL_RENDERBUFFER_EXT, final_depth_rb); 1341 1342 // Check framebuffer completeness at the end of initialization. 1343 CHECK_FRAMEBUFFER_STATUS(); 1344 assert(glGetError()==0); 1350 1345 } 1351 1346 1352 1347 1353 1348 //resize the offscreen buffer 1354 void resize_offscreen_buffer(int w, int h){ 1355 win_width = w; 1356 win_height = h; 1357 1358 if (g_fonts) 1359 { 1349 void 1350 nv_resize_offscreen_buffer(int w, int h) 1351 { 1352 win_width = w; 1353 win_height = h; 1354 1355 if (g_fonts) { 1360 1356 g_fonts->resize(w, h); 1361 1357 } 1362 1363 //fprintf(stderr, "screen_buffer size: %d\n", sizeof(screen_buffer)); 1364 printf("screen_buffer size: %d %d\n", w, h); 1365 1366 if (screen_buffer) { 1367 delete[] screen_buffer; 1368 screen_buffer = NULL; 1369 } 1370 1371 screen_buffer = new unsigned char[4*win_width*win_height]; 1372 assert(screen_buffer != NULL); 1373 1374 //delete the current render buffer resources 1375 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo); 1376 glDeleteTextures(1, &final_color_tex); 1377 glDeleteFramebuffersEXT(1, &final_fbo); 1378 1379 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, final_depth_rb); 1380 glDeleteRenderbuffersEXT(1, &final_depth_rb); 1381 fprintf(stdin," after glDeleteRenderbuffers\n"); 1382 1383 //change the camera setting 1384 cam->set_screen_size(0, 0, win_width, win_height); 1385 plane_render->set_screen_size(win_width, win_height); 1386 1387 //Reinitialize final fbo for final display 1388 glGenFramebuffersEXT(1, &final_fbo); 1389 glGenTextures(1, &final_color_tex); 1390 glGenRenderbuffersEXT(1, &final_depth_rb); 1391 fprintf(stdin," after glGenRenderbuffers\n"); 1392 1393 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo); 1394 1395 //initialize final color texture 1396 glBindTexture(GL_TEXTURE_2D, final_color_tex); 1397 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1398 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1358 1359 //fprintf(stderr, "screen_buffer size: %d\n", sizeof(screen_buffer)); 1360 printf("screen_buffer size: %d %d\n", w, h); 1361 1362 if (screen_buffer) { 1363 delete[] screen_buffer; 1364 screen_buffer = NULL; 1365 } 1366 1367 screen_buffer = new unsigned char[4*win_width*win_height]; 1368 assert(screen_buffer != NULL); 1369 1370 //delete the current render buffer resources 1371 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo); 1372 glDeleteTextures(1, &final_color_tex); 1373 glDeleteFramebuffersEXT(1, &final_fbo); 1374 1375 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, final_depth_rb); 1376 glDeleteRenderbuffersEXT(1, &final_depth_rb); 1377 1378 //change the camera setting 1379 cam->set_screen_size(0, 0, win_width, win_height); 1380 plane_render->set_screen_size(win_width, win_height); 1381 1382 //Reinitialize final fbo for final display 1383 glGenFramebuffersEXT(1, &final_fbo); 1384 glGenTextures(1, &final_color_tex); 1385 glGenRenderbuffersEXT(1, &final_depth_rb); 1386 1387 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo); 1388 1389 //initialize final color texture 1390 glBindTexture(GL_TEXTURE_2D, final_color_tex); 1391 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1392 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1399 1393 #ifdef NV40 1400 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, win_width, win_height, 0,1401 1394 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, win_width, win_height, 0, 1395 GL_RGB, GL_INT, NULL); 1402 1396 #else 1403 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, win_width, win_height, 0,1404 1397 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, win_width, win_height, 0, 1398 GL_RGB, GL_INT, NULL); 1405 1399 #endif 1406 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, 1407 GL_COLOR_ATTACHMENT0_EXT, 1408 GL_TEXTURE_2D, final_color_tex, 0); 1409 fprintf(stdin," after glFramebufferTexture2DEXT\n"); 1400 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, 1401 GL_COLOR_ATTACHMENT0_EXT, 1402 GL_TEXTURE_2D, final_color_tex, 0); 1410 1403 1411 // initialize final depth renderbuffer 1412 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, final_depth_rb); 1413 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, 1414 GL_DEPTH_COMPONENT24, win_width, win_height); 1415 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, 1416 GL_DEPTH_ATTACHMENT_EXT, 1417 GL_RENDERBUFFER_EXT, final_depth_rb); 1418 fprintf(stdin," after glFramebufferRenderEXT\n"); 1419 1420 // Check framebuffer completeness at the end of initialization. 1421 CHECK_FRAMEBUFFER_STATUS(); 1422 assert(glGetError()==0); 1423 fprintf(stdin," after assert\n"); 1404 // initialize final depth renderbuffer 1405 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, final_depth_rb); 1406 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, 1407 GL_DEPTH_COMPONENT24, win_width, win_height); 1408 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, 1409 GL_DEPTH_ATTACHMENT_EXT, 1410 GL_RENDERBUFFER_EXT, final_depth_rb); 1411 1412 // Check framebuffer completeness at the end of initialization. 1413 CHECK_FRAMEBUFFER_STATUS(); 1414 assert(glGetError()==0); 1415 fprintf(stdin," after assert\n"); 1424 1416 } 1425 1417 1426 1418 1427 1419 //init line integral convolution 1428 void init_lic(){ 1429 lic = new Lic(NMESH, win_width, win_height, 0.3, g_context, volume[1]->id, 1420 void 1421 init_lic() { 1422 1423 lic = new Lic(NMESH, win_width, win_height, 0.3, g_context, volume[1]->id, 1430 1424 volume[1]->aspect_ratio_width, 1431 1425 volume[1]->aspect_ratio_height, … … 1446 1440 */ 1447 1441 1448 1449 void make_test_2D_data() 1450 { 1451 1452 int w = 300; 1453 int h = 200; 1454 float* data = new float[w*h]; 1455 1456 //procedurally make a gradient plane 1457 for(int j=0; j<h; j++){ 1458 for(int i=0; i<w; i++){ 1459 data[w*j+i] = float(i)/float(w); 1460 } 1461 } 1462 1463 plane[0] = new Texture2D(w, h, GL_FLOAT, GL_LINEAR, 1, data); 1464 1465 delete[] data; 1442 void 1443 make_test_2D_data() 1444 { 1445 1446 int w = 300; 1447 int h = 200; 1448 float* data = new float[w*h]; 1449 1450 //procedurally make a gradient plane 1451 for(int j=0; j<h; j++){ 1452 for(int i=0; i<w; i++){ 1453 data[w*j+i] = float(i)/float(w); 1454 } 1455 } 1456 plane[0] = new Texture2D(w, h, GL_FLOAT, GL_LINEAR, 1, data); 1457 delete[] data; 1466 1458 } 1467 1459 … … 1518 1510 g_vol_render = new VolumeRenderer(); 1519 1511 1512 1520 1513 /* 1521 1514 //I added this to debug : Wei … … 1532 1525 */ 1533 1526 1527 1534 1528 //create an 2D plane renderer 1535 1529 plane_render = new PlaneRenderer(g_context, win_width, win_height); 1536 1530 make_test_2D_data(); 1537 1531 1538 plane_render->add_plane(plane[0], get_transfunc("default"));1532 plane_render->add_plane(plane[0], nv_get_transfunc("default")); 1539 1533 1540 1534 assert(glGetError()==0); … … 1544 1538 } 1545 1539 1546 void read_screen() 1547 { 1548 glReadPixels(0, 0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE, screen_buffer); 1540 void 1541 nv_read_screen() 1542 { 1543 glReadPixels(0, 0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE, 1544 screen_buffer); 1549 1545 assert(glGetError()==0); 1550 1546 } 1551 1552 void display();1553 1554 1547 1555 1548 #if DO_RLE … … 1560 1553 int offsets_size; 1561 1554 1562 void do_rle(){ 1555 void 1556 do_rle(){ 1563 1557 int len = win_width*win_height*3; 1564 1558 rle_size = 0; … … 1591 1585 // used internally to build up the BMP file header 1592 1586 // writes an integer value into the header data structure at pos 1593 void1587 static void 1594 1588 bmp_header_add_int(unsigned char* header, int& pos, int data) 1595 1589 { … … 1771 1765 1772 1766 /*----------------------------------------------------*/ 1773 void idle() 1767 static void 1768 idle() 1774 1769 { 1775 1770 glutSetWindow(render_window); … … 1783 1778 1784 1779 #ifdef XINETD 1785 // in Command.cpp1786 1780 xinetd_listen(); 1787 1781 #else … … 1790 1784 } 1791 1785 1792 1793 voiddisplay_offscreen_buffer()1794 { 1795 glEnable(GL_TEXTURE_2D);1796 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);1797 glBindTexture(GL_TEXTURE_2D, final_color_tex);1798 1799 glViewport(0, 0, win_width, win_height);1800 glMatrixMode(GL_PROJECTION);1801 glLoadIdentity();1802 gluOrtho2D(0, win_width, 0, win_height);1803 glMatrixMode(GL_MODELVIEW);1804 glLoadIdentity();1805 1806 glColor3f(1.,1.,1.); //MUST HAVE THIS LINE!!!1807 glBegin(GL_QUADS);1808 glTexCoord2f(0, 0); glVertex2f(0, 0);1809 glTexCoord2f(1, 0); glVertex2f(win_width, 0);1810 glTexCoord2f(1, 1); glVertex2f(win_width, win_height);1811 glTexCoord2f(0, 1); glVertex2f(0, win_height);1812 glEnd();1813 1814 } 1815 1816 voidoffscreen_buffer_capture()1786 void 1787 nv_display_offscreen_buffer() 1788 { 1789 glEnable(GL_TEXTURE_2D); 1790 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 1791 glBindTexture(GL_TEXTURE_2D, final_color_tex); 1792 1793 glViewport(0, 0, win_width, win_height); 1794 glMatrixMode(GL_PROJECTION); 1795 glLoadIdentity(); 1796 gluOrtho2D(0, win_width, 0, win_height); 1797 glMatrixMode(GL_MODELVIEW); 1798 glLoadIdentity(); 1799 1800 glColor3f(1.,1.,1.); //MUST HAVE THIS LINE!!! 1801 glBegin(GL_QUADS); 1802 glTexCoord2f(0, 0); glVertex2f(0, 0); 1803 glTexCoord2f(1, 0); glVertex2f(win_width, 0); 1804 glTexCoord2f(1, 1); glVertex2f(win_width, win_height); 1805 glTexCoord2f(0, 1); glVertex2f(0, win_height); 1806 glEnd(); 1807 } 1808 1809 void 1810 nv_offscreen_buffer_capture() 1817 1811 { 1818 1812 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo); 1819 1813 } 1820 1814 1821 void draw_bounding_box(float x0, float y0, float z0, 1822 float x1, float y1, float z1, 1823 float r, float g, float b, float line_width) 1824 { 1825 glDisable(GL_TEXTURE_2D); 1826 1827 glColor4d(r, g, b, 1.0); 1828 glLineWidth(line_width); 1829 1830 glBegin(GL_LINE_LOOP); 1831 1832 glVertex3d(x0, y0, z0); 1833 glVertex3d(x1, y0, z0); 1834 glVertex3d(x1, y1, z0); 1835 glVertex3d(x0, y1, z0); 1836 1837 glEnd(); 1838 1839 glBegin(GL_LINE_LOOP); 1840 1841 glVertex3d(x0, y0, z1); 1842 glVertex3d(x1, y0, z1); 1843 glVertex3d(x1, y1, z1); 1844 glVertex3d(x0, y1, z1); 1845 1846 glEnd(); 1847 1848 1849 glBegin(GL_LINE_LOOP); 1850 1851 glVertex3d(x0, y0, z0); 1852 glVertex3d(x0, y0, z1); 1853 glVertex3d(x0, y1, z1); 1854 glVertex3d(x0, y1, z0); 1855 1856 glEnd(); 1857 1858 glBegin(GL_LINE_LOOP); 1859 1860 glVertex3d(x1, y0, z0); 1861 glVertex3d(x1, y0, z1); 1862 glVertex3d(x1, y1, z1); 1863 glVertex3d(x1, y1, z0); 1864 1865 glEnd(); 1866 1867 glEnable(GL_TEXTURE_2D); 1868 } 1869 1870 1871 1872 int particle_distance_sort(const void* a, const void* b){ 1873 if((*((Particle*)a)).aux > (*((Particle*)b)).aux) 1874 return -1; 1875 else 1876 return 1; 1815 /* 1816 * Is this routine being used? --gah 1817 * / 1818 void 1819 draw_bounding_box(float x0, float y0, float z0, 1820 float x1, float y1, float z1, 1821 float r, float g, float b, float line_width) 1822 { 1823 glDisable(GL_TEXTURE_2D); 1824 1825 glColor4d(r, g, b, 1.0); 1826 glLineWidth(line_width); 1827 1828 glBegin(GL_LINE_LOOP); 1829 1830 glVertex3d(x0, y0, z0); 1831 glVertex3d(x1, y0, z0); 1832 glVertex3d(x1, y1, z0); 1833 glVertex3d(x0, y1, z0); 1834 1835 glEnd(); 1836 1837 glBegin(GL_LINE_LOOP); 1838 1839 glVertex3d(x0, y0, z1); 1840 glVertex3d(x1, y0, z1); 1841 glVertex3d(x1, y1, z1); 1842 glVertex3d(x0, y1, z1); 1843 1844 glEnd(); 1845 1846 1847 glBegin(GL_LINE_LOOP); 1848 1849 glVertex3d(x0, y0, z0); 1850 glVertex3d(x0, y0, z1); 1851 glVertex3d(x0, y1, z1); 1852 glVertex3d(x0, y1, z0); 1853 1854 glEnd(); 1855 1856 glBegin(GL_LINE_LOOP); 1857 1858 glVertex3d(x1, y0, z0); 1859 glVertex3d(x1, y0, z1); 1860 glVertex3d(x1, y1, z1); 1861 glVertex3d(x1, y1, z0); 1862 1863 glEnd(); 1864 1865 glEnable(GL_TEXTURE_2D); 1866 } 1867 1868 1869 1870 static int 1871 particle_distance_sort(const void* a, const void* b) 1872 { 1873 if((*((Particle*)a)).aux > (*((Particle*)b)).aux) { 1874 return -1; 1875 } else { 1876 return 1; 1877 } 1877 1878 } 1878 1879 … … 1962 1963 1963 1964 //oddeven sort on GPU 1964 void sortstep() 1965 void 1966 sortstep() 1965 1967 { 1966 1968 // perform one step of the current sorting algorithm … … 2030 2032 2031 2033 2032 void draw_3d_axis() 2033 { 2034 void 2035 draw_3d_axis() 2036 { 2034 2037 glDisable(GL_TEXTURE_2D); 2035 2038 glEnable(GL_DEPTH_TEST); 2036 2037 //draw axes 2038 GLUquadric *obj; 2039 obj = gluNewQuadric(); 2040 2041 glDepthFunc(GL_LESS); 2039 2040 //draw axes 2041 GLUquadric *obj; 2042 2043 obj = gluNewQuadric(); 2044 2045 glDepthFunc(GL_LESS); 2042 2046 glEnable(GL_COLOR_MATERIAL); 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2047 glEnable(GL_DEPTH_TEST); 2048 glDisable(GL_BLEND); 2049 2050 int segments = 50; 2051 2052 glColor3f(0.8, 0.8, 0.8); 2053 glPushMatrix(); 2054 glTranslatef(0.4, 0., 0.); 2055 glRotatef(90, 1, 0, 0); 2056 glRotatef(180, 0, 1, 0); 2057 glScalef(0.0005, 0.0005, 0.0005); 2058 glutStrokeCharacter(GLUT_STROKE_ROMAN, 'x'); 2059 glPopMatrix(); 2060 2061 glPushMatrix(); 2062 glTranslatef(0., 0.4, 0.); 2063 glRotatef(90, 1, 0, 0); 2064 glRotatef(180, 0, 1, 0); 2065 glScalef(0.0005, 0.0005, 0.0005); 2066 glutStrokeCharacter(GLUT_STROKE_ROMAN, 'y'); 2067 glPopMatrix(); 2068 2069 glPushMatrix(); 2070 glTranslatef(0., 0., 0.4); 2071 glRotatef(90, 1, 0, 0); 2072 glRotatef(180, 0, 1, 0); 2073 glScalef(0.0005, 0.0005, 0.0005); 2074 glutStrokeCharacter(GLUT_STROKE_ROMAN, 'z'); 2075 glPopMatrix(); 2076 2077 glEnable(GL_LIGHTING); 2078 glEnable(GL_LIGHT0); 2079 2080 //glColor3f(0.2, 0.2, 0.8); 2081 glPushMatrix(); 2082 glutSolidSphere(0.02, segments, segments ); 2083 glPopMatrix(); 2084 2085 glPushMatrix(); 2086 glRotatef(-90, 1, 0, 0); 2087 gluCylinder(obj, 0.01, 0.01, 0.3, segments, segments); 2088 glPopMatrix(); 2089 2090 glPushMatrix(); 2091 glTranslatef(0., 0.3, 0.); 2092 glRotatef(-90, 1, 0, 0); 2093 gluCylinder(obj, 0.02, 0.0, 0.06, segments, segments); 2094 glPopMatrix(); 2095 2096 glPushMatrix(); 2097 glRotatef(90, 0, 1, 0); 2098 gluCylinder(obj, 0.01, 0.01, 0.3, segments, segments); 2099 glPopMatrix(); 2100 2101 glPushMatrix(); 2102 glTranslatef(0.3, 0., 0.); 2103 glRotatef(90, 0, 1, 0); 2104 gluCylinder(obj, 0.02, 0.0, 0.06, segments, segments); 2105 glPopMatrix(); 2106 2107 glPushMatrix(); 2108 gluCylinder(obj, 0.01, 0.01, 0.3, segments, segments); 2109 glPopMatrix(); 2110 2111 glPushMatrix(); 2112 glTranslatef(0., 0., 0.3); 2113 gluCylinder(obj, 0.02, 0.0, 0.06, segments, segments); 2114 glPopMatrix(); 2115 2116 glDisable(GL_LIGHTING); 2117 glDisable(GL_DEPTH_TEST); 2118 gluDeleteQuadric(obj); 2119 2116 2120 glEnable(GL_TEXTURE_2D); 2117 2121 glDisable(GL_DEPTH_TEST); … … 2119 2123 2120 2124 /* 2121 void draw_axis() 2122 { 2123 glDisable(GL_TEXTURE_2D); 2124 glEnable(GL_DEPTH_TEST); 2125 2126 //red x 2127 glColor3f(1,0,0); 2128 glBegin(GL_LINES); 2125 void 2126 draw_axis() 2127 { 2128 glDisable(GL_TEXTURE_2D); 2129 glEnable(GL_DEPTH_TEST); 2130 2131 //red x 2132 glColor3f(1,0,0); 2133 glBegin(GL_LINES); 2129 2134 glVertex3f(0,0,0); 2130 2135 glVertex3f(1.5,0,0); 2131 glEnd();2132 2133 //blue y2134 glColor3f(0,0,1);2135 glBegin(GL_LINES);2136 glEnd(); 2137 2138 //blue y 2139 glColor3f(0,0,1); 2140 glBegin(GL_LINES); 2136 2141 glVertex3f(0,0,0); 2137 2142 glVertex3f(0,1.5,0); 2138 glEnd();2139 2140 //green z2141 glColor3f(0,1,0);2142 glBegin(GL_LINES);2143 glEnd(); 2144 2145 //green z 2146 glColor3f(0,1,0); 2147 glBegin(GL_LINES); 2143 2148 glVertex3f(0,0,0); 2144 2149 glVertex3f(0,0,1.5); 2145 glEnd();2146 2147 glEnable(GL_TEXTURE_2D);2148 glDisable(GL_DEPTH_TEST);2150 glEnd(); 2151 2152 glEnable(GL_TEXTURE_2D); 2153 glDisable(GL_DEPTH_TEST); 2149 2154 } 2150 2155 */ 2151 2156 2152 2157 2153 2154 2158 /*----------------------------------------------------*/ 2155 void display() 2159 void 2160 nv_display() 2156 2161 { 2157 2162 assert(glGetError()==0); 2158 2163 2159 2164 //lic->convolve(); //flow line integral convolution 2160 2165 //psys->advect(); //advect particles 2161 2166 2162 2167 //start final rendering 2163 2168 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear screen 2164 2169 2165 if (volume_mode) 2166 { 2170 if (volume_mode) { 2167 2171 //3D rendering mode 2168 2172 glEnable(GL_TEXTURE_2D); 2169 2173 glEnable(GL_DEPTH_TEST); 2170 2174 2171 2175 //camera setting activated 2172 2176 cam->activate(); 2173 2177 2174 2178 //set up the orientation of items in the scene. 2175 2179 glPushMatrix(); … … 2183 2187 // this is the default 2184 2188 break; 2185 2189 2186 2190 case 3: // z 2187 2191 glRotatef(-90, 1, 0, 0); 2188 2192 glRotatef(-90, 0, 0, 1); 2189 2193 break; 2190 2194 2191 2195 case -1: // -x 2192 2196 glRotatef(-90, 0, 0, 1); 2193 2197 break; 2194 2198 2195 2199 case -2: // -y 2196 2200 glRotatef(180, 0, 0, 1); 2197 2201 glRotatef(-90, 0, 1, 0); 2198 2202 break; 2199 2203 2200 2204 case -3: // -z 2201 2205 glRotatef(90, 1, 0, 0); 2202 2206 break; 2203 2207 } 2204 2208 2205 2209 glPushMatrix(); 2206 2210 //now render things in the scene 2207 if (axis_on) 2208 { 2209 draw_3d_axis(); 2210 } 2211 2212 if (g_grid->isVisible()) 2213 { 2211 if (axis_on) { 2212 draw_3d_axis(); 2213 } 2214 if (g_grid->isVisible()) { 2214 2215 g_grid->render(); 2215 2216 } 2216 2217 2217 2218 //lic->render(); //display the line integral convolution result 2218 2219 //soft_display_verts(); … … 2222 2223 //fprintf(stderr, "particle pixels: %d\n", perf->get_pixel_count()); 2223 2224 //perf->reset(); 2224 2225 2225 2226 perf->enable(); 2226 2227 g_vol_render->render_all(); 2227 2228 2228 2229 perf->disable(); 2229 2230 for (int i i = 0; ii < g_heightMap.size(); ++ii)2231 {2232 if (g_heightMap[ii]->isVisible())2233 g_heightMap[ii]->render(); 2230 2231 for (int i = 0; i < g_heightMap.size(); ++i) { 2232 if (g_heightMap[i]->isVisible()) { 2233 g_heightMap[i]->render(); 2234 } 2234 2235 } 2235 2236 2236 glPopMatrix(); 2237 2238 float mat[16]; 2239 glGetFloatv(GL_MODELVIEW_MATRIX, mat); 2240 2241 for (int i = 0; i < g_pointSet.size(); ++i) 2242 { 2243 if (g_pointSet[i]->isVisible()) 2244 { 2245 g_pointset_renderer->render(g_pointSet[i]->getCluster(), mat, g_pointSet[i]->getSortLevel(), 2246 g_pointSet[i]->getScale(), 2247 g_pointSet[i]->getOrigin()); 2248 } 2249 } 2250 2251 glPopMatrix(); 2252 } 2253 else { 2237 } else { 2254 2238 //2D rendering mode 2255 2239 perf->enable(); 2256 2240 plane_render->render(); 2257 2241 perf->disable(); 2258 }2242 } 2259 2243 2260 2244 #ifdef XINETD … … 2267 2251 2268 2252 2269 void mouse(int button, int state, int x, int y){ 2270 if(button==GLUT_LEFT_BUTTON){ 2271 2272 if(state==GLUT_DOWN){ 2273 left_last_x = x; 2274 left_last_y = y; 2275 left_down = true; 2276 right_down = false; 2277 } 2278 else{ 2279 left_down = false; 2280 right_down = false; 2281 } 2282 } 2283 else{ 2284 //fprintf(stderr, "right mouse\n"); 2285 2286 if(state==GLUT_DOWN){ 2287 //fprintf(stderr, "right mouse down\n"); 2288 right_last_x = x; 2289 right_last_y = y; 2290 left_down = false; 2291 right_down = true; 2292 } 2293 else{ 2294 //fprintf(stderr, "right mouse up\n"); 2295 left_down = false; 2296 right_down = false; 2297 } 2298 } 2299 } 2300 2301 2302 void update_rot(int delta_x, int delta_y){ 2303 live_rot_x += delta_x; 2304 live_rot_y += delta_y; 2305 2306 if(live_rot_x > 360.0) 2307 live_rot_x -= 360.0; 2308 else if(live_rot_x < -360.0) 2309 live_rot_x += 360.0; 2310 2311 if(live_rot_y > 360.0) 2312 live_rot_y -= 360.0; 2313 else if(live_rot_y < -360.0) 2314 live_rot_y += 360.0; 2315 2316 cam->rotate(live_rot_x, live_rot_y, live_rot_z); 2317 } 2318 2319 2320 void update_trans(int delta_x, int delta_y, int delta_z){ 2321 live_obj_x += delta_x*0.03; 2322 live_obj_y += delta_y*0.03; 2323 live_obj_z += delta_z*0.03; 2253 static void 2254 mouse(int button, int state, int x, int y) 2255 { 2256 if(button==GLUT_LEFT_BUTTON){ 2257 if (state==GLUT_DOWN) { 2258 left_last_x = x; 2259 left_last_y = y; 2260 left_down = true; 2261 right_down = false; 2262 } else { 2263 left_down = false; 2264 right_down = false; 2265 } 2266 } else { 2267 //fprintf(stderr, "right mouse\n"); 2268 2269 if(state==GLUT_DOWN){ 2270 //fprintf(stderr, "right mouse down\n"); 2271 right_last_x = x; 2272 right_last_y = y; 2273 left_down = false; 2274 right_down = true; 2275 } else { 2276 //fprintf(stderr, "right mouse up\n"); 2277 left_down = false; 2278 right_down = false; 2279 } 2280 } 2281 } 2282 2283 2284 static void 2285 update_rot(int delta_x, int delta_y) 2286 { 2287 live_rot_x += delta_x; 2288 live_rot_y += delta_y; 2289 2290 if (live_rot_x > 360.0) { 2291 live_rot_x -= 360.0; 2292 } else if(live_rot_x < -360.0) { 2293 live_rot_x += 360.0; 2294 } 2295 if (live_rot_y > 360.0) { 2296 live_rot_y -= 360.0; 2297 } else if(live_rot_y < -360.0) { 2298 live_rot_y += 360.0; 2299 } 2300 cam->rotate(live_rot_x, live_rot_y, live_rot_z); 2301 } 2302 2303 2304 static void 2305 update_trans(int delta_x, int delta_y, int delta_z) 2306 { 2307 live_obj_x += delta_x*0.03; 2308 live_obj_y += delta_y*0.03; 2309 live_obj_z += delta_z*0.03; 2324 2310 } 2325 2311 2326 2312 void end_service(); 2327 2313 2328 void keyboard(unsigned char key, int x, int y){ 2329 2314 static void 2315 keyboard(unsigned char key, int x, int y) 2316 { 2330 2317 bool log = false; 2331 2318 2332 switch (key) {2333 2319 switch (key) { 2320 case 'q': 2334 2321 #ifdef XINETD 2335 2336 2322 //end_service(); 2323 NvExitService(); 2337 2324 #endif 2338 exit(0); 2339 break; 2340 case '+': 2341 lic_slice_z+=0.05; 2342 lic->set_offset(lic_slice_z); 2343 break; 2344 case '-': 2345 lic_slice_z-=0.05; 2346 lic->set_offset(lic_slice_z); 2347 break; 2348 case ',': 2349 lic_slice_x+=0.05; 2350 //init_particles(); 2351 break; 2352 case '.': 2353 lic_slice_x-=0.05; 2354 //init_particles(); 2355 break; 2356 case '1': 2357 //advect = true; 2358 break; 2359 case '2': 2360 //psys_x+=0.05; 2361 break; 2362 case '3': 2363 //psys_x-=0.05; 2364 break; 2365 case 'w': //zoom out 2366 live_obj_z-=0.05; 2367 log = true; 2368 cam->move(live_obj_x, live_obj_y, live_obj_z); 2369 break; 2370 case 's': //zoom in 2371 live_obj_z+=0.05; 2372 log = true; 2373 cam->move(live_obj_x, live_obj_y, live_obj_z); 2374 break; 2375 case 'a': //left 2376 live_obj_x-=0.05; 2377 log = true; 2378 cam->move(live_obj_x, live_obj_y, live_obj_z); 2379 break; 2380 case 'd': //right 2381 live_obj_x+=0.05; 2382 log = true; 2383 cam->move(live_obj_x, live_obj_y, live_obj_z); 2384 break; 2385 case 'i': 2386 //init_particles(); 2387 break; 2388 case 'v': 2389 g_vol_render->switch_volume_mode(); 2390 break; 2391 case 'b': 2392 g_vol_render->switch_slice_mode(); 2393 break; 2394 case 'n': 2395 resize_offscreen_buffer(win_width*2, win_height*2); 2396 break; 2397 case 'm': 2398 resize_offscreen_buffer(win_width/2, win_height/2); 2399 break; 2400 2401 default: 2402 break; 2403 } 2404 2325 exit(0); 2326 break; 2327 case '+': 2328 lic_slice_z+=0.05; 2329 lic->set_offset(lic_slice_z); 2330 break; 2331 case '-': 2332 lic_slice_z-=0.05; 2333 lic->set_offset(lic_slice_z); 2334 break; 2335 case ',': 2336 lic_slice_x+=0.05; 2337 //init_particles(); 2338 break; 2339 case '.': 2340 lic_slice_x-=0.05; 2341 //init_particles(); 2342 break; 2343 case '1': 2344 //advect = true; 2345 break; 2346 case '2': 2347 //psys_x+=0.05; 2348 break; 2349 case '3': 2350 //psys_x-=0.05; 2351 break; 2352 case 'w': //zoom out 2353 live_obj_z-=0.05; 2354 log = true; 2355 cam->move(live_obj_x, live_obj_y, live_obj_z); 2356 break; 2357 case 's': //zoom in 2358 live_obj_z+=0.05; 2359 log = true; 2360 cam->move(live_obj_x, live_obj_y, live_obj_z); 2361 break; 2362 case 'a': //left 2363 live_obj_x-=0.05; 2364 log = true; 2365 cam->move(live_obj_x, live_obj_y, live_obj_z); 2366 break; 2367 case 'd': //right 2368 live_obj_x+=0.05; 2369 log = true; 2370 cam->move(live_obj_x, live_obj_y, live_obj_z); 2371 break; 2372 case 'i': 2373 //init_particles(); 2374 break; 2375 case 'v': 2376 g_vol_render->switch_volume_mode(); 2377 break; 2378 case 'b': 2379 g_vol_render->switch_slice_mode(); 2380 break; 2381 case 'n': 2382 nv_resize_offscreen_buffer(win_width*2, win_height*2); 2383 break; 2384 case 'm': 2385 nv_resize_offscreen_buffer(win_width/2, win_height/2); 2386 break; 2387 default: 2388 break; 2389 } 2405 2390 #ifdef EVENTLOG 2406 2391 if(log){ 2407 float param[3] = {live_obj_x, live_obj_y, live_obj_z};2408 Event* tmp = new Event(EVENT_MOVE, param, NvGetTimeInterval());2409 tmp->write(event_log);2410 delete tmp;2392 float param[3] = {live_obj_x, live_obj_y, live_obj_z}; 2393 Event* tmp = new Event(EVENT_MOVE, param, NvGetTimeInterval()); 2394 tmp->write(event_log); 2395 delete tmp; 2411 2396 } 2412 2397 #endif 2413 2398 } 2414 2399 2415 void motion(int x, int y) 2416 { 2417 2400 static void 2401 motion(int x, int y) 2402 { 2418 2403 int old_x, old_y; 2419 2404 2420 2405 if(left_down){ 2421 old_x = left_last_x; 2422 old_y = left_last_y; 2423 } 2424 else if(right_down){ 2425 old_x = right_last_x; 2426 old_y = right_last_y; 2427 } 2428 2406 old_x = left_last_x; 2407 old_y = left_last_y; 2408 } else if(right_down){ 2409 old_x = right_last_x; 2410 old_y = right_last_y; 2411 } 2412 2429 2413 int delta_x = x - old_x; 2430 2414 int delta_y = y - old_y; 2431 2415 2432 2416 //more coarse event handling 2433 2417 //if(abs(delta_x)<10 && abs(delta_y)<10) 2434 2435 2418 //return; 2419 2436 2420 if(left_down){ 2437 left_last_x = x; 2438 left_last_y = y; 2439 2440 update_rot(-delta_y, -delta_x); 2441 } 2442 else if (right_down){ 2443 //fprintf(stderr, "right mouse motion (%d,%d)\n", x, y); 2444 2445 right_last_x = x; 2446 right_last_y = y; 2447 2448 update_trans(0, 0, delta_x); 2449 } 2450 2421 left_last_x = x; 2422 left_last_y = y; 2423 2424 update_rot(-delta_y, -delta_x); 2425 } else if (right_down){ 2426 //fprintf(stderr, "right mouse motion (%d,%d)\n", x, y); 2427 2428 right_last_x = x; 2429 right_last_y = y; 2430 2431 update_trans(0, 0, delta_x); 2432 } 2433 2451 2434 #ifdef EVENTLOG 2452 2435 float param[3] = {live_rot_x, live_rot_y, live_rot_z}; … … 2455 2438 delete tmp; 2456 2439 #endif 2457 2440 2458 2441 glutPostRedisplay(); 2459 2442 } … … 2513 2496 { 2514 2497 2515 char path [1000]; 2498 char *path; 2499 path = NULL; 2516 2500 while(1) { 2517 2501 int c; … … 2529 2513 switch(c) { 2530 2514 case 'p': 2531 strncpy(path, optarg, sizeof(path));2515 path = optarg; 2532 2516 break; 2533 2517 default: … … 2551 2535 glutInitWindowPosition(10, 10); 2552 2536 render_window = glutCreateWindow(argv[0]); 2553 glutDisplayFunc( display);2537 glutDisplayFunc(nv_display); 2554 2538 2555 2539 #ifndef XINETD … … 2560 2544 2561 2545 glutIdleFunc(idle); 2562 glutReshapeFunc( resize_offscreen_buffer);2546 glutReshapeFunc(nv_resize_offscreen_buffer); 2563 2547 2564 2548 NvInit(path); … … 2578 2562 return 0; 2579 2563 } 2564 -
trunk/vizservers/nanovis/socket/Socket.cpp
r226 r834 35 35 } 36 36 37 void set_address(char *hname, char *sname, struct sockaddr_in *sap, char *protocol){ 38 struct servent *sp; 39 struct hostent *hp; 40 char *endptr; 41 short port; 42 43 bzero(sap, sizeof(*sap)); 44 sap->sin_family = AF_INET; 45 46 if(hname!=NULL){ 47 if(!inet_aton(hname, &sap->sin_addr)){ 48 hp = gethostbyname(hname); 49 if(hp==NULL) 50 error(1, 0, "unknown host: %s\n", hname); 51 52 sap->sin_addr = *(struct in_addr *) hp->h_addr; 53 } 54 } 55 else 56 sap->sin_addr.s_addr = htonl(INADDR_ANY); 57 58 port = strtol(sname, &endptr, 0); 59 if(*endptr=='\0') 60 sap->sin_port = htons(port); 61 else{ 62 sp = getservbyname(sname, protocol); 63 if(sp==NULL) 64 error(1, 0, "unknown service: %s\n", sname); 65 } 37 void 38 set_address(char *hname, char *sname, struct sockaddr_in *sap, char *protocol) 39 { 40 struct servent *sp; 41 struct hostent *hp; 42 char *endptr; 43 short port; 44 45 bzero(sap, sizeof(*sap)); 46 sap->sin_family = AF_INET; 47 48 if (hname!=NULL) { 49 if (!inet_aton(hname, &sap->sin_addr)) { 50 hp = gethostbyname(hname); 51 if(hp==NULL) { 52 error(1, 0, "unknown host: %s\n", hname); 53 } 54 sap->sin_addr = *(struct in_addr *) hp->h_addr; 55 } 56 } else { 57 sap->sin_addr.s_addr = htonl(INADDR_ANY); 58 } 59 port = strtol(sname, &endptr, 0); 60 if (*endptr=='\0') { 61 sap->sin_port = htons(port); 62 } else { 63 sp = getservbyname(sname, protocol); 64 } 65 if (sp == NULL) { 66 error(1, 0, "unknown service: %s\n", sname); 67 } 66 68 } 67 69
Note: See TracChangeset
for help on using the changeset viewer.