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


Python plyfile.PlyData方法代码示例

本文整理汇总了Python中plyfile.PlyData方法的典型用法代码示例。如果您正苦于以下问题:Python plyfile.PlyData方法的具体用法?Python plyfile.PlyData怎么用?Python plyfile.PlyData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在plyfile的用法示例。


在下文中一共展示了plyfile.PlyData方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: write

# 需要导入模块: import plyfile [as 别名]
# 或者: from plyfile import PlyData [as 别名]
def write(self, path):
        """
        Writes the object to file. This is a wrapper for :func:`plyfile.PlyData.write`

        :param path: The path of the ouput file.
        """
        if len(self.points) > 0:
            # coordinate_array = self.points[["x", "y", "z"]].values.T
            # vertex_array = list(zip(coordinate_array[0],coordinate_array[1], coordinate_array[2]))
            # vertex_array = np.array(vertex_array, dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
            vertex_array = self.points.to_records(index=False)
            elements = plyfile.PlyElement.describe(vertex_array, "vertex")
            plyfile.PlyData([elements]).write(path)
        else:
            raise ValueError(
                "There is no data contained in this Cloud object, it is impossible to write."
            ) 
开发者ID:brycefrank,项目名称:pyfor,代码行数:19,代码来源:cloud.py

示例2: visualize

# 需要导入模块: import plyfile [as 别名]
# 或者: from plyfile import PlyData [as 别名]
def visualize(args):
    print("visualizing...")
    scene = np.load(CONF.SCANNETV2_FILE.format(args.scene_id))

    vertex = []
    for i in range(scene.shape[0]):
        vertex.append(
            (
                scene[i][0],
                scene[i][1],
                scene[i][2],
                CONF.PALETTE[int(scene[i][7])][0],
                CONF.PALETTE[int(scene[i][7])][1],
                CONF.PALETTE[int(scene[i][7])][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(CONF.SCAN_LABELS, exist_ok=True)
    output_pc.write(CONF.SCANNETV2_LABEL.format(args.scene_id)) 
开发者ID:daveredrum,项目名称:Pointnet2.ScanNet,代码行数:35,代码来源:visualize_prep_scene.py

示例3: visualize

# 需要导入模块: import plyfile [as 别名]
# 或者: from plyfile import PlyData [as 别名]
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))) 
开发者ID:daveredrum,项目名称:Pointnet2.ScanNet,代码行数:33,代码来源:visualize.py

示例4: save_ply

# 需要导入模块: import plyfile [as 别名]
# 或者: from plyfile import PlyData [as 别名]
def save_ply(points, filename, colors=None, normals=None):
    vertex = np.core.records.fromarrays(points.transpose(), names='x, y, z', formats='f4, f4, f4')
    n = len(vertex)
    desc = vertex.dtype.descr

    if normals is not None:
        vertex_normal = np.core.records.fromarrays(normals.transpose(), names='nx, ny, nz', formats='f4, f4, f4')
        assert len(vertex_normal) == n
        desc = desc + vertex_normal.dtype.descr

    if colors is not None:
        vertex_color = np.core.records.fromarrays(colors.transpose() * 255, names='red, green, blue',
                                                  formats='u1, u1, u1')
        assert len(vertex_color) == n
        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) 
开发者ID:mit-han-lab,项目名称:pvcnn,代码行数:35,代码来源:prepare_data.py

示例5: save_ply

# 需要导入模块: import plyfile [as 别名]
# 或者: from plyfile import PlyData [as 别名]
def save_ply(points, filename, colors=None, normals=None):
    vertex = np.core.records.fromarrays(points.transpose(), names='x, y, z', formats='f4, f4, f4')
    n = len(vertex)
    desc = vertex.dtype.descr

    if normals is not None:
        vertex_normal = np.core.records.fromarrays(normals.transpose(), names='nx, ny, nz', formats='f4, f4, f4')
        assert len(vertex_normal) == n
        desc = desc + vertex_normal.dtype.descr

    if colors is not None:
        vertex_color = np.core.records.fromarrays(colors.transpose() * 255, names='red, green, blue',
                                                  formats='u1, u1, u1')
        assert len(vertex_color) == n
        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) 
开发者ID:hkust-vgd,项目名称:scanobjectnn,代码行数:35,代码来源:data_utils.py

