igl logo

libigl file formats

Triangle mesh file format performance

.obj and .off file formats support meshes with arbitrary polygon degrees. However, often we are only working with triangle meshes. Further, .obj files do not have useful headers revealing the number of elements. For triangle meshes, .off and .obj are inferior file formats to the .mesh file format. The current (version 0.1.6) IO functions for these file formats perform as follows for reading and writing a 300,000 triangle mesh:


writeOBJ:  1.33742 secs
writeOFF:  0.510111 secs
writeMESH: 0.218139 secs

readOBJ:   1.3782 secs
readOFF:   0.691496 secs
readMESH:  0.242315 secs
  

This reveals that .mesh is 6.5x faster than .obj and about 2.5x faster than .off.

While .obj files support normals, it is typically much faster to (re)compute normals from the geometry using per_face_normals, per_vertex_normals, per_corner_normals than to read and write them to files.

It gets even better if you're willing to use a nonstandard format. If your triangle mesh is in (V,F) then you can read and write those variables as dense matrices of doubles to .dmat uncompressed binary files. This not only ensures perfect precision but also big speed ups. On that same 300,000 triangle mesh, .dmat achieves:


writeDMAT: 0.0384338 secs

readDMAT:  0.0117921 secs
  

This reveals that binary .dmat files are 34x/116x faster at writing and reading than .obj and a hefty 5x/20x over .mesh. In this case it may pay to compute normals once into N and also read and write it to a .dmat file.