octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [unclassified] patch for color_properties assignment


From: Kai Habel
Subject: Re: [unclassified] patch for color_properties assignment
Date: Wed, 11 Jul 2007 08:37:33 +0000
User-agent: IceDove 1.5.0.12 (X11/20070607)

Shai Ayal schrieb:
On 7/11/07, Kai Habel <address@hidden> wrote:
Hello,

I have some problems with this patch.
I think we have to modify the constructor
"color_property::color_property (const octave_value& val)" in the same
way. Because if I try to set the allowed radio_values (e.g. for line) with

xudata (Matrix ()),
color ("none|flat|interp"),
linestyle ("-"),

I get the following error:
octave:1> h=__go_line__ (gca)
error: invalid color specification
error: __goline__: unable to create graphics handle
error: evaluating assignment expression near line 1, column 2


The way it is written is too ambigious -- the std::string argument
could be converted to either a color_values, radio_values or
octave_value since all of them have std::string constructors.

In the case above, the following should work:
color(radio_values("none|flat|interp"));


Yes of course, that should work. It seems I was to focused on my work around.


Another problem is the radio_values::validate method. In your patch you
check first for valid radio values:

          if (radio_val.validate (s))
+           {
+             current_val = s;
+             current_type = radio_t;
+           }
+           else
+           {
+             color_values col (s);
+             if (! error_state)
+               {
+                 color_val = col;
+                 current_type = color_t;
+               }
+             else
+               error ("invalid color specification");
+           }



but if 's' is a string color value (e.g. 'r' or 'red')  validate calls
the error function and sets the error flag. This causes an error message
and octave terminates. I have turned off the error call in
radio_values::validate for test purposes. Then the creation of a line
object with:
h=__go_line__ (gca);

works as expected.

I think the issue here is that validate raises an error. I will send a
patch which will overcome this (e,g, replace radio_val.validate (s)
with

radio_val.possible_vals.find (val) != radio_val.possible_vals.end ()

Yes, that should work as well.
Shai

p.s. How do you draw the patch in gnuplot?
David came up with the idea to use the new qualifier 'with filledcurve' some time ago and indeed you can use it to draw patches, but only in 2D. FYI, I have attached the relevant patch for __go_draw_axes__.m

I think I have patch running now, I can use the contourf.m and __contourc__.cc function from octplot and draw nice plots. It will take some time to check my changes, but I hope to send it to the list before my holidays start next week. :-)

Kai


--- ../cvs-octave/octave/scripts/plot/__go_draw_axes__.m        2007-07-10 
19:50:16.000000000 +0000
+++ ./__go_draw_axes__.m        2007-07-10 19:48:20.000000000 +0000
@@ -406,6 +406,84 @@
            endif
          endif
 
+        case "patch"
+          if (!have_newer_gnuplot)
+            warning("patch objects require gnuplot v4.2 or later!, sorry")
+          else
+           if (! isempty (obj.zdata))
+              warning("gnuplot (as of v4.2) supports only 2D patches, ignoring 
z values")
+           endif
+           nd = 2;
+            cmap = parent_figure_obj.colormap;
+            clim = axis_obj.clim;
+           data_idx++;
+           is_image_data(data_idx) = false;
+            titlespec{data_idx} = "title \"\"";
+           usingclause{data_idx} = "";
+            if (isfield (obj, "facecolor") && isfield (obj, "cdata"))
+                if (strncmp(obj.facecolor, "none", 4))
+                 color = [1, 1, 1];
+                elseif (strncmp(obj.facecolor, "flat", 4))
+                  r = 1 + round((size(cmap, 1) - 1) * (obj.cdata - 
clim(1))/(clim(2) - clim(1)));
+                  r = max(1, min(r, size(cmap, 1)));
+                 color = cmap(r, :);
+                elseif (strncmp(obj.facecolor, "interp", 6))
+                  warning("\"interp\" not supported, using 1st entry of cdata")
+                  r = 1 + round((size(cmap, 1) - 1) * obj.cdata(1));
+                  r = max(1, min(r, size(cmap, 1)));
+                 color = cmap(r, :);
+                else
+                 color = obj.facecolor;
+                endif
+            else
+                color = [1 0 0];
+            endif
+
+           withclause{data_idx} = sprintf ("with filledcurve lc rgb 
\"#%02x%02x%02x\"",round (255*color));
+           parametric(data_idx) = true;
+
+           xdat = obj.xdata(:);
+           ydat = obj.ydata(:);
+
+           if (xautoscale)
+              [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat);
+           endif
+           if (yautoscale)
+             [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ydat);
+           endif
+           data{data_idx} = [xdat, ydat]';
+           usingclause{data_idx} = "using ($1):($2)";
+         endif
+
+          # patch outline
+          data_idx++;
+          is_image_data(data_idx) = false;
+          # I had to use data_idx instead of i here, not sure if o.k. (Kai)
+          parametric(data_idx) = true;
+          titlespec{data_idx} = "title \"\"";
+         usingclause{data_idx} = "";
+          if (isfield (obj, "edgecolor"))
+            if (strncmp(obj.edgecolor, "none", 4))
+              color = [1, 1, 1];
+            elseif (strncmp(obj.edgecolor, "flat", 4))
+              warning("\"flat\" for edgecolor not supported");
+              color = [0, 0, 0];
+            elseif (strncmp(obj.edgecolor, "interp", 6))
+              warning("\"interp\" for edgecolor not supported");
+              color = [0, 0, 0];
+            else
+             color = obj.edgecolor;
+            endif
+          else
+            color = [0, 0, 0];
+          endif
+         withclause{data_idx} = sprintf ("with lines lc rgb 
\"#%02x%02x%02x\"",round (255*color));
+
+          xdat = [xdat; xdat(1)];
+         ydat = [ydat; ydat(1)];
+         data{data_idx} = [xdat, ydat]';
+         usingclause{data_idx} = "using ($1):($2)";
+
        case "surface"
          data_idx++;
          is_image_data(data_idx) = false;

reply via email to

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