Beispiel #1
0
from cmmlib import cmm
from cmmlib.inout import load_mesh
from cmmlib.vis.weights import show_many_weights

mu = 2.0
K = 6

vms = []
for i, fn in enumerate(['hand_868', 'hand_868_holes2']):
    verts, tris = load_mesh('meshes/%s.obj' % fn)

    Phi_cpr = cmm.compressed_manifold_modes(verts, tris, K, mu=mu)
    Phi_dense = cmm.manifold_harmonics(verts, tris, K)

    vms += [(verts, tris, Phi_cpr, 'CMM #%d' % i),
            (verts, tris, Phi_dense, 'MH #%d' % i)]

show_many_weights(vms, show_labels=True)
import numpy as np
from cmmlib import cmm
from cmmlib.inout import load_mesh
from cmmlib.vis.weights import show_many_weights

K = 6
verts, tris = load_mesh('meshes/hand_4054.obj')

# compute bases
Phi_cmh = cmm.compressed_manifold_modes(verts, tris, K, mu=2, scaled=False)
Phi_mh = cmm.manifold_harmonics(verts, tris, K, scaled=False)

# reconstruct from bases
verts_rec_cmh = np.dot(Phi_cmh, np.dot(Phi_cmh.T, verts))
verts_rec_mh = np.dot(Phi_mh, np.dot(Phi_mh.T, verts))

show_many_weights(
    ((verts, tris, None, 'Input'), (verts_rec_mh, tris, None, 'MH reconstr.'),
     (verts_rec_cmh, tris, None, 'CMM reconstr.')),
    show_labels=True,
    actor_options=dict(edge_visibility=True, line_width=1.0))
Beispiel #3
0
import numpy as np

from cmmlib import cmm
from cmmlib.inout import load_mesh
from cmmlib.vis.weights import show_many_weights

scape_dir = path.join('meshes', 'scape')
if not path.exists(scape_dir) or not path.exists(
        path.join(scape_dir, 'mesh000.off')):
    print "SCAPE dataset not found. You need to get it from James Davis."
    print "Instructions on this website: "
    print "http://robotics.stanford.edu/~drago/Projects/scape/scape.html"
    sys.exit(1)

meshes = [
    load_mesh(path.join(scape_dir, 'mesh%03d.off' % i), normalize=True)
    for i in [0, 7, 10]
]

results = []
for verts, tris in meshes:
    Phi_cmh = cmm.compressed_manifold_modes(verts,
                                            tris,
                                            10,
                                            mu=12.5,
                                            scaled=True,
                                            maxiter=2000)
    results.append((verts, tris, Phi_cmh))

show_many_weights(results)
Beispiel #4
0
import sys
from os import path
import numpy as np

from cmmlib import cmm
from cmmlib.inout import load_mesh
from cmmlib.vis.weights import show_many_weights


scape_dir = path.join('meshes', 'scape')
if not path.exists(scape_dir) or not path.exists(path.join(scape_dir, 'mesh000.off')):
    print "SCAPE dataset not found. You need to get it from James Davis."
    print "Instructions on this website: "
    print "http://robotics.stanford.edu/~drago/Projects/scape/scape.html"
    sys.exit(1)

meshes = [load_mesh(path.join(scape_dir, 'mesh%03d.off' % i), normalize=True)
          for i in [0, 7, 10]]

results = []
for verts, tris in meshes:
    Phi_cmh = cmm.compressed_manifold_modes(
        verts, tris, 10, mu=12.5, scaled=True, maxiter=2000)
    results.append((verts, tris, Phi_cmh))

show_many_weights(results)
from cmmlib import cmm
from cmmlib.inout import load_mesh
from cmmlib.vis.weights import show_many_weights


mu = 2.0
K = 6

vms = []
for i, fn in enumerate(['hand_868', 'hand_868_holes2']):
    verts, tris = load_mesh('meshes/%s.obj' % fn)

    Phi_cpr = cmm.compressed_manifold_modes(verts, tris, K, mu=mu)
    Phi_dense = cmm.manifold_harmonics(verts, tris, K)

    vms += [(verts, tris, Phi_cpr, 'CMM #%d' % i),
            (verts, tris, Phi_dense, 'MH #%d' % i)]

show_many_weights(vms, show_labels=True)
import numpy as np
from cmmlib import cmm
from cmmlib.inout import load_mesh
from cmmlib.vis.weights import show_many_weights


K = 6
verts, tris = load_mesh('meshes/hand_4054.obj')

# compute bases
Phi_cmh = cmm.compressed_manifold_modes(verts, tris, K, mu=2, scaled=False)
Phi_mh = cmm.manifold_harmonics(verts, tris, K, scaled=False)

# reconstruct from bases
verts_rec_cmh = np.dot(Phi_cmh, np.dot(Phi_cmh.T, verts))
verts_rec_mh = np.dot(Phi_mh, np.dot(Phi_mh.T, verts))

show_many_weights(
    ((verts, tris, None, 'Input'),
     (verts_rec_mh, tris, None, 'MH reconstr.'),
     (verts_rec_cmh, tris, None, 'CMM reconstr.')),
    show_labels=True,
    actor_options=dict(edge_visibility=True, line_width=1.0))
    # for different K, compute the CMMs
    Phis = []
    for K in Ks:
        Phi_cmh = cmm.compressed_manifold_modes(
            verts, tris, K, mu, scaled=True, init='varimax')
        Phis.append(Phi_cmh)

    # color the mesh according to the CMMs
    lut = LUTManager(lut_mode='hsv').lut.table.to_array()
    colors = []
    for K, Phi in zip(Ks, Phis):
        # pass Phi through the lookup table depending on it's strength
        ti = np.linspace(0, 1, K, endpoint=False) * (lut.shape[0]-1)
        lut_rgb = lut[ti.astype(np.int), :3].astype(np.float)
        Phi = np.abs(Phi / (Phi.max(0) - Phi.min(0))[np.newaxis])
        a = Phi.sum(axis=1)[:, np.newaxis]
        Phi_color = (lut_rgb[np.newaxis] * Phi[:, :, np.newaxis]).sum(axis=1)
        # mix with grey
        color = np.clip(Phi_color * a + 200 * (1-a), 0, 255)
        colors.append(color)

    results.append((verts, tris, colors))

# visualize!
show_many_weights([
    (verts, tris, color.astype(np.uint8)[...,np.newaxis], "#%s K=%d" % (path.basename(fn), K))
    for (fn, _, _), (verts, tris, colors) in zip(experiments, results)
    for K, color in zip(Ks, colors)],
    center=False, show_labels=True,
    )