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

Overview

TriangleMeshDistance

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

The distance computation to the triangle collection is accelerated with a sphere bounding volume hierarchy. The signed 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).

Example

// Declare mesh vertices and triangles
std::vector
   <
   double, 
   3>> vertices;
std::vector
   
    <
    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

  • TriangleMeshDistance keeps a copy of the vertex and triangle data passed as input.
  • Additionally, 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. This can potentially reuse memory allocations.
Issues
  • Why use std::abs here?

    Why use std::abs here?

    https://github.com/InteractiveComputerGraphics/TriangleMeshDistance/blob/4eefe274bee688c2dfaf0fbc61ca19bfec9cf6c1/TriangleMeshDistance/include/tmd/TriangleMeshDistance.h#L379

    dot -> abs -> acos

    the result angle is [0, pi/2]

    i think it is this

    dot -> acos -> if angle > 0 then angle else pi + angle

    opened by zhouhang95 1
  • Fix bug related to invalid vector resize

    Fix bug related to invalid vector resize

    The bug should be obvious by just looking at the code diff.

    I found this bug while trying to found out why I was getting error messages about non-watertight meshes, even if I confirmed that the meshes are manifold. Turns out the BVH construction code was adding duplicate (0, 0, 0) triangles because of this bug. The test included in this repo didn't catch this bug because it only tested the constructor which uses std::vector and not the constructor with raw pointers.

    opened by lasagnaphil 1
Owner
Interactive Computer Graphics
Interactive Computer Graphics
Extremely simple yet powerful header-only C++ plotting library built on the popular matplotlib

matplotlib-cpp Welcome to matplotlib-cpp, possibly the simplest C++ plotting library. It is built to resemble the plotting API used by Matlab and matp

Benno Evers 3.2k Jun 20, 2022
linalg.h is a single header, public domain, short vector math library for C++

linalg.h linalg.h is a single header, public domain, short vector math library for C++. It is inspired by the syntax of popular shading and compute la

Sterling Orsten 724 Jun 23, 2022
libmpc++ is a C++ header-only library to solve linear and non-linear MPC

libmpc++ libmpc++ is a C++ library to solve linear and non-linear MPC. The library is written in modern C++17 and it is tested to work on Linux, macOS

Nicola Piccinelli 32 Jun 9, 2022
A work-in-progress C++20/23 header-only maths library for game development, embedded, kernel and general-purpose that works in constant context.

kMath /kmæθ/ A work-in-progress general-purpose C++20/23 header-only maths library that works in constant context Abstract The kMath Project aims to p

The λ Project 10 Apr 18, 2022
A C++ header-only library of statistical distribution functions.

StatsLib StatsLib is a templated C++ library of statistical distribution functions, featuring unique compile-time computing capabilities and seamless

Keith O'Hara 377 Jun 19, 2022
RcppFastFloat: Rcpp Bindings for the fastfloat C++ Header-Only Library

Converting ascii text into (floating-point) numeric values is a very common problem. The fast_float header-only C++ library by Daniel Lemire does this very well, and very fast at up to or over to 1 gigabyte per second as described in more detail in a recent arXiv paper.

Dirk Eddelbuettel 18 May 2, 2022
Header only FFT library

dj_fft: Header-only FFT library Details This repository provides a header-only library to compute fourier transforms in 1D, 2D, and 3D. Its goal is to

Jonathan Dupuy 119 Jun 27, 2022
C++ header-only fixed-point math library

fpm A C++ header-only fixed-point math library. "fpm" stands for "fixed-point math". It is designed to serve as a drop-in replacement for floating-poi

Mike Lankamp 295 Jun 17, 2022
C++ header-only library with methods to efficiently encode/decode Morton codes in/from 2D/3D coordinates

Libmorton v0.2.7 Libmorton is a C++ header-only library with methods to efficiently encode/decode 64, 32 and 16-bit Morton codes and coordinates, in 2

Jeroen Baert 445 Jun 20, 2022
A header-only C++ library for large scale eigenvalue problems

NOTE: Spectra 1.0.0 is released, with a lot of API-breaking changes. Please see the migration guide for a smooth transition to the new version. NOTE:

Yixuan Qiu 566 Jun 23, 2022
Header-only C++11 library to handle physical measures

cpp-measures Header-only C++11 library to handle physical measures License: This project is released under the Mozilla Public License 2.0. Purpose Thi

Carlo Milanesi 20 Jun 28, 2018
A C++ header only library for decomposition of spectra into a sum of response functions whose weights are positive definite.

DecompLib A C++ header only library for decomposition of spectra into a sum of response functions whose weights are positive definite. Introduction Bu

James T. Matta 2 Jan 22, 2022
A matrix header-only library, uses graphs internally, helpful when your matrix is part of a simulation where it needs to grow many times (or auto expand)

GraphMat Header-only Library Matrix implemented as a graph, specially for the use case when it should be auto expanding at custom rate, specially in s

Aditya Gupta 3 Oct 25, 2021
nml is a simple matrix and linear algebra library written in standard C.

nml is a simple matrix and linear algebra library written in standard C.

Andrei Ciobanu 33 Jun 4, 2022
A simple C++ complex & real matrix library, with matrix inversion, left division and determinant calculation

NaiveMatrixLib 帆帆的简易矩阵计算库 A simple C++ stdlib-based complex & real matrix library, with matrix inversion, left division (A\b) and determinant calculat

FerryYoungFan 48 Apr 27, 2022
Simple long integer math library for C++

SLIMCPP Simple long integer math library for C++ SLIMCPP is C++ header-only library that implements long integers that exceed maximum size of native t

null 19 May 19, 2022
MIRACL Cryptographic SDK: Multiprecision Integer and Rational Arithmetic Cryptographic Library is a C software library that is widely regarded by developers as the gold standard open source SDK for elliptic curve cryptography (ECC).

MIRACL What is MIRACL? Multiprecision Integer and Rational Arithmetic Cryptographic Library – the MIRACL Crypto SDK – is a C software library that is

MIRACL 482 Jun 24, 2022
Windows Calculator: A simple yet powerful calculator that ships with Windows

The Windows Calculator app is a modern Windows app written in C++ that ships pre-installed with Windows. The app provides standard, scientific, and programmer calculator functionality, as well as a set of converters between various units of measurement and currencies.

Microsoft 25.1k Jun 19, 2022
A C library for statistical and scientific computing

Apophenia is an open statistical library for working with data sets and statistical or simulation models. It provides functions on the same level as t

null 184 Jun 17, 2022