Exemplo n.º 1
0
def _read_dmat_helper(args):
    i, base_path, dmat_prefix = args
    filename = os.path.join(base_path, dmat_prefix + str(i) + '.dmat')
    if (i % 13 == 0):
        print('.', end='', flush=True)
    displacements = igl.eigen.MatrixXd()
    igl.readDMAT(filename, displacements)
    return e2p(displacements)
Exemplo n.º 2
0
def read_dmat(i):
    #filename = 'data-armadillo/verts%d.ply' % (i + 1)
    filename = base_path + 'displacements_%d.dmat' % i
    if (i % 13 == 0):
        print('.', end='', flush=True)
    verts = igl.eigen.MatrixXd()
    igl.readDMAT(filename, verts, _i, _d, _d)
    return e2p(verts)
Exemplo n.º 3
0
def load_displacements_and_energy(model_root,
                                  use_reencoded=False,
                                  use_extra_samples=False):
    from keras.models import Model, load_model
    encoder = load_model(os.path.join(model_root, 'keras_models/encoder.hdf5'))
    U = igl.eigen.MatrixXd()
    igl.readDMAT(
        os.path.join(model_root, 'pca_results/ae_pca_components.dmat'), U)

    if not use_reencoded and not use_extra_samples:
        training_data_path = os.path.join(model_root, 'training_data/training')
        displacements = my_utils.load_displacement_dmats_to_numpy(
            training_data_path)
        flatten_displ, unflatten_displ = my_utils.get_flattners(displacements)
        encoded_displacements = encoder.predict(
            flatten_displ(displacements) @ U)
        energies = my_utils.load_energy_dmats_to_numpy(training_data_path)

    if use_reencoded:
        reencoded_training_data_path = os.path.join(
            model_root, 'augmented_training_data/reencoded/')
        displacements_path = os.path.join(reencoded_training_data_path,
                                          'displacements.dmat')
        enc_displacements_path = os.path.join(reencoded_training_data_path,
                                              'enc_displacements.dmat')
        energies_path = os.path.join(reencoded_training_data_path,
                                     'energies.dmat')

        displacements = my_utils.read_double_dmat_to_numpy(displacements_path)
        encoded_displacements = my_utils.read_double_dmat_to_numpy(
            enc_displacements_path)
        energies = my_utils.read_double_dmat_to_numpy(energies_path)

    if use_extra_samples:
        sampled_training_data_path = os.path.join(
            model_root, 'augmented_training_data/sampled/')
        displacements_path = os.path.join(sampled_training_data_path,
                                          'displacements.dmat')
        enc_displacements_path = os.path.join(sampled_training_data_path,
                                              'enc_displacements.dmat')
        energies_path = os.path.join(sampled_training_data_path,
                                     'energies.dmat')

        displacements = numpy.append(
            displacements,
            my_utils.read_double_dmat_to_numpy(displacements_path),
            axis=0)
        encoded_displacements = numpy.append(
            encoded_displacements,
            my_utils.read_double_dmat_to_numpy(enc_displacements_path),
            axis=0)
        energies = numpy.append(
            energies,
            my_utils.read_double_dmat_to_numpy(energies_path),
            axis=0)

    return displacements, encoded_displacements, energies
Exemplo n.º 4
0
def load_base_vert_and_face_dmat_to_numpy(base_path):
    """ Returns a tuple (verts, faces) """
    verts_filename = os.path.join(base_path, 'base_verts.dmat')
    faces_filename = os.path.join(base_path, 'base_faces.dmat')

    verts = igl.eigen.MatrixXd()
    faces = igl.eigen.MatrixXi()
    igl.readDMAT(verts_filename, verts)
    igl.readDMAT(faces_filename, faces)

    return e2p(verts), e2p(faces)
Exemplo n.º 5
0
    igl.readOBJ(TUTORIAL_SHARED_PATH + "arm.obj", V, F)
    U = igl.eigen.MatrixXd(V)
    igl.readTGF(TUTORIAL_SHARED_PATH + "arm.tgf", C, BE)

    # retrieve parents for forward kinematics
    igl.directed_edge_parents(BE, P)
    rest_pose = igl.RotationList()
    igl.directed_edge_orientations(C, BE, rest_pose)
    poses = [[igl.eigen.Quaterniond.Identity() for i in range(4)] for j in range(4)]

    twist = igl.eigen.Quaterniond(pi, igl.eigen.MatrixXd([1, 0, 0]))
    poses[1][2] = rest_pose[2] * twist * rest_pose[2].conjugate()
    bend = igl.eigen.Quaterniond(-pi * 0.7, igl.eigen.MatrixXd([0, 0, 1]))
    poses[3][2] = rest_pose[2] * bend * rest_pose[2].conjugate()

    igl.readDMAT(TUTORIAL_SHARED_PATH + "arm-weights.dmat", W)
    igl.lbs_matrix(V, W, M)

    # Plot the mesh with pseudocolors
    viewer = igl.viewer.Viewer()
    viewer.data.set_mesh(U, F)
    viewer.data.set_edges(C, BE, sea_green)
    viewer.core.show_lines = False
    viewer.core.show_overlay_depth = False
    viewer.core.line_width = 1
    viewer.core.trackball_angle.normalize()
    viewer.callback_pre_draw = pre_draw
    viewer.callback_key_down = key_down
    viewer.core.is_animating = False
    viewer.core.camera_zoom = 2.5
    viewer.core.animation_max_fps = 30.0
