- Timestamp:
- Nov 12, 2014, 4:08:52 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/vtkisosurfaceviewer.tcl
r4699 r4704 62 62 public method scale {args} 63 63 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 81 64 # The following methods are only used by this class. 65 66 private method AdjustSetting {what {value ""}} 82 67 private method BuildAxisTab {} 83 68 private method BuildCameraTab {} … … 87 72 private method BuildIsosurfaceTab {} 88 73 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 {} 89 80 private method DrawLegend {} 90 81 private method EnterLegend { x y } 82 private method EventuallyChangeContourLevels {} 83 private method EventuallyRequestLegend {} 91 84 private method EventuallyResize { w h } 92 private method EventuallyChangeContourLevels {}93 85 private method EventuallyRotate { q } 94 private method EventuallyRequestLegend {}95 86 private method EventuallySetCutplane { axis args } 87 private method GenerateContourList {} 96 88 private method GetImage { args } 97 89 private method GetVtkData { args } 90 private method InitSettings { args } 98 91 private method IsValidObject { dataobj } 99 92 private method LeaveLegend {} 100 93 private method MotionLegend { x y } 94 private method Pan {option x y} 101 95 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 } 102 101 private method RequestLegend {} 102 private method Rotate {option x y} 103 private method SetCurrentColormap { color } 103 104 private method SetLegendTip { x y } 104 105 private method SetObjectStyle { dataobj comp } 106 private method SetOrientation { side } 105 107 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 } 109 112 110 113 private variable _arcball "" … … 215 218 # Initialize the view to some default parameters. 216 219 array set _view { 217 qw 0.853553218 qx -0.353553219 qy0.353553220 qz 0.146447221 zoom 1.0222 xpan 0223 ypan 0224 ortho 0220 -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 225 228 } 226 229 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] 229 231 230 232 array set _contourList { … … 496 498 497 499 itcl::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]" 500 501 set _rotatePending 0 501 502 } … … 521 522 522 523 itcl::body Rappture::VtkIsosurfaceViewer::EventuallyRotate { q } { 523 foreach { _view( qw) _view(qx) _view(qy) _view(qz) } $q break524 foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break 524 525 if { !$_rotatePending } { 525 526 set _rotatePending 1 … … 985 986 $_arcball resize $w $h 986 987 DoResize 987 # 988 988 989 # 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] 997 991 DoRotate 998 992 PanCamera 999 993 set _first "" 1000 994 InitSettings -xgrid -ygrid -zgrid -axismode \ 1001 -axesvisible -axislabels -axisminorticks 995 -axesvisible -axislabels -axisminorticks -ortho 1002 996 #SendCmd "axis lformat all %g" 1003 997 StopBufferingCommands … … 1182 1176 switch -- $option { 1183 1177 "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)" 1186 1180 } 1187 1181 "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)" 1190 1184 } 1191 1185 "reset" { 1192 1186 array set _view { 1193 qw 0.8535531194 qx -0.3535531195 qy 0.3535531196 qz 0.1464471197 zoom 1.01198 xpan 01199 ypan01187 -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 1200 1194 } 1201 1195 if { $_first != "" } { … … 1205 1199 } 1206 1200 } 1207 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1208 $_arcball quaternion $q 1201 $_arcball quaternion [ViewToQuaternion] 1209 1202 DoRotate 1210 1203 SendCmd "camera reset" … … 1214 1207 1215 1208 itcl::body Rappture::VtkIsosurfaceViewer::PanCamera {} { 1216 set x $_view( xpan)1217 set y $_view( ypan)1209 set x $_view(-xpan) 1210 set y $_view(-ypan) 1218 1211 SendCmd "camera pan $x $y" 1219 1212 } … … 1293 1286 set x [expr $x / double($w)] 1294 1287 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] 1297 1290 PanCamera 1298 1291 return … … 1316 1309 set _click(x) $x 1317 1310 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] 1320 1313 PanCamera 1321 1314 } … … 1359 1352 } 1360 1353 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 } 1361 1372 "-background" { 1362 1373 set bgcolor [$itk_component(background) value] … … 1371 1382 DrawLegend 1372 1383 } 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) $mode1389 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 }1396 1384 "-cutplaneedges" { 1397 1385 set bool $_settings($what) 1398 1386 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" 1399 1399 } 1400 1400 "-cutplanesvisible" { … … 1418 1418 SendCmd "cutplane wireframe $bool" 1419 1419 } 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 white1438 } else {1439 $itk_component(${axis}position) configure -state disabled \1440 -troughcolor grey821441 }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 01449 }1450 1420 "-colormap" { 1451 1421 set _changed($what) 1 1452 1422 StartBufferingCommands 1453 1423 set color [$itk_component(colormap) value] 1454 set _settings( -colormap) $color1424 set _settings($what) $color 1455 1425 if { $color == "none" } { 1456 1426 if { $_settings(-colormapvisible) } { … … 1468 1438 EventuallyRequestLegend 1469 1439 } 1470 "-numcontours" {1471 set _settings($what) [$itk_component(numcontours) value]1472 if { $_contourList(numLevels) != $_settings($what) } {1473 set _contourList(numLevels) $_settings($what)1474 EventuallyChangeContourLevels1475 }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) $color1517 DrawLegend1518 }1519 "-isosurfaceopacity" {1520 set _settings($what) [expr $_widget($what) * 0.01]1521 SendCmd "contour3d opacity $_settings($what)"1522 }1523 1440 "-field" { 1524 1441 set label [$itk_component(field) value] … … 1550 1467 DrawLegend 1551 1468 } 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 } 1552 1506 "-legendvisible" { 1553 1507 if { !$_settings($what) } { … … 1555 1509 } 1556 1510 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" 1557 1558 } 1558 1559 default { … … 1871 1872 label $inner.${tag}label -text $tag -font "Arial 9" 1872 1873 entry $inner.${tag} -font "Arial 9" -bg white \ 1873 -textvariable [itcl::scope _view( $tag)]1874 -textvariable [itcl::scope _view(-$tag)] 1874 1875 bind $inner.${tag} <KeyPress-Return> \ 1875 1876 [itcl::code $this camera set ${tag}] … … 1882 1883 checkbutton $inner.ortho \ 1883 1884 -text "Orthographic Projection" \ 1884 -variable [itcl::scope _view( ortho)] \1885 -command [itcl::code $this camera setortho] \1885 -variable [itcl::scope _view(-ortho)] \ 1886 -command [itcl::code $this AdjustSetting -ortho] \ 1886 1887 -font "Arial 9" 1887 1888 blt::table $inner \ … … 2062 2063 } 2063 2064 "set" { 2064 set wh o[lindex $args 0]2065 set x $_view($wh o)2065 set what [lindex $args 0] 2066 set x $_view($what) 2066 2067 set code [catch { string is double $x } result] 2067 2068 if { $code != 0 || !$result } { 2068 2069 return 2069 2070 } 2070 switch -- $wh o{2071 " ortho" {2072 if {$_view( ortho)} {2071 switch -- $what { 2072 "-ortho" { 2073 if {$_view($what)} { 2073 2074 SendCmd "camera mode ortho" 2074 2075 } else { … … 2076 2077 } 2077 2078 } 2078 " xpan" - "ypan" {2079 "-xpan" - "-ypan" { 2079 2080 PanCamera 2080 2081 } 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] 2083 2084 $_arcball quaternion $q 2084 2085 EventuallyRotate $q 2085 2086 } 2086 " zoom" {2087 SendCmd "camera zoom $_view( zoom)"2087 "-zoom" { 2088 SendCmd "camera zoom $_view(-zoom)" 2088 2089 } 2089 2090 } … … 2593 2594 bottom "0.707107 0.707107 0 0" 2594 2595 } 2595 foreach name { qw qx qyqz } value $positions($side) {2596 foreach name { -qw -qx -qy -qz } value $positions($side) { 2596 2597 set _view($name) $value 2597 2598 } 2598 set q [ list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]2599 set q [ViewToQuaternion] 2599 2600 $_arcball quaternion $q 2600 2601 SendCmd "camera orient $q" 2601 2602 SendCmd "camera reset" 2602 set _view( xpan) 02603 set _view( ypan) 02604 set _view( zoom) 1.02603 set _view(-xpan) 0 2604 set _view(-ypan) 0 2605 set _view(-zoom) 1.0 2605 2606 } 2606 2607
Note: See TracChangeset
for help on using the changeset viewer.