How to use the plyfile.PlyData function in plyfile

To help you get started, we’ve selected a few plyfile examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yifeishi / HierarchyLayout / prerprocess / pointcnn / folder for trans / data_utils.py View on Github external
desc = desc + vertex_color.dtype.descr

    vertex_all = np.empty(n, dtype=desc)

    for prop in vertex.dtype.names:
        vertex_all[prop] = vertex[prop]

    if normals is not None:
        for prop in vertex_normal.dtype.names:
            vertex_all[prop] = vertex_normal[prop]

    if colors is not None:
        for prop in vertex_color.dtype.names:
            vertex_all[prop] = vertex_color[prop]

    ply = plyfile.PlyData([plyfile.PlyElement.describe(vertex_all, 'vertex')], text=False)
    if not os.path.exists(os.path.dirname(filename)):
        os.makedirs(os.path.dirname(filename))
    ply.write(filename)
github nateroblin33 / 3d-bone-tracking-tool / files / speedcam.py View on Github external
dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])

    face6 = np.array([([0, 1, 2], 0, 0, 0),#black face
                ([0, 2, 3], 0,   255,   255),
                ([0, 1, 3],   255, 0,   0),
                ([1, 2, 3],   255,   140, 0)],
               dtype=[('vertex_indices', 'i4', (3,)),
                      ('red', 'u1'), ('green', 'u1'),
                      ('blue', 'u1')])

    # Saves Point Cloud files under the given names (I have been changing it every time I want to make a new set of Point Clouds, otherwise it overwrites the previous file with the same name)
    PlyData([PlyElement.describe(vertex1, 'vertex'),PlyElement.describe(face1, 'face')]).write(bone1FileName)
    PlyData([PlyElement.describe(vertex2, 'vertex'),PlyElement.describe(face2, 'face')]).write(bone2FileName)
    PlyData([PlyElement.describe(vertex3, 'vertex'),PlyElement.describe(face3, 'face')]).write(bone3FileName)
    PlyData([PlyElement.describe(vertex4, 'vertex'),PlyElement.describe(face4, 'face')]).write(bone4FileName)
    PlyData([PlyElement.describe(vertex5, 'vertex'),PlyElement.describe(face5, 'face')]).write(bone5FileName)
    PlyData([PlyElement.describe(vertex6, 'vertex'),PlyElement.describe(face6, 'face')]).write(bone6FileName)
github woodfrog / floor-sp / utils / data_preprocess.py View on Github external
def pc_transform(read_file, pc_file, trans_matrix, downsample=True, write_output=False, out_path=None):
    if read_file:
        with open(pc_file, 'rb') as f:
            plydata = PlyData.read(f)
            dtype = plydata['vertex'].data.dtype
        #print('dtype: {}'.format(dtype))

        data = np.array(plydata['vertex'].data.tolist())
    else:
        data = pc_file
        assert isinstance(data, np.ndarray)
        data = np.array(data.tolist())

    xyz = data[:, :3]
    xyz = np.concatenate([xyz, np.ones([xyz.shape[0], 1])], axis=1)

    transformed_xyz = np.matmul(trans_matrix, xyz.transpose([1, 0])).transpose([1, 0])
    transformed_xyz = transformed_xyz[:, :3]

    normal_trans_mat = trans_matrix.copy()
github daveredrum / Pointnet2.ScanNet / scripts / visualize.py View on Github external
)

    vertex = np.array(
        vertex,
        dtype=[
            ("x", np.dtype("float32")), 
            ("y", np.dtype("float32")), 
            ("z", np.dtype("float32")),
            ("red", np.dtype("uint8")),
            ("green", np.dtype("uint8")),
            ("blue", np.dtype("uint8"))
        ]
    )

    output_pc = PlyElement.describe(vertex, "vertex")
    output_pc = PlyData([output_pc])
    output_root = os.path.join(CONF.OUTPUT_ROOT, args.folder, "preds")
    os.makedirs(output_root, exist_ok=True)
    output_pc.write(os.path.join(output_root, "{}.ply".format(args.scene_id)))
