当前位置: 首页>>代码示例>>Python>>正文


Python plyfile.PlyData类代码示例

本文整理汇总了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"
开发者ID:4sp1r3,项目名称:python-plyfile,代码行数:11,代码来源:test_plyfile.py

示例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
开发者ID:hassnov,项目名称:Conv3D,代码行数:49,代码来源:cluster_points_parallel2.py

示例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)
开发者ID:JinlongYANG,项目名称:sp,代码行数:15,代码来源:mesh.py

示例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
开发者ID:nmwsharp,项目名称:DDGSpring2016,代码行数:25,代码来源:InputOutput.py

示例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)
开发者ID:caskeep,项目名称:3D-SIS,代码行数:28,代码来源:visualize_benchmark.py

示例6: main

def main():
    parser = ArgumentParser()
    parser.add_argument("ply_filename")

    args = parser.parse_args()

    plot(PlyData.read(args.ply_filename))
开发者ID:srinath9,项目名称:pythonpointcloud,代码行数:7,代码来源:test.py

示例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
开发者ID:lfkeong,项目名称:vsfm_util,代码行数:26,代码来源:mayavi_util.py

示例8: main

def main():
    parser = ArgumentParser()
    parser.add_argument('ply_filename')

    args = parser.parse_args()

    plot(PlyData.read(args.ply_filename))
    mlab.show()
开发者ID:4sp1r3,项目名称:python-plyfile,代码行数:8,代码来源:plot.py

示例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
开发者ID:hassnov,项目名称:Conv3D,代码行数:46,代码来源:PlyReader.py

示例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)
开发者ID:Blitzman,项目名称:cviu-si-dl-study,代码行数:9,代码来源:pack_dataset.py

示例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)
开发者ID:4sp1r3,项目名称:python-plyfile,代码行数:9,代码来源:test_plyfile.py

示例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))
开发者ID:4sp1r3,项目名称:python-plyfile,代码行数:9,代码来源:test_plyfile.py

示例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))
开发者ID:4sp1r3,项目名称:python-plyfile,代码行数:9,代码来源:test_plyfile.py

示例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
开发者ID:caskeep,项目名称:3D-SIS,代码行数:10,代码来源:utils.py

示例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))
开发者ID:srinath9,项目名称:pythonpointcloud,代码行数:11,代码来源:driver.py


注:本文中的plyfile.PlyData类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。