Mercurial > hg > octave-lyh
changeset 15069:7a3957ca99c3
Handle complex arguments in imagesc (bug #36866)
* image.m: Don't error out with complex images, show real part and
warn, like imshow.
* graphics.in.h (array_property): Change type_constraint to std::set
instead of std::list.
(array_property::add_constraint): Use std::set::insert instead of
std::list::push_back.
(image::properties::init): Add new "real" constraint.
* graphics.cc (array_property::validate): Check for new "real" type constraint.
* gl-render.cc (opengl_renderer::draw_image): Abort if no image data is found.
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Tue, 31 Jul 2012 18:06:54 -0400 |
parents | f57d7578c1a6 |
children | 1feefc5e5630 |
files | scripts/image/image.m src/gl-render.cc src/graphics.cc src/graphics.in.h |
diffstat | 4 files changed, 17 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/image/image.m +++ b/scripts/image/image.m @@ -73,7 +73,8 @@ endif if (iscomplex (img)) - error ("image: data can not be complex"); + warning ("image: only showing real part of complex image"); + img = real (img); endif oldax = gca ();
--- a/src/gl-render.cc +++ b/src/gl-render.cc @@ -2488,6 +2488,10 @@ Matrix x = props.get_xdata ().matrix_value (); Matrix y = props.get_ydata ().matrix_value (); + // Someone wants us to draw an empty image? No way. + if (x.is_empty () || y.is_empty ()) + return; + if (w > 1 && x(1) == x(0)) x(1) = x(1) + (w-1);
--- a/src/graphics.cc +++ b/src/graphics.cc @@ -1201,10 +1201,14 @@ // check value type if (type_constraints.size () > 0) { - for (std::list<std::string>::const_iterator it = type_constraints.begin (); - ! xok && it != type_constraints.end (); ++it) - if ((*it) == v.class_name ()) - xok = true; + if(type_constraints.find (v.class_name()) != type_constraints.end()) + xok = true; + + // check if complex is allowed (it's also of class "double", so + // checking that alone is not enough to ensure real type) + if (type_constraints.find ("real") != type_constraints.end () + && v.is_complex_type ()) + xok = false; } else xok = v.is_numeric_type ();
--- a/src/graphics.in.h +++ b/src/graphics.in.h @@ -1413,7 +1413,7 @@ octave_value get (void) const { return data; } void add_constraint (const std::string& type) - { type_constraints.push_back (type); } + { type_constraints.insert (type); } void add_constraint (const dim_vector& dims) { size_constraints.push_back (dims); } @@ -1486,7 +1486,7 @@ double xmax; double xminp; double xmaxp; - std::list<std::string> type_constraints; + std::set<std::string> type_constraints; std::list<dim_vector> size_constraints; }; @@ -4432,6 +4432,7 @@ cdata.add_constraint ("uint8"); cdata.add_constraint ("uint16"); cdata.add_constraint ("int16"); + cdata.add_constraint ("real"); cdata.add_constraint (dim_vector (-1, -1)); cdata.add_constraint (dim_vector (-1, -1, 3)); }