St Sht
St Sht

Reputation: 19

3D body plot in matlab ( volume visualization )

I have little or no experience with volumetric data in MATLAB, I need to complete next task: I have 3 vectors ( rows ):

x_ = vector(1:smpl:max_row,1);

y_ = vector(1:smpl:max_row,2);

z_ = vector(1:smpl:max_row,3);

that are samples from large 3 columns array vector with height max_row. x_ , y_ , z_ are points of 3D figure - surface points of the figure ( volume ). They represent 3D body that should be drawn in matlab.

I created linear grid:

%linear grid

a = -1.1:step:(-1.1+step*(length(x_)-1));

b = -1.1:step:(-1.1+step*(length(y_)-1));

c = -1.1:step:(-1.1+step*(length(z_)-1));


[x,y,z] = meshgrid(-1.1:step:(-1.1+step*(length(x_)-1)));

and also I create array v length(x_)*length(x_)*length(x_) that contains '1' in cells that are of 3D body representation function points and '0' another.

I tryied to make interpolation:

vi = interp3(x,y,z,v,x,y,z,'nearest');

but then vi = v that I've already created.

Now I need to plot the v array on 3D and form 3D body like in

http://www.mathworks.com/help/techdoc/ref/isonormals.html

for example.

I make that next way:

%plotting:

figure

p = patch(isosurface(x,y,z,v,1e-5,'verbose'),'FaceColor','green','EdgeColor','none');

grid on;

isonormals(v,p);

daspect([1 1 1])

view(3); 

axis tight;

camproj perspective;

camlight

lighting gouraud

colormap(hsv)

but I get then only small rectangles in place of function '1' that are not connected like in picture that is attached. I expect solid body enclosed by that points to be plotted.

Does anybody know what is the problem , how to draw 3D body from the x,y,z,v arrays ?

Thanks in advance.

image:

https://i.sstatic.net/2JZiK.jpg

Upvotes: 0

Views: 7157

Answers (1)

tim
tim

Reputation: 10176

Try this, which will be a nice plot (it interpolates a bit though):

x = vector(1:smpl:max_row,1);
y = vector(1:smpl:max_row,2);
z = vector(1:smpl:max_row,3);

% Settings
displaySurface = 1;
displayPoints = 0;
xres = 800; % Resolution, the higher, the smoother
yres = 800;         
cm = 'default'; % Colormap

% Axes Limits
xmin = min(x); 
ymin = min(y);
xmax = max(x); 
ymax = max(y); 
xi = linspace(xmin, xmax, xres);
yi = linspace(ymin, ymax, yres);

% Figure
myfig = figure('Position', [200 200 800 600]);

rotate3d off
[XI, YI] = meshgrid(xi, yi);
ZI = griddata(x, y, z, XI, YI, 'cubic');
mesh(XI,YI,ZI);
colormap(cm)

if(displaySurface == 1)
    hold on;
    surf(XI, YI, ZI, 'EdgeColor', 'none');
end
hold on;
xlabel('x');
ylabel('y'); 
zlabel('z'); 
title('Title', 'FontWeight', 'bold');
xlim([xmin xmax])
ylim([ymin ymax])
grid off;

if(displayPoints == 1)
    hold on
    plot3(x, y, z,'marker','p','markerfacecolor','w','linestyle','none')
    hidden off 
end

Upvotes: 1

Related Questions