Changeset 2466 for trunk


Ignore:
Timestamp:
Sep 4, 2011, 11:13:10 AM (13 years ago)
Author:
gah
Message:
 
File:
1 edited

Legend:

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

    r2464 r2466  
    6868    protected method Disconnect {}
    6969    protected method DoResize {}
    70     protected method FixSettings {what {value ""}}
     70    protected method AdjustSetting {what {value ""}}
     71    protected method FixSettings { args  }
    7172    protected method Pan {option x y}
    7273    protected method Pick {x y}
     
    7475    protected method ReceiveDataset { args }
    7576    protected method ReceiveImage { args }
     77    protected method ReceiveLegend { args }
    7678    protected method Rotate {option x y}
    7779    protected method SendCmd {string}
     
    7981
    8082    # The following methods are only used by this class.
     83    private method BuildAxisTab {}
    8184    private method BuildCameraTab {}
     85    private method BuildColormap { colormap dataobj comp }
     86    private method BuildDownloadPopup { widget command }
     87    private method BuildStreamsTab {}
    8288    private method BuildVolumeTab {}
    83     private method BuildStreamsTab {}
    84     private method BuildAxisTab {}
    85     private method BuildColormap { colormap dataobj comp }
     89    private method ConvertToVtkData { dataobj comp }
     90    private method DrawLegend {}
    8691    private method EventuallyResize { w h }
    87     private method SetStyles { dataobj comp }
    88     private method PanCamera {}
    89     private method ConvertToVtkData { dataobj comp }
    9092    private method GetImage { args }
    9193    private method GetVtkData { args }
    92     private method BuildDownloadPopup { widget command }
     94    private method IsValidObject { dataobj }
     95    private method PanCamera {}
    9396    private method SetObjectStyle { dataobj comp }
    94     private method IsValidObject { dataobj }
     97    private method SetStyles { dataobj comp }
     98    private method RequestLegend {}
    9599
    96100    private variable _arcball ""
     
    116120                                    # to starting position.
    117121    private variable _haveStreams 0
    118     # Array of transfer functions in server.  If 0 the transfer has been
    119     # defined but not loaded.  If 1 the transfer function has been named
    120     # and loaded.
     122
    121123    private variable _first ""     ;# This is the topmost dataset.
    122124    private variable _start 0
    123125    private variable _buffering 0
    124126   
    125     # This indicates which isomarkers and transfer function to use when
    126     # changing markers, opacity, or thickness.
    127127    common _downloadPopup          ;# download options from popup
    128128    private common _hardcopy
     
    157157    $_parser alias image [itcl::code $this ReceiveImage]
    158158    $_parser alias dataset [itcl::code $this ReceiveDataset]
     159    $_parser alias legend [itcl::code $this ReceiveLegend]
    159160
    160161    array set _outline {
     
    181182    $_arcball quaternion $q
    182183
    183     set _limits(vmin) 0.0
    184     set _limits(vmax) 1.0
     184    set _limits(zmin) 0.0
     185    set _limits(zmax) 1.0
    185186
    186187    array set _settings [subst {
    187188        $this-axes              1
     189        $this-legend            1
    188190        $this-seeds             1
    189191        $this-streamlines       1
     
    262264    Rappture::Tooltip::for $itk_component(zoomout) "Zoom out"
    263265
    264     if { [catch {
    265         BuildVolumeTab
    266         BuildAxisTab
    267         BuildStreamsTab
    268         BuildCameraTab
    269     } errs] != 0 } {
    270         puts stderr err=$errs
     266    BuildVolumeTab
     267    BuildAxisTab
     268    BuildStreamsTab
     269    BuildCameraTab
     270
     271    # Legend
     272
     273    set _image(legend) [image create photo]
     274    itk_component add legend {
     275        canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0
     276    } {
     277        usual
     278        ignore -highlightthickness
     279        rename -background -plotbackground plotBackground Background
    271280    }
    272281
     
    354363    image delete $_image(download)
    355364    array unset _settings $this-*
    356     catch { blt::arcball destroy $_arcball}
     365    catch { blt::arcball destroy $_arcball }
    357366}
    358367
     
    367376    set _start [clock clicks -milliseconds]
    368377    SendCmd "screen size $_width $_height"
    369 
     378    if { $_haveStreams } {
     379        RequestLegend
     380    }
    370381    # Must reset camera to have object scaling to take effect.
    371382    #SendCmd "camera reset"
     
    547558    foreach dataobj $args {
    548559        array set bounds [limits $dataobj]
    549  puts stderr bounds=[array get bounds]
    550560        if {![info exists _limits(xmin)] || $_limits(xmin) > $bounds(xmin)} {
    551561            set _limits(xmin) $bounds(xmin)
     
    809819    DoResize
    810820   
    811     set _limits(vmin) ""
    812     set _limits(vmax) ""
     821    set _limits(zmin) ""
     822    set _limits(zmax) ""
    813823    set _first ""
    814824    set _haveStreams 0
     
    828838                set _datasets($tag) 1
    829839            }
     840            SetStyles $dataobj $comp
    830841            lappend _obj2datasets($dataobj) $tag
    831842            SetObjectStyle $dataobj $comp
     
    853864        set _reset 0
    854865    }
    855     FixSettings opacity
    856     FixSettings grid-x
    857     FixSettings grid-y
    858     FixSettings grid-z
    859     FixSettings volume
    860     FixSettings lighting
    861     FixSettings wireframe
    862     FixSettings axes
    863     FixSettings edges
    864     FixSettings seeds
    865     FixSettings streamlines
    866     FixSettings axismode
     866
     867    FixSettings opacity grid-x grid-y grid-z volume lighting \
     868        wireframe axes edges seeds streamlines axismode
    867869
    868870    if { !$_haveStreams } {
     
    10971099# to the back end.
    10981100# ----------------------------------------------------------------------
    1099 itcl::body Rappture::VtkViewer::FixSettings {what {value ""}} {
     1101itcl::body Rappture::VtkViewer::FixSettings { args } {
     1102    foreach setting $args {
     1103        AdjustSetting $setting
     1104    }
     1105}
     1106
     1107#
     1108# AdjustSetting --
     1109#
     1110#       Changes/updates a specific setting in the widget.  There are
     1111#       usually user-setable option.  Commands are sent to the render
     1112#       server.
     1113#
     1114itcl::body Rappture::VtkViewer::AdjustSetting {what {value ""}} {
    11001115    if { ![isconnected] } {
    11011116        return
     
    12051220
    12061221#
     1222# RequestLegend --
     1223#
     1224#       Request a new legend from the server.  The size of the legend
     1225#       is determined from the height of the canvas.  It will be rotated
     1226#       to be vertical when drawn.
     1227#
     1228itcl::body Rappture::VtkViewer::RequestLegend {} {
     1229    #puts stderr "RequestLegend _first=$_first"
     1230    set lineht [font metrics $itk_option(-font) -linespace]
     1231    set c $itk_component(legend)
     1232    set w [expr {$_height-20}]
     1233    set h 45;                           # Hard coding height of legend
     1234
     1235    if { $w == 0} {
     1236        return
     1237    }
     1238    # Set the legend on the first streamlines dataset.
     1239    foreach dataset [CurrentDatasets -visible] {
     1240        foreach {dataobj comp} [split $dataset -] break
     1241        if { [$dataobj type $comp] == "streamlines" &&
     1242             [info exists _dataset2style($dataset)] } {
     1243            SendCmd "legend $_dataset2style($dataset) scalar {} $w $h"
     1244            break;
     1245        }
     1246    }
     1247}
     1248
     1249#
    12071250# SetStyles --
    12081251#
     
    12141257    }
    12151258    set tag $dataobj-$comp
    1216     array set style [lindex [$dataobj components -style $comp] 0]
     1259    array set style [$dataobj style $comp]
    12171260    set colormap "$style(-color):$style(-levels):$style(-opacity)"
    12181261    if { [info exists _colormaps($colormap)] } {
     
    12281271        set _colormaps($colormap) 1
    12291272    }
    1230     #SendCmd "polydata add $style(-levels) $tag\n"
    1231     SendCmd "pseudocolor colormap $colormap $tag"
     1273    #SendCmd "pseudocolor colormap $colormap $tag"
     1274    SendCmd "streamlines colormap $colormap $tag"
    12321275    return $colormap
    12331276}
     
    12421285        -opacity 1.0
    12431286    }
    1244     array set style [lindex [$dataobj components -style $comp] 0]
    1245 
     1287    array set style [$dataobj style $comp]
    12461288    if {$style(-color) == "rainbow"} {
    12471289        set style(-color) "white:yellow:green:cyan:blue:magenta"
     
    13401382        -text "Visible" \
    13411383        -variable [itcl::scope _settings($this-volume)] \
    1342         -command [itcl::code $this FixSettings volume] \
     1384        -command [itcl::code $this AdjustSetting volume] \
    13431385        -font "Arial 9"
    13441386
     
    13461388        -text "Wireframe" \
    13471389        -variable [itcl::scope _settings($this-wireframe)] \
    1348         -command [itcl::code $this FixSettings wireframe] \
     1390        -command [itcl::code $this AdjustSetting wireframe] \
    13491391        -font "Arial 9"
    13501392
     
    13521394        -text "Lighting" \
    13531395        -variable [itcl::scope _settings($this-lighting)] \
    1354         -command [itcl::code $this FixSettings lighting] \
     1396        -command [itcl::code $this AdjustSetting lighting] \
    13551397        -font "Arial 9"
    13561398
     
    13581400        -text "Edges" \
    13591401        -variable [itcl::scope _settings($this-edges)] \
    1360         -command [itcl::code $this FixSettings edges] \
     1402        -command [itcl::code $this AdjustSetting edges] \
    13611403        -font "Arial 9"
    13621404
     
    13651407        -variable [itcl::scope _settings($this-opacity)] \
    13661408        -width 10 \
    1367         -showvalue off -command [itcl::code $this FixSettings opacity]
     1409        -showvalue off -command [itcl::code $this AdjustSetting opacity]
    13681410
    13691411    blt::table $inner \
     
    13931435        -text "Visible" \
    13941436        -variable [itcl::scope _settings($this-streamlines)] \
    1395         -command [itcl::code $this FixSettings streamlines] \
     1437        -command [itcl::code $this AdjustSetting streamlines] \
    13961438        -font "Arial 9"
    13971439
     
    13991441        -text "Show seeds" \
    14001442        -variable [itcl::scope _settings($this-seeds)] \
    1401         -command [itcl::code $this FixSettings seeds] \
     1443        -command [itcl::code $this AdjustSetting seeds] \
    14021444        -font "Arial 9"
    14031445
     
    14141456    $itk_component(streammode) value "lines"
    14151457    bind $inner.streammode_combo <<Value>> \
    1416         [itcl::code $this FixSettings streammode]
     1458        [itcl::code $this AdjustSetting streammode]
    14171459
    14181460    label $inner.opacity_l -text "Opacity" -font "Arial 9"
     
    14201462        -variable [itcl::scope _settings($this-opacity)] \
    14211463        -width 10 \
    1422         -showvalue off -command [itcl::code $this FixSettings opacity]
     1464        -showvalue off -command [itcl::code $this AdjustSetting opacity]
    14231465
    14241466    blt::table $inner \
     
    14471489        -text "Visible" \
    14481490        -variable [itcl::scope _settings($this-axes)] \
    1449         -command [itcl::code $this FixSettings axes] \
     1491        -command [itcl::code $this AdjustSetting axes] \
    14501492        -font "Arial 9"
    14511493
     
    14551497        -text "X" \
    14561498        -variable [itcl::scope _settings($this-grid-x)] \
    1457         -command [itcl::code $this FixSettings grid-x] \
     1499        -command [itcl::code $this AdjustSetting grid-x] \
    14581500        -font "Arial 9"
    14591501    checkbutton $f.y \
    14601502        -text "Y" \
    14611503        -variable [itcl::scope _settings($this-grid-y)] \
    1462         -command [itcl::code $this FixSettings grid-y] \
     1504        -command [itcl::code $this AdjustSetting grid-y] \
    14631505        -font "Arial 9"
    14641506    checkbutton $f.z \
    14651507        -text "Z" \
    14661508        -variable [itcl::scope _settings($this-grid-z)] \
    1467         -command [itcl::code $this FixSettings grid-z] \
     1509        -command [itcl::code $this AdjustSetting grid-z] \
    14681510        -font "Arial 9"
    14691511    pack $f.x $f.y $f.z -side left
     
    14811523        "outer_edges"     "outer"         
    14821524    $itk_component(axismode) value "outer"
    1483     bind $inner.axismode_combo <<Value>> [itcl::code $this FixSettings axismode]
     1525    bind $inner.axismode_combo <<Value>> \
     1526        [itcl::code $this AdjustSetting axismode]
    14841527
    14851528    blt::table $inner \
     
    17031746    return 1
    17041747}
     1748
     1749# ----------------------------------------------------------------------
     1750# USAGE: ReceiveLegend <colormap> <size>>
     1751#
     1752# Invoked automatically whenever the "legend" command comes in from
     1753# the rendering server.  Indicates that binary image data with the
     1754# specified <size> will follow.
     1755# ----------------------------------------------------------------------
     1756itcl::body Rappture::VtkViewer::ReceiveLegend { colormap size } {
     1757    #puts stderr "ReceiveLegend colormap=$colormap size=$size"
     1758    if { [IsConnected] } {
     1759        set bytes [ReceiveBytes $size]
     1760        if { ![info exists _image(legend)] } {
     1761            set _image(legend) [image create photo]
     1762        }
     1763        #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
     1764        set src [image create photo -data $bytes]
     1765        blt::winop image rotate $src $_image(legend) 90
     1766        set dst $_image(legend)
     1767        DrawLegend
     1768    }
     1769}
     1770
     1771#
     1772# DrawLegend --
     1773#
     1774#       Draws the legend in it's own canvas which resides to the right
     1775#       of the contour plot area.
     1776#
     1777itcl::body Rappture::VtkViewer::DrawLegend {} {
     1778    set c $itk_component(view)
     1779    set w [winfo width $c]
     1780    set h [winfo height $c]
     1781    set lineht [font metrics $itk_option(-font) -linespace]
     1782   
     1783    if { $_settings($this-legend) } {
     1784        set x 2
     1785        if { [$c find withtag "legend"] == "" } {
     1786            $c create image $x [expr {$lineht+2}] -anchor nw \
     1787                -image $_image(legend) -tags "transfunc legend"
     1788            $c create text $x 2 -anchor nw \
     1789                -fill $itk_option(-plotforeground) -tags "zmax legend" \
     1790                -font "Arial 6"
     1791            $c create text $x [expr {$h-2}] -anchor sw \
     1792                -fill $itk_option(-plotforeground) -tags "zmin legend" \
     1793                -font "Arial 6"
     1794        }
     1795        # Reset the item coordinates according the current size of the plot.
     1796        $c coords transfunc $x [expr {$lineht+2}]
     1797        if { $_limits(zmin) != "" } {
     1798            $c itemconfigure zmin -text [format %g $_limits(zmin)]
     1799        }
     1800        if { $_limits(zmax) != "" } {
     1801            $c itemconfigure zmax -text [format %g $_limits(zmax)]
     1802        }
     1803        $c coords zmin $x [expr {$h-2}]
     1804        $c coords zmax $x 2
     1805    }
     1806}
Note: See TracChangeset for help on using the changeset viewer.