Algorithmadvanced
Extended free-form deformation
Also called EFFD.
Free-form deformation with lattices of non-parallelepiped shape, such as cylinders, glued into one, so that the deformation follows the object.
- Solves
- Shape deformation
- Time
- Θ(N q) deformO(N c K q) embed
- Space
- Θ(c q + N) extra
- Where
- K = the largest number of Newton steps per chunk; N = the number of points to deform; c = the number of chunks of the lattice; q = the number of control points of one chunk
- Model
- Real RAM
- Properties
- deterministicnot exactonlineiterative
- Evidence
- Proof sketchCode in 1 languages
Extended free-form deformation (EFFD) is free-form deformation with a lattice of any shape. The lattice is made of several Bezier volumes, the chunks, glued along shared faces, so it can be a ring, a cylinder or a bent tube that hugs the object. Because the undeformed lattice is no longer a box, the local coordinates of a point have no closed form, and EFFD finds them by Newton iteration. After that, the deformation is the same as in FFD: each point follows its chunk. Sabine Coquillart (1990) introduced the method as a sculpting tool, for example to dig a groove that runs around a cylinder.
In plain words
In plain free-form deformation the object sits in a box of jelly with a grid of handles. Many objects do not fit a box well: a bottle, a ring, a bent pipe. EFFD lets you build the jelly from several pieces, each shaped like part of the object, glued side by side. The catch is that a point of the object no longer knows at once where it sits inside its piece. So, before the edit, each point searches for its place, by guessing and correcting the guess a few times. When the search fails, the point lies outside every piece and is left alone. Then the handles move, and each point follows its own piece as in plain FFD.
The problem
The input is a lattice of chunks and a set of points. Chunk is a Bezier volume over , where maps the local index of a control point to an index in one global list . Two chunks that share a face use the same global indices for its control points. is the rest lattice and the edited lattice. The output is, for each point , the point , where , or NOT FOUND if no chunk holds .
The algorithm
is the 3 by 3 Jacobian matrix of at , computed from the derivatives of the Bernstein polynomials.
EFFD(X, chunks, P, P')- 1
for each chunk b do - 2
w ← (1/2, 1/2, 1/2) - 3
repeat at most K times - 4
r ← B_b(w; P) - X - 5
if |r| < tol then leave the loop - 6
w ← w - J_b(w)^(-1) r - 7
if |r| < tol and w ∈ [0, 1]^3 then - 8
return B_b(w; P') - 9
return NOT FOUND
Lines L2 to L6 are Newton's method for the system of three equations in three unknowns. Line L7 accepts the result only if it converged and lies in the parameter cube; a solution outside the cube belongs to the extension of the polynomial, not to the chunk. The embedding, lines L1 to L7, depends only on , so it runs once; line L8 runs again each time the user edits . The implementation also stops a chunk when is singular or the iterate runs away.
Example
The lattice is a quarter of a thick ring and the next quarter, two chunks of degree . In the first chunk, runs along a quadratic arc with the control points , , , runs from the radius to , and runs from the height to . The second chunk uses the arc , , , and the two chunks share the 4 control points of the face at 90 degrees. The point is , and Newton's method from finds it in the first chunk at once. Now move the two outer middle control points and to and . Each has the weight at , so moves by to . The point lies in the hole of the ring; Newton's method converges in neither chunk to a parameter in the cube, so it is NOT FOUND. The tests check these values, the recovery of random parameters, and the continuity across the shared face.
Correctness
If line L7 accepts for chunk , then within the tolerance, so lies in chunk and line L8 is the FFD of that chunk. With , line L8 returns , so the rest lattice gives the identity; an affine map applied to all of gives the same map on the points, by the Bernstein identities of free-form deformation. On a shared face, both chunks reduce to the same Bezier patch of the shared control points, so the deformation is continuous across the face for every . Newton's method converges quadratically from a start close enough to a solution where is invertible; this is a local result, and from it can fail or find a solution outside the cube. The proof gives the details and the cases where the embedding can miss a point.
Proof: Extended free-form deformation is the identity at rest on embedded points, reproduces affine maps, and is continuous across shared facesfull
We use the notation of the page. A chunk has the degree and the map , with . We say that line L7 accepts for if and .
What the algorithm returns
Lemma 1. If the algorithm returns a point for , it returns for a chunk and a parameter with .
Proof. Line L8 runs only after line L7 accepts , and nothing changes or between the two lines.
So the result is a point of chunk of the edited lattice, at the parameter of a point of chunk of the rest lattice that is within tol of .
Identity and affine invariance
Theorem 1. If , the returned point satisfies .
Proof. By Lemma 1, and .
Theorem 2. If for an affine map and every global index , then , so .
Proof. for every , by the binomial theorem in each variable. So . Then .
Continuity across a shared face
Theorem 3. Let chunk and chunk share a face: for all , , and both have the degrees in the other two variables. Then for every edited lattice and all , .
Proof. if and 0 otherwise, and if and 0 otherwise. So and , which are the same sum.
Two points just on each side of the face have parameters close to in chunk and in chunk , so by the continuity of each polynomial they map to nearby points: the deformation has no tear at the face. The first derivative across the face is on one side and on the other, so the deformation is only if these agree; an edit that moves one inner layer alone breaks this, which is the crease of the Pitfalls.
The embedding
Newton's method for converges quadratically to a root if is invertible, is Lipschitz near , and the start is close enough to (the local convergence theorem for Newton's method on systems; see Newton's method for systems). is a polynomial, so is Lipschitz on bounded sets. The theorem says nothing about a start at far from the root, and the algorithm makes no claim there. There are three ways the embedding can miss:
- Newton's method does not converge within steps, or meets a singular .
- It converges to a root outside , which line L7 rejects, while another root inside the cube exists.
- The rest chunk folds, so two parameters in the cube map to , and the one found depends on the start.
In cases 1 and 2 the algorithm can return NOT FOUND for a point inside the lattice, and in case 3 the result is one of several valid answers. If the rest chunk is one to one on with an invertible Jacobian, case 3 cannot occur, and every root in the cube is the unique parameter of . The tests use a lattice of this kind, where the arc map times the radius has a strictly increasing angle, so each chunk is one to one.
Complexity
One Newton step evaluates and in time for a chunk with control points, plus for the 3 by 3 solve. Embedding a point costs in the worst case, when it tries every chunk; a bounding box per chunk usually rejects most chunks at once. After the embedding, each edit costs per point. The lattice takes memory, and each point stores its chunk and its .
Properties
- Identity at rest (proved). If the embedding converged, the rest lattice gives back the point, within the Newton tolerance.
- Affine invariance (proved). An affine map of the whole lattice gives the same map of the embedded points.
- C0 across shared faces (proved). Chunks that share control points on a face meet continuously for every edit.
- Not C1 in general. The derivatives across a shared face agree only if the neighbouring layers of control points satisfy the usual Bezier conditions; an edit that ignores them makes a crease.
- Embedding is numerical. Newton's method has only local convergence. The start, the iteration limit and the tolerance are tuning, not part of a proof.
- Points outside do not move. As in FFD, points with no chunk are left in place.
Variants and improvements
- Better starts. Start Newton's method from the nearest sample of a precomputed grid of parameters, or subdivide the chunk until the point is close, to make the embedding robust.
- Bounding boxes. The convex hull property of Bezier volumes bounds each chunk by its control points, so a chunk whose box misses the point can be skipped.
- Smooth junctions. Keep the layers on both sides of a shared face collinear when editing, to get junctions.
- Cages. Cage-based deformation uses a coarse mesh of any shape and closed-form coordinates, so it needs no Newton iteration at all.
When to use it
Use EFFD when the deformation should follow a curved or ring-shaped part of an object, such as a groove around a cylinder or a bulge along a bent pipe, and a box lattice would put control points far from the surface. If the lattice can be a box, plain FFD is simpler and has exact local coordinates. If the shape is better framed by a coarse mesh than by Bezier chunks, use cage-based deformation.
Pitfalls
- Failed embedding. A point near a chunk boundary or a fold of the rest lattice can be NOT FOUND or land in the wrong chunk. Check the residual, and try all chunks before giving up.
- Folded rest lattice. If changes sign inside a chunk, a point can have two parameters, and the deformation is not well defined there.
- Tolerance. A loose tolerance gives points that jump a little even at rest. The tests use and accept parameters within of the cube.
- Shared indices. Chunks that store their own copies of the shared face points instead of shared indices drift apart when only one copy moves.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/extended-free-form-deformation/. The authors are listed in prov/7CMXN6.jsonl.
"""Extended free-form deformation in the spirit of Coquillart (1990).
The lattice is a list of chunks. Each chunk is a Bezier volume of degree
(l, m, n) whose control points are indices into one global list of points,
so neighbouring chunks that share a face share the same control points and
meet with C0 continuity. The undeformed lattice need not be a box, so the
local coordinates of a point are not given by a formula. They are found by
Newton iteration on B_c(w) = X, chunk by chunk. The deformed point is then
B_c(w) evaluated with the moved control points.
"""
from math import comb
NOT_FOUND = None
def bernstein(deg, x):
"""Return [B_0^deg(x), ..., B_deg^deg(x)]."""
return [comb(deg, i) * (1 - x) ** (deg - i) * x ** i for i in range(deg + 1)]
def bernstein_derivative(deg, x):
"""Return the derivatives of the Bernstein polynomials of degree deg."""
if deg == 0:
return [0.0]
low = bernstein(deg - 1, x)
return [deg * ((low[i - 1] if i >= 1 else 0) - (low[i] if i < deg else 0)) for i in range(deg + 1)]
class Chunk:
"""One Bezier volume. idx[i][j][k] is an index into the global point list."""
def __init__(self, deg, idx):
self.deg = tuple(deg)
l, m, n = self.deg
if len(idx) != l + 1 or any(len(p) != m + 1 for p in idx) or any(len(r) != n + 1 for p in idx for r in p):
raise ValueError("the index grid does not match the degree")
self.idx = idx
def evaluate(self, points, w):
"""Return B_c(w) for the given global point list."""
l, m, n = self.deg
bs, bt, bu = bernstein(l, w[0]), bernstein(m, w[1]), bernstein(n, w[2])
out = [0.0, 0.0, 0.0]
for i in range(l + 1):
for j in range(m + 1):
for k in range(n + 1):
c = bs[i] * bt[j] * bu[k]
p = points[self.idx[i][j][k]]
for d in range(3):
out[d] += c * p[d]
return tuple(out)
def jacobian(self, points, w):
"""Return the 3 by 3 matrix dB_c/dw; column a is the derivative by w[a]."""
l, m, n = self.deg
b = (bernstein(l, w[0]), bernstein(m, w[1]), bernstein(n, w[2]))
db = (bernstein_derivative(l, w[0]), bernstein_derivative(m, w[1]), bernstein_derivative(n, w[2]))
jac = [[0.0] * 3 for _ in range(3)]
for i in range(l + 1):
for j in range(m + 1):
for k in range(n + 1):
p = points[self.idx[i][j][k]]
ws = (db[0][i] * b[1][j] * b[2][k], b[0][i] * db[1][j] * b[2][k], b[0][i] * b[1][j] * db[2][k])
for a in range(3):
for d in range(3):
jac[d][a] += ws[a] * p[d]
return jac
def solve3(a, r):
"""Solve a x = r for a 3 by 3 matrix by Cramer's rule. Return None if singular."""
def det(m):
return (
m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1])
- m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0])
+ m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0])
)
d = det(a)
scale = max(abs(v) for row in a for v in row) or 1.0
if abs(d) <= 1e-14 * scale ** 3:
return None
out = []
for c in range(3):
m = [[r[i] if k == c else a[i][k] for k in range(3)] for i in range(3)]
out.append(det(m) / d)
return out
def embed(chunks, points, x, iters=30, tol=1e-12, slack=1e-9):
"""Return (chunk index, w) with B_c(w) = x and w in [0, 1]^3, or NOT_FOUND."""
for c, chunk in enumerate(chunks): # @line L1
w = [0.5, 0.5, 0.5] # @line L2
ok = False
for _ in range(iters): # @line L3
b = chunk.evaluate(points, w)
r = [b[d] - x[d] for d in range(3)] # @line L4
if max(abs(v) for v in r) < tol: # @line L5
ok = True
break
step = solve3(chunk.jacobian(points, w), r)
if step is None:
break
w = [w[d] - step[d] for d in range(3)] # @line L6
if max(abs(v) for v in w) > 1e6:
break
if ok and all(-slack <= v <= 1 + slack for v in w): # @line L7
return c, tuple(min(1.0, max(0.0, v)) for v in w)
return NOT_FOUND # @line L9
def deform(chunks, rest, moved, x, **kw):
"""Return the deformed position of x, or NOT_FOUND if x is outside the lattice."""
hit = embed(chunks, rest, x, **kw)
if hit is NOT_FOUND:
return NOT_FOUND
c, w = hit
return chunks[c].evaluate(moved, w) # @line L8
def quarter_ring_lattice(r_in=1.0, r_out=2.0, height=1.0):
"""Build the two-chunk example lattice: two quarter rings around the z axis.
Each chunk has degree (2, 1, 1). The index s runs along a quadratic arc
with the control points (r, 0), (r, r), (0, r) for the first quarter and
(0, r), (-r, r), (-r, 0) for the second. The index t runs from r_in to
r_out and the index u from z = 0 to z = height. The two chunks share the
face at 90 degrees through shared indices.
"""
points = []
index = {}
def pid(key, p):
if key not in index:
index[key] = len(points)
points.append(p)
return index[key]
arcs = [((1, 0), (1, 1), (0, 1)), ((0, 1), (-1, 1), (-1, 0))]
chunks = []
for q, arc in enumerate(arcs):
idx = []
for i, (ax, ay) in enumerate(arc):
plane = []
for j, r in enumerate((r_in, r_out)):
row = []
for k, z in enumerate((0.0, height)):
row.append(pid((2 * q + i, j, k), (r * ax, r * ay, z)))
plane.append(row)
idx.append(plane)
chunks.append(Chunk((2, 1, 1), idx))
return chunks, points, index
test_extended_free_form_deformation.py 87 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/extended-free-form-deformation/. The authors are listed in prov/7CMXN6.jsonl.
import math
import random
from extended_free_form_deformation import NOT_FOUND, deform, embed, quarter_ring_lattice
def close(a, b, eps=1e-9):
return all(abs(x - y) <= eps for x, y in zip(a, b))
def test_newton_recovers_the_local_coordinates():
chunks, pts, _ = quarter_ring_lattice()
rng = random.Random(11)
for _ in range(40):
c = rng.randrange(2)
w = tuple(rng.uniform(0.02, 0.98) for _ in range(3))
x = chunks[c].evaluate(pts, w)
hit = embed(chunks, pts, x)
assert hit is not NOT_FOUND
c2, w2 = hit
assert close(chunks[c2].evaluate(pts, w2), x)
assert c2 == c
assert close(w2, w, 1e-8)
def test_undeformed_lattice_is_identity():
chunks, pts, _ = quarter_ring_lattice()
rng = random.Random(12)
for _ in range(30):
c = rng.randrange(2)
x = chunks[c].evaluate(pts, [rng.random() for _ in range(3)])
assert close(deform(chunks, pts, pts, x), x)
def test_worked_example():
chunks, pts, index = quarter_ring_lattice()
x = chunks[0].evaluate(pts, (0.5, 0.5, 0.5))
assert close(x, (1.125, 1.125, 0.5))
moved = list(pts)
for k in range(2):
p = index[(1, 1, k)]
moved[p] = (2.5, 2.5, moved[p][2])
y = deform(chunks, pts, moved, x)
assert close(y, (1.25, 1.25, 0.5))
def test_shared_face_is_continuous():
chunks, pts, index = quarter_ring_lattice()
rng = random.Random(13)
moved = [tuple(v + rng.uniform(-0.2, 0.2) for v in p) for p in pts]
for _ in range(20):
t, u = rng.random(), rng.random()
a = chunks[0].evaluate(moved, (1.0, t, u))
b = chunks[1].evaluate(moved, (0.0, t, u))
assert close(a, b, 1e-12)
# Points just on each side of the shared face map to nearby points.
eps = 1e-7
xa = chunks[0].evaluate(pts, (1 - eps, t, u))
xb = chunks[1].evaluate(pts, (eps, t, u))
ya = deform(chunks, pts, moved, xa)
yb = deform(chunks, pts, moved, xb)
assert math.dist(ya, yb) < 1e-5
def test_point_outside_is_not_found():
chunks, pts, _ = quarter_ring_lattice()
for x in ((0.2, 0.2, 0.5), (3.0, 0.0, 0.5), (0.0, -1.5, 0.5), (1.2, 1.2, 1.5), (1.2, 1.2, -0.1)):
assert embed(chunks, pts, x) is NOT_FOUND
assert deform(chunks, pts, pts, x) is NOT_FOUND
def test_affine_motion_of_all_points_is_reproduced():
chunks, pts, _ = quarter_ring_lattice()
rng = random.Random(14)
a = [[rng.uniform(-1, 1) + (2 if r == c else 0) for c in range(3)] for r in range(3)]
b = [rng.uniform(-1, 1) for _ in range(3)]
def aff(p):
return tuple(sum(a[r][c] * p[c] for c in range(3)) + b[r] for r in range(3))
moved = [aff(p) for p in pts]
for _ in range(20):
c = rng.randrange(2)
x = chunks[c].evaluate(pts, [rng.random() for _ in range(3)])
assert close(deform(chunks, pts, moved, x), aff(x), 1e-8)
History
Coquillart presented EFFD at SIGGRAPH 1990 as a way to sculpt shapes that the box lattice of Sederberg and Parry could not follow. She built lattices from elementary ones, such as cylindrical lattices, joined them, and then embedded the object numerically. The cost and the fragility of the numerical embedding later pushed work toward cages with closed-form coordinates, such as mean value, harmonic and Green coordinates.
References
- Sabine Coquillart, Extended free-form deformation: a sculpturing tool for 3D geometric modeling, SIGGRAPH 90, Computer Graphics 24(4), 187-196, 1990, the whole paper (lattices built from joined elementary lattices such as cylinders, the embedding of a point by a numerical solve, and the deformation of the object with the lattice)
- Thomas W. Sederberg and Scott R. Parry, Free-form deformation of solid geometric models, SIGGRAPH 86, Computer Graphics 20(4), 151-160, 1986, the whole paper (the parallelepiped lattice that EFFD generalizes)
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag 7CMXN6 Edit this page History Report an error Markdown