使用tinyply.net保存ply格式点云

1.github项目地址

https://github.com/yk35/tinyply.net/tree/master

2.安装方式。文档说明需要下载项目后编译生成dll文件

3.按文档说明生产dll文件

4.在自己的项目中引用tinyplynet.dll即可

5.github文档中的使用说明

6.我的代码示例

复制代码
     public static async Task<string> SavePointCloudToPLYV4(string PlyName, SurfacePoint[] surfaceBuffer, bool isAsync,bool isBinary)
     {
         string result = "";

         try
         { 
             string PlyDir = "";

             PlyDir = AppDomain.CurrentDomain.BaseDirectory + "AppPLY";
             if (!Directory.Exists(PlyDir))
             {
                 Directory.CreateDirectory(PlyDir);
             }

             string PLYFile = $@"{PlyDir}/{PlyName}.ply";

           
                 _ = Task.Run(async () =>
                 {
                     Serilog.Log.Logger.Debug($"开始异步拼接PLY文件内容");

                     try
                     {
                         var vertices = new List<double>();
                         foreach(var item in surfaceBuffer)
                         {
                             vertices.Add(item.x);
                             vertices.Add(item.y);
                             vertices.Add(item.z); 
                         }

                         var output = new PlyFile();
                         output.AddPropertiesToElement("vertex", new[] { "x", "y", "z" }, vertices);
                         //output.AddListPropertyToElement("face", "vertex_indices", faces);
                         using var outStream = File.Create(PLYFile);
                         output.Write(outStream, isBinary); // true = binary
 
                     }
                     catch (Exception ex)
                     {
                         Serilog.Log.Logger.Error($" 异步点云保存出现异常 [{PLYFile}] {ex.Message} {ex.StackTrace}");
                     }

                     Serilog.Log.Logger.Debug($" 异步点云保存完成 [{PLYFile}]");
                 });
              
        
             result = PLYFile;
 
         }
         catch (Exception ex)
         {
             Serilog.Log.Logger.Error($" 保存点云出现异常[{PlyName}] {ex.Message}");
          
         }
 

         return result;
     }

使用二进制格式ply文件保存和读取速度会比ascii码格式快很多

相关推荐
似水明俊德4 小时前
02-C#.Net-反射-面试题
开发语言·面试·职场和发展·c#·.net
似水明俊德7 小时前
02-C#.Net-反射-学习笔记
开发语言·笔记·学习·c#·.net
Murphy20238 小时前
.net8 Swashbuckle.AspNetCore WEBAPI 配置要点记录
.net·swagger·webapi·swashbuckle
余衫马9 小时前
Agent Skills 实战(.NET):理论 × 代码 × 企业案例
人工智能·.net·agent·skill·openclaw
CSharp精选营11 小时前
字符串拼接用“+”还是 StringBuilder?别再凭感觉写了
.net·stringbuilder·字符串拼接·csharp
.NET修仙日记11 小时前
Acme .NET 工具类库:一站式解决.NET开发高频场景问题
.net·nuget·acme·.net8.0·.net9.0·acme.net·.net10.0
.NET修仙日记13 小时前
Acme.ReturnOh:让.NET API返回值处理更优雅,统一响应格式一步到位
c#·.net·webapi
喵叔哟14 小时前
19-AIAgent智能代理开发
微服务·.net
唐青枫17 小时前
深入理解 C#.NET TaskScheduler:为什么大量使用 Work-Stealing
c#·.net
喵叔哟17 小时前
20-多模态AI应用开发
人工智能·微服务·.net