diff --git a/apps/camera_lidar_calibration/App.cpp b/apps/camera_lidar_calibration/App.cpp index aba7d8c8..a56befe8 100644 --- a/apps/camera_lidar_calibration/App.cpp +++ b/apps/camera_lidar_calibration/App.cpp @@ -437,7 +437,7 @@ void AppState::loadImage(const char* path) } // ── AppState::loadImageClosestToCloudTime ───────────────────────────────────── -void AppState::loadImageClosestToCloudTime(const char* dir) +void AppState::loadImageClosestToCloudTime(const char* dir, CloudTimeRef ref) { int64_t t0 = std::numeric_limits::max(), t1 = std::numeric_limits::min(); for (const auto& p : cloud.points) @@ -451,8 +451,9 @@ void AppState::loadImageClosestToCloudTime(const char* dir) statusMsg = std::string("No point times in the loaded clouds, so no image picked from ") + dir; return; } - const int64_t mid = t0 + (t1 - t0) / 2; - const auto image = calib::closestImage(dir, mid); + const bool first = ref == CloudTimeRef::First; + const int64_t target = first ? t0 : t0 + (t1 - t0) / 2; + const auto image = calib::closestImage(dir, target); if (!image) { statusMsg = std::string("No image with a capture time in ") + dir; @@ -465,9 +466,10 @@ void AppState::loadImageClosestToCloudTime(const char* dir) std::snprintf( buf, sizeof(buf), - "%s is %+.3f s from the middle of the clouds' %.1f s; ", + "%s is %+.3f s from the %s of the clouds' %.1f s; ", std::filesystem::path(image->path).filename().string().c_str(), - static_cast(image->tsNs - mid) * 1e-9, + static_cast(image->tsNs - target) * 1e-9, + first ? "first point" : "middle", static_cast(t1 - t0) * 1e-9); statusMsg = buf + statusMsg; } @@ -1118,7 +1120,8 @@ void App::update() state.orbit.update(allowOrbit); // Drag & drop images (*.jpg/*.jpeg/*.png/*.bmp), point clouds (*.laz/*.las), intrinsics - // (*.yml/*.yaml), a calibration or saved pairs (*.json) onto the window to load them -- + // (*.yml/*.yaml), a calibration or saved pairs (*.json) onto the window to load them. A dropped + // folder of images loads the one taken closest to the first point time of the clouds -- // raylib's GLFW backend surfaces OS drag & drop the same way on Windows, Linux and macOS, // so no platform-specific code is needed here. if (IsFileDropped()) @@ -1127,14 +1130,19 @@ void App::update() bool sawCloud = false; // Pairs go last, so the image and calibration dropped with them are what // loadPairs() rescales to and checks rectification against. - std::vector pairFiles; + // Folders go after the clouds dropped with them, whose first point time picks the image. + std::vector pairFiles, imageDirs; for (unsigned int i = 0; i < dropped.count; i++) { - if (AppState::isPairsFile(dropped.paths[i])) + if (std::filesystem::is_directory(dropped.paths[i])) + imageDirs.push_back(dropped.paths[i]); + else if (AppState::isPairsFile(dropped.paths[i])) pairFiles.push_back(dropped.paths[i]); else handleDroppedFile(state, dropped.paths[i], sawCloud); } + for (const std::string& dir : imageDirs) + state.loadImageClosestToCloudTime(dir.c_str(), AppState::CloudTimeRef::First); for (const std::string& path : pairFiles) state.loadPairs(path.c_str()); UnloadDroppedFiles(dropped); diff --git a/apps/camera_lidar_calibration/App.h b/apps/camera_lidar_calibration/App.h index f0f96918..98302788 100644 --- a/apps/camera_lidar_calibration/App.h +++ b/apps/camera_lidar_calibration/App.h @@ -152,10 +152,16 @@ struct AppState //! to see the sensor models, keeping the current viewing angle. void focusOnSensors(); void loadImage(const char* path); - //! Loads the image in `dir` taken closest to the middle of the loaded - //! clouds' point times (calib::closestImage); leaves the image as it is, - //! saying why in statusMsg, when the clouds or images carry no times. - void loadImageClosestToCloudTime(const char* dir); + //! Which point time of the loaded clouds loadImageClosestToCloudTime matches. + enum class CloudTimeRef + { + First, //!< earliest point time (a dropped folder) + Middle //!< middle of the point times (--closest_to_laz) + }; + //! Loads the image in `dir` taken closest to the clouds' `ref` point time + //! (calib::closestImage); leaves the image as it is, saying why in + //! statusMsg, when the clouds or images carry no times. + void loadImageClosestToCloudTime(const char* dir, CloudTimeRef ref = CloudTimeRef::Middle); void loadCloud(const char* path); // clear + load void addCloud(const char* path); // merge into existing cloud void loadIntrinsics(const char* path);