Main Content

mesh2pc

Create point cloud from surface mesh

Since R2024b

    Description

    ptCloud = mesh2pc(surfaceMeshObj) creates a point cloud from the input surface mesh object using the Poisson-disk sampling method.

    example

    ptCloud = mesh2pc(triangulationObj) creates a point cloud from the surface mesh specified by the input triangulation object using the Poisson-disk sampling method.

    ptCloud = mesh2pc(vertices,faces) creates a point cloud from the surface mesh specified by the input vertices and faces using the Poisson-disk sampling method.

    ptCloud = mesh2pc(___,Name=Value) specifies options using one or more name-value arguments in addition to any combination of input arguments from previous syntaxes. For example, NumPoints=1000 samples 1000 points from the input mesh surface to create a point cloud.

    Examples

    collapse all

    Read surface mesh data from the specified PLY file.

    fileName = fullfile(toolboxdir("lidar"),"lidardata", ... 
    "surfaceMesh","sphere.ply");
    mesh = readSurfaceMesh(fileName);

    Display the surface mesh.

    surfaceMeshShow(mesh)

    Create a point cloud from surface mesh.

    ptCloud = mesh2pc(mesh);

    Display the output point cloud.

    figure
    pcshow(ptCloud);

    Figure contains an axes object. The axes object contains an object of type scatter.

    Input Arguments

    collapse all

    Surface mesh data, specified as a surfaceMesh object.

    Triangulation of a surface mesh, specified as a triangulation object.

    Mesh vertices, specified as an M-by-3 matrix. M is the total number of vertices. Each row of the matrix is of the form [x y z], specifying the coordinates of a vertex. Each vertex has a vertex ID equal to its row number in the matrix.

    Data Types: single | double

    Mesh triangular faces, specified as an N-by-3 matrix. N is the number of faces. Each row of the matrix is of the form [V1 V2 V3], specifying the positive integer vertex IDs of the vertices that define the triangular face.

    Data Types: single | double | int32

    Name-Value Arguments

    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: mesh2pc(surfaceMeshObj,NumPoints=1000) samples 1000 points from the input mesh surface to create a point cloud.

    Number of points to sample from the surface mesh, specified as a positive integer. By default, this value is twice the number of vertices in the input surface mesh.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Method for sampling surface mesh points, specified as one of these options:

    • "UniformSampling" — Sample points uniformly from the surface mesh based on the face area.

    • "PoissonDiskSampling" — Sample points from the surface mesh such that each sampled point is approximately at the same distance from the neighboring sampled points.

    Data Types: char | string

    Flag to use face normals, specified as a logical 1 (true) or 0 (false).

    • true — The function outputs point cloud normals by interpolating the face normals of the input surface mesh.

    • false — The function outputs point cloud normals by interpolating the vertex normals of the input surface mesh.

    Data Types: logical

    Flag to use vertex colors, specified as a logical 1 (true) or 0 (false).

    • true — The function outputs point cloud colors by interpolating color values of surface mesh vertices.

    • false — The function does not return any colors in the output point cloud.

    Data Types: logical

    Over sampling factor for Poisson-disk sampling, specified as a positive scalar. The function initially uses this factor to uniformly over sample the input surface mesh data. Then, the function uses the elimination criteria of the Poisson-disk sampling method to get an output point cloud with the specified number of points NumPoints.

    Note

    To use this argument, you must specify SamplingMethod as PoissonDiskSampling.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Output Arguments

    collapse all

    Output point cloud constructed from the input surface mesh data, returned as a pointCloud object.

    References

    [1] Yuksel, Cem. “Sample Elimination for Generating Poisson Disk Sample Sets.” Computer Graphics Forum 34, no. 2 (May 2015): 25–32. https://doi.org/10.1111/cgf.12538.

    Version History

    Introduced in R2024b