import argparse import concurrent.futures import json from pathlib import Path import sys import numpy as np from scipy import sparse import torch ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / 'stb_minimal_20261017/trnerf')) from loaders.loader_captured_ours import _apply_shift from evaluation.io import sha256, write_json from evaluation import PROTOCOL def scene_bounds(scene): with (ROOT / 'Reconstruction' / scene / 'sp_merged_map.ply').open('rb') as source: header = [] while True: line = source.readline().decode('ascii').strip() header.append(line) if line == 'end_header': break count = int(next(line.split()[-1] for line in header if line.startswith('element vertex'))) points = np.fromfile(source, dtype=[('x', '= 100) & (counts.sum(-1) > 0) assert mask.any(), f'Empty test mask: {scene}/{stem}' np.save(mask_path, mask) records[stem] = dict(frame, file_path=f'{stem}.npz', histogram_path=histogram_path.name, histogram_sha256=sha256(histogram_path), mask_path=mask_path.name, mask_sha256=sha256(mask_path), reference_scale=1.0) contract = dict(protocol=PROTOCOL, scene_id=scene, measurement_root=str(cache), intrinsics_sha256=sha256(intrinsics), height=192, width=256, n_bins=672, bin_width_s=7.5e-10, time_start=0, histogram_peak=peak, display_scale=display, training_frames=train, scale_policy='Maximum calibrated bin count and maximum integrated count over hardware-valid pixels of the ten supplied training frames; shared by 3/5/10 views.', mask_policy='offset <= 10 AND calibrated GT peak >= 100 AND positive signal', frames=[records[Path(frame['file_path']).stem] for frame in test]) write_json(reference / 'contract.json', contract) write_json(cache / 'scene.json', dict(scene=scene, aabb=scene_bounds(scene), aabb_source='Supplied sp_merged_map.ply extrema, expanded by 5% or 0.5m per axis', test_frames=len(test), train_frames=10)) print(f'Prepared {scene}: {len(frames)} captures, {len(test)} tests, peak={peak}, display={display}', flush=True) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--workers', type=int, default=3) args = parser.parse_args() scenes = sorted(path.name for path in (ROOT / 'Reconstruction/SP-TransientBench_9scenes_train_test').iterdir()) with concurrent.futures.ProcessPoolExecutor(max_workers=args.workers) as executor: list(executor.map(prepare_scene, scenes))