The goal is to build a distance field representation of a 3D CAD model.
We get the 3D model from the Large Geometric Models Archive. This is in PLY format which we need to convert to STL using meshlab.
system ("test -f distance.stl || "
"gunzip -f horse.ply.gz && "
We read the STL file, compute the bounding box of the model and set the domain center and size using this bounding box.
We initialize the distance field on the coarse initial mesh and refine it adaptively until the threshold error (on distance) is reached.
We display an isosurface of the distance function coloured with the level of refinement.
We also compute the volume and surface fractions from the distance field. We first construct a vertex field interpolated from the centered field and then call the appropriate VOF functions.
Finally we display the surface reconstructed from volume fractions.
Note that the "tail" of the horse is an artefact due to an inconsistency in the surface mesh, which is self-intersecting near this point.
Isosurface of the distance function coloured with level of refinement.