使用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码格式快很多

相关推荐
张人玉2 小时前
WPF 多语言实现完整笔记(.NET 4.7.2)
笔记·.net·wpf·多语言实现·多语言适配
波波0071 天前
Native AOT 能改变什么?.NET 预编译技术深度剖析
开发语言·.net
Crazy Struggle2 天前
.NET 中如何快速实现 List 集合去重?
c#·.net
极客智造2 天前
ImageSharp 实战应用指南:.NET 跨平台图像处理落地实践
图像处理·.net
时光追逐者2 天前
一个基于 .NET + Vue 实现的通用权限管理平台(RBAC模式),前后端分离模式,开箱即用!
前端·vue.js·c#·.net·.net core
大黄说说2 天前
在 .NET Aspire 项目中集成 AgileConfig 实现统一配置管理
.net
wy3136228212 天前
C#——报错:System.Net.Sockets.SocketException (10049): 在其上下文中,该请求的地址无效。
开发语言·c#·.net
缺点内向2 天前
C#编程实战:如何为Word文档添加背景色或背景图片
开发语言·c#·自动化·word·.net
!chen3 天前
SignalR移植到Esp32小智设备无缝连接.NET功能拓展MCP服务
windows·.net