Changeset 4752 for tags


Ignore:
Timestamp:
Nov 19, 2014 2:39:21 AM (10 years ago)
Author:
ldelgass
Message:

backport vtkisosurface viewer from 1.3 branch head

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tags/1.3.5/gui/scripts/vtkisosurfaceviewer.tcl

    r4351 r4752  
    5757    public method get {args}
    5858    public method isconnected {}
    59     public method limits { colormap }
    6059    public method parameters {title args} {
    6160        # do nothing
     
    6362    public method scale {args}
    6463
    65     protected method Connect {}
    66     protected method CurrentDatasets {args}
    67     protected method Disconnect {}
    68     protected method DoResize {}
    69     protected method DoRotate {}
    70     protected method AdjustSetting {what {value ""}}
    71     protected method InitSettings { args  }
    72     protected method Pan {option x y}
    73     protected method Pick {x y}
    74     protected method Rebuild {}
    75     protected method ReceiveDataset { args }
    76     protected method ReceiveImage { args }
    77     protected method ReceiveLegend { colormap title vmin vmax size }
    78     protected method Rotate {option x y}
    79     protected method Zoom {option}
    80 
    8164    # The following methods are only used by this class.
     65
     66    private method AdjustSetting {what {value ""}}
    8267    private method BuildAxisTab {}
    8368    private method BuildCameraTab {}
     
    8772    private method BuildIsosurfaceTab {}
    8873    private method Combo { option }
     74    private method Connect {}
     75    private method CurrentDatasets {args}
     76    private method Disconnect {}
     77    private method DoChangeContourLevels {}
     78    private method DoResize {}
     79    private method DoRotate {}
    8980    private method DrawLegend {}
    9081    private method EnterLegend { x y }
     82    private method EventuallyChangeContourLevels {}
     83    private method EventuallyRequestLegend {}
    9184    private method EventuallyResize { w h }
    9285    private method EventuallyRotate { q }
    93     private method EventuallyRequestLegend {}
    9486    private method EventuallySetCutplane { axis args }
     87    private method GenerateContourList {}
    9588    private method GetImage { args }
    9689    private method GetVtkData { args }
     90    private method InitSettings { args  }
    9791    private method IsValidObject { dataobj }
    9892    private method LeaveLegend {}
    9993    private method MotionLegend { x y }
     94    private method Pan {option x y}
    10095    private method PanCamera {}
     96    private method Pick {x y}
     97    private method Rebuild {}
     98    private method ReceiveDataset { args }
     99    private method ReceiveImage { args }
     100    private method ReceiveLegend { colormap title vmin vmax size }
    101101    private method RequestLegend {}
     102    private method Rotate {option x y}
     103    private method SetCurrentColormap { color }
     104    private method SetCurrentFieldName { dataobj }
    102105    private method SetLegendTip { x y }
    103     private method SetObjectStyle { dataobj comp }
    104     private method Slice {option args}
    105     private method SetCurrentColormap { color }
     106    private method SetObjectStyle { dataobj comp }
    106107    private method SetOrientation { side }
    107     private method UpdateContourList {}
     108    private method Slice {option args}
     109    private method Zoom {option}
     110    private method ViewToQuaternion {} {
     111        return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)]
     112    }
    108113
    109114    private variable _arcball ""
     
    120125    private variable _currentColormap ""
    121126    private variable _currentNumContours -1
    122     private variable _currentOpacity ""
    123127
    124128    private variable _dataset2style    ;# maps dataobj-component to transfunc
     
    138142    private variable _title ""
    139143    private variable _isolines
    140     private variable _contourList ""
     144    private variable _contourList
     145    private variable _currentLimits ""
     146    private variable _widget
    141147
    142148    common _downloadPopup;              # download options from popup
     
    184190    $_dispatcher dispatch $this !legend "[itcl::code $this RequestLegend]; list"
    185191
     192    # Contour levels event
     193    $_dispatcher register !contours
     194    $_dispatcher dispatch $this !contours \
     195        "[itcl::code $this DoChangeContourLevels]; list"
     196
    186197    # X-Cutplane event
    187198    $_dispatcher register !xcutplane
     
    208219    # Initialize the view to some default parameters.
    209220    array set _view {
    210         qw              0.853553
    211         qx              -0.353553
    212         qy              0.353553
    213         qz              0.146447
    214         zoom            1.0
    215         xpan            0
    216         ypan            0
    217         ortho           0
     221        -ortho           0
     222        -qw              0.853553
     223        -qx              -0.353553
     224        -qy              0.353553
     225        -qz              0.146447
     226        -xpan            0
     227        -ypan            0
     228        -zoom            1.0
    218229    }
    219230    set _arcball [blt::arcball create 100 100]
    220     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    221     $_arcball quaternion $q
    222 
     231    $_arcball quaternion [ViewToQuaternion]
     232
     233    array set _contourList {
     234        numLevels       10
     235        reqValues       ""
     236        updatePending   0
     237        values          ""
     238    }
    223239    array set _settings {
    224240        -axesvisible                    1
    225         -axislabelsvisible              1
    226         -background                     black
    227         -colormap                       BCGYR
    228         -colormapvisible                1
     241        -axislabels                     1
     242        -axisminorticks                 1
     243        -axismode                       "static"
     244        -background                     black
     245        -colormap                       BCGYR
     246        -colormapvisible                1
    229247        -cutplaneedges                  0
    230248        -cutplanelighting               1
    231         -cutplaneopacity                100
     249        -cutplaneopacity                1.0
    232250        -cutplanepreinterp              1
    233251        -cutplanesvisible               0
    234252        -cutplanewireframe              0
    235         -field                          "Default"
    236         -isolinecolor                   white
     253        -field                          "Default"
     254        -isolinecolor                   white
    237255        -isosurfaceedges                0
    238256        -isosurfacelighting             1
    239         -isosurfaceopacity              60
    240         -isosurfaceoutline              0
     257        -isosurfaceopacity              0.6
    241258        -isosurfacevisible              1
    242259        -isosurfacewireframe            0
    243260        -legendvisible                  1
    244261        -numcontours                    10
    245         -xaxisgrid                      0
     262        -outline                        0
    246263        -xcutplaneposition              50
    247264        -xcutplanevisible               1
    248         -yaxisgrid                      0
     265        -xgrid                          0
    249266        -ycutplaneposition              50
    250267        -ycutplanevisible               1
    251         -zaxisgrid                      0
     268        -ygrid                          0
    252269        -zcutplaneposition              50
    253270        -zcutplanevisible               1
     271        -zgrid                          0
    254272    }
    255273    array set _changed {
     274        -colormap                0
    256275        -isosurfaceopacity       0
    257         -colormap                0
     276        -cutplaneopacity         0
    258277        -numcontours             0
     278    }
     279    array set _widget {
     280        -isosurfaceopacity       60
     281        -cutplaneopacity         100
    259282    }
    260283
     
    341364    $itk_component(contour) select
    342365    Rappture::Tooltip::for $itk_component(contour) \
    343         "Don't display the isosurface"
     366        "Hide the isosurface"
    344367    pack $itk_component(contour) -padx 2 -pady 2
    345368
     
    352375    }
    353376    Rappture::Tooltip::for $itk_component(cutplane) \
    354         "Show/Hide cutplanes"
     377        "Show the cutplanes"
    355378    pack $itk_component(cutplane) -padx 2 -pady 2
    356379
     
    441464    EnableWaitDialog 500
    442465    Connect
    443     update
    444466}
    445467
     
    468490}
    469491
     492itcl::body Rappture::VtkIsosurfaceViewer::DoChangeContourLevels {} {
     493    GenerateContourList
     494    SendCmd [list contour3d contourlist $_contourList(values)]
     495    SendCmd [list camera reset]
     496    DrawLegend
     497    set _contourList(updatePending) 0
     498}
     499
    470500itcl::body Rappture::VtkIsosurfaceViewer::DoRotate {} {
    471     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    472     SendCmd "camera orient $q"
     501    SendCmd "camera orient [ViewToQuaternion]"
    473502    set _rotatePending 0
    474503}
     
    494523
    495524itcl::body Rappture::VtkIsosurfaceViewer::EventuallyRotate { q } {
    496     foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break
     525    foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break
    497526    if { !$_rotatePending } {
    498527        set _rotatePending 1
     
    506535        set _cutplanePending 1
    507536        $_dispatcher event -after 100 !${axis}cutplane
     537    }
     538}
     539
     540itcl::body Rappture::VtkIsosurfaceViewer::EventuallyChangeContourLevels {} {
     541    set n $_contourList(numLevels)
     542    set _contourList(values) ""
     543    if { !$_contourList(updatePending) } {
     544        set _contourList(updatePending) 1
     545        global rotate_delay
     546        $_dispatcher event -after $rotate_delay !contours
    508547    }
    509548}
     
    784823                set session $env(SESSION)
    785824            }
     825            lappend info "version" "$Rappture::version"
     826            lappend info "build" "$Rappture::build"
     827            lappend info "installdir" "$Rappture::installdir"
    786828            lappend info "hub" [exec hostname]
    787829            lappend info "client" "vtkisosurfaceviewer"
     
    833875    # disconnected -- no more data sitting on server
    834876    set _outbuf ""
    835     array unset _datasets
    836     array unset _data
    837     array unset _colormaps
    838     array unset _seeds
    839     array unset _dataset2style
    840     array unset _obj2datasets
     877    array unset _datasets
     878    array unset _data
     879    array unset _colormaps
     880    array unset _dataset2style
     881    array unset _obj2datasets
    841882}
    842883
     
    940981    # generates a new call to Rebuild).   
    941982    StartBufferingCommands
    942 
    943983    if { $_reset } {
    944984        set _width $w
     
    946986        $_arcball resize $w $h
    947987        DoResize
    948         #
     988
    949989        # Reset the camera and other view parameters
    950         #
    951         set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    952         $_arcball quaternion $q
    953         if {$_view(ortho)} {
    954             SendCmd "camera mode ortho"
    955         } else {
    956             SendCmd "camera mode persp"
    957         }
     990        $_arcball quaternion [ViewToQuaternion]
     991        InitSettings -ortho
    958992        DoRotate
    959993        PanCamera
    960994        set _first ""
    961         InitSettings -xaxisgrid -yaxisgrid -zaxisgrid -axismode \
    962             -axesvisible -axislabelsvisible
    963         foreach axis { x y z } {
    964             SendCmd "axis lformat $axis %g"
    965         }
     995        InitSettings -background \
     996            -xgrid -ygrid -zgrid -axismode \
     997            -axesvisible -axislabels -axisminorticks
     998        #SendCmd "axis lformat all %g"
    966999        StopBufferingCommands
    9671000        SendCmd "imgflush"
     
    9691002    }
    9701003    set _first ""
    971     SendCmd "contour3d visible 0"
     1004    SendCmd "dataset visible 0"
     1005    eval scale $_dlist
    9721006    foreach dataobj [get -objects] {
    9731007        if { [info exists _obj2ovride($dataobj-raise)] &&  $_first == "" } {
    9741008            set _first $dataobj
     1009            SetCurrentFieldName $dataobj
    9751010        }
    9761011        set _obj2datasets($dataobj) ""
     
    9871022                if { $_reportClientInfo }  {
    9881023                    set info {}
    989                     lappend info "tool_id"       [$dataobj hints toolId]
    990                     lappend info "tool_name"     [$dataobj hints toolName]
    991                     lappend info "tool_version"  [$dataobj hints toolRevision]
    992                     lappend info "tool_title"    [$dataobj hints toolTitle]
     1024                    lappend info "tool_id"       [$dataobj hints toolid]
     1025                    lappend info "tool_name"     [$dataobj hints toolname]
     1026                    lappend info "tool_title"    [$dataobj hints tooltitle]
     1027                    lappend info "tool_command"  [$dataobj hints toolcommand]
     1028                    lappend info "tool_revision" [$dataobj hints toolrevision]
    9931029                    lappend info "dataset_label" [$dataobj hints label]
    9941030                    lappend info "dataset_size"  $length
     
    9961032                    SendCmd "clientinfo [list $info]"
    9971033                }
    998                 append _outbuf "dataset add $tag data follows $length\n"
     1034                SendCmd "dataset add $tag data follows $length"
    9991035                append _outbuf $bytes
    10001036                set _datasets($tag) 1
     
    10031039            lappend _obj2datasets($dataobj) $tag
    10041040            if { [info exists _obj2ovride($dataobj-raise)] } {
    1005                 # Setting dataset visible enables outline
    1006                 # and contour3d
    10071041                SendCmd "contour3d visible 1 $tag"
    10081042            }
     
    10101044    }
    10111045
    1012     if { $_first != "" } {
    1013         $itk_component(field) choices delete 0 end
    1014         $itk_component(fieldmenu) delete 0 end
    1015         array unset _fields
    1016         set _curFldName ""
    1017         foreach cname [$_first components] {
    1018             foreach fname [$_first fieldnames $cname] {
    1019                 if { [info exists _fields($fname)] } {
    1020                     continue
    1021                 }
    1022                 foreach { label units components } \
    1023                     [$_first fieldinfo $fname] break
    1024                 $itk_component(field) choices insert end "$fname" "$label"
    1025                 $itk_component(fieldmenu) add radiobutton -label "$label" \
    1026                     -value $label -variable [itcl::scope _curFldLabel] \
    1027                     -selectcolor red \
    1028                     -activebackground $itk_option(-plotbackground) \
    1029                     -activeforeground $itk_option(-plotforeground) \
    1030                     -font "Arial 8" \
    1031                     -command [itcl::code $this Combo invoke]
    1032                 set _fields($fname) [list $label $units $components]
    1033                 if { $_curFldName == "" } {
    1034                     set _curFldName $fname
    1035                     set _curFldLabel $label
    1036                 }
    1037             }
    1038         }
    1039         $itk_component(field) value $_curFldLabel
    1040     }
    1041     InitSettings -cutplanesvisible -isosurfacevisible -isosurfaceoutline
     1046    InitSettings -cutplanesvisible -isosurfacevisible -outline
    10421047    if { $_reset } {
    10431048        # These are settings that rely on a dataset being loaded.
     
    10621067                set label [string toupper $axis]
    10631068            }
    1064             # May be a space in the axis label.
    10651069            SendCmd [list axis name $axis $label]
    10661070        }
    10671071        if { [array size _fields] < 2 } {
    1068             blt::table forget $itk_component(field) $itk_component(field_l)
     1072            catch {blt::table forget $itk_component(field) $itk_component(field_l)}
    10691073        }
    10701074        set _reset 0
    10711075    }
     1076    # Redraw the legend even if we're using the same colormap. The position
     1077    # of the isolines may have changed because the range of data changed.
     1078    DrawLegend
    10721079
    10731080    # Actually write the commands to the server socket.  If it fails, we don't
     
    11341141    switch -- $option {
    11351142        "in" {
    1136             set _view(zoom) [expr {$_view(zoom)*1.25}]
    1137             SendCmd "camera zoom $_view(zoom)"
     1143            set _view(-zoom) [expr {$_view(-zoom)*1.25}]
     1144            SendCmd "camera zoom $_view(-zoom)"
    11381145        }
    11391146        "out" {
    1140             set _view(zoom) [expr {$_view(zoom)*0.8}]
    1141             SendCmd "camera zoom $_view(zoom)"
     1147            set _view(-zoom) [expr {$_view(-zoom)*0.8}]
     1148            SendCmd "camera zoom $_view(-zoom)"
    11421149        }
    11431150        "reset" {
    11441151            array set _view {
    1145                 qw     0.853553
    1146                 qx     -0.353553
    1147                 qy     0.353553
    1148                 qz     0.146447
    1149                 zoom   1.0
    1150                 xpan   0
    1151                 ypan   0
     1152                -qw     0.853553
     1153                -qx     -0.353553
     1154                -qy     0.353553
     1155                -qz     0.146447
     1156                -xpan   0
     1157                -ypan   0
     1158                -zoom   1.0
    11521159            }
    11531160            if { $_first != "" } {
     
    11571164                }
    11581165            }
    1159             set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    1160             $_arcball quaternion $q
     1166            $_arcball quaternion [ViewToQuaternion]
    11611167            DoRotate
    11621168            SendCmd "camera reset"
     
    11661172
    11671173itcl::body Rappture::VtkIsosurfaceViewer::PanCamera {} {
    1168     set x $_view(xpan)
    1169     set y $_view(ypan)
     1174    set x $_view(-xpan)
     1175    set y $_view(-ypan)
    11701176    SendCmd "camera pan $x $y"
    11711177}
     
    12451251            set x [expr $x / double($w)]
    12461252            set y [expr $y / double($h)]
    1247             set _view(xpan) [expr $_view(xpan) + $x]
    1248             set _view(ypan) [expr $_view(ypan) + $y]
     1253            set _view(-xpan) [expr $_view(-xpan) + $x]
     1254            set _view(-ypan) [expr $_view(-ypan) + $y]
    12491255            PanCamera
    12501256            return
     
    12681274            set _click(x) $x
    12691275            set _click(y) $y
    1270             set _view(xpan) [expr $_view(xpan) - $dx]
    1271             set _view(ypan) [expr $_view(ypan) - $dy]
     1276            set _view(-xpan) [expr $_view(-xpan) - $dx]
     1277            set _view(-ypan) [expr $_view(-ypan) - $dy]
    12721278            PanCamera
    12731279        }
     
    13111317    }
    13121318    switch -- $what {
     1319        "-axesvisible" {
     1320            set bool $_settings($what)
     1321            SendCmd "axis visible all $bool"
     1322        }
     1323        "-axislabels" {
     1324            set bool $_settings($what)
     1325            SendCmd "axis labels all $bool"
     1326        }
     1327        "-axisminorticks" {
     1328            set bool $_settings($what)
     1329            SendCmd "axis minticks all $bool"
     1330        }
     1331        "-axismode" {
     1332            set mode [$itk_component(axisMode) value]
     1333            set mode [$itk_component(axisMode) translate $mode]
     1334            set _settings($what) $mode
     1335            SendCmd "axis flymode $mode"
     1336        }
    13131337        "-background" {
    13141338            set bgcolor [$itk_component(background) value]
     
    13231347            DrawLegend
    13241348        }
    1325         "-axesvisible" {
    1326             set bool $_settings(-axesvisible)
    1327             SendCmd "axis visible all $bool"
    1328         }
    1329         "-axislabelsvisible" {
    1330             set bool $_settings(-axislabelsvisible)
    1331             SendCmd "axis labels all $bool"
    1332         }
    1333         "-xaxisgrid" - "-yaxisgrid" - "-zaxisgrid" {
    1334             set axis [string tolower [string range $what 1 1]]
    1335             set bool $_settings($what)
    1336             SendCmd "axis grid $axis $bool"
    1337         }
    1338         "-axismode" {
    1339             set mode [$itk_component(axisMode) value]
    1340             set mode [$itk_component(axisMode) translate $mode]
    1341             set _settings($what) $mode
    1342             SendCmd "axis flymode $mode"
    1343         }
    13441349        "-cutplaneedges" {
    13451350            set bool $_settings($what)
    13461351            SendCmd "cutplane edges $bool"
    13471352        }
     1353        "-cutplanelighting" {
     1354            set bool $_settings($what)
     1355            SendCmd "cutplane lighting $bool"
     1356        }
     1357        "-cutplaneopacity" {
     1358            set _settings($what) [expr $_widget($what) * 0.01]
     1359            SendCmd "cutplane opacity $_settings($what)"
     1360        }
     1361        "-cutplanepreinterp" {
     1362            set bool $_settings($what)
     1363            SendCmd "cutplane preinterp $bool"
     1364        }
    13481365        "-cutplanesvisible" {
    13491366            set bool $_settings($what)
    1350             SendCmd "cutplane visible $bool"
     1367            SendCmd "cutplane visible 0"
     1368            if { $bool } {
     1369                foreach tag [CurrentDatasets -visible] {
     1370                    SendCmd "cutplane visible $bool $tag"
     1371                }
     1372            }
     1373            if { $bool } {
     1374                Rappture::Tooltip::for $itk_component(cutplane) \
     1375                    "Hide the cutplanes"
     1376            } else {
     1377                Rappture::Tooltip::for $itk_component(cutplane) \
     1378                    "Show the cutplanes"
     1379            }
    13511380        }
    13521381        "-cutplanewireframe" {
     
    13541383            SendCmd "cutplane wireframe $bool"
    13551384        }
    1356         "-cutplanelighting" {
    1357             set bool $_settings($what)
    1358             SendCmd "cutplane lighting $bool"
    1359         }
    1360         "-cutplaneopacity" {
    1361             set val $_settings($what)
    1362             set sval [expr { 0.01 * double($val) }]
    1363             SendCmd "cutplane opacity $sval"
    1364         }
    1365         "-cutplanepreinterp" {
    1366             set bool $_settings($what)
    1367             SendCmd "cutplane preinterp $bool"
    1368         }
    1369         "-xcutplanevisible" - "-ycutplanevisible" - "-zcutplanevisible" {
    1370             set axis [string tolower [string range $what 1 1]]
    1371             set bool $_settings($what)
    1372             if { $bool } {
    1373                 $itk_component(${axis}position) configure -state normal \
    1374                     -troughcolor white
    1375             } else {
    1376                 $itk_component(${axis}position) configure -state disabled \
    1377                     -troughcolor grey82
    1378             }
    1379             SendCmd "cutplane axis $axis $bool"
    1380         }
    1381         "-xcutplaneposition" - "-ycutplaneposition" - "-zcutplaneposition" {
    1382             set axis [string tolower [string range $what 1 1]]
    1383             set pos [expr $_settings($what) * 0.01]
    1384             SendCmd "cutplane slice ${axis} ${pos}"
    1385             set _cutplanePending 0
    1386         }
    13871385        "-colormap" {
    1388             set _changed(-colormap) 1
     1386            set _changed($what) 1
    13891387            StartBufferingCommands
    13901388            set color [$itk_component(colormap) value]
    1391             set _settings(-colormap) $color
     1389            set _settings($what) $color
    13921390            if { $color == "none" } {
    13931391                if { $_settings(-colormapvisible) } {
     
    14051403            EventuallyRequestLegend
    14061404        }
    1407         "-numcontours" {
    1408             set _settings($what) [$itk_component(numcontours) value]
    1409             set _currentNumContours $_settings($what)
    1410             UpdateContourList
    1411             set _changed($what) 1
    1412             SendCmd "contour3d contourlist [list $_contourList]"
    1413             DrawLegend
    1414         }
    1415         "-isosurfacewireframe" {
    1416             set bool $_settings($what)
    1417             SendCmd "contour3d wireframe $bool"
    1418         }
    1419         "-isosurfacevisible" {
    1420             set bool $_settings($what)
    1421             SendCmd "contour3d visible 0"
    1422             if { $bool } {
    1423                 foreach tag [CurrentDatasets -visible] {
    1424                     SendCmd "contour3d visible $bool $tag"
    1425                 }
    1426             }
    1427             if { $bool } {
    1428                 Rappture::Tooltip::for $itk_component(contour) \
    1429                     "Hide the isosurface"
    1430             } else {
    1431                 Rappture::Tooltip::for $itk_component(contour) \
    1432                     "Show the isosurface"
    1433             }
    1434             DrawLegend
    1435         }
    1436         "-isosurfacelighting" {
    1437             set bool $_settings($what)
    1438             SendCmd "contour3d lighting $bool"
    1439         }
    1440         "-isosurfaceedges" {
    1441             set bool $_settings($what)
    1442             SendCmd "contour3d edges $bool"
    1443         }
    1444         "-isosurfaceoutline" {
    1445             set bool $_settings($what)
    1446             SendCmd "outline visible $bool"
    1447         }
    1448         "-isolinecolor" {
    1449             set color [$itk_component(isolineColor) value]
    1450             set _settings($what) $color
    1451             DrawLegend
    1452         }
    1453         "-isosurfaceopacity" {
    1454             set val $_settings($what)
    1455             set sval [expr { 0.01 * double($val) }]
    1456             SendCmd "contour3d opacity $sval"
    1457         }
    14581405        "-field" {
    14591406            set label [$itk_component(field) value]
     
    14821429            SendCmd "contour3d colormode $_colorMode $_curFldName"
    14831430            SendCmd "camera reset"
    1484             UpdateContourList
     1431            GenerateContourList
    14851432            DrawLegend
     1433        }
     1434        "-isolinecolor" {
     1435            set color [$itk_component(isolineColor) value]
     1436            set _settings($what) $color
     1437            DrawLegend
     1438        }
     1439        "-isosurfaceedges" {
     1440            set bool $_settings($what)
     1441            SendCmd "contour3d edges $bool"
     1442        }
     1443        "-isosurfacelighting" {
     1444            set bool $_settings($what)
     1445            SendCmd "contour3d lighting $bool"
     1446        }
     1447        "-isosurfaceopacity" {
     1448            set _settings($what) [expr $_widget($what) * 0.01]
     1449            SendCmd "contour3d opacity $_settings($what)"
     1450        }
     1451        "-isosurfacevisible" {
     1452            set bool $_settings($what)
     1453            SendCmd "contour3d visible 0"
     1454            if { $bool } {
     1455                foreach tag [CurrentDatasets -visible] {
     1456                    SendCmd "contour3d visible $bool $tag"
     1457                }
     1458            }
     1459            if { $bool } {
     1460                Rappture::Tooltip::for $itk_component(contour) \
     1461                    "Hide the isosurface"
     1462            } else {
     1463                Rappture::Tooltip::for $itk_component(contour) \
     1464                    "Show the isosurface"
     1465            }
     1466        }
     1467        "-isosurfacewireframe" {
     1468            set bool $_settings($what)
     1469            SendCmd "contour3d wireframe $bool"
    14861470        }
    14871471        "-legendvisible" {
     
    14901474            }
    14911475            DrawLegend
     1476        }
     1477        "-numcontours" {
     1478            set _settings($what) [$itk_component(numcontours) value]
     1479            if { $_contourList(numLevels) != $_settings($what) } {
     1480                set _contourList(numLevels) $_settings($what)
     1481                EventuallyChangeContourLevels
     1482            }
     1483        }
     1484        "-ortho" {
     1485            set bool $_view($what)
     1486            if { $bool } {
     1487                SendCmd "camera mode ortho"
     1488            } else {
     1489                SendCmd "camera mode persp"
     1490            }
     1491        }
     1492        "-outline" {
     1493            set bool $_settings($what)
     1494            SendCmd "outline visible 0"
     1495            if { $bool } {
     1496                foreach tag [CurrentDatasets -visible] {
     1497                    SendCmd "outline visible $bool $tag"
     1498                }
     1499            }
     1500        }
     1501        "-xcutplanevisible" - "-ycutplanevisible" - "-zcutplanevisible" {
     1502            set axis [string tolower [string range $what 1 1]]
     1503            set bool $_settings($what)
     1504            if { $bool } {
     1505                $itk_component(${axis}position) configure -state normal \
     1506                    -troughcolor white
     1507            } else {
     1508                $itk_component(${axis}position) configure -state disabled \
     1509                    -troughcolor grey82
     1510            }
     1511            SendCmd "cutplane axis $axis $bool"
     1512        }
     1513        "-xcutplaneposition" - "-ycutplaneposition" - "-zcutplaneposition" {
     1514            set axis [string tolower [string range $what 1 1]]
     1515            set pos [expr $_settings($what) * 0.01]
     1516            SendCmd "cutplane slice ${axis} ${pos}"
     1517            set _cutplanePending 0
     1518        }
     1519        "-xgrid" - "-ygrid" - "-zgrid" {
     1520            set axis [string tolower [string range $what 1 1]]
     1521            set bool $_settings($what)
     1522            SendCmd "axis grid $axis $bool"
    14921523        }
    14931524        default {
     
    15691600}
    15701601
    1571 itcl::body Rappture::VtkIsosurfaceViewer::limits { dataobj } {
    1572     foreach { limits(xmin) limits(xmax) } [$dataobj limits x] break
    1573     foreach { limits(ymin) limits(ymax) } [$dataobj limits y] break
    1574     foreach { limits(zmin) limits(zmax) } [$dataobj limits z] break
    1575     foreach { limits(vmin) limits(vmax) } [$dataobj limits v] break
    1576     return [array get limits]
    1577 }
    1578 
    15791602itcl::body Rappture::VtkIsosurfaceViewer::BuildIsosurfaceTab {} {
    15801603
     
    16131636    checkbutton $inner.outline \
    16141637        -text "Outline" \
    1615         -variable [itcl::scope _settings(-isosurfaceoutline)] \
    1616         -command [itcl::code $this AdjustSetting -isosurfaceoutline] \
     1638        -variable [itcl::scope _settings(-outline)] \
     1639        -command [itcl::code $this AdjustSetting -outline] \
    16171640        -font "Arial 9"
    16181641
     
    16581681    label $inner.opacity_l -text "Opacity" -font "Arial 9"
    16591682    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
    1660         -variable [itcl::scope _settings(-isosurfaceopacity)] \
     1683        -variable [itcl::scope _widget(-isosurfaceopacity)] \
    16611684        -width 10 \
    16621685        -showvalue off \
    16631686        -command [itcl::code $this AdjustSetting -isosurfaceopacity]
    1664 
    1665     label $inner.scale_l -text "Scale" -font "Arial 9"
    1666     ::scale $inner.scale -from 1 -to 100 -orient horizontal \
    1667         -variable [itcl::scope _settings(-contourscale)] \
    1668         -width 10 \
    1669         -showvalue off \
    1670         -command [itcl::code $this AdjustSetting -contourscale]
     1687    $inner.opacity set [expr $_settings(-isosurfaceopacity) * 100.0]
    16711688
    16721689    itk_component add field_l {
     
    16851702        Rappture::Combobox $inner.colormap -width 10 -editable 0
    16861703    }
    1687     $inner.colormap choices insert end \
    1688         "BCGYR"              "BCGYR"            \
    1689         "BGYOR"              "BGYOR"            \
    1690         "blue"               "blue"             \
    1691         "blue-to-brown"      "blue-to-brown"    \
    1692         "blue-to-orange"     "blue-to-orange"   \
    1693         "blue-to-grey"       "blue-to-grey"     \
    1694         "green-to-magenta"   "green-to-magenta" \
    1695         "greyscale"          "greyscale"        \
    1696         "nanohub"            "nanohub"          \
    1697         "rainbow"            "rainbow"          \
    1698         "spectral"           "spectral"         \
    1699         "ROYGB"              "ROYGB"            \
    1700         "RYGCB"              "RYGCB"            \
    1701         "brown-to-blue"      "brown-to-blue"    \
    1702         "grey-to-blue"       "grey-to-blue"     \
    1703         "orange-to-blue"     "orange-to-blue"   
     1704    $inner.colormap choices insert end [GetColormapList]
    17041705
    17051706    $itk_component(colormap) value "BCGYR"
     
    17501751
    17511752    checkbutton $inner.visible \
    1752         -text "Show Axes" \
     1753        -text "Axes" \
    17531754        -variable [itcl::scope _settings(-axesvisible)] \
    17541755        -command [itcl::code $this AdjustSetting -axesvisible] \
     
    17561757
    17571758    checkbutton $inner.labels \
    1758         -text "Show Axis Labels" \
    1759         -variable [itcl::scope _settings(-axislabelsvisible)] \
    1760         -command [itcl::code $this AdjustSetting -axislabelsvisible] \
     1759        -text "Axis Labels" \
     1760        -variable [itcl::scope _settings(-axislabels)] \
     1761        -command [itcl::code $this AdjustSetting -axislabels] \
    17611762        -font "Arial 9"
    1762 
    1763     checkbutton $inner.gridx \
    1764         -text "Show X Grid" \
    1765         -variable [itcl::scope _settings(-xaxisgrid)] \
    1766         -command [itcl::code $this AdjustSetting -xaxisgrid] \
     1763    label $inner.grid_l -text "Grid" -font "Arial 9"
     1764    checkbutton $inner.xgrid \
     1765        -text "X" \
     1766        -variable [itcl::scope _settings(-xgrid)] \
     1767        -command [itcl::code $this AdjustSetting -xgrid] \
    17671768        -font "Arial 9"
    1768     checkbutton $inner.gridy \
    1769         -text "Show Y Grid" \
    1770         -variable [itcl::scope _settings(-yaxisgrid)] \
    1771         -command [itcl::code $this AdjustSetting -yaxisgrid] \
     1769    checkbutton $inner.ygrid \
     1770        -text "Y" \
     1771        -variable [itcl::scope _settings(-ygrid)] \
     1772        -command [itcl::code $this AdjustSetting -ygrid] \
    17721773        -font "Arial 9"
    1773     checkbutton $inner.gridz \
    1774         -text "Show Z Grid" \
    1775         -variable [itcl::scope _settings(-zaxisgrid)] \
    1776         -command [itcl::code $this AdjustSetting -zaxisgrid] \
     1774    checkbutton $inner.zgrid \
     1775        -text "Z" \
     1776        -variable [itcl::scope _settings(-zgrid)] \
     1777        -command [itcl::code $this AdjustSetting -zgrid] \
     1778        -font "Arial 9"
     1779    checkbutton $inner.minorticks \
     1780        -text "Minor Ticks" \
     1781        -variable [itcl::scope _settings(-axisminorticks)] \
     1782        -command [itcl::code $this AdjustSetting -axisminorticks] \
    17771783        -font "Arial 9"
    17781784
     
    17871793        "furthest_triad"  "farthest" \
    17881794        "outer_edges"     "outer"         
    1789     $itk_component(axisMode) value "static"
     1795    $itk_component(axisMode) value $_settings(-axismode)
    17901796    bind $inner.mode <<Value>> [itcl::code $this AdjustSetting -axismode]
    17911797
    17921798    blt::table $inner \
    1793         0,0 $inner.visible -anchor w -cspan 2 \
    1794         1,0 $inner.labels  -anchor w -cspan 2 \
    1795         2,0 $inner.gridx   -anchor w -cspan 2 \
    1796         3,0 $inner.gridy   -anchor w -cspan 2 \
    1797         4,0 $inner.gridz   -anchor w -cspan 2 \
    1798         5,0 $inner.mode_l  -anchor w -cspan 2 -padx { 2 0 } \
    1799         6,0 $inner.mode    -fill x   -cspan 2
     1799        0,0 $inner.visible -anchor w -cspan 4 \
     1800        1,0 $inner.labels  -anchor w -cspan 4 \
     1801        2,0 $inner.minorticks  -anchor w -cspan 4 \
     1802        4,0 $inner.grid_l  -anchor w \
     1803        4,1 $inner.xgrid   -anchor w \
     1804        4,2 $inner.ygrid   -anchor w \
     1805        4,3 $inner.zgrid   -anchor w \
     1806        5,0 $inner.mode_l  -anchor w -padx { 2 0 } \
     1807        5,1 $inner.mode    -fill x   -cspan 3
    18001808
    18011809    blt::table configure $inner r* c* -resize none
    1802     blt::table configure $inner r7 c1 -resize expand
     1810    blt::table configure $inner r7 c6 -resize expand
     1811    blt::table configure $inner r3 -height 0.125i
    18031812}
    18041813
     
    18221831        0,0 $inner.view_l -anchor e -pady 2 \
    18231832        0,1 $inner.view -anchor w -pady 2
     1833    blt::table configure $inner r0 -resize none
    18241834
    18251835    set labels { qx qy qz qw xpan ypan zoom }
     
    18281838        label $inner.${tag}label -text $tag -font "Arial 9"
    18291839        entry $inner.${tag} -font "Arial 9"  -bg white \
    1830             -textvariable [itcl::scope _view($tag)]
     1840            -textvariable [itcl::scope _view(-$tag)]
    18311841        bind $inner.${tag} <KeyPress-Return> \
    18321842            [itcl::code $this camera set ${tag}]
     
    18391849    checkbutton $inner.ortho \
    18401850        -text "Orthographic Projection" \
    1841         -variable [itcl::scope _view(ortho)] \
    1842         -command [itcl::code $this camera set ortho] \
     1851        -variable [itcl::scope _view(-ortho)] \
     1852        -command [itcl::code $this AdjustSetting -ortho] \
    18431853        -font "Arial 9"
    18441854    blt::table $inner \
     
    18471857    incr row
    18481858
    1849     blt::table configure $inner c* r* -resize none
     1859    blt::table configure $inner c* -resize none
    18501860    blt::table configure $inner c2 -resize expand
    18511861    blt::table configure $inner r$row -resize expand
     
    18941904    label $inner.opacity_l -text "Opacity" -font "Arial 9"
    18951905    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
    1896         -variable [itcl::scope _settings(-cutplaneopacity)] \
     1906        -variable [itcl::scope _widget(-cutplaneopacity)] \
    18971907        -width 10 \
    18981908        -showvalue off \
    18991909        -command [itcl::code $this AdjustSetting -cutplaneopacity]
    1900     $inner.opacity set $_settings(-cutplaneopacity)
     1910    $inner.opacity set [expr $_settings(-cutplaneopacity) * 100.0]
    19011911
    19021912    # X-value slicer...
     
    20192029        }
    20202030        "set" {
    2021             set who [lindex $args 0]
    2022             set x $_view($who)
     2031            set what [lindex $args 0]
     2032            set x $_view($what)
    20232033            set code [catch { string is double $x } result]
    20242034            if { $code != 0 || !$result } {
    20252035                return
    20262036            }
    2027             switch -- $who {
    2028                 "ortho" {
    2029                     if {$_view(ortho)} {
     2037            switch -- $what {
     2038                "-ortho" {
     2039                    if {$_view($what)} {
    20302040                        SendCmd "camera mode ortho"
    20312041                    } else {
     
    20332043                    }
    20342044                }
    2035                 "xpan" - "ypan" {
     2045                "-xpan" - "-ypan" {
    20362046                    PanCamera
    20372047                }
    2038                 "qx" - "qy" - "qz" - "qw" {
    2039                     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     2048                "-qx" - "-qy" - "-qz" - "-qw" {
     2049                    set q [ViewToQuaternion]
    20402050                    $_arcball quaternion $q
    20412051                    EventuallyRotate $q
    20422052                }
    2043                 "zoom" {
    2044                     SendCmd "camera zoom $_view(zoom)"
     2053                "-zoom" {
     2054                    SendCmd "camera zoom $_view(-zoom)"
    20452055                }
    20462056             }
     
    21172127    set tag $dataobj-$comp
    21182128    array set style {
    2119         -color BCGYR
    2120         -cutplanesvisible 0
    2121         -edgecolor black
    2122         -edges 0
    2123         -isosurfacevisible 1
    2124         -levels 10
    2125         -lighting 1
    2126         -linewidth 1.0
    2127         -opacity 0.6
    2128         -outline 0
    2129         -wireframe 0
    2130         -xcutplaneposition 50
    2131         -xcutplanevisible 1
    2132         -ycutplaneposition 50
    2133         -ycutplanevisible 1
    2134         -zcutplaneposition 50
    2135         -zcutplanevisible 1
     2129        -color                  BCGYR
     2130        -cutplanesvisible       0
     2131        -edgecolor              black
     2132        -edges                  0
     2133        -isosurfacevisible      1
     2134        -levels                 10
     2135        -lighting               1
     2136        -linewidth              1.0
     2137        -opacity                0.6
     2138        -outline                0
     2139        -wireframe              0
     2140        -xcutplaneposition      50
     2141        -xcutplanevisible       1
     2142        -ycutplaneposition      50
     2143        -ycutplanevisible       1
     2144        -zcutplaneposition      50
     2145        -zcutplanevisible       1
    21362146    }
    21372147    array set style [$dataobj style $comp]
    21382148    if { $dataobj != $_first || $style(-levels) == 1 } {
    2139         set style(-opacity) 1
    2140     }
    2141     SendCmd "cutplane add $tag"
    2142     SendCmd "cutplane visible 0 $tag"
     2149        set style(-opacity) 1.0
     2150    }
    21432151
    21442152    # This is too complicated.  We want to set the colormap, number of
     
    21642172        $itk_component(colormap) value $style(-color)
    21652173    }
    2166     set _currentOpacity $style(-opacity)
    2167     if { $_currentNumContours != $style(-levels) } {
    2168         set _currentNumContours $style(-levels)
    2169         set _settings(-numcontours) $_currentNumContours
    2170         $itk_component(numcontours) value $_currentNumContours
    2171         UpdateContourList
    2172         DrawLegend
     2174    if { $_contourList(numLevels) != $style(-levels) } {
     2175        if { [llength $style(-levels)] > 1 } {
     2176            set _contourList(reqValues) [lsort -real $style(-levels)]
     2177        } else {
     2178            set _settings(-numcontours) $style(-levels)
     2179            $itk_component(numcontours) value $style(-levels)
     2180            set _contourList(numLevels) $style(-levels)
     2181        }
     2182        EventuallyChangeContourLevels
    21732183    }
    21742184    set _settings(-isosurfacevisible) $style(-isosurfacevisible)
     
    21812191    set _settings(-zcutplaneposition) $style(-zcutplaneposition)
    21822192 
    2183     SendCmd [list contour3d add contourlist $_contourList $tag]
    2184     SendCmd "contour3d edges $style(-edges) $tag"
     2193    SendCmd "cutplane add $tag"
     2194    SendCmd "cutplane color [Color2RGB $itk_option(-plotforeground)] $tag"
     2195    SendCmd "cutplane visible $style(-cutplanesvisible) $tag"
     2196
    21852197    SendCmd "outline add $tag"
    21862198    SendCmd "outline color [Color2RGB $itk_option(-plotforeground)] $tag"
    21872199    SendCmd "outline visible $style(-outline) $tag"
    2188     set _settings(-isosurfaceoutline) $style(-outline)
     2200    set _settings(-outline) $style(-outline)
     2201 
     2202    GenerateContourList
     2203    SendCmd [list contour3d add contourlist $_contourList(values) $tag]
     2204    SendCmd "contour3d visible $style(-isosurfacevisible) $tag"
     2205    SendCmd "contour3d edges $style(-edges) $tag"
    21892206    set _settings(-isosurfaceedges) $style(-edges)
    21902207    #SendCmd "contour3d color [Color2RGB $settings(-color)] $tag"
     
    21932210    SendCmd "contour3d linecolor [Color2RGB $style(-edgecolor)] $tag"
    21942211    SendCmd "contour3d linewidth $style(-linewidth) $tag"
    2195     SendCmd "contour3d opacity $_currentOpacity $tag"
     2212    SendCmd "contour3d opacity $style(-opacity) $tag"
    21962213    set _settings(-isosurfaceopacity) $style(-opacity)
    21972214    SetCurrentColormap $style(-color)
    21982215    SendCmd "contour3d wireframe $style(-wireframe) $tag"
    21992216    set _settings(-isosurfacewireframe) $style(-wireframe)
    2200     set _settings(-isosurfaceopacity) [expr $style(-opacity) * 100.0]
    22012217}
    22022218
     
    24322448            incr offset $lineht
    24332449        }
    2434         foreach value $_contourList {
     2450        foreach value $_contourList(values) {
    24352451            set norm [expr 1.0 - (($value - $vmin) / $range)]
    24362452            set y1 [expr int(round(($norm * $ih) + $offset))]
     
    25452561        bottom "0.707107 0.707107 0 0"
    25462562    }
    2547     foreach name { qw qx qy qz } value $positions($side) {
     2563    foreach name { -qw -qx -qy -qz } value $positions($side) {
    25482564        set _view($name) $value
    25492565    }
    2550     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     2566    set q [ViewToQuaternion]
    25512567    $_arcball quaternion $q
    25522568    SendCmd "camera orient $q"
    25532569    SendCmd "camera reset"
    2554     set _view(xpan) 0
    2555     set _view(ypan) 0
    2556     set _view(zoom) 1.0
    2557 }
    2558 
    2559 itcl::body Rappture::VtkIsosurfaceViewer::UpdateContourList {} {
     2570    set _view(-xpan) 0
     2571    set _view(-ypan) 0
     2572    set _view(-zoom) 1.0
     2573}
     2574
     2575itcl::body Rappture::VtkIsosurfaceViewer::GenerateContourList {} {
    25602576    if { ![info exists _limits($_curFldName)] } {
    2561         return
    2562     }
    2563     if { $_currentNumContours < 1 } {
    2564         set _contourList ""
    2565         return
    2566     }
    2567     foreach { vmin vmax } $_limits($_curFldName) break
    2568     set v [blt::vector create \#auto]
    2569     $v seq $vmin $vmax [expr $_currentNumContours+2]
    2570     $v delete end 0
    2571     set _contourList [$v range 0 end]
    2572     blt::vector destroy $v
    2573 }
    2574 
     2577        puts stderr "no _curFldName"
     2578        return ""
     2579    }
     2580    if { $_contourList(numLevels) < 1 } {
     2581        # There are tools that set 0 levels to get cutplanes only
     2582        #puts stderr "numLevels < 1"
     2583        return ""
     2584    }
     2585    if { [llength $_contourList(reqValues)] > 1 } {
     2586        set values $_contourList(reqValues)
     2587    } else {
     2588        foreach { vmin vmax } $_limits($_curFldName) break
     2589        set v [blt::vector create \#auto]
     2590        $v seq $vmin $vmax [expr $_contourList(numLevels)+2]
     2591        $v delete end 0
     2592        set values [$v range 0 end]
     2593        blt::vector destroy $v
     2594    }
     2595    set _contourList(values) $values
     2596}
     2597
     2598itcl::body Rappture::VtkIsosurfaceViewer::SetCurrentFieldName { dataobj } {
     2599    set _first $dataobj
     2600    $itk_component(field) choices delete 0 end
     2601    $itk_component(fieldmenu) delete 0 end
     2602    array unset _fields
     2603    set _curFldName ""
     2604    foreach cname [$_first components] {
     2605        foreach fname [$_first fieldnames $cname] {
     2606            if { [info exists _fields($fname)] } {
     2607                continue
     2608            }
     2609            foreach { label units components } \
     2610                [$_first fieldinfo $fname] break
     2611            $itk_component(field) choices insert end "$fname" "$label"
     2612            $itk_component(fieldmenu) add radiobutton -label "$label" \
     2613                -value $label -variable [itcl::scope _curFldLabel] \
     2614                -selectcolor red \
     2615                -activebackground $itk_option(-plotbackground) \
     2616                -activeforeground $itk_option(-plotforeground) \
     2617                -font "Arial 8" \
     2618                -command [itcl::code $this Combo invoke]
     2619            set _fields($fname) [list $label $units $components]
     2620            if { $_curFldName == "" } {
     2621                set _curFldName $fname
     2622                set _curFldLabel $label
     2623            }
     2624        }
     2625    }
     2626    $itk_component(field) value $_curFldLabel
     2627    if { ![info exists _limits($_curFldName)] } {
     2628        SendCmd "dataset maprange all"
     2629    } else {
     2630        set limits $_limits($_curFldName)
     2631        SendCmd "dataset maprange explicit $limits $_curFldName"
     2632        if { $limits != $_currentLimits } {
     2633            set _currentLimits $limits
     2634            EventuallyChangeContourLevels
     2635        }
     2636    }
     2637}
Note: See TracChangeset for help on using the changeset viewer.