STL_Import: import function for STL files
STL_Import is a tool designed to import into MATLAB both binary and ASCII STL files.
This script is mainly a collage between file exchange file id 22409 and 3642, plus some other features that can be considered new.
SYNOPSIS:
- mode 1 (default)
[p,t,tnorm]=STL_Import(filename,mode) - mode 2
[v,tnorm])=STL_Import(filename,mode)
input:
- filename: string representing the name of the file
mode:
- mode=1 (if omitted is automatically set to one)
set the the output to:
output=[p,t,tnorm]
where:
- p=points (unique) of the model nx3 array
- t=triangles indexes of the model
- tnorm= normals of triangles
- mode=2
set the the output to:
output=[v,tnorm]
where:
- v= vertex (not unique points) of the model nx3 array. Each trhee points we have a triangle in consecutive order.
- tnorm= normals of triangles
EXAMPLES:
[pv,tnorm]=STL_Import('link1.stl',2);%MODE2
Author: Giaccari Luigi (giaccariluigi@msn.com)
Download Now
Popularity: 5% [?]
Related Posts
Comments
22 Comments on STL_Import: import function for STL files
-
Shehzad on
Thu, 24th Sep 2009 11:19
-
Andrei on
Sat, 10th Oct 2009 12:04
-
Edward on
Fri, 6th Nov 2009 02:14
-
Gav on
Thu, 12th Nov 2009 19:32
-
fran on
Sat, 5th Dec 2009 03:54
-
fran on
Tue, 8th Dec 2009 02:13
-
fran on
Tue, 8th Dec 2009 11:01
-
fran on
Wed, 23rd Dec 2009 09:55
-
adam on
Wed, 17th Mar 2010 23:42
Dear Sir Giaccari Luigi
Hope you are fine.
I am trying to process different information from an STL file. your STL_Import code has been of great help.
in mode ‘1′ we can extract
p
t
tnorm
what i want to do is to know that which tnorm vector belongs to which triangular facet from the STL file.
if i can get that information i will to process the idea that which triangular facet belongs to which surface based on the direction
of the normal and its comparison with the normals of the neighbor facets.
please reply me.
i will be greatly thankful to you sir.
with regards
Shehzad
[Reply]
Hi Luigi Giaccari,
I have a question.
which is the easier way to plot (to have a graphical representation) of the object that was loaded using this function.
Thnaks,
Andrei
[Reply]
Luigi Giaccari Reply:
October 10th, 2009 at 21:03
Very easy,
type in the command window:
help trisurf
or better:
doc trisurf
Bye
[Reply]
Hi Luigi Giaccari,
Thanks for sharing this m file. Right now I still couldn’t run this file, even though I have set “filename=’link1.stl’ ” after the first line. Matlab still gave me ‘invalid input number /mode setting’. Please kindly tell me the exact procedure how to run this program in MATLAB.
PS. I have link1.stl file and set the path in the MATLAB already.
Thanks a lot,
Edward
[Reply]
Paul Reply:
November 6th, 2009 at 22:18
Hi,
Maybe I can help you:
You don’t have to change anything in the file or to add some extra lines – you don’t even have to open it. You simply have to write in the Matlab – Window Command one of the following lines:
[p,t,tnorm]=STL_Import(‘link1.stl’,1);
[pv,tnorm]=STL_Import(‘link1.stl’,2);
and press enter.
For example if you have the file ‘c:\work\object1.stl’ and you want to have the unique points, triangle index and tnorm (you have to use mode 1) then write the following command in Window Command:
[p,t,tnorm]=STL_Import(‘c:\work\object1.stl’,1);
Regards,
Paul
PS: I hope that Luigi G won’t mind that I answer to this question. By the way: nice function. Thanks you Luigi.
[Reply]
Luigi Giaccari Reply:
November 6th, 2009 at 22:47
Paul’s answer is absolutely correct.
Thanks Paul
[Reply]
I was wondering, using your code, can i use it to view the stl code?…. and perhaps save it as a txt file?….
If not do you know where I can find it?….
[Reply]
Luigi Giaccari Reply:
November 15th, 2009 at 10:13
What do you mean “see the STL code”?
maybe you mean reading from binary and saving into ascii…
is that what you mean?
[Reply]
Gav Reply:
November 16th, 2009 at 09:54
yes, thats what i mean, read from binary to ascii!!! thanks
[Reply]
Luigi Giaccari Reply:
November 17th, 2009 at 11:36
You can use my function to read:
[p,t,tnorm]=STL_Import(’link1.stl’,1);
and this function to write:
http://www.mathworks.com/matlabcentral/fileexchange/20922-patch2stl
but I seuggest you to code your own function, using the “fprintf” command is pretty easy.
Luigi
i already developed the delaunay 3D triangulation and tri surface from the point cloud. but my problem is how to convert it into the STL file so that it can be read by the RP machine..? can u help me…?
[Reply]
Luigi Giaccari Reply:
December 5th, 2009 at 11:38
http://www.mathworks.com/matlabcentral/fileexchange/24400-stlexport
Luigi
[Reply]
sir..
i already download the file from the website that you give to me..
http://www.mathworks.com/matlabcentral/fileexchange/24400-stlexport
but i don’t understand what it mean by the “triangles_file”…
can u explain it …..
[Reply]
Luigi Giaccari Reply:
December 8th, 2009 at 09:23
triangles_file==t
nodes_files==p
I guess…
Luigi
[Reply]
mmm…
how about this example of surface reconstruction that i get from the matlab file exchange..
what is their triangles_file..?
for node_file..it is the file .MAT?
sorry sir.. i still new in matlab..
i want to try convert it to stl file so that i can fabricate it in RP machine..
[Reply]
Luigi Giaccari Reply:
December 8th, 2009 at 16:03
Dear fran
I told you all you need to do the job.
I can give you hints but I can not make your work.
If you want we can agree a reasonable payment and I will get your surface reconstruction work. I can get binary or ascii STL file, and you can get your rapid prototyping.
If you are interested contact me on my e-mail
Luigi
[Reply]
sir…
why we need the normal of the triangulation before convert it to stl file?
[Reply]
Luigi Giaccari Reply:
December 23rd, 2009 at 11:05
The STL format is defined as:
normal
p1(x,y,z)
p2(x,y,z)
p3(x,y,z)
that’s why we need the normal
[Reply]
Great .m file, really appreciate it.
My questions concerns plotting the .STL file.
I’ve used the following:
tri=delaunay(t,tnorm)
trisurf(tri,t,tnorm,p)
I receive the following error:
??? Error using ==> horzcat
CAT arguments dimensions are not consistent.
Error in ==> trisurf at 40
h = patch(‘faces’,tri,’vertices’,[x(:) y(:)
z(:)],’facevertexcdata’,c(:),…
I’m simply trying to the plot the output after running the program.
THANKS!
[Reply]
Tell me what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!
Include MATLAB code in your comment by doing the following:
<pre lang="MATLAB">
%insert code here
</pre>



















































Luigi Giaccari Reply:
September 24th, 2009 at 12:43
Dear Shehzad,
“what i want to do is to know that which tnorm vector belongs to which triangular facet from the STL file.
if
i can get that information i will to process the idea that which
triangular facet belongs to which surface based on the direction
of the normal and its comparison with the normals of the neighbor facets.”
Consider this:
is not unique lists of points taken from the STL files. The first trhee
points are the first STL facet, point 4 5 6 forms the second facet and
so on…
For example:
t=[ 1 10 15; 3 6 7]
means that the first facet is formed by points 1 10 15 and the second by points 3 6 7 (points are now stored in the p array).
This
means that the tnorm array stays the same in both cases. Mode 1 and
mode 2 are just 2 different way to describe a triangulation. Generally
mode one is better for mesh processing mode 2 for graphics.
If
you want the neigbourood triangles you need to use mode 1 and then get
edge to trianges connectivity. The new computational geometry toolbox
in R2009a may help you, if you don’t have it contact me and I will give
you something.
[Reply]