Changeset 879
- Timestamp:
- Feb 12, 2008 5:30:52 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/nanovisviewer.tcl
r878 r879 44 44 public method delete {args} 45 45 public method scale {args} 46 public method getLimits {} { 46 public method getLimits { { option "-current"} } { 47 if { $option == "-current" } { 48 set dataobj [lindex [get] 0] 49 return [list $_limits($dataobj-vmin) $_limits($dataobj-vmax)] 50 } 47 51 return [list $_limits(vmin) $_limits(vmax)] 48 52 } … … 77 81 protected method _fixLegend {} 78 82 protected method _serverDown {} 79 protected method _ge tTransfuncData {dataobj comp}83 protected method _genTransfuncData {dataobj comp} 80 84 public method update_transfer_function {} 81 85 public method remove_duplicate_isomarker { m x } 82 86 public method _addIsoMarker { x y } 83 87 protected method _initIsoMarkers {dataobj comp} 88 protected method _hideIsoMarkers {dataobj} 89 protected method _showIsoMarkers {dataobj} 84 90 protected method _color2rgb {color} 85 91 protected method _euler2xyz {theta phi psi} … … 94 100 95 101 private variable _dlist "" ;# list of data objects 102 private variable _all_data_objs 96 103 private variable _dims "" ;# dimensionality of data objects 97 104 private variable _obj2style ;# maps dataobj => style settings … … 176 183 set _tick [$c create image 0 $h \ 177 184 -image $_normal_icon -anchor s \ 178 -tags "$this $obj" ]185 -tags "$this $obj" -state hidden] 179 186 set _label [$c create text 0 $h \ 180 187 -anchor n -fill white -font "Helvetica 6" \ … … 192 199 193 200 public method get_relative_value {} { 194 foreach {min max} [$_nvobj getLimits ] break201 foreach {min max} [$_nvobj getLimits -current] break 195 202 return [expr {($_value-$min)/($max - $min)}] 203 } 204 public method show {} { 205 set_absolute_value $_value 206 $_canvas itemconfigure $_tick -state normal 207 $_canvas raise $_tick 208 } 209 public method hide {} { 210 $_canvas itemconfigure $_tick -state hidden 196 211 } 197 212 public method get_screen_position { } { … … 210 225 public method set_absolute_value { x } { 211 226 set _value $x 212 213 set w [winfo width $_canvas] 214 set h [winfo height $_canvas] 215 set y0 10 216 set y1 [expr {$y0+22-1}] 227 set y 31 217 228 $_canvas itemconfigure $_label -text [format %.4g $_value] 218 set screen_pos[get_screen_position]219 $_canvas coords $_tick $ screen_pos [expr $y1+3]220 $_canvas coords $_label $ screen_pos [expr {$y1+5}]229 set x [get_screen_position] 230 $_canvas coords $_tick $x [expr {$y+3}] 231 $_canvas coords $_label $x [expr {$y+5}] 221 232 } 222 233 public method set_relative_value { x } { 223 foreach {min max} [$_nvobj getLimits ] break234 foreach {min max} [$_nvobj getLimits -current] break 224 235 set r [expr $max - $min] 225 236 set_absolute_value [expr {($x * $r) + $min}] … … 642 653 if {$pos < 0} { 643 654 lappend _dlist $dataobj 655 set _all_data_objs($dataobj) 1 644 656 set _obj2ovride($dataobj-color) $params(-color) 645 657 set _obj2ovride($dataobj-width) $params(-width) … … 1072 1084 # 1073 1085 _initIsoMarkers $dataobj $comp 1074 foreach {sname cmap wmap} [_ge tTransfuncData $dataobj $comp] break1086 foreach {sname cmap wmap} [_genTransfuncData $dataobj $comp] break 1075 1087 set cmdstr [list transfunc define $sname $cmap $wmap] 1076 1088 _send_echo >>line $cmdstr … … 1095 1107 } 1096 1108 } 1109 _showIsoMarkers $first 1097 1110 # if there are any commands in the buffer, send them now that we're done 1098 1111 _send_echo >>line $_buffer(out) … … 1210 1223 set volume $info(id) 1211 1224 foreach { dataobj comp } $_id2obj($volume) break 1212 set _limits(vmin-$dataobj-$comp) $info(min) 1213 set _limits(vmax-$dataobj-$comp) $info(max) 1225 if { ![info exists _limits($dataobj-vmin] } { 1226 set _limits($dataobj-vmin) $info(min) 1227 set _limits($dataobj-vmax) $info(max) 1228 } else { 1229 if { $_limits($dataobj-vmin) > $info(min) } { 1230 set _limits($dataobj-vmin) $info(min) 1231 } 1232 if { $_limits($dataobj-vmax) > $info(max) } { 1233 set _limits($dataobj-vmax) $info(max) 1234 } 1235 } 1214 1236 set _limits(vmin) $info(vmin) 1215 1237 set _limits(vmax) $info(vmax) … … 1276 1298 } 1277 1299 } 1278 foreach key [array names _obj2id *-*] { 1279 set state [string match $first-* $key] 1280 _send volume state $state $_obj2id($key) 1281 if {[info exists _obj2style($key)]} { 1282 _send volume shading transfunc $_obj2style($key) $_obj2id($key) 1283 } 1284 } 1300 1301 _showIsoMarkers $first 1302 update_transfer_function 1285 1303 1286 1304 # sync the state of slicers … … 1543 1561 1544 1562 # ---------------------------------------------------------------------- 1545 # USAGE: _probe start <x> <y>1546 # USAGE: _probe update <x> <y>1547 # USAGE: _probe end <x> <y>1548 #1549 # Used internally to handle the various probe operations, when the1550 # user clicks and drags on the legend area. The probe changes the1551 # transfer function to highlight the area being selected in the1552 # legend.1553 # ----------------------------------------------------------------------1554 itcl::body Rappture::NanovisViewer::_probe {option args} {1555 set c $itk_component(legend)1556 set w [winfo width $c]1557 set h [winfo height $c]1558 set y0 101559 set y1 [expr {$y0+[image height $_image(legend)]-1}]1560 1561 set dataobj [lindex [get] 0]1562 if {"" == $dataobj} {1563 return1564 }1565 set comp [lindex [$dataobj components] 0]1566 if {![info exists _obj2style($dataobj-$comp)]} {1567 return1568 }1569 1570 switch -- $option {1571 start {1572 # create the probe marker on the legend1573 $c create rect 0 0 5 $h -width 3 \1574 -outline black -fill "" -tags markerbg1575 $c create rect 0 0 5 $h -width 1 \1576 -outline white -fill "" -tags marker1577 1578 # define a new transfer function1579 _send transfunc define probe {0 0 0 0 1 0 0 0} {0 0 1 0}1580 _send volume shading transfunc probe $_obj2id($dataobj-$comp)1581 1582 # now, probe this point1583 eval _probe update $args1584 }1585 update {1586 set x [lindex $args 0]1587 if {$x < 10} {set x 10}1588 if {$x > $w-10} {set x [expr {$w-10}]}1589 foreach tag {markerbg marker} {1590 $c coords $tag [expr {$x-2}] [expr {$y0-2}] \1591 [expr {$x+2}] [expr {$y1+2}]1592 }1593 1594 # value of the probe point, in the range 0-11595 set val [expr {double($x-10)/($w-20)}]1596 set dl [expr {($val > 0.1) ? 0.1 : $val}]1597 set dr [expr {($val < 0.9) ? 0.1 : 1-$val}]1598 1599 # compute a transfer function for the probe value1600 foreach {sname cmap wmap} [_getTransfuncData $dataobj $comp] break1601 set wmap "0.0 0.0 [expr {$val-$dl}] 0.0 $val 1.0 [expr {$val+$dr}] 0.0 1.0 0.0"1602 _send transfunc define probe $cmap $wmap1603 }1604 end {1605 $c delete marker markerbg1606 1607 # put the volume back to its old transfer function1608 _send volume shading transfunc $_obj2style($dataobj-$comp) $_obj2id($dataobj-$comp)1609 }1610 default {1611 error "bad option \"$option\": should be start, update, end"1612 }1613 }1614 }1615 1616 # ----------------------------------------------------------------------1617 1563 # USAGE: _state <component> 1618 1564 # … … 1669 1615 if {[isconnected]} { 1670 1616 set val $Rappture::NanovisViewer::_isosurface($this) 1671 _send "volume" "shading" "isosurface" $val 1617 set dataobj [lindex [get] 0] 1618 _send "volume" "shading" "isosurface" $val 1672 1619 } 1673 1620 } … … 1698 1645 } 1699 1646 } 1700 1701 1647 if {$w > 0 && $h > 0 && "" != $ivol} { 1702 1648 _send legend $ivol $w $h 1703 1649 } else { 1704 $itk_component(legend) delete all1650 #$itk_component(legend) delete all 1705 1651 } 1706 1652 } … … 1720 1666 1721 1667 # ---------------------------------------------------------------------- 1722 # USAGE: _ge tTransfuncData <dataobj> <comp>1668 # USAGE: _genTransfuncData <dataobj> <comp> 1723 1669 # 1724 1670 # Used internally to compute the colormap and alpha map used to define … … 1726 1672 # Returns: name {v r g b ...} {v w ...} 1727 1673 # ---------------------------------------------------------------------- 1728 itcl::body Rappture::NanovisViewer::_ge tTransfuncData {dataobj comp} {1674 itcl::body Rappture::NanovisViewer::_genTransfuncData {dataobj comp} { 1729 1675 array set style { 1730 1676 -color rainbow … … 1857 1803 } 1858 1804 1805 itcl::body Rappture::NanovisViewer::_hideIsoMarkers {dataobj} { 1806 if { [info exists _isomarkers($dataobj)] } { 1807 foreach m $_isomarkers($dataobj) { 1808 $m hide 1809 } 1810 } 1811 } 1812 1813 itcl::body Rappture::NanovisViewer::_showIsoMarkers {dataobj} { 1814 foreach obj [array names _all_data_objs] { 1815 _hideIsoMarkers $obj 1816 } 1817 if { ![info exists _isomarkers($dataobj)] } { 1818 return 1819 } 1820 foreach m $_isomarkers($dataobj) { 1821 $m show 1822 } 1823 } 1824 1859 1825 itcl::body Rappture::NanovisViewer::_initIsoMarkers {dataobj comp} { 1860 1826 if { [info exists _isomarkers($dataobj)] } { 1827 _hideIsoMarkers $dataObj 1861 1828 return 1862 1829 } … … 1910 1877 return 1911 1878 } 1912 # compute a transfer function for the probe value1913 foreach {sname cmap wmap} [_ge tTransfuncData $dataobj $comp] break1879 # Compute a transfer function for the current data set. 1880 foreach {sname cmap wmap} [_genTransfuncData $dataobj $comp] break 1914 1881 _send transfunc define $_obj2style($key) $cmap $wmap 1915 1882 _send volume shading transfunc $_obj2style($key) $_obj2id($key) … … 1919 1886 itcl::body Rappture::NanovisViewer::_addIsoMarker { x y } { 1920 1887 set dataobj [lindex [get] 0] 1921 if {"" == $dataobj} { 1922 return 0 1923 } 1924 set key $dataobj 1888 if {$dataobj == ""} { 1889 return 0; # No data sets defined 1890 } 1925 1891 set c $itk_component(legend) 1926 1892 set m [IsoMarker \#auto $c $this] 1927 1893 set w [winfo width $c] 1928 1894 $m set_relative_value [expr {double($x-10)/($w-20)}] 1929 lappend _isomarkers($key) $m 1895 $m show 1896 lappend _isomarkers($dataobj) $m 1930 1897 update_transfer_function 1931 1898 return 1 … … 1937 1904 return 0 1938 1905 } 1939 set key $dataobj1940 set list {}1941 1906 set bool 1 1942 set marker [namespace tail $marker] 1943 foreach m $_isomarkers($key) { 1944 set sx [$m get_screen_position] 1945 if { $m != $marker } { 1946 if { $x >= ($sx-3) && $x <= ($sx+3) } { 1947 $marker set_relative_value [$m get_relative_value] 1948 itcl::delete object $m 1949 set bool 0 1950 continue 1907 if { [info exists _isomarkers($dataobj)] } { 1908 set list {} 1909 set marker [namespace tail $marker] 1910 foreach m $_isomarkers($dataobj) { 1911 set sx [$m get_screen_position] 1912 if { $m != $marker } { 1913 if { $x >= ($sx-3) && $x <= ($sx+3) } { 1914 $marker set_relative_value [$m get_relative_value] 1915 itcl::delete object $m 1916 set bool 0 1917 continue 1918 } 1951 1919 } 1920 lappend list $m 1952 1921 } 1953 lappend list $m 1954 } 1955 set _isomarkers($key) $list 1956 update_transfer_function 1922 set _isomarkers($dataobj) $list 1923 update_transfer_function 1924 } 1957 1925 return $bool 1958 1926 }
Note: See TracChangeset
for help on using the changeset viewer.