Ignore:
Timestamp:
Jul 16, 2014, 12:21:36 PM (10 years ago)
Author:
gah
Message:

merge transferfunctioneditor into nanovis, fix cloud with units

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.3/gui/scripts/field.tcl

    r4494 r4504  
    11# -*- mode: tcl; indent-tabs-mode: nil -*-
    2 
    32# ----------------------------------------------------------------------
    43#  COMPONENT: field - extracts data from an XML description of a field
     
    8281                                        # valid data.
    8382    private variable _isValidComponent; #  Array of valid components found
     83    private variable _alwaysConvertDX 0;
     84
    8485    constructor {xmlobj path} {
    8586        # defined below
     
    8889        # defined below
    8990    }
    90     public method blob { cname }
     91    public method blob { cname } 
    9192    public method components {args}
    9293    public method controls {option args}
     
    9495    public method numComponents {cname}
    9596    public method fieldlimits {}
     97    public method valueLimits { cname }
    9698    public method flowhints { cname }
    9799    public method hints {{key ""}}
     
    150152
    151153    private method AvsToVtk { cname contents }
     154    private method DicomToVtk { cname contents }
    152155    private method BuildPointsOnMesh { cname }
    153156    protected method GetAssociation { cname }
     
    318321    }
    319322    if {[info exists _comp2dx($cname)]} {
    320         return ""  ;# no mesh -- it's embedded in the blob data
     323        return ""  ;# no mesh -- it's embedded in the value data
    321324    }
    322325    if {[info exists _comp2mesh($cname)]} {
     
    362365    }
    363366    if {[info exists _comp2dx($cname)]} {
    364         error "method \"values\" is not implemented for dx file data"
     367        error "method \"values\" is not implemented for dx data"
    365368    }
    366369    if {[info exists _comp2unirect2d($cname)]} {
     
    389392    }
    390393    if {[info exists _comp2dx($cname)]} {
    391         return $_comp2dx($cname)  ;# return gzipped, base64-encoded DX data
     394        return $_comp2dx($cname)
    392395    }
    393396    if {[info exists _comp2unirect2d($cname)]} {
     
    400403    }
    401404    error "can't get field blob: Unknown component \"$cname\": should be one of [join [lsort [array names _comp2dims]] {, }]"
     405}
     406
     407itcl::body Rappture::Field::valueLimits { cname } {
     408    if { [info exists _comp2limits($cname)] } {
     409        return $_comp2limits($cname)
     410    }
     411    return ""
    402412}
    403413
     
    520530    return [list $min $max]
    521531}
     532
    522533
    523534# ----------------------------------------------------------------------
     
    789800        } elseif {[$_field element $cname.ucd] != ""} {
    790801            set type "ucd"
     802        } elseif {[$_field element $cname.dicom] != ""} {
     803            set type "dicom"
    791804        }
    792805        set _comp2style($cname) ""
     
    894907            set _dim 3
    895908            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 } {
    913927                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") } {
    914938                set _type "vtk"
    915939                set _comp2vtk($cname) $vtkdata
    916940            } 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 component
    921                 }
    922941                set _type "dx"
    923                 set _comp2dx($cname) $contents
     942                set _comp2dx($cname) $data
    924943            }
    925944            set _comp2style($cname) [$_field get $cname.style]
     
    928947                    [Rappture::FlowHints ::\#auto $_field $cname $_units]
    929948            }
     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]
    930966            incr _counter
    931967        } elseif { $type == "ucd"} {
     
    941977        }
    942978        set _isValidComponent($cname) 1
     979        #puts stderr "Field $cname type is: $_type"
    943980    }
    944981    if { [array size _isValidComponent] == 0 } {
     
    15081545        # sort x-coords in increasing order
    15091546        $xv sort $yv
    1510        
    15111547        set _comp2dims($cname) "1D"
    15121548        set _comp2xy($cname) [list $xv $yv]
     
    16411677    file delete $tmpfile
    16421678    return $vtkdata
     1679}
     1680
     1681itcl::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)
    16431724}
    16441725
Note: See TracChangeset for help on using the changeset viewer.