示例6: save_ply

# 需要导入模块: import plyfile [as 别名]
# 或者: from plyfile import PlyData [as 别名]
def save_ply(points, filename, colors=None, normals=None):
    vertex = np.array([tuple(p) for p in points], dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
    n = len(vertex)
    desc = vertex.dtype.descr

    if normals is not None:
        vertex_normal = np.array([tuple(n) for n in normals], dtype=[('nx', 'f4'), ('ny', 'f4'), ('nz', 'f4')])
        assert len(vertex_normal) == n
        desc = desc + vertex_normal.dtype.descr

    if colors is not None:
        vertex_color = np.array([tuple(c * 255) for c in colors],
                                dtype=[('red', 'u1'), ('green', 'u1'), ('blue', 'u1')])
        assert len(vertex_color) == n
        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) 
开发者ID:hxdengBerkeley,项目名称:PointCNN.Pytorch,代码行数:35,代码来源:data_utils.py

示例7: read_3d_point_cloud_from_ply

# 需要导入模块: import plyfile [as 别名]
# 或者: from plyfile import PlyData [as 别名]
def read_3d_point_cloud_from_ply(path_to_ply_file):
    """
    Read a 3D point cloud from a ply file and return a numpy array.

    Args:
        path_to_ply_file (str): path to a .ply file

    Returns:
        numpy array with the list of 3D points, one point per line
        list of strings with the ply header comments
    """
    plydata = plyfile.PlyData.read(path_to_ply_file)
    d = np.asarray(plydata['vertex'].data)
    array = np.column_stack([d[p.name] for p in plydata['vertex'].properties])
    return array, plydata.comments 
开发者ID:cmla,项目名称:s2p,代码行数:17,代码来源:ply.py

示例8: write_3d_point_cloud_to_ply

# 需要导入模块: import plyfile [as 别名]
# 或者: from plyfile import PlyData [as 别名]
def write_3d_point_cloud_to_ply(path_to_ply_file, coordinates, colors=None,
                                extra_properties=None,
                                extra_properties_names=None, comments=[]):
    """
    Write a 3D point cloud to a ply file.

    Args:
        path_to_ply_file (str): path to a .ply file
        coordinates (array): numpy array of shape (n, 3) containing x, y, z coordinates
        colors (array): numpy array of shape (n, 3) or (n, 1) containing either
            r, g, b or gray levels
        extra_properties (array): optional numpy array of shape (n, k)
        extra_properties_names (list): list of k strings with the names of the
            (optional) extra properties
        comments (list): list of strings containing the ply header comments
    """
    points = coordinates
    dtypes = [('x', coordinates.dtype),
              ('y', coordinates.dtype),
              ('z', coordinates.dtype)]

    if colors is not None:
        if colors.shape[1] == 1:  # replicate grayscale 3 times
            colors = np.column_stack([colors] * 3)
        elif colors.shape[1] != 3:
            raise Exception('Error: colors must have either 1 or 3 columns')
        points = np.column_stack((points, colors))
        dtypes += [('red', colors.dtype),
                   ('green', colors.dtype),
                   ('blue', colors.dtype)]

    if extra_properties is not None:
        points = np.column_stack((points, extra_properties))
        dtypes += [(s, extra_properties.dtype) for s in extra_properties_names]

    tuples = [tuple(x) for x in points]
    plydata = plyfile.PlyElement.describe(np.asarray(tuples, dtype=dtypes),
                                          'vertex')
    plyfile.PlyData([plydata], comments=comments).write(path_to_ply_file) 
开发者ID:cmla,项目名称:s2p,代码行数:41,代码来源:ply.py

示例9: write_ply_to_file

