Index: trunk/gui/scripts/field.tcl
===================================================================
--- trunk/gui/scripts/field.tcl	(revision 1544)
+++ trunk/gui/scripts/field.tcl	(revision 1545)
@@ -763,6 +763,4 @@
 	    set _comp2dims($cname) "3D"
 	    set data [$_field get -decode yes $cname.opendx]
-	    set data [Rappture::encoding::decode -as zb64 $data]
-
 	    set data "<ODX>$data"
 	    set data [Rappture::encoding::encode -as zb64 $data]
Index: trunk/gui/scripts/flowvisviewer.tcl
===================================================================
--- trunk/gui/scripts/flowvisviewer.tcl	(revision 1544)
+++ trunk/gui/scripts/flowvisviewer.tcl	(revision 1545)
@@ -257,4 +257,11 @@
     }]
 
+    itk_component add 3dview {
+	label $itk_component(plotarea).vol -image $_image(plot) \
+	    -highlightthickness 0 -borderwidth 0
+    } {
+	usual
+	ignore -highlightthickness -borderwidth  -background
+    }
     set f [$itk_component(main) component controls]
     itk_component add reset {
Index: trunk/gui/scripts/heightmapviewer.tcl
===================================================================
--- trunk/gui/scripts/heightmapviewer.tcl	(revision 1544)
+++ trunk/gui/scripts/heightmapviewer.tcl	(revision 1545)
@@ -1,5 +1,5 @@
 
 # ----------------------------------------------------------------------
-#  COMPONENT: heightmapviewer - 3D surface rendering
+#  Component: heightmapviewer - 3D surface rendering
 #
 #  This widget performs surface rendering on 3D scalar/vector datasets.
@@ -70,5 +70,5 @@
     private method BuildCameraTab {}
     private method PanCamera {}
-
+    protected method CurrentSurfaces {{what -all}}
     protected method Rebuild {}
     protected method Zoom {option}
@@ -94,4 +94,5 @@
     private variable _serverObjs   ;# contains all the dataobj-component 
 				   ;# to heightmaps in the server
+    private variable _location ""
     private variable _first ""
     private variable _width 0
@@ -142,5 +143,7 @@
 	pan-y	0
     }
-
+    foreach val {xmin xmax ymin ymax zmin zmax vmin vmax} {
+	set _limits($val) ""
+    }
     array set _settings [subst {
 	$this-pan-x		$_view(pan-x)
@@ -159,4 +162,13 @@
     }]
 
+    itk_component add 3dview {
+	canvas $itk_component(plotarea).vol \
+	    -highlightthickness 0 -borderwidth 0 
+    } {
+	usual
+	ignore -highlightthickness -borderwidth  -background
+    }
+    $_image(plot) configure -data ""
+    $itk_component(3dview) create image 0 0 -anchor nw -image $_image(plot) 
     set f [$itk_component(main) component controls]
     itk_component add zoom {
@@ -175,5 +187,6 @@
     }
     pack $itk_component(reset) -side top -padx 1 -pady { 4 0 }
-    Rappture::Tooltip::for $itk_component(reset) "Reset the view to the default zoom level"
+    Rappture::Tooltip::for $itk_component(reset) \
+	"Reset the view to the default zoom level"
 
     itk_component add zoomin {
@@ -216,20 +229,8 @@
     BuildCameraTab
 
-    # Legend
-    set _image(legend) [image create photo]
-    itk_component add legend {
-	canvas $itk_component(plotarea).legend -width 30 -highlightthickness 0
-    } {
-	usual
-	ignore -highlightthickness
-	rename -background -plotbackground plotBackground Background
-    }
     set w [expr [winfo reqwidth $itk_component(hull)] - 80]
     pack forget $itk_component(3dview)
     pack $itk_component(3dview) -side left -fill both -expand yes
-    pack $itk_component(legend) -side left -fill y
-
-    bind $itk_component(legend) <Configure> \
-	[list $_dispatcher event -idle !legend]
+
 
     # Bindings for rotation via mouse
@@ -331,4 +332,5 @@
 	set _obj2ovride($dataobj-width) $params(-width)
 	set _obj2ovride($dataobj-raise) $params(-raise)
+	set _obj2ovride($dataobj-brightness) $params(-brightness)
 	$_dispatcher event -idle !rebuild
     }
