Changeset 1919 for branches/blt4


Ignore:
Timestamp:
Oct 17, 2010, 8:47:44 PM (14 years ago)
Author:
gah
Message:
 
Location:
branches/blt4/gui/scripts
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • branches/blt4/gui/scripts/Makefile.in

    r1918 r1919  
    117117                $(srcdir)/valueresult.tcl \
    118118                $(srcdir)/videoviewer.tcl \
     119                $(srcdir)/videoparticle.tcl \
    119120                $(srcdir)/visviewer.tcl \
    120121                $(srcdir)/vtkviewer.tcl \
  • branches/blt4/gui/scripts/barresult.tcl

    r1804 r1919  
    106106
    107107    private variable _dispatcher "" ;# dispatcher for !events
    108     private variable _dlist ""     ;# list of dataobj objects
     108    private variable _dlist ""     ;# list of dataobjs
    109109    private variable _dataobj2color  ;# maps dataobj => plotting color
    110110    private variable _dataobj2width  ;# maps dataobj => line width
     
    916916           
    917917            # Some elements are generated dynamically and therefore will
    918             # not have a dataobj object associated with them.
     918            # not have a dataobj associated with them.
    919919            set mapx [$g element cget $elem -mapx]
    920920            set mapy [$g element cget $elem -mapy]
     
    958958               
    959959                # Some elements are generated dynamically and therefore will
    960                 # not have a dataobj object associated with them.
     960                # not have a dataobj associated with them.
    961961                set mapx [$g element cget $elem -mapx]
    962962                set mapy [$g element cget $elem -mapy]
  • branches/blt4/gui/scripts/flowvisviewer.tcl

    r1764 r1919  
    27882788            if { $_settings($this-currenttime) >= $_flow(duration) } {
    27892789                if { !$_settings($this-loop) } {
    2790                     flow off
     2790                    flow off
    27912791                    return
    27922792                }
  • branches/blt4/gui/scripts/getopts.tcl

    r1342 r1919  
    4747    #
    4848    foreach line [split $spec \n] {
    49         if {[llength $line] == 0} {
    50             continue  ;# ignore blank lines
    51         }
     49        if {[llength $line] == 0} {
     50            continue  ;# ignore blank lines
     51        }
    5252
    53         set type [lindex $line 0]
    54         switch -- $type {
    55             value {
    56                 if {[llength $line] < 3} {
    57                     error "bad value spec \"$line\": should be \"value -flag default\""
    58                 }
    59                 set name [lindex $line 1]
    60                 set flags($name) $type
    61                 set params($name) [lindex $line 2]
    62                 lappend opts $name
    63             }
    64             flag {
    65                 if {[llength $line] < 3 || [llength $line] > 4} {
    66                     error "bad value spec \"$line\": should be \"flag group -flag ?default?\""
    67                 }
    68                 set group [lindex $line 1]
    69                 set name [lindex $line 2]
    70                 set flags($name) [list $type $group]
    71                 if {[llength $line] > 3} {
    72                     set params($group) $name
    73                     set params($name) 1
    74                 } else {
    75                     if {![info exists params($group)]} {
    76                         set params($group) ""
    77                     }
    78                     set params($name) 0
    79                 }
    80                 lappend opts $name
    81             }
    82             list {
    83                 if {[llength $line] < 3} {
    84                     error "bad value spec \"$line\": should be \"list -flag default\""
    85                 }
    86                 set name [lindex $line 1]
    87                 set flags($name) $type
    88                 set params($name) [lindex $line 2]
    89                 lappend opts $name
    90             }
    91             default {
    92                 error "bad arg type \"$type\": should be flag or value"
    93             }
    94         }
     53        set type [lindex $line 0]
     54        switch -- $type {
     55            value {
     56                if {[llength $line] < 3} {
     57                    error "bad value spec \"$line\": should be \"value -flag default\""
     58                }
     59                set name [lindex $line 1]
     60                set flags($name) $type
     61                set params($name) [lindex $line 2]
     62                lappend opts $name
     63            }
     64            flag {
     65                if {[llength $line] < 3 || [llength $line] > 4} {
     66                    error "bad value spec \"$line\": should be \"flag group -flag ?default?\""
     67                }
     68                set group [lindex $line 1]
     69                set name [lindex $line 2]
     70                set flags($name) [list $type $group]
     71                if {[llength $line] > 3} {
     72                    set params($group) $name
     73                    set params($name) 1
     74                } else {
     75                    if {![info exists params($group)]} {
     76                        set params($group) ""
     77                    }
     78                    set params($name) 0
     79                }
     80                lappend opts $name
     81            }
     82            list {
     83                if {[llength $line] < 3} {
     84                    error "bad value spec \"$line\": should be \"list -flag default\""
     85                }
     86                set name [lindex $line 1]
     87                set flags($name) $type
     88                set params($name) [lindex $line 2]
     89                lappend opts $name
     90            }
     91            default {
     92                error "bad arg type \"$type\": should be flag or value"
     93            }
     94        }
    9595    }
    9696
     
    9999    #
    100100    while {[llength $args] > 0} {
    101         set first [lindex $args 0]
    102         if {[string index $first 0] != "-"} {
    103             break
    104         }
    105         if {"--" == $first} {
    106             set args [lrange $args 1 end]
    107             break
    108         }
    109         if {![info exists params($first)]} {
    110             error "bad option \"$first\": should be [join [lsort $opts] {, }]"
    111         }
    112         switch -- [lindex $flags($first) 0] {
    113             value {
    114                 if {[llength $args] < 2} {
    115                     error "missing value for option $first"
    116                 }
    117                 set params($first) [lindex $args 1]
    118                 set args [lrange $args 2 end]
    119             }
    120             flag {
    121                 set group [lindex $flags($first) 1]
    122                 set params($group) $first
    123                 set params($first) 1
    124                 set args [lrange $args 1 end]
    125             }
    126             list {
    127                 if {[llength $args] < 2} {
    128                     error "missing value for option $first"
    129                 }
    130                 set params($first) [lrange $args 1 end]
    131                 set args ""
    132             }
    133         }
     101        set first [lindex $args 0]
     102        if {[string index $first 0] != "-"} {
     103            break
     104        }
     105        if {"--" == $first} {
     106            set args [lrange $args 1 end]
     107            break
     108        }
     109        if {![info exists params($first)]} {
     110            error "bad option \"$first\": should be [join [lsort $opts] {, }]"
     111        }
     112        switch -- [lindex $flags($first) 0] {
     113            value {
     114                if {[llength $args] < 2} {
     115                    error "missing value for option $first"
     116                }
     117                set params($first) [lindex $args 1]
     118                set args [lrange $args 2 end]
     119            }
     120            flag {
     121                set group [lindex $flags($first) 1]
     122                set params($group) $first
     123                set params($first) 1
     124                set args [lrange $args 1 end]
     125            }
     126            list {
     127                if {[llength $args] < 2} {
     128                    error "missing value for option $first"
     129                }
     130                foreach arg [lrange $args 1 end] {
     131                    if {[string index $arg 0] == "-"} {
     132                        break
     133                    }
     134                }
     135                set idx [lsearch -exact $args $arg]
     136                if {$idx == [expr [llength $args] - 1]} {
     137                    # reached the end of the $args list
     138                    # with no other -'d arguments
     139                    set params($first) [lrange $args 1 end]
     140                    set args ""
     141                } else {
     142                    # there are further -'d arguments to process
     143                    set params($first) [lrange $args 1 [expr $idx-1]]
     144                    set args [lrange $args $idx end]
     145                }
     146            }
     147        }
    134148    }
    135149    return ""
  • branches/blt4/gui/scripts/histogram.tcl

    r1550 r1919  
    155155            error "bad option \"$which\": should be x, xlin, xlog, y, ylin, ylog"
    156156        }
     157    }
     158    if {"" == $vname} {
     159        return {0 1}
    157160    }
    158161    $vname dup tmp
  • branches/blt4/gui/scripts/historesult.tcl

    r1804 r1919  
    7575}
    7676
    77 option add *XyResult.autoColors $autocolors widgetDefault
    78 option add *XyResult*Balloon*Entry.background white widgetDefault
     77option add *HistogramResult.autoColors $autocolors widgetDefault
     78option add *HistogramResult*Balloon*Entry.background white widgetDefault
    7979
    8080itcl::class Rappture::HistogramResult {
     
    488488        }
    489489        controls {
    490             set popup .historesultdownload
    491             if {![winfo exists .historesultdownload]} {
     490            set popup .histogramresultdownload
     491            if {![winfo exists .histogramresultdownload]} {
    492492                # if we haven't created the popup yet, do it now
    493493                Rappture::Balloon $popup \
     
    517517        }
    518518        now {
    519             set popup .historesultdownload
    520             if {[winfo exists .historesultdownload]} {
     519            set popup .histogramresultdownload
     520            if {[winfo exists .histogramresultdownload]} {
    521521                $popup deactivate
    522522            }
     
    564564                }
    565565                image {
    566                     set popup .histoprintdownload
     566                    set popup .histogramprintdownload
    567567                    if { ![winfo exists $popup] } {
    568568                        # Create a popup for the print dialog
     
    727727            foreach x [$xv values] y [$yv values] z [$zv values] {
    728728                set elem "elem[incr count]"
    729                 set _elem2histo($elem) $dataobj
     729                set _elem2dataobj($elem) $dataobj
    730730                $g element create $elem -x $x -y $y -barwidth $z \
    731731                    -label $label -foreground $color \
     
    736736            set z [expr {$r / ([$xv length]-1) * 0.8}]
    737737            set elem "elem[incr count]"
    738             set _elem2histo($elem) $dataobj
     738            set _elem2dataobj($elem) $dataobj
    739739            $g element create $elem -x $xv -y $yv -barwidth $z \
    740740                    -label $label -foreground $color \
  • branches/blt4/gui/scripts/videoviewer.tcl

    r1901 r1919  
    4545    public method video {args}
    4646
     47    protected method togglePtrBind {pbvar}
    4748    protected method togglePtrCtrl {pbvar}
    48     protected method togglePtrBind {pbvar}
     49    protected method whatPtrCtrl {}
    4950
    5051    protected method Play {}
     52    protected method Seek {n}
    5153    protected method Rubberband {status win x y}
    5254    protected method Distance {status win x y}
    5355    protected method Measure {status win x y}
     56    protected method Particle {status win x y}
     57    protected method Trajectory {args}
    5458    protected method updateMeasurements {}
     59    protected method calculateTrajectory {args}
    5560
    5661    private common   _settings
     
    6267    private variable _units "m"
    6368    private variable _movie ""      ;# movie we grab images from
     69    private variable _lastFrame 0   ;# last frame in the movie
    6470    private variable _imh ""        ;# current image being displayed
    6571    private variable _id ""         ;# id of the next play command from after
    6672    private variable _pbvlist ""    ;# list of push button variables
    6773    private variable _px2dist 0     ;# conversion for screen px to distance
     74    private variable _measCnt 0     ;# count of the number measure lines
     75    private variable _measTags ""   ;# list of measure line tags on canvas
     76    private variable _particles ""  ;# list of particles
     77    private variable _pcnt -1       ;# particle count
     78    private variable _framerate 30  ;# video frame rate
     79    private variable _mspf 20       ;# milliseconds per frame wait time
     80    private variable _waiting 0     ;# number of frames behind we are
    6881}
    6982
     
    8194        $this-arrows            0
    8295        $this-currenttime       0
     96        $this-framenum          0
    8397        $this-duration          1:00
    8498        $this-loop              0
     
    179193
    180194
     195
     196    # ==== particle mark tool ====
     197    set particleImg [image create photo -file [file join $imagesDir "volume-on.gif"]]
     198    itk_component add particle {
     199        Rappture::PushButton $itk_component(pointercontrols).particlepb \
     200            -onimage $particleImg \
     201            -offimage $particleImg \
     202            -command [itcl::code $this togglePtrCtrl partPbVar] \
     203            -variable partPbVar
     204    } {
     205        usual
     206    }
     207    Rappture::Tooltip::for $itk_component(particle) \
     208        "Mark the location of a particle to follow"
     209
     210    lappend _pbvlist partPbVar
     211
    181212    blt::table $itk_component(pointercontrols) \
    182213        0,0 $itk_component(rectangle) -pady {3 0} \
    183214        0,1 $itk_component(distance) -pady {3 0} \
    184         0,2 $itk_component(measure) -pady {3 0}
     215        0,2 $itk_component(measure) -pady {3 0} \
     216        0,3 $itk_component(particle) -pady {3 0}
    185217
    186218    blt::table configure $itk_component(pointercontrols) c* -resize none
     
    195227            -borderwidth 1 -padx 1 -pady 1 \
    196228            -image [Rappture::icon flow-rewind] \
    197             -command [itcl::code $this video reset]
     229            -command [itcl::code $this video seek 0]
    198230    } {
    199231        usual
     
    255287    }
    256288    $itk_component(dial) current 0.0
    257     bind $itk_component(dial) <<Value>> [itcl::code $this flow goto]
     289    bind $itk_component(dial) <<Value>> [itcl::code $this video seek -currenttime]
     290
     291    # Current Frame Number
     292    itk_component add framenum {
     293        Rappture::Spinint $itk_component(moviecontrols).framenum \
     294            -min 1 -max 1 -width 1 -font "arial 9"
     295    } {
     296        usual
     297        ignore -highlightthickness
     298        rename -background -controlbackground controlBackground Background
     299    }
     300    $itk_component(framenum) value 1
     301    bind $itk_component(framenum) <<Value>> \
     302        [itcl::code $this video seek -framenum]
     303    Rappture::Tooltip::for $itk_component(framenum) \
     304        "Set the current frame number"
     305
     306
    258307    # Duration
    259308    itk_component add duration {
     
    303352
    304353    $itk_component(speed) value 1
    305     bind $itk_component(speed) <<Value>> [itcl::code $this flow speed]
     354    bind $itk_component(speed) <<Value>> [itcl::code $this video speed]
    306355
    307356
     
    312361        0,3 $itk_component(loop) -padx {2 0} \
    313362        0,4 $itk_component(dial) -fill x -padx {2 0 } \
    314         0,5 $itk_component(duration) -padx { 0 0} \
     363        0,5 $itk_component(framenum) -padx { 0 0} \
     364        0,6 $itk_component(duration) -padx { 0 0} \
    315365        0,7 $itk_component(speed) -padx {2 3}
    316366
     
    327377    }
    328378    Rappture::Tooltip::for $itk_component(distGauge) \
    329         "Length of structure"
    330 
    331     itk_component add measGauge {
    332         Rappture::Gauge $itk_interior.measGauge \
    333             -units "m"
    334     } {
    335         usual
    336         rename -background -controlbackground controlBackground Background
    337     }
    338     Rappture::Tooltip::for $itk_component(measGauge) \
    339379        "Length of structure"
    340380
     
    359399# ----------------------------------------------------------------------
    360400itcl::body Rappture::VideoViewer::load {filename} {
    361     set _movie [Rappture::MediaPlayer $filename]
     401    set _movie [Rappture::Video $filename]
     402    set _framerate [${_movie} get framerate]
     403    set _mspf [expr round(((1.0/${_framerate})*1000)/pow(2,[$itk_component(speed) value]-1))]
     404    # set _mspf 7
     405    puts "framerate = ${_framerate}"
     406    puts "mspf = ${_mspf}"
    362407
    363408    set _imh [image create photo]
    364     $_imh put [$_movie read]
     409    $_imh put [$_movie next]
    365410    $itk_component(main) create image 0 0 -anchor nw -image $_imh
    366411
     412    set _lastFrame [$_movie get position end]
     413    set offset [expr 1.0/double(${_lastFrame})]
     414    puts "end = ${_lastFrame}"
     415    puts "offset = $offset"
     416    $itk_component(dial) configure -offset $offset
     417
     418    set lcv ${_lastFrame}
     419    set cnt 1
     420    while {$lcv > 9} {
     421        set lcv [expr $lcv/10]
     422        incr cnt
     423    }
     424    $itk_component(framenum) configure -max ${_lastFrame} -width $cnt
     425
     426    set pch [$itk_component(pointercontrols) cget -height]
     427    set mch [$itk_component(moviecontrols) cget -height]
     428    set pch 30
     429    set mch 30
    367430    $itk_component(main) configure -scrollregion [$itk_component(main) bbox all]
    368431    foreach { x0 y0 x1 y1 } [$itk_component(main) bbox all] break
    369432    set w [expr abs($x1-$x0)]
    370     set h [expr abs($y1-$y0)]
    371     $itk_component(main) configure -width $w -height $h
     433    set h [expr abs($y1-$y0+$pch+$mch)]
     434    # $itk_component(main) configure -width $w -height $h
    372435    .main configure -width $w -height $h
    373436
     
    378441# ----------------------------------------------------------------------
    379442itcl::body Rappture::VideoViewer::video { args } {
     443    set ret 0
    380444    set option [lindex $args 0]
    381445    switch -- $option {
    382446        "play" {
    383447            if {$_settings($this-play) == 1} {
     448                # while in play move, you can't seek using the
     449                # framenum spinint widget
     450                bind $itk_component(framenum) <<Value>> ""
    384451                # start playing
    385452                Play
     
    388455                after cancel $_id
    389456                set _settings($this-play) 0
     457                # setup seek bindings using the
     458                # framenum spinint widget
     459                bind $itk_component(framenum) <<Value>> \
     460                    [itcl::code $this video seek -framenum]
    390461            }
    391462        }
    392463        "seek" {
     464            Seek [lreplace $args 0 0]
    393465        }
    394466        "stop" {
     
    396468            set _settings($this-play) 0
    397469        }
     470        "position" {
     471            set ret [${_movie} get position cur]
     472        }
     473        "speed" {
     474            set _mspf [expr round(((1.0/${_framerate})*1000)/pow(2,[$itk_component(speed) value]-1))]
     475            puts "_mspf = ${_mspf}"
     476        }
    398477        default {
    399             error "bad option \"$option\": should be play, stop, toggle, or reset."
    400         }
    401     }
     478            error "bad option \"$option\": should be play, stop, toggle, position, or reset."
     479        }
     480    }
     481    return $ret
    402482}
    403483
    404484# ----------------------------------------------------------------------
    405485# togglePtrCtrl - choose pointer mode:
    406 #                 rectangle, distance, or measure
     486#                 rectangle, distance, measure, particlemark
    407487# ----------------------------------------------------------------------
    408488itcl::body Rappture::VideoViewer::togglePtrCtrl {pbvar} {
    409489
    410490    upvar 1 $pbvar inState
    411 
     491    puts "togglePtrCtrl to $pbvar"
    412492    if {$inState == 1} {
    413493        # unpush previously pushed buttons
     
    424504
    425505# ----------------------------------------------------------------------
     506# whatPtrCtrl - figure out the current pointer mode:
     507#                 rectangle, distance, measure, particlemark
     508# ----------------------------------------------------------------------
     509itcl::body Rappture::VideoViewer::whatPtrCtrl {} {
     510    foreach pbv $_pbvlist {
     511        upvar #0 $pbv var
     512        if {$var != "" && $var != 0} {
     513            return $pbv
     514        }
     515    }
     516}
     517
     518
     519# ----------------------------------------------------------------------
    426520# togglePtrBind - update the bindings based on pointer controls
    427521# ----------------------------------------------------------------------
    428522itcl::body Rappture::VideoViewer::togglePtrBind {pbvar} {
    429523
     524    if {[string compare $pbvar current] == 0} {
     525        set pbvar [whatPtrCtrl]
     526    }
     527
    430528    if {[string compare $pbvar rectPbVar] == 0} {
    431529
    432530        # Bindings for selecting rectangle
     531        $itk_component(main) configure -cursor ""
     532
    433533        bind $itk_component(main) <ButtonPress-1> \
    434534            [itcl::code $this Rubberband new %W %x %y]
     
    441541
    442542        # Bindings for setting distance
     543        $itk_component(main) configure -cursor ""
     544
    443545        bind $itk_component(main) <ButtonPress-1> \
    444546            [itcl::code $this Distance new %W %x %y]
     
    451553
    452554        # Bindings for measuring distance
     555        $itk_component(main) configure -cursor ""
     556
    453557        bind $itk_component(main) <ButtonPress-1> \
    454558            [itcl::code $this Measure new %W %x %y]
     
    458562            [itcl::code $this Measure release %W %x %y]
    459563
     564    } elseif {[string compare $pbvar partPbVar] == 0} {
     565
     566        # Bindings for marking particle locations
     567        $itk_component(main) configure -cursor ""
     568
     569        bind $itk_component(main) <ButtonPress-1> \
     570            [itcl::code $this Particle new %W %x %y]
     571        bind $itk_component(main) <B1-Motion> ""
     572        bind $itk_component(main) <ButtonRelease-1> ""
     573
     574    } elseif {[string compare $pbvar particle] == 0} {
     575
     576        # Bindings for interacting with particles
     577        $itk_component(main) configure -cursor hand2
     578
     579        bind $itk_component(main) <ButtonPress-1> ""
     580        bind $itk_component(main) <B1-Motion> ""
     581        bind $itk_component(main) <ButtonRelease-1> ""
     582
    460583    } else {
    461584
     
    463586
    464587    }
    465 
    466588}
    467589
     
    471593# ----------------------------------------------------------------------
    472594itcl::body Rappture::VideoViewer::Play {} {
    473     $_imh put [$_movie read]
    474     set _id [after 20 [itcl::code $this Play]]
     595
     596    set cur [$_movie get position cur]
     597
     598#    # this probably is incorrect because other people
     599#    # could schedule stuff in the after queue
     600#    if {[llength [after info]] > 1} {
     601#        # drop frames that get caught up in the "after queue"
     602#        # in order to keep up with the frame rate
     603#        #foreach i [after info] {
     604#        #    after cancel $i
     605#        #}
     606#        incr _waiting
     607#    } else {
     608#        # display the next frame
     609#        $_imh put [$_movie seek +[incr _waiting]]
     610#        set _waiting 0
     611#
     612#        # update the dial and framenum widgets
     613#        set _settings($this-currenttime) [expr 1.0*$cur/${_lastFrame}]
     614#        $itk_component(framenum) value $cur
     615#
     616#    }
     617
     618    # display the next frame
     619    $_imh put [$_movie next]
     620
     621    # update the dial and framenum widgets
     622    set _settings($this-currenttime) [expr 1.0*$cur/${_lastFrame}]
     623    $itk_component(framenum) value $cur
     624
     625    if {[expr $cur%100] == 0} {
     626        puts "after: [after info]"
     627        puts "id = ${_id}"
     628    }
     629
     630    # schedule the next frame to be displayed
     631    if {$cur < ${_lastFrame}} {
     632        set _id [after ${_mspf} [itcl::code $this Play]]
     633    }
     634}
     635
     636
     637# ----------------------------------------------------------------------
     638# Seek - go to a frame in the video video frame
     639#   Seek -percent 43
     640#   Seek -percent 0.5
     641#   Seek +5
     642#   Seek -5
     643#   Seek 35
     644#   Seek -currenttime
     645#   Seek -framenum
     646# ----------------------------------------------------------------------
     647itcl::body Rappture::VideoViewer::Seek {args} {
     648    set option [lindex $args 0]
     649    switch -- $option {
     650        "-percent" {
     651            set val [lindex $args 1]
     652            if {[string is integer -strict $val] == 1} {
     653                set val [expr double($val) / 100.0]
     654            }
     655            # convert the percentage to a frame number (new cur)
     656            set val [expr int($val * ${_lastFrame})]
     657        }
     658        "-currenttime" {
     659            set val $_settings($this-currenttime)
     660            set val [expr round($val * ${_lastFrame})]
     661        }
     662        "-framenum" {
     663            set val [$itk_component(framenum) value]
     664        }
     665        default {
     666            set val $option
     667        }
     668    }
     669    if {"" == $val} {
     670        error "bad value: \"$val\": should be \"seek \[-percent\] value\""
     671    }
     672    $_imh put [$_movie seek $val]
     673    set cur [$_movie get position cur]
     674    set _settings($this-currenttime) [expr double($cur) / double(${_lastFrame})]
    475675}
    476676
     
    527727    set dist [Rappture::Units::convert [$itk_component(distGauge) value] -units off]
    528728    set px2dist [expr $dist/$px]
    529     if {$px2dist != $_px2dist} {
     729    if {$px2dist != ${_px2dist}} {
    530730        set _px2dist $px2dist
    531731    }
    532732
    533     # if the measure object exists?
    534     foreach { x0 y0 x1 y1 } [$itk_component(main) bbox "measure"] break
    535     set px [expr sqrt(pow(($x1-$x0),2)+pow(($y1-$y0),2))]
    536     set dist [expr $px*$_px2dist]
    537     $itk_component(measGauge) value $dist
     733    # if measure lines exist, update their values
     734    foreach tag ${_measTags} {
     735        foreach { x0 y0 x1 y1 } [$itk_component(main) bbox $tag] break
     736        set px [expr sqrt(pow(($x1-$x0),2)+pow(($y1-$y0),2))]
     737        set dist [expr $px*${_px2dist}]
     738        regexp {measure(\d+)} $tag match cnt
     739        $itk_component(measGauge$cnt) value $dist
     740    }
    538741}
    539742
     
    548751        "new" {
    549752            $win delete "distance"
    550             $win delete "distance_val"
     753            $win delete "distance-val"
    551754            $win create line \
    552755                $x $y $x $y -fill red -width 2  \
     
    567770                -window $itk_component(distGauge) \
    568771                -anchor center \
    569                 -tags "distance_val"
     772                -tags "distance-val"
    570773        }
    571774        default {
     
    583786        "new" {
    584787            $win delete "measure"
    585             $win delete "measure_val"
    586788            $win create line \
    587789                $x $y $x $y -fill green -width 2  \
     
    593795        }
    594796        "release" {
     797            # finish drawing the measuring line
    595798            Measure drag $win $x $y
     799
     800            # calculate the location on the measuring line to place gauge
    596801            foreach { x0 y0 x1 y1 } [$itk_component(main) bbox "measure"] break
     802            puts "bbox for $_measCnt is ($x0,$y0) ($x1,$y1)"
    597803            set rootx [winfo rootx $itk_component(main)]
    598804            set rooty [winfo rooty $itk_component(main)]
    599805            set x [expr "$x0 + (abs($x1-$x0)/2)"]
    600806            set y [expr "$y0 + (abs($y1-$y0)/2)"]
     807
     808#            set popup ".measure$_measCnt-popup"
     809#            if { ![winfo exists $popup] } {
     810#                # Create a popup for the measure line dialog
     811#                Rappture::Balloon $popup -title "Configure measurement..."
     812#                set inner [$popup component inner]
     813#                # Create the print dialog widget and add it to the
     814#                # the balloon popup.
     815#                Rappture::XyPrint $inner.print-
     816#                $popup configure \
     817#                    -deactivatecommand [list $inner.print reset]-
     818#                blt::table $inner 0,0 $inner.print -fill both
     819#            }
     820#
     821#
     822            # create a new gauge for this measuring line
     823            itk_component add measGauge$_measCnt {
     824                Rappture::Gauge $itk_interior.measGauge$_measCnt \
     825                    -units "m"
     826            } {
     827                usual
     828                rename -background -controlbackground controlBackground Background
     829            }
     830            Rappture::Tooltip::for $itk_component(measGauge$_measCnt) \
     831                "Length of structure $_measCnt"
     832
     833            # place the gauge on the measuring line
    601834            $itk_component(main) create window $x $y \
    602                 -window $itk_component(measGauge) \
     835                -window $itk_component(measGauge$_measCnt) \
    603836                -anchor center \
    604                 -tags "measure_val"
     837                -tags "measure$_measCnt-val"
     838
     839            # set the value of the gauge with the calculated distance
    605840            set px [expr sqrt(pow(($x1-$x0),2)+pow(($y1-$y0),2))]
    606841            set dist [expr $px*$_px2dist]
    607             $itk_component(measGauge) value $dist
     842            $itk_component(measGauge$_measCnt) value $dist
     843
     844            # rename the tag for the line
     845            # so we can have multiple measure lines
     846            # store tag name for future value updates
     847            $itk_component(main) addtag "measure$_measCnt" withtag "measure"
     848            $itk_component(main) dtag "measure" "measure"
     849            lappend _measTags "measure$_measCnt"
     850            incr _measCnt
    608851        }
    609852        default {
     
    612855    }
    613856}
     857
     858# ----------------------------------------------------------------------
     859# Particle - mark a particle in the video, a new particle object is
     860#            created from information like the name, which video
     861#            frames it lives in, it's coords in the canvas in each
     862#            frame, it's color...
     863# ----------------------------------------------------------------------
     864itcl::body Rappture::VideoViewer::Particle {status win x y} {
     865    switch -- $status {
     866        "new" {
     867            incr _pcnt
     868            puts "pcnt = ${_pcnt}"
     869            set name "particle${_pcnt}"
     870            set p [Rappture::VideoParticle $itk_component(main).#auto $win \
     871                    -fncallback [itcl::code $this video position cur] \
     872                    -trajcallback [itcl::code $this Trajectory] \
     873                    -halo 5 \
     874                    -name $name \
     875                    -color green]
     876            set frameNum [$_movie get position cur]
     877            $p Add frame $frameNum $x $y
     878            $p Show particle
     879
     880            # link the new particle to the last particle added
     881            set lastp ""
     882            while {[llength ${_particles}] > 0} {
     883                set lastp [lindex ${_particles} end]
     884                if {[llength [$lastp Coords]] != 0} {
     885                    break
     886                } else {
     887                    set _particles [lreplace ${_particles} end end]
     888                    set lastp ""
     889                }
     890            }
     891
     892            if {[string compare "" $lastp] != 0} {
     893                $lastp Link $p
     894                bind $lastp <<Motion>> [itcl::code $lastp drawVectors]]
     895            }
     896
     897
     898            # add the particle to the list
     899            lappend _particles $p
     900
     901            $win bind $name <ButtonPress-1> [itcl::code $p Move press %x %y]
     902            $win bind $name <B1-Motion> [itcl::code $p Move motion %x %y]
     903            $win bind $name <ButtonRelease-1> [itcl::code $p Move release %x %y]
     904
     905            $win bind $name <ButtonPress-3> [itcl::code $p Menu activate %x %y]
     906
     907            $win bind $name <Enter> [itcl::code $this togglePtrBind particle]
     908            $win bind $name <Leave> [itcl::code $this togglePtrBind current]
     909
     910#            set pm [Rappture::VideoParticleManager]
     911#            $pm add $p0
     912#            set plist [$pm list]
     913        }
     914        default {
     915            error "bad status \"$status\": should be new, drag, or release"
     916        }
     917    }
     918}
     919
     920# ----------------------------------------------------------------------
     921# Trajectory - draw a trajectory between two particles
     922# ----------------------------------------------------------------------
     923itcl::body Rappture::VideoViewer::Trajectory {args} {
     924
     925    set nargs [llength $args]
     926    if {($nargs != 1) && ($nargs != 2)} {
     927        error "wrong # args: should be \"Trajectory p0 p1\""
     928    }
     929
     930    set p0 ""
     931    set p1 ""
     932    foreach {p0 p1} $args break
     933
     934    if {[string compare "" $p0] == 0} {
     935        # p0 does not exist
     936        return
     937    }
     938
     939    # remove any old trajectory links from p0
     940    set p0name [$p0 cget -name]
     941    set oldlink "vec-$p0name"
     942    puts "removing $oldlink"
     943    $itk_component(main) delete $oldlink
     944
     945    # check to see if p1 exists anymore
     946    if {[string compare "" $p1] == 0} {
     947        # p1 does not exist
     948        return
     949    }
     950
     951    foreach {x0 y0} [$p0 Coords] break
     952    foreach {x1 y1} [$p1 Coords] break
     953    set p1name [$p1 cget -name]
     954    set link "vec-$p0name-$p1name"
     955    puts "adding $link"
     956    $itk_component(main) create line $x0 $y0 $x1 $y1 \
     957        -fill green \
     958        -width 2 \
     959        -tags "vector $link vec-$p0name" \
     960        -dash {4 4} \
     961        -arrow last
     962
     963    # calculate trajectory, truncate it after 4 sigdigs
     964    puts "---------$link---------"
     965    set t [calculateTrajectory [$p0 Frame] $x0 $y0 [$p1 Frame] $x1 $y1]
     966    set tt [string range $t 0 [expr [string first . $t] + 4]]
     967
     968
     969    # calculate coords for text
     970    foreach { x0 y0 x1 y1 } [$itk_component(main) bbox $link] break
     971    set x [expr "$x0 + (abs($x1-$x0)/2)"]
     972    set y [expr "$y0 + (abs($y1-$y0)/2)"]
     973
     974    $itk_component(main) create text $x $y \
     975        -tags "vectext $link vec-$p0name" \
     976        -justify center \
     977        -text "$tt [$itk_component(distGauge) cget -units]/s" \
     978        -fill green \
     979        -width [expr sqrt(pow(abs($x1-$x0),2)+pow(abs($y1-$y0),2))]
     980}
     981
     982# ----------------------------------------------------------------------
     983# calculateTrajectory - calculate the value of the trajectory
     984# ----------------------------------------------------------------------
     985itcl::body Rappture::VideoViewer::calculateTrajectory {args} {
     986    # set framerate 29.97         ;# frames per second
     987    # set px2dist    8.00         ;# px per meter
     988
     989    foreach {f0 x0 y0 f1 x1 y1} $args break
     990    set px [expr sqrt(pow(abs($x1-$x0),2)+pow(abs($y1-$y0),2))]
     991    set frames [expr $f1 - $f0]
     992
     993    if {($frames != 0) && (${_px2dist} != 0)} {
     994        set t [expr 1.0*$px/$frames/${_px2dist}*${_framerate}]
     995    } else {
     996        set t 0.0
     997    }
     998
     999    puts "px = $px"
     1000    puts "frames = $frames"
     1001    puts "px2dist = ${_px2dist}"
     1002    puts "framerate = ${_framerate}"
     1003    puts "trajectory = $t"
     1004
     1005    return $t
     1006}
     1007
Note: See TracChangeset for help on using the changeset viewer.