| 1 |
export type Vec2 = [number, number]; |
| 2 |
export type Vec3 = [number, number, number]; |
| 3 |
export type Quat = [number, number, number, number]; // w, x, y, z |
| 4 |
|
| 5 |
export interface Rigid3d { |
| 6 |
rotation: Quat; |
| 7 |
translation: Vec3; |
| 8 |
} |
| 9 |
|
| 10 |
export interface Camera { |
| 11 |
id: number; |
| 12 |
modelId: number; |
| 13 |
width: number; |
| 14 |
height: number; |
| 15 |
params: number[]; |
| 16 |
} |
| 17 |
|
| 18 |
export const INVALID_POINT3D_ID = 0xffffffffffffffffn; |
| 19 |
|
| 20 |
// Observations are flattened so their buffers can be transferred from the parser worker. |
| 21 |
export interface Point2DData { |
| 22 |
// [x0, y0, x1, y1, ...] |
| 23 |
xy: Float64Array; |
| 24 |
point3DIds: BigUint64Array; |
| 25 |
} |
| 26 |
|
| 27 |
export interface Point2D { |
| 28 |
xy: Vec2; |
| 29 |
point3DId: bigint | null; |
| 30 |
} |
| 31 |
|
| 32 |
export interface ImageRecord { |
| 33 |
id: number; |
| 34 |
cameraId: number; |
| 35 |
frameId: number; |
| 36 |
rigId: number; |
| 37 |
name: string; |
| 38 |
camFromWorld: Rigid3d; |
| 39 |
points2D: Point2DData; |
| 40 |
} |
| 41 |
|
| 42 |
export interface TrackElement { |
| 43 |
imageId: number; |
| 44 |
point2DIdx: number; |
| 45 |
} |
| 46 |
|
| 47 |
export interface Point3D { |
| 48 |
id: bigint; |
| 49 |
xyz: Vec3; |
| 50 |
color: [number, number, number]; |
| 51 |
error: number; |
| 52 |
track: TrackElement[]; |
| 53 |
} |
| 54 |
|
| 55 |
export interface Point3DData { |
| 56 |
ids: BigUint64Array; |
| 57 |
xyz: Float64Array; |
| 58 |
colors: Uint8Array; |
| 59 |
errors: Float32Array; |
| 60 |
// Offsets delimit each point's range in the two parallel track arrays. |
| 61 |
trackOffsets: Uint32Array; |
| 62 |
trackImageIds: Uint32Array; |
| 63 |
trackPoint2DIdxs: Uint32Array; |
| 64 |
} |
| 65 |
|
| 66 |
export interface Reconstruction { |
| 67 |
cameras: Map<number, Camera>; |
| 68 |
images: Map<number, ImageRecord>; |
| 69 |
points3D: Point3DData; |
| 70 |
modernRigFormat: boolean; |
| 71 |
} |
| 72 |
|
| 73 |
export function point2DCount(image: ImageRecord): number { |
| 74 |
return image.points2D.point3DIds.length; |
| 75 |
} |
| 76 |
|
| 77 |
export function point2DAt(image: ImageRecord, index: number): Point2D | undefined { |
| 78 |
if (index < 0 || index >= point2DCount(image)) return undefined; |
| 79 |
const point3DId = image.points2D.point3DIds[index]!; |
| 80 |
return { |
| 81 |
xy: [image.points2D.xy[index * 2]!, image.points2D.xy[index * 2 + 1]!], |
| 82 |
point3DId: point3DId === INVALID_POINT3D_ID ? null : point3DId, |
| 83 |
}; |
| 84 |
} |
| 85 |
|
| 86 |
export function point3DCount(points: Point3DData): number { |
| 87 |
return points.ids.length; |
| 88 |
} |
| 89 |
|
| 90 |
export function point3DTrackLength(points: Point3DData, index: number): number { |
| 91 |
return points.trackOffsets[index + 1]! - points.trackOffsets[index]!; |
| 92 |
} |
| 93 |
|
| 94 |
export function point3DAt(points: Point3DData, index: number): Point3D { |
| 95 |
if (index < 0 || index >= point3DCount(points)) throw new RangeError(`Invalid 3D point index ${index}`); |
| 96 |
const track = Array.from( |
| 97 |
{length: point3DTrackLength(points, index)}, |
| 98 |
(_, offset) => { |
| 99 |
const trackIndex = points.trackOffsets[index]! + offset; |
| 100 |
return { |
| 101 |
imageId: points.trackImageIds[trackIndex]!, |
| 102 |
point2DIdx: points.trackPoint2DIdxs[trackIndex]!, |
| 103 |
}; |
| 104 |
}, |
| 105 |
); |
| 106 |
return { |
| 107 |
id: points.ids[index]!, |
| 108 |
xyz: [points.xyz[index * 3]!, points.xyz[index * 3 + 1]!, points.xyz[index * 3 + 2]!], |
| 109 |
color: [points.colors[index * 3]!, points.colors[index * 3 + 1]!, points.colors[index * 3 + 2]!], |
| 110 |
error: points.errors[index]!, |
| 111 |
track, |
| 112 |
}; |
| 113 |
} |
| 114 |
|
| 115 |
export function findPoint3DIndex(points: Point3DData, id: bigint): number { |
| 116 |
let lower = 0; |
| 117 |
let upper = points.ids.length; |
| 118 |
while (lower < upper) { |
| 119 |
const middle = lower + Math.floor((upper - lower) / 2); |
| 120 |
const middleId = points.ids[middle]!; |
| 121 |
if (middleId < id) lower = middle + 1; |
| 122 |
else upper = middle; |
| 123 |
} |
| 124 |
return lower < points.ids.length && points.ids[lower] === id ? lower : -1; |
| 125 |
} |
| 126 |
|
| 127 |
export interface LocalFile { |
| 128 |
path: string; |
| 129 |
file: File; |
| 130 |
} |
| 131 |
|
| 132 |
export interface SparseModelCandidate { |
| 133 |
path: string; |
| 134 |
files: Map<string, File>; |
| 135 |
} |