Simply3DScan
WriterPcd.cs
Go to the documentation of this file.
1 using System.Collections.Generic;
2 using System.IO;
3 using System.Text;
4 using SharedObjects;
5 
6 namespace PointWriter
7 {
8  // example
9  //# .PCD v.7 - Point Cloud Data file format
10  //VERSION .7
11  //FIELDS x y z rgb
12  //SIZE 4 4 4 4
13  //TYPE F F F F
14  //COUNT 1 1 1 1
15  //WIDTH 163247
16  //HEIGHT 1
17  //VIEWPOINT 0 0 0 1 0 0 0
18  //POINTS 163247
19  //DATA ascii
20  //178 56 456 45645
21 
22 
26  public class WriterPcd : IPointWriter
27  {
31  private readonly List<ColorPoint3D> points = new List<ColorPoint3D>();
32 
37  [LogException]
38  public void AddPoint(ColorPoint3D point)
39  {
40  this.points.Add(point);
41  }
42 
47  [Log]
48  [LogException]
49  public void Write(string fileName)
50  {
51  StreamWriter streamWriter = new StreamWriter(fileName);
52  streamWriter.Write(this.CreateHeader());
53  foreach (ColorPoint3D point in this.points)
54  {
55  //todo color?
56  streamWriter.WriteLine("{0} {1} {2} {3}", (float)point.X, (float)point.Y, (float)point.Z, (int)point.Color.R << 16|(int)point.Color.G<<8|(int)point.Color.B);
57  }
58  streamWriter.Close();
59  }
60 
61  [LogException]
62  private string CreateHeader()
63  {
64  StringBuilder builder = new StringBuilder();
65  builder.AppendLine("VERSION .7");
66  builder.AppendLine("FIELDS x y z rgb");
67  builder.AppendLine("SIZE 4 4 4 4");
68  builder.AppendLine("TYPE F F F F");
69  builder.AppendLine("COUNT 1 1 1 1");
70  builder.AppendLine($"WIDTH {this.points.Count}");
71  builder.AppendLine("HEIGHT 1");
72  builder.AppendLine("VIEWPOINT 0 0 0 1 0 0 0");
73  builder.AppendLine($"POINTS {this.points.Count}");
74  builder.AppendLine("DATA ascii");
75  return builder.ToString();
76  }
77  }
78 }
void AddPoint(ColorPoint3D point)
Adds the point.
Definition: WriterPcd.cs:38
double Z
Gets or sets the z.
Definition: ColorPoint3D.cs:30
double Y
Gets or sets the y.
Definition: ColorPoint3D.cs:23
double X
Gets or sets the x.
Definition: ColorPoint3D.cs:16
Write Points to PCD file
Definition: WriterPcd.cs:26
Color Color
Gets or sets the color.
Definition: ColorPoint3D.cs:38
void Write(string fileName)
Writes to specified file name.
Definition: WriterPcd.cs:49
Interface for writing points to file
Definition: IPointWriter.cs:8