Contenido principal

addPointCloud

R2026b

Display point cloud in point cloud viewer

Since R2026b

    Description

    points = addPointCloud(pcview,ptCloud) displays the point cloud ptCloud in the point cloud viewer pcview and returns a object that you can use to control the appearance and behavior of the displayed point cloud.

    example

    points = addPointCloud(pcview,filename) displays the point cloud from the specified file filename.

    points = addPointCloud(___,color) displays the point cloud with the specified colors color for each point in addition to any combination of input arguments from previous syntaxes.

    points = addPointCloud(___,Name=Value) specifies additional options using one or more name-value arguments, For example, PointSize=3 sets the size of the rendered points to 3 pixels.

    Examples

    collapse all

    Download two point cloud tiles from the U.S. Geological Survey (USGS) 3D Elevation Program (3DEP) [1], covering the University of Utah campus and adjacent Wasatch Mountain foothills. Visualize each tile individually, then combine them in a single viewer using the addPointCloud method.

    baseURL = "https://rockyweb.usgs.gov/vdelivery/Datasets/Staged/Elevation/LPC/Projects/Wasatch_Fault_UT_LiDAR/UT_Wasatch_L4_2013/LAZ/";
    
    tiles = [
        "USGS_LPC_Wasatch_Fault_UT_LiDAR_12TVL2900012000.laz"
        "USGS_LPC_Wasatch_Fault_UT_LiDAR_12TVL3000012000.laz"
    ];

    Download the tiles if they are not already cached locally.

    for i = 1:numel(tiles)
        localFile = fullfile(tempdir, tiles(i));
        if ~exist(localFile,"file")
            websave(localFile, baseURL + tiles(i));
        end
    end

    Read the two tiles as point clouds.

    reader1 = lasFileReader(fullfile(tempdir, tiles(1)));
    pc1 = readPointCloud(reader1);
    
    reader2 = lasFileReader(fullfile(tempdir, tiles(2)));
    pc2 = readPointCloud(reader2);

    Visualize the first tile in its own pcviewer instance.

    pcview1 = pcviewer(pc1);

    Visualize the second tile in its own pcviewer instance.

    pcview2 = pcviewer(pc2);

    Use addPointCloud to add the second point cloud to a viewer that already displays the first. This avoids concatenating the point clouds and lets you control each one independently.

    pcview = pcviewer(pc1);

    addPointCloud(pcview, pc2);

    References

    [1] USGS Lidar Point Cloud UT_Wasatch_L4_2013 courtesy of the U.S. Geological Survey

    Input Arguments

    collapse all

    Point cloud viewer in which to display point cloud, specified as a pcviewer object.

    Point cloud to display, specified as a pointCloud object.

    Filename of point cloud to display, specified as a string scalar or a character vector. You must specify a PLY, PCD, LAS, or LAZ file.

    Color for points in the point cloud, specified as a short name, long name, RGB triplet, an M-by-3 matrix, or an M-by-N-by-3 array. The color input sets the Color property. For more information on color values, see Color Values on the pcviewer reference page.

    • If the data type of the Location property of the input point cloud is single or double, each RGB value must be in the range [0, 1].

    • If the data type of the Location property of the input point cloud is uint8, each color RGB value must be in the range [0, 255].

    • The Color property of the Points object stores the color value as an RGB triplet, an M-by-3 matrix, or an M-by-N-by-3 array. If you specify one or more color names, the function converts them to their corresponding RGB triplets.

    ColorFormatExample
    Specify one color for all points

    Short or long color name.

    "r"

    "red"

    RGB triplet, as a 1-by-3 vector.

    [255 0 0]1-by-3 grid, with columns labeled r, g, and b respectively.

    Specify a color for each point

    Vector of strings, or cell array of character vectors of color names.

    ["red","yellow","blue"]

    M-by-3 matrix for an unorganized point cloud, in which each row is an RGB triplet. M is the number of rows in the unorganized point cloud.

    255 0 0
    255 0 0
    0 255 255
    M-by-3 grid, with columns labeled r,g,b respectively.

    M-by-N-by-3 array for an organized point cloud, in which each page specifies the red, green, or blue value for the corresponding point in the point cloud. M-by-N is the size of the organized point cloud.

    M-by-N-by3 grid, with 3 m-by-n matrices labeled r, g, and b respectively.

    Name-Value Arguments

    collapse all

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: addPointCloud(pcview,ptCloud,PointSize=3) sets the size of the rendered points to 3 pixels.

    Source of the color data, specified as one of:

    • "auto" — Uses the Color property of the input point cloud, if available. Otherwise, uses "Intensity" if available. If neither is available, uses the z-coordinates of the vertices.

    • "X" — Use the x-coordinates of the vertices.

    • "Y" — Use the y-coordinates of the vertices.

    • "Z" — Use the z-coordinates of the vertices.

    • "Color" — Use RGB color values stored in the point cloud.

    • "Intensity" — Use intensity values stored in the point cloud.

    • "Row" — Use row indices of an organized point cloud.

    • "Column" — Use column indices of an organized point cloud..

    • "Range" — Use range values when available.

    • "Azimuth" — Use azimuth values stored in the point cloud.

    • "Elevation" — Use elevation values stored in the point cloud.

    • "Custom" — Use the values specified by the Color property.

    Point size, specified as a positive scalar in pixels.

    Output Arguments

    collapse all

    Point cloud points, returned as a Points object. You can use this object to display and modify the properties of the points of the point cloud, such as color and point size. When pcviewer generates an octree to improve visualization performance for large point clouds, the Points objects in the scene are converted to BlockedPoints objects.

    Version History

    Introduced in R2026b