Exemplo n.º 6
0
from shared import TUTORIAL_SHARED_PATH, check_dependencies

dependencies = ["glfw"]
check_dependencies(dependencies)


V = igl.eigen.MatrixXd()
F = igl.eigen.MatrixXi()

# Load a mesh in OFF format
igl.readOFF(TUTORIAL_SHARED_PATH + "cheburashka.off", V, F)

# Read scalar function values from a file, U: #V by 1
U = igl.eigen.MatrixXd()
igl.readDMAT(TUTORIAL_SHARED_PATH + "cheburashka-scalar.dmat", U)
U = U.col(0)

# Compute gradient operator: #F*3 by #V
G = igl.eigen.SparseMatrixd()
igl.grad(V, F, G)

# Compute gradient of U
GU = (G * U).MapMatrix(F.rows(), 3)

# Compute gradient magnitude
GU_mag = GU.rowwiseNorm()

viewer = igl.glfw.Viewer()
viewer.data().set_mesh(V, F)
    sea_green = igl.eigen.MatrixXd([[70. / 255., 252. / 255., 167. / 255.]])

    selected = 0
    pose = igl.RotationList()
    anim_t = 1.0
    anim_t_dir = -0.03

    igl.readMESH(TUTORIAL_SHARED_PATH + "hand.mesh", V, T, F)
    U = igl.eigen.MatrixXd(V)
    igl.readTGF(TUTORIAL_SHARED_PATH + "hand.tgf", C, BE)

    # Retrieve parents for forward kinematics
    igl.directed_edge_parents(BE, P)

    # Read pose as matrix of quaternions per row
    igl.readDMAT(TUTORIAL_SHARED_PATH + "hand-pose.dmat", Q)
    igl.column_to_quats(Q, pose)
    assert (len(pose) == BE.rows())

    # List of boundary indices (aka fixed value indices into VV)
    b = igl.eigen.MatrixXi()
    # List of boundary conditions of each weight function
    bc = igl.eigen.MatrixXd()

    igl.boundary_conditions(V, T, C, igl.eigen.MatrixXi(), BE, igl.eigen.MatrixXi(), b, bc)

    # compute BBW weights matrix
    bbw_data = igl.BBWData()
    # only a few iterations for sake of demo
    bbw_data.active_set_params.max_iter = 8
    bbw_data.verbosity = 2
Exemplo n.º 8
0
    U = igl.eigen.MatrixXd(V)
    igl.readTGF(TUTORIAL_SHARED_PATH + "arm.tgf", C, BE)

    # retrieve parents for forward kinematics
    igl.directed_edge_parents(BE, P)
    rest_pose = igl.RotationList()
    igl.directed_edge_orientations(C, BE, rest_pose)
    poses = [[igl.eigen.Quaterniond.Identity() for i in range(4)]
             for j in range(4)]

    twist = igl.eigen.Quaterniond(pi, igl.eigen.MatrixXd([1, 0, 0]))
    poses[1][2] = rest_pose[2] * twist * rest_pose[2].conjugate()
    bend = igl.eigen.Quaterniond(-pi * 0.7, igl.eigen.MatrixXd([0, 0, 1]))
    poses[3][2] = rest_pose[2] * bend * rest_pose[2].conjugate()

    igl.readDMAT(TUTORIAL_SHARED_PATH + "arm-weights.dmat", W)
    igl.lbs_matrix(V, W, M)

    # Plot the mesh with pseudocolors
    viewer = igl.viewer.Viewer()
    viewer.data.set_mesh(U, F)
    viewer.data.set_edges(C, BE, sea_green)
    viewer.core.show_lines = False
    viewer.core.show_overlay_depth = False
    viewer.core.line_width = 1
    viewer.core.trackball_angle.normalize()
    viewer.callback_pre_draw = pre_draw
    viewer.callback_key_down = key_down
    viewer.core.is_animating = False
    viewer.core.camera_zoom = 2.5
    viewer.core.animation_max_fps = 30.0
