neka-nat / cupoch

Robotics with GPU computing
MIT License
918 stars 107 forks source link

PointCloud interoperability between cupoch and Open3D #130

Open dlzou opened 2 months ago

dlzou commented 2 months ago

Firstly, thanks for the effort put into this great library!

I have some Python code that uses cupoch for ICP registration. Afterward, it calls get_information_matrix from Open3D API. Currently, the code does this to convert from cupoch.geometry.PointCloud to open3d.geometry.PointCloud:

import cupoch as cph
import open3d as o3d

...

cloud_A = cph.geometry.PointCloud()
cloud_B = cph.geometry.PointCloud()
cloud_A.points = cph.utility.Vector3fVector(pts_A)
cloud_B.points = cph.utility.Vector3fVector(pts_B)

tfB2A = cph.registration.registration_icp(
    cloud_B,
    cloud_A,
    ...
)

# Conversion
cloud_A_cpu = o3d.geometry.PointCloud()
cloud_B_cpu = o3d.geometry.PointCloud()
pts_A_cpu = np.asarray(cloud_A.points.cpu()).astype(float, copy=False)
cloud_A_cpu.points = o3d.utility.Vector3dVector(pts_A_cpu)
pts_B_cpu = np.asarray(cloud_B.points.cpu()).astype(float, copy=False)
cloud_B_cpu.points = o3d.utility.Vector3dVector(pts_B_cpu)

information_icp = (
    o3d.pipelines.registration.get_information_matrix_from_point_clouds(
        cloud_B_cpu,
        cloud_A_cpu,
        INFORMATION_MATRIX_CORRESPONDENCE_DISTANCE,
        tfB2A,
    )
)

From timing the section commented as "Conversion" I suspect it's doing some unnecessary copying. Is there a faster way to do this conversion?