Changeset 4512 for branches/1.3/gui/scripts/vtkisosurfaceviewer.tcl
- Timestamp:
- Jul 16, 2014, 4:24:32 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.3/gui/scripts/vtkisosurfaceviewer.tcl
r4504 r4512 63 63 public method scale {args} 64 64 65 protected method Connect {}66 protected method CurrentDatasets {args}67 protected method Disconnect {}68 protected method DoResize {}69 protected method DoRotate {}70 protected method DoChangeContourLevels {}71 protected method AdjustSetting {what {value ""}}72 protected method InitSettings { args }73 protected method Pan {option x y}74 protected method Pick {x y}75 protected method Rebuild {}76 protected method ReceiveDataset { args }77 protected method ReceiveImage { args }78 protected method ReceiveLegend { colormap title vmin vmax size }79 protected method Rotate {option x y}80 protected method Zoom {option}81 82 65 # The following methods are only used by this class. 66 67 private method AdjustSetting {what {value ""}} 83 68 private method BuildAxisTab {} 84 69 private method BuildCameraTab {} … … 88 73 private method BuildIsosurfaceTab {} 89 74 private method Combo { option } 75 private method Connect {} 76 private method CurrentDatasets {args} 77 private method Disconnect {} 78 private method DoChangeContourLevels {} 79 private method DoResize {} 80 private method DoRotate {} 90 81 private method DrawLegend {} 91 82 private method EnterLegend { x y } 83 private method EventuallyChangeContourLevels {} 84 private method EventuallyRequestLegend {} 92 85 private method EventuallyResize { w h } 93 private method EventuallyChangeContourLevels {}94 86 private method EventuallyRotate { q } 95 private method EventuallyRequestLegend {}96 87 private method EventuallySetCutplane { axis args } 88 private method GenerateContourList {} 97 89 private method GetImage { args } 98 90 private method GetVtkData { args } 91 private method InitSettings { args } 99 92 private method IsValidObject { dataobj } 100 93 private method LeaveLegend {} 101 94 private method MotionLegend { x y } 95 private method Pan {option x y} 102 96 private method PanCamera {} 97 private method Pick {x y} 98 private method Rebuild {} 99 private method ReceiveDataset { args } 100 private method ReceiveImage { args } 101 private method ReceiveLegend { colormap title vmin vmax size } 103 102 private method RequestLegend {} 103 private method Rotate {option x y} 104 private method SetCurrentColormap { color } 104 105 private method SetLegendTip { x y } 105 106 private method SetObjectStyle { dataobj comp } 107 private method SetOrientation { side } 106 108 private method Slice {option args} 107 private method SetCurrentColormap { color } 108 private method SetOrientation { side } 109 private method GenerateContourList {} 109 private method Zoom {option} 110 private method ViewToQuaternion {} { 111 return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)] 112 } 110 113 111 114 private variable _arcball "" … … 216 219 # Initialize the view to some default parameters. 217 220 array set _view { 218 qw 0.853553219 qx -0.353553220 qy0.353553221 qz 0.146447222 zoom 1.0223 xpan 0224 ypan 0225 ortho 0221 -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 226 229 } 227 230 set _arcball [blt::arcball create 100 100] 228 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 229 $_arcball quaternion $q 231 $_arcball quaternion [ViewToQuaternion] 230 232 231 233 array set _contourList { … … 275 277 } 276 278 array set _widget { 277 -isosurfaceopacity 0278 -cutplaneopacity 0279 -isosurfaceopacity 60 280 -cutplaneopacity 100 279 281 } 280 282 … … 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 … … 982 983 $_arcball resize $w $h 983 984 DoResize 984 # 985 985 986 # Reset the camera and other view parameters 986 # 987 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 988 $_arcball quaternion $q 989 if {$_view(ortho)} { 990 SendCmd "camera mode ortho" 991 } else { 992 SendCmd "camera mode persp" 993 } 987 $_arcball quaternion [ViewToQuaternion] 994 988 DoRotate 995 989 PanCamera 996 990 set _first "" 997 991 InitSettings -xgrid -ygrid -zgrid -axismode \ 998 -axesvisible -axislabelsvisible 992 -axesvisible -axislabelsvisible -ortho 999 993 SendCmd "axis lformat all %g" 1000 994 # Too many major ticks, so turn off minor ticks … … 1181 1175 switch -- $option { 1182 1176 "in" { 1183 set _view( zoom) [expr {$_view(zoom)*1.25}]1184 SendCmd "camera zoom $_view( zoom)"1177 set _view(-zoom) [expr {$_view(-zoom)*1.25}] 1178 SendCmd "camera zoom $_view(-zoom)" 1185 1179 } 1186 1180 "out" { 1187 set _view( zoom) [expr {$_view(zoom)*0.8}]1188 SendCmd "camera zoom $_view( zoom)"1181 set _view(-zoom) [expr {$_view(-zoom)*0.8}] 1182 SendCmd "camera zoom $_view(-zoom)" 1189 1183 } 1190 1184 "reset" { 1191 1185 array set _view { 1192 qw 0.8535531193 qx -0.3535531194 qy 0.3535531195 qz 0.1464471196 zoom 1.01197 xpan 01198 ypan01186 -qw 0.853553 1187 -qx -0.353553 1188 -qy 0.353553 1189 -qz 0.146447 1190 -xpan 0 1191 -ypan 0 1192 -zoom 1.0 1199 1193 } 1200 1194 if { $_first != "" } { … … 1204 1198 } 1205 1199 } 1206 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1207 $_arcball quaternion $q 1200 $_arcball quaternion [ViewToQuaternion] 1208 1201 DoRotate 1209 1202 SendCmd "camera reset" … … 1213 1206 1214 1207 itcl::body Rappture::VtkIsosurfaceViewer::PanCamera {} { 1215 set x $_view( xpan)1216 set y $_view( ypan)1208 set x $_view(-xpan) 1209 set y $_view(-ypan) 1217 1210 SendCmd "camera pan $x $y" 1218 1211 } … … 1292 1285 set x [expr $x / double($w)] 1293 1286 set y [expr $y / double($h)] 1294 set _view( xpan) [expr $_view(xpan) + $x]1295 set _view( ypan) [expr $_view(ypan) + $y]1287 set _view(-xpan) [expr $_view(-xpan) + $x] 1288 set _view(-ypan) [expr $_view(-ypan) + $y] 1296 1289 PanCamera 1297 1290 return … … 1315 1308 set _click(x) $x 1316 1309 set _click(y) $y 1317 set _view( xpan) [expr $_view(xpan) - $dx]1318 set _view( ypan) [expr $_view(ypan) - $dy]1310 set _view(-xpan) [expr $_view(-xpan) - $dx] 1311 set _view(-ypan) [expr $_view(-ypan) - $dy] 1319 1312 PanCamera 1320 1313 } … … 1358 1351 } 1359 1352 switch -- $what { 1353 "-axesvisible" { 1354 set bool $_settings($what) 1355 SendCmd "axis visible all $bool" 1356 } 1357 "-axislabelsvisible" { 1358 set bool $_settings($what) 1359 SendCmd "axis labels all $bool" 1360 } 1361 "-xgrid" - "-ygrid" - "-zgrid" { 1362 set axis [string tolower [string range $what 1 1]] 1363 set bool $_settings($what) 1364 SendCmd "axis grid $axis $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 } 1360 1372 "-background" { 1361 1373 set bgcolor [$itk_component(background) value] … … 1370 1382 DrawLegend 1371 1383 } 1372 "-axesvisible" {1373 set bool $_settings(-axesvisible)1374 SendCmd "axis visible all $bool"1375 }1376 "-axislabelsvisible" {1377 set bool $_settings(-axislabelsvisible)1378 SendCmd "axis labels all $bool"1379 }1380 "-xgrid" - "-ygrid" - "-zgrid" {1381 set axis [string tolower [string range $what 1 1]]1382 set bool $_settings($what)1383 SendCmd "axis grid $axis $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 1384 "-cutplaneedges" { 1392 1385 set bool $_settings($what) 1393 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" 1394 1399 } 1395 1400 "-cutplanesvisible" { … … 1413 1418 SendCmd "cutplane wireframe $bool" 1414 1419 } 1415 "-cutplanelighting" {1416 set bool $_settings($what)1417 SendCmd "cutplane lighting $bool"1418 }1419 "-cutplaneopacity" {1420 set _settings($what) [$_widget(-cutplaneopacity) * 0.01]1421 SendCmd "cutplane opacity $_settings($what)"1422 }1423 "-cutplanepreinterp" {1424 set bool $_settings($what)1425 SendCmd "cutplane preinterp $bool"1426 }1427 "-xcutplanevisible" - "-ycutplanevisible" - "-zcutplanevisible" {1428 set axis [string tolower [string range $what 1 1]]1429 set bool $_settings($what)1430 if { $bool } {1431 $itk_component(${axis}position) configure -state normal \1432 -troughcolor white1433 } else {1434 $itk_component(${axis}position) configure -state disabled \1435 -troughcolor grey821436 }1437 SendCmd "cutplane axis $axis $bool"1438 }1439 "-xcutplaneposition" - "-ycutplaneposition" - "-zcutplaneposition" {1440 set axis [string tolower [string range $what 1 1]]1441 set pos [expr $_settings($what) * 0.01]1442 SendCmd "cutplane slice ${axis} ${pos}"1443 set _cutplanePending 01444 }1445 1420 "-colormap" { 1446 1421 set _changed($what) 1 1447 1422 StartBufferingCommands 1448 1423 set color [$itk_component(colormap) value] 1449 set _settings( -colormap) $color1424 set _settings($what) $color 1450 1425 if { $color == "none" } { 1451 1426 if { $_settings(-colormapvisible) } { … … 1463 1438 EventuallyRequestLegend 1464 1439 } 1465 "-numcontours" {1466 set _settings($what) [$itk_component(numcontours) value]1467 if { $_contourList(numLevels) != $_settings($what) } {1468 set _contourList(numLevels) $_settings($what)1469 EventuallyChangeContourLevels1470 }1471 }1472 "-isosurfacewireframe" {1473 set bool $_settings($what)1474 SendCmd "contour3d wireframe $bool"1475 }1476 "-isosurfacevisible" {1477 set bool $_settings($what)1478 SendCmd "contour3d visible 0"1479 if { $bool } {1480 foreach tag [CurrentDatasets -visible] {1481 SendCmd "contour3d visible $bool $tag"1482 }1483 }1484 if { $bool } {1485 Rappture::Tooltip::for $itk_component(contour) \1486 "Hide the isosurface"1487 } else {1488 Rappture::Tooltip::for $itk_component(contour) \1489 "Show the isosurface"1490 }1491 }1492 "-isosurfacelighting" {1493 set bool $_settings($what)1494 SendCmd "contour3d lighting $bool"1495 }1496 "-isosurfaceedges" {1497 set bool $_settings($what)1498 SendCmd "contour3d edges $bool"1499 }1500 "-outline" {1501 set bool $_settings($what)1502 SendCmd "outline visible 0"1503 if { $bool } {1504 foreach tag [CurrentDatasets -visible] {1505 SendCmd "outline visible $bool $tag"1506 }1507 }1508 }1509 "-isolinecolor" {1510 set color [$itk_component(isolineColor) value]1511 set _settings($what) $color1512 DrawLegend1513 }1514 "-isosurfaceopacity" {1515 set _settings($what) [$_widget(-isosurfaceopacity) * 0.01]1516 SendCmd "contour3d opacity $_settings($what)"1517 }1518 1440 "-field" { 1519 1441 set label [$itk_component(field) value] … … 1542 1464 SendCmd "contour3d colormode $_colorMode $_curFldName" 1543 1465 SendCmd "camera reset" 1544 UpdateContourList1466 GenerateContourList 1545 1467 DrawLegend 1468 } 1469 "-isolinecolor" { 1470 set color [$itk_component(isolineColor) value] 1471 set _settings(-isolinecolor) $color 1472 set _settings($what) $color 1473 DrawLegend 1474 } 1475 "-isosurfaceedges" { 1476 set bool $_settings($what) 1477 SendCmd "contour3d edges $bool" 1478 } 1479 "-isosurfacelighting" { 1480 set bool $_settings($what) 1481 SendCmd "contour3d lighting $bool" 1482 } 1483 "-isosurfaceopacity" { 1484 set _settings($what) [expr $_widget($what) * 0.01] 1485 SendCmd "contour3d opacity $_settings($what)" 1486 } 1487 "-isosurfacevisible" { 1488 set bool $_settings($what) 1489 SendCmd "contour3d visible 0" 1490 if { $bool } { 1491 foreach tag [CurrentDatasets -visible] { 1492 SendCmd "contour3d visible $bool $tag" 1493 } 1494 } 1495 if { $bool } { 1496 Rappture::Tooltip::for $itk_component(contour) \ 1497 "Hide the isosurface" 1498 } else { 1499 Rappture::Tooltip::for $itk_component(contour) \ 1500 "Show the isosurface" 1501 } 1502 } 1503 "-isosurfacewireframe" { 1504 set bool $_settings($what) 1505 SendCmd "contour3d wireframe $bool" 1546 1506 } 1547 1507 "-legendvisible" { … … 1550 1510 } 1551 1511 DrawLegend 1512 } 1513 "-numcontours" { 1514 set _settings($what) [$itk_component(numcontours) value] 1515 if { $_contourList(numLevels) != $_settings($what) } { 1516 set _contourList(numLevels) $_settings($what) 1517 EventuallyChangeContourLevels 1518 } 1519 } 1520 "-ortho" { 1521 set bool $_view($what) 1522 if { $bool } { 1523 SendCmd "camera mode ortho" 1524 } else { 1525 SendCmd "camera mode persp" 1526 } 1527 } 1528 "-outline" { 1529 set bool $_settings($what) 1530 SendCmd "outline visible 0" 1531 if { $bool } { 1532 foreach tag [CurrentDatasets -visible] { 1533 SendCmd "outline visible $bool $tag" 1534 } 1535 } 1536 } 1537 "-xcutplanevisible" - "-ycutplanevisible" - "-zcutplanevisible" { 1538 set axis [string tolower [string range $what 1 1]] 1539 set bool $_settings($what) 1540 if { $bool } { 1541 $itk_component(${axis}position) configure -state normal \ 1542 -troughcolor white 1543 } else { 1544 $itk_component(${axis}position) configure -state disabled \ 1545 -troughcolor grey82 1546 } 1547 SendCmd "cutplane axis $axis $bool" 1548 } 1549 "-xcutplaneposition" - "-ycutplaneposition" - "-zcutplaneposition" { 1550 set axis [string tolower [string range $what 1 1]] 1551 set pos [expr $_settings($what) * 0.01] 1552 SendCmd "cutplane slice ${axis} ${pos}" 1553 set _cutplanePending 0 1552 1554 } 1553 1555 default { … … 1722 1724 -showvalue off \ 1723 1725 -command [itcl::code $this AdjustSetting -isosurfaceopacity] 1724 $inner.opacity set [expr $_settings(-isosurfaceeopacity) * 100.0] 1726 set _widget(-isosurfaceopacity) \ 1727 [expr $_settings(-isosurfaceopacity) * 100.0] 1725 1728 1726 1729 itk_component add field_l { … … 1866 1869 label $inner.${tag}label -text $tag -font "Arial 9" 1867 1870 entry $inner.${tag} -font "Arial 9" -bg white \ 1868 -textvariable [itcl::scope _view( $tag)]1871 -textvariable [itcl::scope _view(-$tag)] 1869 1872 bind $inner.${tag} <KeyPress-Return> \ 1870 1873 [itcl::code $this camera set ${tag}] … … 1877 1880 checkbutton $inner.ortho \ 1878 1881 -text "Orthographic Projection" \ 1879 -variable [itcl::scope _view( ortho)] \1880 -command [itcl::code $this camera setortho] \1882 -variable [itcl::scope _view(-ortho)] \ 1883 -command [itcl::code $this AdjustSetting -ortho] \ 1881 1884 -font "Arial 9" 1882 1885 blt::table $inner \ … … 1936 1939 -showvalue off \ 1937 1940 -command [itcl::code $this AdjustSetting -cutplaneopacity] 1938 $inner.opacity set[expr $_settings(-cutplaneopacity) * 100.0]1941 set _widget(-cutplaneopacity) [expr $_settings(-cutplaneopacity) * 100.0] 1939 1942 1940 1943 # X-value slicer... … … 2057 2060 } 2058 2061 "set" { 2059 set wh o[lindex $args 0]2060 set x $_view($wh o)2062 set what [lindex $args 0] 2063 set x $_view($what) 2061 2064 set code [catch { string is double $x } result] 2062 2065 if { $code != 0 || !$result } { 2063 2066 return 2064 2067 } 2065 switch -- $wh o{2066 " ortho" {2067 if {$_view( ortho)} {2068 switch -- $what { 2069 "-ortho" { 2070 if {$_view($what)} { 2068 2071 SendCmd "camera mode ortho" 2069 2072 } else { … … 2071 2074 } 2072 2075 } 2073 " xpan" - "ypan" {2076 "-xpan" - "-ypan" { 2074 2077 PanCamera 2075 2078 } 2076 " qx" - "qy" - "qz" - "qw" {2077 set q [ list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]2079 "-qx" - "-qy" - "-qz" - "-qw" { 2080 set q [ViewToQuaternion] 2078 2081 $_arcball quaternion $q 2079 2082 EventuallyRotate $q 2080 2083 } 2081 " zoom" {2082 SendCmd "camera zoom $_view( zoom)"2084 "-zoom" { 2085 SendCmd "camera zoom $_view(-zoom)" 2083 2086 } 2084 2087 } … … 2588 2591 bottom "0.707107 0.707107 0 0" 2589 2592 } 2590 foreach name { qw qx qyqz } value $positions($side) {2593 foreach name { -qw -qx -qy -qz } value $positions($side) { 2591 2594 set _view($name) $value 2592 2595 } 2593 set q [ list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]2596 set q [ViewToQuaternion] 2594 2597 $_arcball quaternion $q 2595 2598 SendCmd "camera orient $q" 2596 2599 SendCmd "camera reset" 2597 set _view( xpan) 02598 set _view( ypan) 02599 set _view( zoom) 1.02600 set _view(-xpan) 0 2601 set _view(-ypan) 0 2602 set _view(-zoom) 1.0 2600 2603 } 2601 2604
Note: See TracChangeset
for help on using the changeset viewer.