Пример #1
0
def meshwrite_binary(filename, verts, faces):
    # print "type(verts): ", type(verts)
    # print "verts.shape: ", verts.shape
    # print "faces.shape: ", faces.shape
    #
    # print "verts[0,:] = ", verts[0, :]
    # print "faces[0,:] = ", faces[0, :]

    # permute faces to get visualization
    # faces = np.flip(faces, 1)

    # converting numpy arrays to format for ply file
    num_verts = verts.shape[0]
    num_faces = faces.shape[0]

    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(verts[i, :])

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

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

    ply_data = PlyData([el_verts, el_faces])
    # ply_data = PlyData([el_verts, el_faces], text=True)
    ply_data.write(filename)
Пример #2
0
def visualize(coords, labels):
    palette = create_color_palette()
    nyu_to_scannet = get_nyu_to_scannet()
    vertex = []
    for i in range(coords.shape[0]):
        vertex.append(
            (
                coords[i][0],
                coords[i][1],
                coords[i][2],
                palette[SCANNET_LABELS[nyu_to_scannet[labels[i]]]][0],
                palette[SCANNET_LABELS[nyu_to_scannet[labels[i]]]][1],
                palette[SCANNET_LABELS[nyu_to_scannet[labels[i]]]][2]
            )
        )
    
    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])
    os.makedirs(PC_LABEL_ROOT, exist_ok=True)
    output_pc.write(PC_LABEL_PATH.format(args.scene_id))
Пример #3
0
def draw_building_no_windows():
    counter = 0
    ifc = getJson('duplex_A_reformat.json')
    o = ifc['Objects']
    r = ifc['ShapeRepresentations']
    all_verts = []
    all_faces = []
    for id in o:
        if o[id]['Class'] != 'Window':
            shape_id = o[id]['Representations'][0]['ref']
            shape_rep = r[shape_id]
            tuple_verts = shape_rep['Vertices']
            tuple_verts = [(x, y, z) for [x, y, z] in tuple_verts]
            all_verts += tuple_verts
            faces = shape_rep['Faces']
            faces = [list(np.array(face) + counter) for face in faces]
            counter += len(tuple_verts)
            faces = [(f, 0, 0, 0) for f in faces]
            all_faces += faces
    all_verts = np.array(all_verts,
                         dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
    all_faces = np.array(all_faces,
                         dtype=[('vertex_indices', 'i4', (3, )), ('red', 'u1'),
                                ('green', 'u1'), ('blue', 'u1')])
    v = PlyElement.describe(all_verts, 'vertex')
    f = PlyElement.describe(all_faces, 'face')
    ply1 = PlyData([v, f])
    ply1.write('ply1.ply')
    mesh = o3d.io.read_triangle_mesh("ply1.ply")
    mesh.compute_vertex_normals()
    o3d.visualization.draw_geometries([mesh])
Пример #4
0
def draw_building(o, r):
    o = copy.deepcopy(o)
    r = copy.deepcopy(r)
    counter = 0
    all_verts = []
    all_faces = []
    for id in o:
        shape_id = o[id]['Representations'][0]['ref']
        shape_rep = r[shape_id]
        verts, faces, counter = format_faces_verts(shape_rep, counter)
        all_verts += verts
        all_faces += faces
    all_verts = np.array(all_verts,
                         dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
    all_faces = np.array(all_faces,
                         dtype=[('vertex_indices', 'i4', (3, )), ('red', 'u1'),
                                ('green', 'u1'), ('blue', 'u1')])
    v = PlyElement.describe(all_verts, 'vertex')
    f = PlyElement.describe(all_faces, 'face')
    ply1 = PlyData([v, f])
    ply1.write('ply1.ply')
    mesh = o3d.io.read_triangle_mesh("ply1.ply")
    mesh.compute_vertex_normals()
    o3d.visualization.draw_geometries([mesh], mesh_show_back_face=True)
    return mesh
Пример #5
0
def main(filename):
    # Load .PLY with "plyfile"
    plydata = PlyData.read(filename)
    vx = plydata['vertex']['x']
    vy = plydata['vertex']['y']
    vz = plydata['vertex']['z']
    verts = np.stack([vx, vy, vz], axis=1).astype('double')
    faces = np.concatenate(plydata['face']['vertex_indices']).astype('uint32')

    # Construct halfedge structure by "tinymesh"
    mesh = Mesh(verts, faces)

    # Get vertices and indices back to Python
    verts = mesh.get_vertices()
    faces = mesh.get_vertex_indices()

    verts = np.asarray(verts, dtype='float32')
    faces = np.asarray(faces, dtype='int32').reshape((-1, 3))

    vert_el = np.array([tuple(v) for v in verts], dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
    face_el = np.array([(tuple(f), ) for f in faces], dtype=[('vertex_indices', 'i4', (3, ))])
    plydata = PlyData(
        [PlyElement.describe(vert_el, 'vertex'),
         PlyElement.describe(face_el, 'face')], text=False)

    base, ext = os.path.splitext(filename)
    outfile = base + "_copy" + ext
    plydata.write(outfile)
Пример #6
0
def export_ply(pc, filename):
    vertex = np.zeros(pc.shape[0], dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
    for i in range(pc.shape[0]):
        vertex[i] = (pc[i][0], pc[i][1], pc[i][2])
    ply_out = PlyData([PlyElement.describe(vertex, 'vertex', comments=['vertices'])])
    ply_filename = filename[:-4] + '.ply'
    ply_out.write(ply_filename)
Пример #7
0
def embedding2ply(filename, xyz, embeddings):
    """write a ply with colors corresponding to geometric features"""

    if embeddings.shape[1] > 3:
        pca = PCA(n_components=3)
        #pca.fit(np.eye(embeddings.shape[1]))
        pca.fit(
            np.vstack((np.zeros(
                (embeddings.shape[1], )), np.eye(embeddings.shape[1]))))
        embeddings = pca.transform(embeddings)

    #value = (embeddings-embeddings.mean(axis=0))/(2*embeddings.std())+0.5
    #value = np.minimum(np.maximum(value,0),1)
    #value = (embeddings)/(3 * embeddings.std())+0.5
    value = np.minimum(np.maximum((embeddings + 1) / 2, 0), 1)

    color = np.array(255 * value, dtype='uint8')
    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)
Пример #8
0
def visualize(args, preds):
    vertex = []
    for i in range(preds.shape[0]):
        vertex.append((
            preds[i][0],
            preds[i][1],
            preds[i][2],
            preds[i][3],
            preds[i][4],
            preds[i][5],
        ))

    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)))
