feat: 第一次提交

main
邱棚 2025-04-12 00:43:02 +08:00
commit 23c0f08844
5 changed files with 84 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/bin/
/obj/

39
PclPointCloud.cs Normal file
View File

@ -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);
}

25
PclWrapperTest.csproj Normal file
View File

@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<None Include="bin\Debug\net8.0\image_0000.pcd" />
<None Update="pcl\libpclwrapper.dylib">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="bin\Debug\net8.0\libpclwrapper.dylib" />
</ItemGroup>
<ItemGroup>
<Folder Include="pcl\" />
</ItemGroup>
</Project>

18
Program.cs Normal file
View File

@ -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");
}
}

BIN
pcl/libpclwrapper.dylib Executable file

Binary file not shown.