Mercurial > octave
annotate doc/interpreter/geometryimages.m @ 21226:a55b8ece1ecd
reorganize octave_config_info again
* build-env-features.sh: Don't include ENABLE_ items in the output.
* toplev.cc (find_config_info): New static function.
(Foctave_config_info): Put Octave configuration info in the main
struct. Put the build system features and build environment info in
substructures. Allow searching of all elements by keyword.
* __have_feature__.m, doc/interpreter/testfun.txi:
Fix name of build features substructure element.
* geometryimages.m, interpimages.m, plotimages.m, sparseimages.m,
splineimages.m: Use __have_feature__ to check for OSMESA.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 08 Feb 2016 23:14:56 -0500 |
parents | e5f78891ad9e |
children | 6267807eb70b |
rev | line source |
---|---|
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19593
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 | |
20307
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20215
diff
changeset
|
19 function geometryimages (d, nm, typ) |
20335
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
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 (); |
20316
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20307
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"}))) |
20776
38968777601b
Open files when generating docs without sparse or QHULL libraries.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20335
diff
changeset
|
36 sombreroimage (outfile, typ, d_typ); |
7262 | 37 elseif (strcmp (typ, "txt")) |
20307
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20215
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); |
20316
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
53 axis ([0, 1, 0, 1]); |
6832 | 54 legend ("Delaunay Triangulation", "Voronoi Diagram"); |
20307
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20215
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); | |
20307
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20215
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)); |
20215
4e15a4c331e7
doc: Fix griddata example to new calling convention
Mike Miller <mtmiller@octave.org>
parents:
19717
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:
19717
diff
changeset
|
70 mesh (xx, yy, zz); |
20307
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20215
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]); |
20307
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20215
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*"); |
20307
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20215
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]); |
20307
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20215
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))) ... | |
19593
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 | |
20776
38968777601b
Open files when generating docs without sparse or QHULL libraries.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20335
diff
changeset
|
116 function sombreroimage (outfile, typ, d_typ) |
20316
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
117 if (strcmp (typ, "txt")) |
20776
38968777601b
Open files when generating docs without sparse or QHULL libraries.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20335
diff
changeset
|
118 fid = fopen (outfile, "wt"); |
20316
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
119 fputs (fid, "+-----------------------------+\n"); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20307
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:
20307
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:
20307
diff
changeset
|
122 fputs (fid, "+-----------------------------+\n"); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
123 fclose (fid); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
124 return; |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
125 else |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
126 [x, y, z] = sombrero (); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
127 unwind_protect |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
128 mesh (x, y, z); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
129 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:
20307
diff
changeset
|
130 unwind_protect_cleanup |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
131 print (outfile, d_typ); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
132 hide_output (); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
133 end_unwind_protect |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
134 endif |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
135 endfunction |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
136 |
20335
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
137 ## 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:
20316
diff
changeset
|
138 ## 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:
20316
diff
changeset
|
139 ## 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:
20316
diff
changeset
|
140 ## problem. |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
141 function set_graphics_toolkit () |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
142 if (isempty (available_graphics_toolkits ())) |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
143 error ("no graphics toolkit available for plotting"); |
20885
e5f78891ad9e
Allow doc's images to be generated using gnuplot when osmesa isn't available.
Ben Abbott <bpabbott@mac.com>
parents:
20779
diff
changeset
|
144 elseif (! strcmp ("gnuplot", graphics_toolkit ()) ... |
21226
a55b8ece1ecd
reorganize octave_config_info again
John W. Eaton <jwe@octave.org>
parents:
20885
diff
changeset
|
145 && ! __have_feature__ ("OSMESA")) |
20885
e5f78891ad9e
Allow doc's images to be generated using gnuplot when osmesa isn't available.
Ben Abbott <bpabbott@mac.com>
parents:
20779
diff
changeset
|
146 if (! any (strcmp ("gnuplot", available_graphics_toolkits ()))) |
e5f78891ad9e
Allow doc's images to be generated using gnuplot when osmesa isn't available.
Ben Abbott <bpabbott@mac.com>
parents:
20779
diff
changeset
|
147 error ("no graphics toolkit available for offscreen plotting"); |
e5f78891ad9e
Allow doc's images to be generated using gnuplot when osmesa isn't available.
Ben Abbott <bpabbott@mac.com>
parents:
20779
diff
changeset
|
148 else |
e5f78891ad9e
Allow doc's images to be generated using gnuplot when osmesa isn't available.
Ben Abbott <bpabbott@mac.com>
parents:
20779
diff
changeset
|
149 graphics_toolkit ("gnuplot"); |
e5f78891ad9e
Allow doc's images to be generated using gnuplot when osmesa isn't available.
Ben Abbott <bpabbott@mac.com>
parents:
20779
diff
changeset
|
150 endif |
20335
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
151 endif |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
152 endfunction |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
153 |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
154 function set_print_size () |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
155 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
|
156 border = 0; # For postscript use 50/72 |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
157 set (0, "defaultfigurepapertype", "<custom>"); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
158 set (0, "defaultfigurepaperorientation", "landscape"); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
159 set (0, "defaultfigurepapersize", image_size + 2*border); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
160 set (0, "defaultfigurepaperposition", [border, border, image_size]); |
6832 | 161 endfunction |
162 | |
20335
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
163 ## 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:
20316
diff
changeset
|
164 ## 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:
20316
diff
changeset
|
165 ## 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
|
166 function hide_output () |
20335
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
167 hf = figure (1, "visible", "off"); |
6855 | 168 endfunction |
7262 | 169 |
170 ## generate something for the texinfo @image command to process | |
20307
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20215
diff
changeset
|
171 function image_as_txt (d, nm) |
20316
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
172 fid = fopen (fullfile (d, [nm ".txt"]), "wt"); |
7262 | 173 fputs (fid, "\n"); |
174 fputs (fid, "+---------------------------------+\n"); | |
175 fputs (fid, "| Image unavailable in text mode. |\n"); | |
176 fputs (fid, "+---------------------------------+\n"); | |
177 fclose (fid); | |
178 endfunction | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
179 |