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