• Stars
    star
    178
  • Rank 207,185 (Top 5 %)
  • Language
    C++
  • License
    MIT License
  • Created almost 4 years ago
  • Updated 10 months ago

Reviews

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

Repository Details

Build high-quality Laplace matrices on meshes and point clouds in Python. Implements [Sharp & Crane SGP 2020].

actions status linux actions status macOS actions status windows PyPI

A Python package for high-quality Laplace matrices on meshes and point clouds. pip install robust_laplacian

The Laplacian is at the heart of many algorithms across geometry processing, simulation, and machine learning. This library builds a high-quality, robust Laplace matrix which often improves the performance of these algorithms, and wraps it all up in a simple, single-function API!

Sample: computing eigenvectors of the point cloud Laplacian demo image of eigenvectors on point cloud

Given as input a triangle mesh with arbitrary connectivity (could be nonmanifold, have boundary, etc), OR a point cloud, this library builds an NxN sparse Laplace matrix, where N is the number of vertices/points. This Laplace matrix is similar to the cotan-Laplacian used widely in geometric computing, but internally the algorithm constructs an intrinsic Delaunay triangulation of the surface, which gives the Laplace matrix great numerical properties. The resulting Laplacian is always a symmetric positive-definite matrix, with all positive edge weights. Additionally, this library performs intrinsic mollification to alleviate floating-point issues with degenerate triangles.

The resulting Laplace matrix L is a "weak" Laplace matrix, so we also generate a diagonal lumped mass matrix M, where each diagonal entry holds an area associated with the mesh element. The "strong" Laplacian can then be formed as M^-1 L, or a Poisson problem could be solved as L x = M y.

A C++ implementation and demo is available.

This library implements the algorithm described in A Laplacian for Nonmanifold Triangle Meshes by Nicholas Sharp and Keenan Crane at SGP 2020 (where it won a best paper award!). See the paper for more details, and please use the citation given at the bottom if it contributes to academic work.

Example

Build a point cloud Laplacian, compute its first 10 eigenvectors, and visualize with Polyscope

pip install numpy scipy plyfile polyscope robust_laplacian
import robust_laplacian
from plyfile import PlyData
import numpy as np
import polyscope as ps
import scipy.sparse.linalg as sla

# Read input
plydata = PlyData.read("/path/to/cloud.ply")
points = np.vstack((
    plydata['vertex']['x'],
    plydata['vertex']['y'],
    plydata['vertex']['z']
)).T

# Build point cloud Laplacian
L, M = robust_laplacian.point_cloud_laplacian(points)

# (or for a mesh)
# L, M = robust_laplacian.mesh_laplacian(verts, faces)

# Compute some eigenvectors
n_eig = 10
evals, evecs = sla.eigsh(L, n_eig, M, sigma=1e-8)

# Visualize
ps.init()
ps_cloud = ps.register_point_cloud("my cloud", points)
for i in range(n_eig):
    ps_cloud.add_scalar_quantity("eigenvector_"+str(i), evecs[:,i], enabled=True)
ps.show()

NOTE: No one can agree on the sign convention for the Laplacian. This library builds the positive semi-definite Laplace matrix, where the diagonal entries are positive and off-diagonal entries are negative. This is the opposite of the sign used by e.g. libIGL in igl.cotmatrix, so you may need to flip a sign when converting code.

API

This package exposes just two functions:

  • mesh_laplacian(verts, faces, mollify_factor=1e-5)
    • verts is an V x 3 numpy array of vertex positions
    • faces is an F x 3 numpy array of face indices, where each is a 0-based index referring to a vertex
    • mollify_factor amount of intrinsic mollifcation to perform. 0 disables, larger values will increase numerical stability, while very large values will slightly implicitly smooth out the geometry. The range of reasonable settings is roughly 0 to 1e-3. The default value should usually be sufficient.
    • return L, M a pair of scipy sparse matrices for the Laplacian L and mass matrix M
  • point_cloud_laplacian(points, mollify_factor=1e-5, n_neighbors=30)
    • points is an V x 3 numpy array of point positions
    • mollify_factor amount of intrinsic mollifcation to perform. 0 disables, larger values will increase numerical stability, while very large values will slightly implicitly smooth out the geometry. The range of reasonable settings is roughly 0 to 1e-3. The default value should usually be sufficient.
    • n_neighbors is the number of nearest neighbors to use when constructing local triangulations. This parameter has little effect on the resulting matrices, and the default value is almost always sufficient.
    • return L, M a pair of scipy sparse matrices for the Laplacian L and mass matrix M

Installation

The package is availabe via pip

pip install robust_laplacian

