changeset 22162:e50536734855

Change default properties of isosurface (bug #48572). * isosurface.m: Change default properties of isosurface to match Matlab more closely. Adapt demo and docstring.
author Markus Mützel <markus.muetzel@gmx.de>
date Thu, 21 Jul 2016 14:43:30 +0200
parents 9babcd597676
children ae89334cb536
files scripts/plot/draw/isosurface.m
diffstat 1 files changed, 21 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/draw/isosurface.m	Wed Jul 20 20:44:21 2016 +0200
+++ b/scripts/plot/draw/isosurface.m	Thu Jul 21 14:43:30 2016 +0200
@@ -68,7 +68,8 @@
 ## instead of a single structure array.
 ##
 ## If called with no output argument, the isosurface geometry is directly
-## processed with the @command{patch} command.
+## processed with the @command{patch} command and a light object is added to
+## the axes if not yet present.
 ##
 ## For example,
 ##
@@ -164,7 +165,6 @@
     [fvc.faces, fvc.vertices, J] = __unite_shared_vertices__ (fvc.faces, fvc.vertices);
 
     if (calc_colors)
-      #fvc.facevertexcdata = fvc.facevertexcdata(vertices_idx);
       fvc.facevertexcdata(J) = []; # share very close vertices
     endif
   endif
@@ -173,15 +173,25 @@
     case 0
       ## plot the calculated surface
       if (calc_colors)
-        pa = patch ("Faces", fvc.faces, "Vertices", fvc.vertices,
-                    "FaceVertexCData", fvc.facevertexcdata,
-                    "FaceColor", "flat", "EdgeColor", "none");
+        fc = fvc.facevertexcdata;
       else
-        pa = patch ("Faces", fvc.faces, "Vertices", fvc.vertices,
-                    "FaceColor", "g", "EdgeColor", "k");
+        fc = iso;
       endif
+      ## FIXME: Matlab uses "EdgeColor", "none". But that would look odd
+      ##        with gnuplot.
+      pa = patch ("Faces", fvc.faces, "Vertices", fvc.vertices,
+                  "FaceVertexCData", fc,
+                  "FaceColor", "flat", "EdgeColor", "k",
+                  "FaceLighting", "gouraud");
+      hax = gca ();
       if (! ishold ())
-        set (gca (), "View", [-37.5, 30], "Box", "off");
+        set (hax, "View", [-37.5, 30], "Box", "off");
+      endif
+      isonormals (x, y, z, val, pa);
+      lights = findobj (hax, "Type", "light");
+      if (isempty (lights))
+        ## FIXME: Matlab seems to use camlight (patch #9014) here
+        light ();
       endif
     case 1
       varargout = {fvc};
@@ -334,9 +344,10 @@
 %! clf;
 %! [x,y,z] = meshgrid (-2:0.5:2, -2:0.5:2, -2:0.5:2);
 %! val = x.^2 + y.^2 + z.^2;
-%! isosurface (x, y, z, val, 1);
+%! isosurface (x, y, z, val, 3);
+%! isosurface (x, y, z, val, 5);
 %! axis equal;
-%! title ('isosurface of a sphere');
+%! title ('isosurfaces of two nested spheres');
 
 %!demo
 %! x = 0:2;