sreiter / stl_reader Goto Github PK
View Code? Open in Web Editor NEWOne header C++ library to load ascii and binary stl ('stereolithography') geometry files
License: BSD 2-Clause "Simplified" License
One header C++ library to load ascii and binary stl ('stereolithography') geometry files
License: BSD 2-Clause "Simplified" License
Nice work bro. How about reading from memory?
Thanks for the library.
I have tested with various STL files. But all of them have missing triangles.
Please see screenshots of Expected vs Result.
Please see the test data attached below.
line 476 newIndex[0]=0 seems a bug
fix suggest:
newIndex[coordsWithIndexInOut[0].index]=0;
by the way i have a proposal:
stl_mesh need to extend its removeDoubles to work in the condition that removing duplicate point and degenerate triangles in each solid ,the data in each solid have no influence with eachother.
As it turns out, when exporting a mesh from SolidWorks (as a binary stl), the binary header starts with the word "solid"...
And after looking at the code in stl_reader which decides if the input file is ascii || binary i see that the decision is based on the first word of the input file. This causes some files (maybe all of them since this is the default SolidWorks behaviour) to crash programms trying to read them with this library.
Do you have any idea of how else to distinguish ascii from binary stl files ?
I am happy to submit a PR fixing this if we come to a solution
Reffer to comment in line 492 " // make sure to only add triangles which refer to three different indices"
When this happens the facets get removed from the trisInOut . Therefore the solidRanges array must be adjusted accordingly.
Especially, it the STL file has multiple solids.
I have fixed this and I have stl_reader.h with that fix.
stl_reader.zip
Also I have added vector solid_names to store the name defined in solid statement for ASCII and a default string for BINARY.
Atof uses set locale to parse nunbers which is wrong. One should either use modern conversion or imbue C locale when opening ifstream on ASCII loading
Hello, thanks for your code.
Note: If you do not want to use exceptions, you may define the macro STL_READER_NO_EXCEPTIONS before including 'stl_reader.h'. In that case, functions will return false if an error occurred.
Could you be a bit more specific? How do I define the macro? Where do I define it?
Thanks,
Cheers,
Davide Bassano
Nice library!
The ReadStlFile_ASCII
, ReadStlFile_BINARY
, and StlFileHasASCIIFormat
functions all take const char*
for the filename.
On windows this causes issues when opening filenames which contain Unicode (UTF-16) strings.
The issue is the ifstream(const char*)
constructor, which on windows will only accept ascii strings.
Possible solutions/ideas:
CharT
const wchar_t*
or possibly const char16_t*
(this is the easiest to monkey-patch in lieu of a fix)std::filesystem::path
as an argument instead of a const char*
, which should do all the conversions for you and just do the right thing on all platforms. Would be backwards compatible, since const char*
converts to a path
implicitly.istream
instead of requiring filenames (would support e.g. piping easier this way I guess)function RemoveDoubles need fixing cuz when degenerated triangles were removed the normalOut data is not updated simultaneously
Hello,
Thanks for creating the library. It's very helpful.
I noticed that the library is using exact comparisons (==
and !=
) for the vertex co-ordinates.
bool operator==(const CoordWithIndex & c) const
{
return (c[0] == data[0]) && (c[1] == data[1]) && (c[2] == data[2]);
}
bool operator!=(const CoordWithIndex & c) const
{
return (c[0] != data[0]) || (c[1] != data[1]) || (c[2] != data[2]);
}
Since the co-ordinate data will be floating point numbers, this might cause a random floating point error, and the comparisons may give a wrong result in the form of either a false positive or false negative result.
Would you be okay with using a tolerance value for these comparisons?
Example: Instead of the equal ==
comparison, we can use:
bool operator==(const CoordWithIndex & c) const
{
const double tolerance = 1E-9;
const bool result_x = (std::abs(c[0]-data[0])<=tolerance);
const bool result_y = (std::abs(c[1]-data[1])<=tolerance);
const bool result_z = (std::abs(c[2]-data[2])<=tolerance);
return (result_x && result_y && result_z);
}
The tolerance value can be set by you, but it's best if the user can change it. They might use 1E-6 or 1E-3 for instance.
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.