ndio/utils/mesh.py
def export_ply(filename, cutout, level=0):
    """
    Converts a dense annotation to a .PLY, using Marching Cubes (PyMCubes).

    Arguments:
        filename (str): The filename to write out to
        cutout (numpy.ndarray): The dense annotation
        level (int): The level at which to run mcubes

    Returns:
        boolean success
    """
    if ".ply" not in filename:
        filename = filename + ".ply"

    vs, fs = mcubes.marching_cubes(cutout, level)

    with open(filename, 'w') as fh:
        lines = [
            "ply"
            "format ascii 1.0",
            "comment generated by ndio",
            "element vertex " + str(len(vs)),
            "property float32 x",
            "property float32 y",
            "property float32 z",
            "element face " + str(len(fs)),
            "property list uint8 int32 vertex_index",
            "end_header"
        ]
        fh.writelines(lines)
        for v in vs:
            fh.write("{} {} {}".format(v[0], v[1], v[2]))
        for f in fs:
            fh.write("3 {} {} {}".format(f[0], f[1], f[2]))
def export_ply(filename, cutout, level=0):
    """
    Converts a dense annotation to a .PLY, using Marching Cubes (PyMCubes).

    Arguments:
        filename (str): The filename to write out to
        cutout (numpy.ndarray): The dense annotation
        level (int): The level at which to run mcubes

    Returns:
        boolean success
    """
    if ".ply" not in filename:
        filename = filename + ".ply"

    vs, fs = mcubes.marching_cubes(cutout, level)

    with open(filename, 'w') as fh:
        lines = [
            "ply"
            "format ascii 1.0",
            "comment generated by ndio",
            "element vertex " + str(len(vs)),
            "property float32 x",
            "property float32 y",
            "property float32 z",
            "element face " + str(len(fs)),
            "property list uint8 int32 vertex_index",
            "end_header"
        ]
        fh.writelines(lines)
        for v in vs:
            fh.write("{} {} {}".format(v[0], v[1], v[2]))
        for f in fs:
            fh.write("3 {} {} {}".format(f[0], f[1], f[2]))
Converts a dense annotation to a .PLY, using Marching Cubes (PyMCubes).

    Arguments:
        filename (str): The filename to write out to
        cutout (numpy.ndarray): The dense annotation
        level (int): The level at which to run mcubes

    Returns:
        boolean success