MATLAB: How to plot contour of an isovalue of volume data using CONTOURSLICE on an arbitrary plane in MATLAB 7.1 (R14SP3)

MATLAB

I would like to plot the contour of volume data isovalues on an arbitrary plane that passes through the volume data.

Best Answer

The CONTOURSLICE function achieves this purpose. It has the option of creating contours of isovalues on a user defined surface within volume data. For more information regarding this function, enter the following at the MATLAB Command Prompt:
doc contourslice
The code below illustrates an example of how to plot a isovalue contour on a user defined surface. In this case, the surface is a plane that has been defined by an origin, and two 3-space vectors. The plane passes through this origin, and satisfies the following expression
P + alpha * v1 + beta * v2
where P is the origin, v1 and v2 are vectors, and alpha and beta are scalar values that define the scaling of the vectors v1 and v2. The example also includes use of the 'CLim' property to adjust the color scale of the isosurface.
% Import data to be analyzed
[x,y,z,v] = flow;
% Create an isosurface of the data at v = -3
% with a color gradient in the x direction
[faces,verts,colors] = isosurface(x,y,z,v,-3,x);
% Display the isosurface on an axes
p = patch('Vertices', verts, 'Faces', faces, ...
'FaceVertexCData', colors, ...
'FaceColor','interp', ...
'edgecolor', 'interp')
set(gca, 'CLim', [3 6])
% Set the face transparency of objects in the current axes to 50%
alpha(0.5)
hold on
% Find the bounding box limits for the volume data
xmin = min(x(:));
xmax = max(x(:));
ymin = min(y(:));
ymax = max(y(:));
zmin = min(z(:));
zmax = max(z(:));
% Select a point that the slice plane will pass through
P = [5 0 0]'
% Create direction vectors to define the slice plane
v1 = [1 1 0]'
v2 = [1 0 1]'
% Create a matrix of the j and k directions of the vectors defining the
% plane
V1 = [v1(2:3) v2(2:3)];
% Determine the location of the plane origin in relation to the bounding
% box of the volume data
b1 = [ymin; zmin] - P(2:3);
b2 = [ymax; zmax] - P(2:3);
% Solve for which alpha and beta values will solve the following equation
%

% P + alpha * v1 + beta * v2 = [x, ymin, zmin]'
% P + alpha * v1 + beta * v2 = [x, ymax, zmax]'
%
% This will provide the bounds for limits on ranges of alpha and beta
alpha_beta = [V1\b1 V1\b2];
% We do not yet know the x value, but the alpha and beta values from the
% above statement will be used to calculate it.
% Calculate the change in alpha and beta required to form a grid with 10000
% regular elements
delta_alpha = (alpha_beta(1,2) - alpha_beta(1,1))/100;
delta_beta = (alpha_beta(2,2) - alpha_beta(2,1))/100;
% Create the array of necessary alpha and beta value grids
[A B] = meshgrid(alpha_beta(1,1):delta_alpha:alpha_beta(1,2), ...
alpha_beta(2,1):delta_beta:alpha_beta(2,2));
% Calculate the values of x, y, and z for each alpha and beta value in the
% grid.
xi = A*v1(1) + B*v2(1) + P(1);
yi = A*v1(2) + B*v2(2) + P(2);
zi = A*v1(3) + B*v2(3) + P(3);
% Use the CONTOURSLICE function to create a contour of the volume data
% along the surface defined by the points contained in xi, yi, and zi, at a
% an isovalue of -3
h = contourslice(x,y,z,v,xi, yi, zi, [-3 -3]);
view(3)
Related Question