Changeset 136 for trunk


Ignore:
Timestamp:
Nov 11, 2005, 10:50:56 PM (19 years ago)
Author:
mmc
Message:
  • Fixed field/mesh to support rectilinear meshes in "vtk native" format. This makes it much faster to load large meshes. Needed for app-qdot.
  • Fixed contour viewer to show separate x/y/z cut planes and isosurfaces.
  • Fixed energy level viewer to label "HOMO" as "Ground State", if that is the language used by the table.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/examples/zoo/field/tool.xml

    r112 r136  
    4545    <about><label>3D Field</label></about>
    4646    <component>
     47      <style>-color yellow</style>
    4748      <mesh>output.mesh(m3d)</mesh>
    4849      <values></values>
  • trunk/gui/scripts/contourresult.tcl

    r115 r136  
    7070option add *ContourResult.controlBackground gray widgetDefault
    7171option add *ContourResult.controlDarkBackground #999999 widgetDefault
     72option add *ContourResult.plotBackground black widgetDefault
     73option add *ContourResult.plotForeground white widgetDefault
    7274option add *ContourResult.font \
    7375    -*-helvetica-medium-r-normal-*-*-120-* widgetDefault
     
    7678    inherit itk::Widget
    7779
    78     itk_option define -foreground foreground Foreground ""
    79     itk_option define -background background Background ""
     80    itk_option define -plotforeground plotForeground Foreground ""
     81    itk_option define -plotbackground plotBackground Background ""
    8082
    8183    constructor {args} { # defined below }
     
    9597    protected method _3dView {theta phi}
    9698    protected method _fixLimits {}
     99    protected method _slicertip {axis}
    97100    protected method _color2rgb {color}
    98101
     
    109112    private variable _limits       ;# autoscale min/max for all axes
    110113    private variable _view         ;# view params for 3D view
    111 
    112     private common _counter 0      ;# used for auto-generated names
    113114}
    114115
    115116itk::usual ContourResult {
    116117    keep -background -foreground -cursor -font
     118    keep -plotbackground -plotforeground
    117119}
    118120
     
    124126    pack propagate $itk_component(hull) no
    125127
    126     set _slicer(axis) ""
    127     set _slicer(plane) ""
     128    set _slicer(xplane) ""
     129    set _slicer(yplane) ""
     130    set _slicer(zplane) ""
     131    set _slicer(xslice) ""
     132    set _slicer(yslice) ""
     133    set _slicer(zslice) ""
    128134    set _slicer(readout) ""
    129135    set _view(theta) 0
     
    138144    pack $itk_component(controls) -side right -fill y
    139145
     146    itk_component add zoom {
     147        frame $itk_component(controls).zoom
     148    } {
     149        usual
     150        rename -background -controlbackground controlBackground Background
     151    }
     152    pack $itk_component(zoom) -side top
     153
    140154    itk_component add reset {
    141         button $itk_component(controls).reset \
     155        button $itk_component(zoom).reset \
    142156            -borderwidth 1 -padx 1 -pady 1 \
    143157            -bitmap ContourResult-reset \
     
    152166
    153167    itk_component add zoomin {
    154         button $itk_component(controls).zin \
     168        button $itk_component(zoom).zin \
    155169            -borderwidth 1 -padx 1 -pady 1 \
    156170            -bitmap ContourResult-zoomin \
     
    165179
    166180    itk_component add zoomout {
    167         button $itk_component(controls).zout \
     181        button $itk_component(zoom).zout \
    168182            -borderwidth 1 -padx 1 -pady 1 \
    169183            -bitmap ContourResult-zoomout \
     
    177191    Rappture::Tooltip::for $itk_component(zoomout) "Zoom out"
    178192
     193    #
     194    # Create slicer controls...
     195    #
     196    itk_component add slicers {
     197        frame $itk_component(controls).slicers
     198    } {
     199        usual
     200        rename -background -controlbackground controlBackground Background
     201    }
     202    pack $itk_component(slicers) -side bottom -padx 4 -pady 4
     203    grid rowconfigure $itk_component(slicers) 1 -weight 1
     204
     205    #
     206    # X-value slicer...
     207    #
    179208    itk_component add xslice {
    180         label $itk_component(controls).xslice \
     209        label $itk_component(slicers).xslice \
    181210            -borderwidth 1 -relief raised -padx 1 -pady 1 \
    182211            -bitmap ContourResult-xslice
     
    187216    }
    188217    bind $itk_component(xslice) <ButtonPress> \
    189         [itcl::code $this _slice axis x]
    190     Rappture::Tooltip::for $itk_component(xslice) "Slice along x-axis"
    191 
    192     itk_component add yslice {
    193         label $itk_component(controls).yslice \
    194             -borderwidth 1 -relief raised -padx 1 -pady 1 \
    195             -bitmap ContourResult-yslice
    196     } {
    197         usual
    198         ignore -borderwidth
    199         rename -highlightbackground -controlbackground controlBackground Background
    200     }
    201     bind $itk_component(yslice) <ButtonPress> \
    202         [itcl::code $this _slice axis y]
    203     Rappture::Tooltip::for $itk_component(yslice) "Slice along y-axis"
    204 
    205     itk_component add zslice {
    206         label $itk_component(controls).zslice \
    207             -borderwidth 1 -relief raised -padx 1 -pady 1 \
    208             -bitmap ContourResult-zslice
    209     } {
    210         usual
    211         ignore -borderwidth
    212         rename -highlightbackground -controlbackground controlBackground Background
    213     }
    214     bind $itk_component(zslice) <ButtonPress> \
    215         [itcl::code $this _slice axis z]
    216     Rappture::Tooltip::for $itk_component(zslice) "Slice along z-axis"
    217 
    218     itk_component add slicer {
    219         ::scale $itk_component(controls).slicer -from 100 -to 0 \
    220             -width 10 -orient vertical -showvalue off \
     218        [itcl::code $this _slice axis x toggle]
     219    Rappture::Tooltip::for $itk_component(xslice) \
     220        "Toggle the X cut plane on/off"
     221    grid $itk_component(xslice) -row 0 -column 0 -sticky ew -padx 1
     222
     223    itk_component add xslicer {
     224        ::scale $itk_component(slicers).xval -from 100 -to 0 \
     225            -width 10 -orient vertical -showvalue off -state disabled \
    221226            -borderwidth 1 -highlightthickness 0 \
    222             -command [itcl::code $this _slice move]
     227            -command [itcl::code $this _slice move x]
    223228    } {
    224229        usual
     
    228233        rename -troughcolor -controldarkbackground controlDarkBackground Background
    229234    }
    230     pack $itk_component(slicer) -side bottom -padx 4 -pady 4
    231     Rappture::Tooltip::for $itk_component(slicer) "Move the cut plane"
     235    grid $itk_component(xslicer) -row 1 -column 0 -padx 1
     236    Rappture::Tooltip::for $itk_component(xslicer) \
     237        "@[itcl::code $this _slicertip x]"
     238
     239    #
     240    # Y-value slicer...
     241    #
     242    itk_component add yslice {
     243        label $itk_component(slicers).yslice \
     244            -borderwidth 1 -relief raised -padx 1 -pady 1 \
     245            -bitmap ContourResult-yslice
     246    } {
     247        usual
     248        ignore -borderwidth
     249        rename -highlightbackground -controlbackground controlBackground Background
     250    }
     251    bind $itk_component(yslice) <ButtonPress> \
     252        [itcl::code $this _slice axis y toggle]
     253    Rappture::Tooltip::for $itk_component(yslice) \
     254        "Toggle the Y cut plane on/off"
     255    grid $itk_component(yslice) -row 0 -column 1 -sticky ew -padx 1
     256
     257    itk_component add yslicer {
     258        ::scale $itk_component(slicers).yval -from 100 -to 0 \
     259            -width 10 -orient vertical -showvalue off -state disabled \
     260            -borderwidth 1 -highlightthickness 0 \
     261            -command [itcl::code $this _slice move y]
     262    } {
     263        usual
     264        ignore -borderwidth
     265        ignore -highlightthickness
     266        rename -highlightbackground -controlbackground controlBackground Background
     267        rename -troughcolor -controldarkbackground controlDarkBackground Background
     268    }
     269    grid $itk_component(yslicer) -row 1 -column 1 -padx 1
     270    Rappture::Tooltip::for $itk_component(yslicer) \
     271        "@[itcl::code $this _slicertip y]"
     272
     273    #
     274    # Z-value slicer...
     275    #
     276    itk_component add zslice {
     277        label $itk_component(slicers).zslice \
     278            -borderwidth 1 -relief raised -padx 1 -pady 1 \
     279            -bitmap ContourResult-zslice
     280    } {
     281        usual
     282        ignore -borderwidth
     283        rename -highlightbackground -controlbackground controlBackground Background
     284    }
     285    grid $itk_component(zslice) -row 0 -column 2 -sticky ew -padx 1
     286    bind $itk_component(zslice) <ButtonPress> \
     287        [itcl::code $this _slice axis z toggle]
     288    Rappture::Tooltip::for $itk_component(zslice) \
     289        "Toggle the Z cut plane on/off"
     290
     291    itk_component add zslicer {
     292        ::scale $itk_component(slicers).zval -from 100 -to 0 \
     293            -width 10 -orient vertical -showvalue off -state disabled \
     294            -borderwidth 1 -highlightthickness 0 \
     295            -command [itcl::code $this _slice move z]
     296    } {
     297        usual
     298        ignore -borderwidth
     299        ignore -highlightthickness
     300        rename -highlightbackground -controlbackground controlBackground Background
     301        rename -troughcolor -controldarkbackground controlDarkBackground Background
     302    }
     303    grid $itk_component(zslicer) -row 1 -column 2 -padx 1
     304    Rappture::Tooltip::for $itk_component(zslicer) \
     305        "@[itcl::code $this _slicertip z]"
    232306
    233307    #
     
    242316    vtkRenderWindow $this-renWin
    243317    $this-renWin AddRenderer $this-ren
     318    $this-renWin LineSmoothingOn
     319    $this-renWin PolygonSmoothingOn
    244320    vtkRenderWindowInteractor $this-iren
    245321    $this-iren SetRenderWindow $this-renWin
     
    430506itcl::body Rappture::ContourResult::_rebuild {} {
    431507    _clear
     508    set id 0
    432509
    433510    # determine the dimensionality from the topmost (raised) object
     
    435512    set dataobj [lindex $dlist end]
    436513    if {$dataobj != ""} {
    437         set _dims [$dataobj components -dimensions]
     514        set _dims [lindex [lsort [$dataobj components -dimensions]] end]
    438515    } else {
    439516        set _dims "0D"
    440517    }
    441518
     519    #
     520    # LOOKUP TABLE FOR COLOR CONTOURS
     521    #
     522    # use vmin/vmax if possible, otherwise get from data
     523    if {$_limits(vmin) == "" || $_limits(vmax) == ""} {
     524        foreach {v0 v1} [$pd GetScalarRange] break
     525    } else {
     526        set v0 $_limits(vmin)
     527        set v1 $_limits(vmax)
     528    }
     529
     530    set lu $this-lookup$id
     531    vtkLookupTable $lu
     532    $lu SetTableRange $v0 $v1
     533    $lu SetHueRange 0.66667 0.0
     534    $lu Build
     535
     536    lappend _obj2vtk($dataobj) $lu
     537
     538    if {$_dims == "3D"} {
     539        #
     540        # 3D LIGHTS (on both sides of all three axes)
     541        #
     542        set x0 $_limits(xmin)
     543        set x1 $_limits(xmax)
     544        set xm [expr {0.5*($x0+$x1)}]
     545        set y0 $_limits(ymin)
     546        set y1 $_limits(ymax)
     547        set ym [expr {0.5*($y0+$y1)}]
     548        set z0 $_limits(zmin)
     549        set z1 $_limits(zmax)
     550        set zm [expr {0.5*($z0+$z1)}]
     551        set xr [expr {$x1-$x0}]
     552        set yr [expr {$y1-$y0}]
     553        set zr [expr {$z1-$z0}]
     554
     555        set lt $this-light$id
     556        vtkLight $lt
     557        $lt SetColor 1 1 1
     558        $lt SetAttenuationValues 0 0 0
     559        $lt SetFocalPoint $xm $ym $zm
     560        $lt SetLightTypeToHeadlight
     561        $this-ren AddLight $lt
     562        lappend _lights($this-ren) $lt
     563
     564    } else {
     565    }
     566
    442567    # scan through all data objects and build the contours
    443     set _counter 0
     568    set firstobj 1
    444569    foreach dataobj [get] {
    445570        foreach comp [$dataobj components] {
    446571            #
    447             # LOOKUP TABLE FOR COLOR CONTOURS
    448             #
    449             # use vmin/vmax if possible, otherwise get from data
    450             if {$_limits(vmin) == "" || $_limits(vmax) == ""} {
    451                 foreach {v0 v1} [$pd GetScalarRange] break
    452             } else {
    453                 set v0 $_limits(vmin)
    454                 set v1 $_limits(vmax)
    455             }
    456 
    457             set lu $this-lookup$_counter
    458             vtkLookupTable $lu
    459             $lu SetTableRange $v0 $v1
    460             $lu SetHueRange 0.66667 0.0
    461             $lu Build
    462 
    463             lappend _obj2vtk($dataobj) $lu
    464 
    465             #
    466572            # Add color contours.
    467573            #
    468             if {$_counter == 0} {
     574            if {$firstobj} {
    469575                if {$_dims == "3D"} {
    470                     pack $itk_component(slicer) -side bottom -padx 4 -pady 4
    471                     pack $itk_component(zslice) -side bottom -padx 4 -pady 4
    472                     pack $itk_component(yslice) -side bottom -padx 4 -pady 4
    473                     pack $itk_component(xslice) -side bottom -padx 4 -pady 4
    474 
    475                     #
    476                     # 3D LIGHTS (on both sides of all three axes)
    477                     #
    478                     set xm [expr {0.5*($_limits(xmax)+$_limits(xmin))}]
    479                     set ym [expr {0.5*($_limits(ymax)+$_limits(ymin))}]
    480                     set zm [expr {0.5*($_limits(zmax)+$_limits(zmin))}]
    481                     set xr [expr {$_limits(xmax)-$_limits(xmin)}]
    482                     set yr [expr {$_limits(ymax)-$_limits(ymin)}]
    483                     set zr [expr {$_limits(zmax)-$_limits(zmin)}]
    484 
    485                     set lt $this-lightxm$_counter
    486                     vtkLight $lt
    487                     $lt SetColor 1 1 1
    488                     $lt SetAttenuationValues 0 0 0
    489                     $lt SetFocalPoint $xm $ym $zm
    490                     $lt SetPosition [expr {$xm-$xr}] 0 0
    491                     $this-ren AddLight $lt
    492                     lappend _lights($this-ren) $lt
    493 
    494                     set lt $this-lightxp$_counter
    495                     vtkLight $lt
    496                     $lt SetColor 1 1 1
    497                     $lt SetAttenuationValues 0 0 0
    498                     $lt SetFocalPoint $xm $ym $zm
    499                     $lt SetPosition [expr {$xm+$xr}] 0 0
    500                     $this-ren AddLight $lt
    501                     lappend _lights($this-ren) $lt
    502 
    503                     set lt $this-lightym$_counter
    504                     vtkLight $lt
    505                     $lt SetColor 1 1 1
    506                     $lt SetAttenuationValues 0 0 0
    507                     $lt SetFocalPoint $xm $ym $zm
    508                     $lt SetPosition 0 [expr {$ym-$yr}] 0
    509                     $this-ren AddLight $lt
    510                     lappend _lights($this-ren) $lt
    511 
    512                     set lt $this-lightyp$_counter
    513                     vtkLight $lt
    514                     $lt SetColor 1 1 1
    515                     $lt SetAttenuationValues 0 0 0
    516                     $lt SetFocalPoint $xm $ym $zm
    517                     $lt SetPosition 0 [expr {$ym+$yr}] 0
    518                     $this-ren AddLight $lt
    519                     lappend _lights($this-ren) $lt
    520 
    521                     set lt $this-lightzm$_counter
    522                     vtkLight $lt
    523                     $lt SetColor 1 1 1
    524                     $lt SetAttenuationValues 0 0 0
    525                     $lt SetFocalPoint $xm $ym $zm
    526                     $lt SetPosition 0 0 [expr {$zm-$zr}]
    527                     $this-ren AddLight $lt
    528                     lappend _lights($this-ren) $lt
    529 
    530                     set lt $this-lightzp$_counter
    531                     vtkLight $lt
    532                     $lt SetColor 1 1 1
    533                     $lt SetAttenuationValues 0 0 0
    534                     $lt SetFocalPoint $xm $ym $zm
    535                     $lt SetPosition 0 0 [expr {$zm+$zr}]
    536                     $this-ren AddLight $lt
    537                     lappend _lights($this-ren) $lt
     576                    pack $itk_component(slicers) -side bottom -padx 4 -pady 4
     577                    pack $itk_component(reset) -side left
     578                    pack $itk_component(zoomin) -side left
     579                    pack $itk_component(zoomout) -side left
    538580
    539581                    #
     
    544586                      vtkPoints {
    545587                        # handle cloud of 3D points
    546                         set pd $this-polydata$_counter
     588                        set pd $this-polydata$id
    547589                        vtkPolyData $pd
    548590                        $pd SetPoints $mesh
    549591                        [$pd GetPointData] SetScalars [$dataobj values $comp]
    550592
    551                         set tr $this-triangles$_counter
     593                        set tr $this-triangles$id
    552594                        vtkDelaunay3D $tr
    553595                        $tr SetInput $pd
     
    555597                        set source [$tr GetOutput]
    556598
    557                         set mp $this-mapper$_counter
     599                        set mp $this-mapper$id
    558600                        vtkPolyDataMapper $mp
    559601
     
    562604                      vtkUnstructuredGrid {
    563605                        # handle 3D grid with connectivity
    564                         set gr $this-grdata$_counter
     606                        set gr $this-grdata$id
    565607                        vtkUnstructuredGrid $gr
     608                        $gr ShallowCopy $mesh
     609                        [$gr GetPointData] SetScalars [$dataobj values $comp]
     610                        set source $gr
     611
     612                        lappend _obj2vtk($dataobj) $gr
     613                      }
     614                      vtkRectilinearGrid {
     615                        # handle 3D grid with connectivity
     616                        set gr $this-grdata$id
     617                        vtkRectilinearGrid $gr
    566618                        $gr ShallowCopy $mesh
    567619                        [$gr GetPointData] SetScalars [$dataobj values $comp]
     
    576628
    577629                    #
    578                     # 3D CUT PLANE
     630                    # 3D ISOSURFACES
    579631                    #
    580                     set pl $this-cutplane$_counter
    581                     vtkPlane $pl
    582                     set _slicer(plane) $pl
    583                     _slice axis "z"
    584 
    585                     set ct $this-cutter$_counter
    586                     vtkCutter $ct
    587                     $ct SetInput $source
    588                     $ct SetCutFunction $pl
    589 
    590                     set mp $this-cutmapper$_counter
     632                    set iso $this-iso$id
     633                    vtkContourFilter $iso
     634                      $iso SetInput $source
     635
     636                    set mp $this-isomap$id
    591637                    vtkPolyDataMapper $mp
    592                     $mp SetInput [$ct GetOutput]
     638                      $mp SetInput [$iso GetOutput]
     639
     640                    set ac $this-isoactor$id
     641                    vtkActor $ac
     642                      $ac SetMapper $mp
     643                      [$ac GetProperty] SetOpacity 0.3
     644                      [$ac GetProperty] SetDiffuse 0.5
     645                      [$ac GetProperty] SetAmbient 0.7
     646                      [$ac GetProperty] SetSpecular 10.0
     647                      [$ac GetProperty] SetSpecularPower 200.0
     648                    $this-ren AddActor $ac
     649
     650                    lappend _obj2vtk($dataobj) $iso $mp $ac
     651                    lappend _actors($this-ren) $ac
     652
     653                    catch {unset style}
     654                    array set style [lindex [$dataobj components -style $comp] 0]
     655                    if {[info exists style(-color)]} {
     656                        $mp ScalarVisibilityOff  ;# take color from actor
     657                        eval [$ac GetProperty] SetColor [_color2rgb $style(-color)]
     658                    }
     659
     660                    if {[info exists style(-opacity)]} {
     661                        [$ac GetProperty] SetOpacity $style(-opacity)
     662                    }
     663
     664                    set levels 5
     665                    if {[info exists style(-levels)]} {
     666                        set levels $style(-levels)
     667                    }
     668                    if {$levels == 1} {
     669                        $iso SetValue 0 [expr {0.5*($v1-$v0)+$v0}]
     670                    } else {
     671                        $iso GenerateValues [expr {$levels+2}] $v0 $v1
     672                    }
     673
     674                    #
     675                    # 3D CUT PLANES
     676                    #
     677                    if {$id == 0} {
     678                        foreach axis {x y z} norm {{1 0 0} {0 1 0} {0 0 1}} {
     679                            set pl $this-${axis}cutplane$id
     680                            vtkPlane $pl
     681                            eval $pl SetNormal $norm
     682                            set _slicer(${axis}plane) $pl
     683
     684                            set ct $this-${axis}cutter$id
     685                            vtkCutter $ct
     686                            $ct SetInput $source
     687                            $ct SetCutFunction $pl
     688
     689                            set mp $this-${axis}cutmapper$id
     690                            vtkPolyDataMapper $mp
     691                            $mp SetInput [$ct GetOutput]
     692                            $mp SetScalarRange $v0 $v1
     693                            $mp SetLookupTable $lu
     694
     695                            lappend _obj2vtk($dataobj) $pl $ct $mp
     696
     697                            set ac $this-${axis}actor$id
     698                            vtkActor $ac
     699                            $ac VisibilityOff
     700                            $ac SetMapper $mp
     701                            $ac SetPosition 0 0 0
     702                            [$ac GetProperty] SetColor 0 0 0
     703                            set _slicer(${axis}slice) $ac
     704
     705                            $this-ren AddActor $ac
     706                            lappend _actors($this-ren) $ac
     707                            lappend _obj2vtk($dataobj) $ac
     708                        }
     709
     710                        #
     711                        # CUT PLANE READOUT
     712                        #
     713                        set tx $this-text$id
     714                        vtkTextMapper $tx
     715                        set tp [$tx GetTextProperty]
     716                        eval $tp SetColor [_color2rgb $itk_option(-plotforeground)]
     717                        $tp SetVerticalJustificationToTop
     718                        set _slicer(readout) $tx
     719
     720                        set txa $this-texta$id
     721                        vtkActor2D $txa
     722                        $txa SetMapper $tx
     723                        [$txa GetPositionCoordinate] \
     724                            SetCoordinateSystemToNormalizedDisplay
     725                        [$txa GetPositionCoordinate] SetValue 0.02 0.98
     726
     727                        $this-ren AddActor $txa
     728                        lappend _actors($this-ren) $txa
     729
     730                        lappend _obj2vtk($dataobj) $tx $txa
     731
     732                        # turn off all slicers by default
     733                        foreach axis {x y z} {
     734                            $itk_component(${axis}slicer) configure -state normal
     735                            $itk_component(${axis}slicer) set 50
     736                            _slice move $axis 50
     737                            _slice axis $axis off
     738                        }
     739                    }
     740
     741                } else {
     742                    pack forget $itk_component(slicers)
     743                    pack $itk_component(reset) -side top
     744                    pack $itk_component(zoomin) -side top
     745                    pack $itk_component(zoomout) -side top
     746
     747                    set pd $this-polydata$id
     748                    vtkPolyData $pd
     749                    $pd SetPoints [$dataobj mesh $comp]
     750                    [$pd GetPointData] SetScalars [$dataobj values $comp]
     751
     752                    set tr $this-triangles$id
     753                    vtkDelaunay2D $tr
     754                    $tr SetInput $pd
     755                    $tr SetTolerance 0.0000000000001
     756                    set source [$tr GetOutput]
     757
     758                    set mp $this-mapper$id
     759                    vtkPolyDataMapper $mp
     760                    $mp SetInput $source
    593761                    $mp SetScalarRange $v0 $v1
    594762                    $mp SetLookupTable $lu
    595763
    596                     lappend _obj2vtk($dataobj) $pl $ct $mp
    597 
    598                     set ac $this-actor$_counter
     764                    set ac $this-actor$id
    599765                    vtkActor $ac
    600766                    $ac SetMapper $mp
     
    603769                    $this-ren AddActor $ac
    604770                    lappend _actors($this-ren) $ac
    605                     lappend _obj2vtk($dataobj) $ac
    606 
    607                     set olf $this-3dolfilter$_counter
    608                     vtkOutlineFilter $olf
    609                     $olf SetInput $source
    610 
    611                     set olm $this-3dolmapper$_counter
    612                     vtkPolyDataMapper $olm
    613                     $olm SetInput [$olf GetOutput]
    614 
    615                     set ola $this-3dolactor$_counter
    616                     vtkActor $ola
    617                     $ola SetMapper $olm
    618                     eval [$ola GetProperty] SetColor 0 0 0
    619                     $this-ren AddActor $ola
    620                     lappend _actors($this-ren) $ola
    621 
    622                     lappend _obj2vtk($dataobj) $olf $olm $ola
    623 
    624                     #
    625                     # CUT PLANE READOUT
    626                     #
    627                     set tx $this-text$_counter
    628                     vtkTextMapper $tx
    629                     set tp [$tx GetTextProperty]
    630                     eval $tp SetColor [_color2rgb $itk_option(-foreground)]
    631                     $tp SetVerticalJustificationToTop
    632                     set _slicer(readout) $tx
    633 
    634                     set txa $this-texta$_counter
    635                     vtkActor2D $txa
    636                     $txa SetMapper $tx
    637                     [$txa GetPositionCoordinate] \
    638                         SetCoordinateSystemToNormalizedDisplay
    639                     [$txa GetPositionCoordinate] SetValue 0.02 0.98
    640 
    641                     $this-ren AddActor $txa
    642                     lappend _actors($this-ren) $txa
    643 
    644                     lappend _obj2vtk($dataobj) $tx $txa
    645                 } else {
    646                     pack forget $itk_component(xslice)
    647                     pack forget $itk_component(yslice)
    648                     pack forget $itk_component(zslice)
    649                     pack forget $itk_component(slicer)
    650 
    651                     set pd $this-polydata$_counter
    652                     vtkPolyData $pd
    653                     $pd SetPoints [$dataobj mesh $comp]
    654                     [$pd GetPointData] SetScalars [$dataobj values $comp]
    655 
    656                     set tr $this-triangles$_counter
    657                     vtkDelaunay2D $tr
    658                     $tr SetInput $pd
    659                     $tr SetTolerance 0.0000000000001
    660                     set source [$tr GetOutput]
    661 
    662                     set mp $this-mapper$_counter
    663                     vtkPolyDataMapper $mp
    664                     $mp SetInput $source
    665                     $mp SetScalarRange $v0 $v1
    666                     $mp SetLookupTable $lu
    667 
    668                     set ac $this-actor$_counter
    669                     vtkActor $ac
    670                     $ac SetMapper $mp
    671                     $ac SetPosition 0 0 0
    672                     [$ac GetProperty] SetColor 0 0 0
    673                     $this-ren AddActor $ac
    674                     lappend _actors($this-ren) $ac
    675771
    676772                    lappend _obj2vtk($dataobj) $pd $tr $mp $ac
    677773                }
    678             }
    679 
    680             #
    681             # Add color lines
    682             #
    683             if {$_counter > 0} {
    684                 set cf $this-clfilter$_counter
     774            } else {
     775                #
     776                # Add color lines
     777                #
     778                set cf $this-clfilter$id
    685779                vtkContourFilter $cf
    686780                $cf SetInput $source
    687781                $cf GenerateValues 20 $v0 $v1
    688782
    689                 set mp $this-clmapper$_counter
     783                set mp $this-clmapper$id
    690784                vtkPolyDataMapper $mp
    691785                $mp SetInput [$cf GetOutput]
     
    693787                $mp SetLookupTable $lu
    694788
    695                 set ac $this-clactor$_counter
     789                set ac $this-clactor$id
    696790                vtkActor $ac
    697791                $ac SetMapper $mp
     
    707801            # Add an outline around the data
    708802            #
    709             set olf $this-olfilter$_counter
    710             vtkOutlineFilter $olf
    711             $olf SetInput $source
    712 
    713             set olm $this-olmapper$_counter
    714             vtkPolyDataMapper $olm
    715             $olm SetInput [$olf GetOutput]
    716 
    717             set ola $this-olactor$_counter
    718             vtkActor $ola
    719             $ola SetMapper $olm
    720             eval [$ola GetProperty] SetColor 0 0 0
    721             $this-ren AddActor $ola
    722             lappend _actors($this-ren) $ola
    723 
    724             lappend _obj2vtk($dataobj) $olf $olm $ola
     803            if {$id == 0} {
     804                set olf $this-olfilter$id
     805                vtkOutlineFilter $olf
     806                $olf SetInput $source
     807
     808                set olm $this-olmapper$id
     809                vtkPolyDataMapper $olm
     810                $olm SetInput [$olf GetOutput]
     811
     812                set ola $this-olactor$id
     813                vtkActor $ola
     814                $ola SetMapper $olm
     815                eval [$ola GetProperty] SetColor [_color2rgb $itk_option(-plotforeground)]
     816                $this-ren AddActor $ola
     817                lappend _actors($this-ren) $ola
     818
     819                lappend _obj2vtk($dataobj) $olf $olm $ola
     820
     821                if {$_dims == "3D"} {
     822                    # pick a good scale factor for text
     823                    if {$xr < $yr} {
     824                        set tscale [expr {0.1*$xr}]
     825                    } else {
     826                        set tscale [expr {0.1*$yr}]
     827                    }
     828
     829                    foreach {i axis px py pz rx ry rz} {
     830                        0  x   $xm   0   0   90   0   0
     831                        1  y     0 $ym   0   90 -90   0
     832                        2  z   $x1   0 $zm   90   0 -45
     833                    } {
     834                        set length "[expr {[set ${axis}1]-[set ${axis}0]}]"
     835
     836                        set vtx $this-${axis}label$id
     837                        vtkVectorText $vtx
     838                        $vtx SetText "$axis"
     839
     840                        set vmp $this-${axis}lmap$id
     841                        vtkPolyDataMapper $vmp
     842                        $vmp SetInput [$vtx GetOutput]
     843
     844                        set vac $this-${axis}lact$id
     845                        vtkActor $vac
     846                        $vac SetMapper $vmp
     847                        $vac SetPosition [expr $px] [expr $py] [expr $pz]
     848                        $vac SetOrientation $rx $ry $rz
     849                        $vac SetScale $tscale
     850                        $this-ren AddActor $vac
     851
     852                        lappend _obj2vtk($dataobj) $vtx $vmp $vac
     853                        lappend _actors($this-ren) $vac
     854
     855                        $vmp Update
     856                        foreach {xx0 xx1 yy0 yy1 zz0 zz1} [$vac GetBounds] break
     857                        switch -- $axis {
     858                          x {
     859                            set dx [expr {-0.5*($xx1-$xx0)}]
     860                            set dy 0
     861                            set dz [expr {1.3*($zz0-$zz1)}]
     862                          }
     863                          y {
     864                            set dx 0
     865                            set dy [expr {0.5*($yy1-$yy0)}]
     866                            set dz [expr {$zz0-$zz1}]
     867                          }
     868                          z {
     869                            set dx [expr {0.2*$tscale}]
     870                            set dy $dx
     871                            set dz [expr {-0.5*($zz1-$zz0)}]
     872                          }
     873                        }
     874                        $vac AddPosition $dx $dy $dz
     875                    }
     876                }
     877            }
    725878
    726879            #
    727880            # Add a legend with the scale.
    728881            #
    729             set lg $this-legend$_counter
    730             vtkScalarBarActor $lg
    731             $lg SetLookupTable $lu
    732             [$lg GetPositionCoordinate] SetCoordinateSystemToNormalizedViewport
    733             [$lg GetPositionCoordinate] SetValue 0.1 0.1
    734             $lg SetOrientationToHorizontal
    735             $lg SetWidth 0.8
    736             $lg SetHeight 1.0
    737 
    738             set tp [$lg GetLabelTextProperty]
    739             eval $tp SetColor [_color2rgb $itk_option(-foreground)]
    740             $tp BoldOff
    741             $tp ItalicOff
    742             $tp ShadowOff
    743             #eval $tp SetShadowColor [_color2rgb gray]
    744 
    745             $this-ren2 AddActor2D $lg
    746             lappend _actors($this-ren2) $lg
    747             lappend _obj2vtk($dataobj) $lg
    748 
    749             incr _counter
    750         }
     882            if {$id == 0} {
     883                set lg $this-legend$id
     884                vtkScalarBarActor $lg
     885                $lg SetLookupTable $lu
     886                [$lg GetPositionCoordinate] SetCoordinateSystemToNormalizedViewport
     887                [$lg GetPositionCoordinate] SetValue 0.1 0.1
     888                $lg SetOrientationToHorizontal
     889                $lg SetWidth 0.8
     890                $lg SetHeight 1.0
     891
     892                set tp [$lg GetLabelTextProperty]
     893                eval $tp SetColor [_color2rgb $itk_option(-plotforeground)]
     894                $tp BoldOff
     895                $tp ItalicOff
     896                $tp ShadowOff
     897                #eval $tp SetShadowColor [_color2rgb gray]
     898
     899                $this-ren2 AddActor2D $lg
     900                lappend _actors($this-ren2) $lg
     901                lappend _obj2vtk($dataobj) $lg
     902            }
     903
     904            incr id
     905        }
     906        set firstobj 0
    751907    }
    752908    _fixLimits
     
    790946        set _obj2vtk($dataobj) ""
    791947    }
    792     set _slicer(axis) ""
    793     set _slicer(plane) ""
     948    set _slicer(xplane) ""
     949    set _slicer(yplane) ""
     950    set _slicer(zplane) ""
     951    set _slicer(xslice) ""
     952    set _slicer(yslice) ""
     953    set _slicer(zslice) ""
    794954    set _slicer(readout) ""
    795955}
     
    8911051
    8921052# ----------------------------------------------------------------------
    893 # USAGE: _slice axis x|y|z
    894 # USAGE: _slice move <newval>
     1053# USAGE: _slice axis x|y|z ?on|off|toggle?
     1054# USAGE: _slice move x|y|z <newval>
    8951055#
    8961056# Called automatically when the user drags the slider to move the
     
    9001060# ----------------------------------------------------------------------
    9011061itcl::body Rappture::ContourResult::_slice {option args} {
    902     if {$_slicer(plane) == ""} {
     1062    if {$_slicer(xplane) == ""} {
    9031063        # no slicer? then bail out!
    9041064        return
     
    9061066    switch -- $option {
    9071067        axis {
    908             if {[llength $args] != 1} {
    909                 error "wrong # args: should be \"_slice axis xyz\""
     1068            if {[llength $args] < 1 || [llength $args] > 2} {
     1069                error "wrong # args: should be \"_slice axis x|y|z ?on|off|toggle?\""
    9101070            }
    9111071            set axis [lindex $args 0]
    912 
    913             switch -- $axis {
    914                 x { $_slicer(plane) SetNormal 1 0 0 }
    915                 y { $_slicer(plane) SetNormal 0 1 0 }
    916                 z { $_slicer(plane) SetNormal 0 0 1 }
    917                 default {
    918                     error "bad axis \"$axis\": should be x, y, z"
    919                 }
    920             }
    921 
    922             set _slicer(axis) $axis
    923             $itk_component(slicer) set 50
    924             _slice move 50
     1072            set op [lindex $args 1]
     1073            if {$op == ""} { set op "on" }
     1074
     1075            if {[$itk_component(${axis}slice) cget -relief] == "raised"} {
     1076                set current "off"
     1077            } else {
     1078                set current "on"
     1079            }
     1080
     1081            if {$op == "toggle"} {
     1082                if {$current == "on"} { set op "off" } else { set op "on" }
     1083            }
     1084
     1085            if {$op} {
     1086                $itk_component(${axis}slicer) configure -state normal
     1087                $_slicer(${axis}slice) VisibilityOn
     1088                $itk_component(${axis}slice) configure -relief sunken
     1089            } else {
     1090                $itk_component(${axis}slicer) configure -state disabled
     1091                $_slicer(${axis}slice) VisibilityOff
     1092                $itk_component(${axis}slice) configure -relief raised
     1093            }
    9251094            $this-renWin Render
    926 
    927             foreach a {x y z} {
    928                 $itk_component(${a}slice) configure -relief raised
    929             }
    930             $itk_component(${axis}slice) configure -relief sunken
    9311095        }
    9321096        move {
    933             if {[llength $args] != 1} {
    934                 error "wrong # args: should be \"_slice move newval\""
    935             }
    936             set newval [lindex $args 0]
     1097            if {[llength $args] != 2} {
     1098                error "wrong # args: should be \"_slice move x|y|z newval\""
     1099            }
     1100            set axis [lindex $args 0]
     1101            set newval [lindex $args 1]
    9371102
    9381103            set xm [expr {0.5*($_limits(xmax)+$_limits(xmin))}]
     
    9401105            set zm [expr {0.5*($_limits(zmax)+$_limits(zmin))}]
    9411106
    942             set a $_slicer(axis)
    9431107            set newval [expr {0.01*($newval-50)
    944                 *($_limits(${a}max)-$_limits(${a}min))
    945                   + 0.5*($_limits(${a}max)+$_limits(${a}min))}]
     1108                *($_limits(${axis}max)-$_limits(${axis}min))
     1109                  + 0.5*($_limits(${axis}max)+$_limits(${axis}min))}]
    9461110
    9471111            # show the current value in the readout
    9481112            if {$_slicer(readout) != ""} {
    949                 $_slicer(readout) SetInput "$a = $newval"
     1113                $_slicer(readout) SetInput "$axis = $newval"
    9501114            }
    9511115
    9521116            # keep a little inside the volume, or the slice will disappear!
    953             if {$newval == $_limits(${a}min)} {
    954                 set range [expr {$_limits(${a}max)-$_limits(${a}min)}]
     1117            if {$newval == $_limits(${axis}min)} {
     1118                set range [expr {$_limits(${axis}max)-$_limits(${axis}min)}]
    9551119                set newval [expr {$newval + 1e-6*$range}]
    9561120            }
    9571121
    9581122            # xfer new value to the proper dimension and move the cut plane
    959             set ${a}m $newval
    960             $_slicer(plane) SetOrigin $xm $ym $zm
     1123            set ${axis}m $newval
     1124            $_slicer(${axis}plane) SetOrigin $xm $ym $zm
    9611125
    9621126            $this-renWin Render
     
    10161180
    10171181# ----------------------------------------------------------------------
     1182# USAGE: _slicertip <axis>
     1183#
     1184# Used internally to generate a tooltip for the x/y/z slicer controls.
     1185# Returns a message that includes the current slicer value.
     1186# ----------------------------------------------------------------------
     1187itcl::body Rappture::ContourResult::_slicertip {axis} {
     1188    set val [$itk_component(${axis}slicer) get]
     1189    set val [expr {0.01*($val-50)
     1190        *($_limits(${axis}max)-$_limits(${axis}min))
     1191          + 0.5*($_limits(${axis}max)+$_limits(${axis}min))}]
     1192    return "Move the [string toupper $axis] cut plane.\nCurrently:  $axis = $val"
     1193}
     1194
     1195# ----------------------------------------------------------------------
    10181196# USAGE: _color2rgb <color>
    10191197#
     
    10301208
    10311209# ----------------------------------------------------------------------
    1032 # CONFIGURATION OPTION: -background
    1033 # ----------------------------------------------------------------------
    1034 itcl::configbody Rappture::ContourResult::background {
    1035     foreach {r g b} [_color2rgb $itk_option(-background)] break
     1210# CONFIGURATION OPTION: -plotbackground
     1211# ----------------------------------------------------------------------
     1212itcl::configbody Rappture::ContourResult::plotbackground {
     1213    foreach {r g b} [_color2rgb $itk_option(-plotbackground)] break
    10361214    $this-ren SetBackground $r $g $b
    10371215    $this-renWin Render
     
    10411219
    10421220# ----------------------------------------------------------------------
    1043 # CONFIGURATION OPTION: -foreground
    1044 # ----------------------------------------------------------------------
    1045 itcl::configbody Rappture::ContourResult::foreground {
     1221# CONFIGURATION OPTION: -plotforeground
     1222# ----------------------------------------------------------------------
     1223itcl::configbody Rappture::ContourResult::plotforeground {
    10461224    after cancel [itcl::code $this _rebuild]
    10471225    after idle [itcl::code $this _rebuild]
  • trunk/gui/scripts/energyLevels.tcl

    r115 r136  
    9797    private variable _edefmax ""   ;# max for default "zoom" view
    9898    private variable _ehomo ""     ;# energy of HOMO level in topmost dataset
     99    private variable _lhomo ""     ;# label for HOMO level
    99100    private variable _elumo ""     ;# energy of LUMO level in topmost dataset
     101    private variable _llumo ""     ;# label for LUMO level
    100102    private variable _hilite ""    ;# item currently highlighted
    101103}
     
    252254        if {"" == $units} {
    253255            set vals [$dataobj values -column $index]
    254             if {[regexp {(^|[[:space:]])HOMO([[:space:]]|$)} $vals]} {
    255                 if {$lpos >= 0} {
    256                     # more than one labels column -- bail out
    257                     set lpos -1
    258                     break
    259                 }
     256            if {$lpos != $epos} {
    260257                set lpos $index
     258                break
    261259            }
    262260        }
     
    438436        # the bottom up.
    439437        #
    440         set e2y [expr {($y1-$y0)/($_emax-$_emin)}]
     438        set e2y [expr {($yzoom1-$yzoom0)/($_emax-$_emin)}]
    441439
    442440        set title ""
     
    455453
    456454            foreach eval [$dataobj values -column $ecol] {
    457                 set y [expr {($eval-$_emin)*$e2y + $y0}]
     455                set y [expr {($eval-$_emin)*$e2y + $yzoom0}]
    458456                $c create line $xx0 $y $xx1 $y -fill $color -width 1
    459457            }
     
    481479                    lval [$dataobj values -column $lcol] {
    482480
    483                 if {$lval == "HOMO"} {
     481                if {[string equal -nocase $lval "HOMO"]} {
    484482                    set nhomo $n
     483                    set _lhomo $lval
    485484                    set nlumo [expr {$n+1}]
    486                 } elseif {$lval == "LUMO"} {
     485                    set _llumo "LUMO"
     486                } elseif {[string equal -nocase $lval "Ground State"]} {
     487                    set nhomo $n
     488                    set _lhomo $lval
     489                    set nlumo [expr {$n+1}]
     490                    set _llumo "1st Excited State"
     491                } elseif {[string equal -nocase $lval "LUMO"]
     492                      || [string equal -nocase $lval "1st Excited State"]} {
    487493                    set nlumo $n
     494                    set _llumo $lval
    488495                }
    489496                incr n
     
    498505                set _edefmax [expr {$_elumo + 0.3*$gap}]
    499506
    500                 set y [expr {($_ehomo-$_emin)*$e2y + $y0}]
     507                set y [expr {($_ehomo-$_emin)*$e2y + $yzoom0}]
    501508                set id [$c create rectangle $xx0 $y $xx1 $y0 \
    502509                    -stipple EnergyLevels-rdiag \
     
    519526        # draw the lines for the "zoom" view (fixed up below)
    520527        set color $itk_option(-foreground)
    521         $c create line $x0 $y0 $x1 $y0 -fill $color -tags zmin
    522         $c create line $x0 $y0 $x1 $y0 -fill $color -tags zmax
    523 
    524         $c create line $x1 $y0 $x2 $y0 -fill $color -tags zoomup
    525         $c create line $x1 $y0 $x2 $y1 -fill $color -tags zoomdn
    526 
    527         $c create line $x2 $y0 $x3 $y0 -fill $color
    528         $c create line $x2 $y1 $x3 $y1 -fill $color
     528        $c create line $x0 $yzoom0 $x1 $yzoom0 -fill $color -tags zmin
     529        $c create line $x0 $yzoom0 $x1 $yzoom0 -fill $color -tags zmax
     530
     531        $c create line $x1 $yzoom0 $x2 $yzoom0 -fill $color -tags zoomup
     532        $c create line $x1 $yzoom0 $x2 $yzoom1 -fill $color -tags zoomdn
     533
     534        $c create line $x2 $yzoom0 $x3 $yzoom0 -fill $color
     535        $c create line $x2 $yzoom1 $x3 $yzoom1 -fill $color
    529536    }
    530537
     
    533540    #
    534541    if {$what == "zoom" || $what == "all"} {
    535         set e2y [expr {($y1-$y0)/($_emax-$_emin)}]
    536 
    537         set y [expr {($_eviewmin-$_emin)*$e2y + $y0}]
     542        set e2y [expr {($yzoom1-$yzoom0)/($_emax-$_emin)}]
     543
     544        set y [expr {($_eviewmin-$_emin)*$e2y + $yzoom0}]
    538545        $c coords zmin $x0 $y $x1 $y
    539         $c coords zoomup $x1 $y $x2 $y0
    540 
    541         set y [expr {($_eviewmax-$_emin)*$e2y + $y0}]
     546        $c coords zoomup $x1 $y $x2 $yzoom0
     547
     548        set y [expr {($_eviewmax-$_emin)*$e2y + $yzoom0}]
    542549        $c coords zmax $x0 $y $x1 $y
    543         $c coords zoomdn $x1 $y $x2 $y1
     550        $c coords zoomdn $x1 $y $x2 $yzoom1
    544551
    545552        # redraw all levels in the current view
    546553        $c delete zlevels zlabels
    547554
    548         set e2y [expr {($y1-$y0)/($_eviewmax-$_eviewmin)}]
     555        set e2y [expr {($yzoom1-$yzoom0)/($_eviewmax-$_eviewmin)}]
    549556        foreach dataobj $dlist {
    550557            set ecol $_dobj2cols($dataobj-energy)
     
    556563            set n 0
    557564            foreach eval [$dataobj values -column $ecol] {
    558                 if {$eval >= $_eviewmin && $eval <= $_eviewmax} {
    559                     set y [expr {($eval-$_eviewmin)*$e2y + $y0}]
     565                set y [expr {($eval-$_eviewmin)*$e2y + $yzoom0}]
     566                if {$y >= $y1 && $y <= $y0} {
    560567                    set id [$c create line $xx2 $y $xx3 $y \
    561568                        -fill $color -width 1 \
     
    570577            set units [$topdobj columns -units $ecol]
    571578
    572             set yy0 [expr {($_ehomo-$_eviewmin)*$e2y + $y0}]
    573             set yy1 [expr {($_elumo-$_eviewmin)*$e2y + $y0}]
    574             $c create line [expr {$x3-10}] $yy0 [expr {$x3-10}] $yy1 \
    575                 -arrow both -fill $itk_option(-foreground) \
    576                 -tags zlabels
    577             $c create text [expr {$x3-15}] [expr {0.5*($yy0+$yy1)}] \
    578                 -anchor e -text "Eg = [expr {$_elumo-$_ehomo}] $units" \
    579                 -tags zlabels
    580 
    581             # label the HOMO level
    582             set tid [$c create text [expr {0.5*($x2+$x3)}] $yy0 -anchor c \
    583                 -text "HOMO = $_ehomo $units" \
    584                 -fill $itk_option(-leveltextforeground) \
    585                 -tags zlabels]
    586 
    587             foreach {xb0 yb0 xb1 yb1} [$c bbox $tid] break
    588             set tid2 [$c create rectangle \
    589                 [expr {$xb0-1}] [expr {$yb0-1}] \
    590                 [expr {$xb1+1}] [expr {$yb1+1}] \
    591                 -outline $itk_option(-leveltextforeground) \
    592                 -fill $itk_option(-leveltextbackground) \
    593                 -tags zlabels]
    594             $c lower $tid2 $tid
    595 
    596             # label the LUMO level
    597             set tid [$c create text [expr {0.5*($x2+$x3)}] $yy1 -anchor c \
    598                 -text "LUMO = $_elumo $units" \
    599                 -fill $itk_option(-leveltextforeground) \
    600                 -tags zlabels]
    601 
    602             foreach {xb0 yb0 xb1 yb1} [$c bbox $tid] break
    603             set tid2 [$c create rectangle \
    604                 [expr {$xb0-1}] [expr {$yb0-1}] \
    605                 [expr {$xb1+1}] [expr {$yb1+1}] \
    606                 -outline $itk_option(-leveltextforeground) \
    607                 -fill $itk_option(-leveltextbackground) \
    608                 -tags zlabels]
    609             $c lower $tid2 $tid
    610 
    611             set id [$c create rectangle $xx2 $yy0 $xx3 $y0 \
    612                 -stipple EnergyLevels-rdiag \
    613                 -outline "" -fill $itk_option(-shadecolor) \
    614                 -tags zlabels]
    615             $c lower $id
     579            set yy0 [expr {($_ehomo-$_eviewmin)*$e2y + $yzoom0}]
     580            set yy1 [expr {($_elumo-$_eviewmin)*$e2y + $yzoom0}]
     581
     582            set textht [font metrics $itk_option(-font) -linespace]
     583            if {$yy0-$yy1 >= 1.5*$textht} {
     584                $c create line [expr {$x3-10}] $yy0 [expr {$x3-10}] $yy1 \
     585                    -arrow both -fill $itk_option(-foreground) \
     586                    -tags zlabels
     587                $c create text [expr {$x3-15}] [expr {0.5*($yy0+$yy1)}] \
     588                    -anchor e -text "Eg = [expr {$_elumo-$_ehomo}] $units" \
     589                    -tags zlabels
     590
     591                # label the HOMO level
     592                set tid [$c create text [expr {0.5*($x2+$x3)}] $yy0 -anchor c \
     593                    -text "$_lhomo = $_ehomo $units" \
     594                    -fill $itk_option(-leveltextforeground) \
     595                    -tags zlabels]
     596
     597                foreach {xb0 yb0 xb1 yb1} [$c bbox $tid] break
     598                set tid2 [$c create rectangle \
     599                    [expr {$xb0-1}] [expr {$yb0-1}] \
     600                    [expr {$xb1+1}] [expr {$yb1+1}] \
     601                    -outline $itk_option(-leveltextforeground) \
     602                    -fill $itk_option(-leveltextbackground) \
     603                    -tags zlabels]
     604                $c lower $tid2 $tid
     605
     606                # label the LUMO level
     607                set tid [$c create text [expr {0.5*($x2+$x3)}] $yy1 -anchor c \
     608                    -text "$_llumo = $_elumo $units" \
     609                    -fill $itk_option(-leveltextforeground) \
     610                    -tags zlabels]
     611
     612                foreach {xb0 yb0 xb1 yb1} [$c bbox $tid] break
     613                set tid2 [$c create rectangle \
     614                    [expr {$xb0-1}] [expr {$yb0-1}] \
     615                    [expr {$xb1+1}] [expr {$yb1+1}] \
     616                    -outline $itk_option(-leveltextforeground) \
     617                    -fill $itk_option(-leveltextbackground) \
     618                    -tags zlabels]
     619                $c lower $tid2 $tid
     620            }
     621
     622            if {$yy0 < $y0} {
     623                set id [$c create rectangle $xx2 $yy0 $xx3 $y0 \
     624                    -stipple EnergyLevels-rdiag \
     625                    -outline "" -fill $itk_option(-shadecolor) \
     626                    -tags zlabels]
     627                $c lower $id
     628            }
    616629        }
    617630    }
     
    653666
    654667            _getLayout
    655             set y2e [expr {($_emax-$_emin)/($y1-$y0)}]
     668            set y2e [expr {($_emax-$_emin)/($yzoom1-$yzoom0)}]
    656669
    657670            if {$x > $x1} {
    658671                return
    659672            }
    660             set midE [expr {($y-$y0)*$y2e + $_emin}]
     673            set midE [expr {($y-$yzoom0)*$y2e + $_emin}]
    661674            set delE [expr {$_eviewmax - $_eviewmin}]
    662675            _view $midE $delE
     
    731744            # touching a line? then find the level and show its info
    732745            if {"" != $id} {
    733                 set e2y [expr {($y1-$y0)/($_eviewmax-$_eviewmin)}]
     746                set e2y [expr {($yzoom1-$yzoom0)/($_eviewmax-$_eviewmin)}]
    734747
    735748                # put the dataobj list in order according to -raise options
     
    750763                    set n 0
    751764                    foreach eval [$dataobj values -column $ecol] {
    752                         set ylevel [expr {($eval-$_eviewmin)*$e2y + $y0}]
     765                        set ylevel [expr {($eval-$_eviewmin)*$e2y + $yzoom0}]
    753766                        if {$y >= $ylevel-3 && $y <= $ylevel+3} {
    754767                            set found 1
     
    787800
    788801            if {$eval == $_ehomo || $eval == $_elumo} {
     802                $itk_component(graph) itemconfigure $dataobj-$level -width 2
     803                set _hilite "$dataobj $level"
    789804                # don't pop up info for the HOMO/LUMO levels
    790805                return
     
    792807
    793808            _getLayout
    794             set e2y [expr {($y1-$y0)/($_eviewmax-$_eviewmin)}]
    795             set y [expr {($eval-$_eviewmin)*$e2y + $y0}]
     809            set e2y [expr {($yzoom1-$yzoom0)/($_eviewmax-$_eviewmin)}]
     810            set y [expr {($eval-$_eviewmin)*$e2y + $yzoom0}]
    796811
    797812            set tid [$c create text [expr {0.5*($x2+$x3)}] $y -anchor c \
     
    847862    # at least a little room for the labels.
    848863    #
    849     set size [font measure $itk_option(-font) "HOMO = X.XXXXXXe-XX eV"]
     864    set size [font measure $itk_option(-font) "$_llumo = X.XXXXXXe-XX eV"]
    850865    set size [expr {$size + 6*$itk_option(-padding)}]
     866
     867    set textht [font metrics $itk_option(-font) -linespace]
     868    set ypad [expr {int(0.5*($textht + 6))}]
    851869
    852870    if {$size > $w-20} {
     
    886904    set y0 [expr {$h - $itk_option(-padding)}]
    887905
     906    upvar yzoom0 yzoom0
     907    set yzoom0 [expr {$y0 - $ypad}]
     908
    888909    upvar y1 y1
    889910    set y1 $itk_option(-padding)
     911
     912    upvar yzoom1 yzoom1
     913    set yzoom1 [expr {$y1 + $ypad}]
    890914}
    891915
  • trunk/gui/scripts/field.tcl

    r115 r136  
    4141    private variable _comp2xy    ;# maps component name => x,y vectors
    4242    private variable _comp2vtk   ;# maps component name => vtkFloatArray
     43    private variable _comp2style ;# maps component name => style settings
    4344    private variable _comp2cntls ;# maps component name => x,y control points
    4445
     
    109110
    110111# ----------------------------------------------------------------------
    111 # USAGE: components ?-name|-dimensions? ?<pattern>?
     112# USAGE: components ?-name|-dimensions|-style? ?<pattern>?
    112113#
    113114# Returns a list of names or types for the various components of
     
    119120        flag what -name default
    120121        flag what -dimensions
     122        flag what -style
    121123    }
    122124
     
    135137            -name { lappend rlist $name }
    136138            -dimensions { lappend rlist $_comp2dims($name) }
     139            -style { lappend rlist $_comp2style($name) }
    137140        }
    138141    }
     
    249252                    }
    250253                    v - vlin - vlog {
    251                         foreach {vmin vmax} [$yv GetRange] break
     254                        catch {unset style}
     255                        array set style $_comp2style($comp)
     256                        if {[info exists style(-min)] && [info exists style(-max)]} {
     257                            # This component has its own hard-coded
     258                            # min/max range.  Ignore it for overall limits.
     259                            set vmin $min
     260                            set vmax $max
     261                        } else {
     262                            foreach {vmin vmax} [$yv GetRange] break
     263                        }
    252264                        set axis vaxis
    253265                    }
     
    381393    catch {unset _comp2vtk}
    382394    catch {unset _comp2dims}
     395    catch {unset _comp2style}
    383396
    384397    #
     
    395408                    && [$_field element $cname.values] != ""} {
    396409            set type "points-on-mesh"
    397         }
     410        } elseif {[$_field element $cname.vtk] != ""} {
     411            set type "vtk"
     412        }
     413
     414        set _comp2style($cname) ""
    398415
    399416        if {$type == "1D"} {
     
    484501                    set _comp2dims($cname) "[$mobj dimensions]D"
    485502                    set _comp2vtk($cname) [list $mobj $farray]
     503                    set _comp2style($cname) [$_field get $cname.style]
    486504                    incr _counter
    487505                } else {
     
    521539                puts "WARNING: can't find mesh $path for field component"
    522540            }
     541        } elseif {$type == "vtk"} {
     542            #
     543            # Extract native vtk data from the XML and use a reader
     544            # to load it.
     545            #
     546            vtkRectilinearGridReader $this-gr
     547            $this-gr SetInputString [$_field get $cname.vtk]
     548
     549
     550            set _comp2dims($cname) "[$mobj dimensions]D"
     551            set _comp2vtk($cname) [list $mobj $farray]
     552            set _comp2style($cname) [$_field get $cname.style]
     553            incr _counter
    523554        }
    524555    }
  • trunk/gui/scripts/mesh.tcl

    r115 r136  
    3434    public proc release {obj}
    3535
     36    private method _buildNodesElements {xmlobj path}
     37    private method _buildRectMesh {xmlobj path}
    3638    private method _getVtkElement {npts}
    3739
     
    4244    private variable _units "m m m" ;# system of units for x, y, z
    4345    private variable _limits        ;# limits xmin, xmax, ymin, ymax, ...
     46    private variable _pdata ""      ;# name of vtkPointData object
     47    private variable _gdata ""      ;# name of vtkDataSet object
    4448
    4549    private common _xp2obj       ;# used for fetch/release ref counting
     
    112116    }
    113117
    114     # create the vtk objects containing points and connectivity
    115     vtkPoints $this-points
    116     vtkUnstructuredGrid $this-grid
    117 
    118118    foreach lim {xmin xmax ymin ymax zmin zmax} {
    119119        set _limits($lim) ""
    120120    }
    121121
    122     #
    123     # Extract each node and add it to the points list.
    124     #
    125     foreach comp [$xmlobj children -type node $path] {
    126         set xyz [$xmlobj get $path.$comp]
    127 
    128         # make sure we have x,y,z
    129         while {[llength $xyz] < 3} {
    130             lappend xyz "0"
    131         }
    132 
    133         # extract each point and add it to the points list
    134         foreach {x y z} $xyz break
    135         foreach dim {x y z} units $_units {
    136             set v [Rappture::Units::convert [set $dim] \
    137                 -context $units -to $units -units off]
    138 
    139             set $dim $v  ;# save back to real x/y/z variable
    140 
    141             if {"" == $_limits(${dim}min)} {
    142                 set _limits(${dim}min) $v
    143                 set _limits(${dim}max) $v
    144             } else {
    145                 if {$v < $_limits(${dim}min)} { set _limits(${dim}min) $v }
    146                 if {$v > $_limits(${dim}max)} { set _limits(${dim}max) $v }
    147             }
    148         }
    149         $this-points InsertNextPoint $x $y $z
    150     }
    151     $this-grid SetPoints $this-points
    152 
    153     #
    154     # Extract each element and add it to the mesh.
    155     #
    156     foreach comp [$xmlobj children -type element $path] {
    157         set nlist [$_mesh get $comp.nodes]
    158         set elem [_getVtkElement [llength $nlist]]
    159 
    160         set i 0
    161         foreach n $nlist {
    162             [$elem GetPointIds] SetId $i $n
    163             incr i
    164         }
    165         $this-grid InsertNextCell [$elem GetCellType] [$elem GetPointIds]
     122    if {[$_mesh element vtk] != ""} {
     123        _buildRectMesh $xmlobj $path
     124    } elseif {[$_mesh element node] != "" && [$_mesh element element] != ""} {
     125        _buildNodesElements $xmlobj $path
     126    } else {
     127        error "can't find mesh data in $path"
    166128    }
    167129}
     
    174136    itcl::delete object $_mesh
    175137
    176     rename $this-points ""
    177     rename $this-grid ""
     138    catch {rename $this-points ""}
     139    catch {rename $this-grid ""}
     140    catch {rename $this-dset ""}
    178141
    179142    foreach type [array names _pts2elem] {
     
    188151# ----------------------------------------------------------------------
    189152itcl::body Rappture::Mesh::points {} {
    190     # not implemented
    191     return $this-points
     153    return $_pdata
    192154}
    193155
     
    239201# ----------------------------------------------------------------------
    240202itcl::body Rappture::Mesh::mesh {} {
    241     return $this-grid
     203    return $_gdata
    242204}
    243205
     
    250212    switch -- $what {
    251213        -points {
    252             return [$this-points GetNumberOfPoints]
     214            return [$_pdata GetNumberOfPoints]
    253215        }
    254216        -elements {
    255             return [$this-points GetNumberOfCells]
     217            return [$_gdata GetNumberOfCells]
    256218        }
    257219        default {
     
    314276
    315277# ----------------------------------------------------------------------
     278# USAGE: _buildNodesElements <xmlobj> <path>
     279#
     280# Used internally to build a mesh representation based on nodes and
     281# elements stored in the XML.
     282# ----------------------------------------------------------------------
     283itcl::body Rappture::Mesh::_buildNodesElements {xmlobj path} {
     284    # create the vtk objects containing points and connectivity
     285    vtkPoints $this-points
     286    set _pdata $this-points
     287    vtkUnstructuredGrid $this-grid
     288    set _gdata $this-grid
     289
     290    #
     291    # Extract each node and add it to the points list.
     292    #
     293    foreach comp [$xmlobj children -type node $path] {
     294        set xyz [$xmlobj get $path.$comp]
     295
     296        # make sure we have x,y,z
     297        while {[llength $xyz] < 3} {
     298            lappend xyz "0"
     299        }
     300
     301        # extract each point and add it to the points list
     302        foreach {x y z} $xyz break
     303        foreach dim {x y z} units $_units {
     304            set v [Rappture::Units::convert [set $dim] \
     305                -context $units -to $units -units off]
     306
     307            set $dim $v  ;# save back to real x/y/z variable
     308
     309            if {"" == $_limits(${dim}min)} {
     310                set _limits(${dim}min) $v
     311                set _limits(${dim}max) $v
     312            } else {
     313                if {$v < $_limits(${dim}min)} { set _limits(${dim}min) $v }
     314                if {$v > $_limits(${dim}max)} { set _limits(${dim}max) $v }
     315            }
     316        }
     317        $this-points InsertNextPoint $x $y $z
     318    }
     319    $this-grid SetPoints $this-points
     320
     321    #
     322    # Extract each element and add it to the mesh.
     323    #
     324    foreach comp [$xmlobj children -type element $path] {
     325        set nlist [$_mesh get $comp.nodes]
     326        set elem [_getVtkElement [llength $nlist]]
     327
     328        set i 0
     329        foreach n $nlist {
     330            [$elem GetPointIds] SetId $i $n
     331            incr i
     332        }
     333        $this-grid InsertNextCell [$elem GetCellType] [$elem GetPointIds]
     334    }
     335}
     336
     337# ----------------------------------------------------------------------
     338# USAGE: _buildRectMesh <xmlobj> <path>
     339#
     340# Used internally to build a mesh representation based on a native
     341# VTK file for a rectangular mesh.
     342# ----------------------------------------------------------------------
     343itcl::body Rappture::Mesh::_buildRectMesh {xmlobj path} {
     344    vtkRectilinearGridReader $this-gr
     345    $this-gr ReadFromInputStringOn
     346    $this-gr SetInputString [$xmlobj get $path.vtk]
     347
     348    set _gdata [$this-gr GetOutput]
     349    set _pdata [$_gdata GetPointData]
     350
     351    $_gdata Update
     352    foreach name {xmin xmax ymin ymax zmin zmax} val [$_gdata GetBounds] {
     353        set _limits($name) $val
     354    }
     355}
     356
     357# ----------------------------------------------------------------------
    316358# USAGE: _getVtkElement <npts>
    317359#
  • trunk/gui/scripts/resultviewer.tcl

    r126 r136  
    207207        }
    208208        ::Rappture::Field {
    209             switch -- [$dataobj components -dimensions] {
     209            set dims [lindex [lsort [$dataobj components -dimensions]] end]
     210            switch -- $dims {
    210211                1D {
    211212                    set mode "xy"
Note: See TracChangeset for help on using the changeset viewer.