1
## Copyright (C) 2007 Kai Habel, David Bateman
3
## This file is part of Octave.
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.
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.
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/>.
20
## @deftypefn {Function File} {} slice (@var{x}, @var{y}, @var{z}, @var{v}, @var{sx}, @var{sy}, @var{sz})
21
## @deftypefnx {Function File} {} slice (@var{x}, @var{y}, @var{z}, @var{v}, @var{xi}, @var{yi}, @var{zi})
22
## @deftypefnx {Function File} {} slice (@var{v}, @var{sx}, @var{sy}, @var{sz})
23
## @deftypefnx {Function File} {} slice (@var{v}, @var{xi}, @var{yi}, @var{zi})
24
## @deftypefnx {Function File} {@var{h} =} slice (@dots{})
25
## @deftypefnx {Function File} {@var{h} =} slice (@dots{}, @var{method})
26
## Plot slices of 3D data/scalar fields. Each element of the 3-dimensional
27
## array @var{v} represents a scalar value at a location given by the
28
## parameters @var{x}, @var{y}, and @var{z}. The parameters @var{x},
29
## @var{x}, and @var{z} are either 3-dimensional arrays of the same size
30
## as the array @var{v} in the "meshgrid" format or vectors. The
31
## parameters @var{xi}, etc respect a similar format to @var{x}, etc,
32
## and they represent the points at which the array @var{vi} is
33
## interpolated using interp3. The vectors @var{sx}, @var{sy}, and
34
## @var{sz} contain points of orthogonal slices of the respective axes.
36
## If @var{x}, @var{y}, @var{z} are omitted, they are assumed to be
37
## @code{x = 1:size (@var{v}, 2)}, @code{y = 1:size (@var{v}, 1)} and
38
## @code{z = 1:size (@var{v}, 3)}.
40
## @var{Method} is one of:
44
## Return the nearest neighbour.
46
## Linear interpolation from nearest neighbours.
48
## Cubic interpolation from four nearest neighbours (not implemented yet).
50
## Cubic spline interpolation---smooth first and second derivatives
51
## throughout the curve.
54
## The default method is @code{"linear"}.
55
## The optional return value @var{h} is a vector of handles to the
56
## surface graphic objects.
60
## [x, y, z] = meshgrid (linspace (-8, 8, 32));
61
## v = sin (sqrt (x.^2 + y.^2 + z.^2)) ./ (sqrt (x.^2 + y.^2 + z.^2));
62
## slice (x, y, z, v, [], 0, []);
63
## [xi, yi] = meshgrid (linspace (-7, 7));
65
## slice (x, y, z, v, xi, yi, zi);
67
## @seealso{interp3, surface, pcolor}
70
## Author: Kai Habel <kai.habel@gmx.de>
72
function h = slice (varargin)
77
if (ischar (varargin{end}))
78
method = varargin{end};
85
error ("slice: expect 3-dimensional array of values");
87
[nx, ny, nz] = size (v);
88
[x, y, z] = meshgrid (1:nx, 1:ny, 1:nz);
95
error ("slice: expect 3-dimensional array of values");
100
if (all ([isvector(x), isvector(y), isvector(z)]))
101
[x, y, z] = meshgrid (x, y, z);
102
elseif (ndims (x) == 3 && size_equal (x, y, z))
105
error ("slice: X, Y, Z size mismatch")
114
if (any ([isvector(sx), isvector(sy), isvector(sz)]))
116
elseif (ndims(sx) == 2 && size_equal (sx, sy, sz))
119
error ("slice: dimensional mismatch for (XI, YI, ZI) or (SX, SY, SZ)");
127
set (ax, "clim", [minv, maxv]);
130
ns = length (sx) + length (sy) + length (sz);
132
[ny, nx, nz] = size (v);
135
[xi, yi, zi] = meshgrid (squeeze (x(1,:,1)),
136
squeeze (y(:,1,1)), sz(i));
137
vz = squeeze (interp3 (x, y, z, v, xi, yi, zi, method));
138
tmp(sidx++) = surface (xi, yi, sz(i) * ones (size (yi)), vz);
143
for i = length(sy):-1:1
144
[xi, yi, zi] = meshgrid (squeeze (x(1,:,1)), sy(i), squeeze (z(1,1,:)));
145
vy = squeeze (interp3 (x, y, z, v, xi, yi, zi, method));
146
tmp(sidx++) = surface (squeeze (xi),
147
squeeze (sy(i) * ones (size (zi))),
153
for i = length(sx):-1:1
154
[xi, yi, zi] = meshgrid (sx(i), squeeze (y(:,1,1)), squeeze (z(1,1,:)));
155
vx = squeeze (interp3 (x, y, z, v, xi, yi, zi, method));
156
tmp(sidx++) = surface (squeeze (sx(i) * ones (size (zi))),
157
squeeze (yi), squeeze(zi), vx);
161
vi = interp3 (x, y, z, v, sx, sy, sz);
162
tmp = surface (sx, sy, sz, vi);
166
set (ax, "view", [-37.5, 30.0], "box", "off", "xgrid", "on",
167
"ygrid", "on", "zgrid", "on");
177
%! [x, y, z] = meshgrid (linspace (-8, 8, 32));
178
%! v = sin (sqrt (x.^2 + y.^2 + z.^2)) ./ (sqrt (x.^2 + y.^2 + z.^2));
179
%! slice (x, y, z, v, [], 0, []);
180
%! [xi, yi] = meshgrid (linspace (-7, 7));
182
%! slice (x, y, z, v, xi, yi, zi);