changeset 8166:4024fc815f8d

__go_draw_axes__.m: Fix interpolation of facecolors.
author Ben Abbott <bpabbott@mac.com>
date Tue, 30 Sep 2008 16:09:09 -0400
parents 75014ec4ac84
children 17352ccd860e
files scripts/ChangeLog scripts/plot/__go_draw_axes__.m scripts/plot/shading.m
diffstat 3 files changed, 83 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Tue Sep 30 13:11:06 2008 -0400
+++ b/scripts/ChangeLog	Tue Sep 30 16:09:09 2008 -0400
@@ -1,3 +1,9 @@
+2008-09-30  Ben Abbott <bpabbott@mac.com>
+
+	* plot/__go_draw_axes__.m: Fix interpolation of facecolors.
+
+	* plot/shading.m: New demo.
+
 2008-09-29  John W. Eaton  <jwe@octave.org>
 
 	* plot/__go_draw_axes__.m: Eliminate have_newer_gnuplot variable.
--- a/scripts/plot/__go_draw_axes__.m	Tue Sep 30 13:11:06 2008 -0400
+++ b/scripts/plot/__go_draw_axes__.m	Tue Sep 30 16:09:09 2008 -0400
@@ -24,6 +24,16 @@
 
   if (nargin == 4)
 
+    ## Gnupot versions > 4.2.4 include a patch to properly interpolate
+    ## colors.  Prior to that version the interpolation of colors used
+    ## the zdata rather than the cdata.
+    ##
+    ## FIXME: when gnuplot 4.3 is released the special treatment might
+    ## be removed.
+
+    persistent gp_version_gt_4p2p4 = ...
+	compare_versions (__gnuplot_version__ (), "4.2.4", ">");
+
     axis_obj = __get__ (h);
 
     parent_figure_obj = get (axis_obj.parent);
@@ -315,6 +325,26 @@
 	continue;
       endif
 
+      ## Check for color interpolation for surfaces.
+      doing_interp_color = strncmp (obj.facecolor, "interp", 6);
+      if (doing_interp_color)
+	## Check to see if gnuplot is fully functional in this regard.
+	if (gp_version_gt_4p2p4)
+	  ## Color interpolation works correctly in gnuplot >4.2.4.
+	  fake_color_interp = false;
+	else
+	  ## The patches may be applied to >4.2.2, but don't count on it.
+	  ## For versions >4.1 & <4.2.5 the interpolation uses the zdata
+	  ## rather than the cdata. As a result surfc() will work because
+	  ## all(zdata(:)==cdata(:)). pcolor() may be given the illusion
+	  ## of working when the veiw is directly from above.
+	  fake_color_interp = (all (axis_obj.view == [0, 90])
+			       || all (obj.zdata(:) == obj.cdata(:)));
+	endif
+      else
+        fake_color_interp = false;
+      endif
+
       switch (obj.type)
 	case "image"
 	  img_data = obj.cdata;
@@ -815,12 +845,23 @@
 	      endfor
 	      data{data_idx} = zz.';
 	    endif
-	    usingclause{data_idx} = "using ($1):($2):($3):($4)";
-            ## fputs (plot_stream, "unset parametric;\n");
 
-	    ## Interpolation does not work for flat surfaces (e.g. pcolor)
-            ## and color mapping --> currently set empty.
-            interp_str = "";
+	    if (doing_interp_color)
+	      interp_str = "interpolate 4, 4";
+	      if (fake_color_interp)
+		## In this instance the interpolation of color respects zdata
+		## rather than cdata.
+		usingclause{data_idx} = "using ($1):($2):($4)";
+	      else
+	        ## The proper gnuplot inputs include xdata, ydata, zdata, & cdata.
+		usingclause{data_idx} = "using ($1):($2):($3):($4)";
+	      endif
+	    else
+	      ## No interpolation of colors.
+	      interp_str = "";
+	      usingclause{data_idx} = "using ($1):($2):($3):($4)";
+	    endif
+
             flat_interp_face = (strncmp (obj.facecolor, "flat", 4)
 				|| strncmp (obj.facecolor, "interp", 6));
             flat_interp_edge = (strncmp (obj.edgecolor, "flat", 4)
@@ -857,7 +898,12 @@
 	      fputs (plot_stream, "unset pm3d\n");
             endif
 
-	    dord = "depthorder";
+	    if (doing_interp_color)
+	      ## "depthorder" interferes with interpolation of colors.
+	      dord = "scansautomatic";
+	    else
+	      dord = "depthorder";
+	    endif
 
 	    if (flat_interp_face && strncmp (obj.edgecolor, "flat", 4))
               fprintf (plot_stream, "set pm3d explicit at s %s %s corners2color c3;\n", 
@@ -981,7 +1027,13 @@
       else
 	zdir = "noreverse";
       endif
-      fprintf (plot_stream, "set zrange [%.15e:%.15e] %s;\n", zlim, zdir);
+      if (doing_interp_color)
+	if (! fake_color_interp || any (obj.zdata(:) ~= 0))
+	  fprintf (plot_stream, "set zrange [%.15e:%.15e] %s;\n", zlim, zdir);
+	end
+      else
+	fprintf (plot_stream, "set zrange [%.15e:%.15e] %s;\n", zlim, zdir);
+      endif
     endif
 
     cmap = parent_figure_obj.colormap;    
--- a/scripts/plot/shading.m	Tue Sep 30 13:11:06 2008 -0400
+++ b/scripts/plot/shading.m	Tue Sep 30 16:09:09 2008 -0400
@@ -74,3 +74,21 @@
   endfor
 
 endfunction
+
+%!demo
+%! figure(1); clf
+%! sombrero
+%! shading faceted
+%! title('shading "faceted"')
+%! figure(2); clf
+%! sombrero
+%! shading interp
+%! title('shading "interp"')
+%! figure (3); clf
+%! pcolor (peaks ())
+%! shading faceted
+%! title('shading "faceted"')
+%! figure (4); clf
+%! pcolor (peaks ())
+%! shading interp
+%! title('shading "interp"')