c++interpolationpoint-cloud-librarydownsamplingpdal

Interpolation of Point cloud at regular intervals


I have a las file:

triangular las file

The data points in this las file are not evenly spaced. It is a point cloud, as you can see from zooming in: zoomed

As an exercise, I would like to try interpolating this data using a regularly spaced 2D grid. I'm not too concerned for now that the las file is a triangle shape.

In some sense, I'm trying to turn this point cloud into a 2D image with regularly spaced pixels.

My first cut at the problem was to try using point cloud library.

#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/surface/grid_projection.h>
#include <pcl/io/pcd_io.h>

#include <pcl/filters/approximate_voxel_grid.h>
#include <pcl/filters/voxel_grid.h>

#include <pcl/io/ply_io.h>

using namespace pcl::io;

int main(int argc, char** argv) 
{   
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>);
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
    if (pcl::io::loadPCDFile("/app/data/triangle.pcd", *cloud) == -1) 
    {
        PCL_ERROR("Couldn't read file\n");
        return (-1);
    }
    
    pcl::VoxelGrid<pcl::PointXYZ> sor;
    sor.setInputCloud (cloud);
    sor.setLeafSize (1, 1, 1);
    
    sor.filter (*cloud_filtered);

    pcl::io::savePCDFileASCII("/app/output/interpolated_cloud.pcd", *cloud_filtered);

    return 0;
}

This doesn't seem to have performed the interpolation at regularly spaced intervals

downsample

It appears the VoxelGrid has performed downsampling but not at regular intervals. I also had to use PDAL to convert my las file to a PCD file

{
    "pipeline": 
    [
        {
            "type": "readers.las",
            "filename": "./data/triangle.las"
        },
        {
            "type": "writers.pcd",
            "filename": "./data/triangle.pcd"
        }
    ]
}

Perhaps I am going in completely the wrong direction here. Maybe I have to implement my own solution.


Solution

  • I tried using lidR in R

    installing packages

    install.packages("lidR")
    install.packages("gstat")
    library(lidR)
    

    Interpolation

    las <- readLAS("triangle.las")
    
    dem <- rasterize_terrain(las, res = 1, algorithm = knnidw(k = 10, p = 2), use_class = c(0L,0L))
    plot(dem)
    
    plot_dtm3d(dem, bg = "white") 
    

    mesh

    These look like they are regularly spaced

    zoomed

    And can be drawn as an image

    grid