Changeset 4504 for branches/1.3/gui/scripts/field.tcl
- Timestamp:
- Jul 16, 2014, 12:21:36 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.3/gui/scripts/field.tcl
r4494 r4504 1 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 3 2 # ---------------------------------------------------------------------- 4 3 # COMPONENT: field - extracts data from an XML description of a field … … 82 81 # valid data. 83 82 private variable _isValidComponent; # Array of valid components found 83 private variable _alwaysConvertDX 0; 84 84 85 constructor {xmlobj path} { 85 86 # defined below … … 88 89 # defined below 89 90 } 90 public method blob { cname } 91 public method blob { cname } 91 92 public method components {args} 92 93 public method controls {option args} … … 94 95 public method numComponents {cname} 95 96 public method fieldlimits {} 97 public method valueLimits { cname } 96 98 public method flowhints { cname } 97 99 public method hints {{key ""}} … … 150 152 151 153 private method AvsToVtk { cname contents } 154 private method DicomToVtk { cname contents } 152 155 private method BuildPointsOnMesh { cname } 153 156 protected method GetAssociation { cname } … … 318 321 } 319 322 if {[info exists _comp2dx($cname)]} { 320 return "" ;# no mesh -- it's embedded in the blobdata323 return "" ;# no mesh -- it's embedded in the value data 321 324 } 322 325 if {[info exists _comp2mesh($cname)]} { … … 362 365 } 363 366 if {[info exists _comp2dx($cname)]} { 364 error "method \"values\" is not implemented for dx filedata"367 error "method \"values\" is not implemented for dx data" 365 368 } 366 369 if {[info exists _comp2unirect2d($cname)]} { … … 389 392 } 390 393 if {[info exists _comp2dx($cname)]} { 391 return $_comp2dx($cname) ;# return gzipped, base64-encoded DX data394 return $_comp2dx($cname) 392 395 } 393 396 if {[info exists _comp2unirect2d($cname)]} { … … 400 403 } 401 404 error "can't get field blob: Unknown component \"$cname\": should be one of [join [lsort [array names _comp2dims]] {, }]" 405 } 406 407 itcl::body Rappture::Field::valueLimits { cname } { 408 if { [info exists _comp2limits($cname)] } { 409 return $_comp2limits($cname) 410 } 411 return "" 402 412 } 403 413 … … 520 530 return [list $min $max] 521 531 } 532 522 533 523 534 # ---------------------------------------------------------------------- … … 789 800 } elseif {[$_field element $cname.ucd] != ""} { 790 801 set type "ucd" 802 } elseif {[$_field element $cname.dicom] != ""} { 803 set type "dicom" 791 804 } 792 805 set _comp2style($cname) "" … … 894 907 set _dim 3 895 908 set _comp2dims($cname) "3D" 896 if { $_viewer != "nanovis" && $_viewer != "flowvis" } { 897 set vtkdata [$_field get -decode yes $cname.$type] 898 if { $vtkdata == "" } { 899 puts stderr "WARNING: No data for \"$_path.$cname.$type\"" 900 continue; # Ignore this component 901 } 902 if 0 { 903 set f [open /tmp/$_path.$cname.dx "w"] 904 puts -nonewline $f $vtkdata 905 close $f 906 } 907 set vtkdata [Rappture::DxToVtk $vtkdata] 908 if 0 { 909 set f [open /tmp/$_path.$cname.vtk "w"] 910 puts -nonewline $f $vtkdata 911 close $f 912 } 909 set data [$_field get -decode no $cname.$type] 910 set contents [Rappture::encoding::decode -as zb64 $data] 911 if { $contents == "" } { 912 puts stderr "WARNING: No data for \"$_path.$cname.$type\"" 913 continue; # Ignore this component 914 } 915 set vector "" 916 if 0 { 917 set f [open /tmp/$_path.$cname.dx "w"] 918 puts -nonewline $f $contents 919 close $f 920 } 921 # This is temporary. I put a check for this in the DxToVtk 922 # parser. 923 if { [string range $contents 0 3] == "<DX>" } { 924 set contents [string range $contents 4 end] 925 } 926 if { [catch { Rappture::DxToVtk $contents } vtkdata] == 0 } { 913 927 ReadVtkDataSet $cname $vtkdata 928 } else { 929 puts stderr "Can't parse dx data: $vtkdata" 930 } 931 if 0 { 932 set f [open /tmp/$_path.$cname.vtk "w"] 933 puts -nonewline $f $vtkdata 934 close $f 935 } 936 if { $_alwaysConvertDX || 937 ($_viewer != "nanovis" && $_viewer != "flowvis") } { 914 938 set _type "vtk" 915 939 set _comp2vtk($cname) $vtkdata 916 940 } else { 917 set contents [$_field get -decode no $cname.$type]918 if { $contents == "" } {919 puts stderr "WARNING: No data for \"$_path.$cname.$type\""920 continue; # Ignore this component921 }922 941 set _type "dx" 923 set _comp2dx($cname) $ contents942 set _comp2dx($cname) $data 924 943 } 925 944 set _comp2style($cname) [$_field get $cname.style] … … 928 947 [Rappture::FlowHints ::\#auto $_field $cname $_units] 929 948 } 949 set _dim 3 950 incr _counter 951 } elseif { $type == "dicom"} { 952 set contents [$_field get $cname.dicom] 953 if { $contents == "" } { 954 continue; # Ignore this component 955 } 956 set viewer [$_field get "about.view"] 957 if { $viewer != "" } { 958 set _viewer $viewer 959 } 960 set vtkdata [DicomToVtk $cname $contents] 961 if { $_viewer == "" } { 962 set _viewer [expr {($_dim == 3) ? "vtkvolume" : "vtkimage"}] 963 } 964 set _comp2vtk($cname) $vtkdata 965 set _comp2style($cname) [$_field get $cname.style] 930 966 incr _counter 931 967 } elseif { $type == "ucd"} { … … 941 977 } 942 978 set _isValidComponent($cname) 1 979 #puts stderr "Field $cname type is: $_type" 943 980 } 944 981 if { [array size _isValidComponent] == 0 } { … … 1508 1545 # sort x-coords in increasing order 1509 1546 $xv sort $yv 1510 1511 1547 set _comp2dims($cname) "1D" 1512 1548 set _comp2xy($cname) [list $xv $yv] … … 1641 1677 file delete $tmpfile 1642 1678 return $vtkdata 1679 } 1680 1681 itcl::body Rappture::Field::DicomToVtk { cname path } { 1682 package require vtk 1683 1684 if { ![file exists $path] } { 1685 puts stderr "path \"$path\" doesn't exist." 1686 return 0 1687 } 1688 1689 if { [file isdir $path] } { 1690 set files [glob -nocomplain $path/*.dcm] 1691 if { [llength $files] == 0 } { 1692 set files [glob -nocomplain $path/*] 1693 if { [llength $files] == 0 } { 1694 puts stderr "no dicom files found in \"$path\"" 1695 return 0 1696 } 1697 } 1698 1699 #array set data [Rappture::DicomToVtk files $files] 1700 array set data [Rappture::DicomToVtk dir $path] 1701 } else { 1702 array set data [Rappture::DicomToVtk files [list $path]] 1703 } 1704 1705 foreach key [array names data] { 1706 if {$key == "vtkdata"} { 1707 if {1} { 1708 set f [open /tmp/$cname.vtk "w"] 1709 fconfigure $f -translation binary -encoding binary 1710 puts -nonewline $f $data(vtkdata) 1711 close $f 1712 } 1713 } else { 1714 puts stderr "$key = \"$data($key)\"" 1715 } 1716 } 1717 1718 # Save viewer choice 1719 set viewer $_viewer 1720 ReadVtkDataSet $cname $data(vtkdata) 1721 # Restore viewer choice (ReadVtkDataSet wants to set it to contour/isosurface) 1722 set _viewer $viewer 1723 return $data(vtkdata) 1643 1724 } 1644 1725
Note: See TracChangeset
for help on using the changeset viewer.