Exemplo n.º 9
0
def read_double_dmat_to_numpy(path):
    U = igl.eigen.MatrixXd()
    igl.readDMAT(path, U)
    return e2p(U)
Exemplo n.º 10
0
    if key == ord(' '):
        viewer.core.is_animating = not viewer.core.is_animating
        return True
    if key == ord('D') or key == ord('d'):
        deformation_field = not deformation_field
        return True
    return False


igl.readOBJ(TUTORIAL_SHARED_PATH + "decimated-max.obj", V, F)
U = igl.eigen.MatrixXd(V)

# S(i) = j: j<0 (vertex i not in handle), j >= 0 (vertex i in handle j)
S = igl.eigen.MatrixXd()
igl.readDMAT(TUTORIAL_SHARED_PATH + "decimated-max-selection.dmat", S)

S = S.castint()

b = igl.eigen.MatrixXd([[t[0] for t in [(i, S[i]) for i in range(0, V.rows())] if t[1] >= 0]]).transpose().castint()

# Boundary conditions directly on deformed positions
U_bc.resize(b.rows(), V.cols())
V_bc.resize(b.rows(), V.cols())

for bi in range(0, b.rows()):
    V_bc.setRow(bi, V.row(b[bi]))

    if S[b[bi]] == 0:
        # Don't move handle 0
        U_bc.setRow(bi, V.row(b[bi]))
Exemplo n.º 11
0
import pyigl as igl

from shared import TUTORIAL_SHARED_PATH, check_dependencies

dependencies = ["glfw"]
check_dependencies(dependencies)

V = igl.eigen.MatrixXd()
F = igl.eigen.MatrixXi()

# Load a mesh in OFF format
igl.readOFF(TUTORIAL_SHARED_PATH + "cheburashka.off", V, F)

# Read scalar function values from a file, U: #V by 1
U = igl.eigen.MatrixXd()
igl.readDMAT(TUTORIAL_SHARED_PATH + "cheburashka-scalar.dmat", U)
U = U.col(0)

# Compute gradient operator: #F*3 by #V
G = igl.eigen.SparseMatrixd()
igl.grad(V, F, G)

# Compute gradient of U
GU = (G * U).MapMatrix(F.rows(), 3)

# Compute gradient magnitude
GU_mag = GU.rowwiseNorm()

viewer = igl.glfw.Viewer()
viewer.data().set_mesh(V, F)
Exemplo n.º 12
0
    if key == ord(' '):
        viewer.core.is_animating = not viewer.core.is_animating
        return True
    if key == ord('D') or key == ord('d'):
        deformation_field = not deformation_field
        return True
    return False


igl.readOBJ(TUTORIAL_SHARED_PATH + "decimated-max.obj", V, F)
U = igl.eigen.MatrixXd(V)

# S(i) = j: j<0 (vertex i not in handle), j >= 0 (vertex i in handle j)
S = igl.eigen.MatrixXd()
igl.readDMAT(TUTORIAL_SHARED_PATH + "decimated-max-selection.dmat", S)

S = S.castint()

b = igl.eigen.MatrixXi([[
    t[0] for t in [(i, S[i]) for i in range(0, V.rows())] if t[1] >= 0
]]).transpose()

# Boundary conditions directly on deformed positions
U_bc.resize(b.rows(), V.cols())
V_bc.resize(b.rows(), V.cols())

for bi in range(0, b.rows()):
    V_bc.setRow(bi, V.row(b[bi]))

    if S[b[bi]] == 0:
Exemplo n.º 13
0
    if key == ord(' '):
        viewer.core.is_animating = not viewer.core.is_animating
        return True
    if key == ord('D') or key == ord('d'):
        deformation_field = not deformation_field
        return True
    return False


igl.readOBJ("../../tutorial/shared/decimated-max.obj", V, F)
U = igl.eigen.MatrixXd(V)

# S(i) = j: j<0 (vertex i not in handle), j >= 0 (vertex i in handle j)
S = igl.eigen.MatrixXd()
igl.readDMAT("../../tutorial/shared/decimated-max-selection.dmat", S)

S = S.castint()

b = igl.eigen.MatrixXi([[
    t[0] for t in [(i, S[i]) for i in range(0, V.rows())] if t[1] >= 0
]]).transpose()

# Boundary conditions directly on deformed positions
U_bc.resize(b.rows(), V.cols())
V_bc.resize(b.rows(), V.cols())

for bi in range(0, b.rows()):
    V_bc.setRow(bi, V.row(b[bi]))

    if (S[b[bi]] == 0):
