Mercurial > hg > octave-terminal
changeset 6337:24e127df8e17
[project @ 2007-02-22 07:03:51 by jwe]
author | jwe |
---|---|
date | Thu, 22 Feb 2007 07:03:51 +0000 |
parents | 44a14099a7a8 |
children | ec88b4ab6d10 |
files | scripts/ChangeLog scripts/plot/__uiobject_draw_axes__.m |
diffstat | 2 files changed, 111 insertions(+), 107 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2007-02-22 Daniel J Sebald <daniel.sebald@ieee.org> + + * plot/__uiobject_draw_axes__.m: + Allow multiple images to be displayed with gnuplot. + 2007-02-20 Rafael Laboissiere <rafael@debian.org> * optimization/glpk.m: Document the fact that extra.mem does not work
--- a/scripts/plot/__uiobject_draw_axes__.m +++ b/scripts/plot/__uiobject_draw_axes__.m @@ -223,29 +223,102 @@ data_idx = 0; data = cell (); - have_img_data = false; - xminp = yminp = zminp = Inf; xmax = ymax = zmax = -Inf; xmin = ymin = zmin = Inf; + palette_set = 0; + for i = 1:length (kids) obj = get (kids(i)); switch (obj.type) case "image" - if (have_img_data) - warning ("an axis can only display one image"); - endif - have_img_data = true; + % FIXME - Is there a better way to determine if the plot command should + % be "plot" or "splot"????? Could have images projected into 3D so there + % is really no reason to limit this. + if (nd == 0) + nd = 2; + end + data_idx++; + img_data = obj.cdata; img_colormap = parent_figure_obj.colormap; img_xdata = obj.xdata; img_ydata = obj.ydata; + [view_cmd, view_fcn, view_zoom] = image_viewer (); + if (ischar (view_fcn) && strcmp (view_fcn, "gnuplot_internal")) + + [y_dim, x_dim] = size (img_data(:,:,1)); + if (x_dim > 1) + dx = abs (img_xdata(2)-img_xdata(1))/(x_dim-1); + else + dx = 1; + endif + if (y_dim > 1) + dy = abs (img_ydata(2)-img_ydata(1))/(y_dim-1); + else + dy = 1; + endif + x_origin = min (img_xdata); + y_origin = min (img_ydata); + + ## Let the file be deleted when Octave exits or `purge_tmp_files' + ## is called. + [fid, fname] = mkstemp (strcat (P_tmpdir, "/gpimageXXXXXX"), 1); + if (ndims (img_data) == 3) + fwrite (fid, permute (img_data, [3, 1, 2])(:), "float"); + format = "1:2:3"; + imagetype = "rgbimage"; + else + fwrite (fid, img_data(:), "float"); + format = "1"; + imagetype = "image"; + % Only need to set pallete once because it doesn't change on a figure. + if (! palette_set) + palette_set = 1; + palette_size = rows (img_colormap); + fprintf (plot_stream, + "set palette positive color model RGB maxcolors %i;\n", + palette_size); + if (palette_size <= 128) + ## Break up command to avoid buffer overflow. + fprintf (plot_stream, "set palette file \"-\" using 1:2:3:4;\n"); + for i = 1:palette_size + fprintf (plot_stream, "%g %g %g %g;\n", + 1e-3*round (1e3*[(i-1)/(palette_size-1), img_colormap(i,:)])); + end + fprintf (plot_stream, "e;\n"); + else + # Let the file be deleted when Octave exits or `purge_tmp_files' is called. + [fid, binary_fname, msg] = mkstemp (strcat (P_tmpdir, "/gpimageXXXXXX"), 1); + fwrite (fid, img_colormap', "float32", 0, "ieee-le"); + fclose (fid); + fprintf (plot_stream, + "set palette file \"%s\" binary record=%d using 1:2:3;\n", + binary_fname, palette_size); + endif + endif + endif + fclose (fid); + + filespec{data_idx} = fname; + titlespec{data_idx} = ""; + usingclause{data_idx} = sprintf ("binary array=%dx%d scan=yx flipy origin=(%g,%g) dx=%g dy=%g using %s", + x_dim, y_dim, x_origin, y_origin, dx, dy, format); + withclause{data_idx} = sprintf ("with %s", imagetype); + + data{data_idx} = 0; % Data in file, set to zero for data available test to pass below. + + else + view_fcn (xlim, ylim, img_data, view_zoom, view_cmd); + endif + case "line" data_idx++; + filespec{data_idx} = '-'; if (isempty (obj.keylabel)) titlespec{data_idx} = "title \"\""; else @@ -376,6 +449,7 @@ case "surface" data_idx++; style = do_linestyle_command (obj, data_idx, plot_stream); + filespec{data_idx} = '-'; if (isempty (obj.keylabel)) titlespec{data_idx} = "title \"\""; else @@ -542,126 +616,51 @@ fputs (plot_stream, "set style data lines;\n"); fflush (plot_stream); - if (nd == 2) - plot_cmd = "plot"; - else - plot_cmd = "splot"; - endif - - have_data = false; - - if (have_img_data) - [view_cmd, view_fcn, view_zoom] = image_viewer (); - if (ischar (view_fcn) && strcmp (view_fcn, "gnuplot_internal")) - have_data = true; - - [y_dim, x_dim] = size (img_data(:,:,1)); - if (x_dim > 1) - dx = abs (img_xdata(2)-img_xdata(1))/(x_dim-1); - else - dx = 1; - endif - if (y_dim > 1) - dy = abs (img_ydata(2)-img_ydata(1))/(y_dim-1); - else - dy = 1; - endif - x_origin = min (img_xdata); - y_origin = min (img_ydata); - - ## Let the file be deleted when Octave exits or `purge_tmp_files' - ## is called. - [fid, fname] = mkstemp (strcat (P_tmpdir, "/gpimageXXXXXX"), 1); - if (ndims (img_data) == 3) - fwrite (fid, permute (img_data, [3, 1, 2])(:), "float"); - format = "1:2:3"; - imagetype = "rgbimage"; - else - fwrite (fid, img_data(:), "float"); - format = "1"; - imagetype = "image"; - palette_size = rows (img_colormap); - fprintf (plot_stream, - "set palette positive color model RGB maxcolors %i;\n", - palette_size); - if (palette_size <= 128) - ## Break up command to avoid buffer overflow. - fprintf (plot_stream, "set palette file \"-\" using 1:2:3:4;\n"); - for i = 1:palette_size - fprintf (plot_stream, "%g %g %g %g;\n", - 1e-3*round (1e3*[(i-1)/(palette_size-1), img_colormap(i,:)])); - end - fprintf (plot_stream, "e;\n"); - else - # Let the file be deleted when Octave exits or `purge_tmp_files' is called. - [fid, binary_fname, msg] = mkstemp (strcat (P_tmpdir, "/gpimageXXXXXX"), 1); - fwrite (fid, img_colormap', "float32", 0, "ieee-le"); - fclose (fid); - fprintf (plot_stream, - "set palette file \"%s\" binary record=%d using 1:2:3;\n", - binary_fname, palette_size); - endif - endif - fclose (fid); - - fprintf (plot_stream, - "plot \"%s\" binary array=%dx%d scan=yx flipy origin=(%g,%g) dx=%g dy=%g using %s with %s", - fname, x_dim, y_dim, x_origin, y_origin, dx, dy, format, imagetype); - - plot_cmd = ","; - else - view_fcn (xlim, ylim, img_data, view_zoom, view_cmd); - endif - endif - - if (! isempty (data)) - have_data = true; + if (have_data) if (nd == 2) - fprintf (plot_stream, "%s '-' %s %s %s", plot_cmd, - usingclause{1}, titlespec{1}, withclause{1}); + plot_cmd = "plot"; else + plot_cmd = "splot"; rot_x = 90 - axis_obj.view(2); rot_z = axis_obj.view(1); while (rot_z < 0) rot_z += 360; endwhile fprintf (plot_stream, "set view %g, %g;\n", rot_x, rot_z); - - fprintf (plot_stream, "%s '-' %s %s %s", plot_cmd, - usingclause{1}, titlespec{1}, withclause{1}); endif + fprintf (plot_stream, "%s \"%s\" %s %s %s", plot_cmd, + filespec{1}, usingclause{1}, titlespec{1}, withclause{1}); for i = 2:data_idx - fprintf (plot_stream, ", '-' %s %s %s", usingclause{i}, - titlespec{i}, withclause{i}); + fprintf (plot_stream, ", \"%s\" %s %s %s", + filespec{i}, usingclause{i}, titlespec{i}, withclause{i}); endfor for i = 1:data_idx - fputs (plot_stream, "\n"); - if (nd == 2) - fprintf (plot_stream, - strcat (repmat ("%g ", 1, rows (data{i})), "\n"), - data{i}); - else - if (parametric(i)) - fprintf (plot_stream, "%g %g %g\n", data{i}); + if (strcmp (filespec{i}, "-")) + if (nd == 2) + fprintf (plot_stream, + strcat (repmat ("%g ", 1, rows (data{i})), "\n"), + data{i}); else - tmp = data{i}; - nc = columns (tmp); - for j = 1:3:nc - fprintf (plot_stream, "%g %g %g\n", tmp(:,j:j+2)'); - fputs (plot_stream, "\n"); - endfor + if (parametric(i)) + fprintf (plot_stream, "%g %g %g\n", data{i}); + else + tmp = data{i}; + nc = columns (tmp); + for j = 1:3:nc + fprintf (plot_stream, "%g %g %g\n", tmp(:,j:j+2)'); + fputs (plot_stream, "\n"); + endfor + endif endif + fputs (plot_stream, "e"); + fflush (plot_stream); endif - fputs (plot_stream, "e"); - fflush (plot_stream); endfor endif - if (have_data) - fputs (plot_stream, "\n"); - fflush (plot_stream); - endif + fputs (plot_stream, "\n"); + fflush (plot_stream); else print_usage ();