File Exchange

image thumbnail

stlTools

version 1.1.0.0 (1.58 MB) by

This is a collection of functions, samples and demos to illustrate how to deal with STL files

94 Downloads

Updated

View License

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

Comments and Ratings (23)

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

When I read in my stl, the faces list has floating point numbers, does anyone know why this is?

deru jian

James

James (view profile)

Faez Alkadi

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

Philipp Ertl

Line 54 in stlReadAscii should be 'nvert = size(vertices,1);' instead of 'length(vertices)' to avoid problems with small .stl files

dcscodelife

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

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

Really good! Compute fast!

dazuoye

It's really really very helpful,thanks!!!

Can Guo

Matt Carney

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

Jan Lünert

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

Fritz (view profile)

Ali Sedghi

very usefull. Thx.

j p

j p (view profile)

Excellent!!Thanks!!

pengfei

Great, thank you!

Brendan

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.

Updates

1.1.0.0

stlReadAscii.m function is reviewed with the suggestion made by Philipp Ertl

1.0.0.0

new tags added

MATLAB Release Compatibility
Created with R2014b
Compatible with any release
Platform Compatibility
Windows macOS Linux

MATLAB Online Live Editor Challenge

Win cash prizes and have your live script featured on our website

Learn more

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video