Changeset 2466 for trunk/gui/scripts
- Timestamp:
- Sep 4, 2011, 11:13:10 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/vtkviewer.tcl
r2464 r2466 68 68 protected method Disconnect {} 69 69 protected method DoResize {} 70 protected method FixSettings {what {value ""}} 70 protected method AdjustSetting {what {value ""}} 71 protected method FixSettings { args } 71 72 protected method Pan {option x y} 72 73 protected method Pick {x y} … … 74 75 protected method ReceiveDataset { args } 75 76 protected method ReceiveImage { args } 77 protected method ReceiveLegend { args } 76 78 protected method Rotate {option x y} 77 79 protected method SendCmd {string} … … 79 81 80 82 # The following methods are only used by this class. 83 private method BuildAxisTab {} 81 84 private method BuildCameraTab {} 85 private method BuildColormap { colormap dataobj comp } 86 private method BuildDownloadPopup { widget command } 87 private method BuildStreamsTab {} 82 88 private method BuildVolumeTab {} 83 private method BuildStreamsTab {} 84 private method BuildAxisTab {} 85 private method BuildColormap { colormap dataobj comp } 89 private method ConvertToVtkData { dataobj comp } 90 private method DrawLegend {} 86 91 private method EventuallyResize { w h } 87 private method SetStyles { dataobj comp }88 private method PanCamera {}89 private method ConvertToVtkData { dataobj comp }90 92 private method GetImage { args } 91 93 private method GetVtkData { args } 92 private method BuildDownloadPopup { widget command } 94 private method IsValidObject { dataobj } 95 private method PanCamera {} 93 96 private method SetObjectStyle { dataobj comp } 94 private method IsValidObject { dataobj } 97 private method SetStyles { dataobj comp } 98 private method RequestLegend {} 95 99 96 100 private variable _arcball "" … … 116 120 # to starting position. 117 121 private variable _haveStreams 0 118 # Array of transfer functions in server. If 0 the transfer has been 119 # defined but not loaded. If 1 the transfer function has been named 120 # and loaded. 122 121 123 private variable _first "" ;# This is the topmost dataset. 122 124 private variable _start 0 123 125 private variable _buffering 0 124 126 125 # This indicates which isomarkers and transfer function to use when126 # changing markers, opacity, or thickness.127 127 common _downloadPopup ;# download options from popup 128 128 private common _hardcopy … … 157 157 $_parser alias image [itcl::code $this ReceiveImage] 158 158 $_parser alias dataset [itcl::code $this ReceiveDataset] 159 $_parser alias legend [itcl::code $this ReceiveLegend] 159 160 160 161 array set _outline { … … 181 182 $_arcball quaternion $q 182 183 183 set _limits( vmin) 0.0184 set _limits( vmax) 1.0184 set _limits(zmin) 0.0 185 set _limits(zmax) 1.0 185 186 186 187 array set _settings [subst { 187 188 $this-axes 1 189 $this-legend 1 188 190 $this-seeds 1 189 191 $this-streamlines 1 … … 262 264 Rappture::Tooltip::for $itk_component(zoomout) "Zoom out" 263 265 264 if { [catch { 265 BuildVolumeTab 266 BuildAxisTab 267 BuildStreamsTab 268 BuildCameraTab 269 } errs] != 0 } { 270 puts stderr err=$errs 266 BuildVolumeTab 267 BuildAxisTab 268 BuildStreamsTab 269 BuildCameraTab 270 271 # Legend 272 273 set _image(legend) [image create photo] 274 itk_component add legend { 275 canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0 276 } { 277 usual 278 ignore -highlightthickness 279 rename -background -plotbackground plotBackground Background 271 280 } 272 281 … … 354 363 image delete $_image(download) 355 364 array unset _settings $this-* 356 catch { blt::arcball destroy $_arcball }365 catch { blt::arcball destroy $_arcball } 357 366 } 358 367 … … 367 376 set _start [clock clicks -milliseconds] 368 377 SendCmd "screen size $_width $_height" 369 378 if { $_haveStreams } { 379 RequestLegend 380 } 370 381 # Must reset camera to have object scaling to take effect. 371 382 #SendCmd "camera reset" … … 547 558 foreach dataobj $args { 548 559 array set bounds [limits $dataobj] 549 puts stderr bounds=[array get bounds]550 560 if {![info exists _limits(xmin)] || $_limits(xmin) > $bounds(xmin)} { 551 561 set _limits(xmin) $bounds(xmin) … … 809 819 DoResize 810 820 811 set _limits( vmin) ""812 set _limits( vmax) ""821 set _limits(zmin) "" 822 set _limits(zmax) "" 813 823 set _first "" 814 824 set _haveStreams 0 … … 828 838 set _datasets($tag) 1 829 839 } 840 SetStyles $dataobj $comp 830 841 lappend _obj2datasets($dataobj) $tag 831 842 SetObjectStyle $dataobj $comp … … 853 864 set _reset 0 854 865 } 855 FixSettings opacity 856 FixSettings grid-x 857 FixSettings grid-y 858 FixSettings grid-z 859 FixSettings volume 860 FixSettings lighting 861 FixSettings wireframe 862 FixSettings axes 863 FixSettings edges 864 FixSettings seeds 865 FixSettings streamlines 866 FixSettings axismode 866 867 FixSettings opacity grid-x grid-y grid-z volume lighting \ 868 wireframe axes edges seeds streamlines axismode 867 869 868 870 if { !$_haveStreams } { … … 1097 1099 # to the back end. 1098 1100 # ---------------------------------------------------------------------- 1099 itcl::body Rappture::VtkViewer::FixSettings {what {value ""}} { 1101 itcl::body Rappture::VtkViewer::FixSettings { args } { 1102 foreach setting $args { 1103 AdjustSetting $setting 1104 } 1105 } 1106 1107 # 1108 # AdjustSetting -- 1109 # 1110 # Changes/updates a specific setting in the widget. There are 1111 # usually user-setable option. Commands are sent to the render 1112 # server. 1113 # 1114 itcl::body Rappture::VtkViewer::AdjustSetting {what {value ""}} { 1100 1115 if { ![isconnected] } { 1101 1116 return … … 1205 1220 1206 1221 # 1222 # RequestLegend -- 1223 # 1224 # Request a new legend from the server. The size of the legend 1225 # is determined from the height of the canvas. It will be rotated 1226 # to be vertical when drawn. 1227 # 1228 itcl::body Rappture::VtkViewer::RequestLegend {} { 1229 #puts stderr "RequestLegend _first=$_first" 1230 set lineht [font metrics $itk_option(-font) -linespace] 1231 set c $itk_component(legend) 1232 set w [expr {$_height-20}] 1233 set h 45; # Hard coding height of legend 1234 1235 if { $w == 0} { 1236 return 1237 } 1238 # Set the legend on the first streamlines dataset. 1239 foreach dataset [CurrentDatasets -visible] { 1240 foreach {dataobj comp} [split $dataset -] break 1241 if { [$dataobj type $comp] == "streamlines" && 1242 [info exists _dataset2style($dataset)] } { 1243 SendCmd "legend $_dataset2style($dataset) scalar {} $w $h" 1244 break; 1245 } 1246 } 1247 } 1248 1249 # 1207 1250 # SetStyles -- 1208 1251 # … … 1214 1257 } 1215 1258 set tag $dataobj-$comp 1216 array set style [ lindex [$dataobj components -style $comp] 0]1259 array set style [$dataobj style $comp] 1217 1260 set colormap "$style(-color):$style(-levels):$style(-opacity)" 1218 1261 if { [info exists _colormaps($colormap)] } { … … 1228 1271 set _colormaps($colormap) 1 1229 1272 } 1230 #SendCmd "p olydata add $style(-levels) $tag\n"1231 SendCmd " pseudocolorcolormap $colormap $tag"1273 #SendCmd "pseudocolor colormap $colormap $tag" 1274 SendCmd "streamlines colormap $colormap $tag" 1232 1275 return $colormap 1233 1276 } … … 1242 1285 -opacity 1.0 1243 1286 } 1244 array set style [lindex [$dataobj components -style $comp] 0] 1245 1287 array set style [$dataobj style $comp] 1246 1288 if {$style(-color) == "rainbow"} { 1247 1289 set style(-color) "white:yellow:green:cyan:blue:magenta" … … 1340 1382 -text "Visible" \ 1341 1383 -variable [itcl::scope _settings($this-volume)] \ 1342 -command [itcl::code $this FixSettingsvolume] \1384 -command [itcl::code $this AdjustSetting volume] \ 1343 1385 -font "Arial 9" 1344 1386 … … 1346 1388 -text "Wireframe" \ 1347 1389 -variable [itcl::scope _settings($this-wireframe)] \ 1348 -command [itcl::code $this FixSettingswireframe] \1390 -command [itcl::code $this AdjustSetting wireframe] \ 1349 1391 -font "Arial 9" 1350 1392 … … 1352 1394 -text "Lighting" \ 1353 1395 -variable [itcl::scope _settings($this-lighting)] \ 1354 -command [itcl::code $this FixSettingslighting] \1396 -command [itcl::code $this AdjustSetting lighting] \ 1355 1397 -font "Arial 9" 1356 1398 … … 1358 1400 -text "Edges" \ 1359 1401 -variable [itcl::scope _settings($this-edges)] \ 1360 -command [itcl::code $this FixSettingsedges] \1402 -command [itcl::code $this AdjustSetting edges] \ 1361 1403 -font "Arial 9" 1362 1404 … … 1365 1407 -variable [itcl::scope _settings($this-opacity)] \ 1366 1408 -width 10 \ 1367 -showvalue off -command [itcl::code $this FixSettingsopacity]1409 -showvalue off -command [itcl::code $this AdjustSetting opacity] 1368 1410 1369 1411 blt::table $inner \ … … 1393 1435 -text "Visible" \ 1394 1436 -variable [itcl::scope _settings($this-streamlines)] \ 1395 -command [itcl::code $this FixSettingsstreamlines] \1437 -command [itcl::code $this AdjustSetting streamlines] \ 1396 1438 -font "Arial 9" 1397 1439 … … 1399 1441 -text "Show seeds" \ 1400 1442 -variable [itcl::scope _settings($this-seeds)] \ 1401 -command [itcl::code $this FixSettingsseeds] \1443 -command [itcl::code $this AdjustSetting seeds] \ 1402 1444 -font "Arial 9" 1403 1445 … … 1414 1456 $itk_component(streammode) value "lines" 1415 1457 bind $inner.streammode_combo <<Value>> \ 1416 [itcl::code $this FixSettingsstreammode]1458 [itcl::code $this AdjustSetting streammode] 1417 1459 1418 1460 label $inner.opacity_l -text "Opacity" -font "Arial 9" … … 1420 1462 -variable [itcl::scope _settings($this-opacity)] \ 1421 1463 -width 10 \ 1422 -showvalue off -command [itcl::code $this FixSettingsopacity]1464 -showvalue off -command [itcl::code $this AdjustSetting opacity] 1423 1465 1424 1466 blt::table $inner \ … … 1447 1489 -text "Visible" \ 1448 1490 -variable [itcl::scope _settings($this-axes)] \ 1449 -command [itcl::code $this FixSettingsaxes] \1491 -command [itcl::code $this AdjustSetting axes] \ 1450 1492 -font "Arial 9" 1451 1493 … … 1455 1497 -text "X" \ 1456 1498 -variable [itcl::scope _settings($this-grid-x)] \ 1457 -command [itcl::code $this FixSettingsgrid-x] \1499 -command [itcl::code $this AdjustSetting grid-x] \ 1458 1500 -font "Arial 9" 1459 1501 checkbutton $f.y \ 1460 1502 -text "Y" \ 1461 1503 -variable [itcl::scope _settings($this-grid-y)] \ 1462 -command [itcl::code $this FixSettingsgrid-y] \1504 -command [itcl::code $this AdjustSetting grid-y] \ 1463 1505 -font "Arial 9" 1464 1506 checkbutton $f.z \ 1465 1507 -text "Z" \ 1466 1508 -variable [itcl::scope _settings($this-grid-z)] \ 1467 -command [itcl::code $this FixSettingsgrid-z] \1509 -command [itcl::code $this AdjustSetting grid-z] \ 1468 1510 -font "Arial 9" 1469 1511 pack $f.x $f.y $f.z -side left … … 1481 1523 "outer_edges" "outer" 1482 1524 $itk_component(axismode) value "outer" 1483 bind $inner.axismode_combo <<Value>> [itcl::code $this FixSettings axismode] 1525 bind $inner.axismode_combo <<Value>> \ 1526 [itcl::code $this AdjustSetting axismode] 1484 1527 1485 1528 blt::table $inner \ … … 1703 1746 return 1 1704 1747 } 1748 1749 # ---------------------------------------------------------------------- 1750 # USAGE: ReceiveLegend <colormap> <size>> 1751 # 1752 # Invoked automatically whenever the "legend" command comes in from 1753 # the rendering server. Indicates that binary image data with the 1754 # specified <size> will follow. 1755 # ---------------------------------------------------------------------- 1756 itcl::body Rappture::VtkViewer::ReceiveLegend { colormap size } { 1757 #puts stderr "ReceiveLegend colormap=$colormap size=$size" 1758 if { [IsConnected] } { 1759 set bytes [ReceiveBytes $size] 1760 if { ![info exists _image(legend)] } { 1761 set _image(legend) [image create photo] 1762 } 1763 #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>" 1764 set src [image create photo -data $bytes] 1765 blt::winop image rotate $src $_image(legend) 90 1766 set dst $_image(legend) 1767 DrawLegend 1768 } 1769 } 1770 1771 # 1772 # DrawLegend -- 1773 # 1774 # Draws the legend in it's own canvas which resides to the right 1775 # of the contour plot area. 1776 # 1777 itcl::body Rappture::VtkViewer::DrawLegend {} { 1778 set c $itk_component(view) 1779 set w [winfo width $c] 1780 set h [winfo height $c] 1781 set lineht [font metrics $itk_option(-font) -linespace] 1782 1783 if { $_settings($this-legend) } { 1784 set x 2 1785 if { [$c find withtag "legend"] == "" } { 1786 $c create image $x [expr {$lineht+2}] -anchor nw \ 1787 -image $_image(legend) -tags "transfunc legend" 1788 $c create text $x 2 -anchor nw \ 1789 -fill $itk_option(-plotforeground) -tags "zmax legend" \ 1790 -font "Arial 6" 1791 $c create text $x [expr {$h-2}] -anchor sw \ 1792 -fill $itk_option(-plotforeground) -tags "zmin legend" \ 1793 -font "Arial 6" 1794 } 1795 # Reset the item coordinates according the current size of the plot. 1796 $c coords transfunc $x [expr {$lineht+2}] 1797 if { $_limits(zmin) != "" } { 1798 $c itemconfigure zmin -text [format %g $_limits(zmin)] 1799 } 1800 if { $_limits(zmax) != "" } { 1801 $c itemconfigure zmax -text [format %g $_limits(zmax)] 1802 } 1803 $c coords zmin $x [expr {$h-2}] 1804 $c coords zmax $x 2 1805 } 1806 }
Note: See TracChangeset
for help on using the changeset viewer.