Index: /trunk/gui/scripts/vtkisosurfaceviewer.tcl
===================================================================
--- /trunk/gui/scripts/vtkisosurfaceviewer.tcl	(revision 3537)
+++ /trunk/gui/scripts/vtkisosurfaceviewer.tcl	(revision 3538)
@@ -106,4 +106,5 @@
     private method SetCurrentColormap { color }
     private method SetOrientation { side }
+    private method UpdateContourList {}
 
     private variable _arcball ""
@@ -119,5 +120,5 @@
     # heightmaps displayed.
     private variable _currentColormap "" ;    
-    private variable _currentNumContours "" ;    
+    private variable _currentNumContours -1;    
     private variable _currentOpacity "" ;    
 
@@ -138,4 +139,5 @@
     private variable _title ""
     private variable _isolines
+    private variable _contourList ""
 
     common _downloadPopup;              # download options from popup
@@ -1047,5 +1049,5 @@
 	    cutplaneXPosition cutplaneYPosition cutplaneZPosition \
 	    cutplaneXVisible cutplaneYVisible cutplaneZVisible \
-            cutplanePreinterp 
+            cutplanePreinterp numContours
 
         Zoom reset
@@ -1410,8 +1412,9 @@
         }
         "numContours" {
-            set _changed(numContours) 1
             set _settings(numContours) [$itk_component(numcontours) value]
             set _currentNumContours $_settings(numContours)
-            SendCmd "contour3d numcontours $_settings(numContours)"
+            UpdateContourList 
+            set _changed(numContours) 1
+            SendCmd "contour3d contourlist [list $_contourList]"
             DrawLegend
         }
@@ -1475,4 +1478,5 @@
             SendCmd "cutplane colormode $_colorMode $_curFldName"
             SendCmd "camera reset"
+            UpdateContourList
             DrawLegend
         }
@@ -1702,5 +1706,5 @@
     itk_component add numcontours {
         Rappture::Spinint $inner.numcontours \
-            -min 2 -max 50 -font "arial 9"
+            -min 1 -max 50 -font "arial 9"
     }
     $itk_component(numcontours) value $_settings(numContours)
@@ -2168,7 +2172,8 @@
         set _settings(numContours) $_currentNumContours
         $itk_component(numcontours) value $_currentNumContours
+        UpdateContourList 
         DrawLegend
     }
-    SendCmd "contour3d add numcontours $_currentNumContours $tag"
+    SendCmd [list contour3d add contourlist $_contourList $tag]
     SendCmd "contour3d edges $style(-edges) $tag"
     SendCmd "dataset outline $style(-outline) $tag"
@@ -2411,28 +2416,24 @@
     if { $color != "none"  && [info exists _limits($_curFldName)] &&
          $_settings(numContours) > 0 } {
-	set pixels [blt::vector create \#auto]
-	set values [blt::vector create \#auto]
-	set range [image height $_image(legend)]
-	# Order of pixels is max to min (max is at top of legend).
-	$pixels seq $ih 0 $_settings(numContours)
+
+        foreach { vmin vmax } $_limits($_curFldName) break
+        set range [expr double($vmax - $vmin)]
+        if { $range <= 0.0 } {
+            set range 1.0;              # Min is greater or equal to max.
+        }
+        set tags "isoline legend"
 	set offset [expr 2 + $lineht]
-	# If there's a legend title, increase the offset by the line height.
 	if { $title != "" } {
 	    incr offset $lineht
 	}
-	# Order of values is min to max.
-        $pixels expr {round($pixels + $offset)}
-        foreach { vmin vmax } $_limits($_curFldName) break
-        $values seq $vmin $vmax $_settings(numContours)
-        set tags "isoline legend"
-        foreach pos [$pixels range 0 end] value [$values range end 0] {
-	    set y1 [expr int($pos)]
+        foreach value $_contourList {
+            set norm [expr ($value - $vmin) / $range]
+            set y1 [expr int(round(($norm * $ih) + $offset))]
             for { set off 0 } { $off < 3 } { incr off } {
                 set _isolines([expr $y1 + $off]) $value
                 set _isolines([expr $y1 - $off]) $value
             }
-            set id [$c create line $x1 $y1 $x2 $y1 -fill $color -tags $tags]
-        }
-        blt::vector destroy $pixels $values
+            $c create line $x1 $y1 $x2 $y1 -fill $color -tags $tags
+        }
     }
 
@@ -2547,2 +2548,14 @@
     set _view(zoom) 1.0
 }
+
+itcl::body Rappture::VtkIsosurfaceViewer::UpdateContourList {} { 
+    if { ![info exists _limits($_curFldName)] } {
+        return
+    }
+    foreach { vmin vmax } $_limits($_curFldName) break
+    set v [blt::vector create \#auto] 
+    $v seq $vmin $vmax [expr $_currentNumContours+2]
+    $v delete end 0 
+    set _contourList [$v range 0 end]
+    blt::vector destroy $v
+}
