Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions apps/camera_lidar_calibration/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int64_t>::max(), t1 = std::numeric_limits<int64_t>::min();
for (const auto& p : cloud.points)
Expand All @@ -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;
Expand All @@ -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<double>(image->tsNs - mid) * 1e-9,
static_cast<double>(image->tsNs - target) * 1e-9,
first ? "first point" : "middle",
static_cast<double>(t1 - t0) * 1e-9);
statusMsg = buf + statusMsg;
}
Expand Down Expand Up @@ -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())
Expand All @@ -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<std::string> pairFiles;
// Folders go after the clouds dropped with them, whose first point time picks the image.
std::vector<std::string> 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);
Expand Down
14 changes: 10 additions & 4 deletions apps/camera_lidar_calibration/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading