Changeset 4639


Ignore:
Timestamp:
Sep 30, 2014, 8:09:28 PM (10 years ago)
Author:
ldelgass
Message:

Fix for grids with a single sample in one of the axes

File:
1 edited

Legend:

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

    r4418 r4639  
    557557            set _dim 3
    558558            set _numPoints [expr $xNum * $yNum * $zNum]
    559             set _numCells [expr ($xNum - 1) * ($yNum - 1) * ($zNum - 1)]
     559            set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1) * ($zNum > 1 ? ($zNum - 1) : 1)]
    560560            if { ($_numPoints*3) != $numCoords } {
    561561                puts stderr "WARNING: bad grid \"$path\": invalid grid: \# of points does not match dimensions <xdim> * <ydim> * <zdim>"
     
    580580            set _dim 2
    581581            set _numPoints [expr $xNum * $yNum]
    582             set _numCells [expr ($xNum - 1) * ($yNum - 1)]
     582            set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1)]
    583583            if { ($_numPoints*2) != $numCoords } {
    584584                puts stderr "WARNING: bad grid \"$path\": \# of points does not match dimensions <xdim> * <ydim>"
     
    630630        # This results in a STRUCTURED_POINTS
    631631        if { $_dim == 1 } {
    632             set xSpace [expr ($xMax - $xMin) / double($xNum - 1)]
     632            if {$xNum == 1} {
     633                set xSpace 0
     634            } else {
     635                set xSpace [expr ($xMax - $xMin) / double($xNum - 1)]
     636            }
    633637            set _numPoints $xNum
    634638            set _numCells [expr $xNum - 1]
     
    642646            set _limits(z) [list 0 0]
    643647        } elseif { $_dim == 2 } {
    644             set xSpace [expr ($xMax - $xMin) / double($xNum - 1)]
    645             set ySpace [expr ($yMax - $yMin) / double($yNum - 1)]
     648            if {$xNum == 1} {
     649                set xSpace 0
     650            } else {
     651                set xSpace [expr ($xMax - $xMin) / double($xNum - 1)]
     652            }
     653            if {$yNum == 1} {
     654                set ySpace 0
     655            } else {
     656                set ySpace [expr ($yMax - $yMin) / double($yNum - 1)]
     657            }
    646658            set _numPoints [expr $xNum * $yNum]
    647             set _numCells [expr ($xNum - 1) * ($yNum - 1)]
     659            set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1)]
    648660            append out "DATASET STRUCTURED_POINTS\n"
    649661            append out "DIMENSIONS $xNum $yNum 1\n"
     
    656668            set _limits(z) [list 0 0]
    657669        } elseif { $_dim == 3 } {
    658             set xSpace [expr ($xMax - $xMin) / double($xNum - 1)]
    659             set ySpace [expr ($yMax - $yMin) / double($yNum - 1)]
    660             set zSpace [expr ($zMax - $zMin) / double($zNum - 1)]
     670            if {$xNum == 1} {
     671                set xSpace 0
     672            } else {
     673                set xSpace [expr ($xMax - $xMin) / double($xNum - 1)]
     674            }
     675            if {$yNum == 1} {
     676                set ySpace 0
     677            } else {
     678                set ySpace [expr ($yMax - $yMin) / double($yNum - 1)]
     679            }
     680            if {$zNum == 1} {
     681                set zSpace 0
     682            } else {
     683                set zSpace [expr ($zMax - $zMin) / double($zNum - 1)]
     684            }
    661685            set _numPoints [expr $xNum * $yNum * $zNum]
    662             set _numCells [expr ($xNum - 1) * ($yNum - 1) * ($zNum - 1)]
     686            set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1) * ($zNum > 1 ? ($zNum - 1) : 1)]
    663687            append out "DATASET STRUCTURED_POINTS\n"
    664688            append out "DIMENSIONS $xNum $yNum $zNum\n"
     
    713737    if { $_dim == 3 } {
    714738        set _numPoints [expr $xNum * $yNum * $zNum]
    715         set _numCells [expr ($xNum - 1) * ($yNum - 1) * ($zNum - 1)]
     739        set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1) * ($zNum > 1 ? ($zNum - 1) : 1)]
    716740        append out "DATASET RECTILINEAR_GRID\n"
    717741        append out "DIMENSIONS $xNum $yNum $zNum\n"
     
    733757    } elseif { $_dim == 2 } {
    734758        set _numPoints [expr $xNum * $yNum]
    735         set _numCells [expr ($xNum - 1) * ($yNum - 1)]
     759        set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1)]
    736760        append out "DATASET RECTILINEAR_GRID\n"
    737761        append out "DIMENSIONS $xNum $yNum 1\n"
Note: See TracChangeset for help on using the changeset viewer.