Changeset 4504


Ignore:
Timestamp:
Jul 16, 2014 12:21:36 PM (10 years ago)
Author:
gah
Message:

merge transferfunctioneditor into nanovis, fix cloud with units

Location:
branches/1.3/gui/scripts
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • branches/1.3/gui/scripts/Makefile.in

    r4482 r4504  
    111111                $(srcdir)/tool.tcl \
    112112                $(srcdir)/tooltip.tcl \
     113                $(srcdir)/transferfunctioneditor.tcl \
    113114                $(srcdir)/tuples.tcl \
    114115                $(srcdir)/unirect2d.tcl \
  • branches/1.3/gui/scripts/cloud.tcl

    r4474 r4504  
    149149        foreach {x y z} $line break
    150150        foreach axis {x y z} units $_units {
    151             set value [Rappture::Units::convert [set $axis] \
     151            if { $units == "" } {
     152                set value [set $axis]
     153            } else {
     154                set value [Rappture::Units::convert [set $axis] \
    152155                        -context $units -to $units -units off]
     156            }
    153157            set $axis $value;           # Set the (x/y/z) coordinate to
    154158                                        # converted value.
  • branches/1.3/gui/scripts/field.tcl

    r4494 r4504  
    11# -*- mode: tcl; indent-tabs-mode: nil -*-
    2 
    32# ----------------------------------------------------------------------
    43#  COMPONENT: field - extracts data from an XML description of a field
     
    8281                                        # valid data.
    8382    private variable _isValidComponent; #  Array of valid components found
     83    private variable _alwaysConvertDX 0;
     84
    8485    constructor {xmlobj path} {
    8586        # defined below
     
    8889        # defined below
    8990    }
    90     public method blob { cname }
     91    public method blob { cname } 
    9192    public method components {args}
    9293    public method controls {option args}
     
    9495    public method numComponents {cname}
    9596    public method fieldlimits {}
     97    public method valueLimits { cname }
    9698    public method flowhints { cname }
    9799    public method hints {{key ""}}
     
    150152
    151153    private method AvsToVtk { cname contents }
     154    private method DicomToVtk { cname contents }
    152155    private method BuildPointsOnMesh { cname }
    153156    protected method GetAssociation { cname }
     
    318321    }
    319322    if {[info exists _comp2dx($cname)]} {
    320         return ""  ;# no mesh -- it's embedded in the blob data
     323        return ""  ;# no mesh -- it's embedded in the value data
    321324    }
    322325    if {[info exists _comp2mesh($cname)]} {
     
    362365    }
    363366    if {[info exists _comp2dx($cname)]} {
    364         error "method \"values\" is not implemented for dx file data"
     367        error "method \"values\" is not implemented for dx data"
    365368    }
    366369    if {[info exists _comp2unirect2d($cname)]} {
     
    389392    }
    390393    if {[info exists _comp2dx($cname)]} {
    391         return $_comp2dx($cname)  ;# return gzipped, base64-encoded DX data
     394        return $_comp2dx($cname)
    392395    }
    393396    if {[info exists _comp2unirect2d($cname)]} {
     
    400403    }
    401404    error "can't get field blob: Unknown component \"$cname\": should be one of [join [lsort [array names _comp2dims]] {, }]"
     405}
     406
     407itcl::body Rappture::Field::valueLimits { cname } {
     408    if { [info exists _comp2limits($cname)] } {
     409        return $_comp2limits($cname)
     410    }
     411    return ""
    402412}
    403413
     
    520530    return [list $min $max]
    521531}
     532
    522533
    523534# ----------------------------------------------------------------------
     
    789800        } elseif {[$_field element $cname.ucd] != ""} {
    790801            set type "ucd"
     802        } elseif {[$_field element $cname.dicom] != ""} {
     803            set type "dicom"
    791804        }
    792805        set _comp2style($cname) ""
     
    894907            set _dim 3
    895908            set _comp2dims($cname) "3D"
    896             if { $_viewer != "nanovis" && $_viewer != "flowvis" } {
    897                 set vtkdata  [$_field get -decode yes $cname.$type]
    898                 if { $vtkdata == "" } {
    899                     puts stderr "WARNING: No data for \"$_path.$cname.$type\""
    900                     continue;               # Ignore this component
    901                 }
    902                 if 0 {
    903                     set f [open /tmp/$_path.$cname.dx "w"]
    904                     puts -nonewline $f $vtkdata
    905                     close $f
    906                 }
    907                 set vtkdata  [Rappture::DxToVtk $vtkdata]
    908                 if 0 {
    909                     set f [open /tmp/$_path.$cname.vtk "w"]
    910                     puts -nonewline $f $vtkdata
    911                     close $f
    912                 }
     909            set data [$_field get -decode no $cname.$type]
     910            set contents [Rappture::encoding::decode -as zb64 $data]
     911            if { $contents == "" } {
     912                puts stderr "WARNING: No data for \"$_path.$cname.$type\""
     913                continue;               # Ignore this component
     914            }
     915            set vector ""
     916            if 0 {
     917                set f [open /tmp/$_path.$cname.dx "w"]
     918                puts -nonewline $f $contents
     919                close $f
     920            }
     921            # This is temporary.  I put a check for this in the DxToVtk
     922            # parser. 
     923            if { [string range $contents  0 3] == "<DX>" } {
     924                set contents [string range $contents 4 end]
     925            }
     926            if { [catch { Rappture::DxToVtk $contents } vtkdata] == 0 } {
    913927                ReadVtkDataSet $cname $vtkdata
     928            } else {
     929                puts stderr "Can't parse dx data: $vtkdata"
     930            }
     931            if 0 {
     932                set f [open /tmp/$_path.$cname.vtk "w"]
     933                puts -nonewline $f $vtkdata
     934                close $f
     935            }
     936            if { $_alwaysConvertDX ||
     937                 ($_viewer != "nanovis" && $_viewer != "flowvis") } {
    914938                set _type "vtk"
    915939                set _comp2vtk($cname) $vtkdata
    916940            } else {
    917                 set contents [$_field get -decode no $cname.$type]
    918                 if { $contents == "" } {
    919                     puts stderr "WARNING: No data for \"$_path.$cname.$type\""
    920                     continue;               # Ignore this component
    921                 }
    922941                set _type "dx"
    923                 set _comp2dx($cname) $contents
     942                set _comp2dx($cname) $data
    924943            }
    925944            set _comp2style($cname) [$_field get $cname.style]
     
    928947                    [Rappture::FlowHints ::\#auto $_field $cname $_units]
    929948            }
     949            set _dim 3
     950            incr _counter
     951        } elseif { $type == "dicom"} {
     952            set contents [$_field get $cname.dicom]
     953            if { $contents == "" } {
     954                continue;               # Ignore this component
     955            }
     956            set viewer [$_field get "about.view"]
     957            if { $viewer != "" } {
     958                set _viewer $viewer
     959            }
     960            set vtkdata [DicomToVtk $cname $contents]
     961            if { $_viewer == "" } {
     962                set _viewer [expr {($_dim == 3) ? "vtkvolume" : "vtkimage"}]
     963            }
     964            set _comp2vtk($cname) $vtkdata
     965            set _comp2style($cname) [$_field get $cname.style]
    930966            incr _counter
    931967        } elseif { $type == "ucd"} {
     
    941977        }
    942978        set _isValidComponent($cname) 1
     979        #puts stderr "Field $cname type is: $_type"
    943980    }
    944981    if { [array size _isValidComponent] == 0 } {
     
    15081545        # sort x-coords in increasing order
    15091546        $xv sort $yv
    1510        
    15111547        set _comp2dims($cname) "1D"
    15121548        set _comp2xy($cname) [list $xv $yv]
     
    16411677    file delete $tmpfile
    16421678    return $vtkdata
     1679}
     1680
     1681itcl::body Rappture::Field::DicomToVtk { cname path } {
     1682    package require vtk
     1683
     1684    if { ![file exists $path] } {
     1685        puts stderr "path \"$path\" doesn't exist."
     1686        return 0
     1687    }
     1688
     1689    if { [file isdir $path] } {
     1690        set files [glob -nocomplain $path/*.dcm]
     1691        if { [llength $files] == 0 } {
     1692            set files [glob -nocomplain $path/*]
     1693            if { [llength $files] == 0 } {
     1694                puts stderr "no dicom files found in \"$path\""
     1695                return 0
     1696            }
     1697        }
     1698
     1699        #array set data [Rappture::DicomToVtk files $files]
     1700        array set data [Rappture::DicomToVtk dir $path]
     1701    } else {
     1702        array set data [Rappture::DicomToVtk files [list $path]]
     1703    }
     1704
     1705    foreach key [array names data] {
     1706        if {$key == "vtkdata"} {
     1707            if {1} {
     1708                set f [open /tmp/$cname.vtk "w"]
     1709                fconfigure $f -translation binary -encoding binary
     1710                puts -nonewline $f $data(vtkdata)
     1711                close $f
     1712            }
     1713        } else {
     1714            puts stderr "$key = \"$data($key)\""
     1715        }
     1716    }
     1717
     1718    # Save viewer choice
     1719    set viewer $_viewer
     1720    ReadVtkDataSet $cname $data(vtkdata)
     1721    # Restore viewer choice (ReadVtkDataSet wants to set it to contour/isosurface)
     1722    set _viewer $viewer
     1723    return $data(vtkdata)
    16431724}
    16441725
  • branches/1.3/gui/scripts/fieldresult.tcl

    r4481 r4504  
    156156# ----------------------------------------------------------------------
    157157itcl::body Rappture::FieldResult::add {dataobj {settings ""}} {
     158    if { ![info exists itk_component(renderer)] } {
     159        puts stderr "add: no renderer created."
     160        return
     161    }
    158162    eval $itk_component(renderer) add $dataobj [list $settings]
    159163}
     
    166170# ----------------------------------------------------------------------
    167171itcl::body Rappture::FieldResult::get {} {
     172    if { ![info exists itk_component(renderer)] } {
     173        puts stderr "get: no renderer created."
     174        return
     175    }
    168176    return [$itk_component(renderer) get]
    169177}
     
    191199# ----------------------------------------------------------------------
    192200itcl::body Rappture::FieldResult::scale {args} {
     201    if { ![info exists itk_component(renderer)] } {
     202        puts stderr "scale: no renderer created."
     203        return
     204    }
    193205    eval $itk_component(renderer) scale $args
    194206}
     
    205217# ----------------------------------------------------------------------
    206218itcl::body Rappture::FieldResult::download {option args} {
     219    if { ![info exists itk_component(renderer)] } {
     220        puts stderr "download: no renderer created."
     221        return
     222    }
    207223    eval $itk_component(renderer) download $option $args
    208224}
    209225
    210226itcl::body Rappture::FieldResult::snap { w h } {
     227    if { ![info exists itk_component(renderer)] } {
     228        puts stderr "snap: no renderer created."
     229        return
     230    }
    211231    return [$itk_component(renderer) snap $w $h]
    212232}
  • branches/1.3/gui/scripts/nanovisviewer.tcl

    r4500 r4504  
    11# -*- mode: tcl; indent-tabs-mode: nil -*-
    2 
    32# ----------------------------------------------------------------------
    43#  COMPONENT: nanovisviewer - 3D volume rendering
     
    7675    public method isconnected {}
    7776    public method limits { tf }
    78     public method overmarker { m x }
    7977    public method parameters {title args} {
    8078        # do nothing
    8179    }
    82     public method rmdupmarker { m x }
    8380    public method scale {args}
    84     public method updatetransferfuncs {}
    85 
    86     protected method Connect {}
    87     protected method CurrentDatasets {{what -all}}
    88     protected method Disconnect {}
    89     protected method DoResize {}
    90     protected method FixLegend {}
    91     protected method AdjustSetting {what {value ""}}
    92     protected method InitSettings { args }
    93     protected method Pan {option x y}
    94     protected method Rebuild {}
    95     protected method ReceiveData { args }
    96     protected method ReceiveImage { args }
    97     protected method ReceiveLegend { tf vmin vmax size }
    98     protected method Rotate {option x y}
    99     protected method SendTransferFuncs {}
    100     protected method Slice {option args}
    101     protected method SlicerTip {axis}
    102     protected method Zoom {option}
     81    public method updateTransferFunctions {}
    10382
    10483    # The following methods are only used by this class.
    105     private method AddIsoMarker { x y }
     84
     85    private method AddNewMarker { x y }
     86    private method AdjustSetting {what {value ""}}
    10687    private method BuildCameraTab {}
    10788    private method BuildCutplanesTab {}
    10889    private method BuildViewTab {}
     90    private method BuildVolumeComponents {}
    10991    private method BuildVolumeTab {}
    110     private method ResetColormap { color }
    111     private method ComputeTransferFunc { tf }
     92    private method ComputeAlphamap { cname }
     93    private method ComputeTransferFunction { cname }
     94    private method Connect {}
     95    private method CurrentDatasets {{what -all}}
     96    private method Disconnect {}
     97    private method DoResize {}
     98    private method DrawLegend { cname }
     99    private method EventuallyRedrawLegend { }
    112100    private method EventuallyResize { w h }
    113     private method EventuallyResizeLegend { }
    114     private method NameTransferFunc { dataobj comp }
     101    private method FixLegend {}
     102    private method GetAlphamap { cname color }
     103    private method GetColormap { cname color }
     104    private method GetDatasetsWithComponent { cname }
     105    private method GetVolumeInfo { w }
     106    private method HideAllMarkers {}
     107    private method InitComponentSettings { cname }
     108    private method InitSettings { args }
     109    private method NameToAlphamap { name }
     110    private method NameTransferFunction { dataobj comp }
     111    private method Pan {option x y}
    115112    private method PanCamera {}
    116     private method ParseLevelsOption { tf levels }
    117     private method ParseMarkersOption { tf markers }
    118     private method volume { tag name }
    119     private method GetVolumeInfo { w }
     113    private method ParseLevelsOption { cname levels }
     114    private method ParseMarkersOption { cname markers }
     115    private method Rebuild {}
     116    private method ReceiveData { args }
     117    private method ReceiveImage { args }
     118    private method ReceiveLegend { tf vmin vmax size }
     119    private method RemoveMarker { x y }
     120    private method ResetColormap { cname color }
     121    private method Rotate {option x y}
     122    private method SendTransferFunctions {}
    120123    private method SetOrientation { side }
     124    private method Slice {option args}
     125    private method SlicerTip {axis}
     126    private method SwitchComponent { cname }
     127    private method ToggleVolume { tag name }
     128    private method Zoom {option}
     129    private method ViewToQuaternion {} {
     130        return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)]
     131    }
    121132
    122133    private variable _arcball ""
    123134
    124135    private variable _dlist ""     ;# list of data objects
    125     private variable _allDataObjs
    126136    private variable _obj2ovride   ;# maps dataobj => style override
    127137    private variable _serverDatasets   ;# contains all the dataobj-component
    128138                                   ;# to volumes in the server
    129     private variable _serverTfs    ;# contains all the transfer functions
    130                                    ;# in the server.
    131     private variable _recvdDatasets    ;# list of data objs to send to server
    132     private variable _dataset2style    ;# maps dataobj-component to transfunc
    133     private variable _style2datasets   ;# maps tf back to list of
    134                                     # dataobj-components using the tf.
    135 
    136     private variable _reset 1;          # Connection to server has been reset
    137     private variable _click        ;# info used for rotate operations
    138     private variable _limits       ;# autoscale min/max for all axes
    139     private variable _view         ;# view params for 3D view
    140     private variable _isomarkers    ;# array of isosurface level values 0..1
     139    private variable _recvdDatasets;    # list of data objs to send to server
     140    private variable _dataset2style;    # maps dataobj-component to transfunc
     141    private variable _style2datasets;   # maps tf back to list of
     142                                        # dataobj-components using the tf.
     143
     144    private variable _reset 1;          # Connection to server has been reset.
     145    private variable _click;            # Info used for rotate operations.
     146    private variable _limits;           # Autoscale min/max for all axes
     147    private variable _view;             # View params for 3D view
     148    private variable _parsedFunction
     149    private variable _transferFunctionEditors
    141150    private variable  _settings
    142     # Array of transfer functions in server.  If 0 the transfer has been
    143     # defined but not loaded.  If 1 the transfer function has been named
    144     # and loaded.
    145     private variable _activeTfs
    146     private variable _first ""     ;# This is the topmost volume.
    147151    private variable _alphamap
    148 
    149     # This
    150     # indicates which isomarkers and transfer
    151     # function to use when changing markers,
    152     # opacity, or thickness.
     152    private variable _widget
     153
     154    private variable _first "" ;        # This is the topmost volume.
     155    private variable _current "";       # Currently selected component
     156    private variable _volcomponents   ; # Array of components found
     157    private variable _componentsList   ; # Array of components found
     158    private variable _cname2style
     159    private variable _cname2transferFunction
     160    private variable _cname2defaultcolormap
     161    private variable _cname2defaultalphamap
     162
    153163    common _downloadPopup          ;# download options from popup
    154164    private common _hardcopy
     
    177187    $_dispatcher register !send_transfunc
    178188    $_dispatcher dispatch $this !send_transfunc \
    179         "[itcl::code $this SendTransferFuncs]; list"
     189        "[itcl::code $this SendTransferFunctions]; list"
    180190
    181191    # Rebuild event
     
    196206    # Initialize the view to some default parameters.
    197207    array set _view {
    198         qw      0.853553
    199         qx      -0.353553
    200         qy      0.353553
    201         qz      0.146447
    202         zoom    1.0
    203         xpan    0
    204         ypan    0
     208        -qw      0.853553
     209        -qx      -0.353553
     210        -qy      0.353553
     211        -qz      0.146447
     212        -xpan    0
     213        -ypan    0
     214        -zoom    1.0
    205215    }
    206216    set _arcball [blt::arcball create 100 100]
    207     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    208     $_arcball quaternion $q
    209 
    210     set _limits(vmin) 0.0
    211     set _limits(vmax) 1.0
     217    $_arcball quaternion [ViewToQuaternion]
     218
     219    set _limits(v) [list 0.0 1.0]
    212220    set _reset 1
    213221
    214     array set _settings [subst {
    215         $this-qw                $_view(qw)
    216         $this-qx                $_view(qx)
    217         $this-qy                $_view(qy)
    218         $this-qz                $_view(qz)
    219         $this-zoom              $_view(zoom)   
    220         $this-xpan              $_view(xpan)
    221         $this-ypan              $_view(ypan)
    222         $this-volume            1
    223         $this-xcutplane         0
    224         $this-xcutposition      0
    225         $this-ycutplane         0
    226         $this-ycutposition      0
    227         $this-zcutplane         0
    228         $this-zcutposition      0
    229     }]
    230 
     222    array set _settings {
     223        -axesvisible       1
     224        -colormap          default
     225        -cutplanesvisible  0
     226        -gridvisible       0
     227        -isosurfaceshading 0
     228        -legendvisible     1
     229        -light2side        1
     230        -outlinevisible    0
     231        -qw                0.853553
     232        -qx                -0.353553
     233        -qy                0.353553
     234        -qz                0.146447
     235        -thickness         350
     236        -volume            1
     237        -volumeopacity     0.5
     238        -volumevisible     1
     239        -xcutplaneposition 50
     240        -xcutplanevisible  1
     241        -xpan              0
     242        -ycutplaneposition 50
     243        -ycutplanevisible  1
     244        -ypan              0
     245        -zcutplaneposition 50
     246        -zcutplanevisible  1
     247        -zoom              1.0
     248    }
     249    array set _widget {
     250        -volumeopacity     50
     251    }
    231252    itk_component add 3dview {
    232253        label $itk_component(plotarea).view -image $_image(plot) \
     
    249270    }
    250271    pack $itk_component(reset) -side top -padx 2 -pady 2
    251     Rappture::Tooltip::for $itk_component(reset) "Reset the view to the default zoom level"
     272    Rappture::Tooltip::for $itk_component(reset) \
     273        "Reset the view to the default zoom level"
    252274
    253275    itk_component add zoomin {
     
    279301            -onimage [Rappture::icon volume-on] \
    280302            -offimage [Rappture::icon volume-off] \
    281             -command [itcl::code $this AdjustSetting volume] \
    282             -variable [itcl::scope _settings($this-volume)]
     303            -command [itcl::code $this AdjustSetting -volume] \
     304            -variable [itcl::scope _settings(-volume)]
    283305    }
    284306    $itk_component(volume) select
     
    286308        "Toggle the volume cloud on/off"
    287309    pack $itk_component(volume) -padx 2 -pady 2
     310
     311    itk_component add cutplane {
     312        Rappture::PushButton $f.cutplane \
     313            -onimage [Rappture::icon cutbutton] \
     314            -offimage [Rappture::icon cutbutton] \
     315            -variable [itcl::scope _settings(-cutplanesvisible)] \
     316            -command [itcl::code $this AdjustSetting -cutplanesvisible]
     317    }
     318    Rappture::Tooltip::for $itk_component(cutplane) \
     319        "Show/Hide cutplanes"
     320    pack $itk_component(cutplane) -padx 2 -pady 2
    288321
    289322    if { [catch {
     
    298331
    299332    # Legend
    300 
    301333    set _image(legend) [image create photo]
    302334    itk_component add legend {
     
    308340    }
    309341    bind $itk_component(legend) <Configure> \
    310         [itcl::code $this EventuallyResizeLegend]
     342        [itcl::code $this EventuallyRedrawLegend]
     343    bind $itk_component(legend) <KeyPress-Delete> \
     344        [itcl::code $this RemoveMarker %x %y]
     345    bind $itk_component(legend) <Enter> \
     346        [list focus $itk_component(legend)]
    311347
    312348    # Hack around the Tk panewindow.  The problem is that the requested
     
    387423    image delete $_image(legend)
    388424    image delete $_image(download)
     425    foreach name [array names _transferFunctionEditors] {
     426        itcl::delete object $_transferFunctionEditors($cname)
     427    }
    389428    catch { blt::arcball destroy $_arcball }
    390     array unset _settings $this-*
     429    array unset _settings
    391430}
    392431
     
    420459    if {$pos < 0} {
    421460        lappend _dlist $dataobj
    422         set _allDataObjs($dataobj) 1
    423461        set _obj2ovride($dataobj-color) $params(-color)
    424462        set _obj2ovride($dataobj-width) $params(-width)
     
    497535        if { $pos >= 0 } {
    498536            set _dlist [lreplace $_dlist $pos $pos]
    499             array unset _limits $dataobj*
    500537            array unset _obj2ovride $dataobj-*
     538            array unset _dataset2style $dataobj-*
    501539            set changed 1
    502540        }
     
    518556# ----------------------------------------------------------------------
    519557itcl::body Rappture::NanovisViewer::scale {args} {
    520     foreach val {xmin xmax ymin ymax zmin zmax vmin vmax} {
    521         set _limits($val) ""
    522     }
     558    array set styles {
     559        -color BCGYR
     560        -levels 6
     561        -markers ""
     562    }
     563    array unset _limits
     564    array unset _volcomponents
    523565    foreach dataobj $args {
    524566        if { ![$dataobj isvalid] } {
    525567            continue;                     # Object doesn't contain valid data.
    526568        }
     569        foreach cname [$dataobj components] {
     570            if { ![info exists _volcomponents($cname)] } {
     571                lappend _componentsList $cname
     572                array set styles [lindex [$dataobj components -style $cname] 0]
     573                set cmap [ColorsToColormap $styles(-color)]
     574                set _cname2defaultcolormap($cname) $cmap
     575                set _settings($cname-colormap) $styles(-color)
     576            }
     577            lappend _volcomponents($cname) $dataobj-$cname
     578            array unset limits
     579            array set limits [$dataobj valueLimits $cname]
     580            set _limits($cname) $limits(v)
     581        }
    527582        foreach axis {x y z v} {
    528583            foreach { min max } [$dataobj limits $axis] break
    529584            if {"" != $min && "" != $max} {
    530                 if {"" == $_limits(${axis}min)} {
    531                     set _limits(${axis}min) $min
    532                     set _limits(${axis}max) $max
     585                if { ![info exists _limits($axis)] } {
     586                    set _limits($axis) [list $min $max]
    533587                } else {
    534                     if {$min < $_limits(${axis}min)} {
    535                         set _limits(${axis}min) $min
     588                    foreach {amin amax} $_limits($axis) break
     589                    if {$min < $amin} {
     590                        set amin $min
    536591                    }
    537                     if {$max > $_limits(${axis}max)} {
    538                         set _limits(${axis}max) $max
     592                    if {$max > $amax} {
     593                        set amax $max
    539594                    }
     595                    set _limits($axis) [list $amin $amax]
    540596                }
    541597            }
    542598        }
    543599    }
     600    BuildVolumeComponents
    544601}
    545602
     
    660717
    661718# ----------------------------------------------------------------------
    662 # USAGE: SendTransferFuncs
    663 # ----------------------------------------------------------------------
    664 itcl::body Rappture::NanovisViewer::SendTransferFuncs {} {
    665     if { $_first == "" } {
    666         puts stderr "first not set"
    667         return
    668     }
    669     # Ensure that the global opacity and thickness settings (in the slider
    670     # settings widgets) are used for the active transfer-function.  Update
    671     # the values in the _settings varible.
    672     set opacity [expr { double($_settings($this-opacity)) * 0.01 }]
    673     # Scale values between 0.00001 and 0.01000
    674     set thickness [expr {double($_settings($this-thickness)) * 0.0001}]
    675 
    676     foreach tag [CurrentDatasets] {
    677         if { ![info exists _serverDatasets($tag)] || !$_serverDatasets($tag) } {
    678             # The volume hasn't reached the server yet.  How did we get
    679             # here?
    680             puts stderr "Don't have $tag in _serverDatasets"
    681             continue
    682         }
    683         if { ![info exists _dataset2style($tag)] } {
    684             puts stderr "don't have style for volume $tag"
    685             continue;                        # How does this happen?
    686         }
    687         set tf $_dataset2style($tag)
    688         set _settings($this-$tf-opacity) $opacity
    689         set _settings($this-$tf-thickness) $thickness
    690         ComputeTransferFunc $tf
    691         # FIXME: Need to the send information as to what transfer functions
    692         #        to update so that we only update the transfer function
    693         #        as necessary.  Right now, all transfer functions are
    694         #        updated. This makes moving the isomarker slider chunky.
    695         if { ![info exists _activeTfs($tf)] || !$_activeTfs($tf) } {
    696             set _activeTfs($tf) 1
    697         }
    698         SendCmd "volume shading transfunc $tf $tag"
     719# USAGE: SendTransferFunctions
     720# ----------------------------------------------------------------------
     721itcl::body Rappture::NanovisViewer::SendTransferFunctions {} {
     722    foreach cname [array names _volcomponents] {
     723        ComputeTransferFunction $cname
    699724    }
    700725    FixLegend
     
    727752
    728753#
    729 # ReceiveLegend --
    730 #
    731 #       The procedure is the response from the render server to each "legend"
    732 #       command.  The server sends back a "legend" command invoked our
    733 #       the slave interpreter.  The purpose is to collect data of the image
    734 #       representing the legend in the canvas.  In addition, the isomarkers
    735 #       of the active transfer function are displayed.
    736 #
    737 #       I don't know is this is the right place to display the isomarkers.
    738 #       I don't know all the different paths used to draw the plot. There's
    739 #       "Rebuild", "add", etc.
    740 #
    741 itcl::body Rappture::NanovisViewer::ReceiveLegend { tf vmin vmax size } {
    742     if { ![isconnected] } {
    743         return
    744     }
    745     set bytes [ReceiveBytes $size]
    746     $_image(legend) configure -data $bytes
    747     ReceiveEcho <<line "<read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
     754# DrawLegend --
     755#
     756itcl::body Rappture::NanovisViewer::DrawLegend { cname } {
    748757    set c $itk_component(legend)
    749758    set w [winfo width $c]
     
    751760    set lx 10
    752761    set ly [expr {$h - 1}]
    753     if {"" == [$c find withtag transfunc]} {
     762    if {"" == [$c find withtag colorbar]} {
    754763        $c create image 10 10 -anchor nw \
    755             -image $_image(legend) -tags transfunc
     764            -image $_image(legend) -tags colorbar
    756765        $c create text $lx $ly -anchor sw \
    757             -fill $itk_option(-plotforeground) -tags "limits vmin"
     766            -fill $itk_option(-plotforeground) -tags "limits text vmin"
    758767        $c create text [expr {$w-$lx}] $ly -anchor se \
    759             -fill $itk_option(-plotforeground) -tags "limits vmax"
    760         $c lower transfunc
    761         $c bind transfunc <ButtonRelease-1> \
    762             [itcl::code $this AddIsoMarker %x %y]
    763     }
    764     # Display the markers used by the active transfer function.
    765 
    766     array set limits [limits $tf]
    767     $c itemconfigure vmin -text [format %g $limits(min)]
     768            -fill $itk_option(-plotforeground) -tags "limits text vmax"
     769        $c create text [expr {$w/2}] $ly -anchor s \
     770            -fill $itk_option(-plotforeground) -tags "limits text title"
     771        $c lower colorbar
     772        $c bind colorbar <ButtonRelease-1> [itcl::code $this AddNewMarker %x %y]
     773    }
     774
     775    # Display the markers used by the current transfer function.
     776    HideAllMarkers
     777    $_transferFunctionEditors($cname) showMarkers $_limits($cname)
     778
     779    foreach {min max} $_limits($cname) break
     780    $c itemconfigure vmin -text [format %g $min]
    768781    $c coords vmin $lx $ly
    769782
    770     $c itemconfigure vmax -text [format %g $limits(max)]
     783    $c itemconfigure vmax -text [format %g $max]
    771784    $c coords vmax [expr {$w-$lx}] $ly
    772785
    773     if { [info exists _isomarkers($tf)] } {
    774         foreach m $_isomarkers($tf) {
    775             $m visible yes
    776         }
    777     }
     786    set title [$_first hints label]
     787    set units [$_first hints units]
     788    if { $units != "" } {
     789        set title "$title ($units)"
     790    }
     791    $c itemconfigure title -text $title
     792    $c coords title [expr {$w/2}] $ly
    778793
    779794    # The colormap may have changed. Resync the slicers with the colormap.
    780795    set datasets [CurrentDatasets -cutplanes]
    781     SendCmd "volume data state $_settings($this-volume) $datasets"
    782796
    783797    # Adjust the cutplane for only the first component in the topmost volume
     
    787801        # Turn off cutplanes for all volumes
    788802        SendCmd "cutplane state 0 $axis"
    789         if { $_settings($this-${axis}cutplane) } {
     803        if { $_settings(-${axis}cutplanevisible) } {
    790804            # Turn on cutplane for this particular volume and set the position
    791805            SendCmd "cutplane state 1 $axis $tag"
    792             set pos [expr {0.01*$_settings($this-${axis}cutposition)}]
     806            set pos [expr {0.01*$_settings(-${axis}cutplaneposition)}]
    793807            SendCmd "cutplane position $pos $axis $tag"
    794808        }
    795809    }
     810}
     811
     812#
     813#
     814# ReceiveLegend --
     815#
     816#       The procedure is the response from the render server to each "legend"
     817#       command.  The server sends back a "legend" command invoked our
     818#       the slave interpreter.  The purpose is to collect data of the image
     819#       representing the legend in the canvas.  In addition, the
     820#       active transfer function is displayed.
     821#
     822#
     823itcl::body Rappture::NanovisViewer::ReceiveLegend { cname vmin vmax size } {
     824    if { ![isconnected] } {
     825        return
     826    }
     827    set bytes [ReceiveBytes $size]
     828    $_image(legend) configure -data $bytes
     829    ReceiveEcho <<line "<read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
     830
     831    DrawLegend $_current
    796832}
    797833
     
    833869    set dataobj [lindex $parts 0]
    834870    set _serverDatasets($tag) 1
    835     if { $_settings($this-volume) && $dataobj == $_first } {
     871    if { $_settings(-volumevisible) && $dataobj == $_first } {
    836872        SendCmd "volume state 1 $tag"
    837873    }
    838     set _limits($tag-min)  $info(min);  # Minimum value of the volume.
    839     set _limits($tag-max)  $info(max);  # Maximum value of the volume.
    840     set _limits(vmin)      $info(vmin); # Overall minimum value.
    841     set _limits(vmax)      $info(vmax); # Overall maximum value.
     874    set _limits($tag) [list $info(min)  $info(max)]
     875    set _limits(v)    [list $info(vmin) $info(vmax)]
    842876
    843877    unset _recvdDatasets($tag)
    844878    if { [array size _recvdDatasets] == 0 } {
    845         # The active transfer function is by default the first component of
    846         # the first data object.  This assumes that the data is always
    847         # successfully transferred.
    848         updatetransferfuncs
     879        updateTransferFunctions
    849880    }
    850881}
     
    869900    # generates a new call to Rebuild).   
    870901    StartBufferingCommands
    871 
    872     # Hide all the isomarkers. Can't remove them. Have to remember the
    873     # settings since the user may have created/deleted/moved markers.
    874 
    875     foreach tf [array names _isomarkers] {
    876         foreach m $_isomarkers($tf) {
    877             $m visible no
    878         }
    879     }
    880902
    881903    if { $_width != $w || $_height != $h || $_reset } {
     
    895917                    }
    896918                    set data [$dataobj blob $cname]
     919                    if 0 {
     920                        set f [open "/tmp/values-$cname.txt" "w"]
     921                        puts $f [$dataobj values $cname]
     922                        close $f
     923                    }
    897924                } else {
    898925                    set data [$dataobj vtkdata $cname]
     
    920947                set _serverDatasets($tag) 0
    921948            }
    922             NameTransferFunc $dataobj $cname
     949            NameTransferFunction $dataobj $cname
    923950        }
    924951    }
     
    928955        # Reset the camera and other view parameters
    929956        #
    930         set _settings($this-qw)    $_view(qw)
    931         set _settings($this-qx)    $_view(qx)
    932         set _settings($this-qy)    $_view(qy)
    933         set _settings($this-qz)    $_view(qz)
    934         set _settings($this-xpan)  $_view(xpan)
    935         set _settings($this-ypan)  $_view(ypan)
    936         set _settings($this-zoom)  $_view(zoom)
    937 
    938         set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     957        set _settings(-qw)    $_view(-qw)
     958        set _settings(-qx)    $_view(-qx)
     959        set _settings(-qy)    $_view(-qy)
     960        set _settings(-qz)    $_view(-qz)
     961        set _settings(-xpan)  $_view(-xpan)
     962        set _settings(-ypan)  $_view(-ypan)
     963        set _settings(-zoom)  $_view(-zoom)
     964
     965        set q [ViewToQuaternion]
    939966        $_arcball quaternion $q
    940967        SendCmd "camera orient $q"
    941968        SendCmd "camera reset"
    942969        PanCamera
    943         SendCmd "camera zoom $_view(zoom)"
    944         InitSettings light2side light transp isosurface grid axes
     970        SendCmd "camera zoom $_view(-zoom)"
    945971       
     972        #cutplane state 0 all
    946973        foreach axis {x y z} {
    947974            # Turn off cutplanes for all volumes
    948975            SendCmd "cutplane state 0 $axis"
    949976        }
     977
     978        InitSettings -light2side -light -volumeopacity \
     979            -isosurfaceshading -gridvisible -axesvisible \
     980            -current
     981
    950982        if {"" != $_first} {
    951983            set axis [$_first hints updir]
     
    960992    }
    961993    # Outline seems to need to be reset every update.
    962     InitSettings outline
     994    InitSettings -outlinevisible -cutplanesvisible
    963995    # nothing to send -- activate the proper ivol
    964996    SendCmd "volume state 0"
     
    9721004        set cname [lindex [$_first components] 0]
    9731005        if { [info exists _serverDatasets($_first-$cname)] } {
    974             updatetransferfuncs
     1006            updateTransferFunctions
    9751007        }
    9761008    }
     
    10211053    switch -- $option {
    10221054        "in" {
    1023             set _view(zoom) [expr {$_view(zoom)*1.25}]
    1024             set _settings($this-zoom) $_view(zoom)
    1025             SendCmd "camera zoom $_view(zoom)"
     1055            set _view(-zoom) [expr {$_view(-zoom)*1.25}]
     1056            set _settings(-zoom) $_view(-zoom)
     1057            SendCmd "camera zoom $_view(-zoom)"
    10261058        }
    10271059        "out" {
    1028             set _view(zoom) [expr {$_view(zoom)*0.8}]
    1029             set _settings($this-zoom) $_view(zoom)
    1030             SendCmd "camera zoom $_view(zoom)"
     1060            set _view(-zoom) [expr {$_view(-zoom)*0.8}]
     1061            set _settings(-zoom) $_view(-zoom)
     1062            SendCmd "camera zoom $_view(-zoom)"
    10311063        }
    10321064        "reset" {
    10331065            array set _view {
    1034                 qw      0.853553
    1035                 qx      -0.353553
    1036                 qy      0.353553
    1037                 qz      0.146447
    1038                 zoom    1.0
    1039                 xpan   0
    1040                 ypan   0
     1066                -qw      0.853553
     1067                -qx      -0.353553
     1068                -qy      0.353553
     1069                -qz      0.146447
     1070                -xpan    0
     1071                -ypan    0
     1072                -zoom    1.0
    10411073            }
    10421074            if { $_first != "" } {
     
    10461078                }
    10471079            }
    1048             set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     1080            set q [ViewToQuaternion]         
    10491081            $_arcball quaternion $q
    10501082            SendCmd "camera orient $q"
    10511083            SendCmd "camera reset"
    1052             set _settings($this-qw)    $_view(qw)
    1053             set _settings($this-qx)    $_view(qx)
    1054             set _settings($this-qy)    $_view(qy)
    1055             set _settings($this-qz)    $_view(qz)
    1056             set _settings($this-xpan)  $_view(xpan)
    1057             set _settings($this-ypan)  $_view(ypan)
    1058             set _settings($this-zoom)  $_view(zoom)
     1084            set _settings(-qw)    $_view(-qw)
     1085            set _settings(-qx)    $_view(-qx)
     1086            set _settings(-qy)    $_view(-qy)
     1087            set _settings(-qz)    $_view(-qz)
     1088            set _settings(-xpan)  $_view(-xpan)
     1089            set _settings(-ypan)  $_view(-ypan)
     1090            set _settings(-zoom)  $_view(-zoom)
    10591091        }
    10601092    }
     
    10621094
    10631095itcl::body Rappture::NanovisViewer::PanCamera {} {
    1064     #set x [expr ($_view(xpan)) / $_limits(xrange)]
    1065     #set y [expr ($_view(ypan)) / $_limits(yrange)]
    1066     set x $_view(xpan)
    1067     set y $_view(ypan)
     1096    set x $_view(-xpan)
     1097    set y $_view(-ypan)
    10681098    SendCmd "camera pan $x $y"
    10691099}
     
    11041134
    11051135                set q [$_arcball rotate $x $y $_click(x) $_click(y)]
    1106                 foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break
    1107                 set _settings($this-qw) $_view(qw)
    1108                 set _settings($this-qx) $_view(qx)
    1109                 set _settings($this-qy) $_view(qy)
    1110                 set _settings($this-qz) $_view(qz)
     1136                foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break
     1137                set _settings(-qw) $_view(-qw)
     1138                set _settings(-qx) $_view(-qx)
     1139                set _settings(-qy) $_view(-qy)
     1140                set _settings(-qz) $_view(-qz)
    11111141                SendCmd "camera orient $q"
    11121142
     
    11411171        set x [expr $x / double($w)]
    11421172        set y [expr $y / double($h)]
    1143         set _view(xpan) [expr $_view(xpan) + $x]
    1144         set _view(ypan) [expr $_view(ypan) + $y]
     1173        set _view(-xpan) [expr $_view(-xpan) + $x]
     1174        set _view(-ypan) [expr $_view(-ypan) + $y]
    11451175        PanCamera
    1146         set _settings($this-xpan) $_view(xpan)
    1147         set _settings($this-ypan) $_view(ypan)
     1176        set _settings(-xpan) $_view(-xpan)
     1177        set _settings(-ypan) $_view(-ypan)
    11481178        return
    11491179    }
     
    11581188        set _click(x) $x
    11591189        set _click(y) $y
    1160         set _view(xpan) [expr $_view(xpan) - $dx]
    1161         set _view(ypan) [expr $_view(ypan) - $dy]
     1190        set _view(-xpan) [expr $_view(-xpan) - $dx]
     1191        set _view(-ypan) [expr $_view(-ypan) - $dy]
    11621192        PanCamera
    1163         set _settings($this-xpan) $_view(xpan)
    1164         set _settings($this-ypan) $_view(ypan)
     1193        set _settings(-xpan) $_view(-xpan)
     1194        set _settings(-ypan) $_view(-ypan)
    11651195    }
    11661196    if { $option == "release" } {
     
    11941224    }
    11951225    switch -- $what {
    1196         light {
    1197             set val $_settings($this-light)
     1226        "-axesvisible" {
     1227            SendCmd "axis visible $_settings($what)"
     1228        }
     1229        "-colormap" {
     1230            set color [$itk_component(colormap) value]
     1231            set _settings($what) $color
     1232            set _settings($_current${what}) $color
     1233            ResetColormap $_current $color
     1234        }
     1235        "-current" {
     1236            set cname [$itk_component(volcomponents) value]
     1237            SwitchComponent $cname
     1238        }
     1239        "-cutplanesvisible" {
     1240            set bool $_settings($what)
     1241            set datasets [CurrentDatasets -cutplanes]
     1242            set tag [lindex $datasets 0]
     1243            SendCmd "cutplane visible $bool $tag"
     1244        }
     1245        "-gridvisible" {
     1246            SendCmd "grid visible $_settings($what)"
     1247        }
     1248        "-isosurfaceshading" {
     1249            SendCmd "volume shading isosurface $_settings($what)"
     1250        }
     1251        "-legendvisible" {
     1252            if { $_settings($what) } {
     1253                blt::table $itk_component(plotarea) \
     1254                    0,0 $itk_component(3dview) -fill both \
     1255                    1,0 $itk_component(legend) -fill x
     1256                blt::table configure $itk_component(plotarea) r1 -resize none
     1257            } else {
     1258                blt::table forget $itk_component(legend)
     1259            }
     1260        }
     1261        "-light" {
     1262            set val $_settings($what)
    11981263            set diffuse [expr {0.01*$val}]
    11991264            set ambient [expr {1.0-$diffuse}]
     
    12051270            SendCmd "volume shading specularExp $specularExp"
    12061271        }
    1207         light2side {
    1208             set val $_settings($this-light2side)
     1272        "-light2side" {
     1273            set val $_settings($what)
    12091274            SendCmd "volume shading light2side $val"
    12101275        }
    1211         transp {
    1212             set val $_settings($this-transp)
    1213             set sval [expr { 0.01 * double($val) }]
    1214             SendCmd "volume shading opacity $sval"
    1215         }
    1216         opacity {
    1217             set val $_settings($this-opacity)
    1218             set sval [expr { 0.01 * double($val) }]
    1219             foreach tf [array names _activeTfs] {
    1220                 set _settings($this-$tf-opacity) $sval
    1221                 set _activeTfs($tf) 0
    1222             }
    1223             updatetransferfuncs
    1224         }
    1225         thickness {
    1226             if { [array names _activeTfs] > 0 } {
    1227                 set val $_settings($this-thickness)
    1228                 # Scale values between 0.00001 and 0.01000
    1229                 set sval [expr {0.0001*double($val)}]
    1230                 foreach tf [array names _activeTfs] {
    1231                     set _settings($this-$tf-thickness) $sval
    1232                     set _activeTfs($tf) 0
    1233                 }
    1234                 updatetransferfuncs
    1235             }
    1236         }
    1237         "outline" {
    1238             SendCmd "volume outline state $_settings($this-outline)"
    1239         }
    1240         "isosurface" {
    1241             SendCmd "volume shading isosurface $_settings($this-isosurface)"
    1242         }
    1243         "colormap" {
    1244             set color [$itk_component(colormap) value]
    1245             set _settings(colormap) $color
    1246             # Only set the colormap on the first volume. Ignore the others.
    1247             #ResetColormap $color
    1248         }
    1249         "grid" {
    1250             SendCmd "grid visible $_settings($this-grid)"
    1251         }
    1252         "axes" {
    1253             SendCmd "axis visible $_settings($this-axes)"
    1254         }
    1255         "legend" {
    1256             if { $_settings($this-legend) } {
    1257                 blt::table $itk_component(plotarea) \
    1258                     0,0 $itk_component(3dview) -fill both \
    1259                     1,0 $itk_component(legend) -fill x
    1260                 blt::table configure $itk_component(plotarea) r1 -resize none
    1261             } else {
    1262                 blt::table forget $itk_component(legend)
    1263             }
    1264         }
    1265         "volume" {
    1266             set datasets [CurrentDatasets -cutplanes]
    1267             SendCmd "volume data state $_settings($this-volume) $datasets"
    1268         }
    1269         "xcutplane" - "ycutplane" - "zcutplane" {
    1270             set axis [string range $what 0 0]
    1271             set bool $_settings($this-$what)
     1276        "-volumeopacity" {
     1277            set _settings($what) [expr $_widget($what) * 0.01]
     1278            set _settings($_current${what}) $_settings($what)
     1279            foreach tag [GetDatasetsWithComponent $_current] {
     1280                SendCmd "volume shading opacity $_settings($what) $tag"
     1281            }
     1282            #updateTransferFunctions
     1283        }
     1284        "-outlinevisible" {
     1285            SendCmd "volume outline state $_settings($what)"
     1286        }
     1287        "-thickness" {
     1288            set val $_settings($what)
     1289            set _settings($_current${what}) $val
     1290            updateTransferFunctions
     1291        }
     1292        "-volume" {
     1293            # This is the global volume visibility control.  It controls the
     1294            # visibility of all the all volumes.  Whenever it's changed, you
     1295            # have to synchronize each of the local controls (see below) with
     1296            # this.
     1297            set datasets [CurrentDatasets]
     1298            set bool $_settings($what)
     1299            SendCmd "volume data state $bool $datasets"
     1300            foreach cname $_componentsList {
     1301                set _settings($cname-volumevisible) $bool
     1302            }
     1303            set _settings(-volumevisible) $bool
     1304        }
     1305        "-volumevisible" {
     1306            # This is the component specific control.  It changes the
     1307            # visibility of only the current component.
     1308            set _settings($_current${what}) $_settings($what)
     1309            foreach tag [GetDatasetsWithComponent $_current] {
     1310                SendCmd "volume data state $_settings($what) $tag"
     1311            }
     1312        }
     1313        "-xcutplanevisible" - "-ycutplanevisible" - "-zcutplanevisible" {
     1314            set axis [string range $what 1 1]
     1315            set bool $_settings($what)
    12721316            set datasets [CurrentDatasets -cutplanes]
    12731317            set tag [lindex $datasets 0]
     
    12991343    set w [expr {$_width-20}]
    13001344    set h [expr {[winfo height $itk_component(legend)]-20-$lineht}]
    1301     if {$w > 0 && $h > 0 && [array names _activeTfs] > 0 && $_first != "" } {
    1302         set tag [lindex [CurrentDatasets] 0]
    1303         if { [info exists _dataset2style($tag)] } {
    1304             SendCmd "legend $_dataset2style($tag) $w $h"
    1305         }
    1306     } else {
    1307         # Can't do this as this will remove the items associated with the
    1308         # isomarkers.
    1309        
    1310         #$itk_component(legend) delete all
    1311     }
    1312 }
    1313 
    1314 #
    1315 # NameTransferFunc --
     1345    if {$w > 0 && $h > 0 && $_first != "" } {
     1346        if { [info exists _cname2transferFunction($_current)] } {
     1347            SendCmd "legend $_current $w $h"
     1348        }
     1349    }
     1350}
     1351
     1352#
     1353# NameTransferFunction --
    13161354#
    13171355#       Creates a transfer function name based on the <style> settings in the
     
    13211359#       server parses the 3D data and sends back the limits via ReceiveData.]
    13221360#
    1323 #       FIXME: The current way we generate transfer-function names completely
    1324 #              ignores the -markers option.  The problem is that we are forced
    1325 #              to compute the name from an increasing complex set of values:
    1326 #              color, levels, marker, opacity.  I think we're stuck doing it
    1327 #              now.
    1328 #
    1329 itcl::body Rappture::NanovisViewer::NameTransferFunc { dataobj cname } {
     1361itcl::body Rappture::NanovisViewer::NameTransferFunction { dataobj cname } {
    13301362    array set styles {
    13311363        -color BCGYR
    13321364        -levels 6
    1333         -opacity 1.0
    13341365        -markers ""
    13351366    }
    13361367    set tag $dataobj-$cname
    13371368    array set styles [lindex [$dataobj components -style $cname] 0]
    1338     set tf "$styles(-color):$styles(-levels):$styles(-opacity)"
    1339     set _dataset2style($tag) $tf
    1340     lappend _style2datasets($tf) $tag
    1341     return $tf
    1342 }
    1343 
    1344 #
    1345 # ComputeTransferFunc --
    1346 #
    1347 #   Computes and sends the transfer function to the render server.  It's
    1348 #   assumed that the volume data limits are known and that the global
    1349 #   transfer-functions slider values have been set up.  Both parts are
    1350 #   needed to compute the relative value (location) of the marker, and
    1351 #   the alpha map of the transfer function.
    1352 #
    1353 itcl::body Rappture::NanovisViewer::ComputeTransferFunc { tf } {
    1354     array set styles {
    1355         -color BCGYR
    1356         -levels 6
    1357         -opacity 1.0
    1358         -markers ""
    1359         -alphamap ""
    1360     }
    1361 
    1362     foreach {dataobj cname} [split [lindex $_style2datasets($tf) 0] -] break
    1363     array set styles [lindex [$dataobj components -style $cname] 0]
     1369    if { ![info exists _cname2transferFunction($cname)] } {
     1370        # Get the colormap right now, since it doesn't change with marker
     1371        # changes.
     1372        set cmap [ColorsToColormap $styles(-color)]
     1373        set wmap [list 0.0 0.0 1.0 1.0]
     1374        set _cname2transferFunction($cname) [list $cmap $wmap]
     1375        SendCmd [list transfunc define $cname $cmap $wmap]
     1376    }
     1377    SendCmd "volume shading transfunc $cname $tag"
     1378    if { ![info exists _transferFunctionEditors($cname)] } {
     1379        set _transferFunctionEditors($cname) \
     1380            [Rappture::TransferFunctionEditor ::\#auto $itk_component(legend) \
     1381                 $cname \
     1382                 -command [itcl::code $this updateTransferFunctions]]
     1383    }
     1384    set _dataset2style($tag) $cname
     1385    lappend _style2datasets($cname) $tag
     1386    return $cname
     1387}
     1388
     1389#
     1390# ComputeTransferFunction --
     1391#
     1392#       Computes and sends the transfer function to the render server.  It's
     1393#       assumed that the volume data limits are known and that the global
     1394#       transfer-functions slider values have been set up.  Both parts are
     1395#       needed to compute the relative value (location) of the marker, and
     1396#       the alpha map of the transfer function.
     1397#
     1398itcl::body Rappture::NanovisViewer::ComputeTransferFunction { cname } {
     1399    foreach {cmap wmap} $_cname2transferFunction($cname) break
    13641400
    13651401    # We have to parse the style attributes for a volume using this
     
    13691405    # of the volumes (the first in the list) using the transfer-function as a
    13701406    # reference.
    1371     #
    1372     # FIXME: The current way we generate transfer-function names completely
    1373     #        ignores the -markers option.  The problem is that we are forced
    1374     #        to compute the name from an increasing complex set of values:
    1375     #        color, levels, marker, opacity.  I think the cow's out of the
    1376     #        barn on this one.
    1377 
    1378     if { ![info exists _isomarkers($tf)] } {
     1407    if { ![info exists _parsedFunction($cname)] } {
     1408        array set styles {
     1409            -color BCGYR
     1410            -levels 6
     1411            -markers ""
     1412        }
     1413        # Accumulate the style from all the datasets using it.
     1414        foreach tag [GetDatasetsWithComponent $cname] {
     1415            foreach {dataobj cname} [split [lindex $tag 0] -] break
     1416            array set styles [lindex [$dataobj components -style $cname] 0]
     1417        }
     1418        eval $_transferFunctionEditors($cname) limits $_limits($cname)
    13791419        # Have to defer creation of isomarkers until we have data limits
    13801420        if { [info exists styles(-markers)] &&
    13811421             [llength $styles(-markers)] > 0 } {
    1382             ParseMarkersOption $tf $styles(-markers)
     1422            ParseMarkersOption $cname $styles(-markers)
    13831423        } else {
    1384             ParseLevelsOption $tf $styles(-levels)
    1385         }
    1386         if { $styles(-alphamap) != "" } {
    1387             set _alphamap($cname) $styles(-alphamap)
    1388         }
    1389     }
    1390     set cmap [ColorsToColormap $styles(-color)]
    1391     set tag $this-$tf
    1392     if { ![info exists _settings($tag-opacity)] } {
    1393         set _settings($tag-opacity) $styles(-opacity)
    1394     }
    1395     set max 1.0 ;#$_settings($tag-opacity)
    1396 
    1397     set isovalues {}
    1398     foreach m $_isomarkers($tf) {
    1399         lappend isovalues [$m relval]
    1400     }
    1401     # Sort the isovalues
    1402     set isovalues [lsort -real $isovalues]
    1403 
    1404     if { ![info exists _settings($tag-thickness)]} {
    1405         set _settings($tag-thickness) 0.005
    1406     }
    1407     set delta $_settings($tag-thickness)
    1408 
    1409     set first [lindex $isovalues 0]
    1410     set last [lindex $isovalues end]
    1411     set wmap ""
    1412     if { $first == "" || $first != 0.0 } {
    1413         lappend wmap 0.0 0.0
    1414     }
    1415     foreach x $isovalues {
    1416         set x1 [expr {$x-$delta-0.00001}]
    1417         set x2 [expr {$x-$delta}]
    1418         set x3 [expr {$x+$delta}]
    1419         set x4 [expr {$x+$delta+0.00001}]
    1420         if { $x1 < 0.0 } {
    1421             set x1 0.0
    1422         } elseif { $x1 > 1.0 } {
    1423             set x1 1.0
    1424         }
    1425         if { $x2 < 0.0 } {
    1426             set x2 0.0
    1427         } elseif { $x2 > 1.0 } {
    1428             set x2 1.0
    1429         }
    1430         if { $x3 < 0.0 } {
    1431             set x3 0.0
    1432         } elseif { $x3 > 1.0 } {
    1433             set x3 1.0
    1434         }
    1435         if { $x4 < 0.0 } {
    1436             set x4 0.0
    1437         } elseif { $x4 > 1.0 } {
    1438             set x4 1.0
    1439         }
    1440         # add spikes in the middle
    1441         lappend wmap $x1 0.0
    1442         lappend wmap $x2 $max
    1443         lappend wmap $x3 $max
    1444         lappend wmap $x4 0.0
    1445     }
    1446     if { $last == "" || $last != 1.0 } {
    1447         lappend wmap 1.0 0.0
    1448     }
    1449     if { [info exists _alphamap($cname)] } {
    1450         set wmap $_alphamap($cname)
    1451     }
    1452     SendCmd [list transfunc define $tf $cmap $wmap]
     1424            ParseLevelsOption $cname $styles(-levels)
     1425        }
     1426       
     1427    }
     1428    set wmap [ComputeAlphamap $cname]
     1429    set _cname2transferFunction($cname) [list $cmap $wmap]
     1430    SendCmd [list transfunc define $cname $cmap $wmap]
     1431}
     1432
     1433itcl::body Rappture::NanovisViewer::AddNewMarker { x y } {
     1434    if { ![info exists _transferFunctionEditors($_current)] } {
     1435        continue
     1436    }
     1437    # Add a new marker to the current transfer function
     1438    $_transferFunctionEditors($_current) newMarker $x $y normal
     1439    $itk_component(legend) itemconfigure labels -fill $itk_option(-plotforeground)
     1440}
     1441
     1442itcl::body Rappture::NanovisViewer::RemoveMarker { x y } {
     1443    if { ![info exists _transferFunctionEditors($_current)] } {
     1444        continue
     1445    }
     1446    # Add a new marker to the current transfer function
     1447    $_transferFunctionEditors($_current) deleteMarker $x $y
    14531448}
    14541449
     
    14981493# marker is a relative value from 0.0 to 1.0.
    14991494#
    1500 itcl::body Rappture::NanovisViewer::ParseLevelsOption { tf levels } {
     1495itcl::body Rappture::NanovisViewer::ParseLevelsOption { cname levels } {
    15011496    set c $itk_component(legend)
     1497    set list {}
    15021498    regsub -all "," $levels " " levels
    15031499    if {[string is int $levels]} {
    15041500        for {set i 1} { $i <= $levels } {incr i} {
    1505             set x [expr {double($i)/($levels+1)}]
    1506             set m [Rappture::IsoMarker \#auto $c $this $tf]
    1507             $m relval $x
    1508             lappend _isomarkers($tf) $m
     1501            lappend list [expr {double($i)/($levels+1)}]
    15091502        }
    15101503    } else {
    15111504        foreach x $levels {
    1512             set m [Rappture::IsoMarker \#auto $c $this $tf]
    1513             $m relval $x
    1514             lappend _isomarkers($tf) $m
    1515         }
    1516     }
     1505            lappend list $x
     1506        }
     1507    }
     1508    set _parsedFunction($cname) 1
     1509    $_transferFunctionEditors($cname) addMarkers $list
     1510    $itk_component(legend) itemconfigure labels -fill $itk_option(-plotforeground)
    15171511}
    15181512
     
    15291523#       not be seen.
    15301524#
    1531 itcl::body Rappture::NanovisViewer::ParseMarkersOption { tf markers } {
     1525itcl::body Rappture::NanovisViewer::ParseMarkersOption { cname markers } {
    15321526    set c $itk_component(legend)
     1527    set list {}
     1528    foreach { min max } $_limits($cname) break
    15331529    regsub -all "," $markers " " markers
    15341530    foreach marker $markers {
    15351531        set n [scan $marker "%g%s" value suffix]
    15361532        if { $n == 2 && $suffix == "%" } {
    1537             # ${n}% : Set relative value.
    1538             set value [expr {$value * 0.01}]
    1539             set m [Rappture::IsoMarker \#auto $c $this $tf]
    1540             $m relval $value
    1541             lappend _isomarkers($tf) $m
     1533            # $n% : Set relative value (0..1).
     1534            lappend list [expr {$value * 0.01}]
    15421535        } else {
    1543             # ${n} : Set absolute value.
    1544             set m [Rappture::IsoMarker \#auto $c $this $tf]
    1545             $m absval $value
    1546             lappend _isomarkers($tf) $m
    1547         }
    1548     }
     1536            # $n : absolute value, compute relative
     1537            lappend list  [expr {(double($value)-$min)/($max-$min)]}
     1538        }
     1539    }
     1540    set _parsedFunction($cname) 1
     1541    $_transferFunctionEditors($cname) addMarkers $list
     1542    $itk_component(legend) itemconfigure labels -fill $itk_option(-plotforeground)
    15491543}
    15501544
     
    15521546# USAGE: UndateTransferFuncs
    15531547# ----------------------------------------------------------------------
    1554 itcl::body Rappture::NanovisViewer::updatetransferfuncs {} {
     1548itcl::body Rappture::NanovisViewer::updateTransferFunctions {} {
    15551549    $_dispatcher event -idle !send_transfunc
    15561550}
    15571551
    1558 itcl::body Rappture::NanovisViewer::AddIsoMarker { x y } {
    1559     if { $_first == "" } {
    1560         error "active transfer function isn't set"
    1561     }
    1562     set tag [lindex [CurrentDatasets] 0]
    1563     set tf $_dataset2style($tag)
    1564     set c $itk_component(legend)
    1565     set m [Rappture::IsoMarker \#auto $c $this $tf]
    1566     set w [winfo width $c]
    1567     $m relval [expr {double($x-10)/($w-20)}]
    1568     lappend _isomarkers($tf) $m
    1569     updatetransferfuncs
    1570     return 1
    1571 }
    1572 
    1573 itcl::body Rappture::NanovisViewer::rmdupmarker { marker x } {
    1574     set tf [$marker transferfunc]
    1575     set bool 0
    1576     if { [info exists _isomarkers($tf)] } {
    1577         set list {}
    1578         set marker [namespace tail $marker]
    1579         foreach m $_isomarkers($tf) {
    1580             set sx [$m screenpos]
    1581             if { $m != $marker } {
    1582                 if { $x >= ($sx-3) && $x <= ($sx+3) } {
    1583                     $marker relval [$m relval]
    1584                     itcl::delete object $m
    1585                     bell
    1586                     set bool 1
    1587                     continue
    1588                 }
    1589             }
    1590             lappend list $m
    1591         }
    1592         set _isomarkers($tf) $list
    1593         updatetransferfuncs
    1594     }
    1595     return $bool
    1596 }
    1597 
    1598 itcl::body Rappture::NanovisViewer::overmarker { marker x } {
    1599     set tf [$marker transferfunc]
    1600     if { [info exists _isomarkers($tf)] } {
    1601         set marker [namespace tail $marker]
    1602         foreach m $_isomarkers($tf) {
    1603             set sx [$m screenpos]
    1604             if { $m != $marker } {
    1605                 set bool [expr { $x >= ($sx-3) && $x <= ($sx+3) }]
    1606                 $m activate $bool
    1607             }
    1608         }
    1609     }
    1610     return ""
    1611 }
    1612 
    1613 itcl::body Rappture::NanovisViewer::limits { tf } {
     1552itcl::body Rappture::NanovisViewer::limits { cname } {
    16141553    set _limits(min) 0.0
    16151554    set _limits(max) 1.0
    1616     if { ![info exists _style2datasets($tf)] } {
     1555    if { ![info exists _style2datasets($cname)] } {
    16171556        return [array get _limits]
    16181557    }
    16191558    set min ""; set max ""
    1620     foreach tag $_style2datasets($tf) {
    1621         if { ![info exists _serverDatasets($tag)] } {
     1559    foreach tag [GetDatasetsWithComponent $cname] {
     1560        if { ![info exists _limits($tag)] } {
    16221561            continue
    16231562        }
    1624         if { ![info exists _limits($tag-min)] } {
    1625             continue
    1626         }
    1627         if { $min == "" || $min > $_limits($tag-min) } {
    1628             set min $_limits($tag-min)
    1629         }
    1630         if { $max == "" || $max < $_limits($tag-max) } {
    1631             set max $_limits($tag-max)
     1563        foreach {amin amax} $_limits($tag) break
     1564        if { $min == "" || $min > $amin } {
     1565            set min $amin
     1566        }
     1567        if { $max == "" || $max < $amax } {
     1568            set max $amax
    16321569        }
    16331570    }
     
    16381575        set _limits(max) $max
    16391576    }
    1640     return [array get _limits]
     1577    return [list $_limits(min) $_limits(max)]
    16411578}
    16421579
    16431580
    16441581itcl::body Rappture::NanovisViewer::BuildViewTab {} {
    1645     foreach { key value } {
    1646         grid            0
    1647         axes            1
    1648         outline         0
    1649         volume          1
    1650         legend          1
    1651         particles       1
    1652         lic             1
    1653     } {
    1654         set _settings($this-$key) $value
    1655     }
    1656 
    16571582    set fg [option get $itk_component(hull) font Font]
    16581583    #set bfg [option get $itk_component(hull) boldFont Font]
     
    16631588    $inner configure -borderwidth 4
    16641589
    1665     set ::Rappture::NanovisViewer::_settings($this-isosurface) 0
     1590    set ::Rappture::NanovisViewer::_settings(-isosurfaceshading) 0
    16661591    checkbutton $inner.isosurface \
    16671592        -text "Isosurface shading" \
    1668         -variable [itcl::scope _settings($this-isosurface)] \
    1669         -command [itcl::code $this AdjustSetting isosurface] \
     1593        -variable [itcl::scope _settings(-isosurfaceshading)] \
     1594        -command [itcl::code $this AdjustSetting -isosurfaceshading] \
    16701595        -font "Arial 9"
    16711596
    16721597    checkbutton $inner.axes \
    16731598        -text "Axes" \
    1674         -variable [itcl::scope _settings($this-axes)] \
    1675         -command [itcl::code $this AdjustSetting axes] \
     1599        -variable [itcl::scope _settings(-axesvisible)] \
     1600        -command [itcl::code $this AdjustSetting -axesvisible] \
    16761601        -font "Arial 9"
    16771602
    16781603    checkbutton $inner.grid \
    16791604        -text "Grid" \
    1680         -variable [itcl::scope _settings($this-grid)] \
    1681         -command [itcl::code $this AdjustSetting grid] \
     1605        -variable [itcl::scope _settings(-gridvisible)] \
     1606        -command [itcl::code $this AdjustSetting -gridvisible] \
    16821607        -font "Arial 9"
    16831608
    16841609    checkbutton $inner.outline \
    16851610        -text "Outline" \
    1686         -variable [itcl::scope _settings($this-outline)] \
    1687         -command [itcl::code $this AdjustSetting outline] \
     1611        -variable [itcl::scope _settings(-outlinevisible)] \
     1612        -command [itcl::code $this AdjustSetting -outlinevisible] \
    16881613        -font "Arial 9"
    16891614
    16901615    checkbutton $inner.legend \
    16911616        -text "Legend" \
    1692         -variable [itcl::scope _settings($this-legend)] \
    1693         -command [itcl::code $this AdjustSetting legend] \
     1617        -variable [itcl::scope _settings(-legendvisible)] \
     1618        -command [itcl::code $this AdjustSetting -legendvisible] \
    16941619        -font "Arial 9"
    16951620
    16961621    checkbutton $inner.volume \
    16971622        -text "Volume" \
    1698         -variable [itcl::scope _settings($this-volume)] \
    1699         -command [itcl::code $this AdjustSetting volume] \
     1623        -variable [itcl::scope _settings(-volume)] \
     1624        -command [itcl::code $this AdjustSetting -volume] \
    17001625        -font "Arial 9"
    17011626
     
    17151640
    17161641itcl::body Rappture::NanovisViewer::BuildVolumeTab {} {
    1717     foreach { key value } {
    1718         light2side      1
    1719         light           40
    1720         transp          50
    1721         opacity         100
    1722         thickness       350
    1723     } {
    1724         set _settings($this-$key) $value
    1725     }
    1726 
    17271642    set inner [$itk_component(main) insert end \
    17281643        -title "Volume Settings" \
     
    17301645    $inner configure -borderwidth 4
    17311646
     1647    set font [option get $itk_component(hull) font Font]
    17321648    set fg [option get $itk_component(hull) font Font]
    17331649    #set bfg [option get $itk_component(hull) boldFont Font]
    17341650
    17351651    checkbutton $inner.vol -text "Show volume" -font $fg \
    1736         -variable [itcl::scope _settings($this-volume)] \
    1737         -command [itcl::code $this AdjustSetting volume]
     1652        -variable [itcl::scope _settings(-volumevisible)] \
     1653        -command [itcl::code $this AdjustSetting -volumevisible]
    17381654    label $inner.shading -text "Shading:" -font $fg
    17391655
    17401656    checkbutton $inner.light2side -text "Two-sided lighting" -font $fg \
    1741         -variable [itcl::scope _settings($this-light2side)] \
    1742         -command [itcl::code $this AdjustSetting light2side]
     1657        -variable [itcl::scope _settings(-light2side)] \
     1658        -command [itcl::code $this AdjustSetting -light2side]
    17431659
    17441660    label $inner.dim -text "Glow" -font $fg
    17451661    ::scale $inner.light -from 0 -to 100 -orient horizontal \
    1746         -variable [itcl::scope _settings($this-light)] \
     1662        -variable [itcl::scope _settings(-light)] \
    17471663        -width 10 \
    1748         -showvalue off -command [itcl::code $this AdjustSetting light]
     1664        -showvalue off -command [itcl::code $this AdjustSetting -light]
    17491665    label $inner.bright -text "Surface" -font $fg
    17501666
     1667    # Opacity
    17511668    label $inner.fog -text "Clear" -font $fg
    17521669    ::scale $inner.transp -from 0 -to 100 -orient horizontal \
    1753         -variable [itcl::scope _settings($this-transp)] \
     1670        -variable [itcl::scope _widget(-volumeopacity)] \
    17541671        -width 10 \
    1755         -showvalue off -command [itcl::code $this AdjustSetting transp]
     1672        -showvalue off -command [itcl::code $this AdjustSetting -volumeopacity]
    17561673    label $inner.plastic -text "Opaque" -font $fg
    17571674
    1758     label $inner.clear -text "Clear" -font $fg
    1759     ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
    1760         -variable [itcl::scope _settings($this-opacity)] \
    1761         -width 10 \
    1762         -showvalue off -command [itcl::code $this AdjustSetting opacity]
    1763     label $inner.opaque -text "Opaque" -font $fg
    1764 
     1675    # Tooth thickness
    17651676    label $inner.thin -text "Thin" -font $fg
    17661677    ::scale $inner.thickness -from 0 -to 1000 -orient horizontal \
    1767         -variable [itcl::scope _settings($this-thickness)] \
     1678        -variable [itcl::scope _settings(-thickness)] \
    17681679        -width 10 \
    1769         -showvalue off -command [itcl::code $this AdjustSetting thickness]
     1680        -showvalue off -command [itcl::code $this AdjustSetting -thickness]
    17701681    label $inner.thick -text "Thick" -font $fg
    17711682
     1683    # Colormap
    17721684    label $inner.colormap_l -text "Colormap" -font "Arial 9"
    17731685    itk_component add colormap {
     
    17781690    $itk_component(colormap) value "BCGYR"
    17791691    bind $inner.colormap <<Value>> \
    1780         [itcl::code $this AdjustSetting colormap]
     1692        [itcl::code $this AdjustSetting -colormap]
     1693    $itk_component(colormap) value "default"
     1694    set _settings(-colormap) "default"
     1695
     1696    # Component
     1697    label $inner.volcomponents_l -text "Component" -font $font
     1698    itk_component add volcomponents {
     1699        Rappture::Combobox $inner.volcomponents -editable no
     1700    }
     1701    bind $inner.volcomponents <<Value>> \
     1702        [itcl::code $this AdjustSetting -current]
    17811703
    17821704    blt::table $inner \
    1783         0,0 $inner.vol -cspan 4 -anchor w -pady 2 \
     1705        0,0 $inner.volcomponents_l -anchor e -cspan 2 \
     1706        0,2 $inner.volcomponents             -cspan 3 -fill x \
    17841707        1,0 $inner.shading -cspan 4 -anchor w -pady {10 2} \
    17851708        2,0 $inner.light2side -cspan 4 -anchor w -pady 2 \
     
    18041727    $inner configure -borderwidth 4
    18051728
     1729    checkbutton $inner.visible \
     1730        -text "Show Cutplanes" \
     1731        -variable [itcl::scope _settings(-cutplanesvisible)] \
     1732        -command [itcl::code $this AdjustSetting -cutplanesvisible] \
     1733        -font "Arial 9"
     1734   
    18061735    # X-value slicer...
    18071736    itk_component add xCutButton {
     
    18091738            -onimage [Rappture::icon x-cutplane] \
    18101739            -offimage [Rappture::icon x-cutplane] \
    1811             -command [itcl::code $this AdjustSetting xcutplane] \
    1812             -variable [itcl::scope _settings($this-xcutplane)]
     1740            -command [itcl::code $this AdjustSetting -xcutplanevisible] \
     1741            -variable [itcl::scope _settings(-xcutplanevisible)]
    18131742    }
    18141743    Rappture::Tooltip::for $itk_component(xCutButton) \
    18151744        "Toggle the X cut plane on/off"
     1745    $itk_component(xCutButton) select
    18161746
    18171747    itk_component add xCutScale {
     
    18201750            -borderwidth 1 -highlightthickness 0 \
    18211751            -command [itcl::code $this Slice move x] \
    1822             -variable [itcl::scope _settings($this-xcutposition)]
     1752            -variable [itcl::scope _settings(-xcutplaneposition)]
    18231753    } {
    18241754        usual
     
    18361766            -onimage [Rappture::icon y-cutplane] \
    18371767            -offimage [Rappture::icon y-cutplane] \
    1838             -command [itcl::code $this AdjustSetting ycutplane] \
    1839             -variable [itcl::scope _settings($this-ycutplane)]
     1768            -command [itcl::code $this AdjustSetting -ycutplanevisible] \
     1769            -variable [itcl::scope _settings(-ycutplanevisible)]
    18401770    }
    18411771    Rappture::Tooltip::for $itk_component(yCutButton) \
    18421772        "Toggle the Y cut plane on/off"
     1773    $itk_component(yCutButton) select
    18431774
    18441775    itk_component add yCutScale {
     
    18471778            -borderwidth 1 -highlightthickness 0 \
    18481779            -command [itcl::code $this Slice move y] \
    1849             -variable [itcl::scope _settings($this-ycutposition)]
     1780            -variable [itcl::scope _settings(-ycutplaneposition)]
    18501781    } {
    18511782        usual
     
    18631794            -onimage [Rappture::icon z-cutplane] \
    18641795            -offimage [Rappture::icon z-cutplane] \
    1865             -command [itcl::code $this AdjustSetting zcutplane] \
    1866             -variable [itcl::scope _settings($this-zcutplane)]
     1796            -command [itcl::code $this AdjustSetting -zcutplanevisible] \
     1797            -variable [itcl::scope _settings(-zcutplanevisible)]
    18671798    }
    18681799    Rappture::Tooltip::for $itk_component(zCutButton) \
    18691800        "Toggle the Z cut plane on/off"
     1801    $itk_component(zCutButton) select
    18701802
    18711803    itk_component add zCutScale {
     
    18741806            -borderwidth 1 -highlightthickness 0 \
    18751807            -command [itcl::code $this Slice move z] \
    1876             -variable [itcl::scope _settings($this-zcutposition)]
     1808            -variable [itcl::scope _settings(-zcutplaneposition)]
    18771809    } {
    18781810        usual
     
    18811813    $itk_component(zCutScale) set 50
    18821814    $itk_component(zCutScale) configure -state disabled
    1883     #$itk_component(zCutScale) configure -state disabled
    18841815    Rappture::Tooltip::for $itk_component(zCutScale) \
    18851816        "@[itcl::code $this SlicerTip z]"
     
    19231854        label $inner.${tag}label -text $tag -font "Arial 9"
    19241855        entry $inner.${tag} -font "Arial 9"  -bg white \
    1925             -textvariable [itcl::scope _settings($this-$tag)]
     1856            -textvariable [itcl::scope _settings(-$tag)]
    19261857        bind $inner.${tag} <Return> \
    1927             [itcl::code $this camera set ${tag}]
     1858            [itcl::code $this camera set -${tag}]
    19281859        bind $inner.${tag} <KP_Enter> \
    1929             [itcl::code $this camera set ${tag}]
     1860            [itcl::code $this camera set -${tag}]
    19301861        blt::table $inner \
    19311862            $row,0 $inner.${tag}label -anchor e -pady 2 \
     
    19761907itcl::body Rappture::NanovisViewer::SlicerTip {axis} {
    19771908    set val [$itk_component(${axis}CutScale) get]
    1978 #    set val [expr {0.01*($val-50)
    1979 #        *($_limits(${axis}max)-$_limits(${axis}min))
    1980 #          + 0.5*($_limits(${axis}max)+$_limits(${axis}min))}]
    19811909    return "Move the [string toupper $axis] cut plane.\nCurrently:  $axis = $val%"
    19821910}
     
    19991927}
    20001928
    2001 itcl::body Rappture::NanovisViewer::EventuallyResizeLegend {} {
     1929itcl::body Rappture::NanovisViewer::EventuallyRedrawLegend {} {
    20021930    if { !$_resizeLegendPending } {
    20031931        $_dispatcher event -idle !legend
     
    20141942        }
    20151943        "set" {
    2016             set who [lindex $args 0]
    2017             set x $_settings($this-$who)
     1944            set what [lindex $args 0]
     1945            set x $_settings($what)
    20181946            set code [catch { string is double $x } result]
    20191947            if { $code != 0 || !$result } {
    2020                 set _settings($this-$who) $_view($who)
     1948                set _settings($what) $_view($what)
    20211949                return
    20221950            }
    2023             switch -- $who {
    2024                 "xpan" - "ypan" {
    2025                     set _view($who) $_settings($this-$who)
     1951            switch -- $what {
     1952                "-xpan" - "-ypan" {
     1953                    set _view($what) $_settings($what)
    20261954                    PanCamera
    20271955                }
    2028                 "qx" - "qy" - "qz" - "qw" {
    2029                     set _view($who) $_settings($this-$who)
    2030                     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     1956                "-qx" - "-qy" - "-qz" - "-qw" {
     1957                    set _view($what) $_settings($what)
     1958                    set q [ViewToQuaternion]
    20311959                    $_arcball quaternion $q
    20321960                    SendCmd "camera orient $q"
    20331961                }
    2034                 "zoom" {
    2035                     set _view($who) $_settings($this-$who)
    2036                     SendCmd "camera zoom $_view(zoom)"
     1962                "-zoom" {
     1963                    set _view($what) $_settings($what)
     1964                    SendCmd "camera zoom $_view($what)"
    20371965                }
    20381966            }
     
    20742002        array set info $vol
    20752003        set name $info(name)
    2076         if { ![info exists _settings($this-volume-$name)] } {
    2077             set _settings($this-volume-$name) $info(hide)
     2004        if { ![info exists _settings(-volumevisible-$name)] } {
     2005            set _settings(-volumevisible-$name) $info(hide)
    20782006        }
    20792007        checkbutton $inner.vol$row -text $info(label) \
    2080             -variable [itcl::scope _settings($this-volume-$name)] \
     2008            -variable [itcl::scope _settings(-volumevisible-$name)] \
    20812009            -onvalue 0 -offvalue 1 \
    2082             -command [itcl::code $this volume $key $name] \
     2010            -command [itcl::code $this ToggleVolume $key $name] \
    20832011            -font "Arial 9"
    20842012        Rappture::Tooltip::for $inner.vol$row $info(description)
    20852013        blt::table $inner $row,0 $inner.vol$row -anchor w
    2086         if { !$_settings($this-volume-$name) } {
     2014        if { !$_settings(-volume-$name) } {
    20872015            $inner.vol$row select
    20882016        }
     
    20952023}
    20962024
    2097 itcl::body Rappture::NanovisViewer::volume { tag name } {
    2098     set bool $_settings($this-volume-$name)
    2099     SendCmd "volume statue $bool $name"
     2025itcl::body Rappture::NanovisViewer::ToggleVolume { tag name } {
     2026    set bool $_settings(-volumevisible-$name)
     2027    SendCmd "volume state $bool $name"
    21002028}
    21012029
     
    21092037        bottom "0.707107 0.707107 0 0"
    21102038    }
    2111     foreach name { qw qx qy qz } value $positions($side) {
     2039    foreach name { -qw -qx -qy -qz } value $positions($side) {
    21122040        set _view($name) $value
    21132041    }
    2114     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     2042    set q [ViewToQuaternion]
    21152043    $_arcball quaternion $q
    21162044    SendCmd "camera orient $q"
    21172045    SendCmd "camera reset"
    2118     set _view(xpan) 0
    2119     set _view(ypan) 0
    2120     set _view(zoom) 1.0
    2121     set _settings($this-xpan) $_view(xpan)
    2122     set _settings($this-ypan) $_view(ypan)
    2123     set _settings($this-zoom) $_view(zoom)
    2124 }
    2125 
     2046    set _view(-xpan) 0
     2047    set _view(-ypan) 0
     2048    set _view(-zoom) 1.0
     2049    set _settings(-xpan) $_view(-xpan)
     2050    set _settings(-ypan) $_view(-ypan)
     2051    set _settings(-zoom) $_view(-zoom)
     2052}
     2053
     2054
     2055#
     2056# InitComponentSettings --
     2057#
     2058#       Initializes the volume settings for a specific component. This
     2059#       should match what's used as global settings above. This
     2060#       is called the first time we try to switch to a given component
     2061#       in SwitchComponent below.
     2062#
     2063itcl::body Rappture::NanovisViewer::InitComponentSettings { cname } {
     2064    # Expanding component name for key.
     2065    array set _settings [subst {
     2066        $cname-ambient           60
     2067        $cname-colormap          default
     2068        $cname-diffuse           40
     2069        $cname-light2side        1
     2070        $cname-volumeopacity     0.5
     2071        $cname-specularexponent  90
     2072        $cname-specularlevel     30
     2073        $cname-thickness         350
     2074        $cname-volumevisible     1
     2075    }]
     2076}
     2077
     2078#
     2079# SwitchComponent --
     2080#
     2081#       This is called when the current component is changed by the
     2082#       dropdown menu in the volume tab.  It synchronizes the global
     2083#       volume settings with the settings of the new current component.
     2084#
     2085itcl::body Rappture::NanovisViewer::SwitchComponent { cname } {
     2086    if { ![info exists _settings($cname-ambient)] } {
     2087        InitComponentSettings $cname
     2088    }
     2089    # _settings variables change widgets, except for colormap
     2090    set _settings(-ambient)          $_settings($cname-ambient)
     2091    set _settings(-colormap)         $_settings($cname-colormap)
     2092    set _settings(-diffuse)          $_settings($cname-diffuse)
     2093    set _settings(-light2side)       $_settings($cname-light2side)
     2094    set _settings(-specularexponent) $_settings($cname-specularexponent)
     2095    set _settings(-specularlevel)    $_settings($cname-specularlevel)
     2096    set _settings(-thickness)        $_settings($cname-thickness)
     2097    set _settings(-volumeopacity)    $_settings($cname-volumeopacity)
     2098    set _settings(-volumevisible)    $_settings($cname-volumevisible)
     2099    $itk_component(colormap) value   $_settings($cname-colormap)
     2100    set _current $cname;                # Reset the current component
     2101}
     2102
     2103#
     2104# BuildVolumeComponents --
     2105#
     2106#       This is called from the "scale" method which is called when a
     2107#       new dataset is added or deleted.  It repopulates the dropdown
     2108#       menu of volume component names.  It sets the current component
     2109#       to the first component in the list (of components found).
     2110#       Finally, if there is only one component, don't display the
     2111#       label or the combobox in the volume settings tab.
     2112#
     2113itcl::body Rappture::NanovisViewer::BuildVolumeComponents {} {
     2114    $itk_component(volcomponents) choices delete 0 end
     2115    foreach name $_componentsList {
     2116        $itk_component(volcomponents) choices insert end $name $name
     2117    }
     2118    set _current [lindex $_componentsList 0]
     2119    $itk_component(volcomponents) value $_current
     2120    set parent [winfo parent $itk_component(volcomponents)]
     2121    if { [llength $_componentsList] <= 1 } {
     2122        # Unpack the components label and dropdown if there's only one
     2123        # component.
     2124        blt::table forget $parent.volcomponents_l $parent.volcomponents
     2125    } else {
     2126        # Pack the components label and dropdown into the table there's
     2127        # more than one component to select.
     2128        blt::table $parent \
     2129            0,0 $parent.volcomponents_l -anchor e -cspan 2 \
     2130            0,2 $parent.volcomponents -cspan 3 -fill x
     2131    }
     2132}
     2133
     2134#
     2135# GetDatasetsWithComponents --
     2136#
     2137#       Returns a list of all the datasets (known by the combination of
     2138#       their data object and component name) that match the given
     2139#       component name.  For example, this is used where we want to change
     2140#       the settings of volumes that have the current component.
     2141#
     2142itcl::body Rappture::NanovisViewer::GetDatasetsWithComponent { cname } {
     2143    if { ![info exists _volcomponents($cname)] } {
     2144        return ""
     2145    }
     2146    set list ""
     2147    foreach tag $_volcomponents($cname) {
     2148        if { ![info exists _serverDatasets($tag)] } {
     2149            continue
     2150        }
     2151        lappend list $tag
     2152    }
     2153    return $list
     2154}
     2155
     2156#
     2157# HideAllMarkers --
     2158#
     2159#       Hide all the markers in all the transfer functions.  Can't simply
     2160#       delete and recreate markers from the <style> since the user may
     2161#       have create, deleted, or moved markers.
     2162#
     2163itcl::body Rappture::NanovisViewer::HideAllMarkers {} {
     2164    foreach cname [array names _transferFunctionEditors] {
     2165        $_transferFunctionEditors($cname) hideMarkers
     2166    }
     2167}
     2168
     2169itcl::body Rappture::NanovisViewer::GetColormap { cname color } {
     2170    if { $color == "default" } {
     2171        return $_cname2defaultcolormap($cname)
     2172    }
     2173    return [ColorsToColormap $color]
     2174}
     2175
     2176itcl::body Rappture::NanovisViewer::GetAlphamap { cname name } {
     2177    if { $name == "default" } {
     2178        return $_cname2defaultalphamap($cname)
     2179    }
     2180    return [NameToAlphamap $name]
     2181}
     2182
     2183itcl::body Rappture::NanovisViewer::ResetColormap { cname color } {
     2184    # Get the current transfer function
     2185    if { ![info exists _cname2transferFunction($cname)] } {
     2186        return
     2187    }
     2188    foreach { cmap wmap } $_cname2transferFunction($cname) break
     2189    set cmap [GetColormap $cname $color]
     2190    set _cname2transferFunction($cname) [list $cmap $wmap]
     2191    SendCmd [list transfunc define $cname $cmap $wmap]
     2192    EventuallyRedrawLegend
     2193}
     2194
     2195itcl::body Rappture::NanovisViewer::ComputeAlphamap { cname } {
     2196    if { ![info exists _transferFunctionEditors($cname)] } {
     2197        return [list 0.0 0.0 1.0 1.0]
     2198    }
     2199    if { ![info exists _settings($cname-ambient)] } {
     2200        InitComponentSettings $cname
     2201    }
     2202
     2203    set isovalues [$_transferFunctionEditors($cname) values]
     2204
     2205    # Currently using volume shading opacity to scale opacity in
     2206    # the volume shader. The transfer function always sets full
     2207    # opacity
     2208    set max 1.0
     2209
     2210    # Use the component-wise thickness setting from the slider
     2211    # settings widget
     2212    # Scale values between 0.00001 and 0.01000
     2213    set delta [expr {double($_settings($cname-thickness)) * 0.0001}]
     2214   
     2215    set first [lindex $isovalues 0]
     2216    set last [lindex $isovalues end]
     2217    set wmap ""
     2218    if { $first == "" || $first != 0.0 } {
     2219        lappend wmap 0.0 0.0
     2220    }
     2221    foreach x $isovalues {
     2222        set x1 [expr {$x-$delta-0.00001}]
     2223        set x2 [expr {$x-$delta}]
     2224        set x3 [expr {$x+$delta}]
     2225        set x4 [expr {$x+$delta+0.00001}]
     2226        if { $x1 < 0.0 } {
     2227            set x1 0.0
     2228        } elseif { $x1 > 1.0 } {
     2229            set x1 1.0
     2230        }
     2231        if { $x2 < 0.0 } {
     2232            set x2 0.0
     2233        } elseif { $x2 > 1.0 } {
     2234            set x2 1.0
     2235        }
     2236        if { $x3 < 0.0 } {
     2237            set x3 0.0
     2238        } elseif { $x3 > 1.0 } {
     2239            set x3 1.0
     2240        }
     2241        if { $x4 < 0.0 } {
     2242            set x4 0.0
     2243        } elseif { $x4 > 1.0 } {
     2244            set x4 1.0
     2245        }
     2246        # add spikes in the middle
     2247        lappend wmap $x1 0.0
     2248        lappend wmap $x2 $max
     2249        lappend wmap $x3 $max
     2250        lappend wmap $x4 0.0
     2251    }
     2252    if { $last == "" || $last != 1.0 } {
     2253        lappend wmap 1.0 0.0
     2254    }
     2255    return $wmap
     2256}
     2257
     2258
     2259itcl::body Rappture::NanovisViewer::NameToAlphamap { name } {
     2260    switch -- $name {
     2261        "ramp-up" {
     2262            set wmap {
     2263                0.0 0.0
     2264                1.0 1.0
     2265            }
     2266        }
     2267        "ramp-down" {
     2268            set wmap {
     2269                0.0 1.0
     2270                1.0 0.0
     2271            }
     2272        }
     2273        "vee" {
     2274            set wmap {
     2275                0.0 1.0
     2276                0.5 0.0
     2277                1.0 1.0
     2278            }
     2279        }
     2280        "tent-1" {
     2281            set wmap {
     2282                0.0 0.0
     2283                0.5 1.0
     2284                1.0 0.0
     2285            }
     2286        }
     2287        "tent-2" {
     2288            set wmap {
     2289                0.0 0.0
     2290                0.25 1.0
     2291                0.5 0.0
     2292                0.75 1.0
     2293                1.0 0.0
     2294            }
     2295        }
     2296        "tent-3" {
     2297            set wmap {
     2298                0.0 0.0
     2299                0.16666 1.0
     2300                0.33333 0.0
     2301                0.5     1.0
     2302                0.66666 0.0
     2303                0.83333 1.0
     2304                1.0 0.0
     2305            }
     2306        }
     2307        "tent-4" {
     2308            set wmap {
     2309                0.0     0.0
     2310                0.125   1.0
     2311                0.25    0.0
     2312                0.375   1.0
     2313                0.5     0.0       
     2314                0.625   1.0
     2315                0.75    0.0
     2316                0.875   1.0
     2317                1.0     0.0
     2318            }
     2319        }
     2320        "sinusoid-1" {
     2321            set wmap {
     2322                0.0                     0.000 0.600 0.800
     2323                0.14285714285714285     0.400 0.900 1.000
     2324                0.2857142857142857      0.600 1.000 1.000
     2325                0.42857142857142855     0.800 1.000 1.000
     2326                0.5714285714285714      0.900 0.900 0.900
     2327                0.7142857142857143      0.600 0.600 0.600
     2328                0.8571428571428571      0.400 0.400 0.400
     2329                1.0                     0.200 0.200 0.200
     2330            }
     2331        }
     2332        "sinusoid-2" {
     2333            set wmap {
     2334                0.0                     0.900 1.000 1.000
     2335                0.1111111111111111      0.800 0.983 1.000
     2336                0.2222222222222222      0.700 0.950 1.000
     2337                0.3333333333333333      0.600 0.900 1.000
     2338                0.4444444444444444      0.500 0.833 1.000
     2339                0.5555555555555556      0.400 0.750 1.000
     2340                0.6666666666666666      0.300 0.650 1.000
     2341                0.7777777777777778      0.200 0.533 1.000
     2342                0.8888888888888888      0.100 0.400 1.000
     2343                1.0                     0.000 0.250 1.000
     2344            }
     2345        }
     2346        "sinusoid-6" {
     2347            set wmap {
     2348                0.0                             0.200   0.100   0.000
     2349                0.09090909090909091             0.400   0.187   0.000
     2350                0.18181818181818182             0.600   0.379   0.210
     2351                0.2727272727272727              0.800   0.608   0.480
     2352                0.36363636363636365             0.850   0.688   0.595
     2353                0.45454545454545453             0.950   0.855   0.808
     2354                0.5454545454545454              0.800   0.993   1.000
     2355                0.6363636363636364              0.600   0.973   1.000
     2356                0.7272727272727273              0.400   0.940   1.000
     2357                0.8181818181818182              0.200   0.893   1.000
     2358                0.9090909090909091              0.000   0.667   0.800
     2359                1.0                             0.000   0.480   0.600
     2360            }
     2361        }
     2362        "sinusoid-10" {
     2363            set wmap {
     2364                0.0                             0.000   0.480   0.600
     2365                0.09090909090909091             0.000   0.667   0.800
     2366                0.18181818181818182             0.200   0.893   1.000
     2367                0.2727272727272727              0.400   0.940   1.000
     2368                0.36363636363636365             0.600   0.973   1.000
     2369                0.45454545454545453             0.800   0.993   1.000
     2370                0.5454545454545454              0.950   0.855   0.808
     2371                0.6363636363636364              0.850   0.688   0.595
     2372                0.7272727272727273              0.800   0.608   0.480
     2373                0.8181818181818182              0.600   0.379   0.210
     2374                0.9090909090909091              0.400   0.187   0.000
     2375                1.0                             0.200   0.100   0.000
     2376            }
     2377        }
     2378        "step-2" {
     2379            set wmap {
     2380                0.0                             0.000   0.167   1.000
     2381                0.09090909090909091             0.100   0.400   1.000
     2382                0.18181818181818182             0.200   0.600   1.000
     2383                0.2727272727272727              0.400   0.800   1.000
     2384                0.36363636363636365             0.600   0.933   1.000
     2385                0.45454545454545453             0.800   1.000   1.000
     2386                0.5454545454545454              1.000   1.000   0.800
     2387                0.6363636363636364              1.000   0.933   0.600
     2388                0.7272727272727273              1.000   0.800   0.400
     2389                0.8181818181818182              1.000   0.600   0.200
     2390                0.9090909090909091              1.000   0.400   0.100
     2391                1.0                             1.000   0.167   0.000
     2392            }
     2393        }
     2394        "step-5" {
     2395            set wmap {
     2396                0.0                             1.000   0.167   0.000
     2397                0.09090909090909091             1.000   0.400   0.100
     2398                0.18181818181818182             1.000   0.600   0.200
     2399                0.2727272727272727              1.000   0.800   0.400
     2400                0.36363636363636365             1.000   0.933   0.600
     2401                0.45454545454545453             1.000   1.000   0.800
     2402                0.5454545454545454              0.800   1.000   1.000
     2403                0.6363636363636364              0.600   0.933   1.000
     2404                0.7272727272727273              0.400   0.800   1.000
     2405                0.8181818181818182              0.200   0.600   1.000
     2406                0.9090909090909091              0.100   0.400   1.000
     2407                1.0                             0.000   0.167   1.000
     2408            }
     2409        }
     2410        "step-12" {
     2411            set wmap {
     2412                "#EE82EE"
     2413                "#4B0082"
     2414                "blue"
     2415                "#008000"
     2416                "yellow"
     2417                "#FFA500"
     2418                "red"
     2419            }
     2420        }
     2421        default {
     2422        }
     2423    }
     2424    return ""
     2425}
     2426
     2427
  • branches/1.3/gui/scripts/vtkisosurfaceviewer.tcl

    r4475 r4504  
    141141    private variable _contourList
    142142    private variable _currentLimits ""
     143    private variable _widget
     144
    143145    common _downloadPopup;              # download options from popup
    144146    private common _hardcopy
     
    242244        -cutplaneedges                  0
    243245        -cutplanelighting               1
    244         -cutplaneopacity                100
     246        -cutplaneopacity                1.0
    245247        -cutplanepreinterp              1
    246248        -cutplanesvisible               0
     
    250252        -isosurfaceedges                0
    251253        -isosurfacelighting             1
    252         -isosurfaceopacity              60
     254        -isosurfaceopacity              0.6
    253255        -isosurfacevisible              1
    254256        -isosurfacewireframe            0
     
    269271        -colormap                0
    270272        -isosurfaceopacity       0
     273        -cutplaneopacity         0
    271274        -numcontours             0
     275    }
     276    array set _widget {
     277        -isosurfaceopacity       0
     278        -cutplaneopacity         0
    272279    }
    273280
     
    483490    GenerateContourList
    484491    SendCmd [list contour3d contourlist $_contourList(values)]
    485     #SendCmd [list camera reset]
     492    SendCmd [list camera reset]
    486493    DrawLegend
    487494    set _contourList(updatePending) 0
     
    970977    # generates a new call to Rebuild).   
    971978    StartBufferingCommands
    972 
    973979    if { $_reset } {
    974980        set _width $w
     
    991997        InitSettings -xgrid -ygrid -zgrid -axismode \
    992998            -axesvisible -axislabelsvisible
    993         foreach axis { x y z } {
    994             SendCmd "axis lformat $axis %g"
    995         }
     999        SendCmd "axis lformat all %g"
     1000        # Too many major ticks, so turn off minor ticks
     1001        SendCmd "axis minticks all 0"
    9961002        StopBufferingCommands
    9971003        SendCmd "imgflush"
     
    11011107                set label [string toupper $axis]
    11021108            }
    1103             # May be a space in the axis label.
    11041109            SendCmd [list axis name $axis $label]
    11051110        }
     
    14131418        }
    14141419        "-cutplaneopacity" {
    1415             set val $_settings($what)
    1416             set sval [expr { 0.01 * double($val) }]
    1417             SendCmd "cutplane opacity $sval"
     1420            set _settings($what) [$_widget(-cutplaneopacity) * 0.01]
     1421            SendCmd "cutplane opacity $_settings($what)"
    14181422        }
    14191423        "-cutplanepreinterp" {
     
    15091513        }
    15101514        "-isosurfaceopacity" {
    1511             set val $_settings($what)
    1512             set sval [expr { 0.01 * double($val) }]
    1513             SendCmd "contour3d opacity $sval"
     1515            set _settings($what) [$_widget(-isosurfaceopacity) * 0.01]
     1516            SendCmd "contour3d opacity $_settings($what)"
    15141517        }
    15151518        "-field" {
     
    15391542            SendCmd "contour3d colormode $_colorMode $_curFldName"
    15401543            SendCmd "camera reset"
     1544            UpdateContourList
    15411545            DrawLegend
    15421546        }
     
    17141718    label $inner.opacity_l -text "Opacity" -font "Arial 9"
    17151719    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
    1716         -variable [itcl::scope _settings(-isosurfaceopacity)] \
     1720        -variable [itcl::scope _widget(-isosurfaceopacity)] \
    17171721        -width 10 \
    17181722        -showvalue off \
    17191723        -command [itcl::code $this AdjustSetting -isosurfaceopacity]
     1724    $inner.opacity set [expr $_settings(-isosurfaceeopacity) * 100.0]
    17201725
    17211726    itk_component add field_l {
     
    17341739        Rappture::Combobox $inner.colormap -width 10 -editable 0
    17351740    }
    1736 
    17371741    $inner.colormap choices insert end [GetColormapList]
     1742
    17381743    $itk_component(colormap) value "BCGYR"
    17391744    bind $inner.colormap <<Value>> \
     
    19271932    label $inner.opacity_l -text "Opacity" -font "Arial 9"
    19281933    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
    1929         -variable [itcl::scope _settings(-cutplaneopacity)] \
     1934        -variable [itcl::scope _widget(-cutplaneopacity)] \
    19301935        -width 10 \
    19311936        -showvalue off \
    19321937        -command [itcl::code $this AdjustSetting -cutplaneopacity]
    1933     $inner.opacity set $_settings(-cutplaneopacity)
     1938    $inner.opacity set [expr $_settings(-cutplaneopacity) * 100.0]
    19341939
    19351940    # X-value slicer...
     
    21502155    set tag $dataobj-$comp
    21512156    array set style {
    2152         -color BCGYR
    2153         -cutplanesvisible 0
    2154         -edgecolor black
    2155         -edges 0
    2156         -isosurfacevisible 1
    2157         -levels 10
    2158         -lighting 1
    2159         -linewidth 1.0
    2160         -opacity 0.6
    2161         -outline 0
    2162         -wireframe 0
    2163         -xcutplaneposition 50
    2164         -xcutplanevisible 1
    2165         -ycutplaneposition 50
    2166         -ycutplanevisible 1
    2167         -zcutplaneposition 50
    2168         -zcutplanevisible 1
     2157        -color                  BCGYR
     2158        -cutplanesvisible       0
     2159        -edgecolor              black
     2160        -edges                  0
     2161        -isosurfaceopacity      0.6
     2162        -isosurfacevisible      1
     2163        -levels                 10
     2164        -lighting               1
     2165        -linewidth              1.0
     2166        -outline                0
     2167        -wireframe              0
     2168        -xcutplaneposition      50
     2169        -xcutplanevisible       1
     2170        -ycutplaneposition      50
     2171        -ycutplanevisible       1
     2172        -zcutplaneposition      50
     2173        -zcutplanevisible       1
    21692174    }
    21702175    array set style [$dataobj style $comp]
    21712176    if { $dataobj != $_first || $style(-levels) == 1 } {
    2172         set style(-opacity) 1
     2177        set style(-isosurfaceopacity) 1.0
    21732178    }
    21742179
     
    21832188
    21842189    if { $_changed(-isosurfaceopacity) } {
    2185         set style(-opacity) [expr $_settings(-isosurfaceopacity) * 0.01]
     2190        set style(-isosurfaceopacity) $_settings(-isosurfaceopacity)
    21862191    }
    21872192    if { $_changed(-numcontours) } {
     
    21962201    }
    21972202    if { $_contourList(numLevels) != $style(-levels) } {
    2198         set _settings(-numcontours) $style(-levels)
    2199         $itk_component(numcontours) value $style(-levels)
    2200         set _contourList(numLevels) $style(-levels)
     2203        if { [llength $style(-levels)] > 1 } {
     2204            set _contourList(reqValues) [lsort -real $style(-levels)]
     2205        } else {
     2206            set _settings(-numcontours) $style(-levels)
     2207            $itk_component(numcontours) value $style(-levels)
     2208            set _contourList(numLevels) $style(-levels)
     2209        }
    22012210        EventuallyChangeContourLevels
    22022211    }
     
    22282237    SendCmd "contour3d linecolor [Color2RGB $style(-edgecolor)] $tag"
    22292238    SendCmd "contour3d linewidth $style(-linewidth) $tag"
    2230     SendCmd "contour3d opacity $style(-opacity) $tag"
    2231     set _settings(-isosurfaceopacity) [expr $style(-opacity) * 100.0]
     2239    SendCmd "contour3d opacity $style(-isosurfaceopacity) $tag"
     2240    set _settings(-isosurfaceopacity) $style(-isosurfaceopacity)
    22322241    SetCurrentColormap $style(-color)
    22332242    SendCmd "contour3d wireframe $style(-wireframe) $tag"
     
    25932602itcl::body Rappture::VtkIsosurfaceViewer::GenerateContourList {} {
    25942603    if { ![info exists _limits($_curFldName)] } {
     2604        puts stderr "no _curFldName"
    25952605        return ""
    25962606    }
    25972607    if { $_contourList(numLevels) < 1 } {
     2608        puts stderr "numLevels < 1"
    25982609        return ""
    25992610    }
    2600     foreach { vmin vmax } $_limits($_curFldName) break
    2601     set v [blt::vector create \#auto]
    2602     $v seq $vmin $vmax [expr $_contourList(numLevels)+2]
    2603     $v delete end 0
    2604     set values [$v range 0 end]
    2605     blt::vector destroy $v
     2611    if { [llength $_contourList(reqValues)] > 1 } {
     2612        set values $_contourList(reqValues)
     2613    } else {
     2614        foreach { vmin vmax } $_limits($_curFldName) break
     2615        set v [blt::vector create \#auto]
     2616        $v seq $vmin $vmax [expr $_contourList(numLevels)+2]
     2617        $v delete end 0
     2618        set values [$v range 0 end]
     2619        blt::vector destroy $v
     2620    }
    26062621    set _contourList(values) $values
    26072622}
Note: See TracChangeset for help on using the changeset viewer.