6807
|
1 ## Copyright (C) 2007 John W. Eaton, Shai Ayal, Kai Habel |
|
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 2, or (at your option) |
|
8 ## 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, write to the Free |
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
|
19 |
6895
|
20 ## Undocumented internal function. |
|
21 |
|
22 ## __patch__ (p, x, y, c) |
|
23 ## Create patch object from x and y with color c and parent p. |
6807
|
24 ## Return handle to patch object. |
|
25 |
|
26 ## Author: Kai Habel |
|
27 |
|
28 function h = __patch__ (p, varargin) |
|
29 |
6885
|
30 if (nargin < 3) |
|
31 print_usage (); |
|
32 endif |
|
33 |
|
34 iarg = 1; |
|
35 have_x = have_z = have_c = false; |
6886
|
36 if (isnumeric (varargin{1})) |
|
37 if (! isnumeric (varargin{2})) |
6885
|
38 print_usage (); |
|
39 endif |
|
40 |
6886
|
41 x = varargin{1}; |
|
42 y = varargin{2}; |
6885
|
43 have_x = true; |
|
44 iarg += 2; |
|
45 |
6886
|
46 if (nargin > 3 && ndims (varargin{3}) == 2 && ndims (x) == 2 |
|
47 && size (varargin{3}) == size (x)) |
6885
|
48 z = varargin {3}; |
|
49 have_z = true; |
6886
|
50 iarg++; |
6885
|
51 endif |
|
52 endif |
|
53 |
6886
|
54 if (have_x && nargin > iarg && isnumeric (varargin{iarg})) |
|
55 c = varargin{iarg}; |
6885
|
56 have_c = true; |
6886
|
57 iarg++; |
6885
|
58 |
|
59 if (ndims (c) == 3 && size (c, 2) == 1) |
|
60 c = permute (c, [1, 3, 2]); |
|
61 endif |
|
62 endif |
|
63 |
|
64 if (rem (nargin - iarg, 2) != 0) |
6807
|
65 print_usage (); |
|
66 endif |
|
67 |
6885
|
68 if (have_x) |
|
69 if (isvector (x)) |
|
70 x = x(:); |
|
71 y = y(:); |
|
72 if (have_z) |
|
73 z = z(:); |
|
74 endif |
|
75 endif |
6807
|
76 |
6885
|
77 [nr, nc] = size (x); |
6807
|
78 |
6885
|
79 for i = 1 : nc |
|
80 h = __go_patch__ (p); |
|
81 ax = get (h, "parent"); |
|
82 if (have_x) |
|
83 set (h, "xdata", x (:, i), "ydata", y (:, i)); |
|
84 if (have_z) |
|
85 set (h, "zdata", z (:, i)); |
|
86 endif |
|
87 endif |
6807
|
88 |
6885
|
89 if (have_c) |
6886
|
90 if (ndims (c) == 2 && ((nr > 3 && size (c, 2) == nc) |
|
91 || (size (c, 1) > 1 && size (c, 2) == nc))) |
6885
|
92 c2 = c (:, i); |
|
93 elseif (ndims (c) == 3) |
6886
|
94 c2 = permute (c(:,i,:), [1, 3, 2]); |
6885
|
95 else |
|
96 c2 = c; |
|
97 endif |
6807
|
98 |
6885
|
99 if (numel (c2) == 1) |
|
100 if (isnan (c)) |
6886
|
101 set (h, "facecolor", [1, 1, 1]); |
|
102 set (h, "cdata", c2); |
6885
|
103 elseif (isnumeric (c2)) |
|
104 ## Have color index. |
6886
|
105 set (h, "facecolor", "flat"); |
|
106 set (h, "cdata", c2); |
|
107 clim = get(ax, "clim"); |
6885
|
108 if (c2 < clim(1)) |
6886
|
109 set (ax, "clim", [c2, clim(2)]) |
6885
|
110 endif |
|
111 if (c2 > clim(2)) |
6886
|
112 set (ax, "clim", [clim(1), c2]) |
6885
|
113 endif |
|
114 else |
|
115 ## Unknown color value. |
6886
|
116 error ("patch: color value not valid"); |
6885
|
117 endif |
|
118 elseif (numel (c2) == 3) |
|
119 ## Have rgb/rgba value. |
6886
|
120 set (h, "facecolor", c2); |
6885
|
121 else |
|
122 ## Color vector. |
|
123 if (length (c2) != length (x) || length (c2) != length (y)) |
6886
|
124 error ("patch: size of x, y, and c must be equal") |
6885
|
125 else |
6886
|
126 set (h, "facecolor", "interp"); |
|
127 set(h, "cdata", c2); |
6885
|
128 if (abs(max(c2) - min(c2)) < eps) |
6886
|
129 set (ax, "clim", [c2(1)-1, c2(1)+1]) |
6885
|
130 else |
6886
|
131 set (ax, "clim", [min(c2), max(c2)]); |
6885
|
132 endif |
|
133 endif |
|
134 endif |
|
135 else |
6886
|
136 set (h, "facecolor", [0, 1, 0]); |
6807
|
137 endif |
|
138 |
6885
|
139 if (nargin > iarg + 1) |
|
140 set (h, varargin{iarg:end}); |
|
141 endif |
|
142 endfor |
6807
|
143 else |
6886
|
144 error ("patch: not supported"); |
6807
|
145 endif |
6886
|
146 |
6807
|
147 endfunction |