Mercurial > octave-nkf
changeset 18933:3d9e503aea2c
Update image "x/ydata" when "cdata" is changed (bug #42121)
* graphics.in.h (image::properties): add two hidden properties "xdatamode" and "ydatamode"
* graphics.in.h (image::properties): modify properties "xdata" and "ydata" so that their respective *mode is updated
* graphics.in.h (image::properties::update_cdata): setting "cdata" updates "x/ydata" when "x/ydatamode" is "auto"
* graphics.in.h (image::properties::update_x/ydata): setting "x/ydata" to empty matrix updates "x/ydata" to [1 npix] and changes "x/ydatamode" to "auto"
* graphics.in.h (image::properties::auto_xdata (void), image::properties::auto_ydata (void)): new functions to compute auto x/ydata
* image.m (__img__): don't replace empty "x/ydata" in order to use new behavior
* image.m: add test for bug #42121
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Mon, 14 Apr 2014 22:53:44 +0200 |
parents | f9cf5ae6b8a2 |
children | 49961d67e4b9 |
files | libinterp/corefcn/graphics.in.h scripts/image/image.m |
diffstat | 2 files changed, 85 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/graphics.in.h Fri Jul 04 21:40:50 2014 -0700 +++ b/libinterp/corefcn/graphics.in.h Mon Apr 14 22:53:44 2014 +0200 @@ -4504,8 +4504,8 @@ radio_property cdatamapping al , "scaled|{direct}" string_property displayname , "" radio_property erasemode , "{normal}|none|xor|background" - row_vector_property xdata u , Matrix () - row_vector_property ydata u , Matrix () + row_vector_property xdata mu , Matrix () + row_vector_property ydata mu , Matrix () // hidden properties for limit computation row_vector_property alim hlr , Matrix () row_vector_property clim hlr , Matrix () @@ -4515,6 +4515,8 @@ bool_property climinclude hlg , "on" bool_property xliminclude hl , "on" bool_property yliminclude hl , "on" + radio_property xdatamode ha , "{auto}|manual" + radio_property ydatamode ha , "{auto}|manual" END_PROPERTIES protected: @@ -4551,10 +4553,25 @@ set_clim (cdata.get_limits ()); else clim = cdata.get_limits (); + + if (xdatamode.is ("auto")) + update_xdata (); + + if (ydatamode.is ("auto")) + update_ydata (); } void update_xdata (void) { + if (xdata.get ().is_empty ()) + set_xdatamode ("auto"); + + if (xdatamode.is ("auto")) + { + set_xdata (get_auto_xdata ()); + set_xdatamode ("auto"); + } + Matrix limits = xdata.get_limits (); float dp = pixel_xsize (); @@ -4565,6 +4582,15 @@ void update_ydata (void) { + if (ydata.get ().is_empty ()) + set_ydatamode ("auto"); + + if (ydatamode.is ("auto")) + { + set_ydata (get_auto_ydata ()); + set_ydatamode ("auto"); + } + Matrix limits = ydata.get_limits (); float dp = pixel_ysize (); @@ -4573,6 +4599,30 @@ set_ylim (limits); } + Matrix get_auto_xdata (void) + { + dim_vector dv = get_cdata ().dims (); + Matrix data; + if (dv(1) > 0.) + { + data = Matrix (1, 2, 1); + data(1) = dv(1); + } + return data; + } + + Matrix get_auto_ydata (void) + { + dim_vector dv = get_cdata ().dims (); + Matrix data; + if (dv(0) > 0.) + { + data = Matrix (1, 2, 1); + data(1) = dv(0); + } + return data; + } + float pixel_size (octave_idx_type dim, const Matrix limits) { octave_idx_type l = dim - 1;
--- a/scripts/image/image.m Fri Jul 04 21:40:50 2014 -0700 +++ b/scripts/image/image.m Mon Apr 14 22:53:44 2014 +0200 @@ -144,16 +144,17 @@ if (! isempty (img)) if (isempty (x)) - x = [1, columns(img)]; + xdata = []; + else + xdata = x([1, end])(:).'; # (:).' is a hack to guarantee row vector endif if (isempty (y)) - y = [1, rows(img)]; + ydata = []; + else + ydata = y([1, end])(:).'; endif - xdata = x([1, end])(:).'; # (:).' is a hack to guarantee row vector - ydata = y([1, end])(:).'; - if (numel (x) > 2 && numel (y) > 2) ## Test data for non-linear spacing which is unsupported tol = .01; # 1% tolerance. FIXME: this value was chosen without thought. @@ -220,4 +221,31 @@ %! h = image (-x, -y, img); %! title ("image (-x, -y, img)"); +%!test +%! ## test hidden properties x/ydatamode (bug #42121) +%! hf = figure ("visible", "off"); +%! unwind_protect +%! nx = 64; ny = 64; +%! cdata = rand (ny, nx)*127; +%! hi = image (cdata); # x/ydatamode is auto +%! assert (get (hi, "xdata"), [1 nx]) +%! assert (get (hi, "ydata"), [1 ny]) +%! set (hi, "cdata", cdata(1:2:end, 1:2:end)) +%! assert (get (hi, "xdata"), [1 nx/2]) +%! assert (get (hi, "ydata"), [1 ny/2]) +%! +%! set (hi, "xdata", [10 100]) # xdatamode is now manual +%! set (hi, "ydata", [10 1000]) # ydatamode is now manual +%! set (hi, "cdata", cdata) +%! assert (get (hi, "xdata"), [10 100]) +%! assert (get (hi, "ydata"), [10 1000]) +%! +%! set (hi, "ydata", []) # ydatamode is now auto +%! set (hi, "cdata", cdata(1:2:end, 1:2:end)) +%! assert (get (hi, "xdata"), [10 100]) +%! assert (get (hi, "ydata"), [1 ny/2]) +%! unwind_protect_cleanup +%! close (hf) +%! end_unwind_protect + ## FIXME: Need %!tests for linear