Changeset 3029 for branches/blt4/gui/scripts/vtkcontourviewer.tcl
- Timestamp:
- Jun 10, 2012, 9:04:26 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/blt4/gui/scripts/vtkcontourviewer.tcl
r3026 r3029 32 32 vtkvis_server Rappture::VtkContourViewer::SetServerList 33 33 } 34 35 34 itcl::class Rappture::VtkContourViewer { 36 35 inherit Rappture::VisViewer … … 65 64 66 65 protected method Connect {} 67 protected method CurrentDatasets { {what -all}}66 protected method CurrentDatasets { args } 68 67 protected method Disconnect {} 69 68 protected method DoResize {} 70 69 protected method FixLegend {} 71 protected method FixSettings {what {value ""}} 70 protected method InitSettings { args } 71 protected method AdjustSetting {what {value ""}} 72 72 protected method Pan {option x y} 73 73 protected method Pick {x y} … … 75 75 protected method ReceiveDataset { args } 76 76 protected method ReceiveImage { args } 77 protected method DrawLegend { }77 protected method DrawLegend { name } 78 78 protected method ReceiveLegend { colormap title vmin vmax size } 79 79 protected method Rotate {option x y} … … 89 89 # The following methods are only used by this class. 90 90 private method BuildCameraTab {} 91 private method BuildColormap { name colors } 92 private method BuildDownloadPopup { widget command } 91 93 private method BuildViewTab {} 92 private method BuildColormap { colormap dataobj comp } 94 private method ChangeColormap { dataobj comp color } 95 private method ColorsToColormap { color } 96 private method FieldMenu { option } 97 private method EnterLegend { x y } 93 98 private method EventuallyResize { w h } 94 99 private method EventuallyResizeLegend { } 95 private method SetStyles { dataobj comp }96 private method PanCamera {}97 100 private method GetImage { args } 98 101 private method GetVtkData { args } 99 private method BuildDownloadPopup { widget command } 102 private method LeaveLegend {} 103 private method MotionLegend { x y } 104 private method PanCamera {} 105 private method SetColormap { dataobj comp } 106 private method SetLegendTip { x y } 107 private method SetObjectStyle { dataobj comp } 100 108 101 109 private variable _arcball "" … … 113 121 # dataobj-components using the tf. 114 122 123 private variable _style ;# Array of current component styles. 115 124 private variable _click ;# info used for rotate operations 116 125 private variable _limits ;# autoscale min/max for all axes 117 126 private variable _view ;# view params for 3D view 118 private common_settings127 private variable _settings 119 128 # Array of transfer functions in server. If 0 the transfer has been 120 129 # defined but not loaded. If 1 the transfer function has been named … … 132 141 private variable _resizeLegendPending 0 133 142 private variable _outline 143 private variable _title "" 144 private variable _currentField "" 145 private variable _scalarFields {} 146 private variable _fields 147 private variable _afterId -1 134 148 } 135 149 … … 137 151 keep -background -foreground -cursor -font 138 152 keep -plotbackground -plotforeground 153 } 154 itk::usual BltComboButton { 155 keep -background -foreground -cursor -font 139 156 } 140 157 … … 197 214 198 215 array set _settings [subst { 199 $this-axes 1 200 $this-edges 0 201 $this-lighting 1 202 $this-opacity 100 203 $this-volume 1 204 $this-isolines 1 205 $this-wireframe 0 206 $this-legend 1 207 $this-colormap 1 216 axes 1 217 edges 0 218 lighting 1 219 opacity 100 220 volume 1 221 isolines 1 222 wireframe 0 223 legend-visible 1 224 contour-field "" 225 contour-palette BCGYR 226 colormap 1 208 227 }] 209 228 210 229 itk_component add view { 211 230 canvas $itk_component(plotarea).view \ 212 -highlightthickness 0 -borderwidth 0 231 -highlightthickness 0 -borderwidth 0 -background black 213 232 } { 214 233 usual 215 234 ignore -highlightthickness -borderwidth -background 216 235 } 217 236 itk_component add fieldmenu { 237 blt::combomenu $itk_component(plotarea).menu -bg black \ 238 -fg white -relief flat \ 239 -textvariable [itcl::scope _currentField] \ 240 -command [itcl::code $this FieldMenu invoke] 241 } { 242 usual 243 ignore -background -foreground -relief 244 } 218 245 set c $itk_component(view) 219 246 bind $c <Configure> [itcl::code $this EventuallyResize %w %h] … … 275 302 Rappture::Tooltip::for $itk_component(zoomout) "Zoom out" 276 303 277 BuildViewTab 304 if { [catch BuildViewTab errs] != 0 } { 305 puts stderr "errs=$errs" 306 } 278 307 BuildCameraTab 279 308 280 # Legend281 282 309 set _image(legend) [image create picture] 283 itk_component add legend { 284 canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0 285 } { 286 usual 287 ignore -highlightthickness 288 rename -background -plotbackground plotBackground Background 289 } 290 bind $itk_component(legend) <Configure> \ 310 bind $itk_component(plotarea) <Configure> \ 291 311 [itcl::code $this EventuallyResizeLegend] 292 312 … … 297 317 pack forget $itk_component(view) 298 318 blt::table $itk_component(plotarea) \ 299 0,0 $itk_component(view) -fill both -reqwidth $w \ 300 1,0 $itk_component(legend) -fill x 301 blt::table $itk_component(plotarea) \ 302 0,0 $itk_component(view) -fill both -reqwidth $w \ 303 0,1 $itk_component(legend) -fill y 304 blt::table configure $itk_component(plotarea) c1 -resize none 305 306 if 0 { 307 bind $itk_component(view) <Configure> \ 308 [itcl::code $this EventuallyResize %w %h] 309 } 319 0,0 $itk_component(view) -fill both -reqwidth $w 320 310 321 # Bindings for panning via mouse 311 322 bind $itk_component(view) <ButtonPress-2> \ … … 367 378 image delete $_image(legend) 368 379 image delete $_image(download) 369 array unset _settings $this-*380 array unset _settings 370 381 catch { blt::arcball destroy $_arcball} 371 382 } 372 383 373 384 itcl::body Rappture::VtkContourViewer::DoResize {} { 374 if { $_width < 2 } { 375 set _width 500 385 set w [expr $_width - 12] 386 if { $w < 2 } { 387 set w 500 376 388 } 377 389 if { $_height < 2 } { 378 390 set _height 500 379 391 } 380 SendCmd "screen size $ _width$_height"381 if { $_settings( $this-legend) } {382 EventuallyResizeLegend392 SendCmd "screen size $w $_height" 393 if { $_settings(legend-visible) } { 394 FixLegend 383 395 } 384 396 set _resizePending 0 … … 707 719 $_image(plot) configure -data $bytes 708 720 #puts stderr "received image [image width $_image(plot)]x[image height $_image(plot)] image>" 721 #puts stderr "w=[winfo width $itk_component(view)]" 709 722 } elseif { $info(type) == "print" } { 710 723 set tag $this-print-$info(-token) … … 721 734 # ---------------------------------------------------------------------- 722 735 itcl::body Rappture::VtkContourViewer::FixLegend {} { 723 puts stderr "FixLegend _first=$_first" 724 set _resizeLegendPending 0 725 set lineht [font metrics $itk_option(-font) -linespace] 726 set c $itk_component(legend) 727 set w 20 728 set h [expr {[winfo height $itk_component(view)] - 2 * ($lineht+2)}] 729 puts stderr "in fixlegend w=$w h=$h" 736 set font "Arial 8" 737 set lineht [font metrics $font -linespace] 738 set c $itk_component(view) 739 set w 12 740 set h [expr {$_height - 3 * ($lineht + 2)}] 741 if { $h < 1} { 742 return 743 } 730 744 if {$w > 0 && $h > 0 && $_first != "" } { 731 set tag [lindex [CurrentDatasets] 0] 732 puts stderr "tag=$tag [info exists _dataset2style($tag)]" 745 set tag [lindex [CurrentDatasets -all] 0] 746 puts stderr "field=$_settings(contour-field) title=$_currentField" 747 set name $_settings(contour-field) 733 748 if { [info exists _dataset2style($tag)] } { 734 SendCmd "legend $_dataset2style($tag) scalar {} $w $h 0" 735 } 736 } else { 737 #$itk_component(legend) delete all 749 set colormap $_dataset2style($tag) 750 SendCmd "legend $colormap scalar ${name} {} $w $h 0" 751 SendCmd "heightmap colormap $colormap $tag" 752 } 753 foreach dataset [CurrentDatasets -all] { 754 SendCmd "dataset scalar ${name} $dataset" 755 SendCmd "dataset visible on $dataset" 756 SendCmd "dataset outline on $dataset" 757 } 738 758 } 739 759 } … … 745 765 # of the contour plot area. 746 766 # 747 itcl::body Rappture::VtkContourViewer::DrawLegend { } {748 set c $itk_component( legend)767 itcl::body Rappture::VtkContourViewer::DrawLegend { name } { 768 set c $itk_component(view) 749 769 set w [winfo width $c] 750 770 set h [winfo height $c] 751 puts stderr "DrawLegend w=$w h=$h" 771 set font "Arial 8" 772 set lineht [font metrics $font -linespace] 773 if { [info exists _fields($name)] } { 774 foreach { title units } $_fields($name) break 775 if { $units != "" } { 776 set title [format "%s (%s)" $title $units] 777 } 778 } else { 779 set title $name 780 } 781 if { $_settings(legend-visible) } { 782 set x [expr $w - 2] 783 if { [$c find withtag "legend"] == "" } { 784 set y 2 785 $c create text $x $y \ 786 -anchor ne \ 787 -fill $itk_option(-plotforeground) -tags "title legend" \ 788 -font $font 789 incr y $lineht 790 $c create text $x $y \ 791 -anchor ne \ 792 -fill $itk_option(-plotforeground) -tags "vmax legend" \ 793 -font $font 794 incr y $lineht 795 $c create image $x $y \ 796 -anchor ne \ 797 -image $_image(legend) -tags "colormap legend" 798 $c create text $x [expr {$h-2}] \ 799 -anchor se \ 800 -fill $itk_option(-plotforeground) -tags "vmin legend" \ 801 -font $font 802 $c bind colormap <Leave> [itcl::code $this LeaveLegend] 803 $c bind colormap <Motion> [itcl::code $this MotionLegend %x %y] 804 } 805 $c bind title <ButtonPress> [itcl::code $this FieldMenu post] 806 $c bind title <Enter> [itcl::code $this FieldMenu activate] 807 $c bind title <Leave> [itcl::code $this FieldMenu deactivate] 808 # Reset the item coordinates according the current size of the plot. 809 $c itemconfigure title -text $title 810 if { $_limits(vmin) != "" } { 811 $c itemconfigure vmin -text [format %g $_limits(vmin)] 812 } 813 if { $_limits(vmax) != "" } { 814 $c itemconfigure vmax -text [format %g $_limits(vmax)] 815 } 816 set y 2 817 $c coords title $x $y 818 incr y $lineht 819 $c coords vmax $x $y 820 incr y $lineht 821 $c coords colormap $x $y 822 $c coords vmin $x [expr {$h - 2}] 823 } 824 } 825 826 if 0 { 827 # 828 # DrawLegend -- 829 # 830 # Draws the legend in it's own canvas which resides to the right 831 # of the contour plot area. 832 # 833 itcl::body Rappture::VtkContourViewer::DrawLegend {} { 834 set c $itk_component(view) 835 set w [winfo width $c] 836 set h [winfo height $c] 837 #puts stderr "DrawLegend w=$w h=$h" 752 838 set lineht [font metrics $itk_option(-font) -linespace] 753 839 754 if { $_settings( $this-legend) } {840 if { $_settings(legend-visible) } { 755 841 if { [$c find withtag "legend"] == "" } { 756 842 $c create image [expr {$w-2}] [expr {$lineht+2}] -anchor ne \ … … 775 861 } 776 862 } 863 } 777 864 778 865 # ---------------------------------------------------------------------- … … 791 878 } 792 879 $_image(legend) configure -data $bytes 793 puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>" 794 DrawLegend 880 set _limits(vmin) $vmin 881 set _limits(vmax) $vmax 882 #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>" 883 set _title $title 884 DrawLegend $title 795 885 } 796 886 } … … 810 900 "world" { 811 901 foreach { x y z value tag } [lrange $args 2 end] break 812 puts stderr "world x=$x y=$y z=$z value=$value tag=$tag"902 #puts stderr "world x=$x y=$y z=$z value=$value tag=$tag" 813 903 } 814 904 "pixel" { 815 905 foreach { x y value tag } [lrange $args 2 end] break 816 puts stderr "pixel x=$x y=$y value=$value tag=$tag"906 #puts stderr "pixel x=$x y=$y value=$value tag=$tag" 817 907 } 818 908 } … … 823 913 "world" { 824 914 foreach { x y z vx vy vz tag } [lrange $args 2 end] break 825 puts stderr "world x=$x y=$y z=$z value=$vx $xy $vz tag=$tag"915 #puts stderr "world x=$x y=$y z=$z value=$vx $xy $vz tag=$tag" 826 916 } 827 917 "pixel" { 828 918 foreach { x y vx vy vz tag } [lrange $args 2 end] break 829 puts stderr "pixel x=$x y=$y value=$vx $xy $vz tag=$tag"919 #puts stderr "pixel x=$x y=$y value=$vx $xy $vz tag=$tag" 830 920 } 831 921 } … … 833 923 "names" { 834 924 foreach { name } [lindex $args 1] { 835 puts stderr "Dataset: $name"925 #puts stderr "Dataset: $name" 836 926 } 837 927 } … … 850 940 # ---------------------------------------------------------------------- 851 941 itcl::body Rappture::VtkContourViewer::Rebuild {} { 852 853 942 # Turn on buffering of commands to the server. We don't want to 854 943 # be preempted by a server disconnect/reconnect (which automatically … … 874 963 append _outbuf "dataset add $tag data follows $length\n" 875 964 append _outbuf $bytes 876 append _outbuf "heightmap add numcontours [expr {$style(-levels)+1}] 0 $tag\n" 877 SetStyles $dataobj $comp 965 SetObjectStyle $dataobj $comp 878 966 set _datasets($tag) 1 879 967 foreach {min max} [$dataobj limits v] break … … 902 990 SendCmd "camera zoom $_view(zoom)" 903 991 } 904 FixSettings opacity 905 FixSettings isolines 906 FixSettings colormap 907 FixSettings lighting 908 FixSettings wireframe 909 FixSettings axes 910 FixSettings edges 992 993 InitSettings opacity isolines colormap lighting wireframe axes edges 911 994 912 995 # Nothing to send -- activate the proper ivol 913 foreach tag [CurrentDatasets ] {996 foreach tag [CurrentDatasets -all] { 914 997 SendCmd "dataset visible 0 $tag" 915 998 } … … 925 1008 } 926 1009 } 927 1010 1011 if { $_currentField == "" && $_first != "" } { 1012 $itk_component(fieldmenu) delete all 1013 $itk_component(fieldmenu2) delete all 1014 array unset _fields 1015 set _scalarFields [$_first hints scalars] 1016 foreach { name title units } $_scalarFields { 1017 $itk_component(fieldmenu) add \ 1018 -type radiobutton -text "$title" -value $name \ 1019 -variable [itcl::scope _settings(contour-field)] 1020 $itk_component(fieldmenu2) add \ 1021 -text "$title" -value $name \ 1022 -variable [itcl::scope _settings(contour-field)] 1023 set _fields($name) [list $title $units] 1024 } 1025 set fld [$_first hints default] 1026 if { $fld == "" } { 1027 set fld [lindex $_scalarFields 0] 1028 } 1029 foreach { name title units } $_scalarFields { 1030 if { $fld == $name } { 1031 set _settings(contour-field) $name 1032 set _currentField $title 1033 break 1034 } 1035 } 1036 } 928 1037 FixLegend 929 1038 … … 939 1048 940 1049 # ---------------------------------------------------------------------- 941 # USAGE: CurrentDatasets ?- cutplanes?1050 # USAGE: CurrentDatasets ?-all -visible? ?dataobjs? 942 1051 # 943 1052 # Returns a list of server IDs for the current datasets being displayed. This … … 945 1054 # object has multiple components. 946 1055 # ---------------------------------------------------------------------- 947 itcl::body Rappture::VtkContourViewer::CurrentDatasets {{what -all}} { 1056 itcl::body Rappture::VtkContourViewer::CurrentDatasets {args} { 1057 set flag [lindex $args 0] 1058 switch -- $flag { 1059 "-all" { 1060 if { [llength $args] > 1 } { 1061 error "CurrentDatasets: can't specify dataobj after \"-all\"" 1062 } 1063 set dlist [get -objects] 1064 } 1065 "-visible" { 1066 if { [llength $args] > 1 } { 1067 set dlist {} 1068 set args [lrange $args 1 end] 1069 foreach dataobj $args { 1070 if { [info exists _obj2ovride($dataobj-raise)] } { 1071 lappend dlist $dataobj 1072 } 1073 } 1074 } else { 1075 set dlist [get] 1076 } 1077 } 1078 default { 1079 set dlist $args 1080 } 1081 } 948 1082 set rlist "" 949 if { $_first == "" } { 950 return 951 } 952 foreach comp [$_first components] { 953 set tag $_first-$comp 954 if { [info exists _datasets($tag)] && $_datasets($tag) } { 955 lappend rlist $tag 1083 foreach dataobj $dlist { 1084 foreach comp [$dataobj components] { 1085 set tag $dataobj-$comp 1086 if { [info exists _datasets($tag)] && $_datasets($tag) } { 1087 lappend rlist $tag 1088 } 956 1089 } 957 1090 } … … 1109 1242 } 1110 1243 1111 # ---------------------------------------------------------------------- 1112 # USAGE: FixSettings <what> ?<value>? 1244 1245 # ---------------------------------------------------------------------- 1246 # USAGE: InitSettings <what> ?<value>? 1113 1247 # 1114 1248 # Used internally to update rendering settings whenever parameters … … 1116 1250 # to the back end. 1117 1251 # ---------------------------------------------------------------------- 1118 itcl::body Rappture::VtkContourViewer::FixSettings {what {value ""}} { 1252 itcl::body Rappture::VtkContourViewer::InitSettings { args } { 1253 foreach spec $args { 1254 if { [info exists _settings($_first-$spec)] } { 1255 # Reset global setting with dataobj specific setting 1256 set _settings($spec) $_settings($_first-$spec) 1257 } 1258 AdjustSetting $spec 1259 } 1260 } 1261 1262 # ---------------------------------------------------------------------- 1263 # USAGE: AdjustSetting <what> ?<value>? 1264 # 1265 # Used internally to update rendering settings whenever parameters 1266 # change in the popup settings panel. Sends the new settings off 1267 # to the back end. 1268 # ---------------------------------------------------------------------- 1269 itcl::body Rappture::VtkContourViewer::AdjustSetting {what {value ""}} { 1119 1270 switch -- $what { 1120 1271 "opacity" { 1121 1272 if {[isconnected]} { 1122 set val $_settings( $this-opacity)1273 set val $_settings(opacity) 1123 1274 set sval [expr { 0.01 * double($val) }] 1124 foreach dataset [CurrentDatasets ] {1275 foreach dataset [CurrentDatasets -all] { 1125 1276 SendCmd "heightmap opacity $sval $dataset" 1126 1277 } … … 1129 1280 "wireframe" { 1130 1281 if {[isconnected]} { 1131 set bool $_settings( $this-wireframe)1132 foreach dataset [CurrentDatasets ] {1282 set bool $_settings(wireframe) 1283 foreach dataset [CurrentDatasets -all] { 1133 1284 SendCmd "heightmap wireframe $bool $dataset" 1134 1285 } … … 1137 1288 "colormap" { 1138 1289 if {[isconnected]} { 1139 set bool $_settings( $this-colormap)1140 foreach dataset [CurrentDatasets ] {1290 set bool $_settings(colormap) 1291 foreach dataset [CurrentDatasets -all] { 1141 1292 SendCmd "heightmap surface $bool $dataset" 1142 1293 } … … 1145 1296 "isolines" { 1146 1297 if {[isconnected]} { 1147 set bool $_settings( $this-isolines)1148 foreach dataset [CurrentDatasets ] {1298 set bool $_settings(isolines) 1299 foreach dataset [CurrentDatasets -all] { 1149 1300 SendCmd "heightmap isolines $bool $dataset" 1150 1301 } … … 1153 1304 "edges" { 1154 1305 if {[isconnected]} { 1155 set bool $_settings( $this-edges)1156 foreach dataset [CurrentDatasets ] {1306 set bool $_settings(edges) 1307 foreach dataset [CurrentDatasets -all] { 1157 1308 SendCmd "heightmap edges $bool $dataset" 1158 1309 } … … 1161 1312 "lighting" { 1162 1313 if {[isconnected]} { 1163 set bool $_settings( $this-lighting)1164 foreach dataset [CurrentDatasets ] {1314 set bool $_settings(lighting) 1315 foreach dataset [CurrentDatasets -all] { 1165 1316 SendCmd "heightmap lighting $bool $dataset" 1166 1317 } … … 1169 1320 "axes" { 1170 1321 if { [isconnected] } { 1171 set bool $_settings( $this-axes)1322 set bool $_settings(axes) 1172 1323 SendCmd "axis visible all $bool" 1173 1324 } 1174 1325 } 1175 1326 "legend" { 1176 if { $_settings($this-legend) } { 1177 blt::table $itk_component(plotarea) \ 1178 0,0 $itk_component(view) -fill both \ 1179 0,1 $itk_component(legend) -fill y 1180 blt::table configure $itk_component(plotarea) c1 -resize none 1181 } else { 1182 blt::table forget $itk_component(legend) 1183 } 1327 if { !$_settings(legend-visible) } { 1328 $itk_component(view) delete legend 1329 } 1330 DrawLegend $_settings(contour-field) 1331 } 1332 "contour-palette" { 1333 puts stderr "newpalette is $_settings(contour-palette)" 1334 foreach dataset [CurrentDatasets -visible $_first] { 1335 foreach {dataobj comp} [split $dataset -] break 1336 ChangeColormap $dataobj $comp $_settings(contour-palette) 1337 } 1338 set _legendPending 1 1339 } 1340 "contour-field" { 1341 foreach { name title units } $_scalarFields { 1342 if { $name == $_settings(contour-field) } { 1343 DrawLegend $name 1344 foreach dataset [CurrentDatasets -visible] { 1345 SendCmd "dataset scalar ${name} $dataset" 1346 SendCmd "cutplane colormode scalar ${name} $dataset" 1347 } 1348 set _legendPending 1 1349 break 1350 } 1351 } 1184 1352 } 1185 1353 default { 1186 error "don't know how to fix $what" 1187 } 1188 } 1189 } 1190 1191 1192 # 1193 # SetStyles -- 1194 # 1195 itcl::body Rappture::VtkContourViewer::SetStyles { dataobj comp } { 1196 array set style { 1197 -color rainbow 1198 -levels 6 1199 -opacity 1.0 1200 } 1201 set tag $dataobj-$comp 1202 array set style [lindex [$dataobj components -style $comp] 0] 1203 set colormap "$style(-color):$style(-levels):$style(-opacity)" 1204 if { [info exists _colormaps($colormap)] } { 1205 puts stderr "Colormap $colormap already built" 1206 } 1207 if { ![info exists _dataset2style($tag)] } { 1208 set _dataset2style($tag) $colormap 1209 lappend _style2datasets($colormap) $tag 1210 } 1211 if { ![info exists _colormaps($colormap)] } { 1212 # Build the pseudo colormap if it doesn't exist. 1213 BuildColormap $colormap $dataobj $comp 1214 set _colormaps($colormap) 1 1215 } 1216 #SendCmd "heightmap numcontours $style(-levels) $tag\n" 1217 SendCmd "heightmap colormap $colormap $tag" 1218 return $colormap 1219 } 1220 1221 # 1222 # BuildColormap -- 1223 # 1224 itcl::body Rappture::VtkContourViewer::BuildColormap { colormap dataobj comp } { 1225 puts stderr "BuildColormap $colormap" 1226 array set style { 1227 -color rainbow 1228 -levels 6 1229 -opacity 1.0 1230 } 1231 array set style [lindex [$dataobj components -style $comp] 0] 1232 1233 if {$style(-color) == "rainbow"} { 1234 set style(-color) "white:yellow:green:cyan:blue:magenta" 1235 } 1236 set clist [split $style(-color) :] 1237 set cmap {} 1238 for {set i 0} {$i < [llength $clist]} {incr i} { 1239 set x [expr {double($i)/([llength $clist]-1)}] 1240 set color [lindex $clist $i] 1241 append cmap "$x [Color2RGB $color] " 1242 } 1243 if { [llength $cmap] == 0 } { 1244 set cmap "0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0" 1245 } 1246 set tag $this-$colormap 1247 if { ![info exists _settings($tag-opacity)] } { 1248 set _settings($tag-opacity) $style(-opacity) 1249 } 1250 set max $_settings($tag-opacity) 1251 1252 set wmap "0.0 1.0 1.0 1.0" 1253 SendCmd "colormap add $colormap { $cmap } { $wmap }" 1354 error "unknown setting \"$what\": should be one of [array names _settings]" 1355 } 1356 } 1254 1357 } 1255 1358 … … 1318 1421 checkbutton $inner.axes \ 1319 1422 -text "Axes" \ 1320 -variable [itcl::scope _settings( $this-axes)] \1321 -command [itcl::code $this FixSettingsaxes] \1423 -variable [itcl::scope _settings(axes)] \ 1424 -command [itcl::code $this AdjustSetting axes] \ 1322 1425 -font "Arial 9" 1323 1426 1324 1427 checkbutton $inner.colormap \ 1325 1428 -text "Colormap" \ 1326 -variable [itcl::scope _settings( $this-colormap)] \1327 -command [itcl::code $this FixSettingscolormap] \1429 -variable [itcl::scope _settings(colormap)] \ 1430 -command [itcl::code $this AdjustSetting colormap] \ 1328 1431 -font "Arial 9" 1329 1432 1330 1433 checkbutton $inner.isolines \ 1331 1434 -text "Isolines" \ 1332 -variable [itcl::scope _settings( $this-isolines)] \1333 -command [itcl::code $this FixSettingsisolines] \1435 -variable [itcl::scope _settings(isolines)] \ 1436 -command [itcl::code $this AdjustSetting isolines] \ 1334 1437 -font "Arial 9" 1335 1438 1336 1439 checkbutton $inner.wireframe \ 1337 1440 -text "Wireframe" \ 1338 -variable [itcl::scope _settings( $this-wireframe)] \1339 -command [itcl::code $this FixSettingswireframe] \1441 -variable [itcl::scope _settings(wireframe)] \ 1442 -command [itcl::code $this AdjustSetting wireframe] \ 1340 1443 -font "Arial 9" 1341 1444 1342 1445 checkbutton $inner.lighting \ 1343 1446 -text "Lighting" \ 1344 -variable [itcl::scope _settings( $this-lighting)] \1345 -command [itcl::code $this FixSettingslighting] \1447 -variable [itcl::scope _settings(lighting)] \ 1448 -command [itcl::code $this AdjustSetting lighting] \ 1346 1449 -font "Arial 9" 1347 1450 1348 1451 checkbutton $inner.legend \ 1349 1452 -text "Legend" \ 1350 -variable [itcl::scope _settings( $this-legend)] \1351 -command [itcl::code $this FixSettingslegend] \1453 -variable [itcl::scope _settings(legend-visible)] \ 1454 -command [itcl::code $this AdjustSetting legend] \ 1352 1455 -font "Arial 9" 1353 1456 1354 1457 checkbutton $inner.edges \ 1355 1458 -text "Edges" \ 1356 -variable [itcl::scope _settings( $this-edges)] \1357 -command [itcl::code $this FixSettingsedges] \1459 -variable [itcl::scope _settings(edges)] \ 1460 -command [itcl::code $this AdjustSetting edges] \ 1358 1461 -font "Arial 9" 1359 1462 1360 1463 label $inner.clear -text "Clear" -font "Arial 9" 1361 1464 ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ 1362 -variable [itcl::scope _settings( $this-opacity)] \1465 -variable [itcl::scope _settings(opacity)] \ 1363 1466 -width 10 \ 1364 -showvalue off -command [itcl::code $this FixSettingsopacity]1467 -showvalue off -command [itcl::code $this AdjustSetting opacity] 1365 1468 label $inner.opaque -text "Opaque" -font "Arial 9" 1469 1470 label $inner.field_l -text "Field" -font "Arial 9" 1471 blt::comboentry $inner.field -width 10 \ 1472 -menu $inner.field.menu \ 1473 -textvariable [itcl::scope _currentField] \ 1474 -edit no 1475 itk_component add fieldmenu2 { 1476 blt::combomenu $inner.field.menu \ 1477 -textvariable [itcl::scope _currentField] \ 1478 -command [itcl::code $this FieldMenu invoke] 1479 } { 1480 usual 1481 ignore -background 1482 } 1483 label $inner.palette_l -text "Palette" -font "Arial 9" 1484 blt::comboentry $inner.palette -width 10 \ 1485 -menu $inner.palette.menu \ 1486 -textvariable [itcl::scope _settings(contour-palette)] \ 1487 -edit no 1488 set palettes { 1489 "BCGYR" 1490 "BGYOR" 1491 "blue" 1492 "blue-to-brown" 1493 "blue-to-orange" 1494 "blue-to-grey" 1495 "green-to-magenta" 1496 "greyscale" 1497 "nanohub" 1498 "rainbow" 1499 "spectral" 1500 "ROYGB" 1501 "RYGCB" 1502 "brown-to-blue" 1503 "grey-to-blue" 1504 "orange-to-blue" 1505 } 1506 blt::combomenu $inner.palette.menu \ 1507 -textvariable [itcl::scope _settings(contour-palette)] \ 1508 -command [itcl::code $this AdjustSetting contour-palette] \ 1509 -yscrollbar $inner.palette.menu.ybar \ 1510 -height { 0 1.2i } 1511 1512 blt::tk::scrollbar $inner.palette.menu.ybar 1513 1514 $inner.palette.menu listadd $palettes 1366 1515 1367 1516 blt::table $inner \ … … 1375 1524 7,0 $inner.clear -anchor e -pady 2 \ 1376 1525 7,1 $inner.opacity -columnspan 2 -pady 2 -fill x\ 1377 7,3 $inner.opaque -anchor w -pady 2 1526 7,3 $inner.opaque -anchor w -pady 2 \ 1527 8,0 $inner.field_l -anchor e -pady 2 \ 1528 8,1 $inner.field -cspan 3 -anchor w -pady 2 -fill x \ 1529 9,0 $inner.palette_l -anchor e -pady 2 \ 1530 9,1 $inner.palette -cspan 3 -fill x -pady 2 1378 1531 1379 1532 blt::table configure $inner r* -resize none 1380 blt::table configure $inner r 8-resize expand1533 blt::table configure $inner r10 -resize expand 1381 1534 } 1382 1535 … … 1615 1768 } 1616 1769 1770 1771 1772 # 1773 # EnterLegend -- 1774 # 1775 itcl::body Rappture::VtkContourViewer::EnterLegend { x y } { 1776 SetLegendTip $x $y 1777 } 1778 1779 # 1780 # MotionLegend -- 1781 # 1782 itcl::body Rappture::VtkContourViewer::MotionLegend { x y } { 1783 Rappture::Tooltip::tooltip cancel 1784 set c $itk_component(view) 1785 after cancel $_afterId 1786 set _afterId [after 50 [itcl::code $this SetLegendTip $x $y]] 1787 } 1788 1789 # 1790 # LeaveLegend -- 1791 # 1792 itcl::body Rappture::VtkContourViewer::LeaveLegend { } { 1793 Rappture::Tooltip::tooltip cancel 1794 after cancel $_afterId 1795 .rappturetooltip configure -icon "" 1796 } 1797 1798 # 1799 # SetLegendTip -- 1800 # 1801 itcl::body Rappture::VtkContourViewer::SetLegendTip { x y } { 1802 set c $itk_component(view) 1803 set w [winfo width $c] 1804 set h [winfo height $c] 1805 set font "Arial 8" 1806 set lineht [font metrics $font -linespace] 1807 1808 set imgHeight [image height $_image(legend)] 1809 set coords [$c coords colormap] 1810 set imgX [expr $w - [image width $_image(legend)] - 2] 1811 set imgY [expr $y - 2 * ($lineht + 2)] 1812 1813 set units "" 1814 if { [info exists _fields($_title)] } { 1815 foreach { title units } $_fields($_title) break 1816 } 1817 # Make a swatch of the selected color 1818 if { [catch { $_image(legend) get 10 $imgY } pixel] != 0 } { 1819 puts stderr "out of range: $imgY" 1820 return 1821 } 1822 if { ![info exists _image(swatch)] } { 1823 set _image(swatch) [image create picture -width 24 -height 24] 1824 } 1825 #set color [eval format "\#%02x%02x%02x" $pixel] 1826 $_image(swatch) blank white 1827 $_image(swatch) draw rectangle 3 3 20 20 -color $pixel -shadow 1 1828 $_image(swatch) draw rectangle 3 3 20 20 -color black -linewidth 1 1829 .rappturetooltip configure -icon $_image(swatch) 1830 1831 # Compute the value of the point 1832 if { [info exists _limits(vmax)] && [info exists _limits(vmin)] } { 1833 set t [expr 1.0 - (double($imgY) / double($imgHeight-1))] 1834 set value [expr $t * ($_limits(vmax) - $_limits(vmin)) + $_limits(vmin)] 1835 } else { 1836 set value 0.0 1837 } 1838 set tipx [expr $x + 15] 1839 set tipy [expr $y - 5] 1840 Rappture::Tooltip::text $c "$value$units" 1841 Rappture::Tooltip::tooltip show $c +$tipx,+$tipy 1842 } 1843 1844 1845 1846 # ---------------------------------------------------------------------- 1847 # USAGE: _dropdown post 1848 # USAGE: _dropdown unpost 1849 # USAGE: _dropdown select 1850 # 1851 # Used internally to handle the dropdown list for this combobox. The 1852 # post/unpost options are invoked when the list is posted or unposted 1853 # to manage the relief of the controlling button. The select option 1854 # is invoked whenever there is a selection from the list, to assign 1855 # the value back to the gauge. 1856 # ---------------------------------------------------------------------- 1857 itcl::body Rappture::VtkContourViewer::FieldMenu {option} { 1858 set c $itk_component(view) 1859 set m $itk_component(fieldmenu) 1860 switch -- $option { 1861 post { 1862 foreach { x1 y1 x2 y2 } [$c bbox title] break 1863 set x1 [expr [winfo width $c] - [winfo reqwidth $m]] 1864 set x [expr $x1 + [winfo rootx $c]] 1865 set y [expr $y2 + [winfo rooty $c]] 1866 blt::ComboMenu::popup $m $x $y 1867 } 1868 activate { 1869 $c itemconfigure title -fill red 1870 } 1871 deactivate { 1872 $c itemconfigure title -fill white 1873 } 1874 invoke { 1875 set value [$itk_component(fieldmenu) item cget $_currentField -value] 1876 set _$_settings(contour-field) $value 1877 $itk_component(view) itemconfigure title -text $_currentField 1878 FixLegend 1879 AdjustSetting contour-field 1880 } 1881 default { 1882 error "bad option \"$option\": should be post, unpost, select" 1883 } 1884 } 1885 } 1886 1887 1888 # 1889 # ChangeColormap -- 1890 # 1891 itcl::body Rappture::VtkContourViewer::ChangeColormap {dataobj comp color} { 1892 set tag $dataobj-$comp 1893 if { ![info exist _style($tag)] } { 1894 error "no initial colormap" 1895 } 1896 array set style $_style($tag) 1897 set style(-color) $color 1898 set _style($tag) [array get style] 1899 SetColormap $dataobj $comp 1900 FixLegend 1901 } 1902 1903 # 1904 # SetColormap -- 1905 # 1906 itcl::body Rappture::VtkContourViewer::SetColormap { dataobj comp } { 1907 array set style { 1908 -color BGYOR 1909 -levels 6 1910 -opacity 1.0 1911 } 1912 set tag $dataobj-$comp 1913 if { ![info exists _initialStyle($tag)] } { 1914 # Save the initial component style. 1915 set _initialStyle($tag) [$dataobj style $comp] 1916 } 1917 1918 # Override defaults with initial style defined in xml. 1919 array set style $_initialStyle($tag) 1920 1921 if { ![info exists _style($tag)] } { 1922 set _style($tag) [array get style] 1923 } 1924 # Override initial style with current style. 1925 array set style $_style($tag) 1926 1927 set name "$style(-color):$style(-levels):$style(-opacity)" 1928 if { ![info exists _colormaps($name)] } { 1929 BuildColormap $name [array get style] 1930 set _colormaps($name) 1 1931 } 1932 SendCmd "heightmap colormap $name $tag" 1933 SendCmd "heightmap add numcontours [expr {$style(-levels)+1}] 0 $tag" 1934 if { ![info exists _dataset2style($tag)] || 1935 $_dataset2style($tag) != $name } { 1936 set _dataset2style($tag) $name 1937 } 1938 } 1939 1940 1941 itcl::body Rappture::VtkContourViewer::ColorsToColormap { colors } { 1942 switch -- $colors { 1943 "grey-to-blue" { 1944 return { 1945 0.0 0.200 0.200 0.200 1946 0.14285714285714285 0.400 0.400 0.400 1947 0.2857142857142857 0.600 0.600 0.600 1948 0.42857142857142855 0.900 0.900 0.900 1949 0.5714285714285714 0.800 1.000 1.000 1950 0.7142857142857143 0.600 1.000 1.000 1951 0.8571428571428571 0.400 0.900 1.000 1952 1.0 0.000 0.600 0.800 1953 } 1954 } 1955 "blue-to-grey" { 1956 return { 1957 0.0 0.000 0.600 0.800 1958 0.14285714285714285 0.400 0.900 1.000 1959 0.2857142857142857 0.600 1.000 1.000 1960 0.42857142857142855 0.800 1.000 1.000 1961 0.5714285714285714 0.900 0.900 0.900 1962 0.7142857142857143 0.600 0.600 0.600 1963 0.8571428571428571 0.400 0.400 0.400 1964 1.0 0.200 0.200 0.200 1965 } 1966 } 1967 "blue" { 1968 return { 1969 0.0 0.900 1.000 1.000 1970 0.1111111111111111 0.800 0.983 1.000 1971 0.2222222222222222 0.700 0.950 1.000 1972 0.3333333333333333 0.600 0.900 1.000 1973 0.4444444444444444 0.500 0.833 1.000 1974 0.5555555555555556 0.400 0.750 1.000 1975 0.6666666666666666 0.300 0.650 1.000 1976 0.7777777777777778 0.200 0.533 1.000 1977 0.8888888888888888 0.100 0.400 1.000 1978 1.0 0.000 0.250 1.000 1979 } 1980 } 1981 "brown-to-blue" { 1982 return { 1983 0.0 0.200 0.100 0.000 1984 0.09090909090909091 0.400 0.187 0.000 1985 0.18181818181818182 0.600 0.379 0.210 1986 0.2727272727272727 0.800 0.608 0.480 1987 0.36363636363636365 0.850 0.688 0.595 1988 0.45454545454545453 0.950 0.855 0.808 1989 0.5454545454545454 0.800 0.993 1.000 1990 0.6363636363636364 0.600 0.973 1.000 1991 0.7272727272727273 0.400 0.940 1.000 1992 0.8181818181818182 0.200 0.893 1.000 1993 0.9090909090909091 0.000 0.667 0.800 1994 1.0 0.000 0.480 0.600 1995 } 1996 } 1997 "blue-to-brown" { 1998 return { 1999 0.0 0.000 0.480 0.600 2000 0.09090909090909091 0.000 0.667 0.800 2001 0.18181818181818182 0.200 0.893 1.000 2002 0.2727272727272727 0.400 0.940 1.000 2003 0.36363636363636365 0.600 0.973 1.000 2004 0.45454545454545453 0.800 0.993 1.000 2005 0.5454545454545454 0.950 0.855 0.808 2006 0.6363636363636364 0.850 0.688 0.595 2007 0.7272727272727273 0.800 0.608 0.480 2008 0.8181818181818182 0.600 0.379 0.210 2009 0.9090909090909091 0.400 0.187 0.000 2010 1.0 0.200 0.100 0.000 2011 } 2012 } 2013 "blue-to-orange" { 2014 return { 2015 0.0 0.000 0.167 1.000 2016 0.09090909090909091 0.100 0.400 1.000 2017 0.18181818181818182 0.200 0.600 1.000 2018 0.2727272727272727 0.400 0.800 1.000 2019 0.36363636363636365 0.600 0.933 1.000 2020 0.45454545454545453 0.800 1.000 1.000 2021 0.5454545454545454 1.000 1.000 0.800 2022 0.6363636363636364 1.000 0.933 0.600 2023 0.7272727272727273 1.000 0.800 0.400 2024 0.8181818181818182 1.000 0.600 0.200 2025 0.9090909090909091 1.000 0.400 0.100 2026 1.0 1.000 0.167 0.000 2027 } 2028 } 2029 "orange-to-blue" { 2030 return { 2031 0.0 1.000 0.167 0.000 2032 0.09090909090909091 1.000 0.400 0.100 2033 0.18181818181818182 1.000 0.600 0.200 2034 0.2727272727272727 1.000 0.800 0.400 2035 0.36363636363636365 1.000 0.933 0.600 2036 0.45454545454545453 1.000 1.000 0.800 2037 0.5454545454545454 0.800 1.000 1.000 2038 0.6363636363636364 0.600 0.933 1.000 2039 0.7272727272727273 0.400 0.800 1.000 2040 0.8181818181818182 0.200 0.600 1.000 2041 0.9090909090909091 0.100 0.400 1.000 2042 1.0 0.000 0.167 1.000 2043 } 2044 } 2045 "rainbow" { 2046 set clist { 2047 "#EE82EE" 2048 "#4B0082" 2049 "blue" 2050 "#008000" 2051 "yellow" 2052 "#FFA500" 2053 "red" 2054 } 2055 } 2056 "BGYOR" { 2057 set clist { 2058 "blue" 2059 "#008000" 2060 "yellow" 2061 "#FFA500" 2062 "red" 2063 } 2064 } 2065 "ROYGB" { 2066 set clist { 2067 "red" 2068 "#FFA500" 2069 "yellow" 2070 "#008000" 2071 "blue" 2072 } 2073 } 2074 "RYGCB" { 2075 set clist { 2076 "red" 2077 "yellow" 2078 "green" 2079 "cyan" 2080 "blue" 2081 } 2082 } 2083 "BCGYR" { 2084 set clist { 2085 "blue" 2086 "cyan" 2087 "green" 2088 "yellow" 2089 "red" 2090 } 2091 } 2092 "spectral" { 2093 return { 2094 0.0 0.150 0.300 1.000 2095 0.1 0.250 0.630 1.000 2096 0.2 0.450 0.850 1.000 2097 0.3 0.670 0.970 1.000 2098 0.4 0.880 1.000 1.000 2099 0.5 1.000 1.000 0.750 2100 0.6 1.000 0.880 0.600 2101 0.7 1.000 0.680 0.450 2102 0.8 0.970 0.430 0.370 2103 0.9 0.850 0.150 0.196 2104 1.0 0.650 0.000 0.130 2105 } 2106 } 2107 "green-to-magenta" { 2108 return { 2109 0.0 0.000 0.316 0.000 2110 0.06666666666666667 0.000 0.526 0.000 2111 0.13333333333333333 0.000 0.737 0.000 2112 0.2 0.000 0.947 0.000 2113 0.26666666666666666 0.316 1.000 0.316 2114 0.3333333333333333 0.526 1.000 0.526 2115 0.4 0.737 1.000 0.737 2116 0.4666666666666667 1.000 1.000 1.000 2117 0.5333333333333333 1.000 0.947 1.000 2118 0.6 1.000 0.737 1.000 2119 0.6666666666666666 1.000 0.526 1.000 2120 0.7333333333333333 1.000 0.316 1.000 2121 0.8 0.947 0.000 0.947 2122 0.8666666666666667 0.737 0.000 0.737 2123 0.9333333333333333 0.526 0.000 0.526 2124 1.0 0.316 0.000 0.316 2125 } 2126 } 2127 "greyscale" { 2128 return { 2129 0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0 2130 } 2131 } 2132 "nanohub" { 2133 set clist "white yellow green cyan blue magenta" 2134 } 2135 default { 2136 set clist $colors 2137 } 2138 } 2139 set cmap {} 2140 for {set i 0} {$i < [llength $clist]} {incr i} { 2141 set x [expr {double($i)/([llength $clist]-1)}] 2142 set color [lindex $clist $i] 2143 append cmap "$x [Color2RGB $color] " 2144 } 2145 return $cmap 2146 } 2147 2148 # 2149 # BuildColormap -- 2150 # 2151 itcl::body Rappture::VtkContourViewer::BuildColormap { name styles } { 2152 array set style $styles 2153 set cmap [ColorsToColormap $style(-color)] 2154 if { [llength $cmap] == 0 } { 2155 set cmap "0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0" 2156 } 2157 if { ![info exists _settings(contour-opacity)] } { 2158 set _settings(contour-opacity) $style(-opacity) 2159 } 2160 set max $_settings(contour-opacity) 2161 2162 set wmap "0.0 1.0 1.0 1.0" 2163 SendCmd "colormap add $name { $cmap } { $wmap }" 2164 } 2165 2166 2167 itcl::body Rappture::VtkContourViewer::SetObjectStyle { dataobj comp } { 2168 # Parse style string. 2169 set tag $dataobj-$comp 2170 set style [$dataobj style $comp] 2171 array set settings { 2172 -color \#808080 2173 -edgecolor black 2174 -edges 0 2175 -lighting 1 2176 -linewidth 1.0 2177 -opacity 0.4 2178 -seedcolor white 2179 -seeds 1 2180 -visible 1 2181 -wireframe 0 2182 } 2183 if { $dataobj != $_first } { 2184 set settings(-opacity) 1 2185 } 2186 array set settings $style 2187 SendCmd "heightmap add numcontours 7 0 $tag" 2188 SendCmd "heightmap linecolor 1. 1. 1. $tag" 2189 SendCmd "heightmap isolinecolor 1. 1. 1. $tag" 2190 SendCmd "heightmap linewidth 1 $tag" 2191 SendCmd "heightmap isolinewidth 2 $tag" 2192 SendCmd "heightmap visible $tag" 2193 SendCmd "heightmap lighting on $tag" 2194 set _settings(contour-wireframe) $settings(-wireframe) 2195 set _settings(contour-opacity) [expr $settings(-opacity) * 100.0] 2196 SetColormap $dataobj $comp 2197 }
Note: See TracChangeset
for help on using the changeset viewer.