Changeset 907
- Timestamp:
- Feb 26, 2008, 7:18:06 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/nanovisviewer.tcl
r904 r907 1 1 2 # ---------------------------------------------------------------------- 2 3 # COMPONENT: nanovisviewer - 3D volume rendering … … 28 29 -*-helvetica-medium-r-normal-*-12-* widgetDefault 29 30 31 # must use this name -- plugs into Rappture::resources::load 32 proc NanovisViewer_init_resources {} { 33 Rappture::resources::register \ 34 nanovis_server [list Rappture::VisViewer::SetServerList "nanovis" ] 35 } 36 30 37 itcl::class Rappture::NanovisViewer { 31 inherit itk::Widget32 38 inherit Rappture::VisViewer 39 33 40 itk_option define -plotforeground plotForeground Foreground "" 34 41 itk_option define -plotbackground plotBackground Background "" 35 42 itk_option define -plotoutline plotOutline PlotOutline "" 36 itk_option define -sendcommand sendCommand SendCommand "" 37 itk_option define -receivecommand receiveCommand ReceiveCommand "" 38 39 constructor {hostlist args} { # defined below } 40 destructor { # defined below } 41 43 44 constructor { hostlist args } { 45 Rappture::VisViewer::constructor $hostlist 46 } { 47 # defined below 48 } 49 destructor { 50 # defined below 51 } 42 52 public method add {dataobj {settings ""}} 43 53 public method get {args} … … 48 58 } 49 59 public method download {option args} 50 public method parameters {title args} { # do nothing }51 public method connect {{hostlist ""}} 52 public method disconnect {}60 public method parameters {title args} { 61 # do nothing 62 } 53 63 public method isconnected {} 54 64 55 protected method _send {args} 56 protected method _send_text {string} 65 protected method Connect {} 66 protected method Disconnect {} 67 protected method _send {string} 57 68 protected method _send_dataobjs {} 58 69 protected method _send_transfuncs {} 59 protected method _send_echo {channel {data ""}} 60 protected method _receive {} 70 61 71 protected method _receive_image {option size} 62 72 protected method _receive_legend {ivol vmin vmax size} 63 73 protected method _receive_data {args} 64 protected method _receive_echo {channel {data ""}}65 74 66 75 protected method _rebuild {} … … 76 85 protected method _fixSettings {what {value ""}} 77 86 protected method _fixLegend {} 78 protected method _serverDown {} 79 protected method _genTransfuncData {dataobj comp} 80 public method update_transfer_function {} 81 public method remove_duplicate_isomarker { m x } 82 public method over_isomarker { m x } 83 public method _addIsoMarker { x y } 84 protected method _initIsoMarkers {dataobj comp} 85 protected method _hideIsoMarkers {dataobj} 86 protected method _showIsoMarkers {dataobj} 87 protected method _color2rgb {color} 88 protected method _euler2xyz {theta phi psi} 89 90 private variable _dispatcher "" ;# dispatcher for !events 91 92 private variable _nvhosts "" ;# list of hosts for nanovis server 93 private variable _sid "" ;# socket connection to nanovis server 94 private variable _parser "" ;# interpreter for incoming commands 95 private variable _buffer ;# buffer for incoming/outgoing commands 96 private variable _image ;# image displayed in plotting area 87 protected method GenTransfuncData {dataobj comp} 88 protected method UpdateTransferFunction {} 89 protected method RemoveDuplicateIsoMarker { m x } 90 protected method OverIsoMarker { m x } 91 protected method AddIsoMarker { x y } 92 protected method InitIsoMarkers {dataobj comp} 93 protected method HideIsoMarkers {dataobj} 94 protected method ShowIsoMarkers {dataobj} 95 96 private variable _outbuf ;# buffer for outgoing commands 97 97 98 98 private variable _dlist "" ;# list of data objects … … 112 112 private variable _limits ;# autoscale min/max for all axes 113 113 private variable _view ;# view params for 3D view 114 114 115 115 private variable _isomarkers ;# array of isosurface level values 0..1 116 116 private common _isosurface ;# indicates to use isosurface shading … … 122 122 } 123 123 124 itcl::class Rappture::NanovisViewer::IsoMarker {125 private variable _value ""; # Absolute value of marker.126 private variable _label ""127 private variable _tick ""128 private variable _canvas ""129 private variable _nvobj ""130 private common _normalIcon [Rappture::icon nvlegendmark]131 private common _activeIcon [Rappture::icon nvlegendmark2]132 private variable _active_motion 0133 private variable _active_press 0134 135 constructor {c obj args} {136 set _canvas $c137 set _nvobj $obj138 139 set w [winfo width $_canvas]140 set h [winfo height $_canvas]141 set _tick [$c create image 0 $h \142 -image $_normalIcon -anchor s \143 -tags "$this $obj" -state hidden]144 set _label [$c create text 0 $h \145 -anchor n -fill white -font "Helvetica 6" \146 -tags "$this $obj" -state hidden]147 $c bind $_tick <Enter> [itcl::code $this handle_event "enter"]148 $c bind $_tick <Leave> [itcl::code $this handle_event "leave"]149 $c bind $_tick <ButtonPress-1> \150 [itcl::code $this handle_event "start" %x %y]151 $c bind $_tick <B1-Motion> \152 [itcl::code $this handle_event "update" %x %y]153 $c bind $_tick <ButtonRelease-1> \154 [itcl::code $this handle_event "end" %x %y]155 }156 destructor {157 $_canvas delete $this158 }159 160 public method get_absolute_value {} {161 return $_value162 }163 public method get_relative_value {} {164 array set limits [$_nvobj get_limits]165 if { $limits(vmax) == $limits(vmin) } {166 set limits(vmin) 0.0167 set limits(vmax) 1.0168 }169 return [expr {($_value-$limits(vmin))/($limits(vmax) - $limits(vmin))}]170 }171 public method activate { bool } {172 if { $bool || $_active_press || $_active_motion } {173 $_canvas itemconfigure $_label -state normal174 $_canvas itemconfigure $_tick -image $_activeIcon175 } else {176 $_canvas itemconfigure $_label -state hidden177 $_canvas itemconfigure $_tick -image $_normalIcon178 }179 }180 public method show {} {181 set_absolute_value $_value182 $_canvas itemconfigure $_tick -state normal183 $_canvas raise $_tick184 }185 public method hide {} {186 $_canvas itemconfigure $_tick -state hidden187 }188 public method get_screen_position { } {189 set x [get_relative_value]190 if { $x < 0.0 } {191 set x 0.0192 } elseif { $x > 1.0 } {193 set x 1.0194 }195 set low 10196 set w [winfo width $_canvas]197 set high [expr {$w - 10}]198 set x [expr {round($x*($high - $low) + $low)}]199 return $x200 }201 public method set_absolute_value { x } {202 set _value $x203 set y 31204 $_canvas itemconfigure $_label -text [format %.4g $_value]205 set x [get_screen_position]206 $_canvas coords $_tick $x [expr {$y+3}]207 $_canvas coords $_label $x [expr {$y+5}]208 }209 public method set_relative_value { x } {210 array set limits [$_nvobj get_limits]211 if { $limits(vmax) == $limits(vmin) } {212 set limits(vmin) 0.0213 set limits(vmax) 1.0214 }215 set r [expr $limits(vmax) - $limits(vmin)]216 set_absolute_value [expr {($x * $r) + $limits(vmin)}]217 }218 public method handle_event { option args } {219 switch -- $option {220 enter {221 set _active_motion 1222 activate yes223 $_canvas raise $_tick224 }225 leave {226 set _active_motion 0227 activate no228 }229 start {230 $_canvas raise $_tick231 set _active_press 1232 activate yes233 }234 update {235 set w [winfo width $_canvas]236 set x [lindex $args 0]237 set_relative_value [expr {double($x-10)/($w-20)}]238 $_nvobj over_isomarker $this $x239 $_nvobj update_transfer_function240 }241 end {242 set x [lindex $args 0]243 if { ![$_nvobj remove_duplicate_isomarker $this $x]} {244 eval handle_event update $args245 }246 set _active_press 0247 activate no248 }249 default {250 error "bad option \"$option\": should be start, update, end"251 }252 }253 }254 }255 256 124 # ---------------------------------------------------------------------- 257 125 # CONSTRUCTOR 258 126 # ---------------------------------------------------------------------- 259 127 itcl::body Rappture::NanovisViewer::constructor {hostlist args} { 260 Rappture::dispatcher _dispatcher 128 129 # Draw legend event 261 130 $_dispatcher register !legend 262 131 $_dispatcher dispatch $this !legend "[itcl::code $this _fixLegend]; list" 263 $_dispatcher register !serverDown 264 $_dispatcher dispatch $this !serverDown "[itcl::code $this _serverDown]; list" 265 266 set _buffer(in) "" 267 set _buffer(out) "" 268 269 # 270 # Create a parser to handle incoming requests 271 # 272 set _parser [interp create -safe] 273 foreach cmd [$_parser eval {info commands}] { 274 $_parser hide $cmd 275 } 132 # Send dataobjs event 133 $_dispatcher register !send_dataobjs 134 $_dispatcher dispatch $this !send_dataobjs \ 135 "[itcl::code $this _send_dataobjs]; list" 136 # Send transfer functions event 137 $_dispatcher register !send_transfuncs 138 $_dispatcher dispatch $this !send_transfuncs \ 139 "[itcl::code $this _send_transfuncs]; list" 140 # Rebuild event 141 $_dispatcher register !rebuild 142 $_dispatcher dispatch $this !rebuild "[itcl::code $this _rebuild]; list" 143 144 set _outbuf "" 145 146 # 147 # Populate parser with commands handle incoming requests 148 # 276 149 $_parser alias image [itcl::code $this _receive_image] 277 150 $_parser alias legend [itcl::code $this _receive_legend] 278 151 $_parser alias data [itcl::code $this _receive_data] 279 280 #281 # Set up the widgets in the main body282 #283 option add hull.width hull.height284 pack propagate $itk_component(hull) no285 152 286 153 set _view(theta) 45 … … 296 163 set _limits(vmax) 1.0 297 164 298 itk_component add controls {299 frame $itk_interior.cntls300 } {301 usual302 rename -background -controlbackground controlBackground Background303 }304 pack $itk_component(controls) -side right -fill y305 306 165 itk_component add zoom { 307 166 frame $itk_component(controls).zoom … … 556 415 557 416 558 # 559 # RENDERING AREA 560 # 561 itk_component add area { 562 frame $itk_interior.area 563 } 564 pack $itk_component(area) -expand yes -fill both 417 # Legend 565 418 566 419 set _image(legend) [image create photo] … … 575 428 bind $itk_component(legend) <Configure> \ 576 429 [list $_dispatcher event -idle !legend] 577 578 set _image(plot) [image create photo]579 itk_component add 3dview {580 label $itk_component(area).vol -image $_image(plot) \581 -highlightthickness 0582 } {583 usual584 ignore -highlightthickness585 rename -background -plotbackground plotBackground Background586 }587 pack $itk_component(3dview) -expand yes -fill both588 430 589 431 # set up bindings for rotation … … 595 437 [itcl::code $this _move release %x %y] 596 438 bind $itk_component(3dview) <Configure> \ 597 [itcl::code $this _send screen %w %h]439 [itcl::code $this _send "screen %w %h"] 598 440 599 441 set _image(download) [image create photo] … … 601 443 eval itk_initialize $args 602 444 603 connect $hostlist445 Connect 604 446 } 605 447 … … 610 452 set _sendobjs "" ;# stop any send in progress 611 453 set _sendobjs2 "" ;# stop any send in progress 612 after cancel [itcl::code $this _send_dataobjs] 613 after cancel [itcl::code $this _rebuild] 454 $_dispatcher cancel !rebuild 455 $_dispatcher cancel !send_dataobjs 456 $_dispatcher cancel !send_transfuncs 614 457 image delete $_image(plot) 615 458 image delete $_image(legend) 616 459 image delete $_image(download) 617 interp delete $_parser618 460 } 619 461 … … 654 496 set _obj2ovride($dataobj-raise) $params(-raise) 655 497 656 after cancel [itcl::code $this _rebuild] 657 after idle [itcl::code $this _rebuild] 498 $_dispatcher event -idle !rebuild 658 499 } 659 500 } … … 736 577 # if anything changed, then rebuild the plot 737 578 if {$changed} { 738 after cancel [itcl::code $this _rebuild] 739 after idle [itcl::code $this _rebuild] 579 $_dispatcher event -idle !rebuild 740 580 } 741 581 } … … 818 658 819 659 # ---------------------------------------------------------------------- 820 # USAGE: connect ?<host:port>,<host:port>...?660 # USAGE: Connect ?<host:port>,<host:port>...? 821 661 # 822 662 # Clients use this method to establish a connection to a new … … 824 664 # Any existing connection is automatically closed. 825 665 # ---------------------------------------------------------------------- 826 itcl::body Rappture::NanovisViewer::connect {{hostlist ""}} { 827 disconnect 828 829 if {"" != $hostlist} { set _nvhosts $hostlist } 830 831 if {"" == $_nvhosts} { 666 itcl::body Rappture::NanovisViewer::Connect {} { 667 Disconnect 668 set _hosts [GetServerList "nanovis"] 669 if { "" == $_hosts } { 832 670 return 0 833 671 } 834 835 blt::busy hold $itk_component(hull); update idletasks 836 837 # HACK ALERT! punt on this for now 838 set memorySize 10000 839 840 # 841 # Connect to the nanovis server. Send the server some estimate 842 # of the size of our job. If it's too busy, that server may 843 # forward us to another. 844 # 845 set try [split $_nvhosts ,] 846 foreach {hostname port} [split [lindex $try 0] :] break 847 set try [lrange $try 1 end] 848 849 while {1} { 850 _send_echo <<line "connecting to $hostname:$port..." 851 if {[catch {socket $hostname $port} sid]} { 852 if {[llength $try] == 0} { 853 return 0 854 } 855 foreach {hostname port} [split [lindex $try 0] :] break 856 set try [lrange $try 1 end] 857 continue 858 } 859 fconfigure $sid -translation binary -encoding binary 860 861 # send memory requirement to the load balancer 862 puts -nonewline $sid [binary format I $memorySize] 863 flush $sid 864 865 # read back a reconnection order 866 set data [read $sid 4] 867 if {[binary scan $data cccc b1 b2 b3 b4] != 4} { 868 error "couldn't read redirection request" 869 } 870 set addr [format "%u.%u.%u.%u" \ 871 [expr {$b1 & 0xff}] \ 872 [expr {$b2 & 0xff}] \ 873 [expr {$b3 & 0xff}] \ 874 [expr {$b4 & 0xff}]] 875 _receive_echo <<line $addr 876 877 if {[string equal $addr "0.0.0.0"]} { 878 fconfigure $sid -buffering line 879 fileevent $sid readable [itcl::code $this _receive] 880 set _sid $sid 881 blt::busy release $itk_component(hull) 882 return 1 883 } 884 set hostname $addr 885 } 886 blt::busy release $itk_component(hull) 887 888 return 0 889 } 890 891 # ---------------------------------------------------------------------- 892 # USAGE: disconnect 672 set result [VisViewer::Connect $_hosts] 673 return $result 674 } 675 676 # ---------------------------------------------------------------------- 677 # USAGE: isconnected ?<host:port>,<host:port>...? 678 # 679 # Clients use this method to establish a connection to a new 680 # server, or to reestablish a connection to the previous server. 681 # Any existing connection is automatically closed. 682 # ---------------------------------------------------------------------- 683 itcl::body Rappture::NanovisViewer::isconnected {} { 684 return [VisViewer::IsConnected] 685 } 686 687 # ---------------------------------------------------------------------- 688 # USAGE: Disconnect 893 689 # 894 690 # Clients use this method to disconnect from the current rendering 895 691 # server. 896 692 # ---------------------------------------------------------------------- 897 itcl::body Rappture::NanovisViewer::disconnect {} { 898 if {"" != $_sid} { 899 catch {close $_sid} 900 set _sid "" 901 } 902 903 set _buffer(in) "" 904 set _buffer(out) "" 693 itcl::body Rappture::NanovisViewer::Disconnect {} { 694 VisViewer::Disconnect 905 695 906 696 # disconnected -- no more data sitting on server 697 set _outbuf "" 907 698 catch {unset _obj2id} 908 699 array unset _id2obj … … 914 705 915 706 # ---------------------------------------------------------------------- 916 # USAGE: isconnected 917 # 918 # Clients use this method to see if we are currently connected to 919 # a server. 920 # ---------------------------------------------------------------------- 921 itcl::body Rappture::NanovisViewer::isconnected {} { 922 return [expr {"" != $_sid}] 923 } 924 925 # ---------------------------------------------------------------------- 926 # USAGE: _send <arg> <arg> ... 707 # USAGE: _send <string> 927 708 # 928 709 # Used internally to send commands off to the rendering server. 929 # This is a more convenient form of _send_text, which actually 930 # does the sending. 931 # ---------------------------------------------------------------------- 932 itcl::body Rappture::NanovisViewer::_send {args} { 933 _send_text $args 934 } 935 936 # ---------------------------------------------------------------------- 937 # USAGE: _send_text <string> 938 # 939 # Used internally to send commands off to the rendering server. 940 # ---------------------------------------------------------------------- 941 itcl::body Rappture::NanovisViewer::_send_text {string} { 942 if {"" == $_sid} { 710 # ---------------------------------------------------------------------- 711 itcl::body Rappture::NanovisViewer::_send {string} { 712 if { ![isconnected]} { 943 713 $_dispatcher cancel !serverDown 944 714 set x [expr {[winfo rootx $itk_component(area)]+10}] … … 946 716 Rappture::Tooltip::cue @$x,$y "Connecting..." 947 717 948 if {[catch {connect} ok] == 0 && $ok} { 718 set code [catch { Connect } ok] 719 if { $code == 0 && $ok} { 949 720 set w [winfo width $itk_component(3dview)] 950 721 set h [winfo height $itk_component(3dview)] 951 722 952 if {[catch {puts $_sid "screen $w $h"}]} { 953 disconnect 954 _receive_echo closed 955 $_dispatcher event -after 750 !serverDown 956 } else { 957 _send_echo >>line "screen $w $h" 958 723 if { [Send "screen $w $h"] } { 959 724 set _view(theta) 45 960 725 set _view(phi) 45 961 726 set _view(psi) 0 962 727 set _view(zoom) 1.0 963 after idle [itcl::code $this _rebuild] 728 $_dispatcher event -idle !rebuild 964 729 Rappture::Tooltip::cue hide 965 730 } 966 return 967 } 968 Rappture::Tooltip::cue @$x,$y "Can't connect to visualization server. This may be a network problem. Wait a few moments and try resetting the view." 969 return 970 } 971 if {"" != $_sid} { 972 # if we're transmitting objects, then buffer this command 731 } else { 732 Rappture::Tooltip::cue @$x,$y "Can't connect to visualization server. This may be a network problem. Wait a few moments and try resetting the view." 733 } 734 } else { 735 # If we're transmitting objects, then buffer this command. 973 736 if {[llength $_sendobjs] > 0} { 974 append _ buffer(out)$string "\n"737 append _outbuf $string "\n" 975 738 } else { 976 if {[catch {puts $_sid $string}]} { 977 disconnect 978 _receive_echo closed 979 $_dispatcher event -after 750 !serverDown 980 } else { 739 if { [Send $string] } { 981 740 foreach line [split $string \n] { 982 _send_echo >>line $line741 SendEcho >>line $line 983 742 } 984 743 } … … 1004 763 # tell the engine to expect some data 1005 764 set cmdstr "volume data follows [string length $data]" 1006 _send_echo >>line $cmdstr 1007 if {[catch {puts $_sid $cmdstr} err]} { 1008 disconnect 1009 $_dispatcher event -after 750 !serverDown 765 if { ![Send $cmdstr] } { 1010 766 return 1011 767 } 1012 1013 768 while {[string length $data] > 0} { 1014 769 update … … 1016 771 set chunk [string range $data 0 8095] 1017 772 set data [string range $data 8096 end] 1018 1019 _send_echo >>line $chunk 1020 if {[catch {puts -nonewline $_sid $chunk} err]} { 1021 disconnect 1022 $_dispatcher event -after 750 !serverDown 773 if { ![Send $chunk -nonewline] } { 1023 774 return 1024 775 } 1025 catch {flush $_sid} 1026 } 1027 _send_echo >>line "" 1028 puts $_sid "" 776 Flush 777 } 778 Send "" 1029 779 1030 780 set volId $_obj2id(count) … … 1044 794 set axis [$first hints updir] 1045 795 if {"" != $axis} { 1046 _send up $axis796 _send "up $axis" 1047 797 } 1048 798 } … … 1051 801 set vols [_currentVolumeIds -cutplanes] 1052 802 foreach axis {x y z} { 1053 eval _send cutplane state [_state ${axis}slice] $axis $vols803 _send "cutplane state [_state ${axis}slice] $axis $vols" 1054 804 set pos [expr {0.01*[$itk_component(${axis}slicer) get]}] 1055 eval _send cutplane position $pos $axis $vols1056 } 1057 eval _send volume data state [_state volume] $vols805 _send "cutplane position $pos $axis $vols" 806 } 807 _send "volume data state [_state volume] $vols" 1058 808 1059 809 # if there are any commands in the buffer, send them now that we're done 1060 _send_echo >>line $_buffer(out) 1061 if {[catch {puts $_sid $_buffer(out)} err]} { 1062 disconnect 1063 $_dispatcher event -after 750 !serverDown 1064 } 1065 set _buffer(out) "" 1066 1067 # $_dispatcher event -idle !legend 810 Send $_outbuf 811 set _outbuf "" 812 813 $_dispatcher event -idle !legend 1068 814 } 1069 815 … … 1080 826 # 1081 827 if { ![info exists _isomarkers($dataobj)] } { 1082 _initIsoMarkers $dataobj $comp828 InitIsoMarkers $dataobj $comp 1083 829 } else { 1084 _hideIsoMarkers $dataobj830 HideIsoMarkers $dataobj 1085 831 } 1086 foreach {sname cmap wmap} [ _genTransfuncData $dataobj $comp] break832 foreach {sname cmap wmap} [GenTransfuncData $dataobj $comp] break 1087 833 set cmdstr [list transfunc define $sname $cmap $wmap] 1088 _send_echo >>line $cmdstr 1089 if {[catch {puts $_sid $cmdstr} err]} { 1090 disconnect 1091 $_dispatcher event -after 750 !serverDown 834 if {![Send $cmdstr] } { 1092 835 return 1093 836 } … … 1102 845 foreach key [array names _obj2id *-*] { 1103 846 set state [string match $first-* $key] 1104 _send volume state $state $_obj2id($key)847 _send "volume state $state $_obj2id($key)" 1105 848 if {[info exists _obj2style($key)]} { 1106 _send volume shading transfunc $_obj2style($key) $_obj2id($key)1107 } 1108 } 1109 _showIsoMarkers $first849 _send "volume shading transfunc $_obj2style($key) $_obj2id($key)" 850 } 851 } 852 ShowIsoMarkers $first 1110 853 # if there are any commands in the buffer, send them now that we're done 1111 _send_echo >>line $_buffer(out) 1112 if {[catch {puts $_sid $_buffer(out)} err]} { 1113 disconnect 1114 $_dispatcher event -after 750 !serverDown 1115 } 1116 set _buffer(out) "" 854 Send $_outbuf 855 set _outbuf "" 1117 856 $_dispatcher event -idle !legend 1118 }1119 1120 # ----------------------------------------------------------------------1121 # USAGE: _send_echo <channel> ?<data>?1122 #1123 # Used internally to echo sent data to clients interested in1124 # this widget. If the -sendcommand option is set, then it is1125 # invoked in the global scope with the <channel> and <data> values1126 # as arguments. Otherwise, this does nothing.1127 # ----------------------------------------------------------------------1128 itcl::body Rappture::NanovisViewer::_send_echo {channel {data ""}} {1129 if {[string length $itk_option(-sendcommand)] > 0} {1130 uplevel #0 $itk_option(-sendcommand) [list $channel $data]1131 }1132 }1133 1134 # ----------------------------------------------------------------------1135 # USAGE: _receive1136 #1137 # Invoked automatically whenever a command is received from the1138 # rendering server. Reads the incoming command and executes it in1139 # a safe interpreter to handle the action.1140 # ----------------------------------------------------------------------1141 itcl::body Rappture::NanovisViewer::_receive {} {1142 if {"" != $_sid} {1143 if {[gets $_sid line] < 0} {1144 disconnect1145 _receive_echo closed1146 $_dispatcher event -after 750 !serverDown1147 } elseif {[string equal [string range $line 0 2] "nv>"]} {1148 _receive_echo <<line $line1149 append _buffer(in) [string range $line 3 end]1150 if {[info complete $_buffer(in)]} {1151 set request $_buffer(in)1152 set _buffer(in) ""1153 $_parser eval $request1154 }1155 } else {1156 # this shows errors coming back from the engine1157 _receive_echo <<error $line1158 puts stderr $line1159 }1160 }1161 857 } 1162 858 … … 1169 865 # ---------------------------------------------------------------------- 1170 866 itcl::body Rappture::NanovisViewer::_receive_image {option size} { 1171 if { "" != $_sid} {1172 set bytes [ read $_sid$size]867 if { [isconnected] } { 868 set bytes [Receive $size] 1173 869 $_image(plot) configure -data $bytes 1174 _receive_echo <<line "<read $size bytes for [image width $_image(plot)]x[image height $_image(plot)] image>"870 ReceiveEcho <<line "<read $size bytes for [image width $_image(plot)]x[image height $_image(plot)] image>" 1175 871 } 1176 872 } … … 1183 879 # specified <size> will follow. 1184 880 # ---------------------------------------------------------------------- 1185 itcl::body Rappture::NanovisViewer::_receive_legend { ivol vmin vmax size} {1186 if { "" != $_sid} {1187 set bytes [ read $_sid$size]881 itcl::body Rappture::NanovisViewer::_receive_legend { ivol vmin vmax size } { 882 if { [isconnected] } { 883 set bytes [Receive $size] 1188 884 $_image(legend) configure -data $bytes 1189 _receive_echo <<line "<read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"885 ReceiveEcho <<line "<read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>" 1190 886 1191 887 set c $itk_component(legend) … … 1201 897 $c lower transfunc 1202 898 $c bind transfunc <ButtonRelease-1> \ 1203 [itcl::code $this _addIsoMarker %x %y]899 [itcl::code $this AddIsoMarker %x %y] 1204 900 } 1205 901 $c itemconfigure vmin -text $vmin … … 1209 905 $c coords vmax [expr {$w-10}] [expr {$h-8}] 1210 906 set first [lindex [get] 0] 1211 _showIsoMarkers $first907 ShowIsoMarkers $first 1212 908 } 1213 909 } … … 1221 917 # ---------------------------------------------------------------------- 1222 918 itcl::body Rappture::NanovisViewer::_receive_data { args } { 1223 if { "" != $_sid} {919 if { [isconnected] } { 1224 920 array set info $args 1225 921 set volume $info(id) 1226 922 foreach { dataobj comp } $_id2obj($volume) break 1227 if { ![info exists _limits($dataobj-vmin] } { 923 924 if { ![info exists _limits($dataobj-vmin)] } { 1228 925 set _limits($dataobj-vmin) $info(min) 1229 926 set _limits($dataobj-vmax) $info(max) … … 1234 931 if { $_limits($dataobj-vmax) > $info(max) } { 1235 932 set _limits($dataobj-vmax) $info(max) 1236 } 1237 } 933 } 934 } 1238 935 set _limits(vmin) $info(vmin) 1239 936 set _limits(vmax) $info(vmax) … … 1241 938 unset _receiveids($info(id)) 1242 939 if { [array size _receiveids] == 0 } { 1243 after idle [itcl::code $this _send_transfuncs]940 $_dispatcher event -idle !send_transfuncs 1244 941 } 1245 }1246 }1247 1248 # ----------------------------------------------------------------------1249 # USAGE: _receive_echo <channel> ?<data>?1250 #1251 # Used internally to echo received data to clients interested in1252 # this widget. If the -receivecommand option is set, then it is1253 # invoked in the global scope with the <channel> and <data> values1254 # as arguments. Otherwise, this does nothing.1255 # ----------------------------------------------------------------------1256 itcl::body Rappture::NanovisViewer::_receive_echo {channel {data ""}} {1257 if {[string length $itk_option(-receivecommand)] > 0} {1258 uplevel #0 $itk_option(-receivecommand) [list $channel $data]1259 942 } 1260 943 } … … 1290 973 if {[llength $_sendobjs] > 0} { 1291 974 # send off new data objects 1292 after idle [itcl::code $this _send_dataobjs] 975 $_dispatcher event -idle !send_dataobjs 1293 976 } else { 1294 977 # nothing to send -- activate the proper volume … … 1297 980 set axis [$first hints updir] 1298 981 if {"" != $axis} { 1299 _send up $axis 1300 } 1301 } 1302 1303 _showIsoMarkers $first 1304 update_transfer_function 982 _send "up $axis" 983 } 984 } 985 ShowIsoMarkers $first 986 UpdateTransferFunction 1305 987 1306 988 # sync the state of slicers 1307 989 set vols [_currentVolumeIds -cutplanes] 1308 990 foreach axis {x y z} { 1309 eval _send cutplane state [_state ${axis}slice] $axis $vols991 _send "cutplane state [_state ${axis}slice] $axis $vols" 1310 992 set pos [expr {0.01*[$itk_component(${axis}slicer) get]}] 1311 eval _send cutplane position $pos $axis $vols1312 } 1313 eval _send volume data state [_state volume] $vols993 _send "cutplane position $pos $axis $vols" 994 } 995 _send "volume data state [_state volume] $vols" 1314 996 $_dispatcher event -idle !legend 1315 997 } … … 1318 1000 # Reset the camera and other view parameters 1319 1001 # 1320 eval _send camera angle [_euler2xyz $_view(theta) $_view(phi) $_view(psi)]1321 _send camera zoom $_view(zoom)1002 _send "camera angle [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)]" 1003 _send "camera zoom $_view(zoom)" 1322 1004 1323 1005 _fixSettings light … … 1328 1010 1329 1011 if {"" == $itk_option(-plotoutline)} { 1330 _send volume outline state off1012 _send "volume outline state off" 1331 1013 } else { 1332 _send volume outline state on 1333 _send volume outline color [_color2rgb $itk_option(-plotoutline)] 1334 } 1335 _send volume axis label x "" 1336 _send volume axis label y "" 1337 _send volume axis label z "" 1014 _send "volume outline state on" 1015 set rgb [Color2RGB $itk_option(-plotoutline)] 1016 _send "volume outline color $rgb" 1017 } 1018 _send "volume axis label x \"\"" 1019 _send "volume axis label y \"\"" 1020 _send "volume axis label z \"\"" 1338 1021 } 1339 1022 … … 1377 1060 in { 1378 1061 set _view(zoom) [expr {$_view(zoom)*1.25}] 1379 _send camera zoom $_view(zoom)1062 _send "camera zoom $_view(zoom)" 1380 1063 } 1381 1064 out { 1382 1065 set _view(zoom) [expr {$_view(zoom)*0.8}] 1383 _send camera zoom $_view(zoom)1066 _send "camera zoom $_view(zoom)" 1384 1067 } 1385 1068 reset { … … 1388 1071 set _view(psi) 0 1389 1072 set _view(zoom) 1.0 1390 eval _send camera angle [_euler2xyz $_view(theta) $_view(phi) $_view(psi)] 1391 _send camera zoom $_view(zoom) 1073 set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)] 1074 _send "camera angle $xyz" 1075 _send "camera zoom $_view(zoom)" 1392 1076 } 1393 1077 } … … 1455 1139 set _view(phi) $phi 1456 1140 set _view(psi) $psi 1457 eval _send camera angle [_euler2xyz$_view(theta) $_view(phi) $_view(psi)]1458 1141 set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)] 1142 _send "camera angle $xyz" 1459 1143 set _click(x) $x 1460 1144 set _click(y) $y … … 1496 1180 if {$current == "on"} { set op "off" } else { set op "on" } 1497 1181 } 1498 1499 1182 if {$op} { 1500 1183 $itk_component(${axis}slicer) configure -state normal 1501 eval _send cutplane state on $axis [_currentVolumeIds -cutplanes]1184 _send "cutplane state 1 $axis [_currentVolumeIds -cutplanes]" 1502 1185 $itk_component(${axis}slice) configure -relief sunken 1503 1186 } else { 1504 1187 $itk_component(${axis}slicer) configure -state disabled 1505 eval _send cutplane state off $axis [_currentVolumeIds -cutplanes]1188 _send "cutplane state 0 $axis [_currentVolumeIds -cutplanes]" 1506 1189 $itk_component(${axis}slice) configure -relief raised 1507 1190 } … … 1522 1205 #puts "readout: $axis = $newval" 1523 1206 1524 eval _send cutplane position $newpos $axis [_currentVolumeIds -cutplanes] 1207 set ids [_currentVolumeIds -cutplanes] 1208 _send "cutplane position $newpos $axis $ids" 1525 1209 } 1526 1210 volume { … … 1537 1221 1538 1222 if {$op} { 1539 eval _send volume data state on [_currentVolumeIds]1223 _send "volume data state on [_currentVolumeIds]" 1540 1224 $itk_component(volume) configure -relief sunken 1541 1225 } else { 1542 eval _send volume data state off [_currentVolumeIds]1226 _send "volume data state off [_currentVolumeIds]" 1543 1227 $itk_component(volume) configure -relief raised 1544 1228 } … … 1592 1276 set val [$inner.scales.light get] 1593 1277 set sval [expr {0.1*$val}] 1594 _send volume shading diffuse $sval1278 _send "volume shading diffuse $sval" 1595 1279 1596 1280 set sval [expr {sqrt($val+1.0)}] 1597 _send volume shading specular $sval1281 _send "volume shading specular $sval" 1598 1282 } 1599 1283 } … … 1602 1286 set val [$inner.scales.transp get] 1603 1287 set sval [expr {0.2*$val+1}] 1604 _send volume shading opacity $sval1288 _send "volume shading opacity $sval" 1605 1289 } 1606 1290 } … … 1612 1296 set sval [expr {0.01*double($val)}] 1613 1297 set _opacity($dataobj) $sval 1614 update_transfer_function1298 UpdateTransferFunction 1615 1299 } 1616 1300 } … … 1623 1307 # Scale values between 0.00001 and 0.01000 1624 1308 set sval [expr {0.00001*double($val)}] 1625 puts stderr "thickness($dataobj) = $sval"1626 1309 set _thickness($dataobj) $sval 1627 update_transfer_function1310 UpdateTransferFunction 1628 1311 } 1629 1312 } … … 1633 1316 set val $Rappture::NanovisViewer::_isosurface($this) 1634 1317 set dataobj [lindex [get] 0] 1635 _send "volume " "shading" "isosurface" $val1318 _send "volume shading isosurface $val" 1636 1319 } 1637 1320 } … … 1663 1346 } 1664 1347 if {$w > 0 && $h > 0 && "" != $ivol} { 1665 _send legend $ivol $w $h1348 _send "legend $ivol $w $h" 1666 1349 } else { 1667 1350 #$itk_component(legend) delete all … … 1670 1353 1671 1354 # ---------------------------------------------------------------------- 1672 # USAGE: _serverDown 1673 # 1674 # Used internally to let the user know when the connection to the 1675 # visualization server has been lost. Puts up a tip encouraging the 1676 # user to press any control to reconnect. 1677 # ---------------------------------------------------------------------- 1678 itcl::body Rappture::NanovisViewer::_serverDown {} { 1679 set x [expr {[winfo rootx $itk_component(area)]+10}] 1680 set y [expr {[winfo rooty $itk_component(area)]+10}] 1681 Rappture::Tooltip::cue @$x,$y "Lost connection to visualization server. This happens sometimes when there are too many users and the system runs out of memory.\n\nTo reconnect, reset the view or press any other control. Your picture should come right back up." 1682 } 1683 1684 # ---------------------------------------------------------------------- 1685 # USAGE: _genTransfuncData <dataobj> <comp> 1355 # USAGE: GenTransfuncData <dataobj> <comp> 1686 1356 # 1687 1357 # Used internally to compute the colormap and alpha map used to define … … 1689 1359 # Returns: name {v r g b ...} {v w ...} 1690 1360 # ---------------------------------------------------------------------- 1691 itcl::body Rappture::NanovisViewer:: _genTransfuncData {dataobj comp} {1361 itcl::body Rappture::NanovisViewer::GenTransfuncData {dataobj comp} { 1692 1362 array set style { 1693 1363 -color rainbow … … 1702 1372 } 1703 1373 set clist [split $style(-color) :] 1704 set cmap "0.0 [ _color2rgbwhite] "1374 set cmap "0.0 [Color2RGB white] " 1705 1375 for {set i 0} {$i < [llength $clist]} {incr i} { 1706 1376 set x [expr {double($i+1)/([llength $clist]+1)}] 1707 1377 set color [lindex $clist $i] 1708 append cmap "$x [ _color2rgb$color] "1709 } 1710 append cmap "1.0 [ _color2rgb$color]"1378 append cmap "$x [Color2RGB $color] " 1379 } 1380 append cmap "1.0 [Color2RGB $color]" 1711 1381 1712 1382 set max $style(-opacity) … … 1727 1397 set delta $_thickness($dataobj) 1728 1398 } 1729 puts stderr "delta=$delta thickness($dataobj)=$_thickness($dataobj)"1730 1399 set first [lindex $isovalues 0] 1731 1400 set last [lindex $isovalues end] … … 1764 1433 1765 1434 # ---------------------------------------------------------------------- 1766 # USAGE: _color2rgb <color>1767 #1768 # Used internally to convert a color name to a set of {r g b} values1769 # needed for the engine. Each r/g/b component is scaled in the1770 # range 0-1.1771 # ----------------------------------------------------------------------1772 itcl::body Rappture::NanovisViewer::_color2rgb {color} {1773 foreach {r g b} [winfo rgb $itk_component(hull) $color] break1774 set r [expr {$r/65535.0}]1775 set g [expr {$g/65535.0}]1776 set b [expr {$b/65535.0}]1777 return [list $r $g $b]1778 }1779 1780 # ----------------------------------------------------------------------1781 # USAGE: _euler2xyz <theta> <phi> <psi>1782 #1783 # Used internally to convert euler angles for the camera placement1784 # the to angles of rotation about the x/y/z axes, used by the engine.1785 # Returns a list: {xangle, yangle, zangle}.1786 # ----------------------------------------------------------------------1787 itcl::body Rappture::NanovisViewer::_euler2xyz {theta phi psi} {1788 set xangle [expr {$theta-90.0}]1789 set yangle [expr {180-$phi}]1790 set zangle $psi1791 return [list $xangle $yangle $zangle]1792 }1793 1794 # ----------------------------------------------------------------------1795 1435 # CONFIGURATION OPTION: -plotbackground 1796 1436 # ---------------------------------------------------------------------- 1797 1437 itcl::configbody Rappture::NanovisViewer::plotbackground { 1798 foreach {r g b} [_color2rgb $itk_option(-plotbackground)] break 1799 #fix this! 1800 #_send color background $r $g $b 1438 if { [isconnected] } { 1439 foreach {r g b} [Color2RGB $itk_option(-plotbackground)] break 1440 #fix this! 1441 #_send "color background $r $g $b" 1442 } 1801 1443 } 1802 1444 … … 1805 1447 # ---------------------------------------------------------------------- 1806 1448 itcl::configbody Rappture::NanovisViewer::plotforeground { 1807 foreach {r g b} [_color2rgb $itk_option(-plotforeground)] break 1808 #fix this! 1809 #_send color background $r $g $b 1449 if { [isconnected] } { 1450 foreach {r g b} [Color2RGB $itk_option(-plotforeground)] break 1451 #fix this! 1452 #_send "color background $r $g $b" 1453 } 1810 1454 } 1811 1455 … … 1814 1458 # ---------------------------------------------------------------------- 1815 1459 itcl::configbody Rappture::NanovisViewer::plotoutline { 1816 if {[isconnected]} { 1460 # Must check if we are connected because this routine is called from the 1461 # class body when the -plotoutline itk_option is defined. At that point 1462 # the NanovisViewer class constructor hasn't been called, so we can't 1463 # start sending commands to visualization server. 1464 if { [isconnected] } { 1817 1465 if {"" == $itk_option(-plotoutline)} { 1818 _send volume outline state off1466 _send "volume outline state off" 1819 1467 } else { 1820 _send volume outline state on1821 _send volume outline color [_color2rgb $itk_option(-plotoutline)]1822 } 1823 } 1824 } 1825 1826 itcl::body Rappture::NanovisViewer:: _hideIsoMarkers {dataobj} {1468 _send "volume outline state on" 1469 _send "volume outline color [Color2RGB $itk_option(-plotoutline)]" 1470 } 1471 } 1472 } 1473 1474 itcl::body Rappture::NanovisViewer::HideIsoMarkers {dataobj} { 1827 1475 if { [info exists _isomarkers($dataobj)] } { 1828 1476 foreach m $_isomarkers($dataobj) { … … 1832 1480 } 1833 1481 1834 itcl::body Rappture::NanovisViewer:: _showIsoMarkers {dataobj} {1482 itcl::body Rappture::NanovisViewer::ShowIsoMarkers {dataobj} { 1835 1483 foreach obj [array names _all_data_objs] { 1836 _hideIsoMarkers $obj1484 HideIsoMarkers $obj 1837 1485 } 1838 1486 if { ![info exists _isomarkers($dataobj)] } { … … 1844 1492 } 1845 1493 1846 itcl::body Rappture::NanovisViewer:: _initIsoMarkers {dataobj comp} {1494 itcl::body Rappture::NanovisViewer::InitIsoMarkers {dataobj comp} { 1847 1495 array set style { 1848 1496 -levels 6x … … 1891 1539 # legend. 1892 1540 # ---------------------------------------------------------------------- 1893 itcl::body Rappture::NanovisViewer:: update_transfer_function {} {1541 itcl::body Rappture::NanovisViewer::UpdateTransferFunction {} { 1894 1542 set dataobj [lindex [get] 0] 1895 1543 if {"" == $dataobj} { … … 1902 1550 } 1903 1551 # Compute a transfer function for the current data set. 1904 foreach {sname cmap wmap} [ _genTransfuncData $dataobj $comp] break1905 _send transfunc define $_obj2style($key) $cmap $wmap1906 _send volume shading transfunc $_obj2style($key) $_obj2id($key)1552 foreach {sname cmap wmap} [GenTransfuncData $dataobj $comp] break 1553 _send [list transfunc define $_obj2style($key) $cmap $wmap] 1554 _send [list volume shading transfunc $_obj2style($key) $_obj2id($key)] 1907 1555 _fixLegend 1908 1556 } 1909 1557 1910 itcl::body Rappture::NanovisViewer:: _addIsoMarker { x y } {1558 itcl::body Rappture::NanovisViewer::AddIsoMarker { x y } { 1911 1559 set dataobj [lindex [get] 0] 1912 1560 if {$dataobj == ""} { … … 1919 1567 $m show 1920 1568 lappend _isomarkers($dataobj) $m 1921 update_transfer_function1569 UpdateTransferFunction 1922 1570 return 1 1923 1571 } 1924 1572 1925 itcl::body Rappture::NanovisViewer:: remove_duplicate_isomarker { marker x } {1573 itcl::body Rappture::NanovisViewer::RemoveDuplicateIsoMarker { marker x } { 1926 1574 set dataobj [lindex [get] 0] 1927 1575 if {"" == $dataobj} { … … 1946 1594 } 1947 1595 set _isomarkers($dataobj) $list 1948 update_transfer_function1596 UpdateTransferFunction 1949 1597 } 1950 1598 return $bool 1951 1599 } 1952 1600 1953 itcl::body Rappture::NanovisViewer:: over_isomarker { marker x } {1601 itcl::body Rappture::NanovisViewer::OverIsoMarker { marker x } { 1954 1602 set dataobj [lindex [get] 0] 1955 1603 if {"" == $dataobj} {
Note: See TracChangeset
for help on using the changeset viewer.