| 38 | * Write images.bin. |
| 39 | */ |
| 40 | export function writeImagesBinary( |
| 41 | images: Map<ImageId, Image>, |
| 42 | wasmReconstruction?: WasmReconstructionWrapper | null |
| 43 | ): ArrayBuffer { |
| 44 | const writer = new BinaryWriter(); |
| 45 | |
| 46 | writer.writeUint64FromNumber(images.size); |
| 47 | |
| 48 | for (const imageId of sortedKeys(images)) { |
| 49 | const img = images.get(imageId)!; |
| 50 | |
| 51 | writer.writeUint32(imageId); |
| 52 | writer.writeFloat64(img.qvec[0]); |
| 53 | writer.writeFloat64(img.qvec[1]); |
| 54 | writer.writeFloat64(img.qvec[2]); |
| 55 | writer.writeFloat64(img.qvec[3]); |
| 56 | writer.writeFloat64(img.tvec[0]); |
| 57 | writer.writeFloat64(img.tvec[1]); |
| 58 | writer.writeFloat64(img.tvec[2]); |
| 59 | writer.writeUint32(img.cameraId); |
| 60 | writer.writeString(img.name); |
| 61 | |
| 62 | let points2D: Point2D[] = img.points2D; |
| 63 | if (points2D.length === 0 && wasmReconstruction) { |
| 64 | points2D = wasmReconstruction.getImagePoints2DArray(imageId); |
| 65 | } |
| 66 | |
| 67 | writer.writeUint64FromNumber(points2D.length); |
| 68 | for (const pt2D of points2D) { |
| 69 | writer.writeFloat64(pt2D.xy[0]); |
| 70 | writer.writeFloat64(pt2D.xy[1]); |
| 71 | writer.writeUint64(toBinaryPoint3DId(pt2D.point3DId)); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | return writer.toArrayBuffer(); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Write points3D.bin. |