wolph / numpy-stl

Simple library to make working with STL files (and 3D objects in general) fast and easy.
http://numpy-stl.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
624 stars 105 forks source link

Loading ASCII STL with empty name prints a warning #88

Closed yupinov closed 5 years ago

yupinov commented 6 years ago

When loading an ASCII mesh which has the first line as 'solid ', numpy-stl issues a warning:

ASCII STL files should start with solid . The application that produced this STL file may be faulty, please report this error. The erroneous line: b'solid'

And then falls back to binary loading which also fails.

The name of the solid is optional, I believe.

yupinov commented 6 years ago

I don't think that's relevant at all, even though I'm not really aware of prefixes. What I've seen inside stl.py is that get() strips the line, so from 'solid ' it becomes 'solid'. Then its beginning is compared with 'solid ' and the warning is printed. Obviously it would not happen with any non-empty name.

Uvar commented 6 years ago

You are absolutely right, this has long since been taken care of by @WoLpH by enforcing everything to bytes literals anyway. My bad.

Do you have a reproducible example we can work with and some information on your python and numpy-stl versions?

yupinov commented 6 years ago

Alright, disregard that. I have some other issue with the way I write my STL files, it seems. This warning gets printed with literally any STL ASCII file with an empty name (and shouldn't be), but the minimal ASCII file actually gets loaded, so it's not critical. Numpy-stl is 2.7.0 from pip, using python 3.5.2.

python3 -c "from stl import mesh; m = mesh.Mesh.from_file('min.stl.txt'); print('Points count ' + str(len(m.points)))"

min.stl.txt

Uvar commented 6 years ago

Clear. It is a warning message, yet no Exception is raised if the mesh is in proper order. (tried adding some other polygons, no issue with loading, although it complains about the header). Maybe we can think about adding support for empty headers. Technically an ASCII STL can be valid with empty header, although the trailing whitespace after solid is still mandatory.

Uvar commented 6 years ago

Issue is with line 156 in stl.py. Stripping whitespace will flag the technically correct b'solid ' the same as b'solid' which should indeed raise the warning.

    if not line.startswith(b('solid ')) and line.startswith(b('solid')):
        cls.warning('ASCII STL files should start with solid <space>. '
                    'The application that produced this STL file may be '
                    'faulty, please report this error. The erroneous '
                    'line: %r', line)

should be moved to within the get method.

wolph commented 6 years ago

I think it might be best to simply remove that check, it probably doesn't matter anyhow :)

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.