Mercurial > octave
annotate scripts/plot/draw/trimesh.m @ 29359:7854d5752dd2
maint: merge stable to default.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 10 Feb 2021 10:10:40 -0500 |
parents | b73a54c31152 0a5b15007766 |
children | 796f54d4ddbf |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
28733
diff
changeset
|
3 ## Copyright (C) 2007-2021 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
6823 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24388
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
6823 | 11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24388
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22355
diff
changeset
|
13 ## (at your option) any later version. |
6823 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22355
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22355
diff
changeset
|
18 ## GNU General Public License for more details. |
6823 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24388
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
6823 | 25 |
26 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
27 ## @deftypefn {} {} trimesh (@var{tri}, @var{x}, @var{y}, @var{z}, @var{c}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
28 ## @deftypefnx {} {} trimesh (@var{tri}, @var{x}, @var{y}, @var{z}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
29 ## @deftypefnx {} {} trimesh (@var{tri}, @var{x}, @var{y}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
30 ## @deftypefnx {} {} trimesh (@dots{}, @var{prop}, @var{val}, @dots{}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
31 ## @deftypefnx {} {@var{h} =} trimesh (@dots{}) |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
32 ## Plot a 3-D triangular wireframe mesh. |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
33 ## |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
34 ## 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
|
35 ## @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
|
36 ## |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
37 ## @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
|
38 ## 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
|
39 ## 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
|
40 ## 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
|
41 ## 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
|
42 ## the triangles are plotted as a 2-D figure. |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
43 ## |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
44 ## 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
|
45 ## 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
|
46 ## change the colormap to control the appearance. |
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 ## Optionally, the color of the mesh can be specified independently of @var{z} |
24314
678912855789
trisurf.m, trimesh.m: Fix input validation (bug #48109).
Hugo Raguet <hugo.raguet@gmail.com>
parents:
23219
diff
changeset
|
49 ## by supplying @var{c}, which is a vector for colormap data, or a matrix with |
678912855789
trisurf.m, trimesh.m: Fix input validation (bug #48109).
Hugo Raguet <hugo.raguet@gmail.com>
parents:
23219
diff
changeset
|
50 ## three columns for RGB data. The number of colors specified in @var{c} must |
678912855789
trisurf.m, trimesh.m: Fix input validation (bug #48109).
Hugo Raguet <hugo.raguet@gmail.com>
parents:
23219
diff
changeset
|
51 ## either equal the number of vertices in @var{z} or the number of triangles |
678912855789
trisurf.m, trimesh.m: Fix input validation (bug #48109).
Hugo Raguet <hugo.raguet@gmail.com>
parents:
23219
diff
changeset
|
52 ## in @var{tri}. |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
53 ## |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
54 ## Any property/value pairs are passed directly to the underlying patch object. |
28733
9342688e86b4
Updated property references for text and graphics functions (bug #50247)
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27923
diff
changeset
|
55 ## The full list of properties is documented at @ref{Patch Properties}. |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
56 ## |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
57 ## 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
|
58 ## object. |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
59 ## @seealso{mesh, tetramesh, triplot, trisurf, delaunay, patch, hidden} |
6823 | 60 ## @end deftypefn |
61 | |
62 function h = trimesh (tri, x, y, z, varargin) | |
63 | |
64 if (nargin < 3) | |
6826 | 65 print_usage (); |
6823 | 66 endif |
67 | |
68 if (nargin == 3) | |
17439
000be929e835
trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
69 htmp = triplot (tri, x, y); |
6823 | 70 elseif (ischar (z)) |
17439
000be929e835
trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
71 htmp = triplot (tri, x, y, z, varargin{:}); |
6823 | 72 else |
17439
000be929e835
trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
73 ## Process color argument |
000be929e835
trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
74 if (nargin > 4 && isnumeric (varargin{1})) |
000be929e835
trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
75 c = varargin{1}; |
000be929e835
trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
76 varargin(1) = []; |
000be929e835
trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
77 if (isvector (c)) |
000be929e835
trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
78 c = c(:); |
28947
b73a54c31152
maint: Use Octave-specific end keywords rather than just 'end'.
Rik <rik@octave.org>
parents:
28896
diff
changeset
|
79 endif |
24314
678912855789
trisurf.m, trimesh.m: Fix input validation (bug #48109).
Hugo Raguet <hugo.raguet@gmail.com>
parents:
23219
diff
changeset
|
80 if (rows (c) != numel (z) && rows (c) != rows (tri)) |
678912855789
trisurf.m, trimesh.m: Fix input validation (bug #48109).
Hugo Raguet <hugo.raguet@gmail.com>
parents:
23219
diff
changeset
|
81 error ("trimesh: the numbers of colors specified in C must equal the number of vertices in Z or the number of triangles in TRI"); |
678912855789
trisurf.m, trimesh.m: Fix input validation (bug #48109).
Hugo Raguet <hugo.raguet@gmail.com>
parents:
23219
diff
changeset
|
82 elseif (columns (c) != 1 && columns (c) != 3) |
678912855789
trisurf.m, trimesh.m: Fix input validation (bug #48109).
Hugo Raguet <hugo.raguet@gmail.com>
parents:
23219
diff
changeset
|
83 error ("trimesh: TrueColor C matrix must have 3 columns"); |
17439
000be929e835
trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
84 endif |
000be929e835
trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
85 else |
000be929e835
trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
86 c = z(:); |
000be929e835
trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
87 endif |
000be929e835
trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
88 |
17126
26589abbc78d
Don't pass axis handle unnecessarily from high level to low level plot functions.
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
89 hax = newplot (); |
17439
000be929e835
trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
90 |
17494
cd98a50bfa63
hidden.m: Fix hidden so that it also works for trimesh objects.
Rik <rik@octave.org>
parents:
17439
diff
changeset
|
91 ## Tag object as "trimesh" so that hidden() can find it. |
24314
678912855789
trisurf.m, trimesh.m: Fix input validation (bug #48109).
Hugo Raguet <hugo.raguet@gmail.com>
parents:
23219
diff
changeset
|
92 htmp = patch ("Faces", tri, "Vertices", [x(:), y(:), z(:)], |
17439
000be929e835
trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
93 "FaceVertexCdata", c, "EdgeColor", "flat", "FaceColor", "w", |
22355
886530282db9
Set "facelighting" and "edgelighting" for mesh plots (bug #48507).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22351
diff
changeset
|
94 "FaceLighting", "none", "EdgeLighting", "flat", |
17494
cd98a50bfa63
hidden.m: Fix hidden so that it also works for trimesh objects.
Rik <rik@octave.org>
parents:
17439
diff
changeset
|
95 "Tag", "trimesh", varargin{:}); |
24314
678912855789
trisurf.m, trimesh.m: Fix input validation (bug #48109).
Hugo Raguet <hugo.raguet@gmail.com>
parents:
23219
diff
changeset
|
96 |
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
|
97 if (! ishold ()) |
22351
e6df1ddfc3cf
Change DefaultAxesBox property to "off".
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
98 set (hax, "view", [-37.5, 30], |
17126
26589abbc78d
Don't pass axis handle unnecessarily from high level to low level plot functions.
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
99 "xgrid", "on", "ygrid", "on", "zgrid", "on"); |
6823 | 100 endif |
17439
000be929e835
trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
101 endif |
000be929e835
trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
102 |
000be929e835
trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
103 if (nargout > 0) |
000be929e835
trimesh.m: Overhaul function to support color matrix argument.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
104 h = htmp; |
6823 | 105 endif |
13747
e8564e8b0043
Restore random number state after %!demos or %!tests
Rik <octave@nomad.inbox5.com>
parents:
12792
diff
changeset
|
106 |
6823 | 107 endfunction |
108 | |
13747
e8564e8b0043
Restore random number state after %!demos or %!tests
Rik <octave@nomad.inbox5.com>
parents:
12792
diff
changeset
|
109 |
6823 | 110 %!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
|
111 %! clf; |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
112 %! colormap ("default"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
113 %! old_state = rand ("state"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
114 %! restore_state = onCleanup (@() rand ("state", old_state)); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
115 %! 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
|
116 %! 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
|
117 %! 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
|
118 %! y = 3 - 6 * rand (N, N); |
6823 | 119 %! 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
|
120 %! 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
|
121 %! trimesh (tri, x(:), y(:), z(:)); |
24388 | 122 %! title ("trimesh() plot of sparsely-sampled peaks() function"); |
13747
e8564e8b0043
Restore random number state after %!demos or %!tests
Rik <octave@nomad.inbox5.com>
parents:
12792
diff
changeset
|
123 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
124 ## Test input validation |
28896
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
28733
diff
changeset
|
125 %!error <Invalid call> trimesh () |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
28733
diff
changeset
|
126 %!error <Invalid call> trimesh (1) |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
28733
diff
changeset
|
127 %!error <Invalid call> trimesh (1,2) |
24314
678912855789
trisurf.m, trimesh.m: Fix input validation (bug #48109).
Hugo Raguet <hugo.raguet@gmail.com>
parents:
23219
diff
changeset
|
128 %!error <the numbers of colors> trimesh (1,2,3,4,[5 6]) |
678912855789
trisurf.m, trimesh.m: Fix input validation (bug #48109).
Hugo Raguet <hugo.raguet@gmail.com>
parents:
23219
diff
changeset
|
129 %!error <the numbers of colors> trimesh (1,2,3,4,[5 6]') |
678912855789
trisurf.m, trimesh.m: Fix input validation (bug #48109).
Hugo Raguet <hugo.raguet@gmail.com>
parents:
23219
diff
changeset
|
130 %!error <the numbers of colors> trimesh ([1;1],[2;2],[3;3],[4;4], zeros (3,3)) |
678912855789
trisurf.m, trimesh.m: Fix input validation (bug #48109).
Hugo Raguet <hugo.raguet@gmail.com>
parents:
23219
diff
changeset
|
131 %!error <TrueColor C matrix must have 3 columns> |
678912855789
trisurf.m, trimesh.m: Fix input validation (bug #48109).
Hugo Raguet <hugo.raguet@gmail.com>
parents:
23219
diff
changeset
|
132 %! trimesh ([1;1],[2;2],[3;3],[4;4],zeros (2,2)) |