Changeset 2144
- Timestamp:
- Mar 23, 2011, 6:43:21 PM (14 years ago)
- Location:
- trunk/gui
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/apps/launcher.tcl
r2126 r2144 91 91 # Note: We're sourcing the driver file "main.tcl" rather than exec-ing 92 92 # wish because we want to see stderr and stdout messages when they 93 # written, rather than when the program completes. It also eliminates94 # one process waiting for the other to complete. If "exec" is needed,95 # then the following could be replaced with blt::bgexec. It doesn't96 # 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. 97 97 set argv $alist 98 98 package require Tk -
trunk/gui/apps/vtkcontour-test
r2126 r2144 352 352 set f [.main pane 0] 353 353 VtkContourViewer_init_resources 354 #set servers [Rappture::VtkContourViewer::GetServerList "vtkvis"]355 Rappture::VtkContourViewer $f.viewer "localhost:2010"354 set servers [Rappture::VtkContourViewer::GetServerList "vtkvis"] 355 Rappture::VtkContourViewer $f.viewer $servers 356 356 pack $f.viewer -expand yes -fill both 357 357 set widgets(vtkcontourviewer) $f.viewer -
trunk/gui/scripts/field.tcl
r1570 r2144 490 490 updir updir 491 491 camera camera.position 492 type about.type 492 493 } { 493 494 set str [$_field get $path] -
trunk/gui/scripts/field2dresult.tcl
r2131 r2144 56 56 } 57 57 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 } 59 70 if {"" != $servers && $flags(-mode) != "vtk"} { 60 71 switch -- $flags(-mode) { -
trunk/gui/scripts/filexfer.tcl
r1925 r2144 343 343 foreach prog { 344 344 clientaction 345 /usr/lib/hubzero/clientaction 345 346 /apps/bin/clientaction 346 347 /apps/xvnc/bin/clientaction -
trunk/gui/scripts/resultviewer.tcl
r2133 r2144 264 264 if {![info exists _mode2widget($mode)]} { 265 265 if { [$dataobj isunirect2d] } { 266 set resultMode "vtkcontour" 266 if { [$dataobj hints type] == "contour" } { 267 set resultMode "vtkcontour" 268 } else { 269 set resultMode "heightmap" 270 } 267 271 } else { 268 272 set resultMode "vtk" -
trunk/gui/scripts/sequenceresult.tcl
r1930 r2144 467 467 2D { 468 468 if { [$dataobj isunirect2d] } { 469 set mode "heightmap" 469 if { [$dataobj hints type] == "contour" } { 470 set mode "vtkcontour" 471 } else { 472 set mode "heightmap" 473 } 470 474 } else { 471 475 set mode "vtk" -
trunk/gui/scripts/unirect2d.tcl
r2128 r2144 79 79 ymin yaxis.min 80 80 ymax yaxis.max 81 type about.type 81 82 } { 82 83 set str [$m get $path] -
trunk/gui/scripts/vtkcontourviewer.tcl
r2127 r2144 1 1 2 2 # ---------------------------------------------------------------------- 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, 7 6 # transmits data, and displays the results. 8 7 # ====================================================================== … … 75 74 protected method ReceiveDataset { args } 76 75 protected method ReceiveImage { args } 76 protected method DrawLegend {} 77 77 protected method ReceiveLegend { colormap size } 78 78 protected method Rotate {option x y} … … 80 80 protected method Zoom {option} 81 81 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 82 88 # The following methods are only used by this class. 83 89 private method BuildCameraTab {} 84 90 private method BuildViewTab {} 85 private method BuildColormap { colormap }91 private method BuildColormap { colormap dataobj comp } 86 92 private method EventuallyResize { w h } 87 93 private method EventuallyResizeLegend { } 88 private method Set Colormap{ dataobj comp }94 private method SetStyles { dataobj comp } 89 95 private method PanCamera {} 90 private method volume { tag name }91 96 private method ConvertToVtkData { dataobj comp } 97 private method GetImage { args } 98 private method GetVtkData { args } 99 private method BuildDownloadPopup { widget command } 92 100 93 101 private variable _outbuf ;# buffer for outgoing commands … … 100 108 private variable _colormaps ;# contains all the colormaps 101 109 ;# in the server. 102 private variable _dataset s2style ;# maps dataobj-component to transfunc110 private variable _dataset2style ;# maps dataobj-component to transfunc 103 111 private variable _style2datasets ;# maps tf back to list of 104 112 # dataobj-components using the tf. … … 111 119 # defined but not loaded. If 1 the transfer function has been named 112 120 # and loaded. 113 private variable _activeColormaps 114 private variable _first "" ;# This is the topmost volume. 121 private variable _first "" ;# This is the topmost dataset. 115 122 private variable _buffering 0 116 123 … … 123 130 private variable _resizePending 0 124 131 private variable _resizeLegendPending 0 132 private variable _outline 125 133 } 126 134 … … 154 162 $_parser alias legend [itcl::code $this ReceiveLegend] 155 163 $_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 } 156 173 157 174 # Initialize the view to some default parameters. … … 163 180 pan-x 0 164 181 pan-y 0 182 zoom-x 1.0 183 zoom-y 1.0 165 184 } 166 185 set _limits(vmin) 0.0 … … 174 193 $this-theta $_view(theta) 175 194 $this-opacity 1 176 $this-edges 1177 195 $this-axes 1 178 196 $this-legend 1 179 197 $this-colormap 1 180 $this-wireframe 1 181 $this-polydata 1 198 $this-edges 0 182 199 $this-isolines 1 183 200 $this-zoom $_view(zoom) … … 185 202 186 203 itk_component add view { 187 label $itk_component(plotarea).vol -image $_image(plot)\204 canvas $itk_component(plotarea).view \ 188 205 -highlightthickness 0 -borderwidth 0 189 206 } { … … 191 208 ignore -highlightthickness -borderwidth -background 192 209 } 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) "" 193 232 194 233 set f [$itk_component(main) component controls] … … 229 268 Rappture::Tooltip::for $itk_component(zoomout) "Zoom out" 230 269 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) select239 Rappture::Tooltip::for $itk_component(volume) \240 "Toggle the volume cloud on/off"241 pack $itk_component(volume) -padx 2 -pady 2242 243 270 BuildViewTab 244 271 BuildCameraTab … … 248 275 set _image(legend) [image create photo] 249 276 itk_component add legend { 250 canvas $itk_component(plotarea).legend - height50 -highlightthickness 0277 canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0 251 278 } { 252 279 usual … … 265 292 0,0 $itk_component(view) -fill both -reqwidth $w \ 266 293 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 { 276 300 bind $itk_component(view) <Configure> \ 277 301 [itcl::code $this EventuallyResize %w %h] 278 302 } 279 303 # Bindings for panning via mouse 280 304 bind $itk_component(view) <ButtonPress-2> \ … … 339 363 } 340 364 365 itcl::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 380 itcl::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 389 itcl::body Rappture::VtkContourViewer::EventuallyResizeLegend {} { 390 if { !$_resizeLegendPending } { 391 $_dispatcher event -after 100 !legend 392 set _resizeLegendPending 1 393 } 394 } 395 341 396 # ---------------------------------------------------------------------- 342 397 # USAGE: add <dataobj> ?<settings>? … … 355 410 -description "" 356 411 -param "" 412 -type "" 357 413 } 358 414 foreach {opt val} $settings { … … 448 504 array unset _limits $dataobj* 449 505 array unset _obj2ovride $dataobj-* 450 array unset _dataset2style $dataobj-*451 506 set changed 1 452 507 } … … 514 569 } 515 570 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 518 584 } 519 585 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 } 529 597 } 530 598 return "" … … 630 698 ReceiveEcho <<line "<read $info(-bytes) bytes" 631 699 if { $info(-type) == "image" } { 632 ReceiveEcho "for [image width $_image(plot)]x[image height $_image(plot)] image>"633 700 $_image(plot) configure -data $bytes 701 #puts stderr "received image [image width $_image(plot)]x[image height $_image(plot)] image>" 634 702 } elseif { $info(type) == "print" } { 635 703 set tag $this-print-$info(-token) … … 638 706 } 639 707 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 # ---------------------------------------------------------------------- 715 itcl::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 # 740 itcl::body Rappture::VtkContourViewer::DrawLegend {} { 651 741 set c $itk_component(legend) 652 742 set w [winfo width $c] 653 743 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 # ---------------------------------------------------------------------- 778 itcl::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 } 673 791 } 674 792 … … 719 837 EventuallyResize $w $h 720 838 839 set _limits(vmin) "" 840 set _limits(vmax) "" 721 841 foreach dataobj [get] { 722 842 foreach comp [$dataobj components] { … … 728 848 append _outbuf $bytes 729 849 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 733 852 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 } 735 861 } 736 862 } … … 747 873 748 874 set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)] 749 SendCmd "camera rotate $xyz"875 #SendCmd "camera rotate $xyz" 750 876 PanCamera 877 SendCmd "camera mode image" 751 878 SendCmd "camera zoom $_view(zoom)" 752 FixSettings edges753 879 FixSettings opacity 754 880 FixSettings isolines 755 FixSettings polydata756 881 FixSettings colormap 757 882 FixSettings axes 758 FixSettings wireframe883 FixSettings edges 759 884 760 885 # Nothing to send -- activate the proper ivol … … 770 895 foreach tag [array names _datasets $_first-*] { 771 896 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 775 904 # display the proper transfer function in the legend. 776 905 set comp [lindex [$_first components] 0] … … 834 963 pan-x 0 835 964 pan-y 0 965 zoom-x 1.0 966 zoom-y 1.0 836 967 } 837 968 if { $_first != "" } { … … 842 973 } 843 974 set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)] 844 SendCmd "camera rotate $xyz"975 #SendCmd "camera rotate $xyz" 845 976 PanCamera 846 977 set _settings($this-theta) $_view(theta) … … 850 981 set _settings($this-pan-y) $_view(pan-y) 851 982 set _settings($this-zoom) $_view(zoom) 852 SendCmd "camera reset "983 SendCmd "camera reset all" 853 984 } 854 985 } … … 860 991 set x $_view(pan-x) 861 992 set y $_view(pan-y) 862 SendCmd "camera pan $x $y"993 #SendCmd "camera pan $x $y" 863 994 } 864 995 … … 929 1060 set _settings($this-phi) $_view(phi) 930 1061 set _settings($this-psi) $_view(psi) 931 SendCmd "camera rotate $xyz"1062 #SendCmd "camera rotate $xyz" 932 1063 set _click(x) $x 933 1064 set _click(y) $y … … 958 1089 set h [winfo height $itk_component(view)] 959 1090 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))] 962 1093 set _view(pan-x) [expr $_view(pan-x) + $x] 963 1094 set _view(pan-y) [expr $_view(pan-y) + $y] … … 1002 1133 set sval [expr { 0.01 * double($val) }] 1003 1134 foreach dataset [CurrentDatasets] { 1004 SendCmd " datasetopacity $sval $dataset"1135 SendCmd "pseudocolor opacity $sval $dataset" 1005 1136 } 1006 1137 } … … 1014 1145 } 1015 1146 } 1016 "wireframe" {1017 if {[isconnected]} {1018 set bool $_settings($this-wireframe)1019 foreach dataset [CurrentDatasets] {1020 SendCmd "polydata wireframe $bool $dataset"1021 }1022 }1023 }1024 1147 "edges" { 1025 1148 if {[isconnected]} { 1026 1149 set bool $_settings($this-edges) 1027 1150 foreach dataset [CurrentDatasets] { 1028 SendCmd "p olydataedges $bool $dataset"1151 SendCmd "pseudocolor edges $bool $dataset" 1029 1152 } 1030 1153 } … … 1032 1155 "colormap" { 1033 1156 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 } 1035 1165 foreach dataset [CurrentDatasets] { 1036 1166 SendCmd "pseudocolor visible $bool $dataset" 1167 SendCmd "contour2d linecolor $linecolor $dataset" 1168 SendCmd "pseudocolor linecolor $linecolor $dataset" 1037 1169 } 1038 1170 } … … 1045 1177 } 1046 1178 "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) 1054 1186 } 1055 1187 } … … 1060 1192 } 1061 1193 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 # 1198 itcl::body Rappture::VtkContourViewer::SetStyles { dataobj comp } { 1089 1199 array set style { 1090 1200 -color rainbow … … 1095 1205 array set style [lindex [$dataobj components -style $comp] 0] 1096 1206 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)] } { 1098 1211 set _dataset2style($tag) $colormap 1099 1212 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 1101 1217 set _colormaps($colormap) 1 1102 1218 } 1219 SendCmd "contour2d add numcontours $style(-levels) $tag\n" 1103 1220 SendCmd "pseudocolor colormap $colormap $tag" 1104 1221 return $colormap … … 1108 1225 # BuildColormap -- 1109 1226 # 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 } { 1227 itcl::body Rappture::VtkContourViewer::BuildColormap { colormap dataobj comp } { 1228 puts stderr "BuildColormap $colormap" 1117 1229 array set style { 1118 1230 -color rainbow … … 1120 1232 -opacity 1.0 1121 1233 } 1122 foreach {dataobj comp} [split $_style2datasets($colormap) -] break1123 1234 array set style [lindex [$dataobj components -style $comp] 0] 1124 1235 … … 1127 1238 } 1128 1239 set clist [split $style(-color) :] 1129 set cmap "0.0 [Color2RGB white] "1240 set cmap {} 1130 1241 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)}] 1132 1243 set color [lindex $clist $i] 1133 1244 append cmap "$x [Color2RGB $color] " 1134 1245 } 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 } 1137 1249 set tag $this-$colormap 1138 1250 if { ![info exists _settings($tag-opacity)] } { … … 1141 1253 set max $_settings($tag-opacity) 1142 1254 1143 set wmap " "1255 set wmap "0.0 1.0 1.0 1.0" 1144 1256 SendCmd "colormap add $colormap { $cmap } { $wmap }" 1145 1257 } … … 1225 1337 -font "Arial 9" 1226 1338 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 1233 1339 checkbutton $inner.legend \ 1234 1340 -text "Legend" \ … … 1237 1343 -font "Arial 9" 1238 1344 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] \ 1249 1349 -font "Arial 9" 1250 1350 … … 1259 1359 0,0 $inner.axes -columnspan 4 -anchor w -pady 2 \ 1260 1360 1,0 $inner.colormap -columnspan 4 -anchor w -pady 2 \ 1261 2,0 $inner.edges -columnspan 4 -anchor w -pady 2 \1262 1361 3,0 $inner.isolines -columnspan 4 -anchor w -pady 2 \ 1263 1362 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 \ 1266 1364 7,0 $inner.clear -anchor e -pady 2 \ 1267 1365 7,1 $inner.opacity -columnspan 2 -pady 2 -fill x\ … … 1298 1396 1299 1397 1300 itcl::body Rappture::VtkContourViewer::DoResize {} {1301 if { $_width < 2 } {1302 set _width 5001303 }1304 if { $_height < 2 } {1305 set _height 5001306 }1307 #SendCmd "screen size $_width $_height"1308 set _resizePending 01309 }1310 1311 itcl::body Rappture::VtkContourViewer::EventuallyResize { w h } {1312 set _width $w1313 set _height $h1314 if { !$_resizePending } {1315 $_dispatcher event -idle !resize1316 set _resizePending 11317 }1318 }1319 1320 itcl::body Rappture::VtkContourViewer::EventuallyResizeLegend {} {1321 if { !$_resizeLegendPending } {1322 $_dispatcher event -idle !legend1323 set _resizeLegendPending 11324 }1325 }1326 1327 1398 # 1328 1399 # camera -- … … 1349 1420 set _view($who) $_settings($this-$who) 1350 1421 set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)] 1351 SendCmd "camera rotate $xyz"1422 #SendCmd "camera rotate $xyz" 1352 1423 } 1353 1424 "zoom" { 1354 1425 set _view($who) $_settings($this-$who) 1355 SendCmd "camera zoom $_view(zoom)"1426 #SendCmd "camera zoom $_view(zoom)" 1356 1427 } 1357 1428 } 1358 1429 } 1359 1430 } 1360 }1361 1362 itcl::body Rappture::VtkContourViewer::volume { tag name } {1363 set bool $_settings($this-dataset-$name)1364 SendCmd "dataset visible $bool $tag"1365 1431 } 1366 1432 … … 1382 1448 return $out 1383 1449 } 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 # 1458 itcl::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 # 1476 itcl::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 # 1501 itcl::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 # 1517 itcl::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 # 1534 itcl::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 1556 itcl::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 1568 itcl::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 1578 itcl::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.