Changeset 3637 for trunk


Ignore:
Timestamp:
Apr 26, 2013, 5:25:25 AM (11 years ago)
Author:
gah
Message:

add pdb to vtk converter to drawing

Location:
trunk/gui/scripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/drawing.tcl

    r3330 r3637  
    1818
    1919itcl::class Rappture::Drawing {
    20     constructor {xmlobj path} {
    21         # defined below
    22     }
    23     destructor {
    24         # defined below
    25     }
    26     public method limits {axis}
    27     public method label { elem }
    28     public method type { elem }
    29     public method style { elem }
    30     public method shape { elem }
    31     public method values { elem }
    32     public method data { elem }
    33     public method hints {{keyword ""}}
    34     public method components { args }
    35 
    3620    private variable _drawing
    3721    private variable _xmlobj
     
    4529    private variable _units
    4630    private variable _limits
    47 }
     31
     32    constructor {xmlobj path} {
     33        # defined below
     34    }
     35    destructor {
     36        # defined below
     37    }
     38    public method limits {axis}
     39    public method label { elem }
     40    public method type { elem }
     41    public method style { elem }
     42    public method shape { elem }
     43    public method values { elem }
     44    public method data { elem }
     45    public method hints {{keyword ""}}
     46    public method components { args }
     47    private method PdbToVtk { cname contents }
     48}
     49
    4850
    4951# ----------------------------------------------------------------------
     
    9799            }
    98100            molecule* {
    99                 set _data($elem) [$_xmlobj get $path.$elem.vtk]
     101                set pdbdata [$_xmlobj get $path.$elem.pdb]
     102                if { $pdbdata != "" } {
     103                    set contents [PdbToVTk $elem $pdbdata]
     104                } else {
     105                    set contents [$_xmlobj get $path.$elem.vtk]
     106                }
    100107                set _data($elem) [string trim $_data($elem)]
    101108                set _styles($elem) [$_xmlobj get $path.$elem.about.style]
     
    330337}
    331338
     339
     340itcl::body Rappture::Drawing::PdbToVtk { cname contents } {
     341    package require vtk
     342
     343    set reader $this-datasetreader
     344    vtkPDBReader $reader
     345
     346    # Write the contents to a file just in case it's binary.
     347    set tmpfile $cname[pid].pdb
     348    set f [open "$tmpfile" "w"]
     349    fconfigure $f -translation binary -encoding binary
     350    puts $f $contents
     351    close $f
     352    $reader SetFileName $tmpfile
     353    $reader Update
     354    file delete $tmpfile
     355
     356    set output [$reader GetOutput]
     357    set pointData [$output GetPointData]
     358    set _scalars {}
     359    for { set i 0 } { $i < [$pointData GetNumberOfArrays] } { incr i } {
     360        set name [$pointData GetArrayName $i]
     361        lappend _scalars $name $name "???"
     362    }
     363    set tmpfile $cname[pid].vtk
     364    set writer $this-datasetwriter
     365    vtkDataSetWriter $writer
     366    $writer SetInputConnection [$reader GetOutputPort]
     367    $writer SetFileName $tmpfile
     368    $writer Write
     369    rename $reader ""
     370    rename $writer ""
     371
     372    set f [open "$tmpfile" "r"]
     373    fconfigure $f -translation binary -encoding binary
     374    set vtkdata [read $f]
     375    close $f
     376    file delete $tmpfile
     377    return $vtkdata
     378}
  • trunk/gui/scripts/molvisviewer.tcl

    r3592 r3637  
    765765        set _cacheid $cacheid
    766766    }
    767     #debug "reading $size bytes from proxy\n"
    768767    set data [ReceiveBytes $size]
    769768    #debug "success: reading $size bytes from proxy\n"
     
    964963                # Save the PDB data in case the user wants to later save it.
    965964                set _pdbdata $data1
    966                 set nBytes [string length $data1]
     965                set numBytes [string length $data1]
    967966
    968967                # We know we're buffered here, so append the "loadpdb" command
    969968                # with the data payload immediately afterwards.
    970                 ServerCmd "loadpdb -defer follows $model $state $nBytes"
     969                ServerCmd "loadpdb -defer follows $model $state $numBytes"
    971970                append _outbuf $data1
    972971                set _dataobjs($model-$state)  1
     
    977976                # Save the PDB data in case the user wants to later save it.
    978977                set _pdbdata $data2
    979                 set nBytes [string length $data2]
     978                set numBytes [string length $data2]
    980979
    981980                # We know we're buffered here, so append the "loadpdb" command
    982981                # with the data payload immediately afterwards.
    983                 ServerCmd "loadpdb -defer follows $model $state $nBytes"
     982                ServerCmd "loadpdb -defer follows $model $state $numBytes"
    984983                append _outbuf $data2
    985984                set _dataobjs($model-$state)  1
     
    10261025                    # Save the PDB data in case the user wants to later save it.
    10271026                    set _pdbdata $data3
    1028                     set nBytes [string length $data3]
     1027                    set numBytes [string length $data3]
    10291028
    10301029                    # We know we're buffered here, so append the "loadpdb"
    10311030                    # command with the data payload immediately afterwards.
    1032                     ServerCmd "loadpdb -defer follows $model $state $nBytes"
     1031                    ServerCmd "loadpdb -defer follows $model $state $numBytes"
    10331032                    append _outbuf $data3
    10341033                }
Note: See TracChangeset for help on using the changeset viewer.