The underlying algorithm is implemented in C++; the pypi entry includes precompiled binaries for many platforms.

Very old versions of pip might need to be upgraded like pip install pip --upgrade to use the precompiled binaries.

Alternately, if no precompiled binary matches your system pip will attempt to compile from source on your machine. This requires a working C++ toolchain, including cmake.

Known limitations

  • For point clouds, this repo uses a simple method to generate planar Delaunay triangulations, which may not be totally robust to collinear or degenerate point clouds.

Dependencies

This python library is mainly a wrapper around the implementation in the geometry-central library; see there for further dependencies. Additionally, this library uses pybind11 to generate bindings, and jc_voronoi for 2D Delaunay triangulation on point clouds. All are permissively licensed.

Citation

@article{Sharp:2020:LNT,
  author={Nicholas Sharp and Keenan Crane},
  title={{A Laplacian for Nonmanifold Triangle Meshes}},
  journal={Computer Graphics Forum (SGP)},
  volume={39},
  number={5},
  year={2020}
}

For developers

This repo is configured with CI on github actions to build wheels across platform.

Deploy a new version

  • Commit the desired version to the master branch, be sure the version string in setup.py corresponds to the new version number. Include the string [ci build] in the commit message to ensure a build happens.
  • Watch th github actions builds to ensure the test & build stages succeed and all wheels are compiled.
  • While you're waiting, update the docs.
  • Tag the commit with a tag like v1.2.3, matching the version in setup.py. This will kick off a new github actions build which deploys the wheels to PyPI after compilation.

More Repositories

1

polyscope

A C++ & Python viewer for 3D data like meshes and point clouds
C++
1,616
star
2

geometry-central

Applied 3D geometry in C++, with a focus on surface meshes.
C++
985
star
3

potpourri3d

An invigorating blend of 3D geometry tools in Python.
Python
388
star
4

diffusion-net

Pytorch implementation of DiffusionNet for fast and robust learning on 3D surfaces like meshes or point clouds.
Python
369
star
5

happly

A C++ header-only parser for the PLY file format. Parse .ply happily!
C++
278
star
6

neural-implicit-queries

Queries on neural implicit surfaces via range analysis: ray casting, intersection, closest point, & more. SIGGRAPH 2022 paper. JAX implementation.
Python
169
star
7

neural-physics-subspaces

Fit low-dimensional subspaces to physical systems with neural networks (SIGGRAPH 2023)
Python
134
star
8

DDGSpring2016

Code repository for 15-869 Discrete Differential Geometry at CMU in Spring 2016.
Python
121
star
9

intrinsic-triangulations-tutorial

An introductory course intrinsic triangulations for powerful & robust geometry processing --- tutorial code and links.
Python
119
star
10

nonmanifold-laplacian

A robust Laplace matrix for general (possibly nonmanifold) triangle meshes, and point clouds [Sharp & Crane SGP 2020]
C++
113
star
11

learned-triangulation

Source code for "PointTriNet: Learned Triangulation of 3D Point Sets", by Nicholas Sharp and Maks Ovsjanikov at ECCV 2020
Python
98
star
12

variational-surface-cutting

Codebase for "Variational Surface Cutting" by Sharp & Crane, SIGGRAPH 2018
C++
87
star
13

flip-geodesics-demo

Construct geodesic paths, loops, networks on surface with a fast and simple edge flipping algorithm. C++ demo app and more.
C++
80
star
14

vector-heat-demo

C++ demo of the Vector Heat Method (Sharp, Soliman, and Crane. 2019.)
C++
58
star
15

navigating-intrinsic-triangulations-demo

Demo code for "Navigating Intrinsic Triangulations". Sharp, Soliman, and Crane. 2019
C++
46
star
16

gc-polyscope-project-template

A template project to get started with geometry-central and Polyscope.
C++
43
star
17

polyscope-py

Python bindings for Polyscope
Python
29
star
18

arrgh

A small python utility to pretty-print a table summarizing arrays & scalars from numpy, pytorch, etc.
Python
24
star
19

discretization-robust-correspondence-benchmark

Benchmark for the generalization of 3D machine learning models across different remeshing/samplings of a surface.
Python
11
star
20

geometry-central-tutorials

Tutorials for the geometry-central geometry processing library.
C++
9
star
21

libigl-polyscope-project-template

An example project and build system using libIGL and Polyscope
CMake
7
star
22

RNA-Surface-Segmentation-Dataset

A dataset of segmented RNA molecule surfaces, as a benchmark task in 3D machine learning on surfaces. From Poulenard et al., 3DV 2019.
7
star
23

polyscope-docs

Documentation for polyscope
HTML
3
star
24

nmwsharp.github.io

HTML
1
star