commit 23c0f088443092441e53e30fc3c03a5f604d2aa1 Author: 12345qiupeng Date: Sat Apr 12 00:43:02 2025 +0800 feat: 第一次提交 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ded7c4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/obj/ diff --git a/PclPointCloud.cs b/PclPointCloud.cs new file mode 100644 index 0000000..dea4616 --- /dev/null +++ b/PclPointCloud.cs @@ -0,0 +1,39 @@ +using System; +using System.Runtime.InteropServices; + +public class PclPointCloud : IDisposable { + private IntPtr handle; + + public PclPointCloud() => handle = create_point_cloud(); + // 构造函数用于内部封装 handle 对象 + public PclPointCloud(IntPtr handle) => this.handle = handle; + public void Dispose() { delete_point_cloud(handle); handle = IntPtr.Zero; } + + public int Load(string path) => load_point_cloud(handle, path); + public int Save(string path) => save_point_cloud(handle, path); + public IntPtr Handle => handle; + + [DllImport("./pcl/libpclwrapper.dylib")] private static extern IntPtr create_point_cloud(); + [DllImport("./pcl/libpclwrapper.dylib")] private static extern void delete_point_cloud(IntPtr ptr); + [DllImport("./pcl/libpclwrapper.dylib")] private static extern int load_point_cloud(IntPtr ptr, string path); + [DllImport("./pcl/libpclwrapper.dylib")] private static extern int save_point_cloud(IntPtr ptr, string path); +} + +public class PclVoxelGrid : IDisposable { + private IntPtr handle; + + public PclVoxelGrid() => handle = create_voxel_filter(); + 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 SetInputCloud(PclPointCloud cloud) => set_voxel_input_cloud(handle, cloud.Handle); + public PclPointCloud Filter() => new PclPointCloud(apply_voxel_filter(handle)); + + [DllImport("./pcl/libpclwrapper.dylib")] private static extern IntPtr create_voxel_filter(); + [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_input_cloud(IntPtr filterPtr, IntPtr cloudPtr); + [DllImport("./pcl/libpclwrapper.dylib")] private static extern IntPtr apply_voxel_filter(IntPtr filterPtr); + + +} \ No newline at end of file diff --git a/PclWrapperTest.csproj b/PclWrapperTest.csproj new file mode 100644 index 0000000..e18a633 --- /dev/null +++ b/PclWrapperTest.csproj @@ -0,0 +1,25 @@ + + + + Exe + net8.0 + enable + enable + + + + + + Always + + + + + + + + + + + + diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..5194c41 --- /dev/null +++ b/Program.cs @@ -0,0 +1,18 @@ +using System; +using System.Runtime.InteropServices; + +class Program +{ + static void Main() + { + using var cloud = new PclPointCloud(); + cloud.Load("image_0000.pcd"); + + using var voxel = new PclVoxelGrid(); + voxel.SetLeafSize(0.2f, 0.2f, 0.2f); + voxel.SetInputCloud(cloud); + + using var filtered = voxel.Filter(); + filtered.Save("output.pcd"); + } +} \ No newline at end of file diff --git a/pcl/libpclwrapper.dylib b/pcl/libpclwrapper.dylib new file mode 100755 index 0000000..577223a Binary files /dev/null and b/pcl/libpclwrapper.dylib differ