Developer Guide

  • 2022.3
  • 10/25/2022
  • Public Content
Contents

Constructing a Convex Hull Polygon for a 3D Point Cloud

The Intel® oneAPI Base Toolkit optimization for convex hull is ported from CUDA optimization code, and the result of the Intel® oneAPI Base Toolkit optimization matches the result of the CUDA implementation. However, it does not match the result of the PCL CPU implementation.
This tutorial shows how to use these optimizations inside a Docker* image. For the same functionality outside of Docker* images, see PCL Optimizations Outside of Docker* Images.
  1. Prepare the environment:
    cd <edge_insights_for_amr_path>/Edge_Insights_for_Autonomous_Mobile_Robots_<version>/AMR_containers ./run_interactive_docker.sh eiforamr-full-flavour-sdk:2022.3 root -c full_flavor mkdir convex_hull && cd convex_hull
  2. Create the file
    oneapi_convex_hull.cpp
    :
    vim oneapi_convex_hull.cpp
  3. Place the following inside the file:
    #include <pcl/oneapi/surface/convex_hull.h> #include <pcl/io/pcd_io.h> #include <pcl/PolygonMesh.h> #include <pcl/surface/convex_hull.h> #include <pcl/visualization/pcl_visualizer.h> using namespace pcl::oneapi; int main (int argc, char** argv) { pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_ptr( new pcl::PointCloud<pcl::PointXYZ>() ); pcl::PointCloud<pcl::PointXYZ>::Ptr convex_ptr; int result = pcl::io::loadPCDFile(argv[1], *cloud_ptr); if (result != 0) { pcl::console::print_info ("Load pcd file failed.\n"); return result; } PseudoConvexHull3D pch(1e5); PseudoConvexHull3D::Cloud cloud_device; PseudoConvexHull3D::Cloud convex_device; cloud_device.upload(cloud_ptr->points); pch.reconstruct(cloud_device, convex_device); convex_ptr.reset(new pcl::PointCloud<pcl::PointXYZ>((int)convex_device.size(), 1)); convex_device.download(convex_ptr->points); pcl::PolygonMesh mesh; pcl::ConvexHull<pcl::PointXYZ> ch; ch.setInputCloud(convex_ptr); ch.reconstruct(mesh); pcl::console::print_info ("Starting visualizer... Close window to exit.\n"); pcl::visualization::PCLVisualizer vis; vis.addPointCloud (cloud_ptr); vis.addPolylineFromPolygonMesh(mesh); vis.resetCamera (); vis.spin (); }
  4. Create a CMakeLists.txt file:
    vim CMakeLists.txt
  5. Place the following inside the file:
    cmake_minimum_required(VERSION 3.5 FATAL_ERROR) set(target oneapi_convex_hull) set(CMAKE_CXX_COMPILER dpcpp) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_FLAGS "-Wall -Wpedantic -Wno-unknown-pragmas -Wno-pass-failed -Wno-unneeded-internal-declaration -Wno-unused-function -Wno-gnu-anonymous-struct -Wno-nested-anon-types -Wno-extra-semi -Wno-unused-local-typedef -fsycl -fsycl-unnamed-lambda -ferror-limit=1") project(${target}) find_package(PCL 1.12 REQUIRED) find_package(PCL-ONEAPI 1.12 REQUIRED) include_directories(${PCL_INCLUDE_DIRS} ${PCL-ONEAPI_INCLUDE_DIRS}) link_directories(${PCL_LIBRARY_DIRS} ${PCL-ONEAPI_LIBRARY_DIRS}) add_definitions(${PCL_DEFINITIONS} ${PCL-ONEAPI_DEFINITIONS}) add_executable (${target} oneapi_convex_hull.cpp) target_link_libraries (${target} sycl pcl_surface pcl_visualization pcl_oneapi_surface)
  6. Source the Intel® oneAPI Base Toolkit environment:
    export PATH=/home/eiforamr/workspace/lib/pcl/share/pcl-1.12:/home/eiforamr/workspace/lib/pcl/share/pcl-oneapi-1.12:$PATH source /opt/intel/oneapi/setvars.sh
  7. Build the code:
    cd /home/eiforamr/workspace/convex_hull/ mkdir build && cd build cmake ../ make -j
  8. Download the test data from GitHub*:
    wget https://raw.githubusercontent.com/PointCloudLibrary/pcl/master/test/bun0.pcd # if the binary is not downloaded try setting the proxies first and try again: export http_proxy="http://<http_proxy>:port" export https_proxy="http://<https_proxy>:port"
  9. Run the binary:
    ./oneapi_convex_hull ./bun0.pcd
Expected results: a convex hull triangle mesh

Code Explanation

Load the test data from GitHub* into a PointCloud<PointXYZ>.
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_ptr( new pcl::PointCloud<pcl::PointXYZ>() ); pcl::PointCloud<pcl::PointXYZ>::Ptr convex_ptr; int result = pcl::io::loadPCDFile(argv[1], *cloud_ptr); if (result != 0) { pcl::console::print_info ("Load pcd file failed.\n"); return result; }
Create GPU input and output device arrays, and load point cloud data into the input device array.
PseudoConvexHull3D::Cloud cloud_device; PseudoConvexHull3D::Cloud convex_device; cloud_device.upload(cloud_ptr->points);
GPU: Perform reconstruction, and generate convex hull vertices.
pch.reconstruct(cloud_device, convex_device);
Download the convex hull vertices from the GPU to the CPU.
convex_device.download(convex_ptr->points);
CPU: Perform reconstruction to generate the convex hull mesh.
pcl::PolygonMesh mesh; pcl::ConvexHull<pcl::PointXYZ> ch; ch.setInputCloud(convex_ptr); ch.reconstruct(mesh);
Visualize the convex hull mesh results.
pcl::console::print_info ("Starting visualizer... Close window to exit.\n"); pcl::visualization::PCLVisualizer vis; vis.addPointCloud (cloud_ptr); vis.addPolylineFromPolygonMesh(mesh); vis.resetCamera (); vis.spin ();

Product and Performance Information

1

Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.