Mercurial > octave-nkf
comparison scripts/plot/draw/surfl.m @ 17572:7bb76a22cde1
maint: Split scripts/plot directory into 4 pieces.
scripts/gui : user-interface functions
scripts/plot/appearance : functions controlling plot appearance
scripts/plot/draw : plotting functions which produce graphs
scripts/plot/util : low-level plotting functions and utilities.
* scripts/gui/guidata.m, scripts/gui/guihandles.m, scripts/gui/module.mk,
scripts/gui/private/__file_filter__.m,
scripts/gui/private/__fltk_file_filter__.m,
scripts/gui/private/__is_function__.m, scripts/gui/private/__uigetdir_fltk__.m,
scripts/gui/private/__uigetfile_fltk__.m,
scripts/gui/private/__uiobject_split_args__.m,
scripts/gui/private/__uiputfile_fltk__.m, scripts/gui/uicontextmenu.m,
scripts/gui/uicontrol.m, scripts/gui/uigetdir.m, scripts/gui/uigetfile.m,
scripts/gui/uimenu.m, scripts/gui/uipanel.m, scripts/gui/uipushtool.m,
scripts/gui/uiputfile.m, scripts/gui/uiresume.m, scripts/gui/uitoggletool.m,
scripts/gui/uitoolbar.m, scripts/gui/uiwait.m, scripts/gui/waitbar.m,
scripts/gui/waitforbuttonpress.m: Moved from scripts/plot to scripts/gui
* scripts/plot/appearance/__clabel__.m,
scripts/plot/appearance/__getlegenddata__.m, scripts/plot/appearance/axis.m,
scripts/plot/appearance/box.m, scripts/plot/appearance/caxis.m,
scripts/plot/appearance/clabel.m, scripts/plot/appearance/daspect.m,
scripts/plot/appearance/diffuse.m, scripts/plot/appearance/grid.m,
scripts/plot/appearance/gtext.m, scripts/plot/appearance/hidden.m,
scripts/plot/appearance/legend.m,
scripts/plot/appearance/orient.m, scripts/plot/appearance/pbaspect.m,
scripts/plot/appearance/private/__axis_label__.m,
scripts/plot/appearance/private/__axis_limits__.m,
scripts/plot/appearance/shading.m, scripts/plot/appearance/specular.m,
scripts/plot/appearance/text.m, scripts/plot/appearance/title.m,
scripts/plot/appearance/view.m, scripts/plot/appearance/whitebg.m,
scripts/plot/appearance/xlabel.m, scripts/plot/appearance/xlim.m,
scripts/plot/appearance/ylabel.m, scripts/plot/appearance/ylim.m,
scripts/plot/appearance/zlabel.m, scripts/plot/appearance/zlim.m:
Moved from scripts/plot to subdir appearance.
* scripts/plot/draw/area.m, scripts/plot/draw/bar.m, scripts/plot/draw/barh.m,
scripts/plot/draw/colorbar.m, scripts/plot/draw/comet.m,
scripts/plot/draw/comet3.m, scripts/plot/draw/compass.m,
scripts/plot/draw/contour.m, scripts/plot/draw/contour3.m,
scripts/plot/draw/contourc.m, scripts/plot/draw/contourf.m,
scripts/plot/draw/cylinder.m, scripts/plot/draw/ellipsoid.m,
scripts/plot/draw/errorbar.m, scripts/plot/draw/ezcontour.m,
scripts/plot/draw/ezcontourf.m, scripts/plot/draw/ezmesh.m,
scripts/plot/draw/ezmeshc.m, scripts/plot/draw/ezplot.m,
scripts/plot/draw/ezplot3.m, scripts/plot/draw/ezpolar.m,
scripts/plot/draw/ezsurf.m, scripts/plot/draw/ezsurfc.m,
scripts/plot/draw/feather.m, scripts/plot/draw/fill.m,
scripts/plot/draw/fplot.m, scripts/plot/draw/hist.m,
scripts/plot/draw/isocolors.m, scripts/plot/draw/isonormals.m,
scripts/plot/draw/isosurface.m, scripts/plot/draw/line.m,
scripts/plot/draw/loglog.m, scripts/plot/draw/loglogerr.m,
scripts/plot/draw/mesh.m, scripts/plot/draw/meshc.m, scripts/plot/draw/meshz.m,
scripts/plot/draw/pareto.m,
scripts/plot/draw/patch.m, scripts/plot/draw/pcolor.m,
scripts/plot/draw/peaks.m, scripts/plot/draw/pie.m, scripts/plot/draw/pie3.m,
scripts/plot/draw/plot.m, scripts/plot/draw/plot3.m,
scripts/plot/draw/plotmatrix.m, scripts/plot/draw/plotyy.m,
scripts/plot/draw/polar.m, scripts/plot/draw/private/__add_datasource__.m,
scripts/plot/draw/private/__bar__.m, scripts/plot/draw/private/__contour__.m,
scripts/plot/draw/private/__errcomm__.m,
scripts/plot/draw/private/__errplot__.m,
scripts/plot/draw/private/__ezplot__.m,
scripts/plot/draw/private/__interp_cube__.m,
scripts/plot/draw/private/__line__.m,
scripts/plot/draw/private/__marching_cube__.m,
scripts/plot/draw/private/__patch__.m, scripts/plot/draw/private/__pie__.m,
scripts/plot/draw/private/__plt__.m, scripts/plot/draw/private/__quiver__.m,
scripts/plot/draw/private/__scatter__.m, scripts/plot/draw/private/__stem__.m,
scripts/plot/draw/quiver.m, scripts/plot/draw/quiver3.m,
scripts/plot/draw/rectangle.m, scripts/plot/draw/ribbon.m,
scripts/plot/draw/rose.m, scripts/plot/draw/scatter.m,
scripts/plot/draw/scatter3.m, scripts/plot/draw/semilogx.m,
scripts/plot/draw/semilogxerr.m, scripts/plot/draw/semilogy.m,
scripts/plot/draw/semilogyerr.m, scripts/plot/draw/shrinkfaces.m,
scripts/plot/draw/slice.m, scripts/plot/draw/sombrero.m,
scripts/plot/draw/sphere.m, scripts/plot/draw/stairs.m,
scripts/plot/draw/stem.m, scripts/plot/draw/stem3.m,
scripts/plot/draw/stemleaf.m, scripts/plot/draw/surf.m,
scripts/plot/draw/surface.m, scripts/plot/draw/surfc.m,
scripts/plot/draw/surfl.m, scripts/plot/draw/surfnorm.m,
scripts/plot/draw/tetramesh.m, scripts/plot/draw/trimesh.m,
scripts/plot/draw/triplot.m, scripts/plot/draw/trisurf.m,
scripts/plot/draw/waterfall.m: Moved from plot/ to subdir draw.
* scripts/plot/util/__actual_axis_position__.m,
scripts/plot/util/__default_plot_options__.m,
scripts/plot/util/__gnuplot_drawnow__.m,
scripts/plot/util/__next_line_color__.m,
scripts/plot/util/__next_line_style__.m,
scripts/plot/util/__plt_get_axis_arg__.m, scripts/plot/util/__pltopt__.m,
scripts/plot/util/allchild.m, scripts/plot/util/ancestor.m,
scripts/plot/util/axes.m, scripts/plot/util/cla.m, scripts/plot/util/clf.m,
scripts/plot/util/close.m, scripts/plot/util/closereq.m,
scripts/plot/util/colstyle.m, scripts/plot/util/copyobj.m,
scripts/plot/util/figure.m, scripts/plot/util/findall.m,
scripts/plot/util/findfigs.m, scripts/plot/util/findobj.m,
scripts/plot/util/gca.m, scripts/plot/util/gcbf.m, scripts/plot/util/gcbo.m,
scripts/plot/util/gcf.m, scripts/plot/util/gco.m, scripts/plot/util/ginput.m,
scripts/plot/util/gnuplot_binary.in, scripts/plot/util/graphics_toolkit.m,
scripts/plot/util/hdl2struct.m, scripts/plot/util/hggroup.m,
scripts/plot/util/hold.m, scripts/plot/util/isaxes.m,
scripts/plot/util/isfigure.m, scripts/plot/util/ishghandle.m,
scripts/plot/util/ishold.m, scripts/plot/util/isprop.m,
scripts/plot/util/linkprop.m, scripts/plot/util/meshgrid.m,
scripts/plot/util/ndgrid.m,
scripts/plot/util/newplot.m, scripts/plot/util/print.m,
scripts/plot/util/printd.m, scripts/plot/util/private/__add_default_menu__.m,
scripts/plot/util/private/__fltk_ginput__.m,
scripts/plot/util/private/__fltk_print__.m,
scripts/plot/util/private/__ghostscript__.m,
scripts/plot/util/private/__gnuplot_get_var__.m,
scripts/plot/util/private/__gnuplot_ginput__.m,
scripts/plot/util/private/__gnuplot_has_feature__.m,
scripts/plot/util/private/__gnuplot_has_terminal__.m,
scripts/plot/util/private/__gnuplot_open_stream__.m,
scripts/plot/util/private/__gnuplot_print__.m,
scripts/plot/util/private/__gnuplot_version__.m,
scripts/plot/util/private/__go_draw_axes__.m,
scripts/plot/util/private/__go_draw_figure__.m,
scripts/plot/util/private/__print_parse_opts__.m,
scripts/plot/util/private/__tight_eps_bbox__.m, scripts/plot/util/refresh.m,
scripts/plot/util/refreshdata.m, scripts/plot/util/saveas.m,
scripts/plot/util/shg.m, scripts/plot/util/struct2hdl.m,
scripts/plot/util/subplot.m: Moved from plot to subdir util.
* etc/HACKING: Updated directory structure info.
* scripts/Makefile.am, scripts/plot/appearance/module.mk,
scripts/plot/draw/module.mk, scripts/plot/util/module.mk:
Added new directories to build system.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 04 Oct 2013 17:09:08 -0700 |
parents | scripts/plot/surfl.m@326af26556ea |
children | d63878346099 |
comparison
equal
deleted
inserted
replaced
17571:6e4ea5c8a4bb | 17572:7bb76a22cde1 |
---|---|
1 ## Copyright (C) 2009-2012 Kai Habel | |
2 ## | |
3 ## This file is part of Octave. | |
4 ## | |
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 | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Function File} {} surfl (@var{z}) | |
21 ## @deftypefnx {Function File} {} surfl (@var{x}, @var{y}, @var{z}) | |
22 ## @deftypefnx {Function File} {} surfl (@dots{}, @var{lsrc}) | |
23 ## @deftypefnx {Function File} {} surfl (@var{x}, @var{y}, @var{z}, @var{lsrc}, @var{P}) | |
24 ## @deftypefnx {Function File} {} surfl (@dots{}, "cdata") | |
25 ## @deftypefnx {Function File} {} surfl (@dots{}, "light") | |
26 ## @deftypefnx {Function File} {} surfl (@var{hax}, @dots{}) | |
27 ## @deftypefnx {Function File} {@var{h} =} surfl (@dots{}) | |
28 ## | |
29 ## Plot a 3-D surface using shading based on various lighting models. | |
30 ## | |
31 ## The surface mesh is plotted using shaded rectangles. The vertices of the | |
32 ## rectangles [@var{x}, @var{y}] are typically the output of @code{meshgrid}. | |
33 ## over a 2-D rectangular region in the x-y plane. @var{z} determines the | |
34 ## height above the plane of each vertex. If only a single @var{z} matrix is | |
35 ## given, then it is plotted over the meshgrid | |
36 ## @code{@var{x} = 1:columns (@var{z}), @var{y} = 1:rows (@var{z})}. | |
37 ## Thus, columns of @var{z} correspond to different @var{x} values and rows | |
38 ## of @var{z} correspond to different @var{y} values. | |
39 ## | |
40 ## The default lighting mode @qcode{"cdata"}, changes the cdata property of the | |
41 ## surface object to give the impression of a lighted surface. | |
42 ## @strong{Warning:} The alternative mode @qcode{"light"} mode which creates a | |
43 ## light object to illuminate the surface is not implemented (yet). | |
44 ## | |
45 ## The light source location can be specified using @var{lsrc}. It can be given | |
46 ## as a 2-element vector [azimuth, elevation] in degrees, or as a 3-element | |
47 ## vector [lx, ly, lz]. The default value is rotated 45 degrees | |
48 ## counterclockwise to the current view. | |
49 ## | |
50 ## The material properties of the surface can specified using a 4-element | |
51 ## vector @var{P} = [@var{AM} @var{D} @var{SP} @var{exp}] which defaults to | |
52 ## @var{p} = [0.55 0.6 0.4 10]. | |
53 ## | |
54 ## @table @asis | |
55 ## @item @qcode{"AM"} strength of ambient light | |
56 ## | |
57 ## @item @qcode{"D"} strength of diffuse reflection | |
58 ## | |
59 ## @item @qcode{"SP"} strength of specular reflection | |
60 ## | |
61 ## @item @qcode{"EXP"} specular exponent | |
62 ## @end table | |
63 ## | |
64 ## If the first argument @var{hax} is an axes handle, then plot into this axis, | |
65 ## rather than the current axes returned by @code{gca}. | |
66 ## | |
67 ## The optional return value @var{h} is a graphics handle to the created | |
68 ## surface object. | |
69 ## | |
70 ## Example: | |
71 ## | |
72 ## @example | |
73 ## @group | |
74 ## colormap (bone (64)); | |
75 ## surfl (peaks); | |
76 ## shading interp; | |
77 ## @end group | |
78 ## @end example | |
79 ## @seealso{diffuse, specular, surf, shading, colormap, caxis} | |
80 ## @end deftypefn | |
81 | |
82 ## Author: Kai Habel <kai.habel@gmx.de> | |
83 | |
84 function h = surfl (varargin) | |
85 | |
86 [hax, varargin, nargin] = __plt_get_axis_arg__ ("surfl", varargin{:}); | |
87 | |
88 if (nargin == 0) | |
89 print_usage (); | |
90 endif | |
91 | |
92 ## Check for lighting type. | |
93 use_cdata = true; | |
94 if (ischar (varargin{end})) | |
95 switch (tolower (varargin{end})) | |
96 case "light" | |
97 warning ("surfl: light method not supported (yet), using cdata method instead"); | |
98 ## This can be implemented when light objects are supported. | |
99 use_cdata = false; | |
100 case "cdata" | |
101 use_cdata = true; | |
102 otherwise | |
103 error ("surfl: unknown lighting method"); | |
104 endswitch | |
105 varargin(end) = []; | |
106 endif | |
107 | |
108 ## Check for reflection properties argument. | |
109 ## | |
110 ## r = [ambient light strength, | |
111 ## diffuse reflection strength, | |
112 ## specular reflection strength, | |
113 ## specular shine] | |
114 if (isnumeric (varargin{end}) && length (varargin{end}) == 4) | |
115 r = varargin{end}; | |
116 varargin(end) = []; | |
117 else | |
118 ## Default values. | |
119 r = [0.55, 0.6, 0.4, 10]; | |
120 endif | |
121 | |
122 ## Check for light vector (lv) argument. | |
123 have_lv = false; | |
124 if (isnumeric (varargin{end})) | |
125 len = numel (varargin{end}); | |
126 lastarg = varargin{end}; | |
127 if (len == 3) | |
128 lv = lastarg; | |
129 varargin(end) = []; | |
130 have_lv = true; | |
131 elseif (len == 2) | |
132 [lv(1), lv(2), lv(3)] = sph2cart ((lastarg(1) - 90) * pi/180, | |
133 lastarg(2) * pi/180, | |
134 1.0); | |
135 varargin(end) = []; | |
136 have_lv = true; | |
137 endif | |
138 endif | |
139 | |
140 oldfig = []; | |
141 if (! isempty (hax)) | |
142 oldfig = get (0, "currentfigure"); | |
143 endif | |
144 unwind_protect | |
145 hax = newplot (hax); | |
146 | |
147 htmp = surface (varargin{:}); | |
148 if (! ishold (hax)) | |
149 set (hax, "view", [-37.5, 30], | |
150 "xgrid", "on", "ygrid", "on", "zgrid", "on", "clim", [0 1]); | |
151 endif | |
152 | |
153 ## Get view vector (vv). | |
154 [az, el] = view (); | |
155 vv = sph2cart ((az - 90) * pi/180.0, el * pi/180.0, 1.0); | |
156 | |
157 if (! have_lv) | |
158 ## Calculate light vector (lv) from view vector. | |
159 phi = pi / 4; # 45 degrees | |
160 R = [cos(phi), -sin(phi), 0; | |
161 sin(phi), cos(phi), 0; | |
162 0, 0, 1]; | |
163 lv = (R * vv.').'; | |
164 endif | |
165 | |
166 vn = get (htmp, "vertexnormals"); | |
167 dar = get (hax, "plotboxaspectratio"); | |
168 vn(:,:,1) *= dar(1); | |
169 vn(:,:,2) *= dar(2); | |
170 vn(:,:,3) *= dar(3); | |
171 | |
172 ## Normalize vn. | |
173 vn ./= repmat (sqrt (sumsq (vn, 3)), [1, 1, 3]); | |
174 [nr, nc] = size (get (htmp, "zdata")); | |
175 | |
176 ## Ambient, diffuse, and specular term. | |
177 cdata = ( r(1) * ones (nr, nc) | |
178 + r(2) * diffuse (vn(:,:,1), vn(:,:,2), vn(:,:,3), lv) | |
179 + r(3) * specular (vn(:,:,1), vn(:,:,2), vn(:,:,3), lv, vv, r(4))); | |
180 cdata ./= sum (r(1:3)); | |
181 | |
182 set (htmp, "cdata", cdata); | |
183 | |
184 unwind_protect_cleanup | |
185 if (! isempty (oldfig)) | |
186 set (0, "currentfigure", oldfig); | |
187 endif | |
188 end_unwind_protect | |
189 | |
190 if (nargout > 0) | |
191 h = htmp; | |
192 endif | |
193 | |
194 endfunction | |
195 | |
196 | |
197 %!demo | |
198 %! clf; | |
199 %! [X,Y,Z] = sombrero (); | |
200 %! colormap (copper (64)); | |
201 %! surfl (X,Y,Z); | |
202 %! shading interp; | |
203 %! title ('surfl() with defaults'); | |
204 | |
205 %!demo | |
206 %! clf; | |
207 %! [X,Y,Z] = sombrero (); | |
208 %! colormap (copper (64)); | |
209 %! [az, el] = view (); | |
210 %! surfl (X,Y,Z, [az+225,el], [0.2 0.6 0.4 25]); | |
211 %! shading interp; | |
212 %! title ('surfl() with lighting vector and material properties'); | |
213 |