@@ -429,6 +431,8 @@
 # ----------------------------------------------------------------------
 itcl::body Rappture::HeightmapViewer::scale { args } {
+    if 0 {
     foreach val {xmin xmax ymin ymax zmin zmax vmin vmax} {
 	set _limits($val) ""
+    }
     }
     foreach obj $args {
@@ -586,31 +590,35 @@
     if { [IsConnected] } {
 	set bytes [ReceiveBytes $size]
+	if { ![info exists _image(legend)] } {
+	    set _image(legend) [image create photo]
+	}
 	ReceiveEcho <<line "<read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
-	if 1 {
 	set src [image create photo -data $bytes]
 	blt::winop image rotate $src $_image(legend) 90
 	set dst $_image(legend)
-	} else {
-	$_image(legend) configure -data $bytes
-	}
-	set c $itk_component(legend)
+
+	set c $itk_component(3dview)
 	set w [winfo width $c]
 	set h [winfo height $c]
-	set lineht [expr [font metrics $itk_option(-font) -linespace] + 4]
-	if {"" == [$c find withtag transfunc]} {
-	    $c create image 0 [expr $lineht] -anchor ne \
-		 -image $_image(legend) -tags transfunc 
-	    $c create text 10 [expr {$h-8}] -anchor se \
-		-fill $itk_option(-plotforeground) -tags vmin \
-		-font "Arial 8 bold"
-	    $c create text [expr {$w-10}] [expr {$h-8}] -anchor ne \
-		 -fill $itk_option(-plotforeground) -tags vmax \
-		-font "Arial 8 bold"
-	}
-	$c coords transfunc [expr $w - 5] [expr $lineht]
-	$c itemconfigure vmin -text $vmin
-	$c itemconfigure vmax -text $vmax
-	$c coords vmax [expr $w - 5] 2
-	$c coords vmin [expr $w - 5] [expr $h - 2]
+	set lineht [font metrics $itk_option(-font) -linespace]
+
+	if { $_settings($this-legend) } {
+	    if { [$c find withtag "legend"] == "" } {
+		$c create image [expr {$w-2}] [expr {$lineht+2}] -anchor ne \
+		    -image $_image(legend) -tags "transfunc legend"
+		$c create text [expr {$w-2}] 2 -anchor ne \
+		    -fill $itk_option(-plotforeground) -tags "vmax legend" \
+		    -font "Arial 8 bold"
+		$c create text [expr {$w-2}] [expr {$h-2}] -anchor se \
+		    -fill $itk_option(-plotforeground) -tags "vmin legend" \
+		    -font "Arial 8 bold"
+	    }
+	    # Reset the item coordinates according the current size of the plot.
+	    $c coords transfunc [expr {$w-2}] [expr {$lineht+2}]
+	    $c itemconfigure vmin -text $vmin
+	    $c itemconfigure vmax -text $vmax
+	    $c coords vmin [expr {$w-2}] [expr {$h-2}]
+	    $c coords vmax [expr {$w-2}] 2
+	}
     }
 }
@@ -647,19 +655,19 @@
 	foreach comp [$dataobj components] {
 	    # Tell the engine to expect some data
-	    set data [$dataobj blob $comp]
-	    set nbytes [string length $data]
-	    append _outbuf "heightmap data follows $nbytes $dataobj-$comp\n"
-	    append _outbuf $data
-
 	    set tag $dataobj-$comp
-	    set _serverObjs($tag) $tag
-
-	    #
-	    # Determine the transfer function needed for this surface
-	    # and make sure that it's defined on the server.
-	    #
-	    foreach {sname cmap wmap} [GetTransfuncData $dataobj $comp] break
-	    SendCmd [list "transfunc" "define" $sname $cmap $wmap]
-	    set _obj2style($tag) $sname
+	    if { ![info exists _serverObjs($tag)] } {
+		set data [$dataobj blob $comp]
+		set nbytes [string length $data]
+		append _outbuf "heightmap data follows $nbytes $dataobj-$comp\n"
+		append _outbuf $data
+		
+		set _serverObjs($tag) $tag
+		
+		# Determine the transfer function needed for this surface
+		# and make sure that it's defined on the server.
+		foreach {sname cmap wmap} [GetTransfuncData $dataobj $comp] break
+		SendCmd [list "transfunc" "define" $sname $cmap $wmap]
+		set _obj2style($tag) $sname
+	    }
 	}
     }
@@ -674,12 +682,20 @@
 	# This is where the initial camera position is set.
 	set location [$_first hints camera]
-	if { $location != "" } {
+	if { $_location == "" && $location != "" } {
 	    array set _view $location
+	    set _location $location
 	}
     }
     SendCmd "heightmap data visible 0"
