本文整理汇总了Python中plyfile.PlyData类的典型用法代码示例。如果您正苦于以下问题:Python PlyData类的具体用法?Python PlyData怎么用?Python PlyData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PlyData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_obj_info
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"
示例2: read_ply
def read_ply(self, file_name):
num_samples = self.num_samples // len(self.files_list)
if self.file_index == len(self.files_list) - 1:
num_samples = num_samples + (self.num_samples - (num_samples * len(self.files_list)))
root, ext = os.path.splitext(file_name)
if not os.path.isfile(root + ".npy"):
ply = PlyData.read(file_name)
vertex = ply['vertex']
(x, y, z) = (vertex[t] for t in ('x', 'y', 'z'))
points = zip(x.ravel(), y.ravel(), z.ravel())
np.save(root + ".npy", points)
else:
points = np.load(root + ".npy")
#load normals
if os.path.isfile(root + "_normals" + ".ply"):
if not os.path.isfile(root + "_normals" + ".npy"):
ply1 = PlyData.read(root + "_normals" + ".ply")
vertex = ply1['vertex']
(nx, ny, nz) = (vertex[t] for t in ('nx', 'ny', 'nz'))
self.normals = np.asarray(zip(nx.ravel(), ny.ravel(), nz.ravel()))
np.save(root + "_normals" + ".npy", self.normals)
else:
self.normals = np.load(root + "_normals" + ".npy")
if self.add_noise:
self.data = utils.add_noise_normal(points, std=self.nois_std)
else:
self.data = np.asarray(points)
self.pc_diameter = utils.get_pc_diameter(self.data)
self.l = self.relL*self.pc_diameter
rot = utils.angle_axis_to_rotation(self.rotation_angle, self.rotation_axis)
self.data = utils.transform_pc(self.data, rot)
#plotutils.show_pc(self.data)
#mlab.show()
#TODO: better sampling
print "sampling file: ", file_name
self.samples, self.sample_indices = Sampler.sample(self.data, -1, min_num_point=-1, file_name=file_name, sampling_algorithm=self.sampling_algorithm)
#self.samples, self.sample_indices = Sampler.sample(self.data, -1, num_samples, file_name=file_name, sampling_algorithm=self.sampling_algorithm)
#self.samples = self.samples[0:num_samples]
#self.sample_indices = self.sample_indices[0:num_samples]
self.tree = spatial.KDTree(self.data)
return self.data
示例3: save_ply
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)
示例4: readMesh_PLY
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
示例5: main
def main():
res_folder = opt.result_dir
ply_folder = opt.scan_path
output_dir = opt.output_dir
os.makedirs(output_dir, exist_ok=True)
reader_ins = Benchmark_reader(res_folder)
for folder in os.listdir(res_folder):
if os.path.isdir(os.path.join(res_folder, folder)):
continue
print(folder)
# ply reader
ply_file = os.path.join(ply_folder, folder.split('.')[0], folder.split('.')[0]+'_vh_clean_2.ply')
ply_data = PlyData.read(ply_file)
points = []
for point in ply_data.elements[0].data:
points.append([point[0], point[1], point[2]])
points = np.array(points)
colors = np.zeros_like(points)
# instance reader
instances = reader_ins[folder]
for instance_idx, instance_key in enumerate(instances.keys()):
r, g, b = create_color_palette()[int((instance_idx + 1)%41)]
colors[instances[instance_key]['points'].nonzero()[0].astype(np.int32)] = [r,g,b]
output_file = os.path.join(output_dir, folder.split('.')[0] + '.ply')
write_ply(points, colors, None, output_file)
示例6: main
def main():
parser = ArgumentParser()
parser.add_argument("ply_filename")
args = parser.parse_args()
plot(PlyData.read(args.ply_filename))
示例7: ply_plot
def ply_plot(ply_file, opacity = 1, color = (1,1,1)):
ply = PlyData.read(ply_file)
'''
Plot vertices and triangles from a PlyData instance. Assumptions:
`ply' has a 'vertex' element with 'x', 'y', and 'z'
properties;
`ply' has a 'face' element with an integral list property
'vertex_indices', all of whose elements have length 3.
'''
vertex = ply['vertex'].data
(x, y, z) = (vertex[t] for t in ('x', 'y', 'z'))
# mlab.points3d(x, y, z, color=(1, 1, 1), mode='point')
tri_idx = ply['face'].data['vertex_indices']
idx_dtype = tri_idx[0].dtype
triangles = numpy.fromiter(tri_idx, [('data', idx_dtype, (3,))],
count=len(tri_idx))['data']
mesh = mlab.triangular_mesh(x, y, z, triangles,
color=color,
opacity = opacity)
return mesh
示例8: main
def main():
parser = ArgumentParser()
parser.add_argument('ply_filename')
args = parser.parse_args()
plot(PlyData.read(args.ply_filename))
mlab.show()
示例9: read_ply
def read_ply(self, file_name, num_samples=1000, sample_class_start=0, add_noise =False,
noise_prob=0.3, noise_factor=0.02, noise_std=0.1, sampling_algorithm=SampleAlgorithm.Uniform,
rotation_axis=[0, 0, 1], rotation_angle=0):
root, ext = os.path.splitext(file_name)
if not os.path.isfile(root + ".npy"):
ply = PlyData.read(file_name)
vertex = ply['vertex']
(x, y, z) = (vertex[t] for t in ('x', 'y', 'z'))
points = zip(x.ravel(), y.ravel(), z.ravel())
np.save(root + ".npy", points)
else:
points = np.load(root + ".npy")
#load normals
if os.path.isfile(root + "_normals" + ".ply"):
if not os.path.isfile(root + "_normals" + ".npy"):
ply1 = PlyData.read(root + "_normals" + ".ply")
vertex = ply1['vertex']
(nx, ny, nz) = (vertex[t] for t in ('nx', 'ny', 'nz'))
self.normals = np.asarray(zip(nx.ravel(), ny.ravel(), nz.ravel()))
np.save(root + "_normals" + ".npy", self.normals)
else:
self.normals = np.load(root + "_normals" + ".npy")
if add_noise:
print "adding noise to model.."
mr = utils.model_resolution(np.array(points))
#mr = 0.404
print "model resolution: ", mr
self.data = utils.add_noise_normal(np.array(points), mr, noise_std)
else:
self.data = np.asarray(points)
rot = utils.angle_axis_to_rotation(rotation_angle, rotation_axis)
self.data = utils.transform_pc(self.data, rot)
#plotutils.show_pc(self.data)
#mlab.show()
#TODO: better sampling
self.samples, self.sample_indices = Sampler.sample(self.data, -1, num_samples-1, file_name=file_name, pose=rot, sampling_algorithm=sampling_algorithm)
self.tree = spatial.KDTree(self.data)
self.sample_class_start = sample_class_start
self.sample_class_current = sample_class_start
self.num_samples = self.samples.shape[0]
print "num samples: ", self.num_samples
logging.basicConfig(filename='example.log',level=logging.DEBUG)
return self.data
示例10: read_ply_cloud
def read_ply_cloud(filename):
ply_data = PlyData.read(filename)
points = ply_data['vertex'].data.copy()
cloud = np.empty([2048, 3])
for i in range(len(points)):
point = points[i]
p = np.array([point[0], point[1], point[2]])
cloud[i] = p
return np.array(cloud)
示例11: test_write_stream
def test_write_stream(tmpdir, tet_ply_txt):
ply0 = tet_ply_txt
test_file = tmpdir.join("test.ply")
with test_file.open("wb") as f:
tet_ply_txt.write(f)
ply1 = PlyData.read(str(test_file))
verify(ply0, ply1)
示例12: write_read
def write_read(ply, tmpdir, name="test.ply"):
"""
Utility: serialize/deserialize a PlyData instance through a
temporary file.
"""
filename = tmpdir.join(name)
ply.write(str(filename))
return PlyData.read(str(filename))
示例13: read_str
def read_str(string, tmpdir, name="test.ply"):
"""
Utility: create a PlyData instance from a string.
"""
filename = tmpdir.join(name)
with filename.open("wb") as f:
f.write(string)
return PlyData.read(str(filename))
示例14: read_mesh_vertices
def read_mesh_vertices(filename):
assert os.path.isfile(filename)
with open(filename, 'rb') as f:
plydata = PlyData.read(f)
num_verts = plydata['vertex'].count
vertices = np.zeros(shape=[num_verts, 3], dtype=np.float32)
vertices[:,0] = plydata['vertex'].data['x']
vertices[:,1] = plydata['vertex'].data['y']
vertices[:,2] = plydata['vertex'].data['z']
return vertices
示例15: main
def main():
parser = ArgumentParser()
parser.add_argument('ply_filename')
args = parser.parse_args()
# file1 = open(args.ply_filename,'r')
# plot(PlyData.read())
# plot(file1)
plot(PlyData.read(args.ply_filename))