- Timestamp:
- Mar 3, 2013, 8:26:31 AM (12 years ago)
- Location:
- trunk/gui/scripts
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/vtkheightmapviewer.tcl
r3416 r3417 69 69 protected method Disconnect {} 70 70 protected method DoResize {} 71 protected method DoContour {}72 71 protected method DoRotate {} 73 72 protected method AdjustSetting {what {value ""}} … … 96 95 private method DrawLegend { title } 97 96 private method EnterLegend { x y } 98 private method EventuallyContour { numContours }99 97 private method EventuallyRequestLegend {} 100 98 private method EventuallyResize { w h } … … 153 151 private variable _height 0 154 152 private variable _resizePending 0 155 private variable _ contourPending 0153 private variable _numIsolinesPending 0 156 154 private variable _rotatePending 0 157 155 private variable _legendPending 0 … … 160 158 private variable _curFldName "" 161 159 private variable _curFldLabel "" 162 private variable _numContours 0163 160 private variable _colorMode "vmag";# Mode of colormap (vmag or scalar) 164 161 } … … 182 179 $_dispatcher register !resize 183 180 $_dispatcher dispatch $this !resize "[itcl::code $this DoResize]; list" 184 185 # Recontour event186 $_dispatcher register !contour187 $_dispatcher dispatch $this !contour "[itcl::code $this DoContour]; list"188 181 189 182 # Rotate event … … 230 223 edges 0 231 224 field "Default" 232 heightmapOpacity 100233 225 heightmapScale 50 234 226 isHeightmap 0 235 isoline s 10227 isolineColor black 236 228 isolinesVisible 1 237 isolineColor black238 229 legendVisible 1 239 lighting 0 230 lighting 1 231 saveLighting 1 232 numIsolines 10 233 opacity 100 240 234 outline 0 241 235 wireframe 0 236 saveOpacity 100 242 237 }] 243 238 … … 424 419 } 425 420 426 itcl::body Rappture::VtkHeightmapViewer::DoContour {} {427 foreach dataset [CurrentDatasets -all] {428 foreach {dataobj comp} [split $dataset -] break429 #SendCmd "heightmap numcontours $_numContours $dataset"430 }431 set _contourPending 0432 }433 434 421 itcl::body Rappture::VtkHeightmapViewer::EventuallyRequestLegend {} { 435 422 if { !$_legendPending } { … … 446 433 set _resizePending 1 447 434 $_dispatcher event -after 400 !resize 448 }449 }450 451 itcl::body Rappture::VtkHeightmapViewer::EventuallyContour { numContours } {452 set _numContours $numContours453 if { !$_contourPending } {454 set _contourPending 1455 $_dispatcher event -after 600 !contour456 435 } 457 436 } … … 752 731 $_dispatcher cancel !rebuild 753 732 $_dispatcher cancel !resize 754 $_dispatcher cancel !contour755 733 $_dispatcher cancel !rotate 756 734 $_dispatcher cancel !legend … … 1066 1044 # 1067 1045 SendCmd "axis color all [Color2RGB $itk_option(-plotforeground)]" 1046 SendCmd "dataset color [Color2RGB $itk_option(-plotforeground)]" 1068 1047 ResetAxes 1069 1048 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] … … 1081 1060 InitSettings axisXGrid axisYGrid axisZGrid \ 1082 1061 axisVisible axisLabels 1083 InitSettings heightmapOpacity \ 1084 heightmapScale lighting \ 1085 colormap field outline \ 1086 edges heightmapOpacity wireframe 1062 InitSettings opacity heightmapScale lighting edges wireframe \ 1063 colormap field outline isHeightmap 1087 1064 set _reset 0 1088 1065 } … … 1334 1311 } 1335 1312 switch -- $what { 1336 "heightmapOpacity" {1337 set val $_settings(heightmapOpacity)1338 set sval [expr { 0.01 * double($val) }]1339 foreach dataset [CurrentDatasets -all] {1340 SendCmd "heightmap opacity $sval $dataset"1341 }1342 }1343 "wireframe" {1344 set bool $_settings(wireframe)1345 foreach dataset [CurrentDatasets -all] {1346 SendCmd "heightmap wireframe $bool $dataset"1347 }1348 }1349 "colormapVisible" {1350 set bool $_settings(colormapVisible)1351 foreach dataset [CurrentDatasets -all] {1352 SendCmd "heightmap surface $bool $dataset"1353 }1354 }1355 "isolinesVisible" {1356 set bool $_settings(isolinesVisible)1357 foreach dataset [CurrentDatasets -all] {1358 SendCmd "heightmap isolines $bool $dataset"1359 }1360 }1361 "lighting" {1362 if { $_settings(isHeightmap) } {1363 set bool $_settings(lighting)1364 SendCmd "heightmap lighting $bool"1365 } else {1366 SendCmd "heightmap lighting 0"1367 }1368 }1369 "edges" {1370 set bool $_settings(edges)1371 foreach dataset [CurrentDatasets -all] {1372 SendCmd "heightmap edges $bool $dataset"1373 }1374 }1375 "axisVisible" {1376 set bool $_settings(axisVisible)1377 SendCmd "axis visible all $bool"1378 }1379 "axisLabels" {1380 set bool $_settings(axisLabels)1381 SendCmd "axis labels all $bool"1382 }1383 "axisXGrid" - "axisYGrid" - "axisZGrid" {1384 set axis [string tolower [string range $what 4 4]]1385 set bool $_settings($what)1386 SendCmd "axis grid $axis $bool"1387 }1388 1313 "axisFlymode" { 1389 1314 set mode [$itk_component(axisflymode) value] … … 1392 1317 SendCmd "axis flymode $mode" 1393 1318 } 1319 "axisLabels" { 1320 set bool $_settings(axisLabels) 1321 SendCmd "axis labels all $bool" 1322 } 1394 1323 "axisMinorTicks" { 1395 1324 set bool $_settings(axisMinorTicks) … … 1398 1327 } 1399 1328 } 1400 "isolines" { 1401 set n $_settings($what) 1402 EventuallyContour $n 1403 } 1404 "isolinesVisible" { 1329 "axisVisible" { 1330 set bool $_settings(axisVisible) 1331 SendCmd "axis visible all $bool" 1332 } 1333 "axisXGrid" - "axisYGrid" - "axisZGrid" { 1334 set axis [string tolower [string range $what 4 4]] 1405 1335 set bool $_settings($what) 1406 foreach dataset [CurrentDatasets -all] { 1407 SendCmd "heightmap isolines $bool $dataset" 1408 } 1409 } 1410 "colormapVisible" { 1411 set bool $_settings($what) 1412 foreach dataset [CurrentDatasets -all] { 1413 SendCmd "heightmap surface $bool $dataset" 1414 } 1336 SendCmd "axis grid $axis $bool" 1415 1337 } 1416 1338 "background" { … … 1424 1346 -plotforeground $fgcolors($bgcolor) 1425 1347 $itk_component(view) delete "legend" 1426 DrawLegend $_curFldName1427 }1428 "isolineColor" {1429 set color [$itk_component(isolinecolor) value]1430 if { $color == "none" } {1431 if { $_settings(isolinesVisible) } {1432 SendCmd "heightmap isolines 0"1433 set _settings(isolinesVisible) 01434 }1435 } else {1436 if { !$_settings(isolinesVisible) } {1437 SendCmd "heightmap isolines 1"1438 set _settings(isolinesVisible) 11439 }1440 SendCmd "heightmap isolinecolor [Color2RGB $color]"1441 }1442 1348 DrawLegend $_curFldName 1443 1349 } … … 1462 1368 EventuallyRequestLegend 1463 1369 } 1464 "heightmapOpacity" { 1465 set val $_settings(heightmapOpacity) 1466 set sval [expr { 0.01 * double($val) }] 1467 foreach dataset [CurrentDatasets -all] { 1468 SendCmd "heightmap opacity $sval $dataset" 1469 } 1470 } 1471 "heightmapScale" { 1472 if { $_settings(isHeightmap) } { 1473 set scale [GetHeightmapScale] 1474 foreach dataset [CurrentDatasets -all] { 1475 SendCmd "heightmap heightscale $scale $dataset" 1476 set _comp2scale($dataset) $scale 1477 } 1478 ResetAxes 1479 } 1480 } 1481 "lighting" { 1482 if { $_settings(isHeightmap) } { 1483 set bool $_settings(lighting) 1484 SendCmd "heightmap lighting $bool" 1485 } else { 1486 SendCmd "heightmap lighting 0" 1487 } 1370 "colormapVisible" { 1371 set bool $_settings($what) 1372 SendCmd "heightmap surface $bool" 1373 } 1374 "edges" { 1375 set bool $_settings(edges) 1376 SendCmd "heightmap edges $bool" 1488 1377 } 1489 1378 "field" { … … 1506 1395 EventuallyRequestLegend 1507 1396 } 1397 "heightmapScale" { 1398 if { $_settings(isHeightmap) } { 1399 set scale [GetHeightmapScale] 1400 foreach dataset [CurrentDatasets -all] { 1401 SendCmd "heightmap heightscale $scale $dataset" 1402 set _comp2scale($dataset) $scale 1403 } 1404 ResetAxes 1405 } 1406 } 1407 "isHeightmap" { 1408 set bool $_settings(isHeightmap) 1409 set c $itk_component(view) 1410 incr _buffering 1411 if { $_buffering == 1 } { 1412 set _outbuf "" 1413 } 1414 # Fix heightmap scale: 0 for contours, 1 for heightmaps. 1415 if { $bool } { 1416 set _settings(heightmapScale) 50 1417 set _settings(opacity) $_settings(saveOpacity) 1418 set _settings(lighting) $_settings(saveLighting) 1419 } else { 1420 set _settings(heightmapScale) 0 1421 set _settings(lighting) 0 1422 set _settings(opacity) 100 1423 } 1424 AdjustSetting lighting 1425 AdjustSetting opacity 1426 set scale [GetHeightmapScale] 1427 foreach dataset [CurrentDatasets -all] { 1428 SendCmd "heightmap heightscale $scale $dataset" 1429 set _comp2scale($dataset) $scale 1430 } 1431 if { $bool } { 1432 $itk_component(lighting) configure -state normal 1433 $itk_component(opacity) configure -state normal 1434 $itk_component(scale) configure -state normal 1435 $itk_component(opacity_l) configure -state normal 1436 $itk_component(scale_l) configure -state normal 1437 if {$_view(ortho)} { 1438 SendCmd "camera mode ortho" 1439 } else { 1440 SendCmd "camera mode persp" 1441 } 1442 } else { 1443 $itk_component(lighting) configure -state disabled 1444 $itk_component(opacity) configure -state disabled 1445 $itk_component(scale) configure -state disabled 1446 $itk_component(opacity_l) configure -state disabled 1447 $itk_component(scale_l) configure -state disabled 1448 } 1449 if {$_settings(stretchToFit)} { 1450 if {$scale == 0} { 1451 SendCmd "camera aspect window" 1452 } else { 1453 SendCmd "camera aspect square" 1454 } 1455 } 1456 SendCmd "camera reset" 1457 ResetAxes 1458 if { $bool } { 1459 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1460 $_arcball quaternion $q 1461 SendCmd "camera orient $q" 1462 } else { 1463 bind $c <ButtonPress-1> {} 1464 bind $c <B1-Motion> {} 1465 bind $c <ButtonRelease-1> {} 1466 SendCmd "camera mode image" 1467 } 1468 # Fix the mouse bindings for rotation/panning and the 1469 # camera mode. Ideally we'd create a bindtag for these. 1470 if { $bool } { 1471 # Bindings for rotation via mouse 1472 bind $c <ButtonPress-1> \ 1473 [itcl::code $this Rotate click %x %y] 1474 bind $c <B1-Motion> \ 1475 [itcl::code $this Rotate drag %x %y] 1476 bind $c <ButtonRelease-1> \ 1477 [itcl::code $this Rotate release %x %y] 1478 } 1479 incr _buffering -1 1480 if { $_buffering == 0 } { 1481 sendto $_outbuf 1482 set _outbuf "" 1483 } 1484 } 1485 "isolineColor" { 1486 set color [$itk_component(isolinecolor) value] 1487 if { $color == "none" } { 1488 if { $_settings(isolinesVisible) } { 1489 SendCmd "heightmap isolines 0" 1490 set _settings(isolinesVisible) 0 1491 } 1492 } else { 1493 if { !$_settings(isolinesVisible) } { 1494 SendCmd "heightmap isolines 1" 1495 set _settings(isolinesVisible) 1 1496 } 1497 SendCmd "heightmap isolinecolor [Color2RGB $color]" 1498 } 1499 DrawLegend $_curFldName 1500 } 1501 "isolinesVisible" { 1502 set bool $_settings($what) 1503 SendCmd "heightmap isolines $bool" 1504 } 1505 "legendVisible" { 1506 if { !$_settings($what) } { 1507 $itk_component(view) delete legend 1508 } 1509 DrawLegend $_curFldName 1510 } 1511 "lighting" { 1512 if { $_settings(isHeightmap) } { 1513 set _settings(saveLighting) $_settings(lighting) 1514 set bool $_settings($what) 1515 SendCmd "heightmap lighting $bool" 1516 } else { 1517 SendCmd "heightmap lighting 0" 1518 } 1519 } 1520 "numIsolines" { 1521 set _settings(numIsolines) [$itk_component(numisolines) value] 1522 SendCmd "heightmap numcontours $_settings(numIsolines)" 1523 DrawLegend $_curFldName 1524 } 1525 "opacity" { 1526 if { $_settings(isHeightmap) } { 1527 set _settings(saveOpacity) $_settings(opacity) 1528 set val $_settings(opacity) 1529 set sval [expr { 0.01 * double($val) }] 1530 SendCmd "heightmap opacity $sval" 1531 } else { 1532 SendCmd "heightmap opacity 1" 1533 } 1534 } 1535 "outline" { 1536 set bool $_settings($what) 1537 SendCmd "dataset outline $bool" 1538 } 1508 1539 "stretchToFit" { 1509 set bool $_settings( stretchToFit)1540 set bool $_settings($what) 1510 1541 if { $bool } { 1511 1542 set heightScale [GetHeightmapScale] … … 1519 1550 } 1520 1551 } 1521 "outline" { 1522 set bool $_settings(outline) 1523 SendCmd "dataset outline $bool" 1524 } 1525 "isHeightmap" { 1526 set bool $_settings(isHeightmap) 1527 incr _buffering 1528 if { $_buffering == 1 } { 1529 set _outbuf "" 1530 } 1531 if { $bool } { 1532 $itk_component(lighting) configure -state normal 1533 if {$_view(ortho)} { 1534 SendCmd "camera mode ortho" 1535 } else { 1536 SendCmd "camera mode persp" 1537 } 1538 } else { 1539 $itk_component(lighting) configure -state disabled 1540 } 1541 set _settings(lighting) $bool 1542 # Fix heightmap scale: 0 for contours, 1 for heightmaps. 1543 if { $bool } { 1544 set _settings(heightmapScale) 50 1545 } else { 1546 set _settings(heightmapScale) 50 1547 } 1548 SendCmd "heightmap lighting $bool" 1549 set scale [GetHeightmapScale] 1550 foreach dataset [CurrentDatasets -all] { 1551 SendCmd "heightmap heightscale $scale $dataset" 1552 set _comp2scale($dataset) $scale 1553 } 1554 if {$_settings(stretchToFit)} { 1555 if {$scale == 0} { 1556 SendCmd "camera aspect window" 1557 } else { 1558 SendCmd "camera aspect square" 1559 } 1560 } 1561 ResetAxes 1562 # Fix the mouse bindings for rotation/panning and the 1563 # camera mode. Ideally we'd create a bindtag for these. 1564 set c $itk_component(view) 1565 if { $bool } { 1566 # Bindings for rotation via mouse 1567 bind $c <ButtonPress-1> \ 1568 [itcl::code $this Rotate click %x %y] 1569 bind $c <B1-Motion> \ 1570 [itcl::code $this Rotate drag %x %y] 1571 bind $c <ButtonRelease-1> \ 1572 [itcl::code $this Rotate release %x %y] 1573 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1574 $_arcball quaternion $q 1575 SendCmd "camera orient $q" 1576 } else { 1577 set _settings(heightmapScale) 0 1578 bind $c <ButtonPress-1> {} 1579 bind $c <B1-Motion> {} 1580 bind $c <ButtonRelease-1> {} 1581 SendCmd "camera mode image" 1582 } 1583 incr _buffering -1 1584 if { $_buffering == 0 } { 1585 sendto $_outbuf 1586 set _outbuf "" 1587 } 1588 } 1589 "legendVisible" { 1590 if { !$_settings(legendVisible) } { 1591 $itk_component(view) delete legend 1592 } 1593 DrawLegend $_curFldName 1552 "wireframe" { 1553 set bool $_settings($what) 1554 SendCmd "heightmap wireframe $bool" 1594 1555 } 1595 1556 default { … … 1643 1604 return 1644 1605 } 1645 foreach { vmin vmax } $_limits(v) break1646 1606 foreach { xmin xmax } $_limits(x) break 1647 1607 foreach { ymin ymax } $_limits(y) break 1608 foreach { vmin vmax } $_limits(v) break 1648 1609 set dataRange [expr $vmax - $vmin] 1649 1610 set boundsRange [expr $xmax - $xmin] … … 1695 1656 set cmap "0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0" 1696 1657 } 1697 if { ![info exists _settings( heightmapOpacity)] } {1698 set _settings( heightmapOpacity) $style(-opacity)1699 } 1700 set max $_settings( heightmapOpacity)1658 if { ![info exists _settings(opacity)] } { 1659 set _settings(opacity) $style(-opacity) 1660 } 1661 set max $_settings(opacity) 1701 1662 1702 1663 set wmap "0.0 1.0 1.0 1.0" … … 1757 1718 1758 1719 set inner [$itk_component(main) insert end \ 1759 -title "Contour Settings" \1760 -icon [Rappture::icon volume-on]]1720 -title "Contour/Surface Settings" \ 1721 -icon [Rappture::icon contour]] 1761 1722 $inner configure -borderwidth 4 1762 1723 … … 1782 1743 ignore -font 1783 1744 } 1784 1785 1745 checkbutton $inner.edges \ 1786 1746 -text "Edges" \ … … 1867 1827 bind $inner.background <<Value>> [itcl::code $this AdjustSetting background] 1868 1828 1869 label $inner.opacity_l -text "Opacity" -font "Arial 9" 1870 ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ 1871 -variable [itcl::scope _settings(heightmapOpacity)] \ 1872 -width 10 \ 1873 -showvalue off \ 1874 -command [itcl::code $this AdjustSetting heightmapOpacity] 1875 1876 label $inner.scale_l -text "Scale" -font "Arial 9" 1877 ::scale $inner.scale -from 0 -to 100 -orient horizontal \ 1878 -variable [itcl::scope _settings(heightmapScale)] \ 1879 -width 10 \ 1880 -showvalue off \ 1881 -command [itcl::code $this AdjustSetting heightmapScale] 1829 itk_component add opacity_l { 1830 label $inner.opacity_l -text "Opacity" -font "Arial 9" 1831 } { 1832 ignore -font 1833 } 1834 itk_component add opacity { 1835 ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ 1836 -variable [itcl::scope _settings(opacity)] \ 1837 -showvalue off \ 1838 -command [itcl::code $this AdjustSetting opacity] 1839 } 1840 itk_component add scale_l { 1841 label $inner.scale_l -text "Scale" -font "Arial 9" 1842 } { 1843 ignore -font 1844 } 1845 itk_component add scale { 1846 ::scale $inner.scale -from 0 -to 100 -orient horizontal \ 1847 -variable [itcl::scope _settings(heightmapScale)] \ 1848 -showvalue off \ 1849 -command [itcl::code $this AdjustSetting heightmapScale] 1850 } 1851 label $inner.numisolines_l -text "No. Isolines" -font "Arial 9" 1852 itk_component add numisolines { 1853 Rappture::Spinint $inner.numisolines \ 1854 -min 0 -max 50 -font "arial 9" 1855 } 1856 $itk_component(numisolines) value $_settings(numIsolines) 1857 bind $itk_component(numisolines) <<Value>> \ 1858 [itcl::code $this AdjustSetting numIsolines] 1882 1859 1883 1860 blt::table $inner \ … … 1888 1865 2,0 $inner.background_l -anchor w -pady 2 \ 1889 1866 2,1 $inner.background -anchor w -pady 2 -fill x \ 1890 4,0 $inner.legend -anchor w -pady 2 -cspan 2 \ 1891 5,0 $inner.wireframe -anchor w -pady 2 -cspan 2\ 1892 6,0 $inner.lighting -anchor w -pady 2 -cspan 2 \ 1893 7,0 $inner.edges -anchor w -pady 2 -cspan 2 \ 1894 8,0 $inner.legend -anchor w -pady 2 -cspan 2 \ 1895 9,0 $inner.stretch -anchor w -pady 2 -cspan 2 \ 1896 10,0 $inner.outline -anchor w -pady 2 -cspan 2 \ 1867 3,0 $inner.numisolines_l -anchor w -pady 2 \ 1868 3,1 $inner.numisolines -anchor w -pady 2 \ 1869 4,0 $inner.stretch -anchor w -pady 2 -cspan 2 \ 1870 5,0 $inner.edges -anchor w -pady 2 -cspan 2 \ 1871 6,0 $inner.legend -anchor w -pady 2 -cspan 2 \ 1872 7,0 $inner.wireframe -anchor w -pady 2 -cspan 2\ 1873 8,0 $inner.outline -anchor w -pady 2 -cspan 2 \ 1874 10,0 $inner.lighting -anchor w -pady 2 -cspan 2 \ 1897 1875 11,0 $inner.opacity_l -anchor w -pady 2 \ 1898 1876 11,1 $inner.opacity -fill x -pady 2 \ … … 1906 1884 } 1907 1885 blt::table configure $inner r* c* -resize none 1908 blt::table configure $inner r13 c1 -resize expand 1886 blt::table configure $inner r9 -height .1i 1887 blt::table configure $inner r14 c1 -resize expand 1909 1888 } 1910 1889 … … 2128 2107 -edges 0 2129 2108 -edgecolor black 2130 -lighting 12131 2109 -linewidth 1.0 2132 2110 -levels 10 … … 2142 2120 $itk_component(colormap) value $style(-color) 2143 2121 } 2144 set _ numContours$style(-levels)2122 set _settings(numIsolines) $style(-levels) 2145 2123 set scale [GetHeightmapScale] 2146 SendCmd "heightmap add numcontours $_ numContours$scale $tag"2124 SendCmd "heightmap add numcontours $_settings(numIsolines) $scale $tag" 2147 2125 set _comp2scale($tag) $_settings(heightmapScale) 2148 2126 SendCmd "heightmap edges $_settings(edges) $tag" … … 2247 2225 set color [$itk_component(isolinecolor) value] 2248 2226 # Draw the isolines on the legend. 2249 if { $color != "none" && $_ numContours> 0 } {2227 if { $color != "none" && $_settings(numIsolines) > 0 } { 2250 2228 set pixels [blt::vector create \#auto] 2251 2229 set values [blt::vector create \#auto] 2252 2230 set range [image height $_image(legend)] 2253 2231 # Order of pixels is max to min (max is at top of legend). 2254 $pixels seq $ih 0 $_ numContours2232 $pixels seq $ih 0 $_settings(numIsolines) 2255 2233 set offset [expr 2 + $lineht] 2256 2234 # If there's a legend title, increase the offset by the line height. … … 2261 2239 # Order of values is min to max. 2262 2240 foreach { vmin vmax } $_limits(v) break 2263 $values seq $vmin $vmax $_ numContours2241 $values seq $vmin $vmax $_settings(numIsolines) 2264 2242 set tags "isoline legend" 2265 2243 foreach pos [$pixels range 0 end] value [$values range end 0] { … … 2376 2354 # Make a swatch of the selected color 2377 2355 if { [catch { $_image(legend) get 10 $iy } pixel] != 0 } { 2378 #puts stderr "out of range: $iy"2379 2356 return 2380 2357 }
Note: See TracChangeset
for help on using the changeset viewer.