Algorithm Search⌘K

Algorithmadvanced

Registration curves

Also called motion registration curves.

Align motions for blending by a timewarp, a coordinate frame alignment and constraint matches, computed from a dynamic time warping of frame distances.

Time
O((n + m) j) alignmentO(n m j) distancesO(n m L) time_warp
Space
O(n m L) grid
Where
L = the slope limit; j = the number of joints; m = the frames of the second motion; n = the frames of the first motion
Properties
deterministicexactofflineiterative
Origin
Lucas Kovar, Michael Gleicher, 2003

A registration curve is the data that makes a blend of two or more motions work without manual setup. It has three parts. The timewarp says which frames of the motions belong together; it is a monotone path through the grid of frame pairs, found by dynamic time warping of a frame distance. The alignment curve gives, for each pair on that path, the rotation about the vertical axis and the ground translation that best place one frame onto the other. The constraint matches pair the foot plants of the motions, so that the blend knows when each foot of the result is planted. Kovar and Gleicher (2003) built these from the point cloud distance of motion graphs; with them, motions that differ in speed, heading and timing blend without feet that slide or cross.

In plain words

Two people walk the same way, but one is slower and one walks along a curve. You want to mix their walks. First you find, for each moment of one walk, the moment of the other walk where the person stands most alike; this list of matches never goes back in time. Then, for each match, you find how to turn and move the second person on the floor so that the two overlap best. You also note when each foot of each person touches the ground. With these three lists, you can mix the two walks in any ratio, and the feet still stand where they should.

The problem

The input is two motions AA with nn frames and BB with mm frames, each frame a point cloud of the jj joint positions with yy up, and a slope limit L≥1L \ge 1. The frame distance is the point cloud distance of the motion graph page, after the best rigid 2D move of BjB_j onto AiA_i:

Dij=min⁡θ,x0,z01j∑joints∣p−Tθ,x0,z0(q)∣2.D_{ij} = \min_{\theta, x_0, z_0} \frac{1}{j} \sum_{\text{joints}} |p - T_{\theta, x_0, z_0}(q)|^2 .

An admissible path is a sequence of cells from (0,0)(0, 0) to (n−1,m−1)(n - 1, m - 1), each step (1,1)(1, 1), (1,0)(1, 0) or (0,1)(0, 1), with at most LL steps of the same non-diagonal kind in a row. The timewarp is the admissible path with the smallest sum of DD over its cells. The alignment curve is the 2D transform for each cell of the path, with the angle unwrapped so that it changes continuously.

The slope limit keeps the path from staying on one frame of a motion for long, which would freeze one of the motions in the blend. Over any L+1L + 1 steps, both motions advance.

The algorithm

  1. REGISTER(A, B, L)
  2. D[i][j] ← frame distance of Aᵢ and Bⱼ for all i, j ▷ the closed form 2D alignment
  3. 1best[(0, 0, diagonal, 0)] ← D[0][0] ▷ state: cell, last step kind, run length
  4. 2for each state (i, j, s, r) in order of i, then j
  5. 3for each step k in (1, 1), (1, 0), (0, 1)
  6. r' ← 0 if k is diagonal, r + 1 if k = s, else 1
  7. 4if r' > L then skip the step ▷ the slope limit
  8. 5relax best[(i, j) + k, k, r'] with best[(i, j, s, r)] + D at the new cell
  9. 6end ← the cheapest state at the cell (n - 1, m - 1)
  10. 7path ← the cells of the predecessors of end, from (0, 0)
  11. 8for each (i, j) on path: θ, x₀, z₀ ← best move of Bⱼ onto Aᵢ, θ unwrapped along the path
  12. return path and the alignment curve

The state carries the kind of the last step and how many of that kind came in a row, so the slope limit becomes a condition on single steps (line L4). Every step increases i+ji + j, so the states form a directed acyclic graph and one pass in order of ii and jj relaxes each state after all its predecessors.

To blend with weight ww on AA, walk the path. At the cell (i,j)(i, j) the blended frame is wAi+(1−w) Tij(Bj)w A_i + (1 - w)\, T_{ij}(B_j), and its time is wi+(1−w)jw i + (1 - w) j. The code blends point clouds to keep the example small; a real system blends joint rotations with slerp and the root by the alignment curve, and resamples the blended times at a fixed frame rate.

The paper adds two steps that the code leaves out. It fits a smooth, strictly increasing curve to the path, so that the timewarp has no stairs. It also finds the constraint matches: the foot plants of the motions that overlap in the timewarp are paired, and the blend plants a foot where the matched plants say so, with a start and end time blended from theirs.

Example

By hand. Let D=(014320)D = \begin{pmatrix} 0 & 1 & 4 \\ 3 & 2 & 0 \end{pmatrix}, n=2n = 2, m=3m = 3 and L=1L = 1. The admissible paths from (0,0)(0, 0) to (1,2)(1, 2) are (0,0),(0,1),(1,2)(0,0), (0,1), (1,2) with cost 0+1+0=10 + 1 + 0 = 1; (0,0),(1,1),(1,2)(0,0), (1,1), (1,2) with cost 2; and (0,0),(0,1),(1,1),(1,2)(0,0), (0,1), (1,1), (1,2) with cost 3. The paths (0,0),(0,1),(0,2),(1,2)(0,0), (0,1), (0,2), (1,2) and (0,0),(1,0),(1,1),(1,2)(0,0), (1,0), (1,1), (1,2) have two steps along jj in a row and are not admissible for L=1L = 1. The algorithm returns the first path, with cost 1.

The slope limit can change the answer. For D=(00055550)D = \begin{pmatrix} 0 & 0 & 0 & 5 \\ 5 & 5 & 5 & 0 \end{pmatrix}, the path (0,0),(0,1),(0,2),(1,3)(0,0), (0,1), (0,2), (1,3) has cost 0 but two steps along jj in a row. With L=2L = 2 it is the answer. With L=1L = 1 the answer is (0,0),(0,1),(1,2),(1,3)(0,0), (0,1), (1,2), (1,3), with cost 5.

A slower copy. The test makes a walk AA with one cycle in 30 frames (31 frames) and the same walk BB at two thirds of the speed, one cycle in 45 frames (46 frames). With L=2L = 2, the path stays within 1.5 frames of the line j=1.5ij = 1.5 i, the true time relation.

A rigid move. If BB is AA turned by 2.52.5 rad and moved by (1,−2)(1, -2) on the floor, the path is the diagonal, every alignment is the inverse move, and the blend at w=0.5w = 0.5 is AA itself.

Correctness

The proof file shows the following facts, in exact arithmetic.

  • Admissible paths are exactly the walks of the state graph from the start state to a state at (n−1,m−1)(n - 1, m - 1), with the same costs.
  • The state graph is acyclic, and the order of line L2 handles every state after its predecessors.
  • So line L6 finds the smallest cost of an admissible path, line L7 returns such a path, and the code raises an error exactly when no admissible path exists (Theorem 1).
  • The path is monotone, and every L+1L + 1 steps advance both motions (Theorem 2).
  • For a fixed weight, the blended times never decrease along the path (Theorem 3), so the blend never plays backward.
  • A rigid copy is recovered exactly (Theorem 4).

The proof does not show that the blend looks good. The frame distance is a visual heuristic, the slope limit is tuning, and the method assumes that the motions are similar enough in structure to be blended at all, for example with the same sequence of foot contacts.

Proof: The slope limited time warp is a minimum cost monotone path, and the blended times never decreasefull

We use the notation of the page. The arithmetic is exact. DD is an nn by mm matrix of frame distances, Dij≥0D_{ij} \ge 0. A step is one of (1,1)(1, 1), (1,0)(1, 0) and (0,1)(0, 1). An admissible path starts at (0,0)(0, 0), ends at (n−1,m−1)(n - 1, m - 1), and has no run of more than LL equal steps of kind (1,0)(1, 0), and none of more than LL steps of kind (0,1)(0, 1). Its cost is the sum of DijD_{ij} over its cells, the first one included.

The state graph

A state is (i,j,s,r)(i, j, s, r): the cell, the kind of the last step (s=0s = 0 for the diagonal, 1 for (1,0)(1, 0), 2 for (0,1)(0, 1)), and the length rr of the current run of non-diagonal steps of that kind (r=0r = 0 after a diagonal step). The start state is (0,0,0,0)(0, 0, 0, 0). From (i,j,s,r)(i, j, s, r), a step of kind kk goes to (i+δi,j+δj,k,r′)(i + \delta_i, j + \delta_j, k, r') with r′=0r' = 0 if k=0k = 0, r′=r+1r' = r + 1 if k=s≠0k = s \ne 0, and r′=1r' = 1 otherwise; line L4 forbids it if r′>Lr' > L, and the step must stay in the matrix. The cost of entering a state is DD at its cell (line L5).

Lemma 1. Admissible paths correspond one to one to walks in the state graph from the start state to a state with cell (n−1,m−1)(n - 1, m - 1), and the cost of the path is D00D_{00} plus the costs of the entered states.

Proof. Given a path, the states are fixed by its steps: ss is the last step and rr counts the run, by the rule above. The run limit of the path is exactly the test r′≤Lr' \le L. Conversely, the cells of a walk form a path whose runs are the counts rr, so it is admissible. □\square

Lemma 2. The state graph has no cycle, and the loops of lines L2 and L3 process every state after all its predecessors.

Proof. Every step increases i+ji + j by 1 or 2, so there is no cycle. A predecessor of a state at (i,j)(i, j) is at (i−1,j−1)(i - 1, j - 1), (i−1,j)(i - 1, j) or (i,j−1)(i, j - 1). The loops visit the cells with ii in the outer loop and jj in the inner loop, so all three come earlier. □\square

Theorem 1. Line L6 returns the smallest cost of an admissible path, line L7 returns such a path, and the code raises an error exactly when no admissible path exists.

Proof. By Lemma 2, when the loop reaches a state, every relaxation into it is done, and best holds the minimum over its predecessors of their best value plus DD at its cell. By induction along the order of Lemma 2, best of each reached state is the smallest cost of a walk from the start to it, and its stored predecessor gives such a walk. States that no walk reaches never enter best. Line L6 takes the minimum over the end states, and Lemma 1 turns walks into admissible paths with the same cost. If no end state is reached, there is no admissible path, and the code raises an error. ■\blacksquare

Theorem 2. The path is monotone in both indices, and every window of L+1L + 1 consecutive steps contains a step that moves ii and a step that moves jj. So the time warp never goes back in time, and it cannot hold one motion still while the other plays for more than LL frames.

Proof. Every step has δi,δj≥0\delta_i, \delta_j \ge 0. A window of L+1L + 1 steps with no step moving jj would be L+1L + 1 steps of kind (1,0)(1, 0) in a row, which the run limit forbids; the same holds for ii. ■\blacksquare

Note that an admissible path exists only if the shapes allow it: for example n=1n = 1 and m>L+1m > L + 1 admit no path.

The alignment and the blend

The alignment of each pair (i,j)(i, j) is the best 2D rigid transform of frame BjB_j onto frame AiA_i; its closed form and its optimality are proved on the motion graph page (Theorem 1 of its proof file). Line L8 adds a multiple of 2π2\pi to each angle so that it differs from the previous angle by at most π\pi; this changes no transform.

Theorem 3. For a fixed weight w∈[0,1]w \in [0, 1], the blended times τl=w il+(1−w) jl\tau_l = w\, i_l + (1 - w)\, j_l along the path never decrease, start at 0 and end at w(n−1)+(1−w)(m−1)w(n - 1) + (1 - w)(m - 1). If 0<w<10 < w < 1, they strictly increase.

Proof. From one path pair to the next, ii and jj do not decrease and at least one increases, so τl+1−τl=w δi+(1−w) δj≥0\tau_{l+1} - \tau_l = w\,\delta_i + (1 - w)\,\delta_j \ge 0, and it is positive when both weights are positive. The ends are the corners of the path. ■\blacksquare

Theorem 4. If Bj=T−1(Aj)B_j = T^{-1}(A_j) for one rigid transform TT about the vertical axis and n=mn = m, then every alignment is TT (up to 2π2\pi in the angle), the diagonal path has cost 0, and the blend at any ww equals AA along the diagonal.

Proof. The aligned distance of AiA_i and BiB_i is 0, which is the smallest possible value, so the diagonal path has cost 0 and is a minimum cost path. For each pair the transform TT makes the residual zero, so it minimizes the alignment energy; it is the one the closed form returns when the points do not all lie on the vertical line through their mean. The blend is wAi+(1−w)T(Bi)=Aiw A_i + (1 - w) T(B_i) = A_i. ■\blacksquare

The test checks that the path is the diagonal in this case; with other paths of cost 0 the code could return another one, which a strictly positive distance off the diagonal rules out.

Complexity

The distance grid has nmn m cells and each costs O(j)O(j), so it costs O(nmj)O(n m j) time. The dynamic program has 3(L+1)3 (L + 1) states per cell and three steps per state, so it costs O(nmL)O(n m L) time and space. The alignment curve costs O(j)O(j) per cell of the path, and the path has at most n+m−1n + m - 1 cells. Two clips of 300 frames each, 10 seconds at 30 frames per second, have 9⋅1049 \cdot 10^4 cells. With more than two motions, registering each one to a single reference motion makes the cost grow linearly in the number of motions.

Properties

  • Exact. The time warp is an optimal admissible path for the given distance.
  • Monotone. The path never goes back in either motion, and both motions advance within L+1L + 1 steps.
  • Invariant to the ground frame. The frame distance and the alignment do not change when a motion is turned about the vertical axis or moved on the floor.
  • Offline. The whole of both motions is needed before the first frame of the blend.

Variants and improvements

  • Smooth timewarps. Fit a strictly increasing smooth curve to the path, so that the blended speed has no steps.
  • Many motions. Register every motion to one reference motion; a point in the timewarp of the reference then gives a frame of every motion, and weights from verbs and adverbs or user input blend them.
  • Transitions. A transition from one motion to another is a registration over a short window, with a weight that goes from 1 to 0.
  • Plain DTW. Without the slope limit and the alignment, this is classic dynamic time warping, as used by motion signal processing to align motions.
  • Rotation alignment. A 3D best rotation, as in the Kabsch algorithm, would also align tilt; for characters on a floor only the vertical axis is wanted.

When to use it

Use registration curves when many motions of the same action must blend with weights that the user sets, for example walks at different speeds and turns, or reaches to different places. The setup is automatic once the motions are cut to the same action. If the motions have different contact sequences, such as a walk and a jump, no registration makes the blend work.

Pitfalls

  • Unwrapped angles. The best rotation is found with an arc tangent in (−π,π](-\pi, \pi]. Without the unwrapping of line L8, a motion that turns past π\pi jumps by 2π2\pi in the alignment curve, and a blend of the angles spins the character.
  • Stairs. A raw DTW path has stairs, where one motion waits on a frame. The slope limit bounds them, and a smooth fit removes them.
  • Ends. The path must start and end at the first and last frames; if the clips start at different phases, cut them first or allow free ends.
  • Cost. The grid is quadratic in the length. For long clips, restrict the path to a band around the diagonal.
  • Blending positions. Blending point clouds, as in the code, shortens bones. Blend rotations in a real system.

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.

registration_curves.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/registration-curves/. The authors are listed in prov/2DMA1Q.jsonl.
"""Registration curves (Kovar and Gleicher 2003) for two motions.

A motion is a list of frames; a frame is a point cloud, the world positions
(x, y, z) of its joints with y up. The registration of motion A (n frames)
and motion B (m frames) has two parts that this file computes:

  * the time warp: a path of frame pairs (i, j) from (0, 0) to
    (n - 1, m - 1), found by dynamic time warping of the frame distance
    matrix. Each step is (1, 0), (0, 1) or (1, 1), and at most L steps in a
    row go in the same non-diagonal direction (the slope limit). So the path
    is monotone in both i and j, and its slope stays in [1/L, L] over any
    L + 1 steps;
  * the alignment curve: for each pair on the path, the 2D rigid transform
    (rotation about y and translation in the ground plane) that best aligns
    frame j of B to frame i of A, with the angle unwrapped along the path.

blend() then plays the path with weight w on A: the blended frame for path
pair (i, j) is w A_i + (1 - w) T(B_j), and its time is
w i + (1 - w) j, which never decreases along the path.
"""

import math


def align_2d(P, Q):
    n = len(P)
    xb = sum(p[0] for p in P) / n
    zb = sum(p[2] for p in P) / n
    xb2 = sum(q[0] for q in Q) / n
    zb2 = sum(q[2] for q in Q) / n
    s = sum(p[0] * q[2] - q[0] * p[2] for p, q in zip(P, Q)) / n - (xb * zb2 - xb2 * zb)
    c = sum(p[0] * q[0] + p[2] * q[2] for p, q in zip(P, Q)) / n - (xb * xb2 + zb * zb2)
    t = math.atan2(s, c)
    x0 = xb - xb2 * math.cos(t) - zb2 * math.sin(t)
    z0 = zb + xb2 * math.sin(t) - zb2 * math.cos(t)
    return t, x0, z0


def transform(q, t, x0, z0):
    ct, st = math.cos(t), math.sin(t)
    return (q[0] * ct + q[2] * st + x0, q[1], -q[0] * st + q[2] * ct + z0)


def frame_distance(P, Q):
    t, x0, z0 = align_2d(P, Q)
    s = 0.0
    for p, q in zip(P, Q):
        r = transform(q, t, x0, z0)
        s += (p[0] - r[0]) ** 2 + (p[1] - r[1]) ** 2 + (p[2] - r[2]) ** 2
    return s / len(P)


def distance_grid(A, B):
    return [[frame_distance(a, b) for b in B] for a in A]


STEPS = ((1, 1), (1, 0), (0, 1))  # diagonal, along i, along j


def time_warp(D, L):
    """Minimum cost path through D with the slope limit L >= 1.

    The state is (i, j, s, r): s is the kind of the last step (0 diagonal,
    1 along i, 2 along j) and r the number of such steps in a row. A step
    of kind 1 or 2 is allowed only if it does not make r exceed L.
    Return (cost, path).
    """
    n, m = len(D), len(D[0])
    INF = math.inf
    best = {}
    best[(0, 0, 0, 0)] = (D[0][0], None)  # @line L1
    for i in range(n):  # @line L2
        for j in range(m):
            for s in range(3):
                for r in range(L + 1):
                    key = (i, j, s, r)
                    if key not in best:
                        continue
                    c = best[key][0]
                    for k, (di, dj) in enumerate(STEPS):  # @line L3
                        a, b = i + di, j + dj
                        if a >= n or b >= m:
                            continue
                        if k == 0:
                            nr = 0
                        elif k == s:
                            nr = r + 1
                        else:
                            nr = 1
                        if nr > L:  # @line L4
                            continue
                        nk = (a, b, k, nr)
                        nc = c + D[a][b]  # @line L5
                        if nc < best.get(nk, (INF,))[0]:
                            best[nk] = (nc, key)
    ends = [k for k in best if k[0] == n - 1 and k[1] == m - 1]
    if not ends:
        raise ValueError("no path satisfies the slope limit")
    end = min(ends, key=lambda k: best[k][0])  # @line L6
    path = []
    k = end
    while k is not None:
        path.append((k[0], k[1]))
        k = best[k][1]
    path.reverse()  # @line L7
    return best[end][0], path


def alignment_curve(A, B, path):
    """The transform of each path pair, with the angle unwrapped."""
    out = []
    prev = None
    for i, j in path:
        t, x0, z0 = align_2d(A[i], B[j])
        if prev is not None:
            while t - prev > math.pi:
                t -= 2 * math.pi
            while t - prev < -math.pi:
                t += 2 * math.pi
        out.append((t, x0, z0))  # @line L8
        prev = t
    return out


def register(A, B, L=2):
    D = distance_grid(A, B)
    cost, path = time_warp(D, L)
    return {"cost": cost, "path": path, "align": alignment_curve(A, B, path), "D": D}


def blend(A, B, reg, w):
    """Blended frames and their times along the path, weight w on A."""
    frames, times = [], []
    for (i, j), (t, x0, z0) in zip(reg["path"], reg["align"]):
        fb = [transform(q, t, x0, z0) for q in B[j]]
        frames.append([tuple(w * a + (1 - w) * b for a, b in zip(pa, pb))
                       for pa, pb in zip(A[i], fb)])
        times.append(w * i + (1 - w) * j)
    return frames, times
test_registration_curves.py 127 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/registration-curves/. The authors are listed in prov/2DMA1Q.jsonl.
"""Tests of registration curves.

The slope limited dynamic time warping equals a brute force search over all
admissible paths on small random grids. The time warp is monotone, starts
and ends at the corners and obeys the slope limit. A slower copy of a clip
is registered close to the true time ratio, a rigidly moved copy gives its
transform back, and the blended times never decrease. Motion data is made
in code.
"""

import math
import random

import registration_curves as rc


def brute(D, L):
    n, m = len(D), len(D[0])
    best = [math.inf, None]

    def go(i, j, s, r, c, path):
        if i == n - 1 and j == m - 1:
            if c < best[0]:
                best[0], best[1] = c, list(path)
            return
        for k, (di, dj) in enumerate(rc.STEPS):
            a, b = i + di, j + dj
            if a >= n or b >= m:
                continue
            nr = 0 if k == 0 else (r + 1 if k == s else 1)
            if nr > L:
                continue
            path.append((a, b))
            go(a, b, k, nr, c + D[a][b], path)
            path.pop()

    go(0, 0, 0, 0, D[0][0], [(0, 0)])
    return best[0]


def check_path(path, n, m, L):
    assert path[0] == (0, 0) and path[-1] == (n - 1, m - 1)
    run, last = 0, None
    for (i, j), (a, b) in zip(path, path[1:]):
        step = (a - i, b - j)
        assert step in rc.STEPS
        if step == (1, 1):
            run, last = 0, None
        else:
            run = run + 1 if step == last else 1
            last = step
            assert run <= L


def walk(n, speed, heading, x0, z0):
    out = []
    ch, sh = math.cos(heading), math.sin(heading)
    for i in range(n):
        ph = 2 * math.pi * speed * i / 30.0
        local = [(0.0, 1.0 + 0.04 * math.cos(2 * ph), 0.0),
                 (0.3 * math.sin(ph), 0.1 + 0.08 * max(0.0, math.sin(ph)), 0.15),
                 (-0.3 * math.sin(ph), 0.1 + 0.08 * max(0.0, -math.sin(ph)), -0.15),
                 (-0.2 * math.sin(ph), 1.2, 0.25),
                 (0.2 * math.sin(ph), 1.2, -0.25)]
        out.append([(x * ch - z * sh + x0, y, x * sh + z * ch + z0) for x, y, z in local])
    return out


def test_dtw_equals_brute_force():
    rng = random.Random(3)
    for _ in range(40):
        n, m = rng.randint(1, 6), rng.randint(1, 6)
        L = rng.randint(1, 3)
        D = [[rng.random() for _ in range(m)] for _ in range(n)]
        b = brute(D, L)
        if b == math.inf:
            try:
                rc.time_warp(D, L)
                assert False, "a path was found where none exists"
            except ValueError:
                pass
            continue
        cost, path = rc.time_warp(D, L)
        assert abs(cost - b) < 1e-12
        assert abs(sum(D[i][j] for i, j in path) - cost) < 1e-12
        check_path(path, n, m, L)


def test_timewarp_of_slower_copy():
    A = walk(31, 1.0, 0.0, 0.0, 0.0)   # one cycle in 30 frames
    B = walk(46, 2.0 / 3.0, 0.0, 0.0, 0.0)  # the same cycle in 45 frames
    reg = rc.register(A, B, L=2)
    path = reg["path"]
    check_path(path, 31, 46, 2)
    for i, j in path:
        assert abs(j - 1.5 * i) <= 1.5


def test_alignment_recovers_rigid_move():
    A = walk(20, 1.0, 0.0, 0.0, 0.0)
    B = walk(20, 1.0, 0.0, 0.0, 0.0)
    th, x0, z0 = 2.5, 1.0, -2.0
    ct, st = math.cos(th), math.sin(th)
    # B is A moved by the inverse of (th, x0, z0)
    B = [[((x - x0) * ct - (z - z0) * st, y, (x - x0) * st + (z - z0) * ct) for x, y, z in fr]
         for fr in A]
    reg = rc.register(A, B, L=2)
    assert reg["path"] == [(i, i) for i in range(20)]
    for t, a, b in reg["align"]:
        assert abs(t - th) < 1e-9 and abs(a - x0) < 1e-9 and abs(b - z0) < 1e-9
    frames, _ = rc.blend(A, B, reg, 0.5)
    assert max(abs(p - q) for fa, fb in zip(frames, A) for pa, pb in zip(fa, fb)
               for p, q in zip(pa, pb)) < 1e-9


def test_blend_times_are_monotone():
    A = walk(31, 1.0, 0.0, 0.0, 0.0)
    B = walk(40, 0.8, 0.4, 0.5, 0.5)
    reg = rc.register(A, B, L=3)
    for w in (0.0, 0.25, 0.5, 1.0):
        _, times = rc.blend(A, B, reg, w)
        assert all(b >= a for a, b in zip(times, times[1:]))
        assert times[0] == 0 and abs(times[-1] - (w * 30 + (1 - w) * 39)) < 1e-12
    angles = [t for t, _, _ in reg["align"]]
    assert all(abs(b - a) < math.pi for a, b in zip(angles, angles[1:]))

History

Lucas Kovar and Michael Gleicher introduced registration curves at the ACM SIGGRAPH/Eurographics Symposium on Computer Animation in 2003. They used the frame distance of their motion graphs (2002) inside dynamic time warping, which Bruderlin and Williams had already used to align motions in 1995, and added the alignment curve and the constraint matches. Dynamic time warping itself comes from speech recognition in the 1970s.

References

  1. Lucas Kovar and Michael Gleicher, Flexible automatic motion blending with registration curves, ACM SIGGRAPH/Eurographics Symposium on Computer Animation, 2003, 214 to 224, the timewarp from dynamic time warping with a slope limit, the alignment curve, the constraint matches, and the blend that uses them
  2. Lucas Kovar, Michael Gleicher and Frederic Pighin, Motion graphs, ACM Transactions on Graphics 21(3) (SIGGRAPH 2002), 473 to 482, the point cloud frame distance with the closed form 2D alignment
  3. Armin Bruderlin and Lance Williams, Motion signal processing, SIGGRAPH 95, 1995, 97 to 104, the timewarping of motions by dynamic programming before a blend

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.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.alignment
  • a full proof of time.distances
  • a full proof of time.time_warp
  • a full proof of space.grid
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example