Пример #9
0
def error2ply(filename, xyz, rgb, labels, prediction):
    """write a ply with green hue for correct classifcation and red for error"""
    if len(prediction.shape) > 1 and prediction.shape[1] > 1:
        prediction = np.argmax(prediction, axis = 1)
    if len(labels.shape) > 1 and labels.shape[1] > 1:
        labels = np.argmax(labels, axis = 1)
    color_rgb = rgb/255;
    for i_ver in range(0, len(labels)):

        color_hsv = list(colorsys.rgb_to_hsv(color_rgb[i_ver,0], color_rgb[i_ver,1], color_rgb[i_ver,2]))
        if (labels[i_ver] == prediction[i_ver]) or (labels[i_ver]==0):
            color_hsv[0] = 0.333333
        else:
            color_hsv[0] = 0
        color_hsv[1] = min(1, color_hsv[1] + 0.3);
        color_hsv[2] = min(1, color_hsv[2] + 0.1);
        color_rgb[i_ver,:] = list(colorsys.hsv_to_rgb(color_hsv[0], color_hsv[1], color_hsv[2]))
    color_rgb = np.array(color_rgb*255, dtype='u1');
    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_rgb[:, i]
    ply = PlyData([PlyElement.describe(vertex_all, 'vertex')], text=True)
    ply.write(filename)
Пример #10
0
def save_ply(path, points, colors=None):
    if torch.is_tensor(points):
        points = points.cpu().numpy()
    if colors is not None:
        if torch.is_tensor(colors):
            colors = colors.cpu().numpy()
        colors = (colors * 255.0).astype(np.uint8)

    points_descr = [('x', 'f4'), ('y', 'f4'), ('z', 'f4')]
    if colors is None:
        dtype_descr = points_descr
    else:
        colors_descr = [('red', 'u1'), ('green', 'u1'), ('blue', 'u1')]
        dtype_descr = points_descr + colors_descr

    vertex = np.empty(len(points), dtype=dtype_descr)
    vertex['x'] = points[:, 0]
    vertex['y'] = points[:, 1]
    vertex['z'] = points[:, 2]
    if colors is not None:
        vertex['red'] = colors[:, 0]
        vertex['green'] = colors[:, 1]
        vertex['blue'] = colors[:, 2]

    data = PlyData([
        PlyElement.describe(
            vertex,
            'vertex',
        ),
    ], )
    data.write(str(path))
