Changeset 1161 for trunk/packages/vizservers
- Timestamp:
- Sep 24, 2008, 10:03:52 AM (16 years ago)
- Location:
- trunk/packages/vizservers
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/Axis.h
r1111 r1161 262 262 double InvMap(double x); 263 263 const char *name(void) { 264 return (name_ == NULL) ? "???" :name_;264 return name_; 265 265 } 266 266 void name(const char *name) { … … 271 271 } 272 272 const char *units(void) { 273 return (units_ == NULL) ? "???" :units_;273 return units_; 274 274 } 275 275 void units(const char *units) { … … 280 280 } 281 281 const char *title(void) { 282 return (title_ == NULL) ? "???" :title_;282 return title_; 283 283 } 284 284 void title(const char *title) { -
trunk/packages/vizservers/nanovis/AxisRange.h
r1111 r1161 2 2 #define _AXIS_RANGE_H 3 3 4 #include <string.h> 5 4 6 class AxisRange { 5 7 double min_, max_; 8 char *units_; 6 9 public: 7 10 AxisRange(void) { 8 11 min(0.0), max(1.0); 12 } 13 ~AxisRange(void) { 14 if (units_ != NULL) { 15 delete [] units_; 16 } 9 17 } 10 18 void SetRange(double min, double max) { … … 23 31 max_ = max; 24 32 } 33 const char *units(void) { 34 return units_; 35 } 36 void units(const char *units) { 37 if (units_ != NULL) { 38 delete [] units_; 39 } 40 units_ = new char [strlen(units) + 1]; 41 strcpy(units_, units); 42 } 25 43 }; 26 44 -
trunk/packages/vizservers/nanovis/Command.cpp
r1156 r1161 104 104 105 105 // Tcl interpreter for incoming messages 106 static Tcl_Interp *interp;107 static Tcl_DString cmdbuffer;108 106 109 107 // default transfer function … … 453 451 return TCL_ERROR; 454 452 } 455 if ( index < NanoVis::volume.size() &&NanoVis::volume[index] != NULL) {453 if (NanoVis::volume[index] != NULL) { 456 454 vectorPtr->push_back(index); 457 455 } … … 1914 1912 } 1915 1913 1916 1917 1914 static int 1918 1915 HeightMapDataFollowsOp(ClientData cdata, Tcl_Interp *interp, int objc, … … 2116 2113 return TCL_OK; 2117 2114 } 2115 2118 2116 2119 2117 static int … … 2475 2473 float xMin, yMin, xMax, yMax; 2476 2474 float *zValues; 2475 const char *xUnits, *yUnits, *zUnits; 2477 2476 2478 2477 if ((objc & 0x01) == 0) { … … 2485 2484 xNum = yNum = zNum = 0; 2486 2485 xMin = yMin = xMax = yMax = 0.0f; 2486 xUnits = yUnits = zUnits = NULL; 2487 2487 int i; 2488 2488 for (i = 1; i < objc; i += 2) { 2489 2489 const char *string; 2490 char c; 2490 2491 2491 2492 string = Tcl_GetString(objv[i]); 2492 if (strcmp(string, "xmin") == 0) { 2493 if (GetFloatFromObj(interp, objv[i+1], &xMin) != TCL_OK) { 2494 return TCL_ERROR; 2495 } 2496 } else if (strcmp(string, "xmax") == 0) { 2497 if (GetFloatFromObj(interp, objv[i+1], &xMax) != TCL_OK) { 2498 return TCL_ERROR; 2499 } 2500 } else if (strcmp(string, "xnum") == 0) { 2501 if (Tcl_GetIntFromObj(interp, objv[i+1], &xNum) != TCL_OK) { 2502 return TCL_ERROR; 2503 } 2504 if (xNum <= 0) { 2505 Tcl_AppendResult(interp, "bad xnum value: must be > 0", 2506 (char *)NULL); 2507 return TCL_ERROR; 2508 } 2509 } else if (strcmp(string, "ymin") == 0) { 2493 c = string[0]; 2494 if ((c == 'x') && (strcmp(string, "xmin") == 0)) { 2495 if (GetFloatFromObj(interp, objv[i+1], &xMin) != TCL_OK) { 2496 return TCL_ERROR; 2497 } 2498 } else if ((c == 'x') && (strcmp(string, "xmax") == 0)) { 2499 if (GetFloatFromObj(interp, objv[i+1], &xMax) != TCL_OK) { 2500 return TCL_ERROR; 2501 } 2502 } else if ((c == 'x') && (strcmp(string, "xnum") == 0)) { 2503 if (Tcl_GetIntFromObj(interp, objv[i+1], &xNum) != TCL_OK) { 2504 return TCL_ERROR; 2505 } 2506 if (xNum <= 0) { 2507 Tcl_AppendResult(interp, "bad xnum value: must be > 0", 2508 (char *)NULL); 2509 return TCL_ERROR; 2510 } 2511 } else if ((c == 'x') && (strcmp(string, "xunits") == 0)) { 2512 xUnits = Tcl_GetString(objv[i+1]); 2513 } else if ((c == 'y') && (strcmp(string, "ymin") == 0)) { 2510 2514 if (GetFloatFromObj(interp, objv[i+1], &yMin) != TCL_OK) { 2511 2515 return TCL_ERROR; 2512 2516 } 2513 } else if ( strcmp(string, "ymax") == 0) {2517 } else if ((c == 'y') && (strcmp(string, "ymax") == 0)) { 2514 2518 if (GetFloatFromObj(interp, objv[i+1], &yMax) != TCL_OK) { 2515 2519 return TCL_ERROR; 2516 2520 } 2517 } else if ( strcmp(string, "ynum") == 0) {2521 } else if ((c == 'y') && (strcmp(string, "ynum") == 0)) { 2518 2522 if (Tcl_GetIntFromObj(interp, objv[i+1], &yNum) != TCL_OK) { 2519 2523 return TCL_ERROR; … … 2524 2528 return TCL_ERROR; 2525 2529 } 2526 } else if (strcmp(string, "zvalues") == 0) { 2530 } else if ((c == 'y') && (strcmp(string, "yunits") == 0)) { 2531 yUnits = Tcl_GetString(objv[i+1]); 2532 } else if ((c == 'z') && (strcmp(string, "zvalues") == 0)) { 2527 2533 Tcl_Obj **zObj; 2528 2534 … … 2537 2543 } 2538 2544 } 2545 } else if ((c == 'z') && (strcmp(string, "zunits") == 0)) { 2546 zUnits = Tcl_GetString(objv[i+1]); 2539 2547 } else { 2540 2548 Tcl_AppendResult(interp, "unknown key \"", string, 2541 "\": should be xmin, xmax, xnum, ymin, ymax, ynum, or zvalues",2549 "\": should be xmin, xmax, xnum, xunits, ymin, ymax, ynum, yunits, zvalues, or zunits", 2542 2550 (char *)NULL); 2543 2551 return TCL_ERROR; … … 2556 2564 hmPtr = new HeightMap(); 2557 2565 2566 // Must set units before the heights. 2567 hmPtr->xAxis.units(xUnits); 2568 hmPtr->yAxis.units(yUnits); 2569 hmPtr->zAxis.units(zUnits); 2570 hmPtr->wAxis.units(yUnits); 2558 2571 hmPtr->setHeight(xMin, yMin, xMax, yMax, xNum, yNum, zValues); 2559 2572 hmPtr->setColorMap(NanoVis::get_transfunc("default")); … … 2565 2578 2566 2579 2567 void 2580 Tcl_Interp * 2568 2581 initTcl() 2569 2582 { 2583 2570 2584 /* 2571 2585 * Ideally the connection is authenticated by nanoscale. I still like the … … 2575 2589 * a test harness through the interpreter for nanovis. 2576 2590 */ 2591 Tcl_Interp *interp; 2577 2592 interp = Tcl_CreateInterp(); 2578 2593 Tcl_MakeSafe(interp); 2579 2580 Tcl_DStringInit(&cmdbuffer);2581 2594 2582 2595 Tcl_CreateObjCommand(interp, "axis", AxisCmd, NULL, NULL); … … 2602 2615 fprintf(NanoVis::logfile, Tcl_GetStringResult(interp)); 2603 2616 } 2604 } 2605 2606 2607 void 2608 xinetd_listen() 2609 { 2610 int flags = fcntl(0, F_GETFL, 0); 2611 fcntl(0, F_SETFL, flags & ~O_NONBLOCK); 2612 2613 int status = TCL_OK; 2614 int npass = 0; 2615 2616 // 2617 // Read and execute as many commands as we can from stdin... 2618 // 2619 while (status == TCL_OK) { 2620 // 2621 // Read the next command from the buffer. First time through we 2622 // block here and wait if necessary until a command comes in. 2623 // 2624 // BE CAREFUL: Read only one command, up to a newline. The "volume 2625 // data follows" command needs to be able to read the data 2626 // immediately following the command, and we shouldn't consume it 2627 // here. 2628 // 2629 while (1) { 2630 int c = fgetc(NanoVis::stdin); 2631 char ch; 2632 if (c <= 0) { 2633 if (npass == 0) { 2634 exit(0); // EOF -- we're done! 2635 } else { 2636 break; 2637 } 2638 } 2639 ch = (char)c; 2640 Tcl_DStringAppend(&cmdbuffer, &ch, 1); 2641 2642 if (ch=='\n' && Tcl_CommandComplete(Tcl_DStringValue(&cmdbuffer))) { 2643 break; 2644 } 2645 } 2646 // no command? then we're done for now 2647 if (Tcl_DStringLength(&cmdbuffer) == 0) { 2648 break; 2649 } 2650 2651 // back to original flags during command evaluation... 2652 fcntl(0, F_SETFL, flags & ~O_NONBLOCK); 2653 if (debug_flag) { 2654 fprintf(NanoVis::logfile, "%s\n", Tcl_DStringValue(&cmdbuffer)); 2655 } 2656 status = Tcl_Eval(interp, Tcl_DStringValue(&cmdbuffer)); 2657 Tcl_DStringSetLength(&cmdbuffer, 0); 2658 2659 // non-blocking for next read -- we might not get anything 2660 fcntl(0, F_SETFL, flags | O_NONBLOCK); 2661 npass++; 2662 } 2663 fcntl(0, F_SETFL, flags); 2664 2665 if (status != TCL_OK) { 2666 const char *string; 2667 int nBytes; 2668 2669 string = Tcl_GetStringFromObj(Tcl_GetObjResult(interp), &nBytes); 2670 struct iovec iov[3]; 2671 iov[0].iov_base = (char *)"NanoVis Server Error: "; 2672 iov[0].iov_len = strlen((char *)iov[0].iov_base); 2673 iov[1].iov_base = (char *)string; 2674 iov[1].iov_len = nBytes; 2675 iov[2].iov_base = (char *)'\n'; 2676 iov[2].iov_len = 1; 2677 writev(0, iov, 3); 2678 return; 2679 } 2680 2681 // 2682 // This is now in "FlowCmd()": 2683 // Generate the latest frame and send it back to the client 2684 // 2685 /* 2686 if (NanoVis::licRenderer && NanoVis::licRenderer->isActivated()) 2687 { 2688 NanoVis::licRenderer->convolve(); 2689 } 2690 2691 if (NanoVis::particleRenderer && NanoVis::particleRenderer->isActivated()) 2692 { 2693 NanoVis::particleRenderer->advect(); 2694 } 2695 */ 2696 2697 NanoVis::update(); 2698 2699 NanoVis::offscreen_buffer_capture(); //enable offscreen render 2700 2701 NanoVis::display(); 2617 return interp; 2618 } 2619 2620 2621 2622 int 2623 NanoVis::render_2d_contour(HeightMap* heightmap, int width, int height) 2624 { 2625 int old_width = win_width; 2626 int old_height = win_height; 2627 2628 resize_offscreen_buffer(width, height); 2629 2630 /* plane_render->set_screen_size(width, height); 2631 2632 // generate data for the legend 2633 float data[512]; 2634 for (int i=0; i < 256; i++) { 2635 data[i] = data[i+256] = (float)(i/255.0); 2636 } 2637 plane[0] = new Texture2D(256, 2, GL_FLOAT, GL_LINEAR, 1, data); 2638 int index = plane_render->add_plane(plane[0], tf); 2639 plane_render->set_active_plane(index); 2640 2641 offscreen_buffer_capture(); 2642 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear screen 2643 2644 //plane_render->render(); 2645 // INSOO : is going to implement here for the topview of the heightmap 2646 heightmap->render(renderContext); 2702 2647 2703 2648 // INSOO 2704 #ifdef XINETD 2705 NanoVis::read_screen(); 2706 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 2707 #else 2708 NanoVis::display_offscreen_buffer(); //display the final rendering on screen 2709 NanoVis::read_screen(); 2710 glutSwapBuffers(); 2711 #endif 2712 2713 #if DO_RLE 2714 do_rle(); 2715 int sizes[2] = { offsets_size*sizeof(offsets[0]), rle_size }; 2716 fprintf(stderr, "Writing %d,%d\n", sizes[0], sizes[1]); fflush(stderr); 2717 write(0, &sizes, sizeof(sizes)); 2718 write(0, offsets, offsets_size*sizeof(offsets[0])); 2719 write(0, rle, rle_size); //unsigned byte 2720 #else 2721 NanoVis::ppm_write("nv>image -bytes"); 2722 #endif 2723 } 2724 2649 glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, screen_buffer); 2650 //glReadPixels(0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE, screen_buffer); // INSOO's 2651 */ 2652 2653 2654 // HELP ME 2655 // GEORGE 2656 // I am not sure what I should do 2657 //char prefix[200]; 2658 //sprintf(prefix, "nv>height_top_view %s %g %g", volArg, min, max); 2659 //ppm_write(prefix); 2660 //write(0, "\n", 1); 2661 2662 2663 2664 2665 //plane_render->remove_plane(index); 2666 2667 resize_offscreen_buffer(old_width, old_height); 2668 2669 return TCL_OK; 2670 } 2671 -
trunk/packages/vizservers/nanovis/Grid.cpp
r1111 r1161 141 141 glLoadIdentity(); 142 142 glTranslatef((int) wx, viewport[3] - (int) wy, 0); 143 _font->draw(xAxis.name()); 143 const char *name = xAxis.name(); 144 if (name == NULL) { 145 name = "???"; 146 } 147 _font->draw(name); 144 148 } 145 149 … … 147 151 glLoadIdentity(); 148 152 glTranslatef((int) wx, viewport[3] - (int)wy, 0); 149 _font->draw(yAxis.name()); 153 const char *name = yAxis.name(); 154 if (name == NULL) { 155 name = "???"; 156 } 157 _font->draw(name); 150 158 } 151 159 … … 153 161 glLoadIdentity(); 154 162 glTranslatef((int) wx, (int) viewport[3] - (int)wy, 0.0f); 155 _font->draw(zAxis.name()); 163 const char *name = zAxis.name(); 164 if (name == NULL) { 165 name = "???"; 166 } 167 _font->draw(name); 156 168 } 157 169 -
trunk/packages/vizservers/nanovis/HeightMap.cpp
r1112 r1161 65 65 glCullFace((GLuint) renderContext->getCullMode()); 66 66 } 67 68 67 glPolygonMode(GL_FRONT_AND_BACK, (GLuint) renderContext->getPolygonMode()); 69 68 glShadeModel((GLuint) renderContext->getShadingModel()); … … 337 336 } 338 337 } 338 #ifdef notdef 339 if (retainScale_) { 340 // Check the units of each axis. If they are the same, we want to 341 // retain the surface's aspect ratio when transforming coordinates to 342 // the grid. Use the range of the longest axis when the units are the 343 // same. 344 if (xAxis.units() != NULL) && (xAxis.units() == yAxis.units()) { 345 } 346 if (yAxis.units() != NULL) && (yAxis.units() == zAxis.units()) { 347 } 348 } 349 #endif 350 339 351 wAxis.SetRange(min, max); 340 352 yAxis.SetRange(min, max); … … 444 456 445 457 // The range of the grid's y-axis 0..1 represents the distance between the 446 // smallest and largest major ticks for all surfaces plotted. Translate 458 // smallest and largest major ticks for all surfaces plotted. Translate 447 459 // this surface's y-values (heights) into the grid's axis coordinates. 448 460 … … 459 471 } 460 472 461 // Normalize the mesh coordinates (x and z min/max) the range of 462 // t he major ticks for the x and z grid axes as well.473 // Normalize the mesh coordinates (x and z min/max) the range of the major 474 // ticks for the x and z grid axes as well. 463 475 464 476 float xScale, zScale; … … 499 511 delete [] normHeights; 500 512 } 513 -
trunk/packages/vizservers/nanovis/nanovis.cpp
r1156 r1161 16 16 */ 17 17 18 #include <fcntl.h> 19 #include <fstream> 18 20 #include <getopt.h> 21 #include <iostream> 22 #include <math.h> 23 #include <memory.h> 24 #include <signal.h> 25 #include <sstream> 19 26 #include <stdio.h> 20 #include <math.h> 21 #include <fstream> 22 #include <iostream> 23 #include <sstream> 27 #include <stdlib.h> 24 28 #include <string> 25 #include <memory.h> 29 #include <sys/resource.h> 30 #include <sys/time.h> 31 #include <sys/times.h> 32 #include <sys/types.h> 26 33 #include <time.h> 27 #include <sys/time.h>28 #include <sys/types.h>29 34 #include <unistd.h> 30 #include <fcntl.h>31 #include <signal.h>32 #include <stdlib.h>33 35 34 36 #include "Nv.h" … … 79 81 X_POS = 1, Y_POS = 2, Z_POS = 3, X_NEG = -1, Y_NEG = -2, Z_NEG = -3 80 82 }; 83 84 #define STATSFILE "/var/tmp/visservers/data.xml" 85 #define KEEPSTATS 1 86 87 #define CVT2SECS(x) ((double)(x).tv_sec) + ((double)(x).tv_usec * 1.0e-6) 88 89 #define TRUE 1 90 #define FALSE 0 91 92 typedef struct { 93 pid_t pid; 94 size_t nFrames; /* # of frames sent to client. */ 95 size_t nBytes; /* # of bytes for all frames. */ 96 size_t nCommands; /* # of commands executed */ 97 double cmdTime; /* Elasped time spend executing commands. */ 98 struct timeval start; /* Start of elapsed time. */ 99 } Stats; 100 101 static Stats stats; 81 102 82 103 // STATIC MEMBER DATA … … 109 130 bool NanoVis::config_pending = false; 110 131 132 Tcl_Interp *NanoVis::interp; 133 Tcl_DString NanoVis::cmdbuffer; 111 134 112 135 //frame buffer for final rendering … … 143 166 144 167 // in Command.cpp 145 extern void xinetd_listen(); 146 extern void initTcl(); 168 extern Tcl_Interp *initTcl(); 147 169 148 170 //ParticleSystem* psys; … … 262 284 } 263 285 286 void removeAllData() 287 { 288 // 289 } 290 291 292 #ifdef KEEPSTATS 293 294 static int 295 WriteStats(const char *who, int code) 296 { 297 double start, finish; 298 pid_t pid; 299 char buf[BUFSIZ]; 300 Tcl_DString ds; 301 302 { 303 struct timeval tv; 304 305 /* Get ending time. */ 306 gettimeofday(&tv, NULL); 307 finish = CVT2SECS(tv); 308 tv = stats.start; 309 start = CVT2SECS(tv); 310 } 311 /* 312 * Session information: 313 * 1. Start date of session in seconds. 314 * 2. Process ID 315 * 3. Number of frames returned. 316 * 4. Number of bytes total returned (in frames). 317 * 5. Total elapsed time of all commands. 318 * 6. Total elapsed time of session. 319 * 7. Exit code of pymol server. 320 * 8. User time. 321 * 9. System time. 322 * 10. Maximum resident size. 323 */ 324 pid = getpid(); 325 Tcl_DStringInit(&ds); 326 327 sprintf(buf, "<session server=\"%s\" ", who); 328 Tcl_DStringAppend(&ds, buf, -1); 329 330 strcpy(buf, ctime(&stats.start.tv_sec)); 331 332 buf[strlen(buf) - 1] = '\0'; 333 Tcl_DStringAppend(&ds, "date=\"", -1); 334 Tcl_DStringAppend(&ds, buf, -1); 335 Tcl_DStringAppend(&ds, "\" ", -1); 336 337 sprintf(buf, "date_secs=\"%ld\" ", stats.start.tv_sec); 338 Tcl_DStringAppend(&ds, buf, -1); 339 340 sprintf(buf, "pid=\"%d\" ", pid); 341 Tcl_DStringAppend(&ds, buf, -1); 342 sprintf(buf, "num_frames=\"%lu\" ", (unsigned long int)stats.nFrames); 343 Tcl_DStringAppend(&ds, buf, -1); 344 sprintf(buf, "frame_bytes=\"%lu\" ", (unsigned long int)stats.nBytes); 345 Tcl_DStringAppend(&ds, buf, -1); 346 sprintf(buf, "num_commands=\"%lu\" ", (unsigned long int)stats.nCommands); 347 Tcl_DStringAppend(&ds, buf, -1); 348 sprintf(buf, "cmd_time=\"%g\" ", stats.cmdTime); 349 Tcl_DStringAppend(&ds, buf, -1); 350 sprintf(buf, "session_time=\"%g\" ", finish - start); 351 Tcl_DStringAppend(&ds, buf, -1); 352 sprintf(buf, "status=\"%d\" ", code); 353 Tcl_DStringAppend(&ds, buf, -1); 354 { 355 long clocksPerSec = sysconf(_SC_CLK_TCK); 356 double clockRes = 1.0 / clocksPerSec; 357 struct tms tms; 358 359 memset(&tms, 0, sizeof(tms)); 360 if (times(&tms) < 0) { 361 fprintf(NanoVis::logfile, "can't get times: %s\n", strerror(errno)); 362 } 363 sprintf(buf, "utime=\"%g\" ", tms.tms_utime * clockRes); 364 Tcl_DStringAppend(&ds, buf, -1); 365 sprintf(buf, "stime=\"%g\" ", tms.tms_stime * clockRes); 366 Tcl_DStringAppend(&ds, buf, -1); 367 sprintf(buf, "cutime=\"%g\" ", tms.tms_cutime * clockRes); 368 Tcl_DStringAppend(&ds, buf, -1); 369 sprintf(buf, "cstime=\"%g\" ", tms.tms_cstime * clockRes); 370 Tcl_DStringAppend(&ds, buf, -1); 371 } 372 Tcl_DStringAppend(&ds, "/>\n", -1); 373 374 { 375 int f; 376 ssize_t length; 377 int result; 378 379 length = Tcl_DStringLength(&ds); 380 f = open(STATSFILE, O_APPEND | O_CREAT | O_WRONLY, 0600); 381 result = FALSE; 382 if (f < 0) { 383 goto error; 384 } 385 if (write(f, Tcl_DStringValue(&ds), length) != length) { 386 goto error; 387 } 388 result = TRUE; 389 error: 390 if (f >= 0) { 391 close(f); 392 } 393 Tcl_DStringFree(&ds); 394 return result; 395 } 396 } 397 #endif 398 399 static void 400 DoExit(int code) 401 { 402 removeAllData(); 403 NvExit(); 404 #ifdef KEEPSTATS 405 WriteStats("nanovis", code); 406 #endif 407 exit(code); 408 } 409 264 410 //report errors related to CG shaders 265 411 void … … 275 421 Trace("Cg error, exiting...\n"); 276 422 cgDestroyContext(g_context); 277 exit(-1);423 DoExit(-1); 278 424 } 279 425 } … … 295 441 cgGLLoadProgram(program); 296 442 return program; 443 } 444 445 static int 446 ExecuteCommand(Tcl_Interp *interp, Tcl_DString *dsPtr) 447 { 448 struct timeval tv; 449 double start, finish; 450 int result; 451 452 gettimeofday(&tv, NULL); 453 start = CVT2SECS(tv); 454 455 if (debug_flag) { 456 fprintf(NanoVis::logfile, "%s\n", Tcl_DStringValue(dsPtr)); 457 } 458 result = Tcl_Eval(interp, Tcl_DStringValue(dsPtr)); 459 Tcl_DStringSetLength(dsPtr, 0); 460 461 gettimeofday(&tv, NULL); 462 finish = CVT2SECS(tv); 463 464 stats.cmdTime += finish - start; 465 stats.nCommands++; 466 return result; 297 467 } 298 468 … … 632 802 cgDestroyContext(g_context); 633 803 fflush(stdout); 634 exit(-1);804 DoExit(-1); 635 805 } 636 806 } … … 646 816 fprintf(stderr, "no path defined for shaders or resources\n"); 647 817 fflush(stderr); 648 exit(1);818 DoExit(-1); 649 819 } 650 820 // init GLEW … … 661 831 fprintf(stderr, "can't set file path to %s\n", path); 662 832 fflush(stderr); 663 exit(1);833 DoExit(1); 664 834 } 665 835 … … 913 1083 } 914 1084 } 915 fwrite( (void*)header, SIZEOF_BMP_HEADER, 1, f);916 fwrite( (void*)screen_buffer, (3*win_width+pad)*win_height, 1, f);1085 fwrite(header, SIZEOF_BMP_HEADER, 1, f); 1086 fwrite(screen_buffer, (3*win_width+pad)*win_height, 1, f); 917 1087 fclose(f); 918 1088 } … … 990 1160 write(0, header, SIZEOF_BMP_HEADER); 991 1161 write(0, screen_buffer, (3*win_width+pad)*win_height); 1162 stats.nFrames++; 1163 stats.nBytes += (3*win_width+pad)*win_height; 992 1164 } 993 1165 … … 1050 1222 writev(0, iov, nRecs); 1051 1223 free(iov); 1224 stats.nFrames++; 1225 stats.nBytes += (bytesPerRow * win_height); 1052 1226 } 1053 1227 … … 1084 1258 1085 1259 #ifdef notdef 1086 1087 1088 1089 1260 struct timespec ts; 1261 ts.tv_sec = 0; 1262 ts.tv_nsec = 300000000; 1263 nanosleep(&ts, 0); 1090 1264 #endif 1091 1265 #ifdef XINETD 1092 xinetd_listen();1266 NanoVis::xinetd_listen(); 1093 1267 #else 1094 1268 glutPostRedisplay(); … … 1744 1918 switch (key) { 1745 1919 case 'q': 1746 exit(0);1920 DoExit(0); 1747 1921 break; 1748 1922 case '+': … … 1920 2094 #endif 1921 2095 1922 void removeAllData() 1923 { 2096 2097 void 2098 NanoVis::xinetd_listen(void) 2099 { 2100 int flags = fcntl(0, F_GETFL, 0); 2101 fcntl(0, F_SETFL, flags & ~O_NONBLOCK); 2102 2103 int status = TCL_OK; 2104 int npass = 0; 2105 1924 2106 // 2107 // Read and execute as many commands as we can from stdin... 2108 // 2109 while (status == TCL_OK) { 2110 // 2111 // Read the next command from the buffer. First time through we 2112 // block here and wait if necessary until a command comes in. 2113 // 2114 // BE CAREFUL: Read only one command, up to a newline. The "volume 2115 // data follows" command needs to be able to read the data 2116 // immediately following the command, and we shouldn't consume it 2117 // here. 2118 // 2119 while (1) { 2120 int c = fgetc(NanoVis::stdin); 2121 char ch; 2122 if (c <= 0) { 2123 if (npass == 0) { 2124 DoExit(0); 2125 } else { 2126 break; 2127 } 2128 } 2129 ch = (char)c; 2130 Tcl_DStringAppend(&cmdbuffer, &ch, 1); 2131 2132 if (ch=='\n' && Tcl_CommandComplete(Tcl_DStringValue(&cmdbuffer))) { 2133 break; 2134 } 2135 } 2136 // no command? then we're done for now 2137 if (Tcl_DStringLength(&cmdbuffer) == 0) { 2138 break; 2139 } 2140 2141 // back to original flags during command evaluation... 2142 fcntl(0, F_SETFL, flags & ~O_NONBLOCK); 2143 status = ExecuteCommand(interp, &cmdbuffer); 2144 // non-blocking for next read -- we might not get anything 2145 fcntl(0, F_SETFL, flags | O_NONBLOCK); 2146 npass++; 2147 } 2148 fcntl(0, F_SETFL, flags); 2149 2150 if (status != TCL_OK) { 2151 const char *string; 2152 int nBytes; 2153 2154 string = Tcl_GetStringFromObj(Tcl_GetObjResult(interp), &nBytes); 2155 struct iovec iov[3]; 2156 iov[0].iov_base = (char *)"NanoVis Server Error: "; 2157 iov[0].iov_len = strlen((char *)iov[0].iov_base); 2158 iov[1].iov_base = (char *)string; 2159 iov[1].iov_len = nBytes; 2160 iov[2].iov_base = (char *)'\n'; 2161 iov[2].iov_len = 1; 2162 writev(0, iov, 3); 2163 return; 2164 } 2165 2166 // 2167 // This is now in "FlowCmd()": 2168 // Generate the latest frame and send it back to the client 2169 // 2170 /* 2171 if (NanoVis::licRenderer && NanoVis::licRenderer->isActivated()) 2172 { 2173 NanoVis::licRenderer->convolve(); 2174 } 2175 2176 if (NanoVis::particleRenderer && NanoVis::particleRenderer->isActivated()) 2177 { 2178 NanoVis::particleRenderer->advect(); 2179 } 2180 */ 2181 2182 NanoVis::update(); 2183 2184 NanoVis::offscreen_buffer_capture(); //enable offscreen render 2185 2186 NanoVis::display(); 2187 2188 // INSOO 2189 #ifdef XINETD 2190 NanoVis::read_screen(); 2191 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 2192 #else 2193 NanoVis::display_offscreen_buffer(); //display the final rendering on screen 2194 NanoVis::read_screen(); 2195 glutSwapBuffers(); 2196 #endif 2197 2198 #if DO_RLE 2199 do_rle(); 2200 int sizes[2] = { offsets_size*sizeof(offsets[0]), rle_size }; 2201 fprintf(stderr, "Writing %d,%d\n", sizes[0], sizes[1]); fflush(stderr); 2202 write(0, &sizes, sizeof(sizes)); 2203 write(0, offsets, offsets_size*sizeof(offsets[0])); 2204 write(0, rle, rle_size); //unsigned byte 2205 #else 2206 NanoVis::ppm_write("nv>image -bytes"); 2207 #endif 1925 2208 } 1926 2209 … … 1932 2215 const char *path; 1933 2216 char *newPath; 2217 struct timeval tv; 1934 2218 1935 2219 newPath = NULL; … … 1937 2221 NanoVis::stdin = stdin; 1938 2222 NanoVis::logfile = stderr; 1939 opterr = 1; 2223 2224 gettimeofday(&tv, NULL); 2225 stats.start = tv; 2226 1940 2227 while (1) { 1941 2228 static struct option long_options[] = { … … 2047 2334 } 2048 2335 NanoVis::initGL(); 2049 initTcl(); 2336 Tcl_DStringInit(&NanoVis::cmdbuffer); 2337 NanoVis::interp = initTcl(); 2050 2338 2051 2339 #ifdef EVENTLOG … … 2055 2343 glutMainLoop(); 2056 2344 2057 removeAllData(); 2058 2059 NvExit(); 2060 return 0; 2345 DoExit(0); 2061 2346 } 2062 2347 -
trunk/packages/vizservers/nanovis/nanovis.h
r1156 r1161 141 141 static bool vector_on; 142 142 143 static Tcl_Interp *interp; 144 static Tcl_DString cmdbuffer; 143 145 144 146 static TransferFunction* get_transfunc(const char *name); … … 164 166 static Volume *load_volume(int index, int width, int height, int depth, 165 167 int n, float* data, double vmin, double vmax, double nzero_min); 168 static void xinetd_listen(void); 166 169 static int render_2d_contour(HeightMap* heightmap, int width, int height); 167 170 -
trunk/packages/vizservers/pymolproxy/pymolproxy.c
r1155 r1161 20 20 21 21 #include <stdio.h> 22 #include <time.h> 22 23 #include <assert.h> 23 24 #include <unistd.h> … … 31 32 #include <poll.h> 32 33 #include <sys/time.h> 34 #include <sys/times.h> 33 35 #include <fcntl.h> 34 36 #include <netinet/in.h> … … 46 48 #endif 47 49 50 #define FALSE 0 51 #define TRUE 1 52 48 53 #define IO_TIMEOUT (30000) 49 #define STATSFILE "/var/tmp/pymolproxy.csv" 54 #define STATSFILE "/var/tmp/visservers/data.xml" 55 #define KEEPSTATS 1 56 #define CVT2SECS(x) ((double)(x).tv_sec) + ((double)(x).tv_usec * 1.0e-6) 50 57 51 58 typedef struct { 52 unsigned int date;59 pid_t child; /* Child process. */ 53 60 size_t nFrames; /* # of frames sent to client. */ 54 61 size_t nBytes; /* # of bytes for all frames. */ … … 63 70 static int debug = 1; 64 71 65 static void66 trace TCL_VARARGS_DEF(char *, arg1)67 {68 if (debug) {69 char *format;70 va_list args;71 72 format = TCL_VARARGS_START(char *, arg1, args);73 vfprintf(flog, format, args);74 fprintf(flog, "\n");75 fflush(flog);76 }77 }78 72 79 73 typedef struct { … … 103 97 } PymolProxy; 104 98 105 static int 106 ExecuteCommand(Tcl_Interp *interp, Tcl_DString *dsPtr, Stats *statsPtr) 99 static void 100 trace TCL_VARARGS_DEF(char *, arg1) 101 { 102 if (debug) { 103 char *format; 104 va_list args; 105 106 format = TCL_VARARGS_START(char *, arg1, args); 107 vfprintf(flog, format, args); 108 fprintf(flog, "\n"); 109 fflush(flog); 110 } 111 } 112 113 #ifdef KEEPSTATS 114 115 static int 116 WriteStats(const char *who, int code) 117 { 118 double start, finish; 119 pid_t pid; 120 char buf[BUFSIZ]; 121 Tcl_DString ds; 122 123 { 124 struct timeval tv; 125 126 /* Get ending time. */ 127 gettimeofday(&tv, NULL); 128 finish = CVT2SECS(tv); 129 tv = stats.start; 130 start = CVT2SECS(tv); 131 } 132 /* 133 * Session information: 134 * 1. Start date of session in seconds. 135 * 2. Process ID 136 * 3. Number of frames returned. 137 * 4. Number of bytes total returned (in frames). 138 * 5. Total elapsed time of all commands. 139 * 6. Total elapsed time of session. 140 * 7. Exit code of pymol server. 141 * 8. User time. 142 * 9. System time. 143 * 10. Maximum resident size. 144 */ 145 pid = getpid(); 146 Tcl_DStringInit(&ds); 147 148 sprintf(buf, "<session server=\"%s\" ", who); 149 Tcl_DStringAppend(&ds, buf, -1); 150 151 strcpy(buf, ctime(&stats.start.tv_sec)); 152 153 buf[strlen(buf) - 1] = '\0'; 154 Tcl_DStringAppend(&ds, "date=\"", -1); 155 Tcl_DStringAppend(&ds, buf, -1); 156 Tcl_DStringAppend(&ds, "\" ", -1); 157 158 sprintf(buf, "date_secs=\"%ld\" ", stats.start.tv_sec); 159 Tcl_DStringAppend(&ds, buf, -1); 160 161 sprintf(buf, "pid=\"%d\" ", pid); 162 Tcl_DStringAppend(&ds, buf, -1); 163 sprintf(buf, "num_frames=\"%lu\" ", (unsigned long int)stats.nFrames); 164 Tcl_DStringAppend(&ds, buf, -1); 165 sprintf(buf, "frame_bytes=\"%lu\" ", (unsigned long int)stats.nBytes); 166 Tcl_DStringAppend(&ds, buf, -1); 167 sprintf(buf, "num_commands=\"%lu\" ", (unsigned long int)stats.nCommands); 168 Tcl_DStringAppend(&ds, buf, -1); 169 sprintf(buf, "cmd_time=\"%g\" ", stats.cmdTime); 170 Tcl_DStringAppend(&ds, buf, -1); 171 sprintf(buf, "session_time=\"%g\" ", finish - start); 172 Tcl_DStringAppend(&ds, buf, -1); 173 sprintf(buf, "status=\"%d\" ", code); 174 Tcl_DStringAppend(&ds, buf, -1); 175 { 176 long clocksPerSec = sysconf(_SC_CLK_TCK); 177 double clockRes = 1.0 / clocksPerSec; 178 struct tms tms; 179 180 memset(&tms, 0, sizeof(tms)); 181 if (times(&tms) < 0) { 182 fprintf(flog, "can't get times: %s\n", strerror(errno)); 183 } 184 sprintf(buf, "utime=\"%g\" ", tms.tms_utime * clockRes); 185 Tcl_DStringAppend(&ds, buf, -1); 186 sprintf(buf, "stime=\"%g\" ", tms.tms_stime * clockRes); 187 Tcl_DStringAppend(&ds, buf, -1); 188 sprintf(buf, "cutime=\"%g\" ", tms.tms_cutime * clockRes); 189 Tcl_DStringAppend(&ds, buf, -1); 190 sprintf(buf, "cstime=\"%g\" ", tms.tms_cstime * clockRes); 191 Tcl_DStringAppend(&ds, buf, -1); 192 } 193 Tcl_DStringAppend(&ds, "/>\n", -1); 194 195 { 196 int f; 197 ssize_t length; 198 int result; 199 200 length = Tcl_DStringLength(&ds); 201 f = open(STATSFILE, O_APPEND | O_CREAT | O_WRONLY, 0600); 202 result = FALSE; 203 if (f < 0) { 204 goto error; 205 } 206 if (write(f, Tcl_DStringValue(&ds), length) != length) { 207 goto error; 208 } 209 result = TRUE; 210 error: 211 if (f >= 0) { 212 close(f); 213 } 214 Tcl_DStringFree(&ds); 215 return result; 216 } 217 } 218 #endif 219 220 static void 221 DoExit(int code) 222 { 223 char fileName[200]; 224 #ifdef KEEPSTATS 225 WriteStats("pymolproxy", code); 226 #endif 227 sprintf(fileName, "/tmp/pymol%d.pdb", getpid()); 228 unlink(fileName); 229 exit(code); 230 } 231 232 static int 233 ExecuteCommand(Tcl_Interp *interp, Tcl_DString *dsPtr) 107 234 { 108 235 struct timeval tv; … … 111 238 112 239 gettimeofday(&tv, NULL); 113 start = ((double)tv.tv_sec) + ((double)tv.tv_usec * 1.0e-6); 240 start = CVT2SECS(tv); 241 114 242 result = Tcl_Eval(interp, Tcl_DStringValue(dsPtr)); 115 243 trace("Executed (%s)", Tcl_DStringValue(dsPtr)); 116 244 Tcl_DStringSetLength(dsPtr, 0); 245 117 246 gettimeofday(&tv, NULL); 118 119 finish = ((double)tv.tv_sec) + ((double)tv.tv_usec * 1.0e-6); 120 stats Ptr->cmdTime += finish - start;121 stats Ptr->nCommands++;247 finish = CVT2SECS(tv); 248 249 stats.cmdTime += finish - start; 250 stats.nCommands++; 122 251 return result; 123 252 } 124 253 125 #ifdef KEEPSTATS126 127 static int128 WriteStats(Stats *statsPtr, int code)129 {130 struct timeval tv;131 double start, finish;132 int f;133 size_t length;134 char buf[4000];135 136 /* Get ending time. */137 gettimeofday(&tv, NULL);138 finish = ((double)tv.tv_sec) + ((double)tv.tv_usec * 1.0e-6);139 tv = statsPtr->start;140 start = ((double)tv.tv_sec) + ((double)tv.tv_usec * 1.0e-6);141 sprintf(buf, "\"pymolproxy\",%d,%d,%d,%d,%d,%d,%g,%g",142 getpid(),143 code,144 statsPtr->date,145 statsPtr->nFrames,146 statsPtr->nBytes,147 statsPtr->nCommands,148 statsPtr->cmdTime,149 finish - start);150 f = open(STATSFILE, O_APPEND | O_CREAT | O_WRONLY, 0600);151 if (f < 0) {152 return 0;153 }154 length = strlen(buf);155 if (write(f, buf, length) != length) {156 return 0;157 }158 close(f);159 return 1;160 }161 #endif162 254 163 255 INLINE static void … … 1247 1339 execvp(argv[0], argv); 1248 1340 trace("pymolproxy: Failed to start pyMol %s\n", argv[0]); 1249 exit(-1); 1250 } 1251 1341 exit(-1); 1342 } 1343 stats.child = pid; 1344 1252 1345 /* close opposite end of pipe, these now belong to the child process */ 1253 1346 close(pairIn[0]); … … 1358 1451 int result; 1359 1452 1360 result = ExecuteCommand(interp, &cmdbuffer , &stats);1453 result = ExecuteCommand(interp, &cmdbuffer); 1361 1454 if (timeout == 0) status = 0; // send update 1362 1455 } … … 1420 1513 1421 1514 status = waitpid(pid, &result, WNOHANG); 1422 #ifdef KEEPSTATS1423 WriteStats(&stats, status);1424 #endif1425 1515 if (status == -1) { 1426 1516 trace("pymolproxy: error waiting on pymol server to exit (%d)\n", errno); … … 1446 1536 1447 1537 Tcl_DeleteInterp(interp); 1448 1449 return ( (status == pid) ? 0 : 1);1538 DoExit(result); 1539 return 0; 1450 1540 } 1451 1541
Note: See TracChangeset
for help on using the changeset viewer.