Changeset 1919 for branches/blt4
- Timestamp:
- Oct 17, 2010, 8:47:44 PM (14 years ago)
- Location:
- branches/blt4/gui/scripts
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/blt4/gui/scripts/Makefile.in
r1918 r1919 117 117 $(srcdir)/valueresult.tcl \ 118 118 $(srcdir)/videoviewer.tcl \ 119 $(srcdir)/videoparticle.tcl \ 119 120 $(srcdir)/visviewer.tcl \ 120 121 $(srcdir)/vtkviewer.tcl \ -
branches/blt4/gui/scripts/barresult.tcl
r1804 r1919 106 106 107 107 private variable _dispatcher "" ;# dispatcher for !events 108 private variable _dlist "" ;# list of dataobj objects108 private variable _dlist "" ;# list of dataobjs 109 109 private variable _dataobj2color ;# maps dataobj => plotting color 110 110 private variable _dataobj2width ;# maps dataobj => line width … … 916 916 917 917 # Some elements are generated dynamically and therefore will 918 # not have a dataobj objectassociated with them.918 # not have a dataobj associated with them. 919 919 set mapx [$g element cget $elem -mapx] 920 920 set mapy [$g element cget $elem -mapy] … … 958 958 959 959 # Some elements are generated dynamically and therefore will 960 # not have a dataobj objectassociated with them.960 # not have a dataobj associated with them. 961 961 set mapx [$g element cget $elem -mapx] 962 962 set mapy [$g element cget $elem -mapy] -
branches/blt4/gui/scripts/flowvisviewer.tcl
r1764 r1919 2788 2788 if { $_settings($this-currenttime) >= $_flow(duration) } { 2789 2789 if { !$_settings($this-loop) } { 2790 flow off2790 flow off 2791 2791 return 2792 2792 } -
branches/blt4/gui/scripts/getopts.tcl
r1342 r1919 47 47 # 48 48 foreach line [split $spec \n] { 49 50 51 49 if {[llength $line] == 0} { 50 continue ;# ignore blank lines 51 } 52 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 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 } 95 95 } 96 96 … … 99 99 # 100 100 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 } 134 148 } 135 149 return "" -
branches/blt4/gui/scripts/histogram.tcl
r1550 r1919 155 155 error "bad option \"$which\": should be x, xlin, xlog, y, ylin, ylog" 156 156 } 157 } 158 if {"" == $vname} { 159 return {0 1} 157 160 } 158 161 $vname dup tmp -
branches/blt4/gui/scripts/historesult.tcl
r1804 r1919 75 75 } 76 76 77 option add * XyResult.autoColors $autocolors widgetDefault78 option add * XyResult*Balloon*Entry.background white widgetDefault77 option add *HistogramResult.autoColors $autocolors widgetDefault 78 option add *HistogramResult*Balloon*Entry.background white widgetDefault 79 79 80 80 itcl::class Rappture::HistogramResult { … … 488 488 } 489 489 controls { 490 set popup .histo resultdownload491 if {![winfo exists .histo resultdownload]} {490 set popup .histogramresultdownload 491 if {![winfo exists .histogramresultdownload]} { 492 492 # if we haven't created the popup yet, do it now 493 493 Rappture::Balloon $popup \ … … 517 517 } 518 518 now { 519 set popup .histo resultdownload520 if {[winfo exists .histo resultdownload]} {519 set popup .histogramresultdownload 520 if {[winfo exists .histogramresultdownload]} { 521 521 $popup deactivate 522 522 } … … 564 564 } 565 565 image { 566 set popup .histo printdownload566 set popup .histogramprintdownload 567 567 if { ![winfo exists $popup] } { 568 568 # Create a popup for the print dialog … … 727 727 foreach x [$xv values] y [$yv values] z [$zv values] { 728 728 set elem "elem[incr count]" 729 set _elem2 histo($elem) $dataobj729 set _elem2dataobj($elem) $dataobj 730 730 $g element create $elem -x $x -y $y -barwidth $z \ 731 731 -label $label -foreground $color \ … … 736 736 set z [expr {$r / ([$xv length]-1) * 0.8}] 737 737 set elem "elem[incr count]" 738 set _elem2 histo($elem) $dataobj738 set _elem2dataobj($elem) $dataobj 739 739 $g element create $elem -x $xv -y $yv -barwidth $z \ 740 740 -label $label -foreground $color \ -
branches/blt4/gui/scripts/videoviewer.tcl
r1901 r1919 45 45 public method video {args} 46 46 47 protected method togglePtrBind {pbvar} 47 48 protected method togglePtrCtrl {pbvar} 48 protected method togglePtrBind {pbvar}49 protected method whatPtrCtrl {} 49 50 50 51 protected method Play {} 52 protected method Seek {n} 51 53 protected method Rubberband {status win x y} 52 54 protected method Distance {status win x y} 53 55 protected method Measure {status win x y} 56 protected method Particle {status win x y} 57 protected method Trajectory {args} 54 58 protected method updateMeasurements {} 59 protected method calculateTrajectory {args} 55 60 56 61 private common _settings … … 62 67 private variable _units "m" 63 68 private variable _movie "" ;# movie we grab images from 69 private variable _lastFrame 0 ;# last frame in the movie 64 70 private variable _imh "" ;# current image being displayed 65 71 private variable _id "" ;# id of the next play command from after 66 72 private variable _pbvlist "" ;# list of push button variables 67 73 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 68 81 } 69 82 … … 81 94 $this-arrows 0 82 95 $this-currenttime 0 96 $this-framenum 0 83 97 $this-duration 1:00 84 98 $this-loop 0 … … 179 193 180 194 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 181 212 blt::table $itk_component(pointercontrols) \ 182 213 0,0 $itk_component(rectangle) -pady {3 0} \ 183 214 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} 185 217 186 218 blt::table configure $itk_component(pointercontrols) c* -resize none … … 195 227 -borderwidth 1 -padx 1 -pady 1 \ 196 228 -image [Rappture::icon flow-rewind] \ 197 -command [itcl::code $this video reset]229 -command [itcl::code $this video seek 0] 198 230 } { 199 231 usual … … 255 287 } 256 288 $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 258 307 # Duration 259 308 itk_component add duration { … … 303 352 304 353 $itk_component(speed) value 1 305 bind $itk_component(speed) <<Value>> [itcl::code $this flowspeed]354 bind $itk_component(speed) <<Value>> [itcl::code $this video speed] 306 355 307 356 … … 312 361 0,3 $itk_component(loop) -padx {2 0} \ 313 362 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} \ 315 365 0,7 $itk_component(speed) -padx {2 3} 316 366 … … 327 377 } 328 378 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 usual336 rename -background -controlbackground controlBackground Background337 }338 Rappture::Tooltip::for $itk_component(measGauge) \339 379 "Length of structure" 340 380 … … 359 399 # ---------------------------------------------------------------------- 360 400 itcl::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}" 362 407 363 408 set _imh [image create photo] 364 $_imh put [$_movie read]409 $_imh put [$_movie next] 365 410 $itk_component(main) create image 0 0 -anchor nw -image $_imh 366 411 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 367 430 $itk_component(main) configure -scrollregion [$itk_component(main) bbox all] 368 431 foreach { x0 y0 x1 y1 } [$itk_component(main) bbox all] break 369 432 set w [expr abs($x1-$x0)] 370 set h [expr abs($y1-$y0 )]371 $itk_component(main) configure -width $w -height $h433 set h [expr abs($y1-$y0+$pch+$mch)] 434 # $itk_component(main) configure -width $w -height $h 372 435 .main configure -width $w -height $h 373 436 … … 378 441 # ---------------------------------------------------------------------- 379 442 itcl::body Rappture::VideoViewer::video { args } { 443 set ret 0 380 444 set option [lindex $args 0] 381 445 switch -- $option { 382 446 "play" { 383 447 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>> "" 384 451 # start playing 385 452 Play … … 388 455 after cancel $_id 389 456 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] 390 461 } 391 462 } 392 463 "seek" { 464 Seek [lreplace $args 0 0] 393 465 } 394 466 "stop" { … … 396 468 set _settings($this-play) 0 397 469 } 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 } 398 477 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 402 482 } 403 483 404 484 # ---------------------------------------------------------------------- 405 485 # togglePtrCtrl - choose pointer mode: 406 # rectangle, distance, or measure486 # rectangle, distance, measure, particlemark 407 487 # ---------------------------------------------------------------------- 408 488 itcl::body Rappture::VideoViewer::togglePtrCtrl {pbvar} { 409 489 410 490 upvar 1 $pbvar inState 411 491 puts "togglePtrCtrl to $pbvar" 412 492 if {$inState == 1} { 413 493 # unpush previously pushed buttons … … 424 504 425 505 # ---------------------------------------------------------------------- 506 # whatPtrCtrl - figure out the current pointer mode: 507 # rectangle, distance, measure, particlemark 508 # ---------------------------------------------------------------------- 509 itcl::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 # ---------------------------------------------------------------------- 426 520 # togglePtrBind - update the bindings based on pointer controls 427 521 # ---------------------------------------------------------------------- 428 522 itcl::body Rappture::VideoViewer::togglePtrBind {pbvar} { 429 523 524 if {[string compare $pbvar current] == 0} { 525 set pbvar [whatPtrCtrl] 526 } 527 430 528 if {[string compare $pbvar rectPbVar] == 0} { 431 529 432 530 # Bindings for selecting rectangle 531 $itk_component(main) configure -cursor "" 532 433 533 bind $itk_component(main) <ButtonPress-1> \ 434 534 [itcl::code $this Rubberband new %W %x %y] … … 441 541 442 542 # Bindings for setting distance 543 $itk_component(main) configure -cursor "" 544 443 545 bind $itk_component(main) <ButtonPress-1> \ 444 546 [itcl::code $this Distance new %W %x %y] … … 451 553 452 554 # Bindings for measuring distance 555 $itk_component(main) configure -cursor "" 556 453 557 bind $itk_component(main) <ButtonPress-1> \ 454 558 [itcl::code $this Measure new %W %x %y] … … 458 562 [itcl::code $this Measure release %W %x %y] 459 563 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 460 583 } else { 461 584 … … 463 586 464 587 } 465 466 588 } 467 589 … … 471 593 # ---------------------------------------------------------------------- 472 594 itcl::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 # ---------------------------------------------------------------------- 647 itcl::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})] 475 675 } 476 676 … … 527 727 set dist [Rappture::Units::convert [$itk_component(distGauge) value] -units off] 528 728 set px2dist [expr $dist/$px] 529 if {$px2dist != $ _px2dist} {729 if {$px2dist != ${_px2dist}} { 530 730 set _px2dist $px2dist 531 731 } 532 732 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 } 538 741 } 539 742 … … 548 751 "new" { 549 752 $win delete "distance" 550 $win delete "distance _val"753 $win delete "distance-val" 551 754 $win create line \ 552 755 $x $y $x $y -fill red -width 2 \ … … 567 770 -window $itk_component(distGauge) \ 568 771 -anchor center \ 569 -tags "distance _val"772 -tags "distance-val" 570 773 } 571 774 default { … … 583 786 "new" { 584 787 $win delete "measure" 585 $win delete "measure_val"586 788 $win create line \ 587 789 $x $y $x $y -fill green -width 2 \ … … 593 795 } 594 796 "release" { 797 # finish drawing the measuring line 595 798 Measure drag $win $x $y 799 800 # calculate the location on the measuring line to place gauge 596 801 foreach { x0 y0 x1 y1 } [$itk_component(main) bbox "measure"] break 802 puts "bbox for $_measCnt is ($x0,$y0) ($x1,$y1)" 597 803 set rootx [winfo rootx $itk_component(main)] 598 804 set rooty [winfo rooty $itk_component(main)] 599 805 set x [expr "$x0 + (abs($x1-$x0)/2)"] 600 806 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 601 834 $itk_component(main) create window $x $y \ 602 -window $itk_component(measGauge ) \835 -window $itk_component(measGauge$_measCnt) \ 603 836 -anchor center \ 604 -tags "measure_val" 837 -tags "measure$_measCnt-val" 838 839 # set the value of the gauge with the calculated distance 605 840 set px [expr sqrt(pow(($x1-$x0),2)+pow(($y1-$y0),2))] 606 841 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 608 851 } 609 852 default { … … 612 855 } 613 856 } 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 # ---------------------------------------------------------------------- 864 itcl::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 # ---------------------------------------------------------------------- 923 itcl::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 # ---------------------------------------------------------------------- 985 itcl::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.