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: John W. Eaton
Subject: Patch for __uio_draw_axes__ for multiple images
Date: Thu, 22 Feb 2007 02:07:07 -0500

On 21-Feb-2007, Daniel J Sebald wrote:

| 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.]

I applied your patch, plus the following changes so that image viewing
will still work if gnuplot is not displaying them.

Thanks,

jwe

scripts/ChangeLog:

2007-02-22  John W. Eaton  <address@hidden>

        * plot/__uiobject_draw_axes__.m: If not using gnuplot for images,
        cache data and display after xlim and ylim have been determined.


Index: scripts/plot/__uiobject_draw_axes__.m
===================================================================
RCS file: /cvs/octave/scripts/plot/__uiobject_draw_axes__.m,v
retrieving revision 1.15
diff -u -u -r1.15 __uiobject_draw_axes__.m
--- scripts/plot/__uiobject_draw_axes__.m       22 Feb 2007 07:03:51 -0000      
1.15
+++ scripts/plot/__uiobject_draw_axes__.m       22 Feb 2007 07:06:12 -0000
@@ -229,18 +229,26 @@
 
     palette_set = 0;
 
+    [view_cmd, view_fcn, view_zoom] = image_viewer ();
+    use_gnuplot_for_images = (ischar (view_fcn)
+                             && strcmp (view_fcn, "gnuplot_internal"));
+
+    ximg_data = {};
+    ximg_data_idx = 0;
+
     for i = 1:length (kids)
 
       obj = get (kids(i));
 
       switch (obj.type)
        case "image"
-         % 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.
+         ## 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
+         endif
          data_idx++;
 
          img_data = obj.cdata;
@@ -248,8 +256,7 @@
          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"))
+         if (use_gnuplot_for_images)
 
            [y_dim, x_dim] = size (img_data(:,:,1));
            if (x_dim > 1)
@@ -276,7 +283,8 @@
              fwrite (fid, img_data(:), "float");
              format = "1";
              imagetype = "image";
-             % Only need to set pallete once because it doesn't change on a 
figure.
+             ## 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);
@@ -289,10 +297,11 @@
                  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
+                 endfor
                  fprintf (plot_stream, "e;\n");
                else
-                 # Let the file be deleted when Octave exits or 
`purge_tmp_files' is called.
+                 ## 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);
@@ -310,10 +319,12 @@
                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.
+           ## Data in file, set to zero for data available test to pass
+           ## below.
+           data{data_idx} = 0; 
 
          else
-           view_fcn (xlim, ylim, img_data, view_zoom, view_cmd);
+           ximg_data{++ximg_data_idx} = img_data;
          endif
 
        case "line"
@@ -616,6 +627,12 @@
     fputs (plot_stream, "set style data lines;\n");
     fflush (plot_stream);
 
+    if (! use_gnuplot_for_images)
+      for i = 1:ximg_data_idx
+       view_fcn (xlim, ylim, ximg_data{i}, view_zoom, view_cmd);
+      endfor
+    endif
+
     if (have_data)
 
       if (nd == 2)

reply via email to

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