Пример #11
0
def tet_ply():

    vertices = []
    faces = []

    vb0, fb0 = writeBone(0, 0, 0, 0, 0, 0, 4)
    vb1, fb1 = writeBone(1, 0, 0, 0, 1, 4, 2)
    vertices += vb0
    vertices += vb1
    faces += fb0
    faces += fb1

    vertex = numpy.array(vertices,
                         dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])

    face = numpy.array(faces,
                       dtype=[('vertex_indices', 'i4', (4, )), ('red', 'u1'),
                              ('green', 'u1'), ('blue', 'u1')])

    data = PlyData([
        PlyElement.describe(
            vertex, 'vertex', comments=['a skeleton pfnn vertices']),
        PlyElement.describe(face, 'face')
    ],
                   text="some text",
                   comments=['a skeleton pfnn'])

    print(data['vertex'][0])
    data.write('test.ply')
    return data
Пример #12
0
def save_ply_cloud(points, gt, filename):
    vertex_ = np.zeros(points.shape[0],
                       dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])

    joints_position = np.zeros(int(gt.shape[0] / 3),
                               dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
    gto = np.zeros(gt.shape[0], dtype=[('gt', 'f4')])

    for i in range(points.shape[0]):
        vertex_[i] = (points[i][0], points[i][1], points[i][2])

    for i in range(joints_position.shape[0]):
        joints_position[i] = (gt[i * 3], gt[i * 3 + 1], gt[i * 3 + 2])
        gto[i] = gt[i]
        gto[i * 3 + 1] = gt[i * 3 + 1]
        gto[i * 3 + 2] = gt[i * 3 + 2]

    #gt_ = np.zeros(points.shape[0], dtype=[('gt', 'f4')])
    #gt_ = gt

    e1 = PlyElement.describe(vertex_, 'vertex', comments=['vertices'])
    e2 = PlyElement.describe(gto, 'gt', comments=['GroundTruth'])
    e3 = PlyElement.describe(joints_position,
                             'jointsp',
                             comments=['Joints Position'])
    ply_out = PlyData([e1, e2, e3])
    ply_out.write(filename)
Пример #13
0
def save_pointcloud_colored(point_cloud, filename, points_per_patch):
    # Vertices
    vertex = np.array([tuple(x) for x in point_cloud.tolist()],
                      dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
    # Colors: 1 random color per patch
    num_activated_voxels = vertex.shape[0] // points_per_patch
    colors = np.random.randint(0, 255, (num_activated_voxels, 3)).repeat(
        points_per_patch, axis=0)
    vertex_color = np.array([tuple(x) for x in colors],
                            dtype=[('red', 'u1'), ('green', 'u1'),
                                   ('blue', 'u1')])

    # Fuse verts+colors arrays
    num_verts = len(vertex)
    vertex_all = np.empty(num_verts,
                          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 = PlyData([PlyElement.describe(vertex_all, 'vertex')])
    ply.write(filename)
Пример #14
0
def meshwrite_color_binary(filename, verts, faces, norms, colors):
    # print "type(verts): ", type(verts)
    # print "verts.shape: ", verts.shape
    # print "faces.shape: ", faces.shape
    #
    # print "verts[0,:] = ", verts[0, :]
    # print "faces[0,:] = ", faces[0, :]

    # permute faces to get visualization
    # faces = np.flip(faces, 1)

    # converting numpy arrays to format for ply file
    # num_verts = num_colors
    num_verts = verts.shape[0]
    num_colors = colors.shape[0]
    assert num_verts == num_colors
    num_faces = faces.shape[0]
    num_norms = norms.shape[0]

    verts_tuple = np.zeros((num_verts, ),
                           dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
    faces_tuple = np.zeros((num_faces, ),
                           dtype=[('vertex_indices', 'i4', (3, ))])
    norms_tuple = np.zeros((num_norms, ),
                           dtype=[('nx', 'f4'), ('ny', 'f4'), ('nz', 'f4')])
    colors_tuple = np.zeros((num_colors, ),
                            dtype=[('red', 'u1'), ('green', 'u1'),
                                   ('blue', 'u1')])

    for i in xrange(0, num_verts):
        verts_tuple[i] = tuple(verts[i, :])
        colors_tuple[i] = tuple(colors[i, :])

    for i in xrange(0, num_norms):
        norms_tuple[i] = tuple(norms[i, :])

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

    # merge color to vertex
    vertex_all = np.empty(
        num_verts, verts_tuple.dtype.descr + norms_tuple.dtype.descr +
        colors_tuple.dtype.descr)
    for prop in verts_tuple.dtype.names:
        vertex_all[prop] = verts_tuple[prop]

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

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

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

    ply_data = PlyData([el_verts, el_faces])
    # ply_data = PlyData([el_verts, el_faces], text=True)
    ply_data.write(filename)
Пример #15
0
def export_pointcloud(vertices, out_file, as_text=True):
    assert (vertices.shape[1] == 3)
    vertices = vertices.astype(np.float32)
    vector_dtype = [('x', 'f4'), ('y', 'f4'), ('z', 'f4')]
    vertices = vertices.view(dtype=vector_dtype).flatten()
    plyel = PlyElement.describe(vertices, 'vertex')
    plydata = PlyData([plyel], text=as_text)
    plydata.write(out_file)
Пример #16
0
def export_ply(pc, filename):
    vertex = np.zeros(pc.shape[0],
                      dtype=[("x", "f4"), ("y", "f4"), ("z", "f4")])
    for i in range(pc.shape[0]):
        vertex[i] = (pc[i][0], pc[i][1], pc[i][2])
    ply_out = PlyData(
        [PlyElement.describe(vertex, "vertex", comments=["vertices"])])
    ply_out.write(filename)
Пример #17
0
def save_ply_file(data, filename):
    vertex = np.zeros(data.shape[0],
                      dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
    for i in range(data.shape[0]):
        vertex[i] = (data[i][0], data[i][1], data[i][2])
    ply_out = PlyData(
        [PlyElement.describe(vertex, 'vertex', comments=['vertices'])])
    ply_out.write(filename)
Пример #18
0
def export_ply(pc, filename):
    """
    export .ply from a point cloud
    """
    vertex = np.zeros(pc.shape[0], dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
    for i in range(pc.shape[0]):
        vertex[i] = (pc[i][0], pc[i][1], pc[i][2])
    ply_out = PlyData([PlyElement.describe(vertex, 'vertex', comments=['vertices'])])
    ply_out.write(filename)
Пример #19
0
def scalar2ply(filename, xyz, scalar):
    """write a ply with an unisgned integer scalar field"""
    prop = [('x', 'f4'), ('y', 'f4'), ('z', 'f4'), ('scalar', 'f4')]
    vertex_all = np.empty(len(xyz), dtype=prop)
    for i in range(0, 3):
        vertex_all[prop[i][0]] = xyz[:, i]
    vertex_all[prop[3][0]] = scalar
    ply = PlyData([PlyElement.describe(vertex_all, 'vertex')], text=True)

    ply.write(filename)
Пример #20
0
def write_ply(filename, xyz, rgb):
    """write into a ply file"""
    prop = [('x', 'f4'), ('y', 'f4'), ('z', 'f4'), ('red', 'u1'), ('green', 'u1'), ('blue', '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]
    ply = PlyData([PlyElement.describe(vertex_all, 'vertex')], text=True)
    ply.write(filename)
Пример #21
0
def test_obj_info(tmpdir):
    ply0 = PlyData([], text=True, obj_info=["test obj_info"])
    test_file = tmpdir.join("test.ply")
    ply0.write(str(test_file))

    ply0_str = test_file.read("rb").decode("ascii")
    assert ply0_str.startswith("ply\r\nformat ascii 1.0\r\n" "obj_info test obj_info\r\n")

    ply1 = PlyData.read(str(test_file))
    assert len(ply1.obj_info) == 1
    assert ply1.obj_info[0] == "test obj_info"
Пример #22
0
def geof2ply(filename, xyz, geof):
    """write a ply with colors corresponding to geometric features"""
    color = np.array(255 * geof[:, [0, 1, 3]], dtype='uint8')
    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)
Пример #23
0
    def save_ply(self, filename):

        vertex = np.array([tuple(i) for i in self.v],
                          dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
        face = np.array([(tuple(i), 255, 255, 255) for i in self.f],
                        dtype=[('vertex_indices', 'i4', (3, )), ('red', 'u1'),
                               ('green', 'u1'), ('blue', 'u1')])
        el = PlyElement.describe(vertex, 'vertex')
        el2 = PlyElement.describe(face, 'face')
        plydata = PlyData([el, el2])
        plydata.write(filename)
Пример #24
0
def spg2ply(filename, spg_graph):
    """write a ply displaying the SPG by adding edges between its centroid"""
    vertex_prop = [('x', 'f4'), ('y', 'f4'), ('z', 'f4')]
    vertex_val = np.empty((spg_graph['sp_centroids']).shape[0], dtype=vertex_prop)
    for i in range(0, 3):
        vertex_val[vertex_prop[i][0]] = spg_graph['sp_centroids'][:, i]
    edges_prop = [('vertex1', 'int32'), ('vertex2', 'int32')]
    edges_val = np.empty((spg_graph['source']).shape[0], dtype=edges_prop)
    edges_val[edges_prop[0][0]] = spg_graph['source'].flatten()
    edges_val[edges_prop[1][0]] = spg_graph['target'].flatten()
    ply = PlyData([PlyElement.describe(vertex_val, 'vertex'), PlyElement.describe(edges_val, 'edge')], text=True)
    ply.write(filename)
Пример #25
0
def export_ply(pc, filename):
    vertex = np.zeros(pc.shape[0],
                      dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4'),
                             ('red', 'uint8'), ('green', 'uint8'),
                             ('blue', 'uint8')])
    for i in range(pc.shape[0]):
        vertex[i] = (pc[i][0], pc[i][1], pc[i][2], pc[i][3], pc[i][4],
                     pc[i][5])
    ply_out = PlyData(
        [PlyElement.describe(vertex, 'vertex', comments=['vertices'])],
        text=True)
    ply_out.write(filename)
Пример #26
0
def to_ply(dct, path):
    verts = np.array(numpy_to_tuple_list(dct['verts']),
                     dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
    faces = np.array([(list(it), )
                      for it in numpy_to_tuple_list(dct['faces'])],
                     dtype=[('vertex_indices', 'i4', (3, ))])
    plydata = PlyData([
        PlyElement.describe(verts, 'vertex'),
        PlyElement.describe(faces, 'face')
    ],
                      text=True)
    plydata.write(path)
Пример #27
0
def test_comment_spaces(tmpdir):
    ply0 = PlyData([], text=True, comments=['  test comment'])
    test_file = tmpdir.join('test.ply')
    ply0.write(str(test_file))

    ply0_str = test_file.read('rb').decode('ascii')
    assert ply0_str.startswith('ply\nformat ascii 1.0\n'
                               'comment   test comment\n')

    ply1 = PlyData.read(str(test_file))
    assert len(ply1.comments) == 1
    assert ply1.comments[0] == '  test comment'
Пример #28
0
def test_obj_info(tmpdir):
    ply0 = PlyData([], text=True, obj_info=['test obj_info'])
    test_file = tmpdir.join('test.ply')
    ply0.write(str(test_file))

    ply0_str = test_file.read('rb').decode('ascii')
    assert ply0_str.startswith('ply\nformat ascii 1.0\n'
                               'obj_info test obj_info\n')

    ply1 = PlyData.read(str(test_file))
    assert len(ply1.obj_info) == 1
    assert ply1.obj_info[0] == 'test obj_info'
Пример #29
0
def writePFNNSkeletonPly(poseData, outTextFile, scaleConstant, sizeFactor):
    # Invert Y and Z axis and convert to meters
    for i in range(31):
        y = poseData[i * 3 + 1]
        z = poseData[i * 3 + 2]
        poseData[i * 3 + 1] = z
        poseData[i * 3 + 2] = y

        for j in range(3):
            poseData[i * 3 + j] *= scaleConstant

    parents = [
        -1, 0, 1, 2, 3, 4, 0, 6, 7, 8, 9, 0, 11, 12, 13, 14, 15, 13, 17, 18,
        19, 20, 21, 20, 13, 24, 25, 26, 27, 28, 27
    ]
    vertices = []
    faces = []

    counter = 0
    for boneId in range(31):
        boneParent = parents[boneId]
        if boneParent == -1:
            continue

        x0, y0, z0 = poseData[boneId * 3 +
                              0], poseData[boneId * 3 +
                                           1], poseData[boneId * 3 + 2]
        x1, y1, z1 = poseData[boneParent * 3 +
                              0], poseData[boneParent * 3 +
                                           1], poseData[boneParent * 3 + 2]

        vb, fb = writeBone(counter, x0, y0, z0, x1, y1, z1, sizeFactor)
        counter += 1

        vertices += vb
        faces += fb

    vertex = numpy.array(vertices,
                         dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])

    face = numpy.array(faces,
                       dtype=[('vertex_indices', 'i4', (4, )), ('red', 'u1'),
                              ('green', 'u1'), ('blue', 'u1')])

    data = PlyData([
        PlyElement.describe(
            vertex, 'vertex', comments=['a skeleton pfnn vertices']),
        PlyElement.describe(face, 'face')
    ],
                   text="some text",
                   comments=['a skeleton pfnn'])
    data.write(outTextFile)
Пример #30
0
def export_ply(vertices, diffuse, normals, filename):
    names = 'x, y, z, nx, ny, nz, red, green, blue'
    formats = 'f4, f4, f4, f4, f4, f4, u1, u1, u1'
    arr = np.concatenate((vertices, normals, diffuse * 255), axis = -1)
    vertices_s = np.core.records.fromarrays(arr.transpose(), names = names, formats = formats)

    # Recreate the PlyElement instance
    v = PlyElement.describe(vertices_s, 'vertex')

    # Create the PlyData instance
    p = PlyData([ v ], text = True)

    p.write(filename)
Пример #31
0
def save_ply_cloud(points, colors, filename):

    vertex = np.zeros(points.shape[0],
                      dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4'),
                             ('red', 'u1'), ('green', 'u1'), ('blue', 'u1')])

    for i in range(points.shape[0]):
        vertex[i] = (points[i][0], points[i][1], points[i][2], colors[i][0],
                     colors[i][1], colors[i][2])

    ply_out = PlyData(
        [PlyElement.describe(vertex, 'vertex', comments=['vertices'])])
    ply_out.write(filename)
Пример #32
0
    def save_ply(self, filename):
        vertex = np.array([tuple(i) for i in self.v], dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
        face = np.array([(tuple(i), 0, 100, 255) for i in self.f] , 
            dtype=[('vertex_indices', 'i4', (3,)),
            ('red', 'u1'), ('green', 'u1'),
            ('blue', 'u1')])
	edge = np.array([(tuple(i)[0], tuple(i)[1], 255, 255, 255) for i in self.e] , 
            dtype=[('vertex1', 'i4'), ('vertex2', 'i4'),
            ('red', 'u1'), ('green', 'u1'),
            ('blue', 'u1')])
        el = PlyElement.describe(vertex, 'vertex')
        el2 = PlyElement.describe(face, 'face')
	el3 = PlyElement.describe(edge, 'edge')
        plydata = PlyData([el, el2, el3])
        plydata.write(filename)
Пример #33
0
def export_ply(pc, filename):
    vertex = np.zeros(pc.shape[0], dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
    for i in range(pc.shape[0]):
        vertex[i] = (pc[i][0], pc[i][1], pc[i][2])
    ply_out = PlyData([PlyElement.describe(vertex, 'vertex', comments=['vertices'])])
    ply_out.write(filename)
Пример #34
0
                    ([0, 1, 3],   0, 255,   0),
                    ([1, 2, 3],   0,   0, 255)],
                   dtype=[('vertex_indices', 'i4', (3,)),
                          ('red', 'u1'), ('green', 'u1'),
                          ('blue', 'u1')])


print "Assembling initial PlyData instance..."
ply0 = PlyData([PlyElement.describe(vertex, 'vertex',
                                    comments=['tetrahedron vertices']),
                PlyElement.describe(face, 'face')],
               text=True,
               comments=['single tetrahedron with colored faces'])

print "Writing test0.ply (ascii)..."
ply0.write('test0.ply')

print "Reading test0.ply..."
ply1 = PlyData.read('test0.ply')

print "(verifying result...)"
verify(ply0, ply1)

print "Writing test1.ply (binary_little_endian)..."
ply1.text = False
ply1.byte_order = '<'
ply1.write('test1.ply')

print "Reading test1.ply..."
ply2 = PlyData.read('test1.ply')