7109
|
1 ## Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2002, 2004, |
|
2 ## 2005, 2006, 2007 John W. Eaton |
|
3 ## |
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
|
7 ## under the terms of the GNU General Public License as published by |
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
|
10 ## |
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
|
19 |
|
20 ## -*- texinfo -*- |
7175
|
21 ## @deftypefn {Function File} {} surface (@var{x}, @var{y}, @var{z}, @var{c}) |
|
22 ## @deftypefnx {Function File} {} surface (@var{x}, @var{y}, @var{z}) |
|
23 ## @deftypefnx {Function File} {} surface (@var{z}, @var{c}) |
|
24 ## @deftypefnx {Function File} {} surface (@var{z}) |
|
25 ## @deftypefnx {Function File} {} surface (@dots{}, @var{prop}, @var{val}) |
|
26 ## @deftypefnx {Function File} {} surface (@var{h}, @dots{}) |
|
27 ## @deftypefnx {Function File} {@var{h} = } surface (@dots{}) |
|
28 ## Plot a surface graphic object given matrices @var{x}, and @var{y} from |
|
29 ## @code{meshgrid} and a matrix @var{z} corresponding to the @var{x} and |
|
30 ## @var{y} coordinates of the surface. If @var{x} and @var{y} are vectors, |
|
31 ## then a typical vertex is (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus, |
|
32 ## columns of @var{z} correspond to different @var{x} values and rows of |
|
33 ## @var{z} correspond to different @var{y} values. If @var{x} and @var{y} |
|
34 ## are missing, they are constructed from size of the matrix @var{z}. |
|
35 ## |
|
36 ## Any additional properties passed are assigned the the surface.. |
7109
|
37 ## @seealso{surf, mesh, patch, line} |
|
38 ## @end deftypefn |
|
39 |
|
40 ## Author: jwe |
|
41 |
7175
|
42 function h = surface (varargin) |
7109
|
43 |
7207
|
44 if (isscalar (varargin{1}) && ishandle (varargin{1})) |
|
45 h = varargin {1}; |
|
46 if (! strcmp (get (h, "type"), "axes")) |
|
47 error ("surface: expecting first argument to be an axes object"); |
|
48 endif |
|
49 oldh = gca (); |
|
50 unwind_protect |
|
51 axes (h); |
|
52 [tmp, bad_usage] = __surface__ (h, varargin{2:end}); |
|
53 unwind_protect_cleanup |
|
54 axes (oldh); |
|
55 end_unwind_protect |
|
56 else |
|
57 [tmp, bad_usage] = __surface__ (gca (), varargin{:}); |
|
58 endif |
7109
|
59 |
7207
|
60 if (bad_usage) |
|
61 print_usage (); |
|
62 endif |
|
63 |
|
64 if (nargout > 0) |
|
65 h = tmp; |
|
66 endif |
|
67 endfunction |
|
68 |
|
69 function [h, bad_usage] = __surface__ (ax, varargin) |
|
70 |
|
71 bad_usage = false; |
|
72 h = 0; |
|
73 firststring = nargin; |
|
74 for i = 2 : nargin |
|
75 if (ischar (varargin {i - 1})) |
|
76 firststring = i - 1; |
7175
|
77 break; |
7109
|
78 endif |
7175
|
79 endfor |
|
80 |
|
81 if (firststring > 5) |
7207
|
82 bad_usage = true; |
7175
|
83 elseif (firststring == 5) |
|
84 x = varargin{1}; |
|
85 y = varargin{2}; |
|
86 z = varargin{3}; |
|
87 c = varargin{4}; |
|
88 |
7110
|
89 if (! size_equal (z, c)) |
7109
|
90 error ("surface: z and c must have same size"); |
|
91 endif |
|
92 if (isvector (x) && isvector (y) && ismatrix (z)) |
|
93 if (rows (z) == length (y) && columns (z) == length (x)) |
|
94 x = x(:)'; |
|
95 y = y(:); |
|
96 else |
7114
|
97 error ("surface: rows (z) must be the same as length (y) and columns (z) must be the same as length (x)"); |
7109
|
98 endif |
|
99 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) |
|
100 if (! (size_equal (x, y) && size_equal (x, z))) |
|
101 error ("surface: x, y, and z must have same dimensions"); |
|
102 endif |
|
103 else |
|
104 error ("surface: x and y must be vectors and z must be a matrix"); |
|
105 endif |
7175
|
106 elseif (firststring == 4) |
|
107 x = varargin{1}; |
|
108 y = varargin{2}; |
|
109 z = varargin{3}; |
|
110 c = z; |
|
111 if (isvector (x) && isvector (y) && ismatrix (z)) |
|
112 if (rows (z) == length (y) && columns (z) == length (x)) |
|
113 x = x(:)'; |
|
114 y = y(:); |
|
115 else |
|
116 error ("surface: rows (z) must be the same as length (y) and columns (z) must be the same as length (x)"); |
|
117 endif |
|
118 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) |
|
119 if (! (size_equal (x, y) && size_equal (x, z))) |
|
120 error ("surface: x, y, and z must have same dimensions"); |
|
121 endif |
|
122 else |
|
123 error ("surface: x and y must be vectors and z must be a matrix"); |
|
124 endif |
|
125 elseif (firststring == 3) |
|
126 z = varargin {1}; |
|
127 c = varargin {2}; |
|
128 if (ismatrix (z)) |
|
129 [nr, nc] = size (z); |
|
130 x = 1:nc; |
|
131 y = (1:nr)'; |
|
132 else |
|
133 error ("surface: argument must be a matrix"); |
|
134 endif |
|
135 elseif (firststring == 2) |
|
136 z = varargin {1}; |
|
137 c = z; |
|
138 if (ismatrix (z)) |
|
139 [nr, nc] = size (z); |
|
140 x = 1:nc; |
|
141 y = (1:nr)'; |
|
142 else |
|
143 error ("surface: argument must be a matrix"); |
|
144 endif |
7109
|
145 else |
7207
|
146 bad_usage = true; |
7189
|
147 endif |
7109
|
148 |
7207
|
149 if (! bad_usage) |
|
150 ## Make a default surface object. |
|
151 h = __go_surface__ (ax, "xdata", x, "ydata", y, "zdata", z, "cdata", c); |
|
152 set (h, "facecolor","flat"); |
|
153 if (firststring < nargin) |
|
154 set (h, varargin {firststring:end}); |
|
155 endif |
7109
|
156 |
7207
|
157 if (! ishold ()) |
|
158 set (ax, "view", [0, 90], "box", "off", "xgrid", "on", |
|
159 "ygrid", "on", "zgrid", "on"); |
|
160 endif |
|
161 endif |
7109
|
162 |
|
163 endfunction |