Changeset 1220


Ignore:
Timestamp:
Nov 17, 2008 2:20:16 PM (15 years ago)
Author:
gah
Message:

Improve data read speed of curve object with vectors; Add pan and scrollwheel features to 3d viewers

Location:
trunk/gui/scripts
Files:
6 edited

Legend:

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

    r1013 r1220  
    268268        set xydata [$_curve get $cname.xy]
    269269        if {"" != $xydata} {
    270             set xv [blt::vector create x$_counter]
    271             set yv [blt::vector create y$_counter]
    272 
    273             foreach line [split $xydata \n] {
    274                 if {[scan $line {%g %g} xval yval] == 2} {
    275                     $xv append $xval
    276                     $yv append $yval
    277                 }
    278             }
     270            set xv [blt::vector create \#auto]
     271            set yv [blt::vector create \#auto]
     272            set tmp [blt::vector create \#auto]
     273            $tmp set $xydata
     274            $tmp split $xv $yv
     275            blt::vector destroy $tmp
    279276        }
    280277
     
    322319    return $_ymarkers;
    323320}
     321
  • trunk/gui/scripts/field.tcl

    r1189 r1220  
    574574                    set xv [blt::vector create x$_counter]
    575575                    set yv [blt::vector create y$_counter]
    576 
    577                     foreach line [split $xydata \n] {
    578                         if {[scan $line {%g %g} xval yval] == 2} {
    579                             $xv append $xval
    580                             $yv append $yval
    581                         }
    582                     }
     576                    set tmp [blt::vector create \#auto]
     577                    $tmp set $xydata
     578                    $tmp split $xv $yv
     579                    blt::vector destroy $tmp
    583580                }
    584581            }
  • trunk/gui/scripts/heightmapviewer.tcl

    r1215 r1220  
    738738    }
    739739
    740     #
     740    # Reset the screen size. 
     741    set w [winfo width $itk_component(3dview)]
     742    set h [winfo height $itk_component(3dview)]
     743    _send "screen $w $h"
     744
    741745    # Reset the camera and other view parameters
    742     #
    743     _send "camera angle [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)]"
     746    set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)]
     747    _send "camera angle $xyz"
    744748    _send "camera zoom $_view(zoom)"
    745749
  • trunk/gui/scripts/molvisviewer.tcl

    r1215 r1220  
    6767    public method rock {option}
    6868    public method representation {option {model "all"} }
     69    public method ResetView {}
    6970
    7071    protected method _send {args}
     
    7879    protected method _vmouse2 {option b m x y}
    7980    protected method _vmouse  {option b m x y}
    80 
    8181    private method _receive_image { size cacheid frame rock }
    8282
     
    9090    private variable _dobj2raise  ;# maps dataobj => raise flag 0/1
    9191    private variable _dobj2ghost
     92
     93    private variable view_
    9294
    9395    private variable _model
     
    138140    set _hostlist $hostlist
    139141
     142    array set view_ {
     143        zoom 0
     144        mx 0
     145        my 0
     146        mz 0
     147        x  0
     148        y  0
     149        z  0
     150    }
     151
    140152    array set _settings [subst {
    141153        $this-model $_mrepresentation
     
    160172            -borderwidth 1 -padx 1 -pady 1 \
    161173            -bitmap [Rappture::icon reset] \
    162             -command [itcl::code $this _send "reset"]
     174            -command [itcl::code $this ResetView]
    163175    } {
    164176        usual
     
    593605
    594606    }
     607
    595608    if { $changed } {
    596609        array unset _imagecache
     
    608621        _update
    609622    }
     623    # Reset screen size
    610624    set w  [winfo width $itk_component(3dview)]
    611625    set h  [winfo height $itk_component(3dview)]
    612626    _send "screen $w $h"
     627    # Reset viewing parameters
     628    _send "reset"
     629    _send "rotate $view_(mx) $view_(my) $view_(mz)"
     630    _send "pan $view_(x) $view_(y)"
     631    _send "zoom $view_(zoom)"
    613632
    614633    set _inrebuild 0
     
    645664        if { [winfo ismapped $itk_component(3dview)] } {
    646665            _send "screen $w $h"
    647             _send "reset -push"
     666            # Why do a reset?
     667            #_send "reset -push"
    648668        } else {
    649669            _send "screen -defer $w $h"
    650             _send "reset -push"
     670            # Why do a reset?
     671            #_send "reset -push"
    651672        }
    652673    }
     
    671692        set dx [expr $x - $_mevent(x)]
    672693        set dy [expr $y - $_mevent(y)]
     694        set view_(x) [expr $view_(x) + $dx]
     695        set view_(y) [expr $view_(y) + $dy]
    673696        _send "pan $dx $dy"
    674697    }
     
    691714    switch -- $option {
    692715        "in" {
     716            set view_(zoom) [expr $view_(zoom) + $factor]
    693717            _send "zoom $factor"
    694718        }
    695719        "out" {
     720            set view_(zoom) [expr $view_(zoom) - $factor]
    696721            _send "zoom -$factor"
    697722        }
    698723        "reset" {
     724            set view_(zoom) 0
    699725            _send "reset"
    700726        }
     
    839865            set mz $dx
    840866        }
     867        # Accumlate movements
     868        set view_(mx) [expr {$view_(mx) + $mx}]
     869        set view_(my) [expr {$view_(my) + $my}]
     870        set view_(mz) [expr {$view_(mz) + $mz}]
    841871        _send "rotate $mx $my $mz"
    842872    }
     
    9901020        }
    9911021    }
     1022}
     1023
     1024#
     1025# ResetView
     1026#
     1027itcl::body Rappture::MolvisViewer::ResetView {} {
     1028    array set view_ {
     1029        mx 0
     1030        my 0
     1031        mz 0
     1032        x 0
     1033        y 0
     1034        z 0
     1035        zoom 0
     1036    }
     1037    _send "reset"
    9921038}
    9931039
     
    10661112    }
    10671113}
     1114
  • trunk/gui/scripts/nanovisviewer.tcl

    r1215 r1220  
    12431243# ----------------------------------------------------------------------
    12441244itcl::body Rappture::NanovisViewer::_pan {option x y} {
     1245    return
     1246    # Experimental stuff
    12451247    if { $option == "click" } {
    12461248        $itk_component(3dview) configure -cursor hand1
  • trunk/gui/scripts/visviewer.tcl

    r1160 r1220  
    2222    itk_option define -receivecommand receiveCommand ReceiveCommand ""
    2323
    24     private common _servers          ;# array of visualization server lists
    25     set _servers(nanovis) ""
    26     set _servers(pymol)   ""
     24    private common servers_         ;# array of visualization server lists
     25    set servers_(nanovis) "bilby.hubzero.org:2000"
     26    set servers_(pymol)   "bilby.hubzero.org:2020"
     27
     28    private variable sid_ ""        ;# socket connection to server
     29    private common done_            ;# Used to indicate status of send.
     30    private variable buffer_        ;# buffer for incoming/outgoing commands
     31    # Number of milliseconds to wait before idle timeout.
     32    #private variable idleTimeout_ 3600000
     33    #private variable idleTimeout_ 0
     34    private variable idleTimeout_ 5000
    2735
    2836    protected variable _dispatcher ""   ;# dispatcher for !events
    2937    protected variable _hosts ""    ;# list of hosts for server
    30     protected variable _sid ""      ;# socket connection to server
    3138    protected variable _parser ""   ;# interpreter for incoming commands
    3239    protected variable _image
    33     private common _done            ;# Used to indicate status of send.
    34     private variable _buffer        ;# buffer for incoming/outgoing commands
    3540
    3641    constructor { hostlist args } {
     
    4651    private method _SendHelper {}
    4752    private method _SendHelper.old {}
     53    private method _CheckConnection {}
    4854
    4955    protected method SendEcho { channel {data ""} }
     
    6571    }
    6672    public proc GetServerList { tag } {
    67         return $_servers($tag)
     73        return $servers_($tag)
    6874    }
    6975    public proc SetServerList { tag namelist } {
    7076        _CheckNameList $namelist
    71         set _servers($tag) $namelist
     77        set servers_($tag) $namelist
    7278    }
    7379    public proc SetPymolServerList { namelist } {
     
    8793    $_dispatcher register !serverDown
    8894    $_dispatcher dispatch $this !serverDown "[itcl::code $this _ServerDown]; list"
     95    $_dispatcher register !timeout
     96    $_dispatcher dispatch $this !timeout "[itcl::code $this Disconnect]; list"
    8997
    9098    _CheckNameList $hostlist
    9199    set _hostlist $hostlist
    92     set _buffer(in) ""
    93     set _buffer(out) ""
     100    set buffer_(in) ""
     101    set buffer_(out) ""
    94102    #
    95103    # Create a parser to handle incoming requests
     
    139147#
    140148itcl::body Rappture::VisViewer::destructor {} {
     149    $_dispatcher cancel !timeout
    141150    interp delete $_parser
    142     array unset _done $this
     151    array unset done_ $this
    143152}
    144153
     
    202211    while {1} {
    203212        SendEcho <<line "connecting to $hostname:$port..."
    204         if { [catch {socket $hostname $port} _sid] != 0 } {
     213        if { [catch {socket $hostname $port} sid_] != 0 } {
    205214            if {[llength $servers] == 0} {
    206215                blt::busy release $itk_component(hull)
     
    212221            continue
    213222        }
    214         fconfigure $_sid -translation binary -encoding binary
     223        fconfigure $sid_ -translation binary -encoding binary
    215224
    216225        # send memory requirement to the load balancer
    217         puts -nonewline $_sid [binary format I $memorySize]
    218         flush $_sid
     226        puts -nonewline $sid_ [binary format I $memorySize]
     227        flush $sid_
    219228
    220229        # read back a reconnection order
    221         set data [read $_sid 4]
     230        set data [read $sid_ 4]
    222231        if {[binary scan $data cccc b1 b2 b3 b4] != 4} {
    223232            blt::busy release $itk_component(hull)
     
    234243            # release the busy window over the hull.
    235244            $_dispatcher cancel !serverDown
     245            if { $idleTimeout_ > 0 } {
     246                $_dispatcher event -after $idleTimeout_ !timeout
     247            }
    236248            blt::busy release $itk_component(hull)
    237             fconfigure $_sid -buffering line
    238             fileevent $_sid readable [itcl::code $this _ReceiveHelper]
     249            fconfigure $sid_ -buffering line
     250            fileevent $sid_ readable [itcl::code $this _ReceiveHelper]
    239251            return 1
    240252        }
     
    254266#
    255267itcl::body Rappture::VisViewer::Disconnect {} {
     268    $_dispatcher cancel !timeout
    256269    if { [IsConnected] } {
    257         catch {close $_sid} err
    258         set _sid ""
    259         $_dispatcher event -after 750 !serverDown
    260     }
    261     set _buffer(in) ""
     270        catch {close $sid_} err
     271        set sid_ ""
     272    }
     273    set buffer_(in) ""
    262274}
    263275
     
    268280#
    269281itcl::body Rappture::VisViewer::IsConnected {} {
    270     return [expr {"" != $_sid}]
    271 }
    272 
    273 #
    274 # _SendHelper --
     282    return [expr {"" != $sid_}]
     283}
     284
     285#
     286# CheckConection --
    275287#
    276288#   Helper routine called from a file event to send data when the
    277289#   connection is writable (i.e. not blocked).  Sets a magic
    278 #   variable _done($this) when we're done.
     290#   variable done_($this) when we're done.
     291#
     292itcl::body Rappture::VisViewer::_CheckConnection {} {
     293    if { [IsConnected] } {
     294        if { [eof $sid_] } {
     295            error "unexpected eof on socket"
     296        }
     297        $_dispatcher cancel !timeout
     298        if { $idleTimeout_ > 0 } {
     299            $_dispatcher event -after $idleTimeout_ !timeout
     300        }
     301        return 1
     302    }
     303    # If we aren't connected, assume it's because the connection to the
     304    # visualization server broke. Try to open a connection and trigger a
     305    # rebuild.
     306    $_dispatcher cancel !serverDown
     307    set x [expr {[winfo rootx $itk_component(area)]+10}]
     308    set y [expr {[winfo rooty $itk_component(area)]+10}]
     309    Rappture::Tooltip::cue @$x,$y "Connecting..."
     310    set code [catch { Connect } ok]
     311    if { $code == 0 && $ok} {
     312        $_dispatcher event -idle !rebuild
     313        Rappture::Tooltip::cue hide
     314        return 1
     315    } else {
     316        Rappture::Tooltip::cue @$x,$y "Can't connect to visualization server.  This may be a network problem.  Wait a few moments and try resetting the view."
     317        return 0
     318    }
     319}
     320
     321#
     322# Flush --
     323#
     324#    Flushes the socket.
     325#
     326itcl::body Rappture::VisViewer::Flush {} {
     327    if { [_CheckConnection] } {
     328        flush $sid_
     329    }
     330}
     331
     332
     333#
     334# _SendHelper --
     335#
     336#   Helper routine called from a file event to send data when the
     337#   connection is writable (i.e. not blocked).  Sets a magic
     338#   variable done_($this) when we're done.
    279339#
    280340itcl::body Rappture::VisViewer::_SendHelper {} {
    281     puts $_sid $_buffer(out)
    282     flush $_sid
    283     set _done($this) 1;     # Success
     341    if { ![_CheckConnection] } {
     342        return 0
     343    }
     344    puts $sid_ $buffer_(out)
     345    flush $sid_
     346    set done_($this) 1;     # Success
    284347}
    285348
     
    289352#   Helper routine called from a file event to send data when the
    290353#   connection is writable (i.e. not blocked).  Sends data in chunks
    291 #   of 8k (or less).  Sets magic variable _done($this) to indicate
     354#   of 8k (or less).  Sets magic variable done_($this) to indicate
    292355#   that we're either finished (success) or could not send bytes to
    293356#   the server (failure).
    294357#
    295358itcl::body Rappture::VisViewer::_SendHelper.old {} {
    296     set bytesLeft [string length $_buffer(out)]
     359    if { ![_CheckConnection] } {
     360        return 0
     361    }
     362    set bytesLeft [string length $buffer_(out)]
    297363    if { $bytesLeft > 0} {
    298         set chunk [string range $_buffer(out) 0 8095]
    299         set _buffer(out)  [string range $_buffer(out) 8096 end]
     364        set chunk [string range $buffer_(out) 0 8095]
     365        set buffer_(out)  [string range $buffer_(out) 8096 end]
    300366        incr bytesLeft -8096
    301367        set code [catch {
    302368            if { $bytesLeft > 0 } {
    303                 puts -nonewline $_sid $chunk
     369                puts -nonewline $sid_ $chunk
    304370            } else {
    305                 puts $_sid $chunk
     371                puts $sid_ $chunk
    306372            }
    307373        } err]
    308374        if { $code != 0 } {
    309             puts stderr "error sending data to $_sid: $err"
     375            puts stderr "error sending data to $sid_: $err"
    310376            Disconnect
    311             set _done($this) 0;     # Failure
     377            set done_($this) 0;     # Failure
    312378        }
    313379    } else {
    314         set _done($this) 1;     # Success
     380        set done_($this) 1;     # Success
    315381    }
    316382}
     
    324390    SendEcho >>line $bytes
    325391
    326     if { ![IsConnected]} {
    327         # If we aren't connected, assume it's because the connection to the
    328         # visualization server broke. Try to open a connection and trigger a
    329         # rebuild.
    330         $_dispatcher cancel !serverDown
    331         set x [expr {[winfo rootx $itk_component(area)]+10}]
    332         set y [expr {[winfo rooty $itk_component(area)]+10}]
    333         Rappture::Tooltip::cue @$x,$y "Connecting..."
    334         set code [catch { Connect } ok]
    335         if { $code == 0 && $ok} {
    336             $_dispatcher event -idle !rebuild
    337             Rappture::Tooltip::cue hide
    338             return 1
    339        } else {
    340             Rappture::Tooltip::cue @$x,$y "Can't connect to visualization server.  This may be a network problem.  Wait a few moments and try resetting the view."
    341            return 0
    342         }
     392    if { ![_CheckConnection] } {
     393        return 0
    343394    }
    344395    # Even though the data is sent in only 1 "puts", we need to verify that
    345396    # the server is ready first.  Wait for the socket to become writable
    346397    # before sending anything.
    347     set _done($this) 1
    348     set _buffer(out) $bytes
    349     fileevent $_sid writable [itcl::code $this _SendHelper]
    350     tkwait variable ::Rappture::VisViewer::_done($this)
    351     fileevent $_sid writable ""
    352     flush $_sid
    353     set _buffer(out) ""
    354     return $_done($this)
     398    set done_($this) 1
     399    set buffer_(out) $bytes
     400    fileevent $sid_ writable [itcl::code $this _SendHelper]
     401    tkwait variable ::Rappture::VisViewer::done_($this)
     402    fileevent $sid_ writable ""
     403    flush $sid_
     404    set buffer_(out) ""
     405    return $done_($this)
    355406}
    356407
     
    361412#
    362413itcl::body Rappture::VisViewer::ReceiveBytes { size } {
    363     if { [eof $_sid] } {
    364         error "unexpected eof on socket"
    365     }
    366     set bytes [read $_sid $size]
     414    if { ![_CheckConnection] } {
     415        return 0
     416    }
     417    set bytes [read $sid_ $size]
    367418    ReceiveEcho <<line "<read $size bytes"
    368419    return $bytes
     
    389440#
    390441itcl::body Rappture::VisViewer::_ReceiveHelper {} {
    391     if { [IsConnected] } {
    392         if { [eof $_sid] } {
    393             error "_receive: unexpected eof on socket"
    394         }
    395         if { [gets $_sid line] < 0 } {
    396             Disconnect
    397         }
    398         set line [string trim $line]
    399         if { $line == "" } {
    400             return
    401         }
    402         if { [string equal [string range $line 0 2] "nv>"] } {
    403             ReceiveEcho <<line $line
    404             append _buffer(in) [string range $line 3 end]
    405             append _buffer(in) "\n"
    406             if {[info complete $_buffer(in)]} {
    407                 set request $_buffer(in)
    408                 set _buffer(in) ""
    409                 $_parser eval $request
    410             }
    411         } else {
    412             # this shows errors coming back from the engine
    413             ReceiveEcho <<error $line
    414             puts stderr "Render Server Error: $line"
    415         }
    416     }
    417 }
    418 
    419 
    420 #
    421 # Flush --
    422 #
    423 #    Flushes the socket.
    424 #
    425 itcl::body Rappture::VisViewer::Flush {} {
    426     if { [IsConnected] } {
    427         flush $_sid
     442    if { ![_CheckConnection] } {
     443        return 0
     444    }
     445    if { [gets $sid_ line] < 0 } {
     446        Disconnect
     447    }
     448    set line [string trim $line]
     449    if { $line == "" } {
     450        return
     451    }
     452    if { [string equal [string range $line 0 2] "nv>"] } {
     453        ReceiveEcho <<line $line
     454        append buffer_(in) [string range $line 3 end]
     455        append buffer_(in) "\n"
     456        if {[info complete $buffer_(in)]} {
     457            set request $buffer_(in)
     458            set buffer_(in) ""
     459            $_parser eval $request
     460        }
     461    } else {
     462        # this shows errors coming back from the engine
     463        ReceiveEcho <<error $line
     464        puts stderr "Render Server Error: $line"
    428465    }
    429466}
Note: See TracChangeset for help on using the changeset viewer.