Changeset 5642 for trunk/gui/scripts
- Timestamp:
- May 31, 2015, 5:06:46 PM (9 years ago)
- Location:
- trunk/gui/scripts
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/flowvisviewer.tcl
r5612 r5642 129 129 private variable _dlist "" ;# list of data objects 130 130 private variable _obj2ovride ;# maps dataobj => style override 131 private variable _ serverDatasets;# contains all the dataobj-component131 private variable _datasets ;# contains all the dataobj-component 132 132 ;# to volumes in the server 133 private variable _recvdDatasets ;# list of data objs to send to server134 133 private variable _dataset2style ;# maps dataobj-component to transfunc 135 134 private variable _style2datasets ;# maps tf back to list of … … 223 222 $_arcball quaternion [ViewToQuaternion] 224 223 225 set _limits(v) [list 0.0 1.0]226 224 set _reset 1 227 225 … … 593 591 # ---------------------------------------------------------------------- 594 592 itcl::body Rappture::FlowvisViewer::add {dataobj {settings ""}} { 593 if { ![$dataobj isvalid] } { 594 return; # Object doesn't contain valid data. 595 } 595 596 array set params { 596 597 -color auto … … 698 699 if { $pos >= 0 } { 699 700 set _dlist [lreplace $_dlist $pos $pos] 700 array unset _limits $dataobj-*701 701 array unset _obj2ovride $dataobj-* 702 array unset _dataset2flow $dataobj-*703 array unset _serverDatasets $dataobj-*704 array unset _dataset2style $dataobj-*705 702 set changed 1 706 703 } … … 708 705 # If anything changed, then rebuild the plot 709 706 if {$changed} { 710 # Repair the reverse lookup711 foreach tf [array names _style2datasets] {712 set list {}713 foreach {dataobj cname} $_style2datasets($tf) break714 if { [info exists _serverDatasets($dataobj-$cname)] } {715 lappend list $dataobj $cname716 }717 if { $list == "" } {718 array unset _style2datasets $tf719 } else {720 set _style2datasets($tf) $list721 }722 }723 707 $_dispatcher event -idle !rebuild 724 708 } … … 758 742 set _limits($cname) $limits(v) 759 743 } 760 foreach axis {x y z v} {744 foreach axis {x y z} { 761 745 foreach { min max } [$dataobj limits $axis] break 762 746 if {"" != $min && "" != $max} { … … 834 818 } 835 819 default { 836 error "bad download format $_downloadPopup(format)"820 error "bad download format \"$_downloadPopup(format)\"" 837 821 } 838 822 } … … 917 901 918 902 # disconnected -- no more data sitting on server 919 array unset _ serverDatasets903 array unset _datasets 920 904 } 921 905 … … 967 951 array set info $args 968 952 set bytes [ReceiveBytes $info(-bytes)] 969 ReceiveEcho <<line "<read $info(-bytes) bytes" 970 switch -- $info(-type) { 953 switch -- $info(-type) { 971 954 "image" { 955 #puts stderr "received image [image width $_image(plot)]x[image height $_image(plot)]" 972 956 $_image(plot) configure -data $bytes 973 #puts stderr "image received [image width $_image(plot)] by [image height $_image(plot)]"974 957 } 975 958 "print" { … … 982 965 } 983 966 default { 984 puts stderr "unknown downloadtype $info(-type)"967 puts stderr "unknown image type $info(-type)" 985 968 } 986 969 } … … 1058 1041 # The procedure is the response from the render server to each "data 1059 1042 # follows" command. The server sends back a "data" command invoked our 1060 # the slave interpreter. The purpose is to collect the min/max of the 1061 # volume sent to the render server. Since the client (flowvisviewer) 1062 # doesn't parse 3D data formats, we rely on the server (nanovis) to 1063 # tell us what the limits are. Once we've received the limits to all 1064 # the data we've sent (tracked by _recvdDatasets) we can then determine 1065 # what the transfer functions are for these volumes. 1066 # 1067 # 1068 # Note: There is a considerable tradeoff in having the server report 1069 # back what the data limits are. It means that much of the code 1070 # having to do with transfer-functions has to wait for the data 1071 # to come back, since the isomarkers are calculated based upon 1072 # the data limits. The client code is much messier because of 1073 # this. The alternative is to parse any of the 3D formats on the 1074 # client side. 1043 # the slave interpreter. The purpose was to collect the min/max of the 1044 # volume sent to the render server. This is no longer needed since we 1045 # already know the limits. 1075 1046 # 1076 1047 itcl::body Rappture::FlowvisViewer::ReceiveData { args } { … … 1083 1054 1084 1055 set tag $info(tag) 1085 set parts [split $tag -]1086 1087 #1088 # Volumes don't exist until we're told about them.1089 #1090 set dataobj [lindex $parts 0]1091 set _serverDatasets($tag) 01092 1056 set _limits($tag) [list $info(min) $info(max)] 1093 1094 unset _recvdDatasets($tag)1095 if { [array size _recvdDatasets] == 0 } {1096 updateTransferFunctions1097 }1098 1057 } 1099 1058 … … 1136 1095 1137 1096 set _first "" 1138 foreach dataobj [get] { 1097 foreach dataobj [get -objects] { 1098 if { [info exists _obj2ovride($dataobj-raise)] && $_first == "" } { 1099 set _first $dataobj 1100 } 1139 1101 foreach cname [$dataobj components] { 1140 1102 set tag $dataobj-$cname 1141 if {[$dataobj type] == "dx"} { 1142 set data [$dataobj blob $cname] 1143 } else { 1144 set data [$dataobj vtkdata $cname] 1145 } 1146 set nbytes [string length $data] 1147 if { $_reportClientInfo } { 1148 set info {} 1149 lappend info "tool_id" [$dataobj hints toolid] 1150 lappend info "tool_name" [$dataobj hints toolname] 1151 lappend info "tool_title" [$dataobj hints tooltitle] 1152 lappend info "tool_command" [$dataobj hints toolcommand] 1153 lappend info "tool_revision" [$dataobj hints toolrevision] 1154 lappend info "dataset_label" [$dataobj hints label] 1155 lappend info "dataset_size" $nbytes 1156 lappend info "dataset_tag" $tag 1157 SendCmd "clientinfo [list $info]" 1158 } 1159 set numComponents [$dataobj numComponents $cname] 1160 # I have a field. Is a vector field or a volume field? 1161 if { $numComponents == 1 } { 1162 SendCmd "volume data follows $nbytes $tag" 1163 } else { 1164 if {[SendFlowCmd $dataobj $cname $nbytes $numComponents] < 0} { 1165 continue 1103 if { ![info exists _datasets($tag)] } { 1104 if { [$dataobj type] == "dx" } { 1105 set data [$dataobj blob $cname] 1106 } else { 1107 set data [$dataobj vtkdata $cname] 1166 1108 } 1167 } 1168 SendData $data 1169 NameTransferFunction $dataobj $cname 1170 set _recvdDatasets($tag) 1 1171 } 1172 } 1173 1174 set _first [lindex [get] 0] 1109 set nbytes [string length $data] 1110 if { $_reportClientInfo } { 1111 set info {} 1112 lappend info "tool_id" [$dataobj hints toolid] 1113 lappend info "tool_name" [$dataobj hints toolname] 1114 lappend info "tool_title" [$dataobj hints tooltitle] 1115 lappend info "tool_command" [$dataobj hints toolcommand] 1116 lappend info "tool_revision" [$dataobj hints toolrevision] 1117 lappend info "dataset_label" [$dataobj hints label] 1118 lappend info "dataset_size" $nbytes 1119 lappend info "dataset_tag" $tag 1120 SendCmd "clientinfo [list $info]" 1121 } 1122 set numComponents [$dataobj numComponents $cname] 1123 # I have a field. Is a vector field or a volume field? 1124 if { $numComponents == 1 } { 1125 SendCmd "volume data follows $nbytes $tag" 1126 } else { 1127 if {[SendFlowCmd $dataobj $cname $nbytes $numComponents] < 0} { 1128 continue 1129 } 1130 } 1131 SendData $data 1132 set _datasets($tag) 1 1133 NameTransferFunction $dataobj $cname 1134 } 1135 } 1136 } 1175 1137 1176 1138 # Turn off cutplanes for all volumes … … 1179 1141 } 1180 1142 1181 # Reset the camera and other view parameters 1182 InitSettings -axesvisible -gridvisible \ 1183 -opacity -light2side -isosurfaceshading \ 1184 -ambient -diffuse -specularlevel -specularexponent \ 1185 -volume -outlinevisible -cutplanesvisible \ 1143 InitSettings -volume -outlinevisible -cutplanesvisible \ 1186 1144 -xcutplanevisible -ycutplanevisible -zcutplanevisible \ 1187 1145 -xcutplaneposition -ycutplaneposition -zcutplaneposition 1188 1146 1189 # nothing to send -- activate the proper volume 1147 if { $_reset } { 1148 InitSettings -axesvisible -gridvisible \ 1149 -opacity -light2side -isosurfaceshading \ 1150 -ambient -diffuse -specularlevel -specularexponent 1151 1152 # 1153 # Reset the camera and other view parameters 1154 # 1155 if {"" != $_first} { 1156 set axis [$_first hints updir] 1157 if { "" != $axis } { 1158 SendCmd "up $axis" 1159 } 1160 set location [$_first hints camera] 1161 if { $location != "" } { 1162 array set _view $location 1163 } 1164 } 1165 set _settings(-qw) $_view(-qw) 1166 set _settings(-qx) $_view(-qx) 1167 set _settings(-qy) $_view(-qy) 1168 set _settings(-qz) $_view(-qz) 1169 set _settings(-xpan) $_view(-xpan) 1170 set _settings(-ypan) $_view(-ypan) 1171 set _settings(-zoom) $_view(-zoom) 1172 1173 set q [ViewToQuaternion] 1174 $_arcball quaternion $q 1175 SendCmd "camera orient $q" 1176 SendCmd "camera reset" 1177 PanCamera 1178 SendCmd "camera zoom $_view(-zoom)" 1179 } 1180 1190 1181 if {"" != $_first} { 1191 set axis [$_first hints updir]1192 if {"" != $axis} {1193 SendCmd "up $axis"1194 }1195 set location [$_first hints camera]1196 if { $location != "" } {1197 array set _view $location1198 }1199 }1200 set _settings(-qw) $_view(-qw)1201 set _settings(-qx) $_view(-qx)1202 set _settings(-qy) $_view(-qy)1203 set _settings(-qz) $_view(-qz)1204 set _settings(-xpan) $_view(-xpan)1205 set _settings(-ypan) $_view(-ypan)1206 set _settings(-zoom) $_view(-zoom)1207 1208 set q [ViewToQuaternion]1209 $_arcball quaternion $q1210 SendCmd "camera orient $q"1211 SendCmd "camera reset"1212 PanCamera1213 SendCmd "camera zoom $_view(-zoom)"1214 1215 foreach dataobj [get] {1216 foreach cname [$dataobj components] {1217 NameTransferFunction $dataobj $cname1218 }1219 }1220 1221 # nothing to send -- activate the proper ivol1222 set _first [lindex [get] 0]1223 if {"" != $_first} {1224 set axis [$_first hints updir]1225 if {"" != $axis} {1226 SendCmd "up $axis"1227 }1228 set location [$_first hints camera]1229 if { $location != "" } {1230 array set _view $location1231 }1232 1182 set cname [lindex [$_first components] 0] 1233 1183 set _activeTf [lindex $_dataset2style($_first-$cname) 0] 1234 } 1235 1236 # sync the state of slicers 1237 set vols [CurrentDatasets -cutplanes] 1238 foreach axis {x y z} { 1239 set pos [expr {0.01*$_settings(-${axis}cutplaneposition)}] 1240 SendCmd "cutplane position $pos $axis $vols" 1241 } 1242 SendCmd "volume data state $_settings(-volume)" 1243 EventuallyRedrawLegend 1184 # Make sure we display the proper transfer function in the legend. 1185 updateTransferFunctions 1186 } 1244 1187 1245 1188 # Actually write the commands to the server socket. If it fails, we don't … … 1259 1202 # ---------------------------------------------------------------------- 1260 1203 itcl::body Rappture::FlowvisViewer::CurrentDatasets {{what -all}} { 1261 return""1204 set rlist "" 1262 1205 if { $_first == "" } { 1263 1206 return 1264 1207 } 1265 foreach tag [array names _serverDatasets *-*] { 1266 if {[string match $_first-* $tag]} { 1208 foreach cname [$_first components] { 1209 set tag $_first-$cname 1210 if { [info exists _datasets($tag)] && $_datasets($tag) } { 1267 1211 array set style { 1268 1212 -cutplanes 1 1269 1213 } 1270 foreach {dataobj cname} [split $tag -] break 1271 array set style [lindex [$dataobj components -style $cname] 0] 1272 if {$what != "-cutplanes" || $style(-cutplanes)} { 1273 lappend rlist $_serverDatasets($tag) 1214 array set style [lindex [$_first components -style $cname] 0] 1215 if { $what != "-cutplanes" || $style(-cutplanes) } { 1216 lappend rlist $tag 1274 1217 } 1275 1218 } … … 1943 1886 1944 1887 itcl::body Rappture::FlowvisViewer::limits { cname } { 1945 set _limits(v) [list 0.0 1.0] 1946 if { ![info exists _style2datasets($cname)] } { 1947 puts stderr "no _style2datasets for cname=($cname)" 1948 return [array get _limits] 1949 } 1950 set min ""; set max "" 1951 foreach tag [GetDatasetsWithComponent $cname] { 1952 if { ![info exists _serverDatasets($tag)] } { 1953 puts stderr "$tag not in _serverDatasets?" 1954 continue 1955 } 1956 if { ![info exists _limits($tag)] } { 1957 puts stderr "$tag no min?" 1958 continue 1959 } 1960 foreach {vmin vmax} $_limits($tag) break 1961 if { $min == "" || $min > $vmin } { 1962 set min $vmin 1963 } 1964 if { $max == "" || $max < $vmax } { 1965 set max $vmax 1966 } 1967 } 1968 if { $min != "" && $max != "" } { 1969 set _limits(v) [list $min $max] 1970 set _limits($cname) [list $min $max] 1888 if { ![info exists _limits($cname)] } { 1889 puts stderr "no limits for cname=($cname)" 1890 return [list 0.0 1.0] 1971 1891 } 1972 1892 return $_limits($cname) … … 3022 2942 set list "" 3023 2943 foreach tag $_volcomponents($cname) { 3024 if { ![info exists _ serverDatasets($tag)] } {2944 if { ![info exists _datasets($tag)] } { 3025 2945 continue 3026 2946 } -
trunk/gui/scripts/nanovisviewer.tcl
r5562 r5642 121 121 private variable _dlist "" ;# list of data objects 122 122 private variable _obj2ovride ;# maps dataobj => style override 123 private variable _ serverDatasets;# contains all the dataobj-component123 private variable _datasets ;# contains all the dataobj-component 124 124 ;# to volumes in the server 125 private variable _recvdDatasets ;# list of data objs to send to server126 125 127 126 private variable _reset 1 ;# Connection to server has been reset. … … 196 195 $_arcball quaternion [ViewToQuaternion] 197 196 198 set _limits(v) [list 0.0 1.0]199 197 set _reset 1 200 198 … … 345 343 bind $itk_component(3dview) <ButtonRelease-1> \ 346 344 [itcl::code $this Rotate release %x %y] 345 347 346 bind $itk_component(3dview) <Configure> \ 348 347 [itcl::code $this EventuallyResize %w %h] … … 563 562 set _limits($cname) $limits(v) 564 563 } 565 foreach axis {x y z v} {564 foreach axis {x y z} { 566 565 foreach { min max } [$dataobj limits $axis] break 567 566 if {"" != $min && "" != $max} { … … 632 631 return [$this GetVtkData [lindex $args 0]] 633 632 } 634 } 635 return "" 633 default { 634 error "bad download format \"$_downloadPopup(format)\"" 635 } 636 } 636 637 } 637 638 default { … … 714 715 715 716 # disconnected -- no more data sitting on server 716 array unset _ serverDatasets717 array unset _datasets 717 718 } 718 719 … … 742 743 array set info $args 743 744 set bytes [ReceiveBytes $info(-bytes)] 744 ReceiveEcho <<line "<read $info(-bytes) bytes" 745 if { $info(-type) == "image" } { 746 ReceiveEcho "for [image width $_image(plot)]x[image height $_image(plot)] image>" 747 $_image(plot) configure -data $bytes 748 } elseif { $info(-type) == "print" } { 749 set tag $this-print-$info(-token) 750 set _hardcopy($tag) $bytes 745 switch -- $info(-type) { 746 "image" { 747 #puts stderr "received image [image width $_image(plot)]x[image height $_image(plot)]" 748 $_image(plot) configure -data $bytes 749 } 750 "print" { 751 set tag $this-print-$info(-token) 752 set _hardcopy($tag) $bytes 753 } 754 default { 755 puts stderr "unknown image type $info(-type)" 756 } 751 757 } 752 758 } … … 836 842 # The procedure is the response from the render server to each "data 837 843 # follows" command. The server sends back a "data" command invoked our 838 # the slave interpreter. The purpose is to collect the min/max of the 839 # volume sent to the render server. Since the client (nanovisviewer) 840 # doesn't parse 3D data formats, we rely on the server (nanovis) to 841 # tell us what the limits are. Once we've received the limits to all 842 # the data we've sent (tracked by _recvdDatasets) we can then determine 843 # what the transfer functions are for these volumes. 844 # 845 # 846 # Note: There is a considerable tradeoff in having the server report 847 # back what the data limits are. It means that much of the code 848 # having to do with transfer-functions has to wait for the data 849 # to come back, since the isomarkers are calculated based upon 850 # the data limits. The client code is much messier because of 851 # this. The alternative is to parse any of the 3D formats on the 852 # client side. 844 # the slave interpreter. The purpose was to collect the min/max of the 845 # volume sent to the render server. This is no longer needed since we 846 # already know the limits. 853 847 # 854 848 itcl::body Rappture::NanovisViewer::ReceiveData { args } { … … 861 855 862 856 set tag $info(tag) 863 set parts [split $tag -] 864 865 # 866 # Volumes don't exist until we're told about them. 867 # 868 set dataobj [lindex $parts 0] 869 set _serverDatasets($tag) 1 870 if { $_settings(-volumevisible) && $dataobj == $_first } { 871 SendCmd "volume state 1 $tag" 872 } 873 set _limits($tag) [list $info(min) $info(max)] 874 set _limits(v) [list $info(vmin) $info(vmax)] 875 876 unset _recvdDatasets($tag) 877 if { [array size _recvdDatasets] == 0 } { 878 updateTransferFunctions 879 } 857 set _limits($tag) [list $info(min) $info(max)] 880 858 } 881 859 … … 908 886 } 909 887 910 foreach dataobj [get] { 888 set _first "" 889 SendCmd "volume state 0" 890 foreach dataobj [get -objects] { 891 if { [info exists _obj2ovride($dataobj-raise)] && $_first == "" } { 892 set _first $dataobj 893 } 911 894 foreach cname [$dataobj components] { 912 895 set tag $dataobj-$cname 913 if { ![info exists _serverDatasets($tag)] } { 914 # Send the data as one huge base64-encoded mess -- yuck! 896 if { ![info exists _datasets($tag)] } { 915 897 if { [$dataobj type] == "dx" } { 916 if { ![$dataobj isvalid] } {917 puts stderr "??? $dataobj is invalid"918 }919 898 set data [$dataobj blob $cname] 920 899 } else { … … 942 921 SendCmd "volume data follows $nbytes $tag" 943 922 SendData $data 944 set _recvdDatasets($tag) 1 945 set _serverDatasets($tag) 0 923 set _datasets($tag) 1 946 924 } 947 925 SetObjectStyle $dataobj $cname 948 } 949 } 950 set _first [lindex [get] 0] 926 if { [info exists _obj2ovride($dataobj-raise)] } { 927 SendCmd "volume state 1 $tag" 928 } 929 } 930 } 951 931 # Outline seems to need to be reset every update. 952 932 InitSettings -outlinevisible -cutplanesvisible 953 933 if { $_reset } { 934 # Turn off cutplanes for all volumes 935 foreach axis {x y z} { 936 SendCmd "cutplane state 0 $axis" 937 } 938 939 InitSettings -axesvisible -gridvisible \ 940 -light2side -isosurfaceshading -opacity \ 941 -ambient -diffuse -specularlevel -specularexponent \ 942 -xcutplanevisible -ycutplanevisible -zcutplanevisible \ 943 -current 944 954 945 # 955 946 # Reset the camera and other view parameters 956 947 # 948 if {"" != $_first} { 949 set axis [$_first hints updir] 950 if { "" != $axis } { 951 SendCmd "up $axis" 952 } 953 set location [$_first hints camera] 954 if { $location != "" } { 955 array set _view $location 956 } 957 } 957 958 set _settings(-qw) $_view(-qw) 958 959 set _settings(-qx) $_view(-qx) … … 969 970 PanCamera 970 971 SendCmd "camera zoom $_view(-zoom)" 971 972 # Turn off cutplanes for all volumes 973 foreach axis {x y z} { 974 SendCmd "cutplane state 0 $axis" 975 } 976 977 InitSettings -axesvisible -gridvisible \ 978 -light2side -isosurfaceshading -opacity \ 979 -ambient -diffuse -specularlevel -specularexponent \ 980 -xcutplanevisible -ycutplanevisible -zcutplanevisible \ 981 -current 982 983 if {"" != $_first} { 984 set axis [$_first hints updir] 985 if { "" != $axis } { 986 SendCmd "up $axis" 987 } 988 set location [$_first hints camera] 989 if { $location != "" } { 990 array set _view $location 991 } 992 } 993 } 994 995 # nothing to send -- activate the proper ivol 996 SendCmd "volume state 0" 972 } 973 997 974 if {"" != $_first} { 998 set datasets [array names _serverDatasets $_first-*] 999 if { $datasets != "" } { 1000 SendCmd "volume state 1 $datasets" 1001 } 1002 # If the first volume already exists on the server, then make sure 1003 # we display the proper transfer function in the legend. 1004 set cname [lindex [$_first components] 0] 1005 if { [info exists _serverDatasets($_first-$cname)] } { 1006 updateTransferFunctions 1007 } 975 # Make sure we display the proper transfer function in the legend. 976 updateTransferFunctions 1008 977 } 1009 978 # Actually write the commands to the server socket. If it fails, we don't … … 1029 998 foreach cname [$_first components] { 1030 999 set tag $_first-$cname 1031 if { [info exists _ serverDatasets($tag)] && $_serverDatasets($tag) } {1000 if { [info exists _datasets($tag)] && $_datasets($tag) } { 1032 1001 array set style { 1033 1002 -cutplanes 1 … … 1338 1307 "-volume" { 1339 1308 # This is the global volume visibility control. It controls the 1340 # visibility of all the all volumes. Whenever it's changed, you 1341 # have to synchronize each of the local controls (see below) with 1342 # this. 1309 # visibility of all the volumes. Whenever it's changed, you have 1310 # to synchronize each of the local controls (see below) with this. 1343 1311 set datasets [CurrentDatasets] 1344 1312 set bool $_settings($what) … … 2219 2187 set list "" 2220 2188 foreach tag $_volcomponents($cname) { 2221 if { ![info exists _ serverDatasets($tag)] } {2189 if { ![info exists _datasets($tag)] } { 2222 2190 continue 2223 2191 }
Note: See TracChangeset
for help on using the changeset viewer.