Changeset 879


Ignore:
Timestamp:
Feb 12, 2008 5:30:52 PM (16 years ago)
Author:
gah
Message:

more fixes for simulation vs. volume data limits

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/nanovisviewer.tcl

    r878 r879  
    4444    public method delete {args}
    4545    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        }
    4751        return [list $_limits(vmin) $_limits(vmax)]
    4852    }
     
    7781    protected method _fixLegend {}
    7882    protected method _serverDown {}
    79     protected method _getTransfuncData {dataobj comp}
     83    protected method _genTransfuncData {dataobj comp}
    8084    public method update_transfer_function {}
    8185    public method remove_duplicate_isomarker { m x }
    8286    public method _addIsoMarker { x y }
    8387    protected method _initIsoMarkers {dataobj comp}
     88    protected method _hideIsoMarkers {dataobj}
     89    protected method _showIsoMarkers {dataobj}
    8490    protected method _color2rgb {color}
    8591    protected method _euler2xyz {theta phi psi}
     
    94100
    95101    private variable _dlist ""     ;# list of data objects
     102    private variable _all_data_objs
    96103    private variable _dims ""      ;# dimensionality of data objects
    97104    private variable _obj2style    ;# maps dataobj => style settings
     
    176183        set _tick [$c create image 0 $h \
    177184                -image $_normal_icon -anchor s \
    178                 -tags "$this $obj"]
     185                -tags "$this $obj" -state hidden]
    179186        set _label [$c create text 0 $h \
    180187                -anchor n -fill white -font "Helvetica 6" \
     
    192199
    193200    public method get_relative_value {} {
    194         foreach {min max} [$_nvobj getLimits] break
     201        foreach {min max} [$_nvobj getLimits -current] break
    195202        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
    196211    }
    197212    public method get_screen_position { } {
     
    210225    public method set_absolute_value { x } {
    211226        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
    217228        $_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}]
    221232    }
    222233    public method set_relative_value { x } {
    223         foreach {min max} [$_nvobj getLimits] break
     234        foreach {min max} [$_nvobj getLimits -current] break
    224235        set r [expr $max - $min]
    225236        set_absolute_value [expr {($x * $r) + $min}]
     
    642653    if {$pos < 0} {
    643654        lappend _dlist $dataobj
     655        set _all_data_objs($dataobj) 1
    644656        set _obj2ovride($dataobj-color) $params(-color)
    645657        set _obj2ovride($dataobj-width) $params(-width)
     
    10721084            #
    10731085            _initIsoMarkers $dataobj $comp
    1074             foreach {sname cmap wmap} [_getTransfuncData $dataobj $comp] break
     1086            foreach {sname cmap wmap} [_genTransfuncData $dataobj $comp] break
    10751087            set cmdstr [list transfunc define $sname $cmap $wmap]
    10761088            _send_echo >>line $cmdstr
     
    10951107        }
    10961108    }
     1109    _showIsoMarkers $first
    10971110    # if there are any commands in the buffer, send them now that we're done
    10981111    _send_echo >>line $_buffer(out)
     
    12101223        set volume $info(id)
    12111224        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        }           
    12141236        set _limits(vmin) $info(vmin)
    12151237        set _limits(vmax) $info(vmax)
     
    12761298            }
    12771299        }
    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
    12851303
    12861304        # sync the state of slicers
     
    15431561
    15441562# ----------------------------------------------------------------------
    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 the
    1550 # user clicks and drags on the legend area.  The probe changes the
    1551 # transfer function to highlight the area being selected in the
    1552 # 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 10
    1559     set y1 [expr {$y0+[image height $_image(legend)]-1}]
    1560 
    1561     set dataobj [lindex [get] 0]
    1562     if {"" == $dataobj} {
    1563         return
    1564     }
    1565     set comp [lindex [$dataobj components] 0]
    1566     if {![info exists _obj2style($dataobj-$comp)]} {
    1567         return
    1568     }
    1569 
    1570     switch -- $option {
    1571         start {
    1572             # create the probe marker on the legend
    1573             $c create rect 0 0 5 $h -width 3 \
    1574                 -outline black -fill "" -tags markerbg
    1575             $c create rect 0 0 5 $h -width 1 \
    1576                 -outline white -fill "" -tags marker
    1577 
    1578             # define a new transfer function
    1579             _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 point
    1583             eval _probe update $args
    1584         }
    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-1
    1595             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 value
    1600             foreach {sname cmap wmap} [_getTransfuncData $dataobj $comp] break
    1601             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 $wmap
    1603         }
    1604         end {
    1605             $c delete marker markerbg
    1606 
    1607             # put the volume back to its old transfer function
    1608             _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 # ----------------------------------------------------------------------
    16171563# USAGE: _state <component>
    16181564#
     
    16691615            if {[isconnected]} {
    16701616                set val $Rappture::NanovisViewer::_isosurface($this)
    1671                 _send "volume" "shading" "isosurface" $val
     1617                set dataobj [lindex [get] 0]
     1618                _send "volume" "shading" "isosurface" $val
    16721619            }
    16731620        }           
     
    16981645        }
    16991646    }
    1700 
    17011647    if {$w > 0 && $h > 0 && "" != $ivol} {
    17021648        _send legend $ivol $w $h
    17031649    } else {
    1704         $itk_component(legend) delete all
     1650        #$itk_component(legend) delete all
    17051651    }
    17061652}
     
    17201666
    17211667# ----------------------------------------------------------------------
    1722 # USAGE: _getTransfuncData <dataobj> <comp>
     1668# USAGE: _genTransfuncData <dataobj> <comp>
    17231669#
    17241670# Used internally to compute the colormap and alpha map used to define
     
    17261672# Returns: name {v r g b ...} {v w ...}
    17271673# ----------------------------------------------------------------------
    1728 itcl::body Rappture::NanovisViewer::_getTransfuncData {dataobj comp} {
     1674itcl::body Rappture::NanovisViewer::_genTransfuncData {dataobj comp} {
    17291675    array set style {
    17301676        -color rainbow
     
    18571803}
    18581804
     1805itcl::body Rappture::NanovisViewer::_hideIsoMarkers {dataobj} {
     1806    if { [info exists _isomarkers($dataobj)] } {
     1807        foreach m $_isomarkers($dataobj) {
     1808            $m hide
     1809        }
     1810    }
     1811}
     1812
     1813itcl::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
    18591825itcl::body Rappture::NanovisViewer::_initIsoMarkers {dataobj comp} {
    18601826    if { [info exists _isomarkers($dataobj)] } {
     1827        _hideIsoMarkers $dataObj
    18611828        return
    18621829    }
     
    19101877        return
    19111878    }
    1912     # compute a transfer function for the probe value
    1913     foreach {sname cmap wmap} [_getTransfuncData $dataobj $comp] break
     1879    # Compute a transfer function for the current data set.
     1880    foreach {sname cmap wmap} [_genTransfuncData $dataobj $comp] break
    19141881    _send transfunc define $_obj2style($key) $cmap $wmap
    19151882    _send volume shading transfunc $_obj2style($key) $_obj2id($key)
     
    19191886itcl::body Rappture::NanovisViewer::_addIsoMarker { x y } {
    19201887    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    }
    19251891    set c $itk_component(legend)
    19261892    set m [IsoMarker \#auto $c $this]
    19271893    set w [winfo width $c]
    19281894    $m set_relative_value [expr {double($x-10)/($w-20)}]
    1929     lappend _isomarkers($key) $m
     1895    $m show
     1896    lappend _isomarkers($dataobj) $m
    19301897    update_transfer_function
    19311898    return 1
     
    19371904        return 0
    19381905    }
    1939     set key $dataobj
    1940     set list {}
    19411906    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                }
    19511919            }
     1920            lappend list $m
    19521921        }
    1953         lappend list $m
    1954     }
    1955     set _isomarkers($key) $list
    1956     update_transfer_function
     1922        set _isomarkers($dataobj) $list
     1923        update_transfer_function
     1924    }
    19571925    return $bool
    19581926}
Note: See TracChangeset for help on using the changeset viewer.