Basic example

This example is given in Examples/EBGeometry_DCEL/main.cpp and shows the following steps:

  1. How to read an STL file into a DCEL mesh.

  2. How to partition and flatten a BVH tree.

  3. How to call the signed distance function and provide a performance comparison between SDF representations.

We will focus on the following parts of the code:

using T    = float;
  }

  // we convert it to a full BVH tree representation. Then we flatten that tree.
  const auto dcelSDF = EBGeometry::Parser::readIntoDCEL<T>(file);
  const auto bvhSDF  = EBGeometry::DCEL::buildFullBVH<T, BV, K>(dcelSDF);
  const auto linSDF  = bvhSDF->flattenTree();
  // Sample some random points around the object.
  constexpr size_t Nsamp = 100;

  const Vec3 lo    = bvhSDF->getBoundingVolume().getLowCorner();
  const Vec3 hi    = bvhSDF->getBoundingVolume().getHighCorner();
  std::mt19937_64 rng(static_cast<size_t>(std::chrono::system_clock::now().time_since_epoch().count()));

  if (std::abs(bvhSum - dcelSum) > std::numeric_limits<T>::epsilon()) {

Reading the surface mesh

The first block of code parses an STL file (here called file) and returns a DCEL mesh description of the STL file. We point out that the parser will issue errors if the STL file is not watertight and orientable.

Constructing the BVH

The second block of code, which begins with

  // Sample some random points around the object.

creates a BVH root node and provides it with all the DCEL faces. The next block of code

  constexpr size_t Nsamp = 100;

  const Vec3 lo    = bvhSDF->getBoundingVolume().getLowCorner();
  const Vec3 hi    = bvhSDF->getBoundingVolume().getHighCorner();

partitions the BVH using pre-defined partitioning functions (see BVH integration for details).

Finally, the BVH tree is flattened by


Summary

Note that all the objects directSDF, bvhSDF, and linSDF represent precisely the same distance field. The objects differ in how they compute it:

  • directSDF will iterate through all faces in the mesh.

  • bvhSDF uses full BVH tree representation, pruning branches during the tree traversal.

  • linSDF uses compact BVH tree representation, also pruning branches during the tree traversal.

All the above functions give the same result, but with different performance metrics.