Geometry Processing – Parameterization
To get started: Fork this repository then issue
git clone --recursive http://github.com/[username]/geometry-processing-parameterization.git
Installation, Layout, and Compilation
See introduction.
Execution
Once built, you can execute the assignment from inside the build/
by running
on a given mesh:
./parameterization [path to mesh with boundary.obj]
Background
In this assignment we will explore how to flatten a surface
embedded (or even just
immersed) in
This process is often referred to as parameterization because the two-dimensional coordinate system of the flattened mesh can now be interpreted as a parameterization of the 3D surface.
In this assignment, we are given a representation of the surface in 3D as a
triangle mesh with a list of
In general, a 3D surface cannot be flattened onto the plane without distortion. Some parts of the surface will have to be stretched and other squished. Surfaces with topological handles or without a boundary
Mass-spring methods
If we view our triangle mesh surface as a simple graph then the surface flattening problem reduces to graph drawing. Distortion can be measured in terms of the relative change in lengths between neighboring vertices.
We can pose the graph drawing problem as an optimization over node locations so that the lengths between neighboring vertices are minimized:
\[
\min_\U ∑\limits_{{i,j} ∈ \E} ‖\u_i - \u_j‖²,
\]
where
Without additional constraints, this minimization has a trivial solution: map
all vertices to the same point, e.g.,
We can avoid this by fixing the mapping of certain vertices. If we choose these
fixed vertices arbitrarily we will in general get overlaps in the flattening.
For graph drawing this means that edges cross each other; for surface
parameterization this means that multiple triangles cover the same patch of the
In 1963, Tutte showed that if the boundary of a disk-topology mesh is fixed to a convex polygon (and all spring stiffness are positive) then minimizing the energy above will result in an injective (i.e., fold-over-free) flattening.
While avoiding fold-overs is important, Tutte-style mappings suffer from a couple problems.
If uniform spring stiffness are used, then the mapping in the
We can try to remedy this by introducing a non-uniform weight or spring
stiffness
For example, we could weigh the distortion of shorter edges (on the 3D mesh)
more than longer ones:
To do this, let's write the energy minimization problem above in matrix form:
\[
\min_\U ½ \tr{\U^\transpose \L \U},
\]
where
What's up with the
$\tr{}$ in the energy?The degrees of freedom in our optimization are a collected in the matrix
$\U ∈ \R^{n×2}$ with two columns. The energy is written as the trace of the quadratic form (a.k.a. matrix)$\Q ∈ \R^{n×n}$ applied to$\U$ . In effect, this is really applying$\Q$ to each column of$\U$ independently and summing the result:\[ \begin{align} \tr{\U^\transpose \Q \U} &= \ &= \tr{\U^\transpose \Q \U} \ &= \tr{ \left[\begin{array}{c} \U_1^\transpose\ \U_2^\transpose \end{array}\right] \Q [\U_1 \U_2] } \ &= \tr{\left[\begin{array}{c} \U_1^\transpose \Q \U_1 & \U_1^\transpose \Q \U_2 \ \U_2^\transpose \Q \U_1 & \U_2^\transpose \Q \U_2 \end{array}\right]} \ &= \U_1^\transpose \Q \U_1 + \U_2^\transpose \Q \U_2. \end{align} \]
The upshots of energies written as the trace of a quadratic form applied to a matrix are that: 1) each column can be optimized independently (assuming constraints are also separable by column), and this is often the case when columns correspond to coordinates (u, v, etc.); and 2) the quadratic form for each columns is the same (the same
$\Q$ ). For quadratic energy minimization, this means that we can precompute work (e.g., Cholesky facotorization) on$\Q$ and take advantage of it for solving with$\U_1$ and$\U_2$ and we might even solve in parallel.
Dirichlet energy
We should immediately recognize this sparsity structure from the discrete
Laplacians considered in the previous assignments. If
But we have more information then edges: we know that our graph is really a
discrete representation of a two-dimensional surface. Wobbliness distortions in
the parameterization correspond to high variation in the
We can model the problem of parametrization as an energy minimization of
the variation in the
We may discretize this problem immediately using piecewise linear
functions spanned by
In the smooth setting, minimizing the variation of
$u$ and$v$ will lead to an injective mapping if the boundary is constrained to a closed convex curve. In the discrete setting, poor triangle shapes in the original 3D mesh could lead to negative cotangent weights$w_{ij}$ so the positive stiffness weight assumption of Tutte's theorem is broken and fold-overs might occur. Keep in mind that positive weights are a sufficient condition for injectivity, but this does not imply that having a few negative weights will necessarily cause a fold-over. Even so, Floater proposes an alternative discrete Laplacian in "Mean value coordinates" in 2003 that retains some nice shape-preserving properties without negative weights.
Modeling distortion as an integral of variation over the given 3D surface is
going in the right direction, but so far we are treating
Least Squares Conformal Mappings
We can reason about distortion in terms of differential quantities of the
mapping from
Area distortion
We would like that regions on
\[
\left|
\begin{array}{cc}
\frac{∂u}{∂x} & \frac{∂u}{∂y} \
\frac{∂v}{∂x} & \frac{∂v}{∂y}
\end{array}
\right|
= 1,
\]
where
The determinant of the Jacobian of a mapping corresponds to the scale factor by which local area expands or shrinks. This quantity also appears during integration by substitution when multivariate functions are involved.
It is tempting to try to throw this equality into a least squares energy an
minimize it. Unfortunately the determinant is already a quadratic function of
Angle distortion
We would also like that local regions on
\[
\begin{align}
∇u &= ∇v^⊥ \
&↓ \
\left( \begin{array}{r}
\frac{∂u}{∂x} \
\frac{∂u}{∂y} \
\end{array} \right)
&=
\left( \begin{array}{r}
\frac{∂v}{∂y} \
-\frac{∂v}{∂x} \
\end{array} \right)
\end{align}
\]
where
By enlisting complex analysis, we can reinterpret the mapping to the real plane
$\R²$ as a mapping to the complex plane$\mathbb{C}$ . The angle preservation equality above corresponds to the Cauchy-Riemann equations. Complex functions that satisfy these equations are called conformal maps.
This equality is linear in
\[ \min_{u,v} ½ ∫_\S ‖∇u - ∇v^⊥‖² \ dA. \]
This energy was employed for surface parameterization of triangle meshes as early as "Intrinsic parameterizations of surface meshes" [Desbrun et al. 2002] and "Least squares conformal maps for automatic texture atlas generation" [Lévy 2002]. Written in this form, it's perhaps not obvious how we can discretize this over a triangle mesh. Let us massage the equations a bit, starting by expanding the squared term:
\[ ∫_\S \left(½ ‖∇u‖² + ½ ‖∇v‖² - ∇u ⋅ ∇v^⊥ \right)\ dA. \]
We should recognize the first two terms as the Dirichlet
energies of
\[
\begin{align}
∫_\S ∇u ⋅ ∇v^⊥ \ dA &= \
∫_\S \left( \begin{array}{r}
\frac{∂u}{∂x} \
\frac{∂u}{∂y} \
\end{array}\right)⋅
\left( \begin{array}{r}
\frac{∂v}{∂y} \
-\frac{∂v}{∂x} \
\end{array} \right) \ dA &= \
∫_\S \left|
\begin{array}{cc}
\frac{∂u}{∂x} & \frac{∂u}{∂y} \
\frac{∂v}{∂x} & \frac{∂v}{∂y}
\end{array}
\right| \ dA &=
∫_{\left(\begin{array}{c}u(\S) \ v(\S) \end{array}\right)} 1 \ dA
,
\end{align}
\]
where we end up with the integrated determinant of the
Jacobian of the
\[
∫_{\left(\begin{array}{c}u(\S) \ v(\S) \end{array}\right)} 1 \ dA
= ∮_{∂\left(\begin{array}{c}u(\S) \ v(\S) \end{array}\right)} \u(s)⋅\n(s) \ ds,
\]
where
If we discretize
\[
∮_{∂(\u(\S))} \u(s)⋅\n(s) \ ds = \
∑\limits_{{i,j} ∈ ∂\S} ∫_0^1
½ (\u_i + t(\u_j - \u_i))⋅\frac{(\u_j-\u_i)^⊥}{‖\u_j - \u_i‖} \ dt = \
½ ∑\limits_{{i,j} ∈ ∂\S} (\u_j-\u_i)⋅(\u_j-\u_i)^⊥ = \
½ ∑\limits_{{i,j} ∈ ∂\S} | \u_i\ \u_j |,
\]
where finally we have a simply quadratic expression: sum over all boundary
edges the determinant of the matrix with vertex positions as columns. This
quadratic form can be written as
Achtung! A naive implementation of $½ ∑\limits_{{i,j} ∈ ∂\S} | \u_i
\u_j |$ into matrix form
Putting this together with the Dirichlet energy terms, we can write the discrete least squares conformal mappings minimization problem as:
\[ \min_{\U ∈ \R^{2n}} \U^\transpose \underbrace{ \left( \left( \begin{array}{rr} \L & 0 \ 0 & \L \end{array} \right)
- \A
\right)
}_{\Q}
\U,
\]
where
$\L ∈ \R^{n × n}$ is the Dirichlet energy quadratic form (a.k.a. cotangent Laplacian) and$\Q ∈ \R^{2n × 2n}$ is the resulting (sparse) quadratic form.
Free boundary
Similar to the mass-spring methods above, without constraints the least squares
conformal mapping energy will also have a trivial solution: set
To avoid this solution, we could "fix two vertices" (as originally suggested by both [Desbrun et al. 2002] and [Lévy et al. 2002]). However, this will introduce bias. Depending on the two vertices we choose we will get a different solution. If we're really unlucky, then we might choose two vertices that the energy would rather like to place near each other and so placing them at arbitrary positions will introduce unnecessary distortion (i.e., high energy).
Instead we would like natural boundary conditions (not to be confused with Neumann boundary conditions). Natural boundary conditions minimize the given energy in the absence of explicit (or essential) boundary conditions. Natural boundary conditions are convenient if we discretize the energy before differentiating to find the minimum. If our discretization is "good", then natural boundary conditions will fall out for free (natural indeed!).
To obtain natural boundary conditions without bias and avoid the trivial solution, we can require that the solution:
- minimizes the given energy,
- has non-zero norm, and
- is orthogonal to trivial solutions.
Let's break these down. The first requirement simply ensures that we're still minimizing the given energy without monkeying around with it in any way.
The second requirement adds the constraint that the solution
\[ ∫_\S ‖\u‖² \ dA = 1. \]
In our discrete case this corresponds to:
\[
\U^\transpose
\underbrace{\left(\begin{array}{cc}\M & 0 \ 0 & \M \end{array}\right)}_{\B}
\U = 1,
\]
where
This is a quadratic constraint. Normally that would be bad news, but this type of constraint results in a well-studied generalized Eigen value problem.
Generalized Eigenvalue problem
Consider a discrete quadratic minimization problem in
$\v ∈ \R^n$ :\[ \min_{\v} ½ \v^\transpose \A \v \text{ subject to } \v^\transpose \B \v = 1, \]
where
$\A,\B ∈ \R^{n × n}$ are positive semi-definite matrices.We can enforce this constraint via the Lagrange multiplier method by introducing the scalar Lagrange multiplier
$λ$ and looking for the saddle-point of the Lagrangian:\[ \mathcal{L}(\v,λ) = ½ \v^\transpose \A \v + λ (1 - \v^\transpose \B \v ). \]
This occurs when
$∂\mathcal{L}/∂\v = 0$ and$∂\mathcal{L}/∂λ = 0$ :\[ \begin{align} \A \v - λ \B \v = 0 & → \A \v = λ \B \v,\ 1 - \v^\transpose \B \v = 0 &→ \v^\transpose \B \v = 1. \end{align} \]
This is the canonical form of the generalized Eigen value problem for which there are available numerical algorithms.
Finally, our third constraint is that the solution is orthogonal to the trivial
solutions. There are two trivial solutions. They correspond to mapping all
This eigenvector is sometimes called the Fiedler vector.
Canonical rotation
The least squares conformal mapping energy is invariant to translation and
rotation. The eigen decomposition process described above will naturally take
care of "picking" a canonical translation by pulling the solution
We can try to find a canonical rotation by using principle component
analysis on the
returned
For mappings with strong reflectional symmetry then singular value
decomposition on the covariance
matrix $\U^\transpose \U ∈ \R^{2 ×
2}$ will produce a rotation that aligns the principle direction of
Why is everything squished up in the interior?
If the surface has only a small boundary then all of the surface will have to be packed inside the interior. We're not directly punishing area distortion so in order to satisfy the angle distortion. Freeing the boundary helps a little, but ultimately the only way to mitigate this is to: 1) trade area distortion for angle distortion or 2) cut (a.k.a. "interrupt") the mapping with discontinuities (see, e.g., Goode homolosine projection used for maps of Earth).
Cutting new boundaries is always necessary for parameterizing closed surfaces. It is (still in 2017) difficult to choose the cuts in an automatic way. Good opportunity for a final project ;-).
Tasks
Blacklist
igl::harmonic
igl::lscm
igl::vector_area_matrix
Whitelist
igl::boundary_loop
igl::cotmatrix
(or your previous implementation)igl::eigs
(Use theigl::EIGS_TYPE_SM
type)igl::map_vertices_to_circle
igl::massmatrix
(or your previous implementation)igl::min_quad_with_fixed
(for minimizing a quadratic energy subject to fixed value constraints)igl::repdiag
src/tutte.cpp
Given a 3D mesh (V
,F
) with a disk topology (i.e., a manifold with single
boundary), compute a 2D parameterization according to Tutte's mapping inside
the unit disk. All boundary vertices should be mapped to the unit circle and
interior vertices mapped inside the disk without flips.
src/vector_area_matrix.cpp
Constructs the symmetric area matrix A
, s.t. [V.col(0)' V.col(1)'] * A * [V.col(0); V.col(1)]
is the vector area of the mesh (V
,F
).
src/lscm.cpp
Given a 3D mesh (V
,F
) with boundary compute a 2D parameterization that
minimizes the "least squares conformal" energy:
\[ ∫_\S ‖ ∇v - (∇u)^⊥ ‖² \ dA, \]
where U
.
Use eigen-decomposition to find an un-biased, non-trivial minimizer. Then use
singular value decomposition to find a canonical rotation to line the principle
axis of