Exemplo n.º 14
0
def reencode_and_augment_training_data(model_root, num_extra_per_poses=0):
    """ 
    Loads existing traing data and generates new encoding / energy vector pairs for 
    1. Energy evalutated on decoded displacements of training data.
    2. Energy evaluated on poses sampled around the encoded training poses.
    """
    training_data_path = os.path.join(model_root, 'training_data/training')
    U = igl.eigen.MatrixXd()
    igl.readDMAT(
        os.path.join(model_root, 'pca_results/ae_pca_components.dmat'), U)

    displacements = my_utils.load_displacement_dmats_to_numpy(
        training_data_path)
    flatten_displ, unflatten_displ = my_utils.get_flattners(displacements)

    from keras.models import Model, load_model
    encoder = load_model(os.path.join(model_root, 'keras_models/encoder.hdf5'))
    decoder = load_model(os.path.join(model_root, 'keras_models/decoder.hdf5'))

    encoded_displacements = encoder.predict(flatten_displ(displacements) @ U)
    decoded_displacements = decoder.predict(
        encoded_displacements) @ U.transpose()

    print('Generating extra samples...')
    extra_encoded_displacements = sample_more_encoded_displacements(
        encoded_displacements, num_extra_per_poses)
    extra_decoded_displacements = decoder.predict(
        extra_encoded_displacements) @ U.transpose()

    sampled_training_data_path = os.path.join(
        model_root, 'augmented_training_data/sampled/')
    reencoded_training_data_path = os.path.join(
        model_root, 'augmented_training_data/reencoded/')
    my_utils.create_dir_if_not_exist(sampled_training_data_path)
    my_utils.create_dir_if_not_exist(reencoded_training_data_path)

    extra_displacements_path = save_mat_with_prefix(
        sampled_training_data_path, 'displacements',
        extra_decoded_displacements)
    save_mat_with_prefix(sampled_training_data_path, 'enc_displacements',
                         extra_encoded_displacements)
    reencoded_displacements_path = save_mat_with_prefix(
        reencoded_training_data_path, 'displacements', decoded_displacements)
    save_mat_with_prefix(reencoded_training_data_path, 'enc_displacements',
                         encoded_displacements)

    tet_mesh_path = os.path.join(model_root, 'tets.mesh')
    parameters_path = os.path.join(model_root,
                                   'training_data/training/parameters.json')

    print('Computing energies for reencoded poses...')
    subprocess.call([
        './generate_data_for_pose/build/bin/GenerateDataForPose',
        reencoded_displacements_path, tet_mesh_path, parameters_path
    ])

    print('Computing energies for samples...')
    subprocess.call([
        './generate_data_for_pose/build/bin/GenerateDataForPose',
        extra_displacements_path, tet_mesh_path, parameters_path
    ])
Exemplo n.º 15
0
    if key == ord(' '):
        viewer.core.is_animating = not viewer.core.is_animating
        return True
    if key == ord('D') or key == ord('d'):
        deformation_field = not deformation_field;
        return True
    return False


igl.readOBJ("../../tutorial/shared/decimated-max.obj",V,F)
U = igl.eigen.MatrixXd(V)

# S(i) = j: j<0 (vertex i not in handle), j >= 0 (vertex i in handle j)
S = igl.eigen.MatrixXd()
igl.readDMAT("../../tutorial/shared/decimated-max-selection.dmat",S)

S = S.castint()

b = igl.eigen.MatrixXi([[t[0] for t in [(i,S[i]) for i in range(0,V.rows())] if t[1] >= 0]]).transpose()

# Boundary conditions directly on deformed positions
U_bc.resize(b.rows(),V.cols())
V_bc.resize(b.rows(),V.cols())

for bi in range(0,b.rows()):
    V_bc.setRow(bi,V.row(b[bi]))

    if (S[b[bi]] == 0):
        # Don't move handle 0
        U_bc.setRow(bi,V.row(b[bi]))
Exemplo n.º 16
0
# Add the igl library to the modules search path
import sys, os
sys.path.insert(0, os.getcwd() + "/../")

import pyigl as igl

V = igl.eigen.MatrixXd()
F = igl.eigen.MatrixXi()

# Load a mesh in OFF format
igl.readOFF("../../tutorial/shared/cheburashka.off", V, F)

# Read scalar function values from a file, U: #V by 1
U = igl.eigen.MatrixXd()
igl.readDMAT("../../tutorial/shared/cheburashka-scalar.dmat",U)
U = U.col(0)

# Compute gradient operator: #F*3 by #V
G = igl.eigen.SparseMatrixd()
igl.grad(V,F,G)

# Compute gradient of U
GU = (G*U).MapMatrix(F.rows(),3)

# Compute gradient magnitude
GU_mag = GU.rowwiseNorm()

viewer = igl.viewer.Viewer()
viewer.data.set_mesh(V, F)

# Compute pseudocolor for original function