Changeset 3289


Ignore:
Timestamp:
Feb 9, 2013, 4:06:03 PM (12 years ago)
Author:
gah
Message:

cleanup isosurface viewer

Location:
branches/Rappture 1.2
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/Rappture 1.2/examples/zoo/field/tool.xml

    r1587 r3289  
    4646      <value>nanovis</value>
    4747    </option>
    48     <default>nanovis</default>
     48    <default>vtk</default>
    4949  </choice>
    5050</input>
  • branches/Rappture 1.2/gui/scripts/cloud.tcl

    r3288 r3289  
    157157        }
    158158    }
    159     parray _limits
    160159    append out "DATASET POLYDATA\n"
    161160    append out "POINTS $_numPoints float\n"
  • branches/Rappture 1.2/gui/scripts/field.tcl

    r3288 r3289  
    1616package require BLT
    1717
    18 namespace eval Rappture { # forward declaration }
     18namespace eval Rappture {
     19    # forward declaration
     20}
     21
     22#
     23# Possible field types:
     24#
     25#       unirect2d       -- heightmap. if extents > 1, flow.
     26#       unirect3d       -- flow
     27#       cloud (2d)      -- contour
     28#       cloud (3d)      -- isosurface
     29#       mesh (3d)       -- isosurface
     30#       mesh (2d)       -- coutour
     31#       dx              -- volume
     32#       ucd             -- isosurface
     33#       vtk (3d)        -- isosurface
     34#       vtk (2d)        -- contour
     35#       
     36# Types:
     37#       Format     Dim  Description                     Viewer          Server
     38#       vtk         2   vtk file data.                  contour         vtkvis
     39#       vtk         3   vtk file data.                  isosurface      vtkvis
     40#       mesh        2   points-on-mesh                  heightmap       vtkvis
     41#       mesh        3   points-on-mesh                  isosurface      vtkvis
     42#       dx          3   DX                              volume          nanovis
     43#       unirect2d   2   unirect3d + extents > 1 flow    flow            nanovis
     44#       unirect3d   3   unirect2d + extents > 1 flow    flow            nanovis
     45#       
    1946
    2047itcl::class Rappture::Field {
    21     constructor {xmlobj path} { # defined below }
    22     destructor { # defined below }
    23 
     48    private variable _dim       0;      # Dimension of mesh
     49    private variable _xmlobj ""  ;      # ref to XML obj with device data
     50    private variable _limits     ;      # maps box name => {z0 z1} limits
     51    private variable _field ""
     52    private variable _fieldNames ""   ; # list of field names.
     53    private variable _fieldUnits ""   ; # list of units of each field name.
     54    private variable _fieldLabels ""  ; # list of labels of each field name.
     55    private variable _viewer            "auto"
     56
     57    constructor {xmlobj path} {
     58        # defined below
     59    }
     60    destructor {
     61        # defined below
     62    }
    2463    public method components {args}
    2564    public method mesh {{cname -overall}}
     
    4079    public method vtkdata {cname}
    4180   
    42     protected method _build {}
     81    protected method Build {}
    4382    protected method _getValue {expr}
    4483
    45     private variable _dim       0;      # Dimension of mesh
    46     private variable _xmlobj ""  ;      # ref to XML obj with device data
    4784    private variable _path "";          # Path of this object in the XML
    4885    private variable _units ""   ;      # system of units for this field
    49     private variable _limits     ;# maps box name => {z0 z1} limits
    5086    private variable _zmax 0     ;# length of the device
    5187
    52     private variable _field ""
    53     private variable _fieldNames ""   ;# list of field names.
    54     private variable _fieldUnits ""   ;# list of units of each field name.
    55     private variable _fieldLabels ""  ;# list of labels of each field name.
    5688    private variable _comp2dims  ;# maps component name => dimensionality
    5789    private variable _comp2xy    ;# maps component name => x,y vectors
    58     private variable _comp2vtk   ;# maps component name => vtkFloatArray
    59     private variable _comp2vtkstreamlines   ;# maps component name => vtkFloatArray
    6090    private variable _comp2isosurface   ;# maps component name => vtkFloatArray
    61     private variable _comp2vtkcontour   ;# maps component name => vtkFloatArray
    62     private variable _comp2vtkvolume   ;# maps component name => vtkFloatArray
     91    private variable _comp2vtk   ;# maps component name => vtk file data
    6392    private variable _comp2volume   ;# maps component name => vtkFloatArray
    6493    private variable _comp2dx    ;# maps component name => OpenDX data
     
    71100    private variable _type ""
    72101    private variable _comp2flowhints
    73     private variable _comp2heightmap
     102    private variable _comp2mesh
    74103    private common _counter 0    ;# counter for unique vector names
    75104
     
    77106    private method ConvertToVtkData { cname }
    78107    private method ReadVtkDataSet { cname contents }
    79     private variable _isVtk
     108    private method AvsToVtk { cname contents }
    80109    private variable _values ""
    81     private variable _viewer "vtkcontour"
    82110}
    83111
     
    122150
    123151    # build up vectors for various components of the field
    124     _build
     152    Build
    125153}
    126154
     
    135163        eval blt::vector destroy $_comp2xy($name)
    136164    }
    137     foreach name [array names _comp2vtk] {
    138         set mobj [lindex $_comp2vtk($name) 0]
    139         set class [$mobj info class]
    140         ${class}::release $mobj
    141 
    142         set fobj [lindex $_comp2vtk($name) 1]
    143         rename $fobj ""
    144     }
    145165    foreach name [array names _comp2unirect2d] {
    146166        itcl::delete object $_comp2unirect2d($name)
     
    152172        itcl::delete object $_comp2flowhints($name)
    153173    }
    154     foreach name [array names _comp2isosurface] {
    155         set mesh [lindex $_comp2isosurface($name) 0]
     174    foreach name [array names _comp2mesh] {
     175        # Data is in the form of a mesh and a vector.
     176        foreach { mesh vector } $_comp2mesh($name) break
     177        # Release the mesh (may be shared)
    156178        set class [$mesh info class]
    157179        ${class}::release $mesh
    158         set vtkarray [lindex $_comp2isosurface($name) 1]
    159         rename $vtkarray ""
    160     }
    161     foreach name [array names _comp2heightmap] {
    162         set mesh [lindex $_comp2heightmap($name) 0]
    163         set class [$mesh info class]
    164         ${class}::release $mesh
    165 
    166         set vtkarray [lindex $_comp2heightmap($name) 1]
    167         rename $vtkarray ""
     180        # Destroy the vector
     181        blt::vector destroy $vector
    168182    }
    169183}
     
    227241        return [lindex $_comp2xy($cname) 0]  ;# return xv
    228242    }
    229     if { [info exists _comp2vtkstreamlines($cname)] } {
    230 puts stderr "comp2vtkstreamlines"
    231         error "mesh: not implemented for streamlines"
    232         return [$mobj mesh]
    233     }
    234     if { [info exists _comp2vtkcontour($cname)] } {
    235 puts stderr "comp2vtkcontour"
    236         error "method \"mesh\" is not implemented for vtkcontour"
    237     }
    238243    if { [info exists _comp2vtk($cname)] } {
    239         set mobj [lindex $_comp2vtk($cname) 0]
    240  puts stderr "comp2vtk mobj=$mobj mesh=[$mobj mesh]"
    241         return [$mobj mesh]
     244        # FIXME: extract mesh from VTK file data.
     245puts stderr "comp2vtk"
     246        error "method \"mesh\" is not implemented for VTK file data"
    242247    }
    243248    if {[info exists _comp2dx($cname)]} {
     
    245250        return ""  ;# no mesh -- it's embedded in the value data
    246251    }
    247     if {[info exists _comp2heightmap($cname)]} {
    248 puts stderr "comp2heightmap"
    249         return ""  ;# no mesh -- it's embedded in the value data
    250     }
    251     if {[info exists _comp2isosurface($cname)]} {
    252 puts stderr "comp2isosurface"
    253         return ""  ;# no mesh -- it's embedded in the value data
    254     }
    255     if {[info exists _comp2vtkvolume($cname)]} {
    256 puts stderr "comp2vtkvolume"
     252    if {[info exists _comp2mesh($cname)]} {
     253puts stderr "comp2mesh"
    257254        return ""  ;# no mesh -- it's embedded in the value data
    258255    }
     
    284281        return [lindex $_comp2xy($cname) 1]  ;# return yv
    285282    }
    286     if { [info exists _comp2vtkcontour($cname)] } {
    287         error "method \"values\" is not implemented for vtkcontour"
    288     }
    289     if { [info exists _comp2heightmap($cname)] } {
    290         return $_values
    291     }
    292     if { [info exists _comp2isosurface($cname)] } {
    293         return $_values
    294     }
    295     if { [info exists _comp2vtkstreamlines($cname)] } {
    296         # FIXME: Need to process the vtk file data to pull out the field's
    297         # values.
    298         error "vtkstreamlines: values not implemented"
    299         return [lindex $_comp2vtkstreamlines($cname) 1]
    300     }
     283    # VTK file data
    301284    if { [info exists _comp2vtk($cname)] } {
    302         return [lindex $_comp2vtk($cname) 1]  ;# return vtkFloatArray
     285        # FIXME: extract the values from the VTK file data
     286        error "method \"values\" is not implemented for vtk file data"
     287    }
     288    # Points-on-mesh
     289    if { [info exists _comp2mesh($cname)] } {
     290        set vector [lindex $_comp2mesh($cname) 1]
     291        return [$vector range 0 end]
    303292    }
    304293    if {[info exists _comp2dx($cname)]} {
     
    327316    }
    328317    if { [info exists _comp2vtk($cname)] } {
    329         return ""
    330     }
    331     if { [info exists _comp2vtkvolume($cname)] } {
    332         return $_comp2vtkvolume($cname)
    333     }
    334     if { [info exists _comp2vtkcontour($cname)] } {
    335         return $_comp2vtkcontour($cname)
    336     }
    337     if { [info exists _comp2vtkstreamlines($cname)] } {
    338         # Return the contents of the vtk file.
    339         return $_comp2vtkstreamlines($cname)
     318        error "blob not implemented for VTK file data"
    340319    }
    341320    if {[info exists _comp2dx($cname)]} {
     
    420399                    foreach {axisMin axisMax} $limits break
    421400                    set axis v
    422                 } elseif {[info exists _comp2vtk($cname)]} {
    423                     foreach {xv yv} $_comp2vtk($cname) break
    424                     switch -- $which {
    425                         x - xlin - xlog {
    426                             foreach {axisMin axisMax} [$xv limits x] break
    427                             set axis x
    428                         }
    429                         y - ylin - ylog {
    430                             foreach {axisMin axisMax} [$xv limits y] break
    431                             set axis y
    432                         }
    433                         z - zlin - zlog {
    434                             foreach {axisMin axisMax} [$xv limits z] break
    435                             set axis z
    436                         }
    437                         v - vlin - vlog {
    438                             catch {unset style}
    439                             array set style $_comp2style($cname)
    440                             if {[info exists style(-min)] &&
    441                                 [info exists style(-max)]} {
    442                                 # This component has its own hard-coded
    443                                 # min/max range.  Ignore it for overall limits.
    444                                 set axisMin $min
    445                                 set axisMax $max
    446                             } else {
    447                                 foreach {axisMin axisMax} [$yv GetRange] break
    448                             }
    449                             set axis v
    450                         }
    451                         default {
    452                             error "bad option \"$which\": should be x, xlin, xlog, y, ylin, ylog, v, vlin, vlog"
    453                         }
    454                     }
    455                 } elseif {[info exists _comp2heightmap($cname)]} {
    456                     foreach {mesh vector} $_comp2heightmap($cname) break
     401                } elseif {[info exists _comp2mesh($cname)]} {
     402                    foreach {mesh vector} $_comp2mesh($cname) break
    457403                    switch -- $which {
    458404                        x - xlin - xlog {
     
    608554            set value [lindex $args 1]
    609555            $_xmlobj put $path.current $value
    610             _build
     556            Build
    611557        }
    612558        default {
     
    680626
    681627# ----------------------------------------------------------------------
    682 # USAGE: _build
     628# USAGE: Build
    683629#
    684630# Used internally to build up the vector representation for the
     
    687633# from scratch.
    688634# ----------------------------------------------------------------------
    689 itcl::body Rappture::Field::_build {} {
     635itcl::body Rappture::Field::Build {} {
    690636
    691637    # Discard any existing data
     
    693639        eval blt::vector destroy $_comp2xy($name)
    694640    }
    695     foreach name [array names _comp2vtk] {
    696         set mobj [lindex $_comp2vtk($name) 0]
    697         set class [$mobj info class]
    698         ${class}::release $mobj
    699 
    700         set fobj [lindex $_comp2vtk($name) 1]
    701         rename $fobj ""
    702     }
     641    array unset _comp2vtk
    703642    foreach name [array names _comp2unirect2d] {
    704643        eval itcl::delete object $_comp2unirect2d($name)
     
    708647    }
    709648    catch {unset _comp2xy}
    710     catch {unset _comp2vtk}
    711649    catch {unset _comp2dx}
    712650    catch {unset _comp2dims}
    713651    catch {unset _comp2style}
    714     array unset _comp2volume
    715     array unset _comp2vtkstreamlines
    716652    array unset _comp2unirect2d
    717653    array unset _comp2unirect3d
     
    725661        set type ""
    726662        if { ([$_field element $cname.constant] != "" &&
    727             [$_field element $cname.domain] != "") ||
    728             [$_field element $cname.xy] != ""} {
     663              [$_field element $cname.domain] != "") ||
     664              [$_field element $cname.xy] != "" } {
    729665            set type "1D"
    730         } elseif {[$_field element $cname.mesh] != "" &&
    731             [$_field element $cname.values] != ""} {
     666        } elseif { [$_field element $cname.mesh] != "" &&
     667                   [$_field element $cname.values] != ""} {
    732668            set type "points-on-mesh"
    733         } elseif {[$_field element $cname.vtk] != ""} {
    734             set _isVtkData($cname) 1
    735             set view [$_field get "about.view"]
    736             switch -- $view {
    737                 "streamlines" {
    738                     set type "vtkstreamlines"
    739                 }
    740                 "contour" - "heightmap" {
    741                     set type "vtkcontour"
    742                 }
    743                 default {
    744                     set type "vtk"
    745                 }
    746             }
     669        } elseif { [$_field element $cname.vtk] != ""} {
     670            set viewer [$_field get "about.view"]
     671            set type "vtk"
     672            if { $viewer != "" } {
     673                set _viewer $viewer
     674            }
    747675        } elseif {[$_field element $cname.opendx] != ""} {
    748676            global env
     
    769697        }
    770698        set _comp2extents($cname) $extents
    771 puts stderr "type=$type"
    772699        set _type $type
    773700        if {$type == "1D"} {
     
    823750            BuildPointsOnMesh $cname
    824751        } elseif {$type == "vtk"} {
    825             #
    826             # Extract native vtk data from the XML and use a reader
    827             # to load it.
    828             #
    829             error "not implemented"
    830         } elseif {$type == "vtkstreamlines"} {
    831             set _comp2dims($cname) "3D"
    832             # Allow redirects to another element.
    833752            set vtkdata [$_field get $cname.vtk]
    834             set _comp2vtkstreamlines($cname) $vtkdata
    835             set _comp2style($cname) [$_field get $cname.style]
    836             incr _counter
    837         } elseif {$type == "vtkcontour"} {
    838             set _comp2dims($cname) "2D"
    839             # Allow redirects to another element.
    840 
    841             set data [$_field get $cname.vtk]
    842             ReadVtkDataSet $cname $data
    843             set _comp2vtkcontour($cname) $data
    844             set _comp2style($cname) [$_field get $cname.style]
    845             incr _counter
    846         } elseif {$type == "vtkvolume"} {
    847             set _comp2dims($cname) "3D"
    848             # Allow redirects to another element.
    849             set data [$_field get -decode no $cname.dx]
    850             set data [Rappture::encoding::decode -as zb64 $data]
    851             if 1 {
    852             set file "/tmp/$cname.dx"
    853             set f [open $file "w"]
    854             puts $f $data
    855             close $f
    856             }
    857             set data [Rappture::ConvertDxToVtk $data]
    858             if 1 {
    859             set file "/tmp/$cname.vtk"
    860             set f [open $file "w"]
    861             puts $f $data
    862             close $f
    863             }
    864             set _comp2vtkvolume($cname) $data
    865             set _comp2style($cname) [$_field get $cname.style]
    866             incr _counter
    867         } elseif {$type == "vtkstreamlines2"} {
    868             set _comp2dims($cname) "3D"
    869             set _comp2vtkstreamlines($cname) [$_field get $cname.vtk]
     753            ReadVtkDataSet $cname $vtkdata
     754            set _comp2vtk($cname) $vtkdata
    870755            set _comp2style($cname) [$_field get $cname.style]
    871756            incr _counter
     
    876761            # off to the NanoVis visualizer.
    877762            #
     763            set _viewer "nanovis"
    878764            set _comp2dims($cname) "3D"
    879765            set _comp2dx($cname)  [$_field get -decode no $cname.dx]
     
    902788            # off to the NanoVis visualizer.
    903789            #
     790            set _viewer "nanovis"
    904791            set _comp2dims($cname) "3D"
    905792            set data [$_field get -decode yes $cname.opendx]
     
    912799                    [Rapture::FlowHints ::\#auto $_field $cname $_units]
    913800            }
     801            incr _counter
     802        } elseif {[$_field element $cname.ucd] != ""} {
     803            set _viewer "isosurface"
     804            set _comp2dims($cname) "3D"
     805            set contents [$_field get $cname.ucd]
     806            set vtkdata [AvsToVtk $cname $contents]
     807            ReadVtkDataSet $cname $vtkdata
     808            set _comp2vtk($cname) $vtkdata
     809            set _comp2style($cname) [$_field get $cname.style]
    914810            incr _counter
    915811        }
     
    1071967            [$ds GetPointData] SetScalars $val
    1072968        }
    1073         "vtkcontour" {
     969        "contour" {
    1074970            return [$dataobj blob $cname]
    1075971        }
     
    1079975        default {
    1080976            set mesh [$dataobj mesh $cname]
    1081 puts stderr "dataobj=$dataobj, mesh=$mesh"
    1082977            switch -- [$mesh GetClassName] {
    1083978                vtkPoints {
     
    11601055        incr _dim
    11611056    }
     1057    if { $_dim == 2 } {
     1058        set _viewer heightmap
     1059    } else {
     1060        set _viewer isosurface
     1061    }
     1062    set _comp2dims($cname) ${_dim}D
    11621063    lappend limits xmin $xmin xmax $xmax ymin $ymin ymax $ymax 
    11631064    set dataAttrs [$dataset GetPointData]
     
    12041105        set cname "component"
    12051106    }
    1206     if { [info exists _comp2vtkstreamlines($cname)] } {
    1207         return $_comp2vtkstreamlines($cname)
    1208     }
    1209     if { [info exists _comp2vtkvolume($cname)] } {
    1210         return $_comp2vtkvolume($cname)
    1211     }
     1107    # DX: Convert DX to VTK
    12121108    if {[info exists _comp2dx($cname)]} {
    1213         return $_comp2dx($cname)
    1214     }
     1109        return [Rappture::ConvertDxToVtk $_comp2dx($cname)]
     1110    }
     1111    # Unirect3d: isosurface
    12151112    if {[info exists _comp2unirect3d($cname)]} {
    1216         return [$_comp2unirect3d($cname) blob]
    1217     }
    1218     if { [info exists _comp2vtkcontour($cname)] && $_dim == 2 } {
    1219         return $_comp2vtkcontour($cname)
    1220     }
     1113        return [$_comp2unirect3d($cname) vtkdata]
     1114    }
     1115    # VTK file data:
    12211116    if { [info exists _comp2vtk($cname)] } {
    12221117        return $_comp2vtk($cname)
    12231118    }
    1224     if { [info exists _comp2heightmap($cname)] } {
     1119    # Points on mesh:  Construct VTK file output.
     1120    if { [info exists _comp2mesh($cname)] } {
     1121        # Data is in the form mesh and vector
     1122        foreach {mesh vector} $_comp2mesh($cname) break
    12251123        set label [hints zlabel]
    12261124        if { $label == "" } {
     
    12291127            regsub -all { } $label {_} label
    12301128        }
    1231         foreach {mesh vector} $_comp2heightmap($cname) break
    12321129        append out "# vtk DataFile Version 3.0\n"
    12331130        append out "[hints label]\n"
     
    12391136        return $out
    12401137    }
    1241     if { [info exists _comp2isosurface($cname)] } {
    1242         set label [hints zlabel]
    1243         if { $label == "" } {
    1244             set label $cname
    1245         } else {
    1246             regsub -all { } $label {_} label
    1247         }
    1248         foreach {mesh vector} $_comp2isosurface($cname) break
    1249         append out "# vtk DataFile Version 3.0\n"
    1250         append out "[hints label]\n"
    1251         append out "ASCII\n"
    1252         append out [$mesh vtkdata]
    1253         append out "SCALARS $label float\n"
    1254         append out "LOOKUP_TABLE default\n"
    1255         append out "[$vector range 0 end]\n"
    1256         return $out
    1257     }
    12581138    error "can't find vtkdata for $cname. This method should only be called by the vtkheightmap widget"
    12591139}
     
    12621142    #
    12631143    # More complex 2D/3D data is represented by a mesh
    1264     # object and an associated vtkFloatArray for field
    1265     # values.
     1144    # object and an associated vector for field values.
    12661145    #
    12671146    set path [$_field get $cname.mesh]
     
    12741153    lappend _fieldLabels $cname
    12751154    lappend _fieldUnits ""
     1155
    12761156    # Handle bizarre cases that hopefully will be deprecated.
    12771157    if { $element == "unirect3d" } {
     
    12821162        }
    12831163        set _dim 3
     1164        set _viewer flowvis
    12841165        set _comp2dims($cname) "3D"
    12851166        set _comp2unirect3d($cname) \
     
    13001181        }
    13011182        set _dim 2
     1183        set _viewer "flowvis"
    13021184        set _comp2dims($cname) "2D"
    13031185        set _comp2unirect2d($cname) \
     
    13101192        return
    13111193    }
     1194    set _viewer "contour"
    13121195    switch -- $element {
    13131196        "cloud" {
     
    13191202        "unirect2d" {
    13201203            set mesh [Rappture::Unirect2d::fetch $_xmlobj $path]
    1321             set _viewer "vtkheightmap"
     1204            set _viewer "heightmap"
    13221205        }
    13231206    }
    13241207    set _dim [$mesh dimensions]
    1325  puts stderr "mesh=$mesh dim=[$mesh dimensions]"
    13261208    if {$_dim == 1} {
    13271209        # Is this used anywhere?
     
    13421224        incr _counter
    13431225        return
     1226    } elseif {$_dim == 2} {
     1227        set _type "heightmap"
     1228        set vector [blt::vector create \#auto]
     1229        $vector set [$_field get $cname.values]
     1230        set _comp2dims($cname) "[$mesh dimensions]D"
     1231        set _comp2mesh($cname) [list $mesh $vector]
     1232        set _comp2style($cname) [$_field get $cname.style]
     1233        incr _counter
     1234        set label [hints zlabel]
     1235        if { $label != "" } {
     1236            set _fieldNames $label
     1237            regsub -all { } $_fieldNames {_} _fieldNames
     1238            set _fieldLabels $label
     1239        }
     1240        set units [hints zunits]
     1241        if { $units != "" } {
     1242            set _fieldUnits $units
     1243        }
     1244        return
    13441245    } elseif {$_dim == 3} {
    13451246        #
     
    13551256            $farray InsertNextValue $v
    13561257        }
    1357         set _viewer "vtkisosurface"
    1358         set _type "vtkisosurface"
     1258        set _viewer "isosurface"
     1259        set _type "isosurface"
    13591260        set vector [blt::vector create \#auto]
    13601261        $vector set [$_field get $cname.values]
    13611262        set _comp2dims($cname) "[$mesh dimensions]D"
    1362         set _comp2isosurface($cname) [list $mesh $vector]
     1263        set _comp2mesh($cname) [list $mesh $vector]
    13631264        set _comp2style($cname) [$_field get $cname.style]
    13641265        incr _counter
     
    13741275        }
    13751276        return
    1376     } elseif {$_dim == 2} {
    1377         set _type "vtkheightmap"
    1378         set vector [blt::vector create \#auto]
    1379         $vector set [$_field get $cname.values]
    1380         set _comp2dims($cname) "[$mesh dimensions]D"
    1381         set _comp2heightmap($cname) [list $mesh $vector]
    1382         set _comp2style($cname) [$_field get $cname.style]
    1383         incr _counter
    1384         set label [hints zlabel]
    1385         if { $label != "" } {
    1386             set _fieldNames $label
    1387             regsub -all { } $_fieldNames {_} _fieldNames
    1388             set _fieldLabels $label
    1389         }
    1390         set units [hints zunits]
    1391         if { $units != "" } {
    1392             set _fieldUnits $units
    1393         }
    1394         return
    13951277    }
    13961278    error "unhandled case in field"
    13971279}
     1280
     1281itcl::body Rappture::Field::AvsToVtk { comp contents } {
     1282    package require vtk
     1283
     1284    set reader $this-datasetreader
     1285    vtkAVSucdReader $reader
     1286
     1287    # Write the contents to a file just in case it's binary.
     1288    set tmpfile file[pid].vtk
     1289    set f [open "$tmpfile" "w"]
     1290    fconfigure $f -translation binary -encoding binary
     1291    puts $f $contents
     1292    close $f
     1293    $reader SetFileName $tmpfile
     1294    $reader Update
     1295    file delete $tmpfile
     1296
     1297    set output [$reader GetOutput]
     1298    set pointData [$output GetPointData]
     1299    set _scalars {}
     1300    for { set i 0 } { $i < [$pointData GetNumberOfArrays] } { incr i } {
     1301        set name [$pointData GetArrayName $i]
     1302        lappend _scalars $name $name "???"
     1303    }
     1304    set writer $this-datasetwriter
     1305    vtkDataSetWriter $writer
     1306    $writer SetInputConnection [$reader GetOutputPort]
     1307    $writer SetFileName $tmpfile
     1308    $writer Write
     1309    rename $reader ""
     1310    rename $writer ""
     1311    set f [open "$tmpfile" "r"]
     1312    fconfigure $f -translation binary -encoding binary
     1313    set vtkdata [read $f]
     1314    file delete $tmpfile
     1315    close $f
     1316    return $vtkdata
     1317}
  • branches/Rappture 1.2/gui/scripts/field2dresult.tcl

    r3216 r3289  
    3131    itk_option define -mode mode Mode "auto"
    3232
    33     constructor {args} { # defined below }
    34     destructor { # defined below }
     33    constructor {args} {
     34        # defined below
     35    }
     36    destructor {
     37        # defined below
     38    }
    3539
    3640    public method add {dataobj {settings ""}}
     
    3943    public method scale {args}
    4044    public method snap {w h}
    41     public method parameters {title args} { # do nothing }
     45    public method parameters {title args} {
     46        # do nothing
     47    }
    4248    public method download {option args}
    4349}
     
    5763    array set flags $args
    5864    set servers ""
     65 puts stderr "field2d mode=$flags(-mode)"
    5966    switch -- $flags(-mode) {
    60         "auto" - "heightmap" - "flowvis" {
     67        "flowvis" {
    6168            set servers [Rappture::VisViewer::GetServerList "nanovis"]
    6269        }
    63         "vtkcontour" - "vtkheightmap" - "vtkstreamlines" - "vtkviewer" {
     70        "auto" - "contour" - "heightmap" - "streamlines" - "vtkviewer" {
    6471            set servers [Rappture::VisViewer::GetServerList "vtkvis"]
    6572        }
     
    7380    if {"" != $servers && $flags(-mode) != "vtk"} {
    7481        switch -- $flags(-mode) {
    75             "auto" - "heightmap" {
     82            "heightmap" {
    7683                itk_component add renderer {
    77                     Rappture::HeightmapViewer $itk_interior.ren $servers
     84                    Rappture::VtkHeightmapViewer $itk_interior.heightmap \
     85                        $servers -mode heightmap
    7886                }
    7987            }
    8088            "flowvis" {
    8189                itk_component add renderer {
    82                     Rappture::FlowvisViewer $itk_interior.ren $servers
     90                    Rappture::FlowvisViewer $itk_interior.flow $servers
    8391                }
    8492            }
    85             "vtkcontour" {
     93            "contour" {
    8694                itk_component add renderer {
    87                     Rappture::VtkHeightmapViewer $itk_interior.ren $servers \
    88                         -mode $flags(-mode)
     95                    Rappture::VtkHeightmapViewer $itk_interior.contour \
     96                        $servers -mode contour
    8997                }
    9098            }
    91             "vtkheightmap" {
     99            "streamlines" {
    92100                itk_component add renderer {
    93                     Rappture::VtkHeightmapViewer $itk_interior.ren $servers \
    94                         -mode $flags(-mode)
    95                 }
    96             }
    97             "vtkstreamlines" {
    98                 itk_component add renderer {
    99                     Rappture::VtkStreamlinesViewer $itk_interior.ren $servers
     101                    Rappture::VtkStreamlinesViewer $itk_interior.streamlines \
     102                        $servers
    100103                }
    101104            }
    102105            "vtkviewer" {
    103106                itk_component add renderer {
    104                     Rappture::VtkViewer $itk_interior.ren $servers
     107                    Rappture::VtkViewer $itk_interior.viewer $servers
    105108                }
    106109            }
     
    115118        }
    116119    }
    117 
    118120    if {![info exists itk_component(renderer)]} {
    119121        itk_component add renderer {
    120             Rappture::ContourResult $itk_interior.ren
     122            Rappture::ContourResult $itk_interior.oldcontour
    121123        }
    122124        pack $itk_component(renderer) -expand yes -fill both
    123125    }
    124126    eval itk_initialize $args
     127    update
    125128}
    126129
  • branches/Rappture 1.2/gui/scripts/field3dresult.tcl

    r3288 r3289  
    5454        -mode auto
    5555    }
    56     array set flags $args
    57     switch -- $flags(-mode) {
     56    array set flags $args
     57 puts stderr "field3d mode=$flags(-mode)"
     58   switch -- $flags(-mode) {
    5859        "auto" - "nanovis" - "flowvis" {
    5960            set servers [Rappture::VisViewer::GetServerList "nanovis"]
    6061        }
    61         "vtkisosurface" - "vtkheightmap" - "vtkstreamlines" - "vtkviewer" - "vtkvolume" {
     62        "isosurface" - "heightmap" - "streamlines" - "vtkviewer" - "vtkvolume" {
    6263            set servers [Rappture::VisViewer::GetServerList "vtkvis"]
    6364        }
     
    7071        }
    7172    }
     73    puts stderr "field3d: servers=$servers flags(-mode)=$flags(-mode)"
    7274    if {"" != $servers && $flags(-mode) != "vtk"} {
    7375        switch -- $flags(-mode) {
     
    8284                }
    8385            }
    84             "vtkcontour" - "vtkheightmap" {
     86            "contour" - "heightmap" {
    8587                itk_component add renderer {
    8688                    Rappture::VtkHeightmapViewer $itk_interior.ren $servers
    8789                }
    8890            }
    89             "vtkisosurface" {
     91            "isosurface" {
    9092                itk_component add renderer {
    9193                    Rappture::VtkIsosurfaceViewer $itk_interior.ren $servers
    9294                }
    9395            }
    94             "vtkstreamlines" {
     96            "streamlines" {
    9597                itk_component add renderer {
    9698                    Rappture::VtkStreamlinesViewer $itk_interior.ren $servers
  • branches/Rappture 1.2/gui/scripts/mesh.tcl

    r3288 r3289  
    180180    foreach cname [$_mesh children] {
    181181        foreach type { vtk cloud grid triangles cells } {
    182             if { [$_mesh element $type] != "" } {
     182            if { $cname == $type } {
    183183                incr subcount
    184184                break
     
    189189    foreach cname [$_mesh children] {
    190190        foreach type { node element } {
    191             if { [$_mesh element $type] != "" } {
     191            if { $cname == $type } {
    192192                incr elemcount
    193193                break
     
    10821082    set type "nodeselements"
    10831083    # create the vtk objects containing points and connectivity
    1084     set _dim 2
    1085     #
    1086     # Extract each node and add it to the points list.
    1087     #
     1084    set _dim 3
    10881085    set points {}
    10891086    set count 0
     1087    # Scan for nodes.  Each node represents a vertex.
    10901088    foreach comp [$xmlobj children -type node $path] {
    10911089        set xyz [$xmlobj get $path.$comp]
     
    10991097        foreach {x y z} $xyz break
    11001098        foreach dim {x y z} units $_units {
    1101             set v [Rappture::Units::convert [set $dim] \
     1099         set v [Rappture::Units::convert [set $dim] \
    11021100                -context $units -to $units -units off]
    11031101
     
    11271125    }
    11281126    set count 0
     1127    set numCells 0
    11291128    set celltypes {}
    11301129    set data {}
     1130    # Next scan for elements.  Each element represents a cell.
    11311131    foreach comp [$xmlobj children -type element $path] {
    11321132        set nlist [$_mesh get $comp.nodes]
     
    11381138        append celltypes "  $celltype\n"
    11391139        append data "  $numNodes $nlist\n"
     1140        incr numCells
     1141        incr count $numNodes
    11401142        incr count
    11411143    }
     
    11431145    append out "POINTS $_numPoints float\n"
    11441146    append out $points
    1145     append out "CELLS $count [expr $count * 4]\n"
     1147    append out "CELLS $numCells $count\n"
    11461148    append out $data
    1147     append out "CELL_TYPES $count\n"
     1149    append out "CELL_TYPES $numCells\n"
    11481150    append out $celltypes
    11491151    append out "\n"
    11501152    append out "POINT_DATA $_numPoints\n"
    1151     foreach axis {x y} {
     1153    foreach axis {x y z} {
    11521154        if { [info exists ${axis}Min] } {
    11531155            set _limits(${axis}min) [set ${axis}Min]
  • branches/Rappture 1.2/gui/scripts/resultviewer.tcl

    r3288 r3289  
    284284        ::Rappture::Field {
    285285            set dims [lindex [lsort [$dataobj components -dimensions]] end]
     286            puts stderr "dims=$dims dataobj=$dataobj"
    286287            switch -- $dims {
    287288                1D {
     
    296297                    set mode "heightmap"
    297298                    if {![info exists _mode2widget($mode)]} {
    298                         set resultMode [$dataobj viewer]
     299                        set viewer [$dataobj viewer]
    299300                        set extents [$dataobj extents]
    300301                        if { $extents > 1 } {
    301                             set resultMode "flowvis"
     302                            set viewer "flowvis"
    302303                        }
    303                         set w $itk_interior.heightmap
     304                        set w $itk_interior.field2d
    304305                        if { ![winfo exists $w] } {
    305                             Rappture::Field2DResult $w -mode $resultMode
    306                         }
    307                         set _mode2widget($mode) $w
     306                            Rappture::Field2DResult $w -mode $viewer
     307                        }
     308                        set _mode2widget($mode) $w
    308309                    }
    309310                }
     
    311312                    set mode "field3D"
    312313                    if {![info exists _mode2widget($mode)]} {
    313                         switch -- [$dataobj type] {
    314                             "vtk" {
    315                                 set fmt "vtk"
    316                             }
    317                             "points-on-mesh" {
    318                                 set mesh [$dataobj mesh]
    319                                 set fmt [expr {("" != $mesh) ? "vtk" : "nanovis"}]
    320                                 set extents [$dataobj extents]
    321                                 if { $extents > 1 } {
    322                                     set fmt "flowvis"
    323                                 }
    324                             }
    325                             "opendx" - "dx" {
    326                                 set fmt "nanovis"
    327                                 set extents [$dataobj extents]
    328                                 if { $extents > 1 } {
    329                                     set fmt "flowvis"
    330                                 }
    331                             }
    332                             "vtkvolume" {
    333                                 set fmt "vtkvolume"
    334                             }
    335                             "vtkstreamlines" {
    336                                 set fmt "vtkstreamlines"
    337                             }
    338                             "vtkisosurface" {
    339                                 set fmt "vtkisosurface"
    340                             }
    341                         }
    342                         set w $itk_interior.field3D
     314                        set fmt [$dataobj viewer]
     315                        set w $itk_interior.field3d
    343316                        Rappture::Field3DResult $w -mode $fmt
    344317                        set _mode2widget($mode) $w
  • branches/Rappture 1.2/gui/scripts/vtkheightmapviewer.tcl

    r3274 r3289  
    3737    itk_option define -plotforeground plotForeground Foreground ""
    3838    itk_option define -plotbackground plotBackground Background ""
    39     itk_option define -mode mode Mode "vtkcontour"
     39    itk_option define -mode mode Mode "contour"
    4040
    4141    constructor { hostlist args } {
     
    214214
    215215    array set _settings [subst {
    216         debug-console           0
    217         axis-labels             1
     216        axisLabels              1
    218217        axis-visible            1
    219218        axis-xgrid              0
     
    225224        axis-minticks           1
    226225        axis-flymode            "static"
    227         contour-edges           0
    228         contour-field           "Default"
    229         contour-isolines        10
    230         heightmap-lighting      1
    231         heightmap-outline       0
     226        edges                   0
     227        field                   "Default"
     228        isolines                10
     229        lighting                1
     230        outline                 0
    232231        contour-opacity         100
    233232        colormap-visible         1
    234233        isolines-visible         1
    235         contour-wireframe       0
    236         heightmap-mode          0
     234        wireframe               0
     235        isHeightmap             0
    237236        heightmap-scale         50
    238         legend-visible          1
    239         stretch-to-fit          0
     237        legendVisible           1
     238        stretchToFit            0
    240239        x-scale                 1.0
    241240        y-scale                 1.0
     
    320319            -onimage [Rappture::icon surface] \
    321320            -offimage [Rappture::icon surface] \
    322             -variable [itcl::scope _settings(heightmap-mode)] \
    323             -command [itcl::code $this AdjustSetting heightmap-mode] \
     321            -variable [itcl::scope _settings(isHeightmap)] \
     322            -command [itcl::code $this AdjustSetting isHeightmap] \
    324323    }
    325324    Rappture::Tooltip::for $itk_component(mode) \
     
    915914        $_arcball resize $w $h
    916915        DoResize
    917         if { $_settings(stretch-to-fit) } {
    918             Adjustsetting stretch-to-fit
     916        if { $_settings(stretchToFit) } {
     917            Adjustsetting stretchToFit
    919918        }
    920919    }
    921920    if { $_reset } {
    922         InitSettings heightmap-mode background
     921        InitSettings isHeightmap background
    923922        #
    924923        # Reset the camera and other view parameters
     
    928927        set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    929928        $_arcball quaternion $q
    930         if {$_settings(heightmap-mode) } {
    931             SendCmd "camera reset all"
     929        if {$_settings(isHeightmap) } {
     930            SendCmd "camera reset"
    932931            if { $_view(ortho)} {
    933932                SendCmd "camera mode ortho"
     
    10221021        $itk_component(field) value $_currentFieldName
    10231022    }
    1024     InitSettings stretch-to-fit
     1023    InitSettings stretchToFit
    10251024
    10261025    if { $_reset } {
     
    10581057        set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    10591058        $_arcball quaternion $q
    1060         if {$_settings(heightmap-mode) } {
    1061             SendCmd "camera reset all"
     1059        if {$_settings(isHeightmap) } {
     1060            SendCmd "camera reset"
    10621061            if { $_view(ortho)} {
    10631062                SendCmd "camera mode ortho"
     
    10691068        PanCamera
    10701069        InitSettings axis-xgrid axis-ygrid axis-zgrid \
    1071             axis-visible axis-labels
     1070            axis-visible axisLabels
    10721071        InitSettings contour-opacity \
    1073             heightmap-scale heightmap-lighting \
    1074             contour-colormap contour-field heightmap-outline \
    1075             contour-edges contour-opacity contour-wireframe
     1072            heightmap-scale lighting \
     1073            colormap field outline \
     1074            edges contour-opacity wireframe
    10761075        set _reset 0
    10771076    }
     
    13281327            }
    13291328        }
    1330         "contour-wireframe" {
    1331             set bool $_settings(contour-wireframe)
     1329        "wireframe" {
     1330            set bool $_settings(wireframe)
    13321331            foreach dataset [CurrentDatasets -all] {
    13331332                SendCmd "heightmap wireframe $bool $dataset"
     
    13461345            }
    13471346        }
    1348         "heightmap-lighting" {
    1349             if { $_settings(heightmap-mode) } {
    1350                 set bool $_settings(heightmap-lighting)
     1347        "lighting" {
     1348            if { $_settings(isHeightmap) } {
     1349                set bool $_settings(lighting)
    13511350                SendCmd "heightmap lighting $bool"
    13521351            } else {
     
    13541353            }
    13551354        }
    1356         "contour-edges" {
    1357             set bool $_settings(contour-edges)
     1355        "edges" {
     1356            set bool $_settings(edges)
    13581357            foreach dataset [CurrentDatasets -all] {
    13591358                SendCmd "heightmap edges $bool $dataset"
     
    13641363            SendCmd "axis visible all $bool"
    13651364        }
    1366         "axis-labels" {
    1367             set bool $_settings(axis-labels)
     1365        "axisLabels" {
     1366            set bool $_settings(axisLabels)
    13681367            SendCmd "axis labels all $bool"
    13691368        }
     
    13851384            }
    13861385        }
    1387         "contour-isolines" {
     1386        "isolines" {
    13881387            set n $_settings($what)
    13891388            EventuallyContour $n
     
    14291428            DrawLegend $_currentFieldName
    14301429        }
    1431         "contour-colormap" {
     1430        "colormap" {
    14321431            set color [$itk_component(colormap) value]
    1433             set _settings(contour-colormap) $color
     1432            set _settings(colormap) $color
    14341433            if { $color == "none" } {
    14351434                if { $_settings(colormap-visible) } {
     
    14551454        }
    14561455        "heightmap-scale" {
    1457             if { $_settings(heightmap-mode) } {
     1456            if { $_settings(isHeightmap) } {
    14581457                set scale [GetHeightmapScale]
    14591458                foreach dataset [CurrentDatasets -all] {
     
    14641463            }
    14651464        }
    1466         "heightmap-lighting" {
    1467             if { $_settings(heightmap-mode) } {
    1468                 set bool $_settings(heightmap-lighting)
     1465        "lighting" {
     1466            if { $_settings(isHeightmap) } {
     1467                set bool $_settings(lighting)
    14691468                SendCmd "heightmap lighting $bool"
    14701469            } else {
     
    14721471            }
    14731472        }
    1474         "contour-field" {
    1475             set new [$itk_component(field) value]
     1473        "field" {
     1474            set new   [$itk_component(field) value]
    14761475            set value [$itk_component(field) translate $new]
    1477             set _settings(contour-field) $value
     1476            set _settings(field) $value
    14781477            if { [info exists _fields($new)] } {
    14791478                set _colorMode scalar
     
    14851484            EventuallyRequestLegend
    14861485        }
    1487         "stretch-to-fit" {
    1488             set bool $_settings(stretch-to-fit)
     1486        "stretchToFit" {
     1487            set bool $_settings(stretchToFit)
    14891488            set _settings(x-scale) 1.0
    14901489            set _settings(y-scale) 1.0
     
    15131512            }
    15141513        }
    1515         "heightmap-outline" {
    1516             set bool $_settings(heightmap-outline)
     1514        "outline" {
     1515            set bool $_settings(outline)
    15171516            SendCmd "dataset outline $bool"
    15181517        }
    1519         "heightmap-mode" {
    1520             set bool $_settings(heightmap-mode)
     1518        "isHeightmap" {
     1519            set bool $_settings(isHeightmap)
    15211520            if { $bool } {
    15221521                $itk_component(lighting) configure -state normal
     
    15251524            }
    15261525            if {[isconnected]} {
    1527                 set _settings(heightmap-lighting) $bool
     1526                set _settings(lighting) $bool
    15281527                # Fix heightmap scale: 0 for contours, 1 for heightmaps.
    15291528                if { $bool } {
     
    15381537                    set _comp2scale($dataset) $scale
    15391538                }
    1540                 if {$_settings(stretch-to-fit)} {
     1539                if {$_settings(stretchToFit)} {
    15411540                    if {$scale == 0} {
    15421541                        SendCmd "camera aspect window"
     
    15741573            }
    15751574        }       
    1576         "legend-visible" {
    1577             if { !$_settings(legend-visible) } {
     1575        "legendVisible" {
     1576            if { !$_settings(legendVisible) } {
    15781577                $itk_component(view) delete legend
    15791578            }
     
    19081907itcl::configbody Rappture::VtkHeightmapViewer::mode {
    19091908    switch -- $itk_option(-mode) {
    1910         "vtkheightmap" {
    1911             set _settings(heightmap-mode) 1
     1909        "heightmap" {
     1910            set _settings(isHeightmap) 1
    19121911        }
    1913         "vtkcontour" {
    1914             set _settings(heightmap-mode) 0
     1912        "contour" {
     1913            set _settings(isHeightmap) 0
    19151914        }
    19161915        default {
     
    19181917        }
    19191918    }
    1920     AdjustSetting heightmap-mode
     1919    AdjustSetting isHeightmap
    19211920}
    19221921
     
    19591958    checkbutton $inner.legend \
    19601959        -text "Legend" \
    1961         -variable [itcl::scope _settings(legend-visible)] \
    1962         -command [itcl::code $this AdjustSetting legend-visible] \
     1960        -variable [itcl::scope _settings(legendVisible)] \
     1961        -command [itcl::code $this AdjustSetting legendVisible] \
    19631962        -font "Arial 9"
    19641963
    19651964    checkbutton $inner.wireframe \
    19661965        -text "Wireframe" \
    1967         -variable [itcl::scope _settings(contour-wireframe)] \
    1968         -command [itcl::code $this AdjustSetting contour-wireframe] \
     1966        -variable [itcl::scope _settings(wireframe)] \
     1967        -command [itcl::code $this AdjustSetting wireframe] \
    19691968        -font "Arial 9"
    19701969
     
    19721971        checkbutton $inner.lighting \
    19731972            -text "Enable Lighting" \
    1974             -variable [itcl::scope _settings(heightmap-lighting)] \
    1975             -command [itcl::code $this AdjustSetting heightmap-lighting] \
     1973            -variable [itcl::scope _settings(lighting)] \
     1974            -command [itcl::code $this AdjustSetting lighting] \
    19761975            -font "Arial 9"
     1976    } {
     1977        ignore -font
    19771978    }
    19781979
    19791980    checkbutton $inner.edges \
    19801981        -text "Edges" \
    1981         -variable [itcl::scope _settings(contour-edges)] \
    1982         -command [itcl::code $this AdjustSetting contour-edges] \
     1982        -variable [itcl::scope _settings(edges)] \
     1983        -command [itcl::code $this AdjustSetting edges] \
    19831984        -font "Arial 9"
    19841985
    19851986    checkbutton $inner.outline \
    19861987        -text "Outline" \
    1987         -variable [itcl::scope _settings(heightmap-outline)] \
    1988         -command [itcl::code $this AdjustSetting heightmap-outline] \
     1988        -variable [itcl::scope _settings(outline)] \
     1989        -command [itcl::code $this AdjustSetting outline] \
    19891990        -font "Arial 9"
    19901991
    19911992    checkbutton $inner.stretch \
    19921993        -text "Stretch to fit" \
    1993         -variable [itcl::scope _settings(stretch-to-fit)] \
    1994         -command [itcl::code $this AdjustSetting stretch-to-fit] \
     1994        -variable [itcl::scope _settings(stretchToFit)] \
     1995        -command [itcl::code $this AdjustSetting stretchToFit] \
    19951996        -font "Arial 9"
    19961997
     
    20002001    }
    20012002    bind $inner.field <<Value>> \
    2002         [itcl::code $this AdjustSetting contour-field]
     2003        [itcl::code $this AdjustSetting field]
    20032004
    20042005    label $inner.colormap_l -text "Colormap" -font "Arial 9"
     
    20272028    $itk_component(colormap) value "BCGYR"
    20282029    bind $inner.colormap <<Value>> \
    2029         [itcl::code $this AdjustSetting contour-colormap]
     2030        [itcl::code $this AdjustSetting colormap]
    20302031
    20312032    label $inner.isolinecolor_l -text "Isolines" -font "Arial 9"
     
    21202121    checkbutton $inner.labels \
    21212122        -text "Axis Labels" \
    2122         -variable [itcl::scope _settings(axis-labels)] \
    2123         -command [itcl::code $this AdjustSetting axis-labels] \
     2123        -variable [itcl::scope _settings(axisLabels)] \
     2124        -command [itcl::code $this AdjustSetting axisLabels] \
    21242125        -font "Arial 9"
    21252126    label $inner.grid_l -text "Grid" -font "Arial 9"
     
    22802281    radiobutton $inner.vtk_button -text "VTK data file" \
    22812282        -variable [itcl::scope _downloadPopup(format)] \
    2282         -font "Helvetica 9 " \
     2283        -font "Arial 9 " \
    22832284        -value vtk 
    22842285    Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file."
    22852286    radiobutton $inner.image_button -text "Image File" \
    22862287        -variable [itcl::scope _downloadPopup(format)] \
     2288        -font "Arial 9 " \
    22872289        -value image
    22882290    Rappture::Tooltip::for $inner.image_button \
     
    23392341    SendCmd "heightmap add numcontours $_numContours $scale $tag"
    23402342    set _comp2scale($tag) $_settings(heightmap-scale)
    2341     SendCmd "heightmap edges $_settings(contour-edges) $tag"
    2342     SendCmd "heightmap wireframe $_settings(contour-wireframe) $tag"
     2343    SendCmd "heightmap edges $_settings(edges) $tag"
     2344    SendCmd "heightmap wireframe $_settings(wireframe) $tag"
    23432345    SendCmd "heightmap colormap $_currentColormap $tag"
    23442346}
     
    24022404    }
    24032405    set x [expr $w - 2]
    2404     if { !$_settings(legend-visible) } {
     2406    if { !$_settings(legendVisible) } {
    24052407        $c delete legend
    24062408        return
     
    26362638        invoke {
    26372639            $itk_component(field) value $_currentFieldName
    2638             AdjustSetting contour-field
     2640            AdjustSetting field
    26392641        }
    26402642        default {
     
    26452647
    26462648itcl::body Rappture::VtkHeightmapViewer::GetHeightmapScale {} {
    2647     if {  $_settings(heightmap-mode) } {
     2649    if {  $_settings(isHeightmap) } {
    26482650        set val $_settings(heightmap-scale)
    26492651        set sval [expr { $val >= 50 ? double($val)/50.0 : 1.0/(2.0-(double($val)/50.0)) }]
  • branches/Rappture 1.2/gui/scripts/vtkisosurfaceviewer.tcl

    r3288 r3289  
    11
    22# ----------------------------------------------------------------------
    3 #  COMPONENT: vtkcontour3dviewer - Vtk 3D contour object viewer
     3#  COMPONENT: vtkisolinesviewer - Vtk 3D contour object viewer
    44#
    55#  It connects to the Vtk server running on a rendering farm,
     
    6868    protected method Disconnect {}
    6969    protected method DoResize {}
    70     protected method DoReseed {}
    7170    protected method DoRotate {}
    7271    protected method AdjustSetting {what {value ""}}
     
    8079    protected method Rotate {option x y}
    8180    protected method SendCmd {string}
    82     protected method SendCmdNoSplash {string}
     81    protected method SendCmdNoWait {string}
    8382    protected method Zoom {option}
    8483
     
    8988    private method BuildCutplaneTab {}
    9089    private method BuildDownloadPopup { widget command }
    91     private method BuildVolumeTab {}
    92     private method ConvertToVtkData { dataobj comp }
     90    private method BuildIsosurfaceTab {}
    9391    private method DrawLegend { title }
    9492    private method Combo { option }
    9593    private method EnterLegend { x y }
    9694    private method EventuallyResize { w h }
    97     private method EventuallyReseed { numPoints }
    9895    private method EventuallyRotate { q }
     96    private method EventuallyRequestLegend {}
    9997    private method EventuallySetCutplane { axis args }
    10098    private method GetImage { args }
     
    105103    private method PanCamera {}
    106104    private method RequestLegend {}
    107     private method SetColormap { dataobj comp }
    108     private method ChangeColormap { dataobj comp color }
    109105    private method ColorsToColormap { color }
    110106    private method SetLegendTip { x y }
    111107    private method SetObjectStyle { dataobj comp }
    112108    private method Slice {option args}
     109    private method ResetColormap { color }
     110    private method EnterIsoline { x y value }
     111    private method LeaveIsoline {}
     112    private method SetIsolineTip { x y value }
     113    private method SetCurrentColormap { stylelist }
    113114
    114115    private variable _arcball ""
     
    122123    private variable _colormaps    ;    # contains all the colormaps
    123124                                   ;    # in the server.
     125    # The name of the current colormap used.  The colormap is global to all
     126    # heightmaps displayed.
     127    private variable _currentColormap "" ;   
     128
     129
    124130    private variable _dataset2style    ;# maps dataobj-component to transfunc
    125131
     
    143149    private variable _height 0
    144150    private variable _resizePending 0
    145     private variable _reseedPending 0
    146151    private variable _rotatePending 0
    147152    private variable _cutplanePending 0
    148153    private variable _legendPending 0
    149     private variable _vectorFields
    150     private variable _scalarFields
     154    private variable _field      ""
     155    private variable _colorMode "vmag"; #  Mode of colormap (vmag or scalar)
     156    private variable _currentField ""
     157    private variable _fieldNames {}
    151158    private variable _fields
    152     private variable _currentField ""
    153     private variable _field      ""
    154     private variable _colorMode "vmag";#  Mode of colormap (vmag or scalar)
     159    private variable _currentFieldName "Default"
     160    private variable _numContours 10
    155161}
    156162
     
    175181    $_dispatcher dispatch $this !resize "[itcl::code $this DoResize]; list"
    176182
    177     # Reseed event
    178     $_dispatcher register !reseed
    179     $_dispatcher dispatch $this !reseed "[itcl::code $this DoReseed]; list"
    180 
    181183    # Rotate event
    182184    $_dispatcher register !rotate
     
    190192    $_dispatcher register !xcutplane
    191193    $_dispatcher dispatch $this !xcutplane \
    192         "[itcl::code $this AdjustSetting cutplane-xposition]; list"
     194        "[itcl::code $this AdjustSetting cutplaneXPosition]; list"
    193195
    194196    # Y-Cutplane event
    195197    $_dispatcher register !ycutplane
    196198    $_dispatcher dispatch $this !ycutplane \
    197         "[itcl::code $this AdjustSetting cutplane-yposition]; list"
     199        "[itcl::code $this AdjustSetting cutplaneYPosition]; list"
    198200
    199201    # Z-Cutplane event
    200202    $_dispatcher register !zcutplane
    201203    $_dispatcher dispatch $this !zcutplane \
    202         "[itcl::code $this AdjustSetting cutplane-zposition]; list"
     204        "[itcl::code $this AdjustSetting cutplaneZPosition]; list"
    203205
    204206    #
     
    211213    # Initialize the view to some default parameters.
    212214    array set _view {
    213         qw              1
    214         qx              0
    215         qy              0
    216         qz              0
     215        qw      0.36
     216        qx      0.25
     217        qy      0.50
     218        qz      0.70
    217219        zoom            1.0
    218220        xpan            0
     
    224226    $_arcball quaternion $q
    225227
    226     set _limits(zmin) 0.0
    227     set _limits(zmax) 1.0
    228 
    229228    array set _settings [subst {
    230         axis-labels             1
    231         axis-visible            1
     229        axisLabelsVisible             1
     230        axesVisible            1
    232231        axis-xcutplane          0
    233232        axis-xgrid              0
     
    239238        axis-zgrid              0
    240239        axis-zposition          0
    241         contour-edges           0
    242         contour-outline         0
    243         contour-lighting        1
    244         contour-opacity         100
    245         contour-visible         1
    246         contour-wireframe       0
    247         cutplane-edges          0
    248         cutplane-lighting       1
    249         cutplane-opacity        100
    250         cutplane-visible        1
    251         cutplane-wireframe      0
    252         cutplane-xposition      50
    253         cutplane-xvisible       0
    254         cutplane-yposition      50
    255         cutplane-yvisible       0
    256         cutplane-zposition      50
    257         cutplane-zvisible       0
    258         legend-visible          1
     240        colormapVisible         1
     241        colormapPalette         BCGYR
     242        isosurfaceEdges         0
     243        isosurfaceOutline       0
     244        isosurfaceLighting      1
     245        isosurfaceOpacity       100
     246        isosurfaceVisible       1
     247        isosurfaceWireframe     0
     248        cutplaneEdges           0
     249        cutplaneLighting        1
     250        cutplaneOpacity        100
     251        cutplaneVisible        1
     252        cutplaneWireframe      0
     253        cutplaneXPosition      50
     254        cutplaneXVisible       0
     255        cutplaneYPosition      50
     256        cutplaneYVisible       0
     257        cutplaneZPosition      50
     258        cutplaneZVisible       0
     259        legendVisible          1
     260        isolineColor           white
     261        background             black
     262        field                  "Default"
    259263    }]
    260264
     
    283287    bind $c <KeyPress-Down>  [list %W yview scroll -10 units]
    284288    bind $c <Enter> "focus %W"
     289    bind $c <Control-F1> [itcl::code $this ToggleConsole]
    285290
    286291    # Fix the scrollregion in case we go off screen
     
    334339            -onimage [Rappture::icon volume-on] \
    335340            -offimage [Rappture::icon volume-off] \
    336             -variable [itcl::scope _settings(contour-visible)] \
    337             -command [itcl::code $this AdjustSetting contour-visible]
     341            -variable [itcl::scope _settings(isosurfaceVisible)] \
     342            -command [itcl::code $this AdjustSetting isosurfaceVisible]
    338343    }
    339344    $itk_component(contour) select
     
    346351            -onimage [Rappture::icon cutbutton] \
    347352            -offimage [Rappture::icon cutbutton] \
    348             -variable [itcl::scope _settings(cutplane-visible)] \
    349             -command [itcl::code $this AdjustSetting cutplane-visible]
     353            -variable [itcl::scope _settings(cutplaneVisible)] \
     354            -command [itcl::code $this AdjustSetting cutplaneVisible]
    350355    }
    351356    $itk_component(cutplane) select
     
    356361
    357362    if { [catch {
    358         BuildVolumeTab
     363        BuildIsosurfaceTab
    359364        BuildCutplaneTab
    360365        BuildAxisTab
     
    466471    set _start [clock clicks -milliseconds]
    467472    SendCmd "screen size $_width $_height"
    468     set _legendPending 1
    469473
    470474    #SendCmd "imgflush"
     
    473477    #SendCmd "camera reset"
    474478    #SendCmd "camera zoom $_view(zoom)"
     479    EventuallyRequestLegend
    475480    set _resizePending 0
    476481}
     
    480485    SendCmd "camera orient $q"
    481486    set _rotatePending 0
     487}
     488
     489itcl::body Rappture::VtkIsosurfaceViewer::EventuallyRequestLegend {} {
     490    if { !$_legendPending } {
     491        set _legendPending 1
     492        $_dispatcher event -idle !legend
     493    }
    482494}
    483495
     
    489501        set _resizePending 1
    490502        $_dispatcher event -after 400 !resize
    491     }
    492 }
    493 
    494 itcl::body Rappture::VtkIsosurfaceViewer::EventuallyReseed { numPoints } {
    495     set _numSeeds $numPoints
    496     if { !$_reseedPending } {
    497         set _reseedPending 1
    498         $_dispatcher event -after 600 !reseed
    499503    }
    500504}
     
    674678# the user scans through data in the ResultSet viewer.
    675679# ----------------------------------------------------------------------
    676 itcl::body Rappture::VtkIsosurfaceViewer::scale {args} {
     680itcl::body Rappture::VtkIsosurfaceViewer::scale { args } {
    677681    array unset _limits
    678682    foreach dataobj $args {
     
    681685            continue
    682686        }
    683         array set bounds $string
    684         if {![info exists _limits(xmin)] || $_limits(xmin) > $bounds(xmin)} {
    685             set _limits(xmin) $bounds(xmin)
    686         }
    687         if {![info exists _limits(xmax)] || $_limits(xmax) < $bounds(xmax)} {
    688             set _limits(xmax) $bounds(xmax)
    689         }
    690 
    691         if {![info exists _limits(ymin)] || $_limits(ymin) > $bounds(ymin)} {
    692             set _limits(ymin) $bounds(ymin)
    693         }
    694         if {![info exists _limits(ymax)] || $_limits(ymax) < $bounds(ymax)} {
    695             set _limits(ymax) $bounds(ymax)
    696         }
    697 
    698         if {![info exists _limits(zmin)] || $_limits(zmin) > $bounds(zmin)} {
    699             set _limits(zmin) $bounds(zmin)
    700         }
    701         if {![info exists _limits(zmax)] || $_limits(zmax) < $bounds(zmax)} {
    702             set _limits(zmax) $bounds(zmax)
    703         }
     687        array set lim $string
     688        foreach axis { x y z v } {
     689            set min ${axis}min
     690            set max ${axis}max
     691            if {![info exists _limits($min)] || $_limits($min) > $lim($min)} {
     692                set _limits($min) $lim($min)
     693            }
     694            if {![info exists _limits($max)] || $_limits($max) < $lim($max)} {
     695                set _limits($max) $lim($max)
     696            }
     697        }
    704698    }
    705699}
     
    719713        coming {
    720714            if {[catch {
    721                 $_image(download) snap $itk_component(plotarea)
    722             } errs ]} {
    723                 puts stderr "errs=$errs"
     715                blt::winop snap $itk_component(plotarea) $_image(download)
     716            }]} {
    724717                $_image(download) configure -width 1 -height 1
    725718                $_image(download) put #000000
     
    811804    $_dispatcher cancel !rebuild
    812805    $_dispatcher cancel !resize
    813     $_dispatcher cancel !reseed
    814806    $_dispatcher cancel !rotate
    815807    $_dispatcher cancel !xcutplane
     
    852844
    853845#
    854 # SendCmdNoSplash
    855 #
    856 #       Send commands off to the rendering server.  This method
    857 #       doesn't initiate the slash screen.
    858 #
    859 itcl::body Rappture::VtkIsosurfaceViewer::SendCmdNoSplash {string} {
     846# SendCmdNoWait
     847#
     848#       Send commands off to the rendering server.  If we're currently
     849#       sending data objects to the server, buffer the commands to be
     850#       sent later.
     851#
     852itcl::body Rappture::VtkIsosurfaceViewer::SendCmdNoWait {string} {
    860853    if { $_buffering } {
    861854        append _outbuf $string "\n"
     
    900893        set _hardcopy($tag) $bytes
    901894    }
    902     if { $_legendPending } {
    903         RequestLegend
    904     }
     895    EventuallyRequestLegend
    905896}
    906897
     
    964955
    965956    set _buffering 1
    966     set _legendPending 1
    967957    # Turn on buffering of commands to the server.  We don't want to
    968958    # be preempted by a server disconnect/reconnect (which automatically
     
    985975    PanCamera
    986976    set _first ""
    987     InitSettings axis-xgrid axis-ygrid axis-zgrid axis-mode \
    988         axis-visible axis-labels cutplane-visible \
    989         cutplane-xposition cutplane-yposition cutplane-zposition \
    990         cutplane-xvisible cutplane-yvisible cutplane-zvisible
     977    InitSettings axis-xgrid axis-ygrid axis-zgrid axisMode \
     978        axesVisible axisLabelsVisible cutplaneVisible \
     979        cutplaneXPosition cutplaneYPosition cutplaneZPosition \
     980        cutplaneXVisible cutplaneYVisible cutplaneZVisible
    991981
    992982    SendCmd "imgflush"
    993983
    994     set _limits(zmin) ""
    995     set _limits(zmax) ""
    996984    set _first ""
    997985    foreach dataobj [get -objects] {
     
    1004992            if { ![info exists _datasets($tag)] } {
    1005993                set bytes [$dataobj vtkdata $comp]
    1006 puts stderr bytes=$bytes
    1007994                set length [string length $bytes]
    1008995                append _outbuf "dataset add $tag data follows $length\n"
     
    10211008        }
    10221009    }
    1023     if {"" != $_first} {
    1024         set location [$_first hints camera]
    1025         if { $location != "" } {
    1026             array set view $location
    1027         }
    1028 
    1029         if 0 {
     1010    if { $_first != "" && $_reset } {
     1011        if 1 {
    10301012            # Tell the server the name of the tool, the version, and dataset
    10311013            # that we are rendering.  Have to do it here because we don't know
     
    10351017            lappend args version [$_first hints toolRevision]
    10361018            lappend args dataset [$_first hints label]
    1037             SendCmd "clientinfo $args"
    1038         }
    1039 
    1040         foreach axis { x y z } {
    1041             set label [$_first hints ${axis}label]
    1042             if { $label != "" } {
    1043                 SendCmd "axis name $axis $label"
    1044             }
    1045             set units [$_first hints ${axis}units]
    1046             if { $units != "" } {
    1047                 SendCmd "axis units $axis $units"
    1048             }
    1049         }
    1050         array unset _scalarFields
    1051         array unset _vectorFields
    1052         set _currentField [$_first hints default]
    1053         $itk_component(field) choices delete 0 end
    1054         $itk_component(fieldmenu) delete 0 end
    1055         array unset _fields
    1056         foreach { name title units } [$_first hints vectors] {
    1057             set _vectorFields($title) $name
    1058             $itk_component(field) choices insert end "$name" "$title"
    1059             $itk_component(fieldmenu) add radiobutton -label "$title" \
    1060                 -value $title -variable [itcl::scope _currentField] \
    1061                 -selectcolor red \
    1062                 -activebackground black \
    1063                 -activeforeground white \
    1064                 -font "Arial 8" \
    1065                 -command [itcl::code $this Combo invoke]
    1066             set _fields($name) [list $title $units]
    1067         }
    1068         foreach { name title units } [$_first hints scalars] {
    1069             set _scalarFields($title) $name
    1070             $itk_component(field) choices insert end "$name" "$title"
    1071             $itk_component(fieldmenu) add radiobutton -label "$title" \
    1072                 -value $title -variable [itcl::scope _currentField] \
    1073                 -selectcolor red \
    1074                 -activebackground black \
    1075                 -activeforeground white \
    1076                 -font "Arial 8" \
    1077                 -command [itcl::code $this Combo invoke]
    1078             set _fields($name) [list $title $units]
    1079         }
    1080         $itk_component(field) value $_currentField
    1081     }
    1082 
    1083     InitSettings contour-visible contour-palette contour-visible
     1019            SendCmd "clientinfo [list $args]"
     1020        }
     1021
     1022        set _fieldNames [$_first hints fieldnames]
     1023        set _fieldUnits [$_first hints fieldunits]
     1024        set _fieldLabels [$_first hints fieldlabels]
     1025        $itk_component(field) choices delete 0 end
     1026        $itk_component(fieldmenu) delete 0 end
     1027        array unset _fields
     1028        foreach name $_fieldNames title $_fieldLabels units $_fieldUnits {
     1029            SendCmd "dataset maprange explicit $_limits(vmin) $_limits(vmax) $name"
     1030            if { $title == "" } {
     1031                set title $name
     1032            }
     1033            $itk_component(field) choices insert end "$name" "$title"
     1034            $itk_component(fieldmenu) add radiobutton -label "$title" \
     1035                -value $title -variable [itcl::scope _currentFieldName] \
     1036                -selectcolor red \
     1037                -activebackground $itk_option(-plotbackground) \
     1038                -activeforeground $itk_option(-plotforeground) \
     1039                -font "Arial 8" \
     1040                -command [itcl::code $this Combo invoke]
     1041            set _fields($name) [list $title $units]
     1042            set _currentFieldName $name
     1043        }
     1044        if { [array size _fields] == 1 } {
     1045            set _currentFieldName $_fieldLabels
     1046            if { $_currentFieldName == "" } {
     1047                puts stderr "no default name from field"
     1048                set _currentFieldName "Default"
     1049            }
     1050        }
     1051        $itk_component(field) value $_currentFieldName
     1052    }
     1053    InitSettings isosurfaceVisible colormapPalette isosurfaceVisible
    10841054
    10851055    if { $_reset } {
    10861056        InitSettings \
    1087             contour-lighting \
    1088             contour-palette contour-field \
    1089             contour-edges contour-lighting contour-opacity contour-wireframe \
    1090             contour-outline
     1057            isosurfaceLighting \
     1058            field \
     1059            isosurfaceEdges isosurfaceLighting isosurfaceOpacity \
     1060            isosurfaceWireframe isosurfaceOutline
    10911061        Zoom reset
    10921062        set _reset 0
     
    11671137        "reset" {
    11681138            array set _view {
    1169                 qw      1
    1170                 qx      0
    1171                 qy      0
    1172                 qz      0
     1139                qw      0.36
     1140                qx      0.25
     1141                qy      0.50
     1142                qz      0.70
    11731143                zoom    1.0
    11741144                xpan   0
     
    13351305    }
    13361306    switch -- $what {
    1337         "contour-opacity" {
    1338             set val $_settings(contour-opacity)
     1307        "isosurfaceOpacity" {
     1308            set val $_settings(isosurfaceOpacity)
    13391309            set sval [expr { 0.01 * double($val) }]
    1340             foreach dataset [CurrentDatasets -visible] {
    1341                 SendCmd "contour3d opacity $sval $dataset"
    1342             }
    1343         }
    1344         "contour-wireframe" {
    1345             set bool $_settings(contour-wireframe)
    1346             foreach dataset [CurrentDatasets -visible] {
    1347                 SendCmd "contour3d wireframe $bool $dataset"
    1348             }
    1349         }
    1350         "contour-visible" {
    1351             set bool $_settings(contour-visible)
    1352             foreach dataset [CurrentDatasets -visible] {
    1353                 SendCmd "contour3d visible $bool $dataset"
    1354             }
     1310            SendCmd "contour3d opacity $sval"
     1311        }
     1312        "isosurfaceWireframe" {
     1313            set bool $_settings(isosurfaceWireframe)
     1314            SendCmd "contour3d wireframe $bool"
     1315        }
     1316        "isosurfaceVisible" {
     1317            set bool $_settings(isosurfaceVisible)
     1318            SendCmd "contour3d visible $bool"
    13551319            if { $bool } {
    13561320                Rappture::Tooltip::for $itk_component(contour) \
     
    13611325            }
    13621326        }
    1363         "contour-lighting" {
    1364             set bool $_settings(contour-lighting)
    1365             foreach dataset [CurrentDatasets -visible] {
    1366                 SendCmd "contour3d lighting $bool $dataset"
    1367             }
    1368         }
    1369         "contour-edges" {
    1370             set bool $_settings(contour-edges)
    1371             foreach dataset [CurrentDatasets -visible] {
    1372                 SendCmd "contour3d edges $bool $dataset"
    1373             }
    1374         }
    1375         "contour-outline" {
    1376             set bool $_settings(contour-outline)
    1377             foreach dataset [CurrentDatasets -visible] {
    1378                 SendCmd "dataset outline $bool $dataset"
    1379             }
    1380         }
    1381         "axis-visible" {
    1382             set bool $_settings(axis-visible)
     1327        "isosurfaceLighting" {
     1328            set bool $_settings(isosurfaceLighting)
     1329            SendCmd "contour3d lighting $bool"
     1330        }
     1331        "isosurfaceEdges" {
     1332            set bool $_settings(isosurfaceEdges)
     1333            SendCmd "contour3d edges $bool"
     1334        }
     1335        "isosurfaceOutline" {
     1336            set bool $_settings(isosurfaceOutline)
     1337            SendCmd "dataset outline $bool"
     1338        }
     1339        "background" {
     1340            set bgcolor [$itk_component(background) value]
     1341            array set fgcolors {
     1342                "black" "white"
     1343                "white" "black"
     1344                "grey"  "black"
     1345            }
     1346            configure -plotbackground $bgcolor \
     1347                -plotforeground $fgcolors($bgcolor)
     1348            $itk_component(view) delete "legend"
     1349            DrawLegend $_currentFieldName
     1350        }
     1351        "axesVisible" {
     1352            set bool $_settings(axesVisible)
    13831353            SendCmd "axis visible all $bool"
    13841354        }
    1385         "axis-labels" {
    1386             set bool $_settings(axis-labels)
     1355        "axisLabelsVisible" {
     1356            set bool $_settings(axisLabelsVisible)
    13871357            SendCmd "axis labels all $bool"
    13881358        }
     
    13921362            SendCmd "axis grid $axis $bool"
    13931363        }
    1394         "axis-mode" {
    1395             set mode [$itk_component(axismode) value]
    1396             set mode [$itk_component(axismode) translate $mode]
     1364        "axisMode" {
     1365            set mode [$itk_component(axisMode) value]
     1366            set mode [$itk_component(axisMode) translate $mode]
    13971367            set _settings($what) $mode
    13981368            SendCmd "axis flymode $mode"
    13991369        }
    1400         "cutplane-edges" {
     1370        "cutplaneEdges" {
    14011371            set bool $_settings($what)
    14021372            foreach dataset [CurrentDatasets -visible] {
     
    14041374            }
    14051375        }
    1406         "cutplane-visible" {
     1376        "cutplaneVisible" {
    14071377            set bool $_settings($what)
    14081378            foreach dataset [CurrentDatasets -visible] {
     
    14101380            }
    14111381        }
    1412         "cutplane-wireframe" {
     1382        "cutplaneWireframe" {
    14131383            set bool $_settings($what)
    14141384            foreach dataset [CurrentDatasets -visible] {
     
    14161386            }
    14171387        }
    1418         "cutplane-lighting" {
     1388        "cutplaneLighting" {
    14191389            set bool $_settings($what)
    14201390            foreach dataset [CurrentDatasets -visible] {
     
    14221392            }
    14231393        }
    1424         "cutplane-opacity" {
     1394        "cutplaneOpacity" {
    14251395            set val $_settings($what)
    14261396            set sval [expr { 0.01 * double($val) }]
     
    14291399            }
    14301400        }
    1431         "cutplane-xvisible" - "cutplane-yvisible" - "cutplane-zvisible" {
    1432             set axis [string range $what 9 9]
     1401        "cutplaneXVisible" - "cutplaneYVisible" - "cutplaneZVisible" {
     1402            set axis [string tolower [string range $what 8 8]]
    14331403            set bool $_settings($what)
    14341404            if { $bool } {
    1435                 $itk_component(${axis}CutScale) configure -state normal \
     1405                $itk_component(${axis}position) configure -state normal \
    14361406                    -troughcolor white
    14371407            } else {
    1438                 $itk_component(${axis}CutScale) configure -state disabled \
     1408                $itk_component(${axis}position) configure -state disabled \
    14391409                    -troughcolor grey82
    14401410            }
     
    14431413            }
    14441414        }
    1445         "cutplane-xposition" - "cutplane-yposition" - "cutplane-zposition" {
    1446             set axis [string range $what 9 9]
     1415        "cutplaneXPosition" - "cutplaneYPosition" - "cutplaneZPosition" {
     1416            set axis [string tolower [string range $what 8 8]]
    14471417            set pos [expr $_settings($what) * 0.01]
    14481418            foreach dataset [CurrentDatasets -visible] {
     
    14511421            set _cutplanePending 0
    14521422        }
    1453         "contour-visible" {
     1423        "isosurfaceVisible" {
    14541424            set bool $_settings($what)
    14551425            foreach dataset [CurrentDatasets -visible] {
    14561426                SendCmd "contour3d visible $bool $dataset"
    14571427            }
     1428            set _settings(isosurfaceVisible) $bool
    14581429            if { $bool } {
    14591430                Rappture::Tooltip::for $itk_component(contour) \
     
    14631434                    "Show the isosurface"
    14641435            }
    1465         }
    1466         "contour-palette" {
    1467             set palette [$itk_component(palette) value]
    1468             set _settings(contour-palette) $palette
    1469             foreach dataset [CurrentDatasets -visible $_first] {
    1470                 foreach {dataobj comp} [split $dataset -] break
    1471                 ChangeColormap $dataobj $comp $palette
    1472             }
    1473             set _legendPending 1
    1474         }
    1475         "contour-opacity" {
    1476             set val $_settings(contour-opacity)
     1436            DrawLegend $_currentFieldName
     1437        }
     1438        "colormapPalette" {
     1439            set color [$itk_component(palette) value]
     1440            set _settings(colormapPalette) $color
     1441            if { $color == "none" } {
     1442                if { $_settings(colormapVisible) } {
     1443                    SendCmd "contour3d surface 0"
     1444                    set _settings(colormapVisible) 0
     1445                }
     1446            } else {
     1447                if { !$_settings(colormapVisible) } {
     1448                    SendCmd "contour3d surface 1"
     1449                    set _settings(colormapVisible) 1
     1450                }
     1451                ResetColormap $color
     1452                SendCmd "contour3d colormap $_currentColormap"
     1453            }
     1454            EventuallyRequestLegend
     1455        }
     1456        "isolineColor" {
     1457            set color [$itk_component(isolineColor) value]
     1458            if { $color == "none" } {
     1459                if { $_settings(isosurfaceVisible) } {
     1460                    SendCmd "contour3d visible 0"
     1461                    set _settings(isosurfaceVisible) 0
     1462                }
     1463            } else {
     1464                if { !$_settings(isosurfaceVisible) } {
     1465                    SendCmd "contour3d visible 1"
     1466                    set _settings(isosurfaceVisible) 1
     1467                }
     1468                set _settings(isolineColor) $color
     1469            }
     1470            DrawLegend $_currentFieldName
     1471        }
     1472        "isosurfaceOpacity" {
     1473            set val $_settings(isosurfaceOpacity)
    14771474            set sval [expr { 0.01 * double($val) }]
    14781475            foreach dataset [CurrentDatasets -visible $_first] {
     
    14801477            }
    14811478        }
    1482         "contour-lighting" {
    1483             set bool $_settings(contour-lighting)
     1479        "isosurfaceLighting" {
     1480            set bool $_settings(isosurfaceLighting)
    14841481            foreach dataset [CurrentDatasets -visible $_first] {
    14851482                SendCmd "contour3d lighting $bool $dataset"
    14861483            }
    14871484        }
    1488         "contour-field" {
     1485        "field" {
    14891486            set new [$itk_component(field) value]
    14901487            set value [$itk_component(field) translate $new]
    1491             set _settings(contour-field) $value
    1492             if { [info exists _scalarFields($new)] } {
    1493                 set name $_scalarFields($new)
     1488            set _settings(field) $value
     1489            if { [info exists _fields($new)] } {
    14941490                set _colorMode scalar
    1495                 set _currentField $new
    1496             } elseif { [info exists _vectorFields($new)] } {
    1497                 set name $_vectorFields($new)
    1498                 set _colorMode vmag
    1499                 set _currentField $new
     1491                set _currentFieldName $new
    15001492            } else {
    15011493                puts stderr "unknown field \"$new\""
    15021494                return
    15031495            }
    1504             foreach dataset [CurrentDatasets -visible] {
    1505                 SendCmd "dataset scalar ${name} $dataset"
    1506                 SendCmd "cutplane colormode $_colorMode ${name} $dataset"
    1507             }
    1508             set _legendPending 1
    1509         }
    1510         "legend-visible" {
    1511             if { !$_settings(legend-visible) } {
     1496            EventuallyRequestLegend
     1497        }
     1498        "legendVisible" {
     1499            if { !$_settings(legendVisible) } {
    15121500                $itk_component(view) delete legend
    15131501            }
    1514             DrawLegend $_settings(contour-field)
     1502            DrawLegend $_settings(field)
    15151503        }
    15161504        default {
     
    15201508}
    15211509
     1510
    15221511#
    15231512# RequestLegend --
    15241513#
    15251514#       Request a new legend from the server.  The size of the legend
    1526 #       is determined from the height of the canvas.  It will be rotated
    1527 #       to be vertical when drawn.
     1515#       is determined from the height of the canvas. 
     1516#
     1517# This should be called when
     1518#       1.  A new current colormap is set.
     1519#       2.  Window is resized.
     1520#       3.  The limits of the data have changed.  (Just need a redraw).
     1521#       4.  Number of isolines have changed. (Just need a redraw).
     1522#       5.  Legend becomes visible (Just need a redraw).
    15281523#
    15291524itcl::body Rappture::VtkIsosurfaceViewer::RequestLegend {} {
     1525    set _legendPending 0
    15301526    set font "Arial 8"
    15311527    set lineht [font metrics $font -linespace]
    1532     set c $itk_component(legend)
     1528    set c $itk_component(view)
    15331529    set w 12
    1534     set h [expr {$_height - 3 * ($lineht + 2)}]
     1530    set h [expr {$_height - 2 * ($lineht + 2)}]
    15351531    if { $h < 1} {
    15361532        return
    15371533    }
    1538     if { [info exists _scalarFields($_currentField)] } {
    1539         set name $_scalarFields($_currentField)
    1540     } elseif { [info exists _vectorFields($_currentField)] } {
    1541         set name $_vectorFields($_currentField)
     1534    if { [info exists _fields($_currentFieldName)] } {
     1535        set title [lindex $_fields($_currentFieldName) 0]
     1536        if { $title != "component" } {
     1537            set h [expr $h - ($lineht + 2)]
     1538        }
    15421539    } else {
    15431540        return
    15441541    }
    1545     # Set the legend on the first coutour dataset.
    1546     foreach dataset [CurrentDatasets -visible $_first] {
    1547         foreach {dataobj comp} [split $dataset -] break
    1548         if { [info exists _dataset2style($dataset)] } {
    1549             SendCmdNoSplash \
    1550                 "legend $_dataset2style($dataset) $_colorMode $name {} $w $h 0"
    1551             break;
    1552         }
    1553     }
    1554 }
    1555 
    1556 #
    1557 # ChangeColormap --
    1558 #
    1559 itcl::body Rappture::VtkIsosurfaceViewer::ChangeColormap {dataobj comp color} {
    1560     set tag $dataobj-$comp
    1561     if { ![info exist _style($tag)] } {
    1562         error "no initial colormap"
    1563     }
    1564     array set style $_style($tag)
    1565     set style(-color) $color
    1566     set _style($tag) [array get style]
    1567     SetColormap $dataobj $comp
    1568 }
    1569 
    1570 #
    1571 # SetColormap --
    1572 #
    1573 itcl::body Rappture::VtkIsosurfaceViewer::SetColormap { dataobj comp } {
    1574     array set style {
    1575         -color BCGYR
    1576         -levels 10
    1577         -opacity 1.0
    1578     }
    1579     set tag $dataobj-$comp
    1580     if { ![info exists _initialStyle($tag)] } {
    1581         # Save the initial component style.
    1582         set _initialStyle($tag) [$dataobj style $comp]
    1583     }
    1584 
    1585     # Override defaults with initial style defined in xml.
    1586     array set style $_initialStyle($tag)
    1587 
    1588     if { ![info exists _style($tag)] } {
    1589         set _style($tag) [array get style]
    1590     }
    1591     # Override initial style with current style.
    1592     array set style $_style($tag)
    1593 
    1594     set name "$style(-color):$style(-levels):$style(-opacity)"
    1595     if { ![info exists _colormaps($name)] } {
    1596         BuildColormap $name [array get style]
    1597         set _colormaps($name) 1
    1598     }
    1599     if { ![info exists _dataset2style($tag)] ||
    1600          $_dataset2style($tag) != $name } {
    1601         SendCmd "contour3d colormap $name $tag"
    1602         SendCmd "contour3d add numcontours [expr {$style(-levels)+1}] $tag"
    1603         SendCmd "cutplane colormap $name $tag"
    1604         set _dataset2style($tag) $name
     1542    # Set the legend on the first heightmap dataset.
     1543    if { $_currentColormap != ""  } {
     1544        set cmap $_currentColormap
     1545        SendCmdNoWait "legend $cmap scalar $title {} $w $h 0"
    16051546    }
    16061547}
     
    18161757# BuildColormap --
    18171758#
    1818 itcl::body Rappture::VtkIsosurfaceViewer::BuildColormap { name styles } {
    1819     array set style $styles
     1759itcl::body Rappture::VtkIsosurfaceViewer::BuildColormap { name stylelist } {
     1760    array set style $stylelist
     1761parray style
    18201762    set cmap [ColorsToColormap $style(-color)]
    18211763    if { [llength $cmap] == 0 } {
     
    18461788itcl::configbody Rappture::VtkIsosurfaceViewer::plotforeground {
    18471789    if { [isconnected] } {
    1848         foreach {r g b} [Color2RGB $itk_option(-plotforeground)] break
    1849         #fix this!
    1850         #SendCmd "color background $r $g $b"
     1790        SendCmd "axis color all [Color2RGB $itk_option(-plotforeground)]"
    18511791    }
    18521792}
    18531793
    18541794itcl::body Rappture::VtkIsosurfaceViewer::limits { dataobj } {
    1855     return
    1856     array unset _limits $dataobj-*
    1857     foreach comp [$dataobj components] {
    1858         set tag $dataobj-$comp
    1859         if { ![info exists _limits($tag)] } {
    1860             set data [$dataobj blob $comp]
    1861             set tmpfile file[pid].vtk
    1862             set f [open "$tmpfile" "w"]
    1863             fconfigure $f -translation binary -encoding binary
    1864             puts $f $data
    1865             close $f
    1866             set reader [vtkDataSetReader $tag-xvtkDataSetReader]
    1867             $reader SetFileName $tmpfile
    1868             $reader ReadAllScalarsOn
    1869             $reader ReadAllVectorsOn
    1870             $reader ReadAllFieldsOn
    1871             $reader Update
    1872             set output [$reader GetOutput]
    1873             set _limits($tag) [$output GetBounds]
    1874             set pointData [$output GetPointData]
    1875             puts stderr "\#scalars=[$reader GetNumberOfScalarsInFile]"
    1876             puts stderr "\#fielddata=[$reader GetNumberOfFieldDataInFile]"
    1877             puts stderr "fielddataname=[$reader GetFieldDataNameInFile 0]"
    1878             set fieldData [$output GetFieldData]
    1879             set pointData [$output GetPointData]
    1880             puts stderr "field \#arrays=[$fieldData GetNumberOfArrays]"
    1881             for { set i 0 } { $i < [$fieldData GetNumberOfArrays] } { incr i } {
    1882                 puts stderr [$fieldData GetArrayName $i]
    1883             }
    1884             puts stderr "point \#arrays=[$pointData GetNumberOfArrays]"
    1885             for { set i 0 } { $i < [$pointData GetNumberOfArrays] } { incr i } {
    1886                 set name [$pointData GetArrayName $i]
    1887                 if { ![info exists _fields($name)] } {
    1888                     $itk_component(field) choices insert end "$name" "$name"
    1889                     set _fields($name) 1
    1890                 }
    1891             }
    1892             puts stderr "field \#components=[$fieldData GetNumberOfComponents]"
    1893             puts stderr "point \#components=[$pointData GetNumberOfComponents]"
    1894             puts stderr "field \#tuples=[$fieldData GetNumberOfTuples]"
    1895             puts stderr "point \#tuples=[$pointData GetNumberOfTuples]"
    1896             puts stderr "point \#scalars=[$pointData GetScalars]"
    1897             puts stderr vectors=[$pointData GetVectors]
    1898             rename $output ""
    1899             rename $reader ""
    1900             file delete $tmpfile
    1901         }
    1902         foreach { xMin xMax yMin yMax zMin zMax} $_limits($tag) break
    1903         if {![info exists limits(xmin)] || $limits(xmin) > $xMin} {
    1904             set limits(xmin) $xMin
    1905         }
    1906         if {![info exists limits(xmax)] || $limits(xmax) < $xMax} {
    1907             set limits(xmax) $xMax
    1908         }
    1909         if {![info exists limits(ymin)] || $limits(ymin) > $yMin} {
    1910             set limits(ymin) $xMin
    1911         }
    1912         if {![info exists limits(ymax)] || $limits(ymax) < $yMax} {
    1913             set limits(ymax) $yMax
    1914         }
    1915         if {![info exists limits(zmin)] || $limits(zmin) > $zMin} {
    1916             set limits(zmin) $zMin
    1917         }
    1918         if {![info exists limits(zmax)] || $limits(zmax) < $zMax} {
    1919             set limits(zmax) $zMax
    1920         }
    1921     }
     1795    foreach { limits(xmin) limits(xmax) } [$dataobj limits x] break
     1796    foreach { limits(ymin) limits(ymax) } [$dataobj limits y] break
     1797    foreach { limits(zmin) limits(zmax) } [$dataobj limits z] break
     1798    foreach { limits(vmin) limits(vmax) } [$dataobj limits v] break
    19221799    return [array get limits]
    19231800}
    19241801
    1925 itcl::body Rappture::VtkIsosurfaceViewer::BuildVolumeTab {} {
     1802itcl::body Rappture::VtkIsosurfaceViewer::BuildIsosurfaceTab {} {
    19261803
    19271804    set fg [option get $itk_component(hull) font Font]
     
    19291806
    19301807    set inner [$itk_component(main) insert end \
    1931         -title "Contour Settings" \
     1808        -title "Isosurface Settings" \
    19321809        -icon [Rappture::icon volume-on]]
    19331810    $inner configure -borderwidth 4
    19341811
    19351812    checkbutton $inner.contour \
    1936         -text "Show Isosurface" \
    1937         -variable [itcl::scope _settings(contour-visible)] \
    1938         -command [itcl::code $this AdjustSetting contour-visible] \
     1813        -text "Isosurfaces" \
     1814        -variable [itcl::scope _settings(isosurfaceVisible)] \
     1815        -command [itcl::code $this AdjustSetting isosurfaceVisible] \
    19391816        -font "Arial 9"
    19401817
    19411818    checkbutton $inner.wireframe \
    1942         -text "Show Wireframe" \
    1943         -variable [itcl::scope _settings(contour-wireframe)] \
    1944         -command [itcl::code $this AdjustSetting contour-wireframe] \
     1819        -text "Wireframe" \
     1820        -variable [itcl::scope _settings(isosurfaceWireframe)] \
     1821        -command [itcl::code $this AdjustSetting isosurfaceWireframe] \
    19451822        -font "Arial 9"
    19461823
    19471824    checkbutton $inner.lighting \
    19481825        -text "Enable Lighting" \
    1949         -variable [itcl::scope _settings(contour-lighting)] \
    1950         -command [itcl::code $this AdjustSetting contour-lighting] \
     1826        -variable [itcl::scope _settings(isosurfaceLighting)] \
     1827        -command [itcl::code $this AdjustSetting isosurfaceLighting] \
    19511828        -font "Arial 9"
    19521829
    19531830    checkbutton $inner.edges \
    1954         -text "Show Edges" \
    1955         -variable [itcl::scope _settings(contour-edges)] \
    1956         -command [itcl::code $this AdjustSetting contour-edges] \
     1831        -text "Edges" \
     1832        -variable [itcl::scope _settings(isosurfaceEdges)] \
     1833        -command [itcl::code $this AdjustSetting isosurfaceEdges] \
    19571834        -font "Arial 9"
    19581835
    19591836    checkbutton $inner.outline \
    1960         -text "Show Outline" \
    1961         -variable [itcl::scope _settings(contour-outline)] \
    1962         -command [itcl::code $this AdjustSetting contour-outline] \
     1837        -text "Outline" \
     1838        -variable [itcl::scope _settings(isosurfaceOutline)] \
     1839        -command [itcl::code $this AdjustSetting isosurfaceOutline] \
    19631840        -font "Arial 9"
    19641841
    19651842    checkbutton $inner.legend \
    1966         -text "Show Legend" \
    1967         -variable [itcl::scope _settings(legend-visible)] \
    1968         -command [itcl::code $this AdjustSetting legend-visible] \
     1843        -text "Legend" \
     1844        -variable [itcl::scope _settings(legendVisible)] \
     1845        -command [itcl::code $this AdjustSetting legendVisible] \
    19691846        -font "Arial 9"
     1847
     1848    label $inner.linecolor_l -text "Isolines" -font "Arial 9"
     1849    itk_component add isolineColor {
     1850        Rappture::Combobox $inner.linecolor -width 10 -editable no
     1851    }
     1852    $inner.linecolor choices insert end \
     1853        "black"              "black"            \
     1854        "blue"               "blue"             \
     1855        "cyan"               "cyan"             \
     1856        "green"              "green"            \
     1857        "grey"               "grey"             \
     1858        "magenta"            "magenta"          \
     1859        "orange"             "orange"           \
     1860        "red"                "red"              \
     1861        "white"              "white"            \
     1862        "none"               "none"
     1863
     1864    $itk_component(isolineColor) value "red"
     1865    bind $inner.linecolor <<Value>> \
     1866        [itcl::code $this AdjustSetting isolineColor]
     1867
     1868    label $inner.background_l -text "Background" -font "Arial 9"
     1869    itk_component add background {
     1870        Rappture::Combobox $inner.background -width 10 -editable no
     1871    }
     1872    $inner.background choices insert end \
     1873        "black"              "black"            \
     1874        "white"              "white"            \
     1875        "grey"               "grey"             
     1876
     1877    $itk_component(background) value $_settings(background)
     1878    bind $inner.background <<Value>> [itcl::code $this AdjustSetting background]
    19701879
    19711880    label $inner.opacity_l -text "Opacity" -font "Arial 9"
    19721881    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
    1973         -variable [itcl::scope _settings(contour-opacity)] \
     1882        -variable [itcl::scope _settings(isosurfaceOpacity)] \
    19741883        -width 10 \
    19751884        -showvalue off \
    1976         -command [itcl::code $this AdjustSetting contour-opacity]
     1885        -command [itcl::code $this AdjustSetting isosurfaceOpacity]
    19771886
    19781887    label $inner.scale_l -text "Scale" -font "Arial 9"
     
    19881897    }
    19891898    bind $inner.field <<Value>> \
    1990         [itcl::code $this AdjustSetting contour-field]
     1899        [itcl::code $this AdjustSetting field]
    19911900
    19921901    label $inner.palette_l -text "Palette" -font "Arial 9"
     
    20141923    $itk_component(palette) value "BCGYR"
    20151924    bind $inner.palette <<Value>> \
    2016         [itcl::code $this AdjustSetting contour-palette]
     1925        [itcl::code $this AdjustSetting colormapPalette]
    20171926
    20181927    blt::table $inner \
    2019         0,0 $inner.contour   -anchor w -pady 2 \
    2020         1,0 $inner.wireframe -anchor w -pady 2 \
    2021         2,0 $inner.lighting  -anchor w -pady 2 \
    2022         3,0 $inner.edges     -anchor w -pady 2 \
    2023         4,0 $inner.outline   -anchor w -pady 2 \
    2024         5,0 $inner.legend    -anchor w -pady 2 \
    2025         6,0 $inner.opacity_l -anchor w -pady 2 \
    2026         6,1 $inner.opacity   -fill x   -pady 2 \
    2027         8,0 $inner.field_l     -anchor w -pady 2  \
    2028         8,1 $inner.field       -anchor w -pady 2  \
    2029         9,0 $inner.palette_l   -anchor w -pady 2  \
    2030         9,1 $inner.palette     -anchor w -pady 2  \
     1928        0,0 $inner.palette_l -anchor w -pady 2  \
     1929        0,1 $inner.palette   -anchor w -pady 2  -fill x \
     1930        1,0 $inner.linecolor_l  -anchor w -pady 2  \
     1931        1,1 $inner.linecolor    -anchor w -pady 2 -fill x  \
     1932        2,0 $inner.background_l -anchor w -pady 2 \
     1933        2,1 $inner.background -anchor w -pady 2  -fill x \
     1934        3,0 $inner.contour   -anchor w -pady 2 -cspan 2 \
     1935        4,0 $inner.wireframe -anchor w -pady 2 -cspan 2 \
     1936        5,0 $inner.lighting  -anchor w -pady 2 -cspan 2 \
     1937        6,0 $inner.edges     -anchor w -pady 2 -cspan 2 \
     1938        7,0 $inner.outline   -anchor w -pady 2 -cspan 2 \
     1939        8,0 $inner.legend    -anchor w -pady 2 \
     1940        9,0 $inner.opacity_l -anchor w -pady 2 \
     1941        9,1 $inner.opacity   -fill x   -pady 2 -fill x \
     1942        10,0 $inner.field_l   -anchor w -pady 2  \
     1943        10,1 $inner.field     -anchor w -pady 2  -fill x \
    20311944
    20321945    blt::table configure $inner r* c* -resize none
    2033     blt::table configure $inner r10 c1 c2 -resize expand
     1946    blt::table configure $inner r11 c1 -resize expand
    20341947}
    20351948
     
    20461959    checkbutton $inner.visible \
    20471960        -text "Show Axes" \
    2048         -variable [itcl::scope _settings(axis-visible)] \
    2049         -command [itcl::code $this AdjustSetting axis-visible] \
     1961        -variable [itcl::scope _settings(axesVisible)] \
     1962        -command [itcl::code $this AdjustSetting axesVisible] \
    20501963        -font "Arial 9"
    20511964
    20521965    checkbutton $inner.labels \
    20531966        -text "Show Axis Labels" \
    2054         -variable [itcl::scope _settings(axis-labels)] \
    2055         -command [itcl::code $this AdjustSetting axis-labels] \
     1967        -variable [itcl::scope _settings(axisLabelsVisible)] \
     1968        -command [itcl::code $this AdjustSetting axisLabelsVisible] \
    20561969        -font "Arial 9"
    20571970
     
    20741987    label $inner.mode_l -text "Mode" -font "Arial 9"
    20751988
    2076     itk_component add axismode {
     1989    itk_component add axisMode {
    20771990        Rappture::Combobox $inner.mode -width 10 -editable no
    20781991    }
     
    20821995        "furthest_triad"  "furthest" \
    20831996        "outer_edges"     "outer"         
    2084     $itk_component(axismode) value "static"
    2085     bind $inner.mode <<Value>> [itcl::code $this AdjustSetting axis-mode]
     1997    $itk_component(axisMode) value "static"
     1998    bind $inner.mode <<Value>> [itcl::code $this AdjustSetting axisMode]
    20861999
    20872000    blt::table $inner \
     
    21452058
    21462059    checkbutton $inner.visible \
    2147         -text "Show Cutplanes" \
    2148         -variable [itcl::scope _settings(cutplane-visible)] \
    2149         -command [itcl::code $this AdjustSetting cutplane-visible] \
     2060        -text "Cutplanes" \
     2061        -variable [itcl::scope _settings(cutplaneVisible)] \
     2062        -command [itcl::code $this AdjustSetting cutplaneVisible] \
    21502063        -font "Arial 9"
    21512064
    21522065    checkbutton $inner.wireframe \
    2153         -text "Show Wireframe" \
    2154         -variable [itcl::scope _settings(cutplane-wireframe)] \
    2155         -command [itcl::code $this AdjustSetting cutplane-wireframe] \
     2066        -text "Wireframe" \
     2067        -variable [itcl::scope _settings(cutplaneWireframe)] \
     2068        -command [itcl::code $this AdjustSetting cutplaneWireframe] \
    21562069        -font "Arial 9"
    21572070
    21582071    checkbutton $inner.lighting \
    21592072        -text "Enable Lighting" \
    2160         -variable [itcl::scope _settings(cutplane-lighting)] \
    2161         -command [itcl::code $this AdjustSetting cutplane-lighting] \
     2073        -variable [itcl::scope _settings(cutplaneLighting)] \
     2074        -command [itcl::code $this AdjustSetting cutplaneLighting] \
    21622075        -font "Arial 9"
    21632076
    21642077    checkbutton $inner.edges \
    2165         -text "Show Edges" \
    2166         -variable [itcl::scope _settings(cutplane-edges)] \
    2167         -command [itcl::code $this AdjustSetting cutplane-edges] \
     2078        -text "Edges" \
     2079        -variable [itcl::scope _settings(cutplaneEdges)] \
     2080        -command [itcl::code $this AdjustSetting cutplaneEdges] \
    21682081        -font "Arial 9"
    21692082
    21702083    label $inner.opacity_l -text "Opacity" -font "Arial 9"
    21712084    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
    2172         -variable [itcl::scope _settings(cutplane-opacity)] \
     2085        -variable [itcl::scope _settings(cutplaneOpacity)] \
    21732086        -width 10 \
    21742087        -showvalue off \
    2175         -command [itcl::code $this AdjustSetting cutplane-opacity]
    2176     $inner.opacity set $_settings(cutplane-opacity)
     2088        -command [itcl::code $this AdjustSetting cutplaneOpacity]
     2089    $inner.opacity set $_settings(cutplaneOpacity)
    21772090
    21782091    # X-value slicer...
    2179     itk_component add xCutButton {
     2092    itk_component add xbutton {
    21802093        Rappture::PushButton $inner.xbutton \
    21812094            -onimage [Rappture::icon x-cutplane] \
    21822095            -offimage [Rappture::icon x-cutplane] \
    2183             -command [itcl::code $this AdjustSetting cutplane-xvisible] \
    2184             -variable [itcl::scope _settings(cutplane-xvisible)]
    2185     }
    2186     Rappture::Tooltip::for $itk_component(xCutButton) \
     2096            -command [itcl::code $this AdjustSetting cutplaneXVisible] \
     2097            -variable [itcl::scope _settings(cutplaneXVisible)]
     2098    }
     2099    Rappture::Tooltip::for $itk_component(xbutton) \
    21872100        "Toggle the X-axis cutplane on/off"
    21882101
    2189     itk_component add xCutScale {
     2102    itk_component add xposition {
    21902103        ::scale $inner.xval -from 100 -to 1 \
    21912104            -width 10 -orient vertical -showvalue yes \
    21922105            -borderwidth 1 -highlightthickness 0 \
    21932106            -command [itcl::code $this EventuallySetCutplane x] \
    2194             -variable [itcl::scope _settings(cutplane-xposition)]
     2107            -variable [itcl::scope _settings(cutplaneXPosition)]
    21952108    } {
    21962109        usual
     
    21982111    }
    21992112    # Set the default cutplane value before disabling the scale.
    2200     $itk_component(xCutScale) set 50
    2201     $itk_component(xCutScale) configure -state disabled
    2202     Rappture::Tooltip::for $itk_component(xCutScale) \
     2113    $itk_component(xposition) set 50
     2114    $itk_component(xposition) configure -state disabled
     2115    Rappture::Tooltip::for $itk_component(xposition) \
    22032116        "@[itcl::code $this Slice tooltip x]"
    22042117
    22052118    # Y-value slicer...
    2206     itk_component add yCutButton {
     2119    itk_component add ybutton {
    22072120        Rappture::PushButton $inner.ybutton \
    22082121            -onimage [Rappture::icon y-cutplane] \
    22092122            -offimage [Rappture::icon y-cutplane] \
    2210             -command [itcl::code $this AdjustSetting cutplane-yvisible] \
    2211             -variable [itcl::scope _settings(cutplane-yvisible)]
    2212     }
    2213     Rappture::Tooltip::for $itk_component(yCutButton) \
     2123            -command [itcl::code $this AdjustSetting cutplaneYVisible] \
     2124            -variable [itcl::scope _settings(cutplaneYVisible)]
     2125    }
     2126    Rappture::Tooltip::for $itk_component(ybutton) \
    22142127        "Toggle the Y-axis cutplane on/off"
    22152128
    2216     itk_component add yCutScale {
     2129    itk_component add yposition {
    22172130        ::scale $inner.yval -from 100 -to 1 \
    22182131            -width 10 -orient vertical -showvalue yes \
    22192132            -borderwidth 1 -highlightthickness 0 \
    22202133            -command [itcl::code $this EventuallySetCutplane y] \
    2221             -variable [itcl::scope _settings(cutplane-yposition)]
     2134            -variable [itcl::scope _settings(cutplaneYPosition)]
    22222135    } {
    22232136        usual
    22242137        ignore -borderwidth -highlightthickness
    22252138    }
    2226     Rappture::Tooltip::for $itk_component(yCutScale) \
     2139    Rappture::Tooltip::for $itk_component(yposition) \
    22272140        "@[itcl::code $this Slice tooltip y]"
    22282141    # Set the default cutplane value before disabling the scale.
    2229     $itk_component(yCutScale) set 50
    2230     $itk_component(yCutScale) configure -state disabled
     2142    $itk_component(yposition) set 50
     2143    $itk_component(yposition) configure -state disabled
    22312144
    22322145    # Z-value slicer...
    2233     itk_component add zCutButton {
     2146    itk_component add zbutton {
    22342147        Rappture::PushButton $inner.zbutton \
    22352148            -onimage [Rappture::icon z-cutplane] \
    22362149            -offimage [Rappture::icon z-cutplane] \
    2237             -command [itcl::code $this AdjustSetting cutplane-zvisible] \
    2238             -variable [itcl::scope _settings(cutplane-zvisible)]
    2239     }
    2240     Rappture::Tooltip::for $itk_component(zCutButton) \
     2150            -command [itcl::code $this AdjustSetting cutplaneZVisible] \
     2151            -variable [itcl::scope _settings(cutplaneZVisible)]
     2152    }
     2153    Rappture::Tooltip::for $itk_component(zbutton) \
    22412154        "Toggle the Z-axis cutplane on/off"
    22422155
    2243     itk_component add zCutScale {
     2156    itk_component add zposition {
    22442157        ::scale $inner.zval -from 100 -to 1 \
    22452158            -width 10 -orient vertical -showvalue yes \
    22462159            -borderwidth 1 -highlightthickness 0 \
    22472160            -command [itcl::code $this EventuallySetCutplane z] \
    2248             -variable [itcl::scope _settings(cutplane-zposition)]
     2161            -variable [itcl::scope _settings(cutplaneZPosition)]
    22492162    } {
    22502163        usual
    22512164        ignore -borderwidth -highlightthickness
    22522165    }
    2253     $itk_component(zCutScale) set 50
    2254     $itk_component(zCutScale) configure -state disabled
    2255     #$itk_component(zCutScale) configure -state disabled
    2256     Rappture::Tooltip::for $itk_component(zCutScale) \
     2166    $itk_component(zposition) set 50
     2167    $itk_component(zposition) configure -state disabled
     2168    Rappture::Tooltip::for $itk_component(zposition) \
    22572169        "@[itcl::code $this Slice tooltip z]"
    22582170
    22592171    blt::table $inner \
    2260         0,0 $inner.visible              -anchor w -pady 2 -cspan 4 \
    2261         1,0 $inner.lighting             -anchor w -pady 2 -cspan 4 \
    2262         2,0 $inner.wireframe            -anchor w -pady 2 -cspan 4 \
    2263         3,0 $inner.edges                -anchor w -pady 2 -cspan 4 \
    2264         4,0 $inner.opacity_l            -anchor w -pady 2 -cspan 3 \
    2265         5,0 $inner.opacity              -fill x   -pady 2 -cspan 3 \
    2266         6,0 $itk_component(xCutButton)  -anchor e -padx 2 -pady 2 \
    2267         7,0 $itk_component(xCutScale)   -fill y \
    2268         6,1 $itk_component(yCutButton)  -anchor e -padx 2 -pady 2 \
    2269         7,1 $itk_component(yCutScale)   -fill y \
    2270         6,2 $itk_component(zCutButton)  -anchor e -padx 2 -pady 2 \
    2271         7,2 $itk_component(zCutScale)   -fill y \
     2172        0,0 $inner.visible              -anchor w -pady 2 -cspan 3 \
     2173        1,0 $inner.lighting             -anchor w -pady 2 -cspan 3 \
     2174        2,0 $inner.wireframe            -anchor w -pady 2 -cspan 3 \
     2175        3,0 $inner.edges                -anchor w -pady 2 -cspan 3 \
     2176        4,0 $inner.opacity_l            -anchor w -pady 2 -cspan 1 \
     2177        4,1 $inner.opacity              -fill x   -pady 2 -cspan 3 \
     2178        6,0 $inner.xbutton              -anchor w -padx 2 -pady 2 \
     2179        7,0 $inner.ybutton              -anchor w -padx 2 -pady 2 \
     2180        8,0 $inner.zbutton              -anchor w -padx 2 -pady 2 \
     2181        6,1 $inner.xval                 -fill y -rspan 4 \
     2182        6,2 $inner.yval                 -fill y -rspan 4 \
     2183        6,3 $inner.zval                 -fill y -rspan 4 \
     2184
    22722185
    22732186    blt::table configure $inner r* c* -resize none
    2274     blt::table configure $inner r7 c3 -resize expand
     2187    blt::table configure $inner r9 c4 -resize expand
     2188    blt::table configure $inner r5 -height 0.12i
    22752189}
    22762190
     
    23112225                    SendCmd "camera zoom $_view(zoom)"
    23122226                }
    2313             }
    2314         }
    2315     }
    2316 }
    2317 
    2318 itcl::body Rappture::VtkIsosurfaceViewer::ConvertToVtkData { dataobj comp } {
    2319     foreach { x1 x2 xN y1 y2 yN } [$dataobj mesh $comp] break
    2320     set values [$dataobj values $comp]
    2321     append out "# vtk DataFile Version 2.0 \n"
    2322     append out "Test data \n"
    2323     append out "ASCII \n"
    2324     append out "DATASET STRUCTURED_POINTS \n"
    2325     append out "DIMENSIONS $xN $yN 1 \n"
    2326     append out "ORIGIN 0 0 0 \n"
    2327     append out "SPACING 1 1 1 \n"
    2328     append out "POINT_DATA [expr $xN * $yN] \n"
    2329     append out "SCALARS field float 1 \n"
    2330     append out "LOOKUP_TABLE default \n"
    2331     append out [join $values "\n"]
    2332     append out "\n"
    2333     return $out
    2334 }
    2335 
     2227             }
     2228        }
     2229    }
     2230}
    23362231
    23372232itcl::body Rappture::VtkIsosurfaceViewer::GetVtkData { args } {
    23382233    set bytes ""
    23392234    foreach dataobj [get] {
    2340         foreach comp [$dataobj components] {
    2341             set tag $dataobj-$comp
    2342             #set contents [ConvertToVtkData $dataobj $comp]
    2343             set contents [$dataobj blob $comp]
     2235        foreach cname [$dataobj components] {
     2236            set tag $dataobj-$cname
     2237            set contents [$dataobj vtkdata $cname]
    23442238            append bytes "$contents\n\n"
    23452239        }
     
    23642258    radiobutton $inner.vtk_button -text "VTK data file" \
    23652259        -variable [itcl::scope _downloadPopup(format)] \
    2366         -font "Helvetica 9 " \
     2260        -font "Arial 9 " \
    23672261        -value vtk 
    23682262    Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file."
    23692263    radiobutton $inner.image_button -text "Image File" \
    23702264        -variable [itcl::scope _downloadPopup(format)] \
     2265        -font "Arial 9 " \
    23712266        -value image
    23722267    Rappture::Tooltip::for $inner.image_button \
     
    24012296    # Parse style string.
    24022297    set tag $dataobj-$comp
    2403     set style [$dataobj style $comp]
    2404     array set settings {
    2405         -color \#808080
     2298    array set style {
     2299        -color BCGYR
    24062300        -edges 0
    24072301        -edgecolor black
     
    24102304        -wireframe 0
    24112305        -lighting 1
    2412         -seeds 1
    2413         -seedcolor white
    2414         -visible 1
    24152306        -outline 0
    2416     }
     2307        -levels 10
     2308    }
     2309    array set style [$dataobj style $comp]
    24172310    if { $dataobj != $_first } {
    2418         set settings(-opacity) 1
    2419     }
    2420     array set settings $style
     2311        set style(-opacity) 1
     2312    }
     2313    if { $_currentColormap == "" } {
     2314        set stylelist [$dataobj style $comp]
     2315        if { $stylelist != "" } {
     2316            array set style $stylelist
     2317            set stylelist [array get style]
     2318            SetCurrentColormap $stylelist
     2319        }
     2320        $itk_component(palette) value $style(-color)
     2321    }
    24212322    SendCmd "cutplane add $tag"
    24222323    SendCmd "cutplane edges 0 $tag"
     
    24312332        SendCmd "cutplane axis $axis 0 $tag"
    24322333    }
    2433 
    2434     SendCmd "contour3d add numcontours 10 $tag"
    2435     SendCmd "contour3d edges $settings(-edges) $tag"
    2436     SendCmd "dataset outline $settings(-outline) $tag"
    2437     set _settings(contour-outline) $settings(-outline)
    2438     set _settings(contour-edges) $settings(-edges)
     2334    set _numContours $style(-levels)
     2335    SendCmd "contour3d add numcontours $_numContours $tag"
     2336    SendCmd "contour3d edges $style(-edges) $tag"
     2337    SendCmd "dataset outline $style(-outline) $tag"
     2338    set _settings(isosurfaceOutline) $style(-outline)
     2339    set _settings(isosurfaceEdges) $style(-edges)
    24392340    #SendCmd "contour3d color [Color2RGB $settings(-color)] $tag"
    2440     SendCmd "contour3d lighting $settings(-lighting) $tag"
    2441     set _settings(contour-lighting) $settings(-lighting)
    2442     SendCmd "contour3d linecolor [Color2RGB $settings(-edgecolor)] $tag"
    2443     SendCmd "contour3d linewidth $settings(-linewidth) $tag"
    2444     SendCmd "contour3d opacity $settings(-opacity) $tag"
    2445     set _settings(contour-opacity) $settings(-opacity)
    2446     SendCmd "contour3d wireframe $settings(-wireframe) $tag"
    2447     set _settings(contour-wireframe) $settings(-wireframe)
    2448     set _settings(contour-opacity) [expr $settings(-opacity) * 100.0]
    2449     SetColormap $dataobj $comp
     2341    SendCmd "contour3d lighting $style(-lighting) $tag"
     2342    set _settings(isosurfaceLighting) $style(-lighting)
     2343    SendCmd "contour3d linecolor [Color2RGB $style(-edgecolor)] $tag"
     2344    SendCmd "contour3d linewidth $style(-linewidth) $tag"
     2345    SendCmd "contour3d opacity $style(-opacity) $tag"
     2346    set _settings(isosurfaceOpacity) $style(-opacity)
     2347    SendCmd "contour3d wireframe $style(-wireframe) $tag"
     2348    set _settings(isosurfaceWireframe) $style(-wireframe)
     2349    set _settings(isosurfaceOpacity) [expr $style(-opacity) * 100.0]
    24502350}
    24512351
     
    24552355    }
    24562356    return 1
    2457 }
    2458 
    2459 # ----------------------------------------------------------------------
    2460 # USAGE: ReceiveLegend <colormap> <title> <vmin> <vmax> <size>
    2461 #
    2462 # Invoked automatically whenever the "legend" command comes in from
    2463 # the rendering server.  Indicates that binary image data with the
    2464 # specified <size> will follow.
    2465 # ----------------------------------------------------------------------
    2466 itcl::body Rappture::VtkIsosurfaceViewer::ReceiveLegend { colormap title vmin vmax size } {
    2467     set _legendPending 0
    2468     #puts stderr "ReceiveLegend colormap=$colormap title=$title range=$vmin,$vmax size=$size"
    2469     set _limits(vmin) $vmin
    2470     set _limits(vmax) $vmax
    2471     set _title $title
    2472     regsub {\(mag\)} $title "" _title
    2473     if { [IsConnected] } {
    2474         set bytes [ReceiveBytes $size]
    2475         if { ![info exists _image(legend)] } {
    2476             set _image(legend) [image create photo]
    2477         }
    2478         $_image(legend) configure -data $bytes
    2479         #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
    2480         if { [catch {DrawLegend $_title} errs] != 0 } {
    2481             puts stderr errs=$errs
    2482         }
    2483     }
    2484 }
    2485 
    2486 #
    2487 # DrawLegend --
    2488 #
    2489 #       Draws the legend in it's own canvas which resides to the right
    2490 #       of the contour plot area.
    2491 #
    2492 itcl::body Rappture::VtkIsosurfaceViewer::DrawLegend { name } {
    2493     set c $itk_component(view)
    2494     set w [winfo width $c]
    2495     set h [winfo height $c]
    2496     set font "Arial 8"
    2497     set lineht [font metrics $font -linespace]
    2498    
    2499     if { [info exists _fields($name)] } {
    2500         foreach { title units } $_fields($name) break
    2501         if { $units != "" } {
    2502             set title [format "%s (%s)" $title $units]
    2503         }
    2504     } else {
    2505         set title $name
    2506     }
    2507     if { $_settings(legend-visible) } {
    2508         set x [expr $w - 2]
    2509         if { [$c find withtag "legend"] == "" } {
    2510             set y 2
    2511             $c create text $x $y \
    2512                 -anchor ne \
    2513                 -fill $itk_option(-plotforeground) -tags "title legend" \
    2514                 -font $font
    2515             incr y $lineht
    2516             $c create text $x $y \
    2517                 -anchor ne \
    2518                 -fill $itk_option(-plotforeground) -tags "vmax legend" \
    2519                 -font $font
    2520             incr y $lineht
    2521             $c create image $x $y \
    2522                 -anchor ne \
    2523                 -image $_image(legend) -tags "colormap legend"
    2524             $c create text $x [expr {$h-2}] \
    2525                 -anchor se \
    2526                 -fill $itk_option(-plotforeground) -tags "vmin legend" \
    2527                 -font $font
    2528             #$c bind colormap <Enter> [itcl::code $this EnterLegend %x %y]
    2529             $c bind colormap <Leave> [itcl::code $this LeaveLegend]
    2530             $c bind colormap <Motion> [itcl::code $this MotionLegend %x %y]
    2531         }
    2532         $c bind title <ButtonPress> [itcl::code $this Combo post]
    2533         $c bind title <Enter> [itcl::code $this Combo activate]
    2534         $c bind title <Leave> [itcl::code $this Combo deactivate]
    2535         # Reset the item coordinates according the current size of the plot.
    2536         $c itemconfigure title -text $title
    2537         if { $_limits(vmin) != "" } {
    2538             $c itemconfigure vmin -text [format %g $_limits(vmin)]
    2539         }
    2540         if { $_limits(vmax) != "" } {
    2541             $c itemconfigure vmax -text [format %g $_limits(vmax)]
    2542         }
    2543         set y 2
    2544         $c coords title $x $y
    2545         incr y $lineht
    2546         $c coords vmax $x $y
    2547         incr y $lineht
    2548         $c coords colormap $x $y
    2549         $c coords vmin $x [expr {$h - 2}]
    2550     }
    25512357}
    25522358
     
    25902396    set imgY [expr $y - 2 * ($lineht + 2)]
    25912397
     2398    set title ""
    25922399    if { [info exists _fields($_title)] } {
    25932400        foreach { title units } $_fields($_title) break
     2401        if { $title == "component" } {
     2402            set title ""
     2403        }
    25942404        if { $units != "" } {
    2595             set title [format "%s (%s)" $title $units]
     2405            append title [format " (%s)" $units]
    25962406        }
    25972407    } else {
    25982408        set title $_title
     2409        if { $title == "component" } {
     2410            set title ""
     2411        }
    25992412    }
    26002413    # Make a swatch of the selected color
    26012414    if { [catch { $_image(legend) get 10 $imgY } pixel] != 0 } {
    2602         #puts stderr "out of range: $imgY"
    26032415        return
    26042416    }
     
    26062418        set _image(swatch) [image create photo -width 24 -height 24]
    26072419    }
    2608     $_image(swatch) blank white
    2609     $_image(swatch) draw rectangle 3 3 20 20 -color $pixel -shadow 1
    2610     $_image(swatch) draw rectangle 3 3 20 20 -color black -linewidth 1
    2611 
    2612     if 0 {
    26132420    set color [eval format "\#%02x%02x%02x" $pixel]
    26142421    $_image(swatch) put black  -to 0 0 23 23
    26152422    $_image(swatch) put $color -to 1 1 22 22
    2616     }
     2423    .rappturetooltip configure -icon $_image(swatch)
     2424
    26172425    .rappturetooltip configure -icon $_image(swatch)
    26182426
     
    26432451        "move" {
    26442452            set axis [lindex $args 0]
    2645             set oldval $_settings(axis-${axis}position)
     2453            set a [string toupper $axis]
     2454            set oldval $_settings(cutplane${a}Position)
    26462455            set newval [lindex $args 1]
    26472456            if {[llength $args] != 2} {
     
    26532462        "tooltip" {
    26542463            set axis [lindex $args 0]
    2655             set val [$itk_component(${axis}CutScale) get]
     2464            set val [$itk_component(${axis}position) get]
    26562465            return "Move the [string toupper $axis] cut plane.\nCurrently:  $axis = $val%"
    26572466        }
     
    26622471}
    26632472
     2473#
     2474# ReceiveLegend --
     2475#
     2476#       Invoked automatically whenever the "legend" command comes in from
     2477#       the rendering server.  Indicates that binary image data with the
     2478#       specified <size> will follow.
     2479#
     2480itcl::body Rappture::VtkIsosurfaceViewer::ReceiveLegend { colormap title min max size } {
     2481    #puts stderr "ReceiveLegend colormap=$colormap title=$title range=$min,$max size=$size"
     2482    set _title $title
     2483    regsub {\(mag\)} $title "" _title
     2484    if { [IsConnected] } {
     2485        set bytes [ReceiveBytes $size]
     2486        if { ![info exists _image(legend)] } {
     2487            set _image(legend) [image create photo]
     2488        }
     2489        $_image(legend) configure -data $bytes
     2490        #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
     2491        if { [catch {DrawLegend $_title} errs] != 0 } {
     2492            global errorInfo
     2493            puts stderr "errs=$errs errorInfo=$errorInfo"
     2494        }
     2495    }
     2496}
     2497
     2498#
     2499# DrawLegend --
     2500#
     2501#       Draws the legend in it's own canvas which resides to the right
     2502#       of the contour plot area.
     2503#
     2504itcl::body Rappture::VtkIsosurfaceViewer::DrawLegend { name } {
     2505    set c $itk_component(view)
     2506    set w [winfo width $c]
     2507    set h [winfo height $c]
     2508    set font "Arial 8"
     2509    set lineht [font metrics $font -linespace]
     2510   
     2511    if { $name == "component" } {
     2512        set title ""
     2513    } else {
     2514        if { [info exists _fields($name)] } {
     2515            foreach { title units } $_fields($name) break
     2516            if { $units != "" } {
     2517                set title [format "%s (%s)" $title $units]
     2518            }
     2519        } else {
     2520            set title $name
     2521        }
     2522    }
     2523    set x [expr $w - 2]
     2524    if { !$_settings(legendVisible) } {
     2525        $c delete legend
     2526        return
     2527    }
     2528    if { [$c find withtag "legend"] == "" } {
     2529        set y 2
     2530        # If there's a legend title, create a text item for the title.
     2531        if { $title != "" } {
     2532            $c create text $x $y \
     2533                -anchor ne \
     2534                -fill $itk_option(-plotforeground) -tags "title legend" \
     2535                -font $font
     2536            incr y $lineht
     2537        }
     2538        $c create text $x $y \
     2539            -anchor ne \
     2540            -fill $itk_option(-plotforeground) -tags "zmax legend" \
     2541            -font $font
     2542        incr y $lineht
     2543        $c create image $x $y \
     2544            -anchor ne \
     2545            -image $_image(legend) -tags "colormap legend"
     2546        $c create text $x [expr {$h-2}] \
     2547            -anchor se \
     2548            -fill $itk_option(-plotforeground) -tags "zmin legend" \
     2549            -font $font
     2550        #$c bind colormap <Enter> [itcl::code $this EnterLegend %x %y]
     2551        $c bind colormap <Leave> [itcl::code $this LeaveLegend]
     2552        $c bind colormap <Motion> [itcl::code $this MotionLegend %x %y]
     2553    }
     2554    $c delete isoline
     2555    set x2 $x
     2556    set iw [image width $_image(legend)]
     2557    set ih [image height $_image(legend)]
     2558    set x1 [expr $x2 - ($iw*12)/10]
     2559    set color $_settings(isolineColor)
     2560    # Draw the isolines on the legend.
     2561    if { $color != "none"  && $_numContours > 0 } {
     2562        set pixels [blt::vector create \#auto]
     2563        set values [blt::vector create \#auto]
     2564        set range [image height $_image(legend)]
     2565        # Order of pixels is max to min (max is at top of legend).
     2566        $pixels seq $ih 0 $_numContours
     2567        set offset [expr 2 + $lineht]
     2568        # If there's a legend title, increase the offset by the line height.
     2569        if { $title != "" } {
     2570            incr offset $lineht
     2571        }
     2572        $pixels expr {round($pixels + $offset)}
     2573        # Order of values is min to max.
     2574        $values seq $_limits(zmin) $_limits(zmax) $_numContours
     2575        set tags "isoline legend"
     2576        foreach pos [$pixels range 0 end] value [$values range end 0] {
     2577            set y1 [expr int($pos)]
     2578            set id [$c create line $x1 $y1 $x2 $y1 -fill $color -tags $tags]
     2579            $c bind $id <Enter> [itcl::code $this EnterIsoline %x %y $value]
     2580            $c bind $id <Leave> [itcl::code $this LeaveIsoline]
     2581        }
     2582        blt::vector destroy $pixels $values
     2583    }
     2584
     2585    $c bind title <ButtonPress> [itcl::code $this Combo post]
     2586    $c bind title <Enter> [itcl::code $this Combo activate]
     2587    $c bind title <Leave> [itcl::code $this Combo deactivate]
     2588    # Reset the item coordinates according the current size of the plot.
     2589    $c itemconfigure title -text $title
     2590    if { [info exists _limits(zmin)] && $_limits(zmin) != "" } {
     2591        $c itemconfigure zmin -text [format %g $_limits(zmin)]
     2592    }
     2593    if { [info exists _limits(zmax)] && $_limits(zmax) != "" } {
     2594        $c itemconfigure zmax -text [format %g $_limits(zmax)]
     2595    }
     2596    set y 2
     2597    # If there's a legend title, move the title to the correct position
     2598    if { $title != "" } {
     2599        $c coords title $x $y
     2600        incr y $lineht
     2601    }
     2602    $c coords zmax $x $y
     2603    incr y $lineht
     2604    $c coords colormap $x $y
     2605    $c coords zmin $x [expr {$h - 2}]
     2606}
     2607
     2608#
     2609# EnterIsoline --
     2610#
     2611itcl::body Rappture::VtkIsosurfaceViewer::EnterIsoline { x y value } {
     2612    SetIsolineTip $x $y $value
     2613}
     2614
     2615#
     2616# LeaveIsoline --
     2617#
     2618itcl::body Rappture::VtkIsosurfaceViewer::LeaveIsoline { } {
     2619    Rappture::Tooltip::tooltip cancel
     2620    .rappturetooltip configure -icon ""
     2621}
     2622
     2623#
     2624# SetIsolineTip --
     2625#
     2626itcl::body Rappture::VtkIsosurfaceViewer::SetIsolineTip { x y value } {
     2627    set c $itk_component(view)
     2628    set w [winfo width $c]
     2629    set h [winfo height $c]
     2630    set font "Arial 8"
     2631    set lineht [font metrics $font -linespace]
     2632   
     2633    if { [info exists _fields($_title)] } {
     2634        foreach { title units } $_fields($_title) break
     2635        if { $title == "component" } {
     2636            set title ""
     2637        }
     2638        if { $units != "" } {
     2639            set title [format "%s (%s)" $title $units]
     2640        }
     2641    } else {
     2642        set title $_title
     2643    }
     2644    # Make a swatch of the selected color
     2645    set imgHeight [image height $_image(legend)]
     2646    set coords [$c coords colormap]
     2647    set imgX [expr $w - [image width $_image(legend)] - 2]
     2648    set imgY [expr $y - 2 * ($lineht + 2)]
     2649
     2650    if { [catch { $_image(legend) get 10 $imgY } pixel] != 0 } {
     2651        return
     2652    }
     2653    if { ![info exists _image(swatch)] } {
     2654        set _image(swatch) [image create photo -width 24 -height 24]
     2655    }
     2656    set color [eval format "\#%02x%02x%02x" $pixel]
     2657    $_image(swatch) put black  -to 0 0 23 23
     2658    $_image(swatch) put $color -to 1 1 22 22
     2659    .rappturetooltip configure -icon $_image(swatch)
     2660
     2661     # Compute the value of the point
     2662    set tipx [expr $x + 15]
     2663    set tipy [expr $y - 5]
     2664    Rappture::Tooltip::text $c "Isosurface $value"
     2665    Rappture::Tooltip::tooltip show $c +$tipx,+$tipy   
     2666}
    26642667
    26652668# ----------------------------------------------------------------------
     
    26882691        }
    26892692        deactivate {
    2690             $c itemconfigure title -fill white
     2693            $c itemconfigure title -fill $itk_option(-plotforeground)
    26912694        }
    26922695        invoke {
    2693             $itk_component(field) value $_currentField
    2694             AdjustSetting contour-field
     2696            $itk_component(field) value $_currentFieldName
     2697            AdjustSetting field
    26952698        }
    26962699        default {
     
    26992702    }
    27002703}
     2704
     2705#
     2706# SetCurrentColormap --
     2707#
     2708itcl::body Rappture::VtkIsosurfaceViewer::SetCurrentColormap { stylelist } {
     2709    array set style {
     2710        -color BCGYR
     2711        -levels 10
     2712        -opacity 1.0
     2713    }
     2714    array set style $stylelist
     2715
     2716    set name "$style(-color):$style(-levels):$style(-opacity)"
     2717    if { ![info exists _colormaps($name)] } {
     2718        set stylelist [array get style]
     2719        BuildColormap $name $stylelist
     2720        set _colormaps($name) $stylelist
     2721    }
     2722    set _currentColormap $name
     2723}
     2724
     2725itcl::body Rappture::VtkIsosurfaceViewer::ColorsToColormap { colors } {
     2726    switch -- $colors {
     2727        "grey-to-blue" {
     2728            return {
     2729                0.0                      0.200 0.200 0.200
     2730                0.14285714285714285      0.400 0.400 0.400
     2731                0.2857142857142857       0.600 0.600 0.600
     2732                0.42857142857142855      0.900 0.900 0.900
     2733                0.5714285714285714       0.800 1.000 1.000
     2734                0.7142857142857143       0.600 1.000 1.000
     2735                0.8571428571428571       0.400 0.900 1.000
     2736                1.0                      0.000 0.600 0.800
     2737            }
     2738        }
     2739        "blue-to-grey" {
     2740            return {
     2741                0.0                     0.000 0.600 0.800
     2742                0.14285714285714285     0.400 0.900 1.000
     2743                0.2857142857142857      0.600 1.000 1.000
     2744                0.42857142857142855     0.800 1.000 1.000
     2745                0.5714285714285714      0.900 0.900 0.900
     2746                0.7142857142857143      0.600 0.600 0.600
     2747                0.8571428571428571      0.400 0.400 0.400
     2748                1.0                     0.200 0.200 0.200
     2749            }
     2750        }
     2751        "blue" {
     2752            return {
     2753                0.0                     0.900 1.000 1.000
     2754                0.1111111111111111      0.800 0.983 1.000
     2755                0.2222222222222222      0.700 0.950 1.000
     2756                0.3333333333333333      0.600 0.900 1.000
     2757                0.4444444444444444      0.500 0.833 1.000
     2758                0.5555555555555556      0.400 0.750 1.000
     2759                0.6666666666666666      0.300 0.650 1.000
     2760                0.7777777777777778      0.200 0.533 1.000
     2761                0.8888888888888888      0.100 0.400 1.000
     2762                1.0                     0.000 0.250 1.000
     2763            }
     2764        }
     2765        "brown-to-blue" {
     2766            return {
     2767                0.0                             0.200   0.100   0.000
     2768                0.09090909090909091             0.400   0.187   0.000
     2769                0.18181818181818182             0.600   0.379   0.210
     2770                0.2727272727272727              0.800   0.608   0.480
     2771                0.36363636363636365             0.850   0.688   0.595
     2772                0.45454545454545453             0.950   0.855   0.808
     2773                0.5454545454545454              0.800   0.993   1.000
     2774                0.6363636363636364              0.600   0.973   1.000
     2775                0.7272727272727273              0.400   0.940   1.000
     2776                0.8181818181818182              0.200   0.893   1.000
     2777                0.9090909090909091              0.000   0.667   0.800
     2778                1.0                             0.000   0.480   0.600
     2779            }
     2780        }
     2781        "blue-to-brown" {
     2782            return {
     2783                0.0                             0.000   0.480   0.600
     2784                0.09090909090909091             0.000   0.667   0.800
     2785                0.18181818181818182             0.200   0.893   1.000
     2786                0.2727272727272727              0.400   0.940   1.000
     2787                0.36363636363636365             0.600   0.973   1.000
     2788                0.45454545454545453             0.800   0.993   1.000
     2789                0.5454545454545454              0.950   0.855   0.808
     2790                0.6363636363636364              0.850   0.688   0.595
     2791                0.7272727272727273              0.800   0.608   0.480
     2792                0.8181818181818182              0.600   0.379   0.210
     2793                0.9090909090909091              0.400   0.187   0.000
     2794                1.0                             0.200   0.100   0.000
     2795            }
     2796        }
     2797        "blue-to-orange" {
     2798            return {
     2799                0.0                             0.000   0.167   1.000
     2800                0.09090909090909091             0.100   0.400   1.000
     2801                0.18181818181818182             0.200   0.600   1.000
     2802                0.2727272727272727              0.400   0.800   1.000
     2803                0.36363636363636365             0.600   0.933   1.000
     2804                0.45454545454545453             0.800   1.000   1.000
     2805                0.5454545454545454              1.000   1.000   0.800
     2806                0.6363636363636364              1.000   0.933   0.600
     2807                0.7272727272727273              1.000   0.800   0.400
     2808                0.8181818181818182              1.000   0.600   0.200
     2809                0.9090909090909091              1.000   0.400   0.100
     2810                1.0                             1.000   0.167   0.000
     2811            }
     2812        }
     2813        "orange-to-blue" {
     2814            return {
     2815                0.0                             1.000   0.167   0.000
     2816                0.09090909090909091             1.000   0.400   0.100
     2817                0.18181818181818182             1.000   0.600   0.200
     2818                0.2727272727272727              1.000   0.800   0.400
     2819                0.36363636363636365             1.000   0.933   0.600
     2820                0.45454545454545453             1.000   1.000   0.800
     2821                0.5454545454545454              0.800   1.000   1.000
     2822                0.6363636363636364              0.600   0.933   1.000
     2823                0.7272727272727273              0.400   0.800   1.000
     2824                0.8181818181818182              0.200   0.600   1.000
     2825                0.9090909090909091              0.100   0.400   1.000
     2826                1.0                             0.000   0.167   1.000
     2827            }
     2828        }
     2829        "rainbow" {
     2830            set clist {
     2831                "#EE82EE"
     2832                "#4B0082"
     2833                "blue"
     2834                "#008000"
     2835                "yellow"
     2836                "#FFA500"
     2837                "red"
     2838            }
     2839        }
     2840        "BGYOR" {
     2841            set clist {
     2842                "blue"
     2843                "#008000"
     2844                "yellow"
     2845                "#FFA500"
     2846                "red"
     2847            }
     2848        }
     2849        "ROYGB" {
     2850            set clist {
     2851                "red"
     2852                "#FFA500"
     2853                "yellow"
     2854                "#008000"
     2855                "blue"
     2856            }
     2857        }
     2858        "RYGCB" {
     2859            set clist {
     2860                "red"
     2861                "yellow"
     2862                "green"
     2863                "cyan"
     2864                "blue"
     2865            }
     2866        }
     2867        "BCGYR" {
     2868            set clist {
     2869                "blue"
     2870                "cyan"
     2871                "green"
     2872                "yellow"
     2873                "red"
     2874            }
     2875        }
     2876        "spectral" {
     2877            return {
     2878                0.0 0.150 0.300 1.000
     2879                0.1 0.250 0.630 1.000
     2880                0.2 0.450 0.850 1.000
     2881                0.3 0.670 0.970 1.000
     2882                0.4 0.880 1.000 1.000
     2883                0.5 1.000 1.000 0.750
     2884                0.6 1.000 0.880 0.600
     2885                0.7 1.000 0.680 0.450
     2886                0.8 0.970 0.430 0.370
     2887                0.9 0.850 0.150 0.196
     2888                1.0 0.650 0.000 0.130
     2889            }
     2890        }
     2891        "green-to-magenta" {
     2892            return {
     2893                0.0 0.000 0.316 0.000
     2894                0.06666666666666667 0.000 0.526 0.000
     2895                0.13333333333333333 0.000 0.737 0.000
     2896                0.2 0.000 0.947 0.000
     2897                0.26666666666666666 0.316 1.000 0.316
     2898                0.3333333333333333 0.526 1.000 0.526
     2899                0.4 0.737 1.000 0.737
     2900                0.4666666666666667 1.000 1.000 1.000
     2901                0.5333333333333333 1.000 0.947 1.000
     2902                0.6 1.000 0.737 1.000
     2903                0.6666666666666666 1.000 0.526 1.000
     2904                0.7333333333333333 1.000 0.316 1.000
     2905                0.8 0.947 0.000 0.947
     2906                0.8666666666666667 0.737 0.000 0.737
     2907                0.9333333333333333 0.526 0.000 0.526
     2908                1.0 0.316 0.000 0.316
     2909            }
     2910        }
     2911        "greyscale" {
     2912            return {
     2913                0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0
     2914            }
     2915        }
     2916        "nanohub" {
     2917            set clist "white yellow green cyan blue magenta"
     2918        }
     2919        default {
     2920            set clist $colors
     2921        }
     2922    }
     2923    set cmap {}
     2924    for {set i 0} {$i < [llength $clist]} {incr i} {
     2925        set x [expr {double($i)/([llength $clist]-1)}]
     2926        set color [lindex $clist $i]
     2927        append cmap "$x [Color2RGB $color] "
     2928    }
     2929    return $cmap
     2930}
     2931
     2932#
     2933# BuildColormap --
     2934#
     2935itcl::body Rappture::VtkIsosurfaceViewer::BuildColormap { name stylelist } {
     2936    array set style $stylelist
     2937    set cmap [ColorsToColormap $style(-color)]
     2938    if { [llength $cmap] == 0 } {
     2939        set cmap "0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0"
     2940    }
     2941    if { ![info exists _settings(isosurfaceOpacity)] } {
     2942        set _settings(isosurfaceOpacity) $style(-opacity)
     2943    }
     2944    set max $_settings(isosurfaceOpacity)
     2945
     2946    set wmap "0.0 1.0 1.0 1.0"
     2947    SendCmd "colormap add $name { $cmap } { $wmap }"
     2948}
     2949
     2950itcl::body Rappture::VtkIsosurfaceViewer::ResetColormap { color } {
     2951    array set style {
     2952        -color BCGYR
     2953        -levels 10
     2954        -opacity 1.0
     2955    }
     2956    if { [info exists _colormap($_currentColormap)] } {
     2957        array set style $_colormap($_currentColormap)
     2958    }
     2959    set style(-color) $color
     2960    SetCurrentColormap [array get style]
     2961}
Note: See TracChangeset for help on using the changeset viewer.