GithubHelp home page GithubHelp logo

sreiter / stl_reader Goto Github PK

View Code? Open in Web Editor NEW
114.0 114.0 26.0 304 KB

One header C++ library to load ascii and binary stl ('stereolithography') geometry files

License: BSD 2-Clause "Simplified" License

C++ 98.00% Shell 0.14% CMake 1.86%

stl_reader's People

Contributors

sreiter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

stl_reader's Issues

I don't want to use exceptions

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

Filename-taking methods do not work with Unicode filenames on windows

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:

  • Templatize the function on CharT
  • Overload the function on windows only with a version which takes a const wchar_t* or possibly const char16_t* (this is the easiest to monkey-patch in lieu of a fix)
  • (C++17 only) Take a 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.
  • Have the function take an arbitrary istream instead of requiring filenames (would support e.g. piping easier this way I guess)

RemoveDoubles does not update the solidRanges datastructure

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.

Missing Triangles

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.

Expected
Result

Please see the test data attached below.

pump.zip

bug in removeDoubles

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.

StlFileHasASCIIFormat does not correctly guess stl binary types

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

Atof uses locale

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

Would using tolerance value for vertex co-ordinate comparisons be safer?

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.