# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1343772414 14400 # Node ID 7a3957ca99c38b3207ca3dd691a72b1b76b3255b # Parent f57d7578c1a6b2de99d455f0785c97ae7b22ec21 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. diff -r f57d7578c1a6 -r 7a3957ca99c3 scripts/image/image.m --- a/scripts/image/image.m Tue Jul 31 15:40:52 2012 -0500 +++ b/scripts/image/image.m Tue Jul 31 18:06:54 2012 -0400 @@ -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 (); diff -r f57d7578c1a6 -r 7a3957ca99c3 src/gl-render.cc --- a/src/gl-render.cc Tue Jul 31 15:40:52 2012 -0500 +++ b/src/gl-render.cc Tue Jul 31 18:06:54 2012 -0400 @@ -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); diff -r f57d7578c1a6 -r 7a3957ca99c3 src/graphics.cc --- a/src/graphics.cc Tue Jul 31 15:40:52 2012 -0500 +++ b/src/graphics.cc Tue Jul 31 18:06:54 2012 -0400 @@ -1201,10 +1201,14 @@ // check value type if (type_constraints.size () > 0) { - for (std::list::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 (); diff -r f57d7578c1a6 -r 7a3957ca99c3 src/graphics.in.h --- a/src/graphics.in.h Tue Jul 31 15:40:52 2012 -0500 +++ b/src/graphics.in.h Tue Jul 31 18:06:54 2012 -0400 @@ -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 type_constraints; + std::set type_constraints; std::list 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)); }