Changeset 2424 for trunk


Ignore:
Timestamp:
Aug 27, 2011 2:22:44 AM (13 years ago)
Author:
ldelgass
Message:

Add vtk data file loader to vtkcontour-test -- creates a dummy data object as
a unirect2d/unirect3d or a mesh+scalars object.

Location:
trunk/gui/apps
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/apps/vtkcontour-test

    r2415 r2424  
    3131package require Rappture
    3232package require RapptureGUI
     33package require vtk
    3334
    3435option add *comm.font -*-courier-medium-r-normal-*-*-120-*
     
    7374itcl::class visData {
    7475    constructor {args} {
    75         set _data [lindex $args 0]
    76     }
    77 
     76        set _reader [vtkDataSetReader $this-xvtkDataSetReader]
     77        $_reader SetFileName [lindex $args 0]
     78        $_reader Update
     79        set _data [$_reader GetOutput]
     80    }
     81    destructor {
     82        rename _data ""
     83        rename _reader ""
     84    }
    7885    public method components {args} {
    7986        if {[llength $args] == 0} {
     
    8289        return ""
    8390    }
     91    public method mesh {args} {
     92        switch -- [$_data GetClassName] {
     93            vtkPolyData {
     94                if {[$_data GetNumberOfCells] > 0} {
     95                    return $_data
     96                } else {
     97                    return [$_data GetPoints]
     98                }
     99            }
     100            vtkStructuredPoints -
     101            vtkUniformGrid -
     102            vtkImageData {
     103                foreach { x1 y1 z1 } [$_data GetOrigin] break
     104                foreach { xN yN zN } [$_data GetDimensions] break
     105                foreach { xS yS zS } [$_data GetSpacing] break
     106                set x2 [expr {$x1 + $xN * $xS}]
     107                set y2 [expr {$x1 + $yN * $yS}]
     108                set z2 [expr {$x1 + $zN * $zS}]
     109                if {$zN == 1} {
     110                    lappend out $x1 $x2 $xN $y1 $y2 $yN
     111                } else {
     112                    lappend out $x1 $x2 $xN $y1 $y2 $yN $z1 $z2 $zN
     113                }
     114                return $out
     115            }
     116            default {
     117                return $_data
     118            }
     119        }
     120    }
     121    public method isunirect2d {args} {
     122        if {[$_data GetClassName] != "vtkImageData" &&
     123            [$_data GetClassName] != "vtkStructuredPoints" &&
     124            [$_data GetClassName] != "vtkUniformGrid"} {
     125            return 0
     126        }
     127        foreach { xN yN zN } [$_data GetDimensions] break
     128        if {$zN == 1} {
     129            return 1
     130        } else {
     131            return 0
     132        }
     133    }
     134    public method isunirect3d {args} {
     135        if {[$_data GetClassName] != "vtkImageData" &&
     136            [$_data GetClassName] != "vtkStructuredPoints" &&
     137            [$_data GetClassName] != "vtkUniformGrid"} {
     138            return 0
     139        }
     140        foreach { xN yN zN } [$_data GetDimensions] break
     141        if {$zN > 1} {
     142            return 1
     143        } else {
     144            return 0
     145        }
     146    }
    84147    public method data {args} {
    85         return $_data
     148        return [values $args]
    86149    }
    87150    public method values {args} {
    88         return $_data
     151        set dataAttrs [$_data GetPointData]
     152        if {"" == $dataAttrs} {
     153            puts stderr "No point data"
     154            return ""
     155        }
     156        set scalarArr [$dataAttrs GetScalars]
     157        if {"" == $scalarArr} {
     158            for {set i 0} {$i < [$dataAttrs GetNumberOfArrays]} {incr i} {
     159                if {[[$dataAttrs GetArray $i] GetNumberOfComponents] == 1} {
     160                    $dataAttrs SetActiveScalars [$dataAttrs GetArrayName $i]
     161                    puts stderr "Set scalars to '[$dataAttrs GetArrayName $i]'"
     162                    break
     163                }
     164            }
     165            set scalarArr [$dataAttrs GetScalars]
     166            if {"" == $scalarArr} {
     167                puts stderr "No scalar point data"
     168                return ""
     169            }
     170        }
     171        if {[isunirect2d] || [isunirect3d]} {
     172            for {set i 0} {$i < [$scalarArr GetNumberOfTuples]} {incr i} {
     173                lappend out [$scalarArr GetComponent $i 0]
     174            }
     175            return $out
     176        }
     177        return $scalarArr
     178    }
     179    public method limits {which} {
     180        foreach { xMin xMax yMin yMax zMin zMax} [$_data GetBounds] break
     181        set min ""
     182        set max ""
     183
     184        switch -- $which {
     185            x - xlin - xlog {
     186                set min $xMin
     187                set max $xMax
     188                set axis "xaxis"
     189            }
     190            y - ylin - ylog {
     191                set min $yMin
     192                set max $yMax
     193                set axis "yaxis"
     194            }
     195            z - zlin - zlog {
     196                set min $zMin
     197                set max $zMax
     198                set axis "zaxis"
     199            }
     200            v - vlin - vlog {
     201                foreach { min max } [$_data GetScalarRange] break
     202                set axis "vaxis"
     203            }
     204            default {
     205                error "unknown axis description \"$which\""
     206            }
     207        }
     208        return [list $min $max]
    89209    }
    90210    public method hints {args} {
     
    93213
    94214    private variable _data ""
     215    private variable _reader ""
    95216}
    96217
     
    105226
    106227    set file [tk_getOpenFile -title "Open VTK File"]
    107     if {"" != $file && [catch {
    108             set fid [open $file r]
    109             fconfigure $fid -translation binary
    110             set info [read $fid]
    111             close $fid
    112           }] == 0} {
    113         set obj [visData #auto $info]
     228    if {"" != $file} {
     229        set obj [visData #auto $file]
    114230        $widgets(vtkcontourviewer) add $obj
    115231    }
     
    336452set widgets(vtkcontourviewer) $f.viewer
    337453
    338 puts stderr [winfo class $widgets(vtkcontourviewer)]
    339 
    340454$f.viewer configure \
    341455    -sendcommand show_comm \
  • trunk/gui/apps/vtkviewer-test

    r2415 r2424  
    340340set widgets(vtkviewer) $f.viewer
    341341
    342 puts stderr [winfo class $widgets(vtkviewer)]
    343 
    344342$f.viewer configure \
    345343    -sendcommand show_comm \
Note: See TracChangeset for help on using the changeset viewer.