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

ascii line returns #160

Closed MrBenGriffin closed 3 years ago

MrBenGriffin commented 3 years ago

mesh.Mesh.from_file() only works with CRLF line returns. While this may be ostensibly accurate, the error message is not correct, and it is trivial (within python) for the line return style being used in a file.

print open('myfile.txt', 'U').read()

wolph commented 3 years ago

The U parameter has been deprecated since Python 3 and universal newlines are enabled by default so it shouldn't be needed: https://docs.python.org/3/library/functions.html#open

There is an additional mode character permitted, 'U', which no longer has any effect, and is considered deprecated. It previously enabled universal newlines in text mode, which became the default behaviour in Python 3.0. Refer to the documentation of the newline parameter for further details.

Doesn't mean there is no bug here though... because that only works for text mode and the files are read in binary mode ;)

I've fixed it for the pure python based parsing and added tests for it. Now the speedups module needs support too...

wolph commented 3 years ago

I believe I've fixed it. Can you try the develop branch?

MrBenGriffin commented 3 years ago

Yeah, my 'U' suggestion was wrong on this - but the problem was there.. (otherwise I wouldn't have found it!)

I will indeed test as soon as I have some time ;-D

MrBenGriffin commented 3 years ago

Hi yeah, that works now - it still fails for 'Mac OS 9' (CR) line endings - the error is as follows. However, for LF and CRLF it's working great - thanks!

The following error appears now only for CR line endings I think the exception sprogging off another exception could probably be handled a bit more gracefully.

exception (0, 'Line longer than 8192, probably non-ascii')
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/stl/stl.py", line 71, in load
    name, data = cls._load_ascii(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/stl/stl.py", line 233, in _load_ascii
    return _speedups.ascii_read(fh, header)
  File "stl/_speedups.pyx", line 121, in stl._speedups.ascii_read
  File "stl/_speedups.pyx", line 72, in stl._speedups.readline
RuntimeError: (0, 'Line longer than 8192, probably non-ascii')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/stl/stl.py", line 374, in from_file
    name, data = cls.load(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/stl/stl.py", line 91, in load
    name, data = cls._load_binary(fh, header,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/stl/stl.py", line 111, in _load_binary
    assert count < MAX_COUNT, ('File too large, got %d triangles which '
AssertionError: File too large, got 808464441 triangles which exceeds the maximum of 100000000
wolph commented 3 years ago

The last Mac OS 9 release is about 20 years old, I don't think that any machine capable of running that is using 3D software :P

MrBenGriffin commented 3 years ago

The last Mac OS 9 release is about 20 years old, I don't think that any machine capable of running that is using 3D software :P

I accept that! It's just sometimes (rarely) people mess up their line returns - but as far as I'm concerned it's looking good, and feel free to close it.

wolph commented 3 years ago

Great, thanks for the bug report :)