Changeset 968 for trunk/gui/scripts


Ignore:
Timestamp:
Mar 28, 2008 1:48:13 PM (16 years ago)
Author:
gah
Message:

major overhaul of isomarkers

Location:
trunk/gui/scripts
Files:
2 edited

Legend:

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

    r966 r968  
    2222    private variable _canvas    ""
    2323    private variable _nvobj     "";     # Parent nanovis object.
     24    private variable _ivol      "";     # Id of volume that this marker is
     25                                        # associated with.
    2426    private variable _active_motion   0
    2527    private variable _active_press    0
     
    2729    private common   _activeIcon [Rappture::icon nvlegendmark2]
    2830
    29     constructor {c obj args} {
     31    constructor {c obj ivol args} {
    3032        set _canvas $c
    3133        set _nvobj $obj
    32        
     34        set _ivol $ivol
    3335        set w [winfo width $_canvas]
    3436        set h [winfo height $_canvas]
     
    5658    }
    5759    public method GetRelativeValue {} {
    58         array set limits [$_nvobj get_limits]
    59         if { $limits(vmax) == $limits(vmin) } {
    60             set limits(vmin) 0.0
    61             set limits(vmax) 1.0
     60        array set limits [$_nvobj GetLimits $_ivol]
     61        if { $limits(max) == $limits(min) } {
     62            if { $limits(max) == 0.0 } {
     63                set limits(min) 0.0
     64                set limits(max) 1.0
     65            } else {
     66                set limits(max) [expr $limits(min) + 1.0]
     67            }
    6268        }
    63         return [expr {($_value-$limits(vmin))/($limits(vmax) - $limits(vmin))}]
     69        return [expr {($_value-$limits(min))/($limits(max) - $limits(min))}]
    6470    }
    6571    public method Activate { bool } {
     
    102108    }
    103109    public method SetRelativeValue { x } {
    104         array set limits [$_nvobj get_limits]
    105         if { $limits(vmax) == $limits(vmin) } {
    106             set limits(vmin) 0.0
    107             set limits(vmax) 1.0
     110        array set limits [$_nvobj GetLimits $_ivol]
     111        if { $limits(max) == $limits(min) } {
     112            set limits(min) 0.0
     113            set limits(max) 1.0
    108114        }
    109         set r [expr $limits(vmax) - $limits(vmin)]
    110         SetAbsoluteValue [expr {($x * $r) + $limits(vmin)}]
     115        set r [expr $limits(max) - $limits(min)]
     116        SetAbsoluteValue [expr {($x * $r) + $limits(min)}]
    111117    }
    112118    public method HandleEvent { option args } {
     
    131137                SetRelativeValue [expr {double($x-10)/($w-20)}]
    132138                $_nvobj OverIsoMarker $this $x
    133                 $_nvobj UpdateTransferFunction
     139                foreach { dataobj comp } [$_nvobj GetDataObj $_ivol] break
     140                $_nvobj UpdateTransferFunction $dataobj $comp
    134141            }
    135142            end {
  • trunk/gui/scripts/nanovisviewer.tcl

    r966 r968  
    5757    public method delete {args}
    5858    public method scale {args}
    59     public method get_limits { { option ""} } {
    60         return [array get _limits]
     59    public method GetDataObj { ivol } {
     60        if { ![info exists _id2obj($ivol)] } {
     61            return ""
     62        }
     63        return $_id2obj($ivol)
     64    }
     65    public method GetLimits { {ivol ""} } {
     66        if { $ivol != "" } {
     67            set _limits(min) $_limits($ivol-min)
     68            set _limits(max) $_limits($ivol-max)
     69        }
     70        return [array get _limits]
    6171    }
    6272    public method download {option args}
     
    6575    }
    6676    public method isconnected {}
    67     public method UpdateTransferFunction {}
     77    public method UpdateTransferFunction { dataobj comp }
    6878    public method RemoveDuplicateIsoMarker { m x }
    6979    public method OverIsoMarker { m x }
     
    7686    protected method _send_transfuncs {}
    7787
    78     protected method _receive_image {option size}
    79     protected method _receive_legend {ivol vmin vmax size}
    80     protected method _receive_data {args}
     88    protected method _ReceiveImage {option size}
     89    protected method _ReceiveLegend {ivol vmin vmax size}
     90    protected method _ReceiveData {args}
    8191
    8292    protected method _rebuild {}
     
    97107    private method _AddIsoMarker { x y }
    98108    private method _InitIsoMarkers {dataobj comp}
    99     private method _HideIsoMarkers {dataobj}
    100     private method _ShowIsoMarkers {dataobj}
    101     private method _ParseMarkersOption {dataobj markers}
    102     private method _ParseLevelsOption {dataobj markers}
     109    private method _HideIsoMarkers {dataobj comp}
     110    private method _ShowIsoMarkers {dataobj comp}
     111    private method _ParseMarkersOption { tag markers }
     112    private method _ParseLevelsOption { tag levels }
    103113
    104114    private variable _outbuf       ;# buffer for outgoing commands
     
    114124    private variable _sendobjs2 ""  ;# list of data objs to send to server
    115125    private variable _receiveids   ;# list of data objs to send to server
    116     private variable _opacity
    117     private variable _thickness
    118126
    119127    private variable _click        ;# info used for _move operations
     
    155163    # Populate parser with commands handle incoming requests
    156164    #
    157     $_parser alias image [itcl::code $this _receive_image]
    158     $_parser alias legend [itcl::code $this _receive_legend]
    159     $_parser alias data [itcl::code $this _receive_data]
     165    $_parser alias image [itcl::code $this _ReceiveImage]
     166    $_parser alias legend [itcl::code $this _ReceiveLegend]
     167    $_parser alias data [itcl::code $this _ReceiveData]
    160168
    161169    # Initialize the view to some default parameters.
     
    785793        }
    786794    }
     795    foreach key [array names _obj2id *-*] {
     796        set state [string match $first-* $key]
     797        _send "volume state $state $_obj2id($key)"
     798        if {[info exists _obj2style($key)]} {
     799            _send "volume shading transfunc $_obj2style($key) $_obj2id($key)"
     800        }
     801    }
    787802
    788803    # sync the state of slicers
     
    813828            # and make sure that it's defined on the server.
    814829            #
    815             if { ![info exists _isomarkers($dataobj)] } {
     830            if { ![info exists _isomarkers($dataobj-$comp)] } {
    816831                _InitIsoMarkers $dataobj $comp
    817832            } else {
    818                 _HideIsoMarkers $dataobj
     833                _HideIsoMarkers $dataobj $comp
    819834            }
    820835            foreach {sname cmap wmap} [GenTransfuncData $dataobj $comp] break
     
    838853        }
    839854    }
    840     _ShowIsoMarkers $first
     855    set comp [lindex [$dataobj components] 0]
     856    _ShowIsoMarkers $first $comp
    841857    # if there are any commands in the buffer, send them now that we're done
    842858    SendBytes $_outbuf
     
    846862
    847863# ----------------------------------------------------------------------
    848 # USAGE: _receive_image -bytes <size>
     864# USAGE: _ReceiveImage -bytes <size>
    849865#
    850866# Invoked automatically whenever the "image" command comes in from
     
    852868# specified <size> will follow.
    853869# ----------------------------------------------------------------------
    854 itcl::body Rappture::NanovisViewer::_receive_image {option size} {
     870itcl::body Rappture::NanovisViewer::_ReceiveImage {option size} {
    855871    if { [isconnected] } {
    856872        set bytes [ReceiveBytes $size]
     
    861877
    862878# ----------------------------------------------------------------------
    863 # USAGE: _receive_legend <volume> <vmin> <vmax> <size>
     879# USAGE: _ReceiveLegend <volume> <vmin> <vmax> <size>
    864880#
    865881# Invoked automatically whenever the "legend" command comes in from
     
    867883# specified <size> will follow.
    868884# ----------------------------------------------------------------------
    869 itcl::body Rappture::NanovisViewer::_receive_legend { ivol vmin vmax size } {
     885itcl::body Rappture::NanovisViewer::_ReceiveLegend { ivol vmin vmax size } {
    870886    if { [isconnected] } {
    871887        set bytes [ReceiveBytes $size]
     
    887903                [itcl::code $this _AddIsoMarker %x %y]
    888904        }
    889         $c itemconfigure vmin -text $vmin
     905        $c itemconfigure vmin -text $_limits($ivol-min)
    890906        $c coords vmin 10 [expr {$h-8}]
    891907
    892         $c itemconfigure vmax -text $vmax
     908        $c itemconfigure vmax -text  $_limits($ivol-max)
    893909        $c coords vmax [expr {$w-10}] [expr {$h-8}]
    894         set first [lindex [get] 0]
    895         _ShowIsoMarkers $first
    896     }
    897 }
    898 
    899 # ----------------------------------------------------------------------
    900 # USAGE: _receive_data <volume> <vmin> <vmax>
     910
     911        foreach { dataobj comp } $_id2obj($ivol) break
     912        _ShowIsoMarkers $dataobj $comp
     913    }
     914}
     915
     916# ----------------------------------------------------------------------
     917# USAGE: _ReceiveData <volume> <vmin> <vmax>
    901918#
    902919# Invoked automatically whenever the "legend" command comes in from
     
    904921# specified <size> will follow.
    905922# ----------------------------------------------------------------------
    906 itcl::body Rappture::NanovisViewer::_receive_data { args } {
     923itcl::body Rappture::NanovisViewer::_ReceiveData { args } {
    907924    if { [isconnected] } {
    908925        array set info $args
    909926        set volume $info(id)
     927        set _limits($volume-min) $info(min)
     928        set _limits($volume-max) $info(max)
    910929        foreach { dataobj comp } $_id2obj($volume) break
    911        
     930
    912931        if { ![info exists _limits($dataobj-vmin)] } {
    913932            set _limits($dataobj-vmin) $info(min)
     
    944963    }
    945964
    946     #
    947     # Find any new data that needs to be sent to the server.
    948     # Queue this up on the _sendobjs list, and send it out
    949     # a little at a time.  Do this first, before we rebuild
    950     # the rest.
    951     #
     965    # Find any new data that needs to be sent to the server.  Queue this up on
     966    # the _sendobjs list, and send it out a little at a time.  Do this first,
     967    # before we rebuild the rest. 
    952968    foreach dataobj [get] {
    953969        set comp [lindex [$dataobj components] 0]
     
    974990            }
    975991        }
    976         _ShowIsoMarkers $first
    977         UpdateTransferFunction
     992        foreach key [array names _obj2id *-*] {
     993            set state [string match $first-* $key]
     994            _send "volume state $state $_obj2id($key)"
     995        }
     996        set comp [lindex [$dataobj components] 0]
     997        _ShowIsoMarkers $first $comp
     998        UpdateTransferFunction $first $comp
    978999
    9791000        # sync the state of slicers
     
    10031024    _fixSettings outline
    10041025
    1005     if {"" == $itk_option(-plotoutline)} {
    1006         _send "volume outline state off"
    1007     } else {
    1008         _send "volume outline state on"
    1009         set rgb [Color2RGB $itk_option(-plotoutline)]
    1010         _send "volume outline color $rgb"
    1011     }
     1026
     1027#     if {"" == $itk_option(-plotoutline)} {
     1028#         _send "volume outline state off"
     1029#     } else {
     1030#         _send "volume outline state on"
     1031#         set rgb [Color2RGB $itk_option(-plotoutline)]
     1032#         _send "volume outline color $rgb"
     1033#     }
    10121034    _send "volume axis label x \"\""
    10131035    _send "volume axis label y \"\""
     
    12781300            }
    12791301        }
    1280 
    12811302        transp {
    12821303            if {[isconnected]} {
     
    12911312                if {$dataobj != 0} {
    12921313                    set val [$inner.scales.opacity get]
    1293                     set sval [expr {0.01*double($val)}]
    1294                     set _opacity($dataobj) $sval
    1295                     UpdateTransferFunction
     1314                    set sval [expr { 0.01 * double($val) }]
     1315                    set comp [lindex [$dataobj components] 0]
     1316                    set tag $dataobj-$comp
     1317                    set _settings($this-$tag-opacity) $sval
     1318                    UpdateTransferFunction $dataobj $comp
    12961319                }
    12971320            }
    12981321        }
     1322
    12991323        thickness {
    13001324            if {[isconnected]} {
     
    13041328                    # Scale values between 0.00001 and 0.01000
    13051329                    set sval [expr {0.0001*double($val)}]
    1306                     set _thickness($dataobj) $sval
    1307                     UpdateTransferFunction
     1330                    set comp [lindex [$dataobj components] 0]
     1331                    set tag $dataobj-$comp
     1332                    set _settings($this-$tag-thickness) $sval
     1333                    UpdateTransferFunction $dataobj $comp
    13081334                }
    13091335            }
     
    13901416    append cmap "1.0 [Color2RGB $color]"
    13911417
    1392     set max $style(-opacity)
    1393     if { [info exists _opacity($dataobj)] } {
    1394         set max $_opacity($dataobj)
    1395     }
    1396     set key $dataobj
     1418    set tag $dataobj-$comp
     1419    if { ![info exists _settings($this-$tag-opacity)] } {
     1420        set _settings($this-$tag-opacity) $style(-opacity)
     1421    }
     1422    set max $_settings($this-$tag-opacity)
     1423
    13971424    set isovalues {}
    1398     foreach m $_isomarkers($key) {
     1425    foreach m $_isomarkers($tag) {
    13991426        lappend isovalues [$m GetRelativeValue]
    14001427    }
     
    14041431
    14051432    set delta 0.01
    1406     if { [info exists _thickness($dataobj)]} {
    1407         set delta $_thickness($dataobj)
     1433    if { [info exists _settings($this-$tag-thickness)]} {
     1434        set delta $_settings($this-$tag-thickness)
    14081435    }
    14091436    set first [lindex $isovalues 0]
     
    14821509}
    14831510
    1484 itcl::body Rappture::NanovisViewer::_HideIsoMarkers {dataobj} {
    1485     if { [info exists _isomarkers($dataobj)] } {
    1486         foreach m $_isomarkers($dataobj) {
     1511itcl::body Rappture::NanovisViewer::_HideIsoMarkers {dataobj comp} {
     1512    set tag $dataobj-$comp
     1513    if { [info exists _isomarkers($tag)] } {
     1514        foreach m $_isomarkers($tag) {
    14871515            $m Hide
    14881516        }
     
    14901518}
    14911519
    1492 itcl::body Rappture::NanovisViewer::_ShowIsoMarkers {dataobj} {
    1493     foreach obj [array names _all_data_objs] {
    1494         _HideIsoMarkers $obj
    1495     }
    1496     if { ![info exists _isomarkers($dataobj)] } {
     1520itcl::body Rappture::NanovisViewer::_ShowIsoMarkers {dataobj comp} {
     1521    set tag $dataobj-$comp
     1522    foreach dataobj [array names _all_data_objs] {
     1523        foreach comp [$dataobj components] {
     1524            _HideIsoMarkers $dataobj $comp
     1525        }
     1526    }
     1527    if { ![info exists _isomarkers($tag)] } {
    14971528        return
    14981529    }
    1499     foreach m $_isomarkers($dataobj) {
     1530    foreach m $_isomarkers($tag) {
    15001531        $m Show
    15011532    }
     
    15071538# marker is a relative value from 0.0 to 1.0.
    15081539#
    1509 itcl::body Rappture::NanovisViewer::_ParseLevelsOption {dataobj levels} {
     1540itcl::body Rappture::NanovisViewer::_ParseLevelsOption { tag levels } {
    15101541    set c $itk_component(legend)
     1542    set ivol $_obj2id($tag)
    15111543    regsub -all "," $levels " " levels
    15121544    for {set i 1} { $i <= $levels } {incr i} {
    15131545        set x [expr {double($i)/($levels+1)}]
    1514         set m [IsoMarker \#auto $c $this]
     1546        set m [IsoMarker \#auto $c $this $ivol]
    15151547        $m SetRelativeValue $x
    1516         lappend _isomarkers($dataobj) $m
     1548        lappend _isomarkers($tag) $m
    15171549    }
    15181550}
     
    15301562#               not be seen.
    15311563#
    1532 itcl::body Rappture::NanovisViewer::_ParseMarkersOption {dataobj markers} {
     1564itcl::body Rappture::NanovisViewer::_ParseMarkersOption {tag markers} {
    15331565    set c $itk_component(legend)
    15341566    regsub -all "," $markers " " markers
     1567    set ivol $_obj2id($tag)
    15351568    foreach marker $markers {
    15361569        set n [scan $marker "%g%s" value suffix]
     
    15381571            # ${n}% : Set relative value.
    15391572            set value [expr {$value * 0.01}]
    1540             set m [IsoMarker \#auto $c $this]
     1573            set m [IsoMarker \#auto $c $this $ivol]
    15411574            $m SetRelativeValue $value
    1542             lappend _isomarkers($dataobj) $m
     1575            lappend _isomarkers($tag) $m
    15431576        } else {
    15441577            # ${n} : Set absolute value.
    1545             set m [IsoMarker \#auto $c $this]
     1578            set m [IsoMarker \#auto $c $this $ivol]
    15461579            $m SetAbsoluteValue $value
    1547             lappend _isomarkers($dataobj) $m
     1580            lappend _isomarkers($tag) $m
    15481581        }
    15491582    }
     
    15551588    }
    15561589    array set style [lindex [$dataobj components -style $comp] 0]
     1590    set tag $dataobj-$comp
    15571591    if { [info exists style(-markers)] } {
    1558         _ParseMarkersOption $dataobj $style(-markers)
     1592        _ParseMarkersOption $tag $style(-markers)
    15591593    } else {
    1560         _ParseLevelsOption $dataobj $style(-levels)
     1594        _ParseLevelsOption $tag $style(-levels)
    15611595    }
    15621596}
     
    15721606# legend.
    15731607# ----------------------------------------------------------------------
    1574 itcl::body Rappture::NanovisViewer::UpdateTransferFunction {} {
    1575     set dataobj [lindex [get] 0]
     1608itcl::body Rappture::NanovisViewer::UpdateTransferFunction { dataobj comp } {
    15761609    if {"" == $dataobj} {
    15771610        return
    15781611    }
    1579     set comp [lindex [$dataobj components] 0]
    1580     set key $dataobj-$comp
    1581     if {![info exists _obj2style($key)]} {
     1612    set tag $dataobj-$comp
     1613    if {![info exists _obj2style($tag)]} {
    15821614        return
    15831615    }
    15841616    # Compute a transfer function for the current data set.
    15851617    foreach {sname cmap wmap} [GenTransfuncData $dataobj $comp] break
    1586     _send [list transfunc define $_obj2style($key) $cmap $wmap]
    1587     _send [list volume shading transfunc $_obj2style($key) $_obj2id($key)]
     1618    _send [list transfunc define $_obj2style($tag) $cmap $wmap]
     1619    _send [list volume shading transfunc $_obj2style($tag) $_obj2id($tag)]
    15881620    _fixLegend
    15891621}
     
    15941626        return 0;                       # No data sets defined
    15951627    }
     1628    set comp [lindex [$dataobj components] 0]
     1629    set ivol $_obj2id($dataobj-$comp)
    15961630    set c $itk_component(legend)
    1597     set m [IsoMarker \#auto $c $this]
     1631    set m [IsoMarker \#auto $c $this $ivol]
    15981632    set w [winfo width $c]
    15991633    $m SetRelativeValue [expr {double($x-10)/($w-20)}]
Note: See TracChangeset for help on using the changeset viewer.