-    set heightmaps [array names _serverObjs $_first-*] 
+    set heightmaps [CurrentSurfaces] 
     if { $heightmaps != ""  && $_settings($this-surface) } {
 	SendCmd "heightmap data visible 1 $heightmaps"
+    }
+    set heightmaps [CurrentSurfaces -raise] 
+    if { $heightmaps != "" } {
+	SendCmd "heightmap opacity 0.25"
+	SendCmd "heightmap opacity 0.95 $heightmaps"
+    } else {
+	SendCmd "heightmap opacity 0.85"
     }
     foreach key $heightmaps {
@@ -923,12 +939,12 @@
     switch -- $what {
 	"legend" {
-	    if { $_settings($this-legend) } {
-		pack $itk_component(legend) -side left -fill y
-	    } else {
-		pack forget $itk_component(legend)
-	    }
-	    set lineht [expr [font metrics $itk_option(-font) -linespace] + 4]
-	    set w [expr {[winfo height $itk_component(legend)] - 2*$lineht}]
-	    set h [expr {[winfo width $itk_component(legend)] - 16}]
+	    if { !$_settings($this-legend) } {
+		$itk_component(3dview) delete "legend"
+	    }
+	    set lineht [font metrics $itk_option(-font) -linespace]
+	    set w [winfo height $itk_component(3dview)]
+	    set h [winfo width $itk_component(3dview)]
+	    set w [expr {$w - 2*$lineht - 4}]
+	    set h 12
 	    set tag ""
 	    if {"" != $_first} {
@@ -939,5 +955,5 @@
 		SendCmd "heightmap legend $tag $w $h"
 	    } else {
-		$itk_component(legend) delete all
+		#$itk_component(legend) delete all
 	    }
 	}
@@ -1198,4 +1214,5 @@
     SendCmd "screen $_width $_height"
     set _resizePending 0
+    $_dispatcher event -idle !legend
 }
 
@@ -1208,2 +1225,30 @@
     }
 }
+
+# ----------------------------------------------------------------------
+# USAGE: CurrentVolumes ?-cutplanes?
+#
+# Returns a list of volume server IDs for the current volume being
+# displayed.  This is normally a single ID, but it might be a list
+# of IDs if the current data object has multiple components.
+# ----------------------------------------------------------------------
+itcl::body Rappture::HeightmapViewer::CurrentSurfaces {{what -all}} {
+    set list {}
+    if { $what == "-all" } {
+	foreach key [array names _serverObjs] {
+	    foreach {dataobj comp} [split $key -] break
+	    if { [info exists _obj2ovride($dataobj-raise)] } {
+		lappend list $dataobj-$comp
+	    }
+	}
+    } else {
+	foreach key [array names _serverObjs] {
+	    foreach {dataobj comp} [split $key -] break
+	    if { [info exists _obj2ovride($dataobj$what)] && 
+		 $_obj2ovride($dataobj$what) } {
+		lappend list $dataobj-$comp
+	    }
+	}
+    }
+    return $list
+}
Index: trunk/gui/scripts/molvisviewer.tcl
===================================================================
--- trunk/gui/scripts/molvisviewer.tcl	(revision 1544)
+++ trunk/gui/scripts/molvisviewer.tcl	(revision 1545)
@@ -197,7 +197,12 @@
     }]
     
-    #
-    # Set up the widgets in the main body
-    #
+    itk_component add 3dview {
+	label $itk_component(plotarea).vol -image $_image(plot) \
+	    -highlightthickness 0 -borderwidth 0
+    } {
+	usual
+	ignore -highlightthickness -borderwidth  -background
+    }
+
     set f [$itk_component(main) component controls]
     itk_component add reset {
Index: trunk/gui/scripts/nanovisviewer.tcl
===================================================================
--- trunk/gui/scripts/nanovisviewer.tcl	(revision 1544)
+++ trunk/gui/scripts/nanovisviewer.tcl	(revision 1545)
@@ -207,4 +207,12 @@
 	$this-zoom		$_view(zoom)
     }]
+
+    itk_component add 3dview {
+	label $itk_component(plotarea).vol -image $_image(plot) \
+	    -highlightthickness 0 -borderwidth 0
+    } {
+	usual
+	ignore -highlightthickness -borderwidth  -background
+    }
 
     set f [$itk_component(main) component controls]
Index: trunk/gui/scripts/visviewer.tcl
===================================================================
--- trunk/gui/scripts/visviewer.tcl	(revision 1544)
+++ trunk/gui/scripts/visviewer.tcl	(revision 1545)
@@ -133,11 +133,4 @@
     pack $itk_component(plotarea) -fill both -expand yes
     set _image(plot) [image create photo]
-    itk_component add 3dview {
-	label $itk_component(plotarea).vol -image $_image(plot) \
-	    -highlightthickness 0 -borderwidth 0
-    } {
-	usual
-	ignore -highlightthickness -borderwidth  -background
-    }
     eval itk_initialize $args
 }