# 需要导入模块: import plyfile [as 别名]
# 或者: from plyfile import PlyData [as 别名]
def write_ply_to_file(path, position, orientation, acceleration=None,
                      global_rotation=np.identity(3, float), local_axis=None,
                      trajectory_color=None, num_axis=3,
                      length=1.0, kpoints=100, interval=100):
    """
    Visualize camera trajectory as ply file
    :param path: path to save
    :param position: Nx3 array of positions
    :param orientation: Nx4 array or orientation as quaternion
    :param acceleration: (optional) Nx3 array of acceleration
    :param global_rotation: (optional) global rotation
    :param local_axis: (optional) local axis vector
    :param trajectory_color: (optional) the color of the trajectory. The default is [255, 0, 0] (red)
    :return: None
    """
    num_cams = position.shape[0]
    assert orientation.shape[0] == num_cams

    max_acceleration = 1.0
    if acceleration is not None:
        assert acceleration.shape[0] == num_cams
        max_acceleration = max(np.linalg.norm(acceleration, axis=1))
        print('max_acceleration: ', max_acceleration)
        num_axis = 4

    sample_pt = np.arange(0, num_cams, interval, dtype=int)
    num_sample = sample_pt.shape[0]

    # Define the optional transformation. Default is set w.r.t tango coordinate system
    position_transformed = np.matmul(global_rotation, np.array(position).transpose()).transpose()
    if local_axis is None:
        local_axis = np.array([[1.0, 0.0, 0.0, 0.0],
                               [0.0, 1.0, 0.0, 0.0],
                               [0.0, 0.0, 1.0, 0.0]])
    if trajectory_color is None:
        trajectory_color = [0, 255, 255]
    axis_color = [[255, 0, 0], [0, 255, 0], [0, 0, 255], [255, 0, 255]]
    vertex_type = [('x', 'f4'), ('y', 'f4'), ('z', 'f4'), ('red', 'u1'), ('green', 'u1'), ('blue', 'u1')]
    positions_data = np.empty((position_transformed.shape[0],), dtype=vertex_type)
    positions_data[:] = [tuple([*i, *trajectory_color]) for i in position_transformed]

    app_vertex = np.empty([num_axis * kpoints], dtype=vertex_type)
    for i in range(num_sample):
        q = quaternion.quaternion(*orientation[sample_pt[i]])
        if acceleration is not None:
            local_axis[:, -1] = acceleration[sample_pt[i]].flatten() / max_acceleration
        global_axes = np.matmul(global_rotation, np.matmul(quaternion.as_rotation_matrix(q), local_axis))
        for k in range(num_axis):
            for j in range(kpoints):
                axes_pts = position_transformed[sample_pt[i]].flatten() +\
                           global_axes[:, k].flatten() * j * length / kpoints
                app_vertex[k*kpoints + j] = tuple([*axes_pts, *axis_color[k]])

        positions_data = np.concatenate([positions_data, app_vertex], axis=0)
    vertex_element = plyfile.PlyElement.describe(positions_data, 'vertex')
    plyfile.PlyData([vertex_element], text=True).write(path) 
开发者ID:Sachini,项目名称:ronin,代码行数:58,代码来源:write_trajectory_to_ply.py

示例10: __init__

# 需要导入模块: import plyfile [as 别名]
# 或者: from plyfile import PlyData [as 别名]
def __init__(self, path):

        if type(path) == str or type(path) == pathlib.PosixPath:
            self.filepath = path
            self.name = os.path.splitext(os.path.split(path)[1])[0]
            self.extension = os.path.splitext(path)[1]

            # A path to las or laz file
            if self.extension.lower() == ".las" or self.extension.lower() == ".laz":
                las = laspy.file.File(self.filepath)
                self._get_las_points(las)

            elif self.extension.lower() == ".ply":
                ply = plyfile.PlyData.read(path)
                ply_points = ply.elements[0].data
                points = pd.DataFrame(
                    {"x": ply_points["x"], "y": ply_points["y"], "z": ply_points["z"]}
                )
                header = "ply_header"
                self.data = PLYData(points, header)

            else:
                raise ValueError(
                    "File extension not supported, please input either a las, laz, ply or CloudData object."
                )

        elif type(path) == CloudData or isinstance(path, CloudData):
            self.data = path

            if type(self.data.header) == laspy.header.HeaderManager:
                self.data = LASData(self.data.points, self.data.header)

            elif self.data.header == "ply_header":
                self.data = PLYData(self.data.points, self.data.header)

        elif (
            path.__class__.__bases__[0] == laspy.file.File
            or type(path) == laspy.file.File
        ):
            self._get_las_points(path)

        else:
            raise ValueError(
                "Object type not supported, please input either a file path with a supported extension or a CloudData object."
            )

        # We're not sure if this is true or false yet
        self.normalized = None
        self.crs = None 
开发者ID:brycefrank,项目名称:pyfor,代码行数:51,代码来源:cloud.py


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