Mercurial > hg > octave-max
comparison scripts/plot/isosurface.m @ 11587:c792872f8942
all script files: untabify and strip trailing whitespace
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 20 Jan 2011 17:35:29 -0500 |
parents | fd0a3ac60b0e |
children | 0579a13f29a1 |
comparison
equal
deleted
inserted
replaced
11586:12df7854fa7c | 11587:c792872f8942 |
---|---|
29 ## @var{val} is a three--dimensional array that contains the data of an | 29 ## @var{val} is a three--dimensional array that contains the data of an |
30 ## isosurface geometry and the second input argument @var{iso} keeps the | 30 ## isosurface geometry and the second input argument @var{iso} keeps the |
31 ## isovalue as a scalar value then return a structure array @var{fv} | 31 ## isovalue as a scalar value then return a structure array @var{fv} |
32 ## that contains the fields @var{Faces} and @var{Vertices} at computed | 32 ## that contains the fields @var{Faces} and @var{Vertices} at computed |
33 ## points @command{[x, y, z] = meshgrid (1:l, 1:m, 1:n)}. The output | 33 ## points @command{[x, y, z] = meshgrid (1:l, 1:m, 1:n)}. The output |
34 ## argument @var{fv} can directly be taken as an input argument for the | 34 ## argument @var{fv} can directly be taken as an input argument for the |
35 ## @command{patch} function. | 35 ## @command{patch} function. |
36 ## | 36 ## |
37 ## If called with further input arguments @var{x}, @var{y} and @var{z} | 37 ## If called with further input arguments @var{x}, @var{y} and @var{z} |
38 ## which are three--dimensional arrays with the same size than @var{val} | 38 ## which are three--dimensional arrays with the same size than @var{val} |
39 ## then the volume data is taken at those given points. | 39 ## then the volume data is taken at those given points. |
74 ## @example | 74 ## @example |
75 ## N = 15; ## Increase number of vertices in each direction | 75 ## N = 15; ## Increase number of vertices in each direction |
76 ## iso = .4; ## Change isovalue to .1 to display a sphere | 76 ## iso = .4; ## Change isovalue to .1 to display a sphere |
77 ## lin = linspace (0, 2, N); | 77 ## lin = linspace (0, 2, N); |
78 ## [x, y, z] = meshgrid (lin, lin, lin); | 78 ## [x, y, z] = meshgrid (lin, lin, lin); |
79 ## c = abs ((x-.5).^2 + (y-.5).^2 + (z-.5).^2); | 79 ## c = abs ((x-.5).^2 + (y-.5).^2 + (z-.5).^2); |
80 ## figure (); ## Open another figure window | 80 ## figure (); ## Open another figure window |
81 ## | 81 ## |
82 ## subplot (2, 2, 1); view (-38, 20); | 82 ## subplot (2, 2, 1); view (-38, 20); |
83 ## [f, v] = isosurface (x, y, z, c, iso); | 83 ## [f, v] = isosurface (x, y, z, c, iso); |
84 ## p = patch ("Faces", f, "Vertices", v, "EdgeColor", "none"); | 84 ## p = patch ("Faces", f, "Vertices", v, "EdgeColor", "none"); |
85 ## set (gca, "PlotBoxAspectRatioMode","manual", "PlotBoxAspectRatio", [1 1 1]); | 85 ## set (gca, "PlotBoxAspectRatioMode","manual", "PlotBoxAspectRatio", [1 1 1]); |
86 ## # set (p, "FaceColor", "green", "FaceLighting", "phong"); | 86 ## # set (p, "FaceColor", "green", "FaceLighting", "phong"); |
87 ## # light ("Position", [1 1 5]); ## Available with the JHandles package | 87 ## # light ("Position", [1 1 5]); ## Available with the JHandles package |
150 endif | 150 endif |
151 [fvc.faces, fvc.vertices, fvc.facevertexcdata] = __marching_cube__ (x, y, z, val, iso, colors); | 151 [fvc.faces, fvc.vertices, fvc.facevertexcdata] = __marching_cube__ (x, y, z, val, iso, colors); |
152 else | 152 else |
153 [fvc.faces, fvc.vertices] = __marching_cube__ (x, y, z, val, iso); | 153 [fvc.faces, fvc.vertices] = __marching_cube__ (x, y, z, val, iso); |
154 endif | 154 endif |
155 | 155 |
156 if (isempty (fvc.vertices) || isempty (fvc.faces)) | 156 if (isempty (fvc.vertices) || isempty (fvc.faces)) |
157 warning ( "The resulting triangulation is empty" ); | 157 warning ( "The resulting triangulation is empty" ); |
158 endif | 158 endif |
159 | 159 |
160 switch (nargout) | 160 switch (nargout) |
161 case 0 | 161 case 0 |
162 ## plot the calculated surface | 162 ## plot the calculated surface |
163 newplot (); | 163 newplot (); |
164 if (calc_colors) | 164 if (calc_colors) |
165 pa = patch ("Faces", fvc.faces, "Vertices", fvc.vertices, | 165 pa = patch ("Faces", fvc.faces, "Vertices", fvc.vertices, |
166 "FaceVertexCData", fvc.facevertexcdata, | 166 "FaceVertexCData", fvc.facevertexcdata, |
167 "FaceColor", "flat", "EdgeColor", "none"); | 167 "FaceColor", "flat", "EdgeColor", "none"); |
168 else | 168 else |
169 pa = patch ("Faces", fvc.faces, "Vertices", fvc.vertices, | 169 pa = patch ("Faces", fvc.faces, "Vertices", fvc.vertices, |
170 "FaceColor", "g", "EdgeColor", "k"); | 170 "FaceColor", "g", "EdgeColor", "k"); |
171 endif | 171 endif |
172 if (! ishold ()) | 172 if (! ishold ()) |
173 set (gca(), "view", [-37.5, 30], | 173 set (gca(), "view", [-37.5, 30], |
174 "xgrid", "on", "ygrid", "on", "zgrid", "on"); | 174 "xgrid", "on", "ygrid", "on", "zgrid", "on"); |
216 | 216 |
217 %!demo | 217 %!demo |
218 %! clf | 218 %! clf |
219 %! [x,y,z] = meshgrid(-2:0.5:2, -2:0.5:2, -2:0.5:2); | 219 %! [x,y,z] = meshgrid(-2:0.5:2, -2:0.5:2, -2:0.5:2); |
220 %! v = x.^2 + y.^2 + z.^2; | 220 %! v = x.^2 + y.^2 + z.^2; |
221 %! isosurface (x, y, z, v, 1) | 221 %! isosurface (x, y, z, v, 1) |