3D body plot ( visualization )

Hi, I have little or no experience with volumetric data in MATLAB, I found next appropriated descriptions: http://www.mathworks.com/help/techdoc/ref/isonormals.html
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
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)
I expect to get body enclosed by the points where v = 1 , but I get then only small rectangles in place of function '1' that are not connected ( see attached picture ) Does anybody know what is the problem , how to draw 3D body from the x,y,z,v vectors ?
Thanks in advance.
image:

5 Comments

First: well written question.
Second:
If you separate the call to ISOSURFACE from the call to PATCH, what is the output from isosurface (size/shape)?
[f v] = isosurface(...
?
Hi Sean de Wolski,
Thank you for your reply. Sorry for maybe messy written description , I am sure the question is clear to draw solid body / 3D body enclosed by array of points ( x, y ,z ). Array v = 1 at the points , 0 else.
Code debugging:
I separated the call to isosurface(...) , the function displays:
ISOSURFACE: Computing triangles and vertices...
.............
ISOSURFACE: number of vertices = 90 , number of triangles = 120
f is array 120*3 double with large amount of non-zero values
v is array 90*3 double with large amount of non-zero values
What should that mean ?
I am just thinking why the points displayed separated and not enclosed to form solid body like in example at the end of :
http://www.mathworks.com/help/techdoc/ref/isonormals.html
?
isosurface(x,y,z,v,1e-5,'verbose') displays little green squares with center in the points where v = 1 but expecting enclosed by that points solid body.
What is a problem?
Thank you very much.
It must be how your data is stored in x,y,z. Does it change if you change the isovalue to 0? Should the output be convex? The output from ISOSURFACE looks like it could/should be correct (i.e. not wrong). Can you post your sample data in a matfile to somewhere?
"Does it change if you change the isovalue to 0?" - yes, when 0 then there is like a white circle inside square that drawn for each point , when 1e-2 then homogeneous square ( see attached pictures ).
http://fileslap.com/94q/fig_to_show2
http://fileslap.com/94r/fig_to_show3
"Should the output be convex?" , - I tryed delaunay , convhull and trisurf plot , but what is displayed is not smooth and not like a solid body. The output should be solid body with smooth surface enclosed as in next image:
http://fileslap.com/94s/plot_
"Can you post your sample data in a matfile to somewhere?" - I uploaded data_for_body.zip archive with 3 .mat files of data 125 on 125 on 125 for X,Y,Z,V from which the solid body should be plotted.
http://fileslap.com/94p/data_for_body
I am continuing to resolve the issue. I hope we will plot the solid body from X,Y,Z,V points soon...

Sign in to comment.

 Accepted Answer

The output from:
fv = isosurface(v,0);
patch(fv);
Is expected, i.e. each object (voxel) is being patched. Since you want to whole thing to be treated as one object, you need to use convhulln or DelaunayTri. If you did not want the output to be convex (concave shape), then you'll have to define a set of constraints to define your shape and/or manually create the object. Alpha shapes would be another approach too.
If it is convex, this will draw the convex hull for your data:
%Import the data:
x = importdata('X_data.mat');
y = importdata('Y_data.mat');
z = importdata('Z_data.mat');
v = importdata('V_data.mat');
idx = logical(v); %which indices?
xidx = x(idx);
yidx = y(idx);
zidx = z(idx);
%Delaunay Triangulation
dt = DelaunayTri(xidx,yidx,zidx);
%Draw
tetramesh(dt,ones(size(dt)));

3 Comments

Thanks for answers, good support.
After triangulation and plotting by:
tri = delaunay3(x_,y_,z_);
trisurf(tri,x_,y_,z_);
I get next picture :
http://fileslap.com/94v/delaunay_2
After plotting by:
X = [x_(:) y_(:) z_(:)];
tetramesh(tri,X);
I get next picture:
http://fileslap.com/94w/delaunay_1
But the next picture is the target:
http://fileslap.com/94s/plot_
How can I get smoother , homogeneous rigid body enclosed by the points and not as I recently get with that triangulation attempt?
Maybe to increase resolution between points , maybe to pad additional?
Does anybody how to plot as in the target from the points?
Thanks in advance.
You could perhaps use SMOOTH3. However, the pictjure you're expecting is _not_ convex. Thus this approach won't work. You need to define your own constraints or use an alpha shape. I'd begin looking here:
http://www.mathworks.com/matlabcentral/fileexchange/?term=alpha+shape
Thank you very much for your help. That is fine solution.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!