Changeset 5003 for trunk


Ignore:
Timestamp:
Feb 11, 2015 2:31:41 PM (6 years ago)
Author:
ldelgass
Message:

whitespace

File:
1 edited

Legend:

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

    r4787 r5003  
    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 GetDimension { path } 
    79     private method GetDouble { path } 
    80     private method GetInt { path } 
    81     private method InitHints {} 
     78    private method GetDimension { path }
     79    private method GetDouble { path }
     80    private method GetInt { path }
     81    private method InitHints {}
    8282    private method ReadGrid { path }
    8383    private method ReadUnstructuredGrid { path }
     
    164164    foreach u $units axis { x y z } {
    165165        if { $u != "" } {
    166             set _axis2units($axis) $u 
     166            set _axis2units($axis) $u
    167167        } else {
    168             set _axis2units($axis) $first 
     168            set _axis2units($axis) $first
    169169        }
    170170    }
     
    179179    # Meshes comes in a variety of flavors
    180180    #
    181     # Dimensionality is determined from the <dimension> tag. 
     181    # Dimensionality is determined from the <dimension> tag.
    182182    #
    183183    # <vtk> described mesh
    184184    # <element> +  <node> definitions
    185     # <grid>            rectangular mesh 
     185    # <grid>            rectangular mesh
    186186    # <unstructured>    homogeneous cell type mesh.
    187187
     
    189189    set subcount 0
    190190    foreach cname [$_mesh children] {
    191         foreach type { vtk grid unstructured } {
    192             if { $cname == $type } {
    193                 incr subcount
    194                 break
    195             }
    196         }
     191        foreach type { vtk grid unstructured } {
     192            if { $cname == $type } {
     193                incr subcount
     194                break
     195            }
     196        }
    197197    }
    198198    if {[$_mesh element "node"] != "" ||
     
    206206    }
    207207    if { $subcount > 1 } {
    208         puts stderr "WARNING: too many mesh types specified for \"$path\"."
     208        puts stderr "WARNING: too many mesh types specified for \"$path\"."
    209209        return
    210210    }
    211211    set result 0
    212212    if { [$_mesh element "vtk"] != ""} {
    213         set result [ReadVtk $path]
     213        set result [ReadVtk $path]
    214214    } elseif {[$_mesh element "grid"] != "" } {
    215         set result [ReadGrid $path]
     215        set result [ReadGrid $path]
    216216    } elseif {[$_mesh element "unstructured"] != "" } {
    217         set result [ReadUnstructuredGrid $path]
     217        set result [ReadUnstructuredGrid $path]
    218218    } elseif {[$_mesh element "node"] != "" && [$_mesh element "element"] != ""} {
    219219        set result [ReadNodesElements $path]
     
    231231
    232232    if { $_xCoords != "" } {
    233         blt::vector destroy $_xCoords
     233        blt::vector destroy $_xCoords
    234234    }
    235235    if { $_yCoords != "" } {
    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.
     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.
    248248#
    249249itcl::body Rappture::Mesh::vtkdata {{what -partial}} {
    250250    if {$what == "-full"} {
    251251        append out "# vtk DataFile Version 3.0\n"
    252         append out "[hints label]\n"
    253         append out "ASCII\n"
     252        append out "[hints label]\n"
     253        append out "ASCII\n"
    254254        append out $_vtkdata
    255255        return $out
     
    340340itcl::body Rappture::Mesh::mesh { {type "vtk"} } {
    341341    switch $type {
    342         "vtk" {
    343             return ""
    344         }
    345         default {
    346             error "Requested mesh type \"$type\" is unknown."
    347         }
     342        "vtk" {
     343            return ""
     344        }
     345        default {
     346            error "Requested mesh type \"$type\" is unknown."
     347        }
    348348    }
    349349}
     
    443443    set string [$_xmlobj get $path.dim]
    444444    if { $string == "" } {
    445         puts stderr "WARNING: no tag <dim> found in mesh \"$path\"."
     445        puts stderr "WARNING: no tag <dim> found in mesh \"$path\"."
    446446        return 0
    447447    }
     
    479479        return 0
    480480    }
    481     # Create a VTK file with the mesh in it. 
     481    # Create a VTK file with the mesh in it.
    482482    set _vtkdata [$_xmlobj get $path.vtk]
    483483    append out "# vtk DataFile Version 3.0\n"
     
    521521    set numCurvilinear 0
    522522    foreach axis { x y z } {
    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
     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
    532532            if {$min > $max} {
    533533                puts stderr "ERROR: grid $axis axis minimum larger than maximum"
    534534                return 0
    535535            }
    536             incr numUniform
    537         } elseif { $coords != "" } {
    538             incr numRectilinear
    539             set ${axis}Coords $coords
    540         } elseif { $dim != "" } {
     536            incr numUniform
     537        } elseif { $coords != "" } {
     538            incr numRectilinear
     539            set ${axis}Coords $coords
     540        } elseif { $dim != "" } {
    541541            set ${axis}Num $dim
    542542            incr numCurvilinear
     
    545545    set _dim [expr $numRectilinear + $numUniform + $numCurvilinear]
    546546    if { $_dim == 0 } {
    547         # No data found.
     547        # No data found.
    548548        puts stderr "WARNING: bad grid \"$path\": no data found"
    549         return 0
     549        return 0
    550550    }
    551551    if { $numCurvilinear > 0 } {
     
    560560            return 0
    561561        }
    562         if { ![info exists xNum] } {
     562        if { ![info exists xNum] } {
    563563            puts stderr "WARNING: bad grid \"$path\": invalid dimensions for curvilinear grid: missing <xdim> from grid description."
    564564            return 0
     
    572572        if { [info exists zNum] } {
    573573            set _dim 3
    574             set _numPoints [expr $xNum * $yNum * $zNum]
     574            set _numPoints [expr $xNum * $yNum * $zNum]
    575575            set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1) * ($zNum > 1 ? ($zNum - 1) : 1)]
    576576            if { ($_numPoints*3) != $numCoords } {
     
    583583            }
    584584            $all split $xv $yv $zv
    585             foreach axis {x y z} {
     585            foreach axis {x y z} {
    586586                set vector [set ${axis}v]
    587587                set _limits($axis) [$vector limits]
    588             }
    589             append out "DATASET STRUCTURED_GRID\n"
    590             append out "DIMENSIONS $xNum $yNum $zNum\n"
    591             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"
    592592            append out [$all range 0 end]
    593593            append out "\n"
    594             set _vtkdata $out
     594            set _vtkdata $out
    595595        } elseif { [info exists yNum] } {
    596596            set _dim 2
    597             set _numPoints [expr $xNum * $yNum]
     597            set _numPoints [expr $xNum * $yNum]
    598598            set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1)]
    599599            if { ($_numPoints*2) != $numCoords } {
     
    605605                return 0
    606606            }
    607             foreach axis {x y} {
     607            foreach axis {x y} {
    608608                set vector [set ${axis}v]
    609609                set _limits($axis) [$vector limits]
    610             }
     610            }
    611611            set _limits(z) [list 0 0]
    612612            $zv seq 0 0 [$xv length]
    613613            $all merge $xv $yv $zv
    614             append out "DATASET STRUCTURED_GRID\n"
    615             append out "DIMENSIONS $xNum $yNum 1\n"
    616             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"
    617617            append out [$all range 0 end]
    618618            append out "\n"
    619             set _vtkdata $out
     619            set _vtkdata $out
    620620        } else {
    621621            set _dim 1
     
    632632            $zv seq 0 0 [$xv length]
    633633            $all merge $xv $yv $zv
    634             append out "DATASET STRUCTURED_GRID\n"
    635             append out "DIMENSIONS $xNum 1 1\n"
    636             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"
    637637            append out [$all range 0 end]
    638638            append out "\n"
    639             set _vtkdata $out
    640         }
     639            set _vtkdata $out
     640        }
    641641        blt::vector destroy $all $xv $yv $zv
    642         return 1
     642        return 1
    643643    }
    644644    if { $numRectilinear == 0 && $numUniform > 0} {
    645         # 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.
    646646        # This results in a STRUCTURED_POINTS
    647647        if { $_dim == 1 } {
     
    651651                set xSpace [expr ($xMax - $xMin) / double($xNum - 1)]
    652652            }
    653             set _numPoints $xNum
     653            set _numPoints $xNum
    654654            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
     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
    660660            set _limits(x) [list $xMin $xMax]
    661661            set _limits(y) [list 0 0]
    662662            set _limits(z) [list 0 0]
    663         } elseif { $_dim == 2 } {
     663        } elseif { $_dim == 2 } {
    664664            if {$xNum == 1} {
    665665                set xSpace 0
     
    672672                set ySpace [expr ($yMax - $yMin) / double($yNum - 1)]
    673673            }
    674             set _numPoints [expr $xNum * $yNum]
     674            set _numPoints [expr $xNum * $yNum]
    675675            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             }
     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 } {
     685        } elseif { $_dim == 3 } {
    686686            if {$xNum == 1} {
    687687                set xSpace 0
     
    699699                set zSpace [expr ($zMax - $zMin) / double($zNum - 1)]
    700700            }
    701             set _numPoints [expr $xNum * $yNum * $zNum]
     701            set _numPoints [expr $xNum * $yNum * $zNum]
    702702            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\""
     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\""
    713713            return 0
    714         }
    715         return 1
     714        }
     715        return 1
    716716    }
    717717    # This is the hybrid case.  Some axes are uniform, others are nonuniform.
    718718    set xv [blt::vector create \#auto]
    719719    if { [info exists xMin] } {
    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]
     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]
    726726    }
    727727    set yv [blt::vector create \#auto]
     
    740740    set zv [blt::vector create \#auto]
    741741    if { $_dim == 3 } {
    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
     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
    752752    }
    753753    if { $_dim == 3 } {
    754         set _numPoints [expr $xNum * $yNum * $zNum]
     754        set _numPoints [expr $xNum * $yNum * $zNum]
    755755        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         }
     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        }
    773773    } elseif { $_dim == 2 } {
    774         set _numPoints [expr $xNum * $yNum]
     774        set _numPoints [expr $xNum * $yNum]
    775775        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         }
     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        }
    791791        set _limits(z) [list 0 0]
    792         set _vtkdata $out
     792        set _vtkdata $out
    793793    } elseif { $_dim == 1 } {
    794794        set _numPoints $xNum
    795795        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"
     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"
    805805        if { [info exists xMin] } {
    806806            set _limits(x) [list $xMin $xMax]
     
    808808        set _limits(y) [list 0 0]
    809809        set _limits(z) [list 0 0]
    810         set _vtkdata $out
    811     } else {
    812         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\""
    813813        return 0
    814814    }
    815     blt::vector destroy $xv $yv $zv 
     815    blt::vector destroy $xv $yv $zv
    816816    return 1
    817817}
     
    847847    set celltypes {}
    848848    foreach { a b c } $triangles {
    849         append data " 3 $a $b $c\n"
    850         append celltypes "5\n"
    851         incr _numCells
     849        append data " 3 $a $b $c\n"
     850        append celltypes "5\n"
     851        incr _numCells
    852852    }
    853853    append out "DATASET UNSTRUCTURED_GRID\n"
    854854    append out "POINTS $_numPoints double\n"
    855855    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    856         append out " $x $y $z\n"
     856        append out " $x $y $z\n"
    857857    }
    858858    set count [expr $_numCells * 4]
     
    879879    set celltypes {}
    880880    foreach { a b c d } $quads {
    881         append data " 4 $a $b $c $d\n"
    882         append celltypes "9\n"
    883         incr _numCells
     881        append data " 4 $a $b $c $d\n"
     882        append celltypes "9\n"
     883        incr _numCells
    884884    }
    885885    append out "DATASET UNSTRUCTURED_GRID\n"
    886886    append out "POINTS $_numPoints double\n"
    887887    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    888         append out " $x $y $z\n"
     888        append out " $x $y $z\n"
    889889    }
    890890    set count [expr $_numCells * 5]
     
    916916            continue
    917917        }
    918         append data " $numIndices $line\n"
    919         incr _numCells
     918        append data " $numIndices $line\n"
     919        incr _numCells
    920920        set count [expr $count + $numIndices + 1]
    921921    }
     
    923923    append out "POINTS $_numPoints double\n"
    924924    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    925         append out " $x $y $z\n"
     925        append out " $x $y $z\n"
    926926    }
    927927    append out "VERTICES $_numCells $count\n"
     
    950950            continue
    951951        }
    952         append data " $numIndices $line\n"
    953         incr _numCells
     952        append data " $numIndices $line\n"
     953        incr _numCells
    954954        set count [expr $count + $numIndices + 1]
    955955    }
     
    957957    append out "POINTS $_numPoints double\n"
    958958    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    959         append out " $x $y $z\n"
     959        append out " $x $y $z\n"
    960960    }
    961961    append out "LINES $_numCells $count\n"
     
    984984            continue
    985985        }
    986         append data " $numIndices $line\n"
    987         incr _numCells
     986        append data " $numIndices $line\n"
     987        incr _numCells
    988988        set count [expr $count + $numIndices + 1]
    989989    }
     
    991991    append out "POINTS $_numPoints double\n"
    992992    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    993         append out " $x $y $z\n"
     993        append out " $x $y $z\n"
    994994    }
    995995    append out "POLYGONS $_numCells $count\n"
     
    10181018            continue
    10191019        }
    1020         append data " $numIndices $line\n"
    1021         incr _numCells
     1020        append data " $numIndices $line\n"
     1021        incr _numCells
    10221022        set count [expr $count + $numIndices + 1]
    10231023    }
     
    10251025    append out "POINTS $_numPoints double\n"
    10261026    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    1027         append out " $x $y $z\n"
     1027        append out " $x $y $z\n"
    10281028    }
    10291029    append out "TRIANGLE_STRIPS $_numCells $count\n"
     
    10471047    set celltypes {}
    10481048    foreach { a b c d } $tetras {
    1049         append data " 4 $a $b $c $d\n"
    1050         append celltypes "10\n"
    1051         incr _numCells
     1049        append data " 4 $a $b $c $d\n"
     1050        append celltypes "10\n"
     1051        incr _numCells
    10521052    }
    10531053    append out "DATASET UNSTRUCTURED_GRID\n"
    10541054    append out "POINTS $_numPoints double\n"
    10551055    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    1056         append out " $x $y $z\n"
     1056        append out " $x $y $z\n"
    10571057    }
    10581058    set count [expr $_numCells * 5]
     
    10761076    set celltypes {}
    10771077    foreach { a b c d e f g h } $hexas {
    1078         append data " 8 $a $b $c $d $e $f $g $h\n"
    1079         append celltypes "12\n"
    1080         incr _numCells
     1078        append data " 8 $a $b $c $d $e $f $g $h\n"
     1079        append celltypes "12\n"
     1080        incr _numCells
    10811081    }
    10821082    append out "DATASET UNSTRUCTURED_GRID\n"
    10831083    append out "POINTS $_numPoints double\n"
    10841084    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    1085         append out " $x $y $z\n"
     1085        append out " $x $y $z\n"
    10861086    }
    10871087    set count [expr $_numCells * 9]
     
    11051105    set celltypes {}
    11061106    foreach { a b c d e f } $wedges {
    1107         append data " 6 $a $b $c $d $e $f\n"
    1108         append celltypes "13\n"
    1109         incr _numCells
     1107        append data " 6 $a $b $c $d $e $f\n"
     1108        append celltypes "13\n"
     1109        incr _numCells
    11101110    }
    11111111    append out "DATASET UNSTRUCTURED_GRID\n"
    11121112    append out "POINTS $_numPoints double\n"
    11131113    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    1114         append out " $x $y $z\n"
     1114        append out " $x $y $z\n"
    11151115    }
    11161116    set count [expr $_numCells * 7]
     
    11341134    set celltypes {}
    11351135    foreach { a b c d e } $pyramids {
    1136         append data " 5 $a $b $c $d $e\n"
    1137         append celltypes "14\n"
    1138         incr _numCells
     1136        append data " 5 $a $b $c $d $e\n"
     1137        append celltypes "14\n"
     1138        incr _numCells
    11391139    }
    11401140    append out "DATASET UNSTRUCTURED_GRID\n"
    11411141    append out "POINTS $_numPoints double\n"
    11421142    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    1143         append out " $x $y $z\n"
     1143        append out " $x $y $z\n"
    11441144    }
    11451145    set count [expr $_numCells * 6]
     
    11531153
    11541154    set _vtkdata $out
    1155     return 1 
     1155    return 1
    11561156}
    11571157
     
    12411241    set celltypes [$_xmlobj get $path.unstructured.celltypes]
    12421242    if { $numCells == 0 && $celltypes != "" } {
    1243         puts stderr "WARNING: bad unstuctured grid \"$path\": no <cells> description found."
     1243        puts stderr "WARNING: bad unstuctured grid \"$path\": no <cells> description found."
    12441244        return 0
    12451245    }
     
    12661266        }
    12671267    }
    1268     # Step 2: Allow points to be specified as <points> or 
     1268    # Step 2: Allow points to be specified as <points> or
    12691269    #         <xcoords>, <ycoords>, <zcoords>.  Split and convert into
    12701270    #         3 vectors, one for each coordinate.
     
    14141414    set data {}
    14151415    foreach cname [$_xmlobj children -type node $path] {
    1416         append data "[$_xmlobj get $path.$cname]\n"
    1417     }   
     1416        append data "[$_xmlobj get $path.$cname]\n"
     1417    }
    14181418    Rappture::ReadPoints $data _dim points
    14191419    if { $_dim == 2 } {
    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]
     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]
    14271427        set _limits(x) [$xv limits]
    14281428        set _limits(y) [$yv limits]
    14291429        set _limits(z) [list 0 0]
    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
     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
    14351435    } elseif { $_dim == 3 } {
    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]
     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]
    14431443        set _limits(x) [$xv limits]
    14441444        set _limits(y) [$yv limits]
    14451445        set _limits(z) [$zv limits]
    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"
     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"
    14501450    }
    14511451    array set node2celltype {
    1452         3 5
    1453         4 10
    1454         8 12
    1455         6 13
    1456         5 14
     1452        3 5
     1453        4 10
     1454        8 12
     1455        6 13
     1456        5 14
    14571457    }
    14581458    set count 0
     
    14631463    foreach cname [$_xmlobj children -type element $path] {
    14641464        set nodeList [$_mesh get $cname.nodes]
    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"
     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"
    14721472        if { $celltype == 12 } {
    14731473            # Formerly used voxels instead of hexahedrons. We're converting
     
    14791479            }
    14801480            set nodeList $newList
    1481         } 
    1482         append data "  $numNodes $nodeList\n"
    1483         incr _numCells
    1484         incr count $numNodes
    1485         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.
    14861486    }
    14871487
     
    14961496    append out "\n"
    14971497    set _vtkdata $out
    1498     set _isValid 1 
     1498    set _isValid 1
    14991499}
    15001500
Note: See TracChangeset for help on using the changeset viewer.