Mesh triangle reduction using quadrics. This is a Pascal port of Sven Forstmann's C++ mesh simplification code. It is fast, memory efficient, free and high quality. It uses a threshold to determine which triangles to delete, leading to fast performance since it avoids sorting, though note that this might lead to lesser quality.
This code is embedded into the Surf Ice surface rendering tool (versions 5 May 2016 and later). Surf Ice is available pre-compiled for Linux, OSX and Windows, and the source code is available on GitHub. The software reads meshes in many popular formats (3ds, ac3d, dxf, GIfTI, gts lwo, ms3d, mz3, ctm, dae/Collada, FreeSurfer, nv, obj, off, ply, stl, vtk) and can export decimated meshes to several formats (mz3, GIfTI, obj, ply). To decimate an image, load the mesh with the File/Open menu item and then choose Advanced/SimplifyMesh menu item to simplify the object. If you are happy with the results you can choose Advanced/SaveMesh. The screen shot below shows the original (left column) and 90% decimated (right column) mesh of the human brain. The top row shows a wire-frame view that helps visualize the mesh complexity, while the bottom row shows the how similar these two meshes look with per-pixel shading.
While this algorithm is embedded into Surf Ice, that is a complex program. This GitHub page includes a basic command line program that allows the user to load a obj format mesh, decimate the mesh and save the result to disk. This should help Delphi, Lazarus or FreePascal developers who want to exploit this algorithm. You will need to have the freepascal compiler installed.
- To compile the program with FreePascal "fpc -O3 -XX -Xs simplify.pas" (though to enforce a 64-bit version you could run ppcx64 -O3 -XX -Xs simplify.pas").
- To compile the program with Delphi 7 "dcc32 -CC -B simplify.pas".
- Once compiled, you can run the program with a command like this "./simplify bunny.obj out.obj 0.2", which should produce a new mesh with 20% of the faces found in the original.
Lazarus can compile the project "gui.lpi" to be a native executable for OSX, Windows or Linux. Launch Lazarus, choose File/Open and select the gui.lpi file and then choose the Run/Run menu item.
Delphi can compile the project "guidelphi.dpr". Launch Delphi, choose File/Open and select the gui_delphi.dpr file and then choose the Run/Run menu item. The provided project was created in Delphi 7, but should support more recent versions.
In general, this is an extremely fast algorithm, and will reduce the level of detail for typically meshes with interactive speeds. However, any mesh simplification method will tend to slow down with more complex meshes and for more complete decimation (e.g. reducing a mesh 99% will take much longer than a 50% reduction). This software reduces a very complex 1.4 millions face mesh into a mesh with just 14 thousand (99% reduction) in 8 seconds on a 2.6GHz Haswell CPU. The C code compiled with either GCC 6.1 or LLVM 7.3 takes about 2.6 seconds. In contrast, Matlab's high-performance but proprietary reducepatch routine requires 12.4 seconds.
- 5-May-2016 : Initial release
- 7-May-2016 : Delphi compatibility, faster FPC (using inlining)
- 9-May-2016 : Meshes scaled to size 1 prior to decimation and then returned to original size (matches assumptions of threshold).
- 20-May-2016 : Faster, fewer calls to setlength
- 29-May-2016 : Added graphical user interface versions for Delphi and Lazarus
- This software uses the MIT license