RHM.numpy.rhm_solver

Functions

bijectivity_energy(P12X2, P21, X2, A2, area2)

Computes the bijectivity energy

get_energies(mesh1, mesh2, X1, X2, P12, P21, ...)

Computes the energies

harmonic_energy(P12X2, W1, area2)

Computes the harmonic energy

penalty_energy(P12X2, X12, A1, area1, area2)

Computes the coupling energy

rhm_refine(mesh1, mesh2, P12_init, P21_init)

Refines a functional map using the RHM algorithm.

rhm_refine_fast(mesh1, mesh2, X1, X2, ...[, ...])

Solve RHM refinement with embeddings

solve_P12(X1, X2, X12, X21, area1, area2, ...)

Solve for the pointwise map

solve_X12_fast(X2, P12, P21, vertex_areas1, ...)

Solves for transferred embedding X12

RHM.numpy.rhm_solver.rhm_refine(mesh1, mesh2, P12_init, P21_init, alpha=0.0005, beta=0.005, emb_dim=8, nit_max=200, nit_min=20, abs_tol=1e-09, n_jobs=1, log=False, precise=True, last_precise=True, verbose=False)

Refines a functional map using the RHM algorithm.

This solves for the optimal pointwise map between two meshes using the RHM algorithm using the RHM energy:

\(E_{RHM} = \alpha E_{dirichlet} + (1-\alpha)E_{bij} + \beta E_{coupling}\)$

Parameters:
  • mesh1 (TriMesh) – The source mesh.

  • mesh2 (TriMesh) – The target mesh.

  • P12_init (PointWiseMap) – The initial map from mesh1 to mesh2. (N1, N2)

  • P21_init (PointWiseMap) – The initial map from mesh2 to mesh1. (N2, N1)

  • alpha (float) – The weight of the harmonic energy term. Bijectivity is weighted by 1-alpha.

  • beta (float) – The weight of the penalty energy term.

  • emb_dim (int) – The dimension of the embedding space for vertices (distance mimics the geodesic distance).

  • nit_max (int) – The maximum number of iterations.

  • nit_min (int) – The minimum number of iterations.

  • abs_tol (float) – The absolute tolerance for the stopping criterion.

  • n_jobs (int) – The number of parallel jobs to run for NN queries

  • log (bool) – Whether to return the values of the energy at each step.

  • precise (bool) – Whether to use the precise computation for the energy terms (else, use simple nn queries).

  • last_precise (bool) – Whether to use the precise computation for the last iteration. Only used if precise is False. Else always True

  • verbose (bool) – Whether to display a progress bar.

Returns:

  • P12 (PointWiseMap) – The refined map from mesh1 to mesh2.

  • P21 (PointWiseMap) – The refined map from mesh2 to mesh1.

  • energy_log (list, optional) – The energy values at each iteration if log is True.

RHM.numpy.rhm_solver.rhm_refine_fast(mesh1, mesh2, X1, X2, P12_init, P21_init, alpha=0.0005, beta=0.005, nit_max=200, nit_min=20, abs_tol=1e-09, n_jobs=1, log=False, precise=True, last_precise=True, verbose=False)

Solve RHM refinement with embeddings

Parameters:
  • mesh1 (TriMesh) – The source mesh.

  • mesh2 (TriMesh) – The target mesh.

  • X1 (np.ndarray) – The embedding of mesh1 vertices. (N1, p)

  • X2 (np.ndarray) – The embedding of mesh2 vertices. (N1, p)

  • P12_init (PointWiseMap) – The initial map from mesh1 to mesh2. (N1, N2)

  • P21_init (PointWiseMap) – The initial map from mesh2 to mesh1. (N2, N1)

  • alpha (float) – The weight of the harmonic energy term. Bijectivity is weighted by 1-alpha.

  • beta (float) – The weight of the penalty energy term.

  • emb_dim (int) – The dimension of the embedding space for vertices (distance mimics the geodesic distance).

  • nit_max (int) – The maximum number of iterations.

  • nit_min (int) – The minimum number of iterations.

  • abs_tol (float) – The absolute tolerance for the stopping criterion.

  • n_jobs (int) – The number of parallel jobs to run for NN queries

  • log (bool) – Whether to return the values of the energy at each step.

  • precise (bool) – Whether to use the precise computation for the energy terms (else, use simple nn queries).

  • last_precise (bool) – Whether to use the precise computation for the last iteration. Only used if precise is False. Else always True

  • verbose (bool) – Whether to display a progress bar.

Returns:

  • P12 (PointWiseMap) – The refined map from mesh1 to mesh2.

  • P21 (PointWiseMap) – The refined map from mesh2 to mesh1.

  • energy_log (list, optional) – The energy values at each iteration if log is True.

RHM.numpy.rhm_solver.solve_P12(X1, X2, X12, X21, area1, area2, alpha, beta, n_jobs=1, precise=True, faces2=None)

Solve for the pointwise map

Solves \((1-\alpha) E_{bij}(P_{12}, X_{21}, X_1) + \beta * E_{coupling}(P_{12}, X_2, X_{12})\)

Expresses the problem in the form $min_{P_{12}}||P_{12} @ A - B||_2^2

where \(A = w_{bij} * X_2\) and \(B = w_{bij} * X_1 + w_{couple} * X_{12}\)

