Changeset 5334


Ignore:
Timestamp:
Apr 28, 2015 3:39:32 PM (9 years ago)
Author:
ldelgass
Message:

In VTK mesh viewer, get bounds/limits from mesh object -- don't need to parse
the VTK file.

File:
1 edited

Legend:

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

    r5195 r5334  
    5757    public method get {args}
    5858    public method isconnected {}
    59     public method limits { dataobj }
    6059    public method parameters {title args} {
    6160        # do nothing
     
    174173    $_arcball quaternion [ViewToQuaternion]
    175174
    176     set _limits(zmin) 0.0
    177     set _limits(zmax) 1.0
    178 
    179175    array set _settings {
    180176        -axesvisible            1
     
    551547itcl::body Rappture::VtkMeshViewer::scale {args} {
    552548    foreach dataobj $args {
    553         array set bounds [limits $dataobj]
    554         if {![info exists _limits(xmin)] || $_limits(xmin) > $bounds(xmin)} {
    555             set _limits(xmin) $bounds(xmin)
    556         }
    557         if {![info exists _limits(xmax)] || $_limits(xmax) < $bounds(xmax)} {
    558             set _limits(xmax) $bounds(xmax)
    559         }
    560 
    561         if {![info exists _limits(ymin)] || $_limits(ymin) > $bounds(ymin)} {
    562             set _limits(ymin) $bounds(ymin)
    563         }
    564         if {![info exists _limits(ymax)] || $_limits(ymax) < $bounds(ymax)} {
    565             set _limits(ymax) $bounds(ymax)
    566         }
    567 
    568         if {![info exists _limits(zmin)] || $_limits(zmin) > $bounds(zmin)} {
    569             set _limits(zmin) $bounds(zmin)
    570         }
    571         if {![info exists _limits(zmax)] || $_limits(zmax) < $bounds(zmax)} {
    572             set _limits(zmax) $bounds(zmax)
     549        if { ![$dataobj isvalid] } {
     550            continue;                   # Object doesn't contain valid data.
     551        }
     552        foreach axis { x y z } {
     553            set lim [$dataobj limits $axis]
     554            if { ![info exists _limits($axis)] } {
     555                set _limits($axis) $lim
     556                continue
     557            }
     558            foreach {min max} $lim break
     559            foreach {amin amax} $_limits($axis) break
     560            if { $amin > $min } {
     561                set amin $min
     562            }
     563            if { $amax < $max } {
     564                set amax $max
     565            }
     566            set _limits($axis) [list $amin $amax]           
    573567        }
    574568    }
     
    824818    }
    825819
    826     set _limits(zmin) ""
    827     set _limits(zmax) ""
    828820    set _first ""
    829821    SendCmd "dataset visible 0"
     
    12261218        SendCmd "outline color $rgb"
    12271219    }
    1228 }
    1229 
    1230 itcl::body Rappture::VtkMeshViewer::limits { dataobj } {
    1231     set tag $dataobj
    1232     if { ![info exists _limits($tag)] } {
    1233         set data [$dataobj vtkdata -full]
    1234         if { $data == "" } {
    1235             continue
    1236         }
    1237         set tmpfile file[pid].vtk
    1238         set f [open "$tmpfile" "w"]
    1239         fconfigure $f -translation binary -encoding binary
    1240         puts $f $data
    1241         close $f
    1242         set reader [vtkDataSetReader $tag-xvtkDataSetReader]
    1243         $reader SetFileName $tmpfile
    1244         $reader Update
    1245         file delete $tmpfile
    1246         set output [$reader GetOutput]
    1247         set _limits($tag) [$output GetBounds]
    1248         rename $output ""
    1249         rename $reader ""
    1250     }
    1251     foreach { xMin xMax yMin yMax zMin zMax} $_limits($tag) break
    1252     if {![info exists limits(xmin)] || $limits(xmin) > $xMin} {
    1253         set limits(xmin) $xMin
    1254     }
    1255     if {![info exists limits(xmax)] || $limits(xmax) < $xMax} {
    1256         set limits(xmax) $xMax
    1257     }
    1258     if {![info exists limits(ymin)] || $limits(ymin) > $yMin} {
    1259         set limits(ymin) $xMin
    1260     }
    1261     if {![info exists limits(ymax)] || $limits(ymax) < $yMax} {
    1262         set limits(ymax) $yMax
    1263     }
    1264     if {![info exists limits(zmin)] || $limits(zmin) > $zMin} {
    1265         set limits(zmin) $zMin
    1266     }
    1267     if {![info exists limits(zmax)] || $limits(zmax) < $zMax} {
    1268         set limits(zmax) $zMax
    1269     }
    1270 
    1271     return [array get limits]
    12721220}
    12731221
Note: See TracChangeset for help on using the changeset viewer.