Mercurial > octave-nkf
comparison scripts/plot/trimesh.m @ 17439:000be929e835
trimesh.m: Overhaul function to support color matrix argument.
* scripts/plot/trimesh.m: Add documentation about C matrix argument.
Also return handle H for 2-D trimesh (equivalent to triplot).
Add code to check for 4th argument being a color matrix.
Set FaceColor to white in patch which corresponds to "hidden on".
Turn off axis plot box for visual compatibility with Matlab.
Add %!error tests for input validation.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 19 Sep 2013 09:33:55 -0700 |
parents | 26589abbc78d |
children | cd98a50bfa63 |
comparison
equal
deleted
inserted
replaced
17438:791c117eb2cf | 17439:000be929e835 |
---|---|
37 ## The color of the trimesh is computed by linearly scaling the @var{z} values | 37 ## The color of the trimesh is computed by linearly scaling the @var{z} values |
38 ## to fit the range of the current colormap. Use @code{caxis} and/or | 38 ## to fit the range of the current colormap. Use @code{caxis} and/or |
39 ## change the colormap to control the appearance. | 39 ## change the colormap to control the appearance. |
40 ## | 40 ## |
41 ## Optionally, the color of the mesh can be specified independently of @var{z} | 41 ## Optionally, the color of the mesh can be specified independently of @var{z} |
42 ## by supplying a color matrix, @var{c}. | 42 ## by supplying a color matrix, @var{c}. If @var{z} has N elements, then |
43 ## @var{c} should be an Nx1 vector for colormap data or an Nx3 matrix for | |
44 ## RGB data. | |
43 ## | 45 ## |
44 ## Any property/value pairs are passed directly to the underlying patch object. | 46 ## Any property/value pairs are passed directly to the underlying patch object. |
45 ## | 47 ## |
46 ## The optional return value @var{h} is a graphics handle to the created patch | 48 ## The optional return value @var{h} is a graphics handle to the created patch |
47 ## object. | 49 ## object. |
53 if (nargin < 3) | 55 if (nargin < 3) |
54 print_usage (); | 56 print_usage (); |
55 endif | 57 endif |
56 | 58 |
57 if (nargin == 3) | 59 if (nargin == 3) |
58 triplot (tri, x, y); | 60 htmp = triplot (tri, x, y); |
59 elseif (ischar (z)) | 61 elseif (ischar (z)) |
60 triplot (tri, x, y, z, varargin{:}); | 62 htmp = triplot (tri, x, y, z, varargin{:}); |
61 else | 63 else |
64 ## Process color argument | |
65 if (nargin > 4 && isnumeric (varargin{1})) | |
66 c = varargin{1}; | |
67 varargin(1) = []; | |
68 if (isvector (c)) | |
69 if (numel (c) != numel (z)) | |
70 error ("trimesh: C must have 'numel (Z)' elements"); | |
71 endif | |
72 c = c(:); | |
73 elseif (rows (c) != numel (z) || columns (c) != 3) | |
74 error ("trimesh: TrueColor C matrix must be 'numel (Z)' rows by 3 columns"); | |
75 endif | |
76 else | |
77 c = z(:); | |
78 endif | |
79 | |
62 hax = newplot (); | 80 hax = newplot (); |
63 handle = patch ("Vertices", [x(:), y(:), z(:)], "Faces", tri, | 81 |
64 "FaceColor", "none", "EdgeColor", __next_line_color__ (), | 82 htmp = patch ("Vertices", [x(:), y(:), z(:)], "Faces", tri, |
65 varargin{:}); | 83 "FaceVertexCdata", c, "EdgeColor", "flat", "FaceColor", "w", |
84 varargin{:}); | |
66 if (! ishold ()) | 85 if (! ishold ()) |
67 set (hax, "view", [-37.5, 30], | 86 set (hax, "view", [-37.5, 30], "box", "off", |
68 "xgrid", "on", "ygrid", "on", "zgrid", "on"); | 87 "xgrid", "on", "ygrid", "on", "zgrid", "on"); |
69 endif | 88 endif |
70 if (nargout > 0) | 89 endif |
71 h = handle; | 90 |
72 endif | 91 if (nargout > 0) |
92 h = htmp; | |
73 endif | 93 endif |
74 | 94 |
75 endfunction | 95 endfunction |
76 | 96 |
77 | 97 |
85 %! y = 3 - 6 * rand (N, N); | 105 %! y = 3 - 6 * rand (N, N); |
86 %! z = peaks (x, y); | 106 %! z = peaks (x, y); |
87 %! tri = delaunay (x(:), y(:)); | 107 %! tri = delaunay (x(:), y(:)); |
88 %! trimesh (tri, x(:), y(:), z(:)); | 108 %! trimesh (tri, x(:), y(:), z(:)); |
89 | 109 |
110 %% Test input validation | |
111 %!error trimesh () | |
112 %!error trimesh (1) | |
113 %!error trimesh (1,2) | |
114 %!error <C must have 'numel \(Z\)' elements> trimesh (1,2,3,4,[5 6]) | |
115 %!error <C must have 'numel \(Z\)' elements> trimesh (1,2,3,4,[5 6]') | |
116 %!error <TrueColor C matrix must> trimesh ([1;1],[2;2],[3;3],[4;4],zeros(3,3)) | |
117 %!error <TrueColor C matrix must> trimesh ([1;1],[2;2],[3;3],[4;4],zeros(2,2)) | |
118 |