github loicland / superpoint_graph / partition / provider.py View on Github external
def write_ply_labels(filename, xyz, rgb, labels):
    """write into a ply file. include the label"""
    prop = [('x', 'f4'), ('y', 'f4'), ('z', 'f4'), ('red', 'u1'), ('green', 'u1')
            , ('blue', 'u1'), ('label', 'u1')]
    vertex_all = np.empty(len(xyz), dtype=prop)
    for i_prop in range(0, 3):
        vertex_all[prop[i_prop][0]] = xyz[:, i_prop]
    for i_prop in range(0, 3):
        vertex_all[prop[i_prop+3][0]] = rgb[:, i_prop]
    vertex_all[prop[6][0]] = labels
    ply = PlyData([PlyElement.describe(vertex_all, 'vertex')], text=True)
    ply.write(filename)
#------------------------------------------------------------------------------
github colmap / colmap / scripts / python / merge_ply_files.py View on Github external
files = []
    for file_name in os.listdir(args.folder_path):
        if len(file_name) < 4 or file_name[-4:].lower() != ".ply":
            continue

        print "Reading file", file_name
        file = plyfile.PlyData.read(os.path.join(args.folder_path, file_name))
        for element in file.elements:
            files.append(element.data)

    print "Merging files"
    merged_file = np.concatenate(files, -1)
    merged_el = plyfile.PlyElement.describe(merged_file, 'vertex')

    print "Writing merged file"
    plyfile.PlyData([merged_el]).write(args.merged_path)
github facebookresearch / DeepSDF / deep_sdf / mesh.py View on Github external
num_faces = faces.shape[0]

    verts_tuple = np.zeros((num_verts,), dtype=[("x", "f4"), ("y", "f4"), ("z", "f4")])

    for i in range(0, num_verts):
        verts_tuple[i] = tuple(mesh_points[i, :])

    faces_building = []
    for i in range(0, num_faces):
        faces_building.append(((faces[i, :].tolist(),)))
    faces_tuple = np.array(faces_building, dtype=[("vertex_indices", "i4", (3,))])

    el_verts = plyfile.PlyElement.describe(verts_tuple, "vertex")
    el_faces = plyfile.PlyElement.describe(faces_tuple, "face")

    ply_data = plyfile.PlyData([el_verts, el_faces])
    logging.debug("saving mesh to %s" % (ply_filename_out))
    ply_data.write(ply_filename_out)

    logging.debug(
        "converting to ply format and writing to file took {} s".format(
            time.time() - start_time
        )
github charlesq34 / pointnet2 / scannet / pc_util.py View on Github external
def write_ply(points, filename, text=True):
    """ input: Nx3, write points to filename as PLY format. """
    points = [(points[i,0], points[i,1], points[i,2]) for i in range(points.shape[0])]
    vertex = np.array(points, dtype=[('x', 'f4'), ('y', 'f4'),('z', 'f4')])
    el = PlyElement.describe(vertex, 'vertex', comments=['vertices'])
    PlyData([el], text=text).write(filename)
github StructuralNeurobiologyLab / SyConn / syconn / proc / meshes.py View on Github external
vertices : iterable of vertices (int)
    invert_vertex_order: Invert the vertex order.

    Returns
    -------
    str
    """
    # create header
    if not indices.ndim == 2:
        indices = np.array(indices, dtype=np.int).reshape((-1, 3))
    if not vertices.ndim == 2:
        vertices = np.array(vertices, dtype=np.float32).reshape((-1, 3))
    ordering = -1 if invert_vertex_order else 1
    vertices = np.array([tuple(el) for el in vertices], dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
    indices = np.array([tuple([el[::ordering]], ) for el in indices], dtype=[('vertex_indices', 'i4', (3,))])
    PlyData([PlyElement.describe(vertices, 'vertex'),
             PlyElement.describe(indices, 'face')]).write(dest_path)
github zju3dv / clean-pvnet / lib / utils / pvnet / pvnet_data_utils.py View on Github external
def get_ply_model(model_path):
    ply = PlyData.read(model_path)
    data = ply.elements[0].data
    x = data['x']
    y = data['y']
    z = data['z']
    model = np.stack([x, y, z], axis=-1)
    return model