Ignore:
Timestamp:
Mar 11, 2015 10:26:15 AM (9 years ago)
Author:
dkearney
Message:

merging updates from 1.3 branch

looks like this branch originally came from the 1.3 branch and then had some
additions from the 1.4-pre branch and then a sync from the 1.3 branch. to get
this branch updated, I am reverting r4797 (additions from 1.4-pre branch),
reverting r4798 (additions from 1.3 branch), then merging in updates from 1.3
branch.

I fixed merge conflicts for the following files:

gui/scripts/gauge.tcl
gui/scripts/main.tcl
gui/scripts/tool.tcl
lang/tcl/scripts/task.tcl

Location:
branches/uq
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/uq

  • branches/uq/gui/scripts/mesh.tcl

    r4798 r5121  
    1 # -*- mode: tcl; indent-tabs-mode: nil -*- 
     1# -*- mode: tcl; indent-tabs-mode: nil -*-
    22
    33# ----------------------------------------------------------------------
     
    1818package require Itcl
    1919
    20 namespace eval Rappture { 
    21     # forward declaration 
     20namespace eval Rappture {
     21    # forward declaration
    2222}
    2323
    2424itcl::class Rappture::Mesh {
    25     private variable _xmlobj ""  ;      # Ref to XML obj with device data
    26     private variable _mesh ""    ;      # Lib obj representing this mesh
    27     private variable _dim       0;      # Dimension of mesh (1, 2, or 3)
    28     private variable _type "";          # Indicates the type of mesh.
    29     private variable _axis2units;       # System of units for x, y, z
    30     private variable _axis2labels;      # 
    31     private variable _hints 
    32     private variable _limits        ;   # Array of mesh limits. Keys are
    33                                         # xmin, xmax, ymin, ymax, ...
    34     private variable _numPoints 0   ;   # # of points in mesh
    35     private variable _numCells 0;       # # of cells in mesh
    36     private variable _vtkdata "";       # Mesh in vtk file format.
     25    private variable _xmlobj ""  ;      # Ref to XML obj with device data
     26    private variable _mesh ""    ;      # Lib obj representing this mesh
     27    private variable _dim        0;     # Dimension of mesh (1, 2, or 3)
     28    private variable _type "";          # Indicates the type of mesh.
     29    private variable _axis2units;       # System of units for x, y, z
     30    private variable _axis2labels;      #
     31    private variable _hints
     32    private variable _limits        ;   # Array of mesh limits. Keys are
     33                                        # xmin, xmax, ymin, ymax, ...
     34    private variable _numPoints 0   ;   # # of points in mesh
     35    private variable _numCells 0   ;    # # of cells in mesh
     36    private variable _vtkdata "";       # Mesh in vtk file format.
    3737    private variable _isValid 0;        # Indicates if the mesh is valid.
    38     constructor {xmlobj path} { 
    39         # defined below
    40     }
    41     destructor { 
    42         # defined below
     38    constructor {xmlobj path} {
     39        # defined below
     40    }
     41    destructor {
     42        # defined below
    4343    }
    4444    public method points {}
     
    5858    public method vtkdata {{what -partial}}
    5959    public method type {} {
    60         return $_type
     60        return $_type
    6161    }
    6262    public method numpoints {} {
    63         return $_numPoints
     63        return $_numPoints
    6464    }
    6565    public method numcells {} {
    66         return $_numCells
    67     }
    68 
    69     private common _xp2obj       ;      # used for fetch/release ref counting
    70     private common _obj2ref      ;      # used for fetch/release ref counting
    71     private variable _xv        ""
    72     private variable _yv        ""
    73     private variable _zv        ""
    74     private variable _xCoords   "";     # For the blt contour only
    75     private variable _yCoords   "";     # For the blt contour only
    76    
     66        return $_numCells
     67    }
     68
     69    private common _xp2obj       ;        # used for fetch/release ref counting
     70    private common _obj2ref      ;        # used for fetch/release ref counting
     71    private variable _xv        ""
     72    private variable _yv        ""
     73    private variable _zv        ""
     74    private variable _xCoords        "";  # For the blt contour only
     75    private variable _yCoords        "";  # For the blt contour only
     76
    7777    private method ReadNodesElements {path}
    78     private method GetCellCount { xNum yNum zNum }
    79     private method GetDimension { path }
    80     private method GetDouble { path }
    81     private method GetInt { path }
    82     private method InitHints {}
     78    private method GetDimension { path }
     79    private method GetDouble { path }
     80    private method GetInt { path }
     81    private method InitHints {}
    8382    private method ReadGrid { path }
    8483    private method ReadUnstructuredGrid { path }
     
    165164    foreach u $units axis { x y z } {
    166165        if { $u != "" } {
    167             set _axis2units($axis) $u 
     166            set _axis2units($axis) $u
    168167        } else {
    169             set _axis2units($axis) $first 
     168            set _axis2units($axis) $first
    170169        }
    171170    }
     
    180179    # Meshes comes in a variety of flavors
    181180    #
    182     # Dimensionality is determined from the <dimension> tag. 
     181    # Dimensionality is determined from the <dimension> tag.
    183182    #
    184183    # <vtk> described mesh
    185184    # <element> +  <node> definitions
    186     # <grid>            rectangular mesh 
     185    # <grid>            rectangular mesh
    187186    # <unstructured>    homogeneous cell type mesh.
    188187
     
    190189    set subcount 0
    191190    foreach cname [$_mesh children] {
    192         foreach type { vtk grid unstructured } {
    193             if { $cname == $type } {
    194                 incr subcount
    195                 break
    196             }
    197         }
     191        foreach type { vtk grid unstructured } {
     192            if { $cname == $type } {
     193                incr subcount
     194                break
     195            }
     196        }
    198197    }
    199198    if {[$_mesh element "node"] != "" ||
     
    207206    }
    208207    if { $subcount > 1 } {
    209         puts stderr "WARNING: too many mesh types specified for \"$path\"."
     208        puts stderr "WARNING: too many mesh types specified for \"$path\"."
    210209        return
    211210    }
    212211    set result 0
    213212    if { [$_mesh element "vtk"] != ""} {
    214         set result [ReadVtk $path]
     213        set result [ReadVtk $path]
    215214    } elseif {[$_mesh element "grid"] != "" } {
    216         set result [ReadGrid $path]
     215        set result [ReadGrid $path]
    217216    } elseif {[$_mesh element "unstructured"] != "" } {
    218         set result [ReadUnstructuredGrid $path]
     217        set result [ReadUnstructuredGrid $path]
    219218    } elseif {[$_mesh element "node"] != "" && [$_mesh element "element"] != ""} {
    220219        set result [ReadNodesElements $path]
     
    232231
    233232    if { $_xCoords != "" } {
    234         blt::vector destroy $_xCoords
     233        blt::vector destroy $_xCoords
    235234    }
    236235    if { $_yCoords != "" } {
    237         blt::vector destroy $_yCoords
    238     }
    239 }
    240 
    241 #
    242 # vtkdata -- 
    243 #
    244 #       This is called by the field object to generate a VTK file to send to
    245 #       the remote render server.  Returns the vtkDataSet object containing
    246 #       (at this point) just the mesh.  The field object doesn't know (or
    247 #       care) what type of mesh is used.  The field object will add field
    248 #       arrays before generating output to send to the remote render server.
     236        blt::vector destroy $_yCoords
     237    }
     238}
     239
     240#
     241# vtkdata --
     242#
     243#        This is called by the field object to generate a VTK file to send to
     244#        the remote render server.  Returns the vtkDataSet object containing
     245#        (at this point) just the mesh.  The field object doesn't know (or
     246#        care) what type of mesh is used.  The field object will add field
     247#        arrays before generating output to send to the remote render server.
    249248#
    250249itcl::body Rappture::Mesh::vtkdata {{what -partial}} {
    251250    if {$what == "-full"} {
    252251        append out "# vtk DataFile Version 3.0\n"
    253         append out "[hints label]\n"
    254         append out "ASCII\n"
     252        append out "[hints label]\n"
     253        append out "ASCII\n"
    255254        append out $_vtkdata
    256255        return $out
     
    341340itcl::body Rappture::Mesh::mesh { {type "vtk"} } {
    342341    switch $type {
    343         "vtk" {
    344             return ""
    345         }
    346         default {
    347             error "Requested mesh type \"$type\" is unknown."
    348         }
     342        "vtk" {
     343            return ""
     344        }
     345        default {
     346            error "Requested mesh type \"$type\" is unknown."
     347        }
    349348    }
    350349}
     
    427426        }
    428427    }
     428    foreach {key path} {
     429        toolid          tool.id
     430        toolname        tool.name
     431        toolcommand     tool.execute
     432        tooltitle       tool.title
     433        toolrevision    tool.version.application.revision
     434    } {
     435        set str [$_xmlobj get $path]
     436        if { "" != $str } {
     437            set _hints($key) $str
     438        }
     439    }
    429440}
    430441
     
    432443    set string [$_xmlobj get $path.dim]
    433444    if { $string == "" } {
    434         puts stderr "WARNING: no tag <dim> found in mesh \"$path\"."
     445        puts stderr "WARNING: no tag <dim> found in mesh \"$path\"."
    435446        return 0
    436447    }
     
    468479        return 0
    469480    }
    470     # Create a VTK file with the mesh in it. 
     481    # Create a VTK file with the mesh in it.
    471482    set _vtkdata [$_xmlobj get $path.vtk]
    472483    append out "# vtk DataFile Version 3.0\n"
     
    500511}
    501512
    502 itcl::body Rappture::Mesh::GetCellCount { xNum yNum zNum } {
    503     set numCells 1
    504     if { $xNum > 0 } {
    505         set numCells [expr $numCells * $xNum]
    506     }
    507     if { $yNum > 0 } {
    508         set numCells [expr $numCells * $yNum]
    509     }
    510     if { $zNum > 0 } {
    511         set numCells [expr $numCells * $zNum]
    512     }
    513     return $numCells
    514 }
    515 
    516513itcl::body Rappture::Mesh::ReadGrid { path } {
    517514    set _type "grid"
     
    524521    set numCurvilinear 0
    525522    foreach axis { x y z } {
    526         set min    [$_xmlobj get "$path.grid.${axis}axis.min"]
    527         set max    [$_xmlobj get "$path.grid.${axis}axis.max"]
    528         set num    [$_xmlobj get "$path.grid.${axis}axis.numpoints"]
    529         set coords [$_xmlobj get "$path.grid.${axis}coords"]
    530         set dim    [$_xmlobj get "$path.grid.${axis}dim"]
    531         if { $min != "" && $max != "" && $num != "" && $num > 0 } {
    532             set ${axis}Min $min
    533             set ${axis}Max $max
    534             set ${axis}Num $num
     523        set min    [$_xmlobj get "$path.grid.${axis}axis.min"]
     524        set max    [$_xmlobj get "$path.grid.${axis}axis.max"]
     525        set num    [$_xmlobj get "$path.grid.${axis}axis.numpoints"]
     526        set coords [$_xmlobj get "$path.grid.${axis}coords"]
     527        set dim    [$_xmlobj get "$path.grid.${axis}dim"]
     528        if { $min != "" && $max != "" && $num != "" && $num > 0 } {
     529            set ${axis}Min $min
     530            set ${axis}Max $max
     531            set ${axis}Num $num
    535532            if {$min > $max} {
    536                 puts stderr "ERROR: grid $axis min can't be greater than max"
     533                puts stderr "ERROR: grid $axis axis minimum larger than maximum"
    537534                return 0
    538535            }
    539             incr numUniform
    540         } elseif { $coords != "" } {
    541             incr numRectilinear
    542             set ${axis}Coords $coords
    543         } elseif { $dim != "" } {
     536            incr numUniform
     537        } elseif { $coords != "" } {
     538            incr numRectilinear
     539            set ${axis}Coords $coords
     540        } elseif { $dim != "" } {
    544541            set ${axis}Num $dim
    545542            incr numCurvilinear
     
    548545    set _dim [expr $numRectilinear + $numUniform + $numCurvilinear]
    549546    if { $_dim == 0 } {
    550         # No data found.
     547        # No data found.
    551548        puts stderr "WARNING: bad grid \"$path\": no data found"
    552         return 0
     549        return 0
    553550    }
    554551    if { $numCurvilinear > 0 } {
     
    563560            return 0
    564561        }
    565         if { ![info exists xNum] } {
     562        if { ![info exists xNum] } {
    566563            puts stderr "WARNING: bad grid \"$path\": invalid dimensions for curvilinear grid: missing <xdim> from grid description."
    567564            return 0
     
    575572        if { [info exists zNum] } {
    576573            set _dim 3
    577             set _numPoints [expr $xNum * $yNum * $zNum]
    578             set _numCells [GetCellCount $xNum $yNum $zNum]
    579             if { ($_numPoints * 3) != $numCoords } {
     574            set _numPoints [expr $xNum * $yNum * $zNum]
     575            set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1) * ($zNum > 1 ? ($zNum - 1) : 1)]
     576            if { ($_numPoints*3) != $numCoords } {
    580577                puts stderr "WARNING: bad grid \"$path\": invalid grid: \# of points does not match dimensions <xdim> * <ydim> * <zdim>"
    581578                return 0
     
    586583            }
    587584            $all split $xv $yv $zv
    588             foreach axis {x y z} {
     585            foreach axis {x y z} {
    589586                set vector [set ${axis}v]
    590587                set _limits($axis) [$vector limits]
    591             }
    592             append out "DATASET STRUCTURED_GRID\n"
    593             append out "DIMENSIONS $xNum $yNum $zNum\n"
    594             append out "POINTS $_numPoints double\n"
     588            }
     589            append out "DATASET STRUCTURED_GRID\n"
     590            append out "DIMENSIONS $xNum $yNum $zNum\n"
     591            append out "POINTS $_numPoints double\n"
    595592            append out [$all range 0 end]
    596593            append out "\n"
    597             set _vtkdata $out
     594            set _vtkdata $out
    598595        } elseif { [info exists yNum] } {
    599596            set _dim 2
    600             set _numPoints [expr $xNum * $yNum]
    601             set _numCells [GetCellCount $xNum $yNum 0]
    602             if { ($_numPoints * 2) != $numCoords } {
     597            set _numPoints [expr $xNum * $yNum]
     598            set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1)]
     599            if { ($_numPoints*2) != $numCoords } {
    603600                puts stderr "WARNING: bad grid \"$path\": \# of points does not match dimensions <xdim> * <ydim>"
    604601                return 0
     
    608605                return 0
    609606            }
    610             foreach axis {x y} {
     607            foreach axis {x y} {
    611608                set vector [set ${axis}v]
    612609                set _limits($axis) [$vector limits]
    613             }
     610            }
    614611            set _limits(z) [list 0 0]
    615612            $zv seq 0 0 [$xv length]
    616613            $all merge $xv $yv $zv
    617             append out "DATASET STRUCTURED_GRID\n"
    618             append out "DIMENSIONS $xNum $yNum 1\n"
    619             append out "POINTS $_numPoints double\n"
     614            append out "DATASET STRUCTURED_GRID\n"
     615            append out "DIMENSIONS $xNum $yNum 1\n"
     616            append out "POINTS $_numPoints double\n"
    620617            append out [$all range 0 end]
    621618            append out "\n"
    622             set _vtkdata $out
     619            set _vtkdata $out
    623620        } else {
    624621            set _dim 1
    625622            set _numPoints $xNum
    626             set _numCells [GetCellCount $xNum 0 0]
     623            set _numCells [expr $xNum - 1]
    627624            if { $_numPoints != $numCoords } {
    628625                puts stderr "WARNING: bad grid \"$path\": \# of points does not match <xdim>"
     
    635632            $zv seq 0 0 [$xv length]
    636633            $all merge $xv $yv $zv
    637             append out "DATASET STRUCTURED_GRID\n"
    638             append out "DIMENSIONS $xNum 1 1\n"
    639             append out "POINTS $_numPoints double\n"
     634            append out "DATASET STRUCTURED_GRID\n"
     635            append out "DIMENSIONS $xNum 1 1\n"
     636            append out "POINTS $_numPoints double\n"
    640637            append out [$all range 0 end]
    641638            append out "\n"
    642             set _vtkdata $out
    643         }
     639            set _vtkdata $out
     640        }
    644641        blt::vector destroy $all $xv $yv $zv
    645         return 1
     642        return 1
    646643    }
    647644    if { $numRectilinear == 0 && $numUniform > 0} {
    648         # This is the special case where all axes 2D/3D are uniform. 
     645        # This is the special case where all axes 2D/3D are uniform.
    649646        # This results in a STRUCTURED_POINTS
    650647        if { $_dim == 1 } {
    651             set xSpacing 0
    652             if { $xNum > 1 } {
    653                 set xSpacing [expr ($xMax - $xMin) / double($xNum - 1)]
    654             }
    655             set _numPoints $xNum
    656             set _numCells [GetCellCount $xNum 0 0]
    657             append out "DATASET STRUCTURED_POINTS\n"
    658             append out "DIMENSIONS $xNum 1 1\n"
    659             append out "ORIGIN $xMin 0 0\n"
    660             append out "SPACING $xSpacing 0 0\n"
    661             set _vtkdata $out
     648            if {$xNum == 1} {
     649                set xSpace 0
     650            } else {
     651                set xSpace [expr ($xMax - $xMin) / double($xNum - 1)]
     652            }
     653            set _numPoints $xNum
     654            set _numCells [expr $xNum - 1]
     655            append out "DATASET STRUCTURED_POINTS\n"
     656            append out "DIMENSIONS $xNum 1 1\n"
     657            append out "ORIGIN $xMin 0 0\n"
     658            append out "SPACING $xSpace 0 0\n"
     659            set _vtkdata $out
    662660            set _limits(x) [list $xMin $xMax]
    663661            set _limits(y) [list 0 0]
    664662            set _limits(z) [list 0 0]
    665         } elseif { $_dim == 2 } {
    666             set xSpacing 0
    667             set ySpacing 0
    668             if { $xNum > 1 } {
    669                 set xSpacing [expr ($xMax - $xMin) / double($xNum - 1)]
    670             }
    671             if { $yNum > 1 } {
    672                 set ySpacing [expr ($yMax - $yMin) / double($yNum - 1)]
    673             }
    674             set _numPoints [expr $xNum * $yNum]
    675             set _numCells [GetCellCount $xNum $yNum 0]
    676             append out "DATASET STRUCTURED_POINTS\n"
    677             append out "DIMENSIONS $xNum $yNum 1\n"
    678             append out "ORIGIN $xMin $yMin 0\n"
    679             append out "SPACING $xSpacing $ySpacing 0\n"
    680             set _vtkdata $out
    681             foreach axis {x y} {
    682                 set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]]
    683             }
     663        } elseif { $_dim == 2 } {
     664            if {$xNum == 1} {
     665                set xSpace 0
     666            } else {
     667                set xSpace [expr ($xMax - $xMin) / double($xNum - 1)]
     668            }
     669            if {$yNum == 1} {
     670                set ySpace 0
     671            } else {
     672                set ySpace [expr ($yMax - $yMin) / double($yNum - 1)]
     673            }
     674            set _numPoints [expr $xNum * $yNum]
     675            set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1)]
     676            append out "DATASET STRUCTURED_POINTS\n"
     677            append out "DIMENSIONS $xNum $yNum 1\n"
     678            append out "ORIGIN $xMin $yMin 0\n"
     679            append out "SPACING $xSpace $ySpace 0\n"
     680            set _vtkdata $out
     681            foreach axis {x y} {
     682                set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]]
     683            }
    684684            set _limits(z) [list 0 0]
    685         } elseif { $_dim == 3 } {
    686             set xSpacing 0
    687             set ySpacing 0
    688             set zSpacing 0
    689             if {$xNum > 1} {
    690                 set xSpacing [expr ($xMax - $xMin) / double($xNum - 1)]
    691             }
    692             if {$yNum > 1} {
    693                 set ySpacing [expr ($yMax - $yMin) / double($yNum - 1)]
    694             }
    695             if {$zNum > 1} {
    696                 set zSpacing [expr ($zMax - $zMin) / double($zNum - 1)]
    697             }
    698             set _numPoints [expr $xNum * $yNum * $zNum]
    699             set _numCells [GetCellCount $xNum $yNum $zNum]
    700             append out "DATASET STRUCTURED_POINTS\n"
    701             append out "DIMENSIONS $xNum $yNum $zNum\n"
    702             append out "ORIGIN $xMin $yMin $zMin\n"
    703             append out "SPACING $xSpacing $ySpacing $zSpacing\n"
    704             set _vtkdata $out
    705             foreach axis {x y z} {
    706                 set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]]
    707             }
    708         } else {
    709             puts stderr "WARNING: bad grid \"$path\": bad dimension \"$_dim\""
     685        } elseif { $_dim == 3 } {
     686            if {$xNum == 1} {
     687                set xSpace 0
     688            } else {
     689                set xSpace [expr ($xMax - $xMin) / double($xNum - 1)]
     690            }
     691            if {$yNum == 1} {
     692                set ySpace 0
     693            } else {
     694                set ySpace [expr ($yMax - $yMin) / double($yNum - 1)]
     695            }
     696            if {$zNum == 1} {
     697                set zSpace 0
     698            } else {
     699                set zSpace [expr ($zMax - $zMin) / double($zNum - 1)]
     700            }
     701            set _numPoints [expr $xNum * $yNum * $zNum]
     702            set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1) * ($zNum > 1 ? ($zNum - 1) : 1)]
     703            append out "DATASET STRUCTURED_POINTS\n"
     704            append out "DIMENSIONS $xNum $yNum $zNum\n"
     705            append out "ORIGIN $xMin $yMin $zMin\n"
     706            append out "SPACING $xSpace $ySpace $zSpace\n"
     707            set _vtkdata $out
     708            foreach axis {x y z} {
     709                set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]]
     710            }
     711        } else {
     712            puts stderr "WARNING: bad grid \"$path\": bad dimension \"$_dim\""
    710713            return 0
    711         }
    712         return 1
     714        }
     715        return 1
    713716    }
    714717    # This is the hybrid case.  Some axes are uniform, others are nonuniform.
    715718    set xv [blt::vector create \#auto]
    716719    if { [info exists xMin] } {
    717         $xv seq $xMin $xMax $xNum
    718     } else {
    719         $xv set [$_xmlobj get $path.grid.xcoords]
    720         set xMin [$xv min]
    721         set xMax [$xv max]
    722         set xNum [$xv length]
     720        $xv seq $xMin $xMax $xNum
     721    } else {
     722        $xv set [$_xmlobj get $path.grid.xcoords]
     723        set xMin [$xv min]
     724        set xMax [$xv max]
     725        set xNum [$xv length]
    723726    }
    724727    set yv [blt::vector create \#auto]
     
    737740    set zv [blt::vector create \#auto]
    738741    if { $_dim == 3 } {
    739         if { [info exists zMin] } {
    740             $zv seq $zMin $zMax $zNum
    741         }  else {
    742             $zv set [$_xmlobj get $path.grid.zcoords]
    743             set zMin [$zv min]
    744             set zMax [$zv max]
    745             set zNum [$zv length]
    746         }
    747     } else {
    748         set zNum 1
     742        if { [info exists zMin] } {
     743            $zv seq $zMin $zMax $zNum
     744        }  else {
     745            $zv set [$_xmlobj get $path.grid.zcoords]
     746            set zMin [$zv min]
     747            set zMax [$zv max]
     748            set zNum [$zv length]
     749        }
     750    } else {
     751        set zNum 1
    749752    }
    750753    if { $_dim == 3 } {
    751         set _numPoints [expr $xNum * $yNum * $zNum]
    752         set _numCells [GetCellCount $xNum $yNum $zNum]
    753         append out "DATASET RECTILINEAR_GRID\n"
    754         append out "DIMENSIONS $xNum $yNum $zNum\n"
    755         append out "X_COORDINATES $xNum double\n"
    756         append out [$xv range 0 end]
    757         append out "\n"
    758         append out "Y_COORDINATES $yNum double\n"
    759         append out [$yv range 0 end]
    760         append out "\n"
    761         append out "Z_COORDINATES $zNum double\n"
    762         append out [$zv range 0 end]
    763         append out "\n"
    764         set _vtkdata $out
    765         foreach axis {x y z} {
    766             if { [info exists ${axis}Min] } {
    767                 set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]]
    768             }
    769         }
     754        set _numPoints [expr $xNum * $yNum * $zNum]
     755        set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1) * ($zNum > 1 ? ($zNum - 1) : 1)]
     756        append out "DATASET RECTILINEAR_GRID\n"
     757        append out "DIMENSIONS $xNum $yNum $zNum\n"
     758        append out "X_COORDINATES $xNum double\n"
     759        append out [$xv range 0 end]
     760        append out "\n"
     761        append out "Y_COORDINATES $yNum double\n"
     762        append out [$yv range 0 end]
     763        append out "\n"
     764        append out "Z_COORDINATES $zNum double\n"
     765        append out [$zv range 0 end]
     766        append out "\n"
     767        set _vtkdata $out
     768        foreach axis {x y z} {
     769            if { [info exists ${axis}Min] } {
     770                set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]]
     771            }
     772        }
    770773    } elseif { $_dim == 2 } {
    771         set _numPoints [expr $xNum * $yNum]
    772         set _numCells [GetCellCount $xNum $yNum 0]
    773         append out "DATASET RECTILINEAR_GRID\n"
    774         append out "DIMENSIONS $xNum $yNum 1\n"
    775         append out "X_COORDINATES $xNum double\n"
    776         append out [$xv range 0 end]
    777         append out "\n"
    778         append out "Y_COORDINATES $yNum double\n"
    779         append out [$yv range 0 end]
    780         append out "\n"
    781         append out "Z_COORDINATES 1 double\n"
    782         append out "0\n"
    783         foreach axis {x y} {
    784             if { [info exists ${axis}Min] } {
    785                 set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]]
    786             }
    787         }
     774        set _numPoints [expr $xNum * $yNum]
     775        set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1)]
     776        append out "DATASET RECTILINEAR_GRID\n"
     777        append out "DIMENSIONS $xNum $yNum 1\n"
     778        append out "X_COORDINATES $xNum double\n"
     779        append out [$xv range 0 end]
     780        append out "\n"
     781        append out "Y_COORDINATES $yNum double\n"
     782        append out [$yv range 0 end]
     783        append out "\n"
     784        append out "Z_COORDINATES 1 double\n"
     785        append out "0\n"
     786        foreach axis {x y} {
     787            if { [info exists ${axis}Min] } {
     788                set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]]
     789            }
     790        }
    788791        set _limits(z) [list 0 0]
    789         set _vtkdata $out
     792        set _vtkdata $out
    790793    } elseif { $_dim == 1 } {
    791794        set _numPoints $xNum
    792         set _numCells [GetCellCount $xNum 0 0]
    793         append out "DATASET RECTILINEAR_GRID\n"
    794         append out "DIMENSIONS $xNum 1 1\n"
    795         append out "X_COORDINATES $xNum double\n"
    796         append out [$xv range 0 end]
    797         append out "\n"
    798         append out "Y_COORDINATES 1 double\n"
    799         append out "0\n"
    800         append out "Z_COORDINATES 1 double\n"
    801         append out "0\n"
     795        set _numCells [expr $xNum - 1]
     796        append out "DATASET RECTILINEAR_GRID\n"
     797        append out "DIMENSIONS $xNum 1 1\n"
     798        append out "X_COORDINATES $xNum double\n"
     799        append out [$xv range 0 end]
     800        append out "\n"
     801        append out "Y_COORDINATES 1 double\n"
     802        append out "0\n"
     803        append out "Z_COORDINATES 1 double\n"
     804        append out "0\n"
    802805        if { [info exists xMin] } {
    803806            set _limits(x) [list $xMin $xMax]
     
    805808        set _limits(y) [list 0 0]
    806809        set _limits(z) [list 0 0]
    807         set _vtkdata $out
    808     } else {
    809         puts stderr "WARNING: bad grid \"$path\": invalid dimension \"$_dim\""
     810        set _vtkdata $out
     811    } else {
     812        puts stderr "WARNING: bad grid \"$path\": invalid dimension \"$_dim\""
    810813        return 0
    811814    }
    812     blt::vector destroy $xv $yv $zv 
     815    blt::vector destroy $xv $yv $zv
    813816    return 1
    814817}
     
    844847    set celltypes {}
    845848    foreach { a b c } $triangles {
    846         append data " 3 $a $b $c\n"
    847         append celltypes "5\n"
    848         incr _numCells
     849        append data " 3 $a $b $c\n"
     850        append celltypes "5\n"
     851        incr _numCells
    849852    }
    850853    append out "DATASET UNSTRUCTURED_GRID\n"
    851854    append out "POINTS $_numPoints double\n"
    852855    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    853         append out " $x $y $z\n"
     856        append out " $x $y $z\n"
    854857    }
    855858    set count [expr $_numCells * 4]
     
    876879    set celltypes {}
    877880    foreach { a b c d } $quads {
    878         append data " 4 $a $b $c $d\n"
    879         append celltypes "9\n"
    880         incr _numCells
     881        append data " 4 $a $b $c $d\n"
     882        append celltypes "9\n"
     883        incr _numCells
    881884    }
    882885    append out "DATASET UNSTRUCTURED_GRID\n"
    883886    append out "POINTS $_numPoints double\n"
    884887    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    885         append out " $x $y $z\n"
     888        append out " $x $y $z\n"
    886889    }
    887890    set count [expr $_numCells * 5]
     
    913916            continue
    914917        }
    915         append data " $numIndices $line\n"
    916         incr _numCells
     918        append data " $numIndices $line\n"
     919        incr _numCells
    917920        set count [expr $count + $numIndices + 1]
    918921    }
     
    920923    append out "POINTS $_numPoints double\n"
    921924    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    922         append out " $x $y $z\n"
     925        append out " $x $y $z\n"
    923926    }
    924927    append out "VERTICES $_numCells $count\n"
     
    947950            continue
    948951        }
    949         append data " $numIndices $line\n"
    950         incr _numCells
     952        append data " $numIndices $line\n"
     953        incr _numCells
    951954        set count [expr $count + $numIndices + 1]
    952955    }
     
    954957    append out "POINTS $_numPoints double\n"
    955958    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    956         append out " $x $y $z\n"
     959        append out " $x $y $z\n"
    957960    }
    958961    append out "LINES $_numCells $count\n"
     
    981984            continue
    982985        }
    983         append data " $numIndices $line\n"
    984         incr _numCells
     986        append data " $numIndices $line\n"
     987        incr _numCells
    985988        set count [expr $count + $numIndices + 1]
    986989    }
     
    988991    append out "POINTS $_numPoints double\n"
    989992    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    990         append out " $x $y $z\n"
     993        append out " $x $y $z\n"
    991994    }
    992995    append out "POLYGONS $_numCells $count\n"
     
    10151018            continue
    10161019        }
    1017         append data " $numIndices $line\n"
    1018         incr _numCells
     1020        append data " $numIndices $line\n"
     1021        incr _numCells
    10191022        set count [expr $count + $numIndices + 1]
    10201023    }
     
    10221025    append out "POINTS $_numPoints double\n"
    10231026    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    1024         append out " $x $y $z\n"
     1027        append out " $x $y $z\n"
    10251028    }
    10261029    append out "TRIANGLE_STRIPS $_numCells $count\n"
     
    10441047    set celltypes {}
    10451048    foreach { a b c d } $tetras {
    1046         append data " 4 $a $b $c $d\n"
    1047         append celltypes "10\n"
    1048         incr _numCells
     1049        append data " 4 $a $b $c $d\n"
     1050        append celltypes "10\n"
     1051        incr _numCells
    10491052    }
    10501053    append out "DATASET UNSTRUCTURED_GRID\n"
    10511054    append out "POINTS $_numPoints double\n"
    10521055    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    1053         append out " $x $y $z\n"
     1056        append out " $x $y $z\n"
    10541057    }
    10551058    set count [expr $_numCells * 5]
     
    10731076    set celltypes {}
    10741077    foreach { a b c d e f g h } $hexas {
    1075         append data " 8 $a $b $c $d $e $f $g $h\n"
    1076         append celltypes "12\n"
    1077         incr _numCells
     1078        append data " 8 $a $b $c $d $e $f $g $h\n"
     1079        append celltypes "12\n"
     1080        incr _numCells
    10781081    }
    10791082    append out "DATASET UNSTRUCTURED_GRID\n"
    10801083    append out "POINTS $_numPoints double\n"
    10811084    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    1082         append out " $x $y $z\n"
     1085        append out " $x $y $z\n"
    10831086    }
    10841087    set count [expr $_numCells * 9]
     
    11021105    set celltypes {}
    11031106    foreach { a b c d e f } $wedges {
    1104         append data " 6 $a $b $c $d $e $f\n"
    1105         append celltypes "13\n"
    1106         incr _numCells
     1107        append data " 6 $a $b $c $d $e $f\n"
     1108        append celltypes "13\n"
     1109        incr _numCells
    11071110    }
    11081111    append out "DATASET UNSTRUCTURED_GRID\n"
    11091112    append out "POINTS $_numPoints double\n"
    11101113    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    1111         append out " $x $y $z\n"
     1114        append out " $x $y $z\n"
    11121115    }
    11131116    set count [expr $_numCells * 7]
     
    11311134    set celltypes {}
    11321135    foreach { a b c d e } $pyramids {
    1133         append data " 5 $a $b $c $d $e\n"
    1134         append celltypes "14\n"
    1135         incr _numCells
     1136        append data " 5 $a $b $c $d $e\n"
     1137        append celltypes "14\n"
     1138        incr _numCells
    11361139    }
    11371140    append out "DATASET UNSTRUCTURED_GRID\n"
    11381141    append out "POINTS $_numPoints double\n"
    11391142    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    1140         append out " $x $y $z\n"
     1143        append out " $x $y $z\n"
    11411144    }
    11421145    set count [expr $_numCells * 6]
     
    11501153
    11511154    set _vtkdata $out
    1152     return 1 
     1155    return 1
    11531156}
    11541157
     
    12171220    # Step 1: Verify that there's only one cell tag of any kind.
    12181221    set numCells 0
    1219     foreach type { 
     1222    foreach type {
    12201223        cells
    1221         hexahedrons 
    1222         lines 
    1223         polygons 
    1224         pyramids 
     1224        hexahedrons
     1225        lines
     1226        polygons
     1227        pyramids
    12251228        quads
    1226         tetrahedrons 
    1227         triangles 
     1229        tetrahedrons
     1230        triangles
    12281231        trianglestrips
    1229         vertices 
    1230         wedges 
     1232        vertices
     1233        wedges
    12311234    } {
    12321235        set data [$_xmlobj get $path.unstructured.$type]
     
    12381241    set celltypes [$_xmlobj get $path.unstructured.celltypes]
    12391242    if { $numCells == 0 && $celltypes != "" } {
    1240         puts stderr "WARNING: bad unstuctured grid \"$path\": no <cells> description found."
     1243        puts stderr "WARNING: bad unstuctured grid \"$path\": no <cells> description found."
    12411244        return 0
    12421245    }
     
    12451248        return 0
    12461249    }
    1247     foreach type { cells
    1248         vertices lines polygons trianglestrips
    1249         triangles quads
    1250         tetrahedrons hexahedrons wedges pyramids } {
     1250    foreach type {
     1251        cells
     1252        hexahedrons
     1253        lines
     1254        polygons
     1255        pyramids
     1256        quads
     1257        tetrahedrons
     1258        triangles
     1259        trianglestrips
     1260        vertices
     1261        wedges
     1262    } {
    12511263        set data [$_xmlobj get $path.unstructured.$type]
    12521264        if { $data != "" } {
     
    12541266        }
    12551267    }
    1256     # Step 2: Allow points to be specified as <points> or 
     1268    # Step 2: Allow points to be specified as <points> or
    12571269    #         <xcoords>, <ycoords>, <zcoords>.  Split and convert into
    12581270    #         3 vectors, one for each coordinate.
     
    14021414    set data {}
    14031415    foreach cname [$_xmlobj children -type node $path] {
    1404         append data "[$_xmlobj get $path.$cname]\n"
    1405     }   
     1416        append data "[$_xmlobj get $path.$cname]\n"
     1417    }
    14061418    Rappture::ReadPoints $data _dim points
    14071419    if { $_dim == 2 } {
    1408         set all [blt::vector create \#auto]
    1409         set xv [blt::vector create \#auto]
    1410         set yv [blt::vector create \#auto]
    1411         set zv [blt::vector create \#auto]
    1412         $all set $points
    1413         $all split $xv $yv
    1414         set _numPoints [$xv length]
     1420        set all [blt::vector create \#auto]
     1421        set xv [blt::vector create \#auto]
     1422        set yv [blt::vector create \#auto]
     1423        set zv [blt::vector create \#auto]
     1424        $all set $points
     1425        $all split $xv $yv
     1426        set _numPoints [$xv length]
    14151427        set _limits(x) [$xv limits]
    14161428        set _limits(y) [$yv limits]
    14171429        set _limits(z) [list 0 0]
    1418         # 2D Dataset. All Z coordinates are 0
    1419         $zv seq 0.0 0.0 $_numPoints
    1420         $all merge $xv $yv $zv
    1421         set points [$all range 0 end]
    1422         blt::vector destroy $all $xv $yv $zv
     1430        # 2D Dataset. All Z coordinates are 0
     1431        $zv seq 0.0 0.0 $_numPoints
     1432        $all merge $xv $yv $zv
     1433        set points [$all range 0 end]
     1434        blt::vector destroy $all $xv $yv $zv
    14231435    } elseif { $_dim == 3 } {
    1424         set all [blt::vector create \#auto]
    1425         set xv [blt::vector create \#auto]
    1426         set yv [blt::vector create \#auto]
    1427         set zv [blt::vector create \#auto]
    1428         $all set $points
    1429         $all split $xv $yv $zv
    1430         set _numPoints [$xv length]
     1436        set all [blt::vector create \#auto]
     1437        set xv [blt::vector create \#auto]
     1438        set yv [blt::vector create \#auto]
     1439        set zv [blt::vector create \#auto]
     1440        $all set $points
     1441        $all split $xv $yv $zv
     1442        set _numPoints [$xv length]
    14311443        set _limits(x) [$xv limits]
    14321444        set _limits(y) [$yv limits]
    14331445        set _limits(z) [$zv limits]
    1434         set points [$all range 0 end]
    1435         blt::vector destroy $all $xv $yv $zv
    1436     } else {
    1437         error "bad dimension \"$_dim\" for nodes mesh"
     1446        set points [$all range 0 end]
     1447        blt::vector destroy $all $xv $yv $zv
     1448    } else {
     1449        error "bad dimension \"$_dim\" for nodes mesh"
    14381450    }
    14391451    array set node2celltype {
    1440         3 5
    1441         4 10
    1442         8 12
    1443         6 13
    1444         5 14
     1452        3 5
     1453        4 10
     1454        8 12
     1455        6 13
     1456        5 14
    14451457    }
    14461458    set count 0
     
    14511463    foreach cname [$_xmlobj children -type element $path] {
    14521464        set nodeList [$_mesh get $cname.nodes]
    1453         set numNodes [llength $nodeList]
    1454         if { ![info exists node2celltype($numNodes)] } {
    1455             puts stderr "WARNING: bad nodes/elements mesh \$path\": unknown number of indices \"$_numNodes\": should be 3, 4, 5, 6, or 8"
    1456             return 0
    1457         }
    1458         set celltype $node2celltype($numNodes)
    1459         append celltypes "  $celltype\n"
     1465        set numNodes [llength $nodeList]
     1466        if { ![info exists node2celltype($numNodes)] } {
     1467            puts stderr "WARNING: bad nodes/elements mesh \$path\": unknown number of indices \"$_numNodes\": should be 3, 4, 5, 6, or 8"
     1468            return 0
     1469        }
     1470        set celltype $node2celltype($numNodes)
     1471        append celltypes "  $celltype\n"
    14601472        if { $celltype == 12 } {
    14611473            # Formerly used voxels instead of hexahedrons. We're converting
     
    14671479            }
    14681480            set nodeList $newList
    1469         } 
    1470         append data "  $numNodes $nodeList\n"
    1471         incr _numCells
    1472         incr count $numNodes
    1473         incr count;                     # One extra for the VTK celltype id.
     1481        }
     1482        append data "  $numNodes $nodeList\n"
     1483        incr _numCells
     1484        incr count $numNodes
     1485        incr count;                        # One extra for the VTK celltype id.
    14741486    }
    14751487
     
    14841496    append out "\n"
    14851497    set _vtkdata $out
    1486     set _isValid 1 
     1498    set _isValid 1
    14871499}
    14881500
Note: See TracChangeset for help on using the changeset viewer.