-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoints3D.cs
More file actions
121 lines (96 loc) · 2.7 KB
/
Points3D.cs
File metadata and controls
121 lines (96 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System.IO;
using System.Collections.Generic;
namespace brab.colmap
{
public class Point3D
{
public ulong Id;
/* position */
public double x, y, z;
/* color */
public uint r, g, b;
public double Error;
public Track[] Track;
override public string ToString()
{
return $"Point3D: Id {Id} pos {x} {y} {z} color {r} {g} {b} Error {Error}";
}
}
public class Track
{
public int ImageId;
public int Point2DIdx;
override public string ToString()
{
return $"Track: {ImageId} {Point2DIdx}";
}
}
public interface Points3D
{
IEnumerable<Point3D> GetPoints();
}
///
/// Note: parsing track for each point is not implemented
///
public class Points3DTxt : Points3D
{
TextFile TxtFile;
public Points3DTxt(string path)
{
TxtFile = new TextFile(path);
}
public IEnumerable<Point3D> GetPoints()
{
var iter = TxtFile.Lines().GetEnumerator();
while (iter.MoveNext())
{
yield return ParseLine.Point3D(iter.Current);
}
}
}
public class Points3DBin : Points3D
{
string FilePath;
public Points3DBin(string path)
{
FilePath = path;
}
public IEnumerable<Point3D> GetPoints()
{
using (var reader = new BinaryReader(File.Open(FilePath, FileMode.Open)))
{
var numPoints = reader.ReadUInt64();
for (ulong i = 0; i < numPoints; i += 1)
{
yield return ReadPoint3D(reader);
}
}
}
Point3D ReadPoint3D(BinaryReader reader)
{
var point = new Point3D();
point.Id = reader.ReadUInt64();
point.x = reader.ReadDouble();
point.y = reader.ReadDouble();
point.z = reader.ReadDouble();
point.r = reader.ReadByte();
point.g = reader.ReadByte();
point.b = reader.ReadByte();
point.Error = reader.ReadDouble();
point.Track = ReadTrack(reader);
return point;
}
Track[] ReadTrack(BinaryReader reader)
{
var trackLen = reader.ReadUInt64();
var track = new Track[trackLen];
for (ulong i = 0; i < trackLen; i += 1)
{
track[i] = new Track();
track[i].ImageId = reader.ReadInt32();
track[i].Point2DIdx = reader.ReadInt32();
}
return track;
}
}
}