Changeset 972 for trunk/gui/scripts


Ignore:
Timestamp:
Mar 29, 2008 10:31:47 PM (16 years ago)
Author:
gah
Message:
 
File:
1 edited

Legend:

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

    r971 r972  
    5757    public method delete {args}
    5858    public method scale {args}
    59     public method GetDataObj { ivol } {
    60         if { ![info exists _id2obj($ivol)] } {
    61             return ""
    62         }
    63         return $_id2obj($ivol)
    64     }
    6559    public method GetLimits { {ivol ""} } {
    6660        if { $ivol != "" } {
     
    8478    protected method _send {string}
    8579    protected method _send_dataobjs {}
    86     protected method _send_transfuncs {}
     80    protected method _send_transfunc {}
    8781
    8882    protected method _ReceiveImage {option size}
     
    10498
    10599    # The following methods are only used by this class.
    106     private method _SetTransfuncData { ivol }
     100    private method _DefineTransferFunction { ivol }
    107101    private method _AddIsoMarker { ivol x y }
    108102    private method _InitIsoMarkers { ivol }
     
    130124       
    131125    private variable _isomarkers    ;# array of isosurface level values 0..1
     126    private variable _styles
    132127    private common   _settings
     128    private variable _currentVolId ""
    133129}
    134130
     
    151147        "[itcl::code $this _send_dataobjs]; list"
    152148    # Send transfer functions event
    153     $_dispatcher register !send_transfuncs
    154     $_dispatcher dispatch $this !send_transfuncs \
    155         "[itcl::code $this _send_transfuncs]; list"
     149    $_dispatcher register !send_transfunc
     150    $_dispatcher dispatch $this !send_transfunc \
     151        "[itcl::code $this _send_transfunc]; list"
    156152    # Rebuild event
    157153    $_dispatcher register !rebuild
     
    493489    $_dispatcher cancel !rebuild
    494490    $_dispatcher cancel !send_dataobjs
    495     $_dispatcher cancel !send_transfuncs
     491    $_dispatcher cancel !send_transfunc
    496492    image delete $_image(plot)
    497493    image delete $_image(legend)
     
    765761            # send the data as one huge base64-encoded mess -- yuck!
    766762            set data [$dataobj values $comp]
    767 
    768             # tell the engine to expect some data
    769763            set nbytes [string length $data]
    770764            if { ![SendBytes "volume data follows $nbytes"] } {
     
    774768                return
    775769            }
    776             set volId $_obj2id(count)
     770            set ivol $_obj2id(count)
    777771            incr _obj2id(count)
    778772
    779             set _id2obj($volId) [list $dataobj $comp]
    780             set _obj2id($dataobj-$comp) $volId
    781             set _receiveids($volId) 1
     773            set _id2obj($ivol) [list $dataobj $comp]
     774            set _obj2id($dataobj-$comp) $ivol
     775            set _receiveids($ivol) 1
     776
    782777        }
    783778    }
     
    819814
    820815# ----------------------------------------------------------------------
    821 # USAGE: _send_transfuncs
    822 # ----------------------------------------------------------------------
    823 itcl::body Rappture::NanovisViewer::_send_transfuncs {} {
    824     blt::busy hold $itk_component(hull); update idletasks
    825     foreach dataobj $_sendobjs2 {
    826         foreach comp [$dataobj components] {
    827             #
    828             # Determine the transfer function needed for this volume
    829             # and make sure that it's defined on the server.
    830             #
    831             set ivol $_obj2id($dataobj-$comp)
    832             if { ![info exists _isomarkers($ivol)] } {
    833                 _InitIsoMarkers $ivol
    834             } else {
    835                 _HideIsoMarkers $ivol
    836             }
    837             if { ![_SetTransfuncData $ivol] } {
    838                 return
    839             }
    840         }
    841     }
    842     set _sendobjs2 ""
    843     blt::busy release $itk_component(hull)
    844 
    845     # activate the proper volume
    846     set first [lindex [get] 0]
    847     foreach key [array names _obj2id *-*] {
    848         set state [string match $first-* $key]
    849         set ivol $_obj2id($key)
    850         _send "volume state $state $ivol"
    851         if {[info exists _id2style($ivol)]} {
    852             _send "volume shading transfunc $_id2style($ivol) $ivol"
    853         }
    854     }
    855     set comp [lindex [$dataobj components] 0]
    856     _ShowIsoMarkers $_obj2id($first-$comp)
    857     # if there are any commands in the buffer, send them now that we're done
    858     SendBytes $_outbuf
    859     set _outbuf ""
     816# USAGE: _send_transfunc
     817# ----------------------------------------------------------------------
     818itcl::body Rappture::NanovisViewer::_send_transfunc {} {
     819    if { ![_DefineTransferFunction $_currentVolId] } {
     820        return
     821    }
     822    _fixLegend
    860823    $_dispatcher event -idle !legend
    861824}
     
    924887    if { [isconnected] } {
    925888        array set info $args
    926         set volume $info(id)
    927         set _limits($volume-min) $info(min)
    928         set _limits($volume-max) $info(max)
    929         foreach { dataobj comp } $_id2obj($volume) break
     889        set ivol $info(id)
     890        set _limits($ivol-min) $info(min)
     891        set _limits($ivol-max) $info(max)
     892        foreach { dataobj comp } $_id2obj($ivol) break
    930893
    931894        if { ![info exists _limits($dataobj-vmin)] } {
     
    944907        lappend _sendobjs2 $dataobj
    945908        unset _receiveids($info(id))
    946         if { [array size _receiveids] == 0 } {
    947             $_dispatcher event -idle !send_transfuncs
    948         }
     909
     910        if { ![info exists _isomarkers($ivol)] } {
     911            _InitIsoMarkers $ivol
     912        } else {
     913            _HideIsoMarkers $ivol
     914        }
     915        # We can update the transfer function now that we know the data limits.
     916        if { ![_DefineTransferFunction $ivol] } {
     917            return
     918        }
     919        _fixLegend
    949920    }
    950921}
     
    982953        set h [winfo height $itk_component(3dview)]
    983954        _send "screen $w $h"
    984         # nothing to send -- activate the proper volume
     955        # nothing to send -- activate the proper ivol
    985956        set first [lindex [get] 0]
    986957        if {"" != $first} {
     
    998969
    999970        _ShowIsoMarkers $ivol
     971
     972        if { [info exists _settings($this-$ivol-opacity)] } {
     973            set inner [$itk_component(controls).panel component inner]
     974            set sval $_settings($this-$ivol-opacity)
     975            set sval [expr {round($sval * 100)}]
     976            $inner.scales.opacity set $sval
     977        }
     978        if { [info exists _settings($this-$ivol-thickness)] } {
     979            set inner [$itk_component(controls).panel component inner]
     980            set sval $_settings($this-$ivol-thickness)
     981            set sval [expr {round($sval * 10000.0)}]
     982            $inner.scales.thickness set $sval
     983        }
    1000984        UpdateTransferFunction $ivol
    1001985
     
    12231207
    12241208            # show the current value in the readout
    1225 #puts "readout: $axis = $newval"
     1209            #puts "readout: $axis = $newval"
    12261210
    12271211            set ids [_currentVolumeIds -cutplanes]
     
    13131297                set dataobj [lindex [get] 0]
    13141298                if {$dataobj != 0} {
    1315                     set val [$inner.scales.opacity get]
    1316                     set sval [expr { 0.01 * double($val) }]
     1299                    set val [$inner.scales.opacity get]
     1300                    set sval [expr { 0.01 * double($val) }]
    13171301                    # FIXME: This will change when we can select the current
    13181302                    #        volume.
    13191303                    set comp [lindex [$dataobj components] 0]
    13201304                    set tag $dataobj-$comp
    1321                     set _settings($this-$tag-opacity) $sval
    1322                     UpdateTransferFunction $_obj2id($tag)
     1305                    if { [info exists _obj2id($tag)] } {
     1306                        set ivol $_obj2id($tag)
     1307                        set _settings($this-$ivol-opacity) $sval
     1308                        UpdateTransferFunction $ivol
     1309                    }
    13231310                }
    13241311            }
     
    13361323                    set comp [lindex [$dataobj components] 0]
    13371324                    set tag $dataobj-$comp
    1338                     set _settings($this-$tag-thickness) $sval
    1339                     UpdateTransferFunction $_obj2id($dataobj-$comp)
     1325                    if { [info exists _obj2id($tag)] } {
     1326                        set ivol $_obj2id($tag)
     1327                        set _settings($this-$ivol-thickness) $sval
     1328                        UpdateTransferFunction $ivol
     1329                    }
    13401330                }
    13411331            }
     
    13791369    set h [expr {[winfo height $itk_component(legend)]-20-$lineht}]
    13801370    set ivol ""
    1381 
    1382     # The changes when we can select the current volume.
    1383     set dataobj [lindex [get] 0]
    1384     if {"" != $dataobj} {
    1385         set comp [lindex [$dataobj components] 0]
    1386         if {[info exists _obj2id($dataobj-$comp)]} {
    1387             set ivol $_obj2id($dataobj-$comp)
    1388         }
     1371    if { $ivol == "" } {
     1372        set dataobj [lindex [get] 0]
     1373        if {"" != $dataobj} {
     1374            set comp [lindex [$dataobj components] 0]
     1375            if {[info exists _obj2id($dataobj-$comp)]} {
     1376                set ivol $_obj2id($dataobj-$comp)
     1377            }
     1378        }
    13891379    }
    13901380    if {$w > 0 && $h > 0 && "" != $ivol} {
     
    13961386
    13971387# ----------------------------------------------------------------------
    1398 # USAGE: _SetTransfuncData <ivol>
     1388# USAGE: _DefineTransferFunction <ivol>
    13991389#
    14001390# Used internally to compute the colormap and alpha map used to define
     
    14021392# Returns: name {v r g b ...} {v w ...}
    14031393# ----------------------------------------------------------------------
    1404 itcl::body Rappture::NanovisViewer::_SetTransfuncData { ivol } {
     1394itcl::body Rappture::NanovisViewer::_DefineTransferFunction { ivol } {
    14051395    array set style {
    14061396        -color rainbow
     
    14111401    array set style [lindex [$dataobj components -style $comp] 0]
    14121402    set sname "$style(-color):$style(-levels):$style(-opacity)"
    1413 
    14141403    if {$style(-color) == "rainbow"} {
    14151404        set style(-color) "white:yellow:green:cyan:blue:magenta"
     
    14381427    set isovalues [lsort -real $isovalues]
    14391428
    1440     set delta 0.01
    1441     if { [info exists _settings($tag-thickness)]} {
    1442         set delta $_settings($tag-thickness)
    1443     }
     1429    if { ![info exists _settings($tag-thickness)]} {
     1430        set _settings($tag-thickness) 0.05
     1431    }
     1432    set delta $_settings($tag-thickness)
     1433
    14441434    set first [lindex $isovalues 0]
    14451435    set last [lindex $isovalues end]
     
    14751465    }
    14761466    set _id2style($ivol) $sname
    1477     return [_send transfunc define $sname $cmap $wmap]
     1467    set _styles($sname) 1
     1468    set cmds [subst {
     1469        transfunc define $sname { $cmap } { $wmap }
     1470        volume shading transfunc $sname $ivol
     1471    }]
     1472    return [SendBytes $cmds]
    14781473}
    14791474
     
    15301525    foreach dataobj [array names _all_data_objs] {
    15311526        foreach comp [$dataobj components] {
    1532             _HideIsoMarkers _$obj2id($dataobj-$comp)
     1527            _HideIsoMarkers $_obj2id($dataobj-$comp)
    15331528        }
    15341529    }
     
    15491544    set c $itk_component(legend)
    15501545    regsub -all "," $levels " " levels
    1551     for {set i 1} { $i <= $levels } {incr i} {
    1552         set x [expr {double($i)/($levels+1)}]
    1553         set m [IsoMarker \#auto $c $this $ivol]
    1554         $m SetRelativeValue $x
    1555         lappend _isomarkers($ivol) $m
     1546    if {[string is int $levels]} {
     1547        for {set i 1} { $i <= $levels } {incr i} {
     1548            set x [expr {double($i)/($levels+1)}]
     1549            set m [IsoMarker \#auto $c $this $ivol]
     1550            $m SetRelativeValue $x
     1551            lappend _isomarkers($ivol) $m
     1552        }
     1553    } else {
     1554        foreach x $levels {
     1555            set m [IsoMarker \#auto $c $this $ivol]
     1556            $m SetRelativeValue $x
     1557            lappend _isomarkers($ivol) $m
     1558        }
    15561559    }
    15571560}
     
    15931596        -levels 6
    15941597    }
     1598    set _isomarkers($ivol) ""
    15951599    foreach {dataobj comp} $_id2obj($ivol) break
    15961600    array set style [lindex [$dataobj components -style $comp] 0]
    1597 
    15981601    if { [info exists style(-markers)] } {
    15991602        _ParseMarkersOption $ivol $style(-markers)
     
    16171620        return
    16181621    }
    1619     # Compute a transfer function for the current data set.
    1620     _SetTransfuncData $ivol
    1621     _send [list volume shading transfunc $_id2style($ivol) $ivol]
    1622     _fixLegend
     1622    set _currentVolId $ivol
     1623    $_dispatcher event -idle !send_transfunc
    16231624}
    16241625
     
    16401641        set list {}
    16411642        set marker [namespace tail $marker]
    1642         foreach m $_isomarkers($tag) {
     1643        foreach m $_isomarkers($ivol) {
    16431644            set sx [$m GetScreenPosition]
    16441645            if { $m != $marker } {
Note: See TracChangeset for help on using the changeset viewer.