feat:测试两种类型体素滤波的库

main
邱棚 2025-04-12 17:22:05 +08:00
parent 451970fc50
commit e02d1219f4
3 changed files with 18 additions and 18 deletions

View File

@ -1,39 +1,39 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
public class PclPointCloud : IDisposable { public class PclPointCloudXYZ : IDisposable {
private IntPtr handle; private IntPtr handle;
public PclPointCloud() => handle = create_point_cloud(); public PclPointCloudXYZ() => handle = create_pointcloud_xyz();
// 构造函数用于内部封装 handle 对象 // 构造函数用于内部封装 handle 对象
public PclPointCloud(IntPtr handle) => this.handle = handle; public PclPointCloudXYZ(IntPtr handle) => this.handle = handle;
public void Dispose() { delete_point_cloud(handle); handle = IntPtr.Zero; } public void Dispose() { delete_pointcloud(handle); handle = IntPtr.Zero; }
public int Load(string path) => load_point_cloud(handle, path); public bool Load(string path) => load_pcd_xyz( path,handle);
public int Save(string path) => save_point_cloud(handle, path); public int Save(string path) => save_pcd_xyz(path,handle);
public IntPtr Handle => handle; public IntPtr Handle => handle;
[DllImport("./pcl/libpclwrapper.dylib")] private static extern IntPtr create_point_cloud(); [DllImport("./pcl/libpclwrapper.dylib")] private static extern IntPtr create_pointcloud_xyz();
[DllImport("./pcl/libpclwrapper.dylib")] private static extern void delete_point_cloud(IntPtr ptr); [DllImport("./pcl/libpclwrapper.dylib")] private static extern void delete_pointcloud(IntPtr ptr);
[DllImport("./pcl/libpclwrapper.dylib")] private static extern int load_point_cloud(IntPtr ptr, string path); [DllImport("./pcl/libpclwrapper.dylib")] private static extern bool load_pcd_xyz(string path,IntPtr ptr);
[DllImport("./pcl/libpclwrapper.dylib")] private static extern int save_point_cloud(IntPtr ptr, string path); [DllImport("./pcl/libpclwrapper.dylib")] private static extern int save_pcd_xyz(string path,IntPtr ptr);
} }
public class PclVoxelGrid : IDisposable { public class PclVoxelGridXYZ : IDisposable {
private IntPtr handle; private IntPtr handle;
public PclVoxelGrid() => handle = create_voxel_filter(); public PclVoxelGridXYZ() => handle = create_voxel_filter_xyz();
public void Dispose() { delete_voxel_filter(handle); handle = IntPtr.Zero; } public void Dispose() { delete_voxel_filter(handle); handle = IntPtr.Zero; }
public void SetLeafSize(float x, float y, float z) => set_voxel_leaf_size(handle, x, y, z); public void SetLeafSize(float x, float y, float z) => set_voxel_leaf_size(handle, x, y, z);
public void SetInputCloud(PclPointCloud cloud) => set_voxel_input_cloud(handle, cloud.Handle); public void SetInputCloud(PclPointCloudXYZ cloud) => set_voxel_input_cloud(handle, cloud.Handle);
public PclPointCloud Filter() => new PclPointCloud(apply_voxel_filter(handle)); public PclPointCloudXYZ Filter() => new PclPointCloudXYZ(apply_voxel_filter_xyz(handle));
[DllImport("./pcl/libpclwrapper.dylib")] private static extern IntPtr create_voxel_filter(); [DllImport("./pcl/libpclwrapper.dylib")] private static extern IntPtr create_voxel_filter_xyz();
[DllImport("./pcl/libpclwrapper.dylib")] private static extern void delete_voxel_filter(IntPtr ptr); [DllImport("./pcl/libpclwrapper.dylib")] private static extern void delete_voxel_filter(IntPtr ptr);
[DllImport("./pcl/libpclwrapper.dylib")] private static extern void set_voxel_leaf_size(IntPtr ptr, float x, float y, float z); [DllImport("./pcl/libpclwrapper.dylib")] private static extern void set_voxel_leaf_size(IntPtr ptr, float x, float y, float z);
[DllImport("./pcl/libpclwrapper.dylib")] private static extern void set_voxel_input_cloud(IntPtr filterPtr, IntPtr cloudPtr); [DllImport("./pcl/libpclwrapper.dylib")] private static extern void set_voxel_input_cloud(IntPtr filterPtr, IntPtr cloudPtr);
[DllImport("./pcl/libpclwrapper.dylib")] private static extern IntPtr apply_voxel_filter(IntPtr filterPtr); [DllImport("./pcl/libpclwrapper.dylib")] private static extern IntPtr apply_voxel_filter_xyz(IntPtr filterPtr);
} }

View File

@ -5,10 +5,10 @@ class Program
{ {
static void Main() static void Main()
{ {
using var cloud = new PclPointCloud(); using var cloud = new PclPointCloudXYZ();
cloud.Load("./dataset/0.pcd"); cloud.Load("./dataset/0.pcd");
using var voxel = new PclVoxelGrid(); using var voxel = new PclVoxelGridXYZ();
voxel.SetLeafSize(0.1f, 0.1f, 0.1f); voxel.SetLeafSize(0.1f, 0.1f, 0.1f);
voxel.SetInputCloud(cloud); voxel.SetInputCloud(cloud);

Binary file not shown.