# HG changeset patch
# User Daniel J Sebald <daniel.sebald@ieee.org>
# Date 1429690446 18000
# Node ID 1d5c058044dde2822202f426c0f849da4571ece7
# Parent  ddc5c766332956347948b5efc8f983ec795b6d24
Display image in 3D view with gnuplot graphics toolkit (bug #44861)

* graphics.cc (calc_dimensions): Add image to the list of 1D or 2D graphics
objects that can be projected into 3D.

* graphics.in.h
(image : public base_graphics_objec): Add zdata, zlim, zliminclude and
zdatamode to image property list similar to x and y dimension properties.
(image::update_cdata): Update the zdata if zdatamode is auto.
(image::update_zdata): Added.  If zdatamode is auto, get the automatic data and
set zlim to the limits of that data.
(image::get_auto_zdata): Added.  If the image cdata has valid dimensions, then
set zdata to [0], otherwise it is an empty matrix.

* __go_draw_axes__.m (__go_draw_axes__): Get a copy of the zdata.  If the zdata
is empty then set z_origin to 0, otherwise z_origin is the first data value of
zdata.  For object type "image", if 'plot' will be used set z_origin_str to ""
and hidden line removal false.  If 'splot' will be used set z_origin_str to the
z_origin preceded by a comma.  Print the z_origin_str into the usingclause.
Add the case of orthographic projection to that in which 'plot' is used.

diff --git a/libinterp/corefcn/graphics.cc b/libinterp/corefcn/graphics.cc
--- a/libinterp/corefcn/graphics.cc
+++ b/libinterp/corefcn/graphics.cc
@@ -10619,7 +10619,7 @@ calc_dimensions (const graphics_object& 
 
   if (go.isa ("surface"))
     nd = 3;
-  else if ((go.isa ("line") || go.isa ("patch"))
+  else if ((go.isa ("line") || go.isa ("patch") || go.isa ("image"))
            && ! go.get ("zdata").is_empty ())
     nd = 3;
   else
diff --git a/libinterp/corefcn/graphics.in.h b/libinterp/corefcn/graphics.in.h
--- a/libinterp/corefcn/graphics.in.h
+++ b/libinterp/corefcn/graphics.in.h
@@ -4675,17 +4675,21 @@ public:
       radio_property erasemode , "{normal}|none|xor|background"
       row_vector_property xdata mu , Matrix ()
       row_vector_property ydata mu , Matrix ()
+      row_vector_property zdata mu , Matrix ()
       // hidden properties for limit computation
       row_vector_property alim hlr , Matrix ()
       row_vector_property clim hlr , Matrix ()
       row_vector_property xlim hlr , Matrix ()
       row_vector_property ylim hlr , Matrix ()
+      row_vector_property zlim hlr , Matrix ()
       bool_property aliminclude hlg , "on"
       bool_property climinclude hlg , "on"
       bool_property xliminclude hl , "on"
       bool_property yliminclude hl , "on"
+      bool_property zliminclude hl , "on"
       radio_property xdatamode ha , "{auto}|manual"
       radio_property ydatamode ha , "{auto}|manual"
+      radio_property zdatamode ha , "{auto}|manual"
     END_PROPERTIES
 
   protected:
@@ -4728,6 +4732,9 @@ public:
 
       if (ydatamode.is ("auto"))
         update_ydata ();
+
+      if (zdatamode.is ("auto"))
+        update_zdata ();
     }
 
     void update_xdata (void)
@@ -4768,6 +4775,18 @@ public:
       set_ylim (limits);
     }
 
+    void update_zdata (void)
+    {
+      if (zdatamode.is ("auto"))
+        {
+          set_zdata (get_auto_zdata ());
+          set_zdatamode ("auto");
+        }
+
+      Matrix limits = zdata.get_limits ();
+      set_zlim (limits);
+    }
+
     Matrix get_auto_xdata (void)
     {
       dim_vector dv = get_cdata ().dims ();
@@ -4792,6 +4811,18 @@ public:
       return data;
     }
 
+    Matrix get_auto_zdata (void)
+    {
+      dim_vector dv = get_cdata ().dims ();
+      Matrix data;
+      if (dv(0) > 0. && dv(1) > 0.)
+        {
+          data = Matrix (1, 1, 1);
+          data(0) = 0;
+        }
+      return data;
+    }
+
     float pixel_size (octave_idx_type dim, const Matrix limits)
     {
       octave_idx_type l = dim - 1;
diff --git a/scripts/plot/util/private/__go_draw_axes__.m b/scripts/plot/util/private/__go_draw_axes__.m
--- a/scripts/plot/util/private/__go_draw_axes__.m
+++ b/scripts/plot/util/private/__go_draw_axes__.m
@@ -488,6 +488,7 @@ function __go_draw_axes__ (h, plot_strea
         img_data = obj.cdata;
         img_xdata = obj.xdata;
         img_ydata = obj.ydata;
+        img_zdata = obj.zdata;
 
         if (ndims (img_data) == 3)
           truecolor = true;
@@ -515,6 +516,11 @@ function __go_draw_axes__ (h, plot_strea
 
         x_origin = min (img_xdata);
         y_origin = min (img_ydata);
+        if (isempty (img_zdata))
+          z_origin = 0;
+        else
+          z_origin = img_zdata(1);
+        endif
 
         [y_dim, x_dim] = size (img_data(:,:,1));
         if (x_dim > 1)
@@ -553,8 +559,15 @@ function __go_draw_axes__ (h, plot_strea
         endif
 
         titlespec{data_idx} = "title \"\"";
-        usingclause{data_idx} = sprintf ("binary array=%dx%d scan=yx origin=(%.15g,%.15g) dx=%.15g dy=%.15g using %s",
-            x_dim, y_dim, x_origin, y_origin, dx, dy, format);
+        if (nd == 2 || all (mod (axis_obj.view, 90) == 0))
+          z_origin_str = "";
+          hidden_removal = false;
+        else
+          z_origin_str = sprintf (",%.15g", z_origin);
+          hidden_removal = true;
+        endif
+        usingclause{data_idx} = sprintf ("binary array=%dx%d scan=yx origin=(%.15g,%.15g%s) dx=%.15g dy=%.15g using %s",
+            x_dim, y_dim, x_origin, y_origin, z_origin_str, dx, dy, format);
         withclause{data_idx} = sprintf ("with %s;", imagetype);
 
       case "line"
@@ -1646,7 +1659,7 @@ function __go_draw_axes__ (h, plot_strea
   fputs (plot_stream, "unset colorbox;\n");
 
   if (have_data)
-    if (nd == 2)
+    if (nd == 2 || all (mod (axis_obj.view, 90) == 0))
       plot_cmd = "plot";
     else
       plot_cmd = "splot";
exporting patch:
<fdopen>
