Mercurial > hg > octave-nkf
annotate scripts/plot/__patch__.m @ 8833:b86b42f77899
__patch__.m: fix indexing of varargin
author | Steffen Groot <steffen.groot@technolution.eu> |
---|---|
date | Fri, 20 Feb 2009 15:23:47 -0500 |
parents | 7d48766c21a5 |
children | eb63fbe60fab |
rev | line source |
---|---|
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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
6807 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
6807 | 18 |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8190
diff
changeset
|
19 ## -*- texinfo -*- |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8190
diff
changeset
|
20 ## @deftypefn {Function File} {[@var{h}, @var{fail}] =} __patch__ (@var{p}, @dots{}) |
6895 | 21 ## Undocumented internal function. |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8190
diff
changeset
|
22 ## @end deftypefn |
6895 | 23 |
24 ## __patch__ (p, x, y, c) | |
25 ## Create patch object from x and y with color c and parent p. | |
6807 | 26 ## Return handle to patch object. |
27 | |
28 ## Author: Kai Habel | |
29 | |
7020 | 30 function [h, fail] = __patch__ (p, varargin) |
7191 | 31 |
7020 | 32 fail = false; |
7191 | 33 |
6885 | 34 if (nargin < 3) |
7020 | 35 fail = true; |
36 return; | |
6885 | 37 endif |
38 | |
39 iarg = 1; | |
7020 | 40 have_x = have_z = have_c = have_faces = false; |
6886 | 41 if (isnumeric (varargin{1})) |
42 if (! isnumeric (varargin{2})) | |
7020 | 43 fail = true; |
44 return; | |
6885 | 45 endif |
46 | |
6886 | 47 x = varargin{1}; |
48 y = varargin{2}; | |
6885 | 49 have_x = true; |
50 iarg += 2; | |
51 | |
6886 | 52 if (nargin > 3 && ndims (varargin{3}) == 2 && ndims (x) == 2 |
7295 | 53 && size_equal(x, varargin{3}) && !ischar(varargin{3})) |
7208 | 54 z = varargin{3}; |
6885 | 55 have_z = true; |
6886 | 56 iarg++; |
6885 | 57 endif |
7191 | 58 elseif (ischar (varargin{1}) |
8190
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
7711
diff
changeset
|
59 && (strcmpi (varargin{1}, "faces") |
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
7711
diff
changeset
|
60 || strcmpi (varargin{1}, "vertices"))) |
7020 | 61 if (! isnumeric (varargin{2})) |
62 fail = true; | |
63 return; | |
64 endif | |
65 | |
8190
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
7711
diff
changeset
|
66 if (strcmpi (varargin{1}, "faces")) |
7020 | 67 faces = varargin{2}; |
8190
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
7711
diff
changeset
|
68 if (strcmpi (varargin{3}, "vertices")) |
7020 | 69 vert = varargin{4}; |
70 have_faces = true; | |
71 endif | |
8833
b86b42f77899
__patch__.m: fix indexing of varargin
Steffen Groot <steffen.groot@technolution.eu>
parents:
8812
diff
changeset
|
72 elseif (strcmpi (varargin{1}, "vertices")) |
7020 | 73 vert = varargin{2}; |
8190
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
7711
diff
changeset
|
74 if (strcmpi (varargin{3}, "faces")) |
7020 | 75 faces = varargin{4}; |
76 have_faces = true; | |
77 endif | |
78 endif | |
79 if (!have_faces) | |
80 fail = true; | |
81 return; | |
82 else | |
83 iarg += 4; | |
84 endif | |
6885 | 85 endif |
86 | |
7020 | 87 if ((have_x || have_faces) && nargin > iarg) |
6925 | 88 if (isnumeric (varargin{iarg})) |
89 c = varargin{iarg}; | |
90 have_c = true; | |
91 iarg++; | |
6885 | 92 |
6925 | 93 if (ndims (c) == 3 && size (c, 2) == 1) |
94 c = permute (c, [1, 3, 2]); | |
95 endif | |
96 elseif (ischar (varargin{iarg}) && rem (nargin - iarg, 2) != 0) | |
7191 | 97 ## Assume that any additional argument over an even number is |
98 ## color string. | |
6925 | 99 c = tolower (varargin{iarg}); |
100 have_c = true; | |
101 iarg++; | |
6885 | 102 endif |
103 endif | |
104 | |
105 if (rem (nargin - iarg, 2) != 0) | |
7020 | 106 fail = true; |
107 return; | |
6807 | 108 endif |
109 | |
6885 | 110 if (have_x) |
111 if (isvector (x)) | |
112 x = x(:); | |
113 y = y(:); | |
114 if (have_z) | |
115 z = z(:); | |
116 endif | |
117 endif | |
118 [nr, nc] = size (x); | |
7020 | 119 if (have_z) |
120 vert = [x(:), y(:), z(:)]; | |
121 else | |
122 vert = [x(:), y(:)]; | |
123 endif | |
7160 | 124 faces = reshape (1:numel(x), rows (x), columns (x)); |
125 faces = faces'; | |
7020 | 126 elseif (have_faces) |
127 nr = size (faces, 2); | |
128 nc = size (faces, 1); | |
129 idx = faces .'; | |
7421 | 130 t1 = isnan (idx); |
7711
263bcc319233
Minor fix for multiple patches with NaN values
David Bateman <dbateman@free.fr>
parents:
7421
diff
changeset
|
131 if (any (t1(:))) |
7421 | 132 t2 = find (t1 != t1([2:end,end],:)); |
133 idx (t1) = idx (t2 (cell2mat (cellfun (@(x) x(1)*ones(1,x(2)), | |
7711
263bcc319233
Minor fix for multiple patches with NaN values
David Bateman <dbateman@free.fr>
parents:
7421
diff
changeset
|
134 mat2cell ([1 : nc; sum(t1)], 2, ones(1,nc)), |
7421 | 135 "UniformOutput", false)))); |
136 endif | |
7189 | 137 x = reshape (vert(:,1)(idx), size (idx)); |
138 y = reshape (vert(:,2)(idx), size (idx)); | |
7020 | 139 if (size(vert,2) > 2) |
140 have_z = true; | |
7189 | 141 z = reshape (vert(:,3)(idx), size (idx)); |
7020 | 142 endif |
6807 | 143 else |
6886 | 144 error ("patch: not supported"); |
6807 | 145 endif |
6886 | 146 |
7020 | 147 cargs = {}; |
148 if (have_c) | |
149 if (ischar (c)) | |
150 cargs{1} = "facecolor"; | |
151 cargs{2} = c; | |
7191 | 152 elseif (isvector (c) && numel (c) == nc) |
7020 | 153 if (isnan (c)) |
154 cargs{1} = "facecolor"; | |
155 cargs{2} = [1, 1, 1]; | |
156 cargs{3} = "cdata"; | |
157 cargs{4} = c; | |
158 elseif (isnumeric (c)) | |
159 cargs{1} = "facecolor"; | |
160 cargs{2} = "flat"; | |
161 cargs{3} = "cdata"; | |
162 cargs{4} = c; | |
163 else | |
164 error ("patch: color value not valid"); | |
165 endif | |
7191 | 166 elseif (size (c, ndims (c)) == 3) |
7020 | 167 cargs{1} = "facecolor"; |
168 cargs{2} = "flat"; | |
169 cargs{3} = "cdata"; | |
170 cargs{4} = c; | |
171 else | |
172 ## Color Vectors | |
173 if (rows (c2) != rows (x) || rows (c2) != length (y)) | |
174 error ("patch: size of x, y, and c must be equal") | |
175 else | |
176 cargs{1} = "facecolor"; | |
177 cargs{2} = "interp"; | |
178 endif | |
179 endif | |
180 else | |
181 cargs{1} = "facecolor"; | |
182 cargs{2} = [0, 1, 0]; | |
183 endif | |
184 | |
7276 | 185 h = __go_patch__ (p, "xdata", x, "ydata", y, "faces", faces, |
186 "vertices", vert, cargs{:}, varargin{iarg:end}); | |
7020 | 187 if (have_z) |
188 set (h, "zdata", z); | |
189 endif | |
190 | |
6807 | 191 endfunction |