Changeset 5260 for branches/1.3


Ignore:
Timestamp:
Apr 17, 2015, 8:33:17 PM (9 years ago)
Author:
ldelgass
Message:

Bring nanovis viewer closer in line with trunk/1.4 branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.3/gui/scripts/nanovisviewer.tcl

    r5257 r5260  
    8383    public method updateTransferFunctions {}
    8484
    85     protected method Connect {}
    86     protected method CurrentDatasets {{what -all}}
    87     protected method Disconnect {}
    88     protected method DoResize {}
    89     protected method FixLegend {}
    90     protected method AdjustSetting {what {value ""}}
    91     protected method InitSettings { args }
    92     protected method Pan {option x y}
    93     protected method Rebuild {}
    94     protected method ReceiveData { args }
    95     protected method ReceiveImage { args }
    96     protected method ReceiveLegend { tf vmin vmax size }
    97     protected method Rotate {option x y}
    98     protected method SendTransferFuncs {}
    99     protected method Slice {option args}
    100     protected method SlicerTip {axis}
    101     protected method Zoom {option}
    102 
    10385    # The following methods are only used by this class.
    10486    private method AddIsoMarker { x y }
     87    private method AdjustSetting {what {value ""}}
    10588    private method BuildCameraTab {}
    10689    private method BuildCutplanesTab {}
    10790    private method BuildViewTab {}
    10891    private method BuildVolumeTab {}
    109     private method ResetColormap { color }
    11092    private method ComputeTransferFunc { tf }
     93    private method Connect {}
     94    private method CurrentDatasets {{what -all}}
     95    private method Disconnect {}
     96    private method DoResize {}
    11197    private method EventuallyResize { w h }
    11298    private method EventuallyResizeLegend { }
     99    private method FixLegend {}
     100    private method GetVolumeInfo { w }
     101    private method InitSettings { args }
    113102    private method NameTransferFunc { dataobj comp }
     103    private method Pan {option x y}
    114104    private method PanCamera {}
    115105    private method ParseLevelsOption { tf levels }
    116106    private method ParseMarkersOption { tf markers }
    117     private method volume { tag name }
    118     private method GetVolumeInfo { w }
     107    private method QuaternionToView { q } {
     108        foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break
     109    }
     110    private method Rebuild {}
     111    private method ReceiveData { args }
     112    private method ReceiveImage { args }
     113    private method ReceiveLegend { tf vmin vmax size }
     114    private method ResetColormap { color }
     115    private method Rotate {option x y}
     116    private method SendTransferFuncs {}
    119117    private method SetOrientation { side }
     118    private method Slice {option args}
     119    private method SlicerTip {axis}
     120    private method ToggleVolume { tag name }
     121    private method ViewToQuaternion {} {
     122        return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)]
     123    }
     124    private method Zoom {option}
    120125
    121126    private variable _arcball ""
    122127
    123     private variable _dlist ""     ;# list of data objects
     128    private variable _dlist ""         ;# list of data objects
    124129    private variable _allDataObjs
    125     private variable _obj2ovride   ;# maps dataobj => style override
     130    private variable _obj2ovride       ;# maps dataobj => style override
    126131    private variable _serverDatasets   ;# contains all the dataobj-component
    127                                    ;# to volumes in the server
    128     private variable _serverTfs    ;# contains all the transfer functions
    129                                    ;# in the server.
     132                                       ;# to volumes in the server
     133    private variable _serverTfs        ;# contains all the transfer functions
     134                                       ;# in the server.
    130135    private variable _recvdDatasets    ;# list of data objs to send to server
    131136    private variable _dataset2style    ;# maps dataobj-component to transfunc
     
    133138                                        # dataobj-components using the tf.
    134139
    135     private variable _reset 1      ;# Connection to server has been reset
    136     private variable _click        ;# info used for rotate operations
    137     private variable _limits       ;# autoscale min/max for all axes
    138     private variable _view         ;# view params for 3D view
    139     private variable _isomarkers   ;# array of isosurface level values 0..1
     140    private variable _reset 1          ;# Connection to server has been reset
     141    private variable _click            ;# info used for rotate operations
     142    private variable _limits           ;# autoscale min/max for all axes
     143    private variable _view             ;# view params for 3D view
     144    private variable _isomarkers       ;# array of isosurface level values 0..1
    140145    private variable  _settings
    141146    # Array of transfer functions in server.  If 0 the transfer has been
     
    143148    # and loaded.
    144149    private variable _activeTfs
    145     private variable _first ""     ;# This is the topmost volume.
     150    private variable _first ""         ;# This is the topmost volume.
    146151
    147152    common _downloadPopup          ;# download options from popup
     
    190195    # Initialize the view to some default parameters.
    191196    array set _view {
    192         qw      0.853553
    193         qx      -0.353553
    194         qy      0.353553
    195         qz      0.146447
    196         zoom    1.0
    197         xpan    0
    198         ypan    0
     197        -qw      0.853553
     198        -qx      -0.353553
     199        -qy      0.353553
     200        -qz      0.146447
     201        -xpan    0
     202        -ypan    0
     203        -zoom    1.0
    199204    }
    200205    set _arcball [blt::arcball create 100 100]
    201     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    202     $_arcball quaternion $q
     206    $_arcball quaternion [ViewToQuaternion]
    203207
    204208    set _limits(vmin) 0.0
     
    207211
    208212    array set _settings [subst {
    209         $this-qw                $_view(qw)
    210         $this-qx                $_view(qx)
    211         $this-qy                $_view(qy)
    212         $this-qz                $_view(qz)
    213         $this-zoom              $_view(zoom)
    214         $this-xpan              $_view(xpan)
    215         $this-ypan              $_view(ypan)
     213        $this-qw                $_view(-qw)
     214        $this-qx                $_view(-qx)
     215        $this-qy                $_view(-qy)
     216        $this-qz                $_view(-qz)
     217        $this-zoom              $_view(-zoom)
     218        $this-xpan              $_view(-xpan)
     219        $this-ypan              $_view(-ypan)
    216220        $this-volume            1
    217221        $this-xcutplane         0
     
    243247    }
    244248    pack $itk_component(reset) -side top -padx 2 -pady 2
    245     Rappture::Tooltip::for $itk_component(reset) "Reset the view to the default zoom level"
     249    Rappture::Tooltip::for $itk_component(reset) \
     250        "Reset the view to the default zoom level"
    246251
    247252    itk_component add zoomin {
     
    292297
    293298    # Legend
    294 
    295299    set _image(legend) [image create photo]
    296300    itk_component add legend {
     
    887891        DoResize
    888892    }
     893
    889894    foreach dataobj [get] {
    890895        foreach cname [$dataobj components] {
     
    901906                    if 0 {
    902907                        set f [open "/tmp/volume.vtk" "w"]
    903                         puts $f $data
     908                        fconfigure $f -translation binary -encoding binary
     909                        puts -nonewline $f $data
    904910                        close $f
    905911                    }
     
    931937        # Reset the camera and other view parameters
    932938        #
    933         set _settings($this-qw)    $_view(qw)
    934         set _settings($this-qx)    $_view(qx)
    935         set _settings($this-qy)    $_view(qy)
    936         set _settings($this-qz)    $_view(qz)
    937         set _settings($this-xpan)  $_view(xpan)
    938         set _settings($this-ypan)  $_view(ypan)
    939         set _settings($this-zoom)  $_view(zoom)
    940 
    941         set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     939        set _settings($this-qw)    $_view(-qw)
     940        set _settings($this-qx)    $_view(-qx)
     941        set _settings($this-qy)    $_view(-qy)
     942        set _settings($this-qz)    $_view(-qz)
     943        set _settings($this-xpan)  $_view(-xpan)
     944        set _settings($this-ypan)  $_view(-ypan)
     945        set _settings($this-zoom)  $_view(-zoom)
     946
     947        set q [ViewToQuaternion]
    942948        $_arcball quaternion $q
    943949        SendCmd "camera orient $q"
    944950        SendCmd "camera reset"
    945951        PanCamera
    946         SendCmd "camera zoom $_view(zoom)"
     952        SendCmd "camera zoom $_view(-zoom)"
    947953        InitSettings light2side light transp isosurface grid axes
    948954
     
    10241030    switch -- $option {
    10251031        "in" {
    1026             set _view(zoom) [expr {$_view(zoom)*1.25}]
    1027             set _settings($this-zoom) $_view(zoom)
    1028             SendCmd "camera zoom $_view(zoom)"
     1032            set _view(-zoom) [expr {$_view(-zoom)*1.25}]
     1033            set _settings($this-zoom) $_view(-zoom)
     1034            SendCmd "camera zoom $_view(-zoom)"
    10291035        }
    10301036        "out" {
    1031             set _view(zoom) [expr {$_view(zoom)*0.8}]
    1032             set _settings($this-zoom) $_view(zoom)
    1033             SendCmd "camera zoom $_view(zoom)"
     1037            set _view(-zoom) [expr {$_view(-zoom)*0.8}]
     1038            set _settings($this-zoom) $_view(-zoom)
     1039            SendCmd "camera zoom $_view(-zoom)"
    10341040        }
    10351041        "reset" {
    10361042            array set _view {
    1037                 qw      0.853553
    1038                 qx      -0.353553
    1039                 qy      0.353553
    1040                 qz      0.146447
    1041                 zoom    1.0
    1042                 xpan   0
    1043                 ypan   0
     1043                -qw      0.853553
     1044                -qx      -0.353553
     1045                -qy      0.353553
     1046                -qz      0.146447
     1047                -xpan    0
     1048                -ypan    0
     1049                -zoom    1.0
    10441050            }
    10451051            if { $_first != "" } {
     
    10491055                }
    10501056            }
    1051             set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     1057            set q [ViewToQuaternion]
    10521058            $_arcball quaternion $q
    10531059            SendCmd "camera orient $q"
    10541060            SendCmd "camera reset"
    1055             set _settings($this-qw)    $_view(qw)
    1056             set _settings($this-qx)    $_view(qx)
    1057             set _settings($this-qy)    $_view(qy)
    1058             set _settings($this-qz)    $_view(qz)
    1059             set _settings($this-xpan)  $_view(xpan)
    1060             set _settings($this-ypan)  $_view(ypan)
    1061             set _settings($this-zoom)  $_view(zoom)
     1061            set _settings($this-qw)    $_view(-qw)
     1062            set _settings($this-qx)    $_view(-qx)
     1063            set _settings($this-qy)    $_view(-qy)
     1064            set _settings($this-qz)    $_view(-qz)
     1065            set _settings($this-xpan)  $_view(-xpan)
     1066            set _settings($this-ypan)  $_view(-ypan)
     1067            set _settings($this-zoom)  $_view(-zoom)
    10621068        }
    10631069    }
     
    10651071
    10661072itcl::body Rappture::NanovisViewer::PanCamera {} {
    1067     #set x [expr ($_view(xpan)) / $_limits(xrange)]
    1068     #set y [expr ($_view(ypan)) / $_limits(yrange)]
    1069     set x $_view(xpan)
    1070     set y $_view(ypan)
     1073    set x $_view(-xpan)
     1074    set y $_view(-ypan)
    10711075    SendCmd "camera pan $x $y"
    10721076}
    1073 
    10741077
    10751078# ----------------------------------------------------------------------
     
    11071110
    11081111                set q [$_arcball rotate $x $y $_click(x) $_click(y)]
    1109                 foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break
    1110                 set _settings($this-qw) $_view(qw)
    1111                 set _settings($this-qx) $_view(qx)
    1112                 set _settings($this-qy) $_view(qy)
    1113                 set _settings($this-qz) $_view(qz)
     1112                QuaternionToView $q
     1113                set _settings($this-qw) $_view(-qw)
     1114                set _settings($this-qx) $_view(-qx)
     1115                set _settings($this-qy) $_view(-qy)
     1116                set _settings($this-qz) $_view(-qz)
    11141117                SendCmd "camera orient $q"
    11151118
     
    11441147        set x [expr $x / double($w)]
    11451148        set y [expr $y / double($h)]
    1146         set _view(xpan) [expr $_view(xpan) + $x]
    1147         set _view(ypan) [expr $_view(ypan) + $y]
     1149        set _view(-xpan) [expr $_view(-xpan) + $x]
     1150        set _view(-ypan) [expr $_view(-ypan) + $y]
    11481151        PanCamera
    1149         set _settings($this-xpan) $_view(xpan)
    1150         set _settings($this-ypan) $_view(ypan)
     1152        set _settings($this-xpan) $_view(-xpan)
     1153        set _settings($this-ypan) $_view(-ypan)
    11511154        return
    11521155    }
     
    11611164        set _click(x) $x
    11621165        set _click(y) $y
    1163         set _view(xpan) [expr $_view(xpan) - $dx]
    1164         set _view(ypan) [expr $_view(ypan) - $dy]
     1166        set _view(-xpan) [expr $_view(-xpan) - $dx]
     1167        set _view(-ypan) [expr $_view(-ypan) - $dy]
    11651168        PanCamera
    1166         set _settings($this-xpan) $_view(xpan)
    1167         set _settings($this-ypan) $_view(ypan)
     1169        set _settings($this-xpan) $_view(-xpan)
     1170        set _settings($this-ypan) $_view(-ypan)
    11681171    }
    11691172    if { $option == "release" } {
     
    19131916        0,0 $inner.view_l -anchor e -pady 2 \
    19141917        0,1 $inner.view -anchor w -pady 2
     1918    blt::table configure $inner r0 -resize none
    19151919
    19161920    set row 1
     
    19211925            -textvariable [itcl::scope _settings($this-$tag)]
    19221926        bind $inner.${tag} <Return> \
    1923             [itcl::code $this camera set ${tag}]
     1927            [itcl::code $this camera set -${tag}]
    19241928        bind $inner.${tag} <KP_Enter> \
    1925             [itcl::code $this camera set ${tag}]
     1929            [itcl::code $this camera set -${tag}]
    19261930        blt::table $inner \
    19271931            $row,0 $inner.${tag}label -anchor e -pady 2 \
     
    19311935    }
    19321936
    1933     blt::table configure $inner c* r* -resize none
     1937    blt::table configure $inner c* -resize none
    19341938    blt::table configure $inner c2 -resize expand
    19351939    blt::table configure $inner r$row -resize expand
     
    19721976itcl::body Rappture::NanovisViewer::SlicerTip {axis} {
    19731977    set val [$itk_component(${axis}CutScale) get]
    1974 #    set val [expr {0.01*($val-50)
    1975 #        *($_limits(${axis}max)-$_limits(${axis}min))
    1976 #          + 0.5*($_limits(${axis}max)+$_limits(${axis}min))}]
    19771978    return "Move the [string toupper $axis] cut plane.\nCurrently:  $axis = $val%"
    19781979}
     
    20102011        }
    20112012        "set" {
    2012             set who [lindex $args 0]
    2013             set x $_settings($this-$who)
     2013            set what [lindex $args 0]
     2014            set x $_settings(${this}${what})
    20142015            set code [catch { string is double $x } result]
    20152016            if { $code != 0 || !$result } {
    2016                 set _settings($this-$who) $_view($who)
     2017                set _settings(${this}${what}) $_view($what)
    20172018                return
    20182019            }
    2019             switch -- $who {
    2020                 "xpan" - "ypan" {
    2021                     set _view($who) $_settings($this-$who)
     2020            switch -- $what {
     2021                "-xpan" - "-ypan" {
     2022                    set _view($what) $_settings(${this}${what})
    20222023                    PanCamera
    20232024                }
    2024                 "qx" - "qy" - "qz" - "qw" {
    2025                     set _view($who) $_settings($this-$who)
    2026                     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     2025                "-qx" - "-qy" - "-qz" - "-qw" {
     2026                    set _view($what) $_settings(${this}${what})
     2027                    set q [ViewToQuaternion]
    20272028                    $_arcball quaternion $q
    20282029                    SendCmd "camera orient $q"
    20292030                }
    2030                 "zoom" {
    2031                     set _view($who) $_settings($this-$who)
    2032                     SendCmd "camera zoom $_view(zoom)"
     2031                "-zoom" {
     2032                    set _view($what) $_settings(${this}${what})
     2033                    SendCmd "camera zoom $_view($what)"
    20332034                }
    20342035            }
     
    20762077            -variable [itcl::scope _settings($this-volume-$name)] \
    20772078            -onvalue 0 -offvalue 1 \
    2078             -command [itcl::code $this volume $key $name] \
     2079            -command [itcl::code $this ToggleVolume $key $name] \
    20792080            -font "Arial 9"
    20802081        Rappture::Tooltip::for $inner.vol$row $info(description)
     
    20912092}
    20922093
    2093 itcl::body Rappture::NanovisViewer::volume { tag name } {
     2094itcl::body Rappture::NanovisViewer::ToggleVolume { tag name } {
    20942095    set bool $_settings($this-volume-$name)
    2095     SendCmd "volume statue $bool $name"
     2096    SendCmd "volume state $bool $name"
    20962097}
    20972098
     
    21052106        bottom "0.707107 0.707107 0 0"
    21062107    }
    2107     foreach name { qw qx qy qz } value $positions($side) {
     2108    foreach name { -qw -qx -qy -qz } value $positions($side) {
    21082109        set _view($name) $value
    21092110    }
    2110     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     2111    set q [ViewToQuaternion]
    21112112    $_arcball quaternion $q
    21122113    SendCmd "camera orient $q"
    21132114    SendCmd "camera reset"
    2114     set _view(xpan) 0
    2115     set _view(ypan) 0
    2116     set _view(zoom) 1.0
    2117     set _settings($this-xpan) $_view(xpan)
    2118     set _settings($this-ypan) $_view(ypan)
    2119     set _settings($this-zoom) $_view(zoom)
    2120 }
    2121 
     2115    set _view(-xpan) 0
     2116    set _view(-ypan) 0
     2117    set _view(-zoom) 1.0
     2118    set _settings($this-xpan) $_view(-xpan)
     2119    set _settings($this-ypan) $_view(-ypan)
     2120    set _settings($this-zoom) $_view(-zoom)
     2121}
     2122
Note: See TracChangeset for help on using the changeset viewer.