How to use the plyfile.PlyElement 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 dranjan / python-plyfile / test / test_plyfile.py View on Github external
def test_element_parse_error_repr():
    prop = PlyProperty('x', 'f4')
    elt = PlyElement('test', [prop], 0)
    e = PlyElementParseError('text', elt, 0, prop)
    assert repr(e)
github RobotLocomotion / pytorch-dense-correspondence / modules / dense_correspondence_manipulation / change_detection / tsdf_converter.py View on Github external
verts_tuple = np.zeros((num_verts,), dtype=[('x', 'f4'), ('y', 'f4'),
                                                ('z', 'f4')])
    faces_tuple = np.zeros((num_faces,), dtype=[('vertex_indices', 'i4', (3,))])

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

    for i in xrange(0, num_faces):
        faces_tuple[i] = faces[i, :].tolist()



    # save it out
    # try to save it
    el_verts = PlyElement.describe(verts_tuple, 'vertex')
    el_faces = PlyElement.describe(faces_tuple, 'face')

    ply_data = PlyData([el_verts, el_faces])
    ply = ply_data.write('test_reconstruction.ply')

    print "converting to ply format and writing to file took", time.time() - ply_conversion_start_time
github mit-han-lab / pvcnn / data / s3dis / prepare_data.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 laempy / pyoints / pyoints / storage / PlyHandler.py View on Github external
dtypes.append(rec.dtype.descr[i])
    rec = rec.view(dtypes)

    dtypes = []
    for i, name in enumerate(rec.dtype.names):
        desc = list(rec.dtype.descr[i])

        # change datatype if required (bug in plyfile?)
        if desc[1] == '
github yangyanli / PointCNN / evaluation / semantic3d_upsampling.py View on Github external
vertex = np.array([tuple(p) for p in points], dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])

    vertex_color = np.array([tuple(c) for c in colors], dtype=[('red', 'u1'), ('green', 'u1'), ('blue', 'u1')])

    n = len(vertex)
    assert len(vertex_color) == n

    vertex_all = np.empty(n, dtype=vertex.dtype.descr + vertex_color.dtype.descr)

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

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

    ply = plyfile.PlyData([plyfile.PlyElement.describe(vertex_all, 'vertex')], text=False)
    ply.write(filename)
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 yangyanli / PointCNN / evaluation / s3dis_upsampling.py View on Github external
vertex = np.array([tuple(p) for p in points], dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])

    vertex_color = np.array([tuple(c) for c in colors], dtype=[('red', 'u1'), ('green', 'u1'), ('blue', 'u1')])

    n = len(vertex)
    assert len(vertex_color) == n

    vertex_all = np.empty(n, dtype=vertex.dtype.descr + vertex_color.dtype.descr)

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

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

    ply = plyfile.PlyData([plyfile.PlyElement.describe(vertex_all, 'vertex')], text=False)
    ply.write(filename)
github StructuralNeurobiologyLab / SyConn / syconn / proc / meshes.py View on Github external
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 daeyun / object-shapes-cvpr18 / python / mvshape / io_utils.py View on Github external
def save_simple_points_ply(out_filename, points, text=False):
    assert points.shape[1] == 3
    assert points.ndim == 2

    dirname = path.dirname(out_filename)
    if not path.isdir(dirname):
        os.makedirs(dirname)
        log.info('mkdir -p {}'.format(dirname))

    xyz_nxyz = points
    vertex = np.core.records.fromarrays(xyz_nxyz.T, names='x, y, z',
                                        formats='f4, f4, f4')

    el = plyfile.PlyElement.describe(vertex, 'vertex')
    ply = plyfile.PlyData([el], text=text)
    ply.write(out_filename)

    # Replace \r\n with \n.
    with open(out_filename, 'rb') as f:
        content = f.read()
    beginning = content[:128]
    rest = content[128:]
    beginning = beginning.replace(b'ply\r\n', b'ply\n')

    with open(out_filename, 'wb') as f:
        f.write(beginning + rest)

    return ply
github loicland / superpoint_graph / partition / provider.py View on Github external
def partition2ply(filename, xyz, components):
    """write a ply with random colors for each components"""
    random_color = lambda: random.randint(0, 255)
    color = np.zeros(xyz.shape)
    for i_com in range(0, len(components)):
        color[components[i_com], :] = [random_color(), random_color()
        , random_color()]
    prop = [('x', 'f4'), ('y', 'f4'), ('z', 'f4'), ('red', 'u1')
    , ('green', 'u1'), ('blue', 'u1')]
    vertex_all = np.empty(len(xyz), dtype=prop)
    for i in range(0, 3):
        vertex_all[prop[i][0]] = xyz[:, i]
    for i in range(0, 3):
        vertex_all[prop[i+3][0]] = color[:, i]
    ply = PlyData([PlyElement.describe(vertex_all, 'vertex')], text=True)
    ply.write(filename)
#------------------------------------------------------------------------------