Mercurial > hg > octave-lyh
comparison scripts/plot/private/__patch__.m @ 13954:2ebbc6c9961b
[Bug #34559] Clean-up __patch__.m and add support for RGB cdata.
* plot/private/__patch__.m (__patch__): Predefine h output argument. Support
CDATA specified in RGB format.
(setdata): Removed unused variables.
(setvertexdata): Likewise. Support case where [x|y]data are specified as row
vectors.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Mon, 28 Nov 2011 22:19:45 +0000 |
parents | 425b861ae66f |
children | 5be545210fe3 |
comparison
equal
deleted
inserted
replaced
13953:642e43164af6 | 13954:2ebbc6c9961b |
---|---|
27 | 27 |
28 ## Author: Kai Habel | 28 ## Author: Kai Habel |
29 | 29 |
30 function [h, failed] = __patch__ (p, varargin) | 30 function [h, failed] = __patch__ (p, varargin) |
31 | 31 |
32 h = NaN; | |
32 failed = false; | 33 failed = false; |
33 | 34 |
34 is_numeric_arg = cellfun (@isnumeric, varargin); | 35 is_numeric_arg = cellfun (@isnumeric, varargin); |
35 | 36 |
36 if (isempty (varargin)) | 37 if (isempty (varargin)) |
126 args{9} = "cdata"; | 127 args{9} = "cdata"; |
127 args{10} = c; | 128 args{10} = c; |
128 else | 129 else |
129 error ("patch: color value not valid"); | 130 error ("patch: color value not valid"); |
130 endif | 131 endif |
131 elseif (size (c, ndims (c)) == 3) | 132 elseif (isvector (c) && numel (c) == 3) |
132 args{7} = "facecolor"; | 133 args{7} = "facecolor"; |
133 args{8} = c; | 134 args{8} = c; |
134 args{9} = "cdata"; | 135 args{9} = "cdata"; |
135 args{10} = []; | 136 args{10} = []; |
137 elseif (ndims (c) == 3 && size (c, 3) == 3) | |
138 ## CDATA is specified as RGB data | |
139 if ((size (c, 1) == 1 && size (c, 2) == 1) ... | |
140 || (size (c, 1) == 1 && size (c, 2) == columns (x))) | |
141 ## Single patch color or per-face color | |
142 args{7} = "facecolor"; | |
143 args{8} = "flat"; | |
144 args{9} = "cdata"; | |
145 args{10} = c; | |
146 elseif (size (c, 1) == rows (x) && size (c, 2) == columns (x)) | |
147 ## Per-vertex color | |
148 args{7} = "facecolor"; | |
149 args{8} = "interp"; | |
150 args{9} = "cdata"; | |
151 agrs{10} = c; | |
152 else | |
153 error ("patch: color value not valid"); | |
154 endif | |
136 else | 155 else |
137 ## Color Vectors | 156 ## Color Vectors |
138 if (isempty (c)) | 157 if (isempty (c)) |
139 args{7} = "facecolor"; | 158 args{7} = "facecolor"; |
140 args{8} = "interp"; | 159 args{8} = "interp"; |
229 fc = "flat"; | 248 fc = "flat"; |
230 else | 249 else |
231 fc = [0, 1, 0]; | 250 fc = [0, 1, 0]; |
232 endif | 251 endif |
233 args = {"facecolor", fc, args{:}}; | 252 args = {"facecolor", fc, args{:}}; |
234 else | 253 endif |
235 fc = args {idx}; | 254 |
236 endif | |
237 | |
238 nr = size (faces, 2); | |
239 nc = size (faces, 1); | 255 nc = size (faces, 1); |
240 idx = faces .'; | 256 idx = faces .'; |
241 t1 = isnan (idx); | 257 t1 = isnan (idx); |
242 for i = find (any (t1)) | 258 for i = find (any (t1)) |
243 first_idx_in_column = find (t1(:,i), 1); | 259 first_idx_in_column = find (t1(:,i), 1); |
300 fc = "flat"; | 316 fc = "flat"; |
301 else | 317 else |
302 fc = [0, 1, 0]; | 318 fc = [0, 1, 0]; |
303 endif | 319 endif |
304 args = {"facecolor", fc, args{:}}; | 320 args = {"facecolor", fc, args{:}}; |
305 else | |
306 fc = args {idx}; | |
307 endif | 321 endif |
308 | 322 |
309 [nr, nc] = size (x); | 323 [nr, nc] = size (x); |
324 if (nr == 1 && nc > 1) | |
325 nr = nc; | |
326 nc = 1; | |
327 end | |
310 if (!isempty (z)) | 328 if (!isempty (z)) |
311 vert = [x(:), y(:), z(:)]; | 329 vert = [x(:), y(:), z(:)]; |
312 else | 330 else |
313 vert = [x(:), y(:)]; | 331 vert = [x(:), y(:)]; |
314 endif | 332 endif |
315 faces = reshape (1:numel(x), rows (x), columns (x)); | 333 faces = reshape (1:numel(x), nr, nc); |
316 faces = faces'; | 334 faces = faces'; |
317 | 335 |
318 if (ndims (c) == 3) | 336 if (ndims (c) == 3) |
319 fvc = reshape (c, size (c, 1) * size (c, 2), size(c, 3)); | 337 fvc = reshape (c, size (c, 1) * size (c, 2), size(c, 3)); |
320 elseif (isvector (c)) | 338 elseif (isvector (c)) |