8#include <nlohmann/json.hpp>
14struct LoadedPlanarSource final {
20auto load_planar_source(
const JsonPlanarDatasetLoader::Entry& entry) -> LoadedPlanarSource {
21 std::ifstream stream(entry.path);
23 throw std::runtime_error(
"JsonPlanarDatasetLoader: failed to open " + entry.path.string());
26 nlohmann::json json_data;
29 auto detections = json_data.get<PlanarDetections>();
33 throw std::runtime_error(
"Requested sensor_id '" + *entry.sensor_id +
34 "' not found in dataset.");
37 nlohmann::json source_info{{
"path", entry.path.string()}, {
"sensor_id",
detections.
sensor_id}};
39 source_info[
"detector"] =
detections.
metadata.value(
"detector", nlohmann::json::object());
42 return LoadedPlanarSource{
44 .source_summary = std::move(source_info),
45 .raw_payload = std::move(json_data),
52 std::optional<std::string> sensor_id) {
53 entries_.push_back(
Entry{path, std::move(sensor_id)});
57 if (entries_.empty()) {
58 throw std::runtime_error(
"JsonPlanarDatasetLoader: no dataset entries configured.");
62 dataset.
metadata = nlohmann::json::object();
63 dataset.
metadata[
"sources"] = nlohmann::json::array();
64 dataset.
raw_json = nlohmann::json::object();
66 for (
const auto& entry : entries_) {
67 auto loaded = load_planar_source(entry);
68 dataset.
metadata[
"sources"].push_back(std::move(loaded.source_summary));
69 dataset.
raw_json[entry.path.string()] = std::move(loaded.raw_payload);
auto load() -> CalibrationDataset override
Load and validate all configured dataset entries.
void add_entry(const std::filesystem::path &path, std::optional< std::string > sensor_id=std::nullopt)
Append a dataset file to the loader queue.
PlanarDetections detections
nlohmann::json source_summary
nlohmann::json raw_payload
Aggregated dataset consumed by the calibration pipeline.
nlohmann::json raw_json
Original dataset payloads keyed by source path.
std::vector< PlanarDetections > planar_cameras
Description of a JSON dataset entry on disk.
std::filesystem::path source_file