source: trunk/gui/scripts/vtkviewer-obsolete.tcl @ 3021

Last change on this file since 3021 was 2792, checked in by gah, 12 years ago

move "package require vtk" into constructor so that applications do not have to load vtk to use Rappture widgets

File size: 38.4 KB
Line 
1
2# ----------------------------------------------------------------------
3#  COMPONENT: vtkviewerobsolete - contour plot in a ResultSet
4#
5#  This widget is a contour plot for 2D meshes with a scalar value.
6#  It is normally used in the ResultViewer to show results from the
7#  run of a Rappture tool.  Use the "add" and "delete" methods to
8#  control the dataobjs showing on the plot.
9# ======================================================================
10#  AUTHOR:  Michael McLennan, Purdue University
11#  Copyright (c) 2004-2005  Purdue Research Foundation
12#
13#  See the file "license.terms" for information on usage and
14#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15# ======================================================================
16package require Itk
17package require BLT
18#package require Img
19
20option add *VtkViewerObsolete.width 4i widgetDefault
21option add *VtkViewerObsolete.height 4i widgetDefault
22option add *VtkViewerObsolete.foreground black widgetDefault
23option add *VtkViewerObsolete.controlBackground gray widgetDefault
24option add *VtkViewerObsolete.controlDarkBackground #999999 widgetDefault
25option add *VtkViewerObsolete.plotBackground black widgetDefault
26option add *VtkViewerObsolete.plotForeground white widgetDefault
27option add *VtkViewerObsolete.font \
28    -*-helvetica-medium-r-normal-*-12-* widgetDefault
29
30itcl::class Rappture::VtkViewerObsolete {
31    inherit itk::Widget
32
33    itk_option define -plotforeground plotForeground Foreground ""
34    itk_option define -plotbackground plotBackground Background ""
35
36    private variable _dlist ""     ;# list of data objects
37    private variable _dims ""      ;# dimensionality of data objects
38    private variable _obj2color    ;# maps dataobj => plotting color
39    private variable _obj2width    ;# maps dataobj => line width
40    private variable _obj2raise    ;# maps dataobj => raise flag 0/1
41    private variable _dataobj2vtk  ;# maps dataobj => vtk objects
42    private variable _actors       ;# array of actors for each dataobj.
43    private variable _lights       ;# list of lights for each renderer
44    private variable _click        ;# info used for _move operations
45    private variable _limits       ;# autoscale min/max for all axes
46    private variable _view         ;# view params for 3D view
47    private variable _download ""  ;# snapshot for download
48
49    private variable _renderer "";
50    private variable _window "";
51    private variable _interactor "";
52    private variable _style "";
53    private variable _light "";
54    private variable _cubeAxesActor ""
55    private variable _axesActor ""
56    private variable _axesWidget "";
57    private variable _settings
58    constructor {args} {
59        # defined below
60    }
61    destructor {
62        # defined below
63    }
64
65    public method add {dataobj {settings ""}}
66    public method get {}
67    public method delete {args}
68    public method scale {args}
69    public method parameters {title args} {
70        # do nothing
71    }
72    public method download {option args}
73
74    protected method Rebuild {}
75    protected method Clear {}
76    protected method Zoom {option}
77    protected method Move {option x y}
78    protected method _3dView {theta phi}
79    protected method _fixLimits {}
80    protected method _color2rgb {color}
81    protected method SetActorProperties { actor style }
82
83    private method ComputeLimits { args }
84    private method GetLimits {}
85    private method BuildCameraTab {}
86    private method UpdateCameraInfo {}
87    private method BuildViewTab {}
88    private method BuildVolumeTab {}
89    protected method FixSettings {what {value ""}}
90
91}
92
93itk::usual VtkViewerObsolete {
94    keep -background -foreground -cursor -font
95    keep -plotbackground -plotforeground
96}
97
98# ----------------------------------------------------------------------
99# CONSTRUCTOR
100# ----------------------------------------------------------------------
101itcl::body Rappture::VtkViewerObsolete::constructor {args} {
102    package require vtk
103    package require vtkinteraction
104    option add hull.width hull.height
105    pack propagate $itk_component(hull) no
106    set _view(theta) 0
107    set _view(phi) 0
108   
109    array set _limits {
110        xMin    0
111        xMax    1
112        yMin    0
113        yMax    1
114        zMin    0
115        zMax    1
116        vMin    0
117        vMax    1
118    }
119
120
121    foreach { key value } {
122        edges           1
123        axes            1
124        smallaxes       0
125        wireframe       0
126    } {
127        set _settings($this-$key) $value
128    }
129    itk_component add main {
130        Rappture::SidebarFrame $itk_interior.main
131    }
132    pack $itk_component(main) -expand yes -fill both
133    set f [$itk_component(main) component frame]
134   
135    itk_component add controls {
136        frame $f.cntls
137    } {
138        usual
139        rename -background -controlbackground controlBackground Background
140    }
141    pack $itk_component(controls) -side right -fill y
142
143    itk_component add zoom {
144        frame $itk_component(controls).zoom
145    } {
146        usual
147        rename -background -controlbackground controlBackground Background
148    }
149    pack $itk_component(zoom) -side top
150   
151    itk_component add reset {
152        button $itk_component(zoom).reset \
153            -borderwidth 1 -padx 1 -pady 1 \
154            -bitmap [Rappture::icon reset] \
155            -command [itcl::code $this Zoom reset]
156    } {
157        usual
158        ignore -borderwidth
159        rename -highlightbackground -controlbackground controlBackground Background
160    }
161    pack $itk_component(reset) -padx 4 -pady 4
162    Rappture::Tooltip::for $itk_component(reset) \
163        "Reset the view to the default zoom level"
164
165    itk_component add zoomin {
166        button $itk_component(zoom).zin \
167            -borderwidth 1 -padx 1 -pady 1 \
168            -bitmap [Rappture::icon zoomin] \
169            -command [itcl::code $this Zoom in]
170    } {
171        usual
172        ignore -borderwidth
173        rename -highlightbackground -controlbackground controlBackground \
174            Background
175    }
176    pack $itk_component(zoomin) -padx 4 -pady 4
177    Rappture::Tooltip::for $itk_component(zoomin) "Zoom in"
178   
179    itk_component add zoomout {
180        button $itk_component(zoom).zout \
181            -borderwidth 1 -padx 1 -pady 1 \
182            -bitmap [Rappture::icon zoomout] \
183            -command [itcl::code $this Zoom out]
184    } {
185        usual
186        ignore -borderwidth
187        rename -highlightbackground -controlbackground controlBackground \
188            Background
189    }
190    pack $itk_component(zoomout) -padx 4 -pady 4
191    Rappture::Tooltip::for $itk_component(zoomout) "Zoom out"
192   
193    #
194    # RENDERING AREA
195    #
196    itk_component add area {
197        frame $f.area
198    }
199    pack $itk_component(area) -expand yes -fill both
200   
201    set _renderer [vtkRenderer $this-Renderer]
202    set _window [vtkRenderWindow $this-RenderWindow]
203    itk_component add plot {
204        vtkTkRenderWidget $itk_component(area).plot -rw $_window \
205            -width 1 -height 1
206    } {
207        # empty
208    }
209    pack $itk_component(plot) -expand yes -fill both
210    $_window AddRenderer $_renderer
211    $_window LineSmoothingOn
212    $_window PolygonSmoothingOn
213   
214    set _interactor [vtkRenderWindowInteractor $this-Interactor]
215    set _style [vtkInteractorStyleTrackballCamera $this-InteractorStyle]
216    $_interactor SetRenderWindow $_window
217    $_interactor SetInteractorStyle $_style
218    $_interactor Initialize
219   
220    set _cubeAxesActor [vtkCubeAxesActor $this-CubeAxesActor]
221    $_cubeAxesActor SetCamera [$_renderer GetActiveCamera]
222    $_renderer AddActor $_cubeAxesActor
223   
224    # Supply small axes guide.
225    set _axesActor [vtkAxesActor $this-AxesActor]
226    set _axesWidget [vtkOrientationMarkerWidget $this-AxesWidget]
227    $_axesWidget SetOrientationMarker $_axesActor
228    $_axesWidget SetInteractor $_interactor
229    $_axesWidget SetEnabled $_settings($this-smallaxes)
230    $_axesWidget SetInteractive 0
231    $_axesWidget SetViewport .7 0 1.0 0.3
232   
233    BuildViewTab
234    BuildCameraTab
235   
236    set v0 0
237    set v1 1
238    set _lookup [vtkLookupTable $this-Lookup]
239    $_lookup SetTableRange $v0 $v1
240    $_lookup SetHueRange 0.66667 0.0
241    $_lookup Build
242   
243    set lightKit [vtkLightKit $this-LightKit]
244    $lightKit AddLightsToRenderer $_renderer
245   
246    #
247    # Create a picture for download snapshots
248    #
249    set _download [image create photo]
250   
251    eval itk_initialize $args
252}
253
254# ----------------------------------------------------------------------
255# DESTRUCTOR
256# ----------------------------------------------------------------------
257itcl::body Rappture::VtkViewerObsolete::destructor {} {
258    Clear
259    after cancel [itcl::code $this Rebuild]
260   
261    foreach c [info commands $this-vtk*] {
262        rename $c ""
263    }
264    image delete $_download
265}
266
267# ----------------------------------------------------------------------
268# USAGE: add <dataobj> ?<settings>?
269#
270# Clients use this to add a data object to the plot.  The optional
271# <settings> are used to configure the plot.  Allowed settings are
272# -color, -brightness, -width, -linestyle, and -raise.
273# ----------------------------------------------------------------------
274itcl::body Rappture::VtkViewerObsolete::add {dataobj {settings ""}} {
275    array set params {
276        -color auto
277        -width 1
278        -linestyle solid
279        -brightness 0
280        -raise 0
281        -description ""
282        -param ""
283    }
284    foreach {opt val} $settings {
285        if {![info exists params($opt)]} {
286            error "bad setting \"$opt\": should be [join [lsort [array names params]] {, }]"
287        }
288        set params($opt) $val
289    }
290    if {$params(-color) == "auto" || $params(-color) == "autoreset"} {
291        # can't handle -autocolors yet
292        set params(-color) black
293    }
294    set pos [lsearch -exact $dataobj $_dlist]
295    if {$pos < 0} {
296        lappend _dlist $dataobj
297
298        set _obj2color($dataobj) $params(-color)
299        set _obj2width($dataobj) $params(-width)
300        set _obj2raise($dataobj) $params(-raise)
301       
302        after cancel [itcl::code $this Rebuild]
303        after idle [itcl::code $this Rebuild]
304    }
305}
306
307# ----------------------------------------------------------------------
308# USAGE: get
309#
310# Clients use this to query the list of objects being plotted, in
311# order from bottom to top of this result.
312# ----------------------------------------------------------------------
313itcl::body Rappture::VtkViewerObsolete::get {} {
314    # put the dataobj list in order according to -raise options
315    set dlist $_dlist
316    foreach obj $dlist {
317        if {[info exists _obj2raise($obj)] && $_obj2raise($obj)} {
318            set i [lsearch -exact $dlist $obj]
319            if {$i >= 0} {
320                set dlist [lreplace $dlist $i $i]
321                lappend dlist $obj
322            }
323        }
324    }
325    return $dlist
326}
327
328# ----------------------------------------------------------------------
329# USAGE: delete ?<dataobj1> <dataobj2> ...?
330#
331# Clients use this to delete a dataobj from the plot.  If no dataobjs
332# are specified, then all dataobjs are deleted.
333# ----------------------------------------------------------------------
334itcl::body Rappture::VtkViewerObsolete::delete {args} {
335    if {[llength $args] == 0} {
336        set args $_dlist
337    }
338
339    # delete all specified dataobjs
340    set changed 0
341    foreach dataobj $args {
342        set i [lsearch -exact $_dlist $dataobj]
343        if {$i >= 0} {
344            set _dlist [lreplace $_dlist $i $i]
345            catch {unset _obj2color($dataobj)}
346            catch {unset _obj2width($dataobj)}
347            catch {unset _obj2raise($dataobj)}
348            foreach actor $_actors($dataobj) {
349                $_renderer RemoveActor $actor
350            }
351            array unset _actors $dataobj
352            array unset _dataobj2vtk $dataobj-*
353            set changed 1
354        }
355    }
356    # If anything changed, then rebuild the plot
357    if {$changed} {
358        after cancel [itcl::code $this Rebuild]
359        after idle [itcl::code $this Rebuild]
360    }
361}
362
363# ----------------------------------------------------------------------
364# USAGE: scale ?<data1> <data2> ...?
365#
366# Sets the default limits for the overall plot according to the
367# limits of the data for all of the given <data> objects.  This
368# accounts for all objects--even those not showing on the screen.
369# Because of this, the limits are appropriate for all objects as
370# the user scans through data in the ResultSet viewer.
371# ----------------------------------------------------------------------
372itcl::body Rappture::VtkViewerObsolete::scale {args} {
373    eval ComputeLimits $args
374    _fixLimits
375}
376
377# ----------------------------------------------------------------------
378# USAGE: download coming
379# USAGE: download controls <downloadCommand>
380# USAGE: download now
381#
382# Clients use this method to create a downloadable representation
383# of the plot.  Returns a list of the form {ext string}, where
384# "ext" is the file extension (indicating the type of data) and
385# "string" is the data itself.
386# ----------------------------------------------------------------------
387itcl::body Rappture::VtkViewerObsolete::download {option args} {
388    switch $option {
389        coming {
390            if {[catch {
391                blt::winop snap $itk_component(plotarea) $_download
392            }]} {
393                $_download configure -width 1 -height 1
394                $_download put #000000
395            }
396        }
397        controls {
398            # no controls for this download yet
399            return ""
400        }
401        now {
402            set writer [vtkJPEGWriter $this-vtkJPEGWriter]
403            set large [vtkRenderLargeImage $this-RenderLargeImage]
404            $_axesWidget SetEnabled 0
405            $large SetInput $_renderer
406            $large SetMagnification 4
407            $writer SetInputConnection [$large GetOutputPort]
408
409            $writer SetFileName junk.jpg
410            $writer Write
411            rename $writer ""
412            rename $large ""
413            FixSettings smallaxes
414
415            set img [image create photo -file junk.jpg]
416            set bytes [$img data -format "jpeg -quality 100"]
417            set bytes [Rappture::encoding::decode -as b64 $bytes]
418            image delete $img
419            return [list .jpg $bytes]
420        }
421        default {
422            error "bad option \"$option\": should be coming, controls, now"
423        }
424    }
425}
426
427# ----------------------------------------------------------------------
428# USAGE: Clear
429#
430# Used internally to clear the drawing area and tear down all vtk
431# objects in the current scene.
432# ----------------------------------------------------------------------
433itcl::body Rappture::VtkViewerObsolete::Clear {} {
434    # clear out any old constructs
435   
436    foreach ren [array names _lights] {
437        foreach light $_lights($ren) {
438            $ren RemoveLight $light
439            rename $light ""
440        }
441        set _lights($ren) ""
442    }
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
451}
452
453# ----------------------------------------------------------------------
454# USAGE: Zoom in
455# USAGE: Zoom out
456# USAGE: Zoom reset
457#
458# Called automatically when the user clicks on one of the zoom
459# controls for this widget.  Changes the zoom for the current view.
460# ----------------------------------------------------------------------
461itcl::body Rappture::VtkViewerObsolete::Zoom {option} {
462    set cam [$_renderer GetActiveCamera]
463    switch -- $option {
464        in {
465            $cam Zoom 1.25
466            $_window Render
467        }
468        out {
469            $cam Zoom 0.8
470            $_window Render
471        }
472        reset {
473            $cam SetViewAngle 30
474            $_renderer ResetCamera
475            _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                angle 30
481            }
482            set dataobj [lindex $_dlist end]
483            if { $dataobj != "" } {
484                array set camera [$dataobj hints camera]
485            }
486            if { [info exists camera(clipmin)] } {
487                $cam SetClippingRange $camera(clipmin) $camera(clipmax)
488            }
489            if { [info exists camera(parallelscale)] } {
490                $cam SetParallelScale $camera(parallelscale)
491            }
492            $cam SetViewAngle $camera(angle)
493            $cam SetFocalPoint $camera(xfocal) $camera(yfocal) $camera(zfocal)
494            $cam SetPosition $camera(xpos) $camera(ypos) $camera(zpos)
495            $cam SetViewUp $camera(xviewup) $camera(yviewup) $camera(zviewup)
496            foreach key [array names camera] {
497                set _settings($this-$key) $camera($key)
498            }
499            $cam ComputeViewPlaneNormal
500            $_window Render
501        }
502    }
503}
504
505# ----------------------------------------------------------------------
506# USAGE: Move click <x> <y>
507# USAGE: Move drag <x> <y>
508# USAGE: Move release <x> <y>
509#
510# Called automatically when the user clicks/drags/releases in the
511# plot area.  Moves the plot according to the user's actions.
512# ----------------------------------------------------------------------
513itcl::body Rappture::VtkViewerObsolete::Move {option x y} {
514    switch -- $option {
515        click {
516            blt::busy configure $itk_component(area) -cursor fleur
517            set _click(x) $x
518            set _click(y) $y
519            set _click(theta) $_view(theta)
520            set _click(phi) $_view(phi)
521        }
522        drag {
523            if {[array size _click] == 0} {
524                Move click $x $y
525            } else {
526                set w [winfo width $itk_component(plot)]
527                set h [winfo height $itk_component(plot)]
528                set scalex [expr {$_limits(xMax)-$_limits(xMin)}]
529                set scaley [expr {$_limits(yMax)-$_limits(yMin)}]
530                set dx [expr {double($x-$_click(x))/$w*$scalex}]
531                set dy [expr {double($y-$_click(y))/$h*$scaley}]
532
533                if {$_dims == "2D"} {
534                    #
535                    # Shift the contour plot in 2D
536                    #
537                    foreach dataobj $_dlist {
538                        foreach actor $_actors($dataobj) {
539                            foreach {ax ay az} [$actor GetPosition] break
540                            $actor SetPosition [expr {$ax+$dx}] \
541                                [expr {$ay-$dy}] 0
542                        }
543                    }
544                    $_window Render
545                } elseif {$_dims == "3D"} {
546                    #
547                    # Rotate the camera in 3D
548                    #
549                    set theta [expr {$_view(theta) - $dy*180}]
550                    if {$theta < 2} { set theta 2 }
551                    if {$theta > 178} { set theta 178 }
552                    set phi [expr {$_view(phi) - $dx*360}]
553                   
554                    _3dView $theta $phi
555                    $_window Render
556                }
557                set _click(x) $x
558                set _click(y) $y
559            }
560        }
561        release {
562            Move drag $x $y
563            blt::busy configure $itk_component(area) -cursor left_ptr
564            catch {unset _click}
565        }
566        default {
567            error "bad option \"$option\": should be click, drag, release"
568        }
569    }
570    UpdateCameraInfo
571}
572
573
574# ----------------------------------------------------------------------
575# USAGE: _3dView <theta> <phi>
576#
577# Used internally to change the position of the camera for 3D data
578# sets.  Sets the camera according to the angles <theta> (angle from
579# the z-axis) and <phi> (angle from the x-axis in the x-y plane).
580# Both angles are in degrees.
581# ----------------------------------------------------------------------
582itcl::body Rappture::VtkViewerObsolete::_3dView {theta phi} {
583    return
584    set deg2rad 0.0174532927778
585    set xn [expr {sin($theta*$deg2rad)*cos($phi*$deg2rad)}]
586    set yn [expr {sin($theta*$deg2rad)*sin($phi*$deg2rad)}]
587    set zn [expr {cos($theta*$deg2rad)}]
588   
589    set xm [expr {0.5*($_limits(xMax)+$_limits(xMin))}]
590    set ym [expr {0.5*($_limits(yMax)+$_limits(yMin))}]
591    set zm [expr {0.5*($_limits(zMax)+$_limits(zMin))}]
592   
593    set cam [$_renderer GetActiveCamera]
594    set zoom [$cam GetViewAngle]
595    $cam SetViewAngle 30
596    $cam SetFocalPoint $xm $ym $zm
597    $cam SetPosition [expr {$xm-$xn}] [expr {$ym-$yn}] [expr {$zm+$zn}]
598    $cam ComputeViewPlaneNormal
599    $cam SetViewUp 0 0 1  ;# z-dir is up
600    $cam OrthogonalizeViewUp
601    $_renderer ResetCamera
602    $cam SetViewAngle $zoom
603   
604    set _view(theta) $theta
605    set _view(phi) $phi
606}
607
608# ----------------------------------------------------------------------
609# USAGE: _fixLimits
610#
611# Used internally to apply automatic limits to the axes for the
612# current plot.
613# ----------------------------------------------------------------------
614itcl::body Rappture::VtkViewerObsolete::_fixLimits {} {
615    $_renderer ResetCamera
616    set camera [$_renderer GetActiveCamera]
617    $camera Zoom 1.5
618    $_window Render
619    if 0 {
620        $this-vtkRenderWindow2 Render
621    }
622}
623
624# ----------------------------------------------------------------------
625# USAGE: _color2rgb <color>
626#
627# Used internally to convert a color name to a set of {r g b} values
628# needed for vtk.  Each r/g/b component is scaled in the range 0-1.
629# ----------------------------------------------------------------------
630itcl::body Rappture::VtkViewerObsolete::_color2rgb {color} {
631    foreach {r g b} [winfo rgb $itk_component(hull) $color] break
632    set r [expr {$r/65535.0}]
633    set g [expr {$g/65535.0}]
634    set b [expr {$b/65535.0}]
635    return [list $r $g $b]
636}
637
638# ----------------------------------------------------------------------
639# CONFIGURATION OPTION: -plotbackground
640# ----------------------------------------------------------------------
641itcl::configbody Rappture::VtkViewerObsolete::plotbackground {
642    foreach {r g b} [_color2rgb $itk_option(-plotbackground)] break
643    $_renderer SetBackground $r $g $b
644    $_window Render
645    if 0 {
646        $this-vtkRenderer2 SetBackground $r $g $b
647        $this-vtkRenderWindow2 Render
648    }
649}
650
651# ----------------------------------------------------------------------
652# CONFIGURATION OPTION: -plotforeground
653# ----------------------------------------------------------------------
654itcl::configbody Rappture::VtkViewerObsolete::plotforeground {
655    after cancel [itcl::code $this Rebuild]
656    after idle [itcl::code $this Rebuild]
657}
658
659itcl::body Rappture::VtkViewerObsolete::SetActorProperties { actor style } {
660    array set props {
661        -color \#6666FF
662        -edgevisibility yes
663        -edgecolor black
664        -linewidth 1.0
665        -opacity 1.0
666    }
667    # Parse style string.
668    array set props $style
669    set prop [$actor GetProperty]
670    eval $prop SetColor [_color2rgb $props(-color)]
671    if { $props(-edgevisibility) } {
672        $prop EdgeVisibilityOn
673    } else {
674        $prop EdgeVisibilityOff
675    }
676    set _settings($this-edges) $props(-edgevisibility)
677    eval $prop SetEdgeColor [_color2rgb $props(-edgecolor)]
678    $prop SetLineWidth $props(-linewidth)
679    $prop SetOpacity $props(-opacity)
680    set _settings($this-opacity) [expr $props(-opacity) * 100.0]
681}
682
683# ----------------------------------------------------------------------
684# USAGE: Rebuild
685#
686# Called automatically whenever something changes that affects the
687# data in the widget.  Clears any existing data and rebuilds the
688# widget to display new data.
689# ----------------------------------------------------------------------
690itcl::body Rappture::VtkViewerObsolete::Rebuild {} {
691    set id 0
692   
693    # determine the dimensionality from the topmost (raised) object
694    set dlist [get]
695    set dataobj [lindex $dlist end]
696    if {$dataobj != ""} {
697        set _dims [lindex [lsort [$dataobj components -dimensions]] end]
698    } else {
699        set _dims "0D"
700    }
701    ComputeLimits
702    $_cubeAxesActor SetCamera [$_renderer GetActiveCamera]
703    eval $_cubeAxesActor SetBounds [GetLimits]
704   
705    if 1 {
706        #
707        # LOOKUP TABLE FOR COLOR CONTOURS
708        #
709        # Use vmin/vmax if possible, otherwise get from data
710        if {$_limits(vMin) == "" || $_limits(vMax) == ""} {
711            set v0 0
712            set v1 1
713            if { [info exists _dataobj2vtk($dataobj)] } {
714                set pd [lindex $_dataobj2vtk($dataobj) 0]
715                if {"" != $pd} {
716                    foreach {v0 v1} [$pd GetScalarRange] break
717                }
718            }
719        } else {
720            set v0 $_limits(vMin)
721            set v1 $_limits(vMax)
722        }
723    }   
724    # scan through all data objects and build the contours
725    set firstobj 1
726    foreach dataobj $_dlist {
727        foreach comp [$dataobj components] {
728            set tag $dataobj-$comp
729            if { ![info exists _dataobj2vtk($tag)] } {
730                set actor [$dataobj values $comp]
731                set style [$dataobj style $comp]
732                set _dataobj2vtk($tag) $actor
733                lappend _actors($dataobj) $actor
734                $_renderer AddActor $actor
735                SetActorProperties $actor $style
736                incr id
737            }
738        }
739        set firstobj 0
740    }
741    set top [lindex [get] end]
742    if { $top != "" } {
743        foreach axis { x y z } {
744            set title [$top hints ${axis}label]
745            set units [$top hints ${axis}units]
746            set method Set[string toupper $axis]Title
747            set label "$title"
748            if { $units != "" } {
749                append label " ($units)"
750            }       
751            $_cubeAxesActor $method $label
752        }
753    }
754    if 1 {
755        _fixLimits
756        Zoom reset
757
758    }
759    $_interactor Start
760    $_window Render
761    return
762
763    #
764    # HACK ALERT!  A single ResetCamera doesn't seem to work for
765    #   some contour data.  You have to do it multiple times to
766    #   get to the right zoom factor on data.  I hope 20 times is
767    #   enough.  I hate Vtk sometimes...
768    #
769    for {set i 0} {$i < 20} {incr i} {
770        $_renderer ResetCamera
771        [$_renderer GetActiveCamera] Zoom 1.5
772    }
773    # prevent interactions -- use our own
774    blt::busy hold $itk_component(area) -cursor left_ptr
775    bind $itk_component(area)_Busy <ButtonPress> \
776        [itcl::code $this Move click %x %y]
777    bind $itk_component(area)_Busy <B1-Motion> \
778        [itcl::code $this Move drag %x %y]
779    bind $itk_component(area)_Busy <ButtonRelease> \
780        [itcl::code $this Move release %x %y]
781}
782
783itcl::body Rappture::VtkViewerObsolete::BuildViewTab {} {
784
785    set fg [option get $itk_component(hull) font Font]
786    #set bfg [option get $itk_component(hull) boldFont Font]
787
788    set tab [$itk_component(main) insert end \
789        -title "View Settings" \
790        -icon [Rappture::icon wrench]]
791    set inner $tab
792    if 0 {
793    blt::scrollset $tab.ss \
794        -xscrollbar $tab.ss.xs \
795        -yscrollbar $tab.ss.ys \
796        -window $tab.ss.frame
797    pack $tab.ss -fill both -expand yes
798    blt::tk::scrollbar $tab.ss.xs               
799    blt::tk::scrollbar $tab.ss.ys               
800    set inner [blt::tk::frame $tab.ss.frame]
801    $inner configure -borderwidth 4
802    }
803    set ::Rappture::VtkViewerObsolete::_settings($this-isosurface) 0
804    checkbutton $inner.isosurface \
805        -text "Isosurface shading" \
806        -variable [itcl::scope _settings($this-isosurface)] \
807        -command [itcl::code $this FixSettings isosurface] \
808        -font "Arial 9"
809
810    checkbutton $inner.axes \
811        -text "Axes" \
812        -variable [itcl::scope _settings($this-axes)] \
813        -command [itcl::code $this FixSettings axes] \
814        -font "Arial 9"
815
816    checkbutton $inner.edges \
817        -text "Edges" \
818        -variable [itcl::scope _settings($this-edges)] \
819        -command [itcl::code $this FixSettings edges] \
820        -font "Arial 9"
821
822    checkbutton $inner.smallaxes \
823        -text "Small Axes" \
824        -variable [itcl::scope _settings($this-smallaxes)] \
825        -command [itcl::code $this FixSettings smallaxes] \
826        -font "Arial 9"
827
828    checkbutton $inner.wireframe \
829        -text "Wireframe" \
830        -variable [itcl::scope _settings($this-wireframe)] \
831        -command [itcl::code $this FixSettings wireframe] \
832        -font "Arial 9"
833
834    blt::table $inner \
835        0,0 $inner.axes  -columnspan 2 -anchor w \
836        1,0 $inner.edges  -columnspan 2 -anchor w \
837        2,0 $inner.wireframe  -columnspan 2 -anchor w \
838        3,0 $inner.smallaxes  -columnspan 2 -anchor w
839
840    blt::table configure $inner r* -resize none
841    blt::table configure $inner r5 -resize expand
842}
843
844itcl::body Rappture::VtkViewerObsolete::BuildVolumeTab {} {
845    foreach { key value } {
846        light           40
847        transp          50
848        opacity         1000
849    } {
850        set _settings($this-$key) $value
851    }
852
853    set tab [$itk_component(main) insert end \
854        -title "Volume Settings" \
855        -icon [Rappture::icon volume-on]]
856    set inner $tab
857    if 0 {
858    blt::scrollset $tab.ss \
859        -xscrollbar $tab.ss.xs \
860        -yscrollbar $tab.ss.ys \
861        -window $tab.ss.frame
862    pack $tab.ss -fill both -expand yes
863    blt::tk::scrollbar $tab.ss.xs               
864    blt::tk::scrollbar $tab.ss.ys               
865    set inner [blt::tk::frame $tab.ss.frame]
866    $inner configure -borderwidth 4
867    }
868    set fg [option get $itk_component(hull) font Font]
869    #set bfg [option get $itk_component(hull) boldFont Font]
870
871    checkbutton $inner.vol -text "Show volume" -font $fg \
872        -variable [itcl::scope _settings($this-volume)] \
873        -command [itcl::code $this FixSettings volume]
874    label $inner.shading -text "Shading:" -font $fg
875
876    label $inner.dim -text "Dim" -font $fg
877    ::scale $inner.light -from 0 -to 100 -orient horizontal \
878        -variable [itcl::scope _settings($this-light)] \
879        -width 10 \
880        -showvalue off -command [itcl::code $this FixSettings light]
881    label $inner.bright -text "Bright" -font $fg
882
883    label $inner.fog -text "Fog" -font $fg
884    ::scale $inner.transp -from 0 -to 100 -orient horizontal \
885        -variable [itcl::scope _settings($this-transp)] \
886        -width 10 \
887        -showvalue off -command [itcl::code $this FixSettings transp]
888    label $inner.plastic -text "Plastic" -font $fg
889
890    label $inner.clear -text "Clear" -font $fg
891    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
892        -variable [itcl::scope _settings($this-opacity)] \
893        -width 10 \
894        -showvalue off -command [itcl::code $this FixSettings opacity]
895    label $inner.opaque -text "Opaque" -font $fg
896
897    blt::table $inner \
898        0,0 $inner.vol -columnspan 4 -anchor w -pady 2 \
899        1,0 $inner.shading -columnspan 4 -anchor w -pady {10 2} \
900        2,0 $inner.dim -anchor e -pady 2 \
901        2,1 $inner.light -columnspan 2 -pady 2 -fill x \
902        2,3 $inner.bright -anchor w -pady 2 \
903        3,0 $inner.fog -anchor e -pady 2 \
904        3,1 $inner.transp -columnspan 2 -pady 2 -fill x \
905        3,3 $inner.plastic -anchor w -pady 2 \
906        4,0 $inner.clear -anchor e -pady 2 \
907        4,1 $inner.opacity -columnspan 2 -pady 2 -fill x\
908        4,3 $inner.opaque -anchor w -pady 2
909
910    blt::table configure $inner c0 c1 c3 r* -resize none
911    blt::table configure $inner r6 -resize expand
912}
913
914itcl::body Rappture::VtkViewerObsolete::UpdateCameraInfo {} {
915    set cam [$_renderer GetActiveCamera]
916    foreach key { x y z } \
917            pt  [$cam GetFocalPoint] \
918            up  [$cam GetViewUp] \
919            pos [$cam GetPosition] {
920        set _settings($this-${key}focal) $pt
921        set _settings($this-${key}up) $up
922        set _settings($this-${key}pos) $pos
923    }
924    foreach {min max} [$cam GetClippingRange] break
925    set _settings($this-clipmin) $min
926    set _settings($this-clipmax) $max
927    set _settings($this-parallelscale) [$cam GetParallelScale]
928    set _settings($this-angle) [$cam GetViewAngle]
929    foreach key { xpos ypos zpos xviewup yviewup zviewup
930        xfocal yfocal zfocal angle clipmin clipmax parallelscale
931    } {
932        set out($key) $_settings($this-$key)
933    }
934    puts \"[array get out]\"
935}
936
937itcl::body Rappture::VtkViewerObsolete::BuildCameraTab {} {
938    set inner [$itk_component(main) insert end \
939        -title "Camera Settings" \
940        -icon [Rappture::icon camera]]
941    $inner configure -borderwidth 4
942    bind $inner <Map> [itcl::code $this UpdateCameraInfo]
943
944    label $inner.xposl -text "Position"
945    entry $inner.xpos -bg white \
946        -textvariable [itcl::scope _settings($this-xpos)]
947    entry $inner.ypos -bg white \
948        -textvariable [itcl::scope _settings($this-ypos)]
949    entry $inner.zpos -bg white \
950        -textvariable [itcl::scope _settings($this-zpos)]
951    label $inner.xviewupl -text "View Up"
952    entry $inner.xviewup -bg white \
953        -textvariable [itcl::scope _settings($this-xviewup)]
954    entry $inner.yviewup -bg white \
955        -textvariable [itcl::scope _settings($this-yviewup)]
956    entry $inner.zviewup -bg white \
957        -textvariable [itcl::scope _settings($this-zviewup)]
958    label $inner.xfocall -text "Focal Point"
959    entry $inner.xfocal -bg white \
960        -textvariable [itcl::scope _settings($this-xfocal)]
961    entry $inner.yfocal -bg white \
962        -textvariable [itcl::scope _settings($this-yfocal)]
963    entry $inner.zfocal -bg white \
964        -textvariable [itcl::scope _settings($this-zfocal)]
965    label $inner.anglel -text "View Angle"
966    entry $inner.angle -bg white \
967        -textvariable [itcl::scope _settings($this-angle)]
968    label $inner.clipl -text "Clipping Range"
969    entry $inner.clipmin -bg white \
970        -textvariable [itcl::scope _settings($this-clipmin)]
971    entry $inner.clipmax -bg white \
972        -textvariable [itcl::scope _settings($this-clipmax)]
973    label $inner.pscalel -text "Parallel Scale"
974    entry $inner.pscale -bg white \
975        -textvariable [itcl::scope _settings($this-parallelscale)]
976
977    button $inner.refresh -text "Refresh" \
978        -command [itcl::code $this UpdateCameraInfo]
979    blt::table $inner \
980        0,0 $inner.xposl -anchor w -pady 2 \
981        1,0 $inner.xpos -pady 2 -fill x\
982        2,0 $inner.ypos -pady 2 -fill x\
983        3,0 $inner.zpos -pady 2 -fill x\
984        4,0 $inner.xviewupl -anchor w -pady 2 \
985        5,0 $inner.xviewup -pady 2 -fill x \
986        6,0 $inner.yviewup -pady 2 -fill x \
987        7,0 $inner.zviewup -pady 2 -fill x \
988        8,0 $inner.xfocall -anchor w -pady 2 \
989        9,0 $inner.xfocal -pady 2 -fill x \
990        10,0 $inner.yfocal -pady 2 -fill x \
991        11,0 $inner.zfocal -pady 2 -fill x \
992        16,0 $inner.anglel -anchor w -pady 2 \
993        17,0 $inner.angle -pady 2 -fill x \
994        18,0 $inner.clipl -anchor w -pady 2 \
995        19,0 $inner.clipmin -pady 2 -fill x \
996        20,0 $inner.clipmax -pady 2 -fill x \
997        21,0 $inner.pscalel -anchor w -pady 2 \
998        22,0 $inner.pscale -pady 2 -fill x \
999        23,0 $inner.refresh
1000
1001    blt::table configure $inner r* c* -resize none
1002    blt::table configure $inner c0 -resize expand
1003    blt::table configure $inner r24 -resize expand
1004}
1005
1006# ----------------------------------------------------------------------
1007# USAGE: FixSettings <what> ?<value>?
1008#
1009# Used internally to update rendering settings whenever parameters
1010# change in the popup settings panel.  Sends the new settings off
1011# to the back end.
1012# ----------------------------------------------------------------------
1013itcl::body Rappture::VtkViewerObsolete::FixSettings {what {value ""}} {
1014    switch -- $what {
1015        light {
1016        }
1017        transp {
1018        }
1019        opacity {
1020            set new [expr $_settings($this-opacity) * 0.01]
1021            foreach dataobj [get] {
1022                foreach comp [$dataobj components] {
1023                    set actor [$dataobj values $comp]
1024                    set prop [$actor GetProperty]
1025                    $prop SetOpacity $new
1026                }
1027            }
1028            $_window Render
1029        }
1030
1031        "wireframe" {
1032            foreach dataobj [get] {
1033                foreach comp [$dataobj components] {
1034                    set actor [$dataobj values $comp]
1035                    set prop [$actor GetProperty]
1036                    if { $_settings($this-wireframe) } {
1037                        $prop SetRepresentationToWireframe
1038                    } else {
1039                        $prop SetRepresentationToSurface
1040                    }
1041                }
1042            }
1043            $_window Render
1044        }
1045        "isosurface" {
1046        }
1047        "edges" {
1048            foreach dataobj [get] {
1049                foreach comp [$dataobj components] {
1050                    set actor [$dataobj values $comp]
1051                    set prop [$actor GetProperty]
1052                    if { $_settings($this-edges) } {
1053                        $prop EdgeVisibilityOn
1054                    } else {
1055                        $prop EdgeVisibilityOff
1056                    }
1057                }
1058            }
1059            $_window Render
1060        }
1061        "axes" {
1062            if { $_settings($this-axes) } {
1063                $_cubeAxesActor VisibilityOn
1064            } else {
1065                $_cubeAxesActor VisibilityOff
1066            }
1067            $_window Render
1068        }
1069        "smallaxes" {
1070            $_axesWidget SetEnabled $_settings($this-smallaxes)
1071            $_window Render
1072        }
1073        default {
1074            error "don't know how to fix $what"
1075        }
1076    }
1077}
1078
1079itcl::body Rappture::VtkViewerObsolete::GetLimits {} {
1080    return [list $_limits(xMin) $_limits(xMax) \
1081                $_limits(yMin) $_limits(yMax) \
1082                $_limits(zMin) $_limits(zMax)]
1083}
1084
1085itcl::body Rappture::VtkViewerObsolete::ComputeLimits { args } {
1086    array set _limits {
1087        xMin 0
1088        xMax 1
1089        yMin 0
1090        yMax 1
1091        zMin 0
1092        zMax 1
1093        vMin 0
1094        vMax 1
1095    }
1096    set actors {}
1097    if { [llength $args] > 0 } {
1098        foreach dataobj $args {
1099            foreach comp [$dataobj components] {
1100                lappend actors [$dataobj values $comp]
1101            }
1102        }
1103    } else {
1104        foreach dataobj [get] {
1105            foreach comp [$dataobj components] {
1106                lappend actors [$dataobj values $comp]
1107            }
1108        }
1109    }
1110    if { [llength $actors] == 0 } {
1111        return
1112    }
1113    set actor [lindex $actors 0]
1114    foreach key { xMin xMax yMin yMax zMin zMax} value [$actor GetBounds] {
1115        set _limits($key) $value
1116    }
1117    foreach actor [lrange $actors 1 end] {
1118        foreach { xMin xMax yMin yMax zMin zMax} [$actor GetBounds] break
1119        if { $xMin < $_limits(xMin) } {
1120            set _limits(xMin) $xMin
1121        }
1122        if { $xMax > $_limits(xMax) } {
1123            set _limits(xMax) $xMax
1124        }
1125        if { $yMin < $_limits(yMin) } {
1126            set _limits(yMin) $yMin
1127        }
1128        if { $yMax > $_limits(yMax) } {
1129            set _limits(yMax) $yMax
1130        }
1131        if { $zMin < $_limits(zMin) } {
1132            set _limits(zMin) $zMin
1133        }
1134        if { $zMax > $_limits(zMax) } {
1135            set _limits(zMax) $zMax
1136        }
1137    }
1138    set _limits(vMin) $_limits(zMin)
1139    set _limits(vMax) $_limits(zMax)
1140}
Note: See TracBrowser for help on using the repository browser.