def test_make2d():
    a = numpy.empty(2, dtype=object)
    a[:] = [numpy.array([0, 1, 2]), numpy.array([3, 4, 5])]

    b = make2d(a)
    assert b.shape == (2, 3)
    assert (b == [[0, 1, 2], [3, 4, 5]]).all()
def readMesh_PLY(filename, output="soup"):

    if (output != 'soup'):
        raise Exception('Mesh types other than soup not yet supported')

    # Read the actual file
    # TODO This takes a long time, maybe try to replace with something faster of my own?
    plydata = PlyData.read(filename)

    # Read vertices
    # If the mesh has more than three columns of vertex data, ignore the later columns
    # (for instance, Stanford Mesh Repo meshes store intensity and confidence here)
    nVerts = plydata['vertex'].count
    verts = np.zeros((nVerts, 3))
    verts[:, 0] = np.array(plydata['vertex'].data['x'])
    verts[:, 1] = np.array(plydata['vertex'].data['y'])
    verts[:, 2] = np.array(plydata['vertex'].data['z'])

    # Read faces
    faces = make2d(plydata['face'].data['vertex_indices'])

    # Build a mesh from these vertices and faces
    mesh = TriSoupMesh(verts, faces)

    return mesh
Beispiel #3
0
def readMesh_PLY(filename, output="soup"):

    if output != "soup":
        raise Exception("Mesh types other than soup not yet supported")

    # Read the actual file
    # TODO This takes a long time, maybe try to replace with something faster of my own?
    plydata = PlyData.read(filename)

    # Read vertices
    # If the mesh has more than three columns of vertex data, ignore the later columns
    # (for instance, Stanford Mesh Repo meshes store intensity and confidence here)
    nVerts = plydata["vertex"].count
    verts = np.zeros((nVerts, 3))
    verts[:, 0] = np.array(plydata["vertex"].data["x"])
    verts[:, 1] = np.array(plydata["vertex"].data["y"])
    verts[:, 2] = np.array(plydata["vertex"].data["z"])

    # Read faces
    faces = make2d(plydata["face"].data["vertex_indices"])

    # Build a mesh from these vertices and faces
    mesh = TriSoupMesh(verts, faces)

    return mesh
Beispiel #4
0
def test_make2d():
    a = numpy.empty(2, dtype=object)
    a[:] = [numpy.array([0, 1, 2]), numpy.array([3, 4, 5])]

    b = make2d(a)
    assert b.shape == (2, 3)
    assert (b == [[0, 1, 2], [3, 4, 5]]).all()
def load_shape(filename, load_triangles = False):
    mesh = plyfile.PlyData.read(filename)
    # convert vertices to numpy array
    vertices = np.transpose(np.vstack((mesh['vertex']['x'],mesh['vertex']['y'],mesh['vertex']['z'])))
    # get triangles
    if load_triangles:
        tridata = mesh['face'].data['vertex_indices']
        triangles = plyfile.make2d(tridata)
        return vertices, triangles
    return vertices
def read_ply_pcl(filename):
    plydata = plyfile.PlyData.read(filename)
    v = np.vstack((plydata['vertex']['x'], plydata['vertex']['y'], plydata['vertex']['z'])).T
    normals = np.vstack((plydata['vertex']['nx'], plydata['vertex']['ny'], plydata['vertex']['nz'])).T
    values = plydata['vertex']['value'].T
    confidence = plydata['vertex']['confidence'].T
    ret = {
        'v': v,
        'confidence': confidence,
        'normals': normals,
        'value': values,
    }
    if 'face' in plydata:
        ret['f'] = plyfile.make2d(plydata['face'].data['vertex_indices'])
    return ret
Beispiel #7
0
def read_ply(path):
    # Read ply dataformat file.
    with open(path, 'rb') as f:
        plydata = PlyData.read(f)

    # Extract numpy arrays for vertices and faces.
    x = plydata['vertex']['x']
    y = plydata['vertex']['y']
    z = plydata['vertex']['z']
    vertices = np.stack((x, y, z), axis=1)

    faces = make2d(plydata['face']['vertex_indices'])
    faces = faces.astype(np.int64)

    # Conver to torch tensors.
    vertices = torch.FloatTensor(vertices)
    faces = torch.LongTensor(faces)

    return vertices, faces
Beispiel #8
0
filename = PINS.filename.get()

if filename.endswith(".zip"):
    zipf = zipfile.ZipFile(filename)
    assert len(zipf.namelist()) == 1
    zply = zipf.open(zipf.namelist()[0])
    plydata = PlyData.read(zply)
else:
    plydata = PlyData.read(filename)
elements = {e.name: e for e in plydata.elements}
vertices = elements["vertex"].data
faces = elements["face"].data

#faces => indices + edges
indices = make2d(faces['vertex_indices']).astype(np.uint16)
assert indices.shape[1] == 3  #triangles only
edges = set()
for triangle in indices:
    for p1, p2 in ((0, 1), (1, 2), (2, 0)):
        i1, i2 = triangle[p1], triangle[p2]
        if i2 < i1: i1, i2 = i2, i1
        edges.add((i1, i2))
edges = np.array(list(edges), dtype=np.uint16)

#vertices => coordinates + normals
for n in range(len(vertices.dtype)):
    assert vertices.dtype[n] == vertices.dtype[0]
vertices = vertices.view(vertices.dtype[0]).reshape(vertices.shape + (-1, ))
coordinates = vertices[:, :3]
normals = vertices[:, 3:6]
Beispiel #9
0
filename = PINS.filename.get()

if filename.endswith(".zip"):
    zipf = zipfile.ZipFile(filename)
    assert len(zipf.namelist()) == 1
    zply = zipf.open(zipf.namelist()[0])
    plydata = PlyData.read(zply)
else:
    plydata = PlyData.read(filename)
elements = {e.name: e for e in plydata.elements}
vertices = elements["vertex"].data
faces = elements["face"].data

#faces => indices + edges
indices = make2d(faces['vertex_indices']).astype(np.uint16)
assert indices.shape[1] == 3 #triangles only
edges = set()
for triangle in indices:
    for p1,p2 in ((0,1),(1,2),(2,0)):
        i1, i2 = triangle[p1], triangle[p2]
        if i2 < i1: i1,i2 = i2,i1
        edges.add((i1,i2))
edges = np.array(list(edges),dtype=np.uint16)

#vertices => coordinates + normals
for n in range(len(vertices.dtype)):
    assert vertices.dtype[n] == vertices.dtype[0]
vertices = vertices.view(vertices.dtype[0]).reshape(vertices.shape + (-1,))
coordinates = vertices[:,:3]
normals = vertices[:,3:6]