Main Content

insertPointCloud

Insert point cloud data into 3-D signed distance map

Since R2024b

    Description

    insertPointCloud(sdm3D,origin,points) inserts a point cloud into the 3-D signed distance map by casting rays from the specified origin to each of the specified points, and updates the distance values of all voxels the digital differential analyzer (DDA) algorithm determines each ray hits.. The FullTracing property of the 3-D signed distance map determines the raycasting type. See FullTracing for more information.

    example

    Examples

    collapse all

    Read and plot the triangulation data from the L-membrane STL. You can use this to compare with the signed distance map.

    triL = stlread("L-Membrane.stl");
    trisurf(triL)
    title("L-Membrane STL")
    [az,el] = view;
    axis equal

    Figure contains an axes object. The axes object with title L-Membrane STL contains an object of type patch.

    Create an empty 3-D signed distance field (SDF) and load the point cloud data for the L-membrane from a MAT file. The MAT file contains point cloud data and the sensor origin associated with each point cloud data.

    sdm3D = signedDistanceMap3D(Resolution=50);
    load LMembranePC.mat

    Insert each point cloud into the signed distance field and show the updated 3-D SDF.

    for i = 1:size(ptcloud,1)
        insertPointCloud(sdm3D,origin(i,:),ptcloud{i});
        show(sdm3D,Colorbar="on");
        view(az,el)
        axis equal
        drawnow
        pause(.25)
    end
    title(["3-D SDF of L-Membrane"])

    Figure contains an axes object. The axes object with title 3-D SDF of L-Membrane contains an object of type scatter.

    Get all active voxels in the 3-D SDF.

    vox = activeVoxels(sdm3D)
    vox = struct with fields:
               ID: 1
          Centers: [49889x3 double]
        Distances: [49889x1 double]
            Sizes: [49889x1 double]
    
    

    For demonstrative purposes, use a random xyz-offset from the voxel centers of the first three voxels as query points. Then get the distance and gradient using those query points.

    querypts = vox.Centers(1:3,:) + 0.1*rand(3,3);
    d = distance(sdm3D,querypts)
    d = 3×1
    
        0.0379
       -0.0447
        0.0600
    
    
    g = gradient(sdm3D,querypts)
    g = 3×3
    
        0.1924    1.5773   -1.4002
        0.1689    1.6524   -0.8267
       -0.0715   -0.2335    0.3677
    
    

    Generate a mesh from the 3-D signed distance field.

    [vertices,faces] = mesh(sdm3D)
    vertices = 18860×3
    
       -0.0100    0.0068    0.1500
       -0.0300    0.0059    0.1500
       -0.0100    0.0100    0.1610
       -0.0300    0.0100    0.1565
        0.0100    0.0047    0.1500
       -0.0100   -0.0100    0.1409
        0.0100   -0.0100    0.1421
        0.0100    0.0025    0.1700
       -0.0010    0.0100    0.1700
        0.0100    0.0094    0.1900
          ⋮
    
    
    faces = 37094×3
    
         2     1     3
         4     2     3
         7     1     6
         5     1     7
         9     3     1
         9     1     8
         8     1     5
         8    10    11
         9     8    11
        10    12    11
          ⋮
    
    

    Visualize the mesh data.

    meshTri = triangulation(faces,vertices);
    trisurf(meshTri)
    axis equal
    title("Mesh from 3-D SDF")

    Figure contains an axes object. The axes object with title Mesh from 3-D SDF contains an object of type patch.

    If needed, you can use this mesh data to create a collision mesh using V-HACD. See collisionVHACD (Robotics System Toolbox) for more information.

    Input Arguments

    collapse all

    3-D signed distance map, specified as a signedDistanceMap3D object.

    Origin of the point cloud data, specified as a three-element vector representing an xyz-point in the world frame. Units are in meters.

    Example: [0 0 0]

    Point cloud data, specified as an N-by-3 matrix. Each row represents an xyz-point observed from a sensor at origin. N is the total number of points in the point cloud.

    If the points are measured with respect to the sensor frame, you must transform the points to the world frame.

    Extended Capabilities

    C/C++ Code Generation
    Generate C and C++ code using MATLAB® Coder™.

    Version History

    Introduced in R2024b