Changeset 4704 for trunk


Ignore:
Timestamp:
Nov 12, 2014, 4:08:52 PM (10 years ago)
Author:
ldelgass
Message:

Manual merge of refactoring in isosurface viewer from release branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/vtkisosurfaceviewer.tcl

    r4699 r4704  
    6262    public method scale {args}
    6363
    64     protected method Connect {}
    65     protected method CurrentDatasets {args}
    66     protected method Disconnect {}
    67     protected method DoResize {}
    68     protected method DoRotate {}
    69     protected method DoChangeContourLevels {}
    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 }
    92     private method EventuallyChangeContourLevels {}
    9385    private method EventuallyRotate { q }
    94     private method EventuallyRequestLegend {}
    9586    private method EventuallySetCutplane { axis args }
     87    private method GenerateContourList {}
    9688    private method GetImage { args }
    9789    private method GetVtkData { args }
     90    private method InitSettings { args  }
    9891    private method IsValidObject { dataobj }
    9992    private method LeaveLegend {}
    10093    private method MotionLegend { x y }
     94    private method Pan {option x y}
    10195    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 }
    102101    private method RequestLegend {}
     102    private method Rotate {option x y}
     103    private method SetCurrentColormap { color }
    103104    private method SetLegendTip { x y }
    104105    private method SetObjectStyle { dataobj comp }
     106    private method SetOrientation { side }
    105107    private method Slice {option args}
    106     private method SetCurrentColormap { color }
    107     private method SetOrientation { side }
    108     private method GenerateContourList {}
     108    private method Zoom {option}
     109    private method ViewToQuaternion {} {
     110        return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)]
     111    }
    109112
    110113    private variable _arcball ""
     
    215218    # Initialize the view to some default parameters.
    216219    array set _view {
    217         qw              0.853553
    218         qx              -0.353553
    219         qy              0.353553
    220         qz              0.146447
    221         zoom            1.0
    222         xpan            0
    223         ypan            0
    224         ortho           0
     220        -ortho           0
     221        -qw              0.853553
     222        -qx              -0.353553
     223        -qy              0.353553
     224        -qz              0.146447
     225        -xpan            0
     226        -ypan            0
     227        -zoom            1.0
    225228    }
    226229    set _arcball [blt::arcball create 100 100]
    227     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    228     $_arcball quaternion $q
     230    $_arcball quaternion [ViewToQuaternion]
    229231
    230232    array set _contourList {
     
    496498
    497499itcl::body Rappture::VtkIsosurfaceViewer::DoRotate {} {
    498     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    499     SendCmd "camera orient $q"
     500    SendCmd "camera orient [ViewToQuaternion]"
    500501    set _rotatePending 0
    501502}
     
    521522
    522523itcl::body Rappture::VtkIsosurfaceViewer::EventuallyRotate { q } {
    523     foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break
     524    foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break
    524525    if { !$_rotatePending } {
    525526        set _rotatePending 1
     
    985986        $_arcball resize $w $h
    986987        DoResize
    987         #
     988
    988989        # Reset the camera and other view parameters
    989         #
    990         set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    991         $_arcball quaternion $q
    992         if {$_view(ortho)} {
    993             SendCmd "camera mode ortho"
    994         } else {
    995             SendCmd "camera mode persp"
    996         }
     990        $_arcball quaternion [ViewToQuaternion]
    997991        DoRotate
    998992        PanCamera
    999993        set _first ""
    1000994        InitSettings -xgrid -ygrid -zgrid -axismode \
    1001             -axesvisible -axislabels -axisminorticks
     995            -axesvisible -axislabels -axisminorticks -ortho
    1002996        #SendCmd "axis lformat all %g"
    1003997        StopBufferingCommands
     
    11821176    switch -- $option {
    11831177        "in" {
    1184             set _view(zoom) [expr {$_view(zoom)*1.25}]
    1185             SendCmd "camera zoom $_view(zoom)"
     1178            set _view(-zoom) [expr {$_view(-zoom)*1.25}]
     1179            SendCmd "camera zoom $_view(-zoom)"
    11861180        }
    11871181        "out" {
    1188             set _view(zoom) [expr {$_view(zoom)*0.8}]
    1189             SendCmd "camera zoom $_view(zoom)"
     1182            set _view(-zoom) [expr {$_view(-zoom)*0.8}]
     1183            SendCmd "camera zoom $_view(-zoom)"
    11901184        }
    11911185        "reset" {
    11921186            array set _view {
    1193                 qw     0.853553
    1194                 qx     -0.353553
    1195                 qy     0.353553
    1196                 qz     0.146447
    1197                 zoom   1.0
    1198                 xpan   0
    1199                 ypan   0
     1187                -qw     0.853553
     1188                -qx     -0.353553
     1189                -qy     0.353553
     1190                -qz     0.146447
     1191                -xpan   0
     1192                -ypan   0
     1193                -zoom   1.0
    12001194            }
    12011195            if { $_first != "" } {
     
    12051199                }
    12061200            }
    1207             set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    1208             $_arcball quaternion $q
     1201            $_arcball quaternion [ViewToQuaternion]
    12091202            DoRotate
    12101203            SendCmd "camera reset"
     
    12141207
    12151208itcl::body Rappture::VtkIsosurfaceViewer::PanCamera {} {
    1216     set x $_view(xpan)
    1217     set y $_view(ypan)
     1209    set x $_view(-xpan)
     1210    set y $_view(-ypan)
    12181211    SendCmd "camera pan $x $y"
    12191212}
     
    12931286            set x [expr $x / double($w)]
    12941287            set y [expr $y / double($h)]
    1295             set _view(xpan) [expr $_view(xpan) + $x]
    1296             set _view(ypan) [expr $_view(ypan) + $y]
     1288            set _view(-xpan) [expr $_view(-xpan) + $x]
     1289            set _view(-ypan) [expr $_view(-ypan) + $y]
    12971290            PanCamera
    12981291            return
     
    13161309            set _click(x) $x
    13171310            set _click(y) $y
    1318             set _view(xpan) [expr $_view(xpan) - $dx]
    1319             set _view(ypan) [expr $_view(ypan) - $dy]
     1311            set _view(-xpan) [expr $_view(-xpan) - $dx]
     1312            set _view(-ypan) [expr $_view(-ypan) - $dy]
    13201313            PanCamera
    13211314        }
     
    13591352    }
    13601353    switch -- $what {
     1354        "-axesvisible" {
     1355            set bool $_settings($what)
     1356            SendCmd "axis visible all $bool"
     1357        }
     1358        "-axislabels" {
     1359            set bool $_settings($what)
     1360            SendCmd "axis labels all $bool"
     1361        }
     1362        "-axisminorticks" {
     1363            set bool $_settings($what)
     1364            SendCmd "axis minticks all $bool"
     1365        }
     1366        "-axismode" {
     1367            set mode [$itk_component(axisMode) value]
     1368            set mode [$itk_component(axisMode) translate $mode]
     1369            set _settings($what) $mode
     1370            SendCmd "axis flymode $mode"
     1371        }
    13611372        "-background" {
    13621373            set bgcolor [$itk_component(background) value]
     
    13711382            DrawLegend
    13721383        }
    1373         "-axesvisible" {
    1374             set bool $_settings($what)
    1375             SendCmd "axis visible all $bool"
    1376         }
    1377         "-axislabels" {
    1378             set bool $_settings($what)
    1379             SendCmd "axis labels all $bool"
    1380         }
    1381         "-axisminorticks" {
    1382             set bool $_settings($what)
    1383             SendCmd "axis minticks all $bool"
    1384         }
    1385         "-axismode" {
    1386             set mode [$itk_component(axisMode) value]
    1387             set mode [$itk_component(axisMode) translate $mode]
    1388             set _settings($what) $mode
    1389             SendCmd "axis flymode $mode"
    1390         }
    1391         "-xgrid" - "-ygrid" - "-zgrid" {
    1392             set axis [string tolower [string range $what 1 1]]
    1393             set bool $_settings($what)
    1394             SendCmd "axis grid $axis $bool"
    1395         }
    13961384        "-cutplaneedges" {
    13971385            set bool $_settings($what)
    13981386            SendCmd "cutplane edges $bool"
     1387        }
     1388        "-cutplanelighting" {
     1389            set bool $_settings($what)
     1390            SendCmd "cutplane lighting $bool"
     1391        }
     1392        "-cutplaneopacity" {
     1393            set _settings($what) [expr $_widget($what) * 0.01]
     1394            SendCmd "cutplane opacity $_settings($what)"
     1395        }
     1396        "-cutplanepreinterp" {
     1397            set bool $_settings($what)
     1398            SendCmd "cutplane preinterp $bool"
    13991399        }
    14001400        "-cutplanesvisible" {
     
    14181418            SendCmd "cutplane wireframe $bool"
    14191419        }
    1420         "-cutplanelighting" {
    1421             set bool $_settings($what)
    1422             SendCmd "cutplane lighting $bool"
    1423         }
    1424         "-cutplaneopacity" {
    1425             set _settings($what) [expr $_widget($what) * 0.01]
    1426             SendCmd "cutplane opacity $_settings($what)"
    1427         }
    1428         "-cutplanepreinterp" {
    1429             set bool $_settings($what)
    1430             SendCmd "cutplane preinterp $bool"
    1431         }
    1432         "-xcutplanevisible" - "-ycutplanevisible" - "-zcutplanevisible" {
    1433             set axis [string tolower [string range $what 1 1]]
    1434             set bool $_settings($what)
    1435             if { $bool } {
    1436                 $itk_component(${axis}position) configure -state normal \
    1437                     -troughcolor white
    1438             } else {
    1439                 $itk_component(${axis}position) configure -state disabled \
    1440                     -troughcolor grey82
    1441             }
    1442             SendCmd "cutplane axis $axis $bool"
    1443         }
    1444         "-xcutplaneposition" - "-ycutplaneposition" - "-zcutplaneposition" {
    1445             set axis [string tolower [string range $what 1 1]]
    1446             set pos [expr $_settings($what) * 0.01]
    1447             SendCmd "cutplane slice ${axis} ${pos}"
    1448             set _cutplanePending 0
    1449         }
    14501420        "-colormap" {
    14511421            set _changed($what) 1
    14521422            StartBufferingCommands
    14531423            set color [$itk_component(colormap) value]
    1454             set _settings(-colormap) $color
     1424            set _settings($what) $color
    14551425            if { $color == "none" } {
    14561426                if { $_settings(-colormapvisible) } {
     
    14681438            EventuallyRequestLegend
    14691439        }
    1470         "-numcontours" {
    1471             set _settings($what) [$itk_component(numcontours) value]
    1472             if { $_contourList(numLevels) != $_settings($what) } {
    1473                 set _contourList(numLevels) $_settings($what)
    1474                 EventuallyChangeContourLevels
    1475             }
    1476         }
    1477         "-isosurfacewireframe" {
    1478             set bool $_settings($what)
    1479             SendCmd "contour3d wireframe $bool"
    1480         }
    1481         "-isosurfacevisible" {
    1482             set bool $_settings($what)
    1483             SendCmd "contour3d visible 0"
    1484             if { $bool } {
    1485                 foreach tag [CurrentDatasets -visible] {
    1486                     SendCmd "contour3d visible $bool $tag"
    1487                 }
    1488             }
    1489             if { $bool } {
    1490                 Rappture::Tooltip::for $itk_component(contour) \
    1491                     "Hide the isosurface"
    1492             } else {
    1493                 Rappture::Tooltip::for $itk_component(contour) \
    1494                     "Show the isosurface"
    1495             }
    1496         }
    1497         "-isosurfacelighting" {
    1498             set bool $_settings($what)
    1499             SendCmd "contour3d lighting $bool"
    1500         }
    1501         "-isosurfaceedges" {
    1502             set bool $_settings($what)
    1503             SendCmd "contour3d edges $bool"
    1504         }
    1505         "-outline" {
    1506             set bool $_settings($what)
    1507             SendCmd "outline visible 0"
    1508             if { $bool } {
    1509                 foreach tag [CurrentDatasets -visible] {
    1510                     SendCmd "outline visible $bool $tag"
    1511                 }
    1512             }
    1513         }
    1514         "-isolinecolor" {
    1515             set color [$itk_component(isolineColor) value]
    1516             set _settings($what) $color
    1517             DrawLegend
    1518         }
    1519         "-isosurfaceopacity" {
    1520             set _settings($what) [expr $_widget($what) * 0.01]
    1521             SendCmd "contour3d opacity $_settings($what)"
    1522         }
    15231440        "-field" {
    15241441            set label [$itk_component(field) value]
     
    15501467            DrawLegend
    15511468        }
     1469        "-isolinecolor" {
     1470            set color [$itk_component(isolineColor) value]
     1471            set _settings($what) $color
     1472            DrawLegend
     1473        }
     1474        "-isosurfaceedges" {
     1475            set bool $_settings($what)
     1476            SendCmd "contour3d edges $bool"
     1477        }
     1478        "-isosurfacelighting" {
     1479            set bool $_settings($what)
     1480            SendCmd "contour3d lighting $bool"
     1481        }
     1482        "-isosurfaceopacity" {
     1483            set _settings($what) [expr $_widget($what) * 0.01]
     1484            SendCmd "contour3d opacity $_settings($what)"
     1485        }
     1486        "-isosurfacevisible" {
     1487            set bool $_settings($what)
     1488            SendCmd "contour3d visible 0"
     1489            if { $bool } {
     1490                foreach tag [CurrentDatasets -visible] {
     1491                    SendCmd "contour3d visible $bool $tag"
     1492                }
     1493            }
     1494            if { $bool } {
     1495                Rappture::Tooltip::for $itk_component(contour) \
     1496                    "Hide the isosurface"
     1497            } else {
     1498                Rappture::Tooltip::for $itk_component(contour) \
     1499                    "Show the isosurface"
     1500            }
     1501        }
     1502        "-isosurfacewireframe" {
     1503            set bool $_settings($what)
     1504            SendCmd "contour3d wireframe $bool"
     1505        }
    15521506        "-legendvisible" {
    15531507            if { !$_settings($what) } {
     
    15551509            }
    15561510            DrawLegend
     1511        }
     1512        "-numcontours" {
     1513            set _settings($what) [$itk_component(numcontours) value]
     1514            if { $_contourList(numLevels) != $_settings($what) } {
     1515                set _contourList(numLevels) $_settings($what)
     1516                EventuallyChangeContourLevels
     1517            }
     1518        }
     1519        "-ortho" {
     1520            set bool $_view($what)
     1521            if { $bool } {
     1522                SendCmd "camera mode ortho"
     1523            } else {
     1524                SendCmd "camera mode persp"
     1525            }
     1526        }
     1527        "-outline" {
     1528            set bool $_settings($what)
     1529            SendCmd "outline visible 0"
     1530            if { $bool } {
     1531                foreach tag [CurrentDatasets -visible] {
     1532                    SendCmd "outline visible $bool $tag"
     1533                }
     1534            }
     1535        }
     1536        "-xcutplanevisible" - "-ycutplanevisible" - "-zcutplanevisible" {
     1537            set axis [string tolower [string range $what 1 1]]
     1538            set bool $_settings($what)
     1539            if { $bool } {
     1540                $itk_component(${axis}position) configure -state normal \
     1541                    -troughcolor white
     1542            } else {
     1543                $itk_component(${axis}position) configure -state disabled \
     1544                    -troughcolor grey82
     1545            }
     1546            SendCmd "cutplane axis $axis $bool"
     1547        }
     1548        "-xcutplaneposition" - "-ycutplaneposition" - "-zcutplaneposition" {
     1549            set axis [string tolower [string range $what 1 1]]
     1550            set pos [expr $_settings($what) * 0.01]
     1551            SendCmd "cutplane slice ${axis} ${pos}"
     1552            set _cutplanePending 0
     1553        }
     1554        "-xgrid" - "-ygrid" - "-zgrid" {
     1555            set axis [string tolower [string range $what 1 1]]
     1556            set bool $_settings($what)
     1557            SendCmd "axis grid $axis $bool"
    15571558        }
    15581559        default {
     
    18711872        label $inner.${tag}label -text $tag -font "Arial 9"
    18721873        entry $inner.${tag} -font "Arial 9"  -bg white \
    1873             -textvariable [itcl::scope _view($tag)]
     1874            -textvariable [itcl::scope _view(-$tag)]
    18741875        bind $inner.${tag} <KeyPress-Return> \
    18751876            [itcl::code $this camera set ${tag}]
     
    18821883    checkbutton $inner.ortho \
    18831884        -text "Orthographic Projection" \
    1884         -variable [itcl::scope _view(ortho)] \
    1885         -command [itcl::code $this camera set ortho] \
     1885        -variable [itcl::scope _view(-ortho)] \
     1886        -command [itcl::code $this AdjustSetting -ortho] \
    18861887        -font "Arial 9"
    18871888    blt::table $inner \
     
    20622063        }
    20632064        "set" {
    2064             set who [lindex $args 0]
    2065             set x $_view($who)
     2065            set what [lindex $args 0]
     2066            set x $_view($what)
    20662067            set code [catch { string is double $x } result]
    20672068            if { $code != 0 || !$result } {
    20682069                return
    20692070            }
    2070             switch -- $who {
    2071                 "ortho" {
    2072                     if {$_view(ortho)} {
     2071            switch -- $what {
     2072                "-ortho" {
     2073                    if {$_view($what)} {
    20732074                        SendCmd "camera mode ortho"
    20742075                    } else {
     
    20762077                    }
    20772078                }
    2078                 "xpan" - "ypan" {
     2079                "-xpan" - "-ypan" {
    20792080                    PanCamera
    20802081                }
    2081                 "qx" - "qy" - "qz" - "qw" {
    2082                     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     2082                "-qx" - "-qy" - "-qz" - "-qw" {
     2083                    set q [ViewToQuaternion]
    20832084                    $_arcball quaternion $q
    20842085                    EventuallyRotate $q
    20852086                }
    2086                 "zoom" {
    2087                     SendCmd "camera zoom $_view(zoom)"
     2087                "-zoom" {
     2088                    SendCmd "camera zoom $_view(-zoom)"
    20882089                }
    20892090             }
     
    25932594        bottom "0.707107 0.707107 0 0"
    25942595    }
    2595     foreach name { qw qx qy qz } value $positions($side) {
     2596    foreach name { -qw -qx -qy -qz } value $positions($side) {
    25962597        set _view($name) $value
    25972598    }
    2598     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     2599    set q [ViewToQuaternion]
    25992600    $_arcball quaternion $q
    26002601    SendCmd "camera orient $q"
    26012602    SendCmd "camera reset"
    2602     set _view(xpan) 0
    2603     set _view(ypan) 0
    2604     set _view(zoom) 1.0
     2603    set _view(-xpan) 0
     2604    set _view(-ypan) 0
     2605    set _view(-zoom) 1.0
    26052606}
    26062607
Note: See TracChangeset for help on using the changeset viewer.