Changeset 1694 for trunk/gui/scripts/nanovisviewer.tcl
- Timestamp:
- Apr 13, 2010, 12:36:52 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/nanovisviewer.tcl
r1638 r1694 16 16 package require BLT 17 17 package require Img 18 18 19 19 # 20 20 # FIXME: 21 # 22 # 23 # 24 # 21 # Need to Add DX readers this client to examine the data before 22 # it's sent to the server. This will eliminate 90% of the insanity in 23 # computing the limits of all the volumes. I can rip out all the 24 # "receive data" "send transfer function" event crap. 25 25 # 26 26 # This means we can compute the transfer function (relative values) and 27 # 28 # 29 # 30 # 31 # 27 # draw the legend min/max values without waiting for the information to 28 # come from the server. This will also prevent the flashing that occurs 29 # when a new volume is drawn (using the default transfer function) and 30 # then when the correct transfer function has been sent and linked to 31 # the volume. 32 32 # 33 33 option add *NanovisViewer.width 4i widgetDefault … … 46 46 proc NanovisViewer_init_resources {} { 47 47 Rappture::resources::register \ 48 48 nanovis_server Rappture::NanovisViewer::SetServerList 49 49 } 50 50 … … 57 57 58 58 constructor { hostlist args } { 59 59 Rappture::VisViewer::constructor $hostlist 60 60 } { 61 61 # defined below 62 62 } 63 63 destructor { 64 64 # defined below 65 65 } 66 66 public proc SetServerList { namelist } { 67 67 Rappture::VisViewer::SetServerList "nanovis" $namelist 68 68 } 69 69 public method add {dataobj {settings ""}} … … 78 78 public method sendto { string } 79 79 public method parameters {title args} { 80 80 # do nothing 81 81 } 82 82 public method rmdupmarker { m x } … … 124 124 private variable _obj2ovride ;# maps dataobj => style override 125 125 private variable _serverVols ;# contains all the dataobj-component 126 126 ;# to volumes in the server 127 127 private variable _serverTfs ;# contains all the transfer functions 128 128 ;# in the server. 129 129 private variable _recvdVols ;# list of data objs to send to server 130 130 private variable _vol2style ;# maps dataobj-component to transfunc 131 131 private variable _style2vols ;# maps tf back to list of 132 132 # dataobj-components using the tf. 133 133 134 134 private variable _click ;# info used for rotate operations … … 173 173 $_dispatcher register !send_transfunc 174 174 $_dispatcher dispatch $this !send_transfunc \ 175 175 "[itcl::code $this SendTransferFuncs]; list" 176 176 177 177 # Rebuild event … … 194 194 # Initialize the view to some default parameters. 195 195 array set _view { 196 197 198 199 200 pan-x0201 pan-y0196 theta 45 197 phi 45 198 psi 0 199 zoom 1.0 200 pan-x 0 201 pan-y 0 202 202 } 203 203 set _limits(vmin) 0.0 … … 205 205 206 206 array set _settings [subst { 207 $this-pan-x$_view(pan-x)208 $this-pan-y$_view(pan-y)209 $this-phi$_view(phi)210 $this-psi$_view(psi)211 $this-theta$_view(theta)212 $this-volume1213 $this-xcutplane0214 $this-xcutposition0215 $this-ycutplane0216 $this-ycutposition0217 $this-zcutplane0218 $this-zcutposition0219 $this-zoom$_view(zoom)207 $this-pan-x $_view(pan-x) 208 $this-pan-y $_view(pan-y) 209 $this-phi $_view(phi) 210 $this-psi $_view(psi) 211 $this-theta $_view(theta) 212 $this-volume 1 213 $this-xcutplane 0 214 $this-xcutposition 0 215 $this-ycutplane 0 216 $this-ycutposition 0 217 $this-zcutplane 0 218 $this-zcutposition 0 219 $this-zoom $_view(zoom) 220 220 }] 221 221 222 222 itk_component add 3dview { 223 224 223 label $itk_component(plotarea).vol -image $_image(plot) \ 224 -highlightthickness 0 -borderwidth 0 225 225 } { 226 227 226 usual 227 ignore -highlightthickness -borderwidth -background 228 228 } 229 229 … … 267 267 itk_component add volume { 268 268 Rappture::PushButton $f.volume \ 269 270 271 272 269 -onimage [Rappture::icon volume-on] \ 270 -offimage [Rappture::icon volume-off] \ 271 -command [itcl::code $this FixSettings volume] \ 272 -variable [itcl::scope _settings($this-volume)] 273 273 } 274 274 $itk_component(volume) select … … 286 286 set _image(legend) [image create photo] 287 287 itk_component add legend { 288 288 canvas $itk_component(plotarea).legend -height 50 -highlightthickness 0 289 289 } { 290 291 292 290 usual 291 ignore -highlightthickness 292 rename -background -plotbackground plotBackground Background 293 293 } 294 294 bind $itk_component(legend) <Configure> \ 295 295 [itcl::code $this EventuallyResizeLegend] 296 296 297 297 # Hack around the Tk panewindow. The problem is that the requested … … 301 301 pack forget $itk_component(3dview) 302 302 blt::table $itk_component(plotarea) \ 303 304 303 0,0 $itk_component(3dview) -fill both -reqwidth $w \ 304 1,0 $itk_component(legend) -fill x 305 305 blt::table configure $itk_component(plotarea) r1 -resize none 306 306 307 307 # Bindings for rotation via mouse 308 308 bind $itk_component(3dview) <ButtonPress-1> \ 309 309 [itcl::code $this Rotate click %x %y] 310 310 bind $itk_component(3dview) <B1-Motion> \ 311 311 [itcl::code $this Rotate drag %x %y] 312 312 bind $itk_component(3dview) <ButtonRelease-1> \ 313 313 [itcl::code $this Rotate release %x %y] 314 314 bind $itk_component(3dview) <Configure> \ 315 315 [itcl::code $this EventuallyResize %w %h] 316 316 317 317 # Bindings for panning via mouse 318 318 bind $itk_component(3dview) <ButtonPress-2> \ 319 319 [itcl::code $this Pan click %x %y] 320 320 bind $itk_component(3dview) <B2-Motion> \ 321 321 [itcl::code $this Pan drag %x %y] 322 322 bind $itk_component(3dview) <ButtonRelease-2> \ 323 323 [itcl::code $this Pan release %x %y] 324 324 325 325 # Bindings for panning via keyboard 326 326 bind $itk_component(3dview) <KeyPress-Left> \ 327 327 [itcl::code $this Pan set -10 0] 328 328 bind $itk_component(3dview) <KeyPress-Right> \ 329 329 [itcl::code $this Pan set 10 0] 330 330 bind $itk_component(3dview) <KeyPress-Up> \ 331 331 [itcl::code $this Pan set 0 -10] 332 332 bind $itk_component(3dview) <KeyPress-Down> \ 333 333 [itcl::code $this Pan set 0 10] 334 334 bind $itk_component(3dview) <Shift-KeyPress-Left> \ 335 335 [itcl::code $this Pan set -2 0] 336 336 bind $itk_component(3dview) <Shift-KeyPress-Right> \ 337 337 [itcl::code $this Pan set 2 0] 338 338 bind $itk_component(3dview) <Shift-KeyPress-Up> \ 339 339 [itcl::code $this Pan set 0 -2] 340 340 bind $itk_component(3dview) <Shift-KeyPress-Down> \ 341 341 [itcl::code $this Pan set 0 2] 342 342 343 343 # Bindings for zoom via keyboard 344 344 bind $itk_component(3dview) <KeyPress-Prior> \ 345 345 [itcl::code $this Zoom out] 346 346 bind $itk_component(3dview) <KeyPress-Next> \ 347 347 [itcl::code $this Zoom in] 348 348 349 349 bind $itk_component(3dview) <Enter> "focus $itk_component(3dview)" 350 350 351 351 if {[string equal "x11" [tk windowingsystem]]} { 352 353 354 352 # Bindings for zoom via mouse 353 bind $itk_component(3dview) <4> [itcl::code $this Zoom out] 354 bind $itk_component(3dview) <5> [itcl::code $this Zoom in] 355 355 } 356 356 … … 384 384 itcl::body Rappture::NanovisViewer::add {dataobj {settings ""}} { 385 385 array set params { 386 387 388 389 390 391 392 386 -color auto 387 -width 1 388 -linestyle solid 389 -brightness 0 390 -raise 0 391 -description "" 392 -param "" 393 393 } 394 394 foreach {opt val} $settings { 395 396 397 398 395 if {![info exists params($opt)]} { 396 error "bad setting \"$opt\": should be [join [lsort [array names params]] {, }]" 397 } 398 set params($opt) $val 399 399 } 400 400 if {$params(-color) == "auto" || $params(-color) == "autoreset"} { 401 402 401 # can't handle -autocolors yet 402 set params(-color) black 403 403 } 404 404 set pos [lsearch -exact $dataobj $_dlist] 405 405 if {$pos < 0} { 406 407 408 409 410 411 406 lappend _dlist $dataobj 407 set _allDataObjs($dataobj) 1 408 set _obj2ovride($dataobj-color) $params(-color) 409 set _obj2ovride($dataobj-width) $params(-width) 410 set _obj2ovride($dataobj-raise) $params(-raise) 411 $_dispatcher event -idle !rebuild 412 412 } 413 413 } … … 423 423 itcl::body Rappture::NanovisViewer::get {args} { 424 424 if {[llength $args] == 0} { 425 425 set args "-objects" 426 426 } 427 427 … … 429 429 switch -- $op { 430 430 -objects { 431 432 433 434 435 436 437 438 439 440 441 442 431 # put the dataobj list in order according to -raise options 432 set dlist $_dlist 433 foreach obj $dlist { 434 if {[info exists _obj2ovride($obj-raise)] && $_obj2ovride($obj-raise)} { 435 set i [lsearch -exact $dlist $obj] 436 if {$i >= 0} { 437 set dlist [lreplace $dlist $i $i] 438 lappend dlist $obj 439 } 440 } 441 } 442 return $dlist 443 443 } 444 444 -image { 445 446 447 448 449 450 451 452 453 454 455 456 457 458 445 if {[llength $args] != 2} { 446 error "wrong # args: should be \"get -image 3dview|legend\"" 447 } 448 switch -- [lindex $args end] { 449 3dview { 450 return $_image(plot) 451 } 452 legend { 453 return $_image(legend) 454 } 455 default { 456 error "bad image name \"[lindex $args end]\": should be 3dview or legend" 457 } 458 } 459 459 } 460 460 default { 461 461 error "bad option \"$op\": should be -objects or -image" 462 462 } 463 463 } … … 474 474 itcl::body Rappture::NanovisViewer::delete {args} { 475 475 if {[llength $args] == 0} { 476 476 set args $_dlist 477 477 } 478 478 # Delete all specified dataobjs 479 479 set changed 0 480 480 foreach dataobj $args { 481 482 483 484 485 486 487 488 481 set pos [lsearch -exact $_dlist $dataobj] 482 if { $pos >= 0 } { 483 set _dlist [lreplace $_dlist $pos $pos] 484 array unset _limits $dataobj* 485 array unset _obj2ovride $dataobj-* 486 array unset _vol2style $dataobj-* 487 set changed 1 488 } 489 489 } 490 490 # If anything changed, then rebuild the plot 491 491 if {$changed} { 492 492 $_dispatcher event -idle !rebuild 493 493 } 494 494 } … … 505 505 itcl::body Rappture::NanovisViewer::scale {args} { 506 506 foreach val {xmin xmax ymin ymax zmin zmax vmin vmax} { 507 507 set _limits($val) "" 508 508 } 509 509 foreach obj $args { 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 510 foreach axis {x y z v} { 511 512 foreach { min max } [$obj limits $axis] break 513 514 if {"" != $min && "" != $max} { 515 if {"" == $_limits(${axis}min)} { 516 set _limits(${axis}min) $min 517 set _limits(${axis}max) $max 518 } else { 519 if {$min < $_limits(${axis}min)} { 520 set _limits(${axis}min) $min 521 } 522 if {$max > $_limits(${axis}max)} { 523 set _limits(${axis}max) $max 524 } 525 } 526 } 527 } 528 528 } 529 529 } … … 541 541 itcl::body Rappture::NanovisViewer::download {option args} { 542 542 switch $option { 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 543 coming { 544 if {[catch { 545 blt::winop snap $itk_component(plotarea) $_image(download) 546 }]} { 547 $_image(download) configure -width 1 -height 1 548 $_image(download) put #000000 549 } 550 } 551 controls { 552 # no controls for this download yet 553 return "" 554 } 555 now { 556 # Get the image data (as base64) and decode it back to binary. 557 # This is better than writing to temporary files. When we switch 558 # to the BLT picture image it won't be necessary to decode the 559 # image data. 560 if { [image width $_image(plot)] > 0 && 561 [image height $_image(plot)] > 0 } { 562 set bytes [$_image(plot) data -format "jpeg -quality 100"] 563 set bytes [Rappture::encoding::decode -as b64 $bytes] 564 return [list .jpg $bytes] 565 } 566 return "" 567 } 568 default { 569 error "bad option \"$option\": should be coming, controls, now" 570 } 571 571 } 572 572 } … … 582 582 set _hosts [GetServerList "nanovis"] 583 583 if { "" == $_hosts } { 584 584 return 0 585 585 } 586 586 set result [VisViewer::Connect $_hosts] 587 587 if { $result } { 588 589 590 588 set w [winfo width $itk_component(3dview)] 589 set h [winfo height $itk_component(3dview)] 590 EventuallyResize $w $h 591 591 } 592 592 return $result … … 639 639 itcl::body Rappture::NanovisViewer::SendCmd {string} { 640 640 if { $_buffering } { 641 641 append _outbuf $string "\n" 642 642 } else { 643 644 645 646 643 foreach line [split $string \n] { 644 SendEcho >>line $line 645 } 646 SendBytes "$string\n" 647 647 } 648 648 } … … 654 654 itcl::body Rappture::NanovisViewer::SendTransferFuncs {} { 655 655 if { $_first == "" } { 656 657 656 puts stderr "first not set" 657 return 658 658 } 659 659 # Insure that the global opacity and thickness settings (in the slider … … 665 665 666 666 foreach vol [CurrentVolumes] { 667 668 669 670 671 672 673 674 continue;# How does this happen?675 676 677 678 679 680 681 #to update so that we only update the transfer function682 #as necessary. Right now, all transfer functions are683 #updated. This makes moving the isomarker slider chunky.684 685 686 687 667 if { ![info exists _serverVols($vol)] || !$_serverVols($vol) } { 668 # The volume hasn't reached the server yet. How did we get 669 # here? 670 continue 671 } 672 if { ![info exists _vol2style($vol)] } { 673 puts stderr "unknown volume $vol" 674 continue; # How does this happen? 675 } 676 set tf $_vol2style($vol) 677 set _settings($this-$tf-opacity) $opacity 678 set _settings($this-$tf-thickness) $thickness 679 ComputeTransferFunc $tf 680 # FIXME: Need to the send information as to what transfer functions 681 # to update so that we only update the transfer function 682 # as necessary. Right now, all transfer functions are 683 # updated. This makes moving the isomarker slider chunky. 684 if { ![info exists _activeTfs($tf)] || !$_activeTfs($tf) } { 685 set _activeTfs($tf) 1 686 } 687 SendCmd "volume shading transfunc $tf $vol" 688 688 } 689 689 FixLegend … … 699 699 itcl::body Rappture::NanovisViewer::ReceiveImage { args } { 700 700 array set info { 701 702 703 701 -token "???" 702 -bytes 0 703 -type image 704 704 } 705 705 array set info $args … … 707 707 ReceiveEcho <<line "<read $info(-bytes) bytes" 708 708 if { $info(-type) == "image" } { 709 ReceiveEcho "for [image width $_image(plot)]x[image height $_image(plot)] image>" 710 709 ReceiveEcho "for [image width $_image(plot)]x[image height $_image(plot)] image>" 710 $_image(plot) configure -data $bytes 711 711 } elseif { $info(type) == "print" } { 712 713 712 set tag $this-print-$info(-token) 713 set _hardcopy($tag) $bytes 714 714 } 715 715 } … … 730 730 itcl::body Rappture::NanovisViewer::ReceiveLegend { tf vmin vmax size } { 731 731 if { ![isconnected] } { 732 732 return 733 733 } 734 734 set bytes [ReceiveBytes $size] … … 742 742 set ly [expr {$h - 1}] 743 743 if {"" == [$c find withtag transfunc]} { 744 745 746 747 748 749 750 751 752 744 $c create image 10 10 -anchor nw \ 745 -image $_image(legend) -tags transfunc 746 $c create text $lx $ly -anchor sw \ 747 -fill $itk_option(-plotforeground) -tags "limits vmin" 748 $c create text [expr {$w-$lx}] $ly -anchor se \ 749 -fill $itk_option(-plotforeground) -tags "limits vmax" 750 $c lower transfunc 751 $c bind transfunc <ButtonRelease-1> \ 752 [itcl::code $this AddIsoMarker %x %y] 753 753 } 754 754 # Display the markers used by the active transfer function. … … 762 762 763 763 if { [info exists _isomarkers($tf)] } { 764 765 766 764 foreach m $_isomarkers($tf) { 765 $m visible yes 766 } 767 767 } 768 768 } … … 791 791 itcl::body Rappture::NanovisViewer::ReceiveData { args } { 792 792 if { ![isconnected] } { 793 793 return 794 794 } 795 795 # Arguments from server are name value pairs. Stuff them in an array. … … 805 805 set _serverVols($tag) 1 806 806 if { $_settings($this-volume) && $dataobj == $_first } { 807 807 SendCmd "volume state 1 $tag" 808 808 } 809 809 set _limits($tag-min) $info(min); # Minimum value of the volume. … … 814 814 unset _recvdVols($tag) 815 815 if { [array size _recvdVols] == 0 } { 816 817 818 819 816 # The active transfer function is by default the first component of 817 # the first data object. This assumes that the data is always 818 # successfully transferred. 819 updatetransferfuncs 820 820 } 821 821 } … … 839 839 840 840 foreach tf [array names _isomarkers] { 841 842 843 841 foreach m $_isomarkers($tf) { 842 $m visible no 843 } 844 844 } 845 845 … … 849 849 850 850 foreach dataobj [get] { 851 852 853 854 855 856 857 858 859 860 861 862 863 851 foreach comp [$dataobj components] { 852 set vol $dataobj-$comp 853 if { ![info exists _serverVols($vol)] } { 854 # Send the data as one huge base64-encoded mess -- yuck! 855 set data [$dataobj values $comp] 856 set nbytes [string length $data] 857 append _outbuf "volume data follows $nbytes $vol\n" 858 append _outbuf $data 859 set _recvdVols($vol) 1 860 set _serverVols($vol) 0 861 } 862 NameTransferFunc $dataobj $comp 863 } 864 864 } 865 865 # … … 889 889 set _first [lindex [get] 0] 890 890 if {"" != $_first} { 891 892 893 894 895 896 897 898 899 900 901 902 891 set axis [$_first hints updir] 892 if { "" != $axis } { 893 SendCmd "up $axis" 894 } 895 set location [$_first hints camera] 896 if { $location != "" } { 897 array set _view $location 898 } 899 set vols [array names _serverVols $_first-*] 900 if { $vols != "" } { 901 SendCmd "volume state 1 $vols" 902 } 903 903 } 904 904 # If the first volume already exists on the server, then make sure we … … 906 906 set comp [lindex [$_first components] 0] 907 907 if { [info exists _serverVols($_first-$comp)] } { 908 908 updatetransferfuncs 909 909 } 910 910 … … 912 912 set vols [CurrentVolumes -cutplanes] 913 913 foreach axis {x y z} { 914 915 916 914 SendCmd "cutplane state $_settings($this-${axis}cutplane) $axis $vols" 915 set pos [expr {0.01*$_settings($this-${axis}cutposition)}] 916 SendCmd "cutplane position $pos $axis $vols" 917 917 } 918 918 SendCmd "volume data state $_settings($this-volume) $vols" 919 set _buffering 0; 919 set _buffering 0; # Turn off buffering. 920 920 # Actually write the commands to the server socket. If it fails, we don't 921 921 # care. We're finished here. 922 922 blt::busy hold $itk_component(hull) 923 SendBytes $_outbuf; 923 SendBytes $_outbuf; 924 924 blt::busy release $itk_component(hull) 925 set _outbuf ""; # Clear the buffer.925 set _outbuf ""; # Clear the buffer. 926 926 } 927 927 … … 936 936 set rlist "" 937 937 if { $_first == "" } { 938 938 return 939 939 } 940 940 foreach comp [$_first components] { 941 942 943 944 945 946 947 948 949 950 941 set vol $_first-$comp 942 if { [info exists _serverVols($vol)] && $_serverVols($vol) } { 943 array set style { 944 -cutplanes 1 945 } 946 array set style [lindex [$_first components -style $comp] 0] 947 if {$what != "-cutplanes" || $style(-cutplanes)} { 948 lappend rlist $vol 949 } 950 } 951 951 } 952 952 return $rlist … … 963 963 itcl::body Rappture::NanovisViewer::Zoom {option} { 964 964 switch -- $option { 965 966 967 968 969 970 971 972 965 "in" { 966 set _view(zoom) [expr {$_view(zoom)*1.25}] 967 set _settings($this-zoom) $_view(zoom) 968 } 969 "out" { 970 set _view(zoom) [expr {$_view(zoom)*0.8}] 971 set _settings($this-zoom) $_view(zoom) 972 } 973 973 "reset" { 974 975 976 977 978 zoom1.0979 pan-x0980 pan-y0981 982 983 984 985 986 987 974 array set _view { 975 theta 45 976 phi 45 977 psi 0 978 zoom 1.0 979 pan-x 0 980 pan-y 0 981 } 982 if { $_first != "" } { 983 set location [$_first hints camera] 984 if { $location != "" } { 985 array set _view $location 986 } 987 } 988 988 set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)] 989 989 SendCmd "camera angle $xyz" 990 991 992 993 994 995 996 990 PanCamera 991 set _settings($this-theta) $_view(theta) 992 set _settings($this-phi) $_view(phi) 993 set _settings($this-psi) $_view(psi) 994 set _settings($this-pan-x) $_view(pan-x) 995 set _settings($this-pan-y) $_view(pan-y) 996 set _settings($this-zoom) $_view(zoom) 997 997 } 998 998 } … … 1067 1067 } 1068 1068 1069 1070 1071 1069 set _view(theta) $theta 1070 set _view(phi) $phi 1071 set _view(psi) $psi 1072 1072 set xyz [Euler2XYZ $theta $phi $psi] 1073 1074 1075 1073 set _settings($this-theta) $_view(theta) 1074 set _settings($this-phi) $_view(phi) 1075 set _settings($this-psi) $_view(psi) 1076 1076 SendCmd "camera angle $xyz" 1077 1077 set _click(x) $x … … 1108 1108 set _view(pan-y) [expr $_view(pan-y) + $y] 1109 1109 PanCamera 1110 1111 1110 set _settings($this-pan-x) $_view(pan-x) 1111 set _settings($this-pan-y) $_view(pan-y) 1112 1112 return 1113 1113 } … … 1125 1125 set _view(pan-y) [expr $_view(pan-y) - $dy] 1126 1126 PanCamera 1127 1128 1127 set _settings($this-pan-x) $_view(pan-x) 1128 set _settings($this-pan-y) $_view(pan-y) 1129 1129 } 1130 1130 if { $option == "release" } { … … 1162 1162 set val $_settings($this-opacity) 1163 1163 set sval [expr { 0.01 * double($val) }] 1164 1165 1166 1167 1164 foreach tf [array names _activeTfs] { 1165 set _settings($this-$tf-opacity) $sval 1166 set _activeTfs($tf) 0 1167 } 1168 1168 updatetransferfuncs 1169 1169 } … … 1175 1175 # Scale values between 0.00001 and 0.01000 1176 1176 set sval [expr {0.0001*double($val)}] 1177 1178 1179 1180 1177 foreach tf [array names _activeTfs] { 1178 set _settings($this-$tf-thickness) $sval 1179 set _activeTfs($tf) 0 1180 } 1181 1181 updatetransferfuncs 1182 1182 } … … 1202 1202 } 1203 1203 } 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1204 "legend" { 1205 if { $_settings($this-legend) } { 1206 blt::table $itk_component(plotarea) \ 1207 0,0 $itk_component(3dview) -fill both \ 1208 1,0 $itk_component(legend) -fill x 1209 blt::table configure $itk_component(plotarea) r1 -resize none 1210 } else { 1211 blt::table forget $itk_component(legend) 1212 } 1213 } 1214 1214 "volume" { 1215 1215 if { [isconnected] } { 1216 1216 set vols [CurrentVolumes -cutplanes] 1217 1217 SendCmd "volume data state $_settings($this-volume) $vols" 1218 1218 } 1219 1219 } 1220 1220 "xcutplane" - "ycutplane" - "zcutplane" { 1221 1222 1221 set axis [string range $what 0 0] 1222 set bool $_settings($this-$what) 1223 1223 if { [isconnected] } { 1224 1225 1226 1227 1228 1229 1224 set vols [CurrentVolumes -cutplanes] 1225 SendCmd "cutplane state $bool $axis $vols" 1226 } 1227 if { $bool } { 1228 $itk_component(${axis}CutScale) configure -state normal \ 1229 -troughcolor white 1230 1230 } else { 1231 1232 1231 $itk_component(${axis}CutScale) configure -state disabled \ 1232 -troughcolor grey82 1233 1233 } 1234 1234 } … … 1252 1252 set h [expr {[winfo height $itk_component(legend)]-20-$lineht}] 1253 1253 if {$w > 0 && $h > 0 && [array names _activeTfs] > 0 && $_first != "" } { 1254 1255 1256 1257 1254 set vol [lindex [CurrentVolumes] 0] 1255 if { [info exists _vol2style($vol)] } { 1256 SendCmd "legend $_vol2style($vol) $w $h" 1257 } 1258 1258 } else { 1259 1260 1261 1262 1259 # Can't do this as this will remove the items associated with the 1260 # isomarkers. 1261 1262 #$itk_component(legend) delete all 1263 1263 } 1264 1264 } … … 1281 1281 itcl::body Rappture::NanovisViewer::NameTransferFunc { dataobj comp } { 1282 1282 array set style { 1283 1284 1285 1283 -color rainbow 1284 -levels 6 1285 -opacity 1.0 1286 1286 } 1287 1287 array set style [lindex [$dataobj components -style $comp] 0] … … 1303 1303 itcl::body Rappture::NanovisViewer::ComputeTransferFunc { tf } { 1304 1304 array set style { 1305 1306 1307 1305 -color rainbow 1306 -levels 6 1307 -opacity 1.0 1308 1308 } 1309 1309 foreach {dataobj comp} [split $_style2vols($tf) -] break … … 1325 1325 1326 1326 if { ![info exists _isomarkers($tf)] } { 1327 1328 1329 1330 1331 1332 1327 # Have to defer creation of isomarkers until we have data limits 1328 if { [info exists style(-markers)] } { 1329 ParseMarkersOption $tf $style(-markers) 1330 } else { 1331 ParseLevelsOption $tf $style(-levels) 1332 } 1333 1333 } 1334 1334 if {$style(-color) == "rainbow"} { 1335 1335 set style(-color) "white:yellow:green:cyan:blue:magenta" 1336 1336 } 1337 1337 set clist [split $style(-color) :] 1338 1338 set cmap "0.0 [Color2RGB white] " 1339 1339 for {set i 0} {$i < [llength $clist]} {incr i} { 1340 1341 1342 1340 set x [expr {double($i+1)/([llength $clist]+1)}] 1341 set color [lindex $clist $i] 1342 append cmap "$x [Color2RGB $color] " 1343 1343 } 1344 1344 append cmap "1.0 [Color2RGB $color]" … … 1346 1346 set tag $this-$tf 1347 1347 if { ![info exists _settings($tag-opacity)] } { 1348 1348 set _settings($tag-opacity) $style(-opacity) 1349 1349 } 1350 1350 set max $_settings($tag-opacity) … … 1352 1352 set isovalues {} 1353 1353 foreach m $_isomarkers($tf) { 1354 1354 lappend isovalues [$m relval] 1355 1355 } 1356 1356 # Sort the isovalues … … 1358 1358 1359 1359 if { ![info exists _settings($tag-thickness)]} { 1360 1360 set _settings($tag-thickness) 0.05 1361 1361 } 1362 1362 set delta $_settings($tag-thickness) … … 1366 1366 set wmap "" 1367 1367 if { $first == "" || $first != 0.0 } { 1368 1368 lappend wmap 0.0 0.0 1369 1369 } 1370 1370 foreach x $isovalues { 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1371 set x1 [expr {$x-$delta-0.00001}] 1372 set x2 [expr {$x-$delta}] 1373 set x3 [expr {$x+$delta}] 1374 set x4 [expr {$x+$delta+0.00001}] 1375 if { $x1 < 0.0 } { 1376 set x1 0.0 1377 } elseif { $x1 > 1.0 } { 1378 set x1 1.0 1379 } 1380 if { $x2 < 0.0 } { 1381 set x2 0.0 1382 } elseif { $x2 > 1.0 } { 1383 set x2 1.0 1384 } 1385 if { $x3 < 0.0 } { 1386 set x3 0.0 1387 } elseif { $x3 > 1.0 } { 1388 set x3 1.0 1389 } 1390 if { $x4 < 0.0 } { 1391 set x4 0.0 1392 } elseif { $x4 > 1.0 } { 1393 set x4 1.0 1394 } 1395 # add spikes in the middle 1396 lappend wmap $x1 0.0 1397 lappend wmap $x2 $max 1398 lappend wmap $x3 $max 1399 lappend wmap $x4 0.0 1400 1400 } 1401 1401 if { $last == "" || $last != 1.0 } { 1402 1402 lappend wmap 1.0 0.0 1403 1403 } 1404 1404 SendCmd "transfunc define $tf { $cmap } { $wmap }" … … 1410 1410 itcl::configbody Rappture::NanovisViewer::plotbackground { 1411 1411 if { [isconnected] } { 1412 1413 1414 1412 foreach {r g b} [Color2RGB $itk_option(-plotbackground)] break 1413 #fix this! 1414 #SendCmd "color background $r $g $b" 1415 1415 } 1416 1416 } … … 1421 1421 itcl::configbody Rappture::NanovisViewer::plotforeground { 1422 1422 if { [isconnected] } { 1423 1424 1425 1423 foreach {r g b} [Color2RGB $itk_option(-plotforeground)] break 1424 #fix this! 1425 #SendCmd "color background $r $g $b" 1426 1426 } 1427 1427 } … … 1436 1436 # start sending commands to visualization server. 1437 1437 if { [isconnected] } { 1438 1439 1440 1441 1442 1443 1438 if {"" == $itk_option(-plotoutline)} { 1439 SendCmd "volume outline state off" 1440 } else { 1441 SendCmd "volume outline state on" 1442 SendCmd "volume outline color [Color2RGB $itk_option(-plotoutline)]" 1443 } 1444 1444 } 1445 1445 } … … 1454 1454 regsub -all "," $levels " " levels 1455 1455 if {[string is int $levels]} { 1456 1457 1458 1459 1460 1461 1456 for {set i 1} { $i <= $levels } {incr i} { 1457 set x [expr {double($i)/($levels+1)}] 1458 set m [Rappture::IsoMarker \#auto $c $this $tf] 1459 $m relval $x 1460 lappend _isomarkers($tf) $m 1461 } 1462 1462 } else { 1463 1464 1465 1466 1467 1463 foreach x $levels { 1464 set m [Rappture::IsoMarker \#auto $c $this $tf] 1465 $m relval $x 1466 lappend _isomarkers($tf) $m 1467 } 1468 1468 } 1469 1469 } … … 1485 1485 regsub -all "," $markers " " markers 1486 1486 foreach marker $markers { 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1487 set n [scan $marker "%g%s" value suffix] 1488 if { $n == 2 && $suffix == "%" } { 1489 # ${n}% : Set relative value. 1490 set value [expr {$value * 0.01}] 1491 set m [Rappture::IsoMarker \#auto $c $this $tf] 1492 $m relval $value 1493 lappend _isomarkers($tf) $m 1494 } else { 1495 # ${n} : Set absolute value. 1496 set m [Rappture::IsoMarker \#auto $c $this $tf] 1497 $m absval $value 1498 lappend _isomarkers($tf) $m 1499 } 1500 1500 } 1501 1501 } … … 1510 1510 itcl::body Rappture::NanovisViewer::AddIsoMarker { x y } { 1511 1511 if { $_first == "" } { 1512 1512 error "active transfer function isn't set" 1513 1513 } 1514 1514 set vol [lindex [CurrentVolumes] 0] … … 1527 1527 set bool 0 1528 1528 if { [info exists _isomarkers($tf)] } { 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1529 set list {} 1530 set marker [namespace tail $marker] 1531 foreach m $_isomarkers($tf) { 1532 set sx [$m screenpos] 1533 if { $m != $marker } { 1534 if { $x >= ($sx-3) && $x <= ($sx+3) } { 1535 $marker relval [$m relval] 1536 itcl::delete object $m 1537 bell 1538 set bool 1 1539 continue 1540 } 1541 } 1542 lappend list $m 1543 } 1544 set _isomarkers($tf) $list 1545 updatetransferfuncs 1546 1546 } 1547 1547 return $bool … … 1551 1551 set tf [$marker transferfunc] 1552 1552 if { [info exists _isomarkers($tf)] } { 1553 1554 1555 1556 1557 1558 1559 1560 1553 set marker [namespace tail $marker] 1554 foreach m $_isomarkers($tf) { 1555 set sx [$m screenpos] 1556 if { $m != $marker } { 1557 set bool [expr { $x >= ($sx-3) && $x <= ($sx+3) }] 1558 $m activate $bool 1559 } 1560 } 1561 1561 } 1562 1562 return "" … … 1567 1567 set _limits(max) 1.0 1568 1568 if { ![info exists _style2vols($tf)] } { 1569 1569 return [array get _limits] 1570 1570 } 1571 1571 set min ""; set max "" 1572 1572 foreach vol $_style2vols($tf) { 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1573 if { ![info exists _serverVols($vol)] } { 1574 continue 1575 } 1576 if { ![info exists _limits($vol-min)] } { 1577 continue 1578 } 1579 if { $min == "" || $min > $_limits($vol-min) } { 1580 set min $_limits($vol-min) 1581 } 1582 if { $max == "" || $max < $_limits($vol-max) } { 1583 set max $_limits($vol-max) 1584 } 1585 1585 } 1586 1586 if { $min != "" } { 1587 1587 set _limits(min) $min 1588 1588 } 1589 1589 if { $max != "" } { 1590 1590 set _limits(max) $max 1591 1591 } 1592 1592 return [array get _limits] … … 1596 1596 itcl::body Rappture::NanovisViewer::BuildViewTab {} { 1597 1597 foreach { key value } { 1598 grid01599 axes11600 outline11601 volume11602 legend11603 particles11604 lic11598 grid 0 1599 axes 1 1600 outline 1 1601 volume 1 1602 legend 1 1603 particles 1 1604 lic 1 1605 1605 } { 1606 1606 set _settings($this-$key) $value 1607 1607 } 1608 1608 … … 1620 1620 -variable [itcl::scope _settings($this-isosurface)] \ 1621 1621 -command [itcl::code $this FixSettings isosurface] \ 1622 1622 -font "Arial 9" 1623 1623 1624 1624 checkbutton $inner.axes \ … … 1626 1626 -variable [itcl::scope _settings($this-axes)] \ 1627 1627 -command [itcl::code $this FixSettings axes] \ 1628 1628 -font "Arial 9" 1629 1629 1630 1630 checkbutton $inner.grid \ … … 1632 1632 -variable [itcl::scope _settings($this-grid)] \ 1633 1633 -command [itcl::code $this FixSettings grid] \ 1634 1634 -font "Arial 9" 1635 1635 1636 1636 checkbutton $inner.outline \ … … 1638 1638 -variable [itcl::scope _settings($this-outline)] \ 1639 1639 -command [itcl::code $this FixSettings outline] \ 1640 1640 -font "Arial 9" 1641 1641 1642 1642 checkbutton $inner.legend \ … … 1644 1644 -variable [itcl::scope _settings($this-legend)] \ 1645 1645 -command [itcl::code $this FixSettings legend] \ 1646 1646 -font "Arial 9" 1647 1647 1648 1648 checkbutton $inner.volume \ … … 1650 1650 -variable [itcl::scope _settings($this-volume)] \ 1651 1651 -command [itcl::code $this FixSettings volume] \ 1652 1652 -font "Arial 9" 1653 1653 1654 1654 blt::table $inner \ 1655 1656 1657 1658 1659 1655 0,0 $inner.axes -columnspan 2 -anchor w \ 1656 1,0 $inner.grid -columnspan 2 -anchor w \ 1657 2,0 $inner.outline -columnspan 2 -anchor w \ 1658 3,0 $inner.volume -columnspan 2 -anchor w \ 1659 4,0 $inner.legend -columnspan 2 -anchor w 1660 1660 1661 1661 if 0 { … … 1668 1668 itcl::body Rappture::NanovisViewer::BuildVolumeTab {} { 1669 1669 foreach { key value } { 1670 light401671 transp501672 opacity1001673 thickness3501670 light 40 1671 transp 50 1672 opacity 100 1673 thickness 350 1674 1674 } { 1675 1675 set _settings($this-$key) $value 1676 1676 } 1677 1677 … … 1692 1692 ::scale $inner.light -from 0 -to 100 -orient horizontal \ 1693 1693 -variable [itcl::scope _settings($this-light)] \ 1694 1694 -width 10 \ 1695 1695 -showvalue off -command [itcl::code $this FixSettings light] 1696 1696 label $inner.bright -text "Bright" -font $fg … … 1699 1699 ::scale $inner.transp -from 0 -to 100 -orient horizontal \ 1700 1700 -variable [itcl::scope _settings($this-transp)] \ 1701 1701 -width 10 \ 1702 1702 -showvalue off -command [itcl::code $this FixSettings transp] 1703 1703 label $inner.plastic -text "Plastic" -font $fg … … 1706 1706 ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ 1707 1707 -variable [itcl::scope _settings($this-opacity)] \ 1708 1708 -width 10 \ 1709 1709 -showvalue off -command [itcl::code $this FixSettings opacity] 1710 1710 label $inner.opaque -text "Opaque" -font $fg … … 1713 1713 ::scale $inner.thickness -from 0 -to 1000 -orient horizontal \ 1714 1714 -variable [itcl::scope _settings($this-thickness)] \ 1715 1715 -width 10 \ 1716 1716 -showvalue off -command [itcl::code $this FixSettings thickness] 1717 1717 label $inner.thick -text "Thick" -font $fg 1718 1718 1719 1719 blt::table $inner \ 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1720 0,0 $inner.vol -columnspan 4 -anchor w -pady 2 \ 1721 1,0 $inner.shading -columnspan 4 -anchor w -pady {10 2} \ 1722 2,0 $inner.dim -anchor e -pady 2 \ 1723 2,1 $inner.light -columnspan 2 -pady 2 -fill x \ 1724 2,3 $inner.bright -anchor w -pady 2 \ 1725 3,0 $inner.fog -anchor e -pady 2 \ 1726 3,1 $inner.transp -columnspan 2 -pady 2 -fill x \ 1727 3,3 $inner.plastic -anchor w -pady 2 \ 1728 4,0 $inner.clear -anchor e -pady 2 \ 1729 4,1 $inner.opacity -columnspan 2 -pady 2 -fill x\ 1730 4,3 $inner.opaque -anchor w -pady 2 \ 1731 5,0 $inner.thin -anchor e -pady 2 \ 1732 5,1 $inner.thickness -columnspan 2 -pady 2 -fill x\ 1733 5,3 $inner.thick -anchor w -pady 2 1734 1734 1735 1735 blt::table configure $inner c0 c1 c3 r* -resize none … … 1746 1746 itk_component add xCutButton { 1747 1747 Rappture::PushButton $inner.xbutton \ 1748 1749 1750 1751 1748 -onimage [Rappture::icon x-cutplane] \ 1749 -offimage [Rappture::icon x-cutplane] \ 1750 -command [itcl::code $this FixSettings xcutplane] \ 1751 -variable [itcl::scope _settings($this-xcutplane)] 1752 1752 } 1753 1753 Rappture::Tooltip::for $itk_component(xCutButton) \ … … 1759 1759 -borderwidth 1 -highlightthickness 0 \ 1760 1760 -command [itcl::code $this Slice move x] \ 1761 1761 -variable [itcl::scope _settings($this-xcutposition)] 1762 1762 } { 1763 1763 usual … … 1773 1773 itk_component add yCutButton { 1774 1774 Rappture::PushButton $inner.ybutton \ 1775 1776 1777 1778 1775 -onimage [Rappture::icon y-cutplane] \ 1776 -offimage [Rappture::icon y-cutplane] \ 1777 -command [itcl::code $this FixSettings ycutplane] \ 1778 -variable [itcl::scope _settings($this-ycutplane)] 1779 1779 } 1780 1780 Rappture::Tooltip::for $itk_component(yCutButton) \ … … 1786 1786 -borderwidth 1 -highlightthickness 0 \ 1787 1787 -command [itcl::code $this Slice move y] \ 1788 1788 -variable [itcl::scope _settings($this-ycutposition)] 1789 1789 } { 1790 1790 usual … … 1800 1800 itk_component add zCutButton { 1801 1801 Rappture::PushButton $inner.zbutton \ 1802 1803 1804 1805 1802 -onimage [Rappture::icon z-cutplane] \ 1803 -offimage [Rappture::icon z-cutplane] \ 1804 -command [itcl::code $this FixSettings zcutplane] \ 1805 -variable [itcl::scope _settings($this-zcutplane)] 1806 1806 } 1807 1807 Rappture::Tooltip::for $itk_component(zCutButton) \ … … 1813 1813 -borderwidth 1 -highlightthickness 0 \ 1814 1814 -command [itcl::code $this Slice move z] \ 1815 1815 -variable [itcl::scope _settings($this-zcutposition)] 1816 1816 } { 1817 1817 usual … … 1825 1825 1826 1826 blt::table $inner \ 1827 1828 1829 1830 1831 1832 1827 1,1 $itk_component(xCutButton) \ 1828 1,2 $itk_component(yCutButton) \ 1829 1,3 $itk_component(zCutButton) \ 1830 0,1 $itk_component(xCutScale) \ 1831 0,2 $itk_component(yCutScale) \ 1832 0,3 $itk_component(zCutScale) \ 1833 1833 1834 1834 blt::table configure $inner r0 r1 c* -resize none … … 1847 1847 set row 0 1848 1848 foreach tag $labels { 1849 1850 1851 1852 1853 1854 1855 1856 1849 label $inner.${tag}label -text $tag -font "Arial 9" 1850 entry $inner.${tag} -font "Arial 9" -bg white \ 1851 -textvariable [itcl::scope _settings($this-$tag)] 1852 bind $inner.${tag} <KeyPress-Return> \ 1853 [itcl::code $this camera set ${tag}] 1854 blt::table $inner \ 1855 $row,0 $inner.${tag}label -anchor e -pady 2 \ 1856 $row,1 $inner.${tag} -anchor w -pady 2 1857 1857 blt::table configure $inner r$row -resize none 1858 1858 incr row 1859 1859 } 1860 1860 blt::table configure $inner c0 c1 -resize none … … 1915 1915 set _height $h 1916 1916 if { !$_resizePending } { 1917 1918 1917 $_dispatcher event -idle !resize 1918 set _resizePending 1 1919 1919 } 1920 1920 } … … 1922 1922 itcl::body Rappture::NanovisViewer::EventuallyResizeLegend {} { 1923 1923 if { !$_resizeLegendPending } { 1924 1925 1924 $_dispatcher event -idle !legend 1925 set _resizeLegendPending 1 1926 1926 } 1927 1927 } … … 1932 1932 itcl::body Rappture::NanovisViewer::camera {option args} { 1933 1933 switch -- $option { 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1934 "show" { 1935 puts [array get _view] 1936 } 1937 "set" { 1938 set who [lindex $args 0] 1939 set x $_settings($this-$who) 1940 set code [catch { string is double $x } result] 1941 if { $code != 0 || !$result } { 1942 set _settings($this-$who) $_view($who) 1943 return 1944 } 1945 switch -- $who { 1946 "pan-x" - "pan-y" { 1947 set _view($who) $_settings($this-$who) 1948 PanCamera 1949 } 1950 "phi" - "theta" - "psi" { 1951 set _view($who) $_settings($this-$who) 1952 set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)] 1953 SendCmd "camera angle $xyz" 1954 } 1955 "zoom" { 1956 set _view($who) $_settings($this-$who) 1957 SendCmd "camera zoom $_view(zoom)" 1958 } 1959 } 1960 } 1961 1961 } 1962 1962 } … … 1965 1965 set flowobj "" 1966 1966 foreach key [array names _obj2flow] { 1967 1968 1967 set flowobj $_obj2flow($key) 1968 break 1969 1969 } 1970 1970 if { $flowobj == "" } { 1971 1971 return 1972 1972 } 1973 1973 if { [winfo exists $w.frame] } { 1974 1974 destroy $w.frame 1975 1975 } 1976 1976 set inner [frame $w.frame] 1977 1977 blt::table $w \ 1978 1978 5,0 $inner -fill both -columnspan 2 -anchor nw 1979 1979 array set hints [$dataobj hints] 1980 1980 1981 1981 label $inner.volumes -text "Volumes" -font "Arial 9 bold" 1982 1982 blt::table $inner \ 1983 1983 1,0 $inner.volumes -anchor w \ 1984 1984 blt::table configure $inner c0 c1 -resize none 1985 1985 blt::table configure $inner c2 -resize expand … … 1988 1988 set volumes [get] 1989 1989 if { [llength $volumes] > 0 } { 1990 1991 1990 blt::table $inner $row,0 $inner.volumes -anchor w 1991 incr row 1992 1992 } 1993 1993 foreach vol $volumes { 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 1994 array unset info 1995 array set info $vol 1996 set name $info(name) 1997 if { ![info exists _settings($this-volume-$name)] } { 1998 set _settings($this-volume-$name) $info(hide) 1999 } 2000 checkbutton $inner.vol$row -text $info(label) \ 2001 -variable [itcl::scope _settings($this-volume-$name)] \ 2002 -onvalue 0 -offvalue 1 \ 2003 -command [itcl::code $this volume $key $name] \ 2004 -font "Arial 9" 2005 Rappture::Tooltip::for $inner.vol$row $info(description) 2006 blt::table $inner $row,0 $inner.vol$row -anchor w 2007 if { !$_settings($this-volume-$name) } { 2008 $inner.vol$row select 2009 } 2010 incr row 2011 2011 } 2012 2012 blt::table configure $inner r* -resize none
Note: See TracChangeset
for help on using the changeset viewer.