Mercurial > octave
annotate scripts/plot/draw/isonormals.m @ 23220:092078913d54
maint: Merge stable to default.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 22 Feb 2017 12:58:07 -0500 |
parents | ef4d915df748 3ac9f9ecfae5 |
children | 1253132e2173 |
rev | line source |
---|---|
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
1 ## Copyright (C) 2009-2017 Martin Helm |
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
|
2 ## |
11104 | 3 ## 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
|
4 ## |
11104 | 5 ## Octave is free software; you can redistribute it and/or modify it |
6 ## under the terms of the GNU General Public License as published by | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22405
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22405
diff
changeset
|
8 ## (at your option) any later version. |
11104 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22405
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22405
diff
changeset
|
13 ## 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
|
14 ## |
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
|
15 ## You should have received a copy of the GNU General Public License |
11104 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
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
|
18 |
9119
3b810beddfa6
Added help texts and tests.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
9110
diff
changeset
|
19 ## -*- texinfo -*- |
22790 | 20 ## @deftypefn {} {@var{vn} =} isonormals (@var{val}, @var{vert}) |
21 ## @deftypefnx {} {@var{vn} =} isonormals (@var{val}, @var{hp}) | |
22 ## @deftypefnx {} {@var{vn} =} isonormals (@var{x}, @var{y}, @var{z}, @var{val}, @var{vert}) | |
23 ## @deftypefnx {} {@var{vn} =} isonormals (@var{x}, @var{y}, @var{z}, @var{val}, @var{hp}) | |
24 ## @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
|
25 ## @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
|
26 ## @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
|
27 ## @deftypefnx {} {} isonormals (@dots{}, "negate") |
9119
3b810beddfa6
Added help texts and tests.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
9110
diff
changeset
|
28 ## |
20173
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
29 ## 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
|
30 ## |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
31 ## The vertex normals @var{vn} are calculated from the gradient of the |
22790 | 32 ## 3-dimensional array @var{val} (size: lxmxn) containing the data for an |
33 ## 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
|
34 ## |
22790 | 35 ## If called with one output argument @var{vn}, and the second input argument |
36 ## @var{vert} holds the vertices of an isosurface, then the normals @var{vn} | |
37 ## 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
|
38 ## @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
|
39 ## @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
|
40 ## @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
|
41 ## |
22790 | 42 ## 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
|
43 ## which are 3-dimensional arrays with the same size as @var{val}, |
22790 | 44 ## then the volume data is taken at these points. Instead of the vertex data |
45 ## @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
|
46 ## |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
47 ## 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
|
48 ## reverse vector normals of an isosurface geometry (i.e., pointed towards |
22790 | 49 ## larger values in @var{val}). |
9119
3b810beddfa6
Added help texts and tests.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
9110
diff
changeset
|
50 ## |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
51 ## 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
|
52 ## 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
|
53 ## |
22142
62208397b99e
Add function "smooth3" (patch #8864).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
21758
diff
changeset
|
54 ## @seealso{isosurface, isocolors, smooth3} |
9119
3b810beddfa6
Added help texts and tests.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
9110
diff
changeset
|
55 ## @end deftypefn |
3b810beddfa6
Added help texts and tests.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
9110
diff
changeset
|
56 |
3b810beddfa6
Added help texts and tests.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
9110
diff
changeset
|
57 ## Author: Martin Helm <martin@mhelm.de> |
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
|
58 |
22790 | 59 function vn = isonormals (varargin) |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
20927
diff
changeset
|
60 |
22790 | 61 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
|
62 negate = false; |
22790 | 63 if (ischar (varargin{narg})) |
64 if (strcmpi (varargin{narg}, "negate")) | |
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
|
65 negate = true; |
22790 | 66 narg -= 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
|
67 else |
22790 | 68 error ("isonormals: Unknown option '%s'", varargin{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
|
69 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
|
70 endif |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
20927
diff
changeset
|
71 |
22790 | 72 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
|
73 case 2 |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
74 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
|
75 vp = varargin{2}; |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
76 x = 1:size (val, 2); |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
77 y = 1:size (val, 1); |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
78 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
|
79 |
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 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
87 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
|
88 print_usage (); |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
89 |
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
|
90 endswitch |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
20927
diff
changeset
|
91 |
19700
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
92 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
|
93 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
|
94 v = vp; |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
95 elseif (ishghandle (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
|
96 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
|
97 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
|
98 else |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
99 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
|
100 endif |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
20927
diff
changeset
|
101 |
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
|
102 if (negate) |
22786 | 103 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
|
104 else |
22786 | 105 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
|
106 endif |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
20927
diff
changeset
|
107 |
22790 | 108 if (nargout == 0) |
109 if (! isempty (pa)) | |
110 set (pa, "VertexNormals", normals); | |
111 endif | |
112 else | |
113 vn = normals; | |
114 endif | |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
20927
diff
changeset
|
115 |
9119
3b810beddfa6
Added help texts and tests.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
9110
diff
changeset
|
116 endfunction |
3b810beddfa6
Added help texts and tests.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
9110
diff
changeset
|
117 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
118 |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
119 %!demo |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
120 %! function isofinish (hp) |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
121 %! axis equal; |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
122 %! set (hp, "VertexNormals", -get (hp, "VertexNormals")); # Revert normals |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
123 %! shading interp; |
22405
81387a85a403
isonormals.m: Matlab compatibility in demos (bug #48873).
Markus Mützel <markus.muetzel@gmx.de>
parents:
22323
diff
changeset
|
124 %! lighting gouraud; |
81387a85a403
isonormals.m: Matlab compatibility in demos (bug #48873).
Markus Mützel <markus.muetzel@gmx.de>
parents:
22323
diff
changeset
|
125 %! 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
|
126 %! light (); |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
127 %! endfunction |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
128 %! |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
129 %! 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
|
130 %! 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
|
131 %! 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
|
132 %! [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
|
133 %! val = (x-.5).^2 + (y-.5).^2 + (z-.5).^2; |
22790 | 134 %! figure (); # Open another figure window |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
135 %! |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
136 %! subplot (2,2,1); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
137 %! view (-38, 20); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
138 %! [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
|
139 %! hp = patch ("Faces", fac, "Vertices", vert, "FaceVertexCData", cdat); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
140 %! title ("without isonormals"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
141 %! isofinish (hp); |
22405
81387a85a403
isonormals.m: Matlab compatibility in demos (bug #48873).
Markus Mützel <markus.muetzel@gmx.de>
parents:
22323
diff
changeset
|
142 %! 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
|
143 %! |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
144 %! subplot (2,2,2); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
145 %! view (-38, 20); |
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 ("patch modified by isonormals"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
148 %! isonormals (x, y, z, val, hp); # Directly modify patch |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
149 %! isofinish (hp); |
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,3); |
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 %! 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
|
155 %! 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
|
156 %! title ('set "VertexNormals" from isonormals'); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
157 %! isofinish (hp); |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
158 %! |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
159 %! subplot (2,2,4); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
160 %! view (-38, 20); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
161 %! hp = patch ("Faces", fac, "Vertices", vert, "FaceVertexCData", cdat); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
162 %! 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
|
163 %! title ('patch modified by isonormals (..., "negate")'); |
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 |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
166 %!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
|
167 %! [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
|
168 %! 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
|
169 %! [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
|
170 |
9119
3b810beddfa6
Added help texts and tests.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
9110
diff
changeset
|
171 %!test |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
172 %! 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
|
173 %! 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
|
174 |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
175 %!test |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
176 %! 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
|
177 %! 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
|
178 %! assert (np, -nn); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
179 |
22149
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
180 %!test |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
181 %! [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
|
182 %! 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
|
183 %! [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
|
184 %! 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
|
185 %! dirn = vert ./ vn; |
ba8a9d2934c7
Point isonormals towards lower values for Matlab compatibility (bug #48552).
Markus Muetzel <markus.muetzel@gmx.de>
parents:
22142
diff
changeset
|
186 %! 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
|
187 |
22790 | 188 ## Test input validation |
189 %!error isonormals () | |
190 %!error isonormals (1) | |
191 %!error isonormals (1,2,3) | |
192 %!error isonormals (1,2,3,4) | |
193 %!error isonormals (1,2,3,4,5,6) | |
194 %!error <Unknown option 'foo'> isonormals (x, y, z, val, vert, "foo") | |
195 %!error <must be a list of vertices> isonormals (1, {1}) | |
196 %!error <must be a list of vertices> isonormals (1, [1 2 3 4]) | |
197 %!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
|
198 ## Test validation of private function __interp_cube__ |
22790 | 199 %!error <X, Y, Z have unequal dimensions> isonormals ({x}, y, z, val, vert) |
200 %!error <X, Y, Z have unequal dimensions> isonormals (x, {y}, z, val, vert) | |
201 %!error <X, Y, Z have unequal dimensions> isonormals (x, y, {z}, val, vert) | |
202 %!error <X, Y, Z have unequal dimensions> isonormals (x, y, z(1), val, vert) | |
203 %!error <X, Y, Z have unequal dimensions> isonormals (x(:), y(:), z, val, vert) | |
204 %!error <VAL dimensions must match those of X, Y, and Z> isonormals (1, 2, 3, val, vert) |