Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Convert 3D coordinates into a mesh using surf2stl

410 views
Skip to first unread message

Zubin

unread,
Feb 24, 2010, 3:25:01 AM2/24/10
to
Hi,

I have a CT data set where I have managed to use thresholding to
delineate my object on every slice and I have used bwtraceboundary to
generate a contour (x and y coordinates) around the structure and save
it for each slice. I increment a z value for each CT slice so
basically I
have a Nx3 array of x, y and z coordinates which define my complete
object in 3D.

I want to export this to some 3D package so I can manipulate it and
clean it up and there is a matlab code available to do this, called
surf2stl (stl is a stereolithography file format) but I can't figure
out how to organize my data to feed it to this function.

Should I organize my data in some other way to achieve this?
Here is the help section of the surf2stl code:

SURF2STL Write STL file from surface data.
SURF2STL('filename',X,Y,Z) writes a stereolithography (STL) file
for a surface with geometry defined by three matrix arguments, X,
Y
and Z. X, Y and Z must be two-dimensional arrays with the same
size.

SURF2STL('filename',x,y,Z), uses two vector arguments replacing
the first two matrix arguments, which must have length(x) = n and
length(y) = m where [m,n] = size(Z). Note that x corresponds to
the columns of Z and y corresponds to the rows.

SURF2STL('filename',dx,dy,Z) uses scalar values of dx and dy to
specify the x and y spacing between grid points.

SURF2STL(...,'mode') may be used to specify the output format.

'binary' - writes in STL binary format (default)
'ascii' - writes in STL ASCII format

Example:

surf2stl('test.stl',1,1,peaks);

See also SURF.

Author: Bill McDonald, 02-20-04


Any help will be greatly appreciated. Thanks a lot!!!!!

Zubin.

Luigi Giaccari

unread,
Feb 28, 2010, 1:43:05 PM2/28/10
to

Liana

unread,
May 7, 2011, 2:35:06 AM5/7/11
to
I have the same question. Did someone can explain how to properly use 'surf2stl' for 3 column vectors X, Y, Z (Z is not the function of X and Y). In particular, it's not clear "why X, Y and Z must be two-dimensional arrays" as it is mentioned in the help section of 'surf2stl'.

Thanks.

Rebecca

unread,
Nov 22, 2011, 11:14:08 PM11/22/11
to
Hi Zubin,

Have you figured out the problem yet? I came across the problem, but couldn't find any useful tutorials online. I realized that this post was a while ago, hope you have resolved the issue. if so, could you please give me some tips?

Thank you!

Best,

Monica

unread,
Jun 29, 2012, 7:03:09 AM6/29/12
to
Hi! i have the same question. Why do X,Y,Z have to be bidiminsional? Did you figure this out?

thank you!

Monica

"Lulu" wrote in message <iq2p6q$iu3$1...@newscl01ah.mathworks.com>...

ScottB

unread,
Jun 29, 2012, 11:49:07 AM6/29/12
to
Zubin,

You just need a meshgrid. An example:

[X,Y] = meshgrid(-2:.2:2, -4:.4:4);
Z = X .* exp(-X.^2 - Y.^2);
surf(X,Y,Z)
surf2stl('test.stl',X,Y,Z)

hth,
ScottB
0 new messages