Changeset 3289
- Timestamp:
- Feb 9, 2013, 4:06:03 PM (12 years ago)
- Location:
- branches/Rappture 1.2
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Rappture 1.2/examples/zoo/field/tool.xml
r1587 r3289 46 46 <value>nanovis</value> 47 47 </option> 48 <default> nanovis</default>48 <default>vtk</default> 49 49 </choice> 50 50 </input> -
branches/Rappture 1.2/gui/scripts/cloud.tcl
r3288 r3289 157 157 } 158 158 } 159 parray _limits160 159 append out "DATASET POLYDATA\n" 161 160 append out "POINTS $_numPoints float\n" -
branches/Rappture 1.2/gui/scripts/field.tcl
r3288 r3289 16 16 package require BLT 17 17 18 namespace eval Rappture { # forward declaration } 18 namespace eval Rappture { 19 # forward declaration 20 } 21 22 # 23 # Possible field types: 24 # 25 # unirect2d -- heightmap. if extents > 1, flow. 26 # unirect3d -- flow 27 # cloud (2d) -- contour 28 # cloud (3d) -- isosurface 29 # mesh (3d) -- isosurface 30 # mesh (2d) -- coutour 31 # dx -- volume 32 # ucd -- isosurface 33 # vtk (3d) -- isosurface 34 # vtk (2d) -- contour 35 # 36 # Types: 37 # Format Dim Description Viewer Server 38 # vtk 2 vtk file data. contour vtkvis 39 # vtk 3 vtk file data. isosurface vtkvis 40 # mesh 2 points-on-mesh heightmap vtkvis 41 # mesh 3 points-on-mesh isosurface vtkvis 42 # dx 3 DX volume nanovis 43 # unirect2d 2 unirect3d + extents > 1 flow flow nanovis 44 # unirect3d 3 unirect2d + extents > 1 flow flow nanovis 45 # 19 46 20 47 itcl::class Rappture::Field { 21 constructor {xmlobj path} { # defined below } 22 destructor { # defined below } 23 48 private variable _dim 0; # Dimension of mesh 49 private variable _xmlobj "" ; # ref to XML obj with device data 50 private variable _limits ; # maps box name => {z0 z1} limits 51 private variable _field "" 52 private variable _fieldNames "" ; # list of field names. 53 private variable _fieldUnits "" ; # list of units of each field name. 54 private variable _fieldLabels "" ; # list of labels of each field name. 55 private variable _viewer "auto" 56 57 constructor {xmlobj path} { 58 # defined below 59 } 60 destructor { 61 # defined below 62 } 24 63 public method components {args} 25 64 public method mesh {{cname -overall}} … … 40 79 public method vtkdata {cname} 41 80 42 protected method _build {}81 protected method Build {} 43 82 protected method _getValue {expr} 44 83 45 private variable _dim 0; # Dimension of mesh46 private variable _xmlobj "" ; # ref to XML obj with device data47 84 private variable _path ""; # Path of this object in the XML 48 85 private variable _units "" ; # system of units for this field 49 private variable _limits ;# maps box name => {z0 z1} limits50 86 private variable _zmax 0 ;# length of the device 51 87 52 private variable _field ""53 private variable _fieldNames "" ;# list of field names.54 private variable _fieldUnits "" ;# list of units of each field name.55 private variable _fieldLabels "" ;# list of labels of each field name.56 88 private variable _comp2dims ;# maps component name => dimensionality 57 89 private variable _comp2xy ;# maps component name => x,y vectors 58 private variable _comp2vtk ;# maps component name => vtkFloatArray59 private variable _comp2vtkstreamlines ;# maps component name => vtkFloatArray60 90 private variable _comp2isosurface ;# maps component name => vtkFloatArray 61 private variable _comp2vtkcontour ;# maps component name => vtkFloatArray 62 private variable _comp2vtkvolume ;# maps component name => vtkFloatArray 91 private variable _comp2vtk ;# maps component name => vtk file data 63 92 private variable _comp2volume ;# maps component name => vtkFloatArray 64 93 private variable _comp2dx ;# maps component name => OpenDX data … … 71 100 private variable _type "" 72 101 private variable _comp2flowhints 73 private variable _comp2 heightmap102 private variable _comp2mesh 74 103 private common _counter 0 ;# counter for unique vector names 75 104 … … 77 106 private method ConvertToVtkData { cname } 78 107 private method ReadVtkDataSet { cname contents } 79 private variable _isVtk108 private method AvsToVtk { cname contents } 80 109 private variable _values "" 81 private variable _viewer "vtkcontour"82 110 } 83 111 … … 122 150 123 151 # build up vectors for various components of the field 124 _build152 Build 125 153 } 126 154 … … 135 163 eval blt::vector destroy $_comp2xy($name) 136 164 } 137 foreach name [array names _comp2vtk] {138 set mobj [lindex $_comp2vtk($name) 0]139 set class [$mobj info class]140 ${class}::release $mobj141 142 set fobj [lindex $_comp2vtk($name) 1]143 rename $fobj ""144 }145 165 foreach name [array names _comp2unirect2d] { 146 166 itcl::delete object $_comp2unirect2d($name) … … 152 172 itcl::delete object $_comp2flowhints($name) 153 173 } 154 foreach name [array names _comp2isosurface] { 155 set mesh [lindex $_comp2isosurface($name) 0] 174 foreach name [array names _comp2mesh] { 175 # Data is in the form of a mesh and a vector. 176 foreach { mesh vector } $_comp2mesh($name) break 177 # Release the mesh (may be shared) 156 178 set class [$mesh info class] 157 179 ${class}::release $mesh 158 set vtkarray [lindex $_comp2isosurface($name) 1] 159 rename $vtkarray "" 160 } 161 foreach name [array names _comp2heightmap] { 162 set mesh [lindex $_comp2heightmap($name) 0] 163 set class [$mesh info class] 164 ${class}::release $mesh 165 166 set vtkarray [lindex $_comp2heightmap($name) 1] 167 rename $vtkarray "" 180 # Destroy the vector 181 blt::vector destroy $vector 168 182 } 169 183 } … … 227 241 return [lindex $_comp2xy($cname) 0] ;# return xv 228 242 } 229 if { [info exists _comp2vtkstreamlines($cname)] } {230 puts stderr "comp2vtkstreamlines"231 error "mesh: not implemented for streamlines"232 return [$mobj mesh]233 }234 if { [info exists _comp2vtkcontour($cname)] } {235 puts stderr "comp2vtkcontour"236 error "method \"mesh\" is not implemented for vtkcontour"237 }238 243 if { [info exists _comp2vtk($cname)] } { 239 set mobj [lindex $_comp2vtk($cname) 0] 240 puts stderr "comp2vtk mobj=$mobj mesh=[$mobj mesh]"241 return [$mobj mesh]244 # FIXME: extract mesh from VTK file data. 245 puts stderr "comp2vtk" 246 error "method \"mesh\" is not implemented for VTK file data" 242 247 } 243 248 if {[info exists _comp2dx($cname)]} { … … 245 250 return "" ;# no mesh -- it's embedded in the value data 246 251 } 247 if {[info exists _comp2heightmap($cname)]} { 248 puts stderr "comp2heightmap" 249 return "" ;# no mesh -- it's embedded in the value data 250 } 251 if {[info exists _comp2isosurface($cname)]} { 252 puts stderr "comp2isosurface" 253 return "" ;# no mesh -- it's embedded in the value data 254 } 255 if {[info exists _comp2vtkvolume($cname)]} { 256 puts stderr "comp2vtkvolume" 252 if {[info exists _comp2mesh($cname)]} { 253 puts stderr "comp2mesh" 257 254 return "" ;# no mesh -- it's embedded in the value data 258 255 } … … 284 281 return [lindex $_comp2xy($cname) 1] ;# return yv 285 282 } 286 if { [info exists _comp2vtkcontour($cname)] } { 287 error "method \"values\" is not implemented for vtkcontour" 288 } 289 if { [info exists _comp2heightmap($cname)] } { 290 return $_values 291 } 292 if { [info exists _comp2isosurface($cname)] } { 293 return $_values 294 } 295 if { [info exists _comp2vtkstreamlines($cname)] } { 296 # FIXME: Need to process the vtk file data to pull out the field's 297 # values. 298 error "vtkstreamlines: values not implemented" 299 return [lindex $_comp2vtkstreamlines($cname) 1] 300 } 283 # VTK file data 301 284 if { [info exists _comp2vtk($cname)] } { 302 return [lindex $_comp2vtk($cname) 1] ;# return vtkFloatArray 285 # FIXME: extract the values from the VTK file data 286 error "method \"values\" is not implemented for vtk file data" 287 } 288 # Points-on-mesh 289 if { [info exists _comp2mesh($cname)] } { 290 set vector [lindex $_comp2mesh($cname) 1] 291 return [$vector range 0 end] 303 292 } 304 293 if {[info exists _comp2dx($cname)]} { … … 327 316 } 328 317 if { [info exists _comp2vtk($cname)] } { 329 return "" 330 } 331 if { [info exists _comp2vtkvolume($cname)] } { 332 return $_comp2vtkvolume($cname) 333 } 334 if { [info exists _comp2vtkcontour($cname)] } { 335 return $_comp2vtkcontour($cname) 336 } 337 if { [info exists _comp2vtkstreamlines($cname)] } { 338 # Return the contents of the vtk file. 339 return $_comp2vtkstreamlines($cname) 318 error "blob not implemented for VTK file data" 340 319 } 341 320 if {[info exists _comp2dx($cname)]} { … … 420 399 foreach {axisMin axisMax} $limits break 421 400 set axis v 422 } elseif {[info exists _comp2vtk($cname)]} { 423 foreach {xv yv} $_comp2vtk($cname) break 424 switch -- $which { 425 x - xlin - xlog { 426 foreach {axisMin axisMax} [$xv limits x] break 427 set axis x 428 } 429 y - ylin - ylog { 430 foreach {axisMin axisMax} [$xv limits y] break 431 set axis y 432 } 433 z - zlin - zlog { 434 foreach {axisMin axisMax} [$xv limits z] break 435 set axis z 436 } 437 v - vlin - vlog { 438 catch {unset style} 439 array set style $_comp2style($cname) 440 if {[info exists style(-min)] && 441 [info exists style(-max)]} { 442 # This component has its own hard-coded 443 # min/max range. Ignore it for overall limits. 444 set axisMin $min 445 set axisMax $max 446 } else { 447 foreach {axisMin axisMax} [$yv GetRange] break 448 } 449 set axis v 450 } 451 default { 452 error "bad option \"$which\": should be x, xlin, xlog, y, ylin, ylog, v, vlin, vlog" 453 } 454 } 455 } elseif {[info exists _comp2heightmap($cname)]} { 456 foreach {mesh vector} $_comp2heightmap($cname) break 401 } elseif {[info exists _comp2mesh($cname)]} { 402 foreach {mesh vector} $_comp2mesh($cname) break 457 403 switch -- $which { 458 404 x - xlin - xlog { … … 608 554 set value [lindex $args 1] 609 555 $_xmlobj put $path.current $value 610 _build556 Build 611 557 } 612 558 default { … … 680 626 681 627 # ---------------------------------------------------------------------- 682 # USAGE: _build628 # USAGE: Build 683 629 # 684 630 # Used internally to build up the vector representation for the … … 687 633 # from scratch. 688 634 # ---------------------------------------------------------------------- 689 itcl::body Rappture::Field:: _build {} {635 itcl::body Rappture::Field::Build {} { 690 636 691 637 # Discard any existing data … … 693 639 eval blt::vector destroy $_comp2xy($name) 694 640 } 695 foreach name [array names _comp2vtk] { 696 set mobj [lindex $_comp2vtk($name) 0] 697 set class [$mobj info class] 698 ${class}::release $mobj 699 700 set fobj [lindex $_comp2vtk($name) 1] 701 rename $fobj "" 702 } 641 array unset _comp2vtk 703 642 foreach name [array names _comp2unirect2d] { 704 643 eval itcl::delete object $_comp2unirect2d($name) … … 708 647 } 709 648 catch {unset _comp2xy} 710 catch {unset _comp2vtk}711 649 catch {unset _comp2dx} 712 650 catch {unset _comp2dims} 713 651 catch {unset _comp2style} 714 array unset _comp2volume715 array unset _comp2vtkstreamlines716 652 array unset _comp2unirect2d 717 653 array unset _comp2unirect3d … … 725 661 set type "" 726 662 if { ([$_field element $cname.constant] != "" && 727 728 [$_field element $cname.xy] != ""} {663 [$_field element $cname.domain] != "") || 664 [$_field element $cname.xy] != "" } { 729 665 set type "1D" 730 } elseif { [$_field element $cname.mesh] != "" &&731 666 } elseif { [$_field element $cname.mesh] != "" && 667 [$_field element $cname.values] != ""} { 732 668 set type "points-on-mesh" 733 } elseif {[$_field element $cname.vtk] != ""} { 734 set _isVtkData($cname) 1 735 set view [$_field get "about.view"] 736 switch -- $view { 737 "streamlines" { 738 set type "vtkstreamlines" 739 } 740 "contour" - "heightmap" { 741 set type "vtkcontour" 742 } 743 default { 744 set type "vtk" 745 } 746 } 669 } elseif { [$_field element $cname.vtk] != ""} { 670 set viewer [$_field get "about.view"] 671 set type "vtk" 672 if { $viewer != "" } { 673 set _viewer $viewer 674 } 747 675 } elseif {[$_field element $cname.opendx] != ""} { 748 676 global env … … 769 697 } 770 698 set _comp2extents($cname) $extents 771 puts stderr "type=$type"772 699 set _type $type 773 700 if {$type == "1D"} { … … 823 750 BuildPointsOnMesh $cname 824 751 } elseif {$type == "vtk"} { 825 #826 # Extract native vtk data from the XML and use a reader827 # to load it.828 #829 error "not implemented"830 } elseif {$type == "vtkstreamlines"} {831 set _comp2dims($cname) "3D"832 # Allow redirects to another element.833 752 set vtkdata [$_field get $cname.vtk] 834 set _comp2vtkstreamlines($cname) $vtkdata 835 set _comp2style($cname) [$_field get $cname.style] 836 incr _counter 837 } elseif {$type == "vtkcontour"} { 838 set _comp2dims($cname) "2D" 839 # Allow redirects to another element. 840 841 set data [$_field get $cname.vtk] 842 ReadVtkDataSet $cname $data 843 set _comp2vtkcontour($cname) $data 844 set _comp2style($cname) [$_field get $cname.style] 845 incr _counter 846 } elseif {$type == "vtkvolume"} { 847 set _comp2dims($cname) "3D" 848 # Allow redirects to another element. 849 set data [$_field get -decode no $cname.dx] 850 set data [Rappture::encoding::decode -as zb64 $data] 851 if 1 { 852 set file "/tmp/$cname.dx" 853 set f [open $file "w"] 854 puts $f $data 855 close $f 856 } 857 set data [Rappture::ConvertDxToVtk $data] 858 if 1 { 859 set file "/tmp/$cname.vtk" 860 set f [open $file "w"] 861 puts $f $data 862 close $f 863 } 864 set _comp2vtkvolume($cname) $data 865 set _comp2style($cname) [$_field get $cname.style] 866 incr _counter 867 } elseif {$type == "vtkstreamlines2"} { 868 set _comp2dims($cname) "3D" 869 set _comp2vtkstreamlines($cname) [$_field get $cname.vtk] 753 ReadVtkDataSet $cname $vtkdata 754 set _comp2vtk($cname) $vtkdata 870 755 set _comp2style($cname) [$_field get $cname.style] 871 756 incr _counter … … 876 761 # off to the NanoVis visualizer. 877 762 # 763 set _viewer "nanovis" 878 764 set _comp2dims($cname) "3D" 879 765 set _comp2dx($cname) [$_field get -decode no $cname.dx] … … 902 788 # off to the NanoVis visualizer. 903 789 # 790 set _viewer "nanovis" 904 791 set _comp2dims($cname) "3D" 905 792 set data [$_field get -decode yes $cname.opendx] … … 912 799 [Rapture::FlowHints ::\#auto $_field $cname $_units] 913 800 } 801 incr _counter 802 } elseif {[$_field element $cname.ucd] != ""} { 803 set _viewer "isosurface" 804 set _comp2dims($cname) "3D" 805 set contents [$_field get $cname.ucd] 806 set vtkdata [AvsToVtk $cname $contents] 807 ReadVtkDataSet $cname $vtkdata 808 set _comp2vtk($cname) $vtkdata 809 set _comp2style($cname) [$_field get $cname.style] 914 810 incr _counter 915 811 } … … 1071 967 [$ds GetPointData] SetScalars $val 1072 968 } 1073 " vtkcontour" {969 "contour" { 1074 970 return [$dataobj blob $cname] 1075 971 } … … 1079 975 default { 1080 976 set mesh [$dataobj mesh $cname] 1081 puts stderr "dataobj=$dataobj, mesh=$mesh"1082 977 switch -- [$mesh GetClassName] { 1083 978 vtkPoints { … … 1160 1055 incr _dim 1161 1056 } 1057 if { $_dim == 2 } { 1058 set _viewer heightmap 1059 } else { 1060 set _viewer isosurface 1061 } 1062 set _comp2dims($cname) ${_dim}D 1162 1063 lappend limits xmin $xmin xmax $xmax ymin $ymin ymax $ymax 1163 1064 set dataAttrs [$dataset GetPointData] … … 1204 1105 set cname "component" 1205 1106 } 1206 if { [info exists _comp2vtkstreamlines($cname)] } { 1207 return $_comp2vtkstreamlines($cname) 1208 } 1209 if { [info exists _comp2vtkvolume($cname)] } { 1210 return $_comp2vtkvolume($cname) 1211 } 1107 # DX: Convert DX to VTK 1212 1108 if {[info exists _comp2dx($cname)]} { 1213 return $_comp2dx($cname) 1214 } 1109 return [Rappture::ConvertDxToVtk $_comp2dx($cname)] 1110 } 1111 # Unirect3d: isosurface 1215 1112 if {[info exists _comp2unirect3d($cname)]} { 1216 return [$_comp2unirect3d($cname) blob] 1217 } 1218 if { [info exists _comp2vtkcontour($cname)] && $_dim == 2 } { 1219 return $_comp2vtkcontour($cname) 1220 } 1113 return [$_comp2unirect3d($cname) vtkdata] 1114 } 1115 # VTK file data: 1221 1116 if { [info exists _comp2vtk($cname)] } { 1222 1117 return $_comp2vtk($cname) 1223 1118 } 1224 if { [info exists _comp2heightmap($cname)] } { 1119 # Points on mesh: Construct VTK file output. 1120 if { [info exists _comp2mesh($cname)] } { 1121 # Data is in the form mesh and vector 1122 foreach {mesh vector} $_comp2mesh($cname) break 1225 1123 set label [hints zlabel] 1226 1124 if { $label == "" } { … … 1229 1127 regsub -all { } $label {_} label 1230 1128 } 1231 foreach {mesh vector} $_comp2heightmap($cname) break1232 1129 append out "# vtk DataFile Version 3.0\n" 1233 1130 append out "[hints label]\n" … … 1239 1136 return $out 1240 1137 } 1241 if { [info exists _comp2isosurface($cname)] } {1242 set label [hints zlabel]1243 if { $label == "" } {1244 set label $cname1245 } else {1246 regsub -all { } $label {_} label1247 }1248 foreach {mesh vector} $_comp2isosurface($cname) break1249 append out "# vtk DataFile Version 3.0\n"1250 append out "[hints label]\n"1251 append out "ASCII\n"1252 append out [$mesh vtkdata]1253 append out "SCALARS $label float\n"1254 append out "LOOKUP_TABLE default\n"1255 append out "[$vector range 0 end]\n"1256 return $out1257 }1258 1138 error "can't find vtkdata for $cname. This method should only be called by the vtkheightmap widget" 1259 1139 } … … 1262 1142 # 1263 1143 # More complex 2D/3D data is represented by a mesh 1264 # object and an associated vtkFloatArray for field 1265 # values. 1144 # object and an associated vector for field values. 1266 1145 # 1267 1146 set path [$_field get $cname.mesh] … … 1274 1153 lappend _fieldLabels $cname 1275 1154 lappend _fieldUnits "" 1155 1276 1156 # Handle bizarre cases that hopefully will be deprecated. 1277 1157 if { $element == "unirect3d" } { … … 1282 1162 } 1283 1163 set _dim 3 1164 set _viewer flowvis 1284 1165 set _comp2dims($cname) "3D" 1285 1166 set _comp2unirect3d($cname) \ … … 1300 1181 } 1301 1182 set _dim 2 1183 set _viewer "flowvis" 1302 1184 set _comp2dims($cname) "2D" 1303 1185 set _comp2unirect2d($cname) \ … … 1310 1192 return 1311 1193 } 1194 set _viewer "contour" 1312 1195 switch -- $element { 1313 1196 "cloud" { … … 1319 1202 "unirect2d" { 1320 1203 set mesh [Rappture::Unirect2d::fetch $_xmlobj $path] 1321 set _viewer " vtkheightmap"1204 set _viewer "heightmap" 1322 1205 } 1323 1206 } 1324 1207 set _dim [$mesh dimensions] 1325 puts stderr "mesh=$mesh dim=[$mesh dimensions]"1326 1208 if {$_dim == 1} { 1327 1209 # Is this used anywhere? … … 1342 1224 incr _counter 1343 1225 return 1226 } elseif {$_dim == 2} { 1227 set _type "heightmap" 1228 set vector [blt::vector create \#auto] 1229 $vector set [$_field get $cname.values] 1230 set _comp2dims($cname) "[$mesh dimensions]D" 1231 set _comp2mesh($cname) [list $mesh $vector] 1232 set _comp2style($cname) [$_field get $cname.style] 1233 incr _counter 1234 set label [hints zlabel] 1235 if { $label != "" } { 1236 set _fieldNames $label 1237 regsub -all { } $_fieldNames {_} _fieldNames 1238 set _fieldLabels $label 1239 } 1240 set units [hints zunits] 1241 if { $units != "" } { 1242 set _fieldUnits $units 1243 } 1244 return 1344 1245 } elseif {$_dim == 3} { 1345 1246 # … … 1355 1256 $farray InsertNextValue $v 1356 1257 } 1357 set _viewer " vtkisosurface"1358 set _type " vtkisosurface"1258 set _viewer "isosurface" 1259 set _type "isosurface" 1359 1260 set vector [blt::vector create \#auto] 1360 1261 $vector set [$_field get $cname.values] 1361 1262 set _comp2dims($cname) "[$mesh dimensions]D" 1362 set _comp2 isosurface($cname) [list $mesh $vector]1263 set _comp2mesh($cname) [list $mesh $vector] 1363 1264 set _comp2style($cname) [$_field get $cname.style] 1364 1265 incr _counter … … 1374 1275 } 1375 1276 return 1376 } elseif {$_dim == 2} {1377 set _type "vtkheightmap"1378 set vector [blt::vector create \#auto]1379 $vector set [$_field get $cname.values]1380 set _comp2dims($cname) "[$mesh dimensions]D"1381 set _comp2heightmap($cname) [list $mesh $vector]1382 set _comp2style($cname) [$_field get $cname.style]1383 incr _counter1384 set label [hints zlabel]1385 if { $label != "" } {1386 set _fieldNames $label1387 regsub -all { } $_fieldNames {_} _fieldNames1388 set _fieldLabels $label1389 }1390 set units [hints zunits]1391 if { $units != "" } {1392 set _fieldUnits $units1393 }1394 return1395 1277 } 1396 1278 error "unhandled case in field" 1397 1279 } 1280 1281 itcl::body Rappture::Field::AvsToVtk { comp contents } { 1282 package require vtk 1283 1284 set reader $this-datasetreader 1285 vtkAVSucdReader $reader 1286 1287 # Write the contents to a file just in case it's binary. 1288 set tmpfile file[pid].vtk 1289 set f [open "$tmpfile" "w"] 1290 fconfigure $f -translation binary -encoding binary 1291 puts $f $contents 1292 close $f 1293 $reader SetFileName $tmpfile 1294 $reader Update 1295 file delete $tmpfile 1296 1297 set output [$reader GetOutput] 1298 set pointData [$output GetPointData] 1299 set _scalars {} 1300 for { set i 0 } { $i < [$pointData GetNumberOfArrays] } { incr i } { 1301 set name [$pointData GetArrayName $i] 1302 lappend _scalars $name $name "???" 1303 } 1304 set writer $this-datasetwriter 1305 vtkDataSetWriter $writer 1306 $writer SetInputConnection [$reader GetOutputPort] 1307 $writer SetFileName $tmpfile 1308 $writer Write 1309 rename $reader "" 1310 rename $writer "" 1311 set f [open "$tmpfile" "r"] 1312 fconfigure $f -translation binary -encoding binary 1313 set vtkdata [read $f] 1314 file delete $tmpfile 1315 close $f 1316 return $vtkdata 1317 } -
branches/Rappture 1.2/gui/scripts/field2dresult.tcl
r3216 r3289 31 31 itk_option define -mode mode Mode "auto" 32 32 33 constructor {args} { # defined below } 34 destructor { # defined below } 33 constructor {args} { 34 # defined below 35 } 36 destructor { 37 # defined below 38 } 35 39 36 40 public method add {dataobj {settings ""}} … … 39 43 public method scale {args} 40 44 public method snap {w h} 41 public method parameters {title args} { # do nothing } 45 public method parameters {title args} { 46 # do nothing 47 } 42 48 public method download {option args} 43 49 } … … 57 63 array set flags $args 58 64 set servers "" 65 puts stderr "field2d mode=$flags(-mode)" 59 66 switch -- $flags(-mode) { 60 " auto" - "heightmap" - "flowvis" {67 "flowvis" { 61 68 set servers [Rappture::VisViewer::GetServerList "nanovis"] 62 69 } 63 " vtkcontour" - "vtkheightmap" - "vtkstreamlines" - "vtkviewer" {70 "auto" - "contour" - "heightmap" - "streamlines" - "vtkviewer" { 64 71 set servers [Rappture::VisViewer::GetServerList "vtkvis"] 65 72 } … … 73 80 if {"" != $servers && $flags(-mode) != "vtk"} { 74 81 switch -- $flags(-mode) { 75 " auto" - "heightmap" {82 "heightmap" { 76 83 itk_component add renderer { 77 Rappture::HeightmapViewer $itk_interior.ren $servers 84 Rappture::VtkHeightmapViewer $itk_interior.heightmap \ 85 $servers -mode heightmap 78 86 } 79 87 } 80 88 "flowvis" { 81 89 itk_component add renderer { 82 Rappture::FlowvisViewer $itk_interior. ren$servers90 Rappture::FlowvisViewer $itk_interior.flow $servers 83 91 } 84 92 } 85 " vtkcontour" {93 "contour" { 86 94 itk_component add renderer { 87 Rappture::VtkHeightmapViewer $itk_interior. ren $servers\88 -mode $flags(-mode)95 Rappture::VtkHeightmapViewer $itk_interior.contour \ 96 $servers -mode contour 89 97 } 90 98 } 91 " vtkheightmap" {99 "streamlines" { 92 100 itk_component add renderer { 93 Rappture::VtkHeightmapViewer $itk_interior.ren $servers \ 94 -mode $flags(-mode) 95 } 96 } 97 "vtkstreamlines" { 98 itk_component add renderer { 99 Rappture::VtkStreamlinesViewer $itk_interior.ren $servers 101 Rappture::VtkStreamlinesViewer $itk_interior.streamlines \ 102 $servers 100 103 } 101 104 } 102 105 "vtkviewer" { 103 106 itk_component add renderer { 104 Rappture::VtkViewer $itk_interior. ren$servers107 Rappture::VtkViewer $itk_interior.viewer $servers 105 108 } 106 109 } … … 115 118 } 116 119 } 117 118 120 if {![info exists itk_component(renderer)]} { 119 121 itk_component add renderer { 120 Rappture::ContourResult $itk_interior. ren122 Rappture::ContourResult $itk_interior.oldcontour 121 123 } 122 124 pack $itk_component(renderer) -expand yes -fill both 123 125 } 124 126 eval itk_initialize $args 127 update 125 128 } 126 129 -
branches/Rappture 1.2/gui/scripts/field3dresult.tcl
r3288 r3289 54 54 -mode auto 55 55 } 56 array set flags $args 57 switch -- $flags(-mode) { 56 array set flags $args 57 puts stderr "field3d mode=$flags(-mode)" 58 switch -- $flags(-mode) { 58 59 "auto" - "nanovis" - "flowvis" { 59 60 set servers [Rappture::VisViewer::GetServerList "nanovis"] 60 61 } 61 " vtkisosurface" - "vtkheightmap" - "vtkstreamlines" - "vtkviewer" - "vtkvolume" {62 "isosurface" - "heightmap" - "streamlines" - "vtkviewer" - "vtkvolume" { 62 63 set servers [Rappture::VisViewer::GetServerList "vtkvis"] 63 64 } … … 70 71 } 71 72 } 73 puts stderr "field3d: servers=$servers flags(-mode)=$flags(-mode)" 72 74 if {"" != $servers && $flags(-mode) != "vtk"} { 73 75 switch -- $flags(-mode) { … … 82 84 } 83 85 } 84 " vtkcontour" - "vtkheightmap" {86 "contour" - "heightmap" { 85 87 itk_component add renderer { 86 88 Rappture::VtkHeightmapViewer $itk_interior.ren $servers 87 89 } 88 90 } 89 " vtkisosurface" {91 "isosurface" { 90 92 itk_component add renderer { 91 93 Rappture::VtkIsosurfaceViewer $itk_interior.ren $servers 92 94 } 93 95 } 94 " vtkstreamlines" {96 "streamlines" { 95 97 itk_component add renderer { 96 98 Rappture::VtkStreamlinesViewer $itk_interior.ren $servers -
branches/Rappture 1.2/gui/scripts/mesh.tcl
r3288 r3289 180 180 foreach cname [$_mesh children] { 181 181 foreach type { vtk cloud grid triangles cells } { 182 if { [$_mesh element $type] != ""} {182 if { $cname == $type } { 183 183 incr subcount 184 184 break … … 189 189 foreach cname [$_mesh children] { 190 190 foreach type { node element } { 191 if { [$_mesh element $type] != ""} {191 if { $cname == $type } { 192 192 incr elemcount 193 193 break … … 1082 1082 set type "nodeselements" 1083 1083 # create the vtk objects containing points and connectivity 1084 set _dim 2 1085 # 1086 # Extract each node and add it to the points list. 1087 # 1084 set _dim 3 1088 1085 set points {} 1089 1086 set count 0 1087 # Scan for nodes. Each node represents a vertex. 1090 1088 foreach comp [$xmlobj children -type node $path] { 1091 1089 set xyz [$xmlobj get $path.$comp] … … 1099 1097 foreach {x y z} $xyz break 1100 1098 foreach dim {x y z} units $_units { 1101 1099 set v [Rappture::Units::convert [set $dim] \ 1102 1100 -context $units -to $units -units off] 1103 1101 … … 1127 1125 } 1128 1126 set count 0 1127 set numCells 0 1129 1128 set celltypes {} 1130 1129 set data {} 1130 # Next scan for elements. Each element represents a cell. 1131 1131 foreach comp [$xmlobj children -type element $path] { 1132 1132 set nlist [$_mesh get $comp.nodes] … … 1138 1138 append celltypes " $celltype\n" 1139 1139 append data " $numNodes $nlist\n" 1140 incr numCells 1141 incr count $numNodes 1140 1142 incr count 1141 1143 } … … 1143 1145 append out "POINTS $_numPoints float\n" 1144 1146 append out $points 1145 append out "CELLS $ count [expr $count * 4]\n"1147 append out "CELLS $numCells $count\n" 1146 1148 append out $data 1147 append out "CELL_TYPES $ count\n"1149 append out "CELL_TYPES $numCells\n" 1148 1150 append out $celltypes 1149 1151 append out "\n" 1150 1152 append out "POINT_DATA $_numPoints\n" 1151 foreach axis {x y } {1153 foreach axis {x y z} { 1152 1154 if { [info exists ${axis}Min] } { 1153 1155 set _limits(${axis}min) [set ${axis}Min] -
branches/Rappture 1.2/gui/scripts/resultviewer.tcl
r3288 r3289 284 284 ::Rappture::Field { 285 285 set dims [lindex [lsort [$dataobj components -dimensions]] end] 286 puts stderr "dims=$dims dataobj=$dataobj" 286 287 switch -- $dims { 287 288 1D { … … 296 297 set mode "heightmap" 297 298 if {![info exists _mode2widget($mode)]} { 298 set resultMode[$dataobj viewer]299 set viewer [$dataobj viewer] 299 300 set extents [$dataobj extents] 300 301 if { $extents > 1 } { 301 set resultMode"flowvis"302 set viewer "flowvis" 302 303 } 303 set w $itk_interior. heightmap304 set w $itk_interior.field2d 304 305 if { ![winfo exists $w] } { 305 Rappture::Field2DResult $w -mode $ resultMode306 307 306 Rappture::Field2DResult $w -mode $viewer 307 } 308 set _mode2widget($mode) $w 308 309 } 309 310 } … … 311 312 set mode "field3D" 312 313 if {![info exists _mode2widget($mode)]} { 313 switch -- [$dataobj type] { 314 "vtk" { 315 set fmt "vtk" 316 } 317 "points-on-mesh" { 318 set mesh [$dataobj mesh] 319 set fmt [expr {("" != $mesh) ? "vtk" : "nanovis"}] 320 set extents [$dataobj extents] 321 if { $extents > 1 } { 322 set fmt "flowvis" 323 } 324 } 325 "opendx" - "dx" { 326 set fmt "nanovis" 327 set extents [$dataobj extents] 328 if { $extents > 1 } { 329 set fmt "flowvis" 330 } 331 } 332 "vtkvolume" { 333 set fmt "vtkvolume" 334 } 335 "vtkstreamlines" { 336 set fmt "vtkstreamlines" 337 } 338 "vtkisosurface" { 339 set fmt "vtkisosurface" 340 } 341 } 342 set w $itk_interior.field3D 314 set fmt [$dataobj viewer] 315 set w $itk_interior.field3d 343 316 Rappture::Field3DResult $w -mode $fmt 344 317 set _mode2widget($mode) $w -
branches/Rappture 1.2/gui/scripts/vtkheightmapviewer.tcl
r3274 r3289 37 37 itk_option define -plotforeground plotForeground Foreground "" 38 38 itk_option define -plotbackground plotBackground Background "" 39 itk_option define -mode mode Mode " vtkcontour"39 itk_option define -mode mode Mode "contour" 40 40 41 41 constructor { hostlist args } { … … 214 214 215 215 array set _settings [subst { 216 debug-console 0 217 axis-labels 1 216 axisLabels 1 218 217 axis-visible 1 219 218 axis-xgrid 0 … … 225 224 axis-minticks 1 226 225 axis-flymode "static" 227 contour-edges0228 contour-field"Default"229 contour-isolines10230 heightmap-lighting1231 heightmap-outline0226 edges 0 227 field "Default" 228 isolines 10 229 lighting 1 230 outline 0 232 231 contour-opacity 100 233 232 colormap-visible 1 234 233 isolines-visible 1 235 contour-wireframe0236 heightmap-mode0234 wireframe 0 235 isHeightmap 0 237 236 heightmap-scale 50 238 legend -visible1239 stretch -to-fit 0237 legendVisible 1 238 stretchToFit 0 240 239 x-scale 1.0 241 240 y-scale 1.0 … … 320 319 -onimage [Rappture::icon surface] \ 321 320 -offimage [Rappture::icon surface] \ 322 -variable [itcl::scope _settings( heightmap-mode)] \323 -command [itcl::code $this AdjustSetting heightmap-mode] \321 -variable [itcl::scope _settings(isHeightmap)] \ 322 -command [itcl::code $this AdjustSetting isHeightmap] \ 324 323 } 325 324 Rappture::Tooltip::for $itk_component(mode) \ … … 915 914 $_arcball resize $w $h 916 915 DoResize 917 if { $_settings(stretch -to-fit) } {918 Adjustsetting stretch -to-fit916 if { $_settings(stretchToFit) } { 917 Adjustsetting stretchToFit 919 918 } 920 919 } 921 920 if { $_reset } { 922 InitSettings heightmap-modebackground921 InitSettings isHeightmap background 923 922 # 924 923 # Reset the camera and other view parameters … … 928 927 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 929 928 $_arcball quaternion $q 930 if {$_settings( heightmap-mode) } {931 SendCmd "camera reset all"929 if {$_settings(isHeightmap) } { 930 SendCmd "camera reset" 932 931 if { $_view(ortho)} { 933 932 SendCmd "camera mode ortho" … … 1022 1021 $itk_component(field) value $_currentFieldName 1023 1022 } 1024 InitSettings stretch -to-fit1023 InitSettings stretchToFit 1025 1024 1026 1025 if { $_reset } { … … 1058 1057 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1059 1058 $_arcball quaternion $q 1060 if {$_settings( heightmap-mode) } {1061 SendCmd "camera reset all"1059 if {$_settings(isHeightmap) } { 1060 SendCmd "camera reset" 1062 1061 if { $_view(ortho)} { 1063 1062 SendCmd "camera mode ortho" … … 1069 1068 PanCamera 1070 1069 InitSettings axis-xgrid axis-ygrid axis-zgrid \ 1071 axis-visible axis -labels1070 axis-visible axisLabels 1072 1071 InitSettings contour-opacity \ 1073 heightmap-scale heightmap-lighting \1074 co ntour-colormap contour-field heightmap-outline \1075 contour-edges contour-opacity contour-wireframe1072 heightmap-scale lighting \ 1073 colormap field outline \ 1074 edges contour-opacity wireframe 1076 1075 set _reset 0 1077 1076 } … … 1328 1327 } 1329 1328 } 1330 " contour-wireframe" {1331 set bool $_settings( contour-wireframe)1329 "wireframe" { 1330 set bool $_settings(wireframe) 1332 1331 foreach dataset [CurrentDatasets -all] { 1333 1332 SendCmd "heightmap wireframe $bool $dataset" … … 1346 1345 } 1347 1346 } 1348 " heightmap-lighting" {1349 if { $_settings( heightmap-mode) } {1350 set bool $_settings( heightmap-lighting)1347 "lighting" { 1348 if { $_settings(isHeightmap) } { 1349 set bool $_settings(lighting) 1351 1350 SendCmd "heightmap lighting $bool" 1352 1351 } else { … … 1354 1353 } 1355 1354 } 1356 " contour-edges" {1357 set bool $_settings( contour-edges)1355 "edges" { 1356 set bool $_settings(edges) 1358 1357 foreach dataset [CurrentDatasets -all] { 1359 1358 SendCmd "heightmap edges $bool $dataset" … … 1364 1363 SendCmd "axis visible all $bool" 1365 1364 } 1366 "axis -labels" {1367 set bool $_settings(axis -labels)1365 "axisLabels" { 1366 set bool $_settings(axisLabels) 1368 1367 SendCmd "axis labels all $bool" 1369 1368 } … … 1385 1384 } 1386 1385 } 1387 " contour-isolines" {1386 "isolines" { 1388 1387 set n $_settings($what) 1389 1388 EventuallyContour $n … … 1429 1428 DrawLegend $_currentFieldName 1430 1429 } 1431 "co ntour-colormap" {1430 "colormap" { 1432 1431 set color [$itk_component(colormap) value] 1433 set _settings(co ntour-colormap) $color1432 set _settings(colormap) $color 1434 1433 if { $color == "none" } { 1435 1434 if { $_settings(colormap-visible) } { … … 1455 1454 } 1456 1455 "heightmap-scale" { 1457 if { $_settings( heightmap-mode) } {1456 if { $_settings(isHeightmap) } { 1458 1457 set scale [GetHeightmapScale] 1459 1458 foreach dataset [CurrentDatasets -all] { … … 1464 1463 } 1465 1464 } 1466 " heightmap-lighting" {1467 if { $_settings( heightmap-mode) } {1468 set bool $_settings( heightmap-lighting)1465 "lighting" { 1466 if { $_settings(isHeightmap) } { 1467 set bool $_settings(lighting) 1469 1468 SendCmd "heightmap lighting $bool" 1470 1469 } else { … … 1472 1471 } 1473 1472 } 1474 " contour-field" {1475 set new [$itk_component(field) value]1473 "field" { 1474 set new [$itk_component(field) value] 1476 1475 set value [$itk_component(field) translate $new] 1477 set _settings( contour-field) $value1476 set _settings(field) $value 1478 1477 if { [info exists _fields($new)] } { 1479 1478 set _colorMode scalar … … 1485 1484 EventuallyRequestLegend 1486 1485 } 1487 "stretch -to-fit" {1488 set bool $_settings(stretch -to-fit)1486 "stretchToFit" { 1487 set bool $_settings(stretchToFit) 1489 1488 set _settings(x-scale) 1.0 1490 1489 set _settings(y-scale) 1.0 … … 1513 1512 } 1514 1513 } 1515 " heightmap-outline" {1516 set bool $_settings( heightmap-outline)1514 "outline" { 1515 set bool $_settings(outline) 1517 1516 SendCmd "dataset outline $bool" 1518 1517 } 1519 " heightmap-mode" {1520 set bool $_settings( heightmap-mode)1518 "isHeightmap" { 1519 set bool $_settings(isHeightmap) 1521 1520 if { $bool } { 1522 1521 $itk_component(lighting) configure -state normal … … 1525 1524 } 1526 1525 if {[isconnected]} { 1527 set _settings( heightmap-lighting) $bool1526 set _settings(lighting) $bool 1528 1527 # Fix heightmap scale: 0 for contours, 1 for heightmaps. 1529 1528 if { $bool } { … … 1538 1537 set _comp2scale($dataset) $scale 1539 1538 } 1540 if {$_settings(stretch -to-fit)} {1539 if {$_settings(stretchToFit)} { 1541 1540 if {$scale == 0} { 1542 1541 SendCmd "camera aspect window" … … 1574 1573 } 1575 1574 } 1576 "legend -visible" {1577 if { !$_settings(legend -visible) } {1575 "legendVisible" { 1576 if { !$_settings(legendVisible) } { 1578 1577 $itk_component(view) delete legend 1579 1578 } … … 1908 1907 itcl::configbody Rappture::VtkHeightmapViewer::mode { 1909 1908 switch -- $itk_option(-mode) { 1910 " vtkheightmap" {1911 set _settings( heightmap-mode) 11909 "heightmap" { 1910 set _settings(isHeightmap) 1 1912 1911 } 1913 " vtkcontour" {1914 set _settings( heightmap-mode) 01912 "contour" { 1913 set _settings(isHeightmap) 0 1915 1914 } 1916 1915 default { … … 1918 1917 } 1919 1918 } 1920 AdjustSetting heightmap-mode1919 AdjustSetting isHeightmap 1921 1920 } 1922 1921 … … 1959 1958 checkbutton $inner.legend \ 1960 1959 -text "Legend" \ 1961 -variable [itcl::scope _settings(legend -visible)] \1962 -command [itcl::code $this AdjustSetting legend -visible] \1960 -variable [itcl::scope _settings(legendVisible)] \ 1961 -command [itcl::code $this AdjustSetting legendVisible] \ 1963 1962 -font "Arial 9" 1964 1963 1965 1964 checkbutton $inner.wireframe \ 1966 1965 -text "Wireframe" \ 1967 -variable [itcl::scope _settings( contour-wireframe)] \1968 -command [itcl::code $this AdjustSetting contour-wireframe] \1966 -variable [itcl::scope _settings(wireframe)] \ 1967 -command [itcl::code $this AdjustSetting wireframe] \ 1969 1968 -font "Arial 9" 1970 1969 … … 1972 1971 checkbutton $inner.lighting \ 1973 1972 -text "Enable Lighting" \ 1974 -variable [itcl::scope _settings( heightmap-lighting)] \1975 -command [itcl::code $this AdjustSetting heightmap-lighting] \1973 -variable [itcl::scope _settings(lighting)] \ 1974 -command [itcl::code $this AdjustSetting lighting] \ 1976 1975 -font "Arial 9" 1976 } { 1977 ignore -font 1977 1978 } 1978 1979 1979 1980 checkbutton $inner.edges \ 1980 1981 -text "Edges" \ 1981 -variable [itcl::scope _settings( contour-edges)] \1982 -command [itcl::code $this AdjustSetting contour-edges] \1982 -variable [itcl::scope _settings(edges)] \ 1983 -command [itcl::code $this AdjustSetting edges] \ 1983 1984 -font "Arial 9" 1984 1985 1985 1986 checkbutton $inner.outline \ 1986 1987 -text "Outline" \ 1987 -variable [itcl::scope _settings( heightmap-outline)] \1988 -command [itcl::code $this AdjustSetting heightmap-outline] \1988 -variable [itcl::scope _settings(outline)] \ 1989 -command [itcl::code $this AdjustSetting outline] \ 1989 1990 -font "Arial 9" 1990 1991 1991 1992 checkbutton $inner.stretch \ 1992 1993 -text "Stretch to fit" \ 1993 -variable [itcl::scope _settings(stretch -to-fit)] \1994 -command [itcl::code $this AdjustSetting stretch -to-fit] \1994 -variable [itcl::scope _settings(stretchToFit)] \ 1995 -command [itcl::code $this AdjustSetting stretchToFit] \ 1995 1996 -font "Arial 9" 1996 1997 … … 2000 2001 } 2001 2002 bind $inner.field <<Value>> \ 2002 [itcl::code $this AdjustSetting contour-field]2003 [itcl::code $this AdjustSetting field] 2003 2004 2004 2005 label $inner.colormap_l -text "Colormap" -font "Arial 9" … … 2027 2028 $itk_component(colormap) value "BCGYR" 2028 2029 bind $inner.colormap <<Value>> \ 2029 [itcl::code $this AdjustSetting co ntour-colormap]2030 [itcl::code $this AdjustSetting colormap] 2030 2031 2031 2032 label $inner.isolinecolor_l -text "Isolines" -font "Arial 9" … … 2120 2121 checkbutton $inner.labels \ 2121 2122 -text "Axis Labels" \ 2122 -variable [itcl::scope _settings(axis -labels)] \2123 -command [itcl::code $this AdjustSetting axis -labels] \2123 -variable [itcl::scope _settings(axisLabels)] \ 2124 -command [itcl::code $this AdjustSetting axisLabels] \ 2124 2125 -font "Arial 9" 2125 2126 label $inner.grid_l -text "Grid" -font "Arial 9" … … 2280 2281 radiobutton $inner.vtk_button -text "VTK data file" \ 2281 2282 -variable [itcl::scope _downloadPopup(format)] \ 2282 -font " Helvetica9 " \2283 -font "Arial 9 " \ 2283 2284 -value vtk 2284 2285 Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file." 2285 2286 radiobutton $inner.image_button -text "Image File" \ 2286 2287 -variable [itcl::scope _downloadPopup(format)] \ 2288 -font "Arial 9 " \ 2287 2289 -value image 2288 2290 Rappture::Tooltip::for $inner.image_button \ … … 2339 2341 SendCmd "heightmap add numcontours $_numContours $scale $tag" 2340 2342 set _comp2scale($tag) $_settings(heightmap-scale) 2341 SendCmd "heightmap edges $_settings( contour-edges) $tag"2342 SendCmd "heightmap wireframe $_settings( contour-wireframe) $tag"2343 SendCmd "heightmap edges $_settings(edges) $tag" 2344 SendCmd "heightmap wireframe $_settings(wireframe) $tag" 2343 2345 SendCmd "heightmap colormap $_currentColormap $tag" 2344 2346 } … … 2402 2404 } 2403 2405 set x [expr $w - 2] 2404 if { !$_settings(legend -visible) } {2406 if { !$_settings(legendVisible) } { 2405 2407 $c delete legend 2406 2408 return … … 2636 2638 invoke { 2637 2639 $itk_component(field) value $_currentFieldName 2638 AdjustSetting contour-field2640 AdjustSetting field 2639 2641 } 2640 2642 default { … … 2645 2647 2646 2648 itcl::body Rappture::VtkHeightmapViewer::GetHeightmapScale {} { 2647 if { $_settings( heightmap-mode) } {2649 if { $_settings(isHeightmap) } { 2648 2650 set val $_settings(heightmap-scale) 2649 2651 set sval [expr { $val >= 50 ? double($val)/50.0 : 1.0/(2.0-(double($val)/50.0)) }] -
branches/Rappture 1.2/gui/scripts/vtkisosurfaceviewer.tcl
r3288 r3289 1 1 2 2 # ---------------------------------------------------------------------- 3 # COMPONENT: vtk contour3dviewer - Vtk 3D contour object viewer3 # COMPONENT: vtkisolinesviewer - Vtk 3D contour object viewer 4 4 # 5 5 # It connects to the Vtk server running on a rendering farm, … … 68 68 protected method Disconnect {} 69 69 protected method DoResize {} 70 protected method DoReseed {}71 70 protected method DoRotate {} 72 71 protected method AdjustSetting {what {value ""}} … … 80 79 protected method Rotate {option x y} 81 80 protected method SendCmd {string} 82 protected method SendCmdNo Splash{string}81 protected method SendCmdNoWait {string} 83 82 protected method Zoom {option} 84 83 … … 89 88 private method BuildCutplaneTab {} 90 89 private method BuildDownloadPopup { widget command } 91 private method BuildVolumeTab {} 92 private method ConvertToVtkData { dataobj comp } 90 private method BuildIsosurfaceTab {} 93 91 private method DrawLegend { title } 94 92 private method Combo { option } 95 93 private method EnterLegend { x y } 96 94 private method EventuallyResize { w h } 97 private method EventuallyReseed { numPoints }98 95 private method EventuallyRotate { q } 96 private method EventuallyRequestLegend {} 99 97 private method EventuallySetCutplane { axis args } 100 98 private method GetImage { args } … … 105 103 private method PanCamera {} 106 104 private method RequestLegend {} 107 private method SetColormap { dataobj comp }108 private method ChangeColormap { dataobj comp color }109 105 private method ColorsToColormap { color } 110 106 private method SetLegendTip { x y } 111 107 private method SetObjectStyle { dataobj comp } 112 108 private method Slice {option args} 109 private method ResetColormap { color } 110 private method EnterIsoline { x y value } 111 private method LeaveIsoline {} 112 private method SetIsolineTip { x y value } 113 private method SetCurrentColormap { stylelist } 113 114 114 115 private variable _arcball "" … … 122 123 private variable _colormaps ; # contains all the colormaps 123 124 ; # in the server. 125 # The name of the current colormap used. The colormap is global to all 126 # heightmaps displayed. 127 private variable _currentColormap "" ; 128 129 124 130 private variable _dataset2style ;# maps dataobj-component to transfunc 125 131 … … 143 149 private variable _height 0 144 150 private variable _resizePending 0 145 private variable _reseedPending 0146 151 private variable _rotatePending 0 147 152 private variable _cutplanePending 0 148 153 private variable _legendPending 0 149 private variable _vectorFields 150 private variable _scalarFields 154 private variable _field "" 155 private variable _colorMode "vmag"; # Mode of colormap (vmag or scalar) 156 private variable _currentField "" 157 private variable _fieldNames {} 151 158 private variable _fields 152 private variable _currentField "" 153 private variable _field "" 154 private variable _colorMode "vmag";# Mode of colormap (vmag or scalar) 159 private variable _currentFieldName "Default" 160 private variable _numContours 10 155 161 } 156 162 … … 175 181 $_dispatcher dispatch $this !resize "[itcl::code $this DoResize]; list" 176 182 177 # Reseed event178 $_dispatcher register !reseed179 $_dispatcher dispatch $this !reseed "[itcl::code $this DoReseed]; list"180 181 183 # Rotate event 182 184 $_dispatcher register !rotate … … 190 192 $_dispatcher register !xcutplane 191 193 $_dispatcher dispatch $this !xcutplane \ 192 "[itcl::code $this AdjustSetting cutplane -xposition]; list"194 "[itcl::code $this AdjustSetting cutplaneXPosition]; list" 193 195 194 196 # Y-Cutplane event 195 197 $_dispatcher register !ycutplane 196 198 $_dispatcher dispatch $this !ycutplane \ 197 "[itcl::code $this AdjustSetting cutplane -yposition]; list"199 "[itcl::code $this AdjustSetting cutplaneYPosition]; list" 198 200 199 201 # Z-Cutplane event 200 202 $_dispatcher register !zcutplane 201 203 $_dispatcher dispatch $this !zcutplane \ 202 "[itcl::code $this AdjustSetting cutplane -zposition]; list"204 "[itcl::code $this AdjustSetting cutplaneZPosition]; list" 203 205 204 206 # … … 211 213 # Initialize the view to some default parameters. 212 214 array set _view { 213 qw 1 214 qx 0 215 qy0216 qz0215 qw 0.36 216 qx 0.25 217 qy 0.50 218 qz 0.70 217 219 zoom 1.0 218 220 xpan 0 … … 224 226 $_arcball quaternion $q 225 227 226 set _limits(zmin) 0.0227 set _limits(zmax) 1.0228 229 228 array set _settings [subst { 230 axis -labels1231 ax is-visible 1229 axisLabelsVisible 1 230 axesVisible 1 232 231 axis-xcutplane 0 233 232 axis-xgrid 0 … … 239 238 axis-zgrid 0 240 239 axis-zposition 0 241 contour-edges 0 242 contour-outline 0 243 contour-lighting 1 244 contour-opacity 100 245 contour-visible 1 246 contour-wireframe 0 247 cutplane-edges 0 248 cutplane-lighting 1 249 cutplane-opacity 100 250 cutplane-visible 1 251 cutplane-wireframe 0 252 cutplane-xposition 50 253 cutplane-xvisible 0 254 cutplane-yposition 50 255 cutplane-yvisible 0 256 cutplane-zposition 50 257 cutplane-zvisible 0 258 legend-visible 1 240 colormapVisible 1 241 colormapPalette BCGYR 242 isosurfaceEdges 0 243 isosurfaceOutline 0 244 isosurfaceLighting 1 245 isosurfaceOpacity 100 246 isosurfaceVisible 1 247 isosurfaceWireframe 0 248 cutplaneEdges 0 249 cutplaneLighting 1 250 cutplaneOpacity 100 251 cutplaneVisible 1 252 cutplaneWireframe 0 253 cutplaneXPosition 50 254 cutplaneXVisible 0 255 cutplaneYPosition 50 256 cutplaneYVisible 0 257 cutplaneZPosition 50 258 cutplaneZVisible 0 259 legendVisible 1 260 isolineColor white 261 background black 262 field "Default" 259 263 }] 260 264 … … 283 287 bind $c <KeyPress-Down> [list %W yview scroll -10 units] 284 288 bind $c <Enter> "focus %W" 289 bind $c <Control-F1> [itcl::code $this ToggleConsole] 285 290 286 291 # Fix the scrollregion in case we go off screen … … 334 339 -onimage [Rappture::icon volume-on] \ 335 340 -offimage [Rappture::icon volume-off] \ 336 -variable [itcl::scope _settings( contour-visible)] \337 -command [itcl::code $this AdjustSetting contour-visible]341 -variable [itcl::scope _settings(isosurfaceVisible)] \ 342 -command [itcl::code $this AdjustSetting isosurfaceVisible] 338 343 } 339 344 $itk_component(contour) select … … 346 351 -onimage [Rappture::icon cutbutton] \ 347 352 -offimage [Rappture::icon cutbutton] \ 348 -variable [itcl::scope _settings(cutplane -visible)] \349 -command [itcl::code $this AdjustSetting cutplane -visible]353 -variable [itcl::scope _settings(cutplaneVisible)] \ 354 -command [itcl::code $this AdjustSetting cutplaneVisible] 350 355 } 351 356 $itk_component(cutplane) select … … 356 361 357 362 if { [catch { 358 Build VolumeTab363 BuildIsosurfaceTab 359 364 BuildCutplaneTab 360 365 BuildAxisTab … … 466 471 set _start [clock clicks -milliseconds] 467 472 SendCmd "screen size $_width $_height" 468 set _legendPending 1469 473 470 474 #SendCmd "imgflush" … … 473 477 #SendCmd "camera reset" 474 478 #SendCmd "camera zoom $_view(zoom)" 479 EventuallyRequestLegend 475 480 set _resizePending 0 476 481 } … … 480 485 SendCmd "camera orient $q" 481 486 set _rotatePending 0 487 } 488 489 itcl::body Rappture::VtkIsosurfaceViewer::EventuallyRequestLegend {} { 490 if { !$_legendPending } { 491 set _legendPending 1 492 $_dispatcher event -idle !legend 493 } 482 494 } 483 495 … … 489 501 set _resizePending 1 490 502 $_dispatcher event -after 400 !resize 491 }492 }493 494 itcl::body Rappture::VtkIsosurfaceViewer::EventuallyReseed { numPoints } {495 set _numSeeds $numPoints496 if { !$_reseedPending } {497 set _reseedPending 1498 $_dispatcher event -after 600 !reseed499 503 } 500 504 } … … 674 678 # the user scans through data in the ResultSet viewer. 675 679 # ---------------------------------------------------------------------- 676 itcl::body Rappture::VtkIsosurfaceViewer::scale { args} {680 itcl::body Rappture::VtkIsosurfaceViewer::scale { args } { 677 681 array unset _limits 678 682 foreach dataobj $args { … … 681 685 continue 682 686 } 683 array set bounds $string 684 if {![info exists _limits(xmin)] || $_limits(xmin) > $bounds(xmin)} { 685 set _limits(xmin) $bounds(xmin) 686 } 687 if {![info exists _limits(xmax)] || $_limits(xmax) < $bounds(xmax)} { 688 set _limits(xmax) $bounds(xmax) 689 } 690 691 if {![info exists _limits(ymin)] || $_limits(ymin) > $bounds(ymin)} { 692 set _limits(ymin) $bounds(ymin) 693 } 694 if {![info exists _limits(ymax)] || $_limits(ymax) < $bounds(ymax)} { 695 set _limits(ymax) $bounds(ymax) 696 } 697 698 if {![info exists _limits(zmin)] || $_limits(zmin) > $bounds(zmin)} { 699 set _limits(zmin) $bounds(zmin) 700 } 701 if {![info exists _limits(zmax)] || $_limits(zmax) < $bounds(zmax)} { 702 set _limits(zmax) $bounds(zmax) 703 } 687 array set lim $string 688 foreach axis { x y z v } { 689 set min ${axis}min 690 set max ${axis}max 691 if {![info exists _limits($min)] || $_limits($min) > $lim($min)} { 692 set _limits($min) $lim($min) 693 } 694 if {![info exists _limits($max)] || $_limits($max) < $lim($max)} { 695 set _limits($max) $lim($max) 696 } 697 } 704 698 } 705 699 } … … 719 713 coming { 720 714 if {[catch { 721 $_image(download) snap $itk_component(plotarea) 722 } errs ]} { 723 puts stderr "errs=$errs" 715 blt::winop snap $itk_component(plotarea) $_image(download) 716 }]} { 724 717 $_image(download) configure -width 1 -height 1 725 718 $_image(download) put #000000 … … 811 804 $_dispatcher cancel !rebuild 812 805 $_dispatcher cancel !resize 813 $_dispatcher cancel !reseed814 806 $_dispatcher cancel !rotate 815 807 $_dispatcher cancel !xcutplane … … 852 844 853 845 # 854 # SendCmdNoSplash 855 # 856 # Send commands off to the rendering server. This method 857 # doesn't initiate the slash screen. 858 # 859 itcl::body Rappture::VtkIsosurfaceViewer::SendCmdNoSplash {string} { 846 # SendCmdNoWait 847 # 848 # Send commands off to the rendering server. If we're currently 849 # sending data objects to the server, buffer the commands to be 850 # sent later. 851 # 852 itcl::body Rappture::VtkIsosurfaceViewer::SendCmdNoWait {string} { 860 853 if { $_buffering } { 861 854 append _outbuf $string "\n" … … 900 893 set _hardcopy($tag) $bytes 901 894 } 902 if { $_legendPending } { 903 RequestLegend 904 } 895 EventuallyRequestLegend 905 896 } 906 897 … … 964 955 965 956 set _buffering 1 966 set _legendPending 1967 957 # Turn on buffering of commands to the server. We don't want to 968 958 # be preempted by a server disconnect/reconnect (which automatically … … 985 975 PanCamera 986 976 set _first "" 987 InitSettings axis-xgrid axis-ygrid axis-zgrid axis -mode \988 ax is-visible axis-labels cutplane-visible \989 cutplane -xposition cutplane-yposition cutplane-zposition \990 cutplane -xvisible cutplane-yvisible cutplane-zvisible977 InitSettings axis-xgrid axis-ygrid axis-zgrid axisMode \ 978 axesVisible axisLabelsVisible cutplaneVisible \ 979 cutplaneXPosition cutplaneYPosition cutplaneZPosition \ 980 cutplaneXVisible cutplaneYVisible cutplaneZVisible 991 981 992 982 SendCmd "imgflush" 993 983 994 set _limits(zmin) ""995 set _limits(zmax) ""996 984 set _first "" 997 985 foreach dataobj [get -objects] { … … 1004 992 if { ![info exists _datasets($tag)] } { 1005 993 set bytes [$dataobj vtkdata $comp] 1006 puts stderr bytes=$bytes1007 994 set length [string length $bytes] 1008 995 append _outbuf "dataset add $tag data follows $length\n" … … 1021 1008 } 1022 1009 } 1023 if {"" != $_first} { 1024 set location [$_first hints camera] 1025 if { $location != "" } { 1026 array set view $location 1027 } 1028 1029 if 0 { 1010 if { $_first != "" && $_reset } { 1011 if 1 { 1030 1012 # Tell the server the name of the tool, the version, and dataset 1031 1013 # that we are rendering. Have to do it here because we don't know … … 1035 1017 lappend args version [$_first hints toolRevision] 1036 1018 lappend args dataset [$_first hints label] 1037 SendCmd "clientinfo $args" 1038 } 1039 1040 foreach axis { x y z } { 1041 set label [$_first hints ${axis}label] 1042 if { $label != "" } { 1043 SendCmd "axis name $axis $label" 1044 } 1045 set units [$_first hints ${axis}units] 1046 if { $units != "" } { 1047 SendCmd "axis units $axis $units" 1048 } 1049 } 1050 array unset _scalarFields 1051 array unset _vectorFields 1052 set _currentField [$_first hints default] 1053 $itk_component(field) choices delete 0 end 1054 $itk_component(fieldmenu) delete 0 end 1055 array unset _fields 1056 foreach { name title units } [$_first hints vectors] { 1057 set _vectorFields($title) $name 1058 $itk_component(field) choices insert end "$name" "$title" 1059 $itk_component(fieldmenu) add radiobutton -label "$title" \ 1060 -value $title -variable [itcl::scope _currentField] \ 1061 -selectcolor red \ 1062 -activebackground black \ 1063 -activeforeground white \ 1064 -font "Arial 8" \ 1065 -command [itcl::code $this Combo invoke] 1066 set _fields($name) [list $title $units] 1067 } 1068 foreach { name title units } [$_first hints scalars] { 1069 set _scalarFields($title) $name 1070 $itk_component(field) choices insert end "$name" "$title" 1071 $itk_component(fieldmenu) add radiobutton -label "$title" \ 1072 -value $title -variable [itcl::scope _currentField] \ 1073 -selectcolor red \ 1074 -activebackground black \ 1075 -activeforeground white \ 1076 -font "Arial 8" \ 1077 -command [itcl::code $this Combo invoke] 1078 set _fields($name) [list $title $units] 1079 } 1080 $itk_component(field) value $_currentField 1081 } 1082 1083 InitSettings contour-visible contour-palette contour-visible 1019 SendCmd "clientinfo [list $args]" 1020 } 1021 1022 set _fieldNames [$_first hints fieldnames] 1023 set _fieldUnits [$_first hints fieldunits] 1024 set _fieldLabels [$_first hints fieldlabels] 1025 $itk_component(field) choices delete 0 end 1026 $itk_component(fieldmenu) delete 0 end 1027 array unset _fields 1028 foreach name $_fieldNames title $_fieldLabels units $_fieldUnits { 1029 SendCmd "dataset maprange explicit $_limits(vmin) $_limits(vmax) $name" 1030 if { $title == "" } { 1031 set title $name 1032 } 1033 $itk_component(field) choices insert end "$name" "$title" 1034 $itk_component(fieldmenu) add radiobutton -label "$title" \ 1035 -value $title -variable [itcl::scope _currentFieldName] \ 1036 -selectcolor red \ 1037 -activebackground $itk_option(-plotbackground) \ 1038 -activeforeground $itk_option(-plotforeground) \ 1039 -font "Arial 8" \ 1040 -command [itcl::code $this Combo invoke] 1041 set _fields($name) [list $title $units] 1042 set _currentFieldName $name 1043 } 1044 if { [array size _fields] == 1 } { 1045 set _currentFieldName $_fieldLabels 1046 if { $_currentFieldName == "" } { 1047 puts stderr "no default name from field" 1048 set _currentFieldName "Default" 1049 } 1050 } 1051 $itk_component(field) value $_currentFieldName 1052 } 1053 InitSettings isosurfaceVisible colormapPalette isosurfaceVisible 1084 1054 1085 1055 if { $_reset } { 1086 1056 InitSettings \ 1087 contour-lighting \1088 contour-palette contour-field \1089 contour-edges contour-lighting contour-opacity contour-wireframe\1090 contour-outline1057 isosurfaceLighting \ 1058 field \ 1059 isosurfaceEdges isosurfaceLighting isosurfaceOpacity \ 1060 isosurfaceWireframe isosurfaceOutline 1091 1061 Zoom reset 1092 1062 set _reset 0 … … 1167 1137 "reset" { 1168 1138 array set _view { 1169 qw 1 1170 qx 0 1171 qy01172 qz01139 qw 0.36 1140 qx 0.25 1141 qy 0.50 1142 qz 0.70 1173 1143 zoom 1.0 1174 1144 xpan 0 … … 1335 1305 } 1336 1306 switch -- $what { 1337 " contour-opacity" {1338 set val $_settings( contour-opacity)1307 "isosurfaceOpacity" { 1308 set val $_settings(isosurfaceOpacity) 1339 1309 set sval [expr { 0.01 * double($val) }] 1340 foreach dataset [CurrentDatasets -visible] { 1341 SendCmd "contour3d opacity $sval $dataset" 1342 } 1343 } 1344 "contour-wireframe" { 1345 set bool $_settings(contour-wireframe) 1346 foreach dataset [CurrentDatasets -visible] { 1347 SendCmd "contour3d wireframe $bool $dataset" 1348 } 1349 } 1350 "contour-visible" { 1351 set bool $_settings(contour-visible) 1352 foreach dataset [CurrentDatasets -visible] { 1353 SendCmd "contour3d visible $bool $dataset" 1354 } 1310 SendCmd "contour3d opacity $sval" 1311 } 1312 "isosurfaceWireframe" { 1313 set bool $_settings(isosurfaceWireframe) 1314 SendCmd "contour3d wireframe $bool" 1315 } 1316 "isosurfaceVisible" { 1317 set bool $_settings(isosurfaceVisible) 1318 SendCmd "contour3d visible $bool" 1355 1319 if { $bool } { 1356 1320 Rappture::Tooltip::for $itk_component(contour) \ … … 1361 1325 } 1362 1326 } 1363 "contour-lighting" { 1364 set bool $_settings(contour-lighting) 1365 foreach dataset [CurrentDatasets -visible] { 1366 SendCmd "contour3d lighting $bool $dataset" 1367 } 1368 } 1369 "contour-edges" { 1370 set bool $_settings(contour-edges) 1371 foreach dataset [CurrentDatasets -visible] { 1372 SendCmd "contour3d edges $bool $dataset" 1373 } 1374 } 1375 "contour-outline" { 1376 set bool $_settings(contour-outline) 1377 foreach dataset [CurrentDatasets -visible] { 1378 SendCmd "dataset outline $bool $dataset" 1379 } 1380 } 1381 "axis-visible" { 1382 set bool $_settings(axis-visible) 1327 "isosurfaceLighting" { 1328 set bool $_settings(isosurfaceLighting) 1329 SendCmd "contour3d lighting $bool" 1330 } 1331 "isosurfaceEdges" { 1332 set bool $_settings(isosurfaceEdges) 1333 SendCmd "contour3d edges $bool" 1334 } 1335 "isosurfaceOutline" { 1336 set bool $_settings(isosurfaceOutline) 1337 SendCmd "dataset outline $bool" 1338 } 1339 "background" { 1340 set bgcolor [$itk_component(background) value] 1341 array set fgcolors { 1342 "black" "white" 1343 "white" "black" 1344 "grey" "black" 1345 } 1346 configure -plotbackground $bgcolor \ 1347 -plotforeground $fgcolors($bgcolor) 1348 $itk_component(view) delete "legend" 1349 DrawLegend $_currentFieldName 1350 } 1351 "axesVisible" { 1352 set bool $_settings(axesVisible) 1383 1353 SendCmd "axis visible all $bool" 1384 1354 } 1385 "axis -labels" {1386 set bool $_settings(axis -labels)1355 "axisLabelsVisible" { 1356 set bool $_settings(axisLabelsVisible) 1387 1357 SendCmd "axis labels all $bool" 1388 1358 } … … 1392 1362 SendCmd "axis grid $axis $bool" 1393 1363 } 1394 "axis -mode" {1395 set mode [$itk_component(axis mode) value]1396 set mode [$itk_component(axis mode) translate $mode]1364 "axisMode" { 1365 set mode [$itk_component(axisMode) value] 1366 set mode [$itk_component(axisMode) translate $mode] 1397 1367 set _settings($what) $mode 1398 1368 SendCmd "axis flymode $mode" 1399 1369 } 1400 "cutplane -edges" {1370 "cutplaneEdges" { 1401 1371 set bool $_settings($what) 1402 1372 foreach dataset [CurrentDatasets -visible] { … … 1404 1374 } 1405 1375 } 1406 "cutplane -visible" {1376 "cutplaneVisible" { 1407 1377 set bool $_settings($what) 1408 1378 foreach dataset [CurrentDatasets -visible] { … … 1410 1380 } 1411 1381 } 1412 "cutplane -wireframe" {1382 "cutplaneWireframe" { 1413 1383 set bool $_settings($what) 1414 1384 foreach dataset [CurrentDatasets -visible] { … … 1416 1386 } 1417 1387 } 1418 "cutplane -lighting" {1388 "cutplaneLighting" { 1419 1389 set bool $_settings($what) 1420 1390 foreach dataset [CurrentDatasets -visible] { … … 1422 1392 } 1423 1393 } 1424 "cutplane -opacity" {1394 "cutplaneOpacity" { 1425 1395 set val $_settings($what) 1426 1396 set sval [expr { 0.01 * double($val) }] … … 1429 1399 } 1430 1400 } 1431 "cutplane -xvisible" - "cutplane-yvisible" - "cutplane-zvisible" {1432 set axis [string range $what 9 9]1401 "cutplaneXVisible" - "cutplaneYVisible" - "cutplaneZVisible" { 1402 set axis [string tolower [string range $what 8 8]] 1433 1403 set bool $_settings($what) 1434 1404 if { $bool } { 1435 $itk_component(${axis} CutScale) configure -state normal \1405 $itk_component(${axis}position) configure -state normal \ 1436 1406 -troughcolor white 1437 1407 } else { 1438 $itk_component(${axis} CutScale) configure -state disabled \1408 $itk_component(${axis}position) configure -state disabled \ 1439 1409 -troughcolor grey82 1440 1410 } … … 1443 1413 } 1444 1414 } 1445 "cutplane -xposition" - "cutplane-yposition" - "cutplane-zposition" {1446 set axis [string range $what 9 9]1415 "cutplaneXPosition" - "cutplaneYPosition" - "cutplaneZPosition" { 1416 set axis [string tolower [string range $what 8 8]] 1447 1417 set pos [expr $_settings($what) * 0.01] 1448 1418 foreach dataset [CurrentDatasets -visible] { … … 1451 1421 set _cutplanePending 0 1452 1422 } 1453 " contour-visible" {1423 "isosurfaceVisible" { 1454 1424 set bool $_settings($what) 1455 1425 foreach dataset [CurrentDatasets -visible] { 1456 1426 SendCmd "contour3d visible $bool $dataset" 1457 1427 } 1428 set _settings(isosurfaceVisible) $bool 1458 1429 if { $bool } { 1459 1430 Rappture::Tooltip::for $itk_component(contour) \ … … 1463 1434 "Show the isosurface" 1464 1435 } 1465 } 1466 "contour-palette" { 1467 set palette [$itk_component(palette) value] 1468 set _settings(contour-palette) $palette 1469 foreach dataset [CurrentDatasets -visible $_first] { 1470 foreach {dataobj comp} [split $dataset -] break 1471 ChangeColormap $dataobj $comp $palette 1472 } 1473 set _legendPending 1 1474 } 1475 "contour-opacity" { 1476 set val $_settings(contour-opacity) 1436 DrawLegend $_currentFieldName 1437 } 1438 "colormapPalette" { 1439 set color [$itk_component(palette) value] 1440 set _settings(colormapPalette) $color 1441 if { $color == "none" } { 1442 if { $_settings(colormapVisible) } { 1443 SendCmd "contour3d surface 0" 1444 set _settings(colormapVisible) 0 1445 } 1446 } else { 1447 if { !$_settings(colormapVisible) } { 1448 SendCmd "contour3d surface 1" 1449 set _settings(colormapVisible) 1 1450 } 1451 ResetColormap $color 1452 SendCmd "contour3d colormap $_currentColormap" 1453 } 1454 EventuallyRequestLegend 1455 } 1456 "isolineColor" { 1457 set color [$itk_component(isolineColor) value] 1458 if { $color == "none" } { 1459 if { $_settings(isosurfaceVisible) } { 1460 SendCmd "contour3d visible 0" 1461 set _settings(isosurfaceVisible) 0 1462 } 1463 } else { 1464 if { !$_settings(isosurfaceVisible) } { 1465 SendCmd "contour3d visible 1" 1466 set _settings(isosurfaceVisible) 1 1467 } 1468 set _settings(isolineColor) $color 1469 } 1470 DrawLegend $_currentFieldName 1471 } 1472 "isosurfaceOpacity" { 1473 set val $_settings(isosurfaceOpacity) 1477 1474 set sval [expr { 0.01 * double($val) }] 1478 1475 foreach dataset [CurrentDatasets -visible $_first] { … … 1480 1477 } 1481 1478 } 1482 " contour-lighting" {1483 set bool $_settings( contour-lighting)1479 "isosurfaceLighting" { 1480 set bool $_settings(isosurfaceLighting) 1484 1481 foreach dataset [CurrentDatasets -visible $_first] { 1485 1482 SendCmd "contour3d lighting $bool $dataset" 1486 1483 } 1487 1484 } 1488 " contour-field" {1485 "field" { 1489 1486 set new [$itk_component(field) value] 1490 1487 set value [$itk_component(field) translate $new] 1491 set _settings(contour-field) $value 1492 if { [info exists _scalarFields($new)] } { 1493 set name $_scalarFields($new) 1488 set _settings(field) $value 1489 if { [info exists _fields($new)] } { 1494 1490 set _colorMode scalar 1495 set _currentField $new 1496 } elseif { [info exists _vectorFields($new)] } { 1497 set name $_vectorFields($new) 1498 set _colorMode vmag 1499 set _currentField $new 1491 set _currentFieldName $new 1500 1492 } else { 1501 1493 puts stderr "unknown field \"$new\"" 1502 1494 return 1503 1495 } 1504 foreach dataset [CurrentDatasets -visible] { 1505 SendCmd "dataset scalar ${name} $dataset" 1506 SendCmd "cutplane colormode $_colorMode ${name} $dataset" 1507 } 1508 set _legendPending 1 1509 } 1510 "legend-visible" { 1511 if { !$_settings(legend-visible) } { 1496 EventuallyRequestLegend 1497 } 1498 "legendVisible" { 1499 if { !$_settings(legendVisible) } { 1512 1500 $itk_component(view) delete legend 1513 1501 } 1514 DrawLegend $_settings( contour-field)1502 DrawLegend $_settings(field) 1515 1503 } 1516 1504 default { … … 1520 1508 } 1521 1509 1510 1522 1511 # 1523 1512 # RequestLegend -- 1524 1513 # 1525 1514 # Request a new legend from the server. The size of the legend 1526 # is determined from the height of the canvas. It will be rotated 1527 # to be vertical when drawn. 1515 # is determined from the height of the canvas. 1516 # 1517 # This should be called when 1518 # 1. A new current colormap is set. 1519 # 2. Window is resized. 1520 # 3. The limits of the data have changed. (Just need a redraw). 1521 # 4. Number of isolines have changed. (Just need a redraw). 1522 # 5. Legend becomes visible (Just need a redraw). 1528 1523 # 1529 1524 itcl::body Rappture::VtkIsosurfaceViewer::RequestLegend {} { 1525 set _legendPending 0 1530 1526 set font "Arial 8" 1531 1527 set lineht [font metrics $font -linespace] 1532 set c $itk_component( legend)1528 set c $itk_component(view) 1533 1529 set w 12 1534 set h [expr {$_height - 3* ($lineht + 2)}]1530 set h [expr {$_height - 2 * ($lineht + 2)}] 1535 1531 if { $h < 1} { 1536 1532 return 1537 1533 } 1538 if { [info exists _scalarFields($_currentField)] } { 1539 set name $_scalarFields($_currentField) 1540 } elseif { [info exists _vectorFields($_currentField)] } { 1541 set name $_vectorFields($_currentField) 1534 if { [info exists _fields($_currentFieldName)] } { 1535 set title [lindex $_fields($_currentFieldName) 0] 1536 if { $title != "component" } { 1537 set h [expr $h - ($lineht + 2)] 1538 } 1542 1539 } else { 1543 1540 return 1544 1541 } 1545 # Set the legend on the first coutour dataset. 1546 foreach dataset [CurrentDatasets -visible $_first] { 1547 foreach {dataobj comp} [split $dataset -] break 1548 if { [info exists _dataset2style($dataset)] } { 1549 SendCmdNoSplash \ 1550 "legend $_dataset2style($dataset) $_colorMode $name {} $w $h 0" 1551 break; 1552 } 1553 } 1554 } 1555 1556 # 1557 # ChangeColormap -- 1558 # 1559 itcl::body Rappture::VtkIsosurfaceViewer::ChangeColormap {dataobj comp color} { 1560 set tag $dataobj-$comp 1561 if { ![info exist _style($tag)] } { 1562 error "no initial colormap" 1563 } 1564 array set style $_style($tag) 1565 set style(-color) $color 1566 set _style($tag) [array get style] 1567 SetColormap $dataobj $comp 1568 } 1569 1570 # 1571 # SetColormap -- 1572 # 1573 itcl::body Rappture::VtkIsosurfaceViewer::SetColormap { dataobj comp } { 1574 array set style { 1575 -color BCGYR 1576 -levels 10 1577 -opacity 1.0 1578 } 1579 set tag $dataobj-$comp 1580 if { ![info exists _initialStyle($tag)] } { 1581 # Save the initial component style. 1582 set _initialStyle($tag) [$dataobj style $comp] 1583 } 1584 1585 # Override defaults with initial style defined in xml. 1586 array set style $_initialStyle($tag) 1587 1588 if { ![info exists _style($tag)] } { 1589 set _style($tag) [array get style] 1590 } 1591 # Override initial style with current style. 1592 array set style $_style($tag) 1593 1594 set name "$style(-color):$style(-levels):$style(-opacity)" 1595 if { ![info exists _colormaps($name)] } { 1596 BuildColormap $name [array get style] 1597 set _colormaps($name) 1 1598 } 1599 if { ![info exists _dataset2style($tag)] || 1600 $_dataset2style($tag) != $name } { 1601 SendCmd "contour3d colormap $name $tag" 1602 SendCmd "contour3d add numcontours [expr {$style(-levels)+1}] $tag" 1603 SendCmd "cutplane colormap $name $tag" 1604 set _dataset2style($tag) $name 1542 # Set the legend on the first heightmap dataset. 1543 if { $_currentColormap != "" } { 1544 set cmap $_currentColormap 1545 SendCmdNoWait "legend $cmap scalar $title {} $w $h 0" 1605 1546 } 1606 1547 } … … 1816 1757 # BuildColormap -- 1817 1758 # 1818 itcl::body Rappture::VtkIsosurfaceViewer::BuildColormap { name styles } { 1819 array set style $styles 1759 itcl::body Rappture::VtkIsosurfaceViewer::BuildColormap { name stylelist } { 1760 array set style $stylelist 1761 parray style 1820 1762 set cmap [ColorsToColormap $style(-color)] 1821 1763 if { [llength $cmap] == 0 } { … … 1846 1788 itcl::configbody Rappture::VtkIsosurfaceViewer::plotforeground { 1847 1789 if { [isconnected] } { 1848 foreach {r g b} [Color2RGB $itk_option(-plotforeground)] break 1849 #fix this! 1850 #SendCmd "color background $r $g $b" 1790 SendCmd "axis color all [Color2RGB $itk_option(-plotforeground)]" 1851 1791 } 1852 1792 } 1853 1793 1854 1794 itcl::body Rappture::VtkIsosurfaceViewer::limits { dataobj } { 1855 return 1856 array unset _limits $dataobj-* 1857 foreach comp [$dataobj components] { 1858 set tag $dataobj-$comp 1859 if { ![info exists _limits($tag)] } { 1860 set data [$dataobj blob $comp] 1861 set tmpfile file[pid].vtk 1862 set f [open "$tmpfile" "w"] 1863 fconfigure $f -translation binary -encoding binary 1864 puts $f $data 1865 close $f 1866 set reader [vtkDataSetReader $tag-xvtkDataSetReader] 1867 $reader SetFileName $tmpfile 1868 $reader ReadAllScalarsOn 1869 $reader ReadAllVectorsOn 1870 $reader ReadAllFieldsOn 1871 $reader Update 1872 set output [$reader GetOutput] 1873 set _limits($tag) [$output GetBounds] 1874 set pointData [$output GetPointData] 1875 puts stderr "\#scalars=[$reader GetNumberOfScalarsInFile]" 1876 puts stderr "\#fielddata=[$reader GetNumberOfFieldDataInFile]" 1877 puts stderr "fielddataname=[$reader GetFieldDataNameInFile 0]" 1878 set fieldData [$output GetFieldData] 1879 set pointData [$output GetPointData] 1880 puts stderr "field \#arrays=[$fieldData GetNumberOfArrays]" 1881 for { set i 0 } { $i < [$fieldData GetNumberOfArrays] } { incr i } { 1882 puts stderr [$fieldData GetArrayName $i] 1883 } 1884 puts stderr "point \#arrays=[$pointData GetNumberOfArrays]" 1885 for { set i 0 } { $i < [$pointData GetNumberOfArrays] } { incr i } { 1886 set name [$pointData GetArrayName $i] 1887 if { ![info exists _fields($name)] } { 1888 $itk_component(field) choices insert end "$name" "$name" 1889 set _fields($name) 1 1890 } 1891 } 1892 puts stderr "field \#components=[$fieldData GetNumberOfComponents]" 1893 puts stderr "point \#components=[$pointData GetNumberOfComponents]" 1894 puts stderr "field \#tuples=[$fieldData GetNumberOfTuples]" 1895 puts stderr "point \#tuples=[$pointData GetNumberOfTuples]" 1896 puts stderr "point \#scalars=[$pointData GetScalars]" 1897 puts stderr vectors=[$pointData GetVectors] 1898 rename $output "" 1899 rename $reader "" 1900 file delete $tmpfile 1901 } 1902 foreach { xMin xMax yMin yMax zMin zMax} $_limits($tag) break 1903 if {![info exists limits(xmin)] || $limits(xmin) > $xMin} { 1904 set limits(xmin) $xMin 1905 } 1906 if {![info exists limits(xmax)] || $limits(xmax) < $xMax} { 1907 set limits(xmax) $xMax 1908 } 1909 if {![info exists limits(ymin)] || $limits(ymin) > $yMin} { 1910 set limits(ymin) $xMin 1911 } 1912 if {![info exists limits(ymax)] || $limits(ymax) < $yMax} { 1913 set limits(ymax) $yMax 1914 } 1915 if {![info exists limits(zmin)] || $limits(zmin) > $zMin} { 1916 set limits(zmin) $zMin 1917 } 1918 if {![info exists limits(zmax)] || $limits(zmax) < $zMax} { 1919 set limits(zmax) $zMax 1920 } 1921 } 1795 foreach { limits(xmin) limits(xmax) } [$dataobj limits x] break 1796 foreach { limits(ymin) limits(ymax) } [$dataobj limits y] break 1797 foreach { limits(zmin) limits(zmax) } [$dataobj limits z] break 1798 foreach { limits(vmin) limits(vmax) } [$dataobj limits v] break 1922 1799 return [array get limits] 1923 1800 } 1924 1801 1925 itcl::body Rappture::VtkIsosurfaceViewer::Build VolumeTab {} {1802 itcl::body Rappture::VtkIsosurfaceViewer::BuildIsosurfaceTab {} { 1926 1803 1927 1804 set fg [option get $itk_component(hull) font Font] … … 1929 1806 1930 1807 set inner [$itk_component(main) insert end \ 1931 -title " ContourSettings" \1808 -title "Isosurface Settings" \ 1932 1809 -icon [Rappture::icon volume-on]] 1933 1810 $inner configure -borderwidth 4 1934 1811 1935 1812 checkbutton $inner.contour \ 1936 -text " Show Isosurface" \1937 -variable [itcl::scope _settings( contour-visible)] \1938 -command [itcl::code $this AdjustSetting contour-visible] \1813 -text "Isosurfaces" \ 1814 -variable [itcl::scope _settings(isosurfaceVisible)] \ 1815 -command [itcl::code $this AdjustSetting isosurfaceVisible] \ 1939 1816 -font "Arial 9" 1940 1817 1941 1818 checkbutton $inner.wireframe \ 1942 -text " ShowWireframe" \1943 -variable [itcl::scope _settings( contour-wireframe)] \1944 -command [itcl::code $this AdjustSetting contour-wireframe] \1819 -text "Wireframe" \ 1820 -variable [itcl::scope _settings(isosurfaceWireframe)] \ 1821 -command [itcl::code $this AdjustSetting isosurfaceWireframe] \ 1945 1822 -font "Arial 9" 1946 1823 1947 1824 checkbutton $inner.lighting \ 1948 1825 -text "Enable Lighting" \ 1949 -variable [itcl::scope _settings( contour-lighting)] \1950 -command [itcl::code $this AdjustSetting contour-lighting] \1826 -variable [itcl::scope _settings(isosurfaceLighting)] \ 1827 -command [itcl::code $this AdjustSetting isosurfaceLighting] \ 1951 1828 -font "Arial 9" 1952 1829 1953 1830 checkbutton $inner.edges \ 1954 -text " ShowEdges" \1955 -variable [itcl::scope _settings( contour-edges)] \1956 -command [itcl::code $this AdjustSetting contour-edges] \1831 -text "Edges" \ 1832 -variable [itcl::scope _settings(isosurfaceEdges)] \ 1833 -command [itcl::code $this AdjustSetting isosurfaceEdges] \ 1957 1834 -font "Arial 9" 1958 1835 1959 1836 checkbutton $inner.outline \ 1960 -text " ShowOutline" \1961 -variable [itcl::scope _settings( contour-outline)] \1962 -command [itcl::code $this AdjustSetting contour-outline] \1837 -text "Outline" \ 1838 -variable [itcl::scope _settings(isosurfaceOutline)] \ 1839 -command [itcl::code $this AdjustSetting isosurfaceOutline] \ 1963 1840 -font "Arial 9" 1964 1841 1965 1842 checkbutton $inner.legend \ 1966 -text " ShowLegend" \1967 -variable [itcl::scope _settings(legend -visible)] \1968 -command [itcl::code $this AdjustSetting legend -visible] \1843 -text "Legend" \ 1844 -variable [itcl::scope _settings(legendVisible)] \ 1845 -command [itcl::code $this AdjustSetting legendVisible] \ 1969 1846 -font "Arial 9" 1847 1848 label $inner.linecolor_l -text "Isolines" -font "Arial 9" 1849 itk_component add isolineColor { 1850 Rappture::Combobox $inner.linecolor -width 10 -editable no 1851 } 1852 $inner.linecolor choices insert end \ 1853 "black" "black" \ 1854 "blue" "blue" \ 1855 "cyan" "cyan" \ 1856 "green" "green" \ 1857 "grey" "grey" \ 1858 "magenta" "magenta" \ 1859 "orange" "orange" \ 1860 "red" "red" \ 1861 "white" "white" \ 1862 "none" "none" 1863 1864 $itk_component(isolineColor) value "red" 1865 bind $inner.linecolor <<Value>> \ 1866 [itcl::code $this AdjustSetting isolineColor] 1867 1868 label $inner.background_l -text "Background" -font "Arial 9" 1869 itk_component add background { 1870 Rappture::Combobox $inner.background -width 10 -editable no 1871 } 1872 $inner.background choices insert end \ 1873 "black" "black" \ 1874 "white" "white" \ 1875 "grey" "grey" 1876 1877 $itk_component(background) value $_settings(background) 1878 bind $inner.background <<Value>> [itcl::code $this AdjustSetting background] 1970 1879 1971 1880 label $inner.opacity_l -text "Opacity" -font "Arial 9" 1972 1881 ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ 1973 -variable [itcl::scope _settings( contour-opacity)] \1882 -variable [itcl::scope _settings(isosurfaceOpacity)] \ 1974 1883 -width 10 \ 1975 1884 -showvalue off \ 1976 -command [itcl::code $this AdjustSetting contour-opacity]1885 -command [itcl::code $this AdjustSetting isosurfaceOpacity] 1977 1886 1978 1887 label $inner.scale_l -text "Scale" -font "Arial 9" … … 1988 1897 } 1989 1898 bind $inner.field <<Value>> \ 1990 [itcl::code $this AdjustSetting contour-field]1899 [itcl::code $this AdjustSetting field] 1991 1900 1992 1901 label $inner.palette_l -text "Palette" -font "Arial 9" … … 2014 1923 $itk_component(palette) value "BCGYR" 2015 1924 bind $inner.palette <<Value>> \ 2016 [itcl::code $this AdjustSetting co ntour-palette]1925 [itcl::code $this AdjustSetting colormapPalette] 2017 1926 2018 1927 blt::table $inner \ 2019 0,0 $inner.contour -anchor w -pady 2 \ 2020 1,0 $inner.wireframe -anchor w -pady 2 \ 2021 2,0 $inner.lighting -anchor w -pady 2 \ 2022 3,0 $inner.edges -anchor w -pady 2 \ 2023 4,0 $inner.outline -anchor w -pady 2 \ 2024 5,0 $inner.legend -anchor w -pady 2 \ 2025 6,0 $inner.opacity_l -anchor w -pady 2 \ 2026 6,1 $inner.opacity -fill x -pady 2 \ 2027 8,0 $inner.field_l -anchor w -pady 2 \ 2028 8,1 $inner.field -anchor w -pady 2 \ 2029 9,0 $inner.palette_l -anchor w -pady 2 \ 2030 9,1 $inner.palette -anchor w -pady 2 \ 1928 0,0 $inner.palette_l -anchor w -pady 2 \ 1929 0,1 $inner.palette -anchor w -pady 2 -fill x \ 1930 1,0 $inner.linecolor_l -anchor w -pady 2 \ 1931 1,1 $inner.linecolor -anchor w -pady 2 -fill x \ 1932 2,0 $inner.background_l -anchor w -pady 2 \ 1933 2,1 $inner.background -anchor w -pady 2 -fill x \ 1934 3,0 $inner.contour -anchor w -pady 2 -cspan 2 \ 1935 4,0 $inner.wireframe -anchor w -pady 2 -cspan 2 \ 1936 5,0 $inner.lighting -anchor w -pady 2 -cspan 2 \ 1937 6,0 $inner.edges -anchor w -pady 2 -cspan 2 \ 1938 7,0 $inner.outline -anchor w -pady 2 -cspan 2 \ 1939 8,0 $inner.legend -anchor w -pady 2 \ 1940 9,0 $inner.opacity_l -anchor w -pady 2 \ 1941 9,1 $inner.opacity -fill x -pady 2 -fill x \ 1942 10,0 $inner.field_l -anchor w -pady 2 \ 1943 10,1 $inner.field -anchor w -pady 2 -fill x \ 2031 1944 2032 1945 blt::table configure $inner r* c* -resize none 2033 blt::table configure $inner r1 0 c1 c2-resize expand1946 blt::table configure $inner r11 c1 -resize expand 2034 1947 } 2035 1948 … … 2046 1959 checkbutton $inner.visible \ 2047 1960 -text "Show Axes" \ 2048 -variable [itcl::scope _settings(ax is-visible)] \2049 -command [itcl::code $this AdjustSetting ax is-visible] \1961 -variable [itcl::scope _settings(axesVisible)] \ 1962 -command [itcl::code $this AdjustSetting axesVisible] \ 2050 1963 -font "Arial 9" 2051 1964 2052 1965 checkbutton $inner.labels \ 2053 1966 -text "Show Axis Labels" \ 2054 -variable [itcl::scope _settings(axis -labels)] \2055 -command [itcl::code $this AdjustSetting axis -labels] \1967 -variable [itcl::scope _settings(axisLabelsVisible)] \ 1968 -command [itcl::code $this AdjustSetting axisLabelsVisible] \ 2056 1969 -font "Arial 9" 2057 1970 … … 2074 1987 label $inner.mode_l -text "Mode" -font "Arial 9" 2075 1988 2076 itk_component add axis mode {1989 itk_component add axisMode { 2077 1990 Rappture::Combobox $inner.mode -width 10 -editable no 2078 1991 } … … 2082 1995 "furthest_triad" "furthest" \ 2083 1996 "outer_edges" "outer" 2084 $itk_component(axis mode) value "static"2085 bind $inner.mode <<Value>> [itcl::code $this AdjustSetting axis -mode]1997 $itk_component(axisMode) value "static" 1998 bind $inner.mode <<Value>> [itcl::code $this AdjustSetting axisMode] 2086 1999 2087 2000 blt::table $inner \ … … 2145 2058 2146 2059 checkbutton $inner.visible \ 2147 -text " ShowCutplanes" \2148 -variable [itcl::scope _settings(cutplane -visible)] \2149 -command [itcl::code $this AdjustSetting cutplane -visible] \2060 -text "Cutplanes" \ 2061 -variable [itcl::scope _settings(cutplaneVisible)] \ 2062 -command [itcl::code $this AdjustSetting cutplaneVisible] \ 2150 2063 -font "Arial 9" 2151 2064 2152 2065 checkbutton $inner.wireframe \ 2153 -text " ShowWireframe" \2154 -variable [itcl::scope _settings(cutplane -wireframe)] \2155 -command [itcl::code $this AdjustSetting cutplane -wireframe] \2066 -text "Wireframe" \ 2067 -variable [itcl::scope _settings(cutplaneWireframe)] \ 2068 -command [itcl::code $this AdjustSetting cutplaneWireframe] \ 2156 2069 -font "Arial 9" 2157 2070 2158 2071 checkbutton $inner.lighting \ 2159 2072 -text "Enable Lighting" \ 2160 -variable [itcl::scope _settings(cutplane -lighting)] \2161 -command [itcl::code $this AdjustSetting cutplane -lighting] \2073 -variable [itcl::scope _settings(cutplaneLighting)] \ 2074 -command [itcl::code $this AdjustSetting cutplaneLighting] \ 2162 2075 -font "Arial 9" 2163 2076 2164 2077 checkbutton $inner.edges \ 2165 -text " ShowEdges" \2166 -variable [itcl::scope _settings(cutplane -edges)] \2167 -command [itcl::code $this AdjustSetting cutplane -edges] \2078 -text "Edges" \ 2079 -variable [itcl::scope _settings(cutplaneEdges)] \ 2080 -command [itcl::code $this AdjustSetting cutplaneEdges] \ 2168 2081 -font "Arial 9" 2169 2082 2170 2083 label $inner.opacity_l -text "Opacity" -font "Arial 9" 2171 2084 ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ 2172 -variable [itcl::scope _settings(cutplane -opacity)] \2085 -variable [itcl::scope _settings(cutplaneOpacity)] \ 2173 2086 -width 10 \ 2174 2087 -showvalue off \ 2175 -command [itcl::code $this AdjustSetting cutplane -opacity]2176 $inner.opacity set $_settings(cutplane -opacity)2088 -command [itcl::code $this AdjustSetting cutplaneOpacity] 2089 $inner.opacity set $_settings(cutplaneOpacity) 2177 2090 2178 2091 # X-value slicer... 2179 itk_component add x CutButton {2092 itk_component add xbutton { 2180 2093 Rappture::PushButton $inner.xbutton \ 2181 2094 -onimage [Rappture::icon x-cutplane] \ 2182 2095 -offimage [Rappture::icon x-cutplane] \ 2183 -command [itcl::code $this AdjustSetting cutplane -xvisible] \2184 -variable [itcl::scope _settings(cutplane -xvisible)]2185 } 2186 Rappture::Tooltip::for $itk_component(x CutButton) \2096 -command [itcl::code $this AdjustSetting cutplaneXVisible] \ 2097 -variable [itcl::scope _settings(cutplaneXVisible)] 2098 } 2099 Rappture::Tooltip::for $itk_component(xbutton) \ 2187 2100 "Toggle the X-axis cutplane on/off" 2188 2101 2189 itk_component add x CutScale{2102 itk_component add xposition { 2190 2103 ::scale $inner.xval -from 100 -to 1 \ 2191 2104 -width 10 -orient vertical -showvalue yes \ 2192 2105 -borderwidth 1 -highlightthickness 0 \ 2193 2106 -command [itcl::code $this EventuallySetCutplane x] \ 2194 -variable [itcl::scope _settings(cutplane -xposition)]2107 -variable [itcl::scope _settings(cutplaneXPosition)] 2195 2108 } { 2196 2109 usual … … 2198 2111 } 2199 2112 # Set the default cutplane value before disabling the scale. 2200 $itk_component(x CutScale) set 502201 $itk_component(x CutScale) configure -state disabled2202 Rappture::Tooltip::for $itk_component(x CutScale) \2113 $itk_component(xposition) set 50 2114 $itk_component(xposition) configure -state disabled 2115 Rappture::Tooltip::for $itk_component(xposition) \ 2203 2116 "@[itcl::code $this Slice tooltip x]" 2204 2117 2205 2118 # Y-value slicer... 2206 itk_component add y CutButton {2119 itk_component add ybutton { 2207 2120 Rappture::PushButton $inner.ybutton \ 2208 2121 -onimage [Rappture::icon y-cutplane] \ 2209 2122 -offimage [Rappture::icon y-cutplane] \ 2210 -command [itcl::code $this AdjustSetting cutplane -yvisible] \2211 -variable [itcl::scope _settings(cutplane -yvisible)]2212 } 2213 Rappture::Tooltip::for $itk_component(y CutButton) \2123 -command [itcl::code $this AdjustSetting cutplaneYVisible] \ 2124 -variable [itcl::scope _settings(cutplaneYVisible)] 2125 } 2126 Rappture::Tooltip::for $itk_component(ybutton) \ 2214 2127 "Toggle the Y-axis cutplane on/off" 2215 2128 2216 itk_component add y CutScale{2129 itk_component add yposition { 2217 2130 ::scale $inner.yval -from 100 -to 1 \ 2218 2131 -width 10 -orient vertical -showvalue yes \ 2219 2132 -borderwidth 1 -highlightthickness 0 \ 2220 2133 -command [itcl::code $this EventuallySetCutplane y] \ 2221 -variable [itcl::scope _settings(cutplane -yposition)]2134 -variable [itcl::scope _settings(cutplaneYPosition)] 2222 2135 } { 2223 2136 usual 2224 2137 ignore -borderwidth -highlightthickness 2225 2138 } 2226 Rappture::Tooltip::for $itk_component(y CutScale) \2139 Rappture::Tooltip::for $itk_component(yposition) \ 2227 2140 "@[itcl::code $this Slice tooltip y]" 2228 2141 # Set the default cutplane value before disabling the scale. 2229 $itk_component(y CutScale) set 502230 $itk_component(y CutScale) configure -state disabled2142 $itk_component(yposition) set 50 2143 $itk_component(yposition) configure -state disabled 2231 2144 2232 2145 # Z-value slicer... 2233 itk_component add z CutButton {2146 itk_component add zbutton { 2234 2147 Rappture::PushButton $inner.zbutton \ 2235 2148 -onimage [Rappture::icon z-cutplane] \ 2236 2149 -offimage [Rappture::icon z-cutplane] \ 2237 -command [itcl::code $this AdjustSetting cutplane -zvisible] \2238 -variable [itcl::scope _settings(cutplane -zvisible)]2239 } 2240 Rappture::Tooltip::for $itk_component(z CutButton) \2150 -command [itcl::code $this AdjustSetting cutplaneZVisible] \ 2151 -variable [itcl::scope _settings(cutplaneZVisible)] 2152 } 2153 Rappture::Tooltip::for $itk_component(zbutton) \ 2241 2154 "Toggle the Z-axis cutplane on/off" 2242 2155 2243 itk_component add z CutScale{2156 itk_component add zposition { 2244 2157 ::scale $inner.zval -from 100 -to 1 \ 2245 2158 -width 10 -orient vertical -showvalue yes \ 2246 2159 -borderwidth 1 -highlightthickness 0 \ 2247 2160 -command [itcl::code $this EventuallySetCutplane z] \ 2248 -variable [itcl::scope _settings(cutplane -zposition)]2161 -variable [itcl::scope _settings(cutplaneZPosition)] 2249 2162 } { 2250 2163 usual 2251 2164 ignore -borderwidth -highlightthickness 2252 2165 } 2253 $itk_component(zCutScale) set 50 2254 $itk_component(zCutScale) configure -state disabled 2255 #$itk_component(zCutScale) configure -state disabled 2256 Rappture::Tooltip::for $itk_component(zCutScale) \ 2166 $itk_component(zposition) set 50 2167 $itk_component(zposition) configure -state disabled 2168 Rappture::Tooltip::for $itk_component(zposition) \ 2257 2169 "@[itcl::code $this Slice tooltip z]" 2258 2170 2259 2171 blt::table $inner \ 2260 0,0 $inner.visible -anchor w -pady 2 -cspan 4 \ 2261 1,0 $inner.lighting -anchor w -pady 2 -cspan 4 \ 2262 2,0 $inner.wireframe -anchor w -pady 2 -cspan 4 \ 2263 3,0 $inner.edges -anchor w -pady 2 -cspan 4 \ 2264 4,0 $inner.opacity_l -anchor w -pady 2 -cspan 3 \ 2265 5,0 $inner.opacity -fill x -pady 2 -cspan 3 \ 2266 6,0 $itk_component(xCutButton) -anchor e -padx 2 -pady 2 \ 2267 7,0 $itk_component(xCutScale) -fill y \ 2268 6,1 $itk_component(yCutButton) -anchor e -padx 2 -pady 2 \ 2269 7,1 $itk_component(yCutScale) -fill y \ 2270 6,2 $itk_component(zCutButton) -anchor e -padx 2 -pady 2 \ 2271 7,2 $itk_component(zCutScale) -fill y \ 2172 0,0 $inner.visible -anchor w -pady 2 -cspan 3 \ 2173 1,0 $inner.lighting -anchor w -pady 2 -cspan 3 \ 2174 2,0 $inner.wireframe -anchor w -pady 2 -cspan 3 \ 2175 3,0 $inner.edges -anchor w -pady 2 -cspan 3 \ 2176 4,0 $inner.opacity_l -anchor w -pady 2 -cspan 1 \ 2177 4,1 $inner.opacity -fill x -pady 2 -cspan 3 \ 2178 6,0 $inner.xbutton -anchor w -padx 2 -pady 2 \ 2179 7,0 $inner.ybutton -anchor w -padx 2 -pady 2 \ 2180 8,0 $inner.zbutton -anchor w -padx 2 -pady 2 \ 2181 6,1 $inner.xval -fill y -rspan 4 \ 2182 6,2 $inner.yval -fill y -rspan 4 \ 2183 6,3 $inner.zval -fill y -rspan 4 \ 2184 2272 2185 2273 2186 blt::table configure $inner r* c* -resize none 2274 blt::table configure $inner r7 c3 -resize expand 2187 blt::table configure $inner r9 c4 -resize expand 2188 blt::table configure $inner r5 -height 0.12i 2275 2189 } 2276 2190 … … 2311 2225 SendCmd "camera zoom $_view(zoom)" 2312 2226 } 2313 } 2314 } 2315 } 2316 } 2317 2318 itcl::body Rappture::VtkIsosurfaceViewer::ConvertToVtkData { dataobj comp } { 2319 foreach { x1 x2 xN y1 y2 yN } [$dataobj mesh $comp] break 2320 set values [$dataobj values $comp] 2321 append out "# vtk DataFile Version 2.0 \n" 2322 append out "Test data \n" 2323 append out "ASCII \n" 2324 append out "DATASET STRUCTURED_POINTS \n" 2325 append out "DIMENSIONS $xN $yN 1 \n" 2326 append out "ORIGIN 0 0 0 \n" 2327 append out "SPACING 1 1 1 \n" 2328 append out "POINT_DATA [expr $xN * $yN] \n" 2329 append out "SCALARS field float 1 \n" 2330 append out "LOOKUP_TABLE default \n" 2331 append out [join $values "\n"] 2332 append out "\n" 2333 return $out 2334 } 2335 2227 } 2228 } 2229 } 2230 } 2336 2231 2337 2232 itcl::body Rappture::VtkIsosurfaceViewer::GetVtkData { args } { 2338 2233 set bytes "" 2339 2234 foreach dataobj [get] { 2340 foreach comp [$dataobj components] { 2341 set tag $dataobj-$comp 2342 #set contents [ConvertToVtkData $dataobj $comp] 2343 set contents [$dataobj blob $comp] 2235 foreach cname [$dataobj components] { 2236 set tag $dataobj-$cname 2237 set contents [$dataobj vtkdata $cname] 2344 2238 append bytes "$contents\n\n" 2345 2239 } … … 2364 2258 radiobutton $inner.vtk_button -text "VTK data file" \ 2365 2259 -variable [itcl::scope _downloadPopup(format)] \ 2366 -font " Helvetica9 " \2260 -font "Arial 9 " \ 2367 2261 -value vtk 2368 2262 Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file." 2369 2263 radiobutton $inner.image_button -text "Image File" \ 2370 2264 -variable [itcl::scope _downloadPopup(format)] \ 2265 -font "Arial 9 " \ 2371 2266 -value image 2372 2267 Rappture::Tooltip::for $inner.image_button \ … … 2401 2296 # Parse style string. 2402 2297 set tag $dataobj-$comp 2403 set style [$dataobj style $comp] 2404 array set settings { 2405 -color \#808080 2298 array set style { 2299 -color BCGYR 2406 2300 -edges 0 2407 2301 -edgecolor black … … 2410 2304 -wireframe 0 2411 2305 -lighting 1 2412 -seeds 12413 -seedcolor white2414 -visible 12415 2306 -outline 0 2416 } 2307 -levels 10 2308 } 2309 array set style [$dataobj style $comp] 2417 2310 if { $dataobj != $_first } { 2418 set settings(-opacity) 1 2419 } 2420 array set settings $style 2311 set style(-opacity) 1 2312 } 2313 if { $_currentColormap == "" } { 2314 set stylelist [$dataobj style $comp] 2315 if { $stylelist != "" } { 2316 array set style $stylelist 2317 set stylelist [array get style] 2318 SetCurrentColormap $stylelist 2319 } 2320 $itk_component(palette) value $style(-color) 2321 } 2421 2322 SendCmd "cutplane add $tag" 2422 2323 SendCmd "cutplane edges 0 $tag" … … 2431 2332 SendCmd "cutplane axis $axis 0 $tag" 2432 2333 } 2433 2434 SendCmd "contour3d add numcontours 10$tag"2435 SendCmd "contour3d edges $s ettings(-edges) $tag"2436 SendCmd "dataset outline $s ettings(-outline) $tag"2437 set _settings( contour-outline) $settings(-outline)2438 set _settings( contour-edges) $settings(-edges)2334 set _numContours $style(-levels) 2335 SendCmd "contour3d add numcontours $_numContours $tag" 2336 SendCmd "contour3d edges $style(-edges) $tag" 2337 SendCmd "dataset outline $style(-outline) $tag" 2338 set _settings(isosurfaceOutline) $style(-outline) 2339 set _settings(isosurfaceEdges) $style(-edges) 2439 2340 #SendCmd "contour3d color [Color2RGB $settings(-color)] $tag" 2440 SendCmd "contour3d lighting $settings(-lighting) $tag" 2441 set _settings(contour-lighting) $settings(-lighting) 2442 SendCmd "contour3d linecolor [Color2RGB $settings(-edgecolor)] $tag" 2443 SendCmd "contour3d linewidth $settings(-linewidth) $tag" 2444 SendCmd "contour3d opacity $settings(-opacity) $tag" 2445 set _settings(contour-opacity) $settings(-opacity) 2446 SendCmd "contour3d wireframe $settings(-wireframe) $tag" 2447 set _settings(contour-wireframe) $settings(-wireframe) 2448 set _settings(contour-opacity) [expr $settings(-opacity) * 100.0] 2449 SetColormap $dataobj $comp 2341 SendCmd "contour3d lighting $style(-lighting) $tag" 2342 set _settings(isosurfaceLighting) $style(-lighting) 2343 SendCmd "contour3d linecolor [Color2RGB $style(-edgecolor)] $tag" 2344 SendCmd "contour3d linewidth $style(-linewidth) $tag" 2345 SendCmd "contour3d opacity $style(-opacity) $tag" 2346 set _settings(isosurfaceOpacity) $style(-opacity) 2347 SendCmd "contour3d wireframe $style(-wireframe) $tag" 2348 set _settings(isosurfaceWireframe) $style(-wireframe) 2349 set _settings(isosurfaceOpacity) [expr $style(-opacity) * 100.0] 2450 2350 } 2451 2351 … … 2455 2355 } 2456 2356 return 1 2457 }2458 2459 # ----------------------------------------------------------------------2460 # USAGE: ReceiveLegend <colormap> <title> <vmin> <vmax> <size>2461 #2462 # Invoked automatically whenever the "legend" command comes in from2463 # the rendering server. Indicates that binary image data with the2464 # specified <size> will follow.2465 # ----------------------------------------------------------------------2466 itcl::body Rappture::VtkIsosurfaceViewer::ReceiveLegend { colormap title vmin vmax size } {2467 set _legendPending 02468 #puts stderr "ReceiveLegend colormap=$colormap title=$title range=$vmin,$vmax size=$size"2469 set _limits(vmin) $vmin2470 set _limits(vmax) $vmax2471 set _title $title2472 regsub {\(mag\)} $title "" _title2473 if { [IsConnected] } {2474 set bytes [ReceiveBytes $size]2475 if { ![info exists _image(legend)] } {2476 set _image(legend) [image create photo]2477 }2478 $_image(legend) configure -data $bytes2479 #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"2480 if { [catch {DrawLegend $_title} errs] != 0 } {2481 puts stderr errs=$errs2482 }2483 }2484 }2485 2486 #2487 # DrawLegend --2488 #2489 # Draws the legend in it's own canvas which resides to the right2490 # of the contour plot area.2491 #2492 itcl::body Rappture::VtkIsosurfaceViewer::DrawLegend { name } {2493 set c $itk_component(view)2494 set w [winfo width $c]2495 set h [winfo height $c]2496 set font "Arial 8"2497 set lineht [font metrics $font -linespace]2498 2499 if { [info exists _fields($name)] } {2500 foreach { title units } $_fields($name) break2501 if { $units != "" } {2502 set title [format "%s (%s)" $title $units]2503 }2504 } else {2505 set title $name2506 }2507 if { $_settings(legend-visible) } {2508 set x [expr $w - 2]2509 if { [$c find withtag "legend"] == "" } {2510 set y 22511 $c create text $x $y \2512 -anchor ne \2513 -fill $itk_option(-plotforeground) -tags "title legend" \2514 -font $font2515 incr y $lineht2516 $c create text $x $y \2517 -anchor ne \2518 -fill $itk_option(-plotforeground) -tags "vmax legend" \2519 -font $font2520 incr y $lineht2521 $c create image $x $y \2522 -anchor ne \2523 -image $_image(legend) -tags "colormap legend"2524 $c create text $x [expr {$h-2}] \2525 -anchor se \2526 -fill $itk_option(-plotforeground) -tags "vmin legend" \2527 -font $font2528 #$c bind colormap <Enter> [itcl::code $this EnterLegend %x %y]2529 $c bind colormap <Leave> [itcl::code $this LeaveLegend]2530 $c bind colormap <Motion> [itcl::code $this MotionLegend %x %y]2531 }2532 $c bind title <ButtonPress> [itcl::code $this Combo post]2533 $c bind title <Enter> [itcl::code $this Combo activate]2534 $c bind title <Leave> [itcl::code $this Combo deactivate]2535 # Reset the item coordinates according the current size of the plot.2536 $c itemconfigure title -text $title2537 if { $_limits(vmin) != "" } {2538 $c itemconfigure vmin -text [format %g $_limits(vmin)]2539 }2540 if { $_limits(vmax) != "" } {2541 $c itemconfigure vmax -text [format %g $_limits(vmax)]2542 }2543 set y 22544 $c coords title $x $y2545 incr y $lineht2546 $c coords vmax $x $y2547 incr y $lineht2548 $c coords colormap $x $y2549 $c coords vmin $x [expr {$h - 2}]2550 }2551 2357 } 2552 2358 … … 2590 2396 set imgY [expr $y - 2 * ($lineht + 2)] 2591 2397 2398 set title "" 2592 2399 if { [info exists _fields($_title)] } { 2593 2400 foreach { title units } $_fields($_title) break 2401 if { $title == "component" } { 2402 set title "" 2403 } 2594 2404 if { $units != "" } { 2595 set title [format "%s (%s)" $title$units]2405 append title [format " (%s)" $units] 2596 2406 } 2597 2407 } else { 2598 2408 set title $_title 2409 if { $title == "component" } { 2410 set title "" 2411 } 2599 2412 } 2600 2413 # Make a swatch of the selected color 2601 2414 if { [catch { $_image(legend) get 10 $imgY } pixel] != 0 } { 2602 #puts stderr "out of range: $imgY"2603 2415 return 2604 2416 } … … 2606 2418 set _image(swatch) [image create photo -width 24 -height 24] 2607 2419 } 2608 $_image(swatch) blank white2609 $_image(swatch) draw rectangle 3 3 20 20 -color $pixel -shadow 12610 $_image(swatch) draw rectangle 3 3 20 20 -color black -linewidth 12611 2612 if 0 {2613 2420 set color [eval format "\#%02x%02x%02x" $pixel] 2614 2421 $_image(swatch) put black -to 0 0 23 23 2615 2422 $_image(swatch) put $color -to 1 1 22 22 2616 } 2423 .rappturetooltip configure -icon $_image(swatch) 2424 2617 2425 .rappturetooltip configure -icon $_image(swatch) 2618 2426 … … 2643 2451 "move" { 2644 2452 set axis [lindex $args 0] 2645 set oldval $_settings(axis-${axis}position) 2453 set a [string toupper $axis] 2454 set oldval $_settings(cutplane${a}Position) 2646 2455 set newval [lindex $args 1] 2647 2456 if {[llength $args] != 2} { … … 2653 2462 "tooltip" { 2654 2463 set axis [lindex $args 0] 2655 set val [$itk_component(${axis} CutScale) get]2464 set val [$itk_component(${axis}position) get] 2656 2465 return "Move the [string toupper $axis] cut plane.\nCurrently: $axis = $val%" 2657 2466 } … … 2662 2471 } 2663 2472 2473 # 2474 # ReceiveLegend -- 2475 # 2476 # Invoked automatically whenever the "legend" command comes in from 2477 # the rendering server. Indicates that binary image data with the 2478 # specified <size> will follow. 2479 # 2480 itcl::body Rappture::VtkIsosurfaceViewer::ReceiveLegend { colormap title min max size } { 2481 #puts stderr "ReceiveLegend colormap=$colormap title=$title range=$min,$max size=$size" 2482 set _title $title 2483 regsub {\(mag\)} $title "" _title 2484 if { [IsConnected] } { 2485 set bytes [ReceiveBytes $size] 2486 if { ![info exists _image(legend)] } { 2487 set _image(legend) [image create photo] 2488 } 2489 $_image(legend) configure -data $bytes 2490 #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>" 2491 if { [catch {DrawLegend $_title} errs] != 0 } { 2492 global errorInfo 2493 puts stderr "errs=$errs errorInfo=$errorInfo" 2494 } 2495 } 2496 } 2497 2498 # 2499 # DrawLegend -- 2500 # 2501 # Draws the legend in it's own canvas which resides to the right 2502 # of the contour plot area. 2503 # 2504 itcl::body Rappture::VtkIsosurfaceViewer::DrawLegend { name } { 2505 set c $itk_component(view) 2506 set w [winfo width $c] 2507 set h [winfo height $c] 2508 set font "Arial 8" 2509 set lineht [font metrics $font -linespace] 2510 2511 if { $name == "component" } { 2512 set title "" 2513 } else { 2514 if { [info exists _fields($name)] } { 2515 foreach { title units } $_fields($name) break 2516 if { $units != "" } { 2517 set title [format "%s (%s)" $title $units] 2518 } 2519 } else { 2520 set title $name 2521 } 2522 } 2523 set x [expr $w - 2] 2524 if { !$_settings(legendVisible) } { 2525 $c delete legend 2526 return 2527 } 2528 if { [$c find withtag "legend"] == "" } { 2529 set y 2 2530 # If there's a legend title, create a text item for the title. 2531 if { $title != "" } { 2532 $c create text $x $y \ 2533 -anchor ne \ 2534 -fill $itk_option(-plotforeground) -tags "title legend" \ 2535 -font $font 2536 incr y $lineht 2537 } 2538 $c create text $x $y \ 2539 -anchor ne \ 2540 -fill $itk_option(-plotforeground) -tags "zmax legend" \ 2541 -font $font 2542 incr y $lineht 2543 $c create image $x $y \ 2544 -anchor ne \ 2545 -image $_image(legend) -tags "colormap legend" 2546 $c create text $x [expr {$h-2}] \ 2547 -anchor se \ 2548 -fill $itk_option(-plotforeground) -tags "zmin legend" \ 2549 -font $font 2550 #$c bind colormap <Enter> [itcl::code $this EnterLegend %x %y] 2551 $c bind colormap <Leave> [itcl::code $this LeaveLegend] 2552 $c bind colormap <Motion> [itcl::code $this MotionLegend %x %y] 2553 } 2554 $c delete isoline 2555 set x2 $x 2556 set iw [image width $_image(legend)] 2557 set ih [image height $_image(legend)] 2558 set x1 [expr $x2 - ($iw*12)/10] 2559 set color $_settings(isolineColor) 2560 # Draw the isolines on the legend. 2561 if { $color != "none" && $_numContours > 0 } { 2562 set pixels [blt::vector create \#auto] 2563 set values [blt::vector create \#auto] 2564 set range [image height $_image(legend)] 2565 # Order of pixels is max to min (max is at top of legend). 2566 $pixels seq $ih 0 $_numContours 2567 set offset [expr 2 + $lineht] 2568 # If there's a legend title, increase the offset by the line height. 2569 if { $title != "" } { 2570 incr offset $lineht 2571 } 2572 $pixels expr {round($pixels + $offset)} 2573 # Order of values is min to max. 2574 $values seq $_limits(zmin) $_limits(zmax) $_numContours 2575 set tags "isoline legend" 2576 foreach pos [$pixels range 0 end] value [$values range end 0] { 2577 set y1 [expr int($pos)] 2578 set id [$c create line $x1 $y1 $x2 $y1 -fill $color -tags $tags] 2579 $c bind $id <Enter> [itcl::code $this EnterIsoline %x %y $value] 2580 $c bind $id <Leave> [itcl::code $this LeaveIsoline] 2581 } 2582 blt::vector destroy $pixels $values 2583 } 2584 2585 $c bind title <ButtonPress> [itcl::code $this Combo post] 2586 $c bind title <Enter> [itcl::code $this Combo activate] 2587 $c bind title <Leave> [itcl::code $this Combo deactivate] 2588 # Reset the item coordinates according the current size of the plot. 2589 $c itemconfigure title -text $title 2590 if { [info exists _limits(zmin)] && $_limits(zmin) != "" } { 2591 $c itemconfigure zmin -text [format %g $_limits(zmin)] 2592 } 2593 if { [info exists _limits(zmax)] && $_limits(zmax) != "" } { 2594 $c itemconfigure zmax -text [format %g $_limits(zmax)] 2595 } 2596 set y 2 2597 # If there's a legend title, move the title to the correct position 2598 if { $title != "" } { 2599 $c coords title $x $y 2600 incr y $lineht 2601 } 2602 $c coords zmax $x $y 2603 incr y $lineht 2604 $c coords colormap $x $y 2605 $c coords zmin $x [expr {$h - 2}] 2606 } 2607 2608 # 2609 # EnterIsoline -- 2610 # 2611 itcl::body Rappture::VtkIsosurfaceViewer::EnterIsoline { x y value } { 2612 SetIsolineTip $x $y $value 2613 } 2614 2615 # 2616 # LeaveIsoline -- 2617 # 2618 itcl::body Rappture::VtkIsosurfaceViewer::LeaveIsoline { } { 2619 Rappture::Tooltip::tooltip cancel 2620 .rappturetooltip configure -icon "" 2621 } 2622 2623 # 2624 # SetIsolineTip -- 2625 # 2626 itcl::body Rappture::VtkIsosurfaceViewer::SetIsolineTip { x y value } { 2627 set c $itk_component(view) 2628 set w [winfo width $c] 2629 set h [winfo height $c] 2630 set font "Arial 8" 2631 set lineht [font metrics $font -linespace] 2632 2633 if { [info exists _fields($_title)] } { 2634 foreach { title units } $_fields($_title) break 2635 if { $title == "component" } { 2636 set title "" 2637 } 2638 if { $units != "" } { 2639 set title [format "%s (%s)" $title $units] 2640 } 2641 } else { 2642 set title $_title 2643 } 2644 # Make a swatch of the selected color 2645 set imgHeight [image height $_image(legend)] 2646 set coords [$c coords colormap] 2647 set imgX [expr $w - [image width $_image(legend)] - 2] 2648 set imgY [expr $y - 2 * ($lineht + 2)] 2649 2650 if { [catch { $_image(legend) get 10 $imgY } pixel] != 0 } { 2651 return 2652 } 2653 if { ![info exists _image(swatch)] } { 2654 set _image(swatch) [image create photo -width 24 -height 24] 2655 } 2656 set color [eval format "\#%02x%02x%02x" $pixel] 2657 $_image(swatch) put black -to 0 0 23 23 2658 $_image(swatch) put $color -to 1 1 22 22 2659 .rappturetooltip configure -icon $_image(swatch) 2660 2661 # Compute the value of the point 2662 set tipx [expr $x + 15] 2663 set tipy [expr $y - 5] 2664 Rappture::Tooltip::text $c "Isosurface $value" 2665 Rappture::Tooltip::tooltip show $c +$tipx,+$tipy 2666 } 2664 2667 2665 2668 # ---------------------------------------------------------------------- … … 2688 2691 } 2689 2692 deactivate { 2690 $c itemconfigure title -fill white2693 $c itemconfigure title -fill $itk_option(-plotforeground) 2691 2694 } 2692 2695 invoke { 2693 $itk_component(field) value $_currentField 2694 AdjustSetting contour-field2696 $itk_component(field) value $_currentFieldName 2697 AdjustSetting field 2695 2698 } 2696 2699 default { … … 2699 2702 } 2700 2703 } 2704 2705 # 2706 # SetCurrentColormap -- 2707 # 2708 itcl::body Rappture::VtkIsosurfaceViewer::SetCurrentColormap { stylelist } { 2709 array set style { 2710 -color BCGYR 2711 -levels 10 2712 -opacity 1.0 2713 } 2714 array set style $stylelist 2715 2716 set name "$style(-color):$style(-levels):$style(-opacity)" 2717 if { ![info exists _colormaps($name)] } { 2718 set stylelist [array get style] 2719 BuildColormap $name $stylelist 2720 set _colormaps($name) $stylelist 2721 } 2722 set _currentColormap $name 2723 } 2724 2725 itcl::body Rappture::VtkIsosurfaceViewer::ColorsToColormap { colors } { 2726 switch -- $colors { 2727 "grey-to-blue" { 2728 return { 2729 0.0 0.200 0.200 0.200 2730 0.14285714285714285 0.400 0.400 0.400 2731 0.2857142857142857 0.600 0.600 0.600 2732 0.42857142857142855 0.900 0.900 0.900 2733 0.5714285714285714 0.800 1.000 1.000 2734 0.7142857142857143 0.600 1.000 1.000 2735 0.8571428571428571 0.400 0.900 1.000 2736 1.0 0.000 0.600 0.800 2737 } 2738 } 2739 "blue-to-grey" { 2740 return { 2741 0.0 0.000 0.600 0.800 2742 0.14285714285714285 0.400 0.900 1.000 2743 0.2857142857142857 0.600 1.000 1.000 2744 0.42857142857142855 0.800 1.000 1.000 2745 0.5714285714285714 0.900 0.900 0.900 2746 0.7142857142857143 0.600 0.600 0.600 2747 0.8571428571428571 0.400 0.400 0.400 2748 1.0 0.200 0.200 0.200 2749 } 2750 } 2751 "blue" { 2752 return { 2753 0.0 0.900 1.000 1.000 2754 0.1111111111111111 0.800 0.983 1.000 2755 0.2222222222222222 0.700 0.950 1.000 2756 0.3333333333333333 0.600 0.900 1.000 2757 0.4444444444444444 0.500 0.833 1.000 2758 0.5555555555555556 0.400 0.750 1.000 2759 0.6666666666666666 0.300 0.650 1.000 2760 0.7777777777777778 0.200 0.533 1.000 2761 0.8888888888888888 0.100 0.400 1.000 2762 1.0 0.000 0.250 1.000 2763 } 2764 } 2765 "brown-to-blue" { 2766 return { 2767 0.0 0.200 0.100 0.000 2768 0.09090909090909091 0.400 0.187 0.000 2769 0.18181818181818182 0.600 0.379 0.210 2770 0.2727272727272727 0.800 0.608 0.480 2771 0.36363636363636365 0.850 0.688 0.595 2772 0.45454545454545453 0.950 0.855 0.808 2773 0.5454545454545454 0.800 0.993 1.000 2774 0.6363636363636364 0.600 0.973 1.000 2775 0.7272727272727273 0.400 0.940 1.000 2776 0.8181818181818182 0.200 0.893 1.000 2777 0.9090909090909091 0.000 0.667 0.800 2778 1.0 0.000 0.480 0.600 2779 } 2780 } 2781 "blue-to-brown" { 2782 return { 2783 0.0 0.000 0.480 0.600 2784 0.09090909090909091 0.000 0.667 0.800 2785 0.18181818181818182 0.200 0.893 1.000 2786 0.2727272727272727 0.400 0.940 1.000 2787 0.36363636363636365 0.600 0.973 1.000 2788 0.45454545454545453 0.800 0.993 1.000 2789 0.5454545454545454 0.950 0.855 0.808 2790 0.6363636363636364 0.850 0.688 0.595 2791 0.7272727272727273 0.800 0.608 0.480 2792 0.8181818181818182 0.600 0.379 0.210 2793 0.9090909090909091 0.400 0.187 0.000 2794 1.0 0.200 0.100 0.000 2795 } 2796 } 2797 "blue-to-orange" { 2798 return { 2799 0.0 0.000 0.167 1.000 2800 0.09090909090909091 0.100 0.400 1.000 2801 0.18181818181818182 0.200 0.600 1.000 2802 0.2727272727272727 0.400 0.800 1.000 2803 0.36363636363636365 0.600 0.933 1.000 2804 0.45454545454545453 0.800 1.000 1.000 2805 0.5454545454545454 1.000 1.000 0.800 2806 0.6363636363636364 1.000 0.933 0.600 2807 0.7272727272727273 1.000 0.800 0.400 2808 0.8181818181818182 1.000 0.600 0.200 2809 0.9090909090909091 1.000 0.400 0.100 2810 1.0 1.000 0.167 0.000 2811 } 2812 } 2813 "orange-to-blue" { 2814 return { 2815 0.0 1.000 0.167 0.000 2816 0.09090909090909091 1.000 0.400 0.100 2817 0.18181818181818182 1.000 0.600 0.200 2818 0.2727272727272727 1.000 0.800 0.400 2819 0.36363636363636365 1.000 0.933 0.600 2820 0.45454545454545453 1.000 1.000 0.800 2821 0.5454545454545454 0.800 1.000 1.000 2822 0.6363636363636364 0.600 0.933 1.000 2823 0.7272727272727273 0.400 0.800 1.000 2824 0.8181818181818182 0.200 0.600 1.000 2825 0.9090909090909091 0.100 0.400 1.000 2826 1.0 0.000 0.167 1.000 2827 } 2828 } 2829 "rainbow" { 2830 set clist { 2831 "#EE82EE" 2832 "#4B0082" 2833 "blue" 2834 "#008000" 2835 "yellow" 2836 "#FFA500" 2837 "red" 2838 } 2839 } 2840 "BGYOR" { 2841 set clist { 2842 "blue" 2843 "#008000" 2844 "yellow" 2845 "#FFA500" 2846 "red" 2847 } 2848 } 2849 "ROYGB" { 2850 set clist { 2851 "red" 2852 "#FFA500" 2853 "yellow" 2854 "#008000" 2855 "blue" 2856 } 2857 } 2858 "RYGCB" { 2859 set clist { 2860 "red" 2861 "yellow" 2862 "green" 2863 "cyan" 2864 "blue" 2865 } 2866 } 2867 "BCGYR" { 2868 set clist { 2869 "blue" 2870 "cyan" 2871 "green" 2872 "yellow" 2873 "red" 2874 } 2875 } 2876 "spectral" { 2877 return { 2878 0.0 0.150 0.300 1.000 2879 0.1 0.250 0.630 1.000 2880 0.2 0.450 0.850 1.000 2881 0.3 0.670 0.970 1.000 2882 0.4 0.880 1.000 1.000 2883 0.5 1.000 1.000 0.750 2884 0.6 1.000 0.880 0.600 2885 0.7 1.000 0.680 0.450 2886 0.8 0.970 0.430 0.370 2887 0.9 0.850 0.150 0.196 2888 1.0 0.650 0.000 0.130 2889 } 2890 } 2891 "green-to-magenta" { 2892 return { 2893 0.0 0.000 0.316 0.000 2894 0.06666666666666667 0.000 0.526 0.000 2895 0.13333333333333333 0.000 0.737 0.000 2896 0.2 0.000 0.947 0.000 2897 0.26666666666666666 0.316 1.000 0.316 2898 0.3333333333333333 0.526 1.000 0.526 2899 0.4 0.737 1.000 0.737 2900 0.4666666666666667 1.000 1.000 1.000 2901 0.5333333333333333 1.000 0.947 1.000 2902 0.6 1.000 0.737 1.000 2903 0.6666666666666666 1.000 0.526 1.000 2904 0.7333333333333333 1.000 0.316 1.000 2905 0.8 0.947 0.000 0.947 2906 0.8666666666666667 0.737 0.000 0.737 2907 0.9333333333333333 0.526 0.000 0.526 2908 1.0 0.316 0.000 0.316 2909 } 2910 } 2911 "greyscale" { 2912 return { 2913 0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0 2914 } 2915 } 2916 "nanohub" { 2917 set clist "white yellow green cyan blue magenta" 2918 } 2919 default { 2920 set clist $colors 2921 } 2922 } 2923 set cmap {} 2924 for {set i 0} {$i < [llength $clist]} {incr i} { 2925 set x [expr {double($i)/([llength $clist]-1)}] 2926 set color [lindex $clist $i] 2927 append cmap "$x [Color2RGB $color] " 2928 } 2929 return $cmap 2930 } 2931 2932 # 2933 # BuildColormap -- 2934 # 2935 itcl::body Rappture::VtkIsosurfaceViewer::BuildColormap { name stylelist } { 2936 array set style $stylelist 2937 set cmap [ColorsToColormap $style(-color)] 2938 if { [llength $cmap] == 0 } { 2939 set cmap "0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0" 2940 } 2941 if { ![info exists _settings(isosurfaceOpacity)] } { 2942 set _settings(isosurfaceOpacity) $style(-opacity) 2943 } 2944 set max $_settings(isosurfaceOpacity) 2945 2946 set wmap "0.0 1.0 1.0 1.0" 2947 SendCmd "colormap add $name { $cmap } { $wmap }" 2948 } 2949 2950 itcl::body Rappture::VtkIsosurfaceViewer::ResetColormap { color } { 2951 array set style { 2952 -color BCGYR 2953 -levels 10 2954 -opacity 1.0 2955 } 2956 if { [info exists _colormap($_currentColormap)] } { 2957 array set style $_colormap($_currentColormap) 2958 } 2959 set style(-color) $color 2960 SetCurrentColormap [array get style] 2961 }
Note: See TracChangeset
for help on using the changeset viewer.