Changeset 1013 for trunk/gui/scripts
- Timestamp:
- Jun 8, 2008, 4:44:42 PM (16 years ago)
- Location:
- trunk/gui/scripts
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/curve.tcl
r811 r1013 29 29 public method limits {which} 30 30 public method hints {{key ""}} 31 public method xmarkers {} 32 public method ymarkers {} 31 33 32 34 protected method _build {} … … 36 38 private variable _comp2xy ;# maps component name => x,y vectors 37 39 private variable _hints ;# cache of hints stored in XML 40 41 private variable _xmarkers "";# list of {x,label,options} triplets. 42 private variable _ymarkers "";# list of {y,label,options} triplets. 38 43 39 44 private common _counter 0 ;# counter for unique vector names … … 279 284 } 280 285 } 281 } 286 # Creates lists of x and y marker data. 287 set _xmarkers {} 288 set _ymarkers {} 289 foreach cname [$_curve children -type "marker" xaxis] { 290 set at [$_curve get "xaxis.$cname.at"] 291 set label [$_curve get "xaxis.$cname.label"] 292 set styles [$_curve get "xaxis.$cname.style"] 293 set data [list $at $label $styles] 294 lappend _xmarkers $data 295 } 296 foreach cname [$_curve children -type "marker" yaxis] { 297 set at [$_curve get "yaxis.$cname.at"] 298 set label [$_curve get "yaxis.$cname.label"] 299 set styles [$_curve get "yaxis.$cname.style"] 300 set data [list $at $label $styles] 301 lappend _xmarkers $data 302 } 303 } 304 305 # ---------------------------------------------------------------------- 306 # USAGE: xmarkers 307 # 308 # Returns the list of settings for each marker on the x-axis. 309 # If no markers have been specified the empty string is returned. 310 # ---------------------------------------------------------------------- 311 itcl::body Rappture::Curve::xmarkers {} { 312 return $_xmarkers; 313 } 314 315 # ---------------------------------------------------------------------- 316 # USAGE: ymarkers 317 # 318 # Returns the list of settings for each marker on the y-axis. 319 # If no markers have been specified the empty string is returned. 320 # ---------------------------------------------------------------------- 321 itcl::body Rappture::Curve::ymarkers {} { 322 return $_ymarkers; 323 } -
trunk/gui/scripts/heightmapviewer.tcl
r935 r1013 568 568 foreach dataobj $_sendobjs { 569 569 foreach comp [$dataobj components] { 570 # send the data as one huge base64-encoded mess -- yuck!571 570 set data [$dataobj blob $comp] 572 571 … … 950 949 } 951 950 set clist [split $style(-color) :] 952 set cmap "0.0 [Color2RGB white] " 951 set color white 952 set cmap "0.0 [Color2RGB $color] " 953 append cmap "$_limits(vmin) [Color2RGB $color] " 954 set range [expr $_limits(vmax) - $_limits(vmin)] 953 955 for {set i 0} {$i < [llength $clist]} {incr i} { 954 956 set xval [expr {double($i+1)/([llength $clist]+1)}] 957 set xval [expr ($xval * $range) + $_limits(vmin)] 955 958 set color [lindex $clist $i] 956 959 append cmap "$xval [Color2RGB $color] " 957 960 } 961 append cmap "$_limits(vmax) [Color2RGB $color] " 958 962 append cmap "1.0 [Color2RGB $color]" 959 963 960 set max$style(-opacity)964 set opacity $style(-opacity) 961 965 set levels $style(-levels) 966 set wmap {} 962 967 if {[string is int $levels]} { 963 set wmap "0.0 0.0 "968 lappend wmap 0.0 0.0 964 969 set delta [expr {0.125/($levels+1)}] 965 970 for {set i 1} {$i <= $levels} {incr i} { 966 971 # add spikes in the middle 967 972 set xval [expr {double($i)/($levels+1)}] 968 append wmap "[expr {$xval-$delta-0.01}] 0.0 [expr {$xval-$delta}] $max [expr {$xval+$delta}] $max [expr {$xval+$delta+0.01}] 0.0 " 969 } 970 append wmap "1.0 0.0 " 973 lappend wmap [expr {$xval-$delta-0.01}] 0.0 974 lappend wmap [expr {$xval-$delta}] $opacity 975 lappend wmap [expr {$xval+$delta}] $opacity 976 lappend wmap [expr {$xval+$delta+0.01}] 0.0 977 } 978 lappend wmap 1.0 0.0 971 979 } else { 972 set wmap "0.0 0.0 "980 lappend wmap 0.0 0.0 973 981 set delta 0.05 974 982 foreach xval [split $levels ,] { 975 append wmap "[expr {$xval-$delta}] 0.0 $xval $max [expr {$xval+$delta}] 0.0 " 976 } 977 append wmap "1.0 0.0 " 983 lappend wmap [expr {$xval-$delta}] 0.0 984 lappend $xval $opacity 985 lappend [expr {$xval+$delta}] 0.0 986 } 987 lappend wmap 1.0 0.0 978 988 } 979 989 -
trunk/gui/scripts/isomarker.tcl
r988 r1013 23 23 private variable _canvas "" 24 24 private variable _nvobj ""; # Parent nanovis object. 25 private variable _ivol ""; # Id of volumethat this marker is25 private variable _ivol ""; # Transfer function that this marker is 26 26 # associated with. 27 27 private variable _active_motion 0 … … 55 55 } 56 56 public method GetVolume {} { 57 57 return $_ivol 58 58 } 59 59 public method GetAbsoluteValue {} { … … 141 141 SetRelativeValue [expr {double($x-10)/($w-20)}] 142 142 $_nvobj OverIsoMarker $this $x 143 $_nvobj UpdateTransferFunction $_ivol143 $_nvobj UpdateTransferFunctions 144 144 } 145 145 end { -
trunk/gui/scripts/molvisviewer.tcl
r935 r1013 78 78 protected method _vmouse {option b m x y} 79 79 80 private method _receive_image { args }80 private method _receive_image { size cacheid frame rock } 81 81 82 82 private variable _inrebuild 0 -
trunk/gui/scripts/nanovisviewer.tcl
r975 r1013 57 57 public method delete {args} 58 58 public method scale {args} 59 public method GetLimits { {ivol ""} } { 60 if { $ivol != "" } { 61 set _limits(min) $_limits($ivol-min) 62 set _limits(max) $_limits($ivol-max) 59 public method GetLimits { ivol } { 60 if { if [info exists _id2style($ivol)] } { 61 set tf $_id2style($ivol) 62 set _limits(min) "" 63 set _limits(max) "" 64 foreach ivol $_style2ids($tf) { 65 if { ![info exists _limits($ivol-min)] } { 66 puts stderr "In GetLimits $ivol" 67 parray _limits 68 error "can't find $ivol limits" 69 } 70 if { $_limits(min) == "" || 71 $_limits(min) > $_limits($ivol-min) } { 72 set _limits(min) $_limits($ivol-min) 73 } 74 if { $_limits(max) == "" || 75 $_limits(max) < $_limits($ivol-max) } { 76 set _limits(max) $_limits($ivol-max) 77 } 78 } 63 79 } 64 80 return [array get _limits] … … 69 85 } 70 86 public method isconnected {} 71 public method UpdateTransferFunction { ivol}87 public method UpdateTransferFunctions {} 72 88 public method RemoveDuplicateIsoMarker { m x } 73 89 public method OverIsoMarker { m x } … … 77 93 78 94 protected method _send {string} 79 protected method _ send_dataobjs {}80 protected method _ send_transfunc{}95 protected method _SendDataObjs {} 96 protected method _SendTransferFunctions {} 81 97 82 98 protected method _ReceiveImage {option size} 83 99 protected method _ReceiveLegend { ivol vmin vmax size } 84 100 protected method _ReceiveData { args } 101 protected method _ReceivePrint { option size } 85 102 86 103 protected method _rebuild {} … … 98 115 99 116 # The following methods are only used by this class. 100 private method _DefineTransferFunction { ivol } 117 private method _NameTransferFunction { ivol } 118 private method _ComputeTransferFunction { tf } 101 119 private method _AddIsoMarker { x y } 102 private method _InitIsoMarkers { ivol } 103 private method _HideIsoMarkers { ivol } 104 private method _ShowIsoMarkers { ivol } 105 private method _ParseMarkersOption { ivol markers } 106 private method _ParseLevelsOption { ivol levels } 120 private method _ParseMarkersOption { tf ivol markers } 121 private method _ParseLevelsOption { tf ivol levels } 107 122 108 123 private variable _outbuf ;# buffer for outgoing commands … … 116 131 private variable _id2obj ;# maps dataobj => volume ID in server 117 132 private variable _sendobjs "" ;# list of data objs to send to server 118 private variable _sendobjs2 "" ;# list of data objs to send to server119 133 private variable _receiveids ;# list of data objs to send to server 134 private variable _obj2styles ;# maps id => style settings 135 private variable _style2ids ;# maps id => style settings 120 136 121 137 private variable _click ;# info used for _move operations … … 126 142 private variable _styles 127 143 private common _settings 128 private variable _active Vol "";# The currently active volume. This144 private variable _activeId "" ;# The currently active volume. This 129 145 # indicates which isomarkers and transfer 130 146 # function to use when changing markers, 131 147 # opacity, or thickness. 148 #common _downloadPopup ;# download options from popup 132 149 } 133 150 … … 148 165 $_dispatcher register !send_dataobjs 149 166 $_dispatcher dispatch $this !send_dataobjs \ 150 "[itcl::code $this _ send_dataobjs]; list"167 "[itcl::code $this _SendDataObjs]; list" 151 168 # Send transfer functions event 152 169 $_dispatcher register !send_transfunc 153 170 $_dispatcher dispatch $this !send_transfunc \ 154 "[itcl::code $this _ send_transfunc]; list"171 "[itcl::code $this _SendTransferFunctions]; list" 155 172 # Rebuild event 156 173 $_dispatcher register !rebuild … … 165 182 $_parser alias legend [itcl::code $this _ReceiveLegend] 166 183 $_parser alias data [itcl::code $this _ReceiveData] 184 #$_parser alias print [itcl::code $this _ReceivePrint] 167 185 168 186 # Initialize the view to some default parameters. … … 423 441 label $inner.scales.thickl -text "Thick" -font $fg 424 442 grid $inner.scales.thickl -row 3 -column 2 -sticky w 425 $inner.scales.thickness set 500443 $inner.scales.thickness set 350 426 444 427 445 set ::Rappture::NanovisViewer::_settings($this-isosurface) 0 … … 489 507 itcl::body Rappture::NanovisViewer::destructor {} { 490 508 set _sendobjs "" ;# stop any send in progress 491 set _sendobjs2 "" ;# stop any send in progress492 509 $_dispatcher cancel !rebuild 493 510 $_dispatcher cancel !send_dataobjs … … 599 616 set args $_dlist 600 617 } 601 602 618 # delete all specified dataobjs 603 619 set changed 0 … … 612 628 } 613 629 } 614 615 630 # if anything changed, then rebuild the plot 616 631 if {$changed} { … … 634 649 foreach obj $args { 635 650 foreach axis {x y z v} { 636 foreach {min max} [$obj limits $axis] break 651 652 foreach { min max } [$obj limits $axis] break 653 637 654 if {"" != $min && "" != $max} { 638 655 if {"" == $_limits(${axis}min)} { … … 728 745 set _id2obj(count) 0 729 746 set _sendobjs "" 730 set _sendobjs2 ""731 747 } 732 748 … … 751 767 752 768 # ---------------------------------------------------------------------- 753 # USAGE: _ send_dataobjs769 # USAGE: _SendDataObjs 754 770 # 755 771 # Used internally to send a series of volume objects off to the … … 757 773 # between so the interface doesn't lock up. 758 774 # ---------------------------------------------------------------------- 759 itcl::body Rappture::NanovisViewer::_ send_dataobjs {} {775 itcl::body Rappture::NanovisViewer::_SendDataObjs {} { 760 776 blt::busy hold $itk_component(hull); update idletasks 761 762 777 foreach dataobj $_sendobjs { 763 778 foreach comp [$dataobj components] { … … 776 791 set _id2obj($ivol) [list $dataobj $comp] 777 792 set _obj2id($dataobj-$comp) $ivol 793 _NameTransferFunction $ivol 778 794 set _receiveids($ivol) 1 779 780 795 } 781 796 } … … 790 805 _send "up $axis" 791 806 } 807 # The active volume is by default the first component of the first 808 # data object. This assumes that the data is always successfully 809 # transferred. 810 set comp [lindex [$first components] 0] 811 set _activeId $_obj2id($first-$comp) 792 812 } 793 813 foreach key [array names _obj2id *-*] { … … 795 815 set ivol $_obj2id($key) 796 816 _send "volume state $state $ivol" 797 if {[info exists _id2style($ivol)]} {798 _send "volume shading transfunc $_id2style($ivol) $ivol"799 }800 817 } 801 818 … … 809 826 _send "volume data state [_state volume] $vols" 810 827 828 if 0 { 829 _send "volume axis label x \"\"" 830 _send "volume axis label y \"\"" 831 _send "volume axis label z \"\"" 832 _send "grid axisname x X eV" 833 _send "grid axisname y Y eV" 834 _send "grid axisname z Z eV" 835 } 811 836 # if there are any commands in the buffer, send them now that we're done 812 837 SendBytes $_outbuf … … 817 842 818 843 # ---------------------------------------------------------------------- 819 # USAGE: _send_transfunc 820 # ---------------------------------------------------------------------- 821 itcl::body Rappture::NanovisViewer::_send_transfunc {} { 822 if { ![_DefineTransferFunction $_activeVol] } { 823 return 824 } 825 _fixLegend 844 # USAGE: _SendTransferFunctions 845 # ---------------------------------------------------------------------- 846 itcl::body Rappture::NanovisViewer::_SendTransferFunctions {} { 847 set first [lindex [get] 0] 848 849 # Insure that the global opacity and thickness settings (in the slider 850 # settings widgets) are used for the transfer-function used by the active 851 # volume. Update the values in the _settings varible. 852 set inner [$itk_component(controls).panel component inner] 853 set tf $_id2style($_activeId) 854 set value [$inner.scales.opacity get] 855 set opacity [expr { double($value) * 0.01 }] 856 set _settings($this-$tf-opacity) $opacity 857 set value [$inner.scales.thickness get] 858 # Scale values between 0.00001 and 0.01000 859 set thickness [expr {double($value) * 0.0001}] 860 set _settings($this-$tf-thickness) $thickness 861 862 if { ![info exists $_obj2styles($first)] } { 863 foreach tf $_obj2styles($first) { 864 if { ![_ComputeTransferFunction $tf] } { 865 return 866 } 867 } 868 _fixLegend 869 } 826 870 } 827 871 … … 844 888 } 845 889 846 # ---------------------------------------------------------------------- 847 # USAGE: _ReceiveLegend <volume> <vmin> <vmax> <size> 848 # 849 # Invoked automatically whenever the "legend" command comes in from 890 # 891 # _ReceiveLegend -- 892 # 893 # The procedure is the response from the render server to each "legend" 894 # command. The server sends back a "legend" command invoked our 895 # the slave interpreter. The purpose is to collect data of the image 896 # representing the legend in the canvas. In addition, the isomarkers 897 # of the active volume are displayed. 898 # 899 # I don't know is this is the right place to display the isomarkers. 900 # I don't know all the different paths used to draw the plot. There's 901 # "_rebuild", "add", etc. 902 # 903 itcl::body Rappture::NanovisViewer::_ReceiveLegend { ivol vmin vmax size } { 904 if { ![isconnected] } { 905 return 906 } 907 set bytes [ReceiveBytes $size] 908 $_image(legend) configure -data $bytes 909 ReceiveEcho <<line "<read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>" 910 911 set c $itk_component(legend) 912 set w [winfo width $c] 913 set h [winfo height $c] 914 foreach { dataobj comp } $_id2obj($ivol) break 915 set lx 10 916 set ly [expr {$h - 1}] 917 if {"" == [$c find withtag transfunc]} { 918 $c create image 10 10 -anchor nw \ 919 -image $_image(legend) -tags transfunc 920 $c create text $lx $ly -anchor sw \ 921 -fill $itk_option(-plotforeground) -tags "limits vmin" 922 $c create text [expr {$w-$lx}] $ly -anchor se \ 923 -fill $itk_option(-plotforeground) -tags "limits vmax" 924 $c lower transfunc 925 $c bind transfunc <ButtonRelease-1> \ 926 [itcl::code $this _AddIsoMarker %x %y] 927 } 928 array set limits [GetLimits $ivol] 929 $c itemconfigure vmin -text [format %.2g $limits(min)] 930 $c coords vmin $lx $ly 931 932 $c itemconfigure vmax -text [format %.2g $limits(max)] 933 $c coords vmax [expr {$w-$lx}] $ly 934 935 # Display the markers used by the active volume. 936 set tf $_id2style($_activeId) 937 if { [info exists _isomarkers($tf)] } { 938 foreach m $_isomarkers($tf) { 939 $m Show 940 } 941 } 942 } 943 944 # 945 # _ReceiveData -- 946 # 947 # The procedure is the response from the render server to each "data 948 # follows" command. The server sends back a "data" command invoked our 949 # the slave interpreter. The purpose is to collect the min/max of the 950 # volume sent to the render server. Since the client (nanovisviewer) 951 # doesn't parse 3D data formats, we rely on the server (nanovis) to 952 # tell us what the limits are. Once we've received the limits to all 953 # the data we've sent (tracked by _receiveids) we can then determine 954 # what the transfer functions are for these volumes. 955 # 956 # 957 # Note: There is a considerable tradeoff in having the server report 958 # back what the data limits are. It means that much of the code 959 # having to do with transfer-functions has to wait for the data 960 # to come back, since the isomarkers are calculated based upon 961 # the data limits. The client code is much messier because of 962 # this. The alternative is to parse any of the 3D formats on the 963 # client side. 964 # 965 itcl::body Rappture::NanovisViewer::_ReceiveData { args } { 966 if { ![isconnected] } { 967 return 968 } 969 # Arguments from server are name value pairs. Stuff them in an array. 970 array set info $args 971 972 set ivol $info(id); # Id of volume created by server. 973 974 set _limits($ivol-min) $info(min); # Minimum value of the volume. 975 set _limits($ivol-max) $info(max); # Maximum value of the volume. 976 set _limits(vmin) $info(vmin); # Overall minimum value. 977 set _limits(vmax) $info(vmax); # Overall maximum value. 978 979 unset _receiveids($ivol) 980 if { [array size _receiveids] == 0 } { 981 UpdateTransferFunctions 982 } 983 } 984 985 # ---------------------------------------------------------------------- 986 # USAGE: _ReceivePrint -bytes <size> 987 # 988 # Invoked automatically whenever the "image" command comes in from 850 989 # the rendering server. Indicates that binary image data with the 851 990 # specified <size> will follow. 852 991 # ---------------------------------------------------------------------- 853 itcl::body Rappture::NanovisViewer::_Receive Legend { ivol vmin vmax size} {992 itcl::body Rappture::NanovisViewer::_ReceivePrint {option size} { 854 993 if { [isconnected] } { 855 994 set bytes [ReceiveBytes $size] 856 $_image(legend) configure -data $bytes 857 ReceiveEcho <<line "<read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>" 858 859 set c $itk_component(legend) 860 set w [winfo width $c] 861 set h [winfo height $c] 862 foreach { dataobj comp } $_id2obj($ivol) break 863 if {"" == [$c find withtag transfunc]} { 864 $c create image 10 10 -anchor nw \ 865 -image $_image(legend) -tags transfunc 866 $c create text 10 [expr {$h-8}] -anchor sw \ 867 -fill $itk_option(-plotforeground) -tags vmin 868 $c create text [expr {$w-10}] [expr {$h-8}] -anchor se \ 869 -fill $itk_option(-plotforeground) -tags vmax 870 $c lower transfunc 871 $c bind transfunc <ButtonRelease-1> \ 872 [itcl::code $this _AddIsoMarker %x %y] 873 } 874 $c itemconfigure vmin -text $_limits($ivol-min) 875 $c coords vmin 10 [expr {$h-8}] 876 877 $c itemconfigure vmax -text $_limits($ivol-max) 878 $c coords vmax [expr {$w-10}] [expr {$h-8}] 879 880 _ShowIsoMarkers $ivol 881 } 882 } 883 884 # ---------------------------------------------------------------------- 885 # USAGE: _ReceiveData <volume> <vmin> <vmax> 886 # 887 # Invoked automatically whenever the "legend" command comes in from 888 # the rendering server. Indicates that binary image data with the 889 # specified <size> will follow. 890 # ---------------------------------------------------------------------- 891 itcl::body Rappture::NanovisViewer::_ReceiveData { args } { 892 if { [isconnected] } { 893 array set info $args 894 set ivol $info(id) 895 set _limits($ivol-min) $info(min) 896 set _limits($ivol-max) $info(max) 897 foreach { dataobj comp } $_id2obj($ivol) break 898 899 if { ![info exists _limits($dataobj-vmin)] } { 900 set _limits($dataobj-vmin) $info(min) 901 set _limits($dataobj-vmax) $info(max) 902 } else { 903 if { $_limits($dataobj-vmin) > $info(min) } { 904 set _limits($dataobj-vmin) $info(min) 905 } 906 if { $_limits($dataobj-vmax) < $info(max) } { 907 set _limits($dataobj-vmax) $info(max) 908 } 909 } 910 set _limits(vmin) $info(vmin) 911 set _limits(vmax) $info(vmax) 912 lappend _sendobjs2 $dataobj 913 unset _receiveids($info(id)) 914 915 if { ![info exists _isomarkers($ivol)] } { 916 _InitIsoMarkers $ivol 917 } else { 918 _HideIsoMarkers $ivol 919 } 920 # We can update the transfer function now that we know the data limits. 921 if { ![_DefineTransferFunction $ivol] } { 922 return 923 } 924 } 925 if { [array size _receiveids] == 0 } { 926 _fixLegend 995 set f [open /tmp/junk "w"] 996 puts $f $bytes 997 close $f 998 $_image(download) configure -data $bytes 999 update 1000 puts stderr "<read $size bytes for [image width $_image(download)]x[image height $_image(download)] image>" 927 1001 } 928 1002 } … … 936 1010 # ---------------------------------------------------------------------- 937 1011 itcl::body Rappture::NanovisViewer::_rebuild {} { 1012 # Hide all the isomarkers. Can't remove them. Have to remember the 1013 # settings since the user may have created/deleted/moved markers. 1014 1015 foreach tf [array names _isomarkers] { 1016 foreach m $_isomarkers($tf) { 1017 $m Hide 1018 } 1019 } 1020 938 1021 # in the midst of sending data? then bail out 939 1022 if {[llength $_sendobjs] > 0} { … … 956 1039 # send off new data objects 957 1040 $_dispatcher event -idle !send_dataobjs 958 } else { 959 set w [winfo width $itk_component(3dview)] 960 set h [winfo height $itk_component(3dview)] 961 _send "screen $w $h" 962 # nothing to send -- activate the proper ivol 963 set first [lindex [get] 0] 964 if {"" != $first} { 965 set axis [$first hints updir] 966 if {"" != $axis} { 967 _send "up $axis" 968 } 969 } 1041 return 1042 } 1043 1044 set w [winfo width $itk_component(3dview)] 1045 set h [winfo height $itk_component(3dview)] 1046 _send "screen $w $h" 1047 1048 # nothing to send -- activate the proper ivol 1049 set first [lindex [get] 0] 1050 if {"" != $first} { 1051 set axis [$first hints updir] 1052 if {"" != $axis} { 1053 _send "up $axis" 1054 } 970 1055 foreach key [array names _obj2id *-*] { 971 1056 set state [string match $first-* $key] 972 1057 _send "volume state $state $_obj2id($key)" 973 1058 } 974 set comp [lindex [$dataobj components] 0] 1059 # 1060 # The _obj2id and _id2style arrays may or may not have the right 1061 # information. It's possible for the server to know about volumes 1062 # that the client has assumed it's deleted. We could add checks. 1063 # But this problem needs to be fixed not bandaided. 1064 set comp [lindex [$first components] 0] 975 1065 set ivol $_obj2id($first-$comp) 976 977 _ShowIsoMarkers $ivol 978 979 if { [info exists _settings($this-$ivol-opacity)] } { 980 set inner [$itk_component(controls).panel component inner] 981 set sval $_settings($this-$ivol-opacity) 982 set sval [expr {round($sval * 100)}] 983 $inner.scales.opacity set $sval 1066 1067 set tf _id2style($ivol) 1068 1069 foreach comp [$first components] { 1070 foreach ivol $_obj2id($first-$comp) { 1071 _NameTransferFunction $ivol 1072 } 984 1073 } 985 if { [info exists _settings($this-$ivol-thickness)] } { 986 set inner [$itk_component(controls).panel component inner] 987 set sval $_settings($this-$ivol-thickness) 988 set sval [expr {round($sval * 10000.0)}] 989 $inner.scales.thickness set $sval 990 } 991 UpdateTransferFunction $ivol 992 993 # sync the state of slicers 994 set vols [_currentVolumeIds -cutplanes] 995 foreach axis {x y z} { 996 _send "cutplane state [_state ${axis}slice] $axis $vols" 997 set pos [expr {0.01*[$itk_component(${axis}slicer) get]}] 998 _send "cutplane position $pos $axis $vols" 999 } 1000 _send "volume data state [_state volume] $vols" 1001 $_dispatcher event -idle !legend 1002 } 1003 1074 } 1075 1076 # sync the state of slicers 1077 set vols [_currentVolumeIds -cutplanes] 1078 foreach axis {x y z} { 1079 _send "cutplane state [_state ${axis}slice] $axis $vols" 1080 set pos [expr {0.01*[$itk_component(${axis}slicer) get]}] 1081 _send "cutplane position $pos $axis $vols" 1082 } 1083 _send "volume data state [_state volume] $vols" 1084 $_dispatcher event -idle !legend 1085 1004 1086 # 1005 1087 # Reset the camera and other view parameters … … 1007 1089 _send "camera angle [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)]" 1008 1090 _send "camera zoom $_view(zoom)" 1009 1091 1010 1092 _fixSettings light 1011 1093 _fixSettings transp 1012 1094 _fixSettings isosurface 1013 _fixSettings opacity1014 _fixSettings thickness1015 1095 _fixSettings grid 1016 1096 _fixSettings axes 1017 1097 _fixSettings outline 1018 1019 1020 # if {"" == $itk_option(-plotoutline)} {1021 # _send "volume outline state off"1022 # } else {1023 # _send "volume outline state on"1024 # set rgb [Color2RGB $itk_option(-plotoutline)]1025 # _send "volume outline color $rgb"1026 # }1027 _send "volume axis label x \"\""1028 _send "volume axis label y \"\""1029 _send "volume axis label z \"\""1030 1098 } 1031 1099 … … 1301 1369 } 1302 1370 opacity { 1303 if {[isconnected] && $_active Vol!= "" } {1371 if {[isconnected] && $_activeId != "" } { 1304 1372 set val [$inner.scales.opacity get] 1305 1373 set sval [expr { 0.01 * double($val) }] 1306 set ivol $_activeVol1307 set _settings($this-$ ivol-opacity) $sval1308 UpdateTransferFunction $ivol1374 set tf $_id2style($_activeId) 1375 set _settings($this-$tf-opacity) $sval 1376 UpdateTransferFunctions 1309 1377 } 1310 1378 } 1311 1379 1312 1380 thickness { 1313 if {[isconnected] && $_active Vol!= "" } {1381 if {[isconnected] && $_activeId != "" } { 1314 1382 set val [$inner.scales.thickness get] 1315 1383 # Scale values between 0.00001 and 0.01000 1316 1384 set sval [expr {0.0001*double($val)}] 1317 set ivol $_activeVol1318 set _settings($this-$ ivol-thickness) $sval1319 UpdateTransferFunction $ivol1385 set tf $_id2style($_activeId) 1386 set _settings($this-$tf-thickness) $sval 1387 UpdateTransferFunctions 1320 1388 } 1321 1389 } … … 1357 1425 set w [expr {[winfo width $itk_component(legend)]-20}] 1358 1426 set h [expr {[winfo height $itk_component(legend)]-20-$lineht}] 1359 set ivol $_active Vol1427 set ivol $_activeId 1360 1428 if {$w > 0 && $h > 0 && "" != $ivol} { 1361 1429 _send "legend $ivol $w $h" 1362 1430 } else { 1363 #$itk_component(legend) delete all 1364 } 1365 } 1366 1367 # ---------------------------------------------------------------------- 1368 # USAGE: _DefineTransferFunction <ivol> 1369 # 1370 # Used internally to compute the colormap and alpha map used to define 1371 # a transfer function for the specified component in a data object. 1372 # Returns: name {v r g b ...} {v w ...} 1373 # ---------------------------------------------------------------------- 1374 itcl::body Rappture::NanovisViewer::_DefineTransferFunction { ivol } { 1431 # Can't do this as this will remove the items associated with the 1432 # isomarkers. 1433 1434 #$itk_component(legend) delete all 1435 } 1436 } 1437 1438 # 1439 # _NameTransferFunction -- 1440 # 1441 # Creates a transfer function name based on the <style> settings in the 1442 # library run.xml file. This placeholder will be used later to create 1443 # and send the actual transfer function once the data info has been sent 1444 # to us by the render server. [We won't know the volume limits until the 1445 # server parses the 3D data and sends back the limits via _ReceiveData.] 1446 # 1447 # FIXME: The current way we generate transfer-function names completely 1448 # ignores the -markers option. The problem is that we are forced 1449 # to compute the name from an increasing complex set of values: 1450 # color, levels, marker, opacity. I think we're stuck doing it 1451 # now. 1452 # 1453 itcl::body Rappture::NanovisViewer::_NameTransferFunction { ivol } { 1375 1454 array set style { 1376 1455 -color rainbow … … 1380 1459 foreach {dataobj comp} $_id2obj($ivol) break 1381 1460 array set style [lindex [$dataobj components -style $comp] 0] 1382 set sname "$style(-color):$style(-levels):$style(-opacity)" 1461 set tf "$style(-color):$style(-levels):$style(-opacity)" 1462 1463 set _id2style($ivol) $tf 1464 lappend _obj2styles($dataobj) $tf 1465 lappend _style2ids($tf) $ivol 1466 } 1467 1468 # 1469 # _ComputeTransferFunction -- 1470 # 1471 # Computes and sends the transfer function to the render server. It's 1472 # assumed that the volume data limits are known and that the global 1473 # transfer-functions slider values have be setup. Both parts are 1474 # needed to compute the relative value (location) of the marker, and 1475 # the alpha map of the transfer function. 1476 # 1477 itcl::body Rappture::NanovisViewer::_ComputeTransferFunction { tf } { 1478 array set style { 1479 -color rainbow 1480 -levels 6 1481 -opacity 1.0 1482 } 1483 set ivol [lindex $_style2ids($tf) 0] 1484 foreach {dataobj comp} $_id2obj($ivol) break 1485 array set style [lindex [$dataobj components -style $comp] 0] 1486 1487 1488 # We have to parse the style attributes for a volume using this 1489 # transfer-function *once*. This sets up the initial isomarkers for the 1490 # transfer function. The user may add/delete markers, so we have to 1491 # maintain a list of markers for each transfer-function. We use the one 1492 # of the volumes (the first in the list) using the transfer-function as a 1493 # reference. 1494 # 1495 # FIXME: The current way we generate transfer-function names completely 1496 # ignores the -markers option. The problem is that we are forced 1497 # to compute the name from an increasing complex set of values: 1498 # color, levels, marker, opacity. I think the cow's out of the 1499 # barn on this one. 1500 1501 if { ![info exists _isomarkers($tf)] } { 1502 # Have to defer creation of isomarkers until we have data limits 1503 if { [info exists style(-markers)] } { 1504 _ParseMarkersOption $tf $ivol $style(-markers) 1505 } else { 1506 _ParseLevelsOption $tf $ivol $style(-levels) 1507 } 1508 } 1383 1509 if {$style(-color) == "rainbow"} { 1384 1510 set style(-color) "white:yellow:green:cyan:blue:magenta" … … 1393 1519 append cmap "1.0 [Color2RGB $color]" 1394 1520 1395 set tag $this-$ ivol1521 set tag $this-$tf 1396 1522 if { ![info exists _settings($tag-opacity)] } { 1397 1523 set _settings($tag-opacity) $style(-opacity) … … 1400 1526 1401 1527 set isovalues {} 1402 foreach m $_isomarkers($ ivol) {1528 foreach m $_isomarkers($tf) { 1403 1529 lappend isovalues [$m GetRelativeValue] 1404 1530 } 1405 1406 1531 # Sort the isovalues 1407 1532 set isovalues [lsort -real $isovalues] … … 1425 1550 if { $x1 < 0.0 } { 1426 1551 set x1 0.0 1427 } 1552 } elseif { $x1 > 1.0 } { 1553 set x1 1.0 1554 } 1428 1555 if { $x2 < 0.0 } { 1429 1556 set x2 0.0 1430 } 1431 if { $x3 > 1.0 } { 1432 set x3 1.0 1433 } 1434 if { $x4 > 1.0 } { 1435 set x4 1.0 1557 } elseif { $x2 > 1.0 } { 1558 set x2 1.0 1559 } 1560 if { $x3 < 0.0 } { 1561 set x3 0.0 1562 } elseif { $x3 > 1.0 } { 1563 set x3 1.0 1564 } 1565 if { $x4 < 0.0 } { 1566 set x4 0.0 1567 } elseif { $x4 > 1.0 } { 1568 set x4 1.0 1436 1569 } 1437 1570 # add spikes in the middle … … 1444 1577 lappend wmap 1.0 0.0 1445 1578 } 1446 set _id2style($ivol) $sname 1447 set _styles($sname) 1 1448 set cmds [subst { 1449 transfunc define $sname { $cmap } { $wmap } 1450 volume shading transfunc $sname $ivol 1451 }] 1452 return [SendBytes $cmds] 1579 SendBytes "transfunc define $tf { $cmap } { $wmap }\n" 1580 #puts stdout "transfunc define $tf { $cmap } { $wmap }\n" 1581 return [SendBytes "volume shading transfunc $tf $_style2ids($tf)\n"] 1453 1582 } 1454 1583 … … 1493 1622 } 1494 1623 1495 itcl::body Rappture::NanovisViewer::_HideIsoMarkers { ivol } {1496 if { [info exists _isomarkers($ivol)] } {1497 foreach m $_isomarkers($ivol) {1498 $m Hide1499 }1500 }1501 }1502 1503 itcl::body Rappture::NanovisViewer::_ShowIsoMarkers { ivol } {1504 # Clear all markers1505 foreach dataobj [array names _all_data_objs] {1506 foreach comp [$dataobj components] {1507 _HideIsoMarkers $_obj2id($dataobj-$comp)1508 }1509 }1510 set _activeVol $ivol1511 if { ![info exists _isomarkers($ivol)] } {1512 return1513 }1514 foreach m $_isomarkers($ivol) {1515 $m Show1516 }1517 }1518 1519 1624 # 1520 1625 # The -levels option takes a single value that represents the number … … 1522 1627 # marker is a relative value from 0.0 to 1.0. 1523 1628 # 1524 itcl::body Rappture::NanovisViewer::_ParseLevelsOption { ivol levels } {1629 itcl::body Rappture::NanovisViewer::_ParseLevelsOption { tf ivol levels } { 1525 1630 set c $itk_component(legend) 1526 1631 regsub -all "," $levels " " levels … … 1530 1635 set m [IsoMarker \#auto $c $this $ivol] 1531 1636 $m SetRelativeValue $x 1532 lappend _isomarkers($ ivol) $m1637 lappend _isomarkers($tf) $m 1533 1638 } 1534 1639 } else { … … 1536 1641 set m [IsoMarker \#auto $c $this $ivol] 1537 1642 $m SetRelativeValue $x 1538 lappend _isomarkers($ ivol) $m1643 lappend _isomarkers($tf) $m 1539 1644 } 1540 1645 } … … 1553 1658 # not be seen. 1554 1659 # 1555 itcl::body Rappture::NanovisViewer::_ParseMarkersOption { ivol markers } {1660 itcl::body Rappture::NanovisViewer::_ParseMarkersOption { tf ivol markers } { 1556 1661 set c $itk_component(legend) 1557 1662 regsub -all "," $markers " " markers … … 1563 1668 set m [IsoMarker \#auto $c $this $ivol] 1564 1669 $m SetRelativeValue $value 1565 lappend _isomarkers($ ivol) $m1670 lappend _isomarkers($tf) $m 1566 1671 } else { 1567 1672 # ${n} : Set absolute value. 1568 1673 set m [IsoMarker \#auto $c $this $ivol] 1569 1674 $m SetAbsoluteValue $value 1570 lappend _isomarkers($ivol) $m 1571 } 1572 } 1573 } 1574 1575 itcl::body Rappture::NanovisViewer::_InitIsoMarkers { ivol } { 1576 array set style { 1577 -levels 6 1578 } 1579 set _isomarkers($ivol) "" 1580 foreach {dataobj comp} $_id2obj($ivol) break 1581 array set style [lindex [$dataobj components -style $comp] 0] 1582 if { [info exists style(-markers)] } { 1583 _ParseMarkersOption $ivol $style(-markers) 1584 } else { 1585 _ParseLevelsOption $ivol $style(-levels) 1675 lappend _isomarkers($tf) $m 1676 } 1586 1677 } 1587 1678 } … … 1597 1688 # legend. 1598 1689 # ---------------------------------------------------------------------- 1599 itcl::body Rappture::NanovisViewer::UpdateTransferFunction { ivol } { 1600 if {![info exists _id2style($ivol)]} { 1601 return 1602 } 1603 set _activeVol $ivol 1690 itcl::body Rappture::NanovisViewer::UpdateTransferFunctions {} { 1604 1691 $_dispatcher event -idle !send_transfunc 1605 1692 } 1606 1693 1607 1694 itcl::body Rappture::NanovisViewer::_AddIsoMarker { x y } { 1608 if { $_active Vol== "" } {1695 if { $_activeId == "" } { 1609 1696 error "active volume isn't set" 1610 1697 } 1611 set ivol $_activeVol1698 set tf $_id2style($_activeId) 1612 1699 set c $itk_component(legend) 1613 set m [IsoMarker \#auto $c $this $ ivol]1700 set m [IsoMarker \#auto $c $this $_activeId] 1614 1701 set w [winfo width $c] 1615 1702 $m SetRelativeValue [expr {double($x-10)/($w-20)}] 1616 $m Show 1617 lappend _isomarkers($ivol) $m 1618 UpdateTransferFunction $ivol 1703 lappend _isomarkers($tf) $m 1704 UpdateTransferFunctions 1619 1705 return 1 1620 1706 } … … 1622 1708 itcl::body Rappture::NanovisViewer::RemoveDuplicateIsoMarker { marker x } { 1623 1709 set ivol [$marker GetVolume] 1710 set tf $_id2style($ivol) 1624 1711 set bool 0 1625 if { [info exists _isomarkers($ ivol)] } {1712 if { [info exists _isomarkers($tf)] } { 1626 1713 set list {} 1627 1714 set marker [namespace tail $marker] 1628 foreach m $_isomarkers($ ivol) {1715 foreach m $_isomarkers($tf) { 1629 1716 set sx [$m GetScreenPosition] 1630 1717 if { $m != $marker } { … … 1639 1726 lappend list $m 1640 1727 } 1641 set _isomarkers($ ivol) $list1642 UpdateTransferFunction $ivol1728 set _isomarkers($tf) $list 1729 UpdateTransferFunctions 1643 1730 } 1644 1731 return $bool -
trunk/gui/scripts/visviewer.tcl
r925 r1013 21 21 22 22 private common _servers ;# array of visualization server lists 23 #set _servers(nanovis) "128.210.189.216:2000" 23 24 set _servers(nanovis) "" 24 25 set _servers(pymol) "" … … 362 363 # ...following 100000 bytes... no 363 364 # 365 # Note: All commands from the render server are on one line. 366 # This is because the render server can send anything 367 # as an error message (restricted again to one line). 368 # 364 369 itcl::body Rappture::VisViewer::_ReceiveHelper {} { 365 370 if { [IsConnected] } { … … 369 374 if { [gets $_sid line] < 0 } { 370 375 Disconnect 371 } elseif {[string equal [string range $line 0 2] "nv>"]} { 376 } 377 set line [string trim $line] 378 if { $line == "" } { 379 return 380 } 381 if { [string equal [string range $line 0 2] "nv>"] } { 372 382 ReceiveEcho <<line $line 373 383 append _buffer(in) [string range $line 3 end] … … 381 391 # this shows errors coming back from the engine 382 392 ReceiveEcho <<error $line 383 puts stderr $line393 puts stderr "Render Server Error: $line" 384 394 } 385 395 } … … 437 447 # 438 448 itcl::body Rappture::VisViewer::SendEcho {channel {data ""}} { 439 #puts stderr ">> line$data"449 #puts stderr ">>$data" 440 450 if {[string length $itk_option(-sendcommand)] > 0} { 441 451 uplevel #0 $itk_option(-sendcommand) [list $channel $data] -
trunk/gui/scripts/xyresult.tcl
r768 r1013 1 1 2 # ---------------------------------------------------------------------- 2 3 # COMPONENT: xyresult - X/Y plot in a ResultSet … … 57 58 protected method _axis {option args} 58 59 protected method _getAxes {xydata} 60 protected method _getLineMarkerOptions { style } 61 protected method _getTextMarkerOptions { style } 62 protected method _enterMarker { g name x y text } 63 protected method _leaveMarker { g name } 59 64 60 65 private variable _dispatcher "" ;# dispatcher for !events … … 75 80 private variable _axisPopup ;# info for axis being edited in popup 76 81 common _downloadPopup ;# download options from popup 82 private variable _markers 77 83 } 78 84 … … 656 662 } 657 663 } 664 665 foreach xydata [get] { 666 set xmin -Inf 667 set ymin -Inf 668 set xmax Inf 669 set ymax Inf 670 # 671 # Create text/line markers for each *axis.marker specified. 672 # 673 foreach m [$xydata xmarkers] { 674 foreach {at label style} $m break 675 set id [$g marker create line -coords [list $at $ymin $at $ymax]] 676 $g marker bind $id <Enter> \ 677 [itcl::code $this _enterMarker $g x-$label $at $ymin $at] 678 $g marker bind $id <Leave> \ 679 [itcl::code $this _leaveMarker $g x-$label] 680 set options [_getLineMarkerOptions $style] 681 if { $options != "" } { 682 eval $g marker configure $id $options 683 } 684 if { $label != "" } { 685 set id [$g marker create text -anchor nw \ 686 -text $label -coords [list $at $ymax]] 687 set options [_getTextMarkerOptions $style] 688 if { $options != "" } { 689 eval $g marker configure $id $options 690 } 691 } 692 } 693 foreach m [$xydata ymarkers] { 694 foreach {at label style} $m break 695 set id [$g marker create line -coords [list $xmin $at $xmax $at]] 696 $g marker bind $id <Enter> \ 697 [itcl::code $this _enterMarker $g y-$label $at $xmin $at] 698 $g marker bind $id <Leave> \ 699 [itcl::code $this _leaveMarker $g y-$label] 700 set options [_getLineMarkerOptions $style] 701 if { $options != "" } { 702 eval $g marker configure $id $options 703 } 704 if { $label != "" } { 705 set id [$g marker create text -anchor se \ 706 -text $label -coords [list $xmax $at]] 707 set options [_getTextMarkerOptions $style] 708 if { $options != "" } { 709 eval $g marker configure $id $options 710 } 711 } 712 } 713 } 658 714 } 659 715 … … 1316 1372 } 1317 1373 1374 1375 # ---------------------------------------------------------------------- 1376 # USAGE: _getLineMarkerOptions <style> 1377 # 1378 # Used internally to create a list of configuration options specific to the 1379 # axis line marker. The input is a list of name value pairs. Options that 1380 # are not recognized are ignored. 1381 # ---------------------------------------------------------------------- 1382 itcl::body Rappture::XyResult::_getLineMarkerOptions {style} { 1383 array set lineOptions { 1384 "-color" "-outline" 1385 "-dashes" "-dashes" 1386 "-linecolor" "-outline" 1387 "-linewidth" "-linewidth" 1388 } 1389 set options {} 1390 foreach {name value} $style { 1391 if { [info exists lineOptions($name)] } { 1392 lappend options $lineOptions($name) $value 1393 } 1394 } 1395 return $options 1396 } 1397 1398 # ---------------------------------------------------------------------- 1399 # USAGE: _getTextMarkerOptions <style> 1400 # 1401 # Used internally to create a list of configuration options specific to the 1402 # axis text marker. The input is a list of name value pairs. Options that 1403 # are not recognized are ignored. 1404 # ---------------------------------------------------------------------- 1405 itcl::body Rappture::XyResult::_getTextMarkerOptions {style} { 1406 array set textOptions { 1407 "-color" "-outline" 1408 "-textcolor" "-outline" 1409 "-font" "-font" 1410 "-xoffset" "-xoffset" 1411 "-yoffset" "-yoffset" 1412 "-anchor" "-anchor" 1413 } 1414 set options {} 1415 foreach {name value} $style { 1416 if { [info exists textOptions($name)] } { 1417 lappend options $textOptions($name) $value 1418 } 1419 } 1420 return $options 1421 } 1422 1318 1423 # ---------------------------------------------------------------------- 1319 1424 # USAGE: _getAxes <curveObj> … … 1374 1479 } 1375 1480 } 1481 1482 itcl::body Rappture::XyResult::_enterMarker { g name x y text } { 1483 _leaveMarker $g $name 1484 set id [$g marker create text \ 1485 -coords [list $x $y] \ 1486 -yoffset -1 \ 1487 -anchor s \ 1488 -text $text] 1489 set _markers($name) $id 1490 } 1491 1492 itcl::body Rappture::XyResult::_leaveMarker { g name } { 1493 if { [info exists _markers($name)] } { 1494 set id $_markers($name) 1495 $g marker delete $id 1496 unset _markers($name) 1497 } 1498 }
Note: See TracChangeset
for help on using the changeset viewer.