Mercurial > octave-nkf
annotate doc/interpreter/geometryimages.m @ 9914:e76d8c767584
Switch to color output for PostScript documentation images
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Fri, 04 Dec 2009 10:44:58 -0800 |
parents | e9fe12c1b0c0 |
children | c5e9931c7ba7 |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2007, 2008 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 | |
6832 | 19 function geometryimages (nm, typ) |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
20 set_print_size (); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
21 hide_output (); |
7257 | 22 if (strcmp (typ, "png")) |
23 set (0, "defaulttextfontname", "*"); | |
24 endif | |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
25 if (strcmp (typ, "eps")) |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
26 d_typ = "-depsc2"; |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
27 else |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
28 d_typ = cstrcat ("-d", typ); |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
29 endif |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
30 |
6878 | 31 if (isempty (findstr (octave_config_info ("DEFS"), "HAVE_QHULL")) |
32 && (strcmp (nm, "voronoi") || strcmp (nm, "griddata") | |
33 || strcmp (nm, "convhull") || strcmp (nm, "delaunay") | |
34 || strcmp (nm, "triplot"))) | |
6855 | 35 sombreroimage (nm, typ); |
7262 | 36 elseif (strcmp (typ, "txt")) |
37 image_as_txt (nm); | |
6855 | 38 elseif (strcmp (nm, "voronoi")) |
6832 | 39 rand("state",9); |
40 x = rand(10,1); | |
41 y = rand(10,1); | |
42 tri = delaunay (x, y); | |
43 [vx, vy] = voronoi (x, y, tri); | |
44 triplot (tri, x, y, "b"); | |
45 hold on; | |
46 plot (vx, vy, "r"); | |
47 [r, c] = tri2circ (tri(end,:), x, y); | |
48 pc = [-1:0.01:1]; | |
49 xc = r * sin(pi*pc) + c(1); | |
50 yc = r * cos(pi*pc) + c(2); | |
51 plot (xc, yc, "g-", "LineWidth", 3); | |
52 axis([0, 1, 0, 1]); | |
53 legend ("Delaunay Triangulation", "Voronoi Diagram"); | |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
54 print (cstrcat (nm, ".", typ), d_typ) |
6832 | 55 elseif (strcmp (nm, "triplot")) |
56 rand ("state", 2) | |
57 x = rand (20, 1); | |
58 y = rand (20, 1); | |
59 tri = delaunay (x, y); | |
60 triplot (tri, x, y); | |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
61 print (cstrcat (nm, ".", typ), d_typ) |
6832 | 62 elseif (strcmp (nm, "griddata")) |
63 rand("state",1); | |
64 x=2*rand(1000,1)-1; | |
65 y=2*rand(size(x))-1; | |
66 z=sin(2*(x.^2+y.^2)); | |
67 [xx,yy]=meshgrid(linspace(-1,1,32)); | |
68 griddata(x,y,z,xx,yy); | |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
69 print (cstrcat (nm, ".", typ), d_typ) |
6832 | 70 elseif (strcmp (nm, "convhull")) |
71 x = -3:0.05:3; | |
72 y = abs (sin (x)); | |
73 k = convhull (x, y); | |
74 plot (x(k),y(k),'r-',x,y,'b+'); | |
75 axis ([-3.05, 3.05, -0.05, 1.05]); | |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
76 print (cstrcat (nm, ".", typ), d_typ) |
6832 | 77 elseif (strcmp (nm, "delaunay")) |
78 rand ("state", 1); | |
6847 | 79 x = rand (1, 10); |
80 y = rand (1, 10); | |
6832 | 81 T = delaunay (x, y); |
82 X = [ x(T(:,1)); x(T(:,2)); x(T(:,3)); x(T(:,1)) ]; | |
83 Y = [ y(T(:,1)); y(T(:,2)); y(T(:,3)); y(T(:,1)) ]; | |
84 axis ([0, 1, 0, 1]); | |
85 plot(X, Y, "b", x, y, "r*"); | |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
86 print (cstrcat (nm, ".", typ), d_typ) |
6847 | 87 elseif (strcmp (nm, "inpolygon")) |
88 randn ("state", 2); | |
89 x = randn (100, 1); | |
90 y = randn (100, 1); | |
91 vx = cos (pi * [-1 : 0.1: 1]); | |
92 vy = sin (pi * [-1 : 0.1 : 1]); | |
93 in = inpolygon (x, y, vx, vy); | |
94 plot(vx, vy, x(in), y(in), "r+", x(!in), y(!in), "bo"); | |
95 axis ([-2, 2, -2, 2]); | |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
96 print (cstrcat (nm, ".", typ), d_typ) |
6832 | 97 else |
98 error ("unrecognized plot requested"); | |
99 endif | |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
100 hide_output (); |
6832 | 101 endfunction |
102 | |
103 function [r, c] = tri2circ (tri, xx, yy) | |
104 x = xx(tri); | |
105 y = yy(tri); | |
106 m = (y(1:end-1) - y(2:end)) ./ (x(1:end-1) - x(2:end)); | |
107 xc = (prod(m) .* (y(1) - y(end)) + m(end)*(x(1)+x(2)) - m(1)*(x(2)+x(3))) ... | |
108 ./ (2 * (m(end) - m(1))); | |
109 yc = - (xc - (x(2) + x(3))./2) ./ m(end) + (y(2) + y(3)) / 2; | |
110 c = [xc, yc]; | |
111 r = sqrt ((xc - x(1)).^2 + (yc - y(1)).^2); | |
112 endfunction | |
113 | |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
114 function set_print_size () |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
115 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
|
116 border = 0; # For postscript use 50/72 |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
117 set (0, "defaultfigurepapertype", "<custom>"); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
118 set (0, "defaultfigurepaperorientation", "landscape"); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
119 set (0, "defaultfigurepapersize", image_size + 2*border); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
120 set (0, "defaultfigurepaperposition", [border, border, image_size]); |
6832 | 121 endfunction |
122 | |
123 ## Use this function before plotting commands and after every call to | |
124 ## print since print() resets output to stdout (unfortunately, gnpulot | |
125 ## can't pop 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
|
126 function hide_output () |
6832 | 127 f = figure (1); |
128 set (f, "visible", "off"); | |
129 endfunction | |
6855 | 130 |
131 function sombreroimage (nm, typ) | |
132 if (strcmp (typ, "txt")) | |
133 fid = fopen (sprintf ("%s.txt", nm), "wt"); | |
134 fputs (fid, "+-----------------------------+\n"); | |
135 fputs (fid, "| Image unavailable because |\n"); | |
136 fputs (fid, "| of a missing QHULL library. |\n"); | |
137 fputs (fid, "+-----------------------------+\n"); | |
138 fclose (fid); | |
139 return; | |
140 else ## if (!strcmp (typ, "txt")) | |
141 | |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
142 hide_output (); |
6855 | 143 |
144 x = y = linspace (-8, 8, 41)'; | |
145 [xx, yy] = meshgrid (x, y); | |
146 r = sqrt (xx .^ 2 + yy .^ 2) + eps; | |
147 z = sin (r) ./ r; | |
148 unwind_protect | |
149 mesh (x, y, z); | |
150 title ("Sorry, graphics not available because octave was\\ncompiled without the QHULL library."); | |
151 unwind_protect_cleanup | |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
152 print (cstrcat (nm, ".", typ), d_typ); |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
153 hide_output (); |
6855 | 154 end_unwind_protect |
155 endif | |
156 endfunction | |
7262 | 157 |
158 ## generate something for the texinfo @image command to process | |
159 function image_as_txt(nm) | |
160 fid = fopen (sprintf ("%s.txt", nm), "wt"); | |
161 fputs (fid, "\n"); | |
162 fputs (fid, "+---------------------------------+\n"); | |
163 fputs (fid, "| Image unavailable in text mode. |\n"); | |
164 fputs (fid, "+---------------------------------+\n"); | |
165 fclose (fid); | |
166 endfunction |