pcolor and "interp" [changeset-2]

Ben Abbott bpabbott at mac.com
Tue Sep 30 14:45:30 CDT 2008


 On Tuesday, September 30, 2008, at 08:36AM, "Ben Abbott" <bpabbott at mac.com> wrote:
>On Monday, September 29, 2008, at 08:26PM, "John W. Eaton" <jwe at bevo.che.wisc.edu> wrote:
>>On 29-Sep-2008, Ben Abbott wrote:
>>
>>| 
>>| On Sep 29, 2008, at 6:48 PM, John W. Eaton wrote:
>>| 
>>| > On 29-Sep-2008, Ben Abbott wrote:
>>| >
>>| > | ok, then is there any objection to patching __gnuplot_version__ to
>>| > | include the patch level?
>>| >
>>| > OK, I checked in the following change.
>>| >
>>| > If we are going to make these changes, I'd prefer to at least have a
>>| > separate patch that removes the current have_newer_gnuplot variable.
>>| > I can easily make that change if you would like.
>>| >
>>| > jwe
>>| 
>>| ok, please do.
>>
>>I checked in the following change.
>>
>>jwe
>>
>
>Thanks. I've attached the changeset that enables interpolation of colors. As I'm presently working on a problem building current sources, I've not yet tried a "make check" with this change in place.
>
>Ben
>

ok, I ran "make check" with no problem. However, I did find a minor type regarding the gnuplot version (my 4.2.3 is patched to properlay interpolate colors). New changeset is attached.

The illusion used for gnuplot version < 4.2.4 when doing a pcolor is questionable to me. However, I included it. Please comment.

Ben
-------------- next part --------------
# HG changeset patch
# User Ben Abbott <bpabbott at mac.com>
# Date 1222803656 14400
# Node ID b05b3f9f70242bddd4578d31f9396f82673fe3a2
# Parent  75014ec4ac84d4d4637b5423fb6e661726553b33
__go_draw_axes__.m: Fix interpolation of facecolors.

diff -r 75014ec4ac84 -r b05b3f9f7024 scripts/ChangeLog
--- a/scripts/ChangeLog	Tue Sep 30 13:11:06 2008 -0400
+++ b/scripts/ChangeLog	Tue Sep 30 15:40:56 2008 -0400
@@ -1,3 +1,7 @@
+2008-09-30  Ben Abbott <bpabbott at mac.com>
+
+	* plot/__go_draw_axes__.m: Fix interpolation of facecolors..
+
 2008-09-29  John W. Eaton  <jwe at octave.org>
 
 	* plot/__go_draw_axes__.m: Eliminate have_newer_gnuplot variable.
diff -r 75014ec4ac84 -r b05b3f9f7024 scripts/plot/__go_draw_axes__.m
--- 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 15:40:56 2008 -0400
@@ -23,6 +23,11 @@
 function __go_draw_axes__ (h, plot_stream, enhanced, mono)
 
   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);
 
@@ -313,6 +318,26 @@
 
       if (strcmp (obj.visible, "off"))
 	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)
@@ -815,12 +840,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 +893,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 +1022,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;    
@@ -1990,3 +2037,22 @@
     typ = -1;
   endif
 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"')
+


More information about the Bug-octave mailing list