• Stars
    star
    157
  • Rank 238,399 (Top 5 %)
  • Language
    C++
  • License
    MIT License
  • Created about 3 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Header only, single file, simple and efficient C++11 library to compute the signed distance function (SDF) to a triangle mesh

TriangleMeshDistance

Header only, single file, simple and efficient C++11 library to compute the signed distance function (SDF) to a triangle mesh.

The distance computation to the triangle collection is accelerated with a sphere bounding volume hierarchy. The sign of the distance is resolved with the method presented in "Generating Signed Distance Fields From Triangle Meshes" by Bærentzen, Andreas & Aanæs, Henrik. (2002).

Assuming triangle normals point outwards from the enclosed volume, the sign of the distance will be positive outside and negative inside.

Example

// Declare mesh vertices and triangles
std::vector<std::array<double, 3>> vertices;
std::vector<std::array<int, 3>> triangles;

// (... fill the `vertices` and `triangles` with the mesh data ...)

// Initialize TriangleMeshDistance
tmd::TriangleMeshDistance mesh_distance(vertices, triangles);

// Query TriangleMeshDistance
tmd::Result result = mesh_distance.signed_distance({ x, y, z });

// Print result
std::cout << "Signed distance: " << result.distance << std::endl;
std::cout << "Nearest point: " << result.nearest_point << std::endl;
std::cout << "Nearest entity: " << result.nearest_entity << std::endl;
std::cout << "Nearest triangle index: " << result.triangle_id << std::endl;

What you need to know about TriangleMeshDistance

  • The input triangle mesh must be fully connected and watertight. Triangle soups and meshes with holes will return the correct distance but the sign will be undefined.
  • Triangle winding (consistent normals orientation) is not verified. The input mesh is required to have consistent normals.
  • TriangleMeshDistance keeps a copy of the vertex and triangle data.
  • The pseudonormals required to compute signed distances are calculated and stored at building time.
  • TriangleMeshDistance can be declared empty and constructed multiple times with different meshes. If the new mesh needs less memory than the curent one, memory allocations will be avoided.

Projects using TriangleMeshDistance

  • Discregrid - A static C++ library for the generation of discrete functions on a box-shaped domain. This is especially suited for the discretization of signed distance fields.
  • PBD - A C++ library for physically-based simulation of rigid bodies, deformables, cloth and fluids using Position-Based Dynamics.
  • SPlisHSPlasH - A C++ library for the physically-based simulation of fluids using Smoothed Particle Hydrodynamics.

More Repositories

1

PositionBasedDynamics

PositionBasedDynamics is a library for the physically-based simulation of rigid bodies, deformable solids and fluids.
C++
1,889
star
2

SPlisHSPlasH

SPlisHSPlasH is an open-source library for the physically-based simulation of fluids.
C++
1,553
star
3

Discregrid

A static C++ library for the generation of discrete functions on a box-shaped domain. This is especially suited for the discretization of signed distance fields.
C++
285
star
4

SPH-Tutorial

A course on Smoothed Particle Hydrodynamics (SPH)
172
star
5

CompactNSearch

A C++ library to compute neighborhood information for point clouds within a fixed radius. Suitable for many applications, e.g. neighborhood search for SPH fluid simulations.
C++
156
star
6

splashsurf

Surface reconstruction library and CLI for particle data from SPH simulations, written in Rust.
Rust
120
star
7

fenris

A library for advanced finite element computations in Rust
Rust
119
star
8

cuNSearch

A C++/CUDA library to efficiently compute neighborhood information on the GPU for 3D point clouds within a fixed radius.
Cuda
93
star
9

FastCorotatedFEM

FastCorotatedFEM is a minimalistic implementation of the corotated FEM method which was proposed in paper "Fast Corotated FEM using Operator Splitting" by Kugelstadt et al.
C++
72
star
10

TreeNSearch

C++ library for fast computation of neighbor lists in point clouds.
C++
52
star
11

blender-sequence-loader

An addon for Blender enabling just-in-time loading and animation of mesh and particle/ point-cloud sequences.
Python
49
star
12

physics-simulation

Introduction to state-of-the-art simulation methods for rigid bodies, deformable solids and fluids in the area of visual computing
41
star
13

Latex4CorelDRAW

This is a addon for CorelDRAW. It allows to add and edit Latex equations or symbols easily.
C#
32
star
14

BlenderPartioTools

BlenderPartioTools is an open-source add-on to import particle data in Blender.
C++
31
star
15

stark

Stark is a C++ and Python simulation platform for the robust simulation of rigid and deformable objects in a strongly coupled manner.
C++
31
star
16

MayaPartioTools

MayaPartioTools is an open-source plugin to visualize and import particle data in Maya.
C++
26
star
17

GenericParameters

GenericParameters is a C++ header-only library to define generic parameters which store additional information like the parameter type, max/min limits, a description, etc.
C++
23
star
18

higher_order_embedded_fem

Source code for our paper "Higher-order finite elements for embedded simulation"
Rust
22
star
19

Latex4PowerPoint

This is a Latex Add-In for Powerpoint. It enables to add and edit Latex equations or symbols in a Powerpoint slide easily. The Add-In is based on ScintillaNET and supports syntax highlighting, code snippets etc.
C#
16
star
20

stark_micropolar

Fork of "stark" with source code for our paper "Curved Three-Director Cosserat Shells with Strong Coupling"
C++
8
star
21

physics-simulation.org

4
star
22

MayaMeshTools

MayaMeshTools is an open-source plugin to import single mesh files and sequences of mesh files in Maya.
C++
4
star
23

stark_magnetic

Fork of "stark" with source code for our paper "Strongly Coupled Simulation of Magnetic Rigid Bodies"
C++
1
star