octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Patch for __uio_draw_axes__ for multiple images


From: Daniel J Sebald
Subject: Patch for __uio_draw_axes__ for multiple images
Date: Wed, 21 Feb 2007 20:54:05 -0600
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041020

Here's another patch that makes the image gnuplot commands more along the format of the 
other types of plotting items.  By adding a "filespec{}" variable the last loop 
in the routine becomes more generic.  Also, this allows multiple images on a plot.  E.g.,

A = loadimage("default.img");
[size_x, size_y] = size(A);
X = ones(1,size_y)'*[1:size_x];
Y = [1:size_y]'*ones(1,size_x);
fig1 = figure();
set(fig1,"visible","off")
image(X, Y, A);
hold on;
image(X+size_x, Y, fliplr(A));
image(X, Y+size_y, flipud(A));
image(X+size_x, Y+size_y, flipud(fliplr(A)));
axis([0 2*size_x+1 0 2*size_y+1]);
ocean(64);
set(fig1,"visible","on");

[Note the above script may be revealing a bug not directly associated with the 
patch.  I'll get that in a new patch.]

Dan
--- /usr/local/src/octave-cvs/octave/scripts/plot/__uiobject_draw_axes__.m      
2007-02-21 12:31:32.000000000 -0600
+++ __uiobject_draw_axes__.m    2007-02-21 20:44:02.808038000 -0600
@@ -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 ();

reply via email to

[Prev in Thread] Current Thread [Next in Thread]