DEV Community

Darkce
Darkce

Posted on • Edited on

I ported the Point Cloud Library (PCL) to the browser!

The Point Cloud Library (PCL) is a standalone, large scale, open project for 2D/3D image and point cloud processing. It is written via C++.

I made it run in the browser with Emscripten and WebAssembly.

Github:https://github.com/luoxuhai/pcl.js

Simple Example

import PCL from 'pcl.js';

async function main() {
  const pcl = await PCL.init({
    url: 'https://cdn.jsdelivr.net/npm/pcl.js/dist/pcl-core.wasm',
  });
  // Write a PCD file
  pcl.fs.writeFile('/test.pcd', ArrayBuffer);
  // Load PCD file, return point cloud object
  const pointCloud = pcl.io.loadPCDFile('/test.pcd');

  // Filtering a PointCloud using a PassThrough filter, see: https://pcl.readthedocs.io/projects/tutorials/en/master/passthrough.html#passthrough
  const pass = new pcl.filters.PassThrough();
  pass.setInputCloud(pointCloud);
  pass.setFilterFieldName('z');
  pass.setFilterLimits(0.0, 1.0);
  pass.filter(pointCloud);

  // Save filtered point cloud objects as PCD files
  pcl.io.savePCDFileASCII('/test-filtered.pcd', pointCloud);
  // Read PCD file content, the content is ArrayBuffer
  const pcd = pcl.fs.readFile('/test-filtered.pcd');

  // Delete all PCD files
  pcl.fs.unlink('/test.pcd')
  pcl.fs.unlink('/test-filtered.pcd')
  // ...
}

main();
Enter fullscreen mode Exit fullscreen mode

Top comments (0)