Changeset 878 for trunk/gui/scripts


Ignore:
Timestamp:
Feb 12, 2008, 11:46:17 AM (17 years ago)
Author:
gah
Message:

nanovis isosurface interface

Location:
trunk/gui/scripts
Files:
2 edited

Legend:

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

    r858 r878  
    674674        } else {
    675675            set r [blt::vector expr {max($xv) - min($xv)}]
    676             set z [expr {$r / ([$xv length]-1)}]
     676            set z [expr {$r / ([$xv length]-1) * 0.8}]
    677677            foreach x [$xv range 0 end] y [$yv range 0 end] {
    678678                set elem "elem[incr count]"
  • trunk/gui/scripts/nanovisviewer.tcl

    r783 r878  
    1717
    1818option add *NanovisViewer.width 4i widgetDefault
     19option add *NanovisViewer*cursor crosshair widgetDefault
    1920option add *NanovisViewer.height 4i widgetDefault
    2021option add *NanovisViewer.foreground black widgetDefault
     
    4344    public method delete {args}
    4445    public method scale {args}
     46    public method getLimits {} {
     47        return [list $_limits(vmin) $_limits(vmax)]
     48    }
    4549    public method download {option args}
    4650    public method parameters {title args} { # do nothing }
    47 
    4851    public method connect {{hostlist ""}}
    4952    public method disconnect {}
     
    5356    protected method _send_text {string}
    5457    protected method _send_dataobjs {}
     58    protected method _send_transfuncs {}
    5559    protected method _send_echo {channel {data ""}}
    5660    protected method _receive {}
    5761    protected method _receive_image {option size}
    5862    protected method _receive_legend {ivol vmin vmax size}
     63    protected method _receive_data {args}
    5964    protected method _receive_echo {channel {data ""}}
    6065
     
    6671    protected method _slicertip {axis}
    6772    protected method _probe {option args}
     73    protected method _marker {index option args}
    6874
    6975    protected method _state {comp}
     
    7278    protected method _serverDown {}
    7379    protected method _getTransfuncData {dataobj comp}
     80    public method update_transfer_function {}
     81    public method remove_duplicate_isomarker { m x }
     82    public method _addIsoMarker { x y }
     83    protected method _initIsoMarkers {dataobj comp}
    7484    protected method _color2rgb {color}
    7585    protected method _euler2xyz {theta phi psi}
     
    8898    private variable _obj2ovride   ;# maps dataobj => style override
    8999    private variable _obj2id       ;# maps dataobj => volume ID in server
     100    private variable _id2obj       ;# maps dataobj => volume ID in server
    90101    private variable _sendobjs ""  ;# list of data objs to send to server
     102    private variable _sendobjs2 ""  ;# list of data objs to send to server
     103    private variable _receiveids   ;# list of data objs to send to server
     104    private variable _opacity
    91105
    92106    private variable _click        ;# info used for _move operations
    93107    private variable _limits       ;# autoscale min/max for all axes
    94108    private variable _view         ;# view params for 3D view
     109       
     110    private variable _isomarkers    ;# array of isosurface level values 0..1
     111    private common _isosurface     ;# indicates to use isosurface shading
    95112}
    96113
     
    98115    keep -background -foreground -cursor -font
    99116    keep -plotbackground -plotforeground
     117}
     118
     119itcl::class Rappture::NanovisViewer::IsoMarker {
     120    private variable _value     "";     # Absolute value of marker.
     121    private variable _label     ""
     122    private variable _tick      ""
     123    private variable _canvas    ""
     124    private variable _nvobj     ""
     125    private common _normal_icon ""
     126    private common _active_icon ""
     127
     128    constructor {c obj args} {
     129        set _canvas $c
     130        set _nvobj $obj
     131       
     132        if { $_normal_icon == "" } {
     133            set normal_icon_data {
     134R0lGODlhBwATAOcxAAAAAAEBAQICAgMDAwQEBAUFBQYGBgcHBwgICAkJCQoKCgsLCwwMDA0N
     135DQ4ODg8PDxAQEBERERISEhMTExQUFBUVFRYWFhcXFxgYGBkZGRoaGhsbGxwcHB0dHR4eHh8f
     136HyAgICEhISIiIiMjIyQkJCUlJSYmJicnJygoKCkpKSoqKisrKywsLC0tLS4uLi8vLzAwMDEx
     137MTIyMjMzMzQ0NDU1NTY2Njc3Nzg4ODk5OTo6Ojs7Ozw8PD09PT4+Pj8/P0BAQEFBQUJCQkND
     138Q0REREVFRUZGRkdHR0hISElJSUpKSktLS0xMTE1NTU5OTk9PT1BQUFFRUVJSUlNTU1RUVFVV
     139VVZWVldXV1hYWFlZWVpaWltbW1xcXF1dXV5eXl9fX2BgYGFhYWJiYmNjY2RkZGVlZWZmZmdn
     140Z2hoaGlpaWpqamtra2xsbG1tbW5ubm9vb3BwcHFxcXJycnNzc3R0dHV1dXZ2dnd3d3h4eHl5
     141eXp6ent7e3x8fH19fX5+fn9/f4CAgIGBgYKCgoODg4SEhIWFhYaGhoeHh4iIiImJiYqKiouL
     142i4yMjI2NjY6Ojo+Pj5CQkJGRkZKSkpOTk5SUlJWVlZaWlpeXl5iYmJmZmZqampubm5ycnJ2d
     143nZ6enp+fn6CgoKGhoaKioqOjo6SkpKWlpaampqenp6ioqKmpqaqqqqurq6ysrK2tra6urq+v
     144r7CwsLGxsbKysrOzs7S0tLW1tba2tre3t7i4uLm5ubq6uru7u7y8vL29vb6+vr+/v8DAwMHB
     145wcLCwsPDw8TExMXFxcbGxsfHx8jIyMnJycrKysvLy8zMzM3Nzc7Ozs/Pz9DQ0NHR0dLS0tPT
     14609TU1NXV1dbW1tfX19jY2NnZ2dra2tvb29zc3N3d3d7e3t/f3+Dg4OHh4eLi4uPj4+Tk5OXl
     1475ebm5ufn5+jo6Onp6erq6uvr6+zs7O3t7e7u7u/v7/Dw8PHx8fLy8vPz8/T09PX19fb29vf3
     1489/j4+Pn5+fr6+vv7+/z8/P39/f7+/v///yH+EUNyZWF0ZWQgd2l0aCBHSU1QACH5BAEKAP8A
     149LAAAAAAHABMAAAg2AP8JHEiwoMGDCBFmW0gw259sDR9GhDjQIUWBFidiXPhwYTZTpv6AXBjy
     150j0iSJk9+BDnSo8uAADs=
     151            }
     152            set active_icon_data {
     153R0lGODlhBwATAOcxAAAAAAEBAQICAgMDAwQEBAUFBQYGBgcHBwgICAkJCQoKCgsLCwwMDA0N
     154DQ4ODg8PDxAQEBERERISEhMTExQUFBUVFRYWFhcXFxgYGBkZGRoaGhsbGxwcHB0dHR4eHh8f
     155HyAgICEhISIiIiMjIyQkJCUlJSYmJicnJygoKCkpKSoqKisrKywsLC0tLS4uLi8vLzAwMDEx
     156MTIyMjMzMzQ0NDU1NTY2Njc3Nzg4ODk5OTo6Ojs7Ozw8PD09PT4+Pj8/P0BAQEFBQUJCQkND
     157Q0REREVFRUZGRkdHR0hISElJSUpKSktLS0xMTE1NTU5OTk9PT1BQUFFRUVJSUlNTU1RUVFVV
     158VVZWVldXV1hYWFlZWVpaWltbW1xcXF1dXV5eXl9fX2BgYGFhYWJiYmNjY2RkZGVlZWZmZmdn
     159Z2hoaGlpaWpqamtra2xsbG1tbW5ubm9vb3BwcHFxcXJycnNzc3R0dHV1dXZ2dnd3d3h4eHl5
     160eXp6ent7e3x8fH19fX5+fn9/f4CAgIGBgYKCgoODg4SEhIWFhYaGhoeHh4iIiImJiYqKiouL
     161i4yMjI2NjY6Ojo+Pj5CQkJGRkZKSkpOTk5SUlJWVlZaWlpeXl5iYmJmZmZqampubm5ycnJ2d
     162nZ6enp+fn6CgoKGhoaKioqOjo6SkpKWlpaampqenp6ioqKmpqaqqqqurq6ysrK2tra6urq+v
     163r7CwsLGxsbKysrOzs7S0tLW1tba2tre3t7i4uLm5ubq6uru7u7y8vL29vb6+vr+/v8DAwMHB
     164wcLCwsPDw8TExMXFxcbGxsfHx8jIyMnJycrKysvLy8zMzM3Nzc7Ozs/Pz9DQ0NHR0dLS0tPT
     16509TU1NXV1dbW1tfX19jY2NnZ2dra2tvb29zc3N3d3d7e3t/f3+Dg4OHh4eLi4uPj4+Tk5OXl
     1665ebm5ufn5+jo6Onp6erq6uvr6+zs7O3t7e7u7u/v7/Dw8PHx8fLy8vPz8/T09PX19fb29vf3
     1679/j4+Pn5+fr6+vv7+/z8/P39/f7+/v///yH+EUNyZWF0ZWQgd2l0aCBHSU1QACH5BAEKAP8A
     168LAAAAAAHABMAAAg2AP8JHEiwoMGDCBFmW0gwG4BsDR9GhDjQIUWBFidiXPhwYbY/fwCAXBgS
     169gEiSJk9+BDnSo8uAADs=
     170            }
     171            set _normal_icon [image create photo -data $normal_icon_data]
     172            set _active_icon [image create photo -data $active_icon_data]
     173        }
     174        set w [winfo width $_canvas]
     175        set h [winfo height $_canvas]
     176        set _tick [$c create image 0 $h \
     177                -image $_normal_icon -anchor s \
     178                -tags "$this $obj"]
     179        set _label [$c create text 0 $h \
     180                -anchor n -fill white -font "Helvetica 6" \
     181                -tags "$this $obj" -state hidden]
     182        $c bind $_tick <Enter> [itcl::code $this handle_event "enter"]
     183        $c bind $_tick <Leave> [itcl::code $this handle_event "leave"]
     184        $c bind $_tick <B1-Motion> \
     185            [itcl::code $this handle_event "update" %x %y]
     186        $c bind $_tick <ButtonRelease-1> \
     187            [itcl::code $this handle_event "end" %x %y]
     188    }
     189    destructor {
     190        $_canvas delete $this
     191    }
     192
     193    public method get_relative_value {} {
     194        foreach {min max} [$_nvobj getLimits] break
     195        return [expr {($_value-$min)/($max - $min)}]
     196    }
     197    public method get_screen_position { } {
     198        set x [get_relative_value]
     199        if { $x < 0.0 } {
     200            set x 0.0
     201        } elseif { $x > 1.0 } {
     202            set x 1.0
     203        }
     204        set low 10
     205        set w [winfo width $_canvas]
     206        set high [expr {$w  - 10}]
     207        set x [expr {round($x*($high - $low) + $low)}]
     208        return $x
     209    }
     210    public method set_absolute_value { x } {
     211        set _value $x
     212
     213        set w [winfo width $_canvas]
     214        set h [winfo height $_canvas]
     215        set y0 10
     216        set y1 [expr {$y0+22-1}]
     217        $_canvas itemconfigure $_label -text [format %.4g $_value]
     218        set screen_pos [get_screen_position]
     219        $_canvas coords $_tick $screen_pos [expr $y1+3]
     220        $_canvas coords $_label $screen_pos [expr {$y1+5}]
     221    }
     222    public method set_relative_value { x } {
     223        foreach {min max} [$_nvobj getLimits] break
     224        set r [expr $max - $min]
     225        set_absolute_value [expr {($x * $r) + $min}]
     226    }
     227    public method handle_event { option args } {
     228        switch -- $option {
     229            enter {
     230                $_canvas itemconfigure $_label -state normal
     231                $_canvas itemconfigure $_tick -image $_active_icon
     232                $_canvas raise $_tick
     233            }
     234            leave {
     235                $_canvas itemconfigure $_label -state hidden
     236                $_canvas itemconfigure $_tick -image $_normal_icon
     237            }
     238            start {
     239                $_canvas raise $_tick
     240            }
     241            update {
     242                set w [winfo width $_canvas]
     243                set x [lindex $args 0]
     244                set_relative_value [expr {double($x-10)/($w-20)}]
     245                $_nvobj update_transfer_function
     246            }
     247            end {
     248                set x [lindex $args 0]
     249                if { ![$_nvobj remove_duplicate_isomarker $this $x]} {
     250                    eval handle_event update $args
     251                }
     252            }
     253            default {
     254                error "bad option \"$option\": should be start, update, end"
     255            }
     256        }
     257    }
    100258}
    101259
     
    122280    $_parser alias image [itcl::code $this _receive_image]
    123281    $_parser alias legend [itcl::code $this _receive_legend]
     282    $_parser alias data [itcl::code $this _receive_data]
    124283
    125284    #
     
    137296    set _view(zfocus) 0
    138297    set _obj2id(count) 0
     298    set _id2obj(count) 0
    139299
    140300    itk_component add controls {
     
    372532    $inner.scales.transp set 50
    373533
     534    label $inner.scales.zerol -text "Transparent" -font $fg
     535    grid $inner.scales.zerol -row 2 -column 0 -sticky e
     536    ::scale $inner.scales.opacity -from 0 -to 100 -orient horizontal \
     537        -showvalue off -command [itcl::code $this _fixSettings opacity]
     538    grid $inner.scales.opacity -row 2 -column 1 -sticky ew
     539    label $inner.scales.onel -text "Opaque" -font $fg
     540    grid $inner.scales.onel -row 2 -column 2 -sticky w
     541    $inner.scales.opacity set 50
     542
     543    set ::Rappture::NanovisViewer::_isosurface($this) 1
     544    ::checkbutton $inner.scales.isosurface \
     545        -text "Isosurface shading" \
     546        -variable ::Rappture::NanovisViewer::_isosurface($this) \
     547        -command [itcl::code $this _fixSettings isosurface]
     548    grid $inner.scales.isosurface -row 3 -column 0 -columnspan 2 -sticky w
     549
     550
    374551    #
    375552    # RENDERING AREA
     
    425602itcl::body Rappture::NanovisViewer::destructor {} {
    426603    set _sendobjs ""  ;# stop any send in progress
     604    set _sendobjs2 ""  ;# stop any send in progress
    427605    after cancel [itcl::code $this _send_dataobjs]
    428606    after cancel [itcl::code $this _rebuild]
     
    720898    # disconnected -- no more data sitting on server
    721899    catch {unset _obj2id}
     900    array unset _id2obj
    722901    set _obj2id(count) 0
     902    set _id2obj(count) 0
    723903    set _sendobjs ""
     904    set _sendobjs2 ""
    724905}
    725906
     
    8391020            puts $_sid ""
    8401021
    841             set _obj2id($dataobj-$comp) $_obj2id(count)
     1022            set volId $_obj2id(count)
    8421023            incr _obj2id(count)
    8431024
     1025            set _id2obj($volId) [list $dataobj $comp]
     1026            set _obj2id($dataobj-$comp) $volId
     1027            set _receiveids($volId) 1
     1028        }
     1029    }
     1030    set _sendobjs ""
     1031    blt::busy release $itk_component(hull)
     1032
     1033    # activate the proper volume
     1034    set first [lindex [get] 0]
     1035    if {"" != $first} {
     1036        set axis [$first hints updir]
     1037        if {"" != $axis} {
     1038            _send up $axis
     1039        }
     1040    }
     1041
     1042    # sync the state of slicers
     1043    set vols [_currentVolumeIds -cutplanes]
     1044    foreach axis {x y z} {
     1045        eval _send cutplane state [_state ${axis}slice] $axis $vols
     1046        set pos [expr {0.01*[$itk_component(${axis}slicer) get]}]
     1047        eval _send cutplane position $pos $axis $vols
     1048    }
     1049    eval _send volume data state [_state volume] $vols
     1050
     1051    # if there are any commands in the buffer, send them now that we're done
     1052    _send_echo >>line $_buffer(out)
     1053    if {[catch {puts $_sid $_buffer(out)} err]} {
     1054        disconnect
     1055        $_dispatcher event -after 750 !serverDown
     1056    }
     1057    set _buffer(out) ""
     1058
     1059#    $_dispatcher event -idle !legend
     1060}
     1061
     1062# ----------------------------------------------------------------------
     1063# USAGE: _send_transfuncs
     1064# ----------------------------------------------------------------------
     1065itcl::body Rappture::NanovisViewer::_send_transfuncs {} {
     1066    blt::busy hold $itk_component(hull); update idletasks
     1067    foreach dataobj $_sendobjs2 {
     1068        foreach comp [$dataobj components] {
    8441069            #
    8451070            # Determine the transfer function needed for this volume
    8461071            # and make sure that it's defined on the server.
    8471072            #
     1073            _initIsoMarkers $dataobj $comp
    8481074            foreach {sname cmap wmap} [_getTransfuncData $dataobj $comp] break
    849 
    8501075            set cmdstr [list transfunc define $sname $cmap $wmap]
    8511076            _send_echo >>line $cmdstr
     
    8551080                return
    8561081            }
    857 
    8581082            set _obj2style($dataobj-$comp) $sname
    8591083        }
    8601084    }
    861     set _sendobjs ""
     1085    set _sendobjs2 ""
    8621086    blt::busy release $itk_component(hull)
    8631087
    8641088    # activate the proper volume
    8651089    set first [lindex [get] 0]
    866     if {"" != $first} {
    867         set axis [$first hints updir]
    868         if {"" != $axis} {
    869             _send up $axis
    870         }
    871     }
    872 
    8731090    foreach key [array names _obj2id *-*] {
    8741091        set state [string match $first-* $key]
     
    8781095        }
    8791096    }
    880 
    881     # sync the state of slicers
    882     set vols [_currentVolumeIds -cutplanes]
    883     foreach axis {x y z} {
    884         eval _send cutplane state [_state ${axis}slice] $axis $vols
    885         set pos [expr {0.01*[$itk_component(${axis}slicer) get]}]
    886         eval _send cutplane position $pos $axis $vols
    887     }
    888     eval _send volume data state [_state volume] $vols
    889 
    8901097    # if there are any commands in the buffer, send them now that we're done
    8911098    _send_echo >>line $_buffer(out)
     
    8951102    }
    8961103    set _buffer(out) ""
    897 
    8981104    $_dispatcher event -idle !legend
    8991105}
     
    9761182            $c create image 10 10 -anchor nw \
    9771183                 -image $_image(legend) -tags transfunc
    978 
    979             $c bind transfunc <ButtonPress-1> \
    980                  [itcl::code $this _probe start %x %y]
    981             $c bind transfunc <B1-Motion> \
    982                  [itcl::code $this _probe update %x %y]
    983             $c bind transfunc <ButtonRelease-1> \
    984                  [itcl::code $this _probe end %x %y]
    985 
    9861184            $c create text 10 [expr {$h-8}] -anchor sw \
    9871185                 -fill $itk_option(-plotforeground) -tags vmin
    9881186            $c create text [expr {$w-10}] [expr {$h-8}] -anchor se \
    9891187                 -fill $itk_option(-plotforeground) -tags vmax
    990         }
    991 
     1188            $c lower transfunc
     1189            $c bind transfunc <ButtonRelease-1> \
     1190                [itcl::code $this _addIsoMarker %x %y]
     1191        }
    9921192        $c itemconfigure vmin -text $vmin
    9931193        $c coords vmin 10 [expr {$h-8}]
     
    9951195        $c itemconfigure vmax -text $vmax
    9961196        $c coords vmax [expr {$w-10}] [expr {$h-8}]
     1197    }
     1198}
     1199
     1200# ----------------------------------------------------------------------
     1201# USAGE: _receive_data <volume> <vmin> <vmax>
     1202#
     1203# Invoked automatically whenever the "legend" command comes in from
     1204# the rendering server.  Indicates that binary image data with the
     1205# specified <size> will follow.
     1206# ----------------------------------------------------------------------
     1207itcl::body Rappture::NanovisViewer::_receive_data { args } {
     1208    if {"" != $_sid} {
     1209        array set info $args
     1210        set volume $info(id)
     1211        foreach { dataobj comp } $_id2obj($volume) break
     1212        set _limits(vmin-$dataobj-$comp) $info(min)
     1213        set _limits(vmax-$dataobj-$comp) $info(max)
     1214        set _limits(vmin) $info(vmin)
     1215        set _limits(vmax) $info(vmax)
     1216        lappend _sendobjs2 $dataobj
     1217        unset _receiveids($info(id))
     1218        if { [array size _receiveids] == 0 } {
     1219            after idle [itcl::code $this _send_transfuncs]
     1220        }
    9971221    }
    9981222}
     
    10761300    eval _send camera angle [_euler2xyz $_view(theta) $_view(phi) $_view(psi)]
    10771301    _send camera zoom $_view(zoom)
    1078     #_fixSettings light
    1079     #_fixSettings transp
     1302
     1303    _fixSettings light
     1304    _fixSettings transp
     1305    _fixSettings isosurface
    10801306
    10811307    if {"" == $itk_option(-plotoutline)} {
     
    14291655            }
    14301656        }
     1657        opacity {
     1658            if {[isconnected]} {
     1659                set dataobj [lindex [get] 0]
     1660                if {$dataobj != 0} {
     1661                    set val [$inner.scales.opacity get]
     1662                    set sval [expr {0.01*double($val)}]
     1663                    set _opacity($dataobj) $sval
     1664                    update_transfer_function
     1665                }
     1666            }
     1667        }
     1668        isosurface {
     1669            if {[isconnected]} {
     1670                set val $Rappture::NanovisViewer::_isosurface($this)
     1671                _send "volume" "shading" "isosurface" $val
     1672            }
     1673        }           
    14311674        default {
    14321675            error "don't know how to fix $what"
     
    14871730        -color rainbow
    14881731        -levels 6
    1489         -opacity 0.5
     1732        -opacity 1.0
    14901733    }
    14911734    array set style [lindex [$dataobj components -style $comp] 0]
     
    14981741    set cmap "0.0 [_color2rgb white] "
    14991742    for {set i 0} {$i < [llength $clist]} {incr i} {
    1500         set xval [expr {double($i+1)/([llength $clist]+1)}]
     1743        set x [expr {double($i+1)/([llength $clist]+1)}]
    15011744        set color [lindex $clist $i]
    1502         append cmap "$xval [_color2rgb $color] "
     1745        append cmap "$x [_color2rgb $color] "
    15031746    }
    15041747    append cmap "1.0 [_color2rgb $color]"
    15051748
    15061749    set max $style(-opacity)
    1507     set levels $style(-levels)
    1508     if {[string is int $levels]} {
    1509         set wmap "0.0 0.0 "
    1510         set delta [expr {0.125/($levels+1)}]
    1511         for {set i 1} {$i <= $levels} {incr i} {
    1512             # add spikes in the middle
    1513             set xval [expr {double($i)/($levels+1)}]
    1514             append wmap "[expr {$xval-$delta-0.01}] 0.0  [expr {$xval-$delta}] $max [expr {$xval+$delta}] $max  [expr {$xval+$delta+0.01}] 0.0 "
    1515         }
    1516         append wmap "1.0 0.0 "
    1517     } else {
    1518         set wmap "0.0 0.0 "
    1519         set delta 0.05
    1520         foreach xval [split $levels ,] {
    1521             append wmap "[expr {$xval-$delta}] 0.0  $xval $max [expr {$xval+$delta}] 0.0 "
    1522         }
    1523         append wmap "1.0 0.0 "
    1524     }
    1525 
     1750    if { [info exists _opacity($dataobj)] } {
     1751        set max $_opacity($dataobj)
     1752    }
     1753    set key $dataobj
     1754    set isovalues {}
     1755    foreach m $_isomarkers($key) {
     1756        lappend isovalues [$m get_relative_value]
     1757    }
     1758
     1759    # Sort the isovalues
     1760    set isovalues [lsort -real $isovalues]
     1761
     1762    set delta 0.0005
     1763    set first [lindex $isovalues 0]
     1764    set last [lindex $isovalues end]
     1765    set wmap ""
     1766    if { $first == "" || $first != 0.0 } {
     1767        lappend wmap 0.0 0.0
     1768    }
     1769    foreach x $isovalues {
     1770        set x1 [expr {$x-$delta-0.001}]
     1771        set x2 [expr {$x-$delta}]
     1772        set x3 [expr {$x+$delta}]
     1773        set x4 [expr {$x+$delta+0.001}]
     1774        if { $x1 < 0.0 } {
     1775            set x1 0.0
     1776        }
     1777        if { $x2 < 0.0 } {
     1778            set x2 0.0
     1779        }
     1780        if { $x3 > 1.0 } {
     1781            set x3 1.0
     1782        }
     1783        if { $x4 > 1.0 } {
     1784            set x4 1.0
     1785        }
     1786        # add spikes in the middle
     1787        lappend wmap $x1 0.0 
     1788        lappend wmap $x2 $max
     1789        lappend wmap $x3 $max 
     1790        lappend wmap $x4 0.0
     1791    }
     1792    if { $last == "" || $last != 1.0 } {
     1793        lappend wmap 1.0 0.0
     1794    }
    15261795    return [list $sname $cmap $wmap]
    15271796}
     
    15871856    }
    15881857}
     1858
     1859itcl::body Rappture::NanovisViewer::_initIsoMarkers {dataobj comp} {
     1860    if { [info exists _isomarkers($dataobj)] } {
     1861        return
     1862    }
     1863    array set style {
     1864        -levels 6
     1865    }
     1866    array set style [lindex [$dataobj components -style $comp] 0]
     1867    set levels $style(-levels)
     1868    set c $itk_component(legend)
     1869    if { [llength $levels] == 1 && [string is int $levels] } {
     1870        for {set i 1} {$i <= $levels} {incr i} {
     1871            set x [expr {double($i)/($levels+1)}]
     1872            set m [IsoMarker \#auto $c $this]
     1873            $m set_relative_value $x
     1874            lappend _isomarkers($dataobj) $m
     1875        }
     1876    } else {
     1877        regsub -all "," $levels " " levels
     1878        foreach level $levels {
     1879            set n [scan $level "%g%s" x unit]
     1880            set m [IsoMarker \#auto $c $this]
     1881            lappend _isomarkers($dataobj) $m
     1882            if { $n == 2 && $unit == "%" } {
     1883                set x [expr {$x * 0.01}]
     1884                $m set_relative_value $x
     1885            } else {
     1886                $m set_absolute_value $x
     1887            }
     1888        }
     1889    }
     1890}
     1891
     1892# ----------------------------------------------------------------------
     1893# USAGE: _marker start <x> <y>
     1894# USAGE: _marker update <x> <y>
     1895# USAGE: _marker end <x> <y>
     1896#
     1897# Used internally to handle the various marker operations performed
     1898# when the user clicks and drags on the legend area.  The marker changes the
     1899# transfer function to highlight the area being selected in the
     1900# legend.
     1901# ----------------------------------------------------------------------
     1902itcl::body Rappture::NanovisViewer::update_transfer_function {} {
     1903    set dataobj [lindex [get] 0]
     1904    if {"" == $dataobj} {
     1905        return
     1906    }
     1907    set comp [lindex [$dataobj components] 0]
     1908    set key $dataobj-$comp
     1909    if {![info exists _obj2style($key)]} {
     1910        return
     1911    }
     1912    # compute a transfer function for the probe value
     1913    foreach {sname cmap wmap} [_getTransfuncData $dataobj $comp] break
     1914    _send transfunc define $_obj2style($key) $cmap $wmap
     1915    _send volume shading transfunc $_obj2style($key) $_obj2id($key)
     1916    _fixLegend
     1917}
     1918
     1919itcl::body Rappture::NanovisViewer::_addIsoMarker { x y } {
     1920    set dataobj [lindex [get] 0]
     1921    if {"" == $dataobj} {
     1922        return 0
     1923    }
     1924    set key $dataobj
     1925    set c $itk_component(legend)
     1926    set m [IsoMarker \#auto $c $this]
     1927    set w [winfo width $c]
     1928    $m set_relative_value [expr {double($x-10)/($w-20)}]
     1929    lappend _isomarkers($key) $m
     1930    update_transfer_function
     1931    return 1
     1932}
     1933
     1934itcl::body Rappture::NanovisViewer::remove_duplicate_isomarker { marker x } {
     1935    set dataobj [lindex [get] 0]
     1936    if {"" == $dataobj} {
     1937        return 0
     1938    }
     1939    set key $dataobj
     1940    set list {}
     1941    set bool 1
     1942    set marker [namespace tail $marker]
     1943    foreach m $_isomarkers($key) {
     1944        set sx [$m get_screen_position]
     1945        if { $m != $marker } {
     1946            if { $x >= ($sx-3) && $x <= ($sx+3) } {
     1947                $marker set_relative_value [$m get_relative_value]
     1948                itcl::delete object $m
     1949                set bool 0
     1950                continue
     1951            }
     1952        }
     1953        lappend list $m
     1954    }
     1955    set _isomarkers($key) $list
     1956    update_transfer_function
     1957    return $bool
     1958}
Note: See TracChangeset for help on using the changeset viewer.