Esempio n. 1
0
        inbox = numpy.array(list(itertools.product(xRange, yRange)))

        # Test inside face for all pixels in the bounding box
        mask[inbox[:, 1], inbox[:, 0]] |= points_in_triangle(face, inbox)

    print_progress(1.0)
    print()
    return ~(mask)

if __name__ == "__main__":
    import obj_reader
    import texture
    from find_seam import find_seam, seam_to_UV
    from util import *

    mesh = obj_reader.quads_to_triangles(obj_reader.load_obj(
        '../models/cow.obj'))
    texture = numpy.array(texture.load_texture(
        "../textures/cow/Cow_Monster_N.png"))

    height, width, depth = (texture.shape + (1,))[:3]
    N = width * height
    textureVec = texture.reshape(N, -1)

    print("\nFinding seam of model")
    seam, boundary, foldovers = find_seam(mesh)
    uv_seam, uv_boundary, uv_foldovers = seam_to_UV(
        mesh, seam, boundary, foldovers)
    print("Done\n")

    print("Number of edges along the seam: %d" % (len(seam) * 2))
    print("Number of edges along the boundary: %d" % len(boundary))
Esempio n. 2
0
    return seam_non_matching, seam_mesh_boundary, seam_foldover_edges


def seam_to_UV(mesh, seam, boundary, foldovers):
    """
    Convert the seam, boundary, and foldovers to be in UV-space.
    Input  Format:
        seam      = [[[fi, [fvi0, fvi1]], [fi', [fvi0', fvi1']]], ...]
        boundary  = [ [fi0, [fvi0, fvi1]], ...]
        foldovers = [ [fi0, [fvi0, fvi1]], ...]
    Return Format:
        ( [[[uv0, uv1], [uv0', uv1']], ...],
          [ [uv0, uv1], ...],
          [ [uv0, uv1], ...] )
    """
    uv_seam = [[[mesh.vt[mesh.f[edge[0]][i].vt] for i in edge[1]]
        for edge in edgePair] for edgePair in seam]
    uv_boundary = [[mesh.vt[mesh.f[edge[0]][i].vt] for i in edge[1]]
        for edge in boundary]
    uv_foldovers = [[mesh.vt[mesh.f[edge[0]][i].vt] for i in edge[1]]
        for edge in foldovers]
    return uv_seam, uv_boundary, uv_foldovers

if __name__ == "__main__":
    import obj_reader
    mesh = obj_reader.load_obj("../models/cube.obj")
    seam_fast = find_seam(mesh)
    print("find_seam_fast.find_seam():")
    print(seam_fast)
Esempio n. 3
0
                           int(numpy.ceil(bbox[1][1])) + 1))
        inbox = numpy.array(list(itertools.product(xRange, yRange)))

        # Test inside face for all pixels in the bounding box
        mask[inbox[:, 1], inbox[:, 0]] |= points_in_triangle(face, inbox)

    return ~mask


if __name__ == "__main__":
    import obj_reader
    import texture
    from find_seam import find_seam, seam_to_UV

    mesh = obj_reader.quads_to_triangles(
        obj_reader.load_obj('../models/cow.obj'))
    texture = numpy.array(
        texture.load_texture("../textures/cow/Cow_Monster_N.png"))

    height, width, depth = (texture.shape + (1, ))[:3]
    N = width * height
    textureVec = texture.reshape(N, -1)

    logging.info("\nFinding seam of model")
    seam, boundary, foldovers = find_seam(mesh)
    uv_seam, uv_boundary, uv_foldovers = seam_to_UV(mesh, seam, boundary,
                                                    foldovers)
    logging.info("Done\n")

    logging.info("Number of edges along the seam: %d" % (len(seam) * 2))
    logging.info("Number of edges along the boundary: %d" % len(boundary))
Esempio n. 4
0
            texture.save_texture(textureData, out_texture)

        current_depth = next_depth


########################################
# CMD-line tool for getting filenames. #
########################################
if __name__ == '__main__':
    (in_mesh, in_texture, out_texture, loadFromDirectory, loadFromData,
     sv_method, do_global) = parse_args()

    # Time the amount of time this takes.
    startTime = time.time()

    mesh = obj_reader.quads_to_triangles(obj_reader.load_obj(in_mesh))

    textureData, textures = (loadTextures(in_texture, loadFromDirectory,
                                          loadFromData))

    height, width = textureData.shape[:2]

    isUnbounded = any([tex.isFloat for tex in textures])
    # TODO: Remove this comment for bounds.
    bounds = None  # (None if isUnbounded else (0, 1))
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    energy_fname = ("%s-%s-%senergies.csv" %
                    (os.path.splitext(os.path.basename(in_mesh))[0],
                     os.path.splitext(os.path.basename(in_texture))[0],
                     "global-" if do_global else ""))
    # out_file = open(os.path.join(root, "energies", energy_fname), "w")