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

相关推荐
唐青枫3 天前
线程不是越多越快:C#.NET Thread 生命周期、同步与后台工作线程实战
c#·.net
唐青枫4 天前
别只会反射:C#.NET Emit 动态生成代码实战详解
c#·.net
Caco_D4 天前
一行代码抓遍全网 20 个热榜!Aneiang.Pa 4.0 发布 — 极简 .NET 爬虫库
爬虫·.net
咕白m6254 天前
.NET 环境下 Word 超链接批量提取方案
c#·.net
小码编匠5 天前
C# 工控上位机必备:数据转换工具类与十个核心模块
后端·c#·.net
唐青枫7 天前
别再乱用 StartNew:C#.NET TaskFactory 任务调度实战详解
c#·.net
2601_9620725510 天前
李梦娇常识4600问|题库|打印版
sql·华为od·华为·c#·华为云·.net·harmonyos
步步为营DotNet11 天前
基于.NET Aspire 实现云原生应用的高效监控与可观测性
云原生·.net·wpf