Changeset 2148 for trunk


Ignore:
Timestamp:
Mar 24, 2011, 6:03:15 PM (13 years ago)
Author:
gah
Message:
 
Location:
trunk/gui/scripts
Files:
3 edited

Legend:

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

    r2088 r2148  
    9393        label   about.label
    9494        color   about.color
     95        camera  about.camera
    9596        type    about.type
    9697        xlabel  xaxis.label
  • trunk/gui/scripts/vtkcontourviewer.tcl

    r2144 r2148  
    371371    }
    372372    SendCmd "screen size $_width $_height"
    373     SendCmd "camera reset all"
    374373    if { $_settings($this-legend) } {
    375374        EventuallyResizeLegend
  • trunk/gui/scripts/vtkviewer.tcl

    r2097 r2148  
    4141    private variable _obj2width    ;# maps dataobj => line width
    4242    private variable _obj2raise    ;# maps dataobj => raise flag 0/1
    43     private variable _obj2vtk      ;# maps dataobj => vtk objects
    44     private variable _actors ""    ;# list of actors for each renderer
     43    private variable _dataobj2vtk  ;# maps dataobj => vtk objects
     44    private variable _actors       ;# array of actors for each dataobj.
    4545    private variable _lights       ;# list of lights for each renderer
    4646    private variable _click        ;# info used for _move operations
     
    8686    private method GetLimits {}
    8787    private method BuildCameraTab {}
     88    private method UpdateCameraInfo {}
    8889    private method BuildViewTab {}
    8990    private method BuildVolumeTab {}
     
    103104    option add hull.width hull.height
    104105    pack propagate $itk_component(hull) no
    105 
    106106    set _view(theta) 0
    107107    set _view(phi) 0
    108 
     108   
    109109    array set _limits {
    110110        xMin    0
     
    117117        vMax    1
    118118    }
     119
     120
    119121    foreach { key value } {
    120122        edges           1
     
    125127        set _settings($this-$key) $value
    126128    }
    127 
    128129    itk_component add main {
    129130        Rappture::SidebarFrame $itk_interior.main
     
    131132    pack $itk_component(main) -expand yes -fill both
    132133    set f [$itk_component(main) component frame]
    133 
     134   
    134135    itk_component add controls {
    135136        frame $f.cntls
     
    147148    }
    148149    pack $itk_component(zoom) -side top
    149 
     150   
    150151    itk_component add reset {
    151152        button $itk_component(zoom).reset \
     
    159160    }
    160161    pack $itk_component(reset) -padx 4 -pady 4
    161     Rappture::Tooltip::for $itk_component(reset) "Reset the view to the default zoom level"
     162    Rappture::Tooltip::for $itk_component(reset) \
     163        "Reset the view to the default zoom level"
    162164
    163165    itk_component add zoomin {
     
    169171        usual
    170172        ignore -borderwidth
    171         rename -highlightbackground -controlbackground controlBackground Background
     173        rename -highlightbackground -controlbackground controlBackground \
     174            Background
    172175    }
    173176    pack $itk_component(zoomin) -padx 4 -pady 4
    174177    Rappture::Tooltip::for $itk_component(zoomin) "Zoom in"
    175 
     178   
    176179    itk_component add zoomout {
    177180        button $itk_component(zoom).zout \
     
    182185        usual
    183186        ignore -borderwidth
    184         rename -highlightbackground -controlbackground controlBackground Background
     187        rename -highlightbackground -controlbackground controlBackground \
     188            Background
    185189    }
    186190    pack $itk_component(zoomout) -padx 4 -pady 4
    187191    Rappture::Tooltip::for $itk_component(zoomout) "Zoom out"
    188 
     192   
    189193    #
    190194    # RENDERING AREA
     
    194198    }
    195199    pack $itk_component(area) -expand yes -fill both
    196 
     200   
    197201    set _renderer [vtkRenderer $this-Renderer]
    198202    set _window [vtkRenderWindow $this-RenderWindow]
     
    201205            -width 1 -height 1
    202206    } {
     207        # empty
    203208    }
    204209    pack $itk_component(plot) -expand yes -fill both
     
    206211    $_window LineSmoothingOn
    207212    $_window PolygonSmoothingOn
    208 
     213   
    209214    set _interactor [vtkRenderWindowInteractor $this-Interactor]
    210215    set _style [vtkInteractorStyleTrackballCamera $this-InteractorStyle]
     
    212217    $_interactor SetInteractorStyle $_style
    213218    $_interactor Initialize
    214 
     219   
    215220    set _cubeAxesActor [vtkCubeAxesActor $this-CubeAxesActor]
    216221    $_cubeAxesActor SetCamera [$_renderer GetActiveCamera]
    217222    $_renderer AddActor $_cubeAxesActor
    218 
     223   
    219224    # Supply small axes guide.
    220225    set _axesActor [vtkAxesActor $this-AxesActor]
     
    225230    $_axesWidget SetInteractive 0
    226231    $_axesWidget SetViewport .7 0 1.0 0.3
    227 
     232   
    228233    BuildViewTab
    229     if 0 {
    230     BuildVolumeTab
    231234    BuildCameraTab
    232     }
     235   
    233236    set v0 0
    234237    set v1 1
     
    237240    $_lookup SetHueRange 0.66667 0.0
    238241    $_lookup Build
    239 
     242   
    240243    set lightKit [vtkLightKit $this-LightKit]
    241244    $lightKit AddLightsToRenderer $_renderer
    242 
     245   
    243246    #
    244247    # Create a picture for download snapshots
    245248    #
    246249    set _download [image create photo]
    247 
     250   
    248251    eval itk_initialize $args
    249252}
     
    255258    Clear
    256259    after cancel [itcl::code $this Rebuild]
    257 
     260   
    258261    foreach c [info commands $this-vtk*] {
    259262        rename $c ""
     
    289292        set params(-color) black
    290293    }
    291 
    292294    set pos [lsearch -exact $dataobj $_dlist]
    293295    if {$pos < 0} {
    294296        lappend _dlist $dataobj
     297
    295298        set _obj2color($dataobj) $params(-color)
    296299        set _obj2width($dataobj) $params(-width)
    297300        set _obj2raise($dataobj) $params(-raise)
    298 
     301       
    299302        after cancel [itcl::code $this Rebuild]
    300303        after idle [itcl::code $this Rebuild]
     
    337340    set changed 0
    338341    foreach dataobj $args {
    339         set pos [lsearch -exact $_dlist $dataobj]
    340         if {$pos >= 0} {
    341             set _dlist [lreplace $_dlist $pos $pos]
     342        set i [lsearch -exact $_dlist $dataobj]
     343        if {$i >= 0} {
     344            set _dlist [lreplace $_dlist $i $i]
    342345            catch {unset _obj2color($dataobj)}
    343346            catch {unset _obj2width($dataobj)}
    344347            catch {unset _obj2raise($dataobj)}
     348            foreach actor $_actors($dataobj) {
     349                $_renderer RemoveActor $actor
     350            }
     351            array unset _actors $dataobj
     352            array unset _dataobj2vtk $dataobj-*
    345353            set changed 1
    346354        }
     
    425433itcl::body Rappture::VtkViewer::Clear {} {
    426434    # clear out any old constructs
    427     foreach actor $_actors {
    428         $_renderer RemoveActor $actor
    429     }
    430     set _actors ""
     435   
    431436    foreach ren [array names _lights] {
    432437        foreach light $_lights($ren) {
     
    436441        set _lights($ren) ""
    437442    }
    438     foreach dataobj [array names _obj2vtk] {
    439         set actor [$data values]
    440         set data [$data values]
    441         foreach cmd $_obj2vtk($dataobj) {
    442             rename $cmd ""
    443         }
    444         set _obj2vtk($dataobj) ""
    445     }
     443    foreach dataobj $_dlist {
     444        foreach actor $_actors($dataobj) {
     445            $_renderer RemoveActor $actor
     446        }
     447    }
     448    array unset _actors
     449    set _dlist ""
     450    array unset _dataobj2vtk
    446451}
    447452
     
    455460# ----------------------------------------------------------------------
    456461itcl::body Rappture::VtkViewer::Zoom {option} {
    457     set camera [$_renderer GetActiveCamera]
     462    set cam [$_renderer GetActiveCamera]
    458463    switch -- $option {
    459464        in {
    460             $camera Zoom 1.25
     465            $cam Zoom 1.25
    461466            $_window Render
    462467        }
    463468        out {
    464             $camera Zoom 0.8
     469            $cam Zoom 0.8
    465470            $_window Render
    466471        }
    467472        reset {
    468             $camera SetViewAngle 30
     473            $cam SetViewAngle 30
    469474            $_renderer ResetCamera
    470475            _3dView 90 -90
     476            array set camera {
     477                xpos 1.73477e-06 ypos 74.7518 zpos -1.73477e-06
     478                xviewup 5.38569e-16 yviewup 2.32071e-08 zviewup 1.0
     479                xfocal 0.0 yfocal 0.0 zfocal 0.0
     480            }
     481            set dataobj [lindex $_dlist end]
     482            if { $dataobj != "" } {
     483                array set camera [$dataobj hints camera]
     484            }
     485            $cam SetFocalPoint $camera(xfocal) $camera(yfocal) $camera(zfocal)
     486            $cam SetPosition $camera(xpos) $camera(ypos) $camera(zpos)
     487            $cam SetViewUp $camera(xviewup) $camera(yviewup) $camera(zviewup)
     488            foreach key [array names camera] {
     489                set _settings($this-$key) $camera($key)
     490            }
    471491            $_window Render
    472492        }
     
    506526                    # Shift the contour plot in 2D
    507527                    #
    508                     foreach actor $_actors {
    509                         foreach {ax ay az} [$actor GetPosition] break
    510                         $actor SetPosition [expr {$ax+$dx}] [expr {$ay-$dy}] 0
    511                     }
     528                    foreach dataobj $_dlist {
     529                        foreach actor $_actors($dataobj) {
     530                            foreach {ax ay az} [$actor GetPosition] break
     531                            $actor SetPosition [expr {$ax+$dx}] \
     532                                [expr {$ay-$dy}] 0
     533                        }
     534                    }
    512535                    $_window Render
    513536                } elseif {$_dims == "3D"} {
     
    519542                    if {$theta > 178} { set theta 178 }
    520543                    set phi [expr {$_view(phi) - $dx*360}]
    521 
     544                   
    522545                    _3dView $theta $phi
    523546                    $_window Render
     
    536559        }
    537560    }
     561    UpdateCameraInfo
    538562}
    539563
     
    552576    set yn [expr {sin($theta*$deg2rad)*sin($phi*$deg2rad)}]
    553577    set zn [expr {cos($theta*$deg2rad)}]
    554 
     578   
    555579    set xm [expr {0.5*($_limits(xMax)+$_limits(xMin))}]
    556580    set ym [expr {0.5*($_limits(yMax)+$_limits(yMin))}]
    557581    set zm [expr {0.5*($_limits(zMax)+$_limits(zMin))}]
    558 
     582   
    559583    set cam [$_renderer GetActiveCamera]
    560584    set zoom [$cam GetViewAngle]
    561585    $cam SetViewAngle 30
    562 
    563586    $cam SetFocalPoint $xm $ym $zm
    564587    $cam SetPosition [expr {$xm-$xn}] [expr {$ym-$yn}] [expr {$zm+$zn}]
     
    568591    $_renderer ResetCamera
    569592    $cam SetViewAngle $zoom
    570 
     593   
    571594    set _view(theta) $theta
    572595    set _view(phi) $phi
     
    585608    $_window Render
    586609    if 0 {
    587     $this-vtkRenderWindow2 Render
     610        $this-vtkRenderWindow2 Render
    588611    }
    589612}
     
    611634    $_window Render
    612635    if 0 {
    613     $this-vtkRenderer2 SetBackground $r $g $b
    614     $this-vtkRenderWindow2 Render
     636        $this-vtkRenderer2 SetBackground $r $g $b
     637        $this-vtkRenderWindow2 Render
    615638    }
    616639}
     
    656679# ----------------------------------------------------------------------
    657680itcl::body Rappture::VtkViewer::Rebuild {} {
    658     Clear
    659681    set id 0
    660 
     682   
    661683    # determine the dimensionality from the topmost (raised) object
    662684    set dlist [get]
     
    670692    $_cubeAxesActor SetCamera [$_renderer GetActiveCamera]
    671693    eval $_cubeAxesActor SetBounds [GetLimits]
    672 
    673     #
    674     # LOOKUP TABLE FOR COLOR CONTOURS
    675     #
    676     # Use vmin/vmax if possible, otherwise get from data
    677     if {$_limits(vMin) == "" || $_limits(vMax) == ""} {
    678         set v0 0
    679         set v1 1
    680         if {[info exists _obj2vtk($dataobj)]} {
    681             set pd [lindex $_obj2vtk($dataobj) 0]
    682             if {"" != $pd} {
    683                 foreach {v0 v1} [$pd GetScalarRange] break
    684             }
    685         }
    686     } else {
    687         set v0 $_limits(vMin)
    688         set v1 $_limits(vMax)
    689     }
    690 
    691     if 0 {
    692         set lu $this-vtkLookup
    693         vtkLookupTable $lu
    694         $lu SetTableRange $v0 $v1
    695         $lu SetHueRange 0.66667 0.0
    696         $lu Build
    697        
    698         lappend _obj2vtk($dataobj) $lu
    699        
    700         #
    701         # 3D LIGHTS (on both sides of all three axes)
    702         #
    703         set x0 $_limits(xMin)
    704         set x1 $_limits(xMax)
    705         set xm [expr {0.5*($x0+$x1)}]
    706         set y0 $_limits(yMin)
    707         set y1 $_limits(yMax)
    708         set ym [expr {0.5*($y0+$y1)}]
    709         set z0 $_limits(zMin)
    710         set z1 $_limits(zMax)
    711         set zm [expr {0.5*($z0+$z1)}]
    712         set xr [expr {$x1-$x0}]
    713         set yr [expr {$y1-$y0}]
    714         set zr [expr {$z1-$z0}]
    715 
    716         set light [vtkLight $this-vtkLight]
    717         $light SetColor 1 1 1
    718         $light SetAttenuationValues 0 0 0
    719         $light SetFocalPoint $xm $ym $zm
    720         $light SetLightTypeToHeadlight
    721         $_renderer AddLight $light
    722         lappend _lights($_renderer) $light
    723     }
     694   
     695    if 1 {
     696        #
     697        # LOOKUP TABLE FOR COLOR CONTOURS
     698        #
     699        # Use vmin/vmax if possible, otherwise get from data
     700        if {$_limits(vMin) == "" || $_limits(vMax) == ""} {
     701            set v0 0
     702            set v1 1
     703            if { [info exists _dataobj2vtk($dataobj)] } {
     704                set pd [lindex $_dataobj2vtk($dataobj) 0]
     705                if {"" != $pd} {
     706                    foreach {v0 v1} [$pd GetScalarRange] break
     707                }
     708            }
     709        } else {
     710            set v0 $_limits(vMin)
     711            set v1 $_limits(vMax)
     712        }
     713    }   
    724714    # scan through all data objects and build the contours
    725715    set firstobj 1
    726     foreach dataobj [get] {
    727         foreach comp [$dataobj components] {
    728             set actor [$dataobj values $comp]
    729             set style [$dataobj style $comp]
    730 
    731             lappend _actors $actor
    732             $_renderer AddActor $actor
    733             SetActorProperties $actor $style
    734             incr id
    735         }
    736         set firstobj 0
     716    foreach dataobj $_dlist {
     717        foreach comp [$dataobj components] {
     718            set tag $dataobj-$comp
     719            if { ![info exists _dataobj2vtk($tag)] } {
     720                set actor [$dataobj values $comp]
     721                set style [$dataobj style $comp]
     722                set _dataobj2vtk($tag) $actor
     723                lappend _actors($dataobj) $actor
     724                $_renderer AddActor $actor
     725                SetActorProperties $actor $style
     726                incr id
     727            }
     728        }
     729        set firstobj 0
    737730    }
    738731    set top [lindex [get] end]
     
    749742        }
    750743    }
    751     _fixLimits
    752     Zoom reset
     744    if 1 {
     745        _fixLimits
     746        Zoom reset
     747
     748    }
    753749    $_interactor Start
    754750    $_window Render
    755 
     751    return
    756752
    757753    #
     
    765761        [$_renderer GetActiveCamera] Zoom 1.5
    766762    }
    767 
    768763    # prevent interactions -- use our own
    769764    blt::busy hold $itk_component(area) -cursor left_ptr
     
    907902}
    908903
     904itcl::body Rappture::VtkViewer::UpdateCameraInfo {} {
     905    set cam [$_renderer GetActiveCamera]
     906    foreach key { x y z } \
     907            pt  [$cam GetFocalPoint] \
     908            up  [$cam GetViewUp] \
     909            pos [$cam GetPosition] {
     910        set _settings($this-${key}focal) $pt
     911        set _settings($this-${key}up) $up
     912        set _settings($this-${key}pos) $pos
     913    }
     914}
     915
     916itcl::body Rappture::VtkViewer::BuildCameraTab {} {
     917    set inner [$itk_component(main) insert end \
     918        -title "Camera Settings" \
     919        -icon [Rappture::icon camera]]
     920    $inner configure -borderwidth 4
     921    bind $inner <Map> [itcl::code $this UpdateCameraInfo]
     922
     923    label $inner.xposl -text "Position"
     924    entry $inner.xpos -bg white \
     925        -textvariable [itcl::scope _settings($this-xpos)]
     926    entry $inner.ypos -bg white \
     927        -textvariable [itcl::scope _settings($this-ypos)]
     928    entry $inner.zpos -bg white \
     929        -textvariable [itcl::scope _settings($this-zpos)]
     930    label $inner.xviewupl -text "View Up"
     931    entry $inner.xviewup -bg white \
     932        -textvariable [itcl::scope _settings($this-xviewup)]
     933    entry $inner.yviewup -bg white \
     934        -textvariable [itcl::scope _settings($this-yviewup)]
     935    entry $inner.zviewup -bg white \
     936        -textvariable [itcl::scope _settings($this-zviewup)]
     937    label $inner.xfocall -text "Focal Point"
     938    entry $inner.xfocal -bg white \
     939        -textvariable [itcl::scope _settings($this-xfocal)]
     940    entry $inner.yfocal -bg white \
     941        -textvariable [itcl::scope _settings($this-yfocal)]
     942    entry $inner.zfocal -bg white \
     943        -textvariable [itcl::scope _settings($this-zfocal)]
     944
     945    button $inner.refresh -text "Refresh" \
     946        -command [itcl::code $this UpdateCameraInfo]
     947    blt::table $inner \
     948        0,0 $inner.xposl -anchor w -pady 2 \
     949        1,0 $inner.xpos -pady 2 -fill x\
     950        2,0 $inner.ypos -pady 2 -fill x\
     951        3,0 $inner.zpos -pady 2 -fill x\
     952        4,0 $inner.xviewupl -anchor w -pady 2 \
     953        5,0 $inner.xviewup -pady 2 -fill x \
     954        6,0 $inner.yviewup -pady 2 -fill x \
     955        7,0 $inner.zviewup -pady 2 -fill x \
     956        8,0 $inner.xfocall -anchor w -pady 2 \
     957        9,0 $inner.xfocal -pady 2 -fill x \
     958        10,0 $inner.yfocal -pady 2 -fill x \
     959        11,0 $inner.zfocal -pady 2 -fill x \
     960        12,0 $inner.refresh
     961
     962    blt::table configure $inner r* c* -resize none
     963    blt::table configure $inner c0 -resize expand
     964    blt::table configure $inner r13 -resize expand
     965}
    909966
    910967# ----------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.