Changeset 3967 for trunk/gui


Ignore:
Timestamp:
Oct 1, 2013 3:52:19 PM (11 years ago)
Author:
gah
Message:

initial transfer of transferfunction editor to vtkvolumeviewer

Location:
trunk/gui/scripts
Files:
3 edited

Legend:

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

    r3966 r3967  
    961961            }
    962962            if { $_viewer == "" } {
    963                 set _viewer [expr {($_dim == 3) ? "nanovis" : "contour"}]
     963                set _viewer [expr {($_dim == 3) ? "vtkvolume" : "contour"}]
    964964            }
    965965            set _comp2vtk($cname) $vtkdata
  • trunk/gui/scripts/filechoiceentry.tcl

    r3965 r3967  
    222222        }
    223223        set root [file root $tail]
    224         puts stderr "file=$file tail=$tail"
    225224        $itk_component(choice) choices insert end $file $tail
    226225        set _str2val($tail) $file
     
    239238# ----------------------------------------------------------------------
    240239itcl::body Rappture::FileChoiceEntry::NewValue {} {
     240    puts stderr "new value in FileChoiceEntry"
    241241    event generate $itk_component(hull) <<Value>>
    242242}
  • trunk/gui/scripts/vtkvolumeviewer.tcl

    r3963 r3967  
    6262    }
    6363    public method scale {args}
     64    public method updateTransferFunctions {}
     65
     66    private method HideAllMarkers {}
     67    private method GetColormap { cname color }
     68    private method ResetColormap { cname color }
     69    private method InitComponentSettings { cname }
     70    private method SwitchComponent { cname }
     71    private method GetDatasetsWithComponent { cname }
     72    private method ComputeAlphamap { cname }
     73    private method ComputeTransferFunction { cname }
     74    private method SetInitialTransferFunction { dataobj cname }
     75    private method SendTransferFunctions {}
     76    private method ParseLevelsOption { cname levels }
     77    private method ParseMarkersOption { cname markers }
     78    private method BuildVolumeComponents {}
     79    private variable _serverDatasets   ;# contains all the dataobj-component
     80                                   ;# to volumes in the server
     81    private variable _current "";       # Currently selected component
     82    private variable _volcomponents   ; # Array of components found
     83    private variable _componentsList   ; # Array of components found
     84    private variable _cname2style
     85    private variable _cname2transferFunction
     86    private variable _cname2defaultcolormap
     87    private variable _cname2defaultalphamap
     88
     89    private variable _parsedFunction
     90    private variable _transferFunctionEditors
    6491
    6592    protected method Connect {}
     
    81108
    82109    # The following methods are only used by this class.
     110
    83111    private method BuildAxisTab {}
    84112    private method BuildCameraTab {}
     
    88116    private method BuildVolumeTab {}
    89117    private method DrawLegend {}
     118    private method DrawLegendOld {}
    90119    private method Combo { option }
    91120    private method EnterLegend { x y }
    92121    private method EventuallyResize { w h }
    93     private method EventuallyReseed { numPoints }
     122    private method EventuallyRequestLegend {}
    94123    private method EventuallyRotate { q }
    95124    private method EventuallySetCutplane { axis args }
     
    157186    package require vtk
    158187    set _serverType "vtkvis"
     188
     189    EnableWaitDialog 900
    159190
    160191    # Rebuild event
     
    234265        volume-blendmode        composite
    235266        volumeLighting          1
    236         volume-ambient          40
    237         volume-diffuse          60
     267        volumeAmbient          40
     268        volumeDiffuse          60
     269        volumeThickness        350
    238270        volume-specularLevel    30
    239271        volume-specularExponent 90
     
    352384    set _image(legend) [image create photo]
    353385    itk_component add legend {
    354         canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0
     386        canvas $itk_component(plotarea).legend -height 50 -highlightthickness 0
    355387    } {
    356388        usual
     
    365397    pack forget $itk_component(view)
    366398    blt::table $itk_component(plotarea) \
    367         0,0 $itk_component(view) -fill both -reqwidth $w
    368     blt::table configure $itk_component(plotarea) c1 -resize none
     399        0,0 $itk_component(view) -fill both -reqwidth $w  \
     400        1,0 $itk_component(legend) -fill x
     401    blt::table configure $itk_component(plotarea) r1 -resize none
    369402
    370403    # Bindings for rotation via mouse
     
    452485    SendCmd "screen size $_width $_height"
    453486
    454     set _legendPending 1
     487    EventuallyRequestLegend
    455488    set _resizePending 0
    456489}
     
    472505}
    473506
    474 itcl::body Rappture::VtkVolumeViewer::EventuallyReseed { numPoints } {
    475     set _numSeeds $numPoints
    476     if { !$_reseedPending } {
    477         set _reseedPending 1
    478         $_dispatcher event -after 600 !reseed
     507itcl::body Rappture::VtkVolumeViewer::EventuallyRequestLegend {} {
     508    if { !$_legendPending } {
     509        set _legendPending 1
     510        $_dispatcher event -after 600 !legend
    479511    }
    480512}
     
    648680# ----------------------------------------------------------------------
    649681itcl::body Rappture::VtkVolumeViewer::scale {args} {
     682    array set style {
     683        -color BCGYR
     684        -levels 6
     685        -opacity 1.0
     686        -markers ""
     687    }
     688    array unset _limits
     689    array unset _volcomponents
     690    foreach dataobj $args {
     691        if { ![$dataobj isvalid] } {
     692            continue;                     # Object doesn't contain valid data.
     693        }
     694        foreach cname [$dataobj components] {
     695            array unset limits
     696            array set limits [$dataobj valueLimits $cname]
     697            set _limits($cname) $limits(v)
     698            if { ![info exists _volcomponents($cname)] } {
     699                lappend _componentsList $cname
     700                ComputeTransferFunction $cname
     701            }
     702            lappend _volcomponents($cname) $dataobj-$cname
     703        }
     704        foreach axis {x y z v} {
     705            foreach { min max } [$dataobj limits $axis] break
     706            if {"" != $min && "" != $max} {
     707                if { ![info exists _limits($axis)] } {
     708                    set _limits($axis) [list $min $max]
     709                } else {
     710                    foreach {amin amax} $_limits($axis) break
     711                    if {$min < $amin} {
     712                        set amin $min
     713                    }
     714                    if {$max > $amax} {
     715                        set amax $max
     716                    }
     717                    set _limits($axis) [list $amin $amax]
     718                }
     719            }
     720        }
     721    }
     722    BuildVolumeComponents
     723
    650724    foreach dataobj $args {
    651725        foreach axis { x y z } {
     
    10371111    }
    10381112
    1039     InitSettings volume-palette \
    1040         volume-ambient volume-diffuse volume-specularLevel volume-specularExponent \
     1113    InitSettings volumeColormap \
     1114        volumeAmbient volumeDiffuse volume-specularLevel volume-specularExponent \
    10411115        volume-opacity volume-quality volumeVisible \
    10421116        cutplaneVisible \
     
    13101384            }
    13111385        }
    1312         "volume-ambient" {
    1313             set val $_settings(volume-ambient)
     1386        "volumeAmbient" {
     1387            set val $_settings(volumeAmbient)
    13141388            set ambient [expr {0.01*$val}]
    13151389            foreach dataset [CurrentDatasets -visible] {
     
    13171391            }
    13181392        }
    1319         "volume-diffuse" {
    1320             set val $_settings(volume-diffuse)
     1393        "volumeDiffuse" {
     1394            set val $_settings(volumeDiffuse)
    13211395            set diffuse [expr {0.01*$val}]
    13221396            foreach dataset [CurrentDatasets -visible] {
     
    14241498            set _cutplanePending 0
    14251499        }
    1426         "volume-palette" {
    1427             set palette [$itk_component(palette) value]
    1428             set _settings(volume-palette) $palette
    1429             foreach dataset [CurrentDatasets -visible $_first] {
    1430                 foreach {dataobj comp} [split $dataset -] break
    1431                 ChangeColormap $dataobj $comp $palette
    1432             }
     1500        "thickness" {
     1501            set val $_settings($this-thickness)
     1502            set _settings($_current-thickness) $val
     1503            updateTransferFunctions
     1504        }
     1505        "volumeColormap" {
     1506            set color [$itk_component(colormap) value]
     1507            set _settings($this-colormap) $color
     1508            set _settings($_current-colormap) $color
     1509            ResetColormap $_current $color
    14331510            set _legendPending 1
    14341511        }
     
    14731550itcl::body Rappture::VtkVolumeViewer::RequestLegend {} {
    14741551    set font "Arial 8"
    1475     set lineht [font metrics $font -linespace]
    1476     set w 12
    1477     set h [expr {$_height - 3 * ($lineht + 2)}]
    1478     if { $h < 1 } {
    1479         return
    1480     }
     1552    set lineht [font metrics $itk_option(-font) -linespace]
     1553    set c $itk_component(legend)
     1554    set w [winfo width $c]
     1555    set h [winfo height $c]
     1556    set h [expr {$h-$lineht-20}]
     1557    puts stderr "legend w=$w h=$h"
    14811558    # Set the legend on the first volume dataset.
    14821559    foreach dataset [CurrentDatasets -visible $_first] {
     
    15931670    $inner configure -borderwidth 4
    15941671
     1672    label $inner.volcomponents_l -text "Component" -font $font
     1673    itk_component add volcomponents {
     1674        Rappture::Combobox $inner.volcomponents -editable no
     1675    }
     1676    $itk_component(volcomponents) value "BCGYR"
     1677    bind $inner.volcomponents <<Value>> \
     1678        [itcl::code $this AdjustSetting current]
     1679
    15951680    checkbutton $inner.visibility \
    15961681        -text "Visible" \
     
    16131698        -font $font
    16141699    ::scale $inner.ambient -from 0 -to 100 -orient horizontal \
    1615         -variable [itcl::scope _settings(volume-ambient)] \
    1616         -showvalue off -command [itcl::code $this AdjustSetting volume-ambient] \
     1700        -variable [itcl::scope _settings(volumeAmbient)] \
     1701        -showvalue off -command [itcl::code $this AdjustSetting volumeAmbient] \
    16171702        -troughcolor grey92
    16181703
    16191704    label $inner.diffuse_l -text "Diffuse" -font $font
    16201705    ::scale $inner.diffuse -from 0 -to 100 -orient horizontal \
    1621         -variable [itcl::scope _settings(volume-diffuse)] \
    1622         -showvalue off -command [itcl::code $this AdjustSetting volume-diffuse] \
     1706        -variable [itcl::scope _settings(volumeDiffuse)] \
     1707        -showvalue off -command [itcl::code $this AdjustSetting volumeDiffuse] \
    16231708        -troughcolor grey92
    16241709
     
    16571742        -text "Transfer Function" -font "Arial 9 bold"
    16581743
    1659     label $inner.palette_l -text "Colormap" -font $font
    1660     itk_component add palette {
    1661         Rappture::Combobox $inner.palette -width 10 -editable no
    1662     }
    1663     $inner.palette choices insert end \
     1744    label $inner.thin -text "Thin" -font $font
     1745    ::scale $inner.thickness -from 0 -to 1000 -orient horizontal \
     1746        -variable [itcl::scope _settings($this-thickness)] \
     1747        -showvalue off -command [itcl::code $this AdjustSetting thickness] \
     1748        -troughcolor grey92
     1749
     1750    label $inner.thick -text "Thick" -font $font
     1751
     1752
     1753    label $inner.colormap_l -text "Colormap" -font $font
     1754    itk_component add colormap {
     1755        Rappture::Combobox $inner.colormap -width 10 -editable no
     1756    }
     1757    $inner.colormap choices insert end \
    16641758        "BCGYR"              "BCGYR"            \
    16651759        "BGYOR"              "BGYOR"            \
     
    16791773        "orange-to-blue"     "orange-to-blue"   
    16801774
    1681     $itk_component(palette) value "BCGYR"
    1682     bind $inner.palette <<Value>> \
    1683         [itcl::code $this AdjustSetting volume-palette]
     1775    $itk_component(colormap) value "BCGYR"
     1776    bind $inner.colormap <<Value>> \
     1777        [itcl::code $this AdjustSetting volumeColormap]
    16841778
    16851779    label $inner.blendmode_l -text "Blend Mode" -font "Arial 9"
     
    16971791
    16981792    blt::table $inner \
    1699         0,0 $inner.field_l   -anchor e -cspan 2  \
    1700         0,2 $inner.field               -cspan 3 -fill x \
    1701         1,1 $inner.lighting_l -anchor w -cspan 4 \
    1702         2,1 $inner.lighting   -anchor w -cspan 3 \
    1703         3,1 $inner.ambient_l       -anchor e -pady 2 \
    1704         3,2 $inner.ambient                   -cspan 3 -fill x \
    1705         4,1 $inner.diffuse_l       -anchor e -pady 2 \
    1706         4,2 $inner.diffuse                   -cspan 3 -fill x \
    1707         5,1 $inner.specularLevel_l -anchor e -pady 2 \
    1708         5,2 $inner.specularLevel             -cspan 3 -fill x \
    1709         6,1 $inner.specularExponent_l -anchor e -pady 2 \
    1710         6,2 $inner.specularExponent          -cspan 3 -fill x \
    1711         7,1 $inner.visibility    -anchor w -cspan 3 \
    1712         8,1 $inner.quality_l -anchor e -pady 2 \
    1713         8,2 $inner.quality                     -cspan 3 -fill x \
    1714         9,1 $inner.transferfunction_l -anchor w              -cspan 4 \
    1715         10,1 $inner.opacity_l -anchor e -pady 2 \
    1716         10,2 $inner.opacity                    -cspan 3 -fill x \
    1717         11,1 $inner.palette_l -anchor e  \
    1718         11,2 $inner.palette                 -padx 2 -cspan 3 -fill x \
    1719         12,1 $inner.blendmode_l -anchor e  \
    1720         12,2 $inner.blendmode               -padx 2 -cspan 3 -fill x \
     1793        0,0 $inner.volcomponents_l -anchor e -cspan 2 \
     1794        0,2 $inner.volcomponents             -cspan 3 -fill x \
     1795        1,0 $inner.field_l   -anchor e -cspan 2  \
     1796        1,2 $inner.field               -cspan 3 -fill x \
     1797        2,1 $inner.lighting_l -anchor w -cspan 4 \
     1798        3,1 $inner.lighting   -anchor w -cspan 3 \
     1799        4,1 $inner.ambient_l       -anchor e -pady 2 \
     1800        4,2 $inner.ambient                   -cspan 3 -fill x \
     1801        5,1 $inner.diffuse_l       -anchor e -pady 2 \
     1802        5,2 $inner.diffuse                   -cspan 3 -fill x \
     1803        6,1 $inner.specularLevel_l -anchor e -pady 2 \
     1804        6,2 $inner.specularLevel             -cspan 3 -fill x \
     1805        7,1 $inner.specularExponent_l -anchor e -pady 2 \
     1806        7,2 $inner.specularExponent          -cspan 3 -fill x \
     1807        8,1 $inner.visibility    -anchor w -cspan 3 \
     1808        9,1 $inner.quality_l -anchor e -pady 2 \
     1809        9,2 $inner.quality                     -cspan 3 -fill x \
     1810        10,1 $inner.transferfunction_l -anchor w              -cspan 4 \
     1811        11,1 $inner.opacity_l -anchor e -pady 2 \
     1812        11,2 $inner.opacity                    -cspan 3 -fill x \
     1813        12,1 $inner.colormap_l -anchor e  \
     1814        12,2 $inner.colormap                 -padx 2 -cspan 3 -fill x \
     1815        13,1 $inner.blendmode_l -anchor e  \
     1816        13,2 $inner.blendmode               -padx 2 -cspan 3 -fill x \
     1817        14,1 $inner.thin             -anchor e \
     1818        14,2 $inner.thickness                 -cspan 2 -fill x \
     1819        14,4 $inner.thick -anchor w 
    17211820
    17221821    blt::table configure $inner r* c* -resize none
    17231822    blt::table configure $inner r* -pady { 2 0 }
    1724     blt::table configure $inner c2 c3 r13 -resize expand
     1823    blt::table configure $inner c2 c3 r15 -resize expand
    17251824    blt::table configure $inner c0 -width .1i
    17261825}
     
    20712170}
    20722171
    2073 itcl::body Rappture::VtkVolumeViewer::SetObjectStyle { dataobj comp } {
     2172itcl::body Rappture::VtkVolumeViewer::SetObjectStyle { dataobj cname } {
    20742173    # Parse style string.
    2075     set tag $dataobj-$comp
    2076     set style [$dataobj style $comp]
     2174    set tag $dataobj-$cname
     2175    set style [$dataobj style $cname]
    20772176    array set settings {
    20782177        -color \#808080
     
    20942193    SendCmd "cutplane add $tag"
    20952194    SendCmd "cutplane visible 0 $tag"
    2096 
    20972195    SendCmd "volume lighting $settings(-lighting) $tag"
    20982196    set _settings(volumeLighting) $settings(-lighting)
    2099     SetColormap $dataobj $comp
     2197    SetInitialTransferFunction $dataobj $cname
     2198    SendCmd "volume colormap $cname $tag"
    21002199}
    21012200
     
    21162215itcl::body Rappture::VtkVolumeViewer::ReceiveLegend { colormap title vmin vmax size } {
    21172216    set _legendPending 0
    2118     puts stderr "ReceiveLegend colormap=$colormap title=$title range=$vmin,$vmax size=$size"
    21192217    if { [IsConnected] } {
    21202218        set bytes [ReceiveBytes $size]
     
    21232221        }
    21242222        $_image(legend) configure -data $bytes
    2125         #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
     2223        puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
    21262224        if { [catch {DrawLegend} errs] != 0 } {
    21272225            puts stderr errs=$errs
     
    21332231# DrawLegend --
    21342232#
     2233itcl::body Rappture::VtkVolumeViewer::DrawLegend {} {
     2234    if { $_current == "" } {
     2235        set _current "component"
     2236    }
     2237    set cname $_current
     2238    set c $itk_component(legend)
     2239    set w [winfo width $c]
     2240    set h [winfo height $c]
     2241    set lx 10
     2242    set ly [expr {$h - 1}]
     2243    if {"" == [$c find withtag transfunc]} {
     2244        $c create image 10 10 -anchor nw \
     2245            -image $_image(legend) -tags transfunc
     2246        $c create text $lx $ly -anchor sw \
     2247            -fill $itk_option(-plotforeground) -tags "limits text vmin"
     2248        $c create text [expr {$w-$lx}] $ly -anchor se \
     2249            -fill $itk_option(-plotforeground) -tags "limits text vmax"
     2250        $c create text [expr {$w/2}] $ly -anchor s \
     2251            -fill $itk_option(-plotforeground) -tags "limits text title"
     2252        $c lower transfunc
     2253    }
     2254
     2255    # Display the markers used by the current transfer function.
     2256    HideAllMarkers
     2257    if { [info exists _transferFunctionEditors($cname)] } {
     2258        $_transferFunctionEditors($cname) showMarkers $_limits($cname)
     2259    }
     2260
     2261    foreach {min max} $_limits($cname) break
     2262    $c itemconfigure vmin -text [format %.2g $min]
     2263    $c coords vmin $lx $ly
     2264
     2265    $c itemconfigure vmax -text [format %.2g $max]
     2266    $c coords vmax [expr {$w-$lx}] $ly
     2267
     2268    set title ""
     2269    if { $_first != "" } {
     2270        set title [$_first hints label]
     2271        set units [$_first hints units]
     2272        if { $units != "" } {
     2273            set title "$title ($units)"
     2274        }
     2275    }
     2276    $c itemconfigure title -text $title
     2277    $c coords title [expr {$w/2}] $ly
     2278}
     2279
     2280#
     2281# DrawLegendOld --
     2282#
    21352283#       Draws the legend in it's own canvas which resides to the right
    21362284#       of the contour plot area.
    21372285#
    2138 itcl::body Rappture::VtkVolumeViewer::DrawLegend { } {
     2286itcl::body Rappture::VtkVolumeViewer::DrawLegendOld { } {
    21392287    set fname $_curFldName
    21402288    set c $itk_component(view)
     
    23222470            set x [expr $x1 + [winfo rootx $itk_component(view)]]
    23232471            set y [expr $y2 + [winfo rooty $itk_component(view)]]
    2324             puts stderr "combo x=$x y=$y"
    23252472            tk_popup $itk_component(fieldmenu) $x $y
    23262473        }
     
    23412488}
    23422489
     2490#
     2491# The -levels option takes a single value that represents the number
     2492# of evenly distributed markers based on the current data range. Each
     2493# marker is a relative value from 0.0 to 1.0.
     2494#
     2495itcl::body Rappture::VtkVolumeViewer::ParseLevelsOption { cname levels } {
     2496    set c $itk_component(legend)
     2497    set list {}
     2498    regsub -all "," $levels " " levels
     2499    if {[string is int $levels]} {
     2500        for {set i 1} { $i <= $levels } {incr i} {
     2501            lappend list [expr {double($i)/($levels+1)}]
     2502        }
     2503    } else {
     2504        foreach x $levels {
     2505            lappend list $x
     2506        }
     2507    }
     2508    set _parsedFunction($cname) 1
     2509    $_transferFunctionEditors($cname) addMarkers $list
     2510}
     2511
     2512#
     2513# The -markers option takes a list of zero or more values (the values
     2514# may be separated either by spaces or commas) that have the following
     2515# format:
     2516#
     2517#   N%  Percent of current total data range.  Converted to
     2518#       to a relative value between 0.0 and 1.0.
     2519#   N   Absolute value of marker.  If the marker is outside of
     2520#       the current range, it will be displayed on the outer
     2521#       edge of the legends, but it range it represents will
     2522#       not be seen.
     2523#
     2524itcl::body Rappture::VtkVolumeViewer::ParseMarkersOption { cname markers } {
     2525    set c $itk_component(legend)
     2526    set list {}
     2527    foreach { min max } $_limits($cname) break
     2528    regsub -all "," $markers " " markers
     2529    foreach marker $markers {
     2530        set n [scan $marker "%g%s" value suffix]
     2531        if { $n == 2 && $suffix == "%" } {
     2532            # $n% : Set relative value (0..1).
     2533            lappend list [expr {$value * 0.01}]
     2534        } else {
     2535            # $n : absolute value, compute relative
     2536            lappend list  [expr {(double($value)-$min)/($max-$min)]}
     2537        }
     2538    }
     2539    set _parsedFunction($cname) 1
     2540    $_transferFunctionEditors($cname) addMarkers $list
     2541}
     2542
     2543#
     2544# SetInitialTransferFunction --
     2545#
     2546#       Creates a transfer function name based on the <style> settings in the
     2547#       library run.xml file. This placeholder will be used later to create
     2548#       and send the actual transfer function once the data info has been sent
     2549#       to us by the render server. [We won't know the volume limits until the
     2550#       server parses the 3D data and sends back the limits via ReceiveData.]
     2551#
     2552itcl::body Rappture::VtkVolumeViewer::SetInitialTransferFunction { dataobj cname } {
     2553    set tag $dataobj-$cname
     2554    if { ![info exists _cname2transferFunction($cname)] } {
     2555        ComputeTransferFunction $cname
     2556    }
     2557    set _dataset2style($tag) $cname
     2558    lappend _style2datasets($cname) $tag
     2559
     2560    return $cname
     2561}
     2562
     2563#
     2564# ComputeTransferFunction --
     2565#
     2566#       Computes and sends the transfer function to the render server.  It's
     2567#       assumed that the volume data limits are known and that the global
     2568#       transfer-functions slider values have been set up.  Both parts are
     2569#       needed to compute the relative value (location) of the marker, and
     2570#       the alpha map of the transfer function.
     2571#
     2572itcl::body Rappture::VtkVolumeViewer::ComputeTransferFunction { cname } {
     2573
     2574    if { ![info exists _transferFunctionEditors($cname)] } {
     2575        set _transferFunctionEditors($cname) \
     2576            [Rappture::TransferFunctionEditor ::\#auto $itk_component(legend) \
     2577                 $cname \
     2578                 -command [itcl::code $this updateTransferFunctions]]
     2579    }
     2580
     2581    # We have to parse the style attributes for a volume using this
     2582    # transfer-function *once*.  This sets up the initial isomarkers for the
     2583    # transfer function.  The user may add/delete markers, so we have to
     2584    # maintain a list of markers for each transfer-function.  We use the one
     2585    # of the volumes (the first in the list) using the transfer-function as a
     2586    # reference.
     2587
     2588    if { ![info exists _parsedFunction($cname)] || ![info exists _cname2transferFunction($cname)] } {
     2589        array set style {
     2590            -color BCGYR
     2591            -levels 6
     2592            -opacity 1.0
     2593            -markers ""
     2594        }
     2595
     2596        # Accumulate the style from all the datasets using it.
     2597        foreach tag [GetDatasetsWithComponent $cname] {
     2598            foreach {dataobj cname} [split [lindex $tag 0] -] break
     2599            array set style [lindex [$dataobj components -style $cname] 0]
     2600        }
     2601        set cmap [ColorsToColormap $style(-color)]
     2602        set _cname2defaultcolormap($cname) $cmap
     2603        set _settings($cname-colormap) $style(-color)
     2604        if { [info exists _transferFunctionEditors($cname)] } {
     2605            eval $_transferFunctionEditors($cname) limits $_limits($cname)
     2606        }
     2607        if { [info exists style(-markers)] &&
     2608             [llength $style(-markers)] > 0 } {
     2609            ParseMarkersOption $cname $style(-markers)
     2610        } else {
     2611            ParseLevelsOption $cname $style(-levels)
     2612        }
     2613    } else {
     2614        foreach {cmap wmap} $_cname2transferFunction($cname) break
     2615    }
     2616
     2617    set wmap [ComputeAlphamap $cname]
     2618    set _cname2transferFunction($cname) [list $cmap $wmap]
     2619    SendCmd [list colormap add $cname $cmap $wmap]
     2620}
     2621
     2622#
     2623# ResetColormap --
     2624#
     2625#       Changes only the colormap portion of the transfer function.
     2626#
     2627itcl::body Rappture::VtkVolumeViewer::ResetColormap { cname color } {
     2628    # Get the current transfer function
     2629    if { ![info exists _cname2transferFunction($cname)] } {
     2630        return
     2631    }
     2632    foreach { cmap wmap } $_cname2transferFunction($cname) break
     2633    set cmap [GetColormap $cname $color]
     2634    set _cname2transferFunction($cname) [list $cmap $wmap]
     2635    SendCmd [list colormap add $cname $cmap $wmap]
     2636    DrawLegend
     2637}
     2638
     2639# ----------------------------------------------------------------------
     2640# USAGE: updateTransferFunctions
     2641#
     2642#       This is called by the transfer function editor whenever the
     2643#       transfer function definition changes.
     2644#
     2645# ----------------------------------------------------------------------
     2646itcl::body Rappture::VtkVolumeViewer::updateTransferFunctions {} {
     2647    foreach cname [array names _volcomponents] {
     2648        ComputeTransferFunction $cname
     2649    }
     2650    DrawLegend
     2651}
     2652
     2653#
     2654# InitComponentSettings --
     2655#
     2656#       Initializes the volume settings for a specific component. This
     2657#       should match what's used as global settings above. This
     2658#       is called the first time we try to switch to a given component
     2659#       in SwitchComponent below.
     2660#
     2661itcl::body Rappture::VtkVolumeViewer::InitComponentSettings { cname } {
     2662    array set _settings [subst {
     2663        $cname-ambient           60
     2664        $cname-colormap          default
     2665        $cname-diffuse           40
     2666        $cname-light2side        1
     2667        $cname-opacity           100
     2668        $cname-outline           0
     2669        $cname-specularExponent  90
     2670        $cname-specularLevel     30
     2671        $cname-thickness         350
     2672        $cname-transp            50
     2673        $cname-volumeVisible     1
     2674    }]
     2675}
     2676
     2677#
     2678# SwitchComponent --
     2679#
     2680#       This is called when the current component is changed by the
     2681#       dropdown menu in the volume tab.  It synchronizes the global
     2682#       volume settings with the settings of the new current component.
     2683#
     2684itcl::body Rappture::VtkVolumeViewer::SwitchComponent { cname } {
     2685    if { ![info exists _settings($cname-ambient)] } {
     2686        InitComponentSettings $cname
     2687    }
     2688    # _settings variables change widgets, except for colormap
     2689    set _settings($this-ambient)          $_settings($cname-ambient)
     2690    set _settings($this-colormap)         $_settings($cname-colormap)
     2691    set _settings($this-diffuse)          $_settings($cname-diffuse)
     2692    set _settings($this-light2side)       $_settings($cname-light2side)
     2693    set _settings($this-opacity)          $_settings($cname-opacity)
     2694    set _settings($this-outline)          $_settings($cname-outline)
     2695    set _settings($this-specularExponent) $_settings($cname-specularExponent)
     2696    set _settings($this-specularLevel)    $_settings($cname-specularLevel)
     2697    set _settings($this-thickness)        $_settings($cname-thickness)
     2698    set _settings($this-transp)           $_settings($cname-transp)
     2699    set _settings($this-volumeVisible)    $_settings($cname-volumeVisible)
     2700    $itk_component(colormap) value        $_settings($cname-colormap)
     2701    set _current $cname;                # Reset the current component
     2702}
     2703
     2704itcl::body Rappture::VtkVolumeViewer::ComputeAlphamap { cname } {
     2705    if { ![info exists _transferFunctionEditors($cname)] } {
     2706        return [list 0.0 0.0 1.0 1.0]
     2707    }
     2708    if { ![info exists _settings($cname-ambient)] } {
     2709        InitComponentSettings $cname
     2710    }
     2711    set max 1.0 ;                       #$_settings($tag-opacity)
     2712
     2713    set isovalues [$_transferFunctionEditors($cname) values]
     2714
     2715    # Ensure that the global opacity and thickness settings (in the slider
     2716    # settings widgets) are used for the active transfer-function.  Update
     2717    # the values in the _settings varible.
     2718    set opacity [expr { double($_settings($cname-opacity)) * 0.01 }]
     2719
     2720    # Scale values between 0.00001 and 0.01000
     2721    set delta [expr {double($_settings($cname-thickness)) * 0.0001}]
     2722   
     2723    set first [lindex $isovalues 0]
     2724    set last [lindex $isovalues end]
     2725    set wmap ""
     2726    if { $first == "" || $first != 0.0 } {
     2727        lappend wmap 0.0 0.0
     2728    }
     2729    foreach x $isovalues {
     2730        set x1 [expr {$x-$delta-0.00001}]
     2731        set x2 [expr {$x-$delta}]
     2732        set x3 [expr {$x+$delta}]
     2733        set x4 [expr {$x+$delta+0.00001}]
     2734        if { $x1 < 0.0 } {
     2735            set x1 0.0
     2736        } elseif { $x1 > 1.0 } {
     2737            set x1 1.0
     2738        }
     2739        if { $x2 < 0.0 } {
     2740            set x2 0.0
     2741        } elseif { $x2 > 1.0 } {
     2742            set x2 1.0
     2743        }
     2744        if { $x3 < 0.0 } {
     2745            set x3 0.0
     2746        } elseif { $x3 > 1.0 } {
     2747            set x3 1.0
     2748        }
     2749        if { $x4 < 0.0 } {
     2750            set x4 0.0
     2751        } elseif { $x4 > 1.0 } {
     2752            set x4 1.0
     2753        }
     2754        # add spikes in the middle
     2755        lappend wmap $x1 0.0
     2756        lappend wmap $x2 $max
     2757        lappend wmap $x3 $max
     2758        lappend wmap $x4 0.0
     2759    }
     2760    if { $last == "" || $last != 1.0 } {
     2761        lappend wmap 1.0 0.0
     2762    }
     2763    return $wmap
     2764}
     2765
     2766#
     2767# HideAllMarkers --
     2768#
     2769#       Hide all the markers in all the transfer functions.  Can't simply
     2770#       delete and recreate markers from the <style> since the user may
     2771#       have create, deleted, or moved markers.
     2772#
     2773itcl::body Rappture::VtkVolumeViewer::HideAllMarkers {} {
     2774    foreach cname [array names _transferFunctionEditors] {
     2775        $_transferFunctionEditors($cname) hideMarkers
     2776    }
     2777}
     2778
     2779
     2780#
     2781# GetDatasetsWithComponents --
     2782#
     2783#       Returns a list of all the datasets (known by the combination of
     2784#       their data object and component name) that match the given
     2785#       component name.  For example, this is used where we want to change
     2786#       the settings of volumes that have the current component.
     2787#
     2788itcl::body Rappture::VtkVolumeViewer::GetDatasetsWithComponent { cname } {
     2789    if { ![info exists _volcomponents($cname)] } {
     2790        return ""
     2791    }
     2792    set list ""
     2793    foreach tag $_volcomponents($cname) {
     2794        if { ![info exists _serverDatasets($tag)] } {
     2795            continue
     2796        }
     2797        lappend list $tag
     2798    }
     2799    return $list
     2800}
     2801
     2802#
     2803# BuildVolumeComponents --
     2804#
     2805#       This is called from the "scale" method which is called when a
     2806#       new dataset is added or deleted.  It repopulates the dropdown
     2807#       menu of volume component names.  It sets the current component
     2808#       to the first component in the list (of components found).
     2809#       Finally, if there is only one component, don't display the
     2810#       label or the combobox in the volume settings tab.
     2811#
     2812itcl::body Rappture::VtkVolumeViewer::BuildVolumeComponents {} {
     2813    $itk_component(volcomponents) choices delete 0 end
     2814    foreach name $_componentsList {
     2815        $itk_component(volcomponents) choices insert end $name $name
     2816    }
     2817    set _current [lindex $_componentsList 0]
     2818    $itk_component(volcomponents) value $_current
     2819    set parent [winfo parent $itk_component(volcomponents)]
     2820    if { [llength $_componentsList] <= 1 } {
     2821        # Unpack the components label and dropdown if there's only one
     2822        # component.
     2823        blt::table forget $parent.volcomponents_l $parent.volcomponents
     2824    } else {
     2825        # Pack the components label and dropdown into the table there's
     2826        # more than one component to select.
     2827        blt::table $parent \
     2828            0,0 $parent.volcomponents_l -anchor e -cspan 2 \
     2829            0,2 $parent.volcomponents -cspan 3 -fill x
     2830    }
     2831}
     2832
     2833itcl::body Rappture::VtkVolumeViewer::GetColormap { cname color } {
     2834    if { $color == "default" } {
     2835        return $_cname2defaultcolormap($cname)
     2836    }
     2837    return [ColorsToColormap $color]
     2838}
Note: See TracChangeset for help on using the changeset viewer.