Mercurial > octave-nkf
annotate doc/interpreter/geometryimages.m @ 20370:b439ccc9a162
doc: Improve building of images for the Manual.
Switch to using 'qt' as the default toolkit.
Stop producing onscreen flicker when building images.
Correctly build extended.pdf with new non-recursive build system.
* plot.txi: Change sample code for generation of image 15.7 to match the code
in plotimages.m
* geometryimages.m, sparseimages.m, interpimages.m, splineimages.m:
Call new function set_graphics_toolkit which makes sure there is at least
something available to do plotting with. Change hide_output() function
to call figure() directly with "visible", "off" properties passed to it
so there is never a moment when the figure is visible (stops flicker).
* plotimages.m: Change directory to working directory where documentation files
are kept before executing print with "-pdflatexstandalone". Call pdflatex
from within the working directory since that is what it expects. Clean up
after pdflatex by deleting auxiliary files. Capture status and output of
system command which invokes pdflatex so that it does not spew in to the
logs. Change text() command to use '\displaystyle' which looks nicer.
Add set_graphics_toolkit function and modify hide_output function as above.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 12 Jul 2015 15:00:26 -0700 |
parents | d8992a16643c |
children |
rev | line source |
---|---|
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19627
diff
changeset
|
1 ## Copyright (C) 2007-2015 David Bateman |
7018 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20250
diff
changeset
|
19 function geometryimages (d, nm, typ) |
20370
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20351
diff
changeset
|
20 set_graphics_toolkit (); |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
21 set_print_size (); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
22 hide_output (); |
20351
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
23 outfile = fullfile (d, [nm "." typ]); |
7257 | 24 if (strcmp (typ, "png")) |
25 set (0, "defaulttextfontname", "*"); | |
26 endif | |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
27 if (strcmp (typ, "eps")) |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
28 d_typ = "-depsc2"; |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
29 else |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
30 d_typ = ["-d" typ]; |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
31 endif |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
32 |
16170
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
33 if (! __have_feature__ ("QHULL") |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
34 && any (strcmp (nm, {"voronoi", "griddata", "convhull", "delaunay", ... |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
35 "triplot"}))) |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
36 sombreroimage (nm, typ, d_typ); |
7262 | 37 elseif (strcmp (typ, "txt")) |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20250
diff
changeset
|
38 image_as_txt (d, nm); |
6855 | 39 elseif (strcmp (nm, "voronoi")) |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
40 rand ("state", 9); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
41 x = rand (10, 1); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
42 y = rand (10, 1); |
6832 | 43 tri = delaunay (x, y); |
44 [vx, vy] = voronoi (x, y, tri); | |
45 triplot (tri, x, y, "b"); | |
46 hold on; | |
47 plot (vx, vy, "r"); | |
48 [r, c] = tri2circ (tri(end,:), x, y); | |
49 pc = [-1:0.01:1]; | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
50 xc = r * sin (pi*pc) + c(1); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
51 yc = r * cos (pi*pc) + c(2); |
6832 | 52 plot (xc, yc, "g-", "LineWidth", 3); |
20351
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
53 axis ([0, 1, 0, 1]); |
6832 | 54 legend ("Delaunay Triangulation", "Voronoi Diagram"); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20250
diff
changeset
|
55 print (outfile, d_typ); |
6832 | 56 elseif (strcmp (nm, "triplot")) |
57 rand ("state", 2) | |
58 x = rand (20, 1); | |
59 y = rand (20, 1); | |
60 tri = delaunay (x, y); | |
61 triplot (tri, x, y); | |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20250
diff
changeset
|
62 print (outfile, d_typ); |
6832 | 63 elseif (strcmp (nm, "griddata")) |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
64 rand ("state", 1); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
65 x = 2 * rand (1000,1) - 1; |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
66 y = 2 * rand (size (x)) - 1; |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
67 z = sin (2 * (x.^2 + y.^2)); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
68 [xx,yy] = meshgrid (linspace (-1,1,32)); |
20250
4e15a4c331e7
doc: Fix griddata example to new calling convention
Mike Miller <mtmiller@octave.org>
parents:
19751
diff
changeset
|
69 zz = griddata (x, y, z, xx, yy); |
4e15a4c331e7
doc: Fix griddata example to new calling convention
Mike Miller <mtmiller@octave.org>
parents:
19751
diff
changeset
|
70 mesh (xx, yy, zz); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20250
diff
changeset
|
71 print (outfile, d_typ); |
6832 | 72 elseif (strcmp (nm, "convhull")) |
73 x = -3:0.05:3; | |
74 y = abs (sin (x)); | |
75 k = convhull (x, y); | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
76 plot (x(k),y(k),'r-', x,y,'b+'); |
6832 | 77 axis ([-3.05, 3.05, -0.05, 1.05]); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20250
diff
changeset
|
78 print (outfile, d_typ); |
6832 | 79 elseif (strcmp (nm, "delaunay")) |
80 rand ("state", 1); | |
6847 | 81 x = rand (1, 10); |
82 y = rand (1, 10); | |
6832 | 83 T = delaunay (x, y); |
84 X = [ x(T(:,1)); x(T(:,2)); x(T(:,3)); x(T(:,1)) ]; | |
85 Y = [ y(T(:,1)); y(T(:,2)); y(T(:,3)); y(T(:,1)) ]; | |
86 axis ([0, 1, 0, 1]); | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
87 plot (X,Y,"b", x,y,"r*"); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20250
diff
changeset
|
88 print (outfile, d_typ); |
6847 | 89 elseif (strcmp (nm, "inpolygon")) |
90 randn ("state", 2); | |
91 x = randn (100, 1); | |
92 y = randn (100, 1); | |
93 vx = cos (pi * [-1 : 0.1: 1]); | |
94 vy = sin (pi * [-1 : 0.1 : 1]); | |
95 in = inpolygon (x, y, vx, vy); | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
96 plot (vx, vy, x(in), y(in), "r+", x(!in), y(!in), "bo"); |
6847 | 97 axis ([-2, 2, -2, 2]); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20250
diff
changeset
|
98 print (outfile, d_typ); |
6832 | 99 else |
100 error ("unrecognized plot requested"); | |
101 endif | |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
102 hide_output (); |
6832 | 103 endfunction |
104 | |
105 function [r, c] = tri2circ (tri, xx, yy) | |
106 x = xx(tri); | |
107 y = yy(tri); | |
108 m = (y(1:end-1) - y(2:end)) ./ (x(1:end-1) - x(2:end)); | |
109 xc = (prod(m) .* (y(1) - y(end)) + m(end)*(x(1)+x(2)) - m(1)*(x(2)+x(3))) ... | |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
110 ./ (2 * (m(end) - m(1))); |
6832 | 111 yc = - (xc - (x(2) + x(3))./2) ./ m(end) + (y(2) + y(3)) / 2; |
112 c = [xc, yc]; | |
113 r = sqrt ((xc - x(1)).^2 + (yc - y(1)).^2); | |
114 endfunction | |
115 | |
20351
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
116 function sombreroimage (nm, typ, d_typ) |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
117 if (strcmp (typ, "txt")) |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
118 fid = fopen ([nm ".txt"], "wt"); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
119 fputs (fid, "+-----------------------------+\n"); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
120 fputs (fid, "| Image unavailable because |\n"); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
121 fputs (fid, "| of a missing QHULL library. |\n"); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
122 fputs (fid, "+-----------------------------+\n"); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
123 fclose (fid); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
124 return; |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
125 else |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
126 hide_output (); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
127 [x, y, z] = sombrero (); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
128 unwind_protect |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
129 mesh (x, y, z); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
130 title ("Sorry, graphics not available because Octave was\\ncompiled without the QHULL library."); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
131 unwind_protect_cleanup |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
132 print (outfile, d_typ); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
133 hide_output (); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
134 end_unwind_protect |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
135 endif |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
136 endfunction |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
137 |
20370
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20351
diff
changeset
|
138 ## This function no longer sets the graphics toolkit; That is now done |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20351
diff
changeset
|
139 ## automatically by C++ code which will ordinarily choose 'qt', but might |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20351
diff
changeset
|
140 ## choose gnuplot on older systems. Only a complete lack of plotting is a |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20351
diff
changeset
|
141 ## problem. |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20351
diff
changeset
|
142 function set_graphics_toolkit () |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20351
diff
changeset
|
143 if (isempty (available_graphics_toolkits ())) |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20351
diff
changeset
|
144 error ("no graphics toolkit available for plotting"); |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20351
diff
changeset
|
145 endif |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20351
diff
changeset
|
146 endfunction |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20351
diff
changeset
|
147 |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
148 function set_print_size () |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
149 image_size = [5.0, 3.5]; # in inches, 16:9 format |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
150 border = 0; # For postscript use 50/72 |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
151 set (0, "defaultfigurepapertype", "<custom>"); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
152 set (0, "defaultfigurepaperorientation", "landscape"); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
153 set (0, "defaultfigurepapersize", image_size + 2*border); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
154 set (0, "defaultfigurepaperposition", [border, border, image_size]); |
6832 | 155 endfunction |
156 | |
20370
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20351
diff
changeset
|
157 ## Use this function before plotting commands and after every call to print |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20351
diff
changeset
|
158 ## since print() resets output to stdout (unfortunately, gnuplot can't pop |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20351
diff
changeset
|
159 ## output as it can the terminal type). |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
160 function hide_output () |
20370
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20351
diff
changeset
|
161 hf = figure (1, "visible", "off"); |
6855 | 162 endfunction |
7262 | 163 |
164 ## generate something for the texinfo @image command to process | |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20250
diff
changeset
|
165 function image_as_txt (d, nm) |
20351
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
166 fid = fopen (fullfile (d, [nm ".txt"]), "wt"); |
7262 | 167 fputs (fid, "\n"); |
168 fputs (fid, "+---------------------------------+\n"); | |
169 fputs (fid, "| Image unavailable in text mode. |\n"); | |
170 fputs (fid, "+---------------------------------+\n"); | |
171 fclose (fid); | |
172 endfunction | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
173 |