# HG changeset patch # User Rik # Date 1379608435 25200 # Node ID 000be929e8358f59758b1cd5592037f14a0f4981 # Parent 791c117eb2cf4f3bb0beacfc45e49b65e17cc9bd 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. diff -r 791c117eb2cf -r 000be929e835 scripts/plot/trimesh.m --- a/scripts/plot/trimesh.m Wed Sep 18 20:29:19 2013 -0700 +++ b/scripts/plot/trimesh.m Thu Sep 19 09:33:55 2013 -0700 @@ -39,7 +39,9 @@ ## change the colormap to control the appearance. ## ## Optionally, the color of the mesh can be specified independently of @var{z} -## by supplying a color matrix, @var{c}. +## by supplying a color matrix, @var{c}. If @var{z} has N elements, then +## @var{c} should be an Nx1 vector for colormap data or an Nx3 matrix for +## RGB data. ## ## Any property/value pairs are passed directly to the underlying patch object. ## @@ -55,21 +57,39 @@ endif if (nargin == 3) - triplot (tri, x, y); + htmp = triplot (tri, x, y); elseif (ischar (z)) - triplot (tri, x, y, z, varargin{:}); + htmp = triplot (tri, x, y, z, varargin{:}); else + ## Process color argument + if (nargin > 4 && isnumeric (varargin{1})) + c = varargin{1}; + varargin(1) = []; + if (isvector (c)) + if (numel (c) != numel (z)) + error ("trimesh: C must have 'numel (Z)' elements"); + endif + c = c(:); + elseif (rows (c) != numel (z) || columns (c) != 3) + error ("trimesh: TrueColor C matrix must be 'numel (Z)' rows by 3 columns"); + endif + else + c = z(:); + endif + hax = newplot (); - handle = patch ("Vertices", [x(:), y(:), z(:)], "Faces", tri, - "FaceColor", "none", "EdgeColor", __next_line_color__ (), - varargin{:}); + + htmp = patch ("Vertices", [x(:), y(:), z(:)], "Faces", tri, + "FaceVertexCdata", c, "EdgeColor", "flat", "FaceColor", "w", + varargin{:}); if (! ishold ()) - set (hax, "view", [-37.5, 30], + set (hax, "view", [-37.5, 30], "box", "off", "xgrid", "on", "ygrid", "on", "zgrid", "on"); endif - if (nargout > 0) - h = handle; - endif + endif + + if (nargout > 0) + h = htmp; endif endfunction @@ -87,3 +107,12 @@ %! tri = delaunay (x(:), y(:)); %! trimesh (tri, x(:), y(:), z(:)); +%% Test input validation +%!error trimesh () +%!error trimesh (1) +%!error trimesh (1,2) +%!error trimesh (1,2,3,4,[5 6]) +%!error trimesh (1,2,3,4,[5 6]') +%!error trimesh ([1;1],[2;2],[3;3],[4;4],zeros(3,3)) +%!error trimesh ([1;1],[2;2],[3;3],[4;4],zeros(2,2)) +