Changeset 6371 for branches/multichoice/gui/scripts/vtkvolumeviewer.tcl
- Timestamp:
- Jun 2, 2016, 8:19:06 AM (8 years ago)
- Location:
- branches/multichoice
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/multichoice
- Property svn:mergeinfo changed
-
branches/multichoice/gui/scripts/vtkvolumeviewer.tcl
r6235 r6371 74 74 private method BuildVolumeComponents {} 75 75 private method BuildVolumeTab {} 76 private method Combo { option }77 76 private method ComputeAlphamap { cname } 78 77 private method ComputeTransferFunction { cname } … … 97 96 private method IsValidObject { dataobj } 98 97 private method LeaveLegend {} 98 private method LegendTitleAction { option } 99 99 private method MotionLegend { x y } 100 100 private method Pan {option x y} … … 109 109 private method ReceiveDataset { args } 110 110 private method ReceiveImage { args } 111 private method ReceiveLegend { colormap title vmin vmax size }111 private method ReceiveLegend { colormap title min max size } 112 112 private method RemoveMarker { x y } 113 113 private method RequestLegend {} … … 115 115 private method Rotate {option x y} 116 116 private method SendTransferFunctions {} 117 private method SetCurrentFieldName { dataobj } 117 118 private method SetInitialTransferFunction { dataobj cname } 118 119 private method SetLegendTip { x y } … … 240 241 array set _settings { 241 242 -axesvisible 1 242 -axisflymode static243 243 -axislabels 1 244 244 -axisminorticks 1 245 -axismode "static" 245 246 -background black 246 247 -color "default" … … 536 537 } 537 538 array set params $settings 538 set params(-description) ""539 set params(-param) ""540 array set params $settings541 539 542 540 if {$params(-color) == "auto" || $params(-color) == "autoreset"} { … … 577 575 set _dlist [lreplace $_dlist $pos $pos] 578 576 array unset _obj2ovride $dataobj-* 579 array unset _settings $dataobj-*580 577 set changed 1 581 578 } … … 638 635 return $dlist 639 636 } 640 -image{637 "-image" { 641 638 if {[llength $args] != 2} { 642 639 error "wrong # args: should be \"get -image view\"" … … 652 649 } 653 650 default { 654 error "bad option \"$op\": should be -objects or -image"651 error "bad option \"$op\": should be -objects, -visible or -image" 655 652 } 656 653 } … … 1004 1001 set _first "" 1005 1002 InitSettings -background \ 1006 -xgrid -ygrid -zgrid -axis flymode \1003 -xgrid -ygrid -zgrid -axismode \ 1007 1004 -axesvisible -axislabels -axisminorticks 1008 1005 StopBufferingCommands … … 1020 1017 if { [info exists _obj2ovride($dataobj-raise)] && $_first == "" } { 1021 1018 set _first $dataobj 1019 SetCurrentFieldName $dataobj 1022 1020 } 1023 1021 foreach cname [$dataobj components] { … … 1066 1064 } 1067 1065 } 1068 $itk_component(field) choices delete 0 end1069 $itk_component(fieldmenu) delete 0 end1070 array unset _fields1071 set _curFldName ""1072 foreach cname [$_first components] {1073 foreach fname [$_first fieldnames $cname] {1074 if { [info exists _fields($fname)] } {1075 continue1076 }1077 foreach { label units components } \1078 [$_first fieldinfo $fname] break1079 # Only scalar fields are valid1080 if {$_allowMultiComponent || $components == 1} {1081 $itk_component(field) choices insert end "$fname" "$label"1082 $itk_component(fieldmenu) add radiobutton -label "$label" \1083 -value $label -variable [itcl::scope _curFldLabel] \1084 -selectcolor red \1085 -activebackground $itk_option(-plotbackground) \1086 -activeforeground $itk_option(-plotforeground) \1087 -font "Arial 8" \1088 -command [itcl::code $this Combo invoke]1089 set _fields($fname) [list $label $units $components]1090 if { $_curFldName == "" } {1091 set _curFldName $fname1092 set _curFldLabel $label1093 }1094 }1095 }1096 }1097 $itk_component(field) value $_curFldLabel1098 1066 } 1099 1067 … … 1331 1299 itcl::body Rappture::VtkVolumeViewer::InitSettings { args } { 1332 1300 foreach spec $args { 1333 if { [info exists _settings($_first${spec})] } {1334 # Reset global setting with dataobj specific setting1335 set _settings($spec) $_settings($_first${spec})1336 }1337 1301 AdjustSetting $spec 1338 1302 } … … 1351 1315 } 1352 1316 switch -- $what { 1353 "-current" { 1354 set cname [$itk_component(volcomponents) value] 1355 SwitchComponent $cname 1317 "-axesvisible" { 1318 set bool $_settings($what) 1319 SendCmd "axis visible all $bool" 1320 } 1321 "-axislabels" { 1322 set bool $_settings($what) 1323 SendCmd "axis labels all $bool" 1324 } 1325 "-axisminorticks" { 1326 set bool $_settings($what) 1327 SendCmd "axis minticks all $bool" 1328 } 1329 "-axismode" { 1330 set mode [$itk_component(axismode) value] 1331 set mode [$itk_component(axismode) translate $mode] 1332 set _settings($what) $mode 1333 SendCmd "axis flymode $mode" 1356 1334 } 1357 1335 "-background" { … … 1368 1346 DrawLegend 1369 1347 } 1370 "-volumeoutline" { 1371 set bool $_settings($what) 1372 SendCmd "outline visible 0" 1373 foreach tag [GetDatasetsWithComponent $_current] { 1374 SendCmd "outline visible $bool $tag" 1375 } 1376 } 1377 "-legendvisible" { 1378 set bool $_settings($what) 1379 if { $bool } { 1380 blt::table $itk_component(plotarea) \ 1381 1,0 $itk_component(legend) -fill x 1382 } else { 1383 blt::table forget $itk_component(legend) 1384 } 1385 } 1386 "-volumevisible" { 1387 set bool $_settings($what) 1388 set _settings($_current${what}) $bool 1389 # Only the data objects in the array _obj2ovride(*-raise) are 1390 # in the working set and can be displayed on screen. The global 1391 # volume control determines whether they are visible. 1392 # 1393 # Note: The use of the current component is a hold over from 1394 # nanovis. If we can't display more than one volume, 1395 # we don't have to limit the effects to a specific 1396 # component. 1397 foreach tag [GetDatasetsWithComponent $_current] { 1398 foreach {dataobj cname} [split $tag -] break 1399 if { [info exists _obj2ovride($dataobj-raise)] } { 1400 SendCmd "volume visible $bool $tag" 1401 } 1402 } 1403 if { $bool } { 1404 Rappture::Tooltip::for $itk_component(volume) \ 1405 "Hide the volume" 1406 } else { 1407 Rappture::Tooltip::for $itk_component(volume) \ 1408 "Show the volume" 1409 } 1410 } 1411 "-volumeblendmode" { 1412 set val [$itk_component(blendmode) value] 1413 set mode [$itk_component(blendmode) translate $val] 1414 set _settings($what) $mode 1415 set _settings($_current${what}) $mode 1416 foreach tag [GetDatasetsWithComponent $_current] { 1417 SendCmd "volume blendmode $mode $tag" 1418 } 1419 } 1420 "-volumeambient" { 1421 # Other parts of the code use the -volumeambient setting to 1422 # tell if the component settings have been initialized 1423 if { ![info exists _settings($_current${what})] } { 1424 InitComponentSettings $_current 1425 } 1426 set val $_settings($what) 1427 set _settings($_current${what}) $val 1428 set ambient [expr {0.01*$val}] 1429 foreach tag [GetDatasetsWithComponent $_current] { 1430 SendCmd "volume shading ambient $ambient $tag" 1431 } 1432 } 1433 "-volumediffuse" { 1434 set val $_settings($what) 1435 set _settings($_current${what}) $val 1436 set diffuse [expr {0.01*$val}] 1437 foreach tag [GetDatasetsWithComponent $_current] { 1438 SendCmd "volume shading diffuse $diffuse $tag" 1439 } 1440 } 1441 "-volumespecularlevel" - "-volumespecularexponent" { 1442 set val $_settings($what) 1443 set _settings($_current${what}) $val 1444 set level [expr {0.01*$val}] 1445 set exp $_settings($what) 1446 foreach tag [GetDatasetsWithComponent $_current] { 1447 SendCmd "volume shading specular $level $exp $tag" 1448 } 1449 } 1450 "-volumelighting" { 1451 set bool $_settings($what) 1452 set _settings($_current${what}) $bool 1453 foreach tag [GetDatasetsWithComponent $_current] { 1454 SendCmd "volume lighting $bool $tag" 1455 } 1456 } 1457 "-volumeopacity" { 1458 set val $_settings($what) 1459 set _settings($_current${what}) $val 1460 set val [expr {0.01*$val}] 1461 foreach tag [GetDatasetsWithComponent $_current] { 1462 SendCmd "volume opacity $val $tag" 1463 } 1464 } 1465 "-volumequality" { 1466 set val $_settings($what) 1467 set _settings($_current${what}) $val 1468 set val [expr {0.01*$val}] 1469 foreach tag [GetDatasetsWithComponent $_current] { 1470 SendCmd "volume quality $val $tag" 1471 } 1472 } 1473 "-axesvisible" { 1474 set bool $_settings($what) 1475 SendCmd "axis visible all $bool" 1476 } 1477 "-axislabels" { 1478 set bool $_settings($what) 1479 SendCmd "axis labels all $bool" 1480 } 1481 "-axisminorticks" { 1482 set bool $_settings($what) 1483 SendCmd "axis minticks all $bool" 1484 } 1485 "-xgrid" - "-ygrid" - "-zgrid" { 1486 set axis [string range $what 1 1] 1487 set bool $_settings($what) 1488 SendCmd "axis grid $axis $bool" 1489 } 1490 "-axisflymode" { 1491 set mode [$itk_component(axismode) value] 1492 set mode [$itk_component(axismode) translate $mode] 1493 set _settings($what) $mode 1494 SendCmd "axis flymode $mode" 1495 } 1496 "-cutplanesvisible" { 1497 set bool $_settings($what) 1498 foreach dataset [CurrentDatasets -visible] { 1499 SendCmd "$_cutplaneCmd visible $bool $dataset" 1500 } 1348 "-color" { 1349 set color [$itk_component(colormap) value] 1350 set _settings($what) $color 1351 set _settings($_current${what}) $color 1352 ResetColormap $_current $color 1353 } 1354 "-current" { 1355 set cname [$itk_component(volcomponents) value] 1356 SwitchComponent $cname 1501 1357 } 1502 1358 "-cutplanelighting" { … … 1524 1380 } 1525 1381 } 1526 "-xcutplanevisible" - "-ycutplanevisible" - "-zcutplanevisible" { 1527 set axis [string range $what 1 1] 1382 "-cutplanesvisible" { 1528 1383 set bool $_settings($what) 1529 if { $bool } {1530 $itk_component(${axis}CutScale) configure -state normal \1531 -troughcolor white1532 } else {1533 $itk_component(${axis}CutScale) configure -state disabled \1534 -troughcolor grey821535 }1536 1384 foreach dataset [CurrentDatasets -visible] { 1537 SendCmd "$_cutplaneCmd axis $axis $bool $dataset" 1538 } 1539 } 1540 "-xcutplaneposition" - "-ycutplaneposition" - "-zcutplaneposition" { 1541 set axis [string range $what 1 1] 1542 set pos [expr $_settings($what) * 0.01] 1543 foreach dataset [CurrentDatasets -visible] { 1544 SendCmd "$_cutplaneCmd slice ${axis} ${pos} $dataset" 1545 } 1546 set _cutplanePending 0 1547 } 1548 "-volumethickness" { 1549 set _settings($_current${what}) $_settings($what) 1550 updateTransferFunctions 1551 } 1552 "-color" { 1553 set color [$itk_component(colormap) value] 1554 set _settings($what) $color 1555 set _settings($_current${what}) $color 1556 ResetColormap $_current $color 1385 SendCmd "$_cutplaneCmd visible $bool $dataset" 1386 } 1557 1387 } 1558 1388 "-field" { … … 1584 1414 SendCmd "camera reset" 1585 1415 DrawLegend 1416 } 1417 "-legendvisible" { 1418 set bool $_settings($what) 1419 if { $bool } { 1420 blt::table $itk_component(plotarea) \ 1421 1,0 $itk_component(legend) -fill x 1422 } else { 1423 blt::table forget $itk_component(legend) 1424 } 1425 } 1426 "-volumeambient" { 1427 # Other parts of the code use the -volumeambient setting to 1428 # tell if the component settings have been initialized 1429 if { ![info exists _settings($_current${what})] } { 1430 InitComponentSettings $_current 1431 } 1432 set val $_settings($what) 1433 set _settings($_current${what}) $val 1434 set ambient [expr {0.01*$val}] 1435 foreach tag [GetDatasetsWithComponent $_current] { 1436 SendCmd "volume shading ambient $ambient $tag" 1437 } 1438 } 1439 "-volumeblendmode" { 1440 set val [$itk_component(blendmode) value] 1441 set mode [$itk_component(blendmode) translate $val] 1442 set _settings($what) $mode 1443 set _settings($_current${what}) $mode 1444 foreach tag [GetDatasetsWithComponent $_current] { 1445 SendCmd "volume blendmode $mode $tag" 1446 } 1447 } 1448 "-volumediffuse" { 1449 set val $_settings($what) 1450 set _settings($_current${what}) $val 1451 set diffuse [expr {0.01*$val}] 1452 foreach tag [GetDatasetsWithComponent $_current] { 1453 SendCmd "volume shading diffuse $diffuse $tag" 1454 } 1455 } 1456 "-volumelighting" { 1457 set bool $_settings($what) 1458 set _settings($_current${what}) $bool 1459 foreach tag [GetDatasetsWithComponent $_current] { 1460 SendCmd "volume lighting $bool $tag" 1461 } 1462 } 1463 "-volumeopacity" { 1464 set val $_settings($what) 1465 set _settings($_current${what}) $val 1466 set val [expr {0.01*$val}] 1467 foreach tag [GetDatasetsWithComponent $_current] { 1468 SendCmd "volume opacity $val $tag" 1469 } 1470 } 1471 "-volumeoutline" { 1472 set bool $_settings($what) 1473 SendCmd "outline visible 0" 1474 foreach tag [GetDatasetsWithComponent $_current] { 1475 SendCmd "outline visible $bool $tag" 1476 } 1477 } 1478 "-volumequality" { 1479 set val $_settings($what) 1480 set _settings($_current${what}) $val 1481 set val [expr {0.01*$val}] 1482 foreach tag [GetDatasetsWithComponent $_current] { 1483 SendCmd "volume quality $val $tag" 1484 } 1485 } 1486 "-volumespecularlevel" - "-volumespecularexponent" { 1487 set val $_settings($what) 1488 set _settings($_current${what}) $val 1489 set level [expr {0.01*$val}] 1490 set exp $_settings($what) 1491 foreach tag [GetDatasetsWithComponent $_current] { 1492 SendCmd "volume shading specular $level $exp $tag" 1493 } 1494 } 1495 "-volumethickness" { 1496 set _settings($_current${what}) $_settings($what) 1497 updateTransferFunctions 1498 } 1499 "-volumevisible" { 1500 set bool $_settings($what) 1501 set _settings($_current${what}) $bool 1502 # Only the data objects in the array _obj2ovride(*-raise) are 1503 # in the working set and can be displayed on screen. The global 1504 # volume control determines whether they are visible. 1505 # 1506 # Note: The use of the current component is a hold over from 1507 # nanovis. If we can't display more than one volume, 1508 # we don't have to limit the effects to a specific 1509 # component. 1510 foreach tag [GetDatasetsWithComponent $_current] { 1511 foreach {dataobj cname} [split $tag -] break 1512 if { [info exists _obj2ovride($dataobj-raise)] } { 1513 SendCmd "volume visible $bool $tag" 1514 } 1515 } 1516 if { $bool } { 1517 Rappture::Tooltip::for $itk_component(volume) \ 1518 "Hide the volume" 1519 } else { 1520 Rappture::Tooltip::for $itk_component(volume) \ 1521 "Show the volume" 1522 } 1523 } 1524 "-xcutplanevisible" - "-ycutplanevisible" - "-zcutplanevisible" { 1525 set axis [string range $what 1 1] 1526 set bool $_settings($what) 1527 if { $bool } { 1528 $itk_component(${axis}CutScale) configure -state normal \ 1529 -troughcolor white 1530 } else { 1531 $itk_component(${axis}CutScale) configure -state disabled \ 1532 -troughcolor grey82 1533 } 1534 foreach dataset [CurrentDatasets -visible] { 1535 SendCmd "$_cutplaneCmd axis $axis $bool $dataset" 1536 } 1537 } 1538 "-xcutplaneposition" - "-ycutplaneposition" - "-zcutplaneposition" { 1539 set axis [string range $what 1 1] 1540 set pos [expr $_settings($what) * 0.01] 1541 foreach dataset [CurrentDatasets -visible] { 1542 SendCmd "$_cutplaneCmd slice ${axis} ${pos} $dataset" 1543 } 1544 set _cutplanePending 0 1545 } 1546 "-xgrid" - "-ygrid" - "-zgrid" { 1547 set axis [string range $what 1 1] 1548 set bool $_settings($what) 1549 SendCmd "axis grid $axis $bool" 1586 1550 } 1587 1551 default { … … 1908 1872 "furthest_triad" "farthest" \ 1909 1873 "outer_edges" "outer" 1910 $itk_component(axismode) value $_settings(-axis flymode)1911 bind $inner.mode <<Value>> [itcl::code $this AdjustSetting -axis flymode]1874 $itk_component(axismode) value $_settings(-axismode) 1875 bind $inner.mode <<Value>> [itcl::code $this AdjustSetting -axismode] 1912 1876 1913 1877 blt::table $inner \ … … 2174 2138 radiobutton $inner.vtk_button -text "VTK data file" \ 2175 2139 -variable [itcl::scope _downloadPopup(format)] \ 2176 -font " Helvetica 9" \2140 -font "Arial 9" \ 2177 2141 -value vtk 2178 2142 Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file." … … 2252 2216 2253 2217 # ---------------------------------------------------------------------- 2254 # USAGE: ReceiveLegend <colormap> <title> < vmin> <vmax> <size>2218 # USAGE: ReceiveLegend <colormap> <title> <min> <max> <size> 2255 2219 # 2256 2220 # Invoked automatically whenever the "legend" command comes in from … … 2258 2222 # specified <size> will follow. 2259 2223 # ---------------------------------------------------------------------- 2260 itcl::body Rappture::VtkVolumeViewer::ReceiveLegend { colormap title vmin vmax size } {2224 itcl::body Rappture::VtkVolumeViewer::ReceiveLegend { colormap title min max size } { 2261 2225 if { [isconnected] } { 2262 2226 set bytes [ReceiveBytes $size] … … 2428 2392 2429 2393 # ---------------------------------------------------------------------- 2430 # USAGE: _dropdown post 2431 # USAGE: _dropdown unpost 2432 # USAGE: _dropdown select 2433 # 2434 # Used internally to handle the dropdown list for this combobox. The 2435 # post/unpost options are invoked when the list is posted or unposted 2436 # to manage the relief of the controlling button. The select option 2437 # is invoked whenever there is a selection from the list, to assign 2438 # the value back to the gauge. 2439 # ---------------------------------------------------------------------- 2440 itcl::body Rappture::VtkVolumeViewer::Combo {option} { 2394 # USAGE: LegendTitleAction post 2395 # USAGE: LegendTitleAction enter 2396 # USAGE: LegendTitleAction leave 2397 # USAGE: LegendTitleAction save 2398 # 2399 # Used internally to handle the dropdown list for the fields menu combobox. 2400 # The post option is invoked when the field title is pressed to launch the 2401 # dropdown. The enter option is invoked when the user mouses over the field 2402 # title. The leave option is invoked when the user moves the mouse away 2403 # from the field title. The save option is invoked whenever there is a 2404 # selection from the list, to alert the visualization server. 2405 # ---------------------------------------------------------------------- 2406 itcl::body Rappture::VtkVolumeViewer::LegendTitleAction {option} { 2441 2407 set c $itk_component(view) 2442 2408 switch -- $option { … … 2448 2414 tk_popup $itk_component(fieldmenu) $x $y 2449 2415 } 2450 activate{2416 enter { 2451 2417 $c itemconfigure title -fill red 2452 2418 } 2453 deactivate {2419 leave { 2454 2420 $c itemconfigure title -fill $itk_option(-plotforeground) 2455 2421 } 2456 invoke {2422 save { 2457 2423 $itk_component(field) value $_curFldLabel 2458 2424 AdjustSetting -field 2459 2425 } 2460 2426 default { 2461 error "bad option \"$option\": should be post, unpost, select"2427 error "bad option \"$option\": should be post, enter, leave or save" 2462 2428 } 2463 2429 } … … 2510 2476 } else { 2511 2477 # $n : absolute value, compute relative 2512 lappend list [expr {(double($value)-$min)/($max-$min)]}2478 lappend list [expr {(double($value)-$min)/($max-$min)}] 2513 2479 } 2514 2480 } … … 2865 2831 return [ColorsToColormap $color] 2866 2832 } 2833 2834 itcl::body Rappture::VtkVolumeViewer::SetCurrentFieldName { dataobj } { 2835 set _first $dataobj 2836 $itk_component(field) choices delete 0 end 2837 $itk_component(fieldmenu) delete 0 end 2838 array unset _fields 2839 set _curFldName "" 2840 foreach cname [$_first components] { 2841 foreach fname [$_first fieldnames $cname] { 2842 if { [info exists _fields($fname)] } { 2843 continue 2844 } 2845 foreach { label units components } \ 2846 [$_first fieldinfo $fname] break 2847 # Only scalar fields are valid 2848 if {$_allowMultiComponent || $components == 1} { 2849 $itk_component(field) choices insert end "$fname" "$label" 2850 $itk_component(fieldmenu) add radiobutton -label "$label" \ 2851 -value $label -variable [itcl::scope _curFldLabel] \ 2852 -selectcolor red \ 2853 -activebackground $itk_option(-plotbackground) \ 2854 -activeforeground $itk_option(-plotforeground) \ 2855 -font "Arial 8" \ 2856 -command [itcl::code $this LegendTitleAction save] 2857 set _fields($fname) [list $label $units $components] 2858 if { $_curFldName == "" } { 2859 set _curFldName $fname 2860 set _curFldLabel $label 2861 } 2862 } 2863 } 2864 } 2865 $itk_component(field) value $_curFldLabel 2866 }
Note: See TracChangeset
for help on using the changeset viewer.