Changeset 4509 for trunk/gui


Ignore:
Timestamp:
Jul 16, 2014 2:02:26 PM (10 years ago)
Author:
gah
Message:

fix contour list generation

Location:
trunk/gui/scripts
Files:
3 edited

Legend:

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

    r4502 r4509  
    11# -*- mode: tcl; indent-tabs-mode: nil -*-
    2 
    32# ----------------------------------------------------------------------
    43#  COMPONENT: field - extracts data from an XML description of a field
     
    9089        # defined below
    9190    }
    92     public method blob { cname }
     91    public method blob { cname } 
    9392    public method components {args}
    9493    public method controls {option args}
  • trunk/gui/scripts/nanovisviewer.tcl

    r4499 r4509  
    8282    public method updateTransferFunctions {}
    8383
    84 
    8584    # The following methods are only used by this class.
     85
     86    private method AddNewMarker { x y }
    8687    private method AdjustSetting {what {value ""}}
    8788    private method BuildCameraTab {}
     
    105106    private method GetVolumeInfo { w }
    106107    private method HideAllMarkers {}
    107     private method AddNewMarker { x y }
    108108    private method InitComponentSettings { cname }
    109109    private method InitSettings { args }
     
    118118    private method ReceiveImage { args }
    119119    private method ReceiveLegend { tf vmin vmax size }
     120    private method RemoveMarker { x y }
    120121    private method ResetColormap { cname color }
    121122    private method Rotate {option x y}
     
    125126    private method SlicerTip {axis}
    126127    private method SwitchComponent { cname }
     128    private method ToggleVolume { tag name }
    127129    private method Zoom {option}
    128     private method ToggleVolume { tag name }
    129     private method RemoveMarker { x y }
    130130    private method ViewToQuaternion {} {
    131131        return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)]
     
    148148    private variable _view;             # View params for 3D view
    149149    private variable _parsedFunction
    150     private variable _transferFunctionEditors;# Array of isosurface level values 0..1
     150    private variable _transferFunctionEditors
    151151    private variable  _settings
    152152    private variable _first "" ;        # This is the topmost volume.
     
    208208        -qy      0.353553
    209209        -qz      0.146447
    210         -zoom    1.0
    211210        -xpan    0
    212211        -ypan    0
     212        -zoom    1.0
    213213    }
    214214    set _arcball [blt::arcball create 100 100]
     
    240240        -volume                 1
    241241        -volumevisible          1
     242        -xcutplaneposition      50
    242243        -xcutplanevisible       1
    243         -xcutplaneposition      50
    244244        -xpan                   0
     245        -ycutplaneposition      50
    245246        -ycutplanevisible       1
    246         -ycutplaneposition      50
    247247        -ypan                   0
     248        -zcutplaneposition      50
    248249        -zcutplanevisible       1
    249         -zcutplaneposition      50
    250250        -zoom                   1.0
    251251    }
     
    721721# ----------------------------------------------------------------------
    722722itcl::body Rappture::NanovisViewer::SendTransferFunctions {} {
    723     if 0 {
    724     if { $_first == "" } {
    725         puts stderr "first not set"
    726         return
    727     }
    728 
    729     foreach tag [CurrentDatasets] {
    730         if { ![info exists _serverDatasets($tag)] || !$_serverDatasets($tag) } {
    731             # The volume hasn't reached the server yet.  How did we get
    732             # here?
    733             puts stderr "Don't have $tag in _serverDatasets"
    734             continue
    735         }
    736         if { ![info exists _dataset2style($tag)] } {
    737             puts stderr "don't have style for volume $tag"
    738             continue;                        # How does this happen?
    739         }
    740         foreach {dataobj cname} [split $tag -] break
    741         set cname $_dataset2style($tag)
    742 
    743         ComputeTransferFunction $cname
    744         SendCmd "volume shading transfunc $cname $tag"
    745     }
    746     }
    747723    foreach cname [array names _volcomponents] {
    748724        ComputeTransferFunction $cname
     
    989965        PanCamera
    990966        SendCmd "camera zoom $_view(-zoom)"
    991 
     967       
     968        #cutplane state 0 all
    992969        foreach axis {x y z} {
    993970            # Turn off cutplanes for all volumes
     
    10881065                -qy      0.353553
    10891066                -qz      0.146447
     1067                -xpan    0
     1068                -ypan    0
    10901069                -zoom    1.0
    1091                 -xpan   0
    1092                 -ypan   0
    10931070            }
    10941071            if { $_first != "" } {
     
    12441221    }
    12451222    switch -- $what {
    1246         "-current" {
    1247             set cname [$itk_component(volcomponents) value]
    1248             SwitchComponent $cname
     1223        "-ambient" {
     1224            # Other parts of the code use the ambient setting to
     1225            # tell if the component settings have been initialized
     1226            if { ![info exists _settings($_current${what})] } {
     1227                InitComponentSettings $_current
     1228            }
     1229            set _settings($_current${what}) $_settings($what)
     1230            set val $_settings($what)
     1231            set val [expr {0.01*$val}]
     1232            foreach tag [GetDatasetsWithComponent $_current] {
     1233                SendCmd "volume shading ambient $val $tag"
     1234            }
     1235        }
     1236        "-axesvisible" {
     1237            SendCmd "axis visible $_settings($what)"
    12491238        }
    12501239        "-background" {
     
    12591248            DrawLegend $_current
    12601249        }
    1261         "-ambient" {
    1262             # Other parts of the code use the ambient setting to
    1263             # tell if the component settings have been initialized
    1264             if { ![info exists _settings($_current${what})] } {
    1265                 InitComponentSettings $_current
    1266             }
    1267             set _settings($_current${what}) $_settings($what)
    1268             set val $_settings($what)
    1269             set val [expr {0.01*$val}]
    1270             foreach tag [GetDatasetsWithComponent $_current] {
    1271                 SendCmd "volume shading ambient $val $tag"
    1272             }
     1250        "-colormap" {
     1251            set color [$itk_component(colormap) value]
     1252            set _settings($what) $color
     1253            set _settings($_current${what}) $color
     1254            ResetColormap $_current $color
     1255        }
     1256        "-current" {
     1257            set cname [$itk_component(volcomponents) value]
     1258            SwitchComponent $cname
     1259        }
     1260        "-cutplanesvisible" {
     1261            set bool $_settings($what)
     1262            set datasets [CurrentDatasets -cutplanes]
     1263            set tag [lindex $datasets 0]
     1264            SendCmd "cutplane visible $bool $tag"
    12731265        }
    12741266        "-diffuse" {
     
    12801272            }
    12811273        }
    1282         "-specularlevel" {
    1283             set _settings($_current${what}) $_settings($what)
    1284             set val $_settings($what)
    1285             set val [expr {0.01*$val}]
    1286             foreach tag [GetDatasetsWithComponent $_current] {
    1287                 SendCmd "volume shading specularLevel $val $tag"
    1288             }
    1289         }
    1290         "-specularexponent" {
    1291             set _settings($_current${what}) $_settings($what)
    1292             set val $_settings($what)
    1293             foreach tag [GetDatasetsWithComponent $_current] {
    1294                 SendCmd "volume shading specularExp $val $tag"
    1295             }
    1296         }
    1297         "-light2side" {
    1298             set _settings($_current${what}) $_settings($what)
    1299             set val $_settings($what)
    1300             foreach tag [GetDatasetsWithComponent $_current] {
    1301                 SendCmd "volume shading light2side $val $tag"
    1302             }
    1303         }
    1304         "-opacity" {
    1305             set _settings($_current${what}) $_settings($what)
    1306             set val $_settings($what)
    1307             set sval [expr { 0.01 * double($val) }]
    1308             foreach tag [GetDatasetsWithComponent $_current] {
    1309                 SendCmd "volume shading opacity $sval $tag"
    1310             }
    1311         }
    1312         "-thickness" {
    1313             set val $_settings($what)
    1314             set _settings($_current${what}) $val
    1315             updateTransferFunctions
    1316         }
    1317         "-outlinevisible" {
    1318             SendCmd "volume outline state $_settings($what)"
    1319         }
    1320         "-outlinecolor" {
    1321             set rgb [Color2RGB $_settings($what)]
    1322             SendCmd "volume outline color $rgb"
     1274        "-gridvisible" {
     1275            SendCmd "grid visible $_settings($what)"
    13231276        }
    13241277        "-isosurfaceshading" {
    13251278            SendCmd "volume shading isosurface $_settings($what)"
    1326         }
    1327         "-colormap" {
    1328             set color [$itk_component(colormap) value]
    1329             set _settings($what) $color
    1330             set _settings($_current${what}) $color
    1331             ResetColormap $_current $color
    1332         }
    1333         "-gridvisible" {
    1334             SendCmd "grid visible $_settings($what)"
    1335         }
    1336         "-axesvisible" {
    1337             SendCmd "axis visible $_settings($what)"
    13381279        }
    13391280        "-legendvisible" {
     
    13461287                blt::table forget $itk_component(legend)
    13471288            }
     1289        }
     1290        "-light2side" {
     1291            set _settings($_current${what}) $_settings($what)
     1292            set val $_settings($what)
     1293            foreach tag [GetDatasetsWithComponent $_current] {
     1294                SendCmd "volume shading light2side $val $tag"
     1295            }
     1296        }
     1297        "-opacity" {
     1298            set _settings($_current${what}) $_settings($what)
     1299            set val $_settings($what)
     1300            set sval [expr { 0.01 * double($val) }]
     1301            foreach tag [GetDatasetsWithComponent $_current] {
     1302                SendCmd "volume shading opacity $sval $tag"
     1303            }
     1304        }
     1305        "-outlinevisible" {
     1306            SendCmd "volume outline state $_settings($what)"
     1307        }
     1308        "-outlinecolor" {
     1309            set rgb [Color2RGB $_settings($what)]
     1310            SendCmd "volume outline color $rgb"
     1311        }
     1312        "-specularlevel" {
     1313            set _settings($_current${what}) $_settings($what)
     1314            set val $_settings($what)
     1315            set val [expr {0.01*$val}]
     1316            foreach tag [GetDatasetsWithComponent $_current] {
     1317                SendCmd "volume shading specularLevel $val $tag"
     1318            }
     1319        }
     1320        "-specularexponent" {
     1321            set _settings($_current${what}) $_settings($what)
     1322            set val $_settings($what)
     1323            foreach tag [GetDatasetsWithComponent $_current] {
     1324                SendCmd "volume shading specularExp $val $tag"
     1325            }
     1326        }
     1327        "-thickness" {
     1328            set val $_settings($what)
     1329            set _settings($_current${what}) $val
     1330            updateTransferFunctions
    13481331        }
    13491332        "-volume" {
     
    13671350                SendCmd "volume data state $_settings($what) $tag"
    13681351            }
    1369         }
    1370         "-cutplanesvisible" {
    1371             set bool $_settings($what)
    1372             set datasets [CurrentDatasets -cutplanes]
    1373             set tag [lindex $datasets 0]
    1374             SendCmd "cutplane visible $bool $tag"
    13751352        }
    13761353        "-xcutplanevisible" - "-ycutplanevisible" - "-zcutplanevisible" {
  • trunk/gui/scripts/vtkisosurfaceviewer.tcl

    r4454 r4509  
    6868    protected method DoResize {}
    6969    protected method DoRotate {}
     70    protected method DoChangeContourLevels {}
    7071    protected method AdjustSetting {what {value ""}}
    7172    protected method InitSettings { args  }
     
    9091    private method EnterLegend { x y }
    9192    private method EventuallyResize { w h }
     93    private method EventuallyChangeContourLevels {}
    9294    private method EventuallyRotate { q }
    9395    private method EventuallyRequestLegend {}
     
    105107    private method SetCurrentColormap { color }
    106108    private method SetOrientation { side }
    107     private method UpdateContourList {}
     109    private method GenerateContourList {}
    108110
    109111    private variable _arcball ""
     
    137139    private variable _title ""
    138140    private variable _isolines
    139     private variable _contourList ""
     141    private variable _contourList
     142    private variable _currentLimits ""
     143    private variable _widget
    140144
    141145    common _downloadPopup;              # download options from popup
     
    183187    $_dispatcher dispatch $this !legend "[itcl::code $this RequestLegend]; list"
    184188
     189    # Contour levels event
     190    $_dispatcher register !contours
     191    $_dispatcher dispatch $this !contours \
     192        "[itcl::code $this DoChangeContourLevels]; list"
     193
    185194    # X-Cutplane event
    186195    $_dispatcher register !xcutplane
     
    220229    $_arcball quaternion $q
    221230
     231    array set _contourList {
     232        numLevels       10
     233        reqValues       ""
     234        updatePending   0
     235        values          ""
     236    }
    222237    array set _settings {
    223238        -axesvisible                    1
     
    229244        -cutplaneedges                  0
    230245        -cutplanelighting               1
    231         -cutplaneopacity                100
     246        -cutplaneopacity                1.0
    232247        -cutplanepreinterp              1
    233248        -cutplanesvisible               0
     
    237252        -isosurfaceedges                0
    238253        -isosurfacelighting             1
    239         -isosurfaceopacity              60
     254        -isosurfaceopacity              0.6
    240255        -isosurfacevisible              1
    241256        -isosurfacewireframe            0
     
    256271        -colormap                0
    257272        -isosurfaceopacity       0
     273        -cutplaneopacity         0
    258274        -numcontours             0
     275    }
     276    array set _widget {
     277        -isosurfaceopacity       0
     278        -cutplaneopacity         0
    259279    }
    260280
     
    467487}
    468488
     489itcl::body Rappture::VtkIsosurfaceViewer::DoChangeContourLevels {} {
     490    GenerateContourList
     491    SendCmd [list contour3d contourlist $_contourList(values)]
     492    SendCmd [list camera reset]
     493    DrawLegend
     494    set _contourList(updatePending) 0
     495}
     496
    469497itcl::body Rappture::VtkIsosurfaceViewer::DoRotate {} {
    470498    set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     
    505533        set _cutplanePending 1
    506534        $_dispatcher event -after 100 !${axis}cutplane
     535    }
     536}
     537
     538itcl::body Rappture::VtkIsosurfaceViewer::EventuallyChangeContourLevels {} {
     539    set n $_contourList(numLevels)
     540    set _contourList(values) ""
     541    if { !$_contourList(updatePending) } {
     542        set _contourList(updatePending) 1
     543        global rotate_delay
     544        $_dispatcher event -after $rotate_delay !contours
    507545    }
    508546}
     
    939977    # generates a new call to Rebuild).   
    940978    StartBufferingCommands
    941 
    942979    if { $_reset } {
    943980        set _width $w
     
    960997        InitSettings -xgrid -ygrid -zgrid -axismode \
    961998            -axesvisible -axislabelsvisible
    962         foreach axis { x y z } {
    963             SendCmd "axis lformat $axis %g"
    964         }
     999        SendCmd "axis lformat all %g"
     1000        # Too many major ticks, so turn off minor ticks
     1001        SendCmd "axis minticks all 0"
    9651002        StopBufferingCommands
    9661003        SendCmd "imgflush"
     
    10351072        }
    10361073        $itk_component(field) value $_curFldLabel
     1074
     1075        if { ![info exists _limits($_curFldName)] } {
     1076            SendCmd "dataset maprange all"
     1077        } else {
     1078            set limits $_limits($_curFldName)
     1079            SendCmd "dataset maprange explicit $limits $_curFldName"
     1080            if { $limits != $_currentLimits } {
     1081                set _currentLimits $limits
     1082                EventuallyChangeContourLevels
     1083            }
     1084        }
    10371085    }
    10381086    InitSettings -cutplanesvisible -isosurfacevisible -outline
     
    10591107                set label [string toupper $axis]
    10601108            }
    1061             # May be a space in the axis label.
    10621109            SendCmd [list axis name $axis $label]
    10631110        }
     
    13481395        "-cutplanesvisible" {
    13491396            set bool $_settings($what)
    1350             SendCmd "cutplane visible 0"
     1397            SendCmd "cutplane visible 0"
    13511398            if { $bool } {
    13521399                foreach tag [CurrentDatasets -visible] {
     
    13711418        }
    13721419        "-cutplaneopacity" {
    1373             set val $_settings($what)
    1374             set sval [expr { 0.01 * double($val) }]
    1375             SendCmd "cutplane opacity $sval"
     1420            set _settings($what) [$_widget(-cutplaneopacity) * 0.01]
     1421            SendCmd "cutplane opacity $_settings($what)"
    13761422        }
    13771423        "-cutplanepreinterp" {
     
    14191465        "-numcontours" {
    14201466            set _settings($what) [$itk_component(numcontours) value]
    1421             set _currentNumContours $_settings($what)
    1422             UpdateContourList
    1423             set _changed($what) 1
    1424             SendCmd "contour3d contourlist [list $_contourList]"
    1425             DrawLegend
     1467            if { $_contourList(numLevels) != $_settings($what) } {
     1468                set _contourList(numLevels) $_settings($what)
     1469                EventuallyChangeContourLevels
     1470            }
    14261471        }
    14271472        "-isosurfacewireframe" {
     
    14681513        }
    14691514        "-isosurfaceopacity" {
    1470             set val $_settings($what)
    1471             set sval [expr { 0.01 * double($val) }]
    1472             SendCmd "contour3d opacity $sval"
     1515            set _settings($what) [$_widget(-isosurfaceopacity) * 0.01]
     1516            SendCmd "contour3d opacity $_settings($what)"
    14731517        }
    14741518        "-field" {
     
    16741718    label $inner.opacity_l -text "Opacity" -font "Arial 9"
    16751719    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
    1676         -variable [itcl::scope _settings(-isosurfaceopacity)] \
     1720        -variable [itcl::scope _widget(-isosurfaceopacity)] \
    16771721        -width 10 \
    16781722        -showvalue off \
    16791723        -command [itcl::code $this AdjustSetting -isosurfaceopacity]
     1724    $inner.opacity set [expr $_settings(-isosurfaceeopacity) * 100.0]
    16801725
    16811726    itk_component add field_l {
     
    18871932    label $inner.opacity_l -text "Opacity" -font "Arial 9"
    18881933    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
    1889         -variable [itcl::scope _settings(-cutplaneopacity)] \
     1934        -variable [itcl::scope _widget(-cutplaneopacity)] \
    18901935        -width 10 \
    18911936        -showvalue off \
    18921937        -command [itcl::code $this AdjustSetting -cutplaneopacity]
    1893     $inner.opacity set $_settings(-cutplaneopacity)
     1938    $inner.opacity set [expr $_settings(-cutplaneopacity) * 100.0]
    18941939
    18951940    # X-value slicer...
     
    21102155    set tag $dataobj-$comp
    21112156    array set style {
    2112         -color BCGYR
    2113         -cutplanesvisible 0
    2114         -edgecolor black
    2115         -edges 0
    2116         -isosurfacevisible 1
    2117         -levels 10
    2118         -lighting 1
    2119         -linewidth 1.0
    2120         -opacity 0.6
    2121         -outline 0
    2122         -wireframe 0
    2123         -xcutplaneposition 50
    2124         -xcutplanevisible 1
    2125         -ycutplaneposition 50
    2126         -ycutplanevisible 1
    2127         -zcutplaneposition 50
    2128         -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
    21292174    }
    21302175    array set style [$dataobj style $comp]
    21312176    if { $dataobj != $_first || $style(-levels) == 1 } {
    2132         set style(-opacity) 1
     2177        set style(-isosurfaceopacity) 1.0
    21332178    }
    21342179
     
    21432188
    21442189    if { $_changed(-isosurfaceopacity) } {
    2145         set style(-opacity) [expr $_settings(-isosurfaceopacity) * 0.01]
     2190        set style(-isosurfaceopacity) $_settings(-isosurfaceopacity)
    21462191    }
    21472192    if { $_changed(-numcontours) } {
     
    21552200        $itk_component(colormap) value $style(-color)
    21562201    }
    2157     if { $_currentNumContours != $style(-levels) } {
    2158         set _currentNumContours $style(-levels)
    2159         set _settings(-numcontours) $_currentNumContours
    2160         $itk_component(numcontours) value $_currentNumContours
    2161         UpdateContourList
    2162         DrawLegend
     2202    if { $_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        }
     2210        EventuallyChangeContourLevels
    21632211    }
    21642212    set _settings(-isosurfacevisible) $style(-isosurfacevisible)
     
    21702218    set _settings(-ycutplaneposition) $style(-ycutplaneposition)
    21712219    set _settings(-zcutplaneposition) $style(-zcutplaneposition)
    2172 
     2220 
    21732221    SendCmd "cutplane add $tag"
    21742222    SendCmd "cutplane visible $style(-cutplanesvisible) $tag"
     
    21792227    set _settings(-outline) $style(-outline)
    21802228 
    2181     SendCmd [list contour3d add contourlist $_contourList $tag]
     2229    GenerateContourList
     2230    SendCmd [list contour3d add contourlist $_contourList(values) $tag]
    21822231    SendCmd "contour3d visible $style(-isosurfacevisible) $tag"
    21832232    SendCmd "contour3d edges $style(-edges) $tag"
     
    21882237    SendCmd "contour3d linecolor [Color2RGB $style(-edgecolor)] $tag"
    21892238    SendCmd "contour3d linewidth $style(-linewidth) $tag"
    2190     SendCmd "contour3d opacity $style(-opacity) $tag"
    2191     set _settings(-isosurfaceopacity) [expr $style(-opacity) * 100.0]
     2239    SendCmd "contour3d opacity $style(-isosurfaceopacity) $tag"
     2240    set _settings(-isosurfaceopacity) $style(-isosurfaceopacity)
    21922241    SetCurrentColormap $style(-color)
    21932242    SendCmd "contour3d wireframe $style(-wireframe) $tag"
     
    24262475            incr offset $lineht
    24272476        }
    2428         foreach value $_contourList {
     2477        foreach value $_contourList(values) {
    24292478            set norm [expr 1.0 - (($value - $vmin) / $range)]
    24302479            set y1 [expr int(round(($norm * $ih) + $offset))]
     
    25512600}
    25522601
    2553 itcl::body Rappture::VtkIsosurfaceViewer::UpdateContourList {} {
     2602itcl::body Rappture::VtkIsosurfaceViewer::GenerateContourList {} {
    25542603    if { ![info exists _limits($_curFldName)] } {
    2555         return
    2556     }
    2557     if { $_currentNumContours < 1 } {
    2558         set _contourList ""
    2559         return
    2560     }
    2561     foreach { vmin vmax } $_limits($_curFldName) break
    2562     set v [blt::vector create \#auto]
    2563     $v seq $vmin $vmax [expr $_currentNumContours+2]
    2564     $v delete end 0
    2565     set _contourList [$v range 0 end]
    2566     blt::vector destroy $v
    2567 }
    2568 
     2604        puts stderr "no _curFldName"
     2605        return ""
     2606    }
     2607    if { $_contourList(numLevels) < 1 } {
     2608        puts stderr "numLevels < 1"
     2609        return ""
     2610    }
     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    }
     2621    set _contourList(values) $values
     2622}
Note: See TracChangeset for help on using the changeset viewer.