【问题标题】:Read and import a .PLY flle with C#使用 C# 读取和导入 .PLY 文件
【发布时间】:2016-05-24 10:47:59
【问题描述】:

您好,我想知道是否有任何方法可以读取 .ply 文件并仅获取 X-Y-Z 位置。ply 文件格式为:

ply

format ascii 1.0

element vertex 303943

property float x

property float y

property float z

property uchar red

property uchar green

property uchar blue

end_header

1.955 1.647 -1.359 182 185 182 

0.87 1.532 -1.453 152 160 153 

0.843 1.548 -1.484 153 161 154 

0.832 1.539 -1.472 151 159 152 

除了在 Matlab 上做这件事的方法之外,我还没有找到任何东西。

【问题讨论】:

  • 是什么阻止您编写一些 c# 代码来解析这种格式并获取 x、y 和 z ?
  • 您似乎误解了 StackOverflow 的概念。你没有描述你想要什么,人们向你发送代码。您提供了您自己的代码的minimal reproducible example,并告诉我们什么不起作用。如果你正在寻找一个现有的图书馆来为你做这件事——这也是题外话。

标签: c# file import


【解决方案1】:

试试这个

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication93
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.txt";
        static void Main(string[] args)
        {
            List<List<double>> data = new List<List<double>>();
            StreamReader reader = new StreamReader(FILENAME);
            string inputLine = "";
            Boolean endHeader = false;
            while ((inputLine = reader.ReadLine()) != null)
            {
                inputLine = inputLine.Trim();
                if (inputLine.Length > 0)
                {
                    if(endHeader)
                    {
                        List<double> newRow = inputLine.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(x => double.Parse(x)).ToList();
                        data.Add(newRow);
                    }
                    else
                    {
                        if(inputLine.Contains("end_header"))
                        {
                            endHeader = true;
                        }
                    }
                }
            }

        }
    }

}

【讨论】:

  • 请注意,该脚本还将读取“面列表”。如果您只需要顶点,则应从 PLY 标题中读取顶点数并仅读取该数量的行。 (或者当 inputLine.Split 给出超过 3 个值时停止读取。ply 格式:paulbourke.net/dataformats/ply
猜你喜欢
  • 1970-01-01
  • 2015-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-14
  • 2015-06-26
  • 1970-01-01
  • 2015-07-26
相关资源
最近更新 更多