Roland's homepage

My random knot in the Web

stl2pov rewrite

Python logo

On 2011-04-04 I re-wrote my parser for STL files in Python. The original C parser was 411 lines (excluding comments and blank lines). The new parser in Python is 134 lines. This is also without comments. It took me about two hours to write from scratch. But that includes debugging and writing a __str__ method and iterator for the STL file object, and a built-in test.

It is my hope that porting programs like this to Python will make portability to other systems easier. And now that I’ve separated the parser into a module, it will also become easier to write front-ends for translation into other formats that just POV. I’m thinking of a front-end to produce PostScript or even PDF. Possibly including a simple viewer.

The stl2pov port to Python was finished on 2011-04-10. You can find it as the py-stl package. It works about as well as the current C version, except that the switch for smooth triangles has been dropped. Generating smooth triangles requires the program to know the neighbours of every facet. I decided that the time spent in mapping the connections between all facets was not worth it, since the time required to process all n facets grows with O(n!). Also. an STL file doesn’t really contain enough topology information to reliably decide when smoothing whether two facets really share an edge, leading to arbitrary choices as to when or when not to connect them. And consider two facets that doshare an edge; in which range should the angle between the facets lie to do smoothing?

←  Learning Python A new STL convertor added  →