The 'stlTools' toolbox is a collection of functions, samples and demos to illustrate how to deal with STL files. Some of them are contributions published in Matlab Central and properly referenced here. This toolbox contains the following files:
(*) stlGetFormat: identifies the format of the STL file and returns 'binary' or 'ascii'. This file is inspired in the 'READ-stl' file written and published by Adam H. Aitkenhead
(*) stlReadAscii: reads an STL file written in ascii format. This file is inspired in the 'READ-stl' file written and published by Adam H. Aitkenhead
(*) stlReadBinary: reads an STL file written in binary format. This file is inspired in the 'READ-stl' file written and published by Adam H. Aitkenhead
(*) stlRead: uses 'stlGetFormat', 'stlReadAscii' and 'stlReadBinary' to make STL reading independent of the format of the file
(*) stlWrite: writes an STL file in 'ascii' or 'binary' formats. This is written and published by Sven Holcombe (*) stlSlimVerts: finds and removes duplicated vertices. This function is written and published by Francis Esmonde-White as PATCHSLIM
(*) stlGetVerts: returns a list of vertices that are 'opened' or 'closed' depending on the 'mode' input parameter. An 'open' vertice is the one that defines an open side. An open side is the one that only takes part of one triangle
(*) stlDelVerts: removes a list of vertices from STL files
(*) stlAddVerts: adds the new vertices from a list (and consequently, new faces) to a STL object
(*) stlPlot: is an easy way to plot an STL object
(*) stlDemo: is a collection of examples about how to use stlTools
(*) femur_binary: is an ascii STL sample used in 'stlDemo'. It is published by Eric Johnson
(*) sphere_ascii: is a binary STL sample
Pau Micó (2019). stlTools (https://www.mathworks.com/matlabcentral/fileexchange/51200-stltools), MATLAB Central File Exchange. Retrieved .
1.1.0.0 | stlReadAscii.m function is reviewed with the suggestion made by Philipp Ertl |
|
1.0.0.0 | new tags added |
Inspired by: stlwrite - write ASCII or Binary STL files, STL File Reader, Mesh voxelisation, Patch Slim (patchslim.m)
Inspired: OWI Edge GUI, stlread_slim_fv(file)
Create scripts with code, output, and formatted text in a single executable document.
nathan q (view profile)
Camille Remy (view profile)
Duncan Denie (view profile)
Works like a charm.
Yash Sheth (view profile)
Pieter Livens (view profile)
I downloaded the files today (7/01/2019) and got an error. I think the demo file currently loads a non-excisting stl. If I change the name everything works as expected.
MQH (view profile)
Hello, I have a ASCII STL fie and i want to display it in matlab. but I dont know how to open it and to use all theses functions because I am beginner in Matlab. could you just tell me how to open it or where should i make changes. Thank in advance
Michael Häußler (view profile)
Performance suggestion:
I found that I can improve the performace of stlReadAscii.m from around 81seconds to around 12seconds on one of my larger .stl files (R2017a).
Consider replacing:
normals = char(content(logical(strncmp(content,'facet normal',12))));
normals = str2num(normals_char(:,13:end));
By:
normals_char = char(content(logical(strncmp(content,'facet normal',12))));
normals = zeros(size(normals_char,1),3);
for normal_id = 1:size(normals,1)
normals(normal_id,:) = sscanf(normals_char(normal_id,13:end),'%f',[1 3]);
end
Same for the vertices. Seems odd that the 'for loop' is faster, but I guess that matlabs interpreter has gotten a little more clever over time. It seems that the str2num() function is actually quite slow (Matlab even throws a warning on that). But of course the code above doesn't read as nice as your version. You can choose if you want to change it.
Apart from that I love the code! Well organized and clearly written. Just does its job well.
Sunny regards from Munich ;)
Johannes (view profile)
Katherine Beaulieu (view profile)
When I read in my stl, the faces list has floating point numbers, does anyone know why this is?
deru jian (view profile)
James (view profile)
Faez Alkadi (view profile)
Hi,
Is there anyway to offset STL File in 3D direction. I know surf2solid turns thin surface to a solid part. But what I'm looking for is to offset STL body. for example positive offset factor makes the body bigger and return new vertices, and negative offset factor make the body smaller and also return the new vertices.
The function (transformSTL.m) in the IGES Toolbox by Per Bergström does only transform STL. But what I'm looking for is something like( offsetIGES.m ) in the same toolbox except for STL instead of IGES file format.
Is there any function that does that?
Thank you so much
mohammad eslami (view profile)
Philipp Ertl (view profile)
Line 54 in stlReadAscii should be 'nvert = size(vertices,1);' instead of 'length(vertices)' to avoid problems with small .stl files
dcscodelife (view profile)
Alexander Laut (view profile)
works for both ascii and binary formats though ascii files tend to read slower. Not sure if this is just the nature of loading an uncompressed format or if more optimization is need but it works really well overall.
Faez Alkadi (view profile)
for stlAddVerts you say it adds the new vertices from a list (and consequently, new faces) to a STL object.
can you put an example and include a list ?
Thanks
Hui WANG (view profile)
Really good! Compute fast!
dazuoye (view profile)
It's really really very helpful,thanks!!!
Can Guo (view profile)
Matt Carney (view profile)
Nicholas Richmond (view profile)
Fantastic! I have found a problem with stlDelVerts, though. If vdel contains any zeros, it throws a "Subscript indices must either be real positive integers or logicals" error.
Felicity J (view profile)
Jan Lünert (view profile)
It always returns my an error saying either "Undefined function or variable" of the file im trying to read or "Not enough input arguments.". Is someone familiar with such problem with the stl toolbox? Thanks in advance!
Fritz (view profile)
Ali Sedghi (view profile)
very usefull. Thx.
j p (view profile)
Excellent!!Thanks!!
pengfei (view profile)
Great, thank you!
Brendan (view profile)
Demo creates an error when it runs. It was looking for 'sphere300faces.stl' but the included sphere is 'sphere_ascii.stl'. Changing the name of the still file or the code fixes it.