- Timestamp:
- Apr 14, 2015, 9:47:12 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/vtkvolumeviewer.tcl
r5208 r5225 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 2 # ---------------------------------------------------------------------- 3 3 # COMPONENT: vtkvolumeviewer - Vtk volume viewer … … 57 57 public method get {args} 58 58 public method isconnected {} 59 public method parameters {title args} { 60 # do nothing 59 public method parameters {title args} { 60 # do nothing 61 61 } 62 62 public method scale {args} 63 63 public method updateTransferFunctions {} 64 64 65 private method AddNewMarker { x y } 65 private method AddNewMarker { x y } 66 66 private method BuildVolumeComponents {} 67 private method ComputeAlphamap { cname } 67 private method ComputeAlphamap { cname } 68 68 private method ComputeTransferFunction { cname } 69 private method GetColormap { cname color } 70 private method GetDatasetsWithComponent { cname } 71 private method HideAllMarkers {} 72 private method InitComponentSettings { cname } 69 private method GetColormap { cname color } 70 private method GetDatasetsWithComponent { cname } 71 private method HideAllMarkers {} 72 private method InitComponentSettings { cname } 73 73 private method ParseLevelsOption { cname levels } 74 74 private method ParseMarkersOption { cname markers } … … 77 77 private method SendTransferFunctions {} 78 78 private method SetInitialTransferFunction { dataobj cname } 79 private method SwitchComponent { cname } 79 private method SwitchComponent { cname } 80 80 81 81 private variable _alphamap 82 private variable _current ""; # Currently selected component 83 private variable _volcomponents ; # Array of components found 82 private variable _current ""; # Currently selected component 83 private variable _volcomponents ; # Array of components found 84 84 private variable _componentsList ; # List of component names 85 85 private variable _cname2transferFunction … … 94 94 private method BuildCameraTab {} 95 95 private method BuildCutplaneTab {} 96 private method BuildDownloadPopup { widget command } 96 private method BuildDownloadPopup { widget command } 97 97 private method BuildViewTab {} 98 98 private method BuildVolumeTab {} … … 105 105 private method DoResize {} 106 106 private method DoRotate {} 107 private method EnterLegend { x y } 108 private method EventuallyResize { w h } 109 private method EventuallyRequestLegend {} 110 private method EventuallyRotate { q } 111 private method EventuallySetCutplane { axis args } 112 private method GetImage { args } 113 private method GetVtkData { args } 107 private method EnterLegend { x y } 108 private method EventuallyResize { w h } 109 private method EventuallyRequestLegend {} 110 private method EventuallyRotate { q } 111 private method EventuallySetCutplane { axis args } 112 private method GetImage { args } 113 private method GetVtkData { args } 114 114 private method InitSettings { args } 115 private method IsValidObject { dataobj } 115 private method IsValidObject { dataobj } 116 116 private method LeaveLegend {} 117 117 private method MotionLegend { x y } … … 119 119 private method PanCamera {} 120 120 private method Pick {x y} 121 private method QuaternionToView { q } { 121 private method QuaternionToView { q } { 122 122 foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break 123 123 } … … 129 129 private method Rotate {option x y} 130 130 private method SetLegendTip { x y } 131 private method SetObjectStyle { dataobj comp } 131 private method SetObjectStyle { dataobj comp } 132 132 private method SetOrientation { side } 133 private method Slice {option args} 134 private method ViewToQuaternion {} { 133 private method Slice {option args} 134 private method ViewToQuaternion {} { 135 135 return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)] 136 136 } … … 140 140 private variable _dlist "" ; # list of data objects 141 141 private variable _obj2ovride ; # maps dataobj => style override 142 private variable _datasets ; # contains all the dataobj-component 142 private variable _datasets ; # contains all the dataobj-component 143 143 ; # datasets in the server 144 144 private variable _colormaps ; # contains all the colormaps … … 164 164 private variable _cutplanePending 0 165 165 private variable _legendPending 0 166 private variable _fields 166 private variable _fields 167 167 private variable _curFldName "" 168 168 private variable _curFldLabel "" … … 234 234 -xpan 0 235 235 -ypan 0 236 -zoom 1.0 236 -zoom 1.0 237 237 } 238 238 set _arcball [blt::arcball create 100 100] … … 282 282 itk_component add fieldmenu { 283 283 menu $itk_component(plotarea).menu -bg black -fg white -relief flat \ 284 -tearoff no 284 -tearoff no 285 285 } { 286 286 usual … … 302 302 303 303 set _map(id) [$c create image 0 0 -anchor nw -image $_image(plot)] 304 set _map(cwidth) -1 305 set _map(cheight) -1 304 set _map(cwidth) -1 305 set _map(cheight) -1 306 306 set _map(zoom) 1.0 307 307 set _map(original) "" … … 349 349 -offimage [Rappture::icon volume-off] \ 350 350 -variable [itcl::scope _settings(-volumevisible)] \ 351 -command [itcl::code $this AdjustSetting -volumevisible] 351 -command [itcl::code $this AdjustSetting -volumevisible] 352 352 } 353 353 $itk_component(volume) select … … 361 361 -offimage [Rappture::icon cutbutton] \ 362 362 -variable [itcl::scope _settings(-cutplanesvisible)] \ 363 -command [itcl::code $this AdjustSetting -cutplanesvisible] 363 -command [itcl::code $this AdjustSetting -cutplanesvisible] 364 364 } 365 365 Rappture::Tooltip::for $itk_component(cutplane) \ … … 380 380 set _image(legend) [image create photo] 381 381 itk_component add legend { 382 canvas $itk_component(plotarea).legend -height 50 -highlightthickness 0 382 canvas $itk_component(plotarea).legend -height 50 -highlightthickness 0 383 383 } { 384 384 usual … … 391 391 [list focus $itk_component(legend)] 392 392 393 # Hack around the Tk panewindow. The problem is that the requested 393 # Hack around the Tk panewindow. The problem is that the requested 394 394 # size of the 3d view isn't set until an image is retrieved from 395 395 # the server. So the panewindow uses the tiny size. … … 398 398 blt::table $itk_component(plotarea) \ 399 399 0,0 $itk_component(view) -fill both -reqwidth $w \ 400 1,0 $itk_component(legend) -fill x 400 1,0 $itk_component(legend) -fill x 401 401 blt::table configure $itk_component(plotarea) r1 -resize none 402 402 … … 483 483 484 484 itcl::body Rappture::VtkVolumeViewer::DoRotate {} { 485 SendCmd "camera orient [ViewToQuaternion]" 485 SendCmd "camera orient [ViewToQuaternion]" 486 486 set _rotatePending 0 487 487 } … … 510 510 if { !$_rotatePending } { 511 511 set _rotatePending 1 512 global rotate_delay 512 global rotate_delay 513 513 $_dispatcher event -after $rotate_delay !rotate 514 514 } … … 617 617 continue 618 618 } 619 if {[info exists _obj2ovride($dataobj-raise)] && 619 if {[info exists _obj2ovride($dataobj-raise)] && 620 620 $_obj2ovride($dataobj-raise)} { 621 621 set dlist [linsert $dlist 0 $dataobj] … … 645 645 } 646 646 return $dlist 647 } 647 } 648 648 -image { 649 649 if {[llength $args] != 2} { … … 879 879 $_dispatcher cancel !legend 880 880 # disconnected -- no more data sitting on server 881 array unset _datasets 882 array unset _colormaps 883 array unset _dataset2style 881 array unset _datasets 882 array unset _colormaps 883 array unset _dataset2style 884 884 885 885 array unset _parsedFunction … … 988 988 # Turn on buffering of commands to the server. We don't want to 989 989 # be preempted by a server disconnect/reconnect (which automatically 990 # generates a new call to Rebuild). 990 # generates a new call to Rebuild). 991 991 StartBufferingCommands 992 992 … … 1022 1022 1023 1023 # No volumes are active (i.e. in the working set of displayed volumes). 1024 # A volume is always invisible if it's not in the working set. A 1024 # A volume is always invisible if it's not in the working set. A 1025 1025 # volume in the working set may be visible/invisible depending upon the 1026 1026 # global visibility value. … … 1034 1034 if { ![info exists _datasets($tag)] } { 1035 1035 set bytes [$dataobj vtkdata $comp] 1036 if 0 { 1036 if 0 { 1037 1037 set f [open /tmp/vtkvolume.vtk "w"] 1038 1038 fconfigure $f -translation binary -encoding binary … … 1142 1142 itcl::body Rappture::VtkVolumeViewer::CurrentDatasets {args} { 1143 1143 set flag [lindex $args 0] 1144 switch -- $flag { 1144 switch -- $flag { 1145 1145 "-all" { 1146 1146 if { [llength $args] > 1 } { … … 1161 1161 set dlist [get -visible] 1162 1162 } 1163 } 1163 } 1164 1164 default { 1165 1165 set dlist $args … … 1280 1280 foreach tag [CurrentDatasets -visible] { 1281 1281 SendCmd "dataset getscalar pixel $x $y $tag" 1282 } 1282 } 1283 1283 } 1284 1284 … … 1393 1393 if { $bool } { 1394 1394 blt::table $itk_component(plotarea) \ 1395 1,0 $itk_component(legend) -fill x 1395 1,0 $itk_component(legend) -fill x 1396 1396 } else { 1397 blt::table forget $itk_component(legend) 1397 blt::table forget $itk_component(legend) 1398 1398 } 1399 1399 } … … 1405 1405 # volume control determines whether they are visible. 1406 1406 # 1407 # Note: The use of the current component is a hold over from 1407 # Note: The use of the current component is a hold over from 1408 1408 # nanovis. If we can't display more than one volume, 1409 # we don't have to limit the effects to a specific 1409 # we don't have to limit the effects to a specific 1410 1410 # component. 1411 1411 foreach tag [GetDatasetsWithComponent $_current] { … … 1653 1653 SendCmd "outline color $rgb" 1654 1654 SendCmd "$_cutplaneCmd color $rgb" 1655 $itk_component(legend) itemconfigure labels -fill $color 1656 $itk_component(legend) itemconfigure limits -fill $color 1655 $itk_component(legend) itemconfigure labels -fill $color 1656 $itk_component(legend) itemconfigure limits -fill $color 1657 1657 } 1658 1658 } … … 1691 1691 -font "Arial 9" 1692 1692 1693 label $inner.background_l -text "Background" -font "Arial 9" 1693 label $inner.background_l -text "Background" -font "Arial 9" 1694 1694 itk_component add background { 1695 1695 Rappture::Combobox $inner.background -width 10 -editable no … … 1698 1698 "black" "black" \ 1699 1699 "white" "white" \ 1700 "grey" "grey" 1700 "grey" "grey" 1701 1701 1702 1702 $itk_component(background) value $_settings(-background) … … 1740 1740 label $inner.lighting_l \ 1741 1741 -text "Lighting / Material Properties" \ 1742 -font "Arial 9 bold" 1742 -font "Arial 9 bold" 1743 1743 1744 1744 checkbutton $inner.lighting \ … … 1800 1800 1801 1801 label $inner.transferfunction_l \ 1802 -text "Transfer Function" -font "Arial 9 bold" 1802 -text "Transfer Function" -font "Arial 9 bold" 1803 1803 1804 1804 label $inner.thin -text "Thin" -font $font … … 1863 1863 14,1 $inner.thin -anchor e \ 1864 1864 14,2 $inner.thickness -cspan 2 -fill x \ 1865 14,4 $inner.thick -anchor w 1865 14,4 $inner.thick -anchor w 1866 1866 1867 1867 blt::table configure $inner r* c* -resize none … … 1913 1913 -font "Arial 9" 1914 1914 1915 label $inner.mode_l -text "Mode" -font "Arial 9" 1915 label $inner.mode_l -text "Mode" -font "Arial 9" 1916 1916 1917 1917 itk_component add axismode { … … 1922 1922 "closest_triad" "closest" \ 1923 1923 "furthest_triad" "farthest" \ 1924 "outer_edges" "outer" 1924 "outer_edges" "outer" 1925 1925 $itk_component(axismode) value $_settings(-axisflymode) 1926 1926 bind $inner.mode <<Value>> [itcl::code $this AdjustSetting -axisflymode] … … 1995 1995 1996 1996 set fg [option get $itk_component(hull) font Font] 1997 1997 1998 1998 set inner [$itk_component(main) insert end \ 1999 1999 -title "Cutplane Settings" \ 2000 -icon [Rappture::icon cutbutton]] 2000 -icon [Rappture::icon cutbutton]] 2001 2001 2002 2002 $inner configure -borderwidth 4 … … 2122 2122 2123 2123 # 2124 # camera -- 2124 # camera -- 2125 2125 # 2126 2126 itcl::body Rappture::VtkVolumeViewer::camera {option args} { 2127 switch -- $option { 2127 switch -- $option { 2128 2128 "show" { 2129 2129 puts [array get _view] … … 2173 2173 2174 2174 itcl::body Rappture::VtkVolumeViewer::GetImage { args } { 2175 if { [image width $_image(download)] > 0 && 2175 if { [image width $_image(download)] > 0 && 2176 2176 [image height $_image(download)] > 0 } { 2177 2177 set bytes [$_image(download) data -format "jpeg -quality 100"] … … 2186 2186 -title "[Rappture::filexfer::label downloadWord] as..." 2187 2187 set inner [$popup component inner] 2188 label $inner.summary -text "" -anchor w 2188 label $inner.summary -text "" -anchor w 2189 2189 radiobutton $inner.vtk_button -text "VTK data file" \ 2190 2190 -variable [itcl::scope _downloadPopup(format)] \ 2191 2191 -font "Helvetica 9 " \ 2192 -value vtk 2192 -value vtk 2193 2193 Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file." 2194 2194 radiobutton $inner.image_button -text "Image File" \ 2195 2195 -variable [itcl::scope _downloadPopup(format)] \ 2196 -value image 2196 -value image 2197 2197 Rappture::Tooltip::for $inner.image_button \ 2198 2198 "Save as digital image." … … 2215 2215 2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \ 2216 2216 4,1 $inner.cancel -width .9i -fill y \ 2217 4,0 $inner.ok -padx 2 -width .9i -fill y 2217 4,0 $inner.ok -padx 2 -width .9i -fill y 2218 2218 blt::table configure $inner r3 -height 4 2219 2219 blt::table configure $inner r4 -pady 4 … … 2351 2351 set font "Arial 8" 2352 2352 set lineht [font metrics $font -linespace] 2353 2353 2354 2354 if { [info exists _fields($fname)] } { 2355 2355 foreach { title units } $_fields($fname) break … … 2363 2363 set x [expr $w - 2] 2364 2364 if { [$c find withtag "legend"] == "" } { 2365 set y 2 2365 set y 2 2366 2366 $c create text $x $y \ 2367 2367 -anchor ne \ … … 2438 2438 set font "Arial 8" 2439 2439 set lineht [font metrics $font -linespace] 2440 2440 2441 2441 set imgHeight [image height $_image(legend)] 2442 2442 set coords [$c coords colormap] … … 2461 2461 } 2462 2462 set color [eval format "\#%02x%02x%02x" $pixel] 2463 $_image(swatch) put black -to 0 0 23 23 2464 $_image(swatch) put $color -to 1 1 22 22 2463 $_image(swatch) put black -to 0 0 23 23 2464 $_image(swatch) put $color -to 1 1 22 22 2465 2465 .rappturetooltip configure -icon $_image(swatch) 2466 2466 … … 2473 2473 set value 0.0 2474 2474 } 2475 set tipx [expr $x + 15] 2475 set tipx [expr $x + 15] 2476 2476 set tipy [expr $y - 5] 2477 2477 Rappture::Tooltip::text $c "$title $value" 2478 Rappture::Tooltip::tooltip show $c +$tipx,+$tipy 2478 Rappture::Tooltip::tooltip show $c +$tipx,+$tipy 2479 2479 } 2480 2480 … … 2521 2521 # ---------------------------------------------------------------------- 2522 2522 itcl::body Rappture::VtkVolumeViewer::Combo {option} { 2523 set c $itk_component(view) 2523 set c $itk_component(view) 2524 2524 switch -- $option { 2525 2525 post { … … 2534 2534 } 2535 2535 deactivate { 2536 $c itemconfigure title -fill $itk_option(-plotforeground) 2536 $c itemconfigure title -fill $itk_option(-plotforeground) 2537 2537 } 2538 2538 invoke { … … 2570 2570 # 2571 2571 # The -markers option takes a list of zero or more values (the values 2572 # may be separated either by spaces or commas) that have the following 2572 # may be separated either by spaces or commas) that have the following 2573 2573 # format: 2574 2574 # … … 2588 2588 set n [scan $marker "%g%s" value suffix] 2589 2589 if { $n == 2 && $suffix == "%" } { 2590 # $n% : Set relative value (0..1). 2590 # $n% : Set relative value (0..1). 2591 2591 lappend list [expr {$value * 0.01}] 2592 2592 } else { … … 2679 2679 set amap $_alphamap($cname) 2680 2680 } 2681 set opaqueAmap "0.0 1.0 1.0 1.0" 2681 set opaqueAmap "0.0 1.0 1.0 1.0" 2682 2682 set _cname2transferFunction($cname) [list $cmap $amap] 2683 2683 SendCmd [list colormap define $cname $cmap $amap] … … 2690 2690 # Changes only the colormap portion of the transfer function. 2691 2691 # 2692 itcl::body Rappture::VtkVolumeViewer::ResetColormap { cname color } { 2692 itcl::body Rappture::VtkVolumeViewer::ResetColormap { cname color } { 2693 2693 # Get the current transfer function 2694 2694 if { ![info exists _cname2transferFunction($cname)] } { … … 2698 2698 set cmap [GetColormap $cname $color] 2699 2699 set _cname2transferFunction($cname) [list $cmap $amap] 2700 set opaqueAmap "0.0 1.0 1.0 1.0" 2700 set opaqueAmap "0.0 1.0 1.0 1.0" 2701 2701 SendCmd [list colormap define $cname $cmap $amap] 2702 2702 SendCmd [list colormap define $cname-opaque $cmap $opaqueAmap] … … 2705 2705 2706 2706 # ---------------------------------------------------------------------- 2707 # USAGE: updateTransferFunctions 2707 # USAGE: updateTransferFunctions 2708 2708 # 2709 2709 # This is called by the transfer function editor whenever the … … 2731 2731 } 2732 2732 # Add a new marker to the current transfer function 2733 $_transferFunctionEditors($_current) deleteMarker $x $y 2734 } 2735 2736 itcl::body Rappture::VtkVolumeViewer::SetOrientation { side } { 2733 $_transferFunctionEditors($_current) deleteMarker $x $y 2734 } 2735 2736 itcl::body Rappture::VtkVolumeViewer::SetOrientation { side } { 2737 2737 array set positions { 2738 2738 front "1 0 0 0" … … 2745 2745 foreach name { -qw -qx -qy -qz } value $positions($side) { 2746 2746 set _view($name) $value 2747 } 2747 } 2748 2748 set q [ViewToQuaternion] 2749 2749 $_arcball quaternion $q 2750 SendCmd "camera orient $q" 2750 SendCmd "camera orient $q" 2751 2751 SendCmd "camera reset" 2752 2752 set _view(-xpan) 0 … … 2763 2763 # in SwitchComponent below. 2764 2764 # 2765 itcl::body Rappture::VtkVolumeViewer::InitComponentSettings { cname } { 2765 itcl::body Rappture::VtkVolumeViewer::InitComponentSettings { cname } { 2766 2766 array set _settings [subst { 2767 2767 $cname-color default … … 2788 2788 # volume settings with the settings of the new current component. 2789 2789 # 2790 itcl::body Rappture::VtkVolumeViewer::SwitchComponent { cname } { 2790 itcl::body Rappture::VtkVolumeViewer::SwitchComponent { cname } { 2791 2791 if { ![info exists _settings(${cname}-volumeambient)] } { 2792 2792 InitComponentSettings $cname … … 2813 2813 } 2814 2814 2815 itcl::body Rappture::VtkVolumeViewer::ComputeAlphamap { cname } { 2815 itcl::body Rappture::VtkVolumeViewer::ComputeAlphamap { cname } { 2816 2816 if { ![info exists _transferFunctionEditors($cname)] } { 2817 2817 return [list 0.0 0.0 1.0 1.0] … … 2878 2878 # HideAllMarkers -- 2879 2879 # 2880 # Hide all the markers in all the transfer functions. Can't simply 2881 # delete and recreate markers from the <style> since the user may 2880 # Hide all the markers in all the transfer functions. Can't simply 2881 # delete and recreate markers from the <style> since the user may 2882 2882 # have create, deleted, or moved markers. 2883 2883 # 2884 itcl::body Rappture::VtkVolumeViewer::HideAllMarkers {} { 2884 itcl::body Rappture::VtkVolumeViewer::HideAllMarkers {} { 2885 2885 foreach cname [array names _transferFunctionEditors] { 2886 $_transferFunctionEditors($cname) hideMarkers 2886 $_transferFunctionEditors($cname) hideMarkers 2887 2887 } 2888 2888 } … … 2892 2892 # 2893 2893 # Returns a list of all the datasets (known by the combination of 2894 # their data object and component name) that match the given 2895 # component name. For example, this is used where we want to change 2894 # their data object and component name) that match the given 2895 # component name. For example, this is used where we want to change 2896 2896 # the settings of volumes that have the current component. 2897 2897 # 2898 itcl::body Rappture::VtkVolumeViewer::GetDatasetsWithComponent { cname } { 2898 itcl::body Rappture::VtkVolumeViewer::GetDatasetsWithComponent { cname } { 2899 2899 if { ![info exists _volcomponents($cname)] } { 2900 2900 return "" … … 2913 2913 # label or the combobox in the volume settings tab. 2914 2914 # 2915 itcl::body Rappture::VtkVolumeViewer::BuildVolumeComponents {} { 2915 itcl::body Rappture::VtkVolumeViewer::BuildVolumeComponents {} { 2916 2916 $itk_component(volcomponents) choices delete 0 end 2917 2917 foreach name $_componentsList { … … 2923 2923 if { [llength $_componentsList] <= 1 } { 2924 2924 # Unpack the components label and dropdown if there's only one 2925 # component. 2925 # component. 2926 2926 catch {blt::table forget $parent.volcomponents_l $parent.volcomponents} 2927 2927 } else { 2928 # Pack the components label and dropdown into the table there's 2929 # more than one component to select. 2928 # Pack the components label and dropdown into the table there's 2929 # more than one component to select. 2930 2930 blt::table $parent \ 2931 2931 0,0 $parent.volcomponents_l -anchor e -cspan 2 \ 2932 0,2 $parent.volcomponents -cspan 3 -fill x 2933 } 2934 } 2935 2936 itcl::body Rappture::VtkVolumeViewer::GetColormap { cname color } { 2932 0,2 $parent.volcomponents -cspan 3 -fill x 2933 } 2934 } 2935 2936 itcl::body Rappture::VtkVolumeViewer::GetColormap { cname color } { 2937 2937 if { $color == "default" } { 2938 2938 return $_cname2defaultcolormap($cname)
Note: See TracChangeset
for help on using the changeset viewer.