source: tags/1.3.5/gui/scripts/vtkisosurfaceviewer.tcl @ 4754

Last change on this file since 4754 was 4754, checked in by ldelgass, 10 years ago

merge r4668:4669 from trunk

File size: 89.9 KB
RevLine 
[3330]1# -*- mode: tcl; indent-tabs-mode: nil -*-
2# ----------------------------------------------------------------------
[4351]3#  COMPONENT: vtkisosurfaceviewer - Vtk 3D contour object viewer
[3330]4#
5#  It connects to the Vtk server running on a rendering farm,
6#  transmits data, and displays the results.
7# ======================================================================
8#  AUTHOR:  Michael McLennan, Purdue University
9#  Copyright (c) 2004-2005  Purdue Research Foundation
10#
11#  See the file "license.terms" for information on usage and
12#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13# ======================================================================
14package require Itk
15package require BLT
16#package require Img
17
18option add *VtkIsosurfaceViewer.width 4i widgetDefault
19option add *VtkIsosurfaceViewer*cursor crosshair widgetDefault
20option add *VtkIsosurfaceViewer.height 4i widgetDefault
21option add *VtkIsosurfaceViewer.foreground black widgetDefault
22option add *VtkIsosurfaceViewer.controlBackground gray widgetDefault
23option add *VtkIsosurfaceViewer.controlDarkBackground #999999 widgetDefault
24option add *VtkIsosurfaceViewer.plotBackground black widgetDefault
25option add *VtkIsosurfaceViewer.plotForeground white widgetDefault
26option add *VtkIsosurfaceViewer.font \
27    -*-helvetica-medium-r-normal-*-12-* widgetDefault
28
29# must use this name -- plugs into Rappture::resources::load
30proc VtkIsosurfaceViewer_init_resources {} {
31    Rappture::resources::register \
32        vtkvis_server Rappture::VtkIsosurfaceViewer::SetServerList
33}
34
35itcl::class Rappture::VtkIsosurfaceViewer {
36    inherit Rappture::VisViewer
37
38    itk_option define -plotforeground plotForeground Foreground ""
39    itk_option define -plotbackground plotBackground Background ""
40
41    constructor { hostlist args } {
42        Rappture::VisViewer::constructor $hostlist
43    } {
44        # defined below
45    }
46    destructor {
47        # defined below
48    }
49    public proc SetServerList { namelist } {
50        Rappture::VisViewer::SetServerList "vtkvis" $namelist
51    }
52    public method add {dataobj {settings ""}}
53    public method camera {option args}
54    public method delete {args}
55    public method disconnect {}
56    public method download {option args}
57    public method get {args}
58    public method isconnected {}
59    public method parameters {title args} {
60        # do nothing
61    }
62    public method scale {args}
63
[4752]64    # The following methods are only used by this class.
[3330]65
[4752]66    private method AdjustSetting {what {value ""}}
[3330]67    private method BuildAxisTab {}
68    private method BuildCameraTab {}
[3514]69    private method BuildColormap { name }
[3330]70    private method BuildCutplaneTab {}
71    private method BuildDownloadPopup { widget command }
72    private method BuildIsosurfaceTab {}
[3879]73    private method Combo { option }
[4752]74    private method Connect {}
75    private method CurrentDatasets {args}
76    private method Disconnect {}
77    private method DoChangeContourLevels {}
78    private method DoResize {}
79    private method DoRotate {}
[3442]80    private method DrawLegend {}
[3330]81    private method EnterLegend { x y }
[4752]82    private method EventuallyChangeContourLevels {}
83    private method EventuallyRequestLegend {}
[3330]84    private method EventuallyResize { w h }
85    private method EventuallyRotate { q }
86    private method EventuallySetCutplane { axis args }
[4752]87    private method GenerateContourList {}
[3330]88    private method GetImage { args }
89    private method GetVtkData { args }
[4752]90    private method InitSettings { args  }
[3330]91    private method IsValidObject { dataobj }
92    private method LeaveLegend {}
93    private method MotionLegend { x y }
[4752]94    private method Pan {option x y}
[3330]95    private method PanCamera {}
[4752]96    private method Pick {x y}
97    private method Rebuild {}
98    private method ReceiveDataset { args }
99    private method ReceiveImage { args }
100    private method ReceiveLegend { colormap title vmin vmax size }
[3330]101    private method RequestLegend {}
[4752]102    private method Rotate {option x y}
103    private method SetCurrentColormap { color }
104    private method SetCurrentFieldName { dataobj }
[3330]105    private method SetLegendTip { x y }
[4752]106    private method SetObjectStyle { dataobj comp }
[3517]107    private method SetOrientation { side }
[4752]108    private method Slice {option args}
109    private method Zoom {option}
110    private method ViewToQuaternion {} {
111        return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)]
112    }
[3330]113
114    private variable _arcball ""
115
116    private variable _dlist ""     ;    # list of data objects
117    private variable _obj2datasets
118    private variable _obj2ovride   ;    # maps dataobj => style override
119    private variable _datasets     ;    # contains all the dataobj-component
120                                   ;    # datasets in the server
121    private variable _colormaps    ;    # contains all the colormaps
122                                   ;    # in the server.
123    # The name of the current colormap used.  The colormap is global to all
124    # heightmaps displayed.
[3623]125    private variable _currentColormap ""
126    private variable _currentNumContours -1
[3330]127
128    private variable _dataset2style    ;# maps dataobj-component to transfunc
129
130    private variable _click        ;    # info used for rotate operations
131    private variable _limits       ;    # autoscale min/max for all axes
132    private variable _view         ;    # view params for 3D view
133    private variable _settings
134    private variable _style;            # Array of current component styles.
[3514]135    private variable _changed
[3330]136    private variable _initialStyle;     # Array of initial component styles.
137    private variable _reset 1;          # indicates if camera needs to be reset
138                                        # to starting position.
139
140    private variable _first ""     ;    # This is the topmost dataset.
141    private variable _start 0
142    private variable _title ""
[3442]143    private variable _isolines
[4752]144    private variable _contourList
145    private variable _currentLimits ""
146    private variable _widget
[3330]147
148    common _downloadPopup;              # download options from popup
149    private common _hardcopy
150    private variable _width 0
151    private variable _height 0
152    private variable _resizePending 0
153    private variable _rotatePending 0
154    private variable _cutplanePending 0
155    private variable _legendPending 0
156    private variable _field      ""
[4186]157    private variable _colorMode "scalar";       #  Mode of colormap (vmag or scalar)
[3330]158    private variable _fieldNames {}
159    private variable _fields
[3409]160    private variable _curFldName ""
161    private variable _curFldLabel ""
[3330]162}
163
164itk::usual VtkIsosurfaceViewer {
165    keep -background -foreground -cursor -font
166    keep -plotbackground -plotforeground
167}
168
169# ----------------------------------------------------------------------
170# CONSTRUCTOR
171# ----------------------------------------------------------------------
172itcl::body Rappture::VtkIsosurfaceViewer::constructor {hostlist args} {
173    package require vtk
174    set _serverType "vtkvis"
175
176    # Rebuild event
177    $_dispatcher register !rebuild
178    $_dispatcher dispatch $this !rebuild "[itcl::code $this Rebuild]; list"
179
180    # Resize event
181    $_dispatcher register !resize
182    $_dispatcher dispatch $this !resize "[itcl::code $this DoResize]; list"
183
184    # Rotate event
185    $_dispatcher register !rotate
186    $_dispatcher dispatch $this !rotate "[itcl::code $this DoRotate]; list"
187
188    # Legend event
189    $_dispatcher register !legend
190    $_dispatcher dispatch $this !legend "[itcl::code $this RequestLegend]; list"
191
[4752]192    # Contour levels event
193    $_dispatcher register !contours
194    $_dispatcher dispatch $this !contours \
195        "[itcl::code $this DoChangeContourLevels]; list"
196
[3330]197    # X-Cutplane event
198    $_dispatcher register !xcutplane
199    $_dispatcher dispatch $this !xcutplane \
[4201]200        "[itcl::code $this AdjustSetting -xcutplaneposition]; list"
[3330]201
202    # Y-Cutplane event
203    $_dispatcher register !ycutplane
204    $_dispatcher dispatch $this !ycutplane \
[4201]205        "[itcl::code $this AdjustSetting -ycutplaneposition]; list"
[3330]206
207    # Z-Cutplane event
208    $_dispatcher register !zcutplane
209    $_dispatcher dispatch $this !zcutplane \
[4201]210        "[itcl::code $this AdjustSetting -zcutplaneposition]; list"
[3330]211
212    #
213    # Populate parser with commands handle incoming requests
214    #
215    $_parser alias image [itcl::code $this ReceiveImage]
216    $_parser alias dataset [itcl::code $this ReceiveDataset]
217    $_parser alias legend [itcl::code $this ReceiveLegend]
218
219    # Initialize the view to some default parameters.
220    array set _view {
[4752]221        -ortho           0
222        -qw              0.853553
223        -qx              -0.353553
224        -qy              0.353553
225        -qz              0.146447
226        -xpan            0
227        -ypan            0
228        -zoom            1.0
[3330]229    }
230    set _arcball [blt::arcball create 100 100]
[4752]231    $_arcball quaternion [ViewToQuaternion]
[3330]232
[4752]233    array set _contourList {
234        numLevels       10
235        reqValues       ""
236        updatePending   0
237        values          ""
238    }
[4201]239    array set _settings {
[4351]240        -axesvisible                    1
[4752]241        -axislabels                     1
242        -axisminorticks                 1
243        -axismode                       "static"
244        -background                     black
245        -colormap                       BCGYR
246        -colormapvisible                1
[4201]247        -cutplaneedges                  0
248        -cutplanelighting               1
[4752]249        -cutplaneopacity                1.0
[4201]250        -cutplanepreinterp              1
251        -cutplanesvisible               0
252        -cutplanewireframe              0
[4752]253        -field                          "Default"
254        -isolinecolor                   white
[4201]255        -isosurfaceedges                0
256        -isosurfacelighting             1
[4752]257        -isosurfaceopacity              0.6
[4201]258        -isosurfacevisible              1
259        -isosurfacewireframe            0
260        -legendvisible                  1
261        -numcontours                    10
[4752]262        -outline                        0
[4201]263        -xcutplaneposition              50
264        -xcutplanevisible               1
[4752]265        -xgrid                          0
[4201]266        -ycutplaneposition              50
267        -ycutplanevisible               1
[4752]268        -ygrid                          0
[4201]269        -zcutplaneposition              50
270        -zcutplanevisible               1
[4752]271        -zgrid                          0
[4201]272    }
[3514]273    array set _changed {
[4752]274        -colormap                0
[4201]275        -isosurfaceopacity       0
[4752]276        -cutplaneopacity         0
[4201]277        -numcontours             0
[3514]278    }
[4752]279    array set _widget {
280        -isosurfaceopacity       60
281        -cutplaneopacity         100
282    }
[3330]283
284    itk_component add view {
285        canvas $itk_component(plotarea).view \
286            -highlightthickness 0 -borderwidth 0
287    } {
288        usual
289        ignore -highlightthickness -borderwidth  -background
290    }
291
292    itk_component add fieldmenu {
293        menu $itk_component(plotarea).menu -bg black -fg white -relief flat \
[4201]294            -tearoff 0
[3330]295    } {
296        usual
297        ignore -background -foreground -relief -tearoff
298    }
299    set c $itk_component(view)
300    bind $c <Configure> [itcl::code $this EventuallyResize %w %h]
301    bind $c <4> [itcl::code $this Zoom in 0.25]
302    bind $c <5> [itcl::code $this Zoom out 0.25]
303    bind $c <KeyPress-Left>  [list %W xview scroll 10 units]
304    bind $c <KeyPress-Right> [list %W xview scroll -10 units]
305    bind $c <KeyPress-Up>    [list %W yview scroll 10 units]
306    bind $c <KeyPress-Down>  [list %W yview scroll -10 units]
307    bind $c <Enter> "focus %W"
308    bind $c <Control-F1> [itcl::code $this ToggleConsole]
309
310    # Fix the scrollregion in case we go off screen
311    $c configure -scrollregion [$c bbox all]
312
313    set _map(id) [$c create image 0 0 -anchor nw -image $_image(plot)]
314    set _map(cwidth) -1
315    set _map(cheight) -1
316    set _map(zoom) 1.0
317    set _map(original) ""
318
319    set f [$itk_component(main) component controls]
320    itk_component add reset {
321        button $f.reset -borderwidth 1 -padx 1 -pady 1 \
322            -highlightthickness 0 \
323            -image [Rappture::icon reset-view] \
324            -command [itcl::code $this Zoom reset]
325    } {
326        usual
327        ignore -highlightthickness
328    }
329    pack $itk_component(reset) -side top -padx 2 -pady 2
[3523]330    Rappture::Tooltip::for $itk_component(reset) \
331        "Reset the view to the default zoom level"
[3330]332
333    itk_component add zoomin {
334        button $f.zin -borderwidth 1 -padx 1 -pady 1 \
335            -highlightthickness 0 \
336            -image [Rappture::icon zoom-in] \
337            -command [itcl::code $this Zoom in]
338    } {
339        usual
340        ignore -highlightthickness
341    }
342    pack $itk_component(zoomin) -side top -padx 2 -pady 2
343    Rappture::Tooltip::for $itk_component(zoomin) "Zoom in"
344
345    itk_component add zoomout {
346        button $f.zout -borderwidth 1 -padx 1 -pady 1 \
347            -highlightthickness 0 \
348            -image [Rappture::icon zoom-out] \
349            -command [itcl::code $this Zoom out]
350    } {
351        usual
352        ignore -highlightthickness
353    }
354    pack $itk_component(zoomout) -side top -padx 2 -pady 2
355    Rappture::Tooltip::for $itk_component(zoomout) "Zoom out"
356
357    itk_component add contour {
358        Rappture::PushButton $f.contour \
359            -onimage [Rappture::icon volume-on] \
360            -offimage [Rappture::icon volume-off] \
[4201]361            -variable [itcl::scope _settings(-isosurfacevisible)] \
362            -command [itcl::code $this AdjustSetting -isosurfacevisible]
[3330]363    }
364    $itk_component(contour) select
365    Rappture::Tooltip::for $itk_component(contour) \
[4752]366        "Hide the isosurface"
[3330]367    pack $itk_component(contour) -padx 2 -pady 2
368
369    itk_component add cutplane {
370        Rappture::PushButton $f.cutplane \
371            -onimage [Rappture::icon cutbutton] \
372            -offimage [Rappture::icon cutbutton] \
[4201]373            -variable [itcl::scope _settings(-cutplanesvisible)] \
374            -command [itcl::code $this AdjustSetting -cutplanesvisible]
[3330]375    }
376    Rappture::Tooltip::for $itk_component(cutplane) \
[4752]377        "Show the cutplanes"
[3330]378    pack $itk_component(cutplane) -padx 2 -pady 2
379
[4351]380
[3330]381    if { [catch {
382        BuildIsosurfaceTab
383        BuildCutplaneTab
384        BuildAxisTab
385        BuildCameraTab
386    } errs] != 0 } {
387        puts stderr errs=$errs
388    }
389    # Legend
390
391    set _image(legend) [image create photo]
392    itk_component add legend {
393        canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0
394    } {
395        usual
396        ignore -highlightthickness
397        rename -background -plotbackground plotBackground Background
398    }
399
400    # Hack around the Tk panewindow.  The problem is that the requested
401    # size of the 3d view isn't set until an image is retrieved from
402    # the server.  So the panewindow uses the tiny size.
403    set w 10000
404    pack forget $itk_component(view)
405    blt::table $itk_component(plotarea) \
406        0,0 $itk_component(view) -fill both -reqwidth $w
407    blt::table configure $itk_component(plotarea) c1 -resize none
408
409    # Bindings for rotation via mouse
410    bind $itk_component(view) <ButtonPress-1> \
411        [itcl::code $this Rotate click %x %y]
412    bind $itk_component(view) <B1-Motion> \
413        [itcl::code $this Rotate drag %x %y]
414    bind $itk_component(view) <ButtonRelease-1> \
415        [itcl::code $this Rotate release %x %y]
416
417    # Bindings for panning via mouse
418    bind $itk_component(view) <ButtonPress-2> \
419        [itcl::code $this Pan click %x %y]
420    bind $itk_component(view) <B2-Motion> \
421        [itcl::code $this Pan drag %x %y]
422    bind $itk_component(view) <ButtonRelease-2> \
423        [itcl::code $this Pan release %x %y]
424
[3443]425    #bind $itk_component(view) <ButtonRelease-3> \
426    #    [itcl::code $this Pick %x %y]
[3330]427
428    # Bindings for panning via keyboard
429    bind $itk_component(view) <KeyPress-Left> \
430        [itcl::code $this Pan set -10 0]
431    bind $itk_component(view) <KeyPress-Right> \
432        [itcl::code $this Pan set 10 0]
433    bind $itk_component(view) <KeyPress-Up> \
434        [itcl::code $this Pan set 0 -10]
435    bind $itk_component(view) <KeyPress-Down> \
436        [itcl::code $this Pan set 0 10]
437    bind $itk_component(view) <Shift-KeyPress-Left> \
438        [itcl::code $this Pan set -2 0]
439    bind $itk_component(view) <Shift-KeyPress-Right> \
440        [itcl::code $this Pan set 2 0]
441    bind $itk_component(view) <Shift-KeyPress-Up> \
442        [itcl::code $this Pan set 0 -2]
443    bind $itk_component(view) <Shift-KeyPress-Down> \
444        [itcl::code $this Pan set 0 2]
445
446    # Bindings for zoom via keyboard
447    bind $itk_component(view) <KeyPress-Prior> \
448        [itcl::code $this Zoom out]
449    bind $itk_component(view) <KeyPress-Next> \
450        [itcl::code $this Zoom in]
451
452    bind $itk_component(view) <Enter> "focus $itk_component(view)"
453
454    if {[string equal "x11" [tk windowingsystem]]} {
455        # Bindings for zoom via mouse
456        bind $itk_component(view) <4> [itcl::code $this Zoom out]
457        bind $itk_component(view) <5> [itcl::code $this Zoom in]
458    }
459
460    set _image(download) [image create photo]
461
462    eval itk_initialize $args
[4186]463
464    EnableWaitDialog 500
[3330]465    Connect
466}
467
468# ----------------------------------------------------------------------
469# DESTRUCTOR
470# ----------------------------------------------------------------------
471itcl::body Rappture::VtkIsosurfaceViewer::destructor {} {
472    Disconnect
473    image delete $_image(plot)
474    image delete $_image(download)
475    catch { blt::arcball destroy $_arcball }
476}
477
478itcl::body Rappture::VtkIsosurfaceViewer::DoResize {} {
479    if { $_width < 2 } {
480        set _width 500
481    }
482    if { $_height < 2 } {
483        set _height 500
484    }
485    set _start [clock clicks -milliseconds]
486    SendCmd "screen size $_width $_height"
487
488    EventuallyRequestLegend
489    set _resizePending 0
490}
491
[4752]492itcl::body Rappture::VtkIsosurfaceViewer::DoChangeContourLevels {} {
493    GenerateContourList
494    SendCmd [list contour3d contourlist $_contourList(values)]
495    SendCmd [list camera reset]
496    DrawLegend
497    set _contourList(updatePending) 0
498}
499
[3330]500itcl::body Rappture::VtkIsosurfaceViewer::DoRotate {} {
[4752]501    SendCmd "camera orient [ViewToQuaternion]"
[3330]502    set _rotatePending 0
503}
504
505itcl::body Rappture::VtkIsosurfaceViewer::EventuallyRequestLegend {} {
506    if { !$_legendPending } {
507        set _legendPending 1
508        $_dispatcher event -idle !legend
509    }
510}
511
512itcl::body Rappture::VtkIsosurfaceViewer::EventuallyResize { w h } {
513    set _width $w
514    set _height $h
515    $_arcball resize $w $h
516    if { !$_resizePending } {
517        set _resizePending 1
518        $_dispatcher event -after 400 !resize
519    }
520}
521
522set rotate_delay 100
523
524itcl::body Rappture::VtkIsosurfaceViewer::EventuallyRotate { q } {
[4752]525    foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break
[3330]526    if { !$_rotatePending } {
527        set _rotatePending 1
528        global rotate_delay
529        $_dispatcher event -after $rotate_delay !rotate
530    }
531}
532
533itcl::body Rappture::VtkIsosurfaceViewer::EventuallySetCutplane { axis args } {
534    if { !$_cutplanePending } {
535        set _cutplanePending 1
536        $_dispatcher event -after 100 !${axis}cutplane
537    }
538}
539
[4752]540itcl::body Rappture::VtkIsosurfaceViewer::EventuallyChangeContourLevels {} {
541    set n $_contourList(numLevels)
542    set _contourList(values) ""
543    if { !$_contourList(updatePending) } {
544        set _contourList(updatePending) 1
545        global rotate_delay
546        $_dispatcher event -after $rotate_delay !contours
547    }
548}
549
[3330]550# ----------------------------------------------------------------------
551# USAGE: add <dataobj> ?<settings>?
552#
553# Clients use this to add a data object to the plot.  The optional
554# <settings> are used to configure the plot.  Allowed settings are
555# -color, -brightness, -width, -linestyle, and -raise.
556# ----------------------------------------------------------------------
557itcl::body Rappture::VtkIsosurfaceViewer::add {dataobj {settings ""}} {
[3571]558    if { ![$dataobj isvalid] } {
559        return;                         # Object doesn't contain valid data.
560    }
[3330]561    array set params {
562        -color auto
563        -width 1
564        -linestyle solid
565        -brightness 0
566        -raise 0
567        -description ""
568        -param ""
569        -type ""
570    }
571    array set params $settings
572    set params(-description) ""
573    set params(-param) ""
[3800]574    array set params $settings
575
[3330]576    if {$params(-color) == "auto" || $params(-color) == "autoreset"} {
577        # can't handle -autocolors yet
578        set params(-color) black
579    }
[3844]580    set pos [lsearch -exact $_dlist $dataobj]
[3330]581    if {$pos < 0} {
582        lappend _dlist $dataobj
583    }
584    set _obj2ovride($dataobj-color) $params(-color)
585    set _obj2ovride($dataobj-width) $params(-width)
586    set _obj2ovride($dataobj-raise) $params(-raise)
587    $_dispatcher event -idle !rebuild
588}
589
590
591# ----------------------------------------------------------------------
592# USAGE: delete ?<dataobj1> <dataobj2> ...?
593#
594#       Clients use this to delete a dataobj from the plot.  If no dataobjs
595#       are specified, then all dataobjs are deleted.  No data objects are
596#       deleted.  They are only removed from the display list.
597#
598# ----------------------------------------------------------------------
599itcl::body Rappture::VtkIsosurfaceViewer::delete {args} {
600    if { [llength $args] == 0} {
601        set args $_dlist
602    }
603    # Delete all specified dataobjs
604    set changed 0
605    foreach dataobj $args {
606        set pos [lsearch -exact $_dlist $dataobj]
607        if { $pos < 0 } {
608            continue;                   # Don't know anything about it.
609        }
610        # Remove it from the dataobj list.
611        set _dlist [lreplace $_dlist $pos $pos]
612        array unset _obj2ovride $dataobj-*
613        array unset _settings $dataobj-*
614        set changed 1
615    }
616    # If anything changed, then rebuild the plot
617    if { $changed } {
618        $_dispatcher event -idle !rebuild
619    }
620}
621
622# ----------------------------------------------------------------------
623# USAGE: get ?-objects?
624# USAGE: get ?-visible?
625# USAGE: get ?-image view?
626#
627# Clients use this to query the list of objects being plotted, in
628# order from bottom to top of this result.  The optional "-image"
629# flag can also request the internal images being shown.
630# ----------------------------------------------------------------------
631itcl::body Rappture::VtkIsosurfaceViewer::get {args} {
632    if {[llength $args] == 0} {
633        set args "-objects"
634    }
635
636    set op [lindex $args 0]
637    switch -- $op {
638        "-objects" {
639            # put the dataobj list in order according to -raise options
640            set dlist {}
641            foreach dataobj $_dlist {
642                if { ![IsValidObject $dataobj] } {
643                    continue
644                }
645                if {[info exists _obj2ovride($dataobj-raise)] &&
646                    $_obj2ovride($dataobj-raise)} {
647                    set dlist [linsert $dlist 0 $dataobj]
648                } else {
649                    lappend dlist $dataobj
650                }
651            }
652            return $dlist
653        }
654        "-visible" {
655            set dlist {}
656            foreach dataobj $_dlist {
657                if { ![IsValidObject $dataobj] } {
658                    continue
659                }
660                if { ![info exists _obj2ovride($dataobj-raise)] } {
661                    # No setting indicates that the object isn't visible.
662                    continue
663                }
664                # Otherwise use the -raise parameter to put the object to
665                # the front of the list.
666                if { $_obj2ovride($dataobj-raise) } {
667                    set dlist [linsert $dlist 0 $dataobj]
668                } else {
669                    lappend dlist $dataobj
670                }
671            }
672            return $dlist
673        }           
674        -image {
675            if {[llength $args] != 2} {
676                error "wrong # args: should be \"get -image view\""
677            }
678            switch -- [lindex $args end] {
679                view {
680                    return $_image(plot)
681                }
682                default {
683                    error "bad image name \"[lindex $args end]\": should be view"
684                }
685            }
686        }
687        default {
688            error "bad option \"$op\": should be -objects or -image"
689        }
690    }
691}
692
693# ----------------------------------------------------------------------
694# USAGE: scale ?<data1> <data2> ...?
695#
696# Sets the default limits for the overall plot according to the
697# limits of the data for all of the given <data> objects.  This
698# accounts for all objects--even those not showing on the screen.
699# Because of this, the limits are appropriate for all objects as
700# the user scans through data in the ResultSet viewer.
701# ----------------------------------------------------------------------
702itcl::body Rappture::VtkIsosurfaceViewer::scale { args } {
703    foreach dataobj $args {
[3571]704        if { ![$dataobj isvalid] } {
705            continue;                   # Object doesn't contain valid data.
706        }
[3440]707        foreach axis { x y z } {
708            set lim [$dataobj limits $axis]
709            if { ![info exists _limits($axis)] } {
710                set _limits($axis) $lim
711                continue
712            }
713            foreach {min max} $lim break
714            foreach {amin amax} $_limits($axis) break
715            if { $amin > $min } {
716                set amin $min
717            }
718            if { $amax < $max } {
719                set amax $max
720            }
721            set _limits($axis) [list $amin $amax]
[3330]722        }
[3440]723        foreach { fname lim } [$dataobj fieldlimits] {
724            if { ![info exists _limits($fname)] } {
725                set _limits($fname) $lim
726                continue
727            }
728            foreach {min max} $lim break
729            foreach {fmin fmax} $_limits($fname) break
730            if { $fmin > $min } {
731                set fmin $min
732            }
733            if { $fmax < $max } {
734                set fmax $max
735            }
736            set _limits($fname) [list $fmin $fmax]
737        }
[3330]738    }
739}
740
741# ----------------------------------------------------------------------
742# USAGE: download coming
743# USAGE: download controls <downloadCommand>
744# USAGE: download now
745#
746# Clients use this method to create a downloadable representation
747# of the plot.  Returns a list of the form {ext string}, where
748# "ext" is the file extension (indicating the type of data) and
749# "string" is the data itself.
750# ----------------------------------------------------------------------
751itcl::body Rappture::VtkIsosurfaceViewer::download {option args} {
752    switch $option {
753        coming {
754            if {[catch {
755                blt::winop snap $itk_component(plotarea) $_image(download)
756            }]} {
757                $_image(download) configure -width 1 -height 1
758                $_image(download) put #000000
759            }
760        }
761        controls {
762            set popup .vtkviewerdownload
763            if { ![winfo exists .vtkviewerdownload] } {
764                set inner [BuildDownloadPopup $popup [lindex $args 0]]
765            } else {
766                set inner [$popup component inner]
767            }
768            set _downloadPopup(image_controls) $inner.image_frame
769            set num [llength [get]]
770            set num [expr {($num == 1) ? "1 result" : "$num results"}]
771            set word [Rappture::filexfer::label downloadWord]
772            $inner.summary configure -text "$word $num in the following format:"
773            update idletasks            ;# Fix initial sizes
774            return $popup
775        }
776        now {
777            set popup .vtkviewerdownload
778            if {[winfo exists .vtkviewerdownload]} {
779                $popup deactivate
780            }
781            switch -- $_downloadPopup(format) {
782                "image" {
783                    return [$this GetImage [lindex $args 0]]
784                }
785                "vtk" {
786                    return [$this GetVtkData [lindex $args 0]]
787                }
788            }
789            return ""
790        }
791        default {
792            error "bad option \"$option\": should be coming, controls, now"
793        }
794    }
795}
796
797# ----------------------------------------------------------------------
798# USAGE: Connect ?<host:port>,<host:port>...?
799#
800# Clients use this method to establish a connection to a new
801# server, or to reestablish a connection to the previous server.
802# Any existing connection is automatically closed.
803# ----------------------------------------------------------------------
804itcl::body Rappture::VtkIsosurfaceViewer::Connect {} {
805    set _hosts [GetServerList "vtkvis"]
806    if { "" == $_hosts } {
807        return 0
808    }
809    set result [VisViewer::Connect $_hosts]
810    if { $result } {
[3592]811        if { $_reportClientInfo }  {
812            # Tell the server the viewer, hub, user and session.
[4186]813            # Do this immediately on connect before buffering any commands
[3592]814            global env
815
816            set info {}
817            set user "???"
818            if { [info exists env(USER)] } {
819                set user $env(USER)
820            }
821            set session "???"
822            if { [info exists env(SESSION)] } {
823                set session $env(SESSION)
824            }
[4752]825            lappend info "version" "$Rappture::version"
826            lappend info "build" "$Rappture::build"
[4754]827            lappend info "svnurl" "$Rappture::svnurl"
[4752]828            lappend info "installdir" "$Rappture::installdir"
[3592]829            lappend info "hub" [exec hostname]
830            lappend info "client" "vtkisosurfaceviewer"
831            lappend info "user" $user
832            lappend info "session" $session
833            SendCmd "clientinfo [list $info]"
834        }
835
[3330]836        set w [winfo width $itk_component(view)]
837        set h [winfo height $itk_component(view)]
838        EventuallyResize $w $h
839    }
840    return $result
841}
842
843#
844# isconnected --
845#
846#       Indicates if we are currently connected to the visualization server.
847#
848itcl::body Rappture::VtkIsosurfaceViewer::isconnected {} {
849    return [VisViewer::IsConnected]
850}
851
852#
853# disconnect --
854#
855itcl::body Rappture::VtkIsosurfaceViewer::disconnect {} {
856    Disconnect
857    set _reset 1
858}
859
860#
861# Disconnect --
862#
863#       Clients use this method to disconnect from the current rendering
864#       server.
865#
866itcl::body Rappture::VtkIsosurfaceViewer::Disconnect {} {
867    VisViewer::Disconnect
868
869    $_dispatcher cancel !rebuild
870    $_dispatcher cancel !resize
871    $_dispatcher cancel !rotate
872    $_dispatcher cancel !xcutplane
873    $_dispatcher cancel !ycutplane
874    $_dispatcher cancel !zcutplane
875    $_dispatcher cancel !legend
876    # disconnected -- no more data sitting on server
877    set _outbuf ""
[4752]878    array unset _datasets
879    array unset _data
880    array unset _colormaps
881    array unset _dataset2style
882    array unset _obj2datasets
[3330]883}
884
885# ----------------------------------------------------------------------
886# USAGE: ReceiveImage -bytes <size> -type <type> -token <token>
887#
888# Invoked automatically whenever the "image" command comes in from
889# the rendering server.  Indicates that binary image data with the
890# specified <size> will follow.
891# ----------------------------------------------------------------------
892itcl::body Rappture::VtkIsosurfaceViewer::ReceiveImage { args } {
893    array set info {
894        -token "???"
895        -bytes 0
896        -type image
897    }
898    array set info $args
899    set bytes [ReceiveBytes $info(-bytes)]
900    if { $info(-type) == "image" } {
901        if 0 {
902            set f [open "last.ppm" "w"]
903            puts $f $bytes
904            close $f
905        }
906        $_image(plot) configure -data $bytes
[4201]907        #set time [clock seconds]
908        #set date [clock format $time]
909        #set w [image width $_image(plot)]
910        #set h [image height $_image(plot)]
911        #puts stderr "$date: received image ${w}x${h} image"       
[3330]912        if { $_start > 0 } {
913            set finish [clock clicks -milliseconds]
914            #puts stderr "round trip time [expr $finish -$_start] milliseconds"
915            set _start 0
916        }
917    } elseif { $info(type) == "print" } {
918        set tag $this-print-$info(-token)
919        set _hardcopy($tag) $bytes
920    }
921}
922
923#
924# ReceiveDataset --
925#
926itcl::body Rappture::VtkIsosurfaceViewer::ReceiveDataset { args } {
927    if { ![isconnected] } {
928        return
929    }
930    set option [lindex $args 0]
931    switch -- $option {
932        "scalar" {
933            set option [lindex $args 1]
934            switch -- $option {
935                "world" {
936                    foreach { x y z value tag } [lrange $args 2 end] break
937                }
938                "pixel" {
939                    foreach { x y value tag } [lrange $args 2 end] break
940                }
941            }
942        }
943        "vector" {
944            set option [lindex $args 1]
945            switch -- $option {
946                "world" {
947                    foreach { x y z vx vy vz tag } [lrange $args 2 end] break
948                }
949                "pixel" {
950                    foreach { x y vx vy vz tag } [lrange $args 2 end] break
951                }
952            }
953        }
954        "names" {
955            foreach { name } [lindex $args 1] {
956                #puts stderr "Dataset: $name"
957            }
958        }
959        default {
960            error "unknown dataset option \"$option\" from server"
961        }
962    }
963}
964
965# ----------------------------------------------------------------------
966# USAGE: Rebuild
967#
968# Called automatically whenever something changes that affects the
969# data in the widget.  Clears any existing data and rebuilds the
970# widget to display new data.
971# ----------------------------------------------------------------------
972itcl::body Rappture::VtkIsosurfaceViewer::Rebuild {} {
973    set w [winfo width $itk_component(view)]
974    set h [winfo height $itk_component(view)]
975    if { $w < 2 || $h < 2 } {
[3530]976        $_dispatcher event -idle !rebuild
[3330]977        return
978    }
979
980    # Turn on buffering of commands to the server.  We don't want to
981    # be preempted by a server disconnect/reconnect (which automatically
982    # generates a new call to Rebuild).   
[3421]983    StartBufferingCommands
[3392]984    if { $_reset } {
985        set _width $w
986        set _height $h
987        $_arcball resize $w $h
988        DoResize
[4752]989
[3392]990        # Reset the camera and other view parameters
[4752]991        $_arcball quaternion [ViewToQuaternion]
992        InitSettings -ortho
[3392]993        DoRotate
994        PanCamera
995        set _first ""
[4752]996        InitSettings -background \
997            -xgrid -ygrid -zgrid -axismode \
998            -axesvisible -axislabels -axisminorticks
999        #SendCmd "axis lformat all %g"
[3514]1000        StopBufferingCommands
[3392]1001        SendCmd "imgflush"
[3514]1002        StartBufferingCommands
[3392]1003    }
[3330]1004    set _first ""
[4752]1005    SendCmd "dataset visible 0"
1006    eval scale $_dlist
[3330]1007    foreach dataobj [get -objects] {
1008        if { [info exists _obj2ovride($dataobj-raise)] &&  $_first == "" } {
1009            set _first $dataobj
[4752]1010            SetCurrentFieldName $dataobj
[3330]1011        }
1012        set _obj2datasets($dataobj) ""
1013        foreach comp [$dataobj components] {
1014            set tag $dataobj-$comp
1015            if { ![info exists _datasets($tag)] } {
1016                set bytes [$dataobj vtkdata $comp]
1017                if 0 {
1018                    set f [open "/tmp/isosurface.vtk" "w"]
1019                    puts $f $bytes
1020                    close $f
1021                }
1022                set length [string length $bytes]
[3421]1023                if { $_reportClientInfo }  {
[3392]1024                    set info {}
[4752]1025                    lappend info "tool_id"       [$dataobj hints toolid]
1026                    lappend info "tool_name"     [$dataobj hints toolname]
1027                    lappend info "tool_title"    [$dataobj hints tooltitle]
1028                    lappend info "tool_command"  [$dataobj hints toolcommand]
1029                    lappend info "tool_revision" [$dataobj hints toolrevision]
[3394]1030                    lappend info "dataset_label" [$dataobj hints label]
1031                    lappend info "dataset_size"  $length
1032                    lappend info "dataset_tag"   $tag
[3392]1033                    SendCmd "clientinfo [list $info]"
1034                }
[4752]1035                SendCmd "dataset add $tag data follows $length"
[3330]1036                append _outbuf $bytes
1037                set _datasets($tag) 1
1038                SetObjectStyle $dataobj $comp
1039            }
1040            lappend _obj2datasets($dataobj) $tag
1041            if { [info exists _obj2ovride($dataobj-raise)] } {
[4351]1042                SendCmd "contour3d visible 1 $tag"
[3330]1043            }
1044        }
1045    }
[3514]1046
[4752]1047    InitSettings -cutplanesvisible -isosurfacevisible -outline
[3330]1048    if { $_reset } {
1049        # These are settings that rely on a dataset being loaded.
1050        InitSettings \
[4201]1051            -isosurfacelighting \
1052            -field \
1053            -isosurfacevisible \
1054            -isosurfaceedges -isosurfacelighting -isosurfaceopacity \
1055            -isosurfacewireframe \
1056            -cutplanesvisible \
1057            -xcutplaneposition -ycutplaneposition -zcutplaneposition \
1058            -xcutplanevisible -ycutplanevisible -zcutplanevisible \
1059            -cutplanepreinterp -numcontours
[3514]1060
[3330]1061        Zoom reset
[3409]1062        foreach axis { x y z } {
1063            # Another problem fixed by a <view>. We looking into a data
1064            # object for the name of the axes. This should be global to
1065            # the viewer itself.
1066            set label [$_first hints ${axis}label]
1067            if { $label == "" } {
[3548]1068                set label [string toupper $axis]
[3409]1069            }
1070            SendCmd [list axis name $axis $label]
1071        }
[3514]1072        if { [array size _fields] < 2 } {
[4752]1073            catch {blt::table forget $itk_component(field) $itk_component(field_l)}
[3514]1074        }
[3330]1075        set _reset 0
1076    }
[4752]1077    # Redraw the legend even if we're using the same colormap. The position
1078    # of the isolines may have changed because the range of data changed.
1079    DrawLegend
[3330]1080
1081    # Actually write the commands to the server socket.  If it fails, we don't
1082    # care.  We're finished here.
1083    blt::busy hold $itk_component(hull)
[3421]1084    StopBufferingCommands;              # Turn off buffering and send commands.
[3330]1085    blt::busy release $itk_component(hull)
1086}
1087
1088# ----------------------------------------------------------------------
1089# USAGE: CurrentDatasets ?-all -visible? ?dataobjs?
1090#
1091# Returns a list of server IDs for the current datasets being displayed.  This
1092# is normally a single ID, but it might be a list of IDs if the current data
1093# object has multiple components.
1094# ----------------------------------------------------------------------
1095itcl::body Rappture::VtkIsosurfaceViewer::CurrentDatasets {args} {
1096    set flag [lindex $args 0]
1097    switch -- $flag {
1098        "-all" {
1099            if { [llength $args] > 1 } {
1100                error "CurrentDatasets: can't specify dataobj after \"-all\""
1101            }
1102            set dlist [get -objects]
1103        }
1104        "-visible" {
1105            if { [llength $args] > 1 } {
1106                set dlist {}
1107                set args [lrange $args 1 end]
1108                foreach dataobj $args {
1109                    if { [info exists _obj2ovride($dataobj-raise)] } {
1110                        lappend dlist $dataobj
1111                    }
1112                }
1113            } else {
1114                set dlist [get -visible]
1115            }
1116        }           
1117        default {
1118            set dlist $args
1119        }
1120    }
1121    set rlist ""
1122    foreach dataobj $dlist {
1123        foreach comp [$dataobj components] {
1124            set tag $dataobj-$comp
1125            if { [info exists _datasets($tag)] && $_datasets($tag) } {
1126                lappend rlist $tag
1127            }
1128        }
1129    }
1130    return $rlist
1131}
1132
1133# ----------------------------------------------------------------------
1134# USAGE: Zoom in
1135# USAGE: Zoom out
1136# USAGE: Zoom reset
1137#
1138# Called automatically when the user clicks on one of the zoom
1139# controls for this widget.  Changes the zoom for the current view.
1140# ----------------------------------------------------------------------
1141itcl::body Rappture::VtkIsosurfaceViewer::Zoom {option} {
1142    switch -- $option {
1143        "in" {
[4752]1144            set _view(-zoom) [expr {$_view(-zoom)*1.25}]
1145            SendCmd "camera zoom $_view(-zoom)"
[3330]1146        }
1147        "out" {
[4752]1148            set _view(-zoom) [expr {$_view(-zoom)*0.8}]
1149            SendCmd "camera zoom $_view(-zoom)"
[3330]1150        }
1151        "reset" {
1152            array set _view {
[4752]1153                -qw     0.853553
1154                -qx     -0.353553
1155                -qy     0.353553
1156                -qz     0.146447
1157                -xpan   0
1158                -ypan   0
1159                -zoom   1.0
[3330]1160            }
1161            if { $_first != "" } {
1162                set location [$_first hints camera]
1163                if { $location != "" } {
1164                    array set _view $location
1165                }
1166            }
[4752]1167            $_arcball quaternion [ViewToQuaternion]
[3550]1168            DoRotate
[3416]1169            SendCmd "camera reset"
[3330]1170        }
1171    }
1172}
1173
1174itcl::body Rappture::VtkIsosurfaceViewer::PanCamera {} {
[4752]1175    set x $_view(-xpan)
1176    set y $_view(-ypan)
[3330]1177    SendCmd "camera pan $x $y"
1178}
1179
1180
1181# ----------------------------------------------------------------------
1182# USAGE: Rotate click <x> <y>
1183# USAGE: Rotate drag <x> <y>
1184# USAGE: Rotate release <x> <y>
1185#
1186# Called automatically when the user clicks/drags/releases in the
1187# plot area.  Moves the plot according to the user's actions.
1188# ----------------------------------------------------------------------
1189itcl::body Rappture::VtkIsosurfaceViewer::Rotate {option x y} {
1190    switch -- $option {
1191        "click" {
1192            $itk_component(view) configure -cursor fleur
1193            set _click(x) $x
1194            set _click(y) $y
1195        }
1196        "drag" {
1197            if {[array size _click] == 0} {
1198                Rotate click $x $y
1199            } else {
1200                set w [winfo width $itk_component(view)]
1201                set h [winfo height $itk_component(view)]
1202                if {$w <= 0 || $h <= 0} {
1203                    return
1204                }
1205
1206                if {[catch {
1207                    # this fails sometimes for no apparent reason
1208                    set dx [expr {double($x-$_click(x))/$w}]
1209                    set dy [expr {double($y-$_click(y))/$h}]
1210                }]} {
1211                    return
1212                }
1213                if { $dx == 0 && $dy == 0 } {
1214                    return
1215                }
1216                set q [$_arcball rotate $x $y $_click(x) $_click(y)]
1217                EventuallyRotate $q
1218                set _click(x) $x
1219                set _click(y) $y
1220            }
1221        }
1222        "release" {
1223            Rotate drag $x $y
1224            $itk_component(view) configure -cursor ""
1225            catch {unset _click}
1226        }
1227        default {
1228            error "bad option \"$option\": should be click, drag, release"
1229        }
1230    }
1231}
1232
1233itcl::body Rappture::VtkIsosurfaceViewer::Pick {x y} {
1234    foreach tag [CurrentDatasets -visible] {
1235        SendCmdNoSplash "dataset getscalar pixel $x $y $tag"
1236    }
1237}
1238
1239# ----------------------------------------------------------------------
1240# USAGE: $this Pan click x y
1241#        $this Pan drag x y
1242#        $this Pan release x y
1243#
1244# Called automatically when the user clicks on one of the zoom
1245# controls for this widget.  Changes the zoom for the current view.
1246# ----------------------------------------------------------------------
1247itcl::body Rappture::VtkIsosurfaceViewer::Pan {option x y} {
1248    switch -- $option {
1249        "set" {
1250            set w [winfo width $itk_component(view)]
1251            set h [winfo height $itk_component(view)]
1252            set x [expr $x / double($w)]
1253            set y [expr $y / double($h)]
[4752]1254            set _view(-xpan) [expr $_view(-xpan) + $x]
1255            set _view(-ypan) [expr $_view(-ypan) + $y]
[3330]1256            PanCamera
1257            return
1258        }
1259        "click" {
1260            set _click(x) $x
1261            set _click(y) $y
1262            $itk_component(view) configure -cursor hand1
1263        }
1264        "drag" {
1265            if { ![info exists _click(x)] } {
1266                set _click(x) $x
1267            }
1268            if { ![info exists _click(y)] } {
1269                set _click(y) $y
1270            }
1271            set w [winfo width $itk_component(view)]
1272            set h [winfo height $itk_component(view)]
1273            set dx [expr ($_click(x) - $x)/double($w)]
1274            set dy [expr ($_click(y) - $y)/double($h)]
1275            set _click(x) $x
1276            set _click(y) $y
[4752]1277            set _view(-xpan) [expr $_view(-xpan) - $dx]
1278            set _view(-ypan) [expr $_view(-ypan) - $dy]
[3330]1279            PanCamera
1280        }
1281        "release" {
1282            Pan drag $x $y
1283            $itk_component(view) configure -cursor ""
1284        }
1285        default {
1286            error "unknown option \"$option\": should set, click, drag, or release"
1287        }
1288    }
1289}
1290
1291# ----------------------------------------------------------------------
1292# USAGE: InitSettings <what> ?<value>?
1293#
1294# Used internally to update rendering settings whenever parameters
1295# change in the popup settings panel.  Sends the new settings off
1296# to the back end.
1297# ----------------------------------------------------------------------
1298itcl::body Rappture::VtkIsosurfaceViewer::InitSettings { args } {
1299    foreach spec $args {
1300        if { [info exists _settings($_first-$spec)] } {
1301            # Reset global setting with dataobj specific setting
1302            set _settings($spec) $_settings($_first-$spec)
1303        }
1304        AdjustSetting $spec
1305    }
1306}
1307
1308#
1309# AdjustSetting --
1310#
1311#       Changes/updates a specific setting in the widget.  There are
1312#       usually user-setable option.  Commands are sent to the render
1313#       server.
1314#
1315itcl::body Rappture::VtkIsosurfaceViewer::AdjustSetting {what {value ""}} {
1316    if { ![isconnected] } {
1317        return
1318    }
1319    switch -- $what {
[4201]1320        "-axesvisible" {
[4752]1321            set bool $_settings($what)
[3330]1322            SendCmd "axis visible all $bool"
1323        }
[4752]1324        "-axislabels" {
1325            set bool $_settings($what)
[3330]1326            SendCmd "axis labels all $bool"
1327        }
[4752]1328        "-axisminorticks" {
[3330]1329            set bool $_settings($what)
[4752]1330            SendCmd "axis minticks all $bool"
[3330]1331        }
[4201]1332        "-axismode" {
[3330]1333            set mode [$itk_component(axisMode) value]
1334            set mode [$itk_component(axisMode) translate $mode]
1335            set _settings($what) $mode
1336            SendCmd "axis flymode $mode"
1337        }
[4752]1338        "-background" {
1339            set bgcolor [$itk_component(background) value]
1340            array set fgcolors {
1341                "black" "white"
1342                "white" "black"
1343                "grey"  "black"
1344            }
1345            configure -plotbackground $bgcolor \
1346                -plotforeground $fgcolors($bgcolor)
1347            $itk_component(view) delete "legend"
1348            DrawLegend
1349        }
[4201]1350        "-cutplaneedges" {
[3330]1351            set bool $_settings($what)
[3514]1352            SendCmd "cutplane edges $bool"
[3330]1353        }
[4201]1354        "-cutplanelighting" {
[3330]1355            set bool $_settings($what)
[3514]1356            SendCmd "cutplane lighting $bool"
[3330]1357        }
[4201]1358        "-cutplaneopacity" {
[4752]1359            set _settings($what) [expr $_widget($what) * 0.01]
1360            SendCmd "cutplane opacity $_settings($what)"
[3330]1361        }
[4201]1362        "-cutplanepreinterp" {
[3517]1363            set bool $_settings($what)
1364            SendCmd "cutplane preinterp $bool"
1365        }
[4752]1366        "-cutplanesvisible" {
[3330]1367            set bool $_settings($what)
[4752]1368            SendCmd "cutplane visible 0"
[3330]1369            if { $bool } {
[4752]1370                foreach tag [CurrentDatasets -visible] {
1371                    SendCmd "cutplane visible $bool $tag"
1372                }
1373            }
1374            if { $bool } {
1375                Rappture::Tooltip::for $itk_component(cutplane) \
1376                    "Hide the cutplanes"
[3330]1377            } else {
[4752]1378                Rappture::Tooltip::for $itk_component(cutplane) \
1379                    "Show the cutplanes"
[3330]1380            }
1381        }
[4752]1382        "-cutplanewireframe" {
1383            set bool $_settings($what)
1384            SendCmd "cutplane wireframe $bool"
[3330]1385        }
[4201]1386        "-colormap" {
[4752]1387            set _changed($what) 1
[3514]1388            StartBufferingCommands
1389            set color [$itk_component(colormap) value]
[4752]1390            set _settings($what) $color
[3330]1391            if { $color == "none" } {
[4201]1392                if { $_settings(-colormapvisible) } {
[3843]1393                    SendCmd "contour3d colormode constant {}"
[4201]1394                    set _settings(-colormapvisible) 0
[3330]1395                }
1396            } else {
[4201]1397                if { !$_settings(-colormapvisible) } {
[3780]1398                    SendCmd "contour3d colormode $_colorMode $_curFldName"
[4201]1399                    set _settings(-colormapvisible) 1
[3330]1400                }
[3514]1401                SetCurrentColormap $color
[3330]1402            }
[3514]1403            StopBufferingCommands
[3330]1404            EventuallyRequestLegend
1405        }
[4201]1406        "-field" {
[3442]1407            set label [$itk_component(field) value]
1408            set fname [$itk_component(field) translate $label]
[4201]1409            set _settings($what) $fname
[3442]1410            if { [info exists _fields($fname)] } {
1411                foreach { label units components } $_fields($fname) break
1412                if { $components > 1 } {
1413                    set _colorMode vmag
1414                } else {
1415                    set _colorMode scalar
1416                }
1417                set _curFldName $fname
1418                set _curFldLabel $label
[3330]1419            } else {
[3442]1420                puts stderr "unknown field \"$fname\""
[3330]1421                return
1422            }
[3555]1423            SendCmd "dataset scalar $_curFldName"
[4351]1424            if { ![info exists _limits($_curFldName)] } {
1425                SendCmd "dataset maprange all"
1426            } else {
1427                SendCmd "dataset maprange explicit $_limits($_curFldName) $_curFldName"
1428            }
[3555]1429            SendCmd "cutplane colormode $_colorMode $_curFldName"
[3442]1430            SendCmd "contour3d colormode $_colorMode $_curFldName"
1431            SendCmd "camera reset"
[4752]1432            GenerateContourList
[3442]1433            DrawLegend
[3330]1434        }
[4752]1435        "-isolinecolor" {
1436            set color [$itk_component(isolineColor) value]
1437            set _settings($what) $color
1438            DrawLegend
1439        }
1440        "-isosurfaceedges" {
1441            set bool $_settings($what)
1442            SendCmd "contour3d edges $bool"
1443        }
1444        "-isosurfacelighting" {
1445            set bool $_settings($what)
1446            SendCmd "contour3d lighting $bool"
1447        }
1448        "-isosurfaceopacity" {
1449            set _settings($what) [expr $_widget($what) * 0.01]
1450            SendCmd "contour3d opacity $_settings($what)"
1451        }
1452        "-isosurfacevisible" {
1453            set bool $_settings($what)
1454            SendCmd "contour3d visible 0"
1455            if { $bool } {
1456                foreach tag [CurrentDatasets -visible] {
1457                    SendCmd "contour3d visible $bool $tag"
1458                }
1459            }
1460            if { $bool } {
1461                Rappture::Tooltip::for $itk_component(contour) \
1462                    "Hide the isosurface"
1463            } else {
1464                Rappture::Tooltip::for $itk_component(contour) \
1465                    "Show the isosurface"
1466            }
1467        }
1468        "-isosurfacewireframe" {
1469            set bool $_settings($what)
1470            SendCmd "contour3d wireframe $bool"
1471        }
[4201]1472        "-legendvisible" {
1473            if { !$_settings($what) } {
[3330]1474                $itk_component(view) delete legend
1475            }
[3442]1476            DrawLegend
[3330]1477        }
[4752]1478        "-numcontours" {
1479            set _settings($what) [$itk_component(numcontours) value]
1480            if { $_contourList(numLevels) != $_settings($what) } {
1481                set _contourList(numLevels) $_settings($what)
1482                EventuallyChangeContourLevels
1483            }
1484        }
1485        "-ortho" {
1486            set bool $_view($what)
1487            if { $bool } {
1488                SendCmd "camera mode ortho"
1489            } else {
1490                SendCmd "camera mode persp"
1491            }
1492        }
1493        "-outline" {
1494            set bool $_settings($what)
1495            SendCmd "outline visible 0"
1496            if { $bool } {
1497                foreach tag [CurrentDatasets -visible] {
1498                    SendCmd "outline visible $bool $tag"
1499                }
1500            }
1501        }
1502        "-xcutplanevisible" - "-ycutplanevisible" - "-zcutplanevisible" {
1503            set axis [string tolower [string range $what 1 1]]
1504            set bool $_settings($what)
1505            if { $bool } {
1506                $itk_component(${axis}position) configure -state normal \
1507                    -troughcolor white
1508            } else {
1509                $itk_component(${axis}position) configure -state disabled \
1510                    -troughcolor grey82
1511            }
1512            SendCmd "cutplane axis $axis $bool"
1513        }
1514        "-xcutplaneposition" - "-ycutplaneposition" - "-zcutplaneposition" {
1515            set axis [string tolower [string range $what 1 1]]
1516            set pos [expr $_settings($what) * 0.01]
1517            SendCmd "cutplane slice ${axis} ${pos}"
1518            set _cutplanePending 0
1519        }
1520        "-xgrid" - "-ygrid" - "-zgrid" {
1521            set axis [string tolower [string range $what 1 1]]
1522            set bool $_settings($what)
1523            SendCmd "axis grid $axis $bool"
1524        }
[3330]1525        default {
1526            error "don't know how to fix $what"
1527        }
1528    }
1529}
1530
1531
1532#
1533# RequestLegend --
1534#
1535#       Request a new legend from the server.  The size of the legend
1536#       is determined from the height of the canvas. 
1537#
1538# This should be called when
1539#       1.  A new current colormap is set.
1540#       2.  Window is resized.
1541#       3.  The limits of the data have changed.  (Just need a redraw).
1542#       4.  Number of isolines have changed. (Just need a redraw).
1543#       5.  Legend becomes visible (Just need a redraw).
1544#
1545itcl::body Rappture::VtkIsosurfaceViewer::RequestLegend {} {
[3780]1546    set _legendPending 0
[3445]1547    if { ![info exists _fields($_curFldName)] } {
1548        return
1549    }
1550    set fname $_curFldName
[3330]1551    set font "Arial 8"
1552    set lineht [font metrics $font -linespace]
1553    set w 12
1554    set h [expr {$_height - 2 * ($lineht + 2)}]
[4186]1555    if { $h < 1 } {
[3330]1556        return
1557    }
[3445]1558    if { [string match "component*" $fname] } {
1559        set title ""
1560    } else {
1561        if { [info exists _fields($fname)] } {
1562            foreach { title units } $_fields($fname) break
1563            if { $units != "" } {
1564                set title [format "%s (%s)" $title $units]
1565            }
1566        } else {
1567            set title $fname
[3330]1568        }
1569    }
[3879]1570    # If there's a title too, subtract one more line
[3445]1571    if { $title != "" } {
1572        incr h -$lineht
1573    }
[3330]1574    # Set the legend on the first heightmap dataset.
1575    if { $_currentColormap != ""  } {
1576        set cmap $_currentColormap
[3445]1577        SendCmdNoWait "legend $cmap scalar $_curFldName {} $w $h 0"
[3330]1578    }
1579}
1580
1581# ----------------------------------------------------------------------
1582# CONFIGURATION OPTION: -plotbackground
1583# ----------------------------------------------------------------------
1584itcl::configbody Rappture::VtkIsosurfaceViewer::plotbackground {
1585    if { [isconnected] } {
[3358]1586        set rgb [Color2RGB $itk_option(-plotbackground)]
1587        SendCmd "screen bgcolor $rgb"
[3330]1588    }
1589}
1590
1591# ----------------------------------------------------------------------
1592# CONFIGURATION OPTION: -plotforeground
1593# ----------------------------------------------------------------------
1594itcl::configbody Rappture::VtkIsosurfaceViewer::plotforeground {
1595    if { [isconnected] } {
[3358]1596        set rgb [Color2RGB $itk_option(-plotforeground)]
1597        SendCmd "axis color all $rgb"
[3544]1598        SendCmd "outline color $rgb"
[3843]1599        SendCmd "cutplane color $rgb"
[3330]1600    }
1601}
1602
1603itcl::body Rappture::VtkIsosurfaceViewer::BuildIsosurfaceTab {} {
1604
1605    set fg [option get $itk_component(hull) font Font]
1606    #set bfg [option get $itk_component(hull) boldFont Font]
1607
1608    set inner [$itk_component(main) insert end \
1609        -title "Isosurface Settings" \
1610        -icon [Rappture::icon volume-on]]
1611    $inner configure -borderwidth 4
1612
1613    checkbutton $inner.contour \
1614        -text "Isosurfaces" \
[4201]1615        -variable [itcl::scope _settings(-isosurfacevisible)] \
1616        -command [itcl::code $this AdjustSetting -isosurfacevisible] \
[3330]1617        -font "Arial 9"
1618
1619    checkbutton $inner.wireframe \
1620        -text "Wireframe" \
[4201]1621        -variable [itcl::scope _settings(-isosurfacewireframe)] \
1622        -command [itcl::code $this AdjustSetting -isosurfacewireframe] \
[3330]1623        -font "Arial 9"
1624
1625    checkbutton $inner.lighting \
1626        -text "Enable Lighting" \
[4201]1627        -variable [itcl::scope _settings(-isosurfacelighting)] \
1628        -command [itcl::code $this AdjustSetting -isosurfacelighting] \
[3330]1629        -font "Arial 9"
1630
1631    checkbutton $inner.edges \
1632        -text "Edges" \
[4201]1633        -variable [itcl::scope _settings(-isosurfaceedges)] \
1634        -command [itcl::code $this AdjustSetting -isosurfaceedges] \
[3330]1635        -font "Arial 9"
1636
1637    checkbutton $inner.outline \
1638        -text "Outline" \
[4752]1639        -variable [itcl::scope _settings(-outline)] \
1640        -command [itcl::code $this AdjustSetting -outline] \
[3330]1641        -font "Arial 9"
1642
1643    checkbutton $inner.legend \
1644        -text "Legend" \
[4201]1645        -variable [itcl::scope _settings(-legendvisible)] \
1646        -command [itcl::code $this AdjustSetting -legendvisible] \
[3330]1647        -font "Arial 9"
1648
1649    label $inner.linecolor_l -text "Isolines" -font "Arial 9"
1650    itk_component add isolineColor {
[4201]1651        Rappture::Combobox $inner.linecolor -width 10 -editable 0
[3330]1652    }
1653    $inner.linecolor choices insert end \
1654        "black"              "black"            \
1655        "blue"               "blue"             \
1656        "cyan"               "cyan"             \
1657        "green"              "green"            \
1658        "grey"               "grey"             \
1659        "magenta"            "magenta"          \
1660        "orange"             "orange"           \
1661        "red"                "red"              \
1662        "white"              "white"            \
1663        "none"               "none"
1664
1665    $itk_component(isolineColor) value "white"
1666    bind $inner.linecolor <<Value>> \
[4341]1667        [itcl::code $this AdjustSetting -isolinecolor]
[3330]1668
1669    label $inner.background_l -text "Background" -font "Arial 9"
1670    itk_component add background {
[4201]1671        Rappture::Combobox $inner.background -width 10 -editable 0
[3330]1672    }
1673    $inner.background choices insert end \
1674        "black"              "black"            \
1675        "white"              "white"            \
1676        "grey"               "grey"             
1677
[4201]1678    $itk_component(background) value $_settings(-background)
1679    bind $inner.background <<Value>> \
1680        [itcl::code $this AdjustSetting -background]
[3330]1681
1682    label $inner.opacity_l -text "Opacity" -font "Arial 9"
1683    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
[4752]1684        -variable [itcl::scope _widget(-isosurfaceopacity)] \
[3330]1685        -width 10 \
1686        -showvalue off \
[4201]1687        -command [itcl::code $this AdjustSetting -isosurfaceopacity]
[4752]1688    $inner.opacity set [expr $_settings(-isosurfaceopacity) * 100.0]
[3330]1689
[3514]1690    itk_component add field_l {
1691        label $inner.field_l -text "Field" -font "Arial 9"
1692    } {
1693        ignore -font
1694    }
[3330]1695    itk_component add field {
[4201]1696        Rappture::Combobox $inner.field -width 10 -editable 0
[3330]1697    }
1698    bind $inner.field <<Value>> \
[4201]1699        [itcl::code $this AdjustSetting -field]
[3330]1700
[3514]1701    label $inner.colormap_l -text "Colormap" -font "Arial 9"
1702    itk_component add colormap {
[4201]1703        Rappture::Combobox $inner.colormap -width 10 -editable 0
[3330]1704    }
[4752]1705    $inner.colormap choices insert end [GetColormapList]
[3330]1706
[3514]1707    $itk_component(colormap) value "BCGYR"
1708    bind $inner.colormap <<Value>> \
[4201]1709        [itcl::code $this AdjustSetting -colormap]
[3330]1710
[3514]1711    label $inner.numcontours_l -text "Number of Isosurfaces" -font "Arial 9"
1712    itk_component add numcontours {
1713        Rappture::Spinint $inner.numcontours \
[4186]1714            -min 0 -max 50 -font "arial 9"
[3514]1715    }
[4201]1716    $itk_component(numcontours) value $_settings(-numcontours)
[3514]1717    bind $itk_component(numcontours) <<Value>> \
[4201]1718        [itcl::code $this AdjustSetting -numcontours]
[3514]1719
[3330]1720    blt::table $inner \
[3514]1721        0,0 $inner.field_l   -anchor w -pady 2  \
1722        0,1 $inner.field     -anchor w -pady 2  -fill x \
1723        1,0 $inner.colormap_l -anchor w -pady 2  \
1724        1,1 $inner.colormap   -anchor w -pady 2  -fill x \
1725        2,0 $inner.linecolor_l  -anchor w -pady 2  \
1726        2,1 $inner.linecolor    -anchor w -pady 2 -fill x  \
1727        3,0 $inner.background_l -anchor w -pady 2 \
1728        3,1 $inner.background -anchor w -pady 2  -fill x \
1729        4,0 $inner.numcontours_l -anchor w -pady 2 \
1730        4,1 $inner.numcontours -anchor w -pady 2 \
1731        5,0 $inner.wireframe -anchor w -pady 2 -cspan 2 \
1732        6,0 $inner.lighting  -anchor w -pady 2 -cspan 2 \
1733        7,0 $inner.edges     -anchor w -pady 2 -cspan 2 \
1734        8,0 $inner.outline   -anchor w -pady 2 -cspan 2 \
1735        9,0 $inner.legend    -anchor w -pady 2 \
1736        10,0 $inner.opacity_l -anchor w -pady 2 \
1737        10,1 $inner.opacity   -fill x   -pady 2 -fill x \
[3330]1738
1739    blt::table configure $inner r* c* -resize none
1740    blt::table configure $inner r11 c1 -resize expand
1741}
1742
1743itcl::body Rappture::VtkIsosurfaceViewer::BuildAxisTab {} {
1744
1745    set fg [option get $itk_component(hull) font Font]
1746    #set bfg [option get $itk_component(hull) boldFont Font]
1747
1748    set inner [$itk_component(main) insert end \
1749        -title "Axis Settings" \
[3517]1750        -icon [Rappture::icon axis2]]
[3330]1751    $inner configure -borderwidth 4
1752
1753    checkbutton $inner.visible \
[4752]1754        -text "Axes" \
[4201]1755        -variable [itcl::scope _settings(-axesvisible)] \
1756        -command [itcl::code $this AdjustSetting -axesvisible] \
[3330]1757        -font "Arial 9"
1758
1759    checkbutton $inner.labels \
[4752]1760        -text "Axis Labels" \
1761        -variable [itcl::scope _settings(-axislabels)] \
1762        -command [itcl::code $this AdjustSetting -axislabels] \
[3330]1763        -font "Arial 9"
[4752]1764    label $inner.grid_l -text "Grid" -font "Arial 9"
1765    checkbutton $inner.xgrid \
1766        -text "X" \
1767        -variable [itcl::scope _settings(-xgrid)] \
1768        -command [itcl::code $this AdjustSetting -xgrid] \
[3330]1769        -font "Arial 9"
[4752]1770    checkbutton $inner.ygrid \
1771        -text "Y" \
1772        -variable [itcl::scope _settings(-ygrid)] \
1773        -command [itcl::code $this AdjustSetting -ygrid] \
[3330]1774        -font "Arial 9"
[4752]1775    checkbutton $inner.zgrid \
1776        -text "Z" \
1777        -variable [itcl::scope _settings(-zgrid)] \
1778        -command [itcl::code $this AdjustSetting -zgrid] \
[3330]1779        -font "Arial 9"
[4752]1780    checkbutton $inner.minorticks \
1781        -text "Minor Ticks" \
1782        -variable [itcl::scope _settings(-axisminorticks)] \
1783        -command [itcl::code $this AdjustSetting -axisminorticks] \
1784        -font "Arial 9"
[3330]1785
1786    label $inner.mode_l -text "Mode" -font "Arial 9"
1787
1788    itk_component add axisMode {
[4201]1789        Rappture::Combobox $inner.mode -width 10 -editable 0
[3330]1790    }
1791    $inner.mode choices insert end \
1792        "static_triad"    "static" \
1793        "closest_triad"   "closest" \
[4186]1794        "furthest_triad"  "farthest" \
[3330]1795        "outer_edges"     "outer"         
[4752]1796    $itk_component(axisMode) value $_settings(-axismode)
[4201]1797    bind $inner.mode <<Value>> [itcl::code $this AdjustSetting -axismode]
[3330]1798
1799    blt::table $inner \
[4752]1800        0,0 $inner.visible -anchor w -cspan 4 \
1801        1,0 $inner.labels  -anchor w -cspan 4 \
1802        2,0 $inner.minorticks  -anchor w -cspan 4 \
1803        4,0 $inner.grid_l  -anchor w \
1804        4,1 $inner.xgrid   -anchor w \
1805        4,2 $inner.ygrid   -anchor w \
1806        4,3 $inner.zgrid   -anchor w \
1807        5,0 $inner.mode_l  -anchor w -padx { 2 0 } \
1808        5,1 $inner.mode    -fill x   -cspan 3
[3330]1809
1810    blt::table configure $inner r* c* -resize none
[4752]1811    blt::table configure $inner r7 c6 -resize expand
1812    blt::table configure $inner r3 -height 0.125i
[3330]1813}
1814
1815
1816itcl::body Rappture::VtkIsosurfaceViewer::BuildCameraTab {} {
1817    set inner [$itk_component(main) insert end \
1818        -title "Camera Settings" \
1819        -icon [Rappture::icon camera]]
1820    $inner configure -borderwidth 4
1821
[3517]1822    label $inner.view_l -text "view" -font "Arial 9"
1823    set f [frame $inner.view]
1824    foreach side { front back left right top bottom } {
1825        button $f.$side  -image [Rappture::icon view$side] \
1826            -command [itcl::code $this SetOrientation $side]
1827        Rappture::Tooltip::for $f.$side "Change the view to $side"
1828        pack $f.$side -side left
1829    }
1830
1831    blt::table $inner \
[3536]1832        0,0 $inner.view_l -anchor e -pady 2 \
1833        0,1 $inner.view -anchor w -pady 2
[4752]1834    blt::table configure $inner r0 -resize none
[3517]1835
[3330]1836    set labels { qx qy qz qw xpan ypan zoom }
[3517]1837    set row 1
[3330]1838    foreach tag $labels {
1839        label $inner.${tag}label -text $tag -font "Arial 9"
1840        entry $inner.${tag} -font "Arial 9"  -bg white \
[4752]1841            -textvariable [itcl::scope _view(-$tag)]
[3330]1842        bind $inner.${tag} <KeyPress-Return> \
1843            [itcl::code $this camera set ${tag}]
1844        blt::table $inner \
1845            $row,0 $inner.${tag}label -anchor e -pady 2 \
1846            $row,1 $inner.${tag} -anchor w -pady 2
1847        blt::table configure $inner r$row -resize none
1848        incr row
1849    }
1850    checkbutton $inner.ortho \
1851        -text "Orthographic Projection" \
[4752]1852        -variable [itcl::scope _view(-ortho)] \
1853        -command [itcl::code $this AdjustSetting -ortho] \
[3330]1854        -font "Arial 9"
1855    blt::table $inner \
[3441]1856            $row,0 $inner.ortho -cspan 2 -anchor w -pady 2
[3330]1857    blt::table configure $inner r$row -resize none
1858    incr row
1859
[4752]1860    blt::table configure $inner c* -resize none
[3330]1861    blt::table configure $inner c2 -resize expand
1862    blt::table configure $inner r$row -resize expand
1863}
1864
1865itcl::body Rappture::VtkIsosurfaceViewer::BuildCutplaneTab {} {
1866
1867    set fg [option get $itk_component(hull) font Font]
1868   
1869    set inner [$itk_component(main) insert end \
1870        -title "Cutplane Settings" \
1871        -icon [Rappture::icon cutbutton]]
1872
1873    $inner configure -borderwidth 4
1874
1875    checkbutton $inner.visible \
1876        -text "Cutplanes" \
[4201]1877        -variable [itcl::scope _settings(-cutplanesvisible)] \
1878        -command [itcl::code $this AdjustSetting -cutplanesvisible] \
[3330]1879        -font "Arial 9"
1880
1881    checkbutton $inner.wireframe \
1882        -text "Wireframe" \
[4201]1883        -variable [itcl::scope _settings(-cutplanewireframe)] \
1884        -command [itcl::code $this AdjustSetting -cutplanewireframe] \
[3330]1885        -font "Arial 9"
1886
1887    checkbutton $inner.lighting \
1888        -text "Enable Lighting" \
[4201]1889        -variable [itcl::scope _settings(-cutplanelighting)] \
1890        -command [itcl::code $this AdjustSetting -cutplanelighting] \
[3330]1891        -font "Arial 9"
1892
1893    checkbutton $inner.edges \
1894        -text "Edges" \
[4201]1895        -variable [itcl::scope _settings(-cutplaneedges)] \
1896        -command [itcl::code $this AdjustSetting -cutplaneedges] \
[3330]1897        -font "Arial 9"
1898
[3517]1899    checkbutton $inner.preinterp \
[3536]1900        -text "Interpolate Scalars" \
[4201]1901        -variable [itcl::scope _settings(-cutplanepreinterp)] \
1902        -command [itcl::code $this AdjustSetting -cutplanepreinterp] \
[3517]1903        -font "Arial 9"
1904
[3330]1905    label $inner.opacity_l -text "Opacity" -font "Arial 9"
1906    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
[4752]1907        -variable [itcl::scope _widget(-cutplaneopacity)] \
[3330]1908        -width 10 \
1909        -showvalue off \
[4201]1910        -command [itcl::code $this AdjustSetting -cutplaneopacity]
[4752]1911    $inner.opacity set [expr $_settings(-cutplaneopacity) * 100.0]
[3330]1912
1913    # X-value slicer...
1914    itk_component add xbutton {
1915        Rappture::PushButton $inner.xbutton \
1916            -onimage [Rappture::icon x-cutplane-red] \
1917            -offimage [Rappture::icon x-cutplane-red] \
[4201]1918            -command [itcl::code $this AdjustSetting -xcutplanevisible] \
1919            -variable [itcl::scope _settings(-xcutplanevisible)] \
[3330]1920    }
1921    Rappture::Tooltip::for $itk_component(xbutton) \
1922        "Toggle the X-axis cutplane on/off"
1923    $itk_component(xbutton) select
1924    itk_component add xposition {
1925        ::scale $inner.xval -from 100 -to 0 \
[4201]1926            -width 10 -orient vertical -showvalue 1 \
[3330]1927            -borderwidth 1 -highlightthickness 0 \
1928            -command [itcl::code $this EventuallySetCutplane x] \
[4201]1929            -variable [itcl::scope _settings(-xcutplaneposition)] \
[3332]1930            -foreground red2 -font "Arial 9 bold"
[3330]1931    } {
1932        usual
1933        ignore -borderwidth -highlightthickness -foreground -font -background
1934    }
1935    # Set the default cutplane value before disabling the scale.
1936    $itk_component(xposition) set 50
1937    $itk_component(xposition) configure -state disabled
1938    Rappture::Tooltip::for $itk_component(xposition) \
1939        "@[itcl::code $this Slice tooltip x]"
1940
1941    # Y-value slicer...
1942    itk_component add ybutton {
1943        Rappture::PushButton $inner.ybutton \
1944            -onimage [Rappture::icon y-cutplane-green] \
1945            -offimage [Rappture::icon y-cutplane-green] \
[4201]1946            -command [itcl::code $this AdjustSetting -ycutplanevisible] \
1947            -variable [itcl::scope _settings(-ycutplanevisible)] \
[3330]1948    }
1949    Rappture::Tooltip::for $itk_component(ybutton) \
1950        "Toggle the Y-axis cutplane on/off"
1951    $itk_component(ybutton) select
1952
1953    itk_component add yposition {
1954        ::scale $inner.yval -from 100 -to 0 \
[4201]1955            -width 10 -orient vertical -showvalue 1 \
[3330]1956            -borderwidth 1 -highlightthickness 0 \
1957            -command [itcl::code $this EventuallySetCutplane y] \
[4201]1958            -variable [itcl::scope _settings(-ycutplaneposition)] \
[3330]1959            -foreground green3 -font "Arial 9 bold"
1960    } {
1961        usual
1962        ignore -borderwidth -highlightthickness -foreground -font
1963    }
1964    Rappture::Tooltip::for $itk_component(yposition) \
1965        "@[itcl::code $this Slice tooltip y]"
1966    # Set the default cutplane value before disabling the scale.
1967    $itk_component(yposition) set 50
1968    $itk_component(yposition) configure -state disabled
1969
1970    # Z-value slicer...
1971    itk_component add zbutton {
1972        Rappture::PushButton $inner.zbutton \
1973            -onimage [Rappture::icon z-cutplane-blue] \
1974            -offimage [Rappture::icon z-cutplane-blue] \
[4201]1975            -command [itcl::code $this AdjustSetting -zcutplanevisible] \
1976            -variable [itcl::scope _settings(-zcutplanevisible)] \
[3330]1977    } {
1978        usual
1979        ignore -foreground
1980    }
1981    Rappture::Tooltip::for $itk_component(zbutton) \
1982        "Toggle the Z-axis cutplane on/off"
1983    $itk_component(zbutton) select
1984
1985    itk_component add zposition {
1986        ::scale $inner.zval -from 100 -to 0 \
[4201]1987            -width 10 -orient vertical -showvalue 1 \
[3330]1988            -borderwidth 1 -highlightthickness 0 \
1989            -command [itcl::code $this EventuallySetCutplane z] \
[4201]1990            -variable [itcl::scope _settings(-zcutplaneposition)] \
[3330]1991            -foreground blue3 -font "Arial 9 bold"
1992    } {
1993        usual
1994        ignore -borderwidth -highlightthickness -foreground -font
1995    }
1996    $itk_component(zposition) set 50
1997    $itk_component(zposition) configure -state disabled
1998    Rappture::Tooltip::for $itk_component(zposition) \
1999        "@[itcl::code $this Slice tooltip z]"
2000
2001    blt::table $inner \
2002        0,0 $inner.visible              -anchor w -pady 2 -cspan 3 \
2003        1,0 $inner.lighting             -anchor w -pady 2 -cspan 3 \
2004        2,0 $inner.wireframe            -anchor w -pady 2 -cspan 3 \
2005        3,0 $inner.edges                -anchor w -pady 2 -cspan 3 \
[3517]2006        4,0 $inner.preinterp            -anchor w -pady 2 -cspan 3 \
2007        5,0 $inner.opacity_l            -anchor w -pady 2 -cspan 1 \
2008        5,1 $inner.opacity              -fill x   -pady 2 -cspan 3 \
[3330]2009        6,0 $inner.xbutton              -anchor w -padx 2 -pady 2 \
2010        7,0 $inner.ybutton              -anchor w -padx 2 -pady 2 \
2011        8,0 $inner.zbutton              -anchor w -padx 2 -pady 2 \
2012        6,1 $inner.xval                 -fill y -rspan 4 \
2013        6,2 $inner.yval                 -fill y -rspan 4 \
2014        6,3 $inner.zval                 -fill y -rspan 4 \
2015
2016
2017    blt::table configure $inner r* c* -resize none
2018    blt::table configure $inner r9 c4 -resize expand
2019}
2020
2021
2022
2023#
2024#  camera --
2025#
2026itcl::body Rappture::VtkIsosurfaceViewer::camera {option args} {
2027    switch -- $option {
2028        "show" {
2029            puts [array get _view]
2030        }
2031        "set" {
[4752]2032            set what [lindex $args 0]
2033            set x $_view($what)
[3330]2034            set code [catch { string is double $x } result]
2035            if { $code != 0 || !$result } {
2036                return
2037            }
[4752]2038            switch -- $what {
2039                "-ortho" {
2040                    if {$_view($what)} {
[3330]2041                        SendCmd "camera mode ortho"
2042                    } else {
2043                        SendCmd "camera mode persp"
2044                    }
2045                }
[4752]2046                "-xpan" - "-ypan" {
[3330]2047                    PanCamera
2048                }
[4752]2049                "-qx" - "-qy" - "-qz" - "-qw" {
2050                    set q [ViewToQuaternion]
[3330]2051                    $_arcball quaternion $q
2052                    EventuallyRotate $q
2053                }
[4752]2054                "-zoom" {
2055                    SendCmd "camera zoom $_view(-zoom)"
[3330]2056                }
2057             }
2058        }
2059    }
2060}
2061
2062itcl::body Rappture::VtkIsosurfaceViewer::GetVtkData { args } {
2063    set bytes ""
2064    foreach dataobj [get] {
2065        foreach cname [$dataobj components] {
2066            set tag $dataobj-$cname
2067            set contents [$dataobj vtkdata $cname]
[3780]2068            append bytes "$contents\n"
[3330]2069        }
2070    }
2071    return [list .vtk $bytes]
2072}
2073
2074itcl::body Rappture::VtkIsosurfaceViewer::GetImage { args } {
2075    if { [image width $_image(download)] > 0 &&
2076         [image height $_image(download)] > 0 } {
2077        set bytes [$_image(download) data -format "jpeg -quality 100"]
2078        set bytes [Rappture::encoding::decode -as b64 $bytes]
2079        return [list .jpg $bytes]
2080    }
2081    return ""
2082}
2083
2084itcl::body Rappture::VtkIsosurfaceViewer::BuildDownloadPopup { popup command } {
2085    Rappture::Balloon $popup \
2086        -title "[Rappture::filexfer::label downloadWord] as..."
2087    set inner [$popup component inner]
2088    label $inner.summary -text "" -anchor w
2089    radiobutton $inner.vtk_button -text "VTK data file" \
2090        -variable [itcl::scope _downloadPopup(format)] \
2091        -font "Arial 9 " \
2092        -value vtk 
2093    Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file."
2094    radiobutton $inner.image_button -text "Image File" \
2095        -variable [itcl::scope _downloadPopup(format)] \
2096        -font "Arial 9 " \
2097        -value image
2098    Rappture::Tooltip::for $inner.image_button \
2099        "Save as digital image."
2100
2101    button $inner.ok -text "Save" \
2102        -highlightthickness 0 -pady 2 -padx 3 \
2103        -command $command \
2104        -compound left \
2105        -image [Rappture::icon download]
2106
2107    button $inner.cancel -text "Cancel" \
2108        -highlightthickness 0 -pady 2 -padx 3 \
2109        -command [list $popup deactivate] \
2110        -compound left \
2111        -image [Rappture::icon cancel]
2112
2113    blt::table $inner \
2114        0,0 $inner.summary -cspan 2  \
2115        1,0 $inner.vtk_button -anchor w -cspan 2 -padx { 4 0 } \
2116        2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \
2117        4,1 $inner.cancel -width .9i -fill y \
2118        4,0 $inner.ok -padx 2 -width .9i -fill y
2119    blt::table configure $inner r3 -height 4
2120    blt::table configure $inner r4 -pady 4
2121    raise $inner.image_button
2122    $inner.vtk_button invoke
2123    return $inner
2124}
2125
2126itcl::body Rappture::VtkIsosurfaceViewer::SetObjectStyle { dataobj comp } {
2127    # Parse style string.
2128    set tag $dataobj-$comp
2129    array set style {
[4752]2130        -color                  BCGYR
2131        -cutplanesvisible       0
2132        -edgecolor              black
2133        -edges                  0
2134        -isosurfacevisible      1
2135        -levels                 10
2136        -lighting               1
2137        -linewidth              1.0
2138        -opacity                0.6
2139        -outline                0
2140        -wireframe              0
2141        -xcutplaneposition      50
2142        -xcutplanevisible       1
2143        -ycutplaneposition      50
2144        -ycutplanevisible       1
2145        -zcutplaneposition      50
2146        -zcutplanevisible       1
[3330]2147    }
2148    array set style [$dataobj style $comp]
[4186]2149    if { $dataobj != $_first || $style(-levels) == 1 } {
[4752]2150        set style(-opacity) 1.0
[3330]2151    }
2152
[3514]2153    # This is too complicated.  We want to set the colormap, number of
2154    # isolines and opacity for the dataset.  They can be the default values,
2155    # the style hints loaded with the dataset, or set by user controls.  As
2156    # datasets get loaded, they first use the defaults that are overidden
2157    # by the style hints.  If the user changes the global controls, then that
2158    # overrides everything else.  I don't know what it means when global
2159    # controls are specified as style hints by each dataset.  It complicates
2160    # the code to handle aberrant cases.
2161
[4201]2162    if { $_changed(-isosurfaceopacity) } {
2163        set style(-opacity) $_settings(-isosurfaceopacity)
[3514]2164    }
[4201]2165    if { $_changed(-numcontours) } {
2166        set style(-levels) $_settings(-numcontours)
[3514]2167    }
[4201]2168    if { $_changed(-colormap) } {
2169        set style(-color) $_settings(-colormap)
[3514]2170    }
2171    if { $_currentColormap == "" } {
[4186]2172        SetCurrentColormap $style(-color)
[3514]2173        $itk_component(colormap) value $style(-color)
2174    }
[4752]2175    if { $_contourList(numLevels) != $style(-levels) } {
2176        if { [llength $style(-levels)] > 1 } {
2177            set _contourList(reqValues) [lsort -real $style(-levels)]
2178        } else {
2179            set _settings(-numcontours) $style(-levels)
2180            $itk_component(numcontours) value $style(-levels)
2181            set _contourList(numLevels) $style(-levels)
2182        }
2183        EventuallyChangeContourLevels
[3514]2184    }
[4201]2185    set _settings(-isosurfacevisible) $style(-isosurfacevisible)
2186    set _settings(-cutplanesvisible)  $style(-cutplanesvisible)
2187    set _settings(-xcutplanevisible)  $style(-xcutplanevisible)
2188    set _settings(-ycutplanevisible)  $style(-ycutplanevisible)
2189    set _settings(-zcutplanevisible)  $style(-zcutplanevisible)
2190    set _settings(-xcutplaneposition) $style(-xcutplaneposition)
2191    set _settings(-ycutplaneposition) $style(-ycutplaneposition)
2192    set _settings(-zcutplaneposition) $style(-zcutplaneposition)
2193 
[4752]2194    SendCmd "cutplane add $tag"
2195    SendCmd "cutplane color [Color2RGB $itk_option(-plotforeground)] $tag"
2196    SendCmd "cutplane visible $style(-cutplanesvisible) $tag"
2197
[3544]2198    SendCmd "outline add $tag"
2199    SendCmd "outline color [Color2RGB $itk_option(-plotforeground)] $tag"
2200    SendCmd "outline visible $style(-outline) $tag"
[4752]2201    set _settings(-outline) $style(-outline)
2202 
2203    GenerateContourList
2204    SendCmd [list contour3d add contourlist $_contourList(values) $tag]
2205    SendCmd "contour3d visible $style(-isosurfacevisible) $tag"
2206    SendCmd "contour3d edges $style(-edges) $tag"
[4201]2207    set _settings(-isosurfaceedges) $style(-edges)
[3330]2208    #SendCmd "contour3d color [Color2RGB $settings(-color)] $tag"
2209    SendCmd "contour3d lighting $style(-lighting) $tag"
[4201]2210    set _settings(-isosurfacelighting) $style(-lighting)
[3330]2211    SendCmd "contour3d linecolor [Color2RGB $style(-edgecolor)] $tag"
2212    SendCmd "contour3d linewidth $style(-linewidth) $tag"
[4752]2213    SendCmd "contour3d opacity $style(-opacity) $tag"
[4201]2214    set _settings(-isosurfaceopacity) $style(-opacity)
[3514]2215    SetCurrentColormap $style(-color)
[3330]2216    SendCmd "contour3d wireframe $style(-wireframe) $tag"
[4201]2217    set _settings(-isosurfacewireframe) $style(-wireframe)
[3330]2218}
2219
2220itcl::body Rappture::VtkIsosurfaceViewer::IsValidObject { dataobj } {
2221    if {[catch {$dataobj isa Rappture::Field} valid] != 0 || !$valid} {
2222        return 0
2223    }
2224    return 1
2225}
2226
2227#
2228# EnterLegend --
2229#
2230itcl::body Rappture::VtkIsosurfaceViewer::EnterLegend { x y } {
2231    SetLegendTip $x $y
2232}
2233
2234#
2235# MotionLegend --
2236#
2237itcl::body Rappture::VtkIsosurfaceViewer::MotionLegend { x y } {
2238    Rappture::Tooltip::tooltip cancel
2239    set c $itk_component(view)
[3442]2240    set cw [winfo width $c]
2241    set ch [winfo height $c]
2242    if { $x >= 0 && $x < $cw && $y >= 0 && $y < $ch } {
2243        SetLegendTip $x $y
2244    }
[3330]2245}
2246
2247#
2248# LeaveLegend --
2249#
2250itcl::body Rappture::VtkIsosurfaceViewer::LeaveLegend { } {
2251    Rappture::Tooltip::tooltip cancel
2252    .rappturetooltip configure -icon ""
2253}
2254
2255#
2256# SetLegendTip --
2257#
2258itcl::body Rappture::VtkIsosurfaceViewer::SetLegendTip { x y } {
[3442]2259    set fname $_curFldName
[3330]2260    set c $itk_component(view)
2261    set w [winfo width $c]
2262    set h [winfo height $c]
[3416]2263
[3330]2264    set font "Arial 8"
2265    set lineht [font metrics $font -linespace]
2266   
[3416]2267    set ih [image height $_image(legend)]
2268    set iy [expr $y - ($lineht + 2)]
[3330]2269
[3445]2270    if { [string match "component*" $fname] } {
[3442]2271        set title ""
[3330]2272    } else {
[3442]2273        if { [info exists _fields($fname)] } {
2274            foreach { title units } $_fields($fname) break
2275            if { $units != "" } {
2276                set title [format "%s (%s)" $title $units]
2277            }
2278        } else {
2279            set title $fname
[3330]2280        }
2281    }
[3416]2282    # If there's a legend title, increase the offset by the line height.
2283    if { $title != "" } {
[3442]2284        incr iy -$lineht
[3416]2285    }
[3330]2286    # Make a swatch of the selected color
[3416]2287    if { [catch { $_image(legend) get 10 $iy } pixel] != 0 } {
[3330]2288        return
2289    }
2290    if { ![info exists _image(swatch)] } {
2291        set _image(swatch) [image create photo -width 24 -height 24]
2292    }
2293    set color [eval format "\#%02x%02x%02x" $pixel]
2294    $_image(swatch) put black  -to 0 0 23 23
2295    $_image(swatch) put $color -to 1 1 22 22
2296    .rappturetooltip configure -icon $_image(swatch)
2297
2298    # Compute the value of the point
[3440]2299    if { [info exists _limits($_curFldName)] } {
2300        foreach { vmin vmax } $_limits($_curFldName) break
[3416]2301        set t [expr 1.0 - (double($iy) / double($ih-1))]
[3440]2302        set value [expr $t * ($vmax - $vmin) + $vmin]
[3330]2303    } else {
2304        set value 0.0
2305    }
[3416]2306    set tx [expr $x + 15]
2307    set ty [expr $y - 5]
[3442]2308    if { [info exists _isolines($y)] } {
2309        Rappture::Tooltip::text $c [format "$title %g (isosurface)" $_isolines($y)]
2310    } else {
2311        Rappture::Tooltip::text $c [format "$title %g" $value]
2312    }
[3416]2313    Rappture::Tooltip::tooltip show $c +$tx,+$ty   
[3330]2314}
2315
2316
2317# ----------------------------------------------------------------------
2318# USAGE: Slice move x|y|z <newval>
2319#
2320# Called automatically when the user drags the slider to move the
2321# cut plane that slices 3D data.  Gets the current value from the
2322# slider and moves the cut plane to the appropriate point in the
2323# data set.
2324# ----------------------------------------------------------------------
2325itcl::body Rappture::VtkIsosurfaceViewer::Slice {option args} {
2326    switch -- $option {
2327        "move" {
2328            set axis [lindex $args 0]
2329            set newval [lindex $args 1]
2330            if {[llength $args] != 2} {
2331                error "wrong # args: should be \"Slice move x|y|z newval\""
2332            }
2333            set newpos [expr {0.01*$newval}]
2334            SendCmd "cutplane slice $axis $newpos"
2335        }
2336        "tooltip" {
2337            set axis [lindex $args 0]
2338            set val [$itk_component(${axis}position) get]
2339            return "Move the [string toupper $axis] cut plane.\nCurrently:  $axis = $val%"
2340        }
2341        default {
2342            error "bad option \"$option\": should be axis, move, or tooltip"
2343        }
2344    }
2345}
2346
2347#
2348# ReceiveLegend --
2349#
2350#       Invoked automatically whenever the "legend" command comes in from
2351#       the rendering server.  Indicates that binary image data with the
2352#       specified <size> will follow.
2353#
2354itcl::body Rappture::VtkIsosurfaceViewer::ReceiveLegend { colormap title min max size } {
2355    #puts stderr "ReceiveLegend colormap=$colormap title=$title range=$min,$max size=$size"
2356    set _title $title
2357    regsub {\(mag\)} $title "" _title
2358    if { [IsConnected] } {
2359        set bytes [ReceiveBytes $size]
2360        if { ![info exists _image(legend)] } {
2361            set _image(legend) [image create photo]
2362        }
2363        $_image(legend) configure -data $bytes
2364        #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
[3442]2365        if { [catch {DrawLegend} errs] != 0 } {
[3330]2366            global errorInfo
2367            puts stderr "errs=$errs errorInfo=$errorInfo"
2368        }
2369    }
2370}
2371
2372#
2373# DrawLegend --
2374#
[3416]2375#       Draws the legend in the own canvas on the right side of the plot area.
[3330]2376#
[3442]2377itcl::body Rappture::VtkIsosurfaceViewer::DrawLegend {} {
2378    set fname $_curFldName
[3330]2379    set c $itk_component(view)
2380    set w [winfo width $c]
2381    set h [winfo height $c]
2382    set font "Arial 8"
2383    set lineht [font metrics $font -linespace]
2384   
[3445]2385    if { [string match "component*" $fname] } {
[3330]2386        set title ""
2387    } else {
[3442]2388        if { [info exists _fields($fname)] } {
2389            foreach { title units } $_fields($fname) break
[3330]2390            if { $units != "" } {
2391                set title [format "%s (%s)" $title $units]
2392            }
2393        } else {
[3442]2394            set title $fname
[3330]2395        }
2396    }
2397    set x [expr $w - 2]
[4201]2398    if { !$_settings(-legendvisible) } {
[3330]2399        $c delete legend
2400        return
2401    }
2402    if { [$c find withtag "legend"] == "" } {
2403        set y 2
2404        # If there's a legend title, create a text item for the title.
[3547]2405        $c create text $x $y \
[4351]2406            -anchor ne \
2407            -fill $itk_option(-plotforeground) -tags "title legend" \
2408            -font $font
2409        if { $title != "" } {
2410            incr y $lineht
2411        }
[3330]2412        $c create text $x $y \
2413            -anchor ne \
[3780]2414            -fill $itk_option(-plotforeground) -tags "vmax legend" \
[3330]2415            -font $font
2416        incr y $lineht
2417        $c create image $x $y \
2418            -anchor ne \
2419            -image $_image(legend) -tags "colormap legend"
[3442]2420        $c create rectangle $x $y 1 1 \
2421            -fill "" -outline "" -tags "sensor legend"
[3330]2422        $c create text $x [expr {$h-2}] \
2423            -anchor se \
[3780]2424            -fill $itk_option(-plotforeground) -tags "vmin legend" \
[3330]2425            -font $font
[3442]2426        $c bind sensor <Enter> [itcl::code $this EnterLegend %x %y]
2427        $c bind sensor <Leave> [itcl::code $this LeaveLegend]
2428        $c bind sensor <Motion> [itcl::code $this MotionLegend %x %y]
[3330]2429    }
2430    $c delete isoline
2431    set x2 $x
2432    set iw [image width $_image(legend)]
2433    set ih [image height $_image(legend)]
2434    set x1 [expr $x2 - ($iw*12)/10]
[4201]2435    set color $_settings(-isolinecolor)
[3330]2436    # Draw the isolines on the legend.
[3442]2437    array unset _isolines
2438    if { $color != "none"  && [info exists _limits($_curFldName)] &&
[4201]2439         $_settings(-numcontours) > 0 } {
[3538]2440
2441        foreach { vmin vmax } $_limits($_curFldName) break
2442        set range [expr double($vmax - $vmin)]
2443        if { $range <= 0.0 } {
2444            set range 1.0;              # Min is greater or equal to max.
2445        }
2446        set tags "isoline legend"
[3330]2447        set offset [expr 2 + $lineht]
2448        if { $title != "" } {
2449            incr offset $lineht
2450        }
[4752]2451        foreach value $_contourList(values) {
[3543]2452            set norm [expr 1.0 - (($value - $vmin) / $range)]
[3538]2453            set y1 [expr int(round(($norm * $ih) + $offset))]
[3442]2454            for { set off 0 } { $off < 3 } { incr off } {
2455                set _isolines([expr $y1 + $off]) $value
2456                set _isolines([expr $y1 - $off]) $value
[3440]2457            }
[3538]2458            $c create line $x1 $y1 $x2 $y1 -fill $color -tags $tags
[3440]2459        }
[3330]2460    }
2461
2462    $c bind title <ButtonPress> [itcl::code $this Combo post]
2463    $c bind title <Enter> [itcl::code $this Combo activate]
2464    $c bind title <Leave> [itcl::code $this Combo deactivate]
2465    # Reset the item coordinates according the current size of the plot.
2466    $c itemconfigure title -text $title
[3440]2467    if { [info exists _limits($_curFldName)] } {
2468        foreach { vmin vmax } $_limits($_curFldName) break
[3780]2469        $c itemconfigure vmin -text [format %g $vmin]
2470        $c itemconfigure vmax -text [format %g $vmax]
[3330]2471    }
2472    set y 2
2473    # If there's a legend title, move the title to the correct position
2474    if { $title != "" } {
[3547]2475        $c itemconfigure title -text $title
[3330]2476        $c coords title $x $y
2477        incr y $lineht
[3547]2478        $c raise title
[3330]2479    }
[3780]2480    $c coords vmax $x $y
[3330]2481    incr y $lineht
2482    $c coords colormap $x $y
[3442]2483    $c coords sensor [expr $x - $iw] $y $x [expr $y + $ih]
2484    $c raise sensor
[3780]2485    $c coords vmin $x [expr {$h - 2}]
[3330]2486}
2487
2488# ----------------------------------------------------------------------
2489# USAGE: _dropdown post
2490# USAGE: _dropdown unpost
2491# USAGE: _dropdown select
2492#
2493# Used internally to handle the dropdown list for this combobox.  The
2494# post/unpost options are invoked when the list is posted or unposted
2495# to manage the relief of the controlling button.  The select option
2496# is invoked whenever there is a selection from the list, to assign
2497# the value back to the gauge.
2498# ----------------------------------------------------------------------
2499itcl::body Rappture::VtkIsosurfaceViewer::Combo {option} {
2500    set c $itk_component(view)
2501    switch -- $option {
2502        post {
2503            foreach { x1 y1 x2 y2 } [$c bbox title] break
[3547]2504            set cw [winfo width $itk_component(view)]
2505            set mw [winfo reqwidth $itk_component(fieldmenu)]
2506            set x1 [expr $cw - $mw]
[3330]2507            set x [expr $x1 + [winfo rootx $itk_component(view)]]
2508            set y [expr $y2 + [winfo rooty $itk_component(view)]]
2509            tk_popup $itk_component(fieldmenu) $x $y
2510        }
2511        activate {
2512            $c itemconfigure title -fill red
2513        }
2514        deactivate {
2515            $c itemconfigure title -fill $itk_option(-plotforeground)
2516        }
2517        invoke {
[3409]2518            $itk_component(field) value $_curFldLabel
[4201]2519            AdjustSetting -field
[3330]2520        }
2521        default {
2522            error "bad option \"$option\": should be post, unpost, select"
2523        }
2524    }
2525}
2526
2527#
2528# SetCurrentColormap --
2529#
[3514]2530itcl::body Rappture::VtkIsosurfaceViewer::SetCurrentColormap { name } {
2531    # Keep track of the colormaps that we build.
[3330]2532    if { ![info exists _colormaps($name)] } {
[3514]2533        BuildColormap $name
2534        set _colormaps($name) 1
[3330]2535    }
2536    set _currentColormap $name
[3514]2537    SendCmd "contour3d colormap $_currentColormap"
[4186]2538    SendCmd "cutplane colormap $_currentColormap"
[3330]2539}
2540
2541#
2542# BuildColormap --
2543#
[3514]2544#       Build the designated colormap on the server.
2545#
2546itcl::body Rappture::VtkIsosurfaceViewer::BuildColormap { name } {
2547    set cmap [ColorsToColormap $name]
[3330]2548    if { [llength $cmap] == 0 } {
2549        set cmap "0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0"
2550    }
2551    set wmap "0.0 1.0 1.0 1.0"
2552    SendCmd "colormap add $name { $cmap } { $wmap }"
2553}
2554
[3517]2555itcl::body Rappture::VtkIsosurfaceViewer::SetOrientation { side } {
2556    array set positions {
2557        front "1 0 0 0"
2558        back  "0 0 1 0"
2559        left  "0.707107 0 -0.707107 0"
2560        right "0.707107 0 0.707107 0"
2561        top   "0.707107 -0.707107 0 0"
2562        bottom "0.707107 0.707107 0 0"
2563    }
[4752]2564    foreach name { -qw -qx -qy -qz } value $positions($side) {
[3517]2565        set _view($name) $value
2566    }
[4752]2567    set q [ViewToQuaternion]
[3517]2568    $_arcball quaternion $q
[3536]2569    SendCmd "camera orient $q"
2570    SendCmd "camera reset"
[4752]2571    set _view(-xpan) 0
2572    set _view(-ypan) 0
2573    set _view(-zoom) 1.0
[3517]2574}
[3538]2575
[4752]2576itcl::body Rappture::VtkIsosurfaceViewer::GenerateContourList {} {
[3538]2577    if { ![info exists _limits($_curFldName)] } {
[4752]2578        puts stderr "no _curFldName"
2579        return ""
[3538]2580    }
[4752]2581    if { $_contourList(numLevels) < 1 } {
2582        # There are tools that set 0 levels to get cutplanes only
2583        #puts stderr "numLevels < 1"
2584        return ""
[4186]2585    }
[4752]2586    if { [llength $_contourList(reqValues)] > 1 } {
2587        set values $_contourList(reqValues)
2588    } else {
2589        foreach { vmin vmax } $_limits($_curFldName) break
2590        set v [blt::vector create \#auto]
2591        $v seq $vmin $vmax [expr $_contourList(numLevels)+2]
2592        $v delete end 0
2593        set values [$v range 0 end]
2594        blt::vector destroy $v
2595    }
2596    set _contourList(values) $values
[3538]2597}
[4201]2598
[4752]2599itcl::body Rappture::VtkIsosurfaceViewer::SetCurrentFieldName { dataobj } {
2600    set _first $dataobj
2601    $itk_component(field) choices delete 0 end
2602    $itk_component(fieldmenu) delete 0 end
2603    array unset _fields
2604    set _curFldName ""
2605    foreach cname [$_first components] {
2606        foreach fname [$_first fieldnames $cname] {
2607            if { [info exists _fields($fname)] } {
2608                continue
2609            }
2610            foreach { label units components } \
2611                [$_first fieldinfo $fname] break
2612            $itk_component(field) choices insert end "$fname" "$label"
2613            $itk_component(fieldmenu) add radiobutton -label "$label" \
2614                -value $label -variable [itcl::scope _curFldLabel] \
2615                -selectcolor red \
2616                -activebackground $itk_option(-plotbackground) \
2617                -activeforeground $itk_option(-plotforeground) \
2618                -font "Arial 8" \
2619                -command [itcl::code $this Combo invoke]
2620            set _fields($fname) [list $label $units $components]
2621            if { $_curFldName == "" } {
2622                set _curFldName $fname
2623                set _curFldLabel $label
2624            }
2625        }
2626    }
2627    $itk_component(field) value $_curFldLabel
2628    if { ![info exists _limits($_curFldName)] } {
2629        SendCmd "dataset maprange all"
2630    } else {
2631        set limits $_limits($_curFldName)
2632        SendCmd "dataset maprange explicit $limits $_curFldName"
2633        if { $limits != $_currentLimits } {
2634            set _currentLimits $limits
2635            EventuallyChangeContourLevels
2636        }
2637    }
2638}
Note: See TracBrowser for help on using the repository browser.