Changeset 3310 for branches


Ignore:
Timestamp:
Feb 19, 2013, 3:15:17 PM (12 years ago)
Author:
gah
Message:

start of fix the way we handle limits in <field> elements

Location:
branches/Rappture 1.2/gui/scripts
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/Rappture 1.2/gui/scripts/cloud.tcl

    r3289 r3310  
    160160    append out "POINTS $_numPoints float\n"
    161161    append out $_points
    162     append out "POINT_DATA $_numPoints\n"
    163162    set _vtkdata $out
    164163}
  • branches/Rappture 1.2/gui/scripts/field.tcl

    r3306 r3310  
    102102    private variable _comp2cntls ;# maps component name => x,y control points
    103103    private variable _comp2extents
    104     private variable _comp2limits 
     104    private variable _comp2limits;      #  Array of limits per component
    105105    private variable _type ""
    106106    private variable _comp2flowhints
     
    424424                        x - xlin - xlog {
    425425                            set axis x
    426                             set axisMax $limits(xmax)
    427                             set axisMin $limits(xmin)
     426                            foreach {axisMin axisMax} $limits(x) break
    428427                        }
    429428                        y - ylin - ylog {
    430429                            set axis y
    431                             set axisMax $limits(ymax)
    432                             set axisMin $limits(ymin)
     430                            foreach {axisMin axisMax} $limits(y) break
    433431                        }
    434432                        z - zlin - zlog {
    435433                            set axis y
    436                             set axisMax $limits(zmax)
    437                             set axisMin $limits(zmin)
     434                            foreach {axisMin axisMax} $limits(z) break
    438435                        }
    439436                        v - vlin - vlog {
    440437                            set axis v
    441                             set axisMax $limits(vmax)
    442                             set axisMin $limits(vmin)
     438                            foreach {axisMin axisMax} $limits(v) break
     439                        }
     440                        default {
     441                            if { ![info exists limits($which)] } {
     442                                error "limits: unknown axis \"$which\""
     443                            }
     444                            set axis v
     445                            foreach {axisMin axisMax} $limits($which) break
    443446                        }
    444447                    }
     
    10611064    if { $_viewer == "" } {
    10621065        if { $_dim == 2 } {
    1063             set _viewer heightmap
     1066            set _viewer contour
    10641067        } else {
    10651068            set _viewer isosurface
     
    10671070    }
    10681071    set _comp2dims($cname) ${_dim}D
    1069     lappend limits xmin $xmin xmax $xmax ymin $ymin ymax $ymax 
     1072    lappend limits x [list $xmin $xmax]
     1073    lappend limits y [list $ymin $ymax]
     1074    lappend limits z [list $zmin $zmax]
    10701075    set dataAttrs [$dataset GetPointData]
    10711076    if { $dataAttrs == ""} {
     
    10831088            set name  [$dataAttrs GetArrayName $i]
    10841089            foreach {min max} [$array GetRange] break
    1085             lappend limits $name-min $min $name-max $max
     1090            lappend limits $name [list $min $max]
    10861091            lappend _fieldNames $name
    10871092            lappend _fieldUnits ""
     
    10891094        }
    10901095    }
    1091     puts stderr "_fieldNames=$_fieldNames"
    1092     lappend limits vmin $vmin vmax $vmax
     1096    lappend limits v [list $vmin $vmax]
    10931097    set _comp2limits($cname) $limits
    10941098    $reader Delete
     
    10971101
    10981102#
    1099 # vtkdata ?<cname>?
     1103# vtkdata --
    11001104#
    11011105#       Returns a string representing the mesh and field data for a specific
    1102 #       component in basic VTK file format.
     1106#       component in the legacy VTK file format.
    11031107#
    11041108itcl::body Rappture::Field::vtkdata {cname} {
     
    11321136        append out "ASCII\n"
    11331137        append out [$mesh vtkdata]
     1138        append out "POINT_DATA [$vector length]\n"
    11341139        append out "SCALARS $label float\n"
    11351140        append out "LOOKUP_TABLE default\n"
     
    11401145}
    11411146
     1147#
     1148# BuildPointsOnMesh --
     1149#
     1150#       Parses the field XML description to build a mesh and values vector
     1151#       representing the field.  Right now we handle the deprecated types
     1152#       of "cloud", "unirect2d", and "unirect3d" (mostly for flows).
     1153#
    11421154itcl::body Rappture::Field::BuildPointsOnMesh {cname} {
    11431155    #
     
    12431255        set label [hints zlabel]
    12441256        if { $label != "" } {
     1257            set _fieldLabels $label
    12451258            set _fieldNames $label
    12461259            regsub -all { } $_fieldNames {_} _fieldNames
    1247             set _fieldLabels $label
    12481260        }
    12491261        set units [hints zunits]
     
    12511263            set _fieldUnits $units
    12521264        }
     1265        array unset _comp2limits $cname
     1266        lappend _comp2limits($cname) x [$mesh limits x]
     1267        lappend _comp2limits($cname) y [$mesh limits y]
     1268        lappend _comp2limits($cname) $label [$vector limits]
     1269        lappend _comp2limits($cname) v [$vector limits]
    12531270        return
    12541271    } elseif {$_dim == 3} {
     
    12831300            set _fieldUnits $units
    12841301        }
     1302        lappend _comp2limits($cname) x [$mesh limits x]
     1303        lappend _comp2limits($cname) y [$mesh limits y]
     1304        lappend _comp2limits($cname) z [$mesh limits z]
     1305        lappend _comp2limits($cname) $label [$vector limits]
     1306        lappend _comp2limits($cname) v [$vector limits]
    12851307        return
    12861308    }
     
    13211343    fconfigure $f -translation binary -encoding binary
    13221344    set vtkdata [read $f]
     1345    close $f
    13231346    file delete $tmpfile
    1324     close $f
    13251347    return $vtkdata
    13261348}
  • branches/Rappture 1.2/gui/scripts/mesh.tcl

    r3304 r3310  
    5656
    5757    private method ReadNodesElements {xmlobj path}
    58     private method _buildRectMesh {xmlobj path}
    59     private method _getVtkElement {npts}
    60 
    61     private variable _pts2elem   ;      # maps # points => vtk element
    6258
    6359    private variable _points ""      ;  # name of vtkPointData object
     
    8985    private method ReadTriangles { xmlobj path }
    9086    private method ReadVtk { xmlobj path }
    91     private method _buildNodesElements {xmlobj path}
    9287}
    9388
     
    162157    }
    163158
    164     foreach lim {xmin xmax ymin ymax zmin zmax} {
    165         set _limits($lim) ""
    166     }
    167159    # Meshes comes in a variety of flavors
    168160    #
     
    241233        blt::mesh destroy $_bltmesh
    242234    }
    243     catch {rename $this-points ""}
    244     catch {rename $this-grid ""}
    245     catch {rename $this-dset ""}
    246     foreach type [array names _pts2elem] {
    247         rename $_pts2elem($type) ""
    248     }
    249235}
    250236
     
    425411    }
    426412    return $value
    427 }
    428 
    429 # ----------------------------------------------------------------------
    430 # USAGE: _buildNodesElements <xmlobj> <path>
    431 #
    432 # Used internally to build a mesh representation based on nodes and
    433 # elements stored in the XML.
    434 # ----------------------------------------------------------------------
    435 itcl::body Rappture::Mesh::_buildNodesElements {xmlobj path} {
    436     # create the vtk objects containing points and connectivity
    437 
    438     set _vtkpoints $this-points
    439     vtkPoints $_vtkpoints
    440 
    441     #
    442     # Extract each node and add it to the points list.
    443     #
    444     foreach comp [$xmlobj children -type node $path] {
    445         set xyz [$xmlobj get $path.$comp]
    446 
    447         # make sure we have x,y,z
    448         while {[llength $xyz] < 3} {
    449             lappend xyz "0"
    450         }
    451 
    452         # extract each point and add it to the points list
    453         foreach {x y z} $xyz break
    454         foreach dim {x y z} units $_units {
    455             set v [Rappture::Units::convert [set $dim] \
    456                 -context $units -to $units -units off]
    457 
    458             set $dim $v  ;# save back to real x/y/z variable
    459 
    460             if {"" == $_limits(${dim}min)} {
    461                 set _limits(${dim}min) $v
    462                 set _limits(${dim}max) $v
    463             } else {
    464                 if {$v < $_limits(${dim}min)} { set _limits(${dim}min) $v }
    465                 if {$v > $_limits(${dim}max)} { set _limits(${dim}max) $v }
    466             }
    467         }
    468         $_vtkpoints InsertNextPoint $x $y $z
    469     }
    470 
    471     set _vtkgrid $this-grid
    472     vtkUnstructuredGrid $_vtkgrid
    473     $_vtkgrid SetPoints $_vtkpoints
    474 
    475     #
    476     # Extract each element and add it to the mesh.
    477     #
    478     foreach comp [$xmlobj children -type element $path] {
    479         set nlist [$_mesh get $comp.nodes]
    480         set elem [_getVtkElement [llength $nlist]]
    481 
    482         set i 0
    483         foreach n $nlist {
    484             [$elem GetPointIds] SetId $i $n
    485             incr i
    486         }
    487         $_vtkgrid InsertNextCell [$elem GetCellType] [$elem GetPointIds]
    488     }
    489 }
    490 
    491 # ----------------------------------------------------------------------
    492 # USAGE: _buildRectMesh <xmlobj> <path>
    493 #
    494 # Used internally to build a mesh representation based on a native
    495 # VTK file for a rectangular mesh.
    496 # ----------------------------------------------------------------------
    497 itcl::body Rappture::Mesh::_buildRectMesh {xmlobj path} {
    498     vtkRectilinearGridReader $this-gr
    499     $this-gr ReadFromInputStringOn
    500     $this-gr SetInputString [$xmlobj get $path.vtk]
    501 
    502     set _vtkgrid [$this-gr GetOutput]
    503     set _points [$_vtkgrid GetPointData]
    504 
    505     $_vtkgrid Update
    506     foreach name {xmin xmax ymin ymax zmin zmax} val [$_vtkgrid GetBounds] {
    507         set _limits($name) $val
    508     }
    509 }
    510 
    511 # ----------------------------------------------------------------------
    512 # USAGE: _getVtkElement <npts>
    513 #
    514 # Used internally to find (or allocate, if necessary) a vtk element
    515 # that can be used to build up a mesh.  The element depends on the
    516 # number of points passed in.  4 points is a tetrahedron, 5 points
    517 # is a pyramid, etc.
    518 # ----------------------------------------------------------------------
    519 itcl::body Rappture::Mesh::_getVtkElement {npts} {
    520     if {![info exists _pts2elem($npts)]} {
    521         switch -- $npts {
    522             3 {
    523                 set _pts2elem($npts) $this-elem3
    524                 vtkTriangle $_pts2elem($npts)
    525             }
    526             4 {
    527                 set _pts2elem($npts) $this-elem4
    528                 vtkTetra $_pts2elem($npts)
    529             }
    530             5 {
    531                 set _pts2elem($npts) $this-elem5
    532                 vtkPyramid $_pts2elem($npts)
    533             }
    534             6 {
    535                 set _pts2elem($npts) $this-elem6
    536                 vtkWedge $_pts2elem($npts)
    537             }
    538             8 {
    539                 set _pts2elem($npts) $this-elem8
    540                 vtkVoxel $_pts2elem($npts)
    541             }
    542         }
    543     }
    544     return $_pts2elem($npts)
    545413}
    546414
     
    570438            append out "$x $y 0\n"
    571439        }
    572         append out "POINT_DATA $_numPoints\n"
    573440        set _vtkdata $out
    574441        foreach axis {x y} {
     
    583450            append out "$x $y $z\n"
    584451        }
    585         append out "POINT_DATA $_numPoints\n"
    586452        set _vtkdata $out
    587453        foreach axis {x y z} {
     
    596462itcl::body Rappture::Mesh::ReadVtk { xmlobj path } {
    597463    set _type "vtk"
    598     if { $_dim < 1 } {
    599         error "can't read vtk mesh: no dimension specified"
    600     }
     464
     465    # Create a VTK file with the mesh in it. 
     466    set _vtkdata [$xmlobj get $path.vtk]
     467    append out "# vtk DataFile Version 3.0\n"
     468    append out "mesh\n"
     469    append out "ASCII\n"
     470    append out "$_vtkdata\n"
    601471
    602472    # Write the contents to a file just in case it's binary.
     
    604474    set f [open "$tmpfile" "w"]
    605475    fconfigure $f -translation binary -encoding binary
    606     puts $f [$xmlobj get vtk]
     476    puts $f $out
    607477    close $f
    608478
    609     # Read the data into a polydata output
    610     set _vtkreader $this-datasetreader
    611     vtkDataSetReader $_vtkreader
    612     $_vtkreader SetFileName $tmpfile
    613     $_vtkreader Update
    614     set _vtkoutput [$_vtkreader GetOutput]
    615     set _vtkpoints [$_vtkoutput GetPointData]
     479    # Read the data back into a vtk dataset and query the bounds.
     480    set reader $this-datasetreader
     481    vtkDataSetReader $reader
     482    $reader SetFileName $tmpfile
     483    $reader Update
     484    set output [$reader GetOutput]
     485    foreach {
     486        _limits(xmin) _limits(xmax)
     487        _limits(ymin) _limits(ymax)
     488        _limits(zmin) _limits(zmax)
     489    } [$output GetBounds] break
     490    set _dim 3;                         # Hard coding all vtk meshes to 3D?
     491    if { $_limits(zmin) >= $_limits(zmax) } {
     492        set _dim 2
     493    }
    616494    file delete $tmpfile
     495    rename $output ""
     496    rename $reader ""
    617497    set _isValid 1
    618498}
     
    654534            append out "ORIGIN 0 0 0\n"
    655535            set _numPoints [expr $xNum * $yNum]
    656             append out "POINT_DATA $_numPoints\n"
    657536            set _vtkdata $out
    658537            foreach axis {x y} {
     
    669548            append out "ORIGIN 0 0 0\n"
    670549            set _numPoints [expr $xNum * $yNum * zNum]
    671             append out "POINT_DATA $_numPoints\n"
    672550            set _vtkdata $out
    673551            foreach axis {x y z} {
     
    726604        append out [$zv range 0 end]
    727605        append out "\n"
    728         append out "POINT_DATA $_numPoints\n"
    729606        set _vtkdata $out
    730607        foreach axis {x y z} {
     
    746623        append out "Z_COORDINATES 1 double\n"
    747624        append out "0\n"
    748         append out "POINT_DATA $_numPoints\n"
    749625        foreach axis {x y} {
    750626            if { [info exists ${axis}Min] } {
     
    852728        append out "CELL_TYPES $numCells\n"
    853729        append out $celltypes
    854         append out "POINT_DATA $_numPoints\n"
    855730        set _limits(xmin) [$xv min]
    856731        set _limits(xmax) [$xv max]
     
    893768        append out "CELL_TYPES $numCells\n"
    894769        append out $celltypes
    895         append out "POINT_DATA $_numPoints\n"
    896770        set _limits(xmin) [$xv min]
    897771        set _limits(xmax) [$xv max]
     
    953827    append out "CELL_TYPES $count\n"
    954828    append out $celltypes
    955     append out "POINT_DATA $_numPoints\n"
    956829    set _limits(xmin) [$xv min]
    957830    set _limits(xmax) [$xv max]
     
    11691042    append out $celltypes
    11701043    append out "\n"
    1171     append out "POINT_DATA $_numPoints\n"
    11721044    set _vtkdata $out
    11731045    set _isValid 1
  • branches/Rappture 1.2/gui/scripts/unirect2d.tcl

    r3217 r3310  
    154154    append out "SPACING $xSpace $ySpace 0\n"
    155155    append out "ORIGIN 0 0 0\n"
    156     append out "POINT_DATA $_numPoints\n"
    157156    set _vtkdata $out
    158157}
Note: See TracChangeset for help on using the changeset viewer.