Changeset 1013 for trunk/gui/scripts


Ignore:
Timestamp:
Jun 8, 2008, 4:44:42 PM (16 years ago)
Author:
gah
Message:

isomarker fixes (markers grouped by transfer-function not volume)

Location:
trunk/gui/scripts
Files:
7 edited

Legend:

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

    r811 r1013  
    2929    public method limits {which}
    3030    public method hints {{key ""}}
     31    public method xmarkers {}
     32    public method ymarkers {}
    3133
    3234    protected method _build {}
     
    3638    private variable _comp2xy    ;# maps component name => x,y vectors
    3739    private variable _hints      ;# cache of hints stored in XML
     40
     41    private variable _xmarkers "";# list of {x,label,options} triplets.
     42    private variable _ymarkers "";# list of {y,label,options} triplets.
    3843
    3944    private common _counter 0    ;# counter for unique vector names
     
    279284        }
    280285    }
    281 }
     286    # Creates lists of x and y marker data.
     287    set _xmarkers {}
     288    set _ymarkers {}
     289    foreach cname [$_curve children -type "marker" xaxis] {
     290        set at     [$_curve get "xaxis.$cname.at"]
     291        set label  [$_curve get "xaxis.$cname.label"]
     292        set styles [$_curve get "xaxis.$cname.style"]
     293        set data [list $at $label $styles]
     294        lappend _xmarkers $data
     295    }
     296    foreach cname [$_curve children -type "marker" yaxis] {
     297        set at     [$_curve get "yaxis.$cname.at"]
     298        set label  [$_curve get "yaxis.$cname.label"]
     299        set styles [$_curve get "yaxis.$cname.style"]
     300        set data [list $at $label $styles]
     301        lappend _xmarkers $data
     302    }
     303}
     304
     305# ----------------------------------------------------------------------
     306# USAGE: xmarkers
     307#
     308# Returns the list of settings for each marker on the x-axis.
     309# If no markers have been specified the empty string is returned.
     310# ----------------------------------------------------------------------
     311itcl::body Rappture::Curve::xmarkers {} {
     312    return $_xmarkers;
     313}
     314
     315# ----------------------------------------------------------------------
     316# USAGE: ymarkers
     317#
     318# Returns the list of settings for each marker on the y-axis.
     319# If no markers have been specified the empty string is returned.
     320# ----------------------------------------------------------------------
     321itcl::body Rappture::Curve::ymarkers {} {
     322    return $_ymarkers;
     323}
  • trunk/gui/scripts/heightmapviewer.tcl

    r935 r1013  
    568568    foreach dataobj $_sendobjs {
    569569        foreach comp [$dataobj components] {
    570             # send the data as one huge base64-encoded mess -- yuck!
    571570            set data [$dataobj blob $comp]
    572571
     
    950949    }
    951950    set clist [split $style(-color) :]
    952     set cmap "0.0 [Color2RGB white] "
     951    set color white
     952    set cmap "0.0 [Color2RGB $color] "
     953    append cmap "$_limits(vmin) [Color2RGB $color] "
     954    set range [expr $_limits(vmax) - $_limits(vmin)]
    953955    for {set i 0} {$i < [llength $clist]} {incr i} {
    954956        set xval [expr {double($i+1)/([llength $clist]+1)}]
     957        set xval [expr ($xval * $range) + $_limits(vmin)]
    955958        set color [lindex $clist $i]
    956959        append cmap "$xval [Color2RGB $color] "
    957960    }
     961    append cmap "$_limits(vmax) [Color2RGB $color] "
    958962    append cmap "1.0 [Color2RGB $color]"
    959963
    960     set max $style(-opacity)
     964    set opacity $style(-opacity)
    961965    set levels $style(-levels)
     966    set wmap {}
    962967    if {[string is int $levels]} {
    963         set wmap "0.0 0.0 "
     968        lappend wmap 0.0 0.0
    964969        set delta [expr {0.125/($levels+1)}]
    965970        for {set i 1} {$i <= $levels} {incr i} {
    966971            # add spikes in the middle
    967972            set xval [expr {double($i)/($levels+1)}]
    968             append wmap "[expr {$xval-$delta-0.01}] 0.0  [expr {$xval-$delta}] $max [expr {$xval+$delta}] $max  [expr {$xval+$delta+0.01}] 0.0 "
    969         }
    970         append wmap "1.0 0.0 "
     973            lappend wmap [expr {$xval-$delta-0.01}] 0.0
     974            lappend wmap [expr {$xval-$delta}] $opacity
     975            lappend wmap [expr {$xval+$delta}] $opacity
     976            lappend wmap [expr {$xval+$delta+0.01}] 0.0
     977        }
     978        lappend wmap 1.0 0.0
    971979    } else {
    972         set wmap "0.0 0.0 "
     980        lappend wmap 0.0 0.0
    973981        set delta 0.05
    974982        foreach xval [split $levels ,] {
    975             append wmap "[expr {$xval-$delta}] 0.0  $xval $max [expr {$xval+$delta}] 0.0 "
    976         }
    977         append wmap "1.0 0.0 "
     983            lappend wmap [expr {$xval-$delta}] 0.0 
     984            lappend $xval $opacity
     985            lappend [expr {$xval+$delta}] 0.0
     986        }
     987        lappend wmap 1.0 0.0
    978988    }
    979989
  • trunk/gui/scripts/isomarker.tcl

    r988 r1013  
    2323    private variable _canvas    ""
    2424    private variable _nvobj     "";     # Parent nanovis object.
    25     private variable _ivol      "";     # Id of volume that this marker is
     25    private variable _ivol      "";     # Transfer function that this marker is
    2626                                        # associated with.
    2727    private variable _active_motion   0
     
    5555    }
    5656    public method GetVolume {} {
    57         return $_ivol
     57        return $_ivol
    5858    }
    5959    public method GetAbsoluteValue {} {
     
    141141                SetRelativeValue [expr {double($x-10)/($w-20)}]
    142142                $_nvobj OverIsoMarker $this $x
    143                 $_nvobj UpdateTransferFunction $_ivol
     143                $_nvobj UpdateTransferFunctions
    144144            }
    145145            end {
  • trunk/gui/scripts/molvisviewer.tcl

    r935 r1013  
    7878    protected method _vmouse  {option b m x y}
    7979
    80     private method _receive_image { args }
     80    private method _receive_image { size cacheid frame rock }
    8181
    8282    private variable _inrebuild 0
  • trunk/gui/scripts/nanovisviewer.tcl

    r975 r1013  
    5757    public method delete {args}
    5858    public method scale {args}
    59     public method GetLimits { {ivol ""} } {
    60         if { $ivol != "" } {
    61             set _limits(min) $_limits($ivol-min)
    62             set _limits(max) $_limits($ivol-max)
     59    public method GetLimits { ivol } {
     60        if { if [info exists _id2style($ivol)] } {
     61            set tf $_id2style($ivol)
     62            set _limits(min) ""
     63            set _limits(max) ""
     64            foreach ivol $_style2ids($tf) {
     65            if { ![info exists _limits($ivol-min)] } {
     66                puts stderr "In GetLimits $ivol"
     67                parray _limits
     68                error "can't find $ivol limits"
     69            }
     70                if { $_limits(min) == "" ||
     71                     $_limits(min) > $_limits($ivol-min) } {
     72                    set _limits(min) $_limits($ivol-min)
     73                }
     74                if { $_limits(max) == "" ||
     75                     $_limits(max) < $_limits($ivol-max) } {
     76                    set _limits(max) $_limits($ivol-max)
     77                }
     78            }
    6379        }
    6480        return [array get _limits]
     
    6985    }
    7086    public method isconnected {}
    71     public method UpdateTransferFunction { ivol }
     87    public method UpdateTransferFunctions {}
    7288    public method RemoveDuplicateIsoMarker { m x }
    7389    public method OverIsoMarker { m x }
     
    7793
    7894    protected method _send {string}
    79     protected method _send_dataobjs {}
    80     protected method _send_transfunc {}
     95    protected method _SendDataObjs {}
     96    protected method _SendTransferFunctions {}
    8197
    8298    protected method _ReceiveImage {option size}
    8399    protected method _ReceiveLegend { ivol vmin vmax size }
    84100    protected method _ReceiveData { args }
     101    protected method _ReceivePrint { option size }
    85102
    86103    protected method _rebuild {}
     
    98115
    99116    # The following methods are only used by this class.
    100     private method _DefineTransferFunction { ivol }
     117    private method _NameTransferFunction { ivol }
     118    private method _ComputeTransferFunction { tf }
    101119    private method _AddIsoMarker { x y }
    102     private method _InitIsoMarkers { ivol }
    103     private method _HideIsoMarkers { ivol }
    104     private method _ShowIsoMarkers { ivol }
    105     private method _ParseMarkersOption { ivol markers }
    106     private method _ParseLevelsOption { ivol levels }
     120    private method _ParseMarkersOption { tf ivol markers }
     121    private method _ParseLevelsOption { tf ivol levels }
    107122
    108123    private variable _outbuf       ;# buffer for outgoing commands
     
    116131    private variable _id2obj       ;# maps dataobj => volume ID in server
    117132    private variable _sendobjs ""  ;# list of data objs to send to server
    118     private variable _sendobjs2 ""  ;# list of data objs to send to server
    119133    private variable _receiveids   ;# list of data objs to send to server
     134    private variable _obj2styles   ;# maps id => style settings
     135    private variable _style2ids    ;# maps id => style settings
    120136
    121137    private variable _click        ;# info used for _move operations
     
    126142    private variable _styles
    127143    private common   _settings
    128     private variable _activeVol "" ;# The currently active volume.  This
     144    private variable _activeId ""  ;# The currently active volume.  This
    129145                                    # indicates which isomarkers and transfer
    130146                                    # function to use when changing markers,
    131147                                    # opacity, or thickness.
     148    #common _downloadPopup          ;# download options from popup
    132149}
    133150
     
    148165    $_dispatcher register !send_dataobjs
    149166    $_dispatcher dispatch $this !send_dataobjs \
    150         "[itcl::code $this _send_dataobjs]; list"
     167        "[itcl::code $this _SendDataObjs]; list"
    151168    # Send transfer functions event
    152169    $_dispatcher register !send_transfunc
    153170    $_dispatcher dispatch $this !send_transfunc \
    154         "[itcl::code $this _send_transfunc]; list"
     171        "[itcl::code $this _SendTransferFunctions]; list"
    155172    # Rebuild event
    156173    $_dispatcher register !rebuild
     
    165182    $_parser alias legend [itcl::code $this _ReceiveLegend]
    166183    $_parser alias data [itcl::code $this _ReceiveData]
     184    #$_parser alias print [itcl::code $this _ReceivePrint]
    167185
    168186    # Initialize the view to some default parameters.
     
    423441    label $inner.scales.thickl -text "Thick" -font $fg
    424442    grid $inner.scales.thickl -row 3 -column 2 -sticky w
    425     $inner.scales.thickness set 500
     443    $inner.scales.thickness set 350
    426444
    427445    set ::Rappture::NanovisViewer::_settings($this-isosurface) 0
     
    489507itcl::body Rappture::NanovisViewer::destructor {} {
    490508    set _sendobjs ""  ;# stop any send in progress
    491     set _sendobjs2 ""  ;# stop any send in progress
    492509    $_dispatcher cancel !rebuild
    493510    $_dispatcher cancel !send_dataobjs
     
    599616        set args $_dlist
    600617    }
    601 
    602618    # delete all specified dataobjs
    603619    set changed 0
     
    612628        }
    613629    }
    614 
    615630    # if anything changed, then rebuild the plot
    616631    if {$changed} {
     
    634649    foreach obj $args {
    635650        foreach axis {x y z v} {
    636             foreach {min max} [$obj limits $axis] break
     651
     652            foreach { min max } [$obj limits $axis] break
     653
    637654            if {"" != $min && "" != $max} {
    638655                if {"" == $_limits(${axis}min)} {
     
    728745    set _id2obj(count) 0
    729746    set _sendobjs ""
    730     set _sendobjs2 ""
    731747}
    732748
     
    751767
    752768# ----------------------------------------------------------------------
    753 # USAGE: _send_dataobjs
     769# USAGE: _SendDataObjs
    754770#
    755771# Used internally to send a series of volume objects off to the
     
    757773# between so the interface doesn't lock up.
    758774# ----------------------------------------------------------------------
    759 itcl::body Rappture::NanovisViewer::_send_dataobjs {} {
     775itcl::body Rappture::NanovisViewer::_SendDataObjs {} {
    760776    blt::busy hold $itk_component(hull); update idletasks
    761 
    762777    foreach dataobj $_sendobjs {
    763778        foreach comp [$dataobj components] {
     
    776791            set _id2obj($ivol) [list $dataobj $comp]
    777792            set _obj2id($dataobj-$comp) $ivol
     793            _NameTransferFunction $ivol
    778794            set _receiveids($ivol) 1
    779 
    780795        }
    781796    }
     
    790805            _send "up $axis"
    791806        }
     807        # The active volume is by default the first component of the first
     808        # data object.  This assumes that the data is always successfully
     809        # transferred.
     810        set comp [lindex [$first components] 0]
     811        set _activeId $_obj2id($first-$comp)
    792812    }
    793813    foreach key [array names _obj2id *-*] {
     
    795815        set ivol $_obj2id($key)
    796816        _send "volume state $state $ivol"
    797         if {[info exists _id2style($ivol)]} {
    798             _send "volume shading transfunc $_id2style($ivol) $ivol"
    799         }
    800817    }
    801818
     
    809826    _send "volume data state [_state volume] $vols"
    810827
     828    if 0 {
     829    _send "volume axis label x \"\""
     830    _send "volume axis label y \"\""
     831    _send "volume axis label z \"\""
     832    _send "grid axisname x X eV"
     833    _send "grid axisname y Y eV"
     834    _send "grid axisname z Z eV"
     835    }
    811836    # if there are any commands in the buffer, send them now that we're done
    812837    SendBytes $_outbuf
     
    817842
    818843# ----------------------------------------------------------------------
    819 # USAGE: _send_transfunc
    820 # ----------------------------------------------------------------------
    821 itcl::body Rappture::NanovisViewer::_send_transfunc {} {
    822     if { ![_DefineTransferFunction $_activeVol] } {
    823         return
    824     }
    825     _fixLegend
     844# USAGE: _SendTransferFunctions
     845# ----------------------------------------------------------------------
     846itcl::body Rappture::NanovisViewer::_SendTransferFunctions {} {
     847    set first [lindex [get] 0]
     848
     849    # Insure that the global opacity and thickness settings (in the slider
     850    # settings widgets) are used for the transfer-function used by the active
     851    # volume.  Update the values in the _settings varible.
     852    set inner [$itk_component(controls).panel component inner]
     853    set tf $_id2style($_activeId)
     854    set value [$inner.scales.opacity get]
     855    set opacity [expr { double($value) * 0.01 }]
     856    set _settings($this-$tf-opacity) $opacity
     857    set value [$inner.scales.thickness get]
     858    # Scale values between 0.00001 and 0.01000
     859    set thickness [expr {double($value) * 0.0001}]
     860    set _settings($this-$tf-thickness) $thickness
     861
     862    if { ![info exists $_obj2styles($first)] } {
     863        foreach tf $_obj2styles($first) {
     864            if { ![_ComputeTransferFunction $tf] } {
     865                return
     866            }
     867        }
     868        _fixLegend
     869    }
    826870}
    827871
     
    844888}
    845889
    846 # ----------------------------------------------------------------------
    847 # USAGE: _ReceiveLegend <volume> <vmin> <vmax> <size>
    848 #
    849 # Invoked automatically whenever the "legend" command comes in from
     890#
     891# _ReceiveLegend --
     892#
     893#       The procedure is the response from the render server to each "legend"
     894#       command.  The server sends back a "legend" command invoked our
     895#       the slave interpreter.  The purpose is to collect data of the image
     896#       representing the legend in the canvas.  In addition, the isomarkers
     897#       of the active volume are displayed.
     898#
     899#       I don't know is this is the right place to display the isomarkers.
     900#       I don't know all the different paths used to draw the plot. There's
     901#       "_rebuild", "add", etc.
     902#
     903itcl::body Rappture::NanovisViewer::_ReceiveLegend { ivol vmin vmax size } {
     904    if { ![isconnected] } {
     905        return
     906    }
     907    set bytes [ReceiveBytes $size]
     908    $_image(legend) configure -data $bytes
     909    ReceiveEcho <<line "<read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
     910   
     911    set c $itk_component(legend)
     912    set w [winfo width $c]
     913    set h [winfo height $c]
     914    foreach { dataobj comp } $_id2obj($ivol) break
     915    set lx 10
     916    set ly [expr {$h - 1}]
     917    if {"" == [$c find withtag transfunc]} {
     918        $c create image 10 10 -anchor nw \
     919            -image $_image(legend) -tags transfunc
     920        $c create text $lx $ly -anchor sw \
     921            -fill $itk_option(-plotforeground) -tags "limits vmin"
     922        $c create text [expr {$w-$lx}] $ly -anchor se \
     923            -fill $itk_option(-plotforeground) -tags "limits vmax"
     924        $c lower transfunc
     925        $c bind transfunc <ButtonRelease-1> \
     926            [itcl::code $this _AddIsoMarker %x %y]
     927    }
     928    array set limits [GetLimits $ivol]
     929    $c itemconfigure vmin -text [format %.2g $limits(min)]
     930    $c coords vmin $lx $ly
     931   
     932    $c itemconfigure vmax -text [format %.2g $limits(max)]
     933    $c coords vmax [expr {$w-$lx}] $ly
     934
     935    # Display the markers used by the active volume.
     936    set tf $_id2style($_activeId)
     937    if { [info exists _isomarkers($tf)] } {
     938        foreach m $_isomarkers($tf) {
     939            $m Show
     940        }
     941    }
     942}
     943
     944#
     945# _ReceiveData --
     946#
     947#       The procedure is the response from the render server to each "data
     948#       follows" command.  The server sends back a "data" command invoked our
     949#       the slave interpreter.  The purpose is to collect the min/max of the
     950#       volume sent to the render server.  Since the client (nanovisviewer)
     951#       doesn't parse 3D data formats, we rely on the server (nanovis) to
     952#       tell us what the limits are.  Once we've received the limits to all
     953#       the data we've sent (tracked by _receiveids) we can then determine
     954#       what the transfer functions are for these volumes.
     955#
     956#
     957#       Note: There is a considerable tradeoff in having the server report
     958#             back what the data limits are.  It means that much of the code
     959#             having to do with transfer-functions has to wait for the data
     960#             to come back, since the isomarkers are calculated based upon
     961#             the data limits.  The client code is much messier because of
     962#             this.  The alternative is to parse any of the 3D formats on the
     963#             client side. 
     964#
     965itcl::body Rappture::NanovisViewer::_ReceiveData { args } {
     966    if { ![isconnected] } {
     967        return
     968    }
     969    # Arguments from server are name value pairs. Stuff them in an array.
     970    array set info $args
     971
     972    set ivol $info(id);                 # Id of volume created by server.
     973
     974    set _limits($ivol-min) $info(min);  # Minimum value of the volume.
     975    set _limits($ivol-max) $info(max);  # Maximum value of the volume.
     976    set _limits(vmin)      $info(vmin); # Overall minimum value.
     977    set _limits(vmax)      $info(vmax); # Overall maximum value.
     978
     979    unset _receiveids($ivol)
     980    if { [array size _receiveids] == 0 } {
     981        UpdateTransferFunctions
     982    }
     983}
     984
     985# ----------------------------------------------------------------------
     986# USAGE: _ReceivePrint -bytes <size>
     987#
     988# Invoked automatically whenever the "image" command comes in from
    850989# the rendering server.  Indicates that binary image data with the
    851990# specified <size> will follow.
    852991# ----------------------------------------------------------------------
    853 itcl::body Rappture::NanovisViewer::_ReceiveLegend { ivol vmin vmax size } {
     992itcl::body Rappture::NanovisViewer::_ReceivePrint {option size} {
    854993    if { [isconnected] } {
    855994        set bytes [ReceiveBytes $size]
    856         $_image(legend) configure -data $bytes
    857         ReceiveEcho <<line "<read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
    858 
    859         set c $itk_component(legend)
    860         set w [winfo width $c]
    861         set h [winfo height $c]
    862         foreach { dataobj comp } $_id2obj($ivol) break
    863         if {"" == [$c find withtag transfunc]} {
    864             $c create image 10 10 -anchor nw \
    865                  -image $_image(legend) -tags transfunc
    866             $c create text 10 [expr {$h-8}] -anchor sw \
    867                  -fill $itk_option(-plotforeground) -tags vmin
    868             $c create text [expr {$w-10}] [expr {$h-8}] -anchor se \
    869                  -fill $itk_option(-plotforeground) -tags vmax
    870             $c lower transfunc
    871             $c bind transfunc <ButtonRelease-1> \
    872                 [itcl::code $this _AddIsoMarker %x %y]
    873         }
    874         $c itemconfigure vmin -text $_limits($ivol-min)
    875         $c coords vmin 10 [expr {$h-8}]
    876 
    877         $c itemconfigure vmax -text  $_limits($ivol-max)
    878         $c coords vmax [expr {$w-10}] [expr {$h-8}]
    879 
    880         _ShowIsoMarkers $ivol
    881     }
    882 }
    883 
    884 # ----------------------------------------------------------------------
    885 # USAGE: _ReceiveData <volume> <vmin> <vmax>
    886 #
    887 # Invoked automatically whenever the "legend" command comes in from
    888 # the rendering server.  Indicates that binary image data with the
    889 # specified <size> will follow.
    890 # ----------------------------------------------------------------------
    891 itcl::body Rappture::NanovisViewer::_ReceiveData { args } {
    892     if { [isconnected] } {
    893         array set info $args
    894         set ivol $info(id)
    895         set _limits($ivol-min) $info(min)
    896         set _limits($ivol-max) $info(max)
    897         foreach { dataobj comp } $_id2obj($ivol) break
    898 
    899         if { ![info exists _limits($dataobj-vmin)] } {
    900             set _limits($dataobj-vmin) $info(min)
    901             set _limits($dataobj-vmax) $info(max)
    902         } else {
    903             if { $_limits($dataobj-vmin) > $info(min) } {
    904                 set _limits($dataobj-vmin) $info(min)
    905             }
    906             if { $_limits($dataobj-vmax) < $info(max) } {
    907                 set _limits($dataobj-vmax) $info(max)
    908             }
    909         }
    910         set _limits(vmin) $info(vmin)
    911         set _limits(vmax) $info(vmax)
    912         lappend _sendobjs2 $dataobj
    913         unset _receiveids($info(id))
    914 
    915         if { ![info exists _isomarkers($ivol)] } {
    916             _InitIsoMarkers $ivol
    917         } else {
    918             _HideIsoMarkers $ivol
    919         }
    920         # We can update the transfer function now that we know the data limits.
    921         if { ![_DefineTransferFunction $ivol] } {
    922             return
    923         }
    924     }
    925     if { [array size _receiveids] == 0 } {
    926         _fixLegend
     995        set f [open /tmp/junk "w"]
     996        puts $f $bytes
     997        close $f
     998        $_image(download) configure -data $bytes
     999        update
     1000        puts stderr "<read $size bytes for [image width $_image(download)]x[image height $_image(download)] image>"
    9271001    }
    9281002}
     
    9361010# ----------------------------------------------------------------------
    9371011itcl::body Rappture::NanovisViewer::_rebuild {} {
     1012    # Hide all the isomarkers. Can't remove them. Have to remember the
     1013    # settings since the user may have created/deleted/moved markers.
     1014
     1015    foreach tf [array names _isomarkers] {
     1016        foreach m $_isomarkers($tf) {
     1017            $m Hide
     1018        }
     1019    }
     1020
    9381021    # in the midst of sending data? then bail out
    9391022    if {[llength $_sendobjs] > 0} {
     
    9561039        # send off new data objects
    9571040        $_dispatcher event -idle !send_dataobjs
    958     } else {
    959         set w [winfo width $itk_component(3dview)]
    960         set h [winfo height $itk_component(3dview)]
    961         _send "screen $w $h"
    962         # nothing to send -- activate the proper ivol
    963         set first [lindex [get] 0]
    964         if {"" != $first} {
    965             set axis [$first hints updir]
    966             if {"" != $axis} {
    967                 _send "up $axis"
    968             }
    969         }
     1041        return
     1042    }
     1043
     1044    set w [winfo width $itk_component(3dview)]
     1045    set h [winfo height $itk_component(3dview)]
     1046    _send "screen $w $h"
     1047
     1048    # nothing to send -- activate the proper ivol
     1049    set first [lindex [get] 0]
     1050    if {"" != $first} {
     1051        set axis [$first hints updir]
     1052        if {"" != $axis} {
     1053            _send "up $axis"
     1054        }
    9701055        foreach key [array names _obj2id *-*] {
    9711056            set state [string match $first-* $key]
    9721057            _send "volume state $state $_obj2id($key)"
    9731058        }
    974         set comp [lindex [$dataobj components] 0]
     1059        #
     1060        # The _obj2id and _id2style arrays may or may not have the right
     1061        # information.  It's possible for the server to know about volumes
     1062        # that the client has assumed it's deleted.  We could add checks.
     1063        # But this problem needs to be fixed not bandaided. 
     1064        set comp [lindex [$first components] 0]
    9751065        set ivol $_obj2id($first-$comp)
    976 
    977         _ShowIsoMarkers $ivol
    978 
    979         if { [info exists _settings($this-$ivol-opacity)] } {
    980             set inner [$itk_component(controls).panel component inner]
    981             set sval $_settings($this-$ivol-opacity)
    982             set sval [expr {round($sval * 100)}]
    983             $inner.scales.opacity set $sval
     1066       
     1067        set tf _id2style($ivol)
     1068   
     1069        foreach comp [$first components] {
     1070            foreach ivol $_obj2id($first-$comp) {
     1071                _NameTransferFunction $ivol
     1072            }
    9841073        }
    985         if { [info exists _settings($this-$ivol-thickness)] } {
    986             set inner [$itk_component(controls).panel component inner]
    987             set sval $_settings($this-$ivol-thickness)
    988             set sval [expr {round($sval * 10000.0)}]
    989             $inner.scales.thickness set $sval
    990         }
    991         UpdateTransferFunction $ivol
    992 
    993         # sync the state of slicers
    994         set vols [_currentVolumeIds -cutplanes]
    995         foreach axis {x y z} {
    996             _send "cutplane state [_state ${axis}slice] $axis $vols"
    997             set pos [expr {0.01*[$itk_component(${axis}slicer) get]}]
    998             _send "cutplane position $pos $axis $vols"
    999         }
    1000         _send "volume data state [_state volume] $vols"
    1001         $_dispatcher event -idle !legend
    1002     }
    1003 
     1074    }
     1075
     1076    # sync the state of slicers
     1077    set vols [_currentVolumeIds -cutplanes]
     1078    foreach axis {x y z} {
     1079        _send "cutplane state [_state ${axis}slice] $axis $vols"
     1080        set pos [expr {0.01*[$itk_component(${axis}slicer) get]}]
     1081        _send "cutplane position $pos $axis $vols"
     1082    }
     1083    _send "volume data state [_state volume] $vols"
     1084    $_dispatcher event -idle !legend
     1085   
    10041086    #
    10051087    # Reset the camera and other view parameters
     
    10071089    _send "camera angle [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)]"
    10081090    _send "camera zoom $_view(zoom)"
    1009 
     1091   
    10101092    _fixSettings light
    10111093    _fixSettings transp
    10121094    _fixSettings isosurface
    1013     _fixSettings opacity
    1014     _fixSettings thickness
    10151095    _fixSettings grid
    10161096    _fixSettings axes
    10171097    _fixSettings outline
    1018 
    1019 
    1020 #     if {"" == $itk_option(-plotoutline)} {
    1021 #         _send "volume outline state off"
    1022 #     } else {
    1023 #         _send "volume outline state on"
    1024 #         set rgb [Color2RGB $itk_option(-plotoutline)]
    1025 #         _send "volume outline color $rgb"
    1026 #     }
    1027     _send "volume axis label x \"\""
    1028     _send "volume axis label y \"\""
    1029     _send "volume axis label z \"\""
    10301098}
    10311099
     
    13011369        }
    13021370        opacity {
    1303             if {[isconnected] && $_activeVol != "" } {
     1371            if {[isconnected] && $_activeId != "" } {
    13041372                set val [$inner.scales.opacity get]
    13051373                set sval [expr { 0.01 * double($val) }]
    1306                 set ivol $_activeVol
    1307                 set _settings($this-$ivol-opacity) $sval
    1308                 UpdateTransferFunction $ivol
     1374                set tf $_id2style($_activeId)
     1375                set _settings($this-$tf-opacity) $sval
     1376                UpdateTransferFunctions
    13091377            }
    13101378        }
    13111379
    13121380        thickness {
    1313             if {[isconnected] && $_activeVol != "" } {
     1381            if {[isconnected] && $_activeId != "" } {
    13141382                set val [$inner.scales.thickness get]
    13151383                # Scale values between 0.00001 and 0.01000
    13161384                set sval [expr {0.0001*double($val)}]
    1317                 set ivol $_activeVol
    1318                 set _settings($this-$ivol-thickness) $sval
    1319                 UpdateTransferFunction $ivol
     1385                set tf $_id2style($_activeId)
     1386                set _settings($this-$tf-thickness) $sval
     1387                UpdateTransferFunctions
    13201388            }
    13211389        }
     
    13571425    set w [expr {[winfo width $itk_component(legend)]-20}]
    13581426    set h [expr {[winfo height $itk_component(legend)]-20-$lineht}]
    1359     set ivol $_activeVol
     1427    set ivol $_activeId
    13601428    if {$w > 0 && $h > 0 && "" != $ivol} {
    13611429        _send "legend $ivol $w $h"
    13621430    } else {
    1363         #$itk_component(legend) delete all
    1364     }
    1365 }
    1366 
    1367 # ----------------------------------------------------------------------
    1368 # USAGE: _DefineTransferFunction <ivol>
    1369 #
    1370 # Used internally to compute the colormap and alpha map used to define
    1371 # a transfer function for the specified component in a data object.
    1372 # Returns: name {v r g b ...} {v w ...}
    1373 # ----------------------------------------------------------------------
    1374 itcl::body Rappture::NanovisViewer::_DefineTransferFunction { ivol } {
     1431        # Can't do this as this will remove the items associated with the
     1432        # isomarkers. 
     1433
     1434        #$itk_component(legend) delete all
     1435    }
     1436}
     1437
     1438#
     1439# _NameTransferFunction --
     1440#
     1441#       Creates a transfer function name based on the <style> settings in the
     1442#       library run.xml file. This placeholder will be used later to create
     1443#       and send the actual transfer function once the data info has been sent
     1444#       to us by the render server. [We won't know the volume limits until the
     1445#       server parses the 3D data and sends back the limits via _ReceiveData.]
     1446#
     1447#       FIXME: The current way we generate transfer-function names completely
     1448#             ignores the -markers option.  The problem is that we are forced
     1449#             to compute the name from an increasing complex set of values:
     1450#             color, levels, marker, opacity.  I think we're stuck doing it
     1451#             now.
     1452#
     1453itcl::body Rappture::NanovisViewer::_NameTransferFunction { ivol } {
    13751454    array set style {
    13761455        -color rainbow
     
    13801459    foreach {dataobj comp} $_id2obj($ivol) break
    13811460    array set style [lindex [$dataobj components -style $comp] 0]
    1382     set sname "$style(-color):$style(-levels):$style(-opacity)"
     1461    set tf "$style(-color):$style(-levels):$style(-opacity)"
     1462
     1463    set _id2style($ivol) $tf
     1464    lappend _obj2styles($dataobj) $tf
     1465    lappend _style2ids($tf) $ivol
     1466}
     1467
     1468#
     1469# _ComputeTransferFunction --
     1470#
     1471#       Computes and sends the transfer function to the render server.  It's
     1472#       assumed that the volume data limits are known and that the global
     1473#       transfer-functions slider values have be setup.  Both parts are
     1474#       needed to compute the relative value (location) of the marker, and
     1475#       the alpha map of the transfer function. 
     1476#
     1477itcl::body Rappture::NanovisViewer::_ComputeTransferFunction { tf } {
     1478    array set style {
     1479        -color rainbow
     1480        -levels 6
     1481        -opacity 1.0
     1482    }
     1483    set ivol [lindex $_style2ids($tf) 0]
     1484    foreach {dataobj comp} $_id2obj($ivol) break
     1485    array set style [lindex [$dataobj components -style $comp] 0]
     1486
     1487
     1488    # We have to parse the style attributes for a volume using this
     1489    # transfer-function *once*.  This sets up the initial isomarkers for the
     1490    # transfer function.  The user may add/delete markers, so we have to
     1491    # maintain a list of markers for each transfer-function.  We use the one
     1492    # of the volumes (the first in the list) using the transfer-function as a
     1493    # reference. 
     1494    #
     1495    # FIXME: The current way we generate transfer-function names completely
     1496    #        ignores the -markers option.  The problem is that we are forced
     1497    #        to compute the name from an increasing complex set of values:
     1498    #        color, levels, marker, opacity.  I think the cow's out of the
     1499    #        barn on this one.
     1500
     1501    if { ![info exists _isomarkers($tf)] } {
     1502        # Have to defer creation of isomarkers until we have data limits
     1503        if { [info exists style(-markers)] } {
     1504            _ParseMarkersOption $tf $ivol $style(-markers)
     1505        } else {
     1506            _ParseLevelsOption $tf $ivol $style(-levels)
     1507        }
     1508    }
    13831509    if {$style(-color) == "rainbow"} {
    13841510        set style(-color) "white:yellow:green:cyan:blue:magenta"
     
    13931519    append cmap "1.0 [Color2RGB $color]"
    13941520
    1395     set tag $this-$ivol
     1521    set tag $this-$tf
    13961522    if { ![info exists _settings($tag-opacity)] } {
    13971523        set _settings($tag-opacity) $style(-opacity)
     
    14001526
    14011527    set isovalues {}
    1402     foreach m $_isomarkers($ivol) {
     1528    foreach m $_isomarkers($tf) {
    14031529        lappend isovalues [$m GetRelativeValue]
    14041530    }
    1405 
    14061531    # Sort the isovalues
    14071532    set isovalues [lsort -real $isovalues]
     
    14251550        if { $x1 < 0.0 } {
    14261551            set x1 0.0
    1427         }
     1552        } elseif { $x1 > 1.0 } {
     1553            set x1 1.0
     1554        }
    14281555        if { $x2 < 0.0 } {
    14291556            set x2 0.0
    1430         }
    1431         if { $x3 > 1.0 } {
    1432             set x3 1.0
    1433         }
    1434         if { $x4 > 1.0 } {
    1435             set x4 1.0
     1557        } elseif { $x2 > 1.0 } {
     1558            set x2 1.0
     1559        }
     1560        if { $x3 < 0.0 } {
     1561            set x3 0.0
     1562        } elseif { $x3 > 1.0 } {
     1563            set x3 1.0
     1564        }
     1565        if { $x4 < 0.0 } {
     1566            set x4 0.0
     1567        } elseif { $x4 > 1.0 } {
     1568            set x4 1.0
    14361569        }
    14371570        # add spikes in the middle
     
    14441577        lappend wmap 1.0 0.0
    14451578    }
    1446     set _id2style($ivol) $sname
    1447     set _styles($sname) 1
    1448     set cmds [subst {
    1449         transfunc define $sname { $cmap } { $wmap }
    1450         volume shading transfunc $sname $ivol
    1451     }]
    1452     return [SendBytes $cmds]
     1579    SendBytes "transfunc define $tf { $cmap } { $wmap }\n"
     1580    #puts stdout "transfunc define $tf { $cmap } { $wmap }\n"
     1581    return [SendBytes "volume shading transfunc $tf $_style2ids($tf)\n"]
    14531582}
    14541583
     
    14931622}
    14941623
    1495 itcl::body Rappture::NanovisViewer::_HideIsoMarkers { ivol } {
    1496     if { [info exists _isomarkers($ivol)] } {
    1497         foreach m $_isomarkers($ivol) {
    1498             $m Hide
    1499         }
    1500     }
    1501 }
    1502 
    1503 itcl::body Rappture::NanovisViewer::_ShowIsoMarkers { ivol } {
    1504     # Clear all markers
    1505     foreach dataobj [array names _all_data_objs] {
    1506         foreach comp [$dataobj components] {
    1507             _HideIsoMarkers $_obj2id($dataobj-$comp)
    1508         }
    1509     }
    1510     set _activeVol $ivol
    1511     if { ![info exists _isomarkers($ivol)] } {
    1512         return
    1513     }
    1514     foreach m $_isomarkers($ivol) {
    1515         $m Show
    1516     }
    1517 }
    1518 
    15191624#
    15201625# The -levels option takes a single value that represents the number
     
    15221627# marker is a relative value from 0.0 to 1.0.
    15231628#
    1524 itcl::body Rappture::NanovisViewer::_ParseLevelsOption { ivol levels } {
     1629itcl::body Rappture::NanovisViewer::_ParseLevelsOption { tf ivol levels } {
    15251630    set c $itk_component(legend)
    15261631    regsub -all "," $levels " " levels
     
    15301635            set m [IsoMarker \#auto $c $this $ivol]
    15311636            $m SetRelativeValue $x
    1532             lappend _isomarkers($ivol) $m
     1637            lappend _isomarkers($tf) $m
    15331638        }
    15341639    } else {
     
    15361641            set m [IsoMarker \#auto $c $this $ivol]
    15371642            $m SetRelativeValue $x
    1538             lappend _isomarkers($ivol) $m
     1643            lappend _isomarkers($tf) $m
    15391644        }
    15401645    }
     
    15531658#               not be seen.
    15541659#
    1555 itcl::body Rappture::NanovisViewer::_ParseMarkersOption { ivol markers } {
     1660itcl::body Rappture::NanovisViewer::_ParseMarkersOption { tf ivol markers } {
    15561661    set c $itk_component(legend)
    15571662    regsub -all "," $markers " " markers
     
    15631668            set m [IsoMarker \#auto $c $this $ivol]
    15641669            $m SetRelativeValue $value
    1565             lappend _isomarkers($ivol) $m
     1670            lappend _isomarkers($tf) $m
    15661671        } else {
    15671672            # ${n} : Set absolute value.
    15681673            set m [IsoMarker \#auto $c $this $ivol]
    15691674            $m SetAbsoluteValue $value
    1570             lappend _isomarkers($ivol) $m
    1571         }
    1572     }
    1573 }
    1574 
    1575 itcl::body Rappture::NanovisViewer::_InitIsoMarkers { ivol } {
    1576     array set style {
    1577         -levels 6
    1578     }
    1579     set _isomarkers($ivol) ""
    1580     foreach {dataobj comp} $_id2obj($ivol) break
    1581     array set style [lindex [$dataobj components -style $comp] 0]
    1582     if { [info exists style(-markers)] } {
    1583         _ParseMarkersOption $ivol $style(-markers)
    1584     } else {
    1585         _ParseLevelsOption $ivol $style(-levels)
     1675            lappend _isomarkers($tf) $m
     1676        }
    15861677    }
    15871678}
     
    15971688# legend.
    15981689# ----------------------------------------------------------------------
    1599 itcl::body Rappture::NanovisViewer::UpdateTransferFunction { ivol } {
    1600     if {![info exists _id2style($ivol)]} {
    1601         return
    1602     }
    1603     set _activeVol $ivol
     1690itcl::body Rappture::NanovisViewer::UpdateTransferFunctions {} {
    16041691    $_dispatcher event -idle !send_transfunc
    16051692}
    16061693
    16071694itcl::body Rappture::NanovisViewer::_AddIsoMarker { x y } {
    1608     if { $_activeVol == "" } {
     1695    if { $_activeId == "" } {
    16091696        error "active volume isn't set"
    16101697    }
    1611     set ivol $_activeVol
     1698    set tf $_id2style($_activeId)
    16121699    set c $itk_component(legend)
    1613     set m [IsoMarker \#auto $c $this $ivol]
     1700    set m [IsoMarker \#auto $c $this $_activeId]
    16141701    set w [winfo width $c]
    16151702    $m SetRelativeValue [expr {double($x-10)/($w-20)}]
    1616     $m Show
    1617     lappend _isomarkers($ivol) $m
    1618     UpdateTransferFunction $ivol
     1703    lappend _isomarkers($tf) $m
     1704    UpdateTransferFunctions
    16191705    return 1
    16201706}
     
    16221708itcl::body Rappture::NanovisViewer::RemoveDuplicateIsoMarker { marker x } {
    16231709    set ivol [$marker GetVolume]
     1710    set tf $_id2style($ivol)
    16241711    set bool 0
    1625     if { [info exists _isomarkers($ivol)] } {
     1712    if { [info exists _isomarkers($tf)] } {
    16261713        set list {}
    16271714        set marker [namespace tail $marker]
    1628         foreach m $_isomarkers($ivol) {
     1715        foreach m $_isomarkers($tf) {
    16291716            set sx [$m GetScreenPosition]
    16301717            if { $m != $marker } {
     
    16391726            lappend list $m
    16401727        }
    1641         set _isomarkers($ivol) $list
    1642         UpdateTransferFunction $ivol
     1728        set _isomarkers($tf) $list
     1729        UpdateTransferFunctions
    16431730    }
    16441731    return $bool
  • trunk/gui/scripts/visviewer.tcl

    r925 r1013  
    2121
    2222    private common _servers          ;# array of visualization server lists
     23    #set _servers(nanovis) "128.210.189.216:2000"
    2324    set _servers(nanovis) ""
    2425    set _servers(pymol)   ""
     
    362363#           ...following 100000 bytes...        no             
    363364#
     365#       Note: All commands from the render server are on one line.
     366#             This is because the render server can send anything
     367#             as an error message (restricted again to one line).
     368#           
    364369itcl::body Rappture::VisViewer::_ReceiveHelper {} {
    365370    if { [IsConnected] } {
     
    369374        if { [gets $_sid line] < 0 } {
    370375            Disconnect
    371         } elseif {[string equal [string range $line 0 2] "nv>"]} {
     376        }
     377        set line [string trim $line]
     378        if { $line == "" } {
     379            return
     380        }
     381        if { [string equal [string range $line 0 2] "nv>"] } {
    372382            ReceiveEcho <<line $line
    373383            append _buffer(in) [string range $line 3 end]
     
    381391            # this shows errors coming back from the engine
    382392            ReceiveEcho <<error $line
    383             puts stderr $line
     393            puts stderr "Render Server Error: $line"
    384394        }
    385395    }
     
    437447#
    438448itcl::body Rappture::VisViewer::SendEcho {channel {data ""}} {
    439     #puts stderr ">>line $data"
     449    #puts stderr ">>$data"
    440450    if {[string length $itk_option(-sendcommand)] > 0} {
    441451        uplevel #0 $itk_option(-sendcommand) [list $channel $data]
  • trunk/gui/scripts/xyresult.tcl

    r768 r1013  
     1
    12# ----------------------------------------------------------------------
    23#  COMPONENT: xyresult - X/Y plot in a ResultSet
     
    5758    protected method _axis {option args}
    5859    protected method _getAxes {xydata}
     60    protected method _getLineMarkerOptions { style }
     61    protected method _getTextMarkerOptions { style }
     62    protected method _enterMarker { g name x y text }
     63    protected method _leaveMarker { g name }
    5964
    6065    private variable _dispatcher "" ;# dispatcher for !events
     
    7580    private variable _axisPopup    ;# info for axis being edited in popup
    7681    common _downloadPopup          ;# download options from popup
     82    private variable _markers
    7783}
    7884                                                                               
     
    656662        }
    657663    }
     664
     665    foreach xydata [get] {
     666        set xmin -Inf
     667        set ymin -Inf
     668        set xmax Inf
     669        set ymax Inf
     670        #
     671        # Create text/line markers for each *axis.marker specified.
     672        #
     673        foreach m [$xydata xmarkers] {
     674            foreach {at label style} $m break
     675            set id [$g marker create line -coords [list $at $ymin $at $ymax]]
     676            $g marker bind $id <Enter> \
     677                [itcl::code $this _enterMarker $g x-$label $at $ymin $at]
     678            $g marker bind $id <Leave> \
     679                [itcl::code $this _leaveMarker $g x-$label]
     680            set options [_getLineMarkerOptions $style]
     681            if { $options != "" } {
     682                eval $g marker configure $id $options
     683            }
     684            if { $label != "" } {
     685                set id [$g marker create text -anchor nw \
     686                            -text $label -coords [list $at $ymax]]
     687                set options [_getTextMarkerOptions $style]
     688                if { $options != "" } {
     689                    eval $g marker configure $id $options
     690                }
     691            }
     692        }
     693        foreach m [$xydata ymarkers] {
     694            foreach {at label style} $m break
     695            set id [$g marker create line -coords [list $xmin $at $xmax $at]]
     696            $g marker bind $id <Enter> \
     697                [itcl::code $this _enterMarker $g y-$label $at $xmin $at]
     698            $g marker bind $id <Leave> \
     699                [itcl::code $this _leaveMarker $g y-$label]
     700            set options [_getLineMarkerOptions $style]
     701            if { $options != "" } {
     702                eval $g marker configure $id $options
     703            }
     704            if { $label != "" } {
     705                set id [$g marker create text -anchor se \
     706                        -text $label -coords [list $xmax $at]]
     707                set options [_getTextMarkerOptions $style]
     708                if { $options != "" } {
     709                    eval $g marker configure $id $options
     710                }
     711            }
     712        }
     713    }
    658714}
    659715
     
    13161372}
    13171373
     1374
     1375# ----------------------------------------------------------------------
     1376# USAGE: _getLineMarkerOptions <style>
     1377#
     1378# Used internally to create a list of configuration options specific to the
     1379# axis line marker.  The input is a list of name value pairs.  Options that
     1380# are not recognized are ignored.
     1381# ----------------------------------------------------------------------
     1382itcl::body Rappture::XyResult::_getLineMarkerOptions {style} {
     1383    array set lineOptions {
     1384        "-color"  "-outline"
     1385        "-dashes" "-dashes"
     1386        "-linecolor" "-outline"
     1387        "-linewidth" "-linewidth"
     1388    }
     1389    set options {}
     1390    foreach {name value} $style {
     1391        if { [info exists lineOptions($name)] } {
     1392            lappend options $lineOptions($name) $value
     1393        }
     1394    }
     1395    return $options
     1396}
     1397
     1398# ----------------------------------------------------------------------
     1399# USAGE: _getTextMarkerOptions <style>
     1400#
     1401# Used internally to create a list of configuration options specific to the
     1402# axis text marker.  The input is a list of name value pairs.  Options that
     1403# are not recognized are ignored.
     1404# ----------------------------------------------------------------------
     1405itcl::body Rappture::XyResult::_getTextMarkerOptions {style} {
     1406    array set textOptions {
     1407        "-color"  "-outline"
     1408        "-textcolor"  "-outline"
     1409        "-font"   "-font"
     1410        "-xoffset" "-xoffset"
     1411        "-yoffset" "-yoffset"
     1412        "-anchor" "-anchor"
     1413    }
     1414    set options {}
     1415    foreach {name value} $style {
     1416        if { [info exists textOptions($name)] } {
     1417            lappend options $textOptions($name) $value
     1418        }
     1419    }
     1420    return $options
     1421}
     1422
    13181423# ----------------------------------------------------------------------
    13191424# USAGE: _getAxes <curveObj>
     
    13741479    }
    13751480}
     1481
     1482itcl::body Rappture::XyResult::_enterMarker { g name x y text } {
     1483    _leaveMarker $g $name
     1484    set id [$g marker create text \
     1485                -coords [list $x $y] \
     1486                -yoffset -1 \
     1487                -anchor s \
     1488                -text $text]
     1489    set _markers($name) $id
     1490}
     1491
     1492itcl::body Rappture::XyResult::_leaveMarker { g name } {
     1493    if { [info exists _markers($name)] } {
     1494        set id $_markers($name)
     1495        $g marker delete $id
     1496        unset _markers($name)
     1497    }
     1498}
Note: See TracChangeset for help on using the changeset viewer.