# HG changeset patch # User jwe # Date 1186767299 0 # Node ID 0089a504fdd68d5395f72fa0578ee0346e290828 # Parent afa9123c5faac8e8f853d111d64e92ca121d7e92 [project @ 2007-08-10 17:34:59 by jwe] diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,13 @@ +2007-08-10 Kai Habel + + * plot/patch.m, plot/__patch__.m: New files. + * plot/Makefile.in (SOURCES): Add them to the list. + +2007-08-07 John W. Eaton + + * path/savepath.m: Use single quotes for argument to PATH command + that is inserted in file. + 2007-07-27 John W. Eaton * plot/drawnow.m: Only set default value for term if GNUTERM is diff --git a/scripts/path/savepath.m b/scripts/path/savepath.m --- a/scripts/path/savepath.m +++ b/scripts/path/savepath.m @@ -108,7 +108,9 @@ fprintf (fid, "%s\n", pre{i}) endfor - fprintf (fid, "%s\n path (\"%s\");\n%s\n", + ## Use single quotes for PATH argument to avoid string escape + ## processing. + fprintf (fid, "%s\n path ('%s');\n%s\n", beginstring, path (), endstring); for i = 1:length (post) diff --git a/scripts/plot/Makefile.in b/scripts/plot/Makefile.in --- a/scripts/plot/Makefile.in +++ b/scripts/plot/Makefile.in @@ -33,6 +33,7 @@ __gnuplot_version__.m \ __line__.m \ __next_line_color__.m \ + __patch__.m \ __plr1__.m \ __plr2__.m \ __plt1__.m \ @@ -77,6 +78,7 @@ ndgrid.m \ newplot.m \ orient.m \ + patch.m \ peaks.m \ plot.m \ plot3.m \ diff --git a/scripts/plot/__patch__.m b/scripts/plot/__patch__.m new file mode 100644 --- /dev/null +++ b/scripts/plot/__patch__.m @@ -0,0 +1,103 @@ +## Copyright (C) 2007 John W. Eaton, Shai Ayal, Kai Habel +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, write to the Free +## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +## 02110-1301, USA. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __patch__ (@var{p}, @var{x}, @var{y}, @var{c}) +## Create patch object from @var{x} and @var{y} with color @var{c} and parent @var{p}. +## Return handle to patch object. +## @end deftypefn + +## Author: Kai Habel + +function h = __patch__ (p, varargin) + + if (nargin < 1) + print_usage (); + endif + + nvargs = numel (varargin); + + if (nvargs > 1 && isnumeric (varargin{1}) && isnumeric (varargin{2})) + num_data_args = 2; + else + num_data_args = 0; + endif + + if (rem (nvargs - num_data_args - 1, 2) == 0 && nvargs > 2) + else + print_usage ("patch"); + endif + + x = varargin{1}; + y = varargin{2}; + c = varargin{3}; + + h = __go_patch__ (p); + ax = get (h, "parent"); + if (num_data_args > 1) + set (h, "xdata", x, "ydata", y); + endif + + if (isstr (c)) + ## Have color string. + set (h, "FaceColor", c); + elseif (length (c) == 1) + if (isnan (c)) + set (h, "FaceColor", [1, 1, 1]); + set (h, "CData", c); + elseif (isnumeric (c)) + ## Have color index. + set (h, "FaceColor", "flat"); + set (h, "CData", c); + + clim = get(ax, "CLim"); + if (c < clim(1)) + set (ax, "CLim", [c, clim(2)]) + endif + if (c > clim(2)) + set (ax, "CLim", [clim(1), c]) + end + + else + ## Unknown color value. + error ("color value not valid"); + end + elseif (length (c) == 3) + ## Have rgb/rgba value. + set (h, "FaceColor", c); + else + ## Color vector. + if (length (c) != length (x) || length (c) != length (y)) + error ("size of x, y, and c must be equal") + else + set (h, "FaceColor", "interp"); + set(h, "CData", c); + if (abs(max(c) - min(c)) < eps) + set (ax, "CLim", [c(1)-1, c(1)+1]) + else + set (ax, "CLim", [min(c), max(c)]); + end + end + end + + if (nvargs > num_data_args + 1) + set (h, varargin{num_data_args+2:end}); + endif + +endfunction diff --git a/scripts/plot/patch.m b/scripts/plot/patch.m new file mode 100644 --- /dev/null +++ b/scripts/plot/patch.m @@ -0,0 +1,42 @@ +## Copyright (C) 2005 John W. Eaton +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, write to the Free +## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +## 02110-1301, USA. + +## -*- texinfo -*- +## @deftypefn {Function File} {} patch () +## @deftypefnx {Function File} {} patch (@var{x}, @var{y}, @var{c}) +## @deftypefnx {Function File} {} patch (@var{x}, @var{y}, @var{c}, @var{opts}) +## Create patch object from @var{x} and @var{y} with color @var{c} and insert in current +## axes object. Return handle to patch object. +## For an uniform colored patch, @var{c} can be given as [r, g, b]-vector, scalar value refering +## to the current colormap, or string value (e.g. "r" or "red"). +## @end deftypefn + +## Author: jwe + +function h = patch (varargin) + + ## make a default patch object, and make it the current axes for + ## the current figure. + tmp = __patch__ (gca (), varargin{:}); + + if (nargout > 0) + h = tmp; + endif + +endfunction diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2007-08-10 Kai Habel + + * graphics.cc, graphics.h (patch): New class. + (axes::axes_properties): New properties, clim and climmode. + (surface::surface_properties::surface_properties): Handle patch. + (F__go_patch__): New function. + 2007-07-30 John W. Eaton * mex.cc (mxArray_number::mxArray_number (int, const char **)): diff --git a/src/graphics.cc b/src/graphics.cc --- a/src/graphics.cc +++ b/src/graphics.cc @@ -245,7 +245,7 @@ { pfx = name.substr (0, 5); - if (pfx.compare ("image")) + if (pfx.compare ("image") || pfx.compare ("patch")) offset = 5; else if (len > 6) { @@ -318,7 +318,7 @@ { pfx = name.substr (0, 5); - if (pfx.compare ("image")) + if (pfx.compare ("image") || pfx.compare ("patch")) offset = 5; else if (len > 6) { @@ -945,9 +945,11 @@ xlim (), ylim (), zlim (), + clim (), xlimmode ("auto"), ylimmode ("auto"), zlimmode ("auto"), + climmode ("auto"), xlabel (octave_NaN), ylabel (octave_NaN), zlabel (octave_NaN), @@ -985,6 +987,9 @@ xlim = tlim; ylim = tlim; zlim = tlim; + Matrix cl (1, 2, 0); + cl(1) = 1; + clim = cl; Matrix tview (1, 2, 0.0); tview(1) = 90; @@ -1054,12 +1059,19 @@ zlim = val; zlimmode = "manual"; } + else if (name.compare ("clim")) + { + clim = val; + climmode = "manual"; + } else if (name.compare ("xlimmode")) xlimmode = val; else if (name.compare ("ylimmode")) ylimmode = val; else if (name.compare ("zlimmode")) zlimmode = val; + else if (name.compare ("climmode")) + climmode = val; else if (name.compare ("xlabel")) { graphics_handle h = ::reparent (val, "set", "xlabel", @@ -1198,10 +1210,15 @@ xlim = tlim; ylim = tlim; zlim = tlim; - + + Matrix cl (1, 2, 0); + cl(1) = 1; + clim = cl; + xlimmode = "auto"; ylimmode = "auto"; zlimmode = "auto"; + climmode = "auto"; xlabel = octave_NaN; ylabel = octave_NaN; zlabel = octave_NaN; @@ -1287,9 +1304,11 @@ m.assign ("xlim", xlim); m.assign ("ylim", ylim); m.assign ("zlim", zlim); + m.assign ("clim", clim); m.assign ("xlimmode", xlimmode); m.assign ("ylimmode", ylimmode); m.assign ("zlimmode", zlimmode); + m.assign ("climmode", climmode); m.assign ("xlabel", xlabel); m.assign ("ylabel", ylabel); m.assign ("zlabel", zlabel); @@ -1365,12 +1384,16 @@ retval = ylim; else if (name.compare ("zlim")) retval = zlim; + else if (name.compare ("clim")) + retval = clim; else if (name.compare ("xlimmode")) retval = xlimmode; else if (name.compare ("ylimmode")) retval = ylimmode; else if (name.compare ("zlimmode")) retval = zlimmode; + else if (name.compare ("climmode")) + retval = climmode; else if (name.compare ("xlabel")) { if (xisnan (xlabel)) @@ -1506,10 +1529,16 @@ m["xlim"] = tlim; m["ylim"] = tlim; m["zlim"] = tlim; + + Matrix cl(1, 2, 0); + cl(1) = 1; + + m["clim"] = cl; m["xlimmode"] = "auto"; m["ylimmode"] = "auto"; m["zlimmode"] = "auto"; + m["climmode"] = "auto"; m["xlabel"] = octave_NaN; m["ylabel"] = octave_NaN; m["zlabel"] = octave_NaN; @@ -1952,6 +1981,173 @@ // --------------------------------------------------------------------- +patch::patch_properties::patch_properties (const graphics_handle& mh, + const graphics_handle& p) + : base_properties (go_name, mh, p), + cdata (Matrix ()), + xdata (Matrix ()), + ydata (Matrix ()), + zdata (Matrix ()), + facecolor (radio_values("{flat}|none|interp")), + facealpha (1.0), + edgecolor (color_values(0, 0, 0), radio_values("flat|none|interp")), + linestyle ("-"), + linewidth (0.5), + marker ("none"), + markeredgecolor ("auto"), + markerfacecolor ("none"), + markersize (1) +{ } + +void +patch::patch_properties::set (const property_name& name, + const octave_value& val) +{ + bool modified = true; + + if (name.compare ("parent")) + set_parent (val); + else if (name.compare ("children")) + children = maybe_set_children (children, val); + else if (name.compare ("__modified__")) + { + __modified__ = val.bool_value (); + modified = false; + } + else if (name.compare ("cdata")) + cdata = val; + else if (name.compare ("xdata")) + xdata = val; + else if (name.compare ("ydata")) + ydata = val; + else if (name.compare ("zdata")) + zdata = val; + else if (name.compare ("facecolor")) + facecolor = val; + else if (name.compare ("facealpha")) + facealpha = val; + else if (name.compare ("edgecolor")) + edgecolor = val; + else if (name.compare ("linestyle")) + linestyle = val; + else if (name.compare ("linewidth")) + linewidth = val; + else if (name.compare ("marker")) + marker = val; + else if (name.compare ("markeredgecolor")) + markeredgecolor = val; + else if (name.compare ("markerfacecolor")) + markerfacecolor = val; + else if (name.compare ("markersize")) + markersize = val; + + else + { + modified = false; + warning ("set: invalid property `%s'", name.c_str ()); + } + + if (modified) + mark_modified (); +} + +octave_value +patch::patch_properties::get (void) const +{ + Octave_map m; + + m.assign ("type", type); + m.assign ("parent", parent); + m.assign ("children", children); + m.assign ("__modified__", __modified__); + m.assign ("cdata", cdata); + m.assign ("xdata", xdata); + m.assign ("ydata", ydata); + m.assign ("zdata", zdata); + m.assign ("facecolor", facecolor); + m.assign ("facealpha", facealpha); + m.assign ("edgecolor", edgecolor); + m.assign ("linestyle", linestyle); + m.assign ("linewidth", linewidth); + m.assign ("marker", marker); + m.assign ("markeredgecolor", markeredgecolor); + m.assign ("markerface", markerfacecolor); + m.assign ("markersize", markersize); + + return m; +} + +octave_value +patch::patch_properties::get (const property_name& name) const +{ + octave_value retval; + + if (name.compare ("type")) + retval = type; + else if (name.compare ("parent")) + retval = parent; + else if (name.compare ("children")) + retval = children; + else if (name.compare ("__modified__")) + retval = __modified__; + else if (name.compare ("cdata")) + retval = cdata; + else if (name.compare ("xdata")) + retval = xdata; + else if (name.compare ("ydata")) + retval = ydata; + else if (name.compare ("zdata")) + retval = zdata; + else if (name.compare ("facecolor")) + retval = facecolor; + else if (name.compare ("facealpha")) + retval = facecolor; + else if (name.compare ("egdecolor")) + retval = edgecolor; + else if (name.compare ("linestyle")) + retval = linestyle; + else if (name.compare ("linewidth")) + retval = linewidth; + else if (name.compare ("marker")) + retval = marker; + else if (name.compare ("markeredgecolor")) + retval = markeredgecolor; + else if (name.compare ("markerfacecolor")) + retval = markerfacecolor; + else if (name.compare ("markersize")) + retval = markersize; + else + warning ("get: invalid property `%s'", name.c_str ()); + + return retval; +} + +property_list::pval_map_type patch::patch_properties::factory_defaults (void) +{ + property_list::pval_map_type m; + + m["cdata"] = Matrix (); + m["xdata"] = Matrix (); + m["ydata"] = Matrix (); + m["zdata"] = Matrix (); + m["facecolor"] = color_property(); + m["facealpha"] = 1.0; + m["edgecolor"] = color_property("black"); + m["linestyle"] = "-"; + m["linewidth"] = 0.5; + m["marker"] = "none"; + m["markeredgecolor"] = "auto"; + m["markerfacecolor"] = "none"; + m["markersize"] = 1; + + + return m; +} + +std::string patch::patch_properties::go_name ("patch"); + +// --------------------------------------------------------------------- + surface::surface_properties::surface_properties (const graphics_handle& mh, const graphics_handle& p) : base_properties (go_name, mh, p), @@ -2096,9 +2292,10 @@ go = new text (h, p); else if (go_name == "image") go = new image (h, p); + else if (go_name == "patch") + go = new patch (h, p); else if (go_name == "surface") go = new surface (h, p); - if (go) handle_map[h] = graphics_object (go); else @@ -2151,6 +2348,7 @@ plist_map["line"] = line::line_properties::factory_defaults (); plist_map["text"] = text::text_properties::factory_defaults (); plist_map["image"] = image::image_properties::factory_defaults (); + plist_map["patch"] = patch::patch_properties::factory_defaults (); plist_map["surface"] = surface::surface_properties::factory_defaults (); return plist_map; @@ -2440,6 +2638,15 @@ GO_BODY (surface); } +DEFUN (__go_patch__, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} __go_patch__ (@var{parent})\n\ +Create a patch graphics object.\n\ +@end deftypefn") +{ + GO_BODY (patch); +} + DEFUN (__go_delete__, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} __go_delete__ (@var{h})\n\ diff --git a/src/graphics.h b/src/graphics.h --- a/src/graphics.h +++ b/src/graphics.h @@ -1179,9 +1179,11 @@ OCTAVE_GRAPHICS_PROPERTY (octave_value, xlim); OCTAVE_GRAPHICS_PROPERTY (octave_value, ylim); OCTAVE_GRAPHICS_PROPERTY (octave_value, zlim); + OCTAVE_GRAPHICS_PROPERTY (octave_value, clim); OCTAVE_GRAPHICS_PROPERTY (octave_value, xlimmode); OCTAVE_GRAPHICS_PROPERTY (octave_value, ylimmode); OCTAVE_GRAPHICS_PROPERTY (octave_value, zlimmode); + OCTAVE_GRAPHICS_PROPERTY (octave_value, climmode); OCTAVE_GRAPHICS_MUTABLE_PROPERTY (graphics_handle, xlabel); OCTAVE_GRAPHICS_MUTABLE_PROPERTY (graphics_handle, ylabel); OCTAVE_GRAPHICS_MUTABLE_PROPERTY (graphics_handle, zlabel); @@ -1584,6 +1586,99 @@ // --------------------------------------------------------------------- +class patch : public base_graphics_object +{ +public: + class patch_properties : public base_properties + { + public: + patch_properties (const graphics_handle& mh, const graphics_handle& p); + + ~patch_properties (void) { } + + void set (const property_name& name, const octave_value& val); + + octave_value get (void) const; + + octave_value get (const property_name& name) const; + + std::string graphics_object_name (void) const { return go_name; } + + static property_list::pval_map_type factory_defaults (void); + + private: + OCTAVE_GRAPHICS_PROPERTY (octave_value, cdata); + OCTAVE_GRAPHICS_PROPERTY (octave_value, xdata); + OCTAVE_GRAPHICS_PROPERTY (octave_value, ydata); + OCTAVE_GRAPHICS_PROPERTY (octave_value, zdata); + OCTAVE_GRAPHICS_PROPERTY (color_property, facecolor); + OCTAVE_GRAPHICS_PROPERTY (octave_value, facealpha); + OCTAVE_GRAPHICS_PROPERTY (color_property, edgecolor); + OCTAVE_GRAPHICS_PROPERTY (octave_value, linestyle); + OCTAVE_GRAPHICS_PROPERTY (octave_value, linewidth); + OCTAVE_GRAPHICS_PROPERTY (octave_value, marker); + OCTAVE_GRAPHICS_PROPERTY (octave_value, markeredgecolor); + OCTAVE_GRAPHICS_PROPERTY (octave_value, markerfacecolor); + OCTAVE_GRAPHICS_PROPERTY (octave_value, markersize); + + static std::string go_name; + }; + + patch_properties properties; + +public: + patch (const graphics_handle& mh, const graphics_handle& p) + : base_graphics_object (), properties (mh, p) + { + properties.override_defaults (*this); + } + + ~patch (void) { properties.delete_children (); } + + std::string type (void) const { return properties.graphics_object_name (); } + + void mark_modified (void) { properties.mark_modified (); } + + void override_defaults (base_graphics_object& obj) + { + // Allow parent (figure) to override first (properties knows how + // to find the parent object). + properties.override_defaults (obj); + } + + void set_from_list (property_list& plist) + { + properties.set_from_list (*this, plist); + } + + void set (const property_name& name, const octave_value& val) + { + properties.set (name, val); + } + + octave_value get (void) const + { + return properties.get (); + } + + octave_value get (const property_name& name) const + { + return properties.get (name); + } + + graphics_handle get_parent (void) const { return properties.get_parent (); } + + void remove_child (const graphics_handle& h) { properties.remove_child (h); } + + void adopt (const graphics_handle& h) { properties.adopt (h); } + + void reparent (const graphics_handle& h) { properties.reparent (h); } + + bool valid_object (void) const { return true; } +}; + +// --------------------------------------------------------------------- + class surface : public base_graphics_object { public: