anoved / phstl

Convert GDAL rasters (like GeoTIFF heightmaps) to 3D STL surfaces.
MIT License
73 stars 21 forks source link

Quantify NormalVector accuracy and performance in stlwriter #11

Closed anoved closed 7 years ago

anoved commented 8 years ago

No indication that it's problematic, but if it contributes significantly to output time on large datasets, allow it to be skipped since most stl software can figure it out dynamically anyway. Likewise, test against normal vectors calculated by other tools (meshlab, etc).

anoved commented 8 years ago

NormalVector normals do differ from those calculated by Meshlab's Recompute Face Normals...

anoved commented 8 years ago

This issue occurs because Python uses 64-bit doubles internally for all floating point operations, whereas many other normal vector implementations appear to use 32-bit floats. (STL format itself limits vector elements to 32 bits.)

Testing by writing a normal calculation test case in C. When using 64-bit double types, output agrees with my Python implementation. When using 32-bit float types, output agrees with Meshlab et al.

Options now include simply documenting this cause of the discrepancy, or rewriting Phstl's normal vector calculation to force use of 32 bit precision throughout (possibly via the Decimal module or similar).