MCPcopy Create free account
hub / github.com/ColmapView/Colmapview.github.io / parsePoints3DText

Function parsePoints3DText

src/parsers/points3d.ts:72–130  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

70 * 63390 1.67241 0.292931 0.609726 115 121 122 1.33927 16 6542 15 7345 6 6714 14 7227
71 */
72export function parsePoints3DText(text: string): Map<bigint, Point3D> {
73 const points = new Map<bigint, Point3D>();
74 const lines = text.split('\n');
75
76 for (const line of lines) {
77 // Skip comments and empty lines
78 if (line.startsWith('#') || line.trim() === '') continue;
79
80 const parts = line.trim().split(/\s+/);
81 if (parts.length < 8) continue;
82
83 const point3DId = parseColmapBigIntToken(parts[0]);
84 const xyzValues = parseColmapNumberTokens(parts.slice(1, 4));
85 const red = parseColmapIntegerToken(parts[4], { min: 0, max: 255 });
86 const green = parseColmapIntegerToken(parts[5], { min: 0, max: 255 });
87 const blue = parseColmapIntegerToken(parts[6], { min: 0, max: 255 });
88 const error = parseColmapNumberToken(parts[7]);
89
90 if (
91 point3DId === null ||
92 xyzValues === null ||
93 red === null ||
94 green === null ||
95 blue === null ||
96 error === null
97 ) {
98 continue;
99 }
100
101 const xyz: [number, number, number] = [
102 xyzValues[0],
103 xyzValues[1],
104 xyzValues[2],
105 ];
106 const rgb: [number, number, number] = [
107 red,
108 green,
109 blue,
110 ];
111
112 // Parse track elements (pairs of IMAGE_ID, POINT2D_IDX)
113 const track: TrackElement[] = [];
114 for (let i = 8; i + 1 < parts.length; i += 2) {
115 const imageId = parseColmapIntegerToken(parts[i], { min: 0 });
116 const point2DIdx = parseColmapIntegerToken(parts[i + 1], { min: 0 });
117
118 if (imageId === null || point2DIdx === null) continue;
119
120 track.push({
121 imageId,
122 point2DIdx,
123 });
124 }
125
126 points.set(point3DId, { point3DId, xyz, rgb, error, track });
127 }
128
129 return points;

Callers 1

points3d.test.tsFile · 0.90

Calls 4

parseColmapBigIntTokenFunction · 0.90
parseColmapNumberTokensFunction · 0.90
parseColmapIntegerTokenFunction · 0.90
parseColmapNumberTokenFunction · 0.90

Tested by

no test coverage detected