# HG changeset patch # User Rik # Date 1310833706 25200 # Node ID 6f91ca83d2bedea9b710476079494712b53ff619 # Parent dc29b64668fae2d8cb8e5b85774587ddb6a4731d codesprint : Make many plot helper functions private. * plot/module.mk : Update where to find files for Automake *__fltk_ginput__.m, __fltk_print__.m, __gnuplot_drawnow__.m, __gnuplot_get_var__.m, __gnuplot_ginput__.m, __gnuplot_has_feature__.m, __gnuplot_open_stream__.m, __gnuplot_print__.m, __gnuplot_version__.m, __go_draw_axes__.m, __go_draw_figure__.m, __marching_cube__.m, __next_line_color__.m, __next_line_style__.m, __print_parse_opts__.m: Move helper functions into plot/private/ directory. diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/__fltk_ginput__.m --- a/scripts/plot/__fltk_ginput__.m Sat Jul 16 09:16:52 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ -## Copyright (C) 2010-2011 Shai Ayal -## -## 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 3 of the License, 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, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {[@var{x}, @var{y}, @var{buttons}] =} __fltk_ginput__ (@var{f}, @var{n}) -## Undocumented internal function. -## @end deftypefn - -## This is ginput.m implementation for fltk. - -## FIXME -- Key presses cannot toggle menu items nor hotkey functionality -## (grid, autoscale) during ginput! - -function [x, y, button] = __fltk_ginput__ (f, n = -1) - - if (isempty (get (f, "currentaxes"))) - error ("ginput: must have at least one axes"); - endif - - x = y = button = []; - ginput_aggregator (0, 0, 0, 0); - - unwind_protect - - orig_windowbuttondownfcn = get (f, "windowbuttondownfcn"); - set (f, "windowbuttondownfcn", @ginput_windowbuttondownfcn); - - orig_ginput_keypressfcn = get (f, "keypressfcn"); - set (f, "keypressfcn", @ginput_keypressfcn); - - while (true) - __fltk_redraw__ (); - - ## Release CPU. - sleep (0.01); - - [x, y, n0, button] = ginput_aggregator (-1, 0, 0, 0); - if (n0 == n || n0 < 0) - break; - endif - endwhile - - unwind_protect_cleanup - set (f, "windowbuttondownfcn", orig_windowbuttondownfcn); - set (f, "keypressfcn", orig_ginput_keypressfcn); - end_unwind_protect - -endfunction - -function [x, y, n, button] = ginput_aggregator (mode, xn, yn, btn) - persistent x y n button; - - if (mode == 0) - ## Initialize. - x = []; - y = []; - button = []; - n = 0; - elseif (mode == 1) - ## Accept mouse button or key press. - x = [x; xn]; - y = [y; yn]; - button = [button; btn]; - n += 1; - elseif (mode == 2) - ## The end due to Enter. - n = -1; - endif -endfunction - -function ginput_windowbuttondownfcn (src, data) - point = get (get (src,"currentaxes"), "currentpoint"); - ## FIXME -- How to get the actual mouse button pressed (1,2,3) into - ## "button"? - button = 1; - ginput_aggregator (1, point(1,1), point(2,1), button); -endfunction - -function ginput_keypressfcn (src, evt) - point = get (get (src, "currentaxes"), "currentpoint"); - ## FIXME -- use evt.Key or evt.Character? - key = evt.Key; - if (key == 10) - ## Enter key. - ginput_aggregator (2, point(1,1), point(2,1), key); - else - ginput_aggregator (1, point(1,1), point(2,1), key); - endif -endfunction - diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/__fltk_print__.m --- a/scripts/plot/__fltk_print__.m Sat Jul 16 09:16:52 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,161 +0,0 @@ -## Copyright (C) 2010-2011 Shai Ayal -## -## 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 3 of the License, 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, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {} __fltk_print__ (@var{@dots{}}) -## Undocumented internal function. -## @end deftypefn - -function opts = __fltk_print__ (opts) - - dos_shell = (ispc () && ! isunix ()); - - figure (opts.figure); - drawnow ("expose"); - __fltk_redraw__ (); - - if (! isempty (opts.fig2dev_binary)) - ## fig2dev is prefered for conversion to emf - fig2dev_devices = {"pstex", "mf", "emf"}; - else - fig2dev_devices = {"pstex", "mf"}; - endif - - gl2ps_device = {}; - pipeline = {}; - switch (lower (opts.devopt)) - case {"eps", "eps2", "epsc", "epsc2"} - ## format GL2PS_EPS - gl2ps_device = {"eps"}; - ## FIXME - use epstool to tighten bbox and provide preview. - pipeline = {opts.epstool_cmd(opts, "-", opts.name)}; - case {"epslatex", "pslatex", "pdflatex", "epslatexstandalone", ... - "pslatexstandalone", "pdflatexstandalone"} - ## format GL2PS_TEX - n = find (opts.devopt == "l", 1); - suffix = opts.devopt(1:n-1); - dot = find (opts.name == ".", 1, "last"); - if ((! isempty (dot)) - && any (strcmpi (opts.name(dot:end), ... - {".eps", ".ps", ".pdf", ".tex", "."}))) - name = opts.name(1:dot-1); - if (dot < numel (opts.name) - && any (strcmpi (opts.name(dot+1:end), {"eps", "ps", "pdf"}))) - ## If user provides eps/ps/pdf suffix, use it. - suffix = opts.name(dot+1:end); - endif - elseif (dot == numel (opts.name)) - name = opts.name; - endif - gl2ps_device = {sprintf("%snotxt", lower (suffix))}; - gl2ps_device{2} = "tex"; - if (dos_shell) - ## FIXME - this will only work on MinGW with the MSYS shell - pipeline = {sprintf("cat > %s-inc.%s", name, suffix)}; - pipeline{2} = sprintf ("cat > %s.tex", name); - else - pipeline = {sprintf("cat > %s-inc.%s", name, suffix)}; - pipeline{2} = sprintf ("cat > %s.tex", name); - endif - case "tikz" - ## format GL2PS_PGF - gl2ps_device = {"pgf"}; - pipeline = {sprintf("cat > %s", opts.name)}; - case "svg" - ## format GL2PS_SVG - gl2ps_device = {"svg"}; - pipeline = {sprintf("cat > %s", opts.name)}; - case fig2dev_devices - cmd_pstoedit = opts.pstoedit_cmd (opts, "fig"); - cmd_fig2dev = opts.fig2dev_cmd (opts, opts.devopt); - if (strcmp (opts.devopt, "pstex")) - [~, ~, ext] = fileparts (opts.name); - if (any (strcmpi (ext, {".ps", ".tex", "."}))) - opts.name = opts.name(1:end-numel(ext)); - endif - opts.name = strcat (opts.name, ".ps"); - cmd = sprintf ("%s | %s > %s", cmd_pstoedit, cmd_fig2dev, opts.name); - gl2ps_device = {"eps"}; - pipeline = {cmd}; - cmd_fig2dev = opts.fig2dev_cmd (opts, "pstex_t"); - gl2ps_device{2} = "eps"; - pipeline{2} = sprintf ("%s | %s > %s", cmd_pstoedit, - cmd_fig2dev, strrep(opts.name, ".ps", ".tex")); - else - cmd = sprintf ("%s | %s > %s", cmd_pstoedit, cmd_fig2dev, opts.name); - gl2ps_device = {"eps"}; - pipeline = {cmd}; - endif - case "aifm" - cmd = opts.pstoedit_cmd (opts, "ps2ai"); - gl2ps_device = {"eps"}; - pipeline = {sprintf("%s > %s", cmd, opts.name)}; - case {"dxf", "emf", "fig", "hpgl"} - cmd = opts.pstoedit_cmd (opts); - gl2ps_device = {"eps"}; - pipeline = {sprintf("%s > %s", cmd, opts.name)}; - case {"corel", "gif"} - error ("print:unsupporteddevice", - "print.m: %s output is not available for the FLTK graphics toolkit", - upper (opts.devopt)); - case opts.ghostscript.device - opts.ghostscript.source = "-"; - opts.ghostscript.output = opts.name; - if (opts.send_to_printer) - opts.unlink(strcmp (opts.unlink, opts.ghostscript.output)) = []; - opts.ghostscript.output = "-"; - endif - [cmd_gs, cmd_cleanup] = __ghostscript__ (opts.ghostscript); - if (opts.send_to_printer || isempty (opts.name)) - cmd_lpr = opts.lpr_cmd (opts); - cmd = sprintf("%s | %s", cmd_gs, cmd_lpr); - else - cmd = sprintf("%s", cmd_gs); - endif - if (! isempty (cmd_cleanup)) - gl2ps_device = {"eps"}; - if (dos_shell) - pipeline = {sprintf("%s & %s", cmd, cmd_cleanup)}; - else - pipeline = {sprintf("%s ; %s", cmd, cmd_cleanup)}; - endif - else - gl2ps_device = {"eps"}; - pipeline = {cmd}; - endif - otherwise - error (sprintf ("print:no%soutput", opts.devopt), - "print.m: %s output is not available for GL2PS output", - upper (opts.devopt)); - endswitch - - opts.pipeline = pipeline; - - for n = 1:numel(pipeline) - if (opts.debug) - fprintf ("fltk-pipeline: '%s'\n", pipeline{n}); - endif - drawnow (gl2ps_device{n}, strcat('|',pipeline{n})); - endfor - - if (! isempty (strfind (opts.devopt, "standalone"))) - opts.latex_standalone (opts); - endif - -endfunction - diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/__gnuplot_drawnow__.m --- a/scripts/plot/__gnuplot_drawnow__.m Sat Jul 16 09:16:52 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,388 +0,0 @@ -## Copyright (C) 2005-2011 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 3 of the License, 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, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {} __gnuplot_drawnow__ (@var{h}, @var{term}, @var{file}, @var{mono}, @var{debug_file}) -## Undocumented internal function. -## @end deftypefn - -## Author: jwe - -function __gnuplot_drawnow__ (h, term, file, mono, debug_file) - - if (nargin < 4) - mono = false; - endif - - if (nargin >= 3 && nargin <= 5) - ## Produce various output formats, or redirect gnuplot stream to a - ## debug file. - plot_stream = []; - fid = []; - default_plot_stream = get (h, "__plot_stream__"); - unwind_protect - plot_stream = __gnuplot_open_stream__ (2, h); - gnuplot_supports_term = __gnuplot_has_terminal__ (term, plot_stream); - if (gnuplot_supports_term) - enhanced = gnuplot_set_term (plot_stream (1), true, h, term, file); - __go_draw_figure__ (h, plot_stream(1), enhanced, mono); - if (nargin == 5) - fid = fopen (debug_file, "wb"); - enhanced = gnuplot_set_term (fid, true, h, term, file); - __go_draw_figure__ (h, fid, enhanced, mono); - endif - else - error ("__gnuplot_drawnow__: the gnuplot terminal, \"%s\", is not available", - gnuplot_trim_term (term)); - endif - unwind_protect_cleanup - set (h, "__plot_stream__", default_plot_stream); - if (! isempty (plot_stream)) - pclose (plot_stream(1)); - if (numel (plot_stream) > 1) - pclose (plot_stream(2)); - endif - if (numel (plot_stream) > 2) - waitpid (plot_stream(3)); - endif - endif - if (! isempty (fid)) - fclose (fid); - endif - end_unwind_protect - elseif (nargin == 1) - ## Graphics terminal for display. - plot_stream = get (h, "__plot_stream__"); - if (isempty (plot_stream)) - plot_stream = __gnuplot_open_stream__ (2, h); - new_stream = true; - else - new_stream = false; - endif - term = gnuplot_default_term (); - if (strcmp (term, "dumb")) - ## popen2 eats stdout of gnuplot, use temporary file instead - dumb_tmp_file = tmpnam (); - enhanced = gnuplot_set_term (plot_stream (1), new_stream, h, ... - term, dumb_tmp_file); - else - enhanced = gnuplot_set_term (plot_stream (1), new_stream, h, term); - endif - __go_draw_figure__ (h, plot_stream (1), enhanced, mono); - fflush (plot_stream (1)); - if (strcmp (term, "dumb")) - fid = -1; - while (fid < 0) - pause (0.1); - fid = fopen (dumb_tmp_file, 'r'); - endwhile - ## reprint the plot on screen - [a, count] = fscanf (fid, '%c', Inf); - fclose (fid); - if (count>0) - if (a(1)==12) - ## avoid ^L at the beginning - a = a(2:end); - endif - puts (a); - endif - unlink (dumb_tmp_file); - endif - else - print_usage (); - endif - -endfunction - -function enhanced = gnuplot_set_term (plot_stream, new_stream, h, term, file) - ## Generate the gnuplot "set terminal ..." command. - ## When "term" originates from print.m, it may include other options. - if (nargin < 4) - ## This supports the gnuplot graphics toolkit. - term = gnuplot_default_term (); - opts_str = ""; - else - ## Get the one word terminal id and save the remaining as options to - ## be passed on to gnuplot. The terminal may respect the graphics - ## toolkit. - [term, opts_str] = gnuplot_trim_term (term); - term = lower (term); - if (strcmpi (term, "lua")) - ## Replace "lau tikz" with - term = "tikz"; - opts_str = strrep (opts_str, "tikz", ""); - endif - endif - - if (strfind (opts_str, "noenhanced")) - enhanced = false; - else - enhanced = gnuplot_is_enhanced_term (term); - endif - - ## Set the terminal. - if (! isempty (term)) - - if (enhanced) - enh_str = "enhanced"; - else - enh_str = ""; - endif - - if (! isempty (h) && isfigure (h)) - - ## Generate gnuplot title string for plot windows. - if (output_to_screen (term) && ~strcmp (term, "dumb")) - fig.numbertitle = get (h, "numbertitle"); - fig.name = get (h, "name"); - if (strcmpi (get (h, "numbertitle"), "on")) - title_str = sprintf ("Figure %d", h); - else - title_str = ""; - endif - if (! isempty (fig.name) && ! isempty (title_str)) - title_str = sprintf ("%s: %s", title_str, fig.name); - elseif (! isempty (fig.name) && isempty (title_str)) - title_str = fig.name; - endif - if (! isempty (title_str)) - title_str = sprintf ("title \"%s\"", title_str); - endif - if (strcmp (term, "aqua")) - ## Adjust axes-label and tick-label spacing. - opts_str = sprintf ("%s font \"%s,%d\"", opts_str, - get (0, "defaultaxesfontname"), - get (0, "defaultaxesfontsize") / 1.5); - endif - else - title_str = ""; - endif - - if (! (any (strfind (opts_str, " size ") > 0) - || any (strfind (opts_str, "size ") == 1))) - ## Get figure size in pixels. Rely on listener to handle coversion. - units = get (h, "units"); - unwind_protect - set (h, "units", "pixels"); - position_in_pixels = get (h, "position"); - unwind_protect_cleanup - set (h, "units", units); - end_unwind_protect - gnuplot_pos = position_in_pixels(1:2); - gnuplot_size = position_in_pixels(3:4); - if (! (output_to_screen (term) - || any (strcmp (term, {"emf", "gif", "jpeg", "pbm", "png", ... - "pngcairo", "svg"})))) - ## Convert to inches - gnuplot_pos = gnuplot_pos / 72; - gnuplot_size = gnuplot_size / 72; - endif - if (all (gnuplot_size > 0)) - terminals_with_size = {"canvas", "emf", "epslatex", "fig", ... - "gif", "jpeg", "latex", "pbm", "pdf", ... - "pdfcairo", "postscript", "png", "pngcairo", ... - "pstex", "pslatex", "svg", "tikz"}; - if (__gnuplot_has_feature__ ("x11_figure_position")) - terminals_with_size{end+1} = "x11"; - endif - if (__gnuplot_has_feature__ ("wxt_figure_size")) - terminals_with_size{end+1} = "wxt"; - endif - switch (term) - case terminals_with_size - size_str = sprintf ("size %g,%g", gnuplot_size); - case "tikz" - size_str = sprintf ("size %gin,%gin", gnuplot_size); - case "dumb" - new_stream = 1; - if (~isempty (getenv ("COLUMNS")) && ~isempty (getenv ("LINES"))) - ## Let dumb use full text screen size (minus prompt lines). - n = sprintf ("%i", -2 - length (find (sprintf ("%s", PS1) == "\n"))); - ## n = the number of times \n appears in PS1 - size_str = ["size ", getenv("COLUMNS"), ",", getenv("LINES"), n]; - else - ## Use the gnuplot default. - size_str = ""; - endif - case {"aqua", "fig", "corel"} - size_str = sprintf ("size %g %g", gnuplot_size); - case "dxf" - size_str = ""; - otherwise - size_str = ""; - endswitch - if (strncmpi (term, "x11", 3) - && __gnuplot_has_feature__ ("x11_figure_position")) - ## X11 allows the window to be positioned as well. - units = get (0, "units"); - unwind_protect - set (0, "units", "pixels"); - screen_size = get (0, "screensize")(3:4); - unwind_protect_cleanup - set (0, "units", units); - end_unwind_protect - if (all (screen_size > 0)) - ## For X11, set the figure positon as well as the size - ## gnuplot position is UL, Octave's is LL (same for screen/window) - gnuplot_pos(2) = screen_size(2) - gnuplot_pos(2) - gnuplot_size(2); - gnuplot_pos = max (gnuplot_pos, 1); - size_str = sprintf ("%s position %d,%d", size_str, - gnuplot_pos(1), gnuplot_pos(2)); - endif - endif - else - size_str = ""; - warning ("gnuplot_set_term: size is zero"); - endif - else - ## A specified size take priority over the figure properies. - size_str = ""; - endif - else - if isempty (h) - disp ("gnuplot_set_term: figure handle is empty"); - elseif !isfigure(h) - disp ("gnuplot_set_term: not a figure handle"); - endif - title_str = ""; - size_str = ""; - endif - - ## Set the gnuplot terminal (type, enhanced, title, options & size). - term_str = sprintf ("set terminal %s", term); - if (! isempty (enh_str)) - term_str = sprintf ("%s %s", term_str, enh_str); - endif - if (! isempty (title_str)) - term_str = sprintf ("%s %s", term_str, title_str); - endif - if (isempty (strfind (term, "corel"))) - if (! isempty (size_str) && new_stream) - ## size_str comes after other options to permit specification of - ## the canvas size for terminals cdr/corel. - term_str = sprintf ("%s %s", term_str, size_str); - endif - if (nargin > 3 && ischar (opts_str)) - ## Options must go last. - term_str = sprintf ("%s %s", term_str, opts_str); - endif - else - if (nargin > 3 && ischar (opts_str)) - ## Options must go last. - term_str = sprintf ("%s %s", term_str, opts_str); - endif - if (! isempty (size_str) && new_stream) - ## size_str comes after other options to permit specification of - ## the canvas size for terminals cdr/corel. - term_str = sprintf ("%s %s", term_str, size_str); - endif - endif - - ## Work around the gnuplot feature of growing the x11 window and - ## flickering window (x11, windows, & wxt) when the mouse and - ## multiplot are set in gnuplot. - fputs (plot_stream, "unset multiplot;\n"); - flickering_terms = {"x11", "windows", "wxt", "dumb"}; - if (! any (strcmp (term, flickering_terms)) - || have_non_legend_axes (h) - || numel (findall (h, "type", "image")) > 0) - fprintf (plot_stream, "%s\n", term_str); - if (nargin == 5) - if (! isempty (file)) - fprintf (plot_stream, "set output '%s';\n", file); - endif - endif - fputs (plot_stream, "set multiplot;\n"); - elseif (any (strcmp (term, flickering_terms))) - fprintf (plot_stream, "%s\n", term_str); - if (nargin == 5) - if (! isempty (file)) - fprintf (plot_stream, "set output '%s';\n", file); - endif - endif - endif - else - ## gnuplot will pick up the GNUTERM environment variable itself - ## so no need to set the terminal type if not also setting the - ## figure title, enhanced mode, or position. - endif - -endfunction - -function term = gnuplot_default_term () - term = getenv ("GNUTERM"); - ## If not specified, guess the terminal type. - if (isempty (term)) - if (ismac ()) - term = "aqua"; - elseif (! isunix ()) - term = "windows"; - elseif (! isempty (getenv ("DISPLAY"))) - term = "x11"; - else - term = "dumb"; - endif - endif -endfunction - -function [term, opts] = gnuplot_trim_term (string) - ## Extract the terminal type and terminal options (from print.m) - string = deblank (string); - n = strfind (string, ' '); - if (isempty (n)) - term = string; - opts = ""; - else - term = string(1:(n-1)); - opts = string((n+1):end); - endif -endfunction - -function have_enhanced = gnuplot_is_enhanced_term (term) - persistent enhanced_terminals; - if (isempty (enhanced_terminals)) - ## Don't include pstex, pslatex or epslatex here as the TeX commands - ## should not be interpreted in that case. - enhanced_terminals = {"aqua", "canvas", "dumb", "emf", "gif", "jpeg", ... - "pdf", "pdfcairo", "pm", "png", "pngcairo", ... - "postscript", "svg", "windows", "wxt", "x11"}; - endif - if (nargin < 1) - ## Determine the default gnuplot terminal. - term = gnuplot_default_term (); - endif - have_enhanced = any (strncmp (enhanced_terminals, term, min (numel (term), 3))); -endfunction - -function ret = output_to_screen (term) - ret = any (strcmpi ({"aqua", "dumb", "wxt", "x11", "windows", "pm"}, term)); -endfunction - -function retval = have_non_legend_axes (h) - retval = false; - all_axes = findall (h, "type", "axes"); - if (! isempty (all_axes)) - n_all_axes = numel (all_axes); - all_axes_tags = get (all_axes, "tag"); - legend_axes = strcmp (all_axes_tags, "legend"); - if (! isempty (legend_axes)) - n_legend_axes = sum (legend_axes); - retval = (n_all_axes - n_legend_axes) > 1; - endif - endif -endfunction diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/__gnuplot_get_var__.m --- a/scripts/plot/__gnuplot_get_var__.m Sat Jul 16 09:16:52 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,161 +0,0 @@ -## Copyright (C) 2009-2011 Ben Abbott -## -## 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 3 of the License, 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, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {@var{value} =} __gnuplot_get_var__ (@var{h}, @var{name}, @var{fmt}) -## Undocumented internal function. -## @end deftypefn - -## Author: Ben Abbott -## Created: 2009-02-07 - -function gp_var_value = __gnuplot_get_var__ (h, gp_var_name, fmt) - - if (nargin == 0) - h = gcf (); - endif - if (nargin < 2) - print_usage (); - endif - if (nargin < 3) - fmt = ''; - endif - - if (numel (h) == 1 && isfigure (h)) - if (isempty (get (gcf, "__plot_stream__"))) - ostream = __gnuplot_open_stream__ (2, h); - else - ostream = get (h, "__plot_stream__"); - endif - else - ostream = h; - endif - if (numel (ostream) < 1) - error ("__gnuplot_get_var__: stream to gnuplot not open"); - elseif (ispc ()) - if (numel (ostream) == 1) - error ("__gnuplot_get_var__: Need mkfifo that is not implemented under Windows"); - endif - use_mkfifo = false; - istream = ostream(2); - ostream = ostream(1); - else - use_mkfifo = true; - ostream = ostream(1); - endif - - if (use_mkfifo) - gpin_name = tmpnam (); - - ## Mode: 6*8*8 == 0600 - [err, msg] = mkfifo (gpin_name, 6*8*8); - - if (err != 0) - error ("__gnuplot_get_var__: Can not make fifo (%s)", msg); - endif - endif - - gp_var_name = strtrim (gp_var_name); - n = min (strfind (gp_var_name, " "), strfind (gp_var_name, ",")) - 1; - if (isempty (n)) - n = numel (gp_var_name); - endif - - unwind_protect - - ## Notes: Variables may be undefined if user closes gnuplot by "q" - ## or Alt-F4. Further, this abrupt close also requires the leading - ## "\n" on the next line. - if (use_mkfifo) - fprintf (ostream, "\nset print \"%s\";\n", gpin_name); - fflush (ostream); - [gpin, err] = fopen (gpin_name, "r"); - if (err != 0) - ## Try a second time, and then give an error. - [gpin, err] = fopen (gpin_name, "r"); - endif - if (err != 0) - error ("__gnuplot_get_var__: can not open fifo"); - endif - gp_cmd = sprintf ("\nif (exists(\"%s\")) print %s; else print NaN\n", - gp_var_name(1:n), gp_var_name); - fputs (ostream, gp_cmd); - - ## Close output file, to force it to be flushed - fputs (ostream, "set print;\n"); - fflush (ostream); - - ## Now read from fifo. - reading = true; - str = {}; - while (reading) - str{end+1} = fgets (gpin); - if (isnumeric (str{end}) && (str{end} == -1)) - reading = false; - str = str(1:(end-1)); - endif - endwhile - str = strcat (str{:}); - fclose (gpin); - else - ## Direct gnuplot to print to - fprintf (ostream, "set print \"-\";\n"); - fflush (ostream); - gp_cmd = sprintf ("\nif (exists(\"%s\")) print \"OCTAVE: \", %s; else print NaN\n", - gp_var_name(1:n), gp_var_name); - fputs (ostream, gp_cmd); - fflush (ostream); - ## Direct gnuplot to print to - fputs (ostream, "set print;\n"); - fflush (ostream); - - str = {}; - while (isempty (str)) - str = char (fread (istream)'); - if (isempty (str)) - sleep (0.05); - else - str = regexp (str, 'OCTAVE:.*', "match"); - str = str{end}(8:end); - endif - fclear (istream); - endwhile - endif - - ## Strip out EOLs and the continuation character "|" - str(str=="\n") = ""; - str(str=="\r") = ""; - n_continue = strfind (str, " \\ "); - if (! isempty (n_continue)) - str(n_continue+1) = ""; - endif - - if (isempty (fmt)) - gp_var_value = strtrim (str); - else - gp_var_value = sscanf (str, fmt); - endif - - unwind_protect_cleanup - if (use_mkfifo) - unlink (gpin_name); - endif - end_unwind_protect - -endfunction - diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/__gnuplot_ginput__.m --- a/scripts/plot/__gnuplot_ginput__.m Sat Jul 16 09:16:52 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,154 +0,0 @@ -## Copyright (C) 2004-2011 Petr Mikulik -## -## 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 3 of the License, 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, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {[@var{x}, @var{y}, @var{buttons}] =} __gnuplot_ginput__ (@var{f}, @var{n}) -## Undocumented internal function. -## @end deftypefn - -## This is ginput.m implementation for gnuplot and X11. -## It requires gnuplot 4.1 and later. - -## This file initially bore the copyright statement -## Petr Mikulik -## History: June 2006; August 2005; June 2004; April 2004 -## License: public domain - -function [x, y, button] = __gnuplot_ginput__ (f, n) - - ostream = get (f, "__plot_stream__"); - if (numel (ostream) < 1) - error ("ginput: stream to gnuplot not open"); - elseif (ispc ()) - if (numel (ostream) == 1) - error ("ginput: Need mkfifo that is not implemented under Windows"); - endif - use_mkfifo = false; - istream = ostream(2); - ostream = ostream(1); - else - use_mkfifo = true; - ostream = ostream(1); - endif - - if (compare_versions (__gnuplot_version__ (), "4.0", "<=")) - error ("ginput: version %s of gnuplot not supported", gnuplot_version ()); - endif - - if (nargin == 1) - x = zeros (100, 1); - y = zeros (100, 1); - button = zeros (100, 1); - else - x = zeros (n, 1); - y = zeros (n, 1); - button = zeros (n, 1); - endif - - if (use_mkfifo) - gpin_name = tmpnam (); - - ##Mode: 6*8*8 == 0600 - [err, msg] = mkfifo (gpin_name, 6*8*8); - - if (err != 0) - error ("ginput: Can not open fifo (%s)", msg); - endif - endif - - unwind_protect - - k = 0; - while (true) - k++; - - ## Notes: MOUSE_* can be undefined if user closes gnuplot by "q" - ## or Alt-F4. Further, this abrupt close also requires the leading - ## "\n" on the next line. - if (use_mkfifo) - fprintf (ostream, "set print \"%s\";\n", gpin_name); - fflush (ostream); - [gpin, err] = fopen (gpin_name, "r"); - if (err != 0) - error ("ginput: Can not open fifo (%s)", msg); - endif - fputs (ostream, "pause mouse any;\n\n"); - fputs (ostream, "\nif (exists(\"MOUSE_KEY\") && exists(\"MOUSE_X\")) print MOUSE_X, MOUSE_Y, MOUSE_KEY; else print \"0 0 -1\"\n"); - - ## Close output file, to force it to be flushed - fputs (ostream, "set print;\n"); - fflush (ostream); - - ## Now read from fifo. - [x(k), y(k), button(k), count] = fscanf (gpin, "%f %f %d", "C"); - fclose (gpin); - else - fprintf (ostream, "set print \"-\";\n"); - fflush (ostream); - fputs (ostream, "pause mouse any;\n\n"); - fputs (ostream, "\nif (exists(\"MOUSE_KEY\") && exists(\"MOUSE_X\")) print \"OCTAVE: \", MOUSE_X, MOUSE_Y, MOUSE_KEY; else print \"0 0 -1\"\n"); - - ## Close output file, to force it to be flushed - fputs (ostream, "set print;\n"); - fflush (ostream); - - str = {}; - while (isempty (str)) - str = char (fread (istream)'); - if (isempty (str)) - sleep (0.05); - else - str = regexp (str, 'OCTAVE:\s+[-+.\d]+\s+[-+.\d]+\s+\d*', 'match'); - endif - fclear (istream); - endwhile - [x(k), y(k), button(k), count] = sscanf (str{end}(8:end), "%f %f %d", "C"); - endif - - if ([x(k), y(k), button(k)] == [0, 0, -1]) - ## Mousing not active (no plot yet). - break; - endif - - if (nargin > 1) - ## Input argument n was given => stop when k == n. - if (k == n) - break; - endif - else - ## Input argument n not given => stop when hitting a return key. - ## if (button(k) == 0x0D || button(k) == 0x0A) - ## ## hit Return or Enter - if (button(k) == 0x0D) - ## hit Return - x(k:end) = []; - y(k:end) = []; - button(k:end) = []; - break; - endif - endif - endwhile - - unwind_protect_cleanup - if (use_mkfifo) - unlink (gpin_name); - endif - end_unwind_protect - -endfunction - diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/__gnuplot_has_feature__.m --- a/scripts/plot/__gnuplot_has_feature__.m Sat Jul 16 09:16:52 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -## Copyright (C) 2009-2011 Ben Abbott -## -## 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 3 of the License, 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, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {@var{has_feature} =} __gnuplot_has_feature__ (@var{feature}) -## Undocumented internal function. -## @end deftypefn - -## Author: Ben Abbott -## Created: 2009-01-27 - -function res = __gnuplot_has_feature__ (feature) - persistent features has_features - features = {"x11_figure_position", - "wxt_figure_size", - "transparent_patches", - "transparent_surface", - "epslatex_implies_eps_filesuffix", - "epslatexstandalone_terminal", - "screen_coordinates_for_{lrtb}margin", - "variable_GPVAL_TERMINALS", - "key_has_font_properties"}; - - if (isempty (has_features)) - try - gnuplot_version = __gnuplot_version__ (); - catch - ## Don't throw an error if gnuplot isn't installed - gnuplot_version = "0.0.0"; - end_try_catch - versions = {"4.2.5", "4.4", "4.4", "4.4", "4.2", "4.2", "4.4", "4.4", "4.4"}; - operators = {">=", ">=", ">=", ">=", ">=", ">=", ">=", ">=", ">="}; - have_features = logical (zeros (size (features))); - for n = 1 : numel (have_features) - has_features(n) = compare_versions (gnuplot_version, versions{n}, operators{n}); - endfor - endif - - n = find (strcmpi (feature, features)); - if (isempty (n)) - res = NaN; - else - res = has_features(n); - endif -endfunction - diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/__gnuplot_open_stream__.m --- a/scripts/plot/__gnuplot_open_stream__.m Sat Jul 16 09:16:52 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -## Copyright (C) 2009-2011 Ben Abbott -## -## 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 3 of the License, 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, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {@var{stream} =} __gnuplot_open_stream__ (@var{npipes}, @var{h}) -## Undocumented internal function. -## @end deftypefn - -## Author: Ben Abbott -## Created: 2009-04-11 - -function plot_stream = __gnuplot_open_stream__ (npipes, h) - [prog, args] = gnuplot_binary (); - if (npipes > 1) - [plot_stream(1), plot_stream(2), pid] = popen2 (prog, args{:}); - if (pid < 0) - error ("__gnuplot_open_stream__: failed to open connection to gnuplot"); - else - plot_stream(3) = pid; - endif - else - plot_stream = popen (sprintf ("%s ", prog, args{:}), "w"); - if (plot_stream < 0) - error ("__gnuplot_open_stream__: failed to open connection to gnuplot"); - endif - endif - if (nargin > 1) - set (h, "__plot_stream__", plot_stream); - endif -endfunction diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/__gnuplot_print__.m --- a/scripts/plot/__gnuplot_print__.m Sat Jul 16 09:16:52 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,300 +0,0 @@ -## Copyright (C) 1999-2011 Daniel Heiserer -## Copyright (C) 2001 Laurent Mazet -## -## 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 3 of the License, 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, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {} __gnuplot_print__ (@var{@dots{}}) -## Undocumented internal function. -## @end deftypefn - -## Author: Daniel Heiserer -## Adapted-By: jwe - -function opts = __gnuplot_print__ (opts) - - dos_shell = (ispc () && ! isunix ()); - - if (isempty (opts.fontsize)) - ## If no fontsize, determine the nominal axes fontsize. - defaultfontsize = get (0, "defaultaxesfontsize"); - axesfontsize = get (findobj (opts.figure, "type", "axes"), "fontsize"); - if (iscell (axesfontsize)) - axesfontsize = round (median (cell2mat (axesfontsize))); - endif - if (isempty (axesfontsize)) - opts.fontsize = defaultfontsize; - else - opts.fontsize = axesfontsize; - endif - endif - ## The axes-label and tick-label spacing is determined by - ## the font spec given in "set terminal ..." - gp_opts = font_spec (opts); - - pipeline = ""; - - switch (lower (opts.devopt)) - case {"eps", "eps2", "epsc", "epsc2"} - if (any (strcmp (opts.devopt, {"eps", "epsc"}))) - gp_opts = sprintf ("%s level1", gp_opts); - endif - if (opts.tight_flag || ! isempty (opts.preview)) - tmp_file = strcat (tmpnam (), ".eps"); - eps_drawnow (opts, tmp_file, gp_opts); - if (dos_shell) - cleanup = sprintf (" & del %s", strrep (tmp_file, '/', '\')); - else - cleanup = sprintf (" ; rm %s", tmp_file); - endif - pipeline = {sprintf("%s %s", - opts.epstool_cmd (opts, tmp_file, opts.name), - cleanup)}; - else - eps_drawnow (opts, opts.name, gp_opts); - endif - case {"epslatex", "pslatex", "pstex", "epslatexstandalone"} - dot = find (opts.name == ".", 1, "last"); - if ((! isempty (dot)) - && any (strcmpi (opts.name(dot:end), - {".eps", ".ps", ".pdf", ".tex", "."}))) - name = opts.name(1:dot-1); - endif - if (strfind (opts.devopt, "standalone")) - term = sprintf ("%s ", - strrep (opts.devopt, "standalone", " standalone")); - else - term = sprintf ("%s ", opts.devopt); - endif - if (__gnuplot_has_feature__ ("epslatex_implies_eps_filesuffix")) - suffix = "tex"; - else - %% Gnuplot 4.0 wants a ".eps" suffix. - suffix = "eps"; - endif - local_drawnow (sprintf ("%s %s", term, gp_opts), - strcat (name, ".", suffix), opts); - case "tikz" - if (__gnuplot_has_terminal__ ("tikz")) - local_drawnow (sprintf ("lua tikz %s", gp_opts), opts.name, opts); - else - error (sprintf ("print:no%soutput", opts.devopt), - "print.m: '%s' output is not available for gnuplot-%s", - upper (opts.devopt), __gnuplot_version__ ()); - endif - case "svg" - local_drawnow (sprintf ("svg dynamic %s", gp_opts), opts.name, opts); - case {"aifm", "corel", "eepic", "emf", "fig"} - local_drawnow (sprintf ("%s %s", opts.devopt, gp_opts), opts.name, opts); - case {"pdfcairo", "pngcairo"} - if (__gnuplot_has_terminal__ (opts.devopt)) - local_drawnow (sprintf ("%s %s", opts.devopt, gp_opts), opts.name, opts); - else - error (sprintf ("print:no%soutput", opts.devopt), - "print.m: '%s' output is not available for gnuplot-%s", - upper (opts.devopt), __gnuplot_version__ ()); - endif - case {"canvas", "dxf", "hpgl", "mf", "gif", "pstricks", "texdraw"} - local_drawnow (sprintf ("%s %s", opts.devopt, gp_opts), opts.name, opts); - case opts.ghostscript.device - gp_opts = font_spec (opts, "devopt", "eps"); - opts.ghostscript.output = opts.name; - opts.ghostscript.source = strcat (tmpnam (), ".eps"); - eps_drawnow (opts, opts.ghostscript.source, gp_opts); - [cmd_gs, cmd_cleanup] = __ghostscript__ (opts.ghostscript); - if (opts.send_to_printer || isempty (opts.name)) - cmd_lpr = opts.lpr_cmd (opts); - cmd = sprintf ("%s | %s", cmd_gs, cmd_lpr); - else - cmd = sprintf ("%s", cmd_gs); - endif - if (dos_shell) - cmd = sprintf ("%s & del %s", cmd, strrep (opts.ghostscript.source, '/', '\')); - else - cmd = sprintf ("%s ; rm %s", cmd, opts.ghostscript.source); - endif - if (! isempty (cmd_cleanup)) - if (dos_shell) - pipeline = {sprintf("%s & %s", cmd, cmd_cleanup)}; - else - pipeline = {sprintf("%s ; %s", cmd, cmd_cleanup)}; - endif - else - pipeline = {cmd}; - endif - otherwise - error (sprintf ("print:no%soutput", opts.devopt), - "print.m: %s output is not available for the Gnuplot graphics toolkit", - upper (opts.devopt)); - endswitch - - - opts.pipeline = pipeline; - - for n = 1:numel(pipeline) - if (opts.debug) - fprintf ("gnuplot-pipeline: '%s'\n", pipeline{n}); - endif - [status, output] = system (pipeline{n}); - if (status) - fprintf ("%s\n%s\n%s\n", - "---------- output begin ----------", - output, - "----------- output end -----------"); - error ("gnuplot:failedpipe", "print: failed to print"); - endif - endfor - -endfunction - -function eps_drawnow (opts, epsfile, gp_opts) - [h, fontsize] = get_figure_text_objs (opts); - unwind_protect - for n = 1:numel(h) - set (h(n), "fontsize", 2 * fontsize{n}); - endfor - local_drawnow (sprintf ("postscript eps %s", gp_opts), epsfile, opts); - unwind_protect_cleanup - for n = 1:numel(h) - set (h(n), "fontsize", fontsize{n}); - endfor - end_unwind_protect -endfunction - -function local_drawnow (term, file, opts) - if (opts.use_color < 0) - mono = true; - else - mono = false; - endif - figure (opts.figure); - if (isempty (opts.debug_file) || ! opts.debug) - drawnow (term, file, mono); - else - drawnow (term, file, mono, opts.debug_file); - endif -endfunction - -function f = font_spec (opts, varargin) - for n = 1:2:numel(varargin) - opts.(varargin{n}) = varargin{n+1}; - endfor - f = ""; - switch (opts.devopt) - case "cgm" - if (! isempty (opts.font) && ! isempty (opts.fontsize)) - f = sprintf ("font ""%s,%d""", opts.font, opts.fontsize); - elseif (! isempty (opts.font)) - f = sprintf ("font ""%s""", opts.font); - elseif (! isempty (opts.fontsize)) - f = sprintf ("%d", opts.fontsize); - endif - case {"eps", "eps2", "epsc", "epsc2"} - ## Gnuplot renders fonts as half their specification, which - ## results in a tight spacing for the axes-labels and tick-labels. - ## Compensate for the half scale. This will produce the proper - ## spacing for the requested fontsize. - if (! isempty (opts.font) && ! isempty (opts.fontsize)) - f = sprintf ("font ""%s,%d""", opts.font, 2 * opts.fontsize); - elseif (! isempty (opts.font)) - f = sprintf ("font ""%s""", opts.font); - elseif (! isempty (opts.fontsize)) - f = sprintf ("%d", 2 * opts.fontsize); - endif - case "svg" - if (! isempty (opts.font) && ! isempty (opts.fontsize)) - fontsize = round (opts.fontsize * 0.75); - f = sprintf ("fname ""%s"" fsize %d", opts.font, fontsize); - elseif (! isempty (opts.font)) - f = sprintf ("fname ""%s""", opts.font); - elseif (! isempty (opts.fontsize)) - fontsize = round (opts.fontsize * 0.75); - f = sprintf ("%s fsize %d", f, fontsize); - endif - case "pdf" - if (! isempty (opts.font) && ! isempty (opts.fontsize)) - f = sprintf ("font ""%s,%d""", opts.font, opts.fontsize); - elseif (! isempty (opts.font)) - f = sprintf ("font ""%s""", opts.font); - elseif (! isempty (opts.fontsize)) - f = sprintf ("fsize %d", f, opts.fontsize); - endif - case {"pdfcairo", "pngcairo"} - if (! isempty (opts.font)) - f = sprintf ("font ""%s""", opts.font); - endif - case {"epslatex", "epslatexstandalone"} - if (! isempty (opts.font) && ! isempty (opts.fontsize)) - f = sprintf ("font ""%s,%d""", opts.font, opts.fontsize); - elseif (! isempty (opts.font)) - f = sprintf ("font ""%s""", opts.font); - elseif (! isempty (opts.fontsize)) - f = sprintf ("%d", opts.fontsize); - endif - case "pslatex" - if (! isempty (opts.fontsize)) - f = sprintf ("%d", opts.fontsize); - endif - case {"gif", "jpeg", "png"} - if (! isempty (opts.font) && ! isempty (opts.fontsize)) - f = sprintf ("font ""%s ,%d""", opts.font, opts.fontsize); - elseif (! isempty (opts.font)) - f = sprintf ("font ""%s""", opts.font); - elseif (! isempty (opts.fontsize)) - f = sprintf ("font ""%d""", opts.fontsize); - endif - case "emf" - if (! isempty (opts.font) && ! isempty (opts.fontsize)) - f = sprintf ("""%s"" %d", opts.font, opts.fontsize); - elseif (! isempty (opts.font)) - f = sprintf ("""%s""", opts.font); - elseif (! isempty (opts.fontsize)) - f = sprintf ("%d", opts.fontsize); - endif - case "canvas" - if (! isempty (opts.fontsize)) - f = sprintf ("fsize %d", opts.fontsize); - endif - case {"aifm", "corel"} - if (! isempty (opts.font) && ! isempty (opts.fontsize)) - f = sprintf ("%s %d", opts.font, opts.fontsize); - elseif (! isempty (opts.font)) - f = sprintf ("%s", opts.font); - elseif (! isempty (opts.fontsize)) - f = sprintf ("%d", opts.fontsize); - endif - case "fig" - if (! isempty (opts.font) && ! isempty (opts.fontsize)) - f = sprintf ("font %s fontsize %d", opts.font, opts.fontsize); - elseif (! isempty (opts.font)) - f = sprintf ("font %s", opts.font); - elseif (! isempty (opts.fontsize)) - f = sprintf ("fontsize %d", opts.fontsize); - endif - endswitch -endfunction - -function [h, fontsize] = get_figure_text_objs (opts) - h = findall (opts.figure, "-property", "fontsize"); - fontsize = get (h, "fontsize"); - switch (numel (fontsize)) - case 0 - fontsize = {}; - case 1 - fontsize = {fontsize}; - endswitch -endfunction diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/__gnuplot_version__.m --- a/scripts/plot/__gnuplot_version__.m Sat Jul 16 09:16:52 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -## Copyright (C) 2006-2011 Daniel Sebald -## -## 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 3 of the License, 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, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {@var{version} =} __gnuplot_version__ () -## Undocumented internal function. -## @end deftypefn - -## Return the version of gnuplot we are using. Note that we do not -## attempt to handle the case of the user switching to different -## versions of gnuplot during the same session. - -function version = __gnuplot_version__ () - - persistent __version__ = ""; - - if (isempty (__version__)) - [status, output] = system (sprintf ("\"%s\" --version", gnuplot_binary ())); - if (status != 0) - ## This message ends in a newline so that the traceback messages - ## are skipped and people might actually see the message, read it, - ## comprehend it, actually take the advice it gives, and stop - ## asking us why plotting fails when gnuplot is not found. - error ("you must have gnuplot installed to display graphics; if you have gnuplot installed in a non-standard location, see the 'gnuplot_binary' function\n"); - endif - output = strrep (output, "gnuplot", ""); - output = strrep (output, "patchlevel", "."); - output = strrep (output, "\n", ""); - output = strrep (output, "\r", ""); - __version__ = strrep (output, " ", ""); - endif - - version = __version__; - -endfunction - diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/__go_draw_axes__.m --- a/scripts/plot/__go_draw_axes__.m Sat Jul 16 09:16:52 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2456 +0,0 @@ -## Copyright (C) 2005-2011 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 3 of the License, 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, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {} __go_draw_axes__ (@var{h}, @var{plot_stream}, @var{enhanced}, @var{mono}) -## Undocumented internal function. -## @end deftypefn - -## Author: jwe - -function __go_draw_axes__ (h, plot_stream, enhanced, mono, - bg_is_set, fg_is_set, hlgnd) - - if (nargin >= 4 && nargin <= 7) - - showhiddenhandles = get (0, "showhiddenhandles"); - unwind_protect - set (0, "showhiddenhandles", "on"); - axis_obj = __get__ (h); - unwind_protect_cleanup - set (0, "showhiddenhandles", showhiddenhandles); - end_unwind_protect - - parent_figure_obj = get (axis_obj.parent); - gnuplot_term = __gnuplot_get_var__ (axis_obj.parent, "GPVAL_TERM"); - - ## Set to false for plotyy axes. - if (strcmp (axis_obj.tag, "plotyy")) - ymirror = false; - else - ymirror = true; - endif - - nd = __calc_dimensions__ (h); - - if (strcmp (axis_obj.dataaspectratiomode, "manual") - && strcmp (axis_obj.xlimmode, "manual") - && strcmp (axis_obj.ylimmode, "manual")) - ## All can't be "manual" - axis_obj.plotboxaspectratiomode = "auto"; - endif - - if (strcmp (axis_obj.dataaspectratiomode, "manual") - && strcmp (axis_obj.xlimmode, "manual") - && strcmp (axis_obj.ylimmode, "manual") - && (nd == 2 || all (mod (axis_obj.view, 90) == 0))) - ## FIXME - adjust plotboxaspectratio to respect other - fpos = get (axis_obj.parent, "position"); - apos = axis_obj.position; - endif - - pos = __actual_axis_position__ (h); - - if (strcmpi (axis_obj.dataaspectratiomode, "manual")) - dr = axis_obj.dataaspectratio; - if (nd == 2 || all (mod (axis_obj.view, 90) == 0)) - dr = dr(1) / dr(2); - else - ## FIXME - need to properly implement 3D - dr = mean (dr(1:2)) / dr(3); - endif - else - dr = 1; - endif - - if (strcmp (axis_obj.activepositionproperty, "position")) - if (__gnuplot_has_feature__ ("screen_coordinates_for_{lrtb}margin")) - if (nd == 2 || all (mod (axis_obj.view, 90) == 0)) - x = [1, 1]; - else - ## 3D plots need to be sized down to fit in the window. - x = 1.0 ./ sqrt([2, 2.5]); - endif - fprintf (plot_stream, "set tmargin screen %.15g;\n", - pos(2)+pos(4)/2+x(2)*pos(4)/2); - fprintf (plot_stream, "set bmargin screen %.15g;\n", - pos(2)+pos(4)/2-x(2)*pos(4)/2); - fprintf (plot_stream, "set lmargin screen %.15g;\n", - pos(1)+pos(3)/2-x(1)*pos(3)/2); - fprintf (plot_stream, "set rmargin screen %.15g;\n", - pos(1)+pos(3)/2+x(1)*pos(3)/2); - sz_str = ""; - else - fprintf (plot_stream, "set tmargin 0;\n"); - fprintf (plot_stream, "set bmargin 0;\n"); - fprintf (plot_stream, "set lmargin 0;\n"); - fprintf (plot_stream, "set rmargin 0;\n"); - - if (nd == 3 && all (axis_obj.view == [0, 90])) - ## FIXME -- Kludge to allow colorbar to be added to a pcolor() plot - pos(3:4) = pos(3:4) * 1.4; - pos(1:2) = pos(1:2) - pos(3:4) * 0.125; - endif - - fprintf (plot_stream, "set origin %.15g, %.15g;\n", pos(1), pos(2)); - - if (strcmpi (axis_obj.dataaspectratiomode, "manual")) - sz_str = sprintf ("set size ratio %.15g", -dr); - else - sz_str = "set size noratio"; - endif - sz_str = sprintf ("%s %.15g, %.15g;\n", sz_str, pos(3), pos(4)); - endif - else ## activepositionproperty == outerposition - fprintf (plot_stream, "unset tmargin;\n"); - fprintf (plot_stream, "unset bmargin;\n"); - fprintf (plot_stream, "unset lmargin;\n"); - fprintf (plot_stream, "unset rmargin;\n"); - fprintf (plot_stream, "set origin %g, %g;\n", pos(1:2)); - sz_str = ""; - if (strcmpi (axis_obj.dataaspectratiomode, "manual")) - sz_str = sprintf ("ratio %g", -dr); - else - sz_str = "noratio"; - endif - sz_str = sprintf ("set size %s %g, %g;\n", sz_str, pos(3:4)); - endif - if (! isempty (sz_str)) - fputs (plot_stream, sz_str); - endif - - ## Reset all labels, axis-labels, tick-labels, and title - ## FIXME - We should have an function to initialize the axis. - ## Presently, this is dispersed in this function. - fputs (plot_stream, "unset label;\n"); - fputs (plot_stream, "unset xtics;\n"); - fputs (plot_stream, "unset ytics;\n"); - fputs (plot_stream, "unset ztics;\n"); - fputs (plot_stream, "unset x2tics;\n"); - fputs (plot_stream, "unset x2tics;\n"); - - if (! isempty (axis_obj.title)) - t = get (axis_obj.title); - if (isempty (t.string)) - fputs (plot_stream, "unset title;\n"); - else - [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string"); - fontspec = create_fontspec (f, s, gnuplot_term); - fprintf (plot_stream, "set title \"%s\" %s %s;\n", - undo_string_escapes (tt), fontspec, - __do_enhanced_option__ (enhanced, t)); - endif - endif - - if (! isempty (axis_obj.xlabel)) - t = get (axis_obj.xlabel); - angle = t.rotation; - colorspec = get_text_colorspec (axis_obj.xcolor, mono); - if (isempty (t.string)) - fprintf (plot_stream, "unset xlabel;\n"); - fprintf (plot_stream, "unset x2label;\n"); - else - [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string"); - fontspec = create_fontspec (f, s, gnuplot_term); - if (strcmpi (axis_obj.xaxislocation, "top")) - fprintf (plot_stream, "set x2label \"%s\" %s %s %s", - undo_string_escapes (tt), colorspec, fontspec, - __do_enhanced_option__ (enhanced, t)); - else - fprintf (plot_stream, "set xlabel \"%s\" %s %s %s", - undo_string_escapes (tt), colorspec, fontspec, - __do_enhanced_option__ (enhanced, t)); - endif - fprintf (plot_stream, " rotate by %f;\n", angle); - if (strcmpi (axis_obj.xaxislocation, "top")) - fprintf (plot_stream, "unset xlabel;\n"); - else - fprintf (plot_stream, "unset x2label;\n"); - endif - endif - endif - - if (! isempty (axis_obj.ylabel)) - t = get (axis_obj.ylabel); - angle = t.rotation; - colorspec = get_text_colorspec (axis_obj.ycolor, mono); - if (isempty (t.string)) - fprintf (plot_stream, "unset ylabel;\n"); - fprintf (plot_stream, "unset y2label;\n"); - else - [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string"); - fontspec = create_fontspec (f, s, gnuplot_term); - if (strcmpi (axis_obj.yaxislocation, "right")) - fprintf (plot_stream, "set y2label \"%s\" %s %s %s", - undo_string_escapes (tt), colorspec, fontspec, - __do_enhanced_option__ (enhanced, t)); - else - fprintf (plot_stream, "set ylabel \"%s\" %s %s %s", - undo_string_escapes (tt), colorspec, fontspec, - __do_enhanced_option__ (enhanced, t)); - endif - fprintf (plot_stream, " rotate by %f;\n", angle); - if (strcmpi (axis_obj.yaxislocation, "right")) - fprintf (plot_stream, "unset ylabel;\n"); - else - fprintf (plot_stream, "unset y2label;\n"); - endif - endif - endif - - if (! isempty (axis_obj.zlabel)) - t = get (axis_obj.zlabel); - angle = t.rotation; - colorspec = get_text_colorspec (axis_obj.zcolor, mono); - if (isempty (t.string)) - fputs (plot_stream, "unset zlabel;\n"); - else - [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string"); - fontspec = create_fontspec (f, s, gnuplot_term); - fprintf (plot_stream, "set zlabel \"%s\" %s %s %s", - undo_string_escapes (tt), colorspec, fontspec, - __do_enhanced_option__ (enhanced, t)); - fprintf (plot_stream, " rotate by %f;\n", angle); - endif - endif - - if (strcmpi (axis_obj.xaxislocation, "top")) - xaxisloc = "x2"; - xaxisloc_using = "x2"; - else - xaxisloc = "x"; - xaxisloc_using = "x1"; - if (strcmpi (axis_obj.xaxislocation, "zero")) - fputs (plot_stream, "set xzeroaxis;\n"); - endif - endif - if (strcmpi (axis_obj.yaxislocation, "right")) - yaxisloc = "y2"; - yaxisloc_using = "y2"; - else - yaxisloc = "y"; - yaxisloc_using = "y1"; - if (strcmpi (axis_obj.yaxislocation, "zero")) - fputs (plot_stream, "set yzeroaxis;\n"); - endif - endif - - have_grid = false; - - if (strcmpi (axis_obj.xgrid, "on")) - have_grid = true; - fprintf (plot_stream, "set grid %stics;\n", xaxisloc); - else - fprintf (plot_stream, "set grid no%stics;\n", xaxisloc); - endif - - if (strcmpi (axis_obj.ygrid, "on")) - have_grid = true; - fprintf (plot_stream, "set grid %stics;\n", yaxisloc); - else - fprintf (plot_stream, "set grid no%stics;\n", yaxisloc); - endif - - if (strcmpi (axis_obj.zgrid, "on")) - have_grid = true; - fputs (plot_stream, "set grid ztics;\n"); - else - fputs (plot_stream, "set grid noztics;\n"); - endif - - if (strcmpi (axis_obj.xminorgrid, "on")) - have_grid = true; - if (strcmp (axis_obj.xscale, "log")) - m = 10; - else - m = 5; - endif - fprintf (plot_stream, "set m%stics %d;\n", xaxisloc, m); - fprintf (plot_stream, "set grid m%stics;\n", xaxisloc); - else - fprintf (plot_stream, "set grid nom%stics;\n", xaxisloc); - endif - - if (strcmpi (axis_obj.yminorgrid, "on")) - have_grid = true; - if (strcmp (axis_obj.yscale, "log")) - m = 10; - else - m = 5; - endif - fprintf (plot_stream, "set m%stics %d;\n", yaxisloc, m); - fprintf (plot_stream, "set grid m%stics;\n", yaxisloc); - else - fprintf (plot_stream, "set grid nom%stics;\n", yaxisloc); - endif - - if (strcmpi (axis_obj.zminorgrid, "on")) - have_grid = true; - if (strcmp (axis_obj.zscale, "log")) - m = 10; - else - m = 5; - endif - fprintf (plot_stream, "set mztics %d;\n", m); - fputs (plot_stream, "set grid mztics;\n"); - else - fputs (plot_stream, "set grid nomztics;\n"); - endif - - ## The grid front/back/layerdefault option also controls the - ## appearance of tics, so it is used even if the grid is absent. - if (strcmpi (axis_obj.layer, "top")) - fputs (plot_stream, "set grid front;\n"); - fputs (plot_stream, "set border front;\n"); - else - fputs (plot_stream, "set grid layerdefault;\n"); - ## FIXME -- the gnuplot help says that "layerdefault" should work - ## for set border too, but it fails for me with gnuplot 4.2.5. So - ## use "back" instead. - fputs (plot_stream, "set border back;\n"); - endif - - fprintf (plot_stream, "set grid linewidth %f, linewidth %f;\n", - axis_obj.linewidth, axis_obj.linewidth); - - if (! have_grid) - fputs (plot_stream, "unset grid;\n"); - endif - - do_tics (axis_obj, plot_stream, ymirror, mono, gnuplot_term); - - fputs (plot_stream, "unset logscale;\n"); - xlogscale = strcmpi (axis_obj.xscale, "log"); - ylogscale = strcmpi (axis_obj.yscale, "log"); - zlogscale = strcmpi (axis_obj.zscale, "log"); - if (xlogscale) - fprintf (plot_stream, "set logscale %s;\n", xaxisloc); - endif - if (ylogscale) - fprintf (plot_stream, "set logscale %s;\n", yaxisloc); - endif - if (zlogscale) - fputs (plot_stream, "set logscale z;\n"); - endif - - xautoscale = strcmpi (axis_obj.xlimmode, "auto"); - yautoscale = strcmpi (axis_obj.ylimmode, "auto"); - zautoscale = strcmpi (axis_obj.zlimmode, "auto"); - cautoscale = strcmpi (axis_obj.climmode, "auto"); - cdatadirect = false; - truecolor = false; - - fputs (plot_stream, "set clip two;\n"); - - kids = axis_obj.children; - ## Remove the axis labels and title from the children, and - ## preserved the original order. - [jnk, k] = setdiff (kids, [axis_obj.xlabel; axis_obj.ylabel; ... - axis_obj.zlabel; axis_obj.title]); - kids = kids (sort (k)); - - if (nd == 3) - fputs (plot_stream, "set parametric;\n"); - fputs (plot_stream, "set style data lines;\n"); - fputs (plot_stream, "set surface;\n"); - fputs (plot_stream, "unset contour;\n"); - endif - - data_idx = 0; - data = cell (); - is_image_data = []; - hidden_removal = NaN; - view_map = false; - - xlim = axis_obj.xlim; - ylim = axis_obj.ylim; - zlim = axis_obj.zlim; - clim = axis_obj.clim; - - if (! cautoscale && clim(1) == clim(2)) - clim(2)++; - endif - addedcmap = []; - - ximg_data = {}; - ximg_data_idx = 0; - - while (! isempty (kids)) - - obj = get (kids(end)); - if (isfield (obj, "units")) - units = obj.units; - unwind_protect - set (kids(end), "units", "data"); - obj = get (kids(end)); - unwind_protect_cleanup - set (kids(end), "units", units); - end_unwind_protect - endif - kids = kids(1:(end-1)); - - if (strcmpi (obj.visible, "off")) - continue; - endif - - if (xlogscale && isfield (obj, "xdata")) - obj.xdata(obj.xdata<=0) = NaN; - endif - if (ylogscale && isfield (obj, "ydata")) - obj.ydata(obj.ydata<=0) = NaN; - endif - if (zlogscale && isfield (obj, "zdata")) - obj.zdata(obj.zdata<=0) = NaN; - endif - - ## Check for facecolor interpolation for surfaces. - doing_interp_color = ... - isfield (obj, "facecolor") && strncmp (obj.facecolor, "interp", 6); - - switch (obj.type) - case "image" - img_data = obj.cdata; - img_xdata = obj.xdata; - img_ydata = obj.ydata; - - if (ndims (img_data) == 3) - truecolor = true; - elseif (strcmpi (obj.cdatamapping, "direct")) - cdatadirect = true; - endif - data_idx++; - is_image_data(data_idx) = true; - parametric(data_idx) = false; - have_cdata(data_idx) = false; - have_3d_patch(data_idx) = false; - - if (img_xdata(2) < img_xdata(1)) - img_xdata = img_xdata(2:-1:1); - img_data = img_data(:,end:-1:1,:); - elseif (img_xdata(1) == img_xdata(2)) - img_xdata = img_xdata(1) + [0, size(img_data,2)-1]; - endif - if (img_ydata(2) < img_ydata(1)) - img_ydata = img_ydata(2:-1:1); - img_data = img_data(end:-1:1,:,:); - elseif (img_ydata(1) == img_ydata(2)) - img_ydata = img_ydata(1) + [0, size(img_data,1)-1]; - endif - - [y_dim, x_dim] = size (img_data(:,:,1)); - if (x_dim > 1) - dx = abs (img_xdata(2)-img_xdata(1))/(x_dim-1); - else - x_dim = 2; - img_data = [img_data, img_data]; - dx = abs (img_xdata(2)-img_xdata(1)); - endif - if (y_dim > 1) - dy = abs (img_ydata(2)-img_ydata(1))/(y_dim-1); - else - y_dim = 2; - img_data = [img_data; img_data]; - dy = abs (img_ydata(2)-img_ydata(1)); - endif - - x_origin = min (img_xdata); - y_origin = min (img_ydata); - - if (ndims (img_data) == 3) - data{data_idx} = permute (img_data, [3, 1, 2])(:); - format = "1:2:3"; - imagetype = "rgbimage"; - else - data{data_idx} = img_data(:); - format = "1"; - imagetype = "image"; - endif - - titlespec{data_idx} = "title \"\""; - usingclause{data_idx} = sprintf ("binary array=%dx%d scan=yx origin=(%.15g,%.15g) dx=%.15g dy=%.15g using %s", - x_dim, y_dim, x_origin, y_origin, dx, dy, format); - withclause{data_idx} = sprintf ("with %s;", imagetype); - - case "line" - if (strncmp (obj.linestyle, "none", 4) - && (! isfield (obj, "marker") - || (isfield (obj, "marker") - && strncmp (obj.marker, "none", 4)))) - continue; - endif - data_idx++; - is_image_data(data_idx) = false; - parametric(data_idx) = true; - have_cdata(data_idx) = false; - have_3d_patch(data_idx) = false; - if (isempty (obj.displayname)) - titlespec{data_idx} = "title \"\""; - else - tmp = undo_string_escapes (__maybe_munge_text__ (enhanced, obj, "displayname")); - titlespec{data_idx} = cstrcat ("title \"", tmp, "\""); - endif - usingclause{data_idx} = sprintf ("record=%d", numel (obj.xdata)); - errbars = ""; - if (nd == 3) - xdat = obj.xdata(:); - ydat = obj.ydata(:); - if (! isempty (obj.zdata)) - zdat = obj.zdata(:); - else - zdat = zeros (size (xdat)); - endif - data{data_idx} = [xdat, ydat, zdat]'; - usingclause{data_idx} = sprintf ("record=%d using ($1):($2):($3)", numel (xdat)); - ## fputs (plot_stream, "set parametric;\n"); - else - xdat = obj.xdata(:); - ydat = obj.ydata(:); - data{data_idx} = [xdat, ydat]'; - usingclause{data_idx} = sprintf ("record=%d using ($1):($2) axes %s%s", - rows(xdat), xaxisloc_using, yaxisloc_using); - endif - - style = do_linestyle_command (obj, obj.color, data_idx, mono, - plot_stream, errbars); - - withclause{data_idx} = sprintf ("with %s linestyle %d", - style{1}, data_idx); - - if (length (style) > 1) - data_idx++; - is_image_data(data_idx) = is_image_data(data_idx - 1); - parametric(data_idx) = parametric(data_idx - 1); - have_cdata(data_idx) = have_cdata(data_idx - 1); - have_3d_patch(data_idx) = have_3d_patch(data_idx - 1); - titlespec{data_idx} = "title \"\""; - usingclause{data_idx} = usingclause{data_idx - 1}; - data{data_idx} = data{data_idx - 1}; - withclause{data_idx} = sprintf ("with %s linestyle %d", - style{2}, data_idx); - endif - if (length (style) > 2) - data_idx++; - is_image_data(data_idx) = is_image_data(data_idx - 1); - parametric(data_idx) = parametric(data_idx - 1); - have_cdata(data_idx) = have_cdata(data_idx - 1); - have_3d_patch(data_idx) = have_3d_patch(data_idx - 1); - titlespec{data_idx} = "title \"\""; - usingclause{data_idx} = usingclause{data_idx - 1}; - data{data_idx} = data{data_idx - 1}; - withclause{data_idx} = sprintf ("with %s linestyle %d", - style{3}, data_idx); - endif - - case "patch" - cmap = parent_figure_obj.colormap; - [nr, nc] = size (obj.xdata); - - if (! isempty (obj.cdata)) - cdat = obj.cdata; - if (strcmpi (obj.cdatamapping, "direct")) - cdatadirect = true; - endif - else - cdat = []; - endif - - data_3d_idx = NaN; - for i = 1:nc - xcol = obj.xdata(:,i); - ycol = obj.ydata(:,i); - if (nd == 3) - if (! isempty (obj.zdata)) - zcol = obj.zdata(:,i); - else - zcol = zeros (size (xcol)); - endif - endif - - if (! isnan (xcol) && ! isnan (ycol)) - ## Is the patch closed or not - if (strncmp (obj.facecolor, "none", 4)) - hidden_removal = false; - else - - if (isnan (hidden_removal)) - hidden_removal = true; - endif - if (nd == 3) - if (numel (xcol) > 3) - error ("__go_draw_axes__: gnuplot (as of v4.2) only supports 3D filled triangular patches"); - else - if (isnan (data_3d_idx)) - data_idx++; - data_3d_idx = data_idx; - is_image_data(data_idx) = false; - parametric(data_idx) = false; - have_cdata(data_idx) = true; - have_3d_patch(data_idx) = true; - withclause{data_3d_idx} = sprintf ("with pm3d"); - usingclause{data_3d_idx} = "using 1:2:3:4"; - data{data_3d_idx} = []; - endif - local_idx = data_3d_idx; - ccdat = NaN; - endif - else - data_idx++; - local_idx = data_idx; - is_image_data(data_idx) = false; - parametric(data_idx) = false; - have_cdata(data_idx) = false; - have_3d_patch(data_idx) = false; - endif - - if (i > 1 || isempty (obj.displayname)) - titlespec{local_idx} = "title \"\""; - else - tmp = undo_string_escapes (__maybe_munge_text__ (enhanced, obj, "displayname")); - titlespec{local_idx} = cstrcat ("title \"", tmp, "\""); - endif - if (isfield (obj, "facecolor")) - if ((strncmp (obj.facecolor, "flat", 4) - || strncmp (obj.facecolor, "interp", 6)) - && isfield (obj, "cdata")) - if (ndims (obj.cdata) == 2 - && (size (obj.cdata, 2) == nc - && (size (obj.cdata, 1) == 1 - || size (obj.cdata, 1) == 3))) - ccol = cdat (:, i); - elseif (ndims (obj.cdata) == 2 - && (size (obj.cdata, 1) == nc - && (size (obj.cdata, 2) == 1 - || size (obj.cdata, 2) == 3))) - ccol = cdat (i, :); - elseif (ndims (obj.cdata) == 3) - ccol = permute (cdat (:, i, :), [1, 3, 2]); - else - ccol = cdat; - endif - if (strncmp (obj.facecolor, "flat", 4)) - if (numel(ccol) == 3) - color = ccol; - elseif (nd == 3 && numel (xcol) == 3) - ccdat = ccol * ones (3,1); - else - r = 1 + round ((size (cmap, 1) - 1) - * (ccol - clim(1))/(clim(2) - clim(1))); - r = max (1, min (r, size (cmap, 1))); - color = cmap(r, :); - endif - elseif (strncmp (obj.facecolor, "interp", 6)) - if (nd == 3 && numel (xcol) == 3) - ccdat = ccol; - if (! isvector (ccdat)) - tmp = rows(cmap) + rows(addedcmap) + ... - [1 : rows(ccdat)]; - addedcmap = [addedcmap; ccdat]; - ccdat = tmp(:); - else - ccdat = ccdat(:); - endif - else - warning ("\"interp\" not supported, using 1st entry of cdata"); - r = 1 + round ((size (cmap, 1) - 1) * ccol(1)); - r = max (1, min (r, size (cmap, 1))); - color = cmap(r,:); - endif - endif - elseif (isnumeric (obj.facecolor)) - color = obj.facecolor; - else - color = [0, 1, 0]; - endif - else - color = [0, 1, 0]; - endif - - if (nd == 3 && numel (xcol) == 3) - if (isnan (ccdat)) - ccdat = (rows (cmap) + rows(addedcmap) + 1) * ones(3, 1); - addedcmap = [addedcmap; reshape(color, 1, 3)]; - endif - data{data_3d_idx} = [data{data_3d_idx}, ... - [[xcol; xcol(end)], [ycol; ycol(end)], ... - [zcol; zcol(end)], [ccdat; ccdat(end)]]']; - else - if (mono) - colorspec = ""; - elseif (__gnuplot_has_feature__ ("transparent_patches") - && isscalar (obj.facealpha)) - colorspec = sprintf ("lc rgb \"#%02x%02x%02x\" fillstyle transparent solid %f", - round (255*color), obj.facealpha); - else - colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"", - round (255*color)); - endif - - withclause{data_idx} = sprintf ("with filledcurve %s", - colorspec); - data{data_idx} = [xcol, ycol]'; - usingclause{data_idx} = sprintf ("record=%d using ($1):($2)", - numel (xcol)); - endif - endif - endif - - ## patch outline - if (!(strncmp (obj.edgecolor, "none", 4) - && (strncmp (obj.marker, "none", 4) - || (strncmp (obj.markeredgecolor, "none", 4) - && strncmp (obj.markerfacecolor, "none", 4))))) - - data_idx++; - is_image_data(data_idx) = false; - parametric(data_idx) = false; - have_cdata(data_idx) = false; - have_3d_patch(data_idx) = false; - titlespec{data_idx} = "title \"\""; - usingclause{data_idx} = sprintf ("record=%d", numel (obj.xdata)); - - if (isfield (obj, "markersize")) - mdat = obj.markersize / 3; - endif - - if (isfield (obj, "edgecolor")) - ## FIXME - ## This is the wrong thing to do as edgecolor, markeredgecolor - ## and markerfacecolor can have different values and we should - ## treat them seperately. However, the below allow the scatter - ## functions to work as expected, where only one of these values - ## is set - if (strncmp (obj.edgecolor, "none", 4)) - if (strncmp (obj.markeredgecolor, "none", 4)) - ec = obj.markerfacecolor; - else - ec = obj.markeredgecolor; - endif - else - ec = obj.edgecolor; - endif - - if ((strncmp (ec, "flat", 4) - || strncmp (ec, "interp", 6)) - && isfield (obj, "cdata")) - if (ndims (obj.cdata) == 2 - && (size (obj.cdata, 2) == nc - && (size (obj.cdata, 1) == 1 - || size (obj.cdata, 1) == 3))) - ccol = cdat (:, i); - elseif (ndims (obj.cdata) == 2 - && (size (obj.cdata, 1) == nc - && (size (obj.cdata, 2) == 1 - || size (obj.cdata, 2) == 3))) - ccol = cdat (i, :); - elseif (ndims (obj.cdata) == 3) - ccol = permute (cdat (:, i, :), [1, 3, 2]); - else - ccol = cdat; - endif - if (strncmp (ec, "flat", 4)) - if (numel(ccol) == 3) - color = ccol; - else - if (isscalar (ccol)) - ccol = repmat(ccol, numel (xcol), 1); - endif - color = "flat"; - have_cdata(data_idx) = true; - endif - elseif (strncmp (ec, "interp", 6)) - if (numel(ccol) == 3) - warning ("\"interp\" not supported, using 1st entry of cdata"); - color = ccol(1,:); - else - if (isscalar (ccol)) - ccol = repmat(ccol, numel (xcol), 1); - endif - color = "interp"; - have_cdata(data_idx) = true; - endif - endif - elseif (isnumeric (ec)) - color = ec; - else - color = [0, 0, 0]; - endif - else - color = [0, 0, 0]; - endif - - if (isfield (obj, "linestyle")) - switch (obj.linestyle) - case "-" - lt = "lt 1"; - case "--" - lt = "lt 2"; - case ":" - lt = "lt 3"; - case "-." - lt = "lt 6"; - case "none" - lt = ""; - otherwise - lt = ""; - endswitch - else - lt = ""; - endif - - if (isfield (obj, "linewidth")) - lw = sprintf("linewidth %f", obj.linewidth); - else - lw = ""; - endif - - [pt, pt2, obj] = gnuplot_pointtype (obj); - if (! isempty (pt)) - pt = sprintf ("pointtype %s", pt); - endif - if (! isempty (pt2)) - pt2 = sprintf ("pointtype %s", pt2); - endif - - if (mono) - colorspec = ""; - else - if (ischar (color)) - colorspec = "palette"; - else - colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"", - round (255*color)); - endif - endif - - sidx = 1; - if (isempty (lt)) - style = ""; - else - style = "lines"; - endif - tmpwith = {}; - - facesame = true; - if (! isequal (pt, pt2) && isfield (obj, "markerfacecolor") - && !strncmp (obj.markerfacecolor, "none", 4)) - if (strncmp (obj.markerfacecolor, "auto", 4) - || ! isnumeric (obj.markerfacecolor) - || (isnumeric (obj.markerfacecolor) - && isequal (color, obj.markerfacecolor))) - style = strcat (style, "points"); - if (isfield (obj, "markersize")) - if (length (mdat) == nc) - m = mdat(i); - else - m = mdat; - endif - ps = sprintf("pointsize %f", m / 3); - else - ps = ""; - endif - - tmpwith{sidx} = sprintf ("with %s %s %s %s %s %s", - style, lw, pt2, lt, ps, - colorspec); - else - facesame = false; - if (! isempty (style)) - tmpwith{sidx} = sprintf ("with %s %s %s %s", - style, lw, lt, - colorspec); - sidx ++; - endif - if (isnumeric (obj.markerfacecolor) && ! mono) - colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"", - round (255*obj.markerfacecolor)); - endif - style = "points"; - if (isfield (obj, "markersize")) - if (length (mdat) == nc) - m = mdat(i); - else - m = mdat; - endif - ps = sprintf("pointsize %f", m / 3); - else - ps = ""; - endif - tmpwith{sidx} = sprintf ("with %s %s %s %s %s %s", - style, lw, pt2, lt, ps, - colorspec); - endif - endif - - if (isfield (obj, "markeredgecolor") - && !strncmp (obj.markeredgecolor, "none", 4)) - if (facesame && !isempty (pt) - && (strncmp (obj.markeredgecolor, "auto", 4) - || ! isnumeric (obj.markeredgecolor) - || (isnumeric (obj.markeredgecolor) - && isequal (color, obj.markeredgecolor)))) - if (sidx == 1 && ((length (style) == 5 - && strncmp (style, "lines", 5)) - || isempty (style))) - style = strcat (style, "points"); - if (isfield (obj, "markersize")) - if (length (mdat) == nc) - m = mdat(i); - else - m = mdat; - endif - ps = sprintf("pointsize %f", m / 3); - else - ps = ""; - endif - tmpwith{sidx} = sprintf ("with %s %s %s %s %s %s", - style, lw, pt, lt, ps, - colorspec); - endif - else - if (!isempty (style)) - if (length(tmpwith) < sidx || isempty (tmpwith{sidx})) - tmpwith{sidx} = sprintf ("with %s %s %s %s", - style, lw, lt, - colorspec); - endif - sidx ++; - endif - - if (!isempty (pt)) - if (! mono) - if (strncmp (obj.markeredgecolor, "auto", 4)) - colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"", - round (255*color)); - elseif (isnumeric (obj.markeredgecolor) && ! mono) - colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"", - round (255*obj.markeredgecolor)); - endif - endif - style = "points"; - if (isfield (obj, "markersize")) - if (length (mdat) == nc) - m = mdat(i); - else - m = mdat; - endif - ps = sprintf("pointsize %f", m / 3); - else - ps = ""; - endif - tmpwith{sidx} = sprintf ("with %s %s %s %s %s %s", - style, lw, pt, lt, ps, - colorspec); - endif - endif - endif - - if (isempty (tmpwith)) - withclause{data_idx} = sprintf ("with %s %s %s %s %s", - style, lw, pt, lt, - colorspec); - else - withclause{data_idx} = tmpwith{1}; - endif - if (nd == 3) - if (ischar (color)) - if (! isnan (xcol) && ! isnan (ycol) && ! isnan (zcol)) - data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)], ... - [zcol; zcol(1)], [ccol; ccol(1)]]'; - else - data{data_idx} = [xcol, ycol, zcol, ccol]'; - endif - usingclause{data_idx} = sprintf ("record=%d using ($1):($2):($3):($4)", columns (data{data_idx})); - else - if (! isnan (xcol) && ! isnan (ycol) && ! isnan (zcol)) - data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)], ... - [zcol; zcol(1)]]'; - else - data{data_idx} = [xcol, ycol, zcol]'; - endif - usingclause{data_idx} = sprintf ("record=%d using ($1):($2):($3)", columns (data{data_idx})); - endif - else - if (ischar (color)) - if (! isnan (xcol) && ! isnan (ycol)) - data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)], ... - [ccol; ccol(1)]]'; - else - data{data_idx} = [xcol, ycol, ccol]'; - endif - usingclause{data_idx} = sprintf ("record=%d using ($1):($2):($3)", columns (data{data_idx})); - else - if (! isnan (xcol) && ! isnan (ycol)) - data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)]]'; - else - data{data_idx} = [xcol, ycol]'; - endif - usingclause{data_idx} = sprintf ("record=%d using ($1):($2)", columns (data{data_idx})); - endif - endif - - if (length (tmpwith) > 1) - data_idx++; - is_image_data(data_idx) = is_image_data(data_idx - 1); - parametric(data_idx) = parametric(data_idx - 1); - have_cdata(data_idx) = have_cdata(data_idx - 1); - have_3d_patch(data_idx) = have_3d_patch(data_idx - 1); - titlespec{data_idx} = "title \"\""; - usingclause{data_idx} = usingclause{data_idx - 1}; - data{data_idx} = data{data_idx - 1}; - withclause{data_idx} = tmpwith{2}; - endif - if (length (tmpwith) > 2) - data_idx++; - is_image_data(data_idx) = is_image_data(data_idx - 1); - parametric(data_idx) = parametric(data_idx - 1); - have_cdata(data_idx) = have_cdata(data_idx - 1); - have_3d_patch(data_idx) = have_3d_patch(data_idx - 1); - titlespec{data_idx} = "title \"\""; - usingclause{data_idx} = usingclause{data_idx - 1}; - data{data_idx} = data{data_idx - 1}; - withclause{data_idx} = tmpwith{3}; - endif - endif - endfor - - case "surface" - view_map = true; - if (! (strncmp (obj.edgecolor, "none", 4) - && strncmp (obj.facecolor, "none", 4))) - data_idx++; - is_image_data(data_idx) = false; - parametric(data_idx) = false; - have_cdata(data_idx) = true; - have_3d_patch(data_idx) = false; - style = do_linestyle_command (obj, obj.edgecolor, - data_idx, mono, - plot_stream); - - if (isempty (obj.displayname)) - titlespec{data_idx} = "title \"\""; - else - tmp = undo_string_escapes (__maybe_munge_text__ (enhanced, obj, "displayname")); - titlespec{data_idx} = cstrcat ("title \"", tmp, "\""); - endif - withclause{data_idx} = sprintf ("with pm3d linestyle %d", - data_idx); - withpm3d = true; - pm3didx = data_idx; - - xdat = obj.xdata; - ydat = obj.ydata; - zdat = obj.zdata; - cdat = obj.cdata; - - err = false; - if (! size_equal(zdat, cdat)) - err = true; - endif - if (isvector (xdat) && isvector (ydat) && ismatrix (zdat)) - if (rows (zdat) == length (ydat) - && columns (zdat) == length (xdat)) - [xdat, ydat] = meshgrid (xdat, ydat); - else - err = true; - endif - elseif (ismatrix (xdat) && ismatrix (ydat) && ismatrix (zdat)) - if (! size_equal (xdat, ydat, zdat)) - err = true; - endif - else - err = true; - endif - if (err) - error ("__go_draw_axes__: invalid grid data"); - endif - xlen = columns (zdat); - ylen = rows (zdat); - if (xlen == columns (xdat) && xlen == columns (ydat) - && ylen == rows (xdat) && ylen == rows (ydat)) - len = 4 * xlen; - zz = zeros (ylen, len); - k = 1; - for kk = 1:4:len - zz(:,kk) = xdat(:,k); - zz(:,kk+1) = ydat(:,k); - zz(:,kk+2) = zdat(:,k); - zz(:,kk+3) = cdat(:,k); - k++; - endfor - data{data_idx} = zz.'; - endif - - if (doing_interp_color) - interp_str = "interpolate 0, 0"; - else - ## No interpolation of facecolors. - interp_str = ""; - endif - usingclause{data_idx} = sprintf ("record=%dx%d using ($1):($2):($3):($4)", ylen, xlen); - - flat_interp_face = (strncmp (obj.facecolor, "flat", 4) - || strncmp (obj.facecolor, "interp", 6)); - flat_interp_edge = (strncmp (obj.edgecolor, "flat", 4) - || strncmp (obj.edgecolor, "interp", 6)); - - facecolor_none_or_white = (strncmp (obj.facecolor, "none", 4) - || (isnumeric (obj.facecolor) - && all (obj.facecolor == 1))); - hidden_removal = false; - fputs (plot_stream, "set style increment default;\n"); - if (flat_interp_edge && facecolor_none_or_white) - withpm3d = false; - withclause{data_idx} = sprintf ("with %s palette", style {1}); - fputs (plot_stream, "unset pm3d\n"); - if (all (obj.facecolor == 1)) - hidden_removal = true; - endif - elseif (facecolor_none_or_white) - if (all (obj.facecolor == 1)) - hidden_removal = true; - endif - fputs(plot_stream,"unset pm3d;\n"); - fputs(plot_stream,"set style increment user;\n"); - withpm3d = false; - withclause{data_idx} = sprintf("with %s linestyle %d", - style{1}, data_idx); - fputs (plot_stream, "unset pm3d\n"); - endif - - if (doing_interp_color) - ## "depthorder" interferes with interpolation of colors. - dord = "scansautomatic"; - else - dord = "depthorder"; - endif - - if (flat_interp_face && strncmp (obj.edgecolor, "flat", 4)) - fprintf (plot_stream, "set pm3d explicit at s %s %s corners2color c3;\n", - interp_str, dord); - elseif (!facecolor_none_or_white) - if (strncmp (obj.edgecolor, "none", 4)) - if (__gnuplot_has_feature__ ("transparent_surface") - && isscalar (obj.facealpha)) - fprintf (plot_stream, - "set style fill transparent solid %f;\n", - obj.facealpha); - endif - fprintf (plot_stream, "set pm3d explicit at s %s corners2color c3;\n", - interp_str, dord); - else - fprintf (plot_stream, "set pm3d explicit at s hidden3d %d %s %s corners2color c3;\n", - data_idx, interp_str, dord); - - if (__gnuplot_has_feature__ ("transparent_surface") - && isscalar (obj.facealpha)) - fprintf (plot_stream, - "set style fill transparent solid %f;\n", - obj.facealpha); - endif - endif - endif - - zz = []; - if (length (style) > 1) - len = 3 * xlen; - zz = zeros (ylen, len); - k = 1; - for kk = 1:3:len - zz(:,kk) = xdat(:,k); - zz(:,kk+1) = ydat(:,k); - zz(:,kk+2) = zdat(:,k); - k++; - endfor - zz = zz.'; - - data_idx++; - is_image_data(data_idx) = is_image_data(data_idx - 1); - parametric(data_idx) = parametric(data_idx - 1); - have_cdata(data_idx) = false; - have_3d_patch(data_idx) = have_3d_patch(data_idx - 1); - titlespec{data_idx} = "title \"\""; - usingclause{data_idx} = sprintf ("record=%dx%d using ($1):($2):($3)", ylen, xlen); - data{data_idx} = zz; - withclause{data_idx} = sprintf ("with %s linestyle %d", - style{2}, data_idx); - - endif - if (length (style) > 2) - data_idx++; - is_image_data(data_idx) = is_image_data(data_idx - 1); - parametric(data_idx) = parametric(data_idx - 1); - have_cdata(data_idx) = false; - have_3d_patch(data_idx) = have_3d_patch(data_idx - 1); - titlespec{data_idx} = "title \"\""; - usingclause{data_idx} = sprintf ("record=%dx%d using ($1):($2):($3)", ylen, xlen); - data{data_idx} = zz; - withclause{data_idx} = sprintf ("with %s linestyle %d", - style{3}, data_idx); - endif - if (withpm3d && strncmp (style {1}, "linespoints", 11)) - if (isempty(zz)) - len = 3 * xlen; - zz = zeros (ylen, len); - k = 1; - for kk = 1:3:len - zz(:,kk) = xdat(:,k); - zz(:,kk+1) = ydat(:,k); - zz(:,kk+2) = zdat(:,k); - k++; - endfor - zz = zz.'; - endif - data_idx++; - is_image_data(data_idx) = is_image_data(data_idx - 1); - parametric(data_idx) = parametric(data_idx - 1); - have_cdata(data_idx) = false; - have_3d_patch(data_idx) = have_3d_patch(data_idx - 1); - titlespec{data_idx} = "title \"\""; - usingclause{data_idx} = sprintf ("record=%dx%d using ($1):($2):($3)", ylen, xlen); - data{data_idx} = zz; - withclause{data_idx} = sprintf ("with points linestyle %d", - pm3didx); - endif - endif - - case "text" - [label, f, s] = __maybe_munge_text__ (enhanced, obj, "string"); - fontspec = create_fontspec (f, s, gnuplot_term); - lpos = obj.position; - halign = obj.horizontalalignment; - valign = obj.verticalalignment; - angle = obj.rotation; - units = obj.units; - color = obj.color; - if (strcmpi (units, "normalized")) - units = "graph"; - elseif (strcmp (axis_obj.yaxislocation, "right") - && strcmp (units, "data")) - units = "second"; - else - units = ""; - endif - - if (isnumeric (color)) - colorspec = get_text_colorspec (color, mono); - endif - - switch valign - ## Text offset in characters. This relies on gnuplot for font metrics. - case "top" - dy = -0.5; - case "cap" - dy = -0.5; - case "middle" - dy = 0; - case "baseline" - dy = 0.5; - case "bottom" - dy = 0.5; - endswitch - ## Gnuplot's Character units are different for x/y and vary with fontsize. The aspect ratio - ## of 1:1.7 was determined by experiment to work for eps/ps/etc. For the MacOS aqua terminal - ## a value of 2.5 is needed. However, the difference is barely noticable. - dx_and_dy = [(-dy * sind (angle)), (dy * cosd(angle))] .* [1.7 1]; - - if (nd == 3) - ## This produces the desired vertical alignment in 3D. - fprintf (plot_stream, - "set label \"%s\" at %s %.15e,%.15e,%.15e %s rotate by %f offset character %f,%f %s %s front %s;\n", - undo_string_escapes (label), units, lpos(1), - lpos(2), lpos(3), halign, angle, dx_and_dy, fontspec, - __do_enhanced_option__ (enhanced, obj), colorspec); - else - fprintf (plot_stream, - "set label \"%s\" at %s %.15e,%.15e %s rotate by %f offset character %f,%f %s %s front %s;\n", - undo_string_escapes (label), units, - lpos(1), lpos(2), halign, angle, dx_and_dy, fontspec, - __do_enhanced_option__ (enhanced, obj), colorspec); - endif - - case "hggroup" - ## Push group children into the kid list. - if (isempty (kids)) - kids = obj.children; - elseif (! isempty (obj.children)) - kids = [kids; obj.children]; - endif - - otherwise - error ("__go_draw_axes__: unknown object class, %s", - obj.type); - endswitch - - endwhile - - ## This is need to prevent warnings for rotations in 3D plots, while - ## allowing colorbars with contours. - if (nd == 2 || (data_idx > 1 && !view_map)) - fputs (plot_stream, "set pm3d implicit;\n"); - else - fputs (plot_stream, "set pm3d explicit;\n"); - endif - - if (isnan(hidden_removal) || hidden_removal) - fputs (plot_stream, "set hidden3d;\n"); - else - fputs (plot_stream, "unset hidden3d;\n"); - endif - - have_data = (! (isempty (data) || all (cellfun (@isempty, data)))); - - ## Note we don't use the [xy]2range of gnuplot as we don't use the - ## dual axis plotting features of gnuplot. - if (isempty (xlim)) - return; - endif - if (strcmpi (axis_obj.xdir, "reverse")) - xdir = "reverse"; - else - xdir = "noreverse"; - endif - fprintf (plot_stream, "set xrange [%.15e:%.15e] %s;\n", xlim, xdir); - if (strcmpi (axis_obj.xaxislocation, "top")) - fprintf (plot_stream, "set x2range [%.15e:%.15e] %s;\n", xlim, xdir); - endif - - if (isempty (ylim)) - return; - endif - if (strcmpi (axis_obj.ydir, "reverse")) - ydir = "reverse"; - else - ydir = "noreverse"; - endif - fprintf (plot_stream, "set yrange [%.15e:%.15e] %s;\n", ylim, ydir); - if (strcmpi (axis_obj.yaxislocation, "right")) - fprintf (plot_stream, "set y2range [%.15e:%.15e] %s;\n", ylim, ydir); - endif - - if (nd == 3) - if (isempty (zlim)) - return; - endif - if (strcmpi (axis_obj.zdir, "reverse")) - zdir = "reverse"; - else - zdir = "noreverse"; - endif - fprintf (plot_stream, "set zrange [%.15e:%.15e] %s;\n", zlim, zdir); - endif - - cmap = parent_figure_obj.colormap; - cmap_sz = rows(cmap); - if (! any (isinf (clim))) - if (truecolor || ! cdatadirect) - if (rows(addedcmap) > 0) - for i = 1:data_idx - if (have_3d_patch(i)) - data{i}(end,:) = clim(2) * (data{i}(end, :) - 0.5) / cmap_sz; - endif - endfor - fprintf (plot_stream, "set cbrange [%g:%g];\n", clim(1), clim(2) * - (cmap_sz + rows(addedcmap)) / cmap_sz); - else - fprintf (plot_stream, "set cbrange [%g:%g];\n", clim); - endif - else - fprintf (plot_stream, "set cbrange [1:%d];\n", cmap_sz + - rows (addedcmap)); - endif - endif - - if (strcmpi (axis_obj.box, "on")) - if (nd == 3) - fputs (plot_stream, "set border 4095;\n"); - else - fputs (plot_stream, "set border 431;\n"); - endif - else - if (nd == 3) - fputs (plot_stream, "set border 895;\n"); - elseif (! isempty (axis_obj.ytick)) - if (strcmpi (axis_obj.yaxislocation, "right")) - fprintf (plot_stream, "unset ytics; set y2tics %s nomirror\n", - axis_obj.tickdir); - if (strcmpi (axis_obj.xaxislocation, "top")) - fprintf (plot_stream, "unset xtics; set x2tics %s nomirror\n", - axis_obj.tickdir); - fputs (plot_stream, "set border 12;\n"); - else - fprintf (plot_stream, "unset x2tics; set xtics %s nomirror\n", - axis_obj.tickdir); - fputs (plot_stream, "set border 9;\n"); - endif - else - fprintf (plot_stream, "unset y2tics; set ytics %s nomirror\n", - axis_obj.tickdir); - if (strcmpi (axis_obj.xaxislocation, "top")) - fprintf (plot_stream, "unset xtics; set x2tics %s nomirror\n", - axis_obj.tickdir); - fputs (plot_stream, "set border 6;\n"); - else - fprintf (plot_stream, "unset x2tics; set xtics %s nomirror\n", - axis_obj.tickdir); - fputs (plot_stream, "set border 3;\n"); - endif - endif - endif - endif - - if (strcmpi (axis_obj.visible, "off")) - fputs (plot_stream, "unset border; unset tics\n"); - else - fprintf (plot_stream, "set border lw %f;\n", axis_obj.linewidth); - endif - - if (! isempty (hlgnd) && ! isempty (hlgnd.children) - && any (strcmpi (get (hlgnd.children, "visible"), "on"))) - if (strcmpi (hlgnd.box, "on")) - box = "box"; - else - box = "nobox"; - endif - if (strcmpi (hlgnd.orientation, "vertical")) - horzvert = "vertical"; - else - horzvert = "horizontal"; - endif - if (strcmpi (hlgnd.textposition, "right")) - reverse = "reverse"; - else - reverse = "noreverse"; - endif - inout = "inside"; - keypos = hlgnd.location; - if (ischar (keypos)) - keypos = lower (keypos); - keyout = findstr (keypos, "outside"); - if (! isempty (keyout)) - inout = "outside"; - keypos = keypos(1:keyout-1); - endif - endif - switch (keypos) - case "north" - pos = "center top"; - case "south" - pos = "center bottom"; - case "east" - pos = "right center"; - case "west" - pos = "left center"; - case "northeast" - pos = "right top"; - case "northwest" - pos = "left top"; - case "southeast" - pos = "right bottom"; - case "southwest" - pos = "left bottom"; - case "best" - pos = ""; - warning ("legend: 'Best' not yet implemented for location specifier.\n"); - ## Least conflict with data in plot. - ## Least unused space outside plot. - otherwise - pos = ""; - endswitch - if (__gnuplot_has_feature__ ("key_has_font_properties")) - [fontname, fontsize] = get_fontname_and_size (hlgnd); - fontspec = create_fontspec (fontname, fontsize, gnuplot_term); - else - fontspec = ""; - endif - fprintf (plot_stream, "set key %s %s;\nset key %s %s %s %s;\n", - inout, pos, box, reverse, horzvert, fontspec); - else - fputs (plot_stream, "unset key;\n"); - endif - fputs (plot_stream, "set style data lines;\n"); - - cmap = [cmap; addedcmap]; - cmap_sz = cmap_sz + rows(addedcmap); - if (length(cmap) > 0) - fprintf (plot_stream, - "set palette positive color model RGB maxcolors %i;\n", - cmap_sz); - fprintf (plot_stream, - "set palette file \"-\" binary record=%d using 1:2:3:4;\n", - cmap_sz); - fwrite (plot_stream, [1:cmap_sz; cmap.'], "float32"); - fwrite (plot_stream, "\n"); - endif - - fputs (plot_stream, "unset colorbox;\n"); - - if (have_data) - if (nd == 2) - plot_cmd = "plot"; - else - plot_cmd = "splot"; - rot_x = 90 - axis_obj.view(2); - rot_z = axis_obj.view(1); - while (rot_z < 0) - rot_z += 360; - endwhile - fputs (plot_stream, "set ticslevel 0;\n"); - if (view_map && rot_x == 0 && rot_z == 0) - fputs (plot_stream, "set view map;\n"); - else - fprintf (plot_stream, "set view %.15g, %.15g;\n", rot_x, rot_z); - endif - endif - if (have_3d_patch (1)) - fputs (plot_stream, "set pm3d depthorder\n"); - fprintf (plot_stream, "%s \"-\" %s %s %s \\\n", plot_cmd, - usingclause{1}, titlespec{1}, withclause{1}); - elseif (is_image_data (1)) - fprintf (plot_stream, "%s \"-\" %s %s %s \\\n", plot_cmd, - usingclause{1}, titlespec{1}, withclause{1}); - else - fprintf (plot_stream, "%s \"-\" binary format='%%float64' %s %s %s \\\n", plot_cmd, - usingclause{1}, titlespec{1}, withclause{1}); - endif - for i = 2:data_idx - if (have_3d_patch (i)) - fprintf (plot_stream, ", \"-\" %s %s %s \\\n", - usingclause{i}, titlespec{i}, withclause{i}); - elseif (is_image_data (i)) - if (! is_image_data (i-1)) - fputs (plot_stream, "; "); - if (bg_is_set) - fputs (plot_stream, "unset obj 1; \\\n"); - bg_is_set = false; - endif - if (fg_is_set) - fputs (plot_stream, "unset obj 2; \\\n"); - fg_is_set = false; - endif - endif - fprintf (plot_stream, "%s \"-\" %s %s %s \\\n", plot_cmd, - usingclause{i}, titlespec{i}, withclause{i}); - elseif (is_image_data (i-1)) - if (bg_is_set) - fputs (plot_stream, "unset obj 1; \\\n"); - bg_is_set = false; - endif - if (fg_is_set) - fputs (plot_stream, "unset obj 2; \\\n"); - fg_is_set = false; - endif - fprintf (plot_stream, "%s \"-\" binary format='%%float64' %s %s %s \\\n", plot_cmd, - usingclause{i}, titlespec{i}, withclause{i}); - else - fprintf (plot_stream, ", \"-\" binary format='%%float64' %s %s %s \\\n", - usingclause{i}, titlespec{i}, withclause{i}); - endif - endfor - fputs (plot_stream, ";\n"); - for i = 1:data_idx - if (have_3d_patch (i)) - ## Can't write 3d patch data as binary as can't plot more than - ## a single patch at a time and have to plot all patches together - ## so that the gnuplot depth ordering is done correctly - for j = 1 : 4 : columns(data{i}) - if (j != 1) - fputs (plot_stream, "\n\n"); - endif - fprintf (plot_stream, "%.15g %.15g %.15g %.15g\n", data{i}(:,j).'); - fprintf (plot_stream, "%.15g %.15g %.15g %.15g\n\n", data{i}(:,j+1).'); - fprintf (plot_stream, "%.15g %.15g %.15g %.15g\n", data{i}(:,j+2).'); - fprintf (plot_stream, "%.15g %.15g %.15g %.15g\n", data{i}(:,j+3).'); - endfor - fputs (plot_stream, "e\n"); - elseif (is_image_data(i)) - fwrite (plot_stream, data{i}, "float32"); - else - __gnuplot_write_data__ (plot_stream, data{i}, nd, parametric(i), - have_cdata(i)); - endif - endfor - else - fputs (plot_stream, "plot \"-\";\nInf Inf\ne\n"); - endif - - ## Needed to allow mouse rotation with pcolor. - if (view_map) - fputs (plot_stream, "unset view;\n"); - endif - - if (bg_is_set) - fputs (plot_stream, "unset obj 1;\n"); - bg_is_set = false; - endif - - fflush (plot_stream); - - else - print_usage (); - endif - -endfunction - -function fontspec = create_fontspec (f, s, gp_term) - if (strcmp (f, "*") || strcmp (gp_term, "tikz")) - fontspec = sprintf ("font \",%d\"", s); - else - fontspec = sprintf ("font \"%s,%d\"", f, s); - endif -endfunction - -function style = do_linestyle_command (obj, linecolor, idx, mono, - plot_stream, errbars = "") - style = {}; - - fprintf (plot_stream, "set style line %d default;\n", idx); - fprintf (plot_stream, "set style line %d", idx); - - found_style = false; - if (isnumeric (linecolor)) - color = linecolor; - if (! mono) - fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"", - round (255*color)); - endif - else - color = [0, 0, 0]; - endif - - if (isfield (obj, "linestyle")) - switch (obj.linestyle) - case "-" - lt = "1"; - case "--" - lt = "2"; - case ":" - lt = "3"; - case "-." - lt = "6"; - case "none" - lt = ""; - otherwise - lt = ""; - endswitch - - if (! isempty (lt)) - fprintf (plot_stream, " linetype %s", lt); - endif - - else - lt = ""; - endif - if (! isempty (errbars)) - found_style = true; - endif - - if (isfield (obj, "linewidth")) - fprintf (plot_stream, " linewidth %f", obj.linewidth); - found_style = true; - endif - - [pt, pt2, obj] = gnuplot_pointtype (obj); - - if (! isempty (pt)) - found_style = true; - endif - - sidx = 1; - if (isempty (errbars)) - if (isempty (lt)) - style {sidx} = ""; - else - style {sidx} = "lines"; - endif - - facesame = true; - if (! isequal (pt, pt2) && isfield (obj, "markerfacecolor") - && !strncmp (obj.markerfacecolor, "none", 4)) - if (strncmp (obj.markerfacecolor, "auto", 4) - || ! isnumeric (obj.markerfacecolor) - || (isnumeric (obj.markerfacecolor) - && isequal (color, obj.markerfacecolor))) - if (! isempty (pt2)) - fprintf (plot_stream, " pointtype %s", pt2); - style {sidx} = strcat (style{sidx}, "points"); - endif - if (isfield (obj, "markersize")) - fprintf (plot_stream, " pointsize %f", obj.markersize / 3); - endif - else - facesame = false; - if (! found_style) - fputs (plot_stream, " default"); - endif - fputs (plot_stream, ";\n"); - if (! isempty (style {sidx})) - sidx ++; - idx ++; - else - fputs (plot_stream, ";\n"); - endif - fprintf (plot_stream, "set style line %d default;\n", idx); - fprintf (plot_stream, "set style line %d", idx); - if (isnumeric (obj.markerfacecolor) && ! mono) - fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"", - round (255*obj.markerfacecolor)); - endif - if (! isempty (pt2)) - style {sidx} = "points"; - fprintf (plot_stream, " pointtype %s", pt2); - endif - if (isfield (obj, "markersize")) - fprintf (plot_stream, " pointsize %f", obj.markersize / 3); - endif - endif - endif - if (isfield (obj, "markeredgecolor") - && !strncmp (obj.markeredgecolor, "none", 4)) - if (facesame && !isempty (pt) - && (strncmp (obj.markeredgecolor, "auto", 4) - || ! isnumeric (obj.markeredgecolor) - || (isnumeric (obj.markeredgecolor) - && isequal (color, obj.markeredgecolor)))) - if (sidx == 1 && ((length (style {sidx}) == 5 - && strncmp (style {sidx}, "lines", 5)) || isempty (style {sidx}))) - if (! isempty (pt)) - style {sidx} = strcat (style{sidx}, "points"); - fprintf (plot_stream, " pointtype %s", pt); - endif - if (isfield (obj, "markersize")) - fprintf (plot_stream, " pointsize %f", obj.markersize / 3); - endif - endif - else - if (! found_style) - fputs (plot_stream, " default"); - endif - fputs (plot_stream, ";\n"); - if (!isempty (style {sidx})) - sidx ++; - idx ++; - else - fputs (plot_stream, ";\n"); - endif - fprintf (plot_stream, "set style line %d default;\n", idx); - fprintf (plot_stream, "set style line %d", idx); - if (! mono) - if (strncmp (obj.markeredgecolor, "auto", 4)) - fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"", - round (255*color)); - elseif (isnumeric (obj.markeredgecolor) && ! mono) - fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"", - round (255*obj.markeredgecolor)); - endif - endif - if (! isempty (pt)) - style {sidx} = "points"; - fprintf (plot_stream, " pointtype %s", pt); - endif - if (isfield (obj, "markersize")) - fprintf (plot_stream, " pointsize %f", obj.markersize / 3); - endif - endif - endif - else - style{1} = errbars; - fputs (plot_stream, " pointtype 0"); - endif - - if (! found_style && isempty (style {1})) - fputs (plot_stream, " default"); - endif - - fputs (plot_stream, ";\n"); - -endfunction - -function [pt, pt2, obj] = gnuplot_pointtype (obj) - if (isfield (obj, "marker")) - switch (obj.marker) - case "+" - pt = pt2 = "1"; - case "o" - pt = "6"; - pt2 = "7"; - case "*" - pt = pt2 = "3"; - case "." - pt = "6"; - pt2 = "7"; - if (isfield (obj, "markerfacecolor") - || strncmp (obj.markerfacecolor, "none", 4)) - obj.markerfacecolor = "auto"; - endif - if (isfield (obj, "markersize")) - obj.markersize /= 3; - else - obj.markersize = 5; - endif - case "x" - pt = pt2 = "2"; - case {"square", "s"} - pt = "4"; - pt2 = "5"; - case {"diamond", "d"} - pt = "12"; - pt2 = "13"; - case "^" - pt = "8"; - pt2 = "9"; - case "v" - pt = "10"; - pt2 = "11"; - case ">" - ## FIXME -- should be triangle pointing right, use triangle pointing up - pt = "8"; - pt2 = "9"; - case "<" - ## FIXME -- should be triangle pointing left, use triangle pointing down - pt = "10"; - pt2 = "11"; - case {"pentagram", "p"} - ## FIXME -- should be pentagram, using pentagon - pt = "14"; - pt2 = "15"; - case {"hexagram", "h"} - ## FIXME -- should be 6 pt start, using "*" instead - pt = pt2 = "3"; - case "none" - pt = pt2 = ""; - otherwise - pt = pt2 = ""; - endswitch - else - pt = pt2 = ""; - endif -endfunction - -function __gnuplot_write_data__ (plot_stream, data, nd, parametric, cdata) - - ## DATA is already transposed. - - ## FIXME -- this may need to be converted to C++ for speed. - - ## Convert NA elements to normal NaN values because fprintf writes - ## "NA" and that confuses gnuplot. - idx = find (isna (data)); - if (any (idx)) - data(idx) = NaN; - endif - - if (nd == 2) - fwrite (plot_stream, data, "float64"); - elseif (nd == 3) - if (parametric) - fwrite (plot_stream, data, "float64"); - else - nr = rows (data); - if (cdata) - for j = 1:4:nr - fwrite (plot_stream, data(j:j+3,:), "float64"); - endfor - else - for j = 1:3:nr - fwrite (plot_stream, data(j:j+2,:), "float64"); - endfor - endif - endif - endif - -endfunction - -function do_tics (obj, plot_stream, ymirror, mono, gnuplot_term) - - obj.xticklabel = ticklabel_to_cell (obj.xticklabel); - obj.yticklabel = ticklabel_to_cell (obj.yticklabel); - obj.zticklabel = ticklabel_to_cell (obj.zticklabel); - - if (strcmp (obj.xminorgrid, "on")) - obj.xminortick = "on"; - endif - if (strcmp (obj.yminorgrid, "on")) - obj.yminortick = "on"; - endif - if (strcmp (obj.zminorgrid, "on")) - obj.zminortick = "on"; - endif - - [fontname, fontsize] = get_fontname_and_size (obj); - fontspec = create_fontspec (fontname, fontsize, gnuplot_term); - - ## A Gnuplot tic scale of 69 is equivalent to Octave's 0.5. - ticklength = sprintf ("scale %4.1f", (69/0.5)*obj.ticklength(1)); - - if (strcmpi (obj.xaxislocation, "top")) - do_tics_1 (obj.xtickmode, obj.xtick, obj.xminortick, obj.xticklabelmode, - obj.xticklabel, obj.xcolor, "x2", plot_stream, true, mono, - "border", obj.tickdir, ticklength, fontname, fontspec, - obj.interpreter, obj.xscale); - do_tics_1 ("manual", [], "off", obj.xticklabelmode, obj.xticklabel, - obj.xcolor, "x", plot_stream, true, mono, "border", - "", "", fontname, fontspec, obj.interpreter, obj.xscale); - elseif (strcmpi (obj.xaxislocation, "zero")) - do_tics_1 (obj.xtickmode, obj.xtick, obj.xminortick, obj.xticklabelmode, - obj.xticklabel, obj.xcolor, "x", plot_stream, true, mono, - "axis", obj.tickdir, ticklength, fontname, fontspec, - obj.interpreter, obj.xscale); - do_tics_1 ("manual", [], "off", obj.xticklabelmode, obj.xticklabel, - obj.xcolor, "x2", plot_stream, true, mono, "axis", - "", "", fontname, fontspec, obj.interpreter, obj.xscale); - else - do_tics_1 (obj.xtickmode, obj.xtick, obj.xminortick, obj.xticklabelmode, - obj.xticklabel, obj.xcolor, "x", plot_stream, true, mono, - "border", obj.tickdir, ticklength, fontname, fontspec, - obj.interpreter, obj.xscale); - do_tics_1 ("manual", [], "off", obj.xticklabelmode, obj.xticklabel, - obj.xcolor, "x2", plot_stream, true, mono, "border", - "", "", fontname, fontspec, obj.interpreter, obj.xscale); - endif - if (strcmpi (obj.yaxislocation, "right")) - do_tics_1 (obj.ytickmode, obj.ytick, obj.yminortick, obj.yticklabelmode, - obj.yticklabel, obj.ycolor, "y2", plot_stream, ymirror, mono, - "border", obj.tickdir, ticklength, fontname, fontspec, - obj.interpreter, obj.yscale); - do_tics_1 ("manual", [], "off", obj.yticklabelmode, obj.yticklabel, - obj.ycolor, "y", plot_stream, ymirror, mono, "border", - "", "", fontname, fontspec, obj.interpreter, obj.yscale); - elseif (strcmpi (obj.yaxislocation, "zero")) - do_tics_1 (obj.ytickmode, obj.ytick, obj.yminortick, obj.yticklabelmode, - obj.yticklabel, obj.ycolor, "y", plot_stream, ymirror, mono, - "axis", obj.tickdir, ticklength, fontname, fontspec, - obj.interpreter, obj.yscale); - do_tics_1 ("manual", [], "off", obj.yticklabelmode, obj.yticklabel, - obj.ycolor, "y2", plot_stream, ymirror, mono, "axis", - "", "", fontname, fontspec, obj.interpreter, obj.yscale); - else - do_tics_1 (obj.ytickmode, obj.ytick, obj.yminortick, obj.yticklabelmode, - obj.yticklabel, obj.ycolor, "y", plot_stream, ymirror, mono, - "border", obj.tickdir, ticklength, fontname, fontspec, - obj.interpreter, obj.yscale); - do_tics_1 ("manual", [], "off", obj.yticklabelmode, obj.yticklabel, - obj.ycolor, "y2", plot_stream, ymirror, mono, "border", - "", "", fontname, fontspec, obj.interpreter, obj.yscale); - endif - do_tics_1 (obj.ztickmode, obj.ztick, obj.zminortick, obj.zticklabelmode, - obj.zticklabel, obj.zcolor, "z", plot_stream, true, mono, - "border", obj.tickdir, ticklength, fontname, fontspec, - obj.interpreter, obj.zscale); -endfunction - -function do_tics_1 (ticmode, tics, mtics, labelmode, labels, color, ax, - plot_stream, mirror, mono, axispos, tickdir, ticklength, - fontname, fontspec, interpreter, scale) - persistent warned_latex = false; - if (strcmpi (interpreter, "tex")) - for n = 1 : numel(labels) - labels{n} = __tex2enhanced__ (labels{n}, fontname, false, false); - endfor - elseif (strcmpi (interpreter, "latex")) - if (! warned_latex) - warning ("latex markup not supported for tick marks"); - warned_latex = true; - endif - endif - if (strcmp (scale, "log")) - fmt = "10^{%T}"; - num_mtics = 10; - else - fmt = "%g"; - num_mtics = 5; - endif - colorspec = get_text_colorspec (color, mono); - if (strcmpi (ticmode, "manual") || strcmpi (labelmode, "manual")) - if (isempty (tics)) - fprintf (plot_stream, "unset %stics;\nunset m%stics;\n", ax, ax); - elseif (strcmpi (labelmode, "manual")) - if (ischar (labels)) - labels = cellstr (labels); - endif - if (isnumeric (labels)) - labels = num2str (real (labels(:))); - endif - if (ischar (labels)) - labels = permute (cellstr (labels), [2, 1]); - endif - if (iscellstr (labels)) - k = 1; - ntics = numel (tics); - nlabels = numel (labels); - fprintf (plot_stream, "set format %s \"%%s\";\n", ax); - if (mirror) - fprintf (plot_stream, "set %stics %s %s %s mirror (", ax, - tickdir, ticklength, axispos); - else - fprintf (plot_stream, "set %stics %s %s %s nomirror (", ax, - tickdir, ticklength, axispos); - endif - - labels = regexprep(labels, '%', "%%"); - for i = 1:ntics - fprintf (plot_stream, " \"%s\" %.15g", labels{k++}, tics(i)); - if (i < ntics) - fputs (plot_stream, ", "); - endif - if (k > nlabels) - k = 1; - endif - endfor - fprintf (plot_stream, ") %s %s;\n", colorspec, fontspec); - if (strcmp (mtics, "on")) - fprintf (plot_stream, "set m%stics %d;\n", ax, num_mtics); - else - fprintf (plot_stream, "unset m%stics;\n", ax); - endif - else - error ("__go_draw_axes__: unsupported type of ticklabel"); - endif - else - fprintf (plot_stream, "set format %s \"%s\";\n", ax, fmt); - if (mirror) - fprintf (plot_stream, "set %stics %s %s %s mirror (", ax, tickdir, - ticklength, axispos); - else - fprintf (plot_stream, "set %stics %s %s %s nomirror (", ax, tickdir, - ticklength, axispos); - endif - fprintf (plot_stream, " %.15g,", tics(1:end-1)); - fprintf (plot_stream, " %.15g) %s;\n", tics(end), fontspec); - if (strcmp (mtics, "on")) - fprintf (plot_stream, "set m%stics %d;\n", ax, num_mtics); - else - fprintf (plot_stream, "unset m%stics;\n", ax); - endif - endif - else - fprintf (plot_stream, "set format %s \"%s\";\n", ax, fmt); - if (mirror) - fprintf (plot_stream, "set %stics %s %s %s mirror %s %s;\n", ax, - axispos, tickdir, ticklength, colorspec, fontspec); - else - fprintf (plot_stream, "set %stics %s %s %s nomirror %s %s;\n", ax, - tickdir, ticklength, axispos, colorspec, fontspec); - endif - if (strcmp (mtics, "on")) - fprintf (plot_stream, "set m%stics %d;\n", ax, num_mtics); - else - fprintf (plot_stream, "unset m%stics;\n", ax); - endif - endif -endfunction - -function ticklabel = ticklabel_to_cell (ticklabel) - if (isnumeric (ticklabel)) - ## Use upto 5 significant digits - ticklabel = num2str (ticklabel(:), 5); - endif - if (ischar (ticklabel)) - if (size (ticklabel, 1) == 1 && any (ticklabel == "|")) - n = setdiff (findstr (ticklabel, "|"), findstr (ticklabel, '\|')); - ticklabel = strsplit (ticklabel, "|"); - else - ticklabel = cellstr (ticklabel); - endif - elseif (isempty (ticklabel)) - ticklabel = {""}; - else - ticklabel = ticklabel; - endif -endfunction - -function colorspec = get_text_colorspec (color, mono) - if (mono) - colorspec = ""; - else - colorspec = sprintf ("textcolor rgb \"#%02x%02x%02x\"", - round (255*color)); - endif -endfunction - -function [f, s, fnt, it, bld] = get_fontname_and_size (t) - if (isempty (t.fontname) || strcmp (t.fontname, "*")) - fnt = "{}"; - else - fnt = t.fontname; - endif - f = fnt; - it = false; - bld = false; - if (! isempty (t.fontweight) && strcmpi (t.fontweight, "bold")) - if (! isempty(t.fontangle) - && (strcmpi (t.fontangle, "italic") - || strcmpi (t.fontangle, "oblique"))) - f = cstrcat (f, "-bolditalic"); - it = true; - bld = true; - else - f = cstrcat (f, "-bold"); - bld = true; - endif - elseif (! isempty(t.fontangle) - && (strcmpi (t.fontangle, "italic") - || strcmpi (t.fontangle, "oblique"))) - f = cstrcat (f, "-italic"); - it = true; - endif - if (isempty (t.fontsize)) - s = 10; - else - s = t.fontsize; - endif -endfunction - -function [str, f, s] = __maybe_munge_text__ (enhanced, obj, fld) - - persistent warned_latex = false; - - if (strcmp (fld, "string")) - [f, s, fnt, it, bld] = get_fontname_and_size (obj); - else - f = "Helvetica"; - s = 10; - fnt = f; - it = false; - bld = false; - endif - - str = getfield (obj, fld); - if (enhanced) - if (strcmpi (obj.interpreter, "tex")) - str = __tex2enhanced__ (str, fnt, it, bld); - elseif (strcmpi (obj.interpreter, "latex")) - if (! warned_latex) - warning ("latex markup not supported for text objects"); - warned_latex = true; - endif - endif - endif -endfunction - -function str = __tex2enhanced__ (str, fnt, it, bld) - persistent sym = __setup_sym_table__ (); - persistent flds = fieldnames (sym); - - [s, e, m] = regexp(str,'\\([a-zA-Z]+|0)','start','end','matches'); - - for i = length (s) : -1 : 1 - ## special case for "\0" and replace with "{/Symbol \306}' - if (strncmp (m{i}, '\0', 2)) - str = cstrcat (str(1:s(i) - 1), '{/Symbol \306}', str(s(i) + 2:end)); - else - f = m{i}(2:end); - if (isfield (sym, f)) - g = getfield(sym, f); - ## FIXME The symbol font doesn't seem to support bold or italic - ##if (bld) - ## if (it) - ## g = regexprep (g, '/Symbol', '/Symbol-bolditalic'); - ## else - ## g = regexprep (g, '/Symbol', '/Symbol-bold'); - ## endif - ##elseif (it) - ## g = regexprep (g, '/Symbol', '/Symbol-italic'); - ##endif - str = cstrcat (str(1:s(i) - 1), g, str(e(i) + 1:end)); - elseif (strncmp (f, "rm", 2)) - bld = false; - it = false; - str = cstrcat (str(1:s(i) - 1), '/', fnt, ' ', str(s(i) + 3:end)); - elseif (strncmp (f, "it", 2) || strncmp (f, "sl", 2)) - it = true; - if (bld) - str = cstrcat (str(1:s(i) - 1), '/', fnt, '-bolditalic ', - str(s(i) + 3:end)); - else - str = cstrcat (str(1:s(i) - 1), '/', fnt, '-italic ', - str(s(i) + 3:end)); - endif - elseif (strncmp (f, "bf", 2)) - bld = true; - if (it) - str = cstrcat (str(1:s(i) - 1), '/', fnt, '-bolditalic ', - str(2(i) + 3:end)); - else - str = cstrcat (str(1:s(i) - 1), '/', fnt, '-bold ', - str(s(i) + 3:end)); - endif - elseif (strcmpi (f, "color")) - ## FIXME Ignore \color but remove trailing {} block as well - d = strfind(str(e(i) + 1:end),'}'); - if (isempty (d)) - warning ('syntax error in \color argument'); - else - str = cstrcat (str(1:s(i) - 1), str(e(i) + d + 1:end)); - endif - elseif(strcmpi (f, "fontname")) - b1 = strfind(str(e(i) + 1:end),'{'); - b2 = strfind(str(e(i) + 1:end),'}'); - if (isempty(b1) || isempty(b2)) - warning ('syntax error in \fontname argument'); - else - str = cstrcat (str(1:s(i) - 1), '/', - str(e(i)+b1(1) + 1:e(i)+b2(1)-1), '{}', - str(e(i) + b2(1) + 1:end)); - endif - elseif(strcmpi (f, "fontsize")) - b1 = strfind(str(e(i) + 1:end),'{'); - b2 = strfind(str(e(i) + 1:end),'}'); - if (isempty(b1) || isempty(b2)) - warning ('syntax error in \fontname argument'); - else - str = cstrcat (str(1:s(i) - 1), '/=', - str(e(i)+b1(1) + 1:e(i)+b2(1)-1), '{}', - str(e(i) + b2(1) + 1:end)); - endif - else - ## Last desperate attempt to treat the symbol. Look for things - ## like \pix, that should be translated to the symbol Pi and x - for j = 1 : length (flds) - if (strncmp (flds{j}, f, length (flds{j}))) - g = getfield(sym, flds{j}); - ## FIXME The symbol font doesn't seem to support bold or italic - ##if (bld) - ## if (it) - ## g = regexprep (g, '/Symbol', '/Symbol-bolditalic'); - ## else - ## g = regexprep (g, '/Symbol', '/Symbol-bold'); - ## endif - ##elseif (it) - ## g = regexprep (g, '/Symbol', '/Symbol-italic'); - ##endif - str = cstrcat (str(1:s(i) - 1), g, - str(s(i) + length (flds{j}) + 1:end)); - break; - endif - endfor - endif - endif - endfor - - ## Prepend @ to things things like _0^x or _{-100}^{100} for - ## alignment But need to put the shorter of the two arguments first. - ## Carful of nested {} and unprinted characters when defining - ## shortest.. Don't have to worry about things like ^\theta as they - ## are already converted to ^{/Symbol q}. - - ## FIXME -- This is a mess... Is it worth it just for a "@" character? - - [s, m] = regexp(str,'[_\^]','start','matches'); - i = 1; - p = 0; - while (i < length (s)) - if (i < length(s)) - if (str(s(i) + p + 1) == "{") - s1 = strfind(str(s(i) + p + 2:end),'{'); - si = 1; - l1 = strfind(str(s(i) + p + 1:end),'}'); - li = 1; - while (li <= length (l1) && si <= length (s1)) - if (l1(li) < s1(si)) - if (li == si) - break; - endif - li++; - else - si++; - endif - endwhile - l1 = l1 (min (length(l1), si)); - if (s(i) + l1 + 1 == s(i+1)) - if (str(s(i + 1) + p + 1) == "{") - s2 = strfind(str(s(i + 1) + p + 2:end),'{'); - si = 1; - l2 = strfind(str(s(i + 1) + p + 1:end),'}'); - li = 1; - while (li <= length (l2) && si <= length (s2)) - if (l2(li) < s2(si)) - if (li == si) - break; - endif - li++; - else - si++; - endif - endwhile - l2 = l2 (min (length(l2), si)); - if (length_string (str(s(i)+p+2:s(i)+p+l1-1)) <= - length_string(str(s(i+1)+p+2:s(i+1)+p+l2-1))) - ## Shortest already first! - str = cstrcat (str(1:s(i)+p-1), "@", str(s(i)+p:end)); - else - ## Have to swap sub/super-script to get shortest first. - str = cstrcat (str(1:s(i)+p-1), "@", str(s(i+1)+p:s(i+1)+p+l2), - str(s(i)+p:s(i)+p+l1), str(s(i+1)+p+l2+1:end)); - endif - else - ## Have to swap sub/super-script to get shortest first. - str = cstrcat (str(1:s(i)+p-1), "@", str(s(i+1)+p:s(i+1)+p+1), - str(s(i)+p:s(i)+p+l1), str(s(i+1)+p+2:end)); - endif - i += 2; - p ++; - else - i++; - endif - else - if (s(i+1) == s(i) + 2) - ## Shortest already first! - str = cstrcat (str(1:s(i)+p-1), "@", str(s(i)+p:end)); - p ++; - i += 2; - else - i ++; - endif - endif - else - i ++; - endif - endwhile - -endfunction - -function l = length_string (s) - l = length (s) - length (strfind(s,'{')) - length (strfind(s,'}')); - m = regexp (s, '/([\w-]+|[\w-]+=\d+)', 'matches'); - if (!isempty (m)) - l = l - sum (cellfun (@length, m)); - endif -endfunction - -function sym = __setup_sym_table__ () - ## Setup the translation table for TeX to gnuplot enhanced mode. - sym.forall = '{/Symbol \042}'; - sym.exists = '{/Symbol \044}'; - sym.ni = '{/Symbol \047}'; - sym.cong = '{/Symbol \100}'; - sym.Delta = '{/Symbol D}'; - sym.Phi = '{/Symbol F}'; - sym.Gamma = '{/Symbol G}'; - sym.vartheta = '{/Symbol J}'; - sym.Lambda = '{/Symbol L}'; - sym.Pi = '{/Symbol P}'; - sym.Theta = '{/Symbol Q}'; - sym.Sigma = '{/Symbol S}'; - sym.varsigma = '{/Symbol V}'; - sym.Omega = '{/Symbol W}'; - sym.Xi = '{/Symbol X}'; - sym.Psi = '{/Symbol Y}'; - sym.perp = '{/Symbol \136}'; - sym.alpha = '{/Symbol a}'; - sym.beta = '{/Symbol b}'; - sym.chi = '{/Symbol c}'; - sym.delta = '{/Symbol d}'; - sym.epsilon = '{/Symbol e}'; - sym.phi = '{/Symbol f}'; - sym.gamma = '{/Symbol g}'; - sym.eta = '{/Symbol h}'; - sym.iota = '{/Symbol i}'; - sym.varphi = '{/Symbol j}'; - sym.kappa = '{/Symbol k}'; - sym.lambda = '{/Symbol l}'; - sym.mu = '{/Symbol m}'; - sym.nu = '{/Symbol n}'; - sym.o = '{/Symbol o}'; - sym.pi = '{/Symbol p}'; - sym.theta = '{/Symbol q}'; - sym.rho = '{/Symbol r}'; - sym.sigma = '{/Symbol s}'; - sym.tau = '{/Symbol t}'; - sym.upsilon = '{/Symbol u}'; - sym.varpi = '{/Symbol v}'; - sym.omega = '{/Symbol w}'; - sym.xi = '{/Symbol x}'; - sym.psi = '{/Symbol y}'; - sym.zeta = '{/Symbol z}'; - sym.sim = '{/Symbol \176}'; - sym.Upsilon = '{/Symbol \241}'; - sym.prime = '{/Symbol \242}'; - sym.leq = '{/Symbol \243}'; - sym.infty = '{/Symbol \245}'; - sym.clubsuit = '{/Symbol \247}'; - sym.diamondsuit = '{/Symbol \250}'; - sym.heartsuit = '{/Symbol \251}'; - sym.spadesuit = '{/Symbol \252}'; - sym.leftrightarrow = '{/Symbol \253}'; - sym.leftarrow = '{/Symbol \254}'; - sym.uparrow = '{/Symbol \255}'; - sym.rightarrow = '{/Symbol \256}'; - sym.downarrow = '{/Symbol \257}'; - sym.circ = '{/Symbol \260}'; - sym.pm = '{/Symbol \261}'; - sym.geq = '{/Symbol \263}'; - sym.times = '{/Symbol \264}'; - sym.propto = '{/Symbol \265}'; - sym.partial = '{/Symbol \266}'; - sym.bullet = '{/Symbol \267}'; - sym.div = '{/Symbol \270}'; - sym.neq = '{/Symbol \271}'; - sym.equiv = '{/Symbol \272}'; - sym.approx = '{/Symbol \273}'; - sym.ldots = '{/Symbol \274}'; - sym.mid = '{/Symbol \275}'; - sym.aleph = '{/Symbol \300}'; - sym.Im = '{/Symbol \301}'; - sym.Re = '{/Symbol \302}'; - sym.wp = '{/Symbol \303}'; - sym.otimes = '{/Symbol \304}'; - sym.oplus = '{/Symbol \305}'; - sym.oslash = '{/Symbol \306}'; - sym.cap = '{/Symbol \307}'; - sym.cup = '{/Symbol \310}'; - sym.supset = '{/Symbol \311}'; - sym.supseteq = '{/Symbol \312}'; - sym.subset = '{/Symbol \314}'; - sym.subseteq = '{/Symbol \315}'; - sym.in = '{/Symbol \316}'; - sym.notin = '{/Symbol \317}'; - sym.angle = '{/Symbol \320}'; - sym.bigtriangledown = '{/Symbol \321}'; - sym.langle = '{/Symbol \341}'; - sym.rangle = '{/Symbol \361}'; - sym.nabla = '{/Symbol \321}'; - sym.prod = '{/Symbol \325}'; - sym.surd = '{/Symbol \326}'; - sym.cdot = '{/Symbol \327}'; - sym.neg = '{/Symbol \330}'; - sym.wedge = '{/Symbol \331}'; - sym.vee = '{/Symbol \332}'; - sym.Leftrightarrow = '{/Symbol \333}'; - sym.Leftarrow = '{/Symbol \334}'; - sym.Uparrow = '{/Symbol \335}'; - sym.Rightarrow = '{/Symbol \336}'; - sym.Downarrow = '{/Symbol \337}'; - sym.diamond = '{/Symbol \340}'; - sym.copyright = '{/Symbol \343}'; - sym.lfloor = '{/Symbol \353}'; - sym.lceil = '{/Symbol \351}'; - sym.rfloor = '{/Symbol \373}'; - sym.rceil = '{/Symbol \371}'; - sym.int = '{/Symbol \362}'; -endfunction - -function retval = __do_enhanced_option__ (enhanced, obj) - retval = ""; - if (enhanced) - if (strcmpi (obj.interpreter, "none")) - retval = "noenhanced"; - else - retval = "enhanced"; - endif - endif -endfunction diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/__go_draw_figure__.m --- a/scripts/plot/__go_draw_figure__.m Sat Jul 16 09:16:52 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,198 +0,0 @@ -## Copyright (C) 2005-2011 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 3 of the License, 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, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {} __go_draw_figure__ (@var{h}, @var{plot_stream}, @var{enhanced}, @var{mono}) -## Undocumented internal function. -## @end deftypefn - -## Author: jwe - -function __go_draw_figure__ (h, plot_stream, enhanced, mono) - - if (nargin == 4) - htype = get (h, "type"); - if (strcmp (htype, "figure")) - ## Get complete list of children. - kids = allchild (h); - nkids = length (kids); - - if (nkids > 0) - fputs (plot_stream, "\nreset;\n"); - fputs (plot_stream, "set autoscale keepfix;\n"); - fputs (plot_stream, "set origin 0, 0\n"); - fputs (plot_stream, "set size 1, 1\n"); - bg = get (h, "color"); - if (isnumeric (bg)) - fprintf (plot_stream, "set obj 1 rectangle from screen 0,0 to screen 1,1 behind fc rgb \"#%02x%02x%02x\"\n", 255 * bg); - bg_is_set = true; - else - bg_is_set = false; - endif - - for i = nkids:-1:1 - type = get (kids(i), "type"); - switch (type) - case "axes" - if (strcmpi (get (kids (i), "tag"), "legend")) - ## This is so ugly. If there was a way of getting - ## gnuplot to give us the text extents of strings - ## then we could get rid of this mess. - lh = getfield (get (kids(i), "userdata"), "handle"); - if (isscalar (lh)) - ## We have a legend with a single parent. It'll be handled - ## below as a gnuplot key to the axis it corresponds to - continue; - else - ca = lh(1); - ## Rely upon listener to convert axes position - ## to "normalized" units. - legend_axes_units = get (kids(i), "units"); - legend_axes_position = get (kids(i), "position"); - legend_axes_outerposition = get (kids(i), "outerposition"); - legend_axes_box = get (kids(i), "box"); - legend_axes_ylim = get (kids(i), "ylim"); - orig_axes_units = get (ca, "units"); - hlgnd = get (kids(i)); - - unwind_protect - set (ca, "units", "normalized"); - set (kids(i), "units", "normalized", "box", "off", - "ylim", [-2, -1], "position", get (ca(1), "position"), - "outerposition", get (ca(1), "outerposition")); - - ## Create a new set of lines with the appropriate - ## displaynames, etc - toberm = []; - hobj = get (kids(i), "children"); - for j = numel (hobj) : -1 : 1 - if (! strcmp (get (hobj(j), "type"), "text")) - continue; - endif - displayname = get (hobj(j), "string"); - ll = []; - lm = []; - for k = numel (hobj) : -1 : 1 - if (! strcmp (get (hobj(k), "type"), "line")) - continue; - endif - if (get (hobj(j), "userdata") - != get (hobj(k), "userdata")) - continue; - endif - if (! strcmp (get (hobj(k), "linestyle"), "none")) - ll = hobj(k); - endif - if (! strcmp (get (hobj(k), "marker"), "none")) - lm = hobj(k); - endif - endfor - - if (! isempty (ll)) - if (!isempty (lm)) - toberm = [toberm, line("xdata",[0,0],"ydata",[0,0], "color", get(lm,"color"), "linestyle", get(ll,"linestyle"), "marker", get(lm,"marker"), "markeredgecolor", get(lm,"markeredgecolor"), "markerfacecolor", get(lm,"markerfacecolor"), "markersize", get (lm, "markersize"), "displayname", displayname, "parent", kids(i))]; - else - toberm = [toberm, line("xdata",[0,0],"ydata",[0,0], "color", get(ll,"color"), "linestyle", get(ll,"linestyle"), "marker", "none", "displayname", displayname, "parent", kids(i))]; - endif - elseif (! isempty (lm)) - toberm = [toberm, line("xdata",[0,0],"ydata",[0,0], "color", get(lm,"color"), "linestyle", "none", "marker", get(lm,"marker"), "markeredgecolor", get(lm,"markeredgecolor"), "markerfacecolor", get(lm,"markerfacecolor"), "markersize", get (lm, "markersize"), "displayname", displayname, "parent", kids(i))]; - endif - endfor - if (bg_is_set) - fprintf (plot_stream, "set border linecolor rgb \"#%02x%02x%02x\"\n", 255 * (1 - bg)); - endif - __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, - bg_is_set, false, hlgnd); - unwind_protect_cleanup - ## Return axes "units" and "position" back to - ## their original values. - set (ca, "units", orig_axes_units); - set (kids(i), "units", legend_axes_units, - "box", legend_axes_box, - "ylim", legend_axes_ylim, - "position", legend_axes_position, - "outerposition", legend_axes_outerposition); - delete (toberm); - bg_is_set = false; - end_unwind_protect - endif - else - ## Rely upon listener to convert axes position - ## to "normalized" units. - orig_axes_units = get (kids(i), "units"); - orig_axes_position = get (kids(i), "position"); - unwind_protect - set (kids(i), "units", "normalized"); - fg = get (kids(i), "color"); - if (isnumeric (fg) && strcmp (get (kids(i), "visible"), "on")) - fprintf (plot_stream, "set obj 2 rectangle from graph 0,0 to graph 1,1 behind fc rgb \"#%02x%02x%02x\"\n", 255 * fg); - fg_is_set = true; - else - fg_is_set = false; - endif - if (bg_is_set) - fprintf (plot_stream, "set border linecolor rgb \"#%02x%02x%02x\"\n", 255 * (1 - bg)); - endif - ## Find if this axes has an associated legend axes and pass it - ## to __go_draw_axes__ - hlegend = []; - fkids = get (h, "children"); - for j = 1 : numel(fkids) - if (ishandle (fkids (j)) - && strcmp (get (fkids (j), "type"), "axes") - && (strcmp (get (fkids (j), "tag"), "legend"))) - udata = get (fkids (j), "userdata"); - if (isscalar(udata.handle) - && ! isempty (intersect (udata.handle, kids (i)))) - hlegend = get (fkids (j)); - break; - endif - endif - endfor - __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, - bg_is_set, fg_is_set, hlegend); - unwind_protect_cleanup - ## Return axes "units" and "position" back to - ## their original values. - set (kids(i), "units", orig_axes_units); - set (kids(i), "position", orig_axes_position); - bg_is_set = false; - fg_is_set = false; - end_unwind_protect - endif - case "uimenu" - ## ignore uimenu objects - otherwise - error ("__go_draw_figure__: unknown object class, %s", type); - endswitch - endfor - fputs (plot_stream, "\nunset multiplot;\n"); - else - fputs (plot_stream, "\nreset; clear;\n"); - fflush (plot_stream); - endif - else - error ("__go_draw_figure__: expecting figure object, found `%s'", - htype); - endif - else - print_usage (); - endif - -endfunction - diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/__marching_cube__.m --- a/scripts/plot/__marching_cube__.m Sat Jul 16 09:16:52 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,530 +0,0 @@ -## Copyright (C) 2009-2011 Martin Helm -## -## 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 3 of the License, 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, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {[@var{t}, @var{p}] =} __marching_cube__ (@var{x}, @var{y}, @var{z}, @var{val}, @var{iso}) -## @deftypefnx {Function File} {[@var{t}, @var{p}, @var{c}] =} __marching_cube__ (@var{x}, @var{y}, @var{z}, @var{val}, @var{iso}, @var{col}) -## Undocumented internal function. -## @end deftypefn - -## -*- texinfo -*- -## @deftypefn {Function File} {[@var{t}, @var{p}] =} __marching_cube__ (@var{x}, @var{y}, @var{z}, @var{val}, @var{iso}) -## @deftypefnx {Function File} {[@var{t}, @var{p}, @var{c}] =} __marching_cube__ (@var{x}, @var{y}, @var{z}, @var{val}, @var{iso}, @var{col}) -## -## Return the triangulation information @var{t} at points @var{p} for -## the isosurface values resp. the volume data @var{val} and the iso -## level @var{iso}. It is considered that the volume data @var{val} is -## given at the points @var{x}, @var{y} and @var{z} which are of type -## three--dimensional numeric arrays. The orientation of the triangles -## is choosen such that the normals point from the higher values to the -## lower values. -## -## Optionally the color data @var{col} can be passed to this function -## whereas computed vertices color data @var{c} is returned as third -## argument. -## -## The marching cube algorithm is well known and described, for example, at -## Wikipedia. The triangulation lookup table and the edge table used -## here are based on Cory Gene Bloyd's implementation and can be found -## beyond other surface and geometry stuff at Paul Bourke's website -## @uref{http://local.wasp.uwa.edu.au/~pbourke/geometry/polygonise}. -## -## For example: -## -## @example -## @group -## N = 20; -## lin = linspace(0, 2, N); -## [x, y, z] = meshgrid (lin, lin, lin); -## -## c = (x-.5).^2 + (y-.5).^2 + (z-.5).^2; -## [t, p] = __marching_cube__ (x, y, z, c, .5); -## -## figure (); -## trimesh (t, p(:,1), p(:,2), p(:,3)); -## @end group -## @end example -## -## Instead of the @command{trimesh} function the @command{patch} -## function can be used to visualize the geometry. For example: -## -## @example -## @group -## figure (); view (-38, 20); -## pa = patch ("Faces", t, "Vertices", p, "FaceVertexCData", p, \ -## "FaceColor", "interp", "EdgeColor", "none"); -## -## ## Revert normals -## set (pa, "VertexNormals", -get(pa, "VertexNormals")); -## -## ## Set lightning (available with the JHandles package) -## # set (pa, "FaceLighting", "gouraud"); -## # light( "Position", [1 1 5]); -## @end group -## @end example -## -## @end deftypefn - -## Author: Martin Helm - -function [T, p, col] = __marching_cube__ (xx, yy, zz, c, iso, colors) - - persistent edge_table=[]; - persistent tri_table=[]; - - calc_cols = false; - lindex = 4; - - if (isempty (tri_table) || isempty (edge_table)) - [edge_table, tri_table] = init_mc (); - endif - - if ((nargin != 5 && nargin != 6) || (nargout != 2 && nargout != 3)) - print_usage (); - endif - - if (!ismatrix (xx) || !ismatrix (yy) || !ismatrix (zz) || !ismatrix (c) || ... - ndims (xx) != 3 || ndims (yy) != 3 || ndims (zz) != 3 || ndims (c) != 3) - error ("__marching_cube__: XX, YY, ZZ, C must be matrices of dim 3"); - endif - - if (!size_equal (xx, yy, zz, c)) - error ("__marching_cube__: XX, YY, ZZ, C must be of equal size"); - endif - - if (any (size (xx) < [2 2 2])) - error ("__marching_cube__: grid size must be at least 2x2x2"); - endif - - if (!isscalar (iso)) - error ("__marching_cube__: ISO must be scalar value"); - endif - - if (nargin == 6) - if ( !ismatrix (colors) || ndims (colors) != 3 || size (colors) != size (c) ) - error ( "COLORS must be a matrix of dim 3 and of same size as C" ); - endif - calc_cols = true; - lindex = 5; - endif - - n = size (c) - 1; - - ## phase I: assign information to each voxel which edges are intersected by - ## the isosurface - cc = zeros (n(1), n(2), n(3), "uint16"); - cedge = zeros (size (cc), "uint16"); - - vertex_idx = {1:n(1), 1:n(2), 1:n(3); ... - 2:n(1)+1, 1:n(2), 1:n(3); ... - 2:n(1)+1, 2:n(2)+1, 1:n(3); ... - 1:n(1), 2:n(2)+1, 1:n(3); ... - 1:n(1), 1:n(2), 2:n(3)+1; ... - 2:n(1)+1, 1:n(2), 2:n(3)+1; ... - 2:n(1)+1, 2:n(2)+1, 2:n(3)+1; ... - 1:n(1), 2:n(2)+1, 2:n(3)+1 }; - - ## calculate which vertices have values higher than iso - for ii=1:8 - idx = c(vertex_idx{ii, :}) > iso; - cc(idx) = bitset (cc(idx), ii); - endfor - - cedge = edge_table(cc+1); # assign the info about intersected edges - id = find (cedge); # select only voxels which are intersected - if (isempty (id)) - T = p = col = []; - return - endif - - ## phase II: calculate the list of intersection points - xyz_off = [1, 1, 1; 2, 1, 1; 2, 2, 1; 1, 2, 1; 1, 1, 2; 2, 1, 2; 2, 2, 2; 1, 2, 2]; - edges = [1 2; 2 3; 3 4; 4 1; 5 6; 6 7; 7 8; 8 5; 1 5; 2 6; 3 7; 4 8]; - offset = sub2ind (size (c), xyz_off(:, 1), xyz_off(:, 2), xyz_off(:, 3)) -1; - pp = zeros (length (id), lindex, 12); - ccedge = [vec(cedge(id)), id]; - ix_offset=0; - for jj=1:12 - id__ = bitget (ccedge(:, 1), jj); - id_ = ccedge(id__, 2); - [ix iy iz] = ind2sub (size (cc), id_); - id_c = sub2ind (size (c), ix, iy, iz); - id1 = id_c + offset(edges(jj, 1)); - id2 = id_c + offset(edges(jj, 2)); - if (calc_cols) - pp(id__, 1:5, jj) = [vertex_interp(iso, xx(id1), yy(id1), zz(id1), ... - xx(id2), yy(id2), zz(id2), c(id1), c(id2), colors(id1), colors(id2)), ... - (1:size (id_, 1))' + ix_offset ]; - else - pp(id__, 1:4, jj) = [vertex_interp(iso, xx(id1), yy(id1), zz(id1), ... - xx(id2), yy(id2), zz(id2), c(id1), c(id2)), ... - (1:size (id_, 1))' + ix_offset ]; - endif - ix_offset += size (id_, 1); - endfor - - ## phase III: calculate the triangulation from the point list - T = []; - tri = tri_table(cc(id)+1, :); - for jj=1:3:15 - id_ = find (tri(:, jj)>0); - p = [id_, lindex*ones(size (id_, 1), 1),tri(id_, jj:jj+2)]; - if (!isempty (p)) - p1 = sub2ind (size (pp), p(:,1), p(:,2), p(:,3)); - p2 = sub2ind (size (pp), p(:,1), p(:,2), p(:,4)); - p3 = sub2ind (size (pp), p(:,1), p(:,2), p(:,5)); - T = [T; pp(p1), pp(p2), pp(p3)]; - endif - endfor - - p = []; - col = []; - for jj = 1:12 - idp = pp(:, lindex, jj) > 0; - if (any (idp)) - p(pp(idp, lindex, jj), 1:3) = pp(idp, 1:3, jj); - if (calc_cols) - col(pp(idp, lindex, jj),1) = pp(idp, 4, jj); - endif - endif - endfor -endfunction - -function p = vertex_interp(isolevel,p1x, p1y, p1z,... - p2x, p2y, p2z,valp1,valp2, col1, col2) - - if (nargin == 9) - p = zeros (length (p1x), 3); - elseif (nargin == 11) - p = zeros (length (p1x), 4); - else - error ("__marching_cube__: wrong number of arguments"); - endif - mu = zeros (length (p1x), 1); - id = abs (valp1-valp2) < (10*eps) .* (abs (valp1) .+ abs (valp2)); - if (any (id)) - p(id, 1:3) = [ p1x(id), p1y(id), p1z(id) ]; - if (nargin == 11) - p(id, 4) = col1(id); - endif - endif - nid = !id; - if (any (nid)) - mu(nid) = (isolevel - valp1(nid)) ./ (valp2(nid) - valp1(nid)); - p(nid, 1:3) = [p1x(nid) + mu(nid) .* (p2x(nid) - p1x(nid)), ... - p1y(nid) + mu(nid) .* (p2y(nid) - p1y(nid)), ... - p1z(nid) + mu(nid) .* (p2z(nid) - p1z(nid))]; - if (nargin == 11) - p(nid, 4) = col1(nid) + mu(nid) .* (col2(nid) - col1(nid)); - endif - endif -endfunction - -function [edge_table, tri_table] = init_mc() - edge_table = [ - 0x0 , 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c, ... - 0x80c, 0x905, 0xa0f, 0xb06, 0xc0a, 0xd03, 0xe09, 0xf00, ... - 0x190, 0x99 , 0x393, 0x29a, 0x596, 0x49f, 0x795, 0x69c, ... - 0x99c, 0x895, 0xb9f, 0xa96, 0xd9a, 0xc93, 0xf99, 0xe90, ... - 0x230, 0x339, 0x33 , 0x13a, 0x636, 0x73f, 0x435, 0x53c, ... - 0xa3c, 0xb35, 0x83f, 0x936, 0xe3a, 0xf33, 0xc39, 0xd30, ... - 0x3a0, 0x2a9, 0x1a3, 0xaa , 0x7a6, 0x6af, 0x5a5, 0x4ac, ... - 0xbac, 0xaa5, 0x9af, 0x8a6, 0xfaa, 0xea3, 0xda9, 0xca0, ... - 0x460, 0x569, 0x663, 0x76a, 0x66 , 0x16f, 0x265, 0x36c, ... - 0xc6c, 0xd65, 0xe6f, 0xf66, 0x86a, 0x963, 0xa69, 0xb60, ... - 0x5f0, 0x4f9, 0x7f3, 0x6fa, 0x1f6, 0xff , 0x3f5, 0x2fc, ... - 0xdfc, 0xcf5, 0xfff, 0xef6, 0x9fa, 0x8f3, 0xbf9, 0xaf0, ... - 0x650, 0x759, 0x453, 0x55a, 0x256, 0x35f, 0x55 , 0x15c, ... - 0xe5c, 0xf55, 0xc5f, 0xd56, 0xa5a, 0xb53, 0x859, 0x950, ... - 0x7c0, 0x6c9, 0x5c3, 0x4ca, 0x3c6, 0x2cf, 0x1c5, 0xcc , ... - 0xfcc, 0xec5, 0xdcf, 0xcc6, 0xbca, 0xac3, 0x9c9, 0x8c0, ... - 0x8c0, 0x9c9, 0xac3, 0xbca, 0xcc6, 0xdcf, 0xec5, 0xfcc, ... - 0xcc , 0x1c5, 0x2cf, 0x3c6, 0x4ca, 0x5c3, 0x6c9, 0x7c0, ... - 0x950, 0x859, 0xb53, 0xa5a, 0xd56, 0xc5f, 0xf55, 0xe5c, ... - 0x15c, 0x55 , 0x35f, 0x256, 0x55a, 0x453, 0x759, 0x650, ... - 0xaf0, 0xbf9, 0x8f3, 0x9fa, 0xef6, 0xfff, 0xcf5, 0xdfc, ... - 0x2fc, 0x3f5, 0xff , 0x1f6, 0x6fa, 0x7f3, 0x4f9, 0x5f0, ... - 0xb60, 0xa69, 0x963, 0x86a, 0xf66, 0xe6f, 0xd65, 0xc6c, ... - 0x36c, 0x265, 0x16f, 0x66 , 0x76a, 0x663, 0x569, 0x460, ... - 0xca0, 0xda9, 0xea3, 0xfaa, 0x8a6, 0x9af, 0xaa5, 0xbac, ... - 0x4ac, 0x5a5, 0x6af, 0x7a6, 0xaa , 0x1a3, 0x2a9, 0x3a0, ... - 0xd30, 0xc39, 0xf33, 0xe3a, 0x936, 0x83f, 0xb35, 0xa3c, ... - 0x53c, 0x435, 0x73f, 0x636, 0x13a, 0x33 , 0x339, 0x230, ... - 0xe90, 0xf99, 0xc93, 0xd9a, 0xa96, 0xb9f, 0x895, 0x99c, ... - 0x69c, 0x795, 0x49f, 0x596, 0x29a, 0x393, 0x99 , 0x190, ... - 0xf00, 0xe09, 0xd03, 0xc0a, 0xb06, 0xa0f, 0x905, 0x80c, ... - 0x70c, 0x605, 0x50f, 0x406, 0x30a, 0x203, 0x109, 0x0 ]; - - tri_table =[ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 1, 8, 3, 9, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 0, 8, 3, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 9, 2, 10, 0, 2, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 2, 8, 3, 2, 10, 8, 10, 9, 8, -1, -1, -1, -1, -1, -1, -1; - 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 0, 11, 2, 8, 11, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 1, 9, 0, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 1, 11, 2, 1, 9, 11, 9, 8, 11, -1, -1, -1, -1, -1, -1, -1; - 3, 10, 1, 11, 10, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 0, 10, 1, 0, 8, 10, 8, 11, 10, -1, -1, -1, -1, -1, -1, -1; - 3, 9, 0, 3, 11, 9, 11, 10, 9, -1, -1, -1, -1, -1, -1, -1; - 9, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 4, 3, 0, 7, 3, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 0, 1, 9, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 4, 1, 9, 4, 7, 1, 7, 3, 1, -1, -1, -1, -1, -1, -1, -1; - 1, 2, 10, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 3, 4, 7, 3, 0, 4, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1; - 9, 2, 10, 9, 0, 2, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1; - 2, 10, 9, 2, 9, 7, 2, 7, 3, 7, 9, 4, -1, -1, -1, -1; - 8, 4, 7, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 11, 4, 7, 11, 2, 4, 2, 0, 4, -1, -1, -1, -1, -1, -1, -1; - 9, 0, 1, 8, 4, 7, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1; - 4, 7, 11, 9, 4, 11, 9, 11, 2, 9, 2, 1, -1, -1, -1, -1; - 3, 10, 1, 3, 11, 10, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1; - 1, 11, 10, 1, 4, 11, 1, 0, 4, 7, 11, 4, -1, -1, -1, -1; - 4, 7, 8, 9, 0, 11, 9, 11, 10, 11, 0, 3, -1, -1, -1, -1; - 4, 7, 11, 4, 11, 9, 9, 11, 10, -1, -1, -1, -1, -1, -1, -1; - 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 9, 5, 4, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 0, 5, 4, 1, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 8, 5, 4, 8, 3, 5, 3, 1, 5, -1, -1, -1, -1, -1, -1, -1; - 1, 2, 10, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 3, 0, 8, 1, 2, 10, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1; - 5, 2, 10, 5, 4, 2, 4, 0, 2, -1, -1, -1, -1, -1, -1, -1; - 2, 10, 5, 3, 2, 5, 3, 5, 4, 3, 4, 8, -1, -1, -1, -1; - 9, 5, 4, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 0, 11, 2, 0, 8, 11, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1; - 0, 5, 4, 0, 1, 5, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1; - 2, 1, 5, 2, 5, 8, 2, 8, 11, 4, 8, 5, -1, -1, -1, -1; - 10, 3, 11, 10, 1, 3, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1; - 4, 9, 5, 0, 8, 1, 8, 10, 1, 8, 11, 10, -1, -1, -1, -1; - 5, 4, 0, 5, 0, 11, 5, 11, 10, 11, 0, 3, -1, -1, -1, -1; - 5, 4, 8, 5, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1; - 9, 7, 8, 5, 7, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 9, 3, 0, 9, 5, 3, 5, 7, 3, -1, -1, -1, -1, -1, -1, -1; - 0, 7, 8, 0, 1, 7, 1, 5, 7, -1, -1, -1, -1, -1, -1, -1; - 1, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 9, 7, 8, 9, 5, 7, 10, 1, 2, -1, -1, -1, -1, -1, -1, -1; - 10, 1, 2, 9, 5, 0, 5, 3, 0, 5, 7, 3, -1, -1, -1, -1; - 8, 0, 2, 8, 2, 5, 8, 5, 7, 10, 5, 2, -1, -1, -1, -1; - 2, 10, 5, 2, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1; - 7, 9, 5, 7, 8, 9, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1; - 9, 5, 7, 9, 7, 2, 9, 2, 0, 2, 7, 11, -1, -1, -1, -1; - 2, 3, 11, 0, 1, 8, 1, 7, 8, 1, 5, 7, -1, -1, -1, -1; - 11, 2, 1, 11, 1, 7, 7, 1, 5, -1, -1, -1, -1, -1, -1, -1; - 9, 5, 8, 8, 5, 7, 10, 1, 3, 10, 3, 11, -1, -1, -1, -1; - 5, 7, 0, 5, 0, 9, 7, 11, 0, 1, 0, 10, 11, 10, 0, -1; - 11, 10, 0, 11, 0, 3, 10, 5, 0, 8, 0, 7, 5, 7, 0, -1; - 11, 10, 5, 7, 11, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 0, 8, 3, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 9, 0, 1, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 1, 8, 3, 1, 9, 8, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1; - 1, 6, 5, 2, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 1, 6, 5, 1, 2, 6, 3, 0, 8, -1, -1, -1, -1, -1, -1, -1; - 9, 6, 5, 9, 0, 6, 0, 2, 6, -1, -1, -1, -1, -1, -1, -1; - 5, 9, 8, 5, 8, 2, 5, 2, 6, 3, 2, 8, -1, -1, -1, -1; - 2, 3, 11, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 11, 0, 8, 11, 2, 0, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1; - 0, 1, 9, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1; - 5, 10, 6, 1, 9, 2, 9, 11, 2, 9, 8, 11, -1, -1, -1, -1; - 6, 3, 11, 6, 5, 3, 5, 1, 3, -1, -1, -1, -1, -1, -1, -1; - 0, 8, 11, 0, 11, 5, 0, 5, 1, 5, 11, 6, -1, -1, -1, -1; - 3, 11, 6, 0, 3, 6, 0, 6, 5, 0, 5, 9, -1, -1, -1, -1; - 6, 5, 9, 6, 9, 11, 11, 9, 8, -1, -1, -1, -1, -1, -1, -1; - 5, 10, 6, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 4, 3, 0, 4, 7, 3, 6, 5, 10, -1, -1, -1, -1, -1, -1, -1; - 1, 9, 0, 5, 10, 6, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1; - 10, 6, 5, 1, 9, 7, 1, 7, 3, 7, 9, 4, -1, -1, -1, -1; - 6, 1, 2, 6, 5, 1, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1; - 1, 2, 5, 5, 2, 6, 3, 0, 4, 3, 4, 7, -1, -1, -1, -1; - 8, 4, 7, 9, 0, 5, 0, 6, 5, 0, 2, 6, -1, -1, -1, -1; - 7, 3, 9, 7, 9, 4, 3, 2, 9, 5, 9, 6, 2, 6, 9, -1; - 3, 11, 2, 7, 8, 4, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1; - 5, 10, 6, 4, 7, 2, 4, 2, 0, 2, 7, 11, -1, -1, -1, -1; - 0, 1, 9, 4, 7, 8, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1; - 9, 2, 1, 9, 11, 2, 9, 4, 11, 7, 11, 4, 5, 10, 6, -1; - 8, 4, 7, 3, 11, 5, 3, 5, 1, 5, 11, 6, -1, -1, -1, -1; - 5, 1, 11, 5, 11, 6, 1, 0, 11, 7, 11, 4, 0, 4, 11, -1; - 0, 5, 9, 0, 6, 5, 0, 3, 6, 11, 6, 3, 8, 4, 7, -1; - 6, 5, 9, 6, 9, 11, 4, 7, 9, 7, 11, 9, -1, -1, -1, -1; - 10, 4, 9, 6, 4, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 4, 10, 6, 4, 9, 10, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1; - 10, 0, 1, 10, 6, 0, 6, 4, 0, -1, -1, -1, -1, -1, -1, -1; - 8, 3, 1, 8, 1, 6, 8, 6, 4, 6, 1, 10, -1, -1, -1, -1; - 1, 4, 9, 1, 2, 4, 2, 6, 4, -1, -1, -1, -1, -1, -1, -1; - 3, 0, 8, 1, 2, 9, 2, 4, 9, 2, 6, 4, -1, -1, -1, -1; - 0, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 8, 3, 2, 8, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1; - 10, 4, 9, 10, 6, 4, 11, 2, 3, -1, -1, -1, -1, -1, -1, -1; - 0, 8, 2, 2, 8, 11, 4, 9, 10, 4, 10, 6, -1, -1, -1, -1; - 3, 11, 2, 0, 1, 6, 0, 6, 4, 6, 1, 10, -1, -1, -1, -1; - 6, 4, 1, 6, 1, 10, 4, 8, 1, 2, 1, 11, 8, 11, 1, -1; - 9, 6, 4, 9, 3, 6, 9, 1, 3, 11, 6, 3, -1, -1, -1, -1; - 8, 11, 1, 8, 1, 0, 11, 6, 1, 9, 1, 4, 6, 4, 1, -1; - 3, 11, 6, 3, 6, 0, 0, 6, 4, -1, -1, -1, -1, -1, -1, -1; - 6, 4, 8, 11, 6, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 7, 10, 6, 7, 8, 10, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1; - 0, 7, 3, 0, 10, 7, 0, 9, 10, 6, 7, 10, -1, -1, -1, -1; - 10, 6, 7, 1, 10, 7, 1, 7, 8, 1, 8, 0, -1, -1, -1, -1; - 10, 6, 7, 10, 7, 1, 1, 7, 3, -1, -1, -1, -1, -1, -1, -1; - 1, 2, 6, 1, 6, 8, 1, 8, 9, 8, 6, 7, -1, -1, -1, -1; - 2, 6, 9, 2, 9, 1, 6, 7, 9, 0, 9, 3, 7, 3, 9, -1; - 7, 8, 0, 7, 0, 6, 6, 0, 2, -1, -1, -1, -1, -1, -1, -1; - 7, 3, 2, 6, 7, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 2, 3, 11, 10, 6, 8, 10, 8, 9, 8, 6, 7, -1, -1, -1, -1; - 2, 0, 7, 2, 7, 11, 0, 9, 7, 6, 7, 10, 9, 10, 7, -1; - 1, 8, 0, 1, 7, 8, 1, 10, 7, 6, 7, 10, 2, 3, 11, -1; - 11, 2, 1, 11, 1, 7, 10, 6, 1, 6, 7, 1, -1, -1, -1, -1; - 8, 9, 6, 8, 6, 7, 9, 1, 6, 11, 6, 3, 1, 3, 6, -1; - 0, 9, 1, 11, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 7, 8, 0, 7, 0, 6, 3, 11, 0, 11, 6, 0, -1, -1, -1, -1; - 7, 11, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 3, 0, 8, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 0, 1, 9, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 8, 1, 9, 8, 3, 1, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1; - 10, 1, 2, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 1, 2, 10, 3, 0, 8, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1; - 2, 9, 0, 2, 10, 9, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1; - 6, 11, 7, 2, 10, 3, 10, 8, 3, 10, 9, 8, -1, -1, -1, -1; - 7, 2, 3, 6, 2, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 7, 0, 8, 7, 6, 0, 6, 2, 0, -1, -1, -1, -1, -1, -1, -1; - 2, 7, 6, 2, 3, 7, 0, 1, 9, -1, -1, -1, -1, -1, -1, -1; - 1, 6, 2, 1, 8, 6, 1, 9, 8, 8, 7, 6, -1, -1, -1, -1; - 10, 7, 6, 10, 1, 7, 1, 3, 7, -1, -1, -1, -1, -1, -1, -1; - 10, 7, 6, 1, 7, 10, 1, 8, 7, 1, 0, 8, -1, -1, -1, -1; - 0, 3, 7, 0, 7, 10, 0, 10, 9, 6, 10, 7, -1, -1, -1, -1; - 7, 6, 10, 7, 10, 8, 8, 10, 9, -1, -1, -1, -1, -1, -1, -1; - 6, 8, 4, 11, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 3, 6, 11, 3, 0, 6, 0, 4, 6, -1, -1, -1, -1, -1, -1, -1; - 8, 6, 11, 8, 4, 6, 9, 0, 1, -1, -1, -1, -1, -1, -1, -1; - 9, 4, 6, 9, 6, 3, 9, 3, 1, 11, 3, 6, -1, -1, -1, -1; - 6, 8, 4, 6, 11, 8, 2, 10, 1, -1, -1, -1, -1, -1, -1, -1; - 1, 2, 10, 3, 0, 11, 0, 6, 11, 0, 4, 6, -1, -1, -1, -1; - 4, 11, 8, 4, 6, 11, 0, 2, 9, 2, 10, 9, -1, -1, -1, -1; - 10, 9, 3, 10, 3, 2, 9, 4, 3, 11, 3, 6, 4, 6, 3, -1; - 8, 2, 3, 8, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1; - 0, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 1, 9, 0, 2, 3, 4, 2, 4, 6, 4, 3, 8, -1, -1, -1, -1; - 1, 9, 4, 1, 4, 2, 2, 4, 6, -1, -1, -1, -1, -1, -1, -1; - 8, 1, 3, 8, 6, 1, 8, 4, 6, 6, 10, 1, -1, -1, -1, -1; - 10, 1, 0, 10, 0, 6, 6, 0, 4, -1, -1, -1, -1, -1, -1, -1; - 4, 6, 3, 4, 3, 8, 6, 10, 3, 0, 3, 9, 10, 9, 3, -1; - 10, 9, 4, 6, 10, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 4, 9, 5, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 0, 8, 3, 4, 9, 5, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1; - 5, 0, 1, 5, 4, 0, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1; - 11, 7, 6, 8, 3, 4, 3, 5, 4, 3, 1, 5, -1, -1, -1, -1; - 9, 5, 4, 10, 1, 2, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1; - 6, 11, 7, 1, 2, 10, 0, 8, 3, 4, 9, 5, -1, -1, -1, -1; - 7, 6, 11, 5, 4, 10, 4, 2, 10, 4, 0, 2, -1, -1, -1, -1; - 3, 4, 8, 3, 5, 4, 3, 2, 5, 10, 5, 2, 11, 7, 6, -1; - 7, 2, 3, 7, 6, 2, 5, 4, 9, -1, -1, -1, -1, -1, -1, -1; - 9, 5, 4, 0, 8, 6, 0, 6, 2, 6, 8, 7, -1, -1, -1, -1; - 3, 6, 2, 3, 7, 6, 1, 5, 0, 5, 4, 0, -1, -1, -1, -1; - 6, 2, 8, 6, 8, 7, 2, 1, 8, 4, 8, 5, 1, 5, 8, -1; - 9, 5, 4, 10, 1, 6, 1, 7, 6, 1, 3, 7, -1, -1, -1, -1; - 1, 6, 10, 1, 7, 6, 1, 0, 7, 8, 7, 0, 9, 5, 4, -1; - 4, 0, 10, 4, 10, 5, 0, 3, 10, 6, 10, 7, 3, 7, 10, -1; - 7, 6, 10, 7, 10, 8, 5, 4, 10, 4, 8, 10, -1, -1, -1, -1; - 6, 9, 5, 6, 11, 9, 11, 8, 9, -1, -1, -1, -1, -1, -1, -1; - 3, 6, 11, 0, 6, 3, 0, 5, 6, 0, 9, 5, -1, -1, -1, -1; - 0, 11, 8, 0, 5, 11, 0, 1, 5, 5, 6, 11, -1, -1, -1, -1; - 6, 11, 3, 6, 3, 5, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1; - 1, 2, 10, 9, 5, 11, 9, 11, 8, 11, 5, 6, -1, -1, -1, -1; - 0, 11, 3, 0, 6, 11, 0, 9, 6, 5, 6, 9, 1, 2, 10, -1; - 11, 8, 5, 11, 5, 6, 8, 0, 5, 10, 5, 2, 0, 2, 5, -1; - 6, 11, 3, 6, 3, 5, 2, 10, 3, 10, 5, 3, -1, -1, -1, -1; - 5, 8, 9, 5, 2, 8, 5, 6, 2, 3, 8, 2, -1, -1, -1, -1; - 9, 5, 6, 9, 6, 0, 0, 6, 2, -1, -1, -1, -1, -1, -1, -1; - 1, 5, 8, 1, 8, 0, 5, 6, 8, 3, 8, 2, 6, 2, 8, -1; - 1, 5, 6, 2, 1, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 1, 3, 6, 1, 6, 10, 3, 8, 6, 5, 6, 9, 8, 9, 6, -1; - 10, 1, 0, 10, 0, 6, 9, 5, 0, 5, 6, 0, -1, -1, -1, -1; - 0, 3, 8, 5, 6, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 10, 5, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 11, 5, 10, 7, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 11, 5, 10, 11, 7, 5, 8, 3, 0, -1, -1, -1, -1, -1, -1, -1; - 5, 11, 7, 5, 10, 11, 1, 9, 0, -1, -1, -1, -1, -1, -1, -1; - 10, 7, 5, 10, 11, 7, 9, 8, 1, 8, 3, 1, -1, -1, -1, -1; - 11, 1, 2, 11, 7, 1, 7, 5, 1, -1, -1, -1, -1, -1, -1, -1; - 0, 8, 3, 1, 2, 7, 1, 7, 5, 7, 2, 11, -1, -1, -1, -1; - 9, 7, 5, 9, 2, 7, 9, 0, 2, 2, 11, 7, -1, -1, -1, -1; - 7, 5, 2, 7, 2, 11, 5, 9, 2, 3, 2, 8, 9, 8, 2, -1; - 2, 5, 10, 2, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1; - 8, 2, 0, 8, 5, 2, 8, 7, 5, 10, 2, 5, -1, -1, -1, -1; - 9, 0, 1, 5, 10, 3, 5, 3, 7, 3, 10, 2, -1, -1, -1, -1; - 9, 8, 2, 9, 2, 1, 8, 7, 2, 10, 2, 5, 7, 5, 2, -1; - 1, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 0, 8, 7, 0, 7, 1, 1, 7, 5, -1, -1, -1, -1, -1, -1, -1; - 9, 0, 3, 9, 3, 5, 5, 3, 7, -1, -1, -1, -1, -1, -1, -1; - 9, 8, 7, 5, 9, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 5, 8, 4, 5, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1; - 5, 0, 4, 5, 11, 0, 5, 10, 11, 11, 3, 0, -1, -1, -1, -1; - 0, 1, 9, 8, 4, 10, 8, 10, 11, 10, 4, 5, -1, -1, -1, -1; - 10, 11, 4, 10, 4, 5, 11, 3, 4, 9, 4, 1, 3, 1, 4, -1; - 2, 5, 1, 2, 8, 5, 2, 11, 8, 4, 5, 8, -1, -1, -1, -1; - 0, 4, 11, 0, 11, 3, 4, 5, 11, 2, 11, 1, 5, 1, 11, -1; - 0, 2, 5, 0, 5, 9, 2, 11, 5, 4, 5, 8, 11, 8, 5, -1; - 9, 4, 5, 2, 11, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 2, 5, 10, 3, 5, 2, 3, 4, 5, 3, 8, 4, -1, -1, -1, -1; - 5, 10, 2, 5, 2, 4, 4, 2, 0, -1, -1, -1, -1, -1, -1, -1; - 3, 10, 2, 3, 5, 10, 3, 8, 5, 4, 5, 8, 0, 1, 9, -1; - 5, 10, 2, 5, 2, 4, 1, 9, 2, 9, 4, 2, -1, -1, -1, -1; - 8, 4, 5, 8, 5, 3, 3, 5, 1, -1, -1, -1, -1, -1, -1, -1; - 0, 4, 5, 1, 0, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 8, 4, 5, 8, 5, 3, 9, 0, 5, 0, 3, 5, -1, -1, -1, -1; - 9, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 4, 11, 7, 4, 9, 11, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1; - 0, 8, 3, 4, 9, 7, 9, 11, 7, 9, 10, 11, -1, -1, -1, -1; - 1, 10, 11, 1, 11, 4, 1, 4, 0, 7, 4, 11, -1, -1, -1, -1; - 3, 1, 4, 3, 4, 8, 1, 10, 4, 7, 4, 11, 10, 11, 4, -1; - 4, 11, 7, 9, 11, 4, 9, 2, 11, 9, 1, 2, -1, -1, -1, -1; - 9, 7, 4, 9, 11, 7, 9, 1, 11, 2, 11, 1, 0, 8, 3, -1; - 11, 7, 4, 11, 4, 2, 2, 4, 0, -1, -1, -1, -1, -1, -1, -1; - 11, 7, 4, 11, 4, 2, 8, 3, 4, 3, 2, 4, -1, -1, -1, -1; - 2, 9, 10, 2, 7, 9, 2, 3, 7, 7, 4, 9, -1, -1, -1, -1; - 9, 10, 7, 9, 7, 4, 10, 2, 7, 8, 7, 0, 2, 0, 7, -1; - 3, 7, 10, 3, 10, 2, 7, 4, 10, 1, 10, 0, 4, 0, 10, -1; - 1, 10, 2, 8, 7, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 4, 9, 1, 4, 1, 7, 7, 1, 3, -1, -1, -1, -1, -1, -1, -1; - 4, 9, 1, 4, 1, 7, 0, 8, 1, 8, 7, 1, -1, -1, -1, -1; - 4, 0, 3, 7, 4, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 4, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 9, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 3, 0, 9, 3, 9, 11, 11, 9, 10, -1, -1, -1, -1, -1, -1, -1; - 0, 1, 10, 0, 10, 8, 8, 10, 11, -1, -1, -1, -1, -1, -1, -1; - 3, 1, 10, 11, 3, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 1, 2, 11, 1, 11, 9, 9, 11, 8, -1, -1, -1, -1, -1, -1, -1; - 3, 0, 9, 3, 9, 11, 1, 2, 9, 2, 11, 9, -1, -1, -1, -1; - 0, 2, 11, 8, 0, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 3, 2, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 2, 3, 8, 2, 8, 10, 10, 8, 9, -1, -1, -1, -1, -1, -1, -1; - 9, 10, 2, 0, 9, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 2, 3, 8, 2, 8, 10, 0, 1, 8, 1, 10, 8, -1, -1, -1, -1; - 1, 10, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 1, 3, 8, 9, 1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 0, 9, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - 0, 3, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ] + 1; -endfunction diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/__next_line_color__.m --- a/scripts/plot/__next_line_color__.m Sat Jul 16 09:16:52 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -## Copyright (C) 2007-2011 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 3 of the License, 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, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {@var{rgb} =} __next_line_color__ (@var{reset}) -## Undocumented internal function. -## @end deftypefn - -## Return the next line color in the rotation. - -## Author: jwe - -function rgb = __next_line_color__ (reset) - - persistent color_rotation; - persistent num_colors; - persistent color_index; - - if (nargin < 2) - if (nargin == 1) - if (reset || isempty (color_rotation)) - color_rotation = get (gca (), "colororder"); - num_colors = rows (color_rotation); - color_index = 1; - endif - elseif (! isempty (color_rotation)) - rgb = color_rotation(color_index,:); - if (++color_index > num_colors) - color_index = 1; - __next_line_style__ ("incr"); - endif - else - error ("__next_line_color__: color_rotation not initialized"); - endif - else - print_usage (); - endif - -endfunction diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/__next_line_style__.m --- a/scripts/plot/__next_line_style__.m Sat Jul 16 09:16:52 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -## Copyright (C) 2010-2011 David Bateman -## -## 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 3 of the License, 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, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {@var{style} =} __next_line_style__ (@var{reset}) -## Undocumented internal function. -## @end deftypefn - -## Return the next line style in the rotation. - - -function [linestyle, marker] = __next_line_style__ (reset) - - persistent style_rotation; - persistent num_styles; - persistent style_index; - - if (nargin < 2) - if (nargin == 1) - if (ischar (reset) && strncmp (reset, "incr", 4)) - if (isempty (style_rotation)) - error ("__next_line_style__: style_rotation not initialized"); - elseif (++style_index > num_styles) - style_index = 1; - endif - elseif (reset || isempty (style_rotation)) - style_rotation = strsplit (get (gca (), "linestyleorder"), "|"); - num_styles = length (style_rotation); - style_index = 1; - endif - elseif (! isempty (style_rotation)) - options = __pltopt__ ("__next_line_style__", - style_rotation (style_index)); - linestyle = options.linestyle; - marker = options.marker; - else - error ("__next_line_style__: style_rotation not initialized"); - endif - else - print_usage (); - endif - -endfunction diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/__print_parse_opts__.m --- a/scripts/plot/__print_parse_opts__.m Sat Jul 16 09:16:52 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,609 +0,0 @@ -## Copyright (C) 2008-2011 David Bateman -## -## 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 3 of the License, 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, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {[@var{x}, @var{y}, @var{buttons}] =} ginput (@var{n}) -## Return which mouse buttons were pressed and keys were hit on the current -## figure. If @var{n} is defined, then wait for @var{n} mouse clicks -## before returning. If @var{n} is not defined, then @code{ginput} will -## loop until the return key is pressed. -## @end deftypefn - -function arg_st = __print_parse_opts__ (varargin) - - persistent warn_on_missing_binary = true - - arg_st.append_to_file = false; - arg_st.canvas_size = []; - arg_st.debug = false; - arg_st.debug_file = "octave-print-commands.log"; - arg_st.devopt = ""; - arg_st.epstool_binary = __quote_path__ (__find_binary__ ("epstool")); - arg_st.figure = get (0, "currentfigure"); - arg_st.fig2dev_binary = __quote_path__ (__find_binary__ ("fig2dev")); - arg_st.fontsize = ""; - arg_st.font = ""; - arg_st.force_solid = 0; # 0=default, -1=dashed, +1=solid - arg_st.formatted_for_printing = false; - arg_st.ghostscript.binary = __quote_path__ (__ghostscript_binary__ ()); - arg_st.ghostscript.debug = false; - arg_st.ghostscript.device = ""; - arg_st.ghostscript.epscrop = true; - arg_st.ghostscript.level = []; - arg_st.ghostscript.output = ""; - arg_st.ghostscript.papersize = ""; - arg_st.ghostscript.pageoffset = []; - arg_st.ghostscript.resolution = 150; - arg_st.ghostscript.antialiasing = false; - arg_st.loose = false; - arg_st.lpr_binary = __quote_path__ (__find_binary__ ("lpr")); - arg_st.name = ""; - arg_st.orientation = ""; - arg_st.pstoedit_binary = __quote_path__ (__find_binary__ ("pstoedit")); - arg_st.preview = ""; - arg_st.printer = ""; - arg_st.send_to_printer = false; - arg_st.special_flag = "textnormal"; - arg_st.tight_flag = false; - arg_st.use_color = 0; # 0=default, -1=mono, +1=color - - if (isunix ()) - arg_st.lpr_options = "-l"; - elseif (ispc ()) - arg_st.lpr_options = "-o l"; - else - arg_st.lpr_options = ""; - endif - arg_st.unlink = {}; - - if (nargin > 0 && isfigure (varargin{1})) - arg_st.figure = varargin{1}; - varargin(1) = []; - endif - - for i = 1:numel(varargin) - arg = strtrim (varargin{i}); - if (ischar (arg)) - if (strcmp (arg, "-color")) - arg_st.use_color = 1; - elseif (strcmp (arg, "-append")) - arg_st.append_to_file = true; - elseif (strcmp (arg, "-mono")) - arg_st.use_color = -1; - elseif (strcmp (arg, "-solid")) - arg_st.force_solid = 1; - elseif (strcmp (arg, "-dashed")) - arg_st.force_solid = -1; - elseif (strncmp (arg, "-portrait", numel (arg))) - arg_st.orientation = "portrait"; - elseif (strncmp (arg, "-landscape", numel (arg))) - arg_st.orientation = "landscape"; - elseif (strcmp (arg, "-loose")) - arg_st.loose = true; - arg_st.tight_flag = false; - elseif (strcmp (arg, "-tight")) - arg_st.loose = false; - arg_st.tight_flag = true; - elseif (strcmp (arg, "-textspecial")) - arg_st.special_flag = "textspecial"; - elseif (any (strcmp (arg, {"-interchange", "-metafile", "-pict", "-tiff"}))) - arg_st.preview = arg(2:end); - elseif (strncmp (arg, "-debug", 6)) - arg_st.debug = true; - arg_st.ghostscript.debug = true; - if (length (arg) > 7) - arg_st.debug_file = arg(8:end); - endif - elseif (length (arg) > 2 && arg(1:2) == "-d") - arg_st.devopt = tolower (arg(3:end)); - elseif (length (arg) > 2 && arg(1:2) == "-P") - arg_st.printer = arg; - elseif (strncmp (arg, "-EPSTOOL:", 9)) - arg_st.epstool_binary = arg{10:end}; - elseif (strncmp (arg, "-FIG2DEV:", 9)) - arg_st.fig2dev_binary = arg{10:end}; - elseif (strncmp (arg, "-PSTOEDIT:", 9)) - arg_st.pstoedit_binary = arg{10:end}; - elseif ((length (arg) > 2) && arg(1:2) == "-G") - arg_st.ghostscript.binary = file_in_path (getenv ("PATH"), arg(3:end)); - if (isempty (arg_st.ghostscript.binary)) - error ("print: Ghostscript binary ""%s"" could not be located", - arg(3:end)); - else - arg_st.ghostscript_binary = __quote_path__ (arg_st.ghostscript_binary); - endif - elseif (length (arg) > 2 && arg(1:2) == "-F") - idx = rindex (arg, ":"); - if (idx) - arg_st.font = arg(3:idx-1); - arg_st.fontsize = str2num (arg(idx+1:end)); - else - arg_st.font = arg(3:end); - endif - elseif (length (arg) > 2 && arg(1:2) == "-S") - arg_st.canvas_size = str2num (arg(3:end)); - elseif (length (arg) > 2 && arg(1:2) == "-r") - arg_st.ghostscript.resolution = str2double (arg(3:end)); - elseif (length (arg) > 2 && arg(1:2) == "-f") - arg_st.figure = str2num (arg(3:end)); - elseif (length (arg) >= 1 && arg(1) == "-") - error ("print: unknown option `%s'", arg); - elseif (length (arg) > 0) - arg_st.name = arg; - endif - elseif (isfigure (arg)) - arg_st.figure = arg; - else - error ("print: expecting inputs to be character string options or a figure handle"); - endif - endfor - - if (arg_st.ghostscript.resolution == 0) - ## Do as Matlab does. - arg_st.ghostscript.resolution = num2str (get (0, "screenpixelsperinch")); - endif - - if (isempty (arg_st.orientation)) - if (isfigure (arg_st.figure)) - arg_st.orientation = get (arg_st.figure, "paperorientation"); - else - ## Allows tests to be run without error. - arg_st.orientation = "portrait"; - endif - endif - - if (isempty (arg_st.ghostscript.binary)) - arg_st.ghostscript.binary = __ghostscript_binary__ (); - endif - - dot = rindex (arg_st.name, "."); - if (isempty (arg_st.devopt)) - if (dot == 0) - arg_st.devopt = "psc"; - else - arg_st.devopt = tolower (arg_st.name(dot+1:end)); - endif - endif - - if (arg_st.use_color == 0) - if (any (strcmp ({"ps", "ps2", "eps", "eps2"}, arg_st.devopt))) - arg_st.use_color = -1; - else - arg_st.use_color = 1; - endif - endif - - if (strcmp (arg_st.devopt, "tex")) - arg_st.devopt = "epslatex"; - elseif (strcmp (arg_st.devopt, "ill")) - arg_st.devopt = "aifm"; - elseif (strcmp (arg_st.devopt, "cdr")) - arg_st.devopt = "corel"; - elseif (strcmp (arg_st.devopt, "meta")) - arg_st.devopt = "emf"; - elseif (strcmp (arg_st.devopt, "jpg")) - arg_st.devopt = "jpeg"; - endif - - dev_list = {"aifm", "corel", "fig", "png", "jpeg", ... - "gif", "pbm", "pbmraw", "dxf", "mf", ... - "svg", "hpgl", "ps", "ps2", "psc", ... - "psc2", "eps", "eps2", "epsc", "epsc2", ... - "emf", "pdf", "pslatex", "epslatex", "epslatexstandalone", ... - "pslatexstandalone", "pdflatexstandalone", ... - "pstex", "tiff", "tiffn" "tikz", "pcxmono", ... - "pcx24b", "pcx256", "pcx16", "pgm", "pgmraw", ... - "ppm", "ppmraw", "pdflatex", "texdraw", ... - "pdfcairo", "pngcairo", "pstricks", ... - "epswrite", "pswrite", "ps2write", "pdfwrite"}; - - suffixes = {"ai", "cdr", "fig", "png", "jpg", ... - "gif", "pbm", "pbm", "dxf", "mf", ... - "svg", "hpgl", "ps", "ps", "ps", ... - "ps", "eps", "eps", "eps", "eps", ... - "emf", "pdf", "tex", "tex", "tex", ... - "tex", "tex", ... - "ps", "tiff", "tiff", "tikz", "pcx", ... - "pcx", "pcx", "pcx", "pgm", "pgm", ... - "ppm", "ppm", "tex", "tex", ... - "pdf", "png", "tex", ... - "eps", "ps", "ps", "pdf"}; - - if (isfigure (arg_st.figure)) - __graphics_toolkit__ = get (arg_st.figure, "__graphics_toolkit__"); - else - ## Allow tests when no figures are present. - __graphics_toolkit__ = get (0, "defaultfigure__graphics_toolkit__"); - endif - - if (strcmp (__graphics_toolkit__, "gnuplot") - && __gnuplot_has_feature__ ("epslatex_implies_eps_filesuffix")) - suffixes(strncmp (dev_list, "epslatex", 8)) = {"eps"}; - endif - - match = strcmpi (dev_list, arg_st.devopt); - if (any (match)) - default_suffix = suffixes {match}; - else - default_suffix = arg_st.devopt; - endif - - if (dot == 0 && ! isempty (arg_st.name)) - arg_st.name = strcat (arg_st.name, ".", default_suffix); - endif - - if (arg_st.append_to_file) - if (isempty (arg_st.name)) - arg_st.append_to_file = false; - elseif (any (strcmpi (arg_st.devopt, {"eps", "eps2", "epsc", "epsc2", ... - "ps", "ps2", "psc", "psc2", "pdf"}))) - have_ghostscript = ! isempty (__ghostscript_binary__ ()); - if (have_ghostscript) - file_exists = ((numel (dir (arg_st.name)) == 1) - && (! isdir (arg_st.name))); - if (! file_exists) - arg_st.append_to_file = false; - endif - else - arg_st.append_to_file = false; - warning ("print.m: appended output requires ghostscript to be installed"); - endif - else - warning ("print.m: appended output is not supported for device '%s'", - arg_st.devopt); - arg_st.append_to_file = false; - endif - endif - - if (! isempty (arg_st.printer) || isempty (arg_st.name)) - arg_st.send_to_printer = true; - endif - - if (any (strcmp (arg_st.devopt, {"ps", "ps2", "psc", "psc2", "pdf"}))) - arg_st.formatted_for_printing = true; - endif - - aliases = gs_aliases (); - if (any (strcmp (arg_st.devopt, fieldnames (aliases)))) - arg_st.devopt = aliases.(arg_st.devopt); - endif - - ## FIXME - eps2 & epsc2 needs to be handled - if (strcmp (arg_st.devopt, "pswrite")) - arg_st.ghostscript.level = 1; - elseif (strcmp (arg_st.devopt, "ps2write")) - arg_st.ghostscript.level = 2; - endif - - if ((any (strcmp (arg_st.devopt, gs_device_list)) - && ! arg_st.formatted_for_printing) - || any (strcmp (arg_st.devopt, {"pswrite", "ps2write", "pdfwrite"}))) - ## Use ghostscript for graphic formats - arg_st.ghostscript.device = arg_st.devopt; - arg_st.ghostscript.output = arg_st.name; - arg_st.ghostscript.antialiasing = true; - if (arg_st.formatted_for_printing) - arg_st.ghostscript.epscrop = ! arg_st.loose; - else - ## pstoedit throws errors if the EPS file isn't cropped - arg_st.ghostscript.epscrop = true; - endif - elseif (all (! strcmp (arg_st.devopt, dev_list))) - ## Assume we are formating output for a printer - arg_st.formatted_for_printing = true; - arg_st.ghostscript.device = arg_st.devopt; - arg_st.ghostscript.output = arg_st.name; - arg_st.ghostscript.antialiasing = false; - arg_st.ghostscript.epscrop = ! arg_st.loose; - endif - - if (isempty (arg_st.canvas_size)) - if (isfigure (arg_st.figure)) - [arg_st.ghostscript.papersize, paperposition] = ... - gs_papersize (arg_st.figure, arg_st.orientation); - else - ## allows tests to be run - arg_st.ghostscript.papersize = "letter"; - paperposition = [0.25, 2.50, 8.00, 6.00] * 72; - endif - arg_st.canvas_size = paperposition(3:4); - if (strcmp (__graphics_toolkit__, "gnuplot") && ! arg_st.ghostscript.epscrop) - arg_st.ghostscript.pageoffset = paperposition(1:2) - 50; - else - arg_st.ghostscript.pageoffset = paperposition(1:2); - endif - else - ## Convert canvas size to points from pixles. - arg_st.canvas_size = arg_st.canvas_size * 72 / arg_st.ghostscript.resolution; - arg_st.ghostscript.papersize = arg_st.canvas_size; - arg_st.ghostscript.epscrop = true; - arg_st.ghostscript.pageoffset = [0, 0]; - endif - - if (arg_st.formatted_for_printing) - arg_st.ghostscript.resolution = []; - else - arg_st.ghostscript.papersize = ""; - arg_st.ghostscript.pageoffset = [0, 0]; - endif - - if (warn_on_missing_binary) - if (isempty (arg_st.ghostscript.binary)) - warning ("print:missing_gs", "print.m: Ghostscript binary is not available.\nOnly eps output is available."); - else - if (isempty (arg_st.epstool_binary)) - warning ("print:missing_epstool", "print.m: epstool binary is not available.\nSome output formats are not available."); - endif - if (isempty (arg_st.fig2dev_binary)) - warning ("print:missing_fig2dev", "print.m: fig2dev binary is not available.\nSome output formats are not available."); - endif - if (isempty (arg_st.pstoedit_binary)) - warning ("print:missing_pstoedit", "print.m: pstoedit binary is not available.\nSome output formats are not available."); - endif - endif - warn_on_missing_binary = false; - endif - -endfunction - -%!test -%! opts = __print_parse_opts__ (); -%! assert (opts.devopt, "pswrite"); -%! assert (opts.use_color, 1); -%! assert (opts.send_to_printer, true); -%! assert (opts.canvas_size, [576, 432]); -%! assert (opts.ghostscript.device, "pswrite") - -%!test -%! opts = __print_parse_opts__ ("test.pdf", "-S640,480"); -%! assert (opts.canvas_size, [307.2, 230.4], 0.1); - -%!test -%! opts = __print_parse_opts__ ("-dpsc", "-append", "-loose"); -%! assert (opts.devopt, "pswrite"); -%! assert (opts.send_to_printer, true); -%! assert (opts.use_color, 1); -%! assert (opts.append_to_file, false); -%! assert (opts.ghostscript.device, "pswrite") -%! assert (opts.ghostscript.epscrop, false); - -%!test -%! opts = __print_parse_opts__ ("-deps", "-tight"); -%! assert (opts.tight_flag, true); -%! assert (opts.send_to_printer, true); -%! assert (opts.use_color, -1); -%! assert (opts.ghostscript.device, "") - -%!test -%! opts = __print_parse_opts__ ("-djpg", "foobar", "-mono", "-loose"); -%! assert (opts.devopt, "jpeg") -%! assert (opts.name, "foobar.jpg") -%! assert (opts.ghostscript.device, "jpeg") -%! assert (opts.ghostscript.epscrop, true); -%! assert (opts.ghostscript.papersize, ""); -%! assert (opts.ghostscript.pageoffset, [0, 0]); -%! assert (opts.send_to_printer, false); -%! assert (opts.printer, ""); -%! assert (opts.use_color, -1); - -%!test -%! opts = __print_parse_opts__ ("-ddeskjet", "foobar", "-mono", "-Pmyprinter"); -%! assert (opts.ghostscript.output, "foobar.deskjet") -%! assert (opts.ghostscript.device, "deskjet") -%! assert (opts.devopt, "deskjet") -%! assert (opts.send_to_printer, true); -%! assert (opts.printer, "-Pmyprinter"); -%! assert (opts.use_color, -1); - -%!test -%! opts = __print_parse_opts__ ("-f5", "-dljet3"); -%! assert (opts.ghostscript.device, "ljet3") -%! assert (strfind (opts.ghostscript.output, ".ljet3")) -%! assert (opts.devopt, "ljet3") -%! assert (opts.send_to_printer, true); -%! assert (opts.figure, 5) - -function cmd = __quote_path__ (cmd) - if (any (cmd == " ") && ! (cmd(1) == """" && cmd(end) == """")) - cmd = strcat ("""", strrep (cmd, """", """"""), """"); - endif -endfunction - -function gs = __ghostscript_binary__ () - - persistent ghostscript_binary = "" - persistent warn_on_no_ghostscript = true - persistent warn_on_bad_gsc = true - - if (isempty (ghostscript_binary)) - GSC = getenv ("GSC"); - if (exist (GSC, "file") - || (! isempty (GSC) && file_in_path (getenv ("PATH"), GSC))) - gs_binaries = {GSC}; - elseif (! isempty (GSC) && warn_on_bad_gsc) - warning ("print:badgscenv", - "print.m: GSC environment variable not set properly"); - warn_on_bad_gsc = false; - gs_binaries = {}; - else - gs_binaries = {}; - endif - if (isunix ()) - ## Unix - Includes Mac OSX and Cygwin. - gs_binaries = horzcat (gs_binaries, {"gs", "gs.exe"}); - else - ## pc - Includes Win32 and mingw. - gs_binaries = horzcat (gs_binaries, {"gs.exe", "gswin32c.exe"}); - endif - n = 0; - while (n < numel (gs_binaries) && isempty (ghostscript_binary)) - n = n + 1; - ghostscript_binary = file_in_path (getenv ("PATH"), gs_binaries{n}); - endwhile - if (warn_on_no_ghostscript && isempty (ghostscript_binary)) - warning ("print:noghostscript", - "print.m: ghostscript not found in PATH"); - warn_on_no_ghostscript = false; - endif - endif - - gs = ghostscript_binary; - -endfunction - -function bin = __find_binary__ (binary) - - persistent data = struct () - - if (! isfield (data, binary)) - ## Reinitialize when `user_binaries' is present. - data.(binary).bin = ""; - data.(binary).warn_on_absence = false; - endif - - if (isempty (data.(binary).bin)) - if (isunix ()) - ## Unix - Includes Mac OSX and Cygwin. - binaries = strcat (binary, {"", ".exe"}); - else - ## pc - Includes Win32 and mingw. - binaries = strcat (binary, {".exe"}); - endif - n = 0; - while (n < numel (binaries) && isempty (data.(binary).bin)) - n = n + 1; - data.(binary).bin = file_in_path (getenv ("PATH"), binaries{n}); - endwhile - if (isempty (data.(binary).bin) && data.(binary).warn_on_absence) - warning (sprintf ("print:no%s", binary), - "print.m: '%s' not found in PATH", binary); - data.(binary).warn_on_absence = false; - endif - endif - - bin = data.(binary).bin; - -endfunction - -function [papersize, paperposition] = gs_papersize (hfig, paperorientation) - persistent papertypes papersizes - - if (isempty (papertypes)) - papertypes = {"usletter", "uslegal", "a0", "a1", ... - "a2", "a3", "a4", "a5", ... - "b0", "b1", "b2", "b3", ... - "b4", "b5", "arch-a", "arch-b", ... - "arch-c", "arch-d", "arch-e", "a", ... - "b", "c", "d", "e", ... - "tabloid"}; - papersizes = [ 8.5, 11.0; 8.5, 14.0; 33.1, 46.8; 23.4, 33.1; - 16.5, 23.4; 11.7, 16.5; 8.3, 11.7; 5.8, 8.3; - 39.4, 55.7; 27.8, 39.4; 19.7, 27.8; 13.9, 19.7; - 9.8, 13.9; 6.9, 9.8; 9.0, 12.0; 12.0, 18.0; - 18.0, 24.0; 24.0, 36.0; 36.0, 48.0; 8.5, 11.0; - 11.0, 17.0; 18.0, 24.0; 24.0, 36.0; 36.0, 48.0; - 11.0, 17.0] * 72; - endif - - papertype = get (hfig, "papertype"); - paperunits = get (hfig, "paperunits"); - paperposition = get (hfig, "paperposition"); - if (strcmp (papertype, "")) - papersize = get (hfig, "papersize"); - papersize = convert2points (papersize , paperunits); - else - papersize = papersizes (strcmp (papertypes, papertype), :); - endif - - if (strcmp (paperunits, "normalized")) - paperposition = paperposition .* papersize([1,2,1,2]); - else - paperposition = convert2points (paperposition, paperunits); - endif - - ## FIXME - This will be obsoleted by listeners for paper properties. - ## Papersize is tall when portrait,and wide when landscape. - if ((papersize(1) > papersize(2) && strcmpi (paperorientation, "portrait")) - || (papersize(1) < papersize(2) && strcmpi (paperorientation, "landscape"))) - papersize = papersize ([2,1]); - paperposition = paperposition([2,1,4,3]); - endif - - if ((! strcmp (papertype, "")) && (strcmp (paperorientation, "portrait"))) - ## For portrait use the ghostscript name - papersize = papertype; - papersize(papersize=="-") = ""; - papersize = strrep (papersize, "us", ""); - switch (papersize) - case "a" - papersize = "letter"; - case {"b", "tabloid"} - papersize = "11x17"; - case {"c", "d", "e"} - papersize = strcat ("arch", papersize); - endswitch - if (strncmp (papersize, "arch", 4)) - papersize(end) = upper (papersize(end)); - endif - endif - -endfunction - -function value = convert2points (value, units) - switch (units) - case "inches" - value = value * 72; - case "centimeters" - value = value * 72 / 25.4; - case "normalized" - error ("print:customnormalized", - "print.m: papersize=='' and paperunits='normalized' may not be combined"); - endswitch -endfunction - -function device_list = gs_device_list (); - ## Graphics formats/languages, not priners. - device_list = {"bmp16"; "bmp16m"; "bmp256"; "bmp32b"; "bmpgray"; ... - "epswrite"; "jpeg"; "jpegcymk"; "jpeggray"; "pbm"; ... - "pbmraw"; "pcx16"; "pcx24b"; "pcx256"; "pcx2up"; ... - "pcxcmyk"; "pcxgray"; "pcxmono"; "pdfwrite"; "pgm"; ... - "pgmraw"; "pgnm"; "pgnmraw"; "png16"; "png16m"; ... - "png256"; "png48"; "pngalpha"; "pnggray"; "pngmono"; ... - "pnm"; "pnmraw"; "ppm"; "ppmraw"; "ps2write"; ... - "pswrite"; "tiff12nc"; "tiff24nc"; "tiff32nc"; ... - "tiffcrle"; "tiffg3"; "tiffg32d"; "tiffg4"; ... - "tiffgray"; "tifflzw"; "tiffpack"; "tiffsep"}; -endfunction - -function aliases = gs_aliases (); - ## Aliases for other devices: "bmp", "png", "tiff", "tiffn", "pdf", - ## "ps", "ps2", "psc", "psc2" - ## - ## eps, epsc, eps2, epsc2 are not included here because those are - ## are generated by the graphics toolkit. - aliases.bmp = "bmp32b"; - aliases.pdf = "pdfwrite"; - aliases.png = "png16m"; - aliases.ps = "pswrite"; - aliases.ps2 = "ps2write"; - aliases.psc = "pswrite"; - aliases.psc2 = "ps2write"; - aliases.tiff = "tiff24nc"; - aliases.tiffn = "tiff24nc"; -endfunction - diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/module.mk --- a/scripts/plot/module.mk Sat Jul 16 09:16:52 2011 -0700 +++ b/scripts/plot/module.mk Sat Jul 16 09:28:26 2011 -0700 @@ -20,38 +20,38 @@ plot/private/__errplot__.m \ plot/private/__ezplot__.m \ plot/private/__fltk_file_filter__.m \ - plot/private/__ghostscript__.m \ + plot/private/__fltk_ginput__.m \ + plot/private/__fltk_print__.m \ plot/private/__getlegenddata__.m \ + plot/private/__ghostscript__.m \ + plot/private/__gnuplot_drawnow__.m \ + plot/private/__gnuplot_get_var__.m \ + plot/private/__gnuplot_ginput__.m \ + plot/private/__gnuplot_has_feature__.m \ plot/private/__gnuplot_has_terminal__.m\ + plot/private/__gnuplot_open_stream__.m \ + plot/private/__gnuplot_print__.m \ + plot/private/__gnuplot_version__.m \ + plot/private/__go_draw_axes__.m \ + plot/private/__go_draw_figure__.m \ plot/private/__interp_cube__.m \ plot/private/__line__.m \ + plot/private/__marching_cube__.m \ + plot/private/__next_line_color__.m \ + plot/private/__next_line_style__.m \ plot/private/__patch__.m \ plot/private/__pie__.m \ plot/private/__plt__.m \ plot/private/__pltopt__.m \ + plot/private/__print_parse_opts__.m \ plot/private/__quiver__.m \ plot/private/__scatter__.m \ plot/private/__stem__.m \ plot/private/__tight_eps_bbox__.m plot_FCN_FILES = \ - plot/__fltk_ginput__.m \ - plot/__fltk_print__.m \ - plot/__gnuplot_drawnow__.m \ - plot/__gnuplot_get_var__.m \ - plot/__gnuplot_ginput__.m \ - plot/__gnuplot_has_feature__.m \ - plot/__gnuplot_open_stream__.m \ - plot/__gnuplot_print__.m \ - plot/__gnuplot_version__.m \ plot/__go_close_all__.m \ - plot/__go_draw_axes__.m \ - plot/__go_draw_figure__.m \ - plot/__marching_cube__.m \ - plot/__next_line_color__.m \ - plot/__next_line_style__.m \ plot/__plt_get_axis_arg__.m \ - plot/__print_parse_opts__.m \ plot/allchild.m \ plot/ancestor.m \ plot/area.m \ diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/private/__fltk_ginput__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/private/__fltk_ginput__.m Sat Jul 16 09:28:26 2011 -0700 @@ -0,0 +1,105 @@ +## Copyright (C) 2010-2011 Shai Ayal +## +## 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 3 of the License, 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, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {[@var{x}, @var{y}, @var{buttons}] =} __fltk_ginput__ (@var{f}, @var{n}) +## Undocumented internal function. +## @end deftypefn + +## This is ginput.m implementation for fltk. + +## FIXME -- Key presses cannot toggle menu items nor hotkey functionality +## (grid, autoscale) during ginput! + +function [x, y, button] = __fltk_ginput__ (f, n = -1) + + if (isempty (get (f, "currentaxes"))) + error ("ginput: must have at least one axes"); + endif + + x = y = button = []; + ginput_aggregator (0, 0, 0, 0); + + unwind_protect + + orig_windowbuttondownfcn = get (f, "windowbuttondownfcn"); + set (f, "windowbuttondownfcn", @ginput_windowbuttondownfcn); + + orig_ginput_keypressfcn = get (f, "keypressfcn"); + set (f, "keypressfcn", @ginput_keypressfcn); + + while (true) + __fltk_redraw__ (); + + ## Release CPU. + sleep (0.01); + + [x, y, n0, button] = ginput_aggregator (-1, 0, 0, 0); + if (n0 == n || n0 < 0) + break; + endif + endwhile + + unwind_protect_cleanup + set (f, "windowbuttondownfcn", orig_windowbuttondownfcn); + set (f, "keypressfcn", orig_ginput_keypressfcn); + end_unwind_protect + +endfunction + +function [x, y, n, button] = ginput_aggregator (mode, xn, yn, btn) + persistent x y n button; + + if (mode == 0) + ## Initialize. + x = []; + y = []; + button = []; + n = 0; + elseif (mode == 1) + ## Accept mouse button or key press. + x = [x; xn]; + y = [y; yn]; + button = [button; btn]; + n += 1; + elseif (mode == 2) + ## The end due to Enter. + n = -1; + endif +endfunction + +function ginput_windowbuttondownfcn (src, data) + point = get (get (src,"currentaxes"), "currentpoint"); + ## FIXME -- How to get the actual mouse button pressed (1,2,3) into + ## "button"? + button = 1; + ginput_aggregator (1, point(1,1), point(2,1), button); +endfunction + +function ginput_keypressfcn (src, evt) + point = get (get (src, "currentaxes"), "currentpoint"); + ## FIXME -- use evt.Key or evt.Character? + key = evt.Key; + if (key == 10) + ## Enter key. + ginput_aggregator (2, point(1,1), point(2,1), key); + else + ginput_aggregator (1, point(1,1), point(2,1), key); + endif +endfunction + diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/private/__fltk_print__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/private/__fltk_print__.m Sat Jul 16 09:28:26 2011 -0700 @@ -0,0 +1,161 @@ +## Copyright (C) 2010-2011 Shai Ayal +## +## 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 3 of the License, 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, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {} __fltk_print__ (@var{@dots{}}) +## Undocumented internal function. +## @end deftypefn + +function opts = __fltk_print__ (opts) + + dos_shell = (ispc () && ! isunix ()); + + figure (opts.figure); + drawnow ("expose"); + __fltk_redraw__ (); + + if (! isempty (opts.fig2dev_binary)) + ## fig2dev is prefered for conversion to emf + fig2dev_devices = {"pstex", "mf", "emf"}; + else + fig2dev_devices = {"pstex", "mf"}; + endif + + gl2ps_device = {}; + pipeline = {}; + switch (lower (opts.devopt)) + case {"eps", "eps2", "epsc", "epsc2"} + ## format GL2PS_EPS + gl2ps_device = {"eps"}; + ## FIXME - use epstool to tighten bbox and provide preview. + pipeline = {opts.epstool_cmd(opts, "-", opts.name)}; + case {"epslatex", "pslatex", "pdflatex", "epslatexstandalone", ... + "pslatexstandalone", "pdflatexstandalone"} + ## format GL2PS_TEX + n = find (opts.devopt == "l", 1); + suffix = opts.devopt(1:n-1); + dot = find (opts.name == ".", 1, "last"); + if ((! isempty (dot)) + && any (strcmpi (opts.name(dot:end), ... + {".eps", ".ps", ".pdf", ".tex", "."}))) + name = opts.name(1:dot-1); + if (dot < numel (opts.name) + && any (strcmpi (opts.name(dot+1:end), {"eps", "ps", "pdf"}))) + ## If user provides eps/ps/pdf suffix, use it. + suffix = opts.name(dot+1:end); + endif + elseif (dot == numel (opts.name)) + name = opts.name; + endif + gl2ps_device = {sprintf("%snotxt", lower (suffix))}; + gl2ps_device{2} = "tex"; + if (dos_shell) + ## FIXME - this will only work on MinGW with the MSYS shell + pipeline = {sprintf("cat > %s-inc.%s", name, suffix)}; + pipeline{2} = sprintf ("cat > %s.tex", name); + else + pipeline = {sprintf("cat > %s-inc.%s", name, suffix)}; + pipeline{2} = sprintf ("cat > %s.tex", name); + endif + case "tikz" + ## format GL2PS_PGF + gl2ps_device = {"pgf"}; + pipeline = {sprintf("cat > %s", opts.name)}; + case "svg" + ## format GL2PS_SVG + gl2ps_device = {"svg"}; + pipeline = {sprintf("cat > %s", opts.name)}; + case fig2dev_devices + cmd_pstoedit = opts.pstoedit_cmd (opts, "fig"); + cmd_fig2dev = opts.fig2dev_cmd (opts, opts.devopt); + if (strcmp (opts.devopt, "pstex")) + [~, ~, ext] = fileparts (opts.name); + if (any (strcmpi (ext, {".ps", ".tex", "."}))) + opts.name = opts.name(1:end-numel(ext)); + endif + opts.name = strcat (opts.name, ".ps"); + cmd = sprintf ("%s | %s > %s", cmd_pstoedit, cmd_fig2dev, opts.name); + gl2ps_device = {"eps"}; + pipeline = {cmd}; + cmd_fig2dev = opts.fig2dev_cmd (opts, "pstex_t"); + gl2ps_device{2} = "eps"; + pipeline{2} = sprintf ("%s | %s > %s", cmd_pstoedit, + cmd_fig2dev, strrep(opts.name, ".ps", ".tex")); + else + cmd = sprintf ("%s | %s > %s", cmd_pstoedit, cmd_fig2dev, opts.name); + gl2ps_device = {"eps"}; + pipeline = {cmd}; + endif + case "aifm" + cmd = opts.pstoedit_cmd (opts, "ps2ai"); + gl2ps_device = {"eps"}; + pipeline = {sprintf("%s > %s", cmd, opts.name)}; + case {"dxf", "emf", "fig", "hpgl"} + cmd = opts.pstoedit_cmd (opts); + gl2ps_device = {"eps"}; + pipeline = {sprintf("%s > %s", cmd, opts.name)}; + case {"corel", "gif"} + error ("print:unsupporteddevice", + "print.m: %s output is not available for the FLTK graphics toolkit", + upper (opts.devopt)); + case opts.ghostscript.device + opts.ghostscript.source = "-"; + opts.ghostscript.output = opts.name; + if (opts.send_to_printer) + opts.unlink(strcmp (opts.unlink, opts.ghostscript.output)) = []; + opts.ghostscript.output = "-"; + endif + [cmd_gs, cmd_cleanup] = __ghostscript__ (opts.ghostscript); + if (opts.send_to_printer || isempty (opts.name)) + cmd_lpr = opts.lpr_cmd (opts); + cmd = sprintf("%s | %s", cmd_gs, cmd_lpr); + else + cmd = sprintf("%s", cmd_gs); + endif + if (! isempty (cmd_cleanup)) + gl2ps_device = {"eps"}; + if (dos_shell) + pipeline = {sprintf("%s & %s", cmd, cmd_cleanup)}; + else + pipeline = {sprintf("%s ; %s", cmd, cmd_cleanup)}; + endif + else + gl2ps_device = {"eps"}; + pipeline = {cmd}; + endif + otherwise + error (sprintf ("print:no%soutput", opts.devopt), + "print.m: %s output is not available for GL2PS output", + upper (opts.devopt)); + endswitch + + opts.pipeline = pipeline; + + for n = 1:numel(pipeline) + if (opts.debug) + fprintf ("fltk-pipeline: '%s'\n", pipeline{n}); + endif + drawnow (gl2ps_device{n}, strcat('|',pipeline{n})); + endfor + + if (! isempty (strfind (opts.devopt, "standalone"))) + opts.latex_standalone (opts); + endif + +endfunction + diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/private/__gnuplot_drawnow__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/private/__gnuplot_drawnow__.m Sat Jul 16 09:28:26 2011 -0700 @@ -0,0 +1,388 @@ +## Copyright (C) 2005-2011 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 3 of the License, 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, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {} __gnuplot_drawnow__ (@var{h}, @var{term}, @var{file}, @var{mono}, @var{debug_file}) +## Undocumented internal function. +## @end deftypefn + +## Author: jwe + +function __gnuplot_drawnow__ (h, term, file, mono, debug_file) + + if (nargin < 4) + mono = false; + endif + + if (nargin >= 3 && nargin <= 5) + ## Produce various output formats, or redirect gnuplot stream to a + ## debug file. + plot_stream = []; + fid = []; + default_plot_stream = get (h, "__plot_stream__"); + unwind_protect + plot_stream = __gnuplot_open_stream__ (2, h); + gnuplot_supports_term = __gnuplot_has_terminal__ (term, plot_stream); + if (gnuplot_supports_term) + enhanced = gnuplot_set_term (plot_stream (1), true, h, term, file); + __go_draw_figure__ (h, plot_stream(1), enhanced, mono); + if (nargin == 5) + fid = fopen (debug_file, "wb"); + enhanced = gnuplot_set_term (fid, true, h, term, file); + __go_draw_figure__ (h, fid, enhanced, mono); + endif + else + error ("__gnuplot_drawnow__: the gnuplot terminal, \"%s\", is not available", + gnuplot_trim_term (term)); + endif + unwind_protect_cleanup + set (h, "__plot_stream__", default_plot_stream); + if (! isempty (plot_stream)) + pclose (plot_stream(1)); + if (numel (plot_stream) > 1) + pclose (plot_stream(2)); + endif + if (numel (plot_stream) > 2) + waitpid (plot_stream(3)); + endif + endif + if (! isempty (fid)) + fclose (fid); + endif + end_unwind_protect + elseif (nargin == 1) + ## Graphics terminal for display. + plot_stream = get (h, "__plot_stream__"); + if (isempty (plot_stream)) + plot_stream = __gnuplot_open_stream__ (2, h); + new_stream = true; + else + new_stream = false; + endif + term = gnuplot_default_term (); + if (strcmp (term, "dumb")) + ## popen2 eats stdout of gnuplot, use temporary file instead + dumb_tmp_file = tmpnam (); + enhanced = gnuplot_set_term (plot_stream (1), new_stream, h, ... + term, dumb_tmp_file); + else + enhanced = gnuplot_set_term (plot_stream (1), new_stream, h, term); + endif + __go_draw_figure__ (h, plot_stream (1), enhanced, mono); + fflush (plot_stream (1)); + if (strcmp (term, "dumb")) + fid = -1; + while (fid < 0) + pause (0.1); + fid = fopen (dumb_tmp_file, 'r'); + endwhile + ## reprint the plot on screen + [a, count] = fscanf (fid, '%c', Inf); + fclose (fid); + if (count>0) + if (a(1)==12) + ## avoid ^L at the beginning + a = a(2:end); + endif + puts (a); + endif + unlink (dumb_tmp_file); + endif + else + print_usage (); + endif + +endfunction + +function enhanced = gnuplot_set_term (plot_stream, new_stream, h, term, file) + ## Generate the gnuplot "set terminal ..." command. + ## When "term" originates from print.m, it may include other options. + if (nargin < 4) + ## This supports the gnuplot graphics toolkit. + term = gnuplot_default_term (); + opts_str = ""; + else + ## Get the one word terminal id and save the remaining as options to + ## be passed on to gnuplot. The terminal may respect the graphics + ## toolkit. + [term, opts_str] = gnuplot_trim_term (term); + term = lower (term); + if (strcmpi (term, "lua")) + ## Replace "lau tikz" with + term = "tikz"; + opts_str = strrep (opts_str, "tikz", ""); + endif + endif + + if (strfind (opts_str, "noenhanced")) + enhanced = false; + else + enhanced = gnuplot_is_enhanced_term (term); + endif + + ## Set the terminal. + if (! isempty (term)) + + if (enhanced) + enh_str = "enhanced"; + else + enh_str = ""; + endif + + if (! isempty (h) && isfigure (h)) + + ## Generate gnuplot title string for plot windows. + if (output_to_screen (term) && ~strcmp (term, "dumb")) + fig.numbertitle = get (h, "numbertitle"); + fig.name = get (h, "name"); + if (strcmpi (get (h, "numbertitle"), "on")) + title_str = sprintf ("Figure %d", h); + else + title_str = ""; + endif + if (! isempty (fig.name) && ! isempty (title_str)) + title_str = sprintf ("%s: %s", title_str, fig.name); + elseif (! isempty (fig.name) && isempty (title_str)) + title_str = fig.name; + endif + if (! isempty (title_str)) + title_str = sprintf ("title \"%s\"", title_str); + endif + if (strcmp (term, "aqua")) + ## Adjust axes-label and tick-label spacing. + opts_str = sprintf ("%s font \"%s,%d\"", opts_str, + get (0, "defaultaxesfontname"), + get (0, "defaultaxesfontsize") / 1.5); + endif + else + title_str = ""; + endif + + if (! (any (strfind (opts_str, " size ") > 0) + || any (strfind (opts_str, "size ") == 1))) + ## Get figure size in pixels. Rely on listener to handle coversion. + units = get (h, "units"); + unwind_protect + set (h, "units", "pixels"); + position_in_pixels = get (h, "position"); + unwind_protect_cleanup + set (h, "units", units); + end_unwind_protect + gnuplot_pos = position_in_pixels(1:2); + gnuplot_size = position_in_pixels(3:4); + if (! (output_to_screen (term) + || any (strcmp (term, {"emf", "gif", "jpeg", "pbm", "png", ... + "pngcairo", "svg"})))) + ## Convert to inches + gnuplot_pos = gnuplot_pos / 72; + gnuplot_size = gnuplot_size / 72; + endif + if (all (gnuplot_size > 0)) + terminals_with_size = {"canvas", "emf", "epslatex", "fig", ... + "gif", "jpeg", "latex", "pbm", "pdf", ... + "pdfcairo", "postscript", "png", "pngcairo", ... + "pstex", "pslatex", "svg", "tikz"}; + if (__gnuplot_has_feature__ ("x11_figure_position")) + terminals_with_size{end+1} = "x11"; + endif + if (__gnuplot_has_feature__ ("wxt_figure_size")) + terminals_with_size{end+1} = "wxt"; + endif + switch (term) + case terminals_with_size + size_str = sprintf ("size %g,%g", gnuplot_size); + case "tikz" + size_str = sprintf ("size %gin,%gin", gnuplot_size); + case "dumb" + new_stream = 1; + if (~isempty (getenv ("COLUMNS")) && ~isempty (getenv ("LINES"))) + ## Let dumb use full text screen size (minus prompt lines). + n = sprintf ("%i", -2 - length (find (sprintf ("%s", PS1) == "\n"))); + ## n = the number of times \n appears in PS1 + size_str = ["size ", getenv("COLUMNS"), ",", getenv("LINES"), n]; + else + ## Use the gnuplot default. + size_str = ""; + endif + case {"aqua", "fig", "corel"} + size_str = sprintf ("size %g %g", gnuplot_size); + case "dxf" + size_str = ""; + otherwise + size_str = ""; + endswitch + if (strncmpi (term, "x11", 3) + && __gnuplot_has_feature__ ("x11_figure_position")) + ## X11 allows the window to be positioned as well. + units = get (0, "units"); + unwind_protect + set (0, "units", "pixels"); + screen_size = get (0, "screensize")(3:4); + unwind_protect_cleanup + set (0, "units", units); + end_unwind_protect + if (all (screen_size > 0)) + ## For X11, set the figure positon as well as the size + ## gnuplot position is UL, Octave's is LL (same for screen/window) + gnuplot_pos(2) = screen_size(2) - gnuplot_pos(2) - gnuplot_size(2); + gnuplot_pos = max (gnuplot_pos, 1); + size_str = sprintf ("%s position %d,%d", size_str, + gnuplot_pos(1), gnuplot_pos(2)); + endif + endif + else + size_str = ""; + warning ("gnuplot_set_term: size is zero"); + endif + else + ## A specified size take priority over the figure properies. + size_str = ""; + endif + else + if isempty (h) + disp ("gnuplot_set_term: figure handle is empty"); + elseif !isfigure(h) + disp ("gnuplot_set_term: not a figure handle"); + endif + title_str = ""; + size_str = ""; + endif + + ## Set the gnuplot terminal (type, enhanced, title, options & size). + term_str = sprintf ("set terminal %s", term); + if (! isempty (enh_str)) + term_str = sprintf ("%s %s", term_str, enh_str); + endif + if (! isempty (title_str)) + term_str = sprintf ("%s %s", term_str, title_str); + endif + if (isempty (strfind (term, "corel"))) + if (! isempty (size_str) && new_stream) + ## size_str comes after other options to permit specification of + ## the canvas size for terminals cdr/corel. + term_str = sprintf ("%s %s", term_str, size_str); + endif + if (nargin > 3 && ischar (opts_str)) + ## Options must go last. + term_str = sprintf ("%s %s", term_str, opts_str); + endif + else + if (nargin > 3 && ischar (opts_str)) + ## Options must go last. + term_str = sprintf ("%s %s", term_str, opts_str); + endif + if (! isempty (size_str) && new_stream) + ## size_str comes after other options to permit specification of + ## the canvas size for terminals cdr/corel. + term_str = sprintf ("%s %s", term_str, size_str); + endif + endif + + ## Work around the gnuplot feature of growing the x11 window and + ## flickering window (x11, windows, & wxt) when the mouse and + ## multiplot are set in gnuplot. + fputs (plot_stream, "unset multiplot;\n"); + flickering_terms = {"x11", "windows", "wxt", "dumb"}; + if (! any (strcmp (term, flickering_terms)) + || have_non_legend_axes (h) + || numel (findall (h, "type", "image")) > 0) + fprintf (plot_stream, "%s\n", term_str); + if (nargin == 5) + if (! isempty (file)) + fprintf (plot_stream, "set output '%s';\n", file); + endif + endif + fputs (plot_stream, "set multiplot;\n"); + elseif (any (strcmp (term, flickering_terms))) + fprintf (plot_stream, "%s\n", term_str); + if (nargin == 5) + if (! isempty (file)) + fprintf (plot_stream, "set output '%s';\n", file); + endif + endif + endif + else + ## gnuplot will pick up the GNUTERM environment variable itself + ## so no need to set the terminal type if not also setting the + ## figure title, enhanced mode, or position. + endif + +endfunction + +function term = gnuplot_default_term () + term = getenv ("GNUTERM"); + ## If not specified, guess the terminal type. + if (isempty (term)) + if (ismac ()) + term = "aqua"; + elseif (! isunix ()) + term = "windows"; + elseif (! isempty (getenv ("DISPLAY"))) + term = "x11"; + else + term = "dumb"; + endif + endif +endfunction + +function [term, opts] = gnuplot_trim_term (string) + ## Extract the terminal type and terminal options (from print.m) + string = deblank (string); + n = strfind (string, ' '); + if (isempty (n)) + term = string; + opts = ""; + else + term = string(1:(n-1)); + opts = string((n+1):end); + endif +endfunction + +function have_enhanced = gnuplot_is_enhanced_term (term) + persistent enhanced_terminals; + if (isempty (enhanced_terminals)) + ## Don't include pstex, pslatex or epslatex here as the TeX commands + ## should not be interpreted in that case. + enhanced_terminals = {"aqua", "canvas", "dumb", "emf", "gif", "jpeg", ... + "pdf", "pdfcairo", "pm", "png", "pngcairo", ... + "postscript", "svg", "windows", "wxt", "x11"}; + endif + if (nargin < 1) + ## Determine the default gnuplot terminal. + term = gnuplot_default_term (); + endif + have_enhanced = any (strncmp (enhanced_terminals, term, min (numel (term), 3))); +endfunction + +function ret = output_to_screen (term) + ret = any (strcmpi ({"aqua", "dumb", "wxt", "x11", "windows", "pm"}, term)); +endfunction + +function retval = have_non_legend_axes (h) + retval = false; + all_axes = findall (h, "type", "axes"); + if (! isempty (all_axes)) + n_all_axes = numel (all_axes); + all_axes_tags = get (all_axes, "tag"); + legend_axes = strcmp (all_axes_tags, "legend"); + if (! isempty (legend_axes)) + n_legend_axes = sum (legend_axes); + retval = (n_all_axes - n_legend_axes) > 1; + endif + endif +endfunction diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/private/__gnuplot_get_var__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/private/__gnuplot_get_var__.m Sat Jul 16 09:28:26 2011 -0700 @@ -0,0 +1,161 @@ +## Copyright (C) 2009-2011 Ben Abbott +## +## 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 3 of the License, 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, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{value} =} __gnuplot_get_var__ (@var{h}, @var{name}, @var{fmt}) +## Undocumented internal function. +## @end deftypefn + +## Author: Ben Abbott +## Created: 2009-02-07 + +function gp_var_value = __gnuplot_get_var__ (h, gp_var_name, fmt) + + if (nargin == 0) + h = gcf (); + endif + if (nargin < 2) + print_usage (); + endif + if (nargin < 3) + fmt = ''; + endif + + if (numel (h) == 1 && isfigure (h)) + if (isempty (get (gcf, "__plot_stream__"))) + ostream = __gnuplot_open_stream__ (2, h); + else + ostream = get (h, "__plot_stream__"); + endif + else + ostream = h; + endif + if (numel (ostream) < 1) + error ("__gnuplot_get_var__: stream to gnuplot not open"); + elseif (ispc ()) + if (numel (ostream) == 1) + error ("__gnuplot_get_var__: Need mkfifo that is not implemented under Windows"); + endif + use_mkfifo = false; + istream = ostream(2); + ostream = ostream(1); + else + use_mkfifo = true; + ostream = ostream(1); + endif + + if (use_mkfifo) + gpin_name = tmpnam (); + + ## Mode: 6*8*8 == 0600 + [err, msg] = mkfifo (gpin_name, 6*8*8); + + if (err != 0) + error ("__gnuplot_get_var__: Can not make fifo (%s)", msg); + endif + endif + + gp_var_name = strtrim (gp_var_name); + n = min (strfind (gp_var_name, " "), strfind (gp_var_name, ",")) - 1; + if (isempty (n)) + n = numel (gp_var_name); + endif + + unwind_protect + + ## Notes: Variables may be undefined if user closes gnuplot by "q" + ## or Alt-F4. Further, this abrupt close also requires the leading + ## "\n" on the next line. + if (use_mkfifo) + fprintf (ostream, "\nset print \"%s\";\n", gpin_name); + fflush (ostream); + [gpin, err] = fopen (gpin_name, "r"); + if (err != 0) + ## Try a second time, and then give an error. + [gpin, err] = fopen (gpin_name, "r"); + endif + if (err != 0) + error ("__gnuplot_get_var__: can not open fifo"); + endif + gp_cmd = sprintf ("\nif (exists(\"%s\")) print %s; else print NaN\n", + gp_var_name(1:n), gp_var_name); + fputs (ostream, gp_cmd); + + ## Close output file, to force it to be flushed + fputs (ostream, "set print;\n"); + fflush (ostream); + + ## Now read from fifo. + reading = true; + str = {}; + while (reading) + str{end+1} = fgets (gpin); + if (isnumeric (str{end}) && (str{end} == -1)) + reading = false; + str = str(1:(end-1)); + endif + endwhile + str = strcat (str{:}); + fclose (gpin); + else + ## Direct gnuplot to print to + fprintf (ostream, "set print \"-\";\n"); + fflush (ostream); + gp_cmd = sprintf ("\nif (exists(\"%s\")) print \"OCTAVE: \", %s; else print NaN\n", + gp_var_name(1:n), gp_var_name); + fputs (ostream, gp_cmd); + fflush (ostream); + ## Direct gnuplot to print to + fputs (ostream, "set print;\n"); + fflush (ostream); + + str = {}; + while (isempty (str)) + str = char (fread (istream)'); + if (isempty (str)) + sleep (0.05); + else + str = regexp (str, 'OCTAVE:.*', "match"); + str = str{end}(8:end); + endif + fclear (istream); + endwhile + endif + + ## Strip out EOLs and the continuation character "|" + str(str=="\n") = ""; + str(str=="\r") = ""; + n_continue = strfind (str, " \\ "); + if (! isempty (n_continue)) + str(n_continue+1) = ""; + endif + + if (isempty (fmt)) + gp_var_value = strtrim (str); + else + gp_var_value = sscanf (str, fmt); + endif + + unwind_protect_cleanup + if (use_mkfifo) + unlink (gpin_name); + endif + end_unwind_protect + +endfunction + diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/private/__gnuplot_ginput__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/private/__gnuplot_ginput__.m Sat Jul 16 09:28:26 2011 -0700 @@ -0,0 +1,154 @@ +## Copyright (C) 2004-2011 Petr Mikulik +## +## 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 3 of the License, 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, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {[@var{x}, @var{y}, @var{buttons}] =} __gnuplot_ginput__ (@var{f}, @var{n}) +## Undocumented internal function. +## @end deftypefn + +## This is ginput.m implementation for gnuplot and X11. +## It requires gnuplot 4.1 and later. + +## This file initially bore the copyright statement +## Petr Mikulik +## History: June 2006; August 2005; June 2004; April 2004 +## License: public domain + +function [x, y, button] = __gnuplot_ginput__ (f, n) + + ostream = get (f, "__plot_stream__"); + if (numel (ostream) < 1) + error ("ginput: stream to gnuplot not open"); + elseif (ispc ()) + if (numel (ostream) == 1) + error ("ginput: Need mkfifo that is not implemented under Windows"); + endif + use_mkfifo = false; + istream = ostream(2); + ostream = ostream(1); + else + use_mkfifo = true; + ostream = ostream(1); + endif + + if (compare_versions (__gnuplot_version__ (), "4.0", "<=")) + error ("ginput: version %s of gnuplot not supported", gnuplot_version ()); + endif + + if (nargin == 1) + x = zeros (100, 1); + y = zeros (100, 1); + button = zeros (100, 1); + else + x = zeros (n, 1); + y = zeros (n, 1); + button = zeros (n, 1); + endif + + if (use_mkfifo) + gpin_name = tmpnam (); + + ##Mode: 6*8*8 == 0600 + [err, msg] = mkfifo (gpin_name, 6*8*8); + + if (err != 0) + error ("ginput: Can not open fifo (%s)", msg); + endif + endif + + unwind_protect + + k = 0; + while (true) + k++; + + ## Notes: MOUSE_* can be undefined if user closes gnuplot by "q" + ## or Alt-F4. Further, this abrupt close also requires the leading + ## "\n" on the next line. + if (use_mkfifo) + fprintf (ostream, "set print \"%s\";\n", gpin_name); + fflush (ostream); + [gpin, err] = fopen (gpin_name, "r"); + if (err != 0) + error ("ginput: Can not open fifo (%s)", msg); + endif + fputs (ostream, "pause mouse any;\n\n"); + fputs (ostream, "\nif (exists(\"MOUSE_KEY\") && exists(\"MOUSE_X\")) print MOUSE_X, MOUSE_Y, MOUSE_KEY; else print \"0 0 -1\"\n"); + + ## Close output file, to force it to be flushed + fputs (ostream, "set print;\n"); + fflush (ostream); + + ## Now read from fifo. + [x(k), y(k), button(k), count] = fscanf (gpin, "%f %f %d", "C"); + fclose (gpin); + else + fprintf (ostream, "set print \"-\";\n"); + fflush (ostream); + fputs (ostream, "pause mouse any;\n\n"); + fputs (ostream, "\nif (exists(\"MOUSE_KEY\") && exists(\"MOUSE_X\")) print \"OCTAVE: \", MOUSE_X, MOUSE_Y, MOUSE_KEY; else print \"0 0 -1\"\n"); + + ## Close output file, to force it to be flushed + fputs (ostream, "set print;\n"); + fflush (ostream); + + str = {}; + while (isempty (str)) + str = char (fread (istream)'); + if (isempty (str)) + sleep (0.05); + else + str = regexp (str, 'OCTAVE:\s+[-+.\d]+\s+[-+.\d]+\s+\d*', 'match'); + endif + fclear (istream); + endwhile + [x(k), y(k), button(k), count] = sscanf (str{end}(8:end), "%f %f %d", "C"); + endif + + if ([x(k), y(k), button(k)] == [0, 0, -1]) + ## Mousing not active (no plot yet). + break; + endif + + if (nargin > 1) + ## Input argument n was given => stop when k == n. + if (k == n) + break; + endif + else + ## Input argument n not given => stop when hitting a return key. + ## if (button(k) == 0x0D || button(k) == 0x0A) + ## ## hit Return or Enter + if (button(k) == 0x0D) + ## hit Return + x(k:end) = []; + y(k:end) = []; + button(k:end) = []; + break; + endif + endif + endwhile + + unwind_protect_cleanup + if (use_mkfifo) + unlink (gpin_name); + endif + end_unwind_protect + +endfunction + diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/private/__gnuplot_has_feature__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/private/__gnuplot_has_feature__.m Sat Jul 16 09:28:26 2011 -0700 @@ -0,0 +1,61 @@ +## Copyright (C) 2009-2011 Ben Abbott +## +## 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 3 of the License, 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, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{has_feature} =} __gnuplot_has_feature__ (@var{feature}) +## Undocumented internal function. +## @end deftypefn + +## Author: Ben Abbott +## Created: 2009-01-27 + +function res = __gnuplot_has_feature__ (feature) + persistent features has_features + features = {"x11_figure_position", + "wxt_figure_size", + "transparent_patches", + "transparent_surface", + "epslatex_implies_eps_filesuffix", + "epslatexstandalone_terminal", + "screen_coordinates_for_{lrtb}margin", + "variable_GPVAL_TERMINALS", + "key_has_font_properties"}; + + if (isempty (has_features)) + try + gnuplot_version = __gnuplot_version__ (); + catch + ## Don't throw an error if gnuplot isn't installed + gnuplot_version = "0.0.0"; + end_try_catch + versions = {"4.2.5", "4.4", "4.4", "4.4", "4.2", "4.2", "4.4", "4.4", "4.4"}; + operators = {">=", ">=", ">=", ">=", ">=", ">=", ">=", ">=", ">="}; + have_features = logical (zeros (size (features))); + for n = 1 : numel (have_features) + has_features(n) = compare_versions (gnuplot_version, versions{n}, operators{n}); + endfor + endif + + n = find (strcmpi (feature, features)); + if (isempty (n)) + res = NaN; + else + res = has_features(n); + endif +endfunction + diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/private/__gnuplot_open_stream__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/private/__gnuplot_open_stream__.m Sat Jul 16 09:28:26 2011 -0700 @@ -0,0 +1,45 @@ +## Copyright (C) 2009-2011 Ben Abbott +## +## 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 3 of the License, 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, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{stream} =} __gnuplot_open_stream__ (@var{npipes}, @var{h}) +## Undocumented internal function. +## @end deftypefn + +## Author: Ben Abbott +## Created: 2009-04-11 + +function plot_stream = __gnuplot_open_stream__ (npipes, h) + [prog, args] = gnuplot_binary (); + if (npipes > 1) + [plot_stream(1), plot_stream(2), pid] = popen2 (prog, args{:}); + if (pid < 0) + error ("__gnuplot_open_stream__: failed to open connection to gnuplot"); + else + plot_stream(3) = pid; + endif + else + plot_stream = popen (sprintf ("%s ", prog, args{:}), "w"); + if (plot_stream < 0) + error ("__gnuplot_open_stream__: failed to open connection to gnuplot"); + endif + endif + if (nargin > 1) + set (h, "__plot_stream__", plot_stream); + endif +endfunction diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/private/__gnuplot_print__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/private/__gnuplot_print__.m Sat Jul 16 09:28:26 2011 -0700 @@ -0,0 +1,300 @@ +## Copyright (C) 1999-2011 Daniel Heiserer +## Copyright (C) 2001 Laurent Mazet +## +## 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 3 of the License, 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, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {} __gnuplot_print__ (@var{@dots{}}) +## Undocumented internal function. +## @end deftypefn + +## Author: Daniel Heiserer +## Adapted-By: jwe + +function opts = __gnuplot_print__ (opts) + + dos_shell = (ispc () && ! isunix ()); + + if (isempty (opts.fontsize)) + ## If no fontsize, determine the nominal axes fontsize. + defaultfontsize = get (0, "defaultaxesfontsize"); + axesfontsize = get (findobj (opts.figure, "type", "axes"), "fontsize"); + if (iscell (axesfontsize)) + axesfontsize = round (median (cell2mat (axesfontsize))); + endif + if (isempty (axesfontsize)) + opts.fontsize = defaultfontsize; + else + opts.fontsize = axesfontsize; + endif + endif + ## The axes-label and tick-label spacing is determined by + ## the font spec given in "set terminal ..." + gp_opts = font_spec (opts); + + pipeline = ""; + + switch (lower (opts.devopt)) + case {"eps", "eps2", "epsc", "epsc2"} + if (any (strcmp (opts.devopt, {"eps", "epsc"}))) + gp_opts = sprintf ("%s level1", gp_opts); + endif + if (opts.tight_flag || ! isempty (opts.preview)) + tmp_file = strcat (tmpnam (), ".eps"); + eps_drawnow (opts, tmp_file, gp_opts); + if (dos_shell) + cleanup = sprintf (" & del %s", strrep (tmp_file, '/', '\')); + else + cleanup = sprintf (" ; rm %s", tmp_file); + endif + pipeline = {sprintf("%s %s", + opts.epstool_cmd (opts, tmp_file, opts.name), + cleanup)}; + else + eps_drawnow (opts, opts.name, gp_opts); + endif + case {"epslatex", "pslatex", "pstex", "epslatexstandalone"} + dot = find (opts.name == ".", 1, "last"); + if ((! isempty (dot)) + && any (strcmpi (opts.name(dot:end), + {".eps", ".ps", ".pdf", ".tex", "."}))) + name = opts.name(1:dot-1); + endif + if (strfind (opts.devopt, "standalone")) + term = sprintf ("%s ", + strrep (opts.devopt, "standalone", " standalone")); + else + term = sprintf ("%s ", opts.devopt); + endif + if (__gnuplot_has_feature__ ("epslatex_implies_eps_filesuffix")) + suffix = "tex"; + else + %% Gnuplot 4.0 wants a ".eps" suffix. + suffix = "eps"; + endif + local_drawnow (sprintf ("%s %s", term, gp_opts), + strcat (name, ".", suffix), opts); + case "tikz" + if (__gnuplot_has_terminal__ ("tikz")) + local_drawnow (sprintf ("lua tikz %s", gp_opts), opts.name, opts); + else + error (sprintf ("print:no%soutput", opts.devopt), + "print.m: '%s' output is not available for gnuplot-%s", + upper (opts.devopt), __gnuplot_version__ ()); + endif + case "svg" + local_drawnow (sprintf ("svg dynamic %s", gp_opts), opts.name, opts); + case {"aifm", "corel", "eepic", "emf", "fig"} + local_drawnow (sprintf ("%s %s", opts.devopt, gp_opts), opts.name, opts); + case {"pdfcairo", "pngcairo"} + if (__gnuplot_has_terminal__ (opts.devopt)) + local_drawnow (sprintf ("%s %s", opts.devopt, gp_opts), opts.name, opts); + else + error (sprintf ("print:no%soutput", opts.devopt), + "print.m: '%s' output is not available for gnuplot-%s", + upper (opts.devopt), __gnuplot_version__ ()); + endif + case {"canvas", "dxf", "hpgl", "mf", "gif", "pstricks", "texdraw"} + local_drawnow (sprintf ("%s %s", opts.devopt, gp_opts), opts.name, opts); + case opts.ghostscript.device + gp_opts = font_spec (opts, "devopt", "eps"); + opts.ghostscript.output = opts.name; + opts.ghostscript.source = strcat (tmpnam (), ".eps"); + eps_drawnow (opts, opts.ghostscript.source, gp_opts); + [cmd_gs, cmd_cleanup] = __ghostscript__ (opts.ghostscript); + if (opts.send_to_printer || isempty (opts.name)) + cmd_lpr = opts.lpr_cmd (opts); + cmd = sprintf ("%s | %s", cmd_gs, cmd_lpr); + else + cmd = sprintf ("%s", cmd_gs); + endif + if (dos_shell) + cmd = sprintf ("%s & del %s", cmd, strrep (opts.ghostscript.source, '/', '\')); + else + cmd = sprintf ("%s ; rm %s", cmd, opts.ghostscript.source); + endif + if (! isempty (cmd_cleanup)) + if (dos_shell) + pipeline = {sprintf("%s & %s", cmd, cmd_cleanup)}; + else + pipeline = {sprintf("%s ; %s", cmd, cmd_cleanup)}; + endif + else + pipeline = {cmd}; + endif + otherwise + error (sprintf ("print:no%soutput", opts.devopt), + "print.m: %s output is not available for the Gnuplot graphics toolkit", + upper (opts.devopt)); + endswitch + + + opts.pipeline = pipeline; + + for n = 1:numel(pipeline) + if (opts.debug) + fprintf ("gnuplot-pipeline: '%s'\n", pipeline{n}); + endif + [status, output] = system (pipeline{n}); + if (status) + fprintf ("%s\n%s\n%s\n", + "---------- output begin ----------", + output, + "----------- output end -----------"); + error ("gnuplot:failedpipe", "print: failed to print"); + endif + endfor + +endfunction + +function eps_drawnow (opts, epsfile, gp_opts) + [h, fontsize] = get_figure_text_objs (opts); + unwind_protect + for n = 1:numel(h) + set (h(n), "fontsize", 2 * fontsize{n}); + endfor + local_drawnow (sprintf ("postscript eps %s", gp_opts), epsfile, opts); + unwind_protect_cleanup + for n = 1:numel(h) + set (h(n), "fontsize", fontsize{n}); + endfor + end_unwind_protect +endfunction + +function local_drawnow (term, file, opts) + if (opts.use_color < 0) + mono = true; + else + mono = false; + endif + figure (opts.figure); + if (isempty (opts.debug_file) || ! opts.debug) + drawnow (term, file, mono); + else + drawnow (term, file, mono, opts.debug_file); + endif +endfunction + +function f = font_spec (opts, varargin) + for n = 1:2:numel(varargin) + opts.(varargin{n}) = varargin{n+1}; + endfor + f = ""; + switch (opts.devopt) + case "cgm" + if (! isempty (opts.font) && ! isempty (opts.fontsize)) + f = sprintf ("font ""%s,%d""", opts.font, opts.fontsize); + elseif (! isempty (opts.font)) + f = sprintf ("font ""%s""", opts.font); + elseif (! isempty (opts.fontsize)) + f = sprintf ("%d", opts.fontsize); + endif + case {"eps", "eps2", "epsc", "epsc2"} + ## Gnuplot renders fonts as half their specification, which + ## results in a tight spacing for the axes-labels and tick-labels. + ## Compensate for the half scale. This will produce the proper + ## spacing for the requested fontsize. + if (! isempty (opts.font) && ! isempty (opts.fontsize)) + f = sprintf ("font ""%s,%d""", opts.font, 2 * opts.fontsize); + elseif (! isempty (opts.font)) + f = sprintf ("font ""%s""", opts.font); + elseif (! isempty (opts.fontsize)) + f = sprintf ("%d", 2 * opts.fontsize); + endif + case "svg" + if (! isempty (opts.font) && ! isempty (opts.fontsize)) + fontsize = round (opts.fontsize * 0.75); + f = sprintf ("fname ""%s"" fsize %d", opts.font, fontsize); + elseif (! isempty (opts.font)) + f = sprintf ("fname ""%s""", opts.font); + elseif (! isempty (opts.fontsize)) + fontsize = round (opts.fontsize * 0.75); + f = sprintf ("%s fsize %d", f, fontsize); + endif + case "pdf" + if (! isempty (opts.font) && ! isempty (opts.fontsize)) + f = sprintf ("font ""%s,%d""", opts.font, opts.fontsize); + elseif (! isempty (opts.font)) + f = sprintf ("font ""%s""", opts.font); + elseif (! isempty (opts.fontsize)) + f = sprintf ("fsize %d", f, opts.fontsize); + endif + case {"pdfcairo", "pngcairo"} + if (! isempty (opts.font)) + f = sprintf ("font ""%s""", opts.font); + endif + case {"epslatex", "epslatexstandalone"} + if (! isempty (opts.font) && ! isempty (opts.fontsize)) + f = sprintf ("font ""%s,%d""", opts.font, opts.fontsize); + elseif (! isempty (opts.font)) + f = sprintf ("font ""%s""", opts.font); + elseif (! isempty (opts.fontsize)) + f = sprintf ("%d", opts.fontsize); + endif + case "pslatex" + if (! isempty (opts.fontsize)) + f = sprintf ("%d", opts.fontsize); + endif + case {"gif", "jpeg", "png"} + if (! isempty (opts.font) && ! isempty (opts.fontsize)) + f = sprintf ("font ""%s ,%d""", opts.font, opts.fontsize); + elseif (! isempty (opts.font)) + f = sprintf ("font ""%s""", opts.font); + elseif (! isempty (opts.fontsize)) + f = sprintf ("font ""%d""", opts.fontsize); + endif + case "emf" + if (! isempty (opts.font) && ! isempty (opts.fontsize)) + f = sprintf ("""%s"" %d", opts.font, opts.fontsize); + elseif (! isempty (opts.font)) + f = sprintf ("""%s""", opts.font); + elseif (! isempty (opts.fontsize)) + f = sprintf ("%d", opts.fontsize); + endif + case "canvas" + if (! isempty (opts.fontsize)) + f = sprintf ("fsize %d", opts.fontsize); + endif + case {"aifm", "corel"} + if (! isempty (opts.font) && ! isempty (opts.fontsize)) + f = sprintf ("%s %d", opts.font, opts.fontsize); + elseif (! isempty (opts.font)) + f = sprintf ("%s", opts.font); + elseif (! isempty (opts.fontsize)) + f = sprintf ("%d", opts.fontsize); + endif + case "fig" + if (! isempty (opts.font) && ! isempty (opts.fontsize)) + f = sprintf ("font %s fontsize %d", opts.font, opts.fontsize); + elseif (! isempty (opts.font)) + f = sprintf ("font %s", opts.font); + elseif (! isempty (opts.fontsize)) + f = sprintf ("fontsize %d", opts.fontsize); + endif + endswitch +endfunction + +function [h, fontsize] = get_figure_text_objs (opts) + h = findall (opts.figure, "-property", "fontsize"); + fontsize = get (h, "fontsize"); + switch (numel (fontsize)) + case 0 + fontsize = {}; + case 1 + fontsize = {fontsize}; + endswitch +endfunction diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/private/__gnuplot_version__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/private/__gnuplot_version__.m Sat Jul 16 09:28:26 2011 -0700 @@ -0,0 +1,51 @@ +## Copyright (C) 2006-2011 Daniel Sebald +## +## 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 3 of the License, 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, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{version} =} __gnuplot_version__ () +## Undocumented internal function. +## @end deftypefn + +## Return the version of gnuplot we are using. Note that we do not +## attempt to handle the case of the user switching to different +## versions of gnuplot during the same session. + +function version = __gnuplot_version__ () + + persistent __version__ = ""; + + if (isempty (__version__)) + [status, output] = system (sprintf ("\"%s\" --version", gnuplot_binary ())); + if (status != 0) + ## This message ends in a newline so that the traceback messages + ## are skipped and people might actually see the message, read it, + ## comprehend it, actually take the advice it gives, and stop + ## asking us why plotting fails when gnuplot is not found. + error ("you must have gnuplot installed to display graphics; if you have gnuplot installed in a non-standard location, see the 'gnuplot_binary' function\n"); + endif + output = strrep (output, "gnuplot", ""); + output = strrep (output, "patchlevel", "."); + output = strrep (output, "\n", ""); + output = strrep (output, "\r", ""); + __version__ = strrep (output, " ", ""); + endif + + version = __version__; + +endfunction + diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/private/__go_draw_axes__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/private/__go_draw_axes__.m Sat Jul 16 09:28:26 2011 -0700 @@ -0,0 +1,2456 @@ +## Copyright (C) 2005-2011 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 3 of the License, 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, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {} __go_draw_axes__ (@var{h}, @var{plot_stream}, @var{enhanced}, @var{mono}) +## Undocumented internal function. +## @end deftypefn + +## Author: jwe + +function __go_draw_axes__ (h, plot_stream, enhanced, mono, + bg_is_set, fg_is_set, hlgnd) + + if (nargin >= 4 && nargin <= 7) + + showhiddenhandles = get (0, "showhiddenhandles"); + unwind_protect + set (0, "showhiddenhandles", "on"); + axis_obj = __get__ (h); + unwind_protect_cleanup + set (0, "showhiddenhandles", showhiddenhandles); + end_unwind_protect + + parent_figure_obj = get (axis_obj.parent); + gnuplot_term = __gnuplot_get_var__ (axis_obj.parent, "GPVAL_TERM"); + + ## Set to false for plotyy axes. + if (strcmp (axis_obj.tag, "plotyy")) + ymirror = false; + else + ymirror = true; + endif + + nd = __calc_dimensions__ (h); + + if (strcmp (axis_obj.dataaspectratiomode, "manual") + && strcmp (axis_obj.xlimmode, "manual") + && strcmp (axis_obj.ylimmode, "manual")) + ## All can't be "manual" + axis_obj.plotboxaspectratiomode = "auto"; + endif + + if (strcmp (axis_obj.dataaspectratiomode, "manual") + && strcmp (axis_obj.xlimmode, "manual") + && strcmp (axis_obj.ylimmode, "manual") + && (nd == 2 || all (mod (axis_obj.view, 90) == 0))) + ## FIXME - adjust plotboxaspectratio to respect other + fpos = get (axis_obj.parent, "position"); + apos = axis_obj.position; + endif + + pos = __actual_axis_position__ (h); + + if (strcmpi (axis_obj.dataaspectratiomode, "manual")) + dr = axis_obj.dataaspectratio; + if (nd == 2 || all (mod (axis_obj.view, 90) == 0)) + dr = dr(1) / dr(2); + else + ## FIXME - need to properly implement 3D + dr = mean (dr(1:2)) / dr(3); + endif + else + dr = 1; + endif + + if (strcmp (axis_obj.activepositionproperty, "position")) + if (__gnuplot_has_feature__ ("screen_coordinates_for_{lrtb}margin")) + if (nd == 2 || all (mod (axis_obj.view, 90) == 0)) + x = [1, 1]; + else + ## 3D plots need to be sized down to fit in the window. + x = 1.0 ./ sqrt([2, 2.5]); + endif + fprintf (plot_stream, "set tmargin screen %.15g;\n", + pos(2)+pos(4)/2+x(2)*pos(4)/2); + fprintf (plot_stream, "set bmargin screen %.15g;\n", + pos(2)+pos(4)/2-x(2)*pos(4)/2); + fprintf (plot_stream, "set lmargin screen %.15g;\n", + pos(1)+pos(3)/2-x(1)*pos(3)/2); + fprintf (plot_stream, "set rmargin screen %.15g;\n", + pos(1)+pos(3)/2+x(1)*pos(3)/2); + sz_str = ""; + else + fprintf (plot_stream, "set tmargin 0;\n"); + fprintf (plot_stream, "set bmargin 0;\n"); + fprintf (plot_stream, "set lmargin 0;\n"); + fprintf (plot_stream, "set rmargin 0;\n"); + + if (nd == 3 && all (axis_obj.view == [0, 90])) + ## FIXME -- Kludge to allow colorbar to be added to a pcolor() plot + pos(3:4) = pos(3:4) * 1.4; + pos(1:2) = pos(1:2) - pos(3:4) * 0.125; + endif + + fprintf (plot_stream, "set origin %.15g, %.15g;\n", pos(1), pos(2)); + + if (strcmpi (axis_obj.dataaspectratiomode, "manual")) + sz_str = sprintf ("set size ratio %.15g", -dr); + else + sz_str = "set size noratio"; + endif + sz_str = sprintf ("%s %.15g, %.15g;\n", sz_str, pos(3), pos(4)); + endif + else ## activepositionproperty == outerposition + fprintf (plot_stream, "unset tmargin;\n"); + fprintf (plot_stream, "unset bmargin;\n"); + fprintf (plot_stream, "unset lmargin;\n"); + fprintf (plot_stream, "unset rmargin;\n"); + fprintf (plot_stream, "set origin %g, %g;\n", pos(1:2)); + sz_str = ""; + if (strcmpi (axis_obj.dataaspectratiomode, "manual")) + sz_str = sprintf ("ratio %g", -dr); + else + sz_str = "noratio"; + endif + sz_str = sprintf ("set size %s %g, %g;\n", sz_str, pos(3:4)); + endif + if (! isempty (sz_str)) + fputs (plot_stream, sz_str); + endif + + ## Reset all labels, axis-labels, tick-labels, and title + ## FIXME - We should have an function to initialize the axis. + ## Presently, this is dispersed in this function. + fputs (plot_stream, "unset label;\n"); + fputs (plot_stream, "unset xtics;\n"); + fputs (plot_stream, "unset ytics;\n"); + fputs (plot_stream, "unset ztics;\n"); + fputs (plot_stream, "unset x2tics;\n"); + fputs (plot_stream, "unset x2tics;\n"); + + if (! isempty (axis_obj.title)) + t = get (axis_obj.title); + if (isempty (t.string)) + fputs (plot_stream, "unset title;\n"); + else + [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string"); + fontspec = create_fontspec (f, s, gnuplot_term); + fprintf (plot_stream, "set title \"%s\" %s %s;\n", + undo_string_escapes (tt), fontspec, + __do_enhanced_option__ (enhanced, t)); + endif + endif + + if (! isempty (axis_obj.xlabel)) + t = get (axis_obj.xlabel); + angle = t.rotation; + colorspec = get_text_colorspec (axis_obj.xcolor, mono); + if (isempty (t.string)) + fprintf (plot_stream, "unset xlabel;\n"); + fprintf (plot_stream, "unset x2label;\n"); + else + [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string"); + fontspec = create_fontspec (f, s, gnuplot_term); + if (strcmpi (axis_obj.xaxislocation, "top")) + fprintf (plot_stream, "set x2label \"%s\" %s %s %s", + undo_string_escapes (tt), colorspec, fontspec, + __do_enhanced_option__ (enhanced, t)); + else + fprintf (plot_stream, "set xlabel \"%s\" %s %s %s", + undo_string_escapes (tt), colorspec, fontspec, + __do_enhanced_option__ (enhanced, t)); + endif + fprintf (plot_stream, " rotate by %f;\n", angle); + if (strcmpi (axis_obj.xaxislocation, "top")) + fprintf (plot_stream, "unset xlabel;\n"); + else + fprintf (plot_stream, "unset x2label;\n"); + endif + endif + endif + + if (! isempty (axis_obj.ylabel)) + t = get (axis_obj.ylabel); + angle = t.rotation; + colorspec = get_text_colorspec (axis_obj.ycolor, mono); + if (isempty (t.string)) + fprintf (plot_stream, "unset ylabel;\n"); + fprintf (plot_stream, "unset y2label;\n"); + else + [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string"); + fontspec = create_fontspec (f, s, gnuplot_term); + if (strcmpi (axis_obj.yaxislocation, "right")) + fprintf (plot_stream, "set y2label \"%s\" %s %s %s", + undo_string_escapes (tt), colorspec, fontspec, + __do_enhanced_option__ (enhanced, t)); + else + fprintf (plot_stream, "set ylabel \"%s\" %s %s %s", + undo_string_escapes (tt), colorspec, fontspec, + __do_enhanced_option__ (enhanced, t)); + endif + fprintf (plot_stream, " rotate by %f;\n", angle); + if (strcmpi (axis_obj.yaxislocation, "right")) + fprintf (plot_stream, "unset ylabel;\n"); + else + fprintf (plot_stream, "unset y2label;\n"); + endif + endif + endif + + if (! isempty (axis_obj.zlabel)) + t = get (axis_obj.zlabel); + angle = t.rotation; + colorspec = get_text_colorspec (axis_obj.zcolor, mono); + if (isempty (t.string)) + fputs (plot_stream, "unset zlabel;\n"); + else + [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string"); + fontspec = create_fontspec (f, s, gnuplot_term); + fprintf (plot_stream, "set zlabel \"%s\" %s %s %s", + undo_string_escapes (tt), colorspec, fontspec, + __do_enhanced_option__ (enhanced, t)); + fprintf (plot_stream, " rotate by %f;\n", angle); + endif + endif + + if (strcmpi (axis_obj.xaxislocation, "top")) + xaxisloc = "x2"; + xaxisloc_using = "x2"; + else + xaxisloc = "x"; + xaxisloc_using = "x1"; + if (strcmpi (axis_obj.xaxislocation, "zero")) + fputs (plot_stream, "set xzeroaxis;\n"); + endif + endif + if (strcmpi (axis_obj.yaxislocation, "right")) + yaxisloc = "y2"; + yaxisloc_using = "y2"; + else + yaxisloc = "y"; + yaxisloc_using = "y1"; + if (strcmpi (axis_obj.yaxislocation, "zero")) + fputs (plot_stream, "set yzeroaxis;\n"); + endif + endif + + have_grid = false; + + if (strcmpi (axis_obj.xgrid, "on")) + have_grid = true; + fprintf (plot_stream, "set grid %stics;\n", xaxisloc); + else + fprintf (plot_stream, "set grid no%stics;\n", xaxisloc); + endif + + if (strcmpi (axis_obj.ygrid, "on")) + have_grid = true; + fprintf (plot_stream, "set grid %stics;\n", yaxisloc); + else + fprintf (plot_stream, "set grid no%stics;\n", yaxisloc); + endif + + if (strcmpi (axis_obj.zgrid, "on")) + have_grid = true; + fputs (plot_stream, "set grid ztics;\n"); + else + fputs (plot_stream, "set grid noztics;\n"); + endif + + if (strcmpi (axis_obj.xminorgrid, "on")) + have_grid = true; + if (strcmp (axis_obj.xscale, "log")) + m = 10; + else + m = 5; + endif + fprintf (plot_stream, "set m%stics %d;\n", xaxisloc, m); + fprintf (plot_stream, "set grid m%stics;\n", xaxisloc); + else + fprintf (plot_stream, "set grid nom%stics;\n", xaxisloc); + endif + + if (strcmpi (axis_obj.yminorgrid, "on")) + have_grid = true; + if (strcmp (axis_obj.yscale, "log")) + m = 10; + else + m = 5; + endif + fprintf (plot_stream, "set m%stics %d;\n", yaxisloc, m); + fprintf (plot_stream, "set grid m%stics;\n", yaxisloc); + else + fprintf (plot_stream, "set grid nom%stics;\n", yaxisloc); + endif + + if (strcmpi (axis_obj.zminorgrid, "on")) + have_grid = true; + if (strcmp (axis_obj.zscale, "log")) + m = 10; + else + m = 5; + endif + fprintf (plot_stream, "set mztics %d;\n", m); + fputs (plot_stream, "set grid mztics;\n"); + else + fputs (plot_stream, "set grid nomztics;\n"); + endif + + ## The grid front/back/layerdefault option also controls the + ## appearance of tics, so it is used even if the grid is absent. + if (strcmpi (axis_obj.layer, "top")) + fputs (plot_stream, "set grid front;\n"); + fputs (plot_stream, "set border front;\n"); + else + fputs (plot_stream, "set grid layerdefault;\n"); + ## FIXME -- the gnuplot help says that "layerdefault" should work + ## for set border too, but it fails for me with gnuplot 4.2.5. So + ## use "back" instead. + fputs (plot_stream, "set border back;\n"); + endif + + fprintf (plot_stream, "set grid linewidth %f, linewidth %f;\n", + axis_obj.linewidth, axis_obj.linewidth); + + if (! have_grid) + fputs (plot_stream, "unset grid;\n"); + endif + + do_tics (axis_obj, plot_stream, ymirror, mono, gnuplot_term); + + fputs (plot_stream, "unset logscale;\n"); + xlogscale = strcmpi (axis_obj.xscale, "log"); + ylogscale = strcmpi (axis_obj.yscale, "log"); + zlogscale = strcmpi (axis_obj.zscale, "log"); + if (xlogscale) + fprintf (plot_stream, "set logscale %s;\n", xaxisloc); + endif + if (ylogscale) + fprintf (plot_stream, "set logscale %s;\n", yaxisloc); + endif + if (zlogscale) + fputs (plot_stream, "set logscale z;\n"); + endif + + xautoscale = strcmpi (axis_obj.xlimmode, "auto"); + yautoscale = strcmpi (axis_obj.ylimmode, "auto"); + zautoscale = strcmpi (axis_obj.zlimmode, "auto"); + cautoscale = strcmpi (axis_obj.climmode, "auto"); + cdatadirect = false; + truecolor = false; + + fputs (plot_stream, "set clip two;\n"); + + kids = axis_obj.children; + ## Remove the axis labels and title from the children, and + ## preserved the original order. + [jnk, k] = setdiff (kids, [axis_obj.xlabel; axis_obj.ylabel; ... + axis_obj.zlabel; axis_obj.title]); + kids = kids (sort (k)); + + if (nd == 3) + fputs (plot_stream, "set parametric;\n"); + fputs (plot_stream, "set style data lines;\n"); + fputs (plot_stream, "set surface;\n"); + fputs (plot_stream, "unset contour;\n"); + endif + + data_idx = 0; + data = cell (); + is_image_data = []; + hidden_removal = NaN; + view_map = false; + + xlim = axis_obj.xlim; + ylim = axis_obj.ylim; + zlim = axis_obj.zlim; + clim = axis_obj.clim; + + if (! cautoscale && clim(1) == clim(2)) + clim(2)++; + endif + addedcmap = []; + + ximg_data = {}; + ximg_data_idx = 0; + + while (! isempty (kids)) + + obj = get (kids(end)); + if (isfield (obj, "units")) + units = obj.units; + unwind_protect + set (kids(end), "units", "data"); + obj = get (kids(end)); + unwind_protect_cleanup + set (kids(end), "units", units); + end_unwind_protect + endif + kids = kids(1:(end-1)); + + if (strcmpi (obj.visible, "off")) + continue; + endif + + if (xlogscale && isfield (obj, "xdata")) + obj.xdata(obj.xdata<=0) = NaN; + endif + if (ylogscale && isfield (obj, "ydata")) + obj.ydata(obj.ydata<=0) = NaN; + endif + if (zlogscale && isfield (obj, "zdata")) + obj.zdata(obj.zdata<=0) = NaN; + endif + + ## Check for facecolor interpolation for surfaces. + doing_interp_color = ... + isfield (obj, "facecolor") && strncmp (obj.facecolor, "interp", 6); + + switch (obj.type) + case "image" + img_data = obj.cdata; + img_xdata = obj.xdata; + img_ydata = obj.ydata; + + if (ndims (img_data) == 3) + truecolor = true; + elseif (strcmpi (obj.cdatamapping, "direct")) + cdatadirect = true; + endif + data_idx++; + is_image_data(data_idx) = true; + parametric(data_idx) = false; + have_cdata(data_idx) = false; + have_3d_patch(data_idx) = false; + + if (img_xdata(2) < img_xdata(1)) + img_xdata = img_xdata(2:-1:1); + img_data = img_data(:,end:-1:1,:); + elseif (img_xdata(1) == img_xdata(2)) + img_xdata = img_xdata(1) + [0, size(img_data,2)-1]; + endif + if (img_ydata(2) < img_ydata(1)) + img_ydata = img_ydata(2:-1:1); + img_data = img_data(end:-1:1,:,:); + elseif (img_ydata(1) == img_ydata(2)) + img_ydata = img_ydata(1) + [0, size(img_data,1)-1]; + endif + + [y_dim, x_dim] = size (img_data(:,:,1)); + if (x_dim > 1) + dx = abs (img_xdata(2)-img_xdata(1))/(x_dim-1); + else + x_dim = 2; + img_data = [img_data, img_data]; + dx = abs (img_xdata(2)-img_xdata(1)); + endif + if (y_dim > 1) + dy = abs (img_ydata(2)-img_ydata(1))/(y_dim-1); + else + y_dim = 2; + img_data = [img_data; img_data]; + dy = abs (img_ydata(2)-img_ydata(1)); + endif + + x_origin = min (img_xdata); + y_origin = min (img_ydata); + + if (ndims (img_data) == 3) + data{data_idx} = permute (img_data, [3, 1, 2])(:); + format = "1:2:3"; + imagetype = "rgbimage"; + else + data{data_idx} = img_data(:); + format = "1"; + imagetype = "image"; + endif + + titlespec{data_idx} = "title \"\""; + usingclause{data_idx} = sprintf ("binary array=%dx%d scan=yx origin=(%.15g,%.15g) dx=%.15g dy=%.15g using %s", + x_dim, y_dim, x_origin, y_origin, dx, dy, format); + withclause{data_idx} = sprintf ("with %s;", imagetype); + + case "line" + if (strncmp (obj.linestyle, "none", 4) + && (! isfield (obj, "marker") + || (isfield (obj, "marker") + && strncmp (obj.marker, "none", 4)))) + continue; + endif + data_idx++; + is_image_data(data_idx) = false; + parametric(data_idx) = true; + have_cdata(data_idx) = false; + have_3d_patch(data_idx) = false; + if (isempty (obj.displayname)) + titlespec{data_idx} = "title \"\""; + else + tmp = undo_string_escapes (__maybe_munge_text__ (enhanced, obj, "displayname")); + titlespec{data_idx} = cstrcat ("title \"", tmp, "\""); + endif + usingclause{data_idx} = sprintf ("record=%d", numel (obj.xdata)); + errbars = ""; + if (nd == 3) + xdat = obj.xdata(:); + ydat = obj.ydata(:); + if (! isempty (obj.zdata)) + zdat = obj.zdata(:); + else + zdat = zeros (size (xdat)); + endif + data{data_idx} = [xdat, ydat, zdat]'; + usingclause{data_idx} = sprintf ("record=%d using ($1):($2):($3)", numel (xdat)); + ## fputs (plot_stream, "set parametric;\n"); + else + xdat = obj.xdata(:); + ydat = obj.ydata(:); + data{data_idx} = [xdat, ydat]'; + usingclause{data_idx} = sprintf ("record=%d using ($1):($2) axes %s%s", + rows(xdat), xaxisloc_using, yaxisloc_using); + endif + + style = do_linestyle_command (obj, obj.color, data_idx, mono, + plot_stream, errbars); + + withclause{data_idx} = sprintf ("with %s linestyle %d", + style{1}, data_idx); + + if (length (style) > 1) + data_idx++; + is_image_data(data_idx) = is_image_data(data_idx - 1); + parametric(data_idx) = parametric(data_idx - 1); + have_cdata(data_idx) = have_cdata(data_idx - 1); + have_3d_patch(data_idx) = have_3d_patch(data_idx - 1); + titlespec{data_idx} = "title \"\""; + usingclause{data_idx} = usingclause{data_idx - 1}; + data{data_idx} = data{data_idx - 1}; + withclause{data_idx} = sprintf ("with %s linestyle %d", + style{2}, data_idx); + endif + if (length (style) > 2) + data_idx++; + is_image_data(data_idx) = is_image_data(data_idx - 1); + parametric(data_idx) = parametric(data_idx - 1); + have_cdata(data_idx) = have_cdata(data_idx - 1); + have_3d_patch(data_idx) = have_3d_patch(data_idx - 1); + titlespec{data_idx} = "title \"\""; + usingclause{data_idx} = usingclause{data_idx - 1}; + data{data_idx} = data{data_idx - 1}; + withclause{data_idx} = sprintf ("with %s linestyle %d", + style{3}, data_idx); + endif + + case "patch" + cmap = parent_figure_obj.colormap; + [nr, nc] = size (obj.xdata); + + if (! isempty (obj.cdata)) + cdat = obj.cdata; + if (strcmpi (obj.cdatamapping, "direct")) + cdatadirect = true; + endif + else + cdat = []; + endif + + data_3d_idx = NaN; + for i = 1:nc + xcol = obj.xdata(:,i); + ycol = obj.ydata(:,i); + if (nd == 3) + if (! isempty (obj.zdata)) + zcol = obj.zdata(:,i); + else + zcol = zeros (size (xcol)); + endif + endif + + if (! isnan (xcol) && ! isnan (ycol)) + ## Is the patch closed or not + if (strncmp (obj.facecolor, "none", 4)) + hidden_removal = false; + else + + if (isnan (hidden_removal)) + hidden_removal = true; + endif + if (nd == 3) + if (numel (xcol) > 3) + error ("__go_draw_axes__: gnuplot (as of v4.2) only supports 3D filled triangular patches"); + else + if (isnan (data_3d_idx)) + data_idx++; + data_3d_idx = data_idx; + is_image_data(data_idx) = false; + parametric(data_idx) = false; + have_cdata(data_idx) = true; + have_3d_patch(data_idx) = true; + withclause{data_3d_idx} = sprintf ("with pm3d"); + usingclause{data_3d_idx} = "using 1:2:3:4"; + data{data_3d_idx} = []; + endif + local_idx = data_3d_idx; + ccdat = NaN; + endif + else + data_idx++; + local_idx = data_idx; + is_image_data(data_idx) = false; + parametric(data_idx) = false; + have_cdata(data_idx) = false; + have_3d_patch(data_idx) = false; + endif + + if (i > 1 || isempty (obj.displayname)) + titlespec{local_idx} = "title \"\""; + else + tmp = undo_string_escapes (__maybe_munge_text__ (enhanced, obj, "displayname")); + titlespec{local_idx} = cstrcat ("title \"", tmp, "\""); + endif + if (isfield (obj, "facecolor")) + if ((strncmp (obj.facecolor, "flat", 4) + || strncmp (obj.facecolor, "interp", 6)) + && isfield (obj, "cdata")) + if (ndims (obj.cdata) == 2 + && (size (obj.cdata, 2) == nc + && (size (obj.cdata, 1) == 1 + || size (obj.cdata, 1) == 3))) + ccol = cdat (:, i); + elseif (ndims (obj.cdata) == 2 + && (size (obj.cdata, 1) == nc + && (size (obj.cdata, 2) == 1 + || size (obj.cdata, 2) == 3))) + ccol = cdat (i, :); + elseif (ndims (obj.cdata) == 3) + ccol = permute (cdat (:, i, :), [1, 3, 2]); + else + ccol = cdat; + endif + if (strncmp (obj.facecolor, "flat", 4)) + if (numel(ccol) == 3) + color = ccol; + elseif (nd == 3 && numel (xcol) == 3) + ccdat = ccol * ones (3,1); + else + r = 1 + round ((size (cmap, 1) - 1) + * (ccol - clim(1))/(clim(2) - clim(1))); + r = max (1, min (r, size (cmap, 1))); + color = cmap(r, :); + endif + elseif (strncmp (obj.facecolor, "interp", 6)) + if (nd == 3 && numel (xcol) == 3) + ccdat = ccol; + if (! isvector (ccdat)) + tmp = rows(cmap) + rows(addedcmap) + ... + [1 : rows(ccdat)]; + addedcmap = [addedcmap; ccdat]; + ccdat = tmp(:); + else + ccdat = ccdat(:); + endif + else + warning ("\"interp\" not supported, using 1st entry of cdata"); + r = 1 + round ((size (cmap, 1) - 1) * ccol(1)); + r = max (1, min (r, size (cmap, 1))); + color = cmap(r,:); + endif + endif + elseif (isnumeric (obj.facecolor)) + color = obj.facecolor; + else + color = [0, 1, 0]; + endif + else + color = [0, 1, 0]; + endif + + if (nd == 3 && numel (xcol) == 3) + if (isnan (ccdat)) + ccdat = (rows (cmap) + rows(addedcmap) + 1) * ones(3, 1); + addedcmap = [addedcmap; reshape(color, 1, 3)]; + endif + data{data_3d_idx} = [data{data_3d_idx}, ... + [[xcol; xcol(end)], [ycol; ycol(end)], ... + [zcol; zcol(end)], [ccdat; ccdat(end)]]']; + else + if (mono) + colorspec = ""; + elseif (__gnuplot_has_feature__ ("transparent_patches") + && isscalar (obj.facealpha)) + colorspec = sprintf ("lc rgb \"#%02x%02x%02x\" fillstyle transparent solid %f", + round (255*color), obj.facealpha); + else + colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"", + round (255*color)); + endif + + withclause{data_idx} = sprintf ("with filledcurve %s", + colorspec); + data{data_idx} = [xcol, ycol]'; + usingclause{data_idx} = sprintf ("record=%d using ($1):($2)", + numel (xcol)); + endif + endif + endif + + ## patch outline + if (!(strncmp (obj.edgecolor, "none", 4) + && (strncmp (obj.marker, "none", 4) + || (strncmp (obj.markeredgecolor, "none", 4) + && strncmp (obj.markerfacecolor, "none", 4))))) + + data_idx++; + is_image_data(data_idx) = false; + parametric(data_idx) = false; + have_cdata(data_idx) = false; + have_3d_patch(data_idx) = false; + titlespec{data_idx} = "title \"\""; + usingclause{data_idx} = sprintf ("record=%d", numel (obj.xdata)); + + if (isfield (obj, "markersize")) + mdat = obj.markersize / 3; + endif + + if (isfield (obj, "edgecolor")) + ## FIXME + ## This is the wrong thing to do as edgecolor, markeredgecolor + ## and markerfacecolor can have different values and we should + ## treat them seperately. However, the below allow the scatter + ## functions to work as expected, where only one of these values + ## is set + if (strncmp (obj.edgecolor, "none", 4)) + if (strncmp (obj.markeredgecolor, "none", 4)) + ec = obj.markerfacecolor; + else + ec = obj.markeredgecolor; + endif + else + ec = obj.edgecolor; + endif + + if ((strncmp (ec, "flat", 4) + || strncmp (ec, "interp", 6)) + && isfield (obj, "cdata")) + if (ndims (obj.cdata) == 2 + && (size (obj.cdata, 2) == nc + && (size (obj.cdata, 1) == 1 + || size (obj.cdata, 1) == 3))) + ccol = cdat (:, i); + elseif (ndims (obj.cdata) == 2 + && (size (obj.cdata, 1) == nc + && (size (obj.cdata, 2) == 1 + || size (obj.cdata, 2) == 3))) + ccol = cdat (i, :); + elseif (ndims (obj.cdata) == 3) + ccol = permute (cdat (:, i, :), [1, 3, 2]); + else + ccol = cdat; + endif + if (strncmp (ec, "flat", 4)) + if (numel(ccol) == 3) + color = ccol; + else + if (isscalar (ccol)) + ccol = repmat(ccol, numel (xcol), 1); + endif + color = "flat"; + have_cdata(data_idx) = true; + endif + elseif (strncmp (ec, "interp", 6)) + if (numel(ccol) == 3) + warning ("\"interp\" not supported, using 1st entry of cdata"); + color = ccol(1,:); + else + if (isscalar (ccol)) + ccol = repmat(ccol, numel (xcol), 1); + endif + color = "interp"; + have_cdata(data_idx) = true; + endif + endif + elseif (isnumeric (ec)) + color = ec; + else + color = [0, 0, 0]; + endif + else + color = [0, 0, 0]; + endif + + if (isfield (obj, "linestyle")) + switch (obj.linestyle) + case "-" + lt = "lt 1"; + case "--" + lt = "lt 2"; + case ":" + lt = "lt 3"; + case "-." + lt = "lt 6"; + case "none" + lt = ""; + otherwise + lt = ""; + endswitch + else + lt = ""; + endif + + if (isfield (obj, "linewidth")) + lw = sprintf("linewidth %f", obj.linewidth); + else + lw = ""; + endif + + [pt, pt2, obj] = gnuplot_pointtype (obj); + if (! isempty (pt)) + pt = sprintf ("pointtype %s", pt); + endif + if (! isempty (pt2)) + pt2 = sprintf ("pointtype %s", pt2); + endif + + if (mono) + colorspec = ""; + else + if (ischar (color)) + colorspec = "palette"; + else + colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"", + round (255*color)); + endif + endif + + sidx = 1; + if (isempty (lt)) + style = ""; + else + style = "lines"; + endif + tmpwith = {}; + + facesame = true; + if (! isequal (pt, pt2) && isfield (obj, "markerfacecolor") + && !strncmp (obj.markerfacecolor, "none", 4)) + if (strncmp (obj.markerfacecolor, "auto", 4) + || ! isnumeric (obj.markerfacecolor) + || (isnumeric (obj.markerfacecolor) + && isequal (color, obj.markerfacecolor))) + style = strcat (style, "points"); + if (isfield (obj, "markersize")) + if (length (mdat) == nc) + m = mdat(i); + else + m = mdat; + endif + ps = sprintf("pointsize %f", m / 3); + else + ps = ""; + endif + + tmpwith{sidx} = sprintf ("with %s %s %s %s %s %s", + style, lw, pt2, lt, ps, + colorspec); + else + facesame = false; + if (! isempty (style)) + tmpwith{sidx} = sprintf ("with %s %s %s %s", + style, lw, lt, + colorspec); + sidx ++; + endif + if (isnumeric (obj.markerfacecolor) && ! mono) + colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"", + round (255*obj.markerfacecolor)); + endif + style = "points"; + if (isfield (obj, "markersize")) + if (length (mdat) == nc) + m = mdat(i); + else + m = mdat; + endif + ps = sprintf("pointsize %f", m / 3); + else + ps = ""; + endif + tmpwith{sidx} = sprintf ("with %s %s %s %s %s %s", + style, lw, pt2, lt, ps, + colorspec); + endif + endif + + if (isfield (obj, "markeredgecolor") + && !strncmp (obj.markeredgecolor, "none", 4)) + if (facesame && !isempty (pt) + && (strncmp (obj.markeredgecolor, "auto", 4) + || ! isnumeric (obj.markeredgecolor) + || (isnumeric (obj.markeredgecolor) + && isequal (color, obj.markeredgecolor)))) + if (sidx == 1 && ((length (style) == 5 + && strncmp (style, "lines", 5)) + || isempty (style))) + style = strcat (style, "points"); + if (isfield (obj, "markersize")) + if (length (mdat) == nc) + m = mdat(i); + else + m = mdat; + endif + ps = sprintf("pointsize %f", m / 3); + else + ps = ""; + endif + tmpwith{sidx} = sprintf ("with %s %s %s %s %s %s", + style, lw, pt, lt, ps, + colorspec); + endif + else + if (!isempty (style)) + if (length(tmpwith) < sidx || isempty (tmpwith{sidx})) + tmpwith{sidx} = sprintf ("with %s %s %s %s", + style, lw, lt, + colorspec); + endif + sidx ++; + endif + + if (!isempty (pt)) + if (! mono) + if (strncmp (obj.markeredgecolor, "auto", 4)) + colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"", + round (255*color)); + elseif (isnumeric (obj.markeredgecolor) && ! mono) + colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"", + round (255*obj.markeredgecolor)); + endif + endif + style = "points"; + if (isfield (obj, "markersize")) + if (length (mdat) == nc) + m = mdat(i); + else + m = mdat; + endif + ps = sprintf("pointsize %f", m / 3); + else + ps = ""; + endif + tmpwith{sidx} = sprintf ("with %s %s %s %s %s %s", + style, lw, pt, lt, ps, + colorspec); + endif + endif + endif + + if (isempty (tmpwith)) + withclause{data_idx} = sprintf ("with %s %s %s %s %s", + style, lw, pt, lt, + colorspec); + else + withclause{data_idx} = tmpwith{1}; + endif + if (nd == 3) + if (ischar (color)) + if (! isnan (xcol) && ! isnan (ycol) && ! isnan (zcol)) + data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)], ... + [zcol; zcol(1)], [ccol; ccol(1)]]'; + else + data{data_idx} = [xcol, ycol, zcol, ccol]'; + endif + usingclause{data_idx} = sprintf ("record=%d using ($1):($2):($3):($4)", columns (data{data_idx})); + else + if (! isnan (xcol) && ! isnan (ycol) && ! isnan (zcol)) + data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)], ... + [zcol; zcol(1)]]'; + else + data{data_idx} = [xcol, ycol, zcol]'; + endif + usingclause{data_idx} = sprintf ("record=%d using ($1):($2):($3)", columns (data{data_idx})); + endif + else + if (ischar (color)) + if (! isnan (xcol) && ! isnan (ycol)) + data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)], ... + [ccol; ccol(1)]]'; + else + data{data_idx} = [xcol, ycol, ccol]'; + endif + usingclause{data_idx} = sprintf ("record=%d using ($1):($2):($3)", columns (data{data_idx})); + else + if (! isnan (xcol) && ! isnan (ycol)) + data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)]]'; + else + data{data_idx} = [xcol, ycol]'; + endif + usingclause{data_idx} = sprintf ("record=%d using ($1):($2)", columns (data{data_idx})); + endif + endif + + if (length (tmpwith) > 1) + data_idx++; + is_image_data(data_idx) = is_image_data(data_idx - 1); + parametric(data_idx) = parametric(data_idx - 1); + have_cdata(data_idx) = have_cdata(data_idx - 1); + have_3d_patch(data_idx) = have_3d_patch(data_idx - 1); + titlespec{data_idx} = "title \"\""; + usingclause{data_idx} = usingclause{data_idx - 1}; + data{data_idx} = data{data_idx - 1}; + withclause{data_idx} = tmpwith{2}; + endif + if (length (tmpwith) > 2) + data_idx++; + is_image_data(data_idx) = is_image_data(data_idx - 1); + parametric(data_idx) = parametric(data_idx - 1); + have_cdata(data_idx) = have_cdata(data_idx - 1); + have_3d_patch(data_idx) = have_3d_patch(data_idx - 1); + titlespec{data_idx} = "title \"\""; + usingclause{data_idx} = usingclause{data_idx - 1}; + data{data_idx} = data{data_idx - 1}; + withclause{data_idx} = tmpwith{3}; + endif + endif + endfor + + case "surface" + view_map = true; + if (! (strncmp (obj.edgecolor, "none", 4) + && strncmp (obj.facecolor, "none", 4))) + data_idx++; + is_image_data(data_idx) = false; + parametric(data_idx) = false; + have_cdata(data_idx) = true; + have_3d_patch(data_idx) = false; + style = do_linestyle_command (obj, obj.edgecolor, + data_idx, mono, + plot_stream); + + if (isempty (obj.displayname)) + titlespec{data_idx} = "title \"\""; + else + tmp = undo_string_escapes (__maybe_munge_text__ (enhanced, obj, "displayname")); + titlespec{data_idx} = cstrcat ("title \"", tmp, "\""); + endif + withclause{data_idx} = sprintf ("with pm3d linestyle %d", + data_idx); + withpm3d = true; + pm3didx = data_idx; + + xdat = obj.xdata; + ydat = obj.ydata; + zdat = obj.zdata; + cdat = obj.cdata; + + err = false; + if (! size_equal(zdat, cdat)) + err = true; + endif + if (isvector (xdat) && isvector (ydat) && ismatrix (zdat)) + if (rows (zdat) == length (ydat) + && columns (zdat) == length (xdat)) + [xdat, ydat] = meshgrid (xdat, ydat); + else + err = true; + endif + elseif (ismatrix (xdat) && ismatrix (ydat) && ismatrix (zdat)) + if (! size_equal (xdat, ydat, zdat)) + err = true; + endif + else + err = true; + endif + if (err) + error ("__go_draw_axes__: invalid grid data"); + endif + xlen = columns (zdat); + ylen = rows (zdat); + if (xlen == columns (xdat) && xlen == columns (ydat) + && ylen == rows (xdat) && ylen == rows (ydat)) + len = 4 * xlen; + zz = zeros (ylen, len); + k = 1; + for kk = 1:4:len + zz(:,kk) = xdat(:,k); + zz(:,kk+1) = ydat(:,k); + zz(:,kk+2) = zdat(:,k); + zz(:,kk+3) = cdat(:,k); + k++; + endfor + data{data_idx} = zz.'; + endif + + if (doing_interp_color) + interp_str = "interpolate 0, 0"; + else + ## No interpolation of facecolors. + interp_str = ""; + endif + usingclause{data_idx} = sprintf ("record=%dx%d using ($1):($2):($3):($4)", ylen, xlen); + + flat_interp_face = (strncmp (obj.facecolor, "flat", 4) + || strncmp (obj.facecolor, "interp", 6)); + flat_interp_edge = (strncmp (obj.edgecolor, "flat", 4) + || strncmp (obj.edgecolor, "interp", 6)); + + facecolor_none_or_white = (strncmp (obj.facecolor, "none", 4) + || (isnumeric (obj.facecolor) + && all (obj.facecolor == 1))); + hidden_removal = false; + fputs (plot_stream, "set style increment default;\n"); + if (flat_interp_edge && facecolor_none_or_white) + withpm3d = false; + withclause{data_idx} = sprintf ("with %s palette", style {1}); + fputs (plot_stream, "unset pm3d\n"); + if (all (obj.facecolor == 1)) + hidden_removal = true; + endif + elseif (facecolor_none_or_white) + if (all (obj.facecolor == 1)) + hidden_removal = true; + endif + fputs(plot_stream,"unset pm3d;\n"); + fputs(plot_stream,"set style increment user;\n"); + withpm3d = false; + withclause{data_idx} = sprintf("with %s linestyle %d", + style{1}, data_idx); + fputs (plot_stream, "unset pm3d\n"); + endif + + if (doing_interp_color) + ## "depthorder" interferes with interpolation of colors. + dord = "scansautomatic"; + else + dord = "depthorder"; + endif + + if (flat_interp_face && strncmp (obj.edgecolor, "flat", 4)) + fprintf (plot_stream, "set pm3d explicit at s %s %s corners2color c3;\n", + interp_str, dord); + elseif (!facecolor_none_or_white) + if (strncmp (obj.edgecolor, "none", 4)) + if (__gnuplot_has_feature__ ("transparent_surface") + && isscalar (obj.facealpha)) + fprintf (plot_stream, + "set style fill transparent solid %f;\n", + obj.facealpha); + endif + fprintf (plot_stream, "set pm3d explicit at s %s corners2color c3;\n", + interp_str, dord); + else + fprintf (plot_stream, "set pm3d explicit at s hidden3d %d %s %s corners2color c3;\n", + data_idx, interp_str, dord); + + if (__gnuplot_has_feature__ ("transparent_surface") + && isscalar (obj.facealpha)) + fprintf (plot_stream, + "set style fill transparent solid %f;\n", + obj.facealpha); + endif + endif + endif + + zz = []; + if (length (style) > 1) + len = 3 * xlen; + zz = zeros (ylen, len); + k = 1; + for kk = 1:3:len + zz(:,kk) = xdat(:,k); + zz(:,kk+1) = ydat(:,k); + zz(:,kk+2) = zdat(:,k); + k++; + endfor + zz = zz.'; + + data_idx++; + is_image_data(data_idx) = is_image_data(data_idx - 1); + parametric(data_idx) = parametric(data_idx - 1); + have_cdata(data_idx) = false; + have_3d_patch(data_idx) = have_3d_patch(data_idx - 1); + titlespec{data_idx} = "title \"\""; + usingclause{data_idx} = sprintf ("record=%dx%d using ($1):($2):($3)", ylen, xlen); + data{data_idx} = zz; + withclause{data_idx} = sprintf ("with %s linestyle %d", + style{2}, data_idx); + + endif + if (length (style) > 2) + data_idx++; + is_image_data(data_idx) = is_image_data(data_idx - 1); + parametric(data_idx) = parametric(data_idx - 1); + have_cdata(data_idx) = false; + have_3d_patch(data_idx) = have_3d_patch(data_idx - 1); + titlespec{data_idx} = "title \"\""; + usingclause{data_idx} = sprintf ("record=%dx%d using ($1):($2):($3)", ylen, xlen); + data{data_idx} = zz; + withclause{data_idx} = sprintf ("with %s linestyle %d", + style{3}, data_idx); + endif + if (withpm3d && strncmp (style {1}, "linespoints", 11)) + if (isempty(zz)) + len = 3 * xlen; + zz = zeros (ylen, len); + k = 1; + for kk = 1:3:len + zz(:,kk) = xdat(:,k); + zz(:,kk+1) = ydat(:,k); + zz(:,kk+2) = zdat(:,k); + k++; + endfor + zz = zz.'; + endif + data_idx++; + is_image_data(data_idx) = is_image_data(data_idx - 1); + parametric(data_idx) = parametric(data_idx - 1); + have_cdata(data_idx) = false; + have_3d_patch(data_idx) = have_3d_patch(data_idx - 1); + titlespec{data_idx} = "title \"\""; + usingclause{data_idx} = sprintf ("record=%dx%d using ($1):($2):($3)", ylen, xlen); + data{data_idx} = zz; + withclause{data_idx} = sprintf ("with points linestyle %d", + pm3didx); + endif + endif + + case "text" + [label, f, s] = __maybe_munge_text__ (enhanced, obj, "string"); + fontspec = create_fontspec (f, s, gnuplot_term); + lpos = obj.position; + halign = obj.horizontalalignment; + valign = obj.verticalalignment; + angle = obj.rotation; + units = obj.units; + color = obj.color; + if (strcmpi (units, "normalized")) + units = "graph"; + elseif (strcmp (axis_obj.yaxislocation, "right") + && strcmp (units, "data")) + units = "second"; + else + units = ""; + endif + + if (isnumeric (color)) + colorspec = get_text_colorspec (color, mono); + endif + + switch valign + ## Text offset in characters. This relies on gnuplot for font metrics. + case "top" + dy = -0.5; + case "cap" + dy = -0.5; + case "middle" + dy = 0; + case "baseline" + dy = 0.5; + case "bottom" + dy = 0.5; + endswitch + ## Gnuplot's Character units are different for x/y and vary with fontsize. The aspect ratio + ## of 1:1.7 was determined by experiment to work for eps/ps/etc. For the MacOS aqua terminal + ## a value of 2.5 is needed. However, the difference is barely noticable. + dx_and_dy = [(-dy * sind (angle)), (dy * cosd(angle))] .* [1.7 1]; + + if (nd == 3) + ## This produces the desired vertical alignment in 3D. + fprintf (plot_stream, + "set label \"%s\" at %s %.15e,%.15e,%.15e %s rotate by %f offset character %f,%f %s %s front %s;\n", + undo_string_escapes (label), units, lpos(1), + lpos(2), lpos(3), halign, angle, dx_and_dy, fontspec, + __do_enhanced_option__ (enhanced, obj), colorspec); + else + fprintf (plot_stream, + "set label \"%s\" at %s %.15e,%.15e %s rotate by %f offset character %f,%f %s %s front %s;\n", + undo_string_escapes (label), units, + lpos(1), lpos(2), halign, angle, dx_and_dy, fontspec, + __do_enhanced_option__ (enhanced, obj), colorspec); + endif + + case "hggroup" + ## Push group children into the kid list. + if (isempty (kids)) + kids = obj.children; + elseif (! isempty (obj.children)) + kids = [kids; obj.children]; + endif + + otherwise + error ("__go_draw_axes__: unknown object class, %s", + obj.type); + endswitch + + endwhile + + ## This is need to prevent warnings for rotations in 3D plots, while + ## allowing colorbars with contours. + if (nd == 2 || (data_idx > 1 && !view_map)) + fputs (plot_stream, "set pm3d implicit;\n"); + else + fputs (plot_stream, "set pm3d explicit;\n"); + endif + + if (isnan(hidden_removal) || hidden_removal) + fputs (plot_stream, "set hidden3d;\n"); + else + fputs (plot_stream, "unset hidden3d;\n"); + endif + + have_data = (! (isempty (data) || all (cellfun (@isempty, data)))); + + ## Note we don't use the [xy]2range of gnuplot as we don't use the + ## dual axis plotting features of gnuplot. + if (isempty (xlim)) + return; + endif + if (strcmpi (axis_obj.xdir, "reverse")) + xdir = "reverse"; + else + xdir = "noreverse"; + endif + fprintf (plot_stream, "set xrange [%.15e:%.15e] %s;\n", xlim, xdir); + if (strcmpi (axis_obj.xaxislocation, "top")) + fprintf (plot_stream, "set x2range [%.15e:%.15e] %s;\n", xlim, xdir); + endif + + if (isempty (ylim)) + return; + endif + if (strcmpi (axis_obj.ydir, "reverse")) + ydir = "reverse"; + else + ydir = "noreverse"; + endif + fprintf (plot_stream, "set yrange [%.15e:%.15e] %s;\n", ylim, ydir); + if (strcmpi (axis_obj.yaxislocation, "right")) + fprintf (plot_stream, "set y2range [%.15e:%.15e] %s;\n", ylim, ydir); + endif + + if (nd == 3) + if (isempty (zlim)) + return; + endif + if (strcmpi (axis_obj.zdir, "reverse")) + zdir = "reverse"; + else + zdir = "noreverse"; + endif + fprintf (plot_stream, "set zrange [%.15e:%.15e] %s;\n", zlim, zdir); + endif + + cmap = parent_figure_obj.colormap; + cmap_sz = rows(cmap); + if (! any (isinf (clim))) + if (truecolor || ! cdatadirect) + if (rows(addedcmap) > 0) + for i = 1:data_idx + if (have_3d_patch(i)) + data{i}(end,:) = clim(2) * (data{i}(end, :) - 0.5) / cmap_sz; + endif + endfor + fprintf (plot_stream, "set cbrange [%g:%g];\n", clim(1), clim(2) * + (cmap_sz + rows(addedcmap)) / cmap_sz); + else + fprintf (plot_stream, "set cbrange [%g:%g];\n", clim); + endif + else + fprintf (plot_stream, "set cbrange [1:%d];\n", cmap_sz + + rows (addedcmap)); + endif + endif + + if (strcmpi (axis_obj.box, "on")) + if (nd == 3) + fputs (plot_stream, "set border 4095;\n"); + else + fputs (plot_stream, "set border 431;\n"); + endif + else + if (nd == 3) + fputs (plot_stream, "set border 895;\n"); + elseif (! isempty (axis_obj.ytick)) + if (strcmpi (axis_obj.yaxislocation, "right")) + fprintf (plot_stream, "unset ytics; set y2tics %s nomirror\n", + axis_obj.tickdir); + if (strcmpi (axis_obj.xaxislocation, "top")) + fprintf (plot_stream, "unset xtics; set x2tics %s nomirror\n", + axis_obj.tickdir); + fputs (plot_stream, "set border 12;\n"); + else + fprintf (plot_stream, "unset x2tics; set xtics %s nomirror\n", + axis_obj.tickdir); + fputs (plot_stream, "set border 9;\n"); + endif + else + fprintf (plot_stream, "unset y2tics; set ytics %s nomirror\n", + axis_obj.tickdir); + if (strcmpi (axis_obj.xaxislocation, "top")) + fprintf (plot_stream, "unset xtics; set x2tics %s nomirror\n", + axis_obj.tickdir); + fputs (plot_stream, "set border 6;\n"); + else + fprintf (plot_stream, "unset x2tics; set xtics %s nomirror\n", + axis_obj.tickdir); + fputs (plot_stream, "set border 3;\n"); + endif + endif + endif + endif + + if (strcmpi (axis_obj.visible, "off")) + fputs (plot_stream, "unset border; unset tics\n"); + else + fprintf (plot_stream, "set border lw %f;\n", axis_obj.linewidth); + endif + + if (! isempty (hlgnd) && ! isempty (hlgnd.children) + && any (strcmpi (get (hlgnd.children, "visible"), "on"))) + if (strcmpi (hlgnd.box, "on")) + box = "box"; + else + box = "nobox"; + endif + if (strcmpi (hlgnd.orientation, "vertical")) + horzvert = "vertical"; + else + horzvert = "horizontal"; + endif + if (strcmpi (hlgnd.textposition, "right")) + reverse = "reverse"; + else + reverse = "noreverse"; + endif + inout = "inside"; + keypos = hlgnd.location; + if (ischar (keypos)) + keypos = lower (keypos); + keyout = findstr (keypos, "outside"); + if (! isempty (keyout)) + inout = "outside"; + keypos = keypos(1:keyout-1); + endif + endif + switch (keypos) + case "north" + pos = "center top"; + case "south" + pos = "center bottom"; + case "east" + pos = "right center"; + case "west" + pos = "left center"; + case "northeast" + pos = "right top"; + case "northwest" + pos = "left top"; + case "southeast" + pos = "right bottom"; + case "southwest" + pos = "left bottom"; + case "best" + pos = ""; + warning ("legend: 'Best' not yet implemented for location specifier.\n"); + ## Least conflict with data in plot. + ## Least unused space outside plot. + otherwise + pos = ""; + endswitch + if (__gnuplot_has_feature__ ("key_has_font_properties")) + [fontname, fontsize] = get_fontname_and_size (hlgnd); + fontspec = create_fontspec (fontname, fontsize, gnuplot_term); + else + fontspec = ""; + endif + fprintf (plot_stream, "set key %s %s;\nset key %s %s %s %s;\n", + inout, pos, box, reverse, horzvert, fontspec); + else + fputs (plot_stream, "unset key;\n"); + endif + fputs (plot_stream, "set style data lines;\n"); + + cmap = [cmap; addedcmap]; + cmap_sz = cmap_sz + rows(addedcmap); + if (length(cmap) > 0) + fprintf (plot_stream, + "set palette positive color model RGB maxcolors %i;\n", + cmap_sz); + fprintf (plot_stream, + "set palette file \"-\" binary record=%d using 1:2:3:4;\n", + cmap_sz); + fwrite (plot_stream, [1:cmap_sz; cmap.'], "float32"); + fwrite (plot_stream, "\n"); + endif + + fputs (plot_stream, "unset colorbox;\n"); + + if (have_data) + if (nd == 2) + plot_cmd = "plot"; + else + plot_cmd = "splot"; + rot_x = 90 - axis_obj.view(2); + rot_z = axis_obj.view(1); + while (rot_z < 0) + rot_z += 360; + endwhile + fputs (plot_stream, "set ticslevel 0;\n"); + if (view_map && rot_x == 0 && rot_z == 0) + fputs (plot_stream, "set view map;\n"); + else + fprintf (plot_stream, "set view %.15g, %.15g;\n", rot_x, rot_z); + endif + endif + if (have_3d_patch (1)) + fputs (plot_stream, "set pm3d depthorder\n"); + fprintf (plot_stream, "%s \"-\" %s %s %s \\\n", plot_cmd, + usingclause{1}, titlespec{1}, withclause{1}); + elseif (is_image_data (1)) + fprintf (plot_stream, "%s \"-\" %s %s %s \\\n", plot_cmd, + usingclause{1}, titlespec{1}, withclause{1}); + else + fprintf (plot_stream, "%s \"-\" binary format='%%float64' %s %s %s \\\n", plot_cmd, + usingclause{1}, titlespec{1}, withclause{1}); + endif + for i = 2:data_idx + if (have_3d_patch (i)) + fprintf (plot_stream, ", \"-\" %s %s %s \\\n", + usingclause{i}, titlespec{i}, withclause{i}); + elseif (is_image_data (i)) + if (! is_image_data (i-1)) + fputs (plot_stream, "; "); + if (bg_is_set) + fputs (plot_stream, "unset obj 1; \\\n"); + bg_is_set = false; + endif + if (fg_is_set) + fputs (plot_stream, "unset obj 2; \\\n"); + fg_is_set = false; + endif + endif + fprintf (plot_stream, "%s \"-\" %s %s %s \\\n", plot_cmd, + usingclause{i}, titlespec{i}, withclause{i}); + elseif (is_image_data (i-1)) + if (bg_is_set) + fputs (plot_stream, "unset obj 1; \\\n"); + bg_is_set = false; + endif + if (fg_is_set) + fputs (plot_stream, "unset obj 2; \\\n"); + fg_is_set = false; + endif + fprintf (plot_stream, "%s \"-\" binary format='%%float64' %s %s %s \\\n", plot_cmd, + usingclause{i}, titlespec{i}, withclause{i}); + else + fprintf (plot_stream, ", \"-\" binary format='%%float64' %s %s %s \\\n", + usingclause{i}, titlespec{i}, withclause{i}); + endif + endfor + fputs (plot_stream, ";\n"); + for i = 1:data_idx + if (have_3d_patch (i)) + ## Can't write 3d patch data as binary as can't plot more than + ## a single patch at a time and have to plot all patches together + ## so that the gnuplot depth ordering is done correctly + for j = 1 : 4 : columns(data{i}) + if (j != 1) + fputs (plot_stream, "\n\n"); + endif + fprintf (plot_stream, "%.15g %.15g %.15g %.15g\n", data{i}(:,j).'); + fprintf (plot_stream, "%.15g %.15g %.15g %.15g\n\n", data{i}(:,j+1).'); + fprintf (plot_stream, "%.15g %.15g %.15g %.15g\n", data{i}(:,j+2).'); + fprintf (plot_stream, "%.15g %.15g %.15g %.15g\n", data{i}(:,j+3).'); + endfor + fputs (plot_stream, "e\n"); + elseif (is_image_data(i)) + fwrite (plot_stream, data{i}, "float32"); + else + __gnuplot_write_data__ (plot_stream, data{i}, nd, parametric(i), + have_cdata(i)); + endif + endfor + else + fputs (plot_stream, "plot \"-\";\nInf Inf\ne\n"); + endif + + ## Needed to allow mouse rotation with pcolor. + if (view_map) + fputs (plot_stream, "unset view;\n"); + endif + + if (bg_is_set) + fputs (plot_stream, "unset obj 1;\n"); + bg_is_set = false; + endif + + fflush (plot_stream); + + else + print_usage (); + endif + +endfunction + +function fontspec = create_fontspec (f, s, gp_term) + if (strcmp (f, "*") || strcmp (gp_term, "tikz")) + fontspec = sprintf ("font \",%d\"", s); + else + fontspec = sprintf ("font \"%s,%d\"", f, s); + endif +endfunction + +function style = do_linestyle_command (obj, linecolor, idx, mono, + plot_stream, errbars = "") + style = {}; + + fprintf (plot_stream, "set style line %d default;\n", idx); + fprintf (plot_stream, "set style line %d", idx); + + found_style = false; + if (isnumeric (linecolor)) + color = linecolor; + if (! mono) + fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"", + round (255*color)); + endif + else + color = [0, 0, 0]; + endif + + if (isfield (obj, "linestyle")) + switch (obj.linestyle) + case "-" + lt = "1"; + case "--" + lt = "2"; + case ":" + lt = "3"; + case "-." + lt = "6"; + case "none" + lt = ""; + otherwise + lt = ""; + endswitch + + if (! isempty (lt)) + fprintf (plot_stream, " linetype %s", lt); + endif + + else + lt = ""; + endif + if (! isempty (errbars)) + found_style = true; + endif + + if (isfield (obj, "linewidth")) + fprintf (plot_stream, " linewidth %f", obj.linewidth); + found_style = true; + endif + + [pt, pt2, obj] = gnuplot_pointtype (obj); + + if (! isempty (pt)) + found_style = true; + endif + + sidx = 1; + if (isempty (errbars)) + if (isempty (lt)) + style {sidx} = ""; + else + style {sidx} = "lines"; + endif + + facesame = true; + if (! isequal (pt, pt2) && isfield (obj, "markerfacecolor") + && !strncmp (obj.markerfacecolor, "none", 4)) + if (strncmp (obj.markerfacecolor, "auto", 4) + || ! isnumeric (obj.markerfacecolor) + || (isnumeric (obj.markerfacecolor) + && isequal (color, obj.markerfacecolor))) + if (! isempty (pt2)) + fprintf (plot_stream, " pointtype %s", pt2); + style {sidx} = strcat (style{sidx}, "points"); + endif + if (isfield (obj, "markersize")) + fprintf (plot_stream, " pointsize %f", obj.markersize / 3); + endif + else + facesame = false; + if (! found_style) + fputs (plot_stream, " default"); + endif + fputs (plot_stream, ";\n"); + if (! isempty (style {sidx})) + sidx ++; + idx ++; + else + fputs (plot_stream, ";\n"); + endif + fprintf (plot_stream, "set style line %d default;\n", idx); + fprintf (plot_stream, "set style line %d", idx); + if (isnumeric (obj.markerfacecolor) && ! mono) + fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"", + round (255*obj.markerfacecolor)); + endif + if (! isempty (pt2)) + style {sidx} = "points"; + fprintf (plot_stream, " pointtype %s", pt2); + endif + if (isfield (obj, "markersize")) + fprintf (plot_stream, " pointsize %f", obj.markersize / 3); + endif + endif + endif + if (isfield (obj, "markeredgecolor") + && !strncmp (obj.markeredgecolor, "none", 4)) + if (facesame && !isempty (pt) + && (strncmp (obj.markeredgecolor, "auto", 4) + || ! isnumeric (obj.markeredgecolor) + || (isnumeric (obj.markeredgecolor) + && isequal (color, obj.markeredgecolor)))) + if (sidx == 1 && ((length (style {sidx}) == 5 + && strncmp (style {sidx}, "lines", 5)) || isempty (style {sidx}))) + if (! isempty (pt)) + style {sidx} = strcat (style{sidx}, "points"); + fprintf (plot_stream, " pointtype %s", pt); + endif + if (isfield (obj, "markersize")) + fprintf (plot_stream, " pointsize %f", obj.markersize / 3); + endif + endif + else + if (! found_style) + fputs (plot_stream, " default"); + endif + fputs (plot_stream, ";\n"); + if (!isempty (style {sidx})) + sidx ++; + idx ++; + else + fputs (plot_stream, ";\n"); + endif + fprintf (plot_stream, "set style line %d default;\n", idx); + fprintf (plot_stream, "set style line %d", idx); + if (! mono) + if (strncmp (obj.markeredgecolor, "auto", 4)) + fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"", + round (255*color)); + elseif (isnumeric (obj.markeredgecolor) && ! mono) + fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"", + round (255*obj.markeredgecolor)); + endif + endif + if (! isempty (pt)) + style {sidx} = "points"; + fprintf (plot_stream, " pointtype %s", pt); + endif + if (isfield (obj, "markersize")) + fprintf (plot_stream, " pointsize %f", obj.markersize / 3); + endif + endif + endif + else + style{1} = errbars; + fputs (plot_stream, " pointtype 0"); + endif + + if (! found_style && isempty (style {1})) + fputs (plot_stream, " default"); + endif + + fputs (plot_stream, ";\n"); + +endfunction + +function [pt, pt2, obj] = gnuplot_pointtype (obj) + if (isfield (obj, "marker")) + switch (obj.marker) + case "+" + pt = pt2 = "1"; + case "o" + pt = "6"; + pt2 = "7"; + case "*" + pt = pt2 = "3"; + case "." + pt = "6"; + pt2 = "7"; + if (isfield (obj, "markerfacecolor") + || strncmp (obj.markerfacecolor, "none", 4)) + obj.markerfacecolor = "auto"; + endif + if (isfield (obj, "markersize")) + obj.markersize /= 3; + else + obj.markersize = 5; + endif + case "x" + pt = pt2 = "2"; + case {"square", "s"} + pt = "4"; + pt2 = "5"; + case {"diamond", "d"} + pt = "12"; + pt2 = "13"; + case "^" + pt = "8"; + pt2 = "9"; + case "v" + pt = "10"; + pt2 = "11"; + case ">" + ## FIXME -- should be triangle pointing right, use triangle pointing up + pt = "8"; + pt2 = "9"; + case "<" + ## FIXME -- should be triangle pointing left, use triangle pointing down + pt = "10"; + pt2 = "11"; + case {"pentagram", "p"} + ## FIXME -- should be pentagram, using pentagon + pt = "14"; + pt2 = "15"; + case {"hexagram", "h"} + ## FIXME -- should be 6 pt start, using "*" instead + pt = pt2 = "3"; + case "none" + pt = pt2 = ""; + otherwise + pt = pt2 = ""; + endswitch + else + pt = pt2 = ""; + endif +endfunction + +function __gnuplot_write_data__ (plot_stream, data, nd, parametric, cdata) + + ## DATA is already transposed. + + ## FIXME -- this may need to be converted to C++ for speed. + + ## Convert NA elements to normal NaN values because fprintf writes + ## "NA" and that confuses gnuplot. + idx = find (isna (data)); + if (any (idx)) + data(idx) = NaN; + endif + + if (nd == 2) + fwrite (plot_stream, data, "float64"); + elseif (nd == 3) + if (parametric) + fwrite (plot_stream, data, "float64"); + else + nr = rows (data); + if (cdata) + for j = 1:4:nr + fwrite (plot_stream, data(j:j+3,:), "float64"); + endfor + else + for j = 1:3:nr + fwrite (plot_stream, data(j:j+2,:), "float64"); + endfor + endif + endif + endif + +endfunction + +function do_tics (obj, plot_stream, ymirror, mono, gnuplot_term) + + obj.xticklabel = ticklabel_to_cell (obj.xticklabel); + obj.yticklabel = ticklabel_to_cell (obj.yticklabel); + obj.zticklabel = ticklabel_to_cell (obj.zticklabel); + + if (strcmp (obj.xminorgrid, "on")) + obj.xminortick = "on"; + endif + if (strcmp (obj.yminorgrid, "on")) + obj.yminortick = "on"; + endif + if (strcmp (obj.zminorgrid, "on")) + obj.zminortick = "on"; + endif + + [fontname, fontsize] = get_fontname_and_size (obj); + fontspec = create_fontspec (fontname, fontsize, gnuplot_term); + + ## A Gnuplot tic scale of 69 is equivalent to Octave's 0.5. + ticklength = sprintf ("scale %4.1f", (69/0.5)*obj.ticklength(1)); + + if (strcmpi (obj.xaxislocation, "top")) + do_tics_1 (obj.xtickmode, obj.xtick, obj.xminortick, obj.xticklabelmode, + obj.xticklabel, obj.xcolor, "x2", plot_stream, true, mono, + "border", obj.tickdir, ticklength, fontname, fontspec, + obj.interpreter, obj.xscale); + do_tics_1 ("manual", [], "off", obj.xticklabelmode, obj.xticklabel, + obj.xcolor, "x", plot_stream, true, mono, "border", + "", "", fontname, fontspec, obj.interpreter, obj.xscale); + elseif (strcmpi (obj.xaxislocation, "zero")) + do_tics_1 (obj.xtickmode, obj.xtick, obj.xminortick, obj.xticklabelmode, + obj.xticklabel, obj.xcolor, "x", plot_stream, true, mono, + "axis", obj.tickdir, ticklength, fontname, fontspec, + obj.interpreter, obj.xscale); + do_tics_1 ("manual", [], "off", obj.xticklabelmode, obj.xticklabel, + obj.xcolor, "x2", plot_stream, true, mono, "axis", + "", "", fontname, fontspec, obj.interpreter, obj.xscale); + else + do_tics_1 (obj.xtickmode, obj.xtick, obj.xminortick, obj.xticklabelmode, + obj.xticklabel, obj.xcolor, "x", plot_stream, true, mono, + "border", obj.tickdir, ticklength, fontname, fontspec, + obj.interpreter, obj.xscale); + do_tics_1 ("manual", [], "off", obj.xticklabelmode, obj.xticklabel, + obj.xcolor, "x2", plot_stream, true, mono, "border", + "", "", fontname, fontspec, obj.interpreter, obj.xscale); + endif + if (strcmpi (obj.yaxislocation, "right")) + do_tics_1 (obj.ytickmode, obj.ytick, obj.yminortick, obj.yticklabelmode, + obj.yticklabel, obj.ycolor, "y2", plot_stream, ymirror, mono, + "border", obj.tickdir, ticklength, fontname, fontspec, + obj.interpreter, obj.yscale); + do_tics_1 ("manual", [], "off", obj.yticklabelmode, obj.yticklabel, + obj.ycolor, "y", plot_stream, ymirror, mono, "border", + "", "", fontname, fontspec, obj.interpreter, obj.yscale); + elseif (strcmpi (obj.yaxislocation, "zero")) + do_tics_1 (obj.ytickmode, obj.ytick, obj.yminortick, obj.yticklabelmode, + obj.yticklabel, obj.ycolor, "y", plot_stream, ymirror, mono, + "axis", obj.tickdir, ticklength, fontname, fontspec, + obj.interpreter, obj.yscale); + do_tics_1 ("manual", [], "off", obj.yticklabelmode, obj.yticklabel, + obj.ycolor, "y2", plot_stream, ymirror, mono, "axis", + "", "", fontname, fontspec, obj.interpreter, obj.yscale); + else + do_tics_1 (obj.ytickmode, obj.ytick, obj.yminortick, obj.yticklabelmode, + obj.yticklabel, obj.ycolor, "y", plot_stream, ymirror, mono, + "border", obj.tickdir, ticklength, fontname, fontspec, + obj.interpreter, obj.yscale); + do_tics_1 ("manual", [], "off", obj.yticklabelmode, obj.yticklabel, + obj.ycolor, "y2", plot_stream, ymirror, mono, "border", + "", "", fontname, fontspec, obj.interpreter, obj.yscale); + endif + do_tics_1 (obj.ztickmode, obj.ztick, obj.zminortick, obj.zticklabelmode, + obj.zticklabel, obj.zcolor, "z", plot_stream, true, mono, + "border", obj.tickdir, ticklength, fontname, fontspec, + obj.interpreter, obj.zscale); +endfunction + +function do_tics_1 (ticmode, tics, mtics, labelmode, labels, color, ax, + plot_stream, mirror, mono, axispos, tickdir, ticklength, + fontname, fontspec, interpreter, scale) + persistent warned_latex = false; + if (strcmpi (interpreter, "tex")) + for n = 1 : numel(labels) + labels{n} = __tex2enhanced__ (labels{n}, fontname, false, false); + endfor + elseif (strcmpi (interpreter, "latex")) + if (! warned_latex) + warning ("latex markup not supported for tick marks"); + warned_latex = true; + endif + endif + if (strcmp (scale, "log")) + fmt = "10^{%T}"; + num_mtics = 10; + else + fmt = "%g"; + num_mtics = 5; + endif + colorspec = get_text_colorspec (color, mono); + if (strcmpi (ticmode, "manual") || strcmpi (labelmode, "manual")) + if (isempty (tics)) + fprintf (plot_stream, "unset %stics;\nunset m%stics;\n", ax, ax); + elseif (strcmpi (labelmode, "manual")) + if (ischar (labels)) + labels = cellstr (labels); + endif + if (isnumeric (labels)) + labels = num2str (real (labels(:))); + endif + if (ischar (labels)) + labels = permute (cellstr (labels), [2, 1]); + endif + if (iscellstr (labels)) + k = 1; + ntics = numel (tics); + nlabels = numel (labels); + fprintf (plot_stream, "set format %s \"%%s\";\n", ax); + if (mirror) + fprintf (plot_stream, "set %stics %s %s %s mirror (", ax, + tickdir, ticklength, axispos); + else + fprintf (plot_stream, "set %stics %s %s %s nomirror (", ax, + tickdir, ticklength, axispos); + endif + + labels = regexprep(labels, '%', "%%"); + for i = 1:ntics + fprintf (plot_stream, " \"%s\" %.15g", labels{k++}, tics(i)); + if (i < ntics) + fputs (plot_stream, ", "); + endif + if (k > nlabels) + k = 1; + endif + endfor + fprintf (plot_stream, ") %s %s;\n", colorspec, fontspec); + if (strcmp (mtics, "on")) + fprintf (plot_stream, "set m%stics %d;\n", ax, num_mtics); + else + fprintf (plot_stream, "unset m%stics;\n", ax); + endif + else + error ("__go_draw_axes__: unsupported type of ticklabel"); + endif + else + fprintf (plot_stream, "set format %s \"%s\";\n", ax, fmt); + if (mirror) + fprintf (plot_stream, "set %stics %s %s %s mirror (", ax, tickdir, + ticklength, axispos); + else + fprintf (plot_stream, "set %stics %s %s %s nomirror (", ax, tickdir, + ticklength, axispos); + endif + fprintf (plot_stream, " %.15g,", tics(1:end-1)); + fprintf (plot_stream, " %.15g) %s;\n", tics(end), fontspec); + if (strcmp (mtics, "on")) + fprintf (plot_stream, "set m%stics %d;\n", ax, num_mtics); + else + fprintf (plot_stream, "unset m%stics;\n", ax); + endif + endif + else + fprintf (plot_stream, "set format %s \"%s\";\n", ax, fmt); + if (mirror) + fprintf (plot_stream, "set %stics %s %s %s mirror %s %s;\n", ax, + axispos, tickdir, ticklength, colorspec, fontspec); + else + fprintf (plot_stream, "set %stics %s %s %s nomirror %s %s;\n", ax, + tickdir, ticklength, axispos, colorspec, fontspec); + endif + if (strcmp (mtics, "on")) + fprintf (plot_stream, "set m%stics %d;\n", ax, num_mtics); + else + fprintf (plot_stream, "unset m%stics;\n", ax); + endif + endif +endfunction + +function ticklabel = ticklabel_to_cell (ticklabel) + if (isnumeric (ticklabel)) + ## Use upto 5 significant digits + ticklabel = num2str (ticklabel(:), 5); + endif + if (ischar (ticklabel)) + if (size (ticklabel, 1) == 1 && any (ticklabel == "|")) + n = setdiff (findstr (ticklabel, "|"), findstr (ticklabel, '\|')); + ticklabel = strsplit (ticklabel, "|"); + else + ticklabel = cellstr (ticklabel); + endif + elseif (isempty (ticklabel)) + ticklabel = {""}; + else + ticklabel = ticklabel; + endif +endfunction + +function colorspec = get_text_colorspec (color, mono) + if (mono) + colorspec = ""; + else + colorspec = sprintf ("textcolor rgb \"#%02x%02x%02x\"", + round (255*color)); + endif +endfunction + +function [f, s, fnt, it, bld] = get_fontname_and_size (t) + if (isempty (t.fontname) || strcmp (t.fontname, "*")) + fnt = "{}"; + else + fnt = t.fontname; + endif + f = fnt; + it = false; + bld = false; + if (! isempty (t.fontweight) && strcmpi (t.fontweight, "bold")) + if (! isempty(t.fontangle) + && (strcmpi (t.fontangle, "italic") + || strcmpi (t.fontangle, "oblique"))) + f = cstrcat (f, "-bolditalic"); + it = true; + bld = true; + else + f = cstrcat (f, "-bold"); + bld = true; + endif + elseif (! isempty(t.fontangle) + && (strcmpi (t.fontangle, "italic") + || strcmpi (t.fontangle, "oblique"))) + f = cstrcat (f, "-italic"); + it = true; + endif + if (isempty (t.fontsize)) + s = 10; + else + s = t.fontsize; + endif +endfunction + +function [str, f, s] = __maybe_munge_text__ (enhanced, obj, fld) + + persistent warned_latex = false; + + if (strcmp (fld, "string")) + [f, s, fnt, it, bld] = get_fontname_and_size (obj); + else + f = "Helvetica"; + s = 10; + fnt = f; + it = false; + bld = false; + endif + + str = getfield (obj, fld); + if (enhanced) + if (strcmpi (obj.interpreter, "tex")) + str = __tex2enhanced__ (str, fnt, it, bld); + elseif (strcmpi (obj.interpreter, "latex")) + if (! warned_latex) + warning ("latex markup not supported for text objects"); + warned_latex = true; + endif + endif + endif +endfunction + +function str = __tex2enhanced__ (str, fnt, it, bld) + persistent sym = __setup_sym_table__ (); + persistent flds = fieldnames (sym); + + [s, e, m] = regexp(str,'\\([a-zA-Z]+|0)','start','end','matches'); + + for i = length (s) : -1 : 1 + ## special case for "\0" and replace with "{/Symbol \306}' + if (strncmp (m{i}, '\0', 2)) + str = cstrcat (str(1:s(i) - 1), '{/Symbol \306}', str(s(i) + 2:end)); + else + f = m{i}(2:end); + if (isfield (sym, f)) + g = getfield(sym, f); + ## FIXME The symbol font doesn't seem to support bold or italic + ##if (bld) + ## if (it) + ## g = regexprep (g, '/Symbol', '/Symbol-bolditalic'); + ## else + ## g = regexprep (g, '/Symbol', '/Symbol-bold'); + ## endif + ##elseif (it) + ## g = regexprep (g, '/Symbol', '/Symbol-italic'); + ##endif + str = cstrcat (str(1:s(i) - 1), g, str(e(i) + 1:end)); + elseif (strncmp (f, "rm", 2)) + bld = false; + it = false; + str = cstrcat (str(1:s(i) - 1), '/', fnt, ' ', str(s(i) + 3:end)); + elseif (strncmp (f, "it", 2) || strncmp (f, "sl", 2)) + it = true; + if (bld) + str = cstrcat (str(1:s(i) - 1), '/', fnt, '-bolditalic ', + str(s(i) + 3:end)); + else + str = cstrcat (str(1:s(i) - 1), '/', fnt, '-italic ', + str(s(i) + 3:end)); + endif + elseif (strncmp (f, "bf", 2)) + bld = true; + if (it) + str = cstrcat (str(1:s(i) - 1), '/', fnt, '-bolditalic ', + str(2(i) + 3:end)); + else + str = cstrcat (str(1:s(i) - 1), '/', fnt, '-bold ', + str(s(i) + 3:end)); + endif + elseif (strcmpi (f, "color")) + ## FIXME Ignore \color but remove trailing {} block as well + d = strfind(str(e(i) + 1:end),'}'); + if (isempty (d)) + warning ('syntax error in \color argument'); + else + str = cstrcat (str(1:s(i) - 1), str(e(i) + d + 1:end)); + endif + elseif(strcmpi (f, "fontname")) + b1 = strfind(str(e(i) + 1:end),'{'); + b2 = strfind(str(e(i) + 1:end),'}'); + if (isempty(b1) || isempty(b2)) + warning ('syntax error in \fontname argument'); + else + str = cstrcat (str(1:s(i) - 1), '/', + str(e(i)+b1(1) + 1:e(i)+b2(1)-1), '{}', + str(e(i) + b2(1) + 1:end)); + endif + elseif(strcmpi (f, "fontsize")) + b1 = strfind(str(e(i) + 1:end),'{'); + b2 = strfind(str(e(i) + 1:end),'}'); + if (isempty(b1) || isempty(b2)) + warning ('syntax error in \fontname argument'); + else + str = cstrcat (str(1:s(i) - 1), '/=', + str(e(i)+b1(1) + 1:e(i)+b2(1)-1), '{}', + str(e(i) + b2(1) + 1:end)); + endif + else + ## Last desperate attempt to treat the symbol. Look for things + ## like \pix, that should be translated to the symbol Pi and x + for j = 1 : length (flds) + if (strncmp (flds{j}, f, length (flds{j}))) + g = getfield(sym, flds{j}); + ## FIXME The symbol font doesn't seem to support bold or italic + ##if (bld) + ## if (it) + ## g = regexprep (g, '/Symbol', '/Symbol-bolditalic'); + ## else + ## g = regexprep (g, '/Symbol', '/Symbol-bold'); + ## endif + ##elseif (it) + ## g = regexprep (g, '/Symbol', '/Symbol-italic'); + ##endif + str = cstrcat (str(1:s(i) - 1), g, + str(s(i) + length (flds{j}) + 1:end)); + break; + endif + endfor + endif + endif + endfor + + ## Prepend @ to things things like _0^x or _{-100}^{100} for + ## alignment But need to put the shorter of the two arguments first. + ## Carful of nested {} and unprinted characters when defining + ## shortest.. Don't have to worry about things like ^\theta as they + ## are already converted to ^{/Symbol q}. + + ## FIXME -- This is a mess... Is it worth it just for a "@" character? + + [s, m] = regexp(str,'[_\^]','start','matches'); + i = 1; + p = 0; + while (i < length (s)) + if (i < length(s)) + if (str(s(i) + p + 1) == "{") + s1 = strfind(str(s(i) + p + 2:end),'{'); + si = 1; + l1 = strfind(str(s(i) + p + 1:end),'}'); + li = 1; + while (li <= length (l1) && si <= length (s1)) + if (l1(li) < s1(si)) + if (li == si) + break; + endif + li++; + else + si++; + endif + endwhile + l1 = l1 (min (length(l1), si)); + if (s(i) + l1 + 1 == s(i+1)) + if (str(s(i + 1) + p + 1) == "{") + s2 = strfind(str(s(i + 1) + p + 2:end),'{'); + si = 1; + l2 = strfind(str(s(i + 1) + p + 1:end),'}'); + li = 1; + while (li <= length (l2) && si <= length (s2)) + if (l2(li) < s2(si)) + if (li == si) + break; + endif + li++; + else + si++; + endif + endwhile + l2 = l2 (min (length(l2), si)); + if (length_string (str(s(i)+p+2:s(i)+p+l1-1)) <= + length_string(str(s(i+1)+p+2:s(i+1)+p+l2-1))) + ## Shortest already first! + str = cstrcat (str(1:s(i)+p-1), "@", str(s(i)+p:end)); + else + ## Have to swap sub/super-script to get shortest first. + str = cstrcat (str(1:s(i)+p-1), "@", str(s(i+1)+p:s(i+1)+p+l2), + str(s(i)+p:s(i)+p+l1), str(s(i+1)+p+l2+1:end)); + endif + else + ## Have to swap sub/super-script to get shortest first. + str = cstrcat (str(1:s(i)+p-1), "@", str(s(i+1)+p:s(i+1)+p+1), + str(s(i)+p:s(i)+p+l1), str(s(i+1)+p+2:end)); + endif + i += 2; + p ++; + else + i++; + endif + else + if (s(i+1) == s(i) + 2) + ## Shortest already first! + str = cstrcat (str(1:s(i)+p-1), "@", str(s(i)+p:end)); + p ++; + i += 2; + else + i ++; + endif + endif + else + i ++; + endif + endwhile + +endfunction + +function l = length_string (s) + l = length (s) - length (strfind(s,'{')) - length (strfind(s,'}')); + m = regexp (s, '/([\w-]+|[\w-]+=\d+)', 'matches'); + if (!isempty (m)) + l = l - sum (cellfun (@length, m)); + endif +endfunction + +function sym = __setup_sym_table__ () + ## Setup the translation table for TeX to gnuplot enhanced mode. + sym.forall = '{/Symbol \042}'; + sym.exists = '{/Symbol \044}'; + sym.ni = '{/Symbol \047}'; + sym.cong = '{/Symbol \100}'; + sym.Delta = '{/Symbol D}'; + sym.Phi = '{/Symbol F}'; + sym.Gamma = '{/Symbol G}'; + sym.vartheta = '{/Symbol J}'; + sym.Lambda = '{/Symbol L}'; + sym.Pi = '{/Symbol P}'; + sym.Theta = '{/Symbol Q}'; + sym.Sigma = '{/Symbol S}'; + sym.varsigma = '{/Symbol V}'; + sym.Omega = '{/Symbol W}'; + sym.Xi = '{/Symbol X}'; + sym.Psi = '{/Symbol Y}'; + sym.perp = '{/Symbol \136}'; + sym.alpha = '{/Symbol a}'; + sym.beta = '{/Symbol b}'; + sym.chi = '{/Symbol c}'; + sym.delta = '{/Symbol d}'; + sym.epsilon = '{/Symbol e}'; + sym.phi = '{/Symbol f}'; + sym.gamma = '{/Symbol g}'; + sym.eta = '{/Symbol h}'; + sym.iota = '{/Symbol i}'; + sym.varphi = '{/Symbol j}'; + sym.kappa = '{/Symbol k}'; + sym.lambda = '{/Symbol l}'; + sym.mu = '{/Symbol m}'; + sym.nu = '{/Symbol n}'; + sym.o = '{/Symbol o}'; + sym.pi = '{/Symbol p}'; + sym.theta = '{/Symbol q}'; + sym.rho = '{/Symbol r}'; + sym.sigma = '{/Symbol s}'; + sym.tau = '{/Symbol t}'; + sym.upsilon = '{/Symbol u}'; + sym.varpi = '{/Symbol v}'; + sym.omega = '{/Symbol w}'; + sym.xi = '{/Symbol x}'; + sym.psi = '{/Symbol y}'; + sym.zeta = '{/Symbol z}'; + sym.sim = '{/Symbol \176}'; + sym.Upsilon = '{/Symbol \241}'; + sym.prime = '{/Symbol \242}'; + sym.leq = '{/Symbol \243}'; + sym.infty = '{/Symbol \245}'; + sym.clubsuit = '{/Symbol \247}'; + sym.diamondsuit = '{/Symbol \250}'; + sym.heartsuit = '{/Symbol \251}'; + sym.spadesuit = '{/Symbol \252}'; + sym.leftrightarrow = '{/Symbol \253}'; + sym.leftarrow = '{/Symbol \254}'; + sym.uparrow = '{/Symbol \255}'; + sym.rightarrow = '{/Symbol \256}'; + sym.downarrow = '{/Symbol \257}'; + sym.circ = '{/Symbol \260}'; + sym.pm = '{/Symbol \261}'; + sym.geq = '{/Symbol \263}'; + sym.times = '{/Symbol \264}'; + sym.propto = '{/Symbol \265}'; + sym.partial = '{/Symbol \266}'; + sym.bullet = '{/Symbol \267}'; + sym.div = '{/Symbol \270}'; + sym.neq = '{/Symbol \271}'; + sym.equiv = '{/Symbol \272}'; + sym.approx = '{/Symbol \273}'; + sym.ldots = '{/Symbol \274}'; + sym.mid = '{/Symbol \275}'; + sym.aleph = '{/Symbol \300}'; + sym.Im = '{/Symbol \301}'; + sym.Re = '{/Symbol \302}'; + sym.wp = '{/Symbol \303}'; + sym.otimes = '{/Symbol \304}'; + sym.oplus = '{/Symbol \305}'; + sym.oslash = '{/Symbol \306}'; + sym.cap = '{/Symbol \307}'; + sym.cup = '{/Symbol \310}'; + sym.supset = '{/Symbol \311}'; + sym.supseteq = '{/Symbol \312}'; + sym.subset = '{/Symbol \314}'; + sym.subseteq = '{/Symbol \315}'; + sym.in = '{/Symbol \316}'; + sym.notin = '{/Symbol \317}'; + sym.angle = '{/Symbol \320}'; + sym.bigtriangledown = '{/Symbol \321}'; + sym.langle = '{/Symbol \341}'; + sym.rangle = '{/Symbol \361}'; + sym.nabla = '{/Symbol \321}'; + sym.prod = '{/Symbol \325}'; + sym.surd = '{/Symbol \326}'; + sym.cdot = '{/Symbol \327}'; + sym.neg = '{/Symbol \330}'; + sym.wedge = '{/Symbol \331}'; + sym.vee = '{/Symbol \332}'; + sym.Leftrightarrow = '{/Symbol \333}'; + sym.Leftarrow = '{/Symbol \334}'; + sym.Uparrow = '{/Symbol \335}'; + sym.Rightarrow = '{/Symbol \336}'; + sym.Downarrow = '{/Symbol \337}'; + sym.diamond = '{/Symbol \340}'; + sym.copyright = '{/Symbol \343}'; + sym.lfloor = '{/Symbol \353}'; + sym.lceil = '{/Symbol \351}'; + sym.rfloor = '{/Symbol \373}'; + sym.rceil = '{/Symbol \371}'; + sym.int = '{/Symbol \362}'; +endfunction + +function retval = __do_enhanced_option__ (enhanced, obj) + retval = ""; + if (enhanced) + if (strcmpi (obj.interpreter, "none")) + retval = "noenhanced"; + else + retval = "enhanced"; + endif + endif +endfunction diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/private/__go_draw_figure__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/private/__go_draw_figure__.m Sat Jul 16 09:28:26 2011 -0700 @@ -0,0 +1,198 @@ +## Copyright (C) 2005-2011 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 3 of the License, 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, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {} __go_draw_figure__ (@var{h}, @var{plot_stream}, @var{enhanced}, @var{mono}) +## Undocumented internal function. +## @end deftypefn + +## Author: jwe + +function __go_draw_figure__ (h, plot_stream, enhanced, mono) + + if (nargin == 4) + htype = get (h, "type"); + if (strcmp (htype, "figure")) + ## Get complete list of children. + kids = allchild (h); + nkids = length (kids); + + if (nkids > 0) + fputs (plot_stream, "\nreset;\n"); + fputs (plot_stream, "set autoscale keepfix;\n"); + fputs (plot_stream, "set origin 0, 0\n"); + fputs (plot_stream, "set size 1, 1\n"); + bg = get (h, "color"); + if (isnumeric (bg)) + fprintf (plot_stream, "set obj 1 rectangle from screen 0,0 to screen 1,1 behind fc rgb \"#%02x%02x%02x\"\n", 255 * bg); + bg_is_set = true; + else + bg_is_set = false; + endif + + for i = nkids:-1:1 + type = get (kids(i), "type"); + switch (type) + case "axes" + if (strcmpi (get (kids (i), "tag"), "legend")) + ## This is so ugly. If there was a way of getting + ## gnuplot to give us the text extents of strings + ## then we could get rid of this mess. + lh = getfield (get (kids(i), "userdata"), "handle"); + if (isscalar (lh)) + ## We have a legend with a single parent. It'll be handled + ## below as a gnuplot key to the axis it corresponds to + continue; + else + ca = lh(1); + ## Rely upon listener to convert axes position + ## to "normalized" units. + legend_axes_units = get (kids(i), "units"); + legend_axes_position = get (kids(i), "position"); + legend_axes_outerposition = get (kids(i), "outerposition"); + legend_axes_box = get (kids(i), "box"); + legend_axes_ylim = get (kids(i), "ylim"); + orig_axes_units = get (ca, "units"); + hlgnd = get (kids(i)); + + unwind_protect + set (ca, "units", "normalized"); + set (kids(i), "units", "normalized", "box", "off", + "ylim", [-2, -1], "position", get (ca(1), "position"), + "outerposition", get (ca(1), "outerposition")); + + ## Create a new set of lines with the appropriate + ## displaynames, etc + toberm = []; + hobj = get (kids(i), "children"); + for j = numel (hobj) : -1 : 1 + if (! strcmp (get (hobj(j), "type"), "text")) + continue; + endif + displayname = get (hobj(j), "string"); + ll = []; + lm = []; + for k = numel (hobj) : -1 : 1 + if (! strcmp (get (hobj(k), "type"), "line")) + continue; + endif + if (get (hobj(j), "userdata") + != get (hobj(k), "userdata")) + continue; + endif + if (! strcmp (get (hobj(k), "linestyle"), "none")) + ll = hobj(k); + endif + if (! strcmp (get (hobj(k), "marker"), "none")) + lm = hobj(k); + endif + endfor + + if (! isempty (ll)) + if (!isempty (lm)) + toberm = [toberm, line("xdata",[0,0],"ydata",[0,0], "color", get(lm,"color"), "linestyle", get(ll,"linestyle"), "marker", get(lm,"marker"), "markeredgecolor", get(lm,"markeredgecolor"), "markerfacecolor", get(lm,"markerfacecolor"), "markersize", get (lm, "markersize"), "displayname", displayname, "parent", kids(i))]; + else + toberm = [toberm, line("xdata",[0,0],"ydata",[0,0], "color", get(ll,"color"), "linestyle", get(ll,"linestyle"), "marker", "none", "displayname", displayname, "parent", kids(i))]; + endif + elseif (! isempty (lm)) + toberm = [toberm, line("xdata",[0,0],"ydata",[0,0], "color", get(lm,"color"), "linestyle", "none", "marker", get(lm,"marker"), "markeredgecolor", get(lm,"markeredgecolor"), "markerfacecolor", get(lm,"markerfacecolor"), "markersize", get (lm, "markersize"), "displayname", displayname, "parent", kids(i))]; + endif + endfor + if (bg_is_set) + fprintf (plot_stream, "set border linecolor rgb \"#%02x%02x%02x\"\n", 255 * (1 - bg)); + endif + __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, + bg_is_set, false, hlgnd); + unwind_protect_cleanup + ## Return axes "units" and "position" back to + ## their original values. + set (ca, "units", orig_axes_units); + set (kids(i), "units", legend_axes_units, + "box", legend_axes_box, + "ylim", legend_axes_ylim, + "position", legend_axes_position, + "outerposition", legend_axes_outerposition); + delete (toberm); + bg_is_set = false; + end_unwind_protect + endif + else + ## Rely upon listener to convert axes position + ## to "normalized" units. + orig_axes_units = get (kids(i), "units"); + orig_axes_position = get (kids(i), "position"); + unwind_protect + set (kids(i), "units", "normalized"); + fg = get (kids(i), "color"); + if (isnumeric (fg) && strcmp (get (kids(i), "visible"), "on")) + fprintf (plot_stream, "set obj 2 rectangle from graph 0,0 to graph 1,1 behind fc rgb \"#%02x%02x%02x\"\n", 255 * fg); + fg_is_set = true; + else + fg_is_set = false; + endif + if (bg_is_set) + fprintf (plot_stream, "set border linecolor rgb \"#%02x%02x%02x\"\n", 255 * (1 - bg)); + endif + ## Find if this axes has an associated legend axes and pass it + ## to __go_draw_axes__ + hlegend = []; + fkids = get (h, "children"); + for j = 1 : numel(fkids) + if (ishandle (fkids (j)) + && strcmp (get (fkids (j), "type"), "axes") + && (strcmp (get (fkids (j), "tag"), "legend"))) + udata = get (fkids (j), "userdata"); + if (isscalar(udata.handle) + && ! isempty (intersect (udata.handle, kids (i)))) + hlegend = get (fkids (j)); + break; + endif + endif + endfor + __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, + bg_is_set, fg_is_set, hlegend); + unwind_protect_cleanup + ## Return axes "units" and "position" back to + ## their original values. + set (kids(i), "units", orig_axes_units); + set (kids(i), "position", orig_axes_position); + bg_is_set = false; + fg_is_set = false; + end_unwind_protect + endif + case "uimenu" + ## ignore uimenu objects + otherwise + error ("__go_draw_figure__: unknown object class, %s", type); + endswitch + endfor + fputs (plot_stream, "\nunset multiplot;\n"); + else + fputs (plot_stream, "\nreset; clear;\n"); + fflush (plot_stream); + endif + else + error ("__go_draw_figure__: expecting figure object, found `%s'", + htype); + endif + else + print_usage (); + endif + +endfunction + diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/private/__marching_cube__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/private/__marching_cube__.m Sat Jul 16 09:28:26 2011 -0700 @@ -0,0 +1,530 @@ +## Copyright (C) 2009-2011 Martin Helm +## +## 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 3 of the License, 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, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {[@var{t}, @var{p}] =} __marching_cube__ (@var{x}, @var{y}, @var{z}, @var{val}, @var{iso}) +## @deftypefnx {Function File} {[@var{t}, @var{p}, @var{c}] =} __marching_cube__ (@var{x}, @var{y}, @var{z}, @var{val}, @var{iso}, @var{col}) +## Undocumented internal function. +## @end deftypefn + +## -*- texinfo -*- +## @deftypefn {Function File} {[@var{t}, @var{p}] =} __marching_cube__ (@var{x}, @var{y}, @var{z}, @var{val}, @var{iso}) +## @deftypefnx {Function File} {[@var{t}, @var{p}, @var{c}] =} __marching_cube__ (@var{x}, @var{y}, @var{z}, @var{val}, @var{iso}, @var{col}) +## +## Return the triangulation information @var{t} at points @var{p} for +## the isosurface values resp. the volume data @var{val} and the iso +## level @var{iso}. It is considered that the volume data @var{val} is +## given at the points @var{x}, @var{y} and @var{z} which are of type +## three--dimensional numeric arrays. The orientation of the triangles +## is choosen such that the normals point from the higher values to the +## lower values. +## +## Optionally the color data @var{col} can be passed to this function +## whereas computed vertices color data @var{c} is returned as third +## argument. +## +## The marching cube algorithm is well known and described, for example, at +## Wikipedia. The triangulation lookup table and the edge table used +## here are based on Cory Gene Bloyd's implementation and can be found +## beyond other surface and geometry stuff at Paul Bourke's website +## @uref{http://local.wasp.uwa.edu.au/~pbourke/geometry/polygonise}. +## +## For example: +## +## @example +## @group +## N = 20; +## lin = linspace(0, 2, N); +## [x, y, z] = meshgrid (lin, lin, lin); +## +## c = (x-.5).^2 + (y-.5).^2 + (z-.5).^2; +## [t, p] = __marching_cube__ (x, y, z, c, .5); +## +## figure (); +## trimesh (t, p(:,1), p(:,2), p(:,3)); +## @end group +## @end example +## +## Instead of the @command{trimesh} function the @command{patch} +## function can be used to visualize the geometry. For example: +## +## @example +## @group +## figure (); view (-38, 20); +## pa = patch ("Faces", t, "Vertices", p, "FaceVertexCData", p, \ +## "FaceColor", "interp", "EdgeColor", "none"); +## +## ## Revert normals +## set (pa, "VertexNormals", -get(pa, "VertexNormals")); +## +## ## Set lightning (available with the JHandles package) +## # set (pa, "FaceLighting", "gouraud"); +## # light( "Position", [1 1 5]); +## @end group +## @end example +## +## @end deftypefn + +## Author: Martin Helm + +function [T, p, col] = __marching_cube__ (xx, yy, zz, c, iso, colors) + + persistent edge_table=[]; + persistent tri_table=[]; + + calc_cols = false; + lindex = 4; + + if (isempty (tri_table) || isempty (edge_table)) + [edge_table, tri_table] = init_mc (); + endif + + if ((nargin != 5 && nargin != 6) || (nargout != 2 && nargout != 3)) + print_usage (); + endif + + if (!ismatrix (xx) || !ismatrix (yy) || !ismatrix (zz) || !ismatrix (c) || ... + ndims (xx) != 3 || ndims (yy) != 3 || ndims (zz) != 3 || ndims (c) != 3) + error ("__marching_cube__: XX, YY, ZZ, C must be matrices of dim 3"); + endif + + if (!size_equal (xx, yy, zz, c)) + error ("__marching_cube__: XX, YY, ZZ, C must be of equal size"); + endif + + if (any (size (xx) < [2 2 2])) + error ("__marching_cube__: grid size must be at least 2x2x2"); + endif + + if (!isscalar (iso)) + error ("__marching_cube__: ISO must be scalar value"); + endif + + if (nargin == 6) + if ( !ismatrix (colors) || ndims (colors) != 3 || size (colors) != size (c) ) + error ( "COLORS must be a matrix of dim 3 and of same size as C" ); + endif + calc_cols = true; + lindex = 5; + endif + + n = size (c) - 1; + + ## phase I: assign information to each voxel which edges are intersected by + ## the isosurface + cc = zeros (n(1), n(2), n(3), "uint16"); + cedge = zeros (size (cc), "uint16"); + + vertex_idx = {1:n(1), 1:n(2), 1:n(3); ... + 2:n(1)+1, 1:n(2), 1:n(3); ... + 2:n(1)+1, 2:n(2)+1, 1:n(3); ... + 1:n(1), 2:n(2)+1, 1:n(3); ... + 1:n(1), 1:n(2), 2:n(3)+1; ... + 2:n(1)+1, 1:n(2), 2:n(3)+1; ... + 2:n(1)+1, 2:n(2)+1, 2:n(3)+1; ... + 1:n(1), 2:n(2)+1, 2:n(3)+1 }; + + ## calculate which vertices have values higher than iso + for ii=1:8 + idx = c(vertex_idx{ii, :}) > iso; + cc(idx) = bitset (cc(idx), ii); + endfor + + cedge = edge_table(cc+1); # assign the info about intersected edges + id = find (cedge); # select only voxels which are intersected + if (isempty (id)) + T = p = col = []; + return + endif + + ## phase II: calculate the list of intersection points + xyz_off = [1, 1, 1; 2, 1, 1; 2, 2, 1; 1, 2, 1; 1, 1, 2; 2, 1, 2; 2, 2, 2; 1, 2, 2]; + edges = [1 2; 2 3; 3 4; 4 1; 5 6; 6 7; 7 8; 8 5; 1 5; 2 6; 3 7; 4 8]; + offset = sub2ind (size (c), xyz_off(:, 1), xyz_off(:, 2), xyz_off(:, 3)) -1; + pp = zeros (length (id), lindex, 12); + ccedge = [vec(cedge(id)), id]; + ix_offset=0; + for jj=1:12 + id__ = bitget (ccedge(:, 1), jj); + id_ = ccedge(id__, 2); + [ix iy iz] = ind2sub (size (cc), id_); + id_c = sub2ind (size (c), ix, iy, iz); + id1 = id_c + offset(edges(jj, 1)); + id2 = id_c + offset(edges(jj, 2)); + if (calc_cols) + pp(id__, 1:5, jj) = [vertex_interp(iso, xx(id1), yy(id1), zz(id1), ... + xx(id2), yy(id2), zz(id2), c(id1), c(id2), colors(id1), colors(id2)), ... + (1:size (id_, 1))' + ix_offset ]; + else + pp(id__, 1:4, jj) = [vertex_interp(iso, xx(id1), yy(id1), zz(id1), ... + xx(id2), yy(id2), zz(id2), c(id1), c(id2)), ... + (1:size (id_, 1))' + ix_offset ]; + endif + ix_offset += size (id_, 1); + endfor + + ## phase III: calculate the triangulation from the point list + T = []; + tri = tri_table(cc(id)+1, :); + for jj=1:3:15 + id_ = find (tri(:, jj)>0); + p = [id_, lindex*ones(size (id_, 1), 1),tri(id_, jj:jj+2)]; + if (!isempty (p)) + p1 = sub2ind (size (pp), p(:,1), p(:,2), p(:,3)); + p2 = sub2ind (size (pp), p(:,1), p(:,2), p(:,4)); + p3 = sub2ind (size (pp), p(:,1), p(:,2), p(:,5)); + T = [T; pp(p1), pp(p2), pp(p3)]; + endif + endfor + + p = []; + col = []; + for jj = 1:12 + idp = pp(:, lindex, jj) > 0; + if (any (idp)) + p(pp(idp, lindex, jj), 1:3) = pp(idp, 1:3, jj); + if (calc_cols) + col(pp(idp, lindex, jj),1) = pp(idp, 4, jj); + endif + endif + endfor +endfunction + +function p = vertex_interp(isolevel,p1x, p1y, p1z,... + p2x, p2y, p2z,valp1,valp2, col1, col2) + + if (nargin == 9) + p = zeros (length (p1x), 3); + elseif (nargin == 11) + p = zeros (length (p1x), 4); + else + error ("__marching_cube__: wrong number of arguments"); + endif + mu = zeros (length (p1x), 1); + id = abs (valp1-valp2) < (10*eps) .* (abs (valp1) .+ abs (valp2)); + if (any (id)) + p(id, 1:3) = [ p1x(id), p1y(id), p1z(id) ]; + if (nargin == 11) + p(id, 4) = col1(id); + endif + endif + nid = !id; + if (any (nid)) + mu(nid) = (isolevel - valp1(nid)) ./ (valp2(nid) - valp1(nid)); + p(nid, 1:3) = [p1x(nid) + mu(nid) .* (p2x(nid) - p1x(nid)), ... + p1y(nid) + mu(nid) .* (p2y(nid) - p1y(nid)), ... + p1z(nid) + mu(nid) .* (p2z(nid) - p1z(nid))]; + if (nargin == 11) + p(nid, 4) = col1(nid) + mu(nid) .* (col2(nid) - col1(nid)); + endif + endif +endfunction + +function [edge_table, tri_table] = init_mc() + edge_table = [ + 0x0 , 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c, ... + 0x80c, 0x905, 0xa0f, 0xb06, 0xc0a, 0xd03, 0xe09, 0xf00, ... + 0x190, 0x99 , 0x393, 0x29a, 0x596, 0x49f, 0x795, 0x69c, ... + 0x99c, 0x895, 0xb9f, 0xa96, 0xd9a, 0xc93, 0xf99, 0xe90, ... + 0x230, 0x339, 0x33 , 0x13a, 0x636, 0x73f, 0x435, 0x53c, ... + 0xa3c, 0xb35, 0x83f, 0x936, 0xe3a, 0xf33, 0xc39, 0xd30, ... + 0x3a0, 0x2a9, 0x1a3, 0xaa , 0x7a6, 0x6af, 0x5a5, 0x4ac, ... + 0xbac, 0xaa5, 0x9af, 0x8a6, 0xfaa, 0xea3, 0xda9, 0xca0, ... + 0x460, 0x569, 0x663, 0x76a, 0x66 , 0x16f, 0x265, 0x36c, ... + 0xc6c, 0xd65, 0xe6f, 0xf66, 0x86a, 0x963, 0xa69, 0xb60, ... + 0x5f0, 0x4f9, 0x7f3, 0x6fa, 0x1f6, 0xff , 0x3f5, 0x2fc, ... + 0xdfc, 0xcf5, 0xfff, 0xef6, 0x9fa, 0x8f3, 0xbf9, 0xaf0, ... + 0x650, 0x759, 0x453, 0x55a, 0x256, 0x35f, 0x55 , 0x15c, ... + 0xe5c, 0xf55, 0xc5f, 0xd56, 0xa5a, 0xb53, 0x859, 0x950, ... + 0x7c0, 0x6c9, 0x5c3, 0x4ca, 0x3c6, 0x2cf, 0x1c5, 0xcc , ... + 0xfcc, 0xec5, 0xdcf, 0xcc6, 0xbca, 0xac3, 0x9c9, 0x8c0, ... + 0x8c0, 0x9c9, 0xac3, 0xbca, 0xcc6, 0xdcf, 0xec5, 0xfcc, ... + 0xcc , 0x1c5, 0x2cf, 0x3c6, 0x4ca, 0x5c3, 0x6c9, 0x7c0, ... + 0x950, 0x859, 0xb53, 0xa5a, 0xd56, 0xc5f, 0xf55, 0xe5c, ... + 0x15c, 0x55 , 0x35f, 0x256, 0x55a, 0x453, 0x759, 0x650, ... + 0xaf0, 0xbf9, 0x8f3, 0x9fa, 0xef6, 0xfff, 0xcf5, 0xdfc, ... + 0x2fc, 0x3f5, 0xff , 0x1f6, 0x6fa, 0x7f3, 0x4f9, 0x5f0, ... + 0xb60, 0xa69, 0x963, 0x86a, 0xf66, 0xe6f, 0xd65, 0xc6c, ... + 0x36c, 0x265, 0x16f, 0x66 , 0x76a, 0x663, 0x569, 0x460, ... + 0xca0, 0xda9, 0xea3, 0xfaa, 0x8a6, 0x9af, 0xaa5, 0xbac, ... + 0x4ac, 0x5a5, 0x6af, 0x7a6, 0xaa , 0x1a3, 0x2a9, 0x3a0, ... + 0xd30, 0xc39, 0xf33, 0xe3a, 0x936, 0x83f, 0xb35, 0xa3c, ... + 0x53c, 0x435, 0x73f, 0x636, 0x13a, 0x33 , 0x339, 0x230, ... + 0xe90, 0xf99, 0xc93, 0xd9a, 0xa96, 0xb9f, 0x895, 0x99c, ... + 0x69c, 0x795, 0x49f, 0x596, 0x29a, 0x393, 0x99 , 0x190, ... + 0xf00, 0xe09, 0xd03, 0xc0a, 0xb06, 0xa0f, 0x905, 0x80c, ... + 0x70c, 0x605, 0x50f, 0x406, 0x30a, 0x203, 0x109, 0x0 ]; + + tri_table =[ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 1, 8, 3, 9, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 0, 8, 3, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 9, 2, 10, 0, 2, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 2, 8, 3, 2, 10, 8, 10, 9, 8, -1, -1, -1, -1, -1, -1, -1; + 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 0, 11, 2, 8, 11, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 1, 9, 0, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 1, 11, 2, 1, 9, 11, 9, 8, 11, -1, -1, -1, -1, -1, -1, -1; + 3, 10, 1, 11, 10, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 0, 10, 1, 0, 8, 10, 8, 11, 10, -1, -1, -1, -1, -1, -1, -1; + 3, 9, 0, 3, 11, 9, 11, 10, 9, -1, -1, -1, -1, -1, -1, -1; + 9, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 4, 3, 0, 7, 3, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 0, 1, 9, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 4, 1, 9, 4, 7, 1, 7, 3, 1, -1, -1, -1, -1, -1, -1, -1; + 1, 2, 10, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 3, 4, 7, 3, 0, 4, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1; + 9, 2, 10, 9, 0, 2, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1; + 2, 10, 9, 2, 9, 7, 2, 7, 3, 7, 9, 4, -1, -1, -1, -1; + 8, 4, 7, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 11, 4, 7, 11, 2, 4, 2, 0, 4, -1, -1, -1, -1, -1, -1, -1; + 9, 0, 1, 8, 4, 7, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1; + 4, 7, 11, 9, 4, 11, 9, 11, 2, 9, 2, 1, -1, -1, -1, -1; + 3, 10, 1, 3, 11, 10, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1; + 1, 11, 10, 1, 4, 11, 1, 0, 4, 7, 11, 4, -1, -1, -1, -1; + 4, 7, 8, 9, 0, 11, 9, 11, 10, 11, 0, 3, -1, -1, -1, -1; + 4, 7, 11, 4, 11, 9, 9, 11, 10, -1, -1, -1, -1, -1, -1, -1; + 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 9, 5, 4, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 0, 5, 4, 1, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 8, 5, 4, 8, 3, 5, 3, 1, 5, -1, -1, -1, -1, -1, -1, -1; + 1, 2, 10, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 3, 0, 8, 1, 2, 10, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1; + 5, 2, 10, 5, 4, 2, 4, 0, 2, -1, -1, -1, -1, -1, -1, -1; + 2, 10, 5, 3, 2, 5, 3, 5, 4, 3, 4, 8, -1, -1, -1, -1; + 9, 5, 4, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 0, 11, 2, 0, 8, 11, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1; + 0, 5, 4, 0, 1, 5, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1; + 2, 1, 5, 2, 5, 8, 2, 8, 11, 4, 8, 5, -1, -1, -1, -1; + 10, 3, 11, 10, 1, 3, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1; + 4, 9, 5, 0, 8, 1, 8, 10, 1, 8, 11, 10, -1, -1, -1, -1; + 5, 4, 0, 5, 0, 11, 5, 11, 10, 11, 0, 3, -1, -1, -1, -1; + 5, 4, 8, 5, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1; + 9, 7, 8, 5, 7, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 9, 3, 0, 9, 5, 3, 5, 7, 3, -1, -1, -1, -1, -1, -1, -1; + 0, 7, 8, 0, 1, 7, 1, 5, 7, -1, -1, -1, -1, -1, -1, -1; + 1, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 9, 7, 8, 9, 5, 7, 10, 1, 2, -1, -1, -1, -1, -1, -1, -1; + 10, 1, 2, 9, 5, 0, 5, 3, 0, 5, 7, 3, -1, -1, -1, -1; + 8, 0, 2, 8, 2, 5, 8, 5, 7, 10, 5, 2, -1, -1, -1, -1; + 2, 10, 5, 2, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1; + 7, 9, 5, 7, 8, 9, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1; + 9, 5, 7, 9, 7, 2, 9, 2, 0, 2, 7, 11, -1, -1, -1, -1; + 2, 3, 11, 0, 1, 8, 1, 7, 8, 1, 5, 7, -1, -1, -1, -1; + 11, 2, 1, 11, 1, 7, 7, 1, 5, -1, -1, -1, -1, -1, -1, -1; + 9, 5, 8, 8, 5, 7, 10, 1, 3, 10, 3, 11, -1, -1, -1, -1; + 5, 7, 0, 5, 0, 9, 7, 11, 0, 1, 0, 10, 11, 10, 0, -1; + 11, 10, 0, 11, 0, 3, 10, 5, 0, 8, 0, 7, 5, 7, 0, -1; + 11, 10, 5, 7, 11, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 0, 8, 3, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 9, 0, 1, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 1, 8, 3, 1, 9, 8, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1; + 1, 6, 5, 2, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 1, 6, 5, 1, 2, 6, 3, 0, 8, -1, -1, -1, -1, -1, -1, -1; + 9, 6, 5, 9, 0, 6, 0, 2, 6, -1, -1, -1, -1, -1, -1, -1; + 5, 9, 8, 5, 8, 2, 5, 2, 6, 3, 2, 8, -1, -1, -1, -1; + 2, 3, 11, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 11, 0, 8, 11, 2, 0, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1; + 0, 1, 9, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1; + 5, 10, 6, 1, 9, 2, 9, 11, 2, 9, 8, 11, -1, -1, -1, -1; + 6, 3, 11, 6, 5, 3, 5, 1, 3, -1, -1, -1, -1, -1, -1, -1; + 0, 8, 11, 0, 11, 5, 0, 5, 1, 5, 11, 6, -1, -1, -1, -1; + 3, 11, 6, 0, 3, 6, 0, 6, 5, 0, 5, 9, -1, -1, -1, -1; + 6, 5, 9, 6, 9, 11, 11, 9, 8, -1, -1, -1, -1, -1, -1, -1; + 5, 10, 6, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 4, 3, 0, 4, 7, 3, 6, 5, 10, -1, -1, -1, -1, -1, -1, -1; + 1, 9, 0, 5, 10, 6, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1; + 10, 6, 5, 1, 9, 7, 1, 7, 3, 7, 9, 4, -1, -1, -1, -1; + 6, 1, 2, 6, 5, 1, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1; + 1, 2, 5, 5, 2, 6, 3, 0, 4, 3, 4, 7, -1, -1, -1, -1; + 8, 4, 7, 9, 0, 5, 0, 6, 5, 0, 2, 6, -1, -1, -1, -1; + 7, 3, 9, 7, 9, 4, 3, 2, 9, 5, 9, 6, 2, 6, 9, -1; + 3, 11, 2, 7, 8, 4, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1; + 5, 10, 6, 4, 7, 2, 4, 2, 0, 2, 7, 11, -1, -1, -1, -1; + 0, 1, 9, 4, 7, 8, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1; + 9, 2, 1, 9, 11, 2, 9, 4, 11, 7, 11, 4, 5, 10, 6, -1; + 8, 4, 7, 3, 11, 5, 3, 5, 1, 5, 11, 6, -1, -1, -1, -1; + 5, 1, 11, 5, 11, 6, 1, 0, 11, 7, 11, 4, 0, 4, 11, -1; + 0, 5, 9, 0, 6, 5, 0, 3, 6, 11, 6, 3, 8, 4, 7, -1; + 6, 5, 9, 6, 9, 11, 4, 7, 9, 7, 11, 9, -1, -1, -1, -1; + 10, 4, 9, 6, 4, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 4, 10, 6, 4, 9, 10, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1; + 10, 0, 1, 10, 6, 0, 6, 4, 0, -1, -1, -1, -1, -1, -1, -1; + 8, 3, 1, 8, 1, 6, 8, 6, 4, 6, 1, 10, -1, -1, -1, -1; + 1, 4, 9, 1, 2, 4, 2, 6, 4, -1, -1, -1, -1, -1, -1, -1; + 3, 0, 8, 1, 2, 9, 2, 4, 9, 2, 6, 4, -1, -1, -1, -1; + 0, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 8, 3, 2, 8, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1; + 10, 4, 9, 10, 6, 4, 11, 2, 3, -1, -1, -1, -1, -1, -1, -1; + 0, 8, 2, 2, 8, 11, 4, 9, 10, 4, 10, 6, -1, -1, -1, -1; + 3, 11, 2, 0, 1, 6, 0, 6, 4, 6, 1, 10, -1, -1, -1, -1; + 6, 4, 1, 6, 1, 10, 4, 8, 1, 2, 1, 11, 8, 11, 1, -1; + 9, 6, 4, 9, 3, 6, 9, 1, 3, 11, 6, 3, -1, -1, -1, -1; + 8, 11, 1, 8, 1, 0, 11, 6, 1, 9, 1, 4, 6, 4, 1, -1; + 3, 11, 6, 3, 6, 0, 0, 6, 4, -1, -1, -1, -1, -1, -1, -1; + 6, 4, 8, 11, 6, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 7, 10, 6, 7, 8, 10, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1; + 0, 7, 3, 0, 10, 7, 0, 9, 10, 6, 7, 10, -1, -1, -1, -1; + 10, 6, 7, 1, 10, 7, 1, 7, 8, 1, 8, 0, -1, -1, -1, -1; + 10, 6, 7, 10, 7, 1, 1, 7, 3, -1, -1, -1, -1, -1, -1, -1; + 1, 2, 6, 1, 6, 8, 1, 8, 9, 8, 6, 7, -1, -1, -1, -1; + 2, 6, 9, 2, 9, 1, 6, 7, 9, 0, 9, 3, 7, 3, 9, -1; + 7, 8, 0, 7, 0, 6, 6, 0, 2, -1, -1, -1, -1, -1, -1, -1; + 7, 3, 2, 6, 7, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 2, 3, 11, 10, 6, 8, 10, 8, 9, 8, 6, 7, -1, -1, -1, -1; + 2, 0, 7, 2, 7, 11, 0, 9, 7, 6, 7, 10, 9, 10, 7, -1; + 1, 8, 0, 1, 7, 8, 1, 10, 7, 6, 7, 10, 2, 3, 11, -1; + 11, 2, 1, 11, 1, 7, 10, 6, 1, 6, 7, 1, -1, -1, -1, -1; + 8, 9, 6, 8, 6, 7, 9, 1, 6, 11, 6, 3, 1, 3, 6, -1; + 0, 9, 1, 11, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 7, 8, 0, 7, 0, 6, 3, 11, 0, 11, 6, 0, -1, -1, -1, -1; + 7, 11, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 3, 0, 8, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 0, 1, 9, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 8, 1, 9, 8, 3, 1, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1; + 10, 1, 2, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 1, 2, 10, 3, 0, 8, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1; + 2, 9, 0, 2, 10, 9, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1; + 6, 11, 7, 2, 10, 3, 10, 8, 3, 10, 9, 8, -1, -1, -1, -1; + 7, 2, 3, 6, 2, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 7, 0, 8, 7, 6, 0, 6, 2, 0, -1, -1, -1, -1, -1, -1, -1; + 2, 7, 6, 2, 3, 7, 0, 1, 9, -1, -1, -1, -1, -1, -1, -1; + 1, 6, 2, 1, 8, 6, 1, 9, 8, 8, 7, 6, -1, -1, -1, -1; + 10, 7, 6, 10, 1, 7, 1, 3, 7, -1, -1, -1, -1, -1, -1, -1; + 10, 7, 6, 1, 7, 10, 1, 8, 7, 1, 0, 8, -1, -1, -1, -1; + 0, 3, 7, 0, 7, 10, 0, 10, 9, 6, 10, 7, -1, -1, -1, -1; + 7, 6, 10, 7, 10, 8, 8, 10, 9, -1, -1, -1, -1, -1, -1, -1; + 6, 8, 4, 11, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 3, 6, 11, 3, 0, 6, 0, 4, 6, -1, -1, -1, -1, -1, -1, -1; + 8, 6, 11, 8, 4, 6, 9, 0, 1, -1, -1, -1, -1, -1, -1, -1; + 9, 4, 6, 9, 6, 3, 9, 3, 1, 11, 3, 6, -1, -1, -1, -1; + 6, 8, 4, 6, 11, 8, 2, 10, 1, -1, -1, -1, -1, -1, -1, -1; + 1, 2, 10, 3, 0, 11, 0, 6, 11, 0, 4, 6, -1, -1, -1, -1; + 4, 11, 8, 4, 6, 11, 0, 2, 9, 2, 10, 9, -1, -1, -1, -1; + 10, 9, 3, 10, 3, 2, 9, 4, 3, 11, 3, 6, 4, 6, 3, -1; + 8, 2, 3, 8, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1; + 0, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 1, 9, 0, 2, 3, 4, 2, 4, 6, 4, 3, 8, -1, -1, -1, -1; + 1, 9, 4, 1, 4, 2, 2, 4, 6, -1, -1, -1, -1, -1, -1, -1; + 8, 1, 3, 8, 6, 1, 8, 4, 6, 6, 10, 1, -1, -1, -1, -1; + 10, 1, 0, 10, 0, 6, 6, 0, 4, -1, -1, -1, -1, -1, -1, -1; + 4, 6, 3, 4, 3, 8, 6, 10, 3, 0, 3, 9, 10, 9, 3, -1; + 10, 9, 4, 6, 10, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 4, 9, 5, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 0, 8, 3, 4, 9, 5, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1; + 5, 0, 1, 5, 4, 0, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1; + 11, 7, 6, 8, 3, 4, 3, 5, 4, 3, 1, 5, -1, -1, -1, -1; + 9, 5, 4, 10, 1, 2, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1; + 6, 11, 7, 1, 2, 10, 0, 8, 3, 4, 9, 5, -1, -1, -1, -1; + 7, 6, 11, 5, 4, 10, 4, 2, 10, 4, 0, 2, -1, -1, -1, -1; + 3, 4, 8, 3, 5, 4, 3, 2, 5, 10, 5, 2, 11, 7, 6, -1; + 7, 2, 3, 7, 6, 2, 5, 4, 9, -1, -1, -1, -1, -1, -1, -1; + 9, 5, 4, 0, 8, 6, 0, 6, 2, 6, 8, 7, -1, -1, -1, -1; + 3, 6, 2, 3, 7, 6, 1, 5, 0, 5, 4, 0, -1, -1, -1, -1; + 6, 2, 8, 6, 8, 7, 2, 1, 8, 4, 8, 5, 1, 5, 8, -1; + 9, 5, 4, 10, 1, 6, 1, 7, 6, 1, 3, 7, -1, -1, -1, -1; + 1, 6, 10, 1, 7, 6, 1, 0, 7, 8, 7, 0, 9, 5, 4, -1; + 4, 0, 10, 4, 10, 5, 0, 3, 10, 6, 10, 7, 3, 7, 10, -1; + 7, 6, 10, 7, 10, 8, 5, 4, 10, 4, 8, 10, -1, -1, -1, -1; + 6, 9, 5, 6, 11, 9, 11, 8, 9, -1, -1, -1, -1, -1, -1, -1; + 3, 6, 11, 0, 6, 3, 0, 5, 6, 0, 9, 5, -1, -1, -1, -1; + 0, 11, 8, 0, 5, 11, 0, 1, 5, 5, 6, 11, -1, -1, -1, -1; + 6, 11, 3, 6, 3, 5, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1; + 1, 2, 10, 9, 5, 11, 9, 11, 8, 11, 5, 6, -1, -1, -1, -1; + 0, 11, 3, 0, 6, 11, 0, 9, 6, 5, 6, 9, 1, 2, 10, -1; + 11, 8, 5, 11, 5, 6, 8, 0, 5, 10, 5, 2, 0, 2, 5, -1; + 6, 11, 3, 6, 3, 5, 2, 10, 3, 10, 5, 3, -1, -1, -1, -1; + 5, 8, 9, 5, 2, 8, 5, 6, 2, 3, 8, 2, -1, -1, -1, -1; + 9, 5, 6, 9, 6, 0, 0, 6, 2, -1, -1, -1, -1, -1, -1, -1; + 1, 5, 8, 1, 8, 0, 5, 6, 8, 3, 8, 2, 6, 2, 8, -1; + 1, 5, 6, 2, 1, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 1, 3, 6, 1, 6, 10, 3, 8, 6, 5, 6, 9, 8, 9, 6, -1; + 10, 1, 0, 10, 0, 6, 9, 5, 0, 5, 6, 0, -1, -1, -1, -1; + 0, 3, 8, 5, 6, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 10, 5, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 11, 5, 10, 7, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 11, 5, 10, 11, 7, 5, 8, 3, 0, -1, -1, -1, -1, -1, -1, -1; + 5, 11, 7, 5, 10, 11, 1, 9, 0, -1, -1, -1, -1, -1, -1, -1; + 10, 7, 5, 10, 11, 7, 9, 8, 1, 8, 3, 1, -1, -1, -1, -1; + 11, 1, 2, 11, 7, 1, 7, 5, 1, -1, -1, -1, -1, -1, -1, -1; + 0, 8, 3, 1, 2, 7, 1, 7, 5, 7, 2, 11, -1, -1, -1, -1; + 9, 7, 5, 9, 2, 7, 9, 0, 2, 2, 11, 7, -1, -1, -1, -1; + 7, 5, 2, 7, 2, 11, 5, 9, 2, 3, 2, 8, 9, 8, 2, -1; + 2, 5, 10, 2, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1; + 8, 2, 0, 8, 5, 2, 8, 7, 5, 10, 2, 5, -1, -1, -1, -1; + 9, 0, 1, 5, 10, 3, 5, 3, 7, 3, 10, 2, -1, -1, -1, -1; + 9, 8, 2, 9, 2, 1, 8, 7, 2, 10, 2, 5, 7, 5, 2, -1; + 1, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 0, 8, 7, 0, 7, 1, 1, 7, 5, -1, -1, -1, -1, -1, -1, -1; + 9, 0, 3, 9, 3, 5, 5, 3, 7, -1, -1, -1, -1, -1, -1, -1; + 9, 8, 7, 5, 9, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 5, 8, 4, 5, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1; + 5, 0, 4, 5, 11, 0, 5, 10, 11, 11, 3, 0, -1, -1, -1, -1; + 0, 1, 9, 8, 4, 10, 8, 10, 11, 10, 4, 5, -1, -1, -1, -1; + 10, 11, 4, 10, 4, 5, 11, 3, 4, 9, 4, 1, 3, 1, 4, -1; + 2, 5, 1, 2, 8, 5, 2, 11, 8, 4, 5, 8, -1, -1, -1, -1; + 0, 4, 11, 0, 11, 3, 4, 5, 11, 2, 11, 1, 5, 1, 11, -1; + 0, 2, 5, 0, 5, 9, 2, 11, 5, 4, 5, 8, 11, 8, 5, -1; + 9, 4, 5, 2, 11, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 2, 5, 10, 3, 5, 2, 3, 4, 5, 3, 8, 4, -1, -1, -1, -1; + 5, 10, 2, 5, 2, 4, 4, 2, 0, -1, -1, -1, -1, -1, -1, -1; + 3, 10, 2, 3, 5, 10, 3, 8, 5, 4, 5, 8, 0, 1, 9, -1; + 5, 10, 2, 5, 2, 4, 1, 9, 2, 9, 4, 2, -1, -1, -1, -1; + 8, 4, 5, 8, 5, 3, 3, 5, 1, -1, -1, -1, -1, -1, -1, -1; + 0, 4, 5, 1, 0, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 8, 4, 5, 8, 5, 3, 9, 0, 5, 0, 3, 5, -1, -1, -1, -1; + 9, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 4, 11, 7, 4, 9, 11, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1; + 0, 8, 3, 4, 9, 7, 9, 11, 7, 9, 10, 11, -1, -1, -1, -1; + 1, 10, 11, 1, 11, 4, 1, 4, 0, 7, 4, 11, -1, -1, -1, -1; + 3, 1, 4, 3, 4, 8, 1, 10, 4, 7, 4, 11, 10, 11, 4, -1; + 4, 11, 7, 9, 11, 4, 9, 2, 11, 9, 1, 2, -1, -1, -1, -1; + 9, 7, 4, 9, 11, 7, 9, 1, 11, 2, 11, 1, 0, 8, 3, -1; + 11, 7, 4, 11, 4, 2, 2, 4, 0, -1, -1, -1, -1, -1, -1, -1; + 11, 7, 4, 11, 4, 2, 8, 3, 4, 3, 2, 4, -1, -1, -1, -1; + 2, 9, 10, 2, 7, 9, 2, 3, 7, 7, 4, 9, -1, -1, -1, -1; + 9, 10, 7, 9, 7, 4, 10, 2, 7, 8, 7, 0, 2, 0, 7, -1; + 3, 7, 10, 3, 10, 2, 7, 4, 10, 1, 10, 0, 4, 0, 10, -1; + 1, 10, 2, 8, 7, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 4, 9, 1, 4, 1, 7, 7, 1, 3, -1, -1, -1, -1, -1, -1, -1; + 4, 9, 1, 4, 1, 7, 0, 8, 1, 8, 7, 1, -1, -1, -1, -1; + 4, 0, 3, 7, 4, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 4, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 9, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 3, 0, 9, 3, 9, 11, 11, 9, 10, -1, -1, -1, -1, -1, -1, -1; + 0, 1, 10, 0, 10, 8, 8, 10, 11, -1, -1, -1, -1, -1, -1, -1; + 3, 1, 10, 11, 3, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 1, 2, 11, 1, 11, 9, 9, 11, 8, -1, -1, -1, -1, -1, -1, -1; + 3, 0, 9, 3, 9, 11, 1, 2, 9, 2, 11, 9, -1, -1, -1, -1; + 0, 2, 11, 8, 0, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 3, 2, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 2, 3, 8, 2, 8, 10, 10, 8, 9, -1, -1, -1, -1, -1, -1, -1; + 9, 10, 2, 0, 9, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 2, 3, 8, 2, 8, 10, 0, 1, 8, 1, 10, 8, -1, -1, -1, -1; + 1, 10, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 1, 3, 8, 9, 1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 0, 9, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + 0, 3, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ] + 1; +endfunction diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/private/__next_line_color__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/private/__next_line_color__.m Sat Jul 16 09:28:26 2011 -0700 @@ -0,0 +1,54 @@ +## Copyright (C) 2007-2011 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 3 of the License, 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, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{rgb} =} __next_line_color__ (@var{reset}) +## Undocumented internal function. +## @end deftypefn + +## Return the next line color in the rotation. + +## Author: jwe + +function rgb = __next_line_color__ (reset) + + persistent color_rotation; + persistent num_colors; + persistent color_index; + + if (nargin < 2) + if (nargin == 1) + if (reset || isempty (color_rotation)) + color_rotation = get (gca (), "colororder"); + num_colors = rows (color_rotation); + color_index = 1; + endif + elseif (! isempty (color_rotation)) + rgb = color_rotation(color_index,:); + if (++color_index > num_colors) + color_index = 1; + __next_line_style__ ("incr"); + endif + else + error ("__next_line_color__: color_rotation not initialized"); + endif + else + print_usage (); + endif + +endfunction diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/private/__next_line_style__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/private/__next_line_style__.m Sat Jul 16 09:28:26 2011 -0700 @@ -0,0 +1,58 @@ +## Copyright (C) 2010-2011 David Bateman +## +## 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 3 of the License, 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, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{style} =} __next_line_style__ (@var{reset}) +## Undocumented internal function. +## @end deftypefn + +## Return the next line style in the rotation. + + +function [linestyle, marker] = __next_line_style__ (reset) + + persistent style_rotation; + persistent num_styles; + persistent style_index; + + if (nargin < 2) + if (nargin == 1) + if (ischar (reset) && strncmp (reset, "incr", 4)) + if (isempty (style_rotation)) + error ("__next_line_style__: style_rotation not initialized"); + elseif (++style_index > num_styles) + style_index = 1; + endif + elseif (reset || isempty (style_rotation)) + style_rotation = strsplit (get (gca (), "linestyleorder"), "|"); + num_styles = length (style_rotation); + style_index = 1; + endif + elseif (! isempty (style_rotation)) + options = __pltopt__ ("__next_line_style__", + style_rotation (style_index)); + linestyle = options.linestyle; + marker = options.marker; + else + error ("__next_line_style__: style_rotation not initialized"); + endif + else + print_usage (); + endif + +endfunction diff -r dc29b64668fa -r 6f91ca83d2be scripts/plot/private/__print_parse_opts__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/private/__print_parse_opts__.m Sat Jul 16 09:28:26 2011 -0700 @@ -0,0 +1,610 @@ +## Copyright (C) 2008-2011 David Bateman +## +## 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 3 of the License, 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, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {[@var{x}, @var{y}, @var{buttons}] =} ginput (@var{n}) +## Return which mouse buttons were pressed and keys were hit on the current +## figure. If @var{n} is defined, then wait for @var{n} mouse clicks +## before returning. If @var{n} is not defined, then @code{ginput} will +## loop until the return key is pressed. +## @end deftypefn + +function arg_st = __print_parse_opts__ (varargin) + + persistent warn_on_missing_binary = true + + arg_st.append_to_file = false; + arg_st.canvas_size = []; + arg_st.debug = false; + arg_st.debug_file = "octave-print-commands.log"; + arg_st.devopt = ""; + arg_st.epstool_binary = __quote_path__ (__find_binary__ ("epstool")); + arg_st.figure = get (0, "currentfigure"); + arg_st.fig2dev_binary = __quote_path__ (__find_binary__ ("fig2dev")); + arg_st.fontsize = ""; + arg_st.font = ""; + arg_st.force_solid = 0; # 0=default, -1=dashed, +1=solid + arg_st.formatted_for_printing = false; + arg_st.ghostscript.binary = __quote_path__ (__ghostscript_binary__ ()); + arg_st.ghostscript.debug = false; + arg_st.ghostscript.device = ""; + arg_st.ghostscript.epscrop = true; + arg_st.ghostscript.level = []; + arg_st.ghostscript.output = ""; + arg_st.ghostscript.papersize = ""; + arg_st.ghostscript.pageoffset = []; + arg_st.ghostscript.resolution = 150; + arg_st.ghostscript.antialiasing = false; + arg_st.loose = false; + arg_st.lpr_binary = __quote_path__ (__find_binary__ ("lpr")); + arg_st.name = ""; + arg_st.orientation = ""; + arg_st.pstoedit_binary = __quote_path__ (__find_binary__ ("pstoedit")); + arg_st.preview = ""; + arg_st.printer = ""; + arg_st.send_to_printer = false; + arg_st.special_flag = "textnormal"; + arg_st.tight_flag = false; + arg_st.use_color = 0; # 0=default, -1=mono, +1=color + + if (isunix ()) + arg_st.lpr_options = "-l"; + elseif (ispc ()) + arg_st.lpr_options = "-o l"; + else + arg_st.lpr_options = ""; + endif + arg_st.unlink = {}; + + if (nargin > 0 && isfigure (varargin{1})) + arg_st.figure = varargin{1}; + varargin(1) = []; + endif + + for i = 1:numel(varargin) + arg = strtrim (varargin{i}); + if (ischar (arg)) + if (strcmp (arg, "-color")) + arg_st.use_color = 1; + elseif (strcmp (arg, "-append")) + arg_st.append_to_file = true; + elseif (strcmp (arg, "-mono")) + arg_st.use_color = -1; + elseif (strcmp (arg, "-solid")) + arg_st.force_solid = 1; + elseif (strcmp (arg, "-dashed")) + arg_st.force_solid = -1; + elseif (strncmp (arg, "-portrait", numel (arg))) + arg_st.orientation = "portrait"; + elseif (strncmp (arg, "-landscape", numel (arg))) + arg_st.orientation = "landscape"; + elseif (strcmp (arg, "-loose")) + arg_st.loose = true; + arg_st.tight_flag = false; + elseif (strcmp (arg, "-tight")) + arg_st.loose = false; + arg_st.tight_flag = true; + elseif (strcmp (arg, "-textspecial")) + arg_st.special_flag = "textspecial"; + elseif (any (strcmp (arg, {"-interchange", "-metafile", "-pict", "-tiff"}))) + arg_st.preview = arg(2:end); + elseif (strncmp (arg, "-debug", 6)) + arg_st.debug = true; + arg_st.ghostscript.debug = true; + if (length (arg) > 7) + arg_st.debug_file = arg(8:end); + endif + elseif (length (arg) > 2 && arg(1:2) == "-d") + arg_st.devopt = tolower (arg(3:end)); + elseif (length (arg) > 2 && arg(1:2) == "-P") + arg_st.printer = arg; + elseif (strncmp (arg, "-EPSTOOL:", 9)) + arg_st.epstool_binary = arg{10:end}; + elseif (strncmp (arg, "-FIG2DEV:", 9)) + arg_st.fig2dev_binary = arg{10:end}; + elseif (strncmp (arg, "-PSTOEDIT:", 9)) + arg_st.pstoedit_binary = arg{10:end}; + elseif ((length (arg) > 2) && arg(1:2) == "-G") + arg_st.ghostscript.binary = file_in_path (getenv ("PATH"), arg(3:end)); + if (isempty (arg_st.ghostscript.binary)) + error ("print: Ghostscript binary ""%s"" could not be located", + arg(3:end)); + else + arg_st.ghostscript_binary = __quote_path__ (arg_st.ghostscript_binary); + endif + elseif (length (arg) > 2 && arg(1:2) == "-F") + idx = rindex (arg, ":"); + if (idx) + arg_st.font = arg(3:idx-1); + arg_st.fontsize = str2num (arg(idx+1:end)); + else + arg_st.font = arg(3:end); + endif + elseif (length (arg) > 2 && arg(1:2) == "-S") + arg_st.canvas_size = str2num (arg(3:end)); + elseif (length (arg) > 2 && arg(1:2) == "-r") + arg_st.ghostscript.resolution = str2double (arg(3:end)); + elseif (length (arg) > 2 && arg(1:2) == "-f") + arg_st.figure = str2num (arg(3:end)); + elseif (length (arg) >= 1 && arg(1) == "-") + error ("print: unknown option `%s'", arg); + elseif (length (arg) > 0) + arg_st.name = arg; + endif + elseif (isfigure (arg)) + arg_st.figure = arg; + else + error ("print: expecting inputs to be character string options or a figure handle"); + endif + endfor + + if (arg_st.ghostscript.resolution == 0) + ## Do as Matlab does. + arg_st.ghostscript.resolution = num2str (get (0, "screenpixelsperinch")); + endif + + if (isempty (arg_st.orientation)) + if (isfigure (arg_st.figure)) + arg_st.orientation = get (arg_st.figure, "paperorientation"); + else + ## Allows tests to be run without error. + arg_st.orientation = "portrait"; + endif + endif + + if (isempty (arg_st.ghostscript.binary)) + arg_st.ghostscript.binary = __ghostscript_binary__ (); + endif + + dot = rindex (arg_st.name, "."); + if (isempty (arg_st.devopt)) + if (dot == 0) + arg_st.devopt = "psc"; + else + arg_st.devopt = tolower (arg_st.name(dot+1:end)); + endif + endif + + if (arg_st.use_color == 0) + if (any (strcmp ({"ps", "ps2", "eps", "eps2"}, arg_st.devopt))) + arg_st.use_color = -1; + else + arg_st.use_color = 1; + endif + endif + + if (strcmp (arg_st.devopt, "tex")) + arg_st.devopt = "epslatex"; + elseif (strcmp (arg_st.devopt, "ill")) + arg_st.devopt = "aifm"; + elseif (strcmp (arg_st.devopt, "cdr")) + arg_st.devopt = "corel"; + elseif (strcmp (arg_st.devopt, "meta")) + arg_st.devopt = "emf"; + elseif (strcmp (arg_st.devopt, "jpg")) + arg_st.devopt = "jpeg"; + endif + + dev_list = {"aifm", "corel", "fig", "png", "jpeg", ... + "gif", "pbm", "pbmraw", "dxf", "mf", ... + "svg", "hpgl", "ps", "ps2", "psc", ... + "psc2", "eps", "eps2", "epsc", "epsc2", ... + "emf", "pdf", "pslatex", "epslatex", "epslatexstandalone", ... + "pslatexstandalone", "pdflatexstandalone", ... + "pstex", "tiff", "tiffn" "tikz", "pcxmono", ... + "pcx24b", "pcx256", "pcx16", "pgm", "pgmraw", ... + "ppm", "ppmraw", "pdflatex", "texdraw", ... + "pdfcairo", "pngcairo", "pstricks", ... + "epswrite", "pswrite", "ps2write", "pdfwrite"}; + + suffixes = {"ai", "cdr", "fig", "png", "jpg", ... + "gif", "pbm", "pbm", "dxf", "mf", ... + "svg", "hpgl", "ps", "ps", "ps", ... + "ps", "eps", "eps", "eps", "eps", ... + "emf", "pdf", "tex", "tex", "tex", ... + "tex", "tex", ... + "ps", "tiff", "tiff", "tikz", "pcx", ... + "pcx", "pcx", "pcx", "pgm", "pgm", ... + "ppm", "ppm", "tex", "tex", ... + "pdf", "png", "tex", ... + "eps", "ps", "ps", "pdf"}; + + if (isfigure (arg_st.figure)) + __graphics_toolkit__ = get (arg_st.figure, "__graphics_toolkit__"); + else + ## Allow tests when no figures are present. + __graphics_toolkit__ = get (0, "defaultfigure__graphics_toolkit__"); + endif + + if (strcmp (__graphics_toolkit__, "gnuplot") + && __gnuplot_has_feature__ ("epslatex_implies_eps_filesuffix")) + suffixes(strncmp (dev_list, "epslatex", 8)) = {"eps"}; + endif + + match = strcmpi (dev_list, arg_st.devopt); + if (any (match)) + default_suffix = suffixes {match}; + else + default_suffix = arg_st.devopt; + endif + + if (dot == 0 && ! isempty (arg_st.name)) + arg_st.name = strcat (arg_st.name, ".", default_suffix); + endif + + if (arg_st.append_to_file) + if (isempty (arg_st.name)) + arg_st.append_to_file = false; + elseif (any (strcmpi (arg_st.devopt, {"eps", "eps2", "epsc", "epsc2", ... + "ps", "ps2", "psc", "psc2", "pdf"}))) + have_ghostscript = ! isempty (__ghostscript_binary__ ()); + if (have_ghostscript) + file_exists = ((numel (dir (arg_st.name)) == 1) + && (! isdir (arg_st.name))); + if (! file_exists) + arg_st.append_to_file = false; + endif + else + arg_st.append_to_file = false; + warning ("print.m: appended output requires ghostscript to be installed"); + endif + else + warning ("print.m: appended output is not supported for device '%s'", + arg_st.devopt); + arg_st.append_to_file = false; + endif + endif + + if (! isempty (arg_st.printer) || isempty (arg_st.name)) + arg_st.send_to_printer = true; + endif + + if (any (strcmp (arg_st.devopt, {"ps", "ps2", "psc", "psc2", "pdf"}))) + arg_st.formatted_for_printing = true; + endif + + aliases = gs_aliases (); + if (any (strcmp (arg_st.devopt, fieldnames (aliases)))) + arg_st.devopt = aliases.(arg_st.devopt); + endif + + ## FIXME - eps2 & epsc2 needs to be handled + if (strcmp (arg_st.devopt, "pswrite")) + arg_st.ghostscript.level = 1; + elseif (strcmp (arg_st.devopt, "ps2write")) + arg_st.ghostscript.level = 2; + endif + + if ((any (strcmp (arg_st.devopt, gs_device_list)) + && ! arg_st.formatted_for_printing) + || any (strcmp (arg_st.devopt, {"pswrite", "ps2write", "pdfwrite"}))) + ## Use ghostscript for graphic formats + arg_st.ghostscript.device = arg_st.devopt; + arg_st.ghostscript.output = arg_st.name; + arg_st.ghostscript.antialiasing = true; + if (arg_st.formatted_for_printing) + arg_st.ghostscript.epscrop = ! arg_st.loose; + else + ## pstoedit throws errors if the EPS file isn't cropped + arg_st.ghostscript.epscrop = true; + endif + elseif (all (! strcmp (arg_st.devopt, dev_list))) + ## Assume we are formating output for a printer + arg_st.formatted_for_printing = true; + arg_st.ghostscript.device = arg_st.devopt; + arg_st.ghostscript.output = arg_st.name; + arg_st.ghostscript.antialiasing = false; + arg_st.ghostscript.epscrop = ! arg_st.loose; + endif + + if (isempty (arg_st.canvas_size)) + if (isfigure (arg_st.figure)) + [arg_st.ghostscript.papersize, paperposition] = ... + gs_papersize (arg_st.figure, arg_st.orientation); + else + ## allows tests to be run + arg_st.ghostscript.papersize = "letter"; + paperposition = [0.25, 2.50, 8.00, 6.00] * 72; + endif + arg_st.canvas_size = paperposition(3:4); + if (strcmp (__graphics_toolkit__, "gnuplot") && ! arg_st.ghostscript.epscrop) + arg_st.ghostscript.pageoffset = paperposition(1:2) - 50; + else + arg_st.ghostscript.pageoffset = paperposition(1:2); + endif + else + ## Convert canvas size to points from pixles. + arg_st.canvas_size = arg_st.canvas_size * 72 / arg_st.ghostscript.resolution; + arg_st.ghostscript.papersize = arg_st.canvas_size; + arg_st.ghostscript.epscrop = true; + arg_st.ghostscript.pageoffset = [0, 0]; + endif + + if (arg_st.formatted_for_printing) + arg_st.ghostscript.resolution = []; + else + arg_st.ghostscript.papersize = ""; + arg_st.ghostscript.pageoffset = [0, 0]; + endif + + if (warn_on_missing_binary) + if (isempty (arg_st.ghostscript.binary)) + warning ("print:missing_gs", "print.m: Ghostscript binary is not available.\nOnly eps output is available."); + else + if (isempty (arg_st.epstool_binary)) + warning ("print:missing_epstool", "print.m: epstool binary is not available.\nSome output formats are not available."); + endif + if (isempty (arg_st.fig2dev_binary)) + warning ("print:missing_fig2dev", "print.m: fig2dev binary is not available.\nSome output formats are not available."); + endif + if (isempty (arg_st.pstoedit_binary)) + warning ("print:missing_pstoedit", "print.m: pstoedit binary is not available.\nSome output formats are not available."); + endif + endif + warn_on_missing_binary = false; + endif + +endfunction + +## Test blocks are not allowed (and not needed) for private functions +#%!test +%! opts = __print_parse_opts__ (); +%! assert (opts.devopt, "pswrite"); +%! assert (opts.use_color, 1); +%! assert (opts.send_to_printer, true); +%! assert (opts.canvas_size, [576, 432]); +%! assert (opts.ghostscript.device, "pswrite") + +#%!test +%! opts = __print_parse_opts__ ("test.pdf", "-S640,480"); +%! assert (opts.canvas_size, [307.2, 230.4], 0.1); + +#%!test +%! opts = __print_parse_opts__ ("-dpsc", "-append", "-loose"); +%! assert (opts.devopt, "pswrite"); +%! assert (opts.send_to_printer, true); +%! assert (opts.use_color, 1); +%! assert (opts.append_to_file, false); +%! assert (opts.ghostscript.device, "pswrite") +%! assert (opts.ghostscript.epscrop, false); + +#%!test +%! opts = __print_parse_opts__ ("-deps", "-tight"); +%! assert (opts.tight_flag, true); +%! assert (opts.send_to_printer, true); +%! assert (opts.use_color, -1); +%! assert (opts.ghostscript.device, "") + +#%!test +%! opts = __print_parse_opts__ ("-djpg", "foobar", "-mono", "-loose"); +%! assert (opts.devopt, "jpeg") +%! assert (opts.name, "foobar.jpg") +%! assert (opts.ghostscript.device, "jpeg") +%! assert (opts.ghostscript.epscrop, true); +%! assert (opts.ghostscript.papersize, ""); +%! assert (opts.ghostscript.pageoffset, [0, 0]); +%! assert (opts.send_to_printer, false); +%! assert (opts.printer, ""); +%! assert (opts.use_color, -1); + +#%!test +%! opts = __print_parse_opts__ ("-ddeskjet", "foobar", "-mono", "-Pmyprinter"); +%! assert (opts.ghostscript.output, "foobar.deskjet") +%! assert (opts.ghostscript.device, "deskjet") +%! assert (opts.devopt, "deskjet") +%! assert (opts.send_to_printer, true); +%! assert (opts.printer, "-Pmyprinter"); +%! assert (opts.use_color, -1); + +#%!test +%! opts = __print_parse_opts__ ("-f5", "-dljet3"); +%! assert (opts.ghostscript.device, "ljet3") +%! assert (strfind (opts.ghostscript.output, ".ljet3")) +%! assert (opts.devopt, "ljet3") +%! assert (opts.send_to_printer, true); +%! assert (opts.figure, 5) + +function cmd = __quote_path__ (cmd) + if (any (cmd == " ") && ! (cmd(1) == """" && cmd(end) == """")) + cmd = strcat ("""", strrep (cmd, """", """"""), """"); + endif +endfunction + +function gs = __ghostscript_binary__ () + + persistent ghostscript_binary = "" + persistent warn_on_no_ghostscript = true + persistent warn_on_bad_gsc = true + + if (isempty (ghostscript_binary)) + GSC = getenv ("GSC"); + if (exist (GSC, "file") + || (! isempty (GSC) && file_in_path (getenv ("PATH"), GSC))) + gs_binaries = {GSC}; + elseif (! isempty (GSC) && warn_on_bad_gsc) + warning ("print:badgscenv", + "print.m: GSC environment variable not set properly"); + warn_on_bad_gsc = false; + gs_binaries = {}; + else + gs_binaries = {}; + endif + if (isunix ()) + ## Unix - Includes Mac OSX and Cygwin. + gs_binaries = horzcat (gs_binaries, {"gs", "gs.exe"}); + else + ## pc - Includes Win32 and mingw. + gs_binaries = horzcat (gs_binaries, {"gs.exe", "gswin32c.exe"}); + endif + n = 0; + while (n < numel (gs_binaries) && isempty (ghostscript_binary)) + n = n + 1; + ghostscript_binary = file_in_path (getenv ("PATH"), gs_binaries{n}); + endwhile + if (warn_on_no_ghostscript && isempty (ghostscript_binary)) + warning ("print:noghostscript", + "print.m: ghostscript not found in PATH"); + warn_on_no_ghostscript = false; + endif + endif + + gs = ghostscript_binary; + +endfunction + +function bin = __find_binary__ (binary) + + persistent data = struct () + + if (! isfield (data, binary)) + ## Reinitialize when `user_binaries' is present. + data.(binary).bin = ""; + data.(binary).warn_on_absence = false; + endif + + if (isempty (data.(binary).bin)) + if (isunix ()) + ## Unix - Includes Mac OSX and Cygwin. + binaries = strcat (binary, {"", ".exe"}); + else + ## pc - Includes Win32 and mingw. + binaries = strcat (binary, {".exe"}); + endif + n = 0; + while (n < numel (binaries) && isempty (data.(binary).bin)) + n = n + 1; + data.(binary).bin = file_in_path (getenv ("PATH"), binaries{n}); + endwhile + if (isempty (data.(binary).bin) && data.(binary).warn_on_absence) + warning (sprintf ("print:no%s", binary), + "print.m: '%s' not found in PATH", binary); + data.(binary).warn_on_absence = false; + endif + endif + + bin = data.(binary).bin; + +endfunction + +function [papersize, paperposition] = gs_papersize (hfig, paperorientation) + persistent papertypes papersizes + + if (isempty (papertypes)) + papertypes = {"usletter", "uslegal", "a0", "a1", ... + "a2", "a3", "a4", "a5", ... + "b0", "b1", "b2", "b3", ... + "b4", "b5", "arch-a", "arch-b", ... + "arch-c", "arch-d", "arch-e", "a", ... + "b", "c", "d", "e", ... + "tabloid"}; + papersizes = [ 8.5, 11.0; 8.5, 14.0; 33.1, 46.8; 23.4, 33.1; + 16.5, 23.4; 11.7, 16.5; 8.3, 11.7; 5.8, 8.3; + 39.4, 55.7; 27.8, 39.4; 19.7, 27.8; 13.9, 19.7; + 9.8, 13.9; 6.9, 9.8; 9.0, 12.0; 12.0, 18.0; + 18.0, 24.0; 24.0, 36.0; 36.0, 48.0; 8.5, 11.0; + 11.0, 17.0; 18.0, 24.0; 24.0, 36.0; 36.0, 48.0; + 11.0, 17.0] * 72; + endif + + papertype = get (hfig, "papertype"); + paperunits = get (hfig, "paperunits"); + paperposition = get (hfig, "paperposition"); + if (strcmp (papertype, "")) + papersize = get (hfig, "papersize"); + papersize = convert2points (papersize , paperunits); + else + papersize = papersizes (strcmp (papertypes, papertype), :); + endif + + if (strcmp (paperunits, "normalized")) + paperposition = paperposition .* papersize([1,2,1,2]); + else + paperposition = convert2points (paperposition, paperunits); + endif + + ## FIXME - This will be obsoleted by listeners for paper properties. + ## Papersize is tall when portrait,and wide when landscape. + if ((papersize(1) > papersize(2) && strcmpi (paperorientation, "portrait")) + || (papersize(1) < papersize(2) && strcmpi (paperorientation, "landscape"))) + papersize = papersize ([2,1]); + paperposition = paperposition([2,1,4,3]); + endif + + if ((! strcmp (papertype, "")) && (strcmp (paperorientation, "portrait"))) + ## For portrait use the ghostscript name + papersize = papertype; + papersize(papersize=="-") = ""; + papersize = strrep (papersize, "us", ""); + switch (papersize) + case "a" + papersize = "letter"; + case {"b", "tabloid"} + papersize = "11x17"; + case {"c", "d", "e"} + papersize = strcat ("arch", papersize); + endswitch + if (strncmp (papersize, "arch", 4)) + papersize(end) = upper (papersize(end)); + endif + endif + +endfunction + +function value = convert2points (value, units) + switch (units) + case "inches" + value = value * 72; + case "centimeters" + value = value * 72 / 25.4; + case "normalized" + error ("print:customnormalized", + "print.m: papersize=='' and paperunits='normalized' may not be combined"); + endswitch +endfunction + +function device_list = gs_device_list (); + ## Graphics formats/languages, not priners. + device_list = {"bmp16"; "bmp16m"; "bmp256"; "bmp32b"; "bmpgray"; ... + "epswrite"; "jpeg"; "jpegcymk"; "jpeggray"; "pbm"; ... + "pbmraw"; "pcx16"; "pcx24b"; "pcx256"; "pcx2up"; ... + "pcxcmyk"; "pcxgray"; "pcxmono"; "pdfwrite"; "pgm"; ... + "pgmraw"; "pgnm"; "pgnmraw"; "png16"; "png16m"; ... + "png256"; "png48"; "pngalpha"; "pnggray"; "pngmono"; ... + "pnm"; "pnmraw"; "ppm"; "ppmraw"; "ps2write"; ... + "pswrite"; "tiff12nc"; "tiff24nc"; "tiff32nc"; ... + "tiffcrle"; "tiffg3"; "tiffg32d"; "tiffg4"; ... + "tiffgray"; "tifflzw"; "tiffpack"; "tiffsep"}; +endfunction + +function aliases = gs_aliases (); + ## Aliases for other devices: "bmp", "png", "tiff", "tiffn", "pdf", + ## "ps", "ps2", "psc", "psc2" + ## + ## eps, epsc, eps2, epsc2 are not included here because those are + ## are generated by the graphics toolkit. + aliases.bmp = "bmp32b"; + aliases.pdf = "pdfwrite"; + aliases.png = "png16m"; + aliases.ps = "pswrite"; + aliases.ps2 = "ps2write"; + aliases.psc = "pswrite"; + aliases.psc2 = "ps2write"; + aliases.tiff = "tiff24nc"; + aliases.tiffn = "tiff24nc"; +endfunction +