annotate scripts/plot/draw/trimesh.m @ 20595:c1a6c31ac29a

eliminate more simple uses of error_state * ov-classdef.cc: Eliminate simple uses of error_state.
author John W. Eaton <jwe@octave.org>
date Tue, 06 Oct 2015 00:20:02 -0400
parents 9fc020886ae9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19627
diff changeset
1 ## Copyright (C) 2007-2015 David Bateman
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
2 ##
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
3 ## This file is part of Octave.
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
4 ##
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6832
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6832
diff changeset
8 ## your option) any later version.
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
9 ##
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
13 ## General Public License for more details.
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
14 ##
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6832
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6832
diff changeset
17 ## <http://www.gnu.org/licenses/>.
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
18
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
19 ## -*- texinfo -*-
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
20 ## @deftypefn {Function File} {} trimesh (@var{tri}, @var{x}, @var{y}, @var{z}, @var{c})
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
21 ## @deftypefnx {Function File} {} trimesh (@var{tri}, @var{x}, @var{y}, @var{z})
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
22 ## @deftypefnx {Function File} {} trimesh (@var{tri}, @var{x}, @var{y})
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
23 ## @deftypefnx {Function File} {} trimesh (@dots{}, @var{prop}, @var{val}, @dots{})
7650
eb7bdde776f2 Texinfo fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
24 ## @deftypefnx {Function File} {@var{h} =} trimesh (@dots{})
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
25 ## Plot a 3-D triangular wireframe mesh.
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
26 ##
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
27 ## In contrast to @code{mesh}, which plots a mesh using rectangles,
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
28 ## @code{trimesh} plots the mesh using triangles.
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13747
diff changeset
29 ##
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
30 ## @var{tri} is typically the output of a Delaunay triangulation over the
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
31 ## grid of @var{x}, @var{y}. Every row of @var{tri} represents one triangle
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
32 ## and contains three indices into [@var{x}, @var{y}] which are the
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
33 ## vertices of the triangles in the x-y plane. @var{z} determines the
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
34 ## height above the plane of each vertex. If no @var{z} input is given then
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
35 ## the triangles are plotted as a 2-D figure.
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
36 ##
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
37 ## The color of the trimesh is computed by linearly scaling the @var{z} values
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
38 ## to fit the range of the current colormap. Use @code{caxis} and/or
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
39 ## change the colormap to control the appearance.
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
40 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
41 ## Optionally, the color of the mesh can be specified independently of @var{z}
17439
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
42 ## by supplying a color matrix, @var{c}. If @var{z} has N elements, then
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
43 ## @var{c} should be an Nx1 vector for colormap data or an Nx3 matrix for
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
44 ## RGB data.
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
45 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
46 ## Any property/value pairs are passed directly to the underlying patch object.
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
47 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
48 ## The optional return value @var{h} is a graphics handle to the created patch
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
49 ## object.
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14846
diff changeset
50 ## @seealso{mesh, tetramesh, triplot, trisurf, delaunay, patch, hidden}
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
51 ## @end deftypefn
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
52
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
53 function h = trimesh (tri, x, y, z, varargin)
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
54
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
55 if (nargin < 3)
6826
8618f29520c6 [project @ 2007-08-24 16:02:07 by jwe]
jwe
parents: 6823
diff changeset
56 print_usage ();
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
57 endif
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
58
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
59 if (nargin == 3)
17439
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
60 htmp = triplot (tri, x, y);
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
61 elseif (ischar (z))
17439
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
62 htmp = triplot (tri, x, y, z, varargin{:});
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
63 else
17439
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
64 ## Process color argument
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
65 if (nargin > 4 && isnumeric (varargin{1}))
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
66 c = varargin{1};
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
67 varargin(1) = [];
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
68 if (isvector (c))
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
69 if (numel (c) != numel (z))
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
70 error ("trimesh: C must have 'numel (Z)' elements");
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
71 endif
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
72 c = c(:);
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
73 elseif (rows (c) != numel (z) || columns (c) != 3)
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
74 error ("trimesh: TrueColor C matrix must be 'numel (Z)' rows by 3 columns");
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
75 endif
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
76 else
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
77 c = z(:);
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
78 endif
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
79
17126
26589abbc78d Don't pass axis handle unnecessarily from high level to low level plot functions.
Rik <rik@octave.org>
parents: 17122
diff changeset
80 hax = newplot ();
17439
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
81
17494
cd98a50bfa63 hidden.m: Fix hidden so that it also works for trimesh objects.
Rik <rik@octave.org>
parents: 17439
diff changeset
82 ## Tag object as "trimesh" so that hidden() can find it.
17439
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
83 htmp = patch ("Vertices", [x(:), y(:), z(:)], "Faces", tri,
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
84 "FaceVertexCdata", c, "EdgeColor", "flat", "FaceColor", "w",
17494
cd98a50bfa63 hidden.m: Fix hidden so that it also works for trimesh objects.
Rik <rik@octave.org>
parents: 17439
diff changeset
85 "Tag", "trimesh", varargin{:});
9110
22ae6b3411a7 Add isocolor, isonormals and isosurface functions (For Martin Helm). Add 3D filled triangular patches and the trisurf function
David Bateman <dbateman@free.fr>
parents: 9051
diff changeset
86 if (! ishold ())
17439
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
87 set (hax, "view", [-37.5, 30], "box", "off",
17126
26589abbc78d Don't pass axis handle unnecessarily from high level to low level plot functions.
Rik <rik@octave.org>
parents: 17122
diff changeset
88 "xgrid", "on", "ygrid", "on", "zgrid", "on");
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
89 endif
17439
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
90 endif
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
91
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
92 if (nargout > 0)
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
93 h = htmp;
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
94 endif
13747
e8564e8b0043 Restore random number state after %!demos or %!tests
Rik <octave@nomad.inbox5.com>
parents: 12792
diff changeset
95
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
96 endfunction
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
97
13747
e8564e8b0043 Restore random number state after %!demos or %!tests
Rik <octave@nomad.inbox5.com>
parents: 12792
diff changeset
98
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
99 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
100 %! clf;
17530
0f45d9dd8107 test: Fix 4 failing plot demos.
Rik <rik@octave.org>
parents: 17494
diff changeset
101 %! colormap ('default');
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
102 %! old_state = rand ('state');
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
103 %! restore_state = onCleanup (@() rand ('state', old_state));
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
104 %! rand ('state', 10);
9110
22ae6b3411a7 Add isocolor, isonormals and isosurface functions (For Martin Helm). Add 3D filled triangular patches and the trisurf function
David Bateman <dbateman@free.fr>
parents: 9051
diff changeset
105 %! N = 10;
22ae6b3411a7 Add isocolor, isonormals and isosurface functions (For Martin Helm). Add 3D filled triangular patches and the trisurf function
David Bateman <dbateman@free.fr>
parents: 9051
diff changeset
106 %! x = 3 - 6 * rand (N, N);
22ae6b3411a7 Add isocolor, isonormals and isosurface functions (For Martin Helm). Add 3D filled triangular patches and the trisurf function
David Bateman <dbateman@free.fr>
parents: 9051
diff changeset
107 %! y = 3 - 6 * rand (N, N);
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
108 %! z = peaks (x, y);
9110
22ae6b3411a7 Add isocolor, isonormals and isosurface functions (For Martin Helm). Add 3D filled triangular patches and the trisurf function
David Bateman <dbateman@free.fr>
parents: 9051
diff changeset
109 %! tri = delaunay (x(:), y(:));
22ae6b3411a7 Add isocolor, isonormals and isosurface functions (For Martin Helm). Add 3D filled triangular patches and the trisurf function
David Bateman <dbateman@free.fr>
parents: 9051
diff changeset
110 %! trimesh (tri, x(:), y(:), z(:));
13747
e8564e8b0043 Restore random number state after %!demos or %!tests
Rik <octave@nomad.inbox5.com>
parents: 12792
diff changeset
111
19867
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
112 ## Test input validation
17439
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
113 %!error trimesh ()
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
114 %!error trimesh (1)
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
115 %!error trimesh (1,2)
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
116 %!error <C must have 'numel \(Z\)' elements> trimesh (1,2,3,4,[5 6])
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
117 %!error <C must have 'numel \(Z\)' elements> trimesh (1,2,3,4,[5 6]')
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
118 %!error <TrueColor C matrix must> trimesh ([1;1],[2;2],[3;3],[4;4],zeros(3,3))
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
119 %!error <TrueColor C matrix must> trimesh ([1;1],[2;2],[3;3],[4;4],zeros(2,2))
000be929e835 trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents: 17126
diff changeset
120