comparison scripts/plot/isonormals.m @ 9119:3b810beddfa6

Added help texts and tests.
author Thomas Treichl <Thomas.Treichl@gmx.net>
date Tue, 14 Apr 2009 22:02:05 +0200
parents 22ae6b3411a7
children 2884758e265b
comparison
equal deleted inserted replaced
9118:308311b642b2 9119:3b810beddfa6
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details. 11 ## GNU General Public License for more details.
12 ## 12 ##
13 ## You should have received a copy of the GNU General Public License 13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; if not, see http://www.gnu.org/licenses/gpl.html. 14 ## along with this program; if not, see http://www.gnu.org/licenses/gpl.html.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} {[@var{n}] =} isonormals (@var{val}, @var{v})
18 ## @deftypefnx {Function File} {[@var{n}] =} isonormals (@var{val}, @var{p})
19 ## @deftypefnx {Function File} {[@var{n}] =} isonormals (@var{x}, @var{y}, @var{z}, @var{val}, @var{v})
20 ## @deftypefnx {Function File} {[@var{n}] =} isonormals (@var{x}, @var{y}, @var{z}, @var{val}, @var{p})
21 ## @deftypefnx {Function File} {[@var{n}] =} isonormals (@dots{}, "negate")
22 ## @deftypefnx {Function File} isonormals (@dots{}, @var{p})
15 ## 23 ##
24 ## If called with one output argument and the first input argument
25 ## @var{val} is a three--dimensional array that contains the data for an
26 ## isosurface geometry and the second input argument @var{v} keeps the
27 ## vertices of an isosurface then return the normals @var{n} in form of
28 ## a matrix with the same size than @var{v} at computed points
29 ## @command{[x, y, z] = meshgrid (1:l, 1:m, 1:n)}. The output argument
30 ## @var{n} can be taken to manually set @var{VertexNormals} of a patch.
31 ##
32 ## If called with further input arguments @var{x}, @var{y} and @var{z}
33 ## which are three--dimensional arrays with the same size than @var{val}
34 ## then the volume data is taken at those given points. Instead of the
35 ## vertices data @var{v} a patch handle @var{p} can be passed to this
36 ## function.
37 ##
38 ## If given the string input argument "negate" as last input argument
39 ## then compute the reverse vector normals of an isosurface geometry.
40 ##
41 ## If no output argument is given then directly redraw the patch that is
42 ## given by the patch handle @var{p}.
43 ##
44 ## For example,
45 ## @example
46 ## function [] = isofinish (p)
47 ## set (gca, "DataAspectRatioMode","manual","DataAspectRatio",[1 1 1]);
48 ## set (p, "VertexNormals", -get(p,"VertexNormals")); ## Revert normals
49 ## set (p, "FaceColor", "interp");
50 ## ## set (p, "FaceLighting", "phong");
51 ## ## light ("Position", [1 1 5]); ## Available with JHandles
52 ## endfunction
53 ##
54 ## N = 15; ## Increase number of vertices in each direction
55 ## iso = .4; ## Change isovalue to .1 to display a sphere
56 ## lin = linspace (0, 2, N);
57 ## [x, y, z] = meshgrid (lin, lin, lin);
58 ## c = abs ((x-.5).^2 + (y-.5).^2 + (z-.5).^2);
59 ## figure (); ## Open another figure window
60 ##
61 ## subplot (2, 2, 1); view (-38, 20);
62 ## [f, v, cdat] = isosurface (x, y, z, c, iso, y);
63 ## p = patch ("Faces", f, "Vertices", v, "FaceVertexCData", cdat, \
64 ## "FaceColor", "interp", "EdgeColor", "none");
65 ## isofinish (p); ## Call user function isofinish
66 ##
67 ## subplot (2, 2, 2); view (-38, 20);
68 ## p = patch ("Faces", f, "Vertices", v, "FaceVertexCData", cdat, \
69 ## "FaceColor", "interp", "EdgeColor", "none");
70 ## isonormals (x, y, z, c, p); ## Directly modify patch
71 ## isofinish (p);
72 ##
73 ## subplot (2, 2, 3); view (-38, 20);
74 ## p = patch ("Faces", f, "Vertices", v, "FaceVertexCData", cdat, \
75 ## "FaceColor", "interp", "EdgeColor", "none");
76 ## n = isonormals (x, y, z, c, v); ## Compute normals of isosurface
77 ## set (p, "VertexNormals", n); ## Manually set vertex normals
78 ## isofinish (p);
79 ##
80 ## subplot (2, 2, 4); view (-38, 20);
81 ## p = patch ("Faces", f, "Vertices", v, "FaceVertexCData", cdat, \
82 ## "FaceColor", "interp", "EdgeColor", "none");
83 ## isonormals (x, y, z, c, v, "negate"); ## Use reverse directly
84 ## isofinish (p);
85 ## @end example
86 ##
87 ## @seealso {isosurface, isocolors, isocaps, marching_cube}
88 ##
89 ## @end deftypefn
90
16 ## Author: Martin Helm <martin@mhelm.de> 91 ## Author: Martin Helm <martin@mhelm.de>
17
18 ## usage: NORMALS = isonormals(X,Y,Z,V,VERT)
19 ## usage: NORMALS = isonormals(V,VERT)
20 ## usage: NORMALS = isonormals(V,P)
21 ## usage: NORMALS = isonormals(X,Y,Z,V,P)
22 ## usage: NORMALS = isonormals(...,'negate')
23 ## usage: isonormals(V,P)
24 ## usage: isonormals(X,Y,Z,V,P)
25 ##
26 92
27 function varargout = isonormals(varargin) 93 function varargout = isonormals(varargin)
28 na = nargin; 94 na = nargin;
29 negate = false; 95 negate = false;
30 if (ischar (varargin{nargin})) 96 if (ischar (varargin{nargin}))
74 varargout = {normals}; 140 varargout = {normals};
75 otherwise 141 otherwise
76 print_usage (); 142 print_usage ();
77 endswitch 143 endswitch
78 endfunction 144 endfunction
145
146 %!test
147 %! [x, y, z] = meshgrid (0:.5:2, 0:.5:2, 0:.5:2);
148 %! c = abs ((x-.5).^2 + (y-.5).^2 + (z-.5).^2);
149 %! [f, v, cdat] = isosurface (x, y, z, c, .4, y);
150 %! n = isonormals (x, y, z, c, v);
151 %! assert (size (v), size (n));
152 %!test
153 %! [x, y, z] = meshgrid (0:.5:2, 0:.5:2, 0:.5:2);
154 %! c = abs ((x-.5).^2 + (y-.5).^2 + (z-.5).^2);
155 %! [f, v, cdat] = isosurface (x, y, z, c, .4, y);
156 %! np = isonormals (x, y, z, c, v);
157 %! nn = isonormals (x, y, z, c, v, "negate");
158 %! assert (all (np == -nn));