Mercurial > octave
annotate scripts/plot/draw/isonormals.m @ 30236:628f26e122d9
maint: use rows() or columns() instead of size(__, 1 | 2) for clarity.
* ccolamd.cc, colamd.cc, Map.m, material.m, isocolors.m, isonormals.m,
isosurface.m, light.m, reducepatch.m, reducevolume.m, movfun.m, ilu.m,
__alltohandles__.m, dump_demos.m, mk-sparse-tst.sh:
Use rows() or columns() instead of size(__, 1 | 2) for clarity.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 11 Oct 2021 20:09:59 -0700 |
parents | 7854d5752dd2 |
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:
27978
diff
changeset
|
3 ## Copyright (C) 2009-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/>. |
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:
diff
changeset
|
7 ## |
11104 | 8 ## This file is part of Octave. |
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:
diff
changeset
|
9 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24423
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
11104 | 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:
24423
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:
22405
diff
changeset
|
13 ## (at your option) any later version. |
11104 | 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:
22405
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22405
diff
changeset
|
18 ## GNU General Public License for more details. |
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:
diff
changeset
|
19 ## |
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:
diff
changeset
|
20 ## You should have received a copy of the GNU General Public License |
11104 | 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:
24423
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 ######################################################################## |
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:
diff
changeset
|
25 |
9119
3b810beddfa6
Added help texts and tests.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
9110
diff
changeset
|
26 ## -*- texinfo -*- |
22790 | 27 ## @deftypefn {} {@var{vn} =} isonormals (@var{val}, @var{vert}) |
28 ## @deftypefnx {} {@var{vn} =} isonormals (@var{val}, @var{hp}) | |
29 ## @deftypefnx {} {@var{vn} =} isonormals (@var{x}, @var{y}, @var{z}, @var{val}, @var{vert}) | |
30 ## @deftypefnx {} {@var{vn} =} isonormals (@var{x}, @var{y}, @var{z}, @var{val}, @var{hp}) | |
31 ## @deftypefnx {} {@var{vn} =} isonormals (@dots{}, "negate") | |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
32 ## @deftypefnx {} {} isonormals (@var{val}, @var{hp}) |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
33 ## @deftypefnx {} {} isonormals (@var{x}, @var{y}, @var{z}, @var{val}, @var{hp}) |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
34 ## @deftypefnx {} {} isonormals (@dots{}, "negate") |
9119
3b810beddfa6
Added help texts and tests.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
9110
diff
changeset
|
35 ## |
20173
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
36 ## Calculate normals to an isosurface. |
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
37 ## |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
38 ## The vertex normals @var{vn} are calculated from the gradient of the |
22790 | 39 ## 3-dimensional array @var{val} (size: lxmxn) containing the data for an |
40 ## isosurface geometry. The normals point towards smaller values in @var{val}. | |
9119
3b810beddfa6
Added help texts and tests.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
9110
diff
changeset
|
41 ## |
22790 | 42 ## If called with one output argument @var{vn}, and the second input argument |
43 ## @var{vert} holds the vertices of an isosurface, then the normals @var{vn} | |
44 ## are calculated at the vertices @var{vert} on a grid given by | |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
45 ## @code{[x, y, z] = meshgrid (1:l, 1:m, 1:n)}. The output argument |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
46 ## @var{vn} has the same size as @var{vert} and can be used to set the |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
47 ## @qcode{"VertexNormals"} property of the corresponding patch. |
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:
diff
changeset
|
48 ## |
22790 | 49 ## If called with additional input arguments @var{x}, @var{y}, and @var{z}, |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
50 ## which are 3-dimensional arrays with the same size as @var{val}, |
22790 | 51 ## then the volume data is taken at these points. Instead of the vertex data |
52 ## @var{vert}, a patch handle @var{hp} can be passed to the function. | |
9119
3b810beddfa6
Added help texts and tests.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
9110
diff
changeset
|
53 ## |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
54 ## If the last input argument is the string @qcode{"negate"}, compute the |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
55 ## reverse vector normals of an isosurface geometry (i.e., pointed towards |
22790 | 56 ## larger values in @var{val}). |
9119
3b810beddfa6
Added help texts and tests.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
9110
diff
changeset
|
57 ## |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
58 ## If no output argument is given, the property @qcode{"VertexNormals"} of |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
59 ## the patch associated with the patch handle @var{hp} is changed directly. |
9119
3b810beddfa6
Added help texts and tests.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
9110
diff
changeset
|
60 ## |
22142
62208397b99e
Add function "smooth3" (patch #8864).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
21758
diff
changeset
|
61 ## @seealso{isosurface, isocolors, smooth3} |
9119
3b810beddfa6
Added help texts and tests.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
9110
diff
changeset
|
62 ## @end deftypefn |
3b810beddfa6
Added help texts and tests.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
9110
diff
changeset
|
63 |
22790 | 64 function vn = isonormals (varargin) |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
20927
diff
changeset
|
65 |
22790 | 66 narg = nargin; |
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:
diff
changeset
|
67 negate = false; |
28896
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
68 if (nargin > 2) |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
69 if (ischar (varargin{end})) |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
70 if (strcmpi (varargin{end}, "negate")) |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
71 negate = true; |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
72 narg -= 1; |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
73 else |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
74 error ("isonormals: Unknown option '%s'", varargin{end}); |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
75 endif |
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:
diff
changeset
|
76 endif |
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:
diff
changeset
|
77 endif |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
20927
diff
changeset
|
78 |
22790 | 79 switch (narg) |
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:
diff
changeset
|
80 case 2 |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
81 val = varargin{1}; |
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:
diff
changeset
|
82 vp = varargin{2}; |
30236
628f26e122d9
maint: use rows() or columns() instead of size(__, 1 | 2) for clarity.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
83 x = 1:columns (val); |
628f26e122d9
maint: use rows() or columns() instead of size(__, 1 | 2) for clarity.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
84 y = 1:rows (val); |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
85 z = 1:size (val, 3); |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
86 |
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:
diff
changeset
|
87 case 5 |
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:
diff
changeset
|
88 x = varargin{1}; |
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:
diff
changeset
|
89 y = varargin{2}; |
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:
diff
changeset
|
90 z = varargin{3}; |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
91 val = varargin{4}; |
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:
diff
changeset
|
92 vp = varargin{5}; |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
93 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
94 otherwise |
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:
diff
changeset
|
95 print_usage (); |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
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:
diff
changeset
|
97 endswitch |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
20927
diff
changeset
|
98 |
19700
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
99 if (isnumeric (vp) && columns (vp) == 3) |
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:
diff
changeset
|
100 pa = []; |
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:
diff
changeset
|
101 v = vp; |
24423
1d52db450db4
Change ishandle to return true for Java objects for Matlab compatibility.
Rik <rik@octave.org>
parents:
24188
diff
changeset
|
102 elseif (isgraphics (vp, "patch")) |
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:
diff
changeset
|
103 pa = vp; |
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:
diff
changeset
|
104 v = get (pa, "Vertices"); |
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:
diff
changeset
|
105 else |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
106 error ("isonormals: input must be a list of vertices or a patch handle"); |
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:
diff
changeset
|
107 endif |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
20927
diff
changeset
|
108 |
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:
diff
changeset
|
109 if (negate) |
22786 | 110 normals = __interp_cube__ ("isonormals", x, y, z, val, v, "normals"); |
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:
diff
changeset
|
111 else |
22786 | 112 normals = -__interp_cube__ ("isonormals", x, y, z, val, v, "normals"); |
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:
diff
changeset
|
113 endif |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
20927
diff
changeset
|
114 |
22790 | 115 if (nargout == 0) |
116 if (! isempty (pa)) | |
117 set (pa, "VertexNormals", normals); | |
118 endif | |
119 else | |
120 vn = normals; | |
121 endif | |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
20927
diff
changeset
|
122 |
9119
3b810beddfa6
Added help texts and tests.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
9110
diff
changeset
|
123 endfunction |
3b810beddfa6
Added help texts and tests.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
9110
diff
changeset
|
124 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
125 |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
126 %!demo |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
127 %! function isofinish (hp) |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
128 %! axis equal; |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
129 %! set (hp, "VertexNormals", -get (hp, "VertexNormals")); # Revert normals |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
130 %! shading interp; |
22405
81387a85a403
isonormals.m: Matlab compatibility in demos (bug #48873).
Markus Mützel <markus.muetzel@gmx.de>
parents:
22323
diff
changeset
|
131 %! lighting gouraud; |
81387a85a403
isonormals.m: Matlab compatibility in demos (bug #48873).
Markus Mützel <markus.muetzel@gmx.de>
parents:
22323
diff
changeset
|
132 %! set (hp, "BackFaceLighting", "lit"); |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
133 %! light (); |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
134 %! endfunction |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
135 %! |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
136 %! N = 15; # Increase number of vertices in each direction |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
137 %! iso = .4; # Change isovalue to .1 to display a sphere |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
138 %! lin = linspace (0, 2, N); |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
139 %! [x, y, z] = meshgrid (lin, lin, lin); |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
140 %! val = (x-.5).^2 + (y-.5).^2 + (z-.5).^2; |
24188
1253132e2173
Use "clf;" at beginning of all plot demos.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
141 %! clf; |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
142 %! |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
143 %! subplot (2,2,1); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
144 %! view (-38, 20); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
145 %! [fac, vert, cdat] = isosurface (x, y, z, val, iso, y); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
146 %! hp = patch ("Faces", fac, "Vertices", vert, "FaceVertexCData", cdat); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
147 %! title ("without isonormals"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
148 %! isofinish (hp); |
22405
81387a85a403
isonormals.m: Matlab compatibility in demos (bug #48873).
Markus Mützel <markus.muetzel@gmx.de>
parents:
22323
diff
changeset
|
149 %! set (hp, "VertexNormalsMode", "auto"); # for Matlab compatibility |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
150 %! |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
151 %! subplot (2,2,2); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
152 %! view (-38, 20); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
153 %! hp = patch ("Faces", fac, "Vertices", vert, "FaceVertexCData", cdat); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
154 %! title ("patch modified by isonormals"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
155 %! isonormals (x, y, z, val, hp); # Directly modify patch |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
156 %! isofinish (hp); |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
157 %! |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
158 %! subplot (2,2,3); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
159 %! view (-38, 20); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
160 %! hp = patch ("Faces", fac, "Vertices", vert, "FaceVertexCData", cdat); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
161 %! vn = isonormals (x, y, z, val, vert); # Compute normals of isosurface |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
162 %! set (hp, "VertexNormals", vn); # Manually set vertex normals |
22312
533c3c4059a3
Add titles to more of the graphic demos.
Rik <rik@octave.org>
parents:
22302
diff
changeset
|
163 %! title ('set "VertexNormals" from isonormals'); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
164 %! isofinish (hp); |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
165 %! |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
166 %! subplot (2,2,4); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
167 %! view (-38, 20); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
168 %! hp = patch ("Faces", fac, "Vertices", vert, "FaceVertexCData", cdat); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
169 %! isonormals (x, y, z, val, hp, "negate"); # Use reverse directly |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
170 %! title ('patch modified by isonormals (..., "negate")'); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
171 %! isofinish (hp); |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
172 |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
173 %!shared x,y,z,val,vert |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
174 %! [x, y, z] = meshgrid (0:.5:2, 0:.5:2, 0:.5:2); |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
175 %! val = abs ((x-.5).^2 + (y-.3).^2 + (z-.4).^2); |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
176 %! [fac, vert, cdat] = isosurface (x, y, z, val, .4, y); |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
177 |
9119
3b810beddfa6
Added help texts and tests.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
9110
diff
changeset
|
178 %!test |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
179 %! vn = isonormals (x, y, z, val, vert); |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
180 %! assert (size (vert), size (vn)); |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
181 |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
182 %!test |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
183 %! np = isonormals (x, y, z, val, vert); |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
184 %! nn = isonormals (x, y, z, val, vert, "negate"); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
185 %! assert (np, -nn); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
186 |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
187 %!test |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
188 %! [x,y,z] = meshgrid (-2:1:2, -2:1:2, -2:1:2); |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
189 %! val = x.^2 + y.^2 + z.^2; |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
190 %! [f,vert] = isosurface (x, y, z, val, 1); |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
191 %! vn = isonormals (x, y, z, val, vert); |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
192 %! dirn = vert ./ vn; |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
193 %! assert (all (dirn(isfinite (dirn)) <= 0)); |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
194 |
22790 | 195 ## Test input validation |
28896
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
196 %!error <Invalid call> isonormals () |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
197 %!error <Invalid call> isonormals (1) |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
198 %!error <Invalid call> isonormals (1,2,3) |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
199 %!error <Invalid call> isonormals (1,2,3,4) |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
200 %!error <Invalid call> isonormals (1,2,3,4,5,6) |
22790 | 201 %!error <Unknown option 'foo'> isonormals (x, y, z, val, vert, "foo") |
202 %!error <must be a list of vertices> isonormals (1, {1}) | |
203 %!error <must be a list of vertices> isonormals (1, [1 2 3 4]) | |
204 %!error <must be a .* patch handle> isonormals (x, y, z, val, x) | |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22790
diff
changeset
|
205 ## Test validation of private function __interp_cube__ |
22790 | 206 %!error <X, Y, Z have unequal dimensions> isonormals ({x}, y, z, val, vert) |
207 %!error <X, Y, Z have unequal dimensions> isonormals (x, {y}, z, val, vert) | |
208 %!error <X, Y, Z have unequal dimensions> isonormals (x, y, {z}, val, vert) | |
209 %!error <X, Y, Z have unequal dimensions> isonormals (x, y, z(1), val, vert) | |
210 %!error <X, Y, Z have unequal dimensions> isonormals (x(:), y(:), z, val, vert) | |
211 %!error <VAL dimensions must match those of X, Y, and Z> isonormals (1, 2, 3, val, vert) |