%CDS301
%example of stream tubes
%use Matlab build-in wind data
%combine the methods of "slice", "contourslice","streamline"

clear; clf

%load the 3-D vector data
load wind

%find the limit
xmin=min(x(:));
xmax=max(x(:));
ymin=min(y(:));
ymax=max(y(:));
zmin=min(z(:));

%Z value for slice and streamtube plane
alt=2.0

%total stream speed
wind_speed=sqrt(u.^2+v.^2+w.^2);

%draw slice
hslice=slice(x,y,z,wind_speed,xmax,ymin,alt);
set(hslice,'FaceColor','interp','EdgeColor','none')
colormap hsv(16)

%add contour lines onto the slices
color_lim=caxis;
cont_intervals=linspace(color_lim(1),color_lim(2),17);
hcont=contourslice(x,y,z,wind_speed,xmax,ymin,alt,cont_intervals,'linear');
set(hcont,'EdgeColor',[0.4,0.4,0.4],'LineWidth',1)

%define the starting points for stream tubes
[sx,sy,sz]=meshgrid(xmin,20:3:50,alt);
htubes=streamtube(x,y,z,u,v,w,sx,sy,sz,[1.25 30]);
% the value of 1.25 scale with width, to emphasize the divergence
% default width is the divergence
% the value of "30" specifies the number of points laing the circumference
set(htubes,'EdgeColor','none','FaceColor','r','AmbientStrength',0.5);

%define the view
view(-100,30)
axis(volumebounds(x,y,z,wind_speed))
set(gca,'Projection','perspective')
camlight left




