Skip to content
Open
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
6 changes: 5 additions & 1 deletion libs/cuvslam/cuvslam2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,11 @@ Odometry::Odometry(const Rig& rig, const Config& cfg) {
std::vector<CameraId> depth_ids;
bool enable_depth_stereo_tracking_fig = false;
if (cfg.odometry_mode == OdometryMode::RGBD) {
depth_ids.push_back(static_cast<CameraId>(cfg.rgbd_settings.depth_camera_id));
const int32_t depth_camera_id = cfg.rgbd_settings.depth_camera_id;
THROW_INVALID_ARG_IF(
depth_camera_id < 0 || static_cast<size_t>(depth_camera_id) >= rig.cameras.size(),
"RGBDSettings::depth_camera_id (" + std::to_string(depth_camera_id) + ") is not a camera id of the rig");
depth_ids.push_back(static_cast<CameraId>(depth_camera_id));
enable_depth_stereo_tracking_fig = cfg.rgbd_settings.enable_depth_stereo_tracking;
} else if (cfg.odometry_mode == OdometryMode::Multisensor) {
depth_ids.reserve(cfg.multisensor_settings.depth_camera_ids.size());
Expand Down
12 changes: 12 additions & 0 deletions libs/cuvslam/test/tracker_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@ TEST_F(TrackerTest, RejectsSlamConfigInOdometryOnlyMode) {
EXPECT_THROW(Tracker(rig, Mode::OdometryOnlyRealtime, realtime, &slam), std::invalid_argument);
}

TEST_F(TrackerTest, RgbdModeChecksDepthCameraId) {
// The depth camera id has to name a camera of the rig: the default -1 means "not set", and an id
// past the end of the rig would reach the frustum graph as a camera that does not exist.
Odometry::Config cfg;
cfg.odometry_mode = Odometry::OdometryMode::RGBD;
EXPECT_THROW(Tracker(rig, Mode::OdometryOnlyRealtime, cfg), std::invalid_argument);

cfg.rgbd_settings.depth_camera_id = static_cast<int32_t>(rig.cameras.size());
EXPECT_THROW(Tracker(rig, Mode::OdometryOnlyRealtime, cfg), std::invalid_argument);
}

TEST_F(TrackerTest, RejectsNonFiniteCalibration) {
constexpr float kNan = std::numeric_limits<float>::quiet_NaN();

Expand Down Expand Up @@ -292,6 +303,7 @@ TEST_F(TrackerTest, RgbdModeRequiresCudaBuild) {
// rather than silently constructing a tracker that cannot run it.
Odometry::Config cfg;
cfg.odometry_mode = Odometry::OdometryMode::RGBD;
cfg.rgbd_settings.depth_camera_id = 0;
try {
Tracker{rig, Mode::OdometryOnlyRealtime, cfg};
FAIL() << "RGBD mode was accepted by a build without CUDA";
Expand Down
Loading