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 |
6925
|
54 if (have_x && nargin > iarg) |
|
55 if (isnumeric (varargin{iarg})) |
|
56 c = varargin{iarg}; |
|
57 have_c = true; |
|
58 iarg++; |
6885
|
59 |
6925
|
60 if (ndims (c) == 3 && size (c, 2) == 1) |
|
61 c = permute (c, [1, 3, 2]); |
|
62 endif |
|
63 elseif (ischar (varargin{iarg}) && rem (nargin - iarg, 2) != 0) |
|
64 ## Assume that any additional argument over an even number is color string |
|
65 c = tolower (varargin{iarg}); |
|
66 have_c = true; |
|
67 iarg++; |
6885
|
68 endif |
|
69 endif |
|
70 |
|
71 if (rem (nargin - iarg, 2) != 0) |
6807
|
72 print_usage (); |
|
73 endif |
|
74 |
6885
|
75 if (have_x) |
|
76 if (isvector (x)) |
|
77 x = x(:); |
|
78 y = y(:); |
|
79 if (have_z) |
|
80 z = z(:); |
|
81 endif |
|
82 endif |
6807
|
83 |
6885
|
84 [nr, nc] = size (x); |
6807
|
85 |
6885
|
86 for i = 1 : nc |
|
87 h = __go_patch__ (p); |
|
88 ax = get (h, "parent"); |
|
89 if (have_x) |
|
90 set (h, "xdata", x (:, i), "ydata", y (:, i)); |
|
91 if (have_z) |
|
92 set (h, "zdata", z (:, i)); |
|
93 endif |
|
94 endif |
6807
|
95 |
6885
|
96 if (have_c) |
6886
|
97 if (ndims (c) == 2 && ((nr > 3 && size (c, 2) == nc) |
|
98 || (size (c, 1) > 1 && size (c, 2) == nc))) |
6885
|
99 c2 = c (:, i); |
|
100 elseif (ndims (c) == 3) |
6886
|
101 c2 = permute (c(:,i,:), [1, 3, 2]); |
6885
|
102 else |
|
103 c2 = c; |
|
104 endif |
6807
|
105 |
6925
|
106 if (ischar (c2)) |
|
107 set (h, "facecolor", c2); |
|
108 elseif (numel (c2) == 1) |
6885
|
109 if (isnan (c)) |
6886
|
110 set (h, "facecolor", [1, 1, 1]); |
|
111 set (h, "cdata", c2); |
6885
|
112 elseif (isnumeric (c2)) |
|
113 ## Have color index. |
6886
|
114 set (h, "facecolor", "flat"); |
|
115 set (h, "cdata", c2); |
|
116 clim = get(ax, "clim"); |
6885
|
117 if (c2 < clim(1)) |
6886
|
118 set (ax, "clim", [c2, clim(2)]) |
6885
|
119 endif |
|
120 if (c2 > clim(2)) |
6886
|
121 set (ax, "clim", [clim(1), c2]) |
6885
|
122 endif |
|
123 else |
|
124 ## Unknown color value. |
6886
|
125 error ("patch: color value not valid"); |
6885
|
126 endif |
|
127 elseif (numel (c2) == 3) |
|
128 ## Have rgb/rgba value. |
6886
|
129 set (h, "facecolor", c2); |
6885
|
130 else |
|
131 ## Color vector. |
|
132 if (length (c2) != length (x) || length (c2) != length (y)) |
6886
|
133 error ("patch: size of x, y, and c must be equal") |
6885
|
134 else |
6886
|
135 set (h, "facecolor", "interp"); |
|
136 set(h, "cdata", c2); |
6885
|
137 if (abs(max(c2) - min(c2)) < eps) |
6886
|
138 set (ax, "clim", [c2(1)-1, c2(1)+1]) |
6885
|
139 else |
6886
|
140 set (ax, "clim", [min(c2), max(c2)]); |
6885
|
141 endif |
|
142 endif |
|
143 endif |
|
144 else |
6886
|
145 set (h, "facecolor", [0, 1, 0]); |
6807
|
146 endif |
|
147 |
6885
|
148 if (nargin > iarg + 1) |
|
149 set (h, varargin{iarg:end}); |
|
150 endif |
|
151 endfor |
6807
|
152 else |
6886
|
153 error ("patch: not supported"); |
6807
|
154 endif |
6886
|
155 |
6807
|
156 endfunction |