Mercurial > hg > octave-nkf
changeset 17052:1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
* scripts/plot/surf.m, scripts/plot/surfl.m, scripts/plot/surfnorm.m:
Update to use new __plt_get_axis_arg__. Rename h to hax. Rename tmp to htmp.
* scripts/plot/surfc.m: Check __plt_get_axis_arg__ before calling newplot.
Remove obsolete code checking for input axis handle. Use cellfun to eliminate
for loop.
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Tue, 23 Jul 2013 16:26:43 +0200 |
parents | 3e1b24a2454a |
children | 27062be131d6 |
files | scripts/plot/surf.m scripts/plot/surfc.m scripts/plot/surfl.m scripts/plot/surfnorm.m |
diffstat | 4 files changed, 80 insertions(+), 69 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/surf.m +++ b/scripts/plot/surf.m @@ -42,24 +42,26 @@ function retval = surf (varargin) - [h, varargin] = __plt_get_axis_arg__ ("surf", varargin{:}); + [hax, varargin] = __plt_get_axis_arg__ ("surf", varargin{:}); - oldh = gca (); + oldfig = ifelse (isempty (hax), [], get (0, "currentfigure")); unwind_protect - axes (h); - newplot (); - tmp = surface (varargin{:}); + hax = newplot (hax); + + htmp = surface (varargin{:}); - if (! ishold ()) - set (h, "view", [-37.5, 30], + if (! ishold (hax)) + set (hax, "view", [-37.5, 30], "xgrid", "on", "ygrid", "on", "zgrid", "on"); endif unwind_protect_cleanup - axes (oldh); + if (! isempty (oldfig)) + set (0, "currentfigure", oldfig); + endif end_unwind_protect if (nargout > 0) - retval = tmp; + retval = htmp; endif endfunction
--- a/scripts/plot/surfc.m +++ b/scripts/plot/surfc.m @@ -24,52 +24,58 @@ ## then a typical vertex is (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus, ## columns of @var{z} correspond to different @var{x} values and rows of ## @var{z} correspond to different @var{y} values. -## @seealso{meshgrid, surf, contour} +## @seealso{ezsurfc, meshgrid, surf, contour} ## @end deftypefn function h = surfc (varargin) - newplot (); - - tmp = surface (varargin{:}); - - ax = get (tmp, "parent"); + [hax, varargin, nargin] = __plt_get_axis_arg__ ("surfc", varargin{:}); - set (tmp, "facecolor", "flat"); - - if (! ishold ()) - set (ax, "view", [-37.5, 30], - "xgrid", "on", "ygrid", "on", "zgrid", "on"); + if (nargin < 1) + print_usage (); endif - drawnow (); - zmin = get (ax, "zlim")(1); + oldfig = ifelse (isempty (hax), [], get (0, "currentfigure")); + unwind_protect + hax = newplot (hax); + + htmp = surface (hax, varargin{:}); - # don't pass axis handle and/or string arguments to __contour__() - stop_idx = nargin; - for i = 2 : nargin - if (ischar (varargin{i})) - stop_idx = i - 1; - break; + set (htmp, "facecolor", "flat"); + + if (! ishold ()) + set (hax, "view", [-37.5, 30], + "xgrid", "on", "ygrid", "on", "zgrid", "on"); endif - endfor + + drawnow (); - start_idx = 1; - if (ishandle (varargin{1})) - start_idx = 2; - endif + # don't pass string arguments to __contour__() + stop_idx = find (cellfun ("isclass", varargin, "char"), 1); + if (isempty (stop_idx)) + stop_idx = nargin; + else + stop_idx--; + endif - if (stop_idx - start_idx == 1 || stop_idx - start_idx == 3) - #don't pass a color matrix c to __contour__ - stop_idx -= 1; - endif + if (stop_idx - 1 == 1 || stop_idx - 1 == 3) + ## Don't pass a color matrix c to __contour__ + stop_idx -= 1; + endif + + zmin = get (hax, "zlim")(1); + [~, htmp2] = __contour__ (hax, zmin, varargin{1:stop_idx}); - [c, tmp2] = __contour__ (ax, zmin, varargin{start_idx:stop_idx}); + htmp = [htmp; htmp2]; - tmp = [tmp; tmp2]; + unwind_protect_cleanup + if (! isempty (oldfig)) + set (0, "currentfigure", oldfig); + endif + end_unwind_protect if (nargout > 0) - h = tmp; + h = htmp; endif endfunction
--- a/scripts/plot/surfl.m +++ b/scripts/plot/surfl.m @@ -69,12 +69,11 @@ function retval = surfl (varargin) - [h, varargin] = __plt_get_axis_arg__ ("surfl", varargin{:}); + [hax, varargin] = __plt_get_axis_arg__ ("surfl", varargin{:}); - oldh = gca (); + oldfig = ifelse (isempty (hax), [], get (0, "currentfigure")); unwind_protect - axes (h); - newplot (); + hax = newplot (hax); ## Check for lighting type. use_cdata = true; @@ -122,9 +121,9 @@ endif endif - htmp = surface (varargin{:}); - if (! ishold ()) - set (h, "view", [-37.5, 30], + htmp = surface ([varargin, "parent", hax]{:}); + if (! ishold (hax)) + set (hax, "view", [-37.5, 30], "xgrid", "on", "ygrid", "on", "zgrid", "on", "clim", [0 1]); endif @@ -143,7 +142,7 @@ endif vn = get (htmp, "vertexnormals"); - dar = get (h, "plotboxaspectratio"); + dar = get (hax, "plotboxaspectratio"); vn(:,:,1) *= dar(1); vn(:,:,2) *= dar(2); vn(:,:,3) *= dar(3); @@ -160,7 +159,9 @@ set (htmp, "cdata", cdata ./ sum (r(1:3))); unwind_protect_cleanup - axes (oldh); + if (! isempty (oldfig)) + set (0, "currentfigure", oldfig); + endif end_unwind_protect if (nargout > 0)
--- a/scripts/plot/surfnorm.m +++ b/scripts/plot/surfnorm.m @@ -53,8 +53,7 @@ function [Nx, Ny, Nz] = surfnorm (varargin) - [h, varargin, nargin] = __plt_get_axis_arg__ ((nargout != 0), "surfnorm", - varargin{:}); + [hax, varargin, nargin] = __plt_get_axis_arg__ ("surfnorm", varargin{:}); if (nargin != 1 && nargin != 3) print_usage (); @@ -115,24 +114,27 @@ nz = nz ./ len; if (nargout == 0) - oldh = gca (); - unwind_protect - axes (h); - newplot (); - surf (x, y, z, varargin{ioff:end}); - old_hold_state = get (h, "nextplot"); - unwind_protect - set (h, "nextplot", "add"); - plot3 ([x(:)'; x(:).' + nx(:).' ; NaN(size(x(:).'))](:), - [y(:)'; y(:).' + ny(:).' ; NaN(size(y(:).'))](:), - [z(:)'; z(:).' + nz(:).' ; NaN(size(z(:).'))](:), - varargin{ioff:end}); - unwind_protect_cleanup - set (h, "nextplot", old_hold_state); - end_unwind_protect - unwind_protect_cleanup - axes (oldh); - end_unwind_protect + oldfig = ifelse (isempty (hax), [], get (0, "currentfigure")); + unwind_protect + hax = newplot (hax); + + surf (hax, x, y, z, varargin{ioff:end}); + old_hold_state = get (hax, "nextplot"); + unwind_protect + set (hax, "nextplot", "add"); + plot3 ([x(:)'; x(:).' + nx(:).' ; NaN(size(x(:).'))](:), + [y(:)'; y(:).' + ny(:).' ; NaN(size(y(:).'))](:), + [z(:)'; z(:).' + nz(:).' ; NaN(size(z(:).'))](:), + varargin{ioff:end}); + unwind_protect_cleanup + set (hax, "nextplot", old_hold_state); + end_unwind_protect + + unwind_protect_cleanup + if (! isempty (oldfig)) + set (0, "currentfigure", oldfig); + endif + end_unwind_protect else Nx = nx; Ny = ny;