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 |
6895
|
19 ## Undocumented internal function. |
|
20 |
|
21 ## __patch__ (p, x, y, c) |
|
22 ## Create patch object from x and y with color c and parent p. |
6807
|
23 ## Return handle to patch object. |
|
24 |
|
25 ## Author: Kai Habel |
|
26 |
7020
|
27 function [h, fail] = __patch__ (p, varargin) |
7191
|
28 |
7020
|
29 fail = false; |
7191
|
30 |
6885
|
31 if (nargin < 3) |
7020
|
32 fail = true; |
|
33 return; |
6885
|
34 endif |
|
35 |
|
36 iarg = 1; |
7020
|
37 have_x = have_z = have_c = have_faces = false; |
6886
|
38 if (isnumeric (varargin{1})) |
|
39 if (! isnumeric (varargin{2})) |
7020
|
40 fail = true; |
|
41 return; |
6885
|
42 endif |
|
43 |
6886
|
44 x = varargin{1}; |
|
45 y = varargin{2}; |
6885
|
46 have_x = true; |
|
47 iarg += 2; |
|
48 |
6886
|
49 if (nargin > 3 && ndims (varargin{3}) == 2 && ndims (x) == 2 |
7020
|
50 && isequal (size (varargin{3}), size (x))) |
7208
|
51 z = varargin{3}; |
6885
|
52 have_z = true; |
6886
|
53 iarg++; |
6885
|
54 endif |
7191
|
55 elseif (ischar (varargin{1}) |
|
56 && (strcmp (tolower (varargin{1}), "faces") |
|
57 || trcmp (tolower (varargin{1}), "vertices"))) |
7020
|
58 if (! isnumeric (varargin{2})) |
|
59 fail = true; |
|
60 return; |
|
61 endif |
|
62 |
|
63 if (strcmp (tolower (varargin{1}), "faces")) |
|
64 faces = varargin{2}; |
|
65 if (strcmp (tolower (varargin{3}), "vertices")) |
|
66 vert = varargin{4}; |
|
67 have_faces = true; |
|
68 endif |
|
69 elseif (strcmp (tolower (varargin{3}), "vertices")) |
|
70 vert = varargin{2}; |
|
71 if (strcmp (tolower (varargin{3}), "faces")) |
|
72 faces = varargin{4}; |
|
73 have_faces = true; |
|
74 endif |
|
75 endif |
|
76 if (!have_faces) |
|
77 fail = true; |
|
78 return; |
|
79 else |
|
80 iarg += 4; |
|
81 endif |
6885
|
82 endif |
|
83 |
7020
|
84 if ((have_x || have_faces) && nargin > iarg) |
6925
|
85 if (isnumeric (varargin{iarg})) |
|
86 c = varargin{iarg}; |
|
87 have_c = true; |
|
88 iarg++; |
6885
|
89 |
6925
|
90 if (ndims (c) == 3 && size (c, 2) == 1) |
|
91 c = permute (c, [1, 3, 2]); |
|
92 endif |
|
93 elseif (ischar (varargin{iarg}) && rem (nargin - iarg, 2) != 0) |
7191
|
94 ## Assume that any additional argument over an even number is |
|
95 ## color string. |
6925
|
96 c = tolower (varargin{iarg}); |
|
97 have_c = true; |
|
98 iarg++; |
6885
|
99 endif |
|
100 endif |
|
101 |
|
102 if (rem (nargin - iarg, 2) != 0) |
7020
|
103 fail = true; |
|
104 return; |
6807
|
105 endif |
|
106 |
6885
|
107 if (have_x) |
|
108 if (isvector (x)) |
|
109 x = x(:); |
|
110 y = y(:); |
|
111 if (have_z) |
|
112 z = z(:); |
|
113 endif |
|
114 endif |
|
115 [nr, nc] = size (x); |
7020
|
116 if (have_z) |
|
117 vert = [x(:), y(:), z(:)]; |
|
118 else |
|
119 vert = [x(:), y(:)]; |
|
120 endif |
7160
|
121 faces = reshape (1:numel(x), rows (x), columns (x)); |
|
122 faces = faces'; |
7020
|
123 elseif (have_faces) |
|
124 nr = size (faces, 2); |
|
125 nc = size (faces, 1); |
|
126 idx = faces .'; |
|
127 for i = 1: nc |
|
128 t1 = isnan (idx (:,i)); |
|
129 if (any (t1)) |
|
130 t2 = find (t1(1:end-1) != t1(2:end))(1); |
|
131 idx(t1,i) = idx(t2,i); |
6885
|
132 endif |
|
133 endfor |
7189
|
134 x = reshape (vert(:,1)(idx), size (idx)); |
|
135 y = reshape (vert(:,2)(idx), size (idx)); |
7020
|
136 if (size(vert,2) > 2) |
|
137 have_z = true; |
7189
|
138 z = reshape (vert(:,3)(idx), size (idx)); |
7020
|
139 endif |
6807
|
140 else |
6886
|
141 error ("patch: not supported"); |
6807
|
142 endif |
6886
|
143 |
7020
|
144 cargs = {}; |
|
145 if (have_c) |
|
146 if (ischar (c)) |
|
147 cargs{1} = "facecolor"; |
|
148 cargs{2} = c; |
7191
|
149 elseif (isvector (c) && numel (c) == nc) |
7020
|
150 if (isnan (c)) |
|
151 cargs{1} = "facecolor"; |
|
152 cargs{2} = [1, 1, 1]; |
|
153 cargs{3} = "cdata"; |
|
154 cargs{4} = c; |
|
155 elseif (isnumeric (c)) |
|
156 cargs{1} = "facecolor"; |
|
157 cargs{2} = "flat"; |
|
158 cargs{3} = "cdata"; |
|
159 cargs{4} = c; |
|
160 else |
|
161 error ("patch: color value not valid"); |
|
162 endif |
7191
|
163 elseif (size (c, ndims (c)) == 3) |
7020
|
164 cargs{1} = "facecolor"; |
|
165 cargs{2} = "flat"; |
|
166 cargs{3} = "cdata"; |
|
167 cargs{4} = c; |
|
168 else |
|
169 ## Color Vectors |
|
170 if (rows (c2) != rows (x) || rows (c2) != length (y)) |
|
171 error ("patch: size of x, y, and c must be equal") |
|
172 else |
|
173 cargs{1} = "facecolor"; |
|
174 cargs{2} = "interp"; |
|
175 endif |
|
176 endif |
|
177 else |
|
178 cargs{1} = "facecolor"; |
|
179 cargs{2} = [0, 1, 0]; |
|
180 endif |
|
181 |
7276
|
182 h = __go_patch__ (p, "xdata", x, "ydata", y, "faces", faces, |
|
183 "vertices", vert, cargs{:}, varargin{iarg:end}); |
7020
|
184 if (have_z) |
|
185 set (h, "zdata", z); |
|
186 endif |
|
187 |
6807
|
188 endfunction |