Skip to content

Chapter 5: External libraries

PyPI version buildwheels

import igl
import scipy as sp
import numpy as np
from meshplot import plot, subplot, interact

import os
root_folder = os.getcwd()

An additional positive side effect of using matrices as basic types is that it is easy to exchange data between libigl and other software and libraries.

Baking ambient occlusion

Ambient occlusion is a rendering technique used to calculate the exposure of each point in a surface to ambient lighting. It is usually encoded as a scalar (normalized between 0 and 1) associated with the vertice of a mesh.

Formally, ambient occlusion is defined as:

\[ A_p = \frac{1}{\pi} \int_\omega V_{p,\omega}(n \cdot \omega) d\omega \]

where V_{p,\omega} is the visibility function at p, defined to be zero if p is occluded in the direction \omega and one otherwise, and d\omega is the infinitesimal solid angle step of the integration variable \omega.

The integral is usually approximated by casting rays in random directions around each vertex. This approximation can be computed using the function:

ao = igl.ambient_occlusion(v, f, v_samples, n_samples, 500)

that given a scene described in v and f, computes the ambient occlusion of the points in v_samples whose associated normals are n_samples. The number of casted rays can be controlled (usually at least 300-500 rays are required to get a smooth result) and the result is returned in ao, as a single scalar for each sample.

Ambient occlusion can be used to darken the surface colors, as shown in the following example:

v, f = igl.read_triangle_mesh(os.path.join(root_folder, "data", "fertility.off"))

n = igl.per_vertex_normals(v, f)

# Compute ambient occlusion factor using embree
ao = igl.ambient_occlusion(v, f, v, n, 20)
ao = 1.0 - ao

plot(v, f, ao, shading={"colormap": "gist_gray"})

References


  1. David Bommes, Henrik Zimmer, Leif Kobbelt. Mixed-integer quadrangulation, 2009. 

  2. Sofien Bouaziz, Mario Deuss, Yuliy Schwartzburg, Thibaut Weise, Mark Pauly Shape-Up: Shaping Discrete Geometry with Projections, 2012 

  3. Matthias Eck, Tony DeRose, Tom Duchamp, Hugues Hoppe, Michael Lounsbery, Werner Stuetzle. Multiresolution Analysis of Arbitrary Meshes, 2005. 

  4. Bruno Lévy, Sylvain Petitjean, Nicolas Ray, Jérome Maillot. Least Squares Conformal Maps, for Automatic Texture Atlas Generation, 2002. 

  5. Nicolas Ray, Bruno Vallet, Wan Chiu Li, Bruno Lévy. N-Symmetry Direction Field Design, 2008. 

  6. Ligang Liu, Lei Zhang, Yin Xu, Craig Gotsman, Steven J. Gortler. A Local/Global Approach to Mesh Parameterization, 2008. 

  7. Patrick Mullen, Yiying Tong, Pierre Alliez, Mathieu Desbrun. Spectral Conformal Parameterization, 2008. 

  8. Daniele Panozzo, Enrico Puppo, Marco Tarini, Olga Sorkine-Hornung. Frame Fields: Anisotropic and Non-Orthogonal Cross Fields, 2014. 

  9. Amir Vaxman, Marcel Campen, Olga Diamanti, Daniele Panozzo, David Bommes, Klaus Hildebrandt, Mirela Ben-Chen. Directional Field Synthesis, Design, and Processing, 2016