Parameters:
  • X1 (np.ndarray) – The embedding of mesh1 vertices. (N1, p)

  • X2 (np.ndarray) – The embedding of mesh2 vertices. (N2, p)

  • X12 (np.ndarray) – The embedding of mesh1 vertices in the target space. (N1, p)

  • X21 (np.ndarray) – The embedding of mesh2 vertices in the source space. (N2, p)

  • area1 (float) – The total area of mesh1.

  • area2 (float) – The total area of mesh2.

  • alpha (float) – The weight of the harmonic energy term. Bijectivity is weighted by 1-alpha.

  • beta (float) – The weight of the penalty energy term.

  • n_jobs (int) – The number of parallel jobs to run for NN queries

  • precise (bool) – Whether to use the precise computation for the energy terms (else, use simple nn queries).

  • faces2 (np.ndarray, optional) – The faces of mesh2 if precise is True.

Returns:

P12 – The refined map from mesh1 to mesh2. (N1, N2)

Return type:

PointWiseMap

RHM.numpy.rhm_solver.solve_X12_fast(X2, P12, P21, vertex_areas1, vertex_areas2, W1, alpha, beta)

Solves for transferred embedding X12

Solves \(\alpha E_{dirichlet}(X_{12}) + (1-\alpha) E_{bij}(P_{21}, X_{12}, X_2) + \beta E_{coupling}(X_{12}, X_2, P_{12})\)

Expresses the problem in the form $min_{X_{12}}||A X_{12} - B||_2^2

And solves the dual problem \(A^T A X_{12} = A^T B\)

Parameters:
  • X2 (np.ndarray) – The embedding of mesh2 vertices. (N2, p)

  • P12 (PointWiseMap) – The refined map from mesh1 to mesh2. (N1, N2)

  • P21 (PointWiseMap) – The refined map from mesh2 to mesh1. (N2, N1)

  • vertex_areas1 (np.ndarray) – The area of each vertex in mesh1. (N1,)

  • vertex_areas2 (np.ndarray) – The area of each vertex in mesh2. (N2,)

  • W1 (sparse.csr_matrix) – The laplacian matrix of mesh1. (N1, N1)

  • alpha (float) – The weight of the harmonic energy term. Bijectivity is weighted by 1-alpha.

  • beta (float) – The weight of the penalty energy term.

Returns:

X12 – The refined embedding of mesh1 vertices in the target space. (N1, p)

Return type:

np.ndarray

RHM.numpy.rhm_solver.harmonic_energy(P12X2, W1, area2)

Computes the harmonic energy

\(E_{dirichlet}(X_{12}) = \frac{1}{A_2} \|X_{12}\|_{W_1}\)

Parameters:
  • P12X2 (np.ndarray) – \(P_{12} X_2\). The embedding of mesh1 vertices in the target space. (N1, p)

  • W1 (sparse.csr_matrix) – The laplacian matrix of mesh1. (N1, N1)

  • area2 (float) – The total area of mesh2.

Returns:

energy – The harmonic energy

Return type:

float

RHM.numpy.rhm_solver.penalty_energy(P12X2, X12, A1, area1, area2)

Computes the coupling energy

\(E_{coupling}(X_{12}, P_{12}X_2) = \frac{1}{A_1 A_2} \|X_{12} - P_{12}X_2\|_{A_1}^2\)

Parameters:
  • P12X2 (np.ndarray) – \(P_{12} X_2\). The embedding of mesh1 vertices in the target space. (N1, p)

  • X12 (np.ndarray) – The embedding of mesh1 vertices in the target space. (N1, p)

  • A1 (sparse.csr_matrix) – The area matrix of mesh1. (N1, N1)

  • area1 (float) – The total area of mesh1.

  • area2 (float) – The total area of mesh2.

Returns:

energy – The penalty energy

Return type:

float

RHM.numpy.rhm_solver.bijectivity_energy(P12X2, P21, X2, A2, area2)

Computes the bijectivity energy

\(E_{bij}(P_{21}, X_{12}, X_2) = \frac{1}{A_2} \|X_{2} - P_{21}X_{12}\|_{A_2}^2\)

Parameters:
  • P12X2 (np.ndarray) – \(P_{12} X_2\). The embedding of mesh1 vertices in the target space. (N1, p)

  • P21 (PointWiseMap) – The refined map from mesh2 to mesh1. (N2, N1)

  • X2 (np.ndarray) – The embedding of mesh2 vertices. (N2, p)

  • A2 (sparse.csr_matrix) – The area matrix of mesh2. (N2, N2)

  • area2 (float) – The total area of mesh2.

Returns:

energy – The bijectivity energy

Return type:

float

RHM.numpy.rhm_solver.get_energies(mesh1, mesh2, X1, X2, P12, P21, X12, X21, alpha, beta)

Computes the energies

Parameters:
  • mesh1 (TriMesh) – The source mesh.

  • mesh2 (TriMesh) – The target mesh.

  • X1 (np.ndarray) – The embedding of mesh1 vertices. (N1, p)

  • X2 (np.ndarray) – The embedding of mesh2 vertices. (N2, p)

  • P12 (PointWiseMap) – The refined map from mesh1 to mesh2. (N1, N2)

  • P21 (PointWiseMap) – The refined map from mesh2 to mesh1. (N2, N1)

  • X12 (np.ndarray) – The embedding of mesh1 vertices in the target space. (N1, p)

  • X21 (np.ndarray) – The embedding of mesh2 vertices in the source space. (N2, p)

  • alpha (float) – The weight of the harmonic energy term. Bijectivity is weighted by 1-alpha.

  • beta (float) – The weight of the penalty energy term.

Returns:

energies – The harmonic, bijectivity, coupling and total energies

Return type:

list