source: trunk/gui/scripts/nanovisviewer.tcl @ 1444

Last change on this file since 1444 was 1444, checked in by gah, 15 years ago
File size: 64.9 KB
Line 
1
2# ----------------------------------------------------------------------
3#  COMPONENT: nanovisviewer - 3D volume rendering
4#
5#  This widget performs volume rendering on 3D scalar/vector datasets.
6#  It connects to the Nanovis server running on a rendering farm,
7#  transmits data, and displays the results.
8# ======================================================================
9#  AUTHOR:  Michael McLennan, Purdue University
10#  Copyright (c) 2004-2005  Purdue Research Foundation
11#
12#  See the file "license.terms" for information on usage and
13#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14# ======================================================================
15package require Itk
16package require BLT
17package require Img
18
19option add *NanovisViewer.width 4i widgetDefault
20option add *NanovisViewer*cursor crosshair widgetDefault
21option add *NanovisViewer.height 4i widgetDefault
22option add *NanovisViewer.foreground black widgetDefault
23option add *NanovisViewer.controlBackground gray widgetDefault
24option add *NanovisViewer.controlDarkBackground #999999 widgetDefault
25option add *NanovisViewer.plotBackground black widgetDefault
26option add *NanovisViewer.plotForeground white widgetDefault
27option add *NanovisViewer.plotOutline gray widgetDefault
28option add *NanovisViewer.font \
29    -*-helvetica-medium-r-normal-*-12-* widgetDefault
30
31# must use this name -- plugs into Rappture::resources::load
32proc NanovisViewer_init_resources {} {
33    Rappture::resources::register \
34        nanovis_server Rappture::NanovisViewer::SetServerList
35}
36
37itcl::class Rappture::NanovisViewer {
38    inherit Rappture::VisViewer
39
40    itk_option define -plotforeground plotForeground Foreground ""
41    itk_option define -plotbackground plotBackground Background ""
42    itk_option define -plotoutline plotOutline PlotOutline ""
43
44    constructor { hostlist args } {
45        Rappture::VisViewer::constructor $hostlist
46    } {
47        # defined below
48    }
49    destructor {
50        # defined below
51    }
52    public proc SetServerList { namelist } {
53        Rappture::VisViewer::SetServerList "nanovis" $namelist
54    }
55    public method add {dataobj {settings ""}}
56    public method camera {option args}
57    public method delete {args}
58    public method download {option args}
59    public method get {args}
60    public method isconnected {}
61    public method limits { tf }
62    public method overmarker { m x }
63    public method parameters {title args} {
64        # do nothing
65    }
66    public method rmdupmarker { m x }
67    public method scale {args}
68    public method updatetransferfuncs {}
69
70    protected method Connect {}
71    protected method CurrentVolumeIds {{what -all}}
72    protected method Disconnect {}
73    protected method DoResize {}
74    protected method FixLegend {}
75    protected method FixSettings {what {value ""}}
76    protected method Pan {option x y}
77    protected method Rebuild {}
78    protected method ReceiveData { args }
79    protected method ReceiveImage { args }
80    protected method ReceiveLegend { tf vmin vmax size }
81    protected method Rotate {option x y}
82    protected method SendCmd {string}
83    protected method SendDataObjs {}
84    protected method SendTransferFuncs {}
85    protected method Slice {option args}
86    protected method SlicerTip {axis}
87    protected method Zoom {option}
88
89    # The following methods are only used by this class.
90    private method AddIsoMarker { x y }
91    private method BuildCameraTab {}
92    private method BuildCutplanesTab {}
93    private method BuildViewTab {}
94    private method BuildVolumeTab {}
95    private method ComputeTransferFunc { tf }
96    private method EventuallyResize { w h }
97    private method EventuallyResizeLegend { }
98    private method NameTransferFunc { dataobj comp }
99    private method PanCamera {}
100    private method ParseLevelsOption { tf levels }
101    private method ParseMarkersOption { tf markers }
102
103    private variable _outbuf       ;# buffer for outgoing commands
104
105    private variable _dlist ""     ;# list of data objects
106    private variable _allDataObjs
107    private variable _obj2ovride   ;# maps dataobj => style override
108    private variable _obj2id       ;# maps dataobj-component to volume ID
109                                    # in the server
110    private variable _id2obj       ;# maps dataobj => volume ID in server
111    private variable _sendobjs ""  ;# list of data objs to send to server
112    private variable _receiveIds   ;# list of data objs to send to server
113    private variable _obj2style    ;# maps dataobj-component to transfunc
114    private variable _style2objs   ;# maps tf back to list of
115                                    # dataobj-components using the tf.
116
117    private variable _click        ;# info used for rotate operations
118    private variable _limits       ;# autoscale min/max for all axes
119    private variable _view         ;# view params for 3D view
120    private variable _isomarkers    ;# array of isosurface level values 0..1
121    private common   _settings
122    private variable _activeTf ""  ;# The currently active transfer function.
123    private variable _first ""     ;# This is the topmost volume.
124    private variable _buffering 0
125
126    # This
127    # indicates which isomarkers and transfer
128    # function to use when changing markers,
129    # opacity, or thickness.
130    common _downloadPopup          ;# download options from popup
131    private common _hardcopy
132    private variable _width 0
133    private variable _height 0
134}
135
136itk::usual NanovisViewer {
137    keep -background -foreground -cursor -font
138    keep -plotbackground -plotforeground
139}
140
141# ----------------------------------------------------------------------
142# CONSTRUCTOR
143# ----------------------------------------------------------------------
144itcl::body Rappture::NanovisViewer::constructor {hostlist args} {
145
146    # Draw legend event
147    $_dispatcher register !legend
148    $_dispatcher dispatch $this !legend "[itcl::code $this FixLegend]; list"
149
150    # Send dataobjs event
151    $_dispatcher register !send_dataobjs
152    $_dispatcher dispatch $this !send_dataobjs \
153        "[itcl::code $this SendDataObjs]; list"
154
155    # Send transfer functions event
156    $_dispatcher register !send_transfunc
157    $_dispatcher dispatch $this !send_transfunc \
158        "[itcl::code $this SendTransferFuncs]; list"
159
160    # Rebuild event
161    $_dispatcher register !rebuild
162    $_dispatcher dispatch $this !rebuild "[itcl::code $this Rebuild]; list"
163
164    # Resize event
165    $_dispatcher register !resize
166    $_dispatcher dispatch $this !resize "[itcl::code $this DoResize]; list"
167
168    set _outbuf ""
169
170    #
171    # Populate parser with commands handle incoming requests
172    #
173    $_parser alias image [itcl::code $this ReceiveImage]
174    $_parser alias legend [itcl::code $this ReceiveLegend]
175    $_parser alias data [itcl::code $this ReceiveData]
176
177    # Initialize the view to some default parameters.
178    array set _view {
179        theta   45
180        phi     45
181        psi     0
182        zoom    1.0
183        pan-x   0
184        pan-y   0
185    }
186    set _obj2id(count) 0
187    set _id2obj(count) 0
188    set _limits(vmin) 0.0
189    set _limits(vmax) 1.0
190
191    array set _settings [subst {
192        $this-pan-x             $_view(pan-x)
193        $this-pan-y             $_view(pan-y)
194        $this-phi               $_view(phi)
195        $this-psi               $_view(psi)
196        $this-theta             $_view(theta)
197        $this-volume            1
198        $this-xcutplane         0
199        $this-xcutposition      0
200        $this-ycutplane         0
201        $this-ycutposition      0
202        $this-zcutplane         0
203        $this-zcutposition      0
204        $this-zoom              $_view(zoom)
205    }]
206
207    set f [$itk_component(main) component controls]
208    itk_component add reset {
209        button $f.reset -borderwidth 1 -padx 1 -pady 1 \
210            -highlightthickness 0 \
211            -image [Rappture::icon reset-view] \
212            -command [itcl::code $this Zoom reset]
213    } {
214        usual
215        ignore -highlightthickness
216    }
217    pack $itk_component(reset) -side top -padx 2 -pady 2
218    Rappture::Tooltip::for $itk_component(reset) "Reset the view to the default zoom level"
219
220    itk_component add zoomin {
221        button $f.zin -borderwidth 1 -padx 1 -pady 1 \
222            -highlightthickness 0 \
223            -image [Rappture::icon zoom-in] \
224            -command [itcl::code $this Zoom in]
225    } {
226        usual
227        ignore -highlightthickness
228    }
229    pack $itk_component(zoomin) -side top -padx 2 -pady 2
230    Rappture::Tooltip::for $itk_component(zoomin) "Zoom in"
231
232    itk_component add zoomout {
233        button $f.zout -borderwidth 1 -padx 1 -pady 1 \
234            -highlightthickness 0 \
235            -image [Rappture::icon zoom-out] \
236            -command [itcl::code $this Zoom out]
237    } {
238        usual
239        ignore -highlightthickness
240    }
241    pack $itk_component(zoomout) -side top -padx 2 -pady 2
242    Rappture::Tooltip::for $itk_component(zoomout) "Zoom out"
243
244    itk_component add volume {
245        Rappture::PushButton $f.volume \
246            -onimage [Rappture::icon volume-on] \
247            -offimage [Rappture::icon volume-off] \
248            -command [itcl::code $this FixSettings volume] \
249            -variable [itcl::scope _settings($this-volume)]
250    }
251    $itk_component(volume) select
252    Rappture::Tooltip::for $itk_component(volume) \
253        "Toggle the volume cloud on/off"
254    pack $itk_component(volume) -padx 2 -pady 2
255
256    BuildViewTab
257    BuildVolumeTab
258    BuildCutplanesTab
259    BuildCameraTab
260
261    # Legend
262
263    set _image(legend) [image create photo]
264    itk_component add legend {
265        canvas $itk_component(plotarea).legend -height 50 -highlightthickness 0
266    } {
267        usual
268        ignore -highlightthickness
269        rename -background -plotbackground plotBackground Background
270    }
271    bind $itk_component(legend) <Configure> \
272        [itcl::code $this EventuallyResizeLegend]
273
274    # Hack around the Tk panewindow.  The problem is that the requested
275    # size of the 3d view isn't set until an image is retrieved from
276    # the server.  So the panewindow uses the tiny size.
277    set w 10000
278    pack forget $itk_component(3dview)
279    blt::table $itk_component(plotarea) \
280        0,0 $itk_component(3dview) -fill both -reqwidth $w \
281        1,0 $itk_component(legend) -fill x
282    blt::table configure $itk_component(plotarea) r1 -resize none
283
284    # Bindings for rotation via mouse
285    bind $itk_component(3dview) <ButtonPress-1> \
286        [itcl::code $this Rotate click %x %y]
287    bind $itk_component(3dview) <B1-Motion> \
288        [itcl::code $this Rotate drag %x %y]
289    bind $itk_component(3dview) <ButtonRelease-1> \
290        [itcl::code $this Rotate release %x %y]
291    bind $itk_component(3dview) <Configure> \
292        [itcl::code $this EventuallyResize %w %h]
293
294    # Bindings for panning via mouse
295    bind $itk_component(3dview) <ButtonPress-2> \
296        [itcl::code $this Pan click %x %y]
297    bind $itk_component(3dview) <B2-Motion> \
298        [itcl::code $this Pan drag %x %y]
299    bind $itk_component(3dview) <ButtonRelease-2> \
300        [itcl::code $this Pan release %x %y]
301
302    # Bindings for panning via keyboard
303    bind $itk_component(3dview) <KeyPress-Left> \
304        [itcl::code $this Pan set -10 0]
305    bind $itk_component(3dview) <KeyPress-Right> \
306        [itcl::code $this Pan set 10 0]
307    bind $itk_component(3dview) <KeyPress-Up> \
308        [itcl::code $this Pan set 0 -10]
309    bind $itk_component(3dview) <KeyPress-Down> \
310        [itcl::code $this Pan set 0 10]
311    bind $itk_component(3dview) <Shift-KeyPress-Left> \
312        [itcl::code $this Pan set -2 0]
313    bind $itk_component(3dview) <Shift-KeyPress-Right> \
314        [itcl::code $this Pan set 2 0]
315    bind $itk_component(3dview) <Shift-KeyPress-Up> \
316        [itcl::code $this Pan set 0 -2]
317    bind $itk_component(3dview) <Shift-KeyPress-Down> \
318        [itcl::code $this Pan set 0 2]
319
320    # Bindings for zoom via keyboard
321    bind $itk_component(3dview) <KeyPress-Prior> \
322        [itcl::code $this Zoom out]
323    bind $itk_component(3dview) <KeyPress-Next> \
324        [itcl::code $this Zoom in]
325
326    bind $itk_component(3dview) <Enter> "focus $itk_component(3dview)"
327
328    if {[string equal "x11" [tk windowingsystem]]} {
329        # Bindings for zoom via mouse
330        bind $itk_component(3dview) <4> [itcl::code $this Zoom out]
331        bind $itk_component(3dview) <5> [itcl::code $this Zoom in]
332    }
333
334    set _image(download) [image create photo]
335
336    eval itk_initialize $args
337
338    Connect
339}
340
341# ----------------------------------------------------------------------
342# DESTRUCTOR
343# ----------------------------------------------------------------------
344itcl::body Rappture::NanovisViewer::destructor {} {
345    set _sendobjs ""  ;# stop any send in progress
346    $_dispatcher cancel !rebuild
347    $_dispatcher cancel !send_dataobjs
348    $_dispatcher cancel !send_transfunc
349    image delete $_image(plot)
350    image delete $_image(legend)
351    image delete $_image(download)
352    array unset _settings $this-*
353}
354
355# ----------------------------------------------------------------------
356# USAGE: add <dataobj> ?<settings>?
357#
358# Clients use this to add a data object to the plot.  The optional
359# <settings> are used to configure the plot.  Allowed settings are
360# -color, -brightness, -width, -linestyle, and -raise.
361# ----------------------------------------------------------------------
362itcl::body Rappture::NanovisViewer::add {dataobj {settings ""}} {
363    array set params {
364        -color auto
365        -width 1
366        -linestyle solid
367        -brightness 0
368        -raise 0
369        -description ""
370        -param ""
371    }
372    foreach {opt val} $settings {
373        if {![info exists params($opt)]} {
374            error "bad setting \"$opt\": should be [join [lsort [array names params]] {, }]"
375        }
376        set params($opt) $val
377    }
378    if {$params(-color) == "auto" || $params(-color) == "autoreset"} {
379        # can't handle -autocolors yet
380        set params(-color) black
381    }
382
383    set pos [lsearch -exact $dataobj $_dlist]
384    if {$pos < 0} {
385        lappend _dlist $dataobj
386        set _allDataObjs($dataobj) 1
387        set _obj2ovride($dataobj-color) $params(-color)
388        set _obj2ovride($dataobj-width) $params(-width)
389        set _obj2ovride($dataobj-raise) $params(-raise)
390        $_dispatcher event -idle !rebuild
391    }
392}
393
394# ----------------------------------------------------------------------
395# USAGE: get ?-objects?
396# USAGE: get ?-image 3dview|legend?
397#
398# Clients use this to query the list of objects being plotted, in
399# order from bottom to top of this result.  The optional "-image"
400# flag can also request the internal images being shown.
401# ----------------------------------------------------------------------
402itcl::body Rappture::NanovisViewer::get {args} {
403    if {[llength $args] == 0} {
404        set args "-objects"
405    }
406
407    set op [lindex $args 0]
408    switch -- $op {
409      -objects {
410        # put the dataobj list in order according to -raise options
411        set dlist $_dlist
412        foreach obj $dlist {
413            if {[info exists _obj2ovride($obj-raise)] && $_obj2ovride($obj-raise)} {
414                set i [lsearch -exact $dlist $obj]
415                if {$i >= 0} {
416                    set dlist [lreplace $dlist $i $i]
417                    lappend dlist $obj
418                }
419            }
420        }
421        return $dlist
422      }
423      -image {
424        if {[llength $args] != 2} {
425            error "wrong # args: should be \"get -image 3dview|legend\""
426        }
427        switch -- [lindex $args end] {
428            3dview {
429                return $_image(plot)
430            }
431            legend {
432                return $_image(legend)
433            }
434            default {
435                error "bad image name \"[lindex $args end]\": should be 3dview or legend"
436            }
437        }
438      }
439      default {
440        error "bad option \"$op\": should be -objects or -image"
441      }
442    }
443}
444
445# ----------------------------------------------------------------------
446# USAGE: delete ?<dataobj1> <dataobj2> ...?
447#
448#       Clients use this to delete a dataobj from the plot.  If no dataobjs
449#       are specified, then all dataobjs are deleted.  No data objects are
450#       deleted.  They are only removed from the display list.
451#
452# ----------------------------------------------------------------------
453itcl::body Rappture::NanovisViewer::delete {args} {
454    if {[llength $args] == 0} {
455        set args $_dlist
456    }
457    # Delete all specified dataobjs
458    set changed 0
459    foreach dataobj $args {
460        set pos [lsearch -exact $_dlist $dataobj]
461        if { $pos >= 0 } {
462            foreach comp [$dataobj components] {
463                if { [info exists obj2id($dataobj-$comp)] } {
464                    set ivol $_obj2id($dataobj-$comp)
465                    array unset _limits $ivol-*
466                }
467            }
468            set _dlist [lreplace $_dlist $pos $pos]
469            array unset _obj2ovride $dataobj-*
470            array unset _obj2id $dataobj-*
471            array unset _obj2style $dataobj-*
472            set changed 1
473        }
474    }
475    # If anything changed, then rebuild the plot
476    if {$changed} {
477        # Repair the reverse lookup
478        foreach tf [array names _style2objs] {
479            set list {}
480            foreach {dataobj comp} $_style2objs($tf) break
481            if { [info exists _obj2id($dataobj-$comp)] } {
482                lappend list $dataobj $comp
483            }
484            if { $list == "" } {
485                array unset _style2objs $tf
486            } else {
487                set _style2objs($tf) $list
488            }
489        }
490        $_dispatcher event -idle !rebuild
491    }
492}
493
494# ----------------------------------------------------------------------
495# USAGE: scale ?<data1> <data2> ...?
496#
497# Sets the default limits for the overall plot according to the
498# limits of the data for all of the given <data> objects.  This
499# accounts for all objects--even those not showing on the screen.
500# Because of this, the limits are appropriate for all objects as
501# the user scans through data in the ResultSet viewer.
502# ----------------------------------------------------------------------
503itcl::body Rappture::NanovisViewer::scale {args} {
504    foreach val {xmin xmax ymin ymax zmin zmax vmin vmax} {
505        set _limits($val) ""
506    }
507    foreach obj $args {
508        foreach axis {x y z v} {
509
510            foreach { min max } [$obj limits $axis] break
511
512            if {"" != $min && "" != $max} {
513                if {"" == $_limits(${axis}min)} {
514                    set _limits(${axis}min) $min
515                    set _limits(${axis}max) $max
516                } else {
517                    if {$min < $_limits(${axis}min)} {
518                        set _limits(${axis}min) $min
519                    }
520                    if {$max > $_limits(${axis}max)} {
521                        set _limits(${axis}max) $max
522                    }
523                }
524            }
525        }
526    }
527}
528
529# ----------------------------------------------------------------------
530# USAGE: download coming
531# USAGE: download controls <downloadCommand>
532# USAGE: download now
533#
534# Clients use this method to create a downloadable representation
535# of the plot.  Returns a list of the form {ext string}, where
536# "ext" is the file extension (indicating the type of data) and
537# "string" is the data itself.
538# ----------------------------------------------------------------------
539itcl::body Rappture::NanovisViewer::download {option args} {
540    switch $option {
541        coming {
542            if {[catch {
543                blt::winop snap $itk_component(plotarea) $_image(download)
544            }]} {
545                $_image(download) configure -width 1 -height 1
546                $_image(download) put #000000
547            }
548        }
549        controls {
550            # no controls for this download yet
551            return ""
552        }
553        now {
554            # Get the image data (as base64) and decode it back to binary.
555            # This is better than writing to temporary files.  When we switch
556            # to the BLT picture image it won't be necessary to decode the
557            # image data.
558            set bytes [$_image(plot) data -format "jpeg -quality 100"]
559            set bytes [Rappture::encoding::decode -as b64 $bytes]
560            return [list .jpg $bytes]
561        }
562        default {
563            error "bad option \"$option\": should be coming, controls, now"
564        }
565    }
566}
567
568# ----------------------------------------------------------------------
569# USAGE: Connect ?<host:port>,<host:port>...?
570#
571# Clients use this method to establish a connection to a new
572# server, or to reestablish a connection to the previous server.
573# Any existing connection is automatically closed.
574# ----------------------------------------------------------------------
575itcl::body Rappture::NanovisViewer::Connect {} {
576    set _hosts [GetServerList "nanovis"]
577    if { "" == $_hosts } {
578        return 0
579    }
580    set result [VisViewer::Connect $_hosts]
581    if { $result } {
582        set w [winfo width $itk_component(3dview)]
583        set h [winfo height $itk_component(3dview)]
584        EventuallyResize $w $h
585    }
586    return $result
587}
588
589#
590# isconnected --
591#
592#       Indicates if we are currently connected to the visualization server.
593#
594itcl::body Rappture::NanovisViewer::isconnected {} {
595    return [VisViewer::IsConnected]
596}
597
598#
599# Disconnect --
600#
601#       Clients use this method to disconnect from the current rendering
602#       server.
603#
604itcl::body Rappture::NanovisViewer::Disconnect {} {
605    VisViewer::Disconnect
606
607    # disconnected -- no more data sitting on server
608    set _outbuf ""
609    catch {unset _obj2id}
610    array unset _id2obj
611    set _obj2id(count) 0
612    set _id2obj(count) 0
613    set _sendobjs ""
614}
615
616#
617# SendCmd
618#
619#       Send commands off to the rendering server.  If we're currently
620#       sending data objects to the server, buffer the commands to be
621#       sent later.
622#
623itcl::body Rappture::NanovisViewer::SendCmd {string} {
624    if { $_buffering } {
625        append _outbuf $string "\n"
626    } else {
627        foreach line [split $string \n] {
628            SendEcho >>line $line
629        }
630        SendBytes "$string\n"
631    }
632}
633
634# ----------------------------------------------------------------------
635# USAGE: SendDataObjs
636#
637# Used internally to send a series of volume objects off to the
638# server.  Sends each object, a little at a time, with updates in
639# between so the interface doesn't lock up.
640# ----------------------------------------------------------------------
641itcl::body Rappture::NanovisViewer::SendDataObjs {} {
642    blt::busy hold $itk_component(hull); update idletasks
643
644    foreach dataobj $_sendobjs {
645        foreach comp [$dataobj components] {
646            # Send the data as one huge base64-encoded mess -- yuck!
647            set data [$dataobj values $comp]
648            set nbytes [string length $data]
649            if { ![SendBytes "volume data follows $nbytes $dataobj-$comp\n"] } {
650                return
651            }
652            if { ![SendBytes $data] } {
653                return
654            }
655            set ivol $_obj2id(count)
656            incr _obj2id(count)
657            NameTransferFunc $dataobj $comp
658            set _receiveIds($ivol) 1
659        }
660    }
661    set _sendobjs ""
662    blt::busy release $itk_component(hull)
663
664    # Turn on buffering of commands to the server.  We don't want to
665    # be preempted by a server disconnect/reconnect (which automatically
666    # generates a new call to Rebuild).   
667    set _buffering 1
668
669    # activate the proper volume
670    set _first [lindex [get] 0]
671    if {"" != $_first} {
672        set axis [$_first hints updir]
673        if {"" != $axis} {
674            SendCmd "up $axis"
675        }
676        # The active transfer function is by default the first component of
677        # the first data object.  This assumes that the data is always
678        # successfully transferred.
679        set comp [lindex [$_first components] 0]
680        set _activeTf [lindex $_obj2style($_first-$comp) 0]
681    }
682    SendCmd "volume state 0"
683    set vols {}
684    foreach key [array names _obj2id $_first-*] {
685        lappend vols $_obj2id($key)
686    }
687    if { $vols != ""  && $_settings($this-volume) } {
688        SendCmd "volume state 1 $vols"
689    }
690    # sync the state of slicers
691    set vols [CurrentVolumeIds -cutplanes]
692    foreach axis {x y z} {
693        SendCmd "cutplane state $_settings($this-${axis}cutplane) $axis $vols"
694        set pos [expr {0.01*$_settings($this-${axis}cutposition)}]
695        SendCmd "cutplane position $pos $axis $vols"
696    }
697
698    if 0 {
699    # Add this when we fix grid for volumes
700    SendCmd "volume axis label x \"\""
701    SendCmd "volume axis label y \"\""
702    SendCmd "volume axis label z \"\""
703    SendCmd "grid axisname x X eV"
704    SendCmd "grid axisname y Y eV"
705    SendCmd "grid axisname z Z eV"
706    }
707
708    # Actually write the commands to the server socket.  If it fails, we don't
709    # care.  We're finished here.
710    SendBytes $_outbuf;                 
711    set _buffering 0;                   # Turn off buffering.
712    set _outbuf "";                     # Clear the buffer.             
713}
714
715# ----------------------------------------------------------------------
716# USAGE: SendTransferFuncs
717# ----------------------------------------------------------------------
718itcl::body Rappture::NanovisViewer::SendTransferFuncs {} {
719    if { $_activeTf == "" } {
720        return
721    }
722    set tf $_activeTf
723    if { $_first == "" } {
724        return
725    }
726
727    # Insure that the global opacity and thickness settings (in the slider
728    # settings widgets) are used for the active transfer-function.  Update the
729    # values in the _settings varible.
730    set value $_settings($this-opacity)
731    set opacity [expr { double($value) * 0.01 }]
732    set _settings($this-$tf-opacity) $opacity
733    set value $_settings($this-thickness)
734    # Scale values between 0.00001 and 0.01000
735    set thickness [expr {double($value) * 0.0001}]
736    set _settings($this-$tf-thickness) $thickness
737
738    foreach key [array names _obj2style $_first-*] {
739        if { [info exists _obj2style($key)] } {
740            foreach tf $_obj2style($key) {
741                ComputeTransferFunc $tf
742            }
743        }
744    }
745    FixLegend
746    if 0 {
747    if { $first != "" && ![info exists _obj2style($_first)] } {
748        foreach tf $_obj2style($_first) {
749            ComputeTransferFunc $tf
750        }
751        $_dispatcher event -idle !legend
752    }
753    }
754}
755
756# ----------------------------------------------------------------------
757# USAGE: ReceiveImage -bytes <size> -type <type> -token <token>
758#
759# Invoked automatically whenever the "image" command comes in from
760# the rendering server.  Indicates that binary image data with the
761# specified <size> will follow.
762# ----------------------------------------------------------------------
763itcl::body Rappture::NanovisViewer::ReceiveImage { args } {
764    if { ![isconnected] } {
765        return
766    }
767    array set info {
768        -token "???"
769        -bytes 0
770        -type image
771    }
772    array set info $args
773    set bytes [ReceiveBytes $info(-bytes)]
774    ReceiveEcho <<line "<read $info(-bytes) bytes"
775    if { $info(-type) == "image" } {
776        ReceiveEcho "for [image width $_image(plot)]x[image height $_image(plot)] image>"       
777        $_image(plot) configure -data $bytes
778    } elseif { $info(type) == "print" } {
779        set tag $this-print-$info(-token)
780        set _hardcopy($tag) $bytes
781    }
782}
783
784#
785# ReceiveLegend --
786#
787#       The procedure is the response from the render server to each "legend"
788#       command.  The server sends back a "legend" command invoked our
789#       the slave interpreter.  The purpose is to collect data of the image
790#       representing the legend in the canvas.  In addition, the isomarkers
791#       of the active transfer function are displayed.
792#
793#       I don't know is this is the right place to display the isomarkers.
794#       I don't know all the different paths used to draw the plot. There's
795#       "Rebuild", "add", etc.
796#
797itcl::body Rappture::NanovisViewer::ReceiveLegend { tf vmin vmax size } {
798    if { ![isconnected] } {
799        return
800    }
801    set bytes [ReceiveBytes $size]
802    $_image(legend) configure -data $bytes
803    ReceiveEcho <<line "<read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
804
805    set c $itk_component(legend)
806    set w [winfo width $c]
807    set h [winfo height $c]
808    #foreach { dataobj comp } $_id2obj($ivol) break
809    set lx 10
810    set ly [expr {$h - 1}]
811    if {"" == [$c find withtag transfunc]} {
812        $c create image 10 10 -anchor nw \
813            -image $_image(legend) -tags transfunc
814        $c create text $lx $ly -anchor sw \
815            -fill $itk_option(-plotforeground) -tags "limits vmin"
816        $c create text [expr {$w-$lx}] $ly -anchor se \
817            -fill $itk_option(-plotforeground) -tags "limits vmax"
818        $c lower transfunc
819        $c bind transfunc <ButtonRelease-1> \
820            [itcl::code $this AddIsoMarker %x %y]
821    }
822    # Display the markers used by the active transfer function.
823    #set tf $_activeTf
824
825    array set limits [limits $tf]
826    $c itemconfigure vmin -text [format %.2g $limits(min)]
827    $c coords vmin $lx $ly
828
829    $c itemconfigure vmax -text [format %.2g $limits(max)]
830    $c coords vmax [expr {$w-$lx}] $ly
831
832    if { [info exists _isomarkers($tf)] } {
833        foreach m $_isomarkers($tf) {
834            $m visible yes
835        }
836    }
837}
838
839#
840# ReceiveData --
841#
842#       The procedure is the response from the render server to each "data
843#       follows" command.  The server sends back a "data" command invoked our
844#       the slave interpreter.  The purpose is to collect the min/max of the
845#       volume sent to the render server.  Since the client (nanovisviewer)
846#       doesn't parse 3D data formats, we rely on the server (nanovis) to
847#       tell us what the limits are.  Once we've received the limits to all
848#       the data we've sent (tracked by _receiveIds) we can then determine
849#       what the transfer functions are for these volumes.
850#
851#
852#       Note: There is a considerable tradeoff in having the server report
853#             back what the data limits are.  It means that much of the code
854#             having to do with transfer-functions has to wait for the data
855#             to come back, since the isomarkers are calculated based upon
856#             the data limits.  The client code is much messier because of
857#             this.  The alternative is to parse any of the 3D formats on the
858#             client side.
859#
860itcl::body Rappture::NanovisViewer::ReceiveData { args } {
861    if { ![isconnected] } {
862        return
863    }
864    # Arguments from server are name value pairs. Stuff them in an array.
865    array set info $args
866
867    set ivol $info(id);         # Id of volume created by server.
868    set tag $info(tag)
869    set parts [split $tag -]
870
871    #
872    # Volumes don't exist until we're told about them.
873    #
874    set _id2obj($ivol) $parts
875    set dataobj [lindex $parts 0]
876    set _obj2id($tag) $ivol
877    if { $_settings($this-volume) && $dataobj == $_first } {
878        SendCmd "volume state 1 $ivol"
879    }
880    set _limits($ivol-min) $info(min);  # Minimum value of the volume.
881    set _limits($ivol-max) $info(max);  # Maximum value of the volume.
882    set _limits(vmin)      $info(vmin); # Overall minimum value.
883    set _limits(vmax)      $info(vmax); # Overall maximum value.
884
885    unset _receiveIds($ivol)
886    if { [array size _receiveIds] == 0 } {
887        updatetransferfuncs
888    }
889}
890
891# ----------------------------------------------------------------------
892# USAGE: Rebuild
893#
894# Called automatically whenever something changes that affects the
895# data in the widget.  Clears any existing data and rebuilds the
896# widget to display new data.
897# ----------------------------------------------------------------------
898itcl::body Rappture::NanovisViewer::Rebuild {} {
899
900    # Hide all the isomarkers. Can't remove them. Have to remember the
901    # settings since the user may have created/deleted/moved markers.
902
903    foreach tf [array names _isomarkers] {
904        foreach m $_isomarkers($tf) {
905            $m visible no
906        }
907    }
908
909    # in the midst of sending data? then bail out
910    if {[llength $_sendobjs] > 0} {
911        return
912    }
913
914    # Turn on buffering of commands to the server.  We don't want to
915    # be preempted by a server disconnect/reconnect (which automatically
916    # generates a new call to Rebuild).   
917    set _buffering 1
918
919    # Find any new data that needs to be sent to the server.  Queue this up on
920    # the _sendobjs list, and send it out a little at a time.  Do this first,
921    # before we rebuild the rest.
922    foreach dataobj [get] {
923        set comp [lindex [$dataobj components] 0]
924        if {![info exists _obj2id($dataobj-$comp)]} {
925            set i [lsearch -exact $_sendobjs $dataobj]
926            if {$i < 0} {
927                lappend _sendobjs $dataobj
928            }
929        }
930    }
931    set w [winfo width $itk_component(3dview)]
932    set h [winfo height $itk_component(3dview)]
933    EventuallyResize $w $h
934
935    #
936    # Reset the camera and other view parameters
937    #
938    set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)]
939    SendCmd "camera angle $xyz"
940    PanCamera
941    SendCmd "camera zoom $_view(zoom)"
942
943    set _settings($this-theta) $_view(theta)
944    set _settings($this-phi)   $_view(phi)
945    set _settings($this-psi)   $_view(psi)
946    set _settings($this-pan-x) $_view(pan-x)
947    set _settings($this-pan-y) $_view(pan-y)
948    set _settings($this-zoom)  $_view(zoom)
949
950    FixSettings light
951    FixSettings transp
952    FixSettings isosurface
953    FixSettings grid
954    FixSettings axes
955    FixSettings outline
956
957    if {[llength $_sendobjs] > 0} {
958        # send off new data objects
959        $_dispatcher event -idle !send_dataobjs
960        return
961    }
962
963    # nothing to send -- activate the proper ivol
964    set _first [lindex [get] 0]
965    if {"" != $_first} {
966        set axis [$_first hints updir]
967        if {"" != $axis} {
968            SendCmd "up $axis"
969        }
970        foreach key [array names _obj2id *-*] {
971            set state [string match $_first-* $key]
972            SendCmd "volume state $state $_obj2id($key)"
973        }
974        #
975        # The _obj2id and _id2style arrays may or may not have the right
976        # information.  It's possible for the server to know about volumes
977        # that the client has assumed it's deleted.  We could add checks.
978        # But this problem needs to be fixed not bandaided.
979        set comp [lindex [$_first components] 0]
980        set ivol $_obj2id($_first-$comp)
981
982        foreach comp [$_first components] {
983            NameTransferFunc $_first $comp
984        }
985    }
986
987    # sync the state of slicers
988    set vols [CurrentVolumeIds -cutplanes]
989    foreach axis {x y z} {
990        SendCmd "cutplane state $_settings($this-${axis}cutplane) $axis $vols"
991        set pos [expr {0.01*$_settings($this-${axis}cutposition)}]
992        SendCmd "cutplane position $pos $axis $vols"
993    }
994    SendCmd "volume data state $_settings($this-volume) $vols"
995    $_dispatcher event -idle !legend
996
997    # Actually write the commands to the server socket.  If it fails, we don't
998    # care.  We're finished here.
999    SendBytes $_outbuf;                 
1000    set _buffering 0;                   # Turn off buffering.
1001    set _outbuf "";                     # Clear the buffer.             
1002}
1003
1004# ----------------------------------------------------------------------
1005# USAGE: CurrentVolumeIds ?-cutplanes?
1006#
1007# Returns a list of volume server IDs for the current volume being
1008# displayed.  This is normally a single ID, but it might be a list
1009# of IDs if the current data object has multiple components.
1010# ----------------------------------------------------------------------
1011itcl::body Rappture::NanovisViewer::CurrentVolumeIds {{what -all}} {
1012    set rlist ""
1013    if { $_first == "" } {
1014        return
1015    }
1016    foreach key [array names _obj2id *-*] {
1017        if {[string match $_first-* $key]} {
1018            array set style {
1019                -cutplanes 1
1020            }
1021            foreach {dataobj comp} [split $key -] break
1022            array set style [lindex [$dataobj components -style $comp] 0]
1023
1024            if {$what != "-cutplanes" || $style(-cutplanes)} {
1025                lappend rlist $_obj2id($key)
1026            }
1027        }
1028    }
1029    return $rlist
1030}
1031
1032# ----------------------------------------------------------------------
1033# USAGE: Zoom in
1034# USAGE: Zoom out
1035# USAGE: Zoom reset
1036#
1037# Called automatically when the user clicks on one of the zoom
1038# controls for this widget.  Changes the zoom for the current view.
1039# ----------------------------------------------------------------------
1040itcl::body Rappture::NanovisViewer::Zoom {option} {
1041    switch -- $option {
1042        "in" {
1043            set _view(zoom) [expr {$_view(zoom)*1.25}]
1044            set _settings($this-zoom) $_view(zoom)
1045        }
1046        "out" {
1047            set _view(zoom) [expr {$_view(zoom)*0.8}]
1048            set _settings($this-zoom) $_view(zoom)
1049        }
1050        "reset" {
1051            array set _view {
1052                theta   45
1053                phi     45
1054                psi     0
1055                zoom    1.0
1056                pan-x   0
1057                pan-y   0
1058            }
1059            if { $_first != "" } {
1060                set location [$_first hints camera]
1061                if { $location != "" } {
1062                    array set _view $location
1063                }
1064            }
1065            set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)]
1066            SendCmd "camera angle $xyz"
1067            PanCamera
1068            set _settings($this-theta) $_view(theta)
1069            set _settings($this-phi)   $_view(phi)
1070            set _settings($this-psi)   $_view(psi)
1071            set _settings($this-pan-x) $_view(pan-x)
1072            set _settings($this-pan-y) $_view(pan-y)
1073            set _settings($this-zoom)  $_view(zoom)
1074        }
1075    }
1076    SendCmd "camera zoom $_view(zoom)"
1077}
1078
1079itcl::body Rappture::NanovisViewer::PanCamera {} {
1080    #set x [expr ($_view(pan-x)) / $_limits(xrange)]
1081    #set y [expr ($_view(pan-y)) / $_limits(yrange)]
1082    set x $_view(pan-x)
1083    set y $_view(pan-y)
1084    SendCmd "camera pan $x $y"
1085}
1086
1087
1088# ----------------------------------------------------------------------
1089# USAGE: Rotate click <x> <y>
1090# USAGE: Rotate drag <x> <y>
1091# USAGE: Rotate release <x> <y>
1092#
1093# Called automatically when the user clicks/drags/releases in the
1094# plot area.  Moves the plot according to the user's actions.
1095# ----------------------------------------------------------------------
1096itcl::body Rappture::NanovisViewer::Rotate {option x y} {
1097    switch -- $option {
1098        click {
1099            $itk_component(3dview) configure -cursor fleur
1100            set _click(x) $x
1101            set _click(y) $y
1102            set _click(theta) $_view(theta)
1103            set _click(phi) $_view(phi)
1104        }
1105        drag {
1106            if {[array size _click] == 0} {
1107                Rotate click $x $y
1108            } else {
1109                set w [winfo width $itk_component(3dview)]
1110                set h [winfo height $itk_component(3dview)]
1111                if {$w <= 0 || $h <= 0} {
1112                    return
1113                }
1114
1115                if {[catch {
1116                    # this fails sometimes for no apparent reason
1117                    set dx [expr {double($x-$_click(x))/$w}]
1118                    set dy [expr {double($y-$_click(y))/$h}]
1119                }]} {
1120                    return
1121                }
1122
1123                #
1124                # Rotate the camera in 3D
1125                #
1126                if {$_view(psi) > 90 || $_view(psi) < -90} {
1127                    # when psi is flipped around, theta moves backwards
1128                    set dy [expr {-$dy}]
1129                }
1130                set theta [expr {$_view(theta) - $dy*180}]
1131                while {$theta < 0} { set theta [expr {$theta+180}] }
1132                while {$theta > 180} { set theta [expr {$theta-180}] }
1133
1134                if {abs($theta) >= 30 && abs($theta) <= 160} {
1135                    set phi [expr {$_view(phi) - $dx*360}]
1136                    while {$phi < 0} { set phi [expr {$phi+360}] }
1137                    while {$phi > 360} { set phi [expr {$phi-360}] }
1138                    set psi $_view(psi)
1139                } else {
1140                    set phi $_view(phi)
1141                    set psi [expr {$_view(psi) - $dx*360}]
1142                    while {$psi < -180} { set psi [expr {$psi+360}] }
1143                    while {$psi > 180} { set psi [expr {$psi-360}] }
1144                }
1145
1146                set _view(theta)        $theta
1147                set _view(phi)          $phi
1148                set _view(psi)          $psi
1149                set xyz [Euler2XYZ $theta $phi $psi]
1150                set _settings($this-theta) $_view(theta)
1151                set _settings($this-phi)   $_view(phi)
1152                set _settings($this-psi)   $_view(psi)
1153                SendCmd "camera angle $xyz"
1154                set _click(x) $x
1155                set _click(y) $y
1156            }
1157        }
1158        release {
1159            Rotate drag $x $y
1160            $itk_component(3dview) configure -cursor ""
1161            catch {unset _click}
1162        }
1163        default {
1164            error "bad option \"$option\": should be click, drag, release"
1165        }
1166    }
1167}
1168
1169# ----------------------------------------------------------------------
1170# USAGE: $this Pan click x y
1171#        $this Pan drag x y
1172#        $this Pan release x y
1173#
1174# Called automatically when the user clicks on one of the zoom
1175# controls for this widget.  Changes the zoom for the current view.
1176# ----------------------------------------------------------------------
1177itcl::body Rappture::NanovisViewer::Pan {option x y} {
1178    # Experimental stuff
1179    set w [winfo width $itk_component(3dview)]
1180    set h [winfo height $itk_component(3dview)]
1181    if { $option == "set" } {
1182        set x [expr $x / double($w)]
1183        set y [expr $y / double($h)]
1184        set _view(pan-x) [expr $_view(pan-x) + $x]
1185        set _view(pan-y) [expr $_view(pan-y) + $y]
1186        PanCamera
1187        set _settings($this-pan-x) $_view(pan-x)
1188        set _settings($this-pan-y) $_view(pan-y)
1189        return
1190    }
1191    if { $option == "click" } {
1192        set _click(x) $x
1193        set _click(y) $y
1194        $itk_component(3dview) configure -cursor hand1
1195    }
1196    if { $option == "drag" || $option == "release" } {
1197        set dx [expr ($_click(x) - $x)/double($w)]
1198        set dy [expr ($_click(y) - $y)/double($h)]
1199        set _click(x) $x
1200        set _click(y) $y
1201        set _view(pan-x) [expr $_view(pan-x) - $dx]
1202        set _view(pan-y) [expr $_view(pan-y) - $dy]
1203        PanCamera
1204        set _settings($this-pan-x) $_view(pan-x)
1205        set _settings($this-pan-y) $_view(pan-y)
1206    }
1207    if { $option == "release" } {
1208        $itk_component(3dview) configure -cursor ""
1209    }
1210}
1211
1212# ----------------------------------------------------------------------
1213# USAGE: FixSettings <what> ?<value>?
1214#
1215# Used internally to update rendering settings whenever parameters
1216# change in the popup settings panel.  Sends the new settings off
1217# to the back end.
1218# ----------------------------------------------------------------------
1219itcl::body Rappture::NanovisViewer::FixSettings {what {value ""}} {
1220    switch -- $what {
1221        light {
1222            if {[isconnected]} {
1223                set val $_settings($this-light)
1224                set sval [expr {0.1*$val}]
1225                SendCmd "volume shading diffuse $sval"
1226                set sval [expr {sqrt($val+1.0)}]
1227                SendCmd "volume shading specular $sval"
1228            }
1229        }
1230        transp {
1231            if {[isconnected]} {
1232                set val $_settings($this-transp)
1233                set sval [expr {0.2*$val+1}]
1234                SendCmd "volume shading opacity $sval"
1235            }
1236        }
1237        opacity {
1238            if {[isconnected] && $_activeTf != "" } {
1239                set val $_settings($this-opacity)
1240                set sval [expr { 0.01 * double($val) }]
1241                set tf $_activeTf
1242                set _settings($this-$tf-opacity) $sval
1243                updatetransferfuncs
1244            }
1245        }
1246
1247        thickness {
1248            if {[isconnected] && $_activeTf != "" } {
1249                set val $_settings($this-thickness)
1250                # Scale values between 0.00001 and 0.01000
1251                set sval [expr {0.0001*double($val)}]
1252                set tf $_activeTf
1253                set _settings($this-$tf-thickness) $sval
1254                updatetransferfuncs
1255            }
1256        }
1257        "outline" {
1258            if {[isconnected]} {
1259                SendCmd "volume outline state $_settings($this-outline)"
1260            }
1261        }
1262        "isosurface" {
1263            if {[isconnected]} {
1264                SendCmd "volume shading isosurface $_settings($this-isosurface)"
1265            }
1266        }
1267        "grid" {
1268            if { [isconnected] } {
1269                SendCmd "grid visible $_settings($this-grid)"
1270            }
1271        }
1272        "axes" {
1273            if { [isconnected] } {
1274                SendCmd "axis visible $_settings($this-axes)"
1275            }
1276        }
1277        "legend" {
1278            if { $_settings($this-legend) } {
1279                blt::table $itk_component(plotarea) \
1280                    0,0 $itk_component(3dview) -fill both \
1281                    1,0 $itk_component(legend) -fill x
1282                blt::table configure $itk_component(plotarea) r1 -resize none
1283            } else {
1284                blt::table forget $itk_component(legend)
1285            }
1286        }
1287        "volume" {
1288            if { [isconnected] } {
1289                set vols [CurrentVolumeIds -cutplanes]
1290                SendCmd "volume data state $_settings($this-volume) $vols"
1291            }
1292        }
1293        "xcutplane" - "ycutplane" - "zcutplane" {
1294            set axis [string range $what 0 0]
1295            set bool $_settings($this-$what)
1296            if { [isconnected] } {
1297                set vols [CurrentVolumeIds -cutplanes]
1298                SendCmd "cutplane state $bool $axis $vols"
1299            }
1300            if { $bool } {
1301                $itk_component(${axis}CutScale) configure -state normal \
1302                    -troughcolor white
1303            } else {
1304                $itk_component(${axis}CutScale) configure -state disabled \
1305                    -troughcolor grey82
1306            }
1307        }
1308        default {
1309            error "don't know how to fix $what"
1310        }
1311    }
1312}
1313
1314# ----------------------------------------------------------------------
1315# USAGE: FixLegend
1316#
1317# Used internally to update the legend area whenever it changes size
1318# or when the field changes.  Asks the server to send a new legend
1319# for the current field.
1320# ----------------------------------------------------------------------
1321itcl::body Rappture::NanovisViewer::FixLegend {} {
1322    set lineht [font metrics $itk_option(-font) -linespace]
1323    set w [expr {$_width-20}]
1324    set h [expr {[winfo height $itk_component(legend)]-20-$lineht}]
1325    if {$w > 0 && $h > 0 && "" != $_activeTf} {
1326        SendCmd "legend $_activeTf $w $h"
1327    } else {
1328        # Can't do this as this will remove the items associated with the
1329        # isomarkers.
1330       
1331        #$itk_component(legend) delete all
1332    }
1333}
1334
1335#
1336# NameTransferFunc --
1337#
1338#       Creates a transfer function name based on the <style> settings in the
1339#       library run.xml file. This placeholder will be used later to create
1340#       and send the actual transfer function once the data info has been sent
1341#       to us by the render server. [We won't know the volume limits until the
1342#       server parses the 3D data and sends back the limits via ReceiveData.]
1343#
1344#       FIXME: The current way we generate transfer-function names completely
1345#              ignores the -markers option.  The problem is that we are forced
1346#              to compute the name from an increasing complex set of values:
1347#              color, levels, marker, opacity.  I think we're stuck doing it
1348#              now.
1349#
1350itcl::body Rappture::NanovisViewer::NameTransferFunc { dataobj comp } {
1351    array set style {
1352        -color rainbow
1353        -levels 6
1354        -opacity 1.0
1355    }
1356    array set style [lindex [$dataobj components -style $comp] 0]
1357    set tf "$style(-color):$style(-levels):$style(-opacity)"
1358    lappend _obj2style($dataobj-$comp) $tf
1359    lappend _style2objs($tf) $dataobj $comp
1360    return $tf
1361}
1362
1363#
1364# ComputeTransferFunc --
1365#
1366#   Computes and sends the transfer function to the render server.  It's
1367#   assumed that the volume data limits are known and that the global
1368#   transfer-functions slider values have be setup.  Both parts are
1369#   needed to compute the relative value (location) of the marker, and
1370#   the alpha map of the transfer function.
1371#
1372itcl::body Rappture::NanovisViewer::ComputeTransferFunc { tf } {
1373    array set style {
1374        -color rainbow
1375        -levels 6
1376        -opacity 1.0
1377    }
1378    set dataobj ""; set comp ""
1379    foreach {dataobj comp} $_style2objs($tf) break
1380    if { $dataobj == "" } {
1381        return 0
1382    }
1383    array set style [lindex [$dataobj components -style $comp] 0]
1384
1385
1386    # We have to parse the style attributes for a volume using this
1387    # transfer-function *once*.  This sets up the initial isomarkers for the
1388    # transfer function.  The user may add/delete markers, so we have to
1389    # maintain a list of markers for each transfer-function.  We use the one
1390    # of the volumes (the first in the list) using the transfer-function as a
1391    # reference.
1392    #
1393    # FIXME: The current way we generate transfer-function names completely
1394    #        ignores the -markers option.  The problem is that we are forced
1395    #        to compute the name from an increasing complex set of values:
1396    #        color, levels, marker, opacity.  I think the cow's out of the
1397    #        barn on this one.
1398
1399    if { ![info exists _isomarkers($tf)] } {
1400        # Have to defer creation of isomarkers until we have data limits
1401        if { [info exists style(-markers)] } {
1402            ParseMarkersOption $tf $style(-markers)
1403        } else {
1404            ParseLevelsOption $tf $style(-levels)
1405        }
1406    }
1407    if {$style(-color) == "rainbow"} {
1408        set style(-color) "white:yellow:green:cyan:blue:magenta"
1409    }
1410    set clist [split $style(-color) :]
1411    set cmap "0.0 [Color2RGB white] "
1412    for {set i 0} {$i < [llength $clist]} {incr i} {
1413        set x [expr {double($i+1)/([llength $clist]+1)}]
1414        set color [lindex $clist $i]
1415        append cmap "$x [Color2RGB $color] "
1416    }
1417    append cmap "1.0 [Color2RGB $color]"
1418
1419    set tag $this-$tf
1420    if { ![info exists _settings($tag-opacity)] } {
1421        set _settings($tag-opacity) $style(-opacity)
1422    }
1423    set max $_settings($tag-opacity)
1424
1425    set isovalues {}
1426    foreach m $_isomarkers($tf) {
1427        lappend isovalues [$m relval]
1428    }
1429    # Sort the isovalues
1430    set isovalues [lsort -real $isovalues]
1431
1432    if { ![info exists _settings($tag-thickness)]} {
1433        set _settings($tag-thickness) 0.05
1434    }
1435    set delta $_settings($tag-thickness)
1436
1437    set first [lindex $isovalues 0]
1438    set last [lindex $isovalues end]
1439    set wmap ""
1440    if { $first == "" || $first != 0.0 } {
1441        lappend wmap 0.0 0.0
1442    }
1443    foreach x $isovalues {
1444        set x1 [expr {$x-$delta-0.00001}]
1445        set x2 [expr {$x-$delta}]
1446        set x3 [expr {$x+$delta}]
1447        set x4 [expr {$x+$delta+0.00001}]
1448        if { $x1 < 0.0 } {
1449            set x1 0.0
1450        } elseif { $x1 > 1.0 } {
1451            set x1 1.0
1452        }
1453        if { $x2 < 0.0 } {
1454            set x2 0.0
1455        } elseif { $x2 > 1.0 } {
1456            set x2 1.0
1457        }
1458        if { $x3 < 0.0 } {
1459            set x3 0.0
1460        } elseif { $x3 > 1.0 } {
1461            set x3 1.0
1462        }
1463        if { $x4 < 0.0 } {
1464            set x4 0.0
1465        } elseif { $x4 > 1.0 } {
1466            set x4 1.0
1467        }
1468        # add spikes in the middle
1469        lappend wmap $x1 0.0
1470        lappend wmap $x2 $max
1471        lappend wmap $x3 $max
1472        lappend wmap $x4 0.0
1473    }
1474    if { $last == "" || $last != 1.0 } {
1475        lappend wmap 1.0 0.0
1476    }
1477    SendBytes "transfunc define $tf { $cmap } { $wmap }\n"
1478    if { [info exists _obj2id($dataobj-$comp)] } {
1479        return [SendBytes "volume shading transfunc $tf $_obj2id($dataobj-$comp)\n"]
1480    }
1481}
1482
1483# ----------------------------------------------------------------------
1484# CONFIGURATION OPTION: -plotbackground
1485# ----------------------------------------------------------------------
1486itcl::configbody Rappture::NanovisViewer::plotbackground {
1487    if { [isconnected] } {
1488        foreach {r g b} [Color2RGB $itk_option(-plotbackground)] break
1489        #fix this!
1490        #SendCmd "color background $r $g $b"
1491    }
1492}
1493
1494# ----------------------------------------------------------------------
1495# CONFIGURATION OPTION: -plotforeground
1496# ----------------------------------------------------------------------
1497itcl::configbody Rappture::NanovisViewer::plotforeground {
1498    if { [isconnected] } {
1499        foreach {r g b} [Color2RGB $itk_option(-plotforeground)] break
1500        #fix this!
1501        #SendCmd "color background $r $g $b"
1502    }
1503}
1504
1505# ----------------------------------------------------------------------
1506# CONFIGURATION OPTION: -plotoutline
1507# ----------------------------------------------------------------------
1508itcl::configbody Rappture::NanovisViewer::plotoutline {
1509    # Must check if we are connected because this routine is called from the
1510    # class body when the -plotoutline itk_option is defined.  At that point
1511    # the NanovisViewer class constructor hasn't been called, so we can't
1512    # start sending commands to visualization server.
1513    if { [isconnected] } {
1514        if {"" == $itk_option(-plotoutline)} {
1515            SendCmd "volume outline state off"
1516        } else {
1517            SendCmd "volume outline state on"
1518            SendCmd "volume outline color [Color2RGB $itk_option(-plotoutline)]"
1519        }
1520    }
1521}
1522
1523#
1524# The -levels option takes a single value that represents the number
1525# of evenly distributed markers based on the current data range. Each
1526# marker is a relative value from 0.0 to 1.0.
1527#
1528itcl::body Rappture::NanovisViewer::ParseLevelsOption { tf levels } {
1529    set c $itk_component(legend)
1530    regsub -all "," $levels " " levels
1531    if {[string is int $levels]} {
1532        for {set i 1} { $i <= $levels } {incr i} {
1533            set x [expr {double($i)/($levels+1)}]
1534            set m [Rappture::IsoMarker \#auto $c $this $tf]
1535            $m relval $x
1536            lappend _isomarkers($tf) $m
1537        }
1538    } else {
1539        foreach x $levels {
1540            set m [Rappture::IsoMarker \#auto $c $this $tf]
1541            $m relval $x
1542            lappend _isomarkers($tf) $m
1543        }
1544    }
1545}
1546
1547#
1548# The -markers option takes a list of zero or more values (the values
1549# may be separated either by spaces or commas) that have the following
1550# format:
1551#
1552#   N%  Percent of current total data range.  Converted to
1553#       to a relative value between 0.0 and 1.0.
1554#   N   Absolute value of marker.  If the marker is outside of
1555#       the current range, it will be displayed on the outer
1556#       edge of the legends, but it range it represents will
1557#       not be seen.
1558#
1559itcl::body Rappture::NanovisViewer::ParseMarkersOption { tf markers } {
1560    set c $itk_component(legend)
1561    regsub -all "," $markers " " markers
1562    foreach marker $markers {
1563        set n [scan $marker "%g%s" value suffix]
1564        if { $n == 2 && $suffix == "%" } {
1565            # ${n}% : Set relative value.
1566            set value [expr {$value * 0.01}]
1567            set m [Rappture::IsoMarker \#auto $c $this $tf]
1568            $m relval $value
1569            lappend _isomarkers($tf) $m
1570        } else {
1571            # ${n} : Set absolute value.
1572            set m [Rappture::IsoMarker \#auto $c $this $tf]
1573            $m absval $value
1574            lappend _isomarkers($tf) $m
1575        }
1576    }
1577}
1578
1579# ----------------------------------------------------------------------
1580# USAGE: UndateTransferFuncs
1581# ----------------------------------------------------------------------
1582itcl::body Rappture::NanovisViewer::updatetransferfuncs {} {
1583    $_dispatcher event -idle !send_transfunc
1584}
1585
1586itcl::body Rappture::NanovisViewer::AddIsoMarker { x y } {
1587    if { $_activeTf == "" } {
1588        error "active transfer function isn't set"
1589    }
1590    set tf $_activeTf
1591    set c $itk_component(legend)
1592    set m [Rappture::IsoMarker \#auto $c $this $tf]
1593    set w [winfo width $c]
1594    $m relval [expr {double($x-10)/($w-20)}]
1595    lappend _isomarkers($tf) $m
1596    updatetransferfuncs
1597    return 1
1598}
1599
1600itcl::body Rappture::NanovisViewer::rmdupmarker { marker x } {
1601    set tf [$marker transferfunc]
1602    set bool 0
1603    if { [info exists _isomarkers($tf)] } {
1604        set list {}
1605        set marker [namespace tail $marker]
1606        foreach m $_isomarkers($tf) {
1607            set sx [$m screenpos]
1608            if { $m != $marker } {
1609                if { $x >= ($sx-3) && $x <= ($sx+3) } {
1610                    $marker relval [$m relval]
1611                    itcl::delete object $m
1612                    bell
1613                    set bool 1
1614                    continue
1615                }
1616            }
1617            lappend list $m
1618        }
1619        set _isomarkers($tf) $list
1620        updatetransferfuncs
1621    }
1622    return $bool
1623}
1624
1625itcl::body Rappture::NanovisViewer::overmarker { marker x } {
1626    set tf [$marker transferfunc]
1627    if { [info exists _isomarkers($tf)] } {
1628        set marker [namespace tail $marker]
1629        foreach m $_isomarkers($tf) {
1630            set sx [$m screenpos]
1631            if { $m != $marker } {
1632                set bool [expr { $x >= ($sx-3) && $x <= ($sx+3) }]
1633                $m activate $bool
1634            }
1635        }
1636    }
1637    return ""
1638}
1639
1640itcl::body Rappture::NanovisViewer::limits { tf } {
1641    set _limits(min) 0.0
1642    set _limits(max) 1.0
1643    if { ![info exists _style2objs($tf)] } {
1644        return [array get _limits]
1645    }
1646    set min ""; set max ""
1647    foreach {dataobj comp} $_style2objs($tf) {
1648        if { ![info exists _obj2id($dataobj-$comp)] } {
1649            continue
1650        }
1651        set ivol $_obj2id($dataobj-$comp)
1652        if { ![info exists _limits($ivol-min)] } {
1653            continue
1654        }
1655        if { $min == "" || $min > $_limits($ivol-min) } {
1656            set min $_limits($ivol-min)
1657        }
1658        if { $max == "" || $max < $_limits($ivol-max) } {
1659            set max $_limits($ivol-max)
1660        }
1661    }
1662    if { $min != "" } {
1663        set _limits(min) $min
1664    }
1665    if { $max != "" } {
1666        set _limits(max) $max
1667    }
1668    return [array get _limits]
1669}
1670
1671
1672itcl::body Rappture::NanovisViewer::BuildViewTab {} {
1673    foreach { key value } {
1674        grid            0
1675        axes            1
1676        outline         1
1677        volume          1
1678        legend          1
1679        particles       1
1680        lic             1
1681    } {
1682        set _settings($this-$key) $value
1683    }
1684
1685    set fg [option get $itk_component(hull) font Font]
1686    #set bfg [option get $itk_component(hull) boldFont Font]
1687
1688    set inner [$itk_component(main) insert end \
1689        -title "View Settings" \
1690        -icon [Rappture::icon wrench]]
1691    $inner configure -borderwidth 4
1692
1693    set ::Rappture::NanovisViewer::_settings($this-isosurface) 0
1694    checkbutton $inner.isosurface \
1695        -text "Isosurface shading" \
1696        -variable [itcl::scope _settings($this-isosurface)] \
1697        -command [itcl::code $this FixSettings isosurface] \
1698        -font "Arial 9"
1699
1700    checkbutton $inner.axes \
1701        -text "Axes" \
1702        -variable [itcl::scope _settings($this-axes)] \
1703        -command [itcl::code $this FixSettings axes] \
1704        -font "Arial 9"
1705
1706    checkbutton $inner.grid \
1707        -text "Grid" \
1708        -variable [itcl::scope _settings($this-grid)] \
1709        -command [itcl::code $this FixSettings grid] \
1710        -font "Arial 9"
1711
1712    checkbutton $inner.outline \
1713        -text "Outline" \
1714        -variable [itcl::scope _settings($this-outline)] \
1715        -command [itcl::code $this FixSettings outline] \
1716        -font "Arial 9"
1717
1718    checkbutton $inner.legend \
1719        -text "Legend" \
1720        -variable [itcl::scope _settings($this-legend)] \
1721        -command [itcl::code $this FixSettings legend] \
1722        -font "Arial 9"
1723
1724    checkbutton $inner.volume \
1725        -text "Volume" \
1726        -variable [itcl::scope _settings($this-volume)] \
1727        -command [itcl::code $this FixSettings volume] \
1728        -font "Arial 9"
1729
1730    blt::table $inner \
1731        0,0 $inner.axes  -columnspan 2 -anchor w \
1732        1,0 $inner.grid  -columnspan 2 -anchor w \
1733        2,0 $inner.outline  -columnspan 2 -anchor w \
1734        3,0 $inner.volume  -columnspan 2 -anchor w \
1735        4,0 $inner.legend  -columnspan 2 -anchor w
1736
1737    blt::table configure $inner r* -resize none
1738    blt::table configure $inner r5 -resize expand
1739}
1740
1741itcl::body Rappture::NanovisViewer::BuildVolumeTab {} {
1742    foreach { key value } {
1743        light           40
1744        transp          50
1745        opacity         100
1746        thickness       350
1747    } {
1748        set _settings($this-$key) $value
1749    }
1750
1751    set inner [$itk_component(main) insert end \
1752        -title "Volume Settings" \
1753        -icon [Rappture::icon volume-on]]
1754    $inner configure -borderwidth 4
1755
1756    set fg [option get $itk_component(hull) font Font]
1757    #set bfg [option get $itk_component(hull) boldFont Font]
1758
1759    checkbutton $inner.vol -text "Show volume" -font $fg \
1760        -variable [itcl::scope _settings($this-volume)] \
1761        -command [itcl::code $this FixSettings volume]
1762    label $inner.shading -text "Shading:" -font $fg
1763
1764    label $inner.dim -text "Dim" -font $fg
1765    ::scale $inner.light -from 0 -to 100 -orient horizontal \
1766        -variable [itcl::scope _settings($this-light)] \
1767        -width 10 \
1768        -showvalue off -command [itcl::code $this FixSettings light]
1769    label $inner.bright -text "Bright" -font $fg
1770
1771    label $inner.fog -text "Fog" -font $fg
1772    ::scale $inner.transp -from 0 -to 100 -orient horizontal \
1773        -variable [itcl::scope _settings($this-transp)] \
1774        -width 10 \
1775        -showvalue off -command [itcl::code $this FixSettings transp]
1776    label $inner.plastic -text "Plastic" -font $fg
1777
1778    label $inner.clear -text "Clear" -font $fg
1779    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
1780        -variable [itcl::scope _settings($this-opacity)] \
1781        -width 10 \
1782        -showvalue off -command [itcl::code $this FixSettings opacity]
1783    label $inner.opaque -text "Opaque" -font $fg
1784
1785    label $inner.thin -text "Thin" -font $fg
1786    ::scale $inner.thickness -from 0 -to 1000 -orient horizontal \
1787        -variable [itcl::scope _settings($this-thickness)] \
1788        -width 10 \
1789        -showvalue off -command [itcl::code $this FixSettings thickness]
1790    label $inner.thick -text "Thick" -font $fg
1791
1792    blt::table $inner \
1793        0,0 $inner.vol -columnspan 4 -anchor w -pady 2 \
1794        1,0 $inner.shading -columnspan 4 -anchor w -pady {10 2} \
1795        2,0 $inner.dim -anchor e -pady 2 \
1796        2,1 $inner.light -columnspan 2 -pady 2 -fill x \
1797        2,3 $inner.bright -anchor w -pady 2 \
1798        3,0 $inner.fog -anchor e -pady 2 \
1799        3,1 $inner.transp -columnspan 2 -pady 2 -fill x \
1800        3,3 $inner.plastic -anchor w -pady 2 \
1801        4,0 $inner.clear -anchor e -pady 2 \
1802        4,1 $inner.opacity -columnspan 2 -pady 2 -fill x\
1803        4,3 $inner.opaque -anchor w -pady 2 \
1804        5,0 $inner.thin -anchor e -pady 2 \
1805        5,1 $inner.thickness -columnspan 2 -pady 2 -fill x\
1806        5,3 $inner.thick -anchor w -pady 2
1807
1808    blt::table configure $inner c0 c1 c3 r* -resize none
1809    blt::table configure $inner r6 -resize expand
1810}
1811
1812itcl::body Rappture::NanovisViewer::BuildCutplanesTab {} {
1813    set inner [$itk_component(main) insert end \
1814        -title "Cutplane Settings" \
1815        -icon [Rappture::icon cutbutton]]
1816    $inner configure -borderwidth 4
1817
1818    # X-value slicer...
1819    itk_component add xCutButton {
1820        Rappture::PushButton $inner.xbutton \
1821            -onimage [Rappture::icon x-cutplane-on] \
1822            -offimage [Rappture::icon x-cutplane-off] \
1823            -command [itcl::code $this FixSettings xcutplane] \
1824            -variable [itcl::scope _settings($this-xcutplane)]
1825    }
1826    Rappture::Tooltip::for $itk_component(xCutButton) \
1827        "Toggle the X cut plane on/off"
1828
1829    itk_component add xCutScale {
1830        ::scale $inner.xval -from 100 -to 0 \
1831            -width 10 -orient vertical -showvalue off \
1832            -borderwidth 1 -highlightthickness 0 \
1833            -command [itcl::code $this Slice move x] \
1834            -variable [itcl::scope _settings($this-xcutposition)]
1835    } {
1836        usual
1837        ignore -borderwidth -highlightthickness
1838    }
1839    # Set the default cutplane value before disabling the scale.
1840    $itk_component(xCutScale) set 50
1841    $itk_component(xCutScale) configure -state disabled
1842    Rappture::Tooltip::for $itk_component(xCutScale) \
1843        "@[itcl::code $this SlicerTip x]"
1844
1845    # Y-value slicer...
1846    itk_component add yCutButton {
1847        Rappture::PushButton $inner.ybutton \
1848            -onimage [Rappture::icon y-cutplane-on] \
1849            -offimage [Rappture::icon y-cutplane-off] \
1850            -command [itcl::code $this FixSettings ycutplane] \
1851            -variable [itcl::scope _settings($this-ycutplane)]
1852    }
1853    Rappture::Tooltip::for $itk_component(yCutButton) \
1854        "Toggle the Y cut plane on/off"
1855
1856    itk_component add yCutScale {
1857        ::scale $inner.yval -from 100 -to 0 \
1858            -width 10 -orient vertical -showvalue off \
1859            -borderwidth 1 -highlightthickness 0 \
1860            -command [itcl::code $this Slice move y] \
1861            -variable [itcl::scope _settings($this-ycutposition)]
1862    } {
1863        usual
1864        ignore -borderwidth -highlightthickness
1865    }
1866    Rappture::Tooltip::for $itk_component(yCutScale) \
1867        "@[itcl::code $this SlicerTip y]"
1868    # Set the default cutplane value before disabling the scale.
1869    $itk_component(yCutScale) set 50
1870    $itk_component(yCutScale) configure -state disabled
1871
1872    # Z-value slicer...
1873    itk_component add zCutButton {
1874        Rappture::PushButton $inner.zbutton \
1875            -onimage [Rappture::icon z-cutplane-on] \
1876            -offimage [Rappture::icon z-cutplane-off] \
1877            -command [itcl::code $this FixSettings zcutplane] \
1878            -variable [itcl::scope _settings($this-zcutplane)]
1879    }
1880    Rappture::Tooltip::for $itk_component(zCutButton) \
1881        "Toggle the Z cut plane on/off"
1882
1883    itk_component add zCutScale {
1884        ::scale $inner.zval -from 100 -to 0 \
1885            -width 10 -orient vertical -showvalue off \
1886            -borderwidth 1 -highlightthickness 0 \
1887            -command [itcl::code $this Slice move z] \
1888            -variable [itcl::scope _settings($this-zcutposition)]
1889    } {
1890        usual
1891        ignore -borderwidth -highlightthickness
1892    }
1893    $itk_component(zCutScale) set 50
1894    $itk_component(zCutScale) configure -state disabled
1895    #$itk_component(zCutScale) configure -state disabled
1896    Rappture::Tooltip::for $itk_component(zCutScale) \
1897        "@[itcl::code $this SlicerTip z]"
1898
1899    blt::table $inner \
1900        1,1 $itk_component(xCutButton) \
1901        1,2 $itk_component(yCutButton) \
1902        1,3 $itk_component(zCutButton) \
1903        0,1 $itk_component(xCutScale) \
1904        0,2 $itk_component(yCutScale) \
1905        0,3 $itk_component(zCutScale) \
1906
1907    blt::table configure $inner r0 r1 c* -resize none
1908    blt::table configure $inner r2 c4 -resize expand
1909    blt::table configure $inner c0 -width 2
1910    blt::table configure $inner c1 c2 c3 -padx 2
1911}
1912
1913itcl::body Rappture::NanovisViewer::BuildCameraTab {} {
1914    set inner [$itk_component(main) insert end \
1915        -title "Camera Settings" \
1916        -icon [Rappture::icon camera]]
1917    $inner configure -borderwidth 4
1918
1919    set labels { phi theta psi pan-x pan-y zoom }
1920    set row 0
1921    foreach tag $labels {
1922        label $inner.${tag}label -text $tag -font "Arial 9"
1923        entry $inner.${tag} -font "Arial 9"  -bg white \
1924            -textvariable [itcl::scope _settings($this-$tag)]
1925        bind $inner.${tag} <KeyPress-Return> \
1926            [itcl::code $this camera set ${tag}]
1927        blt::table $inner \
1928            $row,0 $inner.${tag}label -anchor e -pady 2 \
1929            $row,1 $inner.${tag} -anchor w -pady 2
1930        blt::table configure $inner r$row -resize none
1931        incr row
1932    }
1933    blt::table configure $inner c0 c1 -resize none
1934    blt::table configure $inner c2 -resize expand
1935    blt::table configure $inner r$row -resize expand
1936}
1937
1938
1939# ----------------------------------------------------------------------
1940# USAGE: Slice move x|y|z <newval>
1941#
1942# Called automatically when the user drags the slider to move the
1943# cut plane that slices 3D data.  Gets the current value from the
1944# slider and moves the cut plane to the appropriate point in the
1945# data set.
1946# ----------------------------------------------------------------------
1947itcl::body Rappture::NanovisViewer::Slice {option args} {
1948    switch -- $option {
1949        move {
1950            if {[llength $args] != 2} {
1951                error "wrong # args: should be \"Slice move x|y|z newval\""
1952            }
1953            set axis [lindex $args 0]
1954            set newval [lindex $args 1]
1955
1956            set newpos [expr {0.01*$newval}]
1957            set ids [CurrentVolumeIds -cutplanes]
1958            SendCmd "cutplane position $newpos $axis $ids"
1959        }
1960        default {
1961            error "bad option \"$option\": should be axis, move, or volume"
1962        }
1963    }
1964}
1965
1966# ----------------------------------------------------------------------
1967# USAGE: SlicerTip <axis>
1968#
1969# Used internally to generate a tooltip for the x/y/z slicer controls.
1970# Returns a message that includes the current slicer value.
1971# ----------------------------------------------------------------------
1972itcl::body Rappture::NanovisViewer::SlicerTip {axis} {
1973    set val [$itk_component(${axis}CutScale) get]
1974#    set val [expr {0.01*($val-50)
1975#        *($_limits(${axis}max)-$_limits(${axis}min))
1976#          + 0.5*($_limits(${axis}max)+$_limits(${axis}min))}]
1977    return "Move the [string toupper $axis] cut plane.\nCurrently:  $axis = $val%"
1978}
1979
1980
1981itcl::body Rappture::NanovisViewer::DoResize {} {
1982    SendCmd "screen $_width $_height"
1983}
1984
1985itcl::body Rappture::NanovisViewer::EventuallyResize { w h } {
1986    if { $_width != $w || $_height != $h } {
1987        set _width $w
1988        set _height $h
1989        $_dispatcher event -idle !resize
1990    }
1991}
1992
1993itcl::body Rappture::NanovisViewer::EventuallyResizeLegend {} {
1994    $_dispatcher event -idle !legend
1995}
1996
1997
1998#  camera --
1999#
2000itcl::body Rappture::NanovisViewer::camera {option args} {
2001    switch -- $option {
2002        "show" {
2003            puts [array get _view]
2004        }
2005        "set" {
2006            set who [lindex $args 0]
2007            set x $_settings($this-$who)
2008            set code [catch { string is double $x } result]
2009            if { $code != 0 || !$result } {
2010                set _settings($this-$who) $_view($who)
2011                return
2012            }
2013            switch -- $who {
2014                "pan-x" - "pan-y" {
2015                    set _view($who) $_settings($this-$who)
2016                    PanCamera
2017                }
2018                "phi" - "theta" - "psi" {
2019                    set _view($who) $_settings($this-$who)
2020                    set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)]
2021                    SendCmd "camera angle $xyz"
2022                }
2023                "zoom" {
2024                    set _view($who) $_settings($this-$who)
2025                    SendCmd "camera zoom $_view(zoom)"
2026                }
2027            }
2028        }
2029    }
2030}
Note: See TracBrowser for help on using the repository browser.