Changeset 2144


Ignore:
Timestamp:
Mar 23, 2011, 6:43:21 PM (14 years ago)
Author:
gah
Message:

vtk-contour-viewer additions: still experimental

Location:
trunk/gui
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/apps/launcher.tcl

    r2126 r2144  
    9191# Note: We're sourcing the driver file "main.tcl" rather than exec-ing
    9292#       wish because we want to see stderr and stdout messages when they
    93 #       written, rather than when the program completes.  It also eliminates
    94 #       one process waiting for the other to complete. If "exec" is needed,
    95 #       then the following could be replaced with blt::bgexec.  It doesn't
    96 #       try to redirect stderr into a file.
     93#       are written, rather than when the program completes.  It also
     94#       eliminates one process waiting for the other to complete. If
     95#       "exec" is needed, then the following could be replaced with
     96#       blt::bgexec.  It doesn't try to redirect stderr into a file.
    9797set argv $alist
    9898package require Tk
  • trunk/gui/apps/vtkcontour-test

    r2126 r2144  
    352352set f [.main pane 0]
    353353VtkContourViewer_init_resources
    354 #set servers [Rappture::VtkContourViewer::GetServerList "vtkvis"]
    355 Rappture::VtkContourViewer $f.viewer "localhost:2010"
     354set servers [Rappture::VtkContourViewer::GetServerList "vtkvis"]
     355Rappture::VtkContourViewer $f.viewer $servers
    356356pack $f.viewer -expand yes -fill both
    357357set widgets(vtkcontourviewer) $f.viewer
  • trunk/gui/scripts/field.tcl

    r1570 r2144  
    490490        updir   updir
    491491        camera  camera.position
     492        type    about.type
    492493    } {
    493494        set str [$_field get $path]
  • trunk/gui/scripts/field2dresult.tcl

    r2131 r2144  
    5656    }
    5757    array set flags $args
    58     set servers [Rappture::VisViewer::GetServerList "nanovis"]
     58    set servers ""
     59    switch -- $flags(-mode) {
     60        "auto" - "heightmap" - "flowvis" {
     61            set servers [Rappture::VisViewer::GetServerList "nanovis"]
     62        }
     63        "vtkcontour" {
     64            set servers [Rappture::VisViewer::GetServerList "vtkvis"]
     65        }
     66        default {
     67            puts stderr "unknown render mode \"$flags(-mode)\""
     68        }
     69    }           
    5970    if {"" != $servers && $flags(-mode) != "vtk"} {
    6071        switch -- $flags(-mode) {
  • trunk/gui/scripts/filexfer.tcl

    r1925 r2144  
    343343        foreach prog {
    344344              clientaction
     345              /usr/lib/hubzero/clientaction
    345346              /apps/bin/clientaction
    346347              /apps/xvnc/bin/clientaction
  • trunk/gui/scripts/resultviewer.tcl

    r2133 r2144  
    264264                    if {![info exists _mode2widget($mode)]} {
    265265                        if { [$dataobj isunirect2d] } {
    266                             set resultMode "vtkcontour"
     266                            if { [$dataobj hints type] == "contour" } {
     267                                set resultMode "vtkcontour"
     268                            } else {
     269                                set resultMode "heightmap"
     270                            }
    267271                        } else {
    268272                            set resultMode "vtk"
  • trunk/gui/scripts/sequenceresult.tcl

    r1930 r2144  
    467467                    2D {
    468468                        if { [$dataobj isunirect2d] } {
    469                             set mode "heightmap"
     469                            if { [$dataobj hints type] == "contour" } {
     470                                set mode "vtkcontour"
     471                            } else {
     472                                set mode "heightmap"
     473                            }
    470474                        } else {
    471475                            set mode "vtk"
  • trunk/gui/scripts/unirect2d.tcl

    r2128 r2144  
    7979        ymin    yaxis.min
    8080        ymax    yaxis.max
     81        type    about.type
    8182    } {
    8283        set str [$m get $path]
  • trunk/gui/scripts/vtkcontourviewer.tcl

    r2127 r2144  
    11
    22# ----------------------------------------------------------------------
    3 #  COMPONENT: vtkcontourviewer - 3D volume rendering
    4 #
    5 #  This widget performs volume rendering on 3D scalar/vector datasets.
    6 #  It connects to the Nanovis server running on a rendering farm,
     3#  COMPONENT: vtkcontourviewer - Contour plot viewer
     4#
     5#  It connects to the Vtk server running on a rendering farm,
    76#  transmits data, and displays the results.
    87# ======================================================================
     
    7574    protected method ReceiveDataset { args }
    7675    protected method ReceiveImage { args }
     76    protected method DrawLegend {}
    7777    protected method ReceiveLegend { colormap size }
    7878    protected method Rotate {option x y}
     
    8080    protected method Zoom {option}
    8181
     82    private method AdjustSelectionRectangle { x y }
     83    private method BeginSelectionRectangle { x y }
     84    private method EndSelectionRectangle { x y }
     85    private method KillSelectionRectangle {}
     86    private method MarchingAnts {}
     87
    8288    # The following methods are only used by this class.
    8389    private method BuildCameraTab {}
    8490    private method BuildViewTab {}
    85     private method BuildColormap { colormap }
     91    private method BuildColormap { colormap dataobj comp }
    8692    private method EventuallyResize { w h }
    8793    private method EventuallyResizeLegend { }
    88     private method SetColormap { dataobj comp }
     94    private method SetStyles { dataobj comp }
    8995    private method PanCamera {}
    90     private method volume { tag name }
    9196    private method ConvertToVtkData { dataobj comp }
     97    private method GetImage { args }
     98    private method GetVtkData { args }
     99    private method BuildDownloadPopup { widget command }
    92100
    93101    private variable _outbuf       ;# buffer for outgoing commands
     
    100108    private variable _colormaps    ;# contains all the colormaps
    101109                                   ;# in the server.
    102     private variable _datasets2style    ;# maps dataobj-component to transfunc
     110    private variable _dataset2style    ;# maps dataobj-component to transfunc
    103111    private variable _style2datasets   ;# maps tf back to list of
    104112                                    # dataobj-components using the tf.
     
    111119    # defined but not loaded.  If 1 the transfer function has been named
    112120    # and loaded.
    113     private variable _activeColormaps
    114     private variable _first ""     ;# This is the topmost volume.
     121    private variable _first ""     ;# This is the topmost dataset.
    115122    private variable _buffering 0
    116123
     
    123130    private variable _resizePending 0
    124131    private variable _resizeLegendPending 0
     132    private variable _outline
    125133}
    126134
     
    154162    $_parser alias legend [itcl::code $this ReceiveLegend]
    155163    $_parser alias dataset [itcl::code $this ReceiveDataset]
     164
     165    array set _outline {
     166        id -1
     167        afterId -1
     168        x1 -1
     169        y1 -1
     170        x2 -1
     171        y2 -1
     172    }
    156173
    157174    # Initialize the view to some default parameters.
     
    163180        pan-x           0
    164181        pan-y           0
     182        zoom-x          1.0
     183        zoom-y          1.0
    165184    }
    166185    set _limits(vmin) 0.0
     
    174193        $this-theta             $_view(theta)
    175194        $this-opacity           1
    176         $this-edges             1
    177195        $this-axes              1
    178196        $this-legend            1
    179197        $this-colormap          1
    180         $this-wireframe         1
    181         $this-polydata          1
     198        $this-edges             0
    182199        $this-isolines          1
    183200        $this-zoom              $_view(zoom)
     
    185202
    186203    itk_component add view {
    187         label $itk_component(plotarea).vol -image $_image(plot) \
     204        canvas $itk_component(plotarea).view \
    188205            -highlightthickness 0 -borderwidth 0
    189206    } {
     
    191208        ignore -highlightthickness -borderwidth  -background
    192209    }
     210
     211    set c $itk_component(view)
     212    bind $c <Configure> [itcl::code $this EventuallyResize %w %h]
     213    bind $c <4> [itcl::code $this Zoom in 0.25]
     214    bind $c <5> [itcl::code $this Zoom out 0.25]
     215    bind $c <KeyPress-Left>  [list %W xview scroll 10 units]
     216    bind $c <KeyPress-Right> [list %W xview scroll -10 units]
     217    bind $c <KeyPress-Up>    [list %W yview scroll 10 units]
     218    bind $c <KeyPress-Down>  [list %W yview scroll -10 units]
     219    bind $c <Enter> "focus %W"
     220
     221    bind $c <ButtonPress-1> [itcl::code $this BeginSelectionRectangle %x %y]
     222    bind $c <B1-Motion> [itcl::code $this AdjustSelectionRectangle %x %y]
     223    bind $c <ButtonRelease-1> [itcl::code $this EndSelectionRectangle %x %y]
     224    # Fix the scrollregion in case we go off screen
     225    $c configure -scrollregion [$c bbox all]
     226
     227    set _map(id) [$c create image 0 0 -anchor nw -image $_image(plot)]
     228    set _map(cwidth) -1
     229    set _map(cheight) -1
     230    set _map(zoom) 1.0
     231    set _map(original) ""
    193232
    194233    set f [$itk_component(main) component controls]
     
    229268    Rappture::Tooltip::for $itk_component(zoomout) "Zoom out"
    230269
    231     itk_component add volume {
    232         Rappture::PushButton $f.volume \
    233             -onimage [Rappture::icon volume-on] \
    234             -offimage [Rappture::icon volume-off] \
    235             -command [itcl::code $this FixSettings volume] \
    236             -variable [itcl::scope _settings($this-volume)]
    237     }
    238     $itk_component(volume) select
    239     Rappture::Tooltip::for $itk_component(volume) \
    240         "Toggle the volume cloud on/off"
    241     pack $itk_component(volume) -padx 2 -pady 2
    242 
    243270    BuildViewTab
    244271    BuildCameraTab
     
    248275    set _image(legend) [image create photo]
    249276    itk_component add legend {
    250         canvas $itk_component(plotarea).legend -height 50 -highlightthickness 0
     277        canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0
    251278    } {
    252279        usual
     
    265292        0,0 $itk_component(view) -fill both -reqwidth $w \
    266293        1,0 $itk_component(legend) -fill x
    267     blt::table configure $itk_component(plotarea) r1 -resize none
    268 
    269     # Bindings for rotation via mouse
    270     bind $itk_component(view) <ButtonPress-1> \
    271         [itcl::code $this Rotate click %x %y]
    272     bind $itk_component(view) <B1-Motion> \
    273         [itcl::code $this Rotate drag %x %y]
    274     bind $itk_component(view) <ButtonRelease-1> \
    275         [itcl::code $this Rotate release %x %y]
     294    blt::table $itk_component(plotarea) \
     295        0,0 $itk_component(view) -fill both -reqwidth $w \
     296        0,1 $itk_component(legend) -fill y
     297    blt::table configure $itk_component(plotarea) c1 -resize none
     298
     299    if 0 {
    276300    bind $itk_component(view) <Configure> \
    277301        [itcl::code $this EventuallyResize %w %h]
    278 
     302    }
    279303    # Bindings for panning via mouse
    280304    bind $itk_component(view) <ButtonPress-2> \
     
    339363}
    340364
     365itcl::body Rappture::VtkContourViewer::DoResize {} {
     366    if { $_width < 2 } {
     367        set _width 500
     368    }
     369    if { $_height < 2 } {
     370        set _height 500
     371    }
     372    SendCmd "screen size $_width $_height"
     373    SendCmd "camera reset all"
     374    if { $_settings($this-legend) } {
     375        EventuallyResizeLegend
     376    }
     377    set _resizePending 0
     378}
     379
     380itcl::body Rappture::VtkContourViewer::EventuallyResize { w h } {
     381    set _width $w
     382    set _height $h
     383    if { !$_resizePending } {
     384        $_dispatcher event -after 100 !resize
     385        set _resizePending 1
     386    }
     387}
     388
     389itcl::body Rappture::VtkContourViewer::EventuallyResizeLegend {} {
     390    if { !$_resizeLegendPending } {
     391        $_dispatcher event -after 100 !legend
     392        set _resizeLegendPending 1
     393    }
     394}
     395
    341396# ----------------------------------------------------------------------
    342397# USAGE: add <dataobj> ?<settings>?
     
    355410        -description ""
    356411        -param ""
     412        -type ""
    357413    }
    358414    foreach {opt val} $settings {
     
    448504            array unset _limits $dataobj*
    449505            array unset _obj2ovride $dataobj-*
    450             array unset _dataset2style $dataobj-*
    451506            set changed 1
    452507        }
     
    514569        }
    515570        controls {
    516             # no controls for this download yet
    517             return ""
     571            set popup .vtkcontourviewerdownload
     572            if { ![winfo exists .vtkcontourviewerdownload] } {
     573                set inner [BuildDownloadPopup $popup [lindex $args 0]]
     574            } else {
     575                set inner [$popup component inner]
     576            }
     577            set _downloadPopup(image_controls) $inner.image_frame
     578            set num [llength [get]]
     579            set num [expr {($num == 1) ? "1 result" : "$num results"}]
     580            set word [Rappture::filexfer::label downloadWord]
     581            $inner.summary configure -text "$word $num in the following format:"
     582            update idletasks            ;# Fix initial sizes
     583            return $popup
    518584        }
    519585        now {
    520             # Get the image data (as base64) and decode it back to binary.
    521             # This is better than writing to temporary files.  When we switch
    522             # to the BLT picture image it won't be necessary to decode the
    523             # image data.
    524             if { [image width $_image(plot)] > 0 &&
    525                  [image height $_image(plot)] > 0 } {
    526                 set bytes [$_image(plot) data -format "jpeg -quality 100"]
    527                 set bytes [Rappture::encoding::decode -as b64 $bytes]
    528                 return [list .jpg $bytes]
     586            set popup .vtkcontourviewerdownload
     587            if {[winfo exists .vtkcontourviewerdownload]} {
     588                $popup deactivate
     589            }
     590            switch -- $_downloadPopup(format) {
     591                "image" {
     592                    return [$this GetImage [lindex $args 0]]
     593                }
     594                "vtk" {
     595                    return [$this GetVtkData [lindex $args 0]]
     596                }
    529597            }
    530598            return ""
     
    630698    ReceiveEcho <<line "<read $info(-bytes) bytes"
    631699    if { $info(-type) == "image" } {
    632         ReceiveEcho "for [image width $_image(plot)]x[image height $_image(plot)] image>"       
    633700        $_image(plot) configure -data $bytes
     701        #puts stderr "received image [image width $_image(plot)]x[image height $_image(plot)] image>"       
    634702    } elseif { $info(type) == "print" } {
    635703        set tag $this-print-$info(-token)
     
    638706}
    639707
    640 #
    641 # ReceiveLegend --
    642 #
    643 itcl::body Rappture::VtkContourViewer::ReceiveLegend { colormap nBytes } {
    644     if { ![isconnected] } {
    645         return
    646     }
    647     set bytes [ReceiveBytes $nBytes]
    648     $_image(legend) configure -data $bytes
    649     ReceiveEcho <<line "<read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
    650 
     708# ----------------------------------------------------------------------
     709# USAGE: FixLegend
     710#
     711# Used internally to update the legend area whenever it changes size
     712# or when the field changes.  Asks the server to send a new legend
     713# for the current field.
     714# ----------------------------------------------------------------------
     715itcl::body Rappture::VtkContourViewer::FixLegend {} {
     716    puts stderr "FixLegend _first=$_first"
     717    set _resizeLegendPending 0
     718    set lineht [font metrics $itk_option(-font) -linespace]
     719    set c $itk_component(legend)
     720    set w [expr {[winfo height $itk_component(view)]-20}]
     721    set h 45
     722    puts stderr "in fixlegend w=$w h=$h"
     723    if {$w > 0 && $h > 0 && $_first != "" } {
     724        set tag [lindex [CurrentDatasets] 0]
     725        puts stderr "tag=$tag [info exists _dataset2style($tag)]"
     726        if { [info exists _dataset2style($tag)] } {
     727            SendCmd "legend $_dataset2style($tag) {} $w $h"
     728        }
     729    } else {
     730        #$itk_component(legend) delete all
     731    }
     732}
     733
     734#
     735# DrawLegend --
     736#
     737#       Draws the legend in it's own canvas which resides to the right
     738#       of the contour plot area.
     739#
     740itcl::body Rappture::VtkContourViewer::DrawLegend {} {
    651741    set c $itk_component(legend)
    652742    set w [winfo width $c]
    653743    set h [winfo height $c]
    654     set lx 10
    655     set ly [expr {$h - 1}]
    656     if {"" == [$c find withtag transfunc]} {
    657         $c create image 10 10 -anchor nw \
    658             -image $_image(legend) -tags transfunc
    659         $c create text $lx $ly -anchor sw \
    660             -fill $itk_option(-plotforeground) -tags "limits vmin"
    661         $c create text [expr {$w-$lx}] $ly -anchor se \
    662             -fill $itk_option(-plotforeground) -tags "limits vmax"
    663         $c lower transfunc
    664     }
    665 
    666     set limits(min) 0
    667     set limits(max) 1.0
    668     $c itemconfigure vmin -text [format %.2g $limits(min)]
    669     $c coords vmin $lx $ly
    670 
    671     $c itemconfigure vmax -text [format %.2g $limits(max)]
    672     $c coords vmax [expr {$w-$lx}] $ly
     744    puts stderr "DrawLegend w=$w h=$h"
     745    set lineht [font metrics $itk_option(-font) -linespace]
     746   
     747    if { $_settings($this-legend) } {
     748        if { [$c find withtag "legend"] == "" } {
     749            $c create image [expr {$w-2}] [expr {$lineht+2}] -anchor ne \
     750                -image $_image(legend) -tags "transfunc legend"
     751            $c create text [expr {$w-2}] 2 -anchor ne \
     752                -fill $itk_option(-plotforeground) -tags "vmax legend" \
     753                -font "Arial 6"
     754            $c create text [expr {$w-2}] [expr {$h-2}] -anchor se \
     755                -fill $itk_option(-plotforeground) -tags "vmin legend" \
     756                -font "Arial 6"
     757        }
     758        # Reset the item coordinates according the current size of the plot.
     759        $c coords transfunc [expr {$w-2}] [expr {$lineht+2}]
     760        if { $_limits(vmin) != "" } {
     761            $c itemconfigure vmin -text [format %g $_limits(vmin)]
     762        }
     763        if { $_limits(vmax) != "" } {
     764            $c itemconfigure vmax -text [format %g $_limits(vmax)]
     765        }
     766        $c coords vmin [expr {$w-2}] [expr {$h-2}]
     767        $c coords vmax [expr {$w-2}] 2
     768    }
     769}
     770
     771# ----------------------------------------------------------------------
     772# USAGE: ReceiveLegend <tf> <vmin> <vmax> <size>
     773#
     774# Invoked automatically whenever the "legend" command comes in from
     775# the rendering server.  Indicates that binary image data with the
     776# specified <size> will follow.
     777# ----------------------------------------------------------------------
     778itcl::body Rappture::VtkContourViewer::ReceiveLegend { colormap size} {
     779    puts stderr "ReceiveLegend colormap=$colormap size=$size"
     780    if { [IsConnected] } {
     781        set bytes [ReceiveBytes $size]
     782        if { ![info exists _image(legend)] } {
     783            set _image(legend) [image create photo]
     784        }
     785        puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
     786        set src [image create photo -data $bytes]
     787        blt::winop image rotate $src $_image(legend) 90
     788        set dst $_image(legend)
     789        DrawLegend
     790    }
    673791}
    674792
     
    719837    EventuallyResize $w $h
    720838   
     839    set _limits(vmin) ""
     840    set _limits(vmax) ""
    721841    foreach dataobj [get] {
    722842        foreach comp [$dataobj components] {
     
    728848                append _outbuf $bytes
    729849                append _outbuf "pseudocolor add $tag\n"
    730                 append _outbuf "contour2d add numcontours 10 $tag\n"
    731                 append _outbuf "polydata add $tag\n"
    732                 #SetColormap $dataobj $comp
     850                append _outbuf "pseudocolor colormap default $tag\n"
     851                SetStyles $dataobj $comp
    733852                set _datasets($tag) 1
    734             }
     853                foreach {min max} [$dataobj limits z] break
     854                if { ($_limits(vmin) == "") || ($min < $_limits(vmin)) } {
     855                    set _limits(vmin) $min
     856                }
     857                if { ($_limits(vmax) == "") || ($max < $_limits(vmax)) } {
     858                    set _limits(vmax) $max
     859                }
     860            }
    735861        }
    736862    }
     
    747873
    748874    set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)]
    749     SendCmd "camera rotate $xyz"
     875    #SendCmd "camera rotate $xyz"
    750876    PanCamera
     877    SendCmd "camera mode image"
    751878    SendCmd "camera zoom $_view(zoom)"
    752     FixSettings edges
    753879    FixSettings opacity
    754880    FixSettings isolines
    755     FixSettings polydata
    756881    FixSettings colormap
    757882    FixSettings axes
    758     FixSettings wireframe
     883    FixSettings edges
    759884
    760885    # Nothing to send -- activate the proper ivol
     
    770895        foreach tag [array names _datasets $_first-*]  {
    771896            SendCmd "dataset visible 1 $tag"
    772         }
    773     }
    774     # If the first volume already exists on the server, then make sure we
     897            SendCmd "pseudocolor opacity 1.0 $tag"
     898        }
     899    }
     900
     901    FixLegend
     902
     903    # If the first dataset already exists on the server, then make sure we
    775904    # display the proper transfer function in the legend.
    776905    set comp [lindex [$_first components] 0]
     
    834963                pan-x   0
    835964                pan-y   0
     965                zoom-x  1.0
     966                zoom-y  1.0
    836967            }
    837968            if { $_first != "" } {
     
    842973            }
    843974            set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)]
    844             SendCmd "camera rotate $xyz"
     975            #SendCmd "camera rotate $xyz"
    845976            PanCamera
    846977            set _settings($this-theta) $_view(theta)
     
    850981            set _settings($this-pan-y) $_view(pan-y)
    851982            set _settings($this-zoom)  $_view(zoom)
    852             SendCmd "camera reset"
     983            SendCmd "camera reset all"
    853984        }
    854985    }
     
    860991    set x $_view(pan-x)
    861992    set y $_view(pan-y)
    862     SendCmd "camera pan $x $y"
     993    #SendCmd "camera pan $x $y"
    863994}
    864995
     
    9291060                set _settings($this-phi)   $_view(phi)
    9301061                set _settings($this-psi)   $_view(psi)
    931                 SendCmd "camera rotate $xyz"
     1062                #SendCmd "camera rotate $xyz"
    9321063                set _click(x) $x
    9331064                set _click(y) $y
     
    9581089    set h [winfo height $itk_component(view)]
    9591090    if { $option == "set" } {
    960         set x [expr $x / double($w)]
    961         set y [expr $y / double($h)]
     1091        set x [expr (($w - $x) / double($w))]
     1092        set y [expr (($h - $y) / double($h))]
    9621093        set _view(pan-x) [expr $_view(pan-x) + $x]
    9631094        set _view(pan-y) [expr $_view(pan-y) + $y]
     
    10021133                set sval [expr { 0.01 * double($val) }]
    10031134                foreach dataset [CurrentDatasets] {
    1004                     SendCmd "dataset opacity $sval $dataset"
     1135                    SendCmd "pseudocolor opacity $sval $dataset"
    10051136                }
    10061137            }
     
    10141145            }
    10151146        }
    1016         "wireframe" {
    1017             if {[isconnected]} {
    1018                 set bool $_settings($this-wireframe)
    1019                 foreach dataset [CurrentDatasets] {
    1020                     SendCmd "polydata wireframe $bool $dataset"
    1021                 }
    1022             }
    1023         }
    10241147        "edges" {
    10251148            if {[isconnected]} {
    10261149                set bool $_settings($this-edges)
    10271150                foreach dataset [CurrentDatasets] {
    1028                     SendCmd "polydata edges $bool $dataset"
     1151                    SendCmd "pseudocolor edges $bool $dataset"
    10291152                }
    10301153            }
     
    10321155        "colormap" {
    10331156            if {[isconnected]} {
    1034                 set bool $_settings($this-polydata)
     1157                set bool $_settings($this-colormap)
     1158                if { $bool } {
     1159                    set linecolor "0.0 0.0 0.0"
     1160                    set opacity 0.0
     1161                } else {
     1162                    set linecolor "1.0 1.0 1.0"
     1163                    set opacity 1.0
     1164                }
    10351165                foreach dataset [CurrentDatasets] {
    10361166                    SendCmd "pseudocolor visible $bool $dataset"
     1167                    SendCmd "contour2d linecolor $linecolor $dataset"
     1168                    SendCmd "pseudocolor linecolor $linecolor $dataset"
    10371169                }
    10381170            }
     
    10451177        }
    10461178        "legend" {
    1047         }
    1048         "polydata" {
    1049             if {[isconnected]} {
    1050                 set bool $_settings($this-polydata)
    1051                 foreach dataset [CurrentDatasets] {
    1052                     SendCmd "polydata visible $bool $dataset"
    1053                 }
     1179            if { $_settings($this-legend) } {
     1180                blt::table $itk_component(plotarea) \
     1181                    0,0 $itk_component(view) -fill both \
     1182                    0,1 $itk_component(legend) -fill y
     1183                blt::table configure $itk_component(plotarea) c1 -resize none
     1184            } else {
     1185                blt::table forget $itk_component(legend)
    10541186            }
    10551187        }
     
    10601192}
    10611193
    1062 # ----------------------------------------------------------------------
    1063 # USAGE: FixLegend
    1064 #
    1065 # Used internally to update the legend area whenever it changes size
    1066 # or when the field changes.  Asks the server to send a new legend
    1067 # for the current field.
    1068 # ----------------------------------------------------------------------
    1069 itcl::body Rappture::VtkContourViewer::FixLegend {} {
    1070     set _resizeLegendPending 0
    1071     set lineht [font metrics $itk_option(-font) -linespace]
    1072     set w [expr {$_width-20}]
    1073     set h [expr {[winfo height $itk_component(legend)]-20-$lineht}]
    1074     if {$w > 0 && $h > 0 && [array names _activeColormaps] > 0 &&
    1075         $_first != "" } {
    1076         set tag [lindex [CurrentDatasets] 0]
    1077         if { [info exists _dataset2style($tag)] } {
    1078             SendCmd "legend $_dataset2style($tag) $w $h"
    1079         }
    1080     } else {
    1081         #$itk_component(legend) delete all
    1082     }
    1083 }
    1084 
    1085 #
    1086 # SetColormap --
    1087 #
    1088 itcl::body Rappture::VtkContourViewer::SetColormap { dataobj comp } {
     1194
     1195#
     1196# SetStyles --
     1197#
     1198itcl::body Rappture::VtkContourViewer::SetStyles { dataobj comp } {
    10891199    array set style {
    10901200        -color rainbow
     
    10951205    array set style [lindex [$dataobj components -style $comp] 0]
    10961206    set colormap "$style(-color):$style(-levels):$style(-opacity)"
    1097     if { ![info exists _colormaps($colormap)] } {
     1207    if { [info exists _colormaps($colormap)] } {
     1208        puts stderr "Colormap $colormap already built"
     1209    }
     1210    if { ![info exists _dataset2style($tag)] } {
    10981211        set _dataset2style($tag) $colormap
    10991212        lappend _style2datasets($colormap) $tag
    1100         BuildColormap $colormap
     1213    }
     1214    if { ![info exists _colormaps($colormap)] } {
     1215        # Build the pseudo colormap if it doesn't exist.
     1216        BuildColormap $colormap $dataobj $comp
    11011217        set _colormaps($colormap) 1
    11021218    }
     1219    SendCmd "contour2d add numcontours $style(-levels) $tag\n"
    11031220    SendCmd "pseudocolor colormap $colormap $tag"
    11041221    return $colormap
     
    11081225# BuildColormap --
    11091226#
    1110 #   Computes and sends the transfer function to the render server.  It's
    1111 #   assumed that the volume data limits are known and that the global
    1112 #   transfer-functions slider values have be setup.  Both parts are
    1113 #   needed to compute the relative value (location) of the marker, and
    1114 #   the alpha map of the transfer function.
    1115 #
    1116 itcl::body Rappture::VtkContourViewer::BuildColormap { colormap } {
     1227itcl::body Rappture::VtkContourViewer::BuildColormap { colormap dataobj comp } {
     1228    puts stderr "BuildColormap $colormap"
    11171229    array set style {
    11181230        -color rainbow
     
    11201232        -opacity 1.0
    11211233    }
    1122     foreach {dataobj comp} [split $_style2datasets($colormap) -] break
    11231234    array set style [lindex [$dataobj components -style $comp] 0]
    11241235
     
    11271238    }
    11281239    set clist [split $style(-color) :]
    1129     set cmap "0.0 [Color2RGB white] "
     1240    set cmap {}
    11301241    for {set i 0} {$i < [llength $clist]} {incr i} {
    1131         set x [expr {double($i+1)/([llength $clist]+1)}]
     1242        set x [expr {double($i)/([llength $clist]-1)}]
    11321243        set color [lindex $clist $i]
    11331244        append cmap "$x [Color2RGB $color] "
    11341245    }
    1135     append cmap "1.0 [Color2RGB $color]"
    1136 
     1246    if { [llength $cmap] == 0 } {
     1247        set cmap "0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0"
     1248    }
    11371249    set tag $this-$colormap
    11381250    if { ![info exists _settings($tag-opacity)] } {
     
    11411253    set max $_settings($tag-opacity)
    11421254
    1143     set wmap ""
     1255    set wmap "0.0 1.0 1.0 1.0"
    11441256    SendCmd "colormap add $colormap { $cmap } { $wmap }"
    11451257}
     
    12251337        -font "Arial 9"
    12261338
    1227     checkbutton $inner.edges \
    1228         -text "Outline" \
    1229         -variable [itcl::scope _settings($this-edges)] \
    1230         -command [itcl::code $this FixSettings edges] \
    1231         -font "Arial 9"
    1232 
    12331339    checkbutton $inner.legend \
    12341340        -text "Legend" \
     
    12371343        -font "Arial 9"
    12381344
    1239     checkbutton $inner.polydata \
    1240         -text "Polydata" \
    1241         -variable [itcl::scope _settings($this-polydata)] \
    1242         -command [itcl::code $this FixSettings polydata] \
    1243         -font "Arial 9"
    1244 
    1245     checkbutton $inner.wireframe \
    1246         -text "Wireframe" \
    1247         -variable [itcl::scope _settings($this-wireframe)] \
    1248         -command [itcl::code $this FixSettings wireframe] \
     1345    checkbutton $inner.edges \
     1346        -text "Edges" \
     1347        -variable [itcl::scope _settings($this-edges)] \
     1348        -command [itcl::code $this FixSettings edges] \
    12491349        -font "Arial 9"
    12501350
     
    12591359        0,0 $inner.axes -columnspan 4 -anchor w -pady 2 \
    12601360        1,0 $inner.colormap -columnspan 4 -anchor w -pady 2 \
    1261         2,0 $inner.edges -columnspan 4 -anchor w -pady 2 \
    12621361        3,0 $inner.isolines -columnspan 4 -anchor w -pady 2 \
    12631362        4,0 $inner.legend  -columnspan 4 -anchor w \
    1264         5,0 $inner.polydata -columnspan 4 -anchor w -pady 2 \
    1265         6,0 $inner.wireframe -columnspan 4 -anchor w -pady 2 \
     1363        6,0 $inner.edges -columnspan 4 -anchor w -pady 2 \
    12661364        7,0 $inner.clear -anchor e -pady 2 \
    12671365        7,1 $inner.opacity -columnspan 2 -pady 2 -fill x\
     
    12981396
    12991397
    1300 itcl::body Rappture::VtkContourViewer::DoResize {} {
    1301     if { $_width < 2 } {
    1302         set _width 500
    1303     }
    1304     if { $_height < 2 } {
    1305         set _height 500
    1306     }
    1307     #SendCmd "screen size $_width $_height"
    1308     set _resizePending 0
    1309 }
    1310 
    1311 itcl::body Rappture::VtkContourViewer::EventuallyResize { w h } {
    1312     set _width $w
    1313     set _height $h
    1314     if { !$_resizePending } {
    1315         $_dispatcher event -idle !resize
    1316         set _resizePending 1
    1317     }
    1318 }
    1319 
    1320 itcl::body Rappture::VtkContourViewer::EventuallyResizeLegend {} {
    1321     if { !$_resizeLegendPending } {
    1322         $_dispatcher event -idle !legend
    1323         set _resizeLegendPending 1
    1324     }
    1325 }
    1326 
    13271398#
    13281399#  camera --
     
    13491420                    set _view($who) $_settings($this-$who)
    13501421                    set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)]
    1351                     SendCmd "camera rotate $xyz"
     1422                    #SendCmd "camera rotate $xyz"
    13521423                }
    13531424                "zoom" {
    13541425                    set _view($who) $_settings($this-$who)
    1355                     SendCmd "camera zoom $_view(zoom)"
     1426                    #SendCmd "camera zoom $_view(zoom)"
    13561427                }
    13571428            }
    13581429        }
    13591430    }
    1360 }
    1361 
    1362 itcl::body Rappture::VtkContourViewer::volume { tag name } {
    1363     set bool $_settings($this-dataset-$name)
    1364     SendCmd "dataset visible $bool $tag"
    13651431}
    13661432
     
    13821448    return $out
    13831449}
     1450
     1451#
     1452# MarchingAnts --
     1453#
     1454#       Called from "after" timer events.  This routine is changes
     1455#       the dash offset of the selection outline rectangle to simulate
     1456#       marching ants.
     1457#
     1458itcl::body Rappture::VtkContourViewer::MarchingAnts {} {
     1459    set c $itk_component(view)
     1460    if { [winfo exists $c] && ![winfo viewable $c] } {
     1461        KillSelectionRectangle
     1462        return
     1463    }
     1464    $c itemconfigure $_outline(id) -dashoffset $_outline(offset)
     1465    incr _outline(offset)
     1466    set _outline(afterId) [after 100 [itcl::code $this MarchingAnts]]
     1467}
     1468
     1469#
     1470# BeginSelectionRectangle --
     1471#
     1472#       Called from ButtonPress-1 events.  This routine creates the
     1473#       the selection outline rectangle.  It also clears the selection
     1474#       in the sensor tree.
     1475#
     1476itcl::body Rappture::VtkContourViewer::BeginSelectionRectangle { x y } {
     1477    set c $itk_component(view)
     1478    set x [$c canvasx $x]
     1479    set y [$c canvasy $y]
     1480    if { $_outline(id) >= 0 } {
     1481        after cancel $_outline(afterId)
     1482        set _outline(afterId) -1
     1483        $c delete $_outline(id)
     1484        set _outline(id) -1
     1485    }
     1486    set _outline(offset) 0
     1487    set _outline(x1) $x
     1488    set _outline(y1) $y
     1489    set _outline(id) \
     1490        [$c create line $x $y $x $y -dash "4 4" -width 2 -fill black]
     1491    MarchingAnts
     1492}
     1493
     1494#
     1495# AdjustSelectionRectangle --
     1496#
     1497#       Called from B1-Motion events.  This routine redraws the selection
     1498#       outline rectangle and redraws the sensors using the "selected"
     1499#       icon.
     1500#
     1501itcl::body Rappture::VtkContourViewer::AdjustSelectionRectangle { x y } {
     1502    set c $itk_component(view)
     1503    set x [$c canvasx $x]
     1504    set y [$c canvasy $y]
     1505    $c coords $_outline(id) $_outline(x1) $_outline(y1) $_outline(x1) $y \
     1506        $x $y $x $_outline(y1) $_outline(x1) $_outline(y1)
     1507    set _outline(x2) $x
     1508    set _outline(y2) $y
     1509}
     1510
     1511#
     1512# KillSelectionRectangle --
     1513#
     1514#       Removes the outline rectangle and adjusts the sensor icon
     1515#       according to the sensor's selected/deselected status.
     1516#
     1517itcl::body Rappture::VtkContourViewer::KillSelectionRectangle { } {
     1518    after cancel $_outline(afterId)
     1519    set _outline(afterId) -1
     1520    set c $itk_component(view)
     1521    $c delete $_outline(id)
     1522    set _outline(id) -1
     1523}
     1524
     1525#
     1526# EndSelectionRectangle --
     1527#
     1528#       Called from the ButtonRelease event to finish the outline of the
     1529#       selection rectangle.  If the outline is too small (less than 10
     1530#       pixels in length or width) the outline is removed and the selection
     1531#       is ignored.  Otherwise a popup menu is automatically generated and
     1532#       displayed.
     1533#
     1534itcl::body Rappture::VtkContourViewer::EndSelectionRectangle { x y } {
     1535    set c $itk_component(view)
     1536    AdjustSelectionRectangle $x $y
     1537    set cx [$c canvasx $x]
     1538    set cy [$c canvasy $y]
     1539    set cw [winfo width $c]
     1540    set ch [winfo height $c]
     1541    if { abs($_outline(x1) - $cx) < 10 && abs($_outline(y1) - $cy) < 10 }  {
     1542        KillSelectionRectangle
     1543    } else {
     1544        set w [expr $_outline(x2) - $_outline(x1)]
     1545        set h [expr $_outline(y2) - $_outline(y1)]
     1546        # Convert the zoom
     1547        set _view(zoom-x) [expr $cw / $w * $_view(zoom-x)]
     1548        set _view(zoom-y) [expr $ch / $h * $_view(zoom-y)]
     1549        set w [expr $w * $_view(zoom-x)]
     1550        set h [expr $h * $_view(zoom-y)]
     1551        SendCmd "camera ortho $_outline(x1) $_outline(y1) $w $h"
     1552        KillSelectionRectangle
     1553    }
     1554}
     1555
     1556itcl::body Rappture::VtkContourViewer::GetVtkData { args } {
     1557    set bytes ""
     1558    foreach dataobj [get] {
     1559        foreach comp [$dataobj components] {
     1560            set tag $dataobj-$comp
     1561            set contents [ConvertToVtkData $dataobj $comp]
     1562            append bytes "$contents\n\n"
     1563        }
     1564    }
     1565    return [list .txt $bytes]
     1566}
     1567
     1568itcl::body Rappture::VtkContourViewer::GetImage { args } {
     1569    if { [image width $_image(download)] > 0 &&
     1570         [image height $_image(download)] > 0 } {
     1571        set bytes [$_image(download) data -format "jpeg -quality 100"]
     1572        set bytes [Rappture::encoding::decode -as b64 $bytes]
     1573        return [list .jpg $bytes]
     1574    }
     1575    return ""
     1576}
     1577
     1578itcl::body Rappture::VtkContourViewer::BuildDownloadPopup { popup command } {
     1579    Rappture::Balloon $popup \
     1580        -title "[Rappture::filexfer::label downloadWord] as..."
     1581    set inner [$popup component inner]
     1582    label $inner.summary -text "" -anchor w
     1583    radiobutton $inner.vtk_button -text "VTK data file" \
     1584        -variable [itcl::scope _downloadPopup(format)] \
     1585        -font "Helvetica 9 " \
     1586        -value vtk 
     1587    Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file."
     1588    radiobutton $inner.image_button -text "Image File" \
     1589        -variable [itcl::scope _downloadPopup(format)] \
     1590        -value image
     1591    Rappture::Tooltip::for $inner.image_button \
     1592        "Save as digital image."
     1593
     1594    button $inner.ok -text "Save" \
     1595        -highlightthickness 0 -pady 2 -padx 3 \
     1596        -command $command \
     1597        -compound left \
     1598        -image [Rappture::icon download]
     1599
     1600    button $inner.cancel -text "Cancel" \
     1601        -highlightthickness 0 -pady 2 -padx 3 \
     1602        -command [list $popup deactivate] \
     1603        -compound left \
     1604        -image [Rappture::icon cancel]
     1605
     1606    blt::table $inner \
     1607        0,0 $inner.summary -cspan 2  \
     1608        1,0 $inner.vtk_button -anchor w -cspan 2 -padx { 4 0 } \
     1609        2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \
     1610        4,1 $inner.cancel -width .9i -fill y \
     1611        4,0 $inner.ok -padx 2 -width .9i -fill y
     1612    blt::table configure $inner r3 -height 4
     1613    blt::table configure $inner r4 -pady 4
     1614    raise $inner.image_button
     1615    $inner.vtk_button invoke
     1616    return $inner
     1617}
     1618
Note: See TracChangeset for help on using the changeset viewer.