Skip to content

Commit 2a64e89

Browse files
committed
Fix unit tests and BAD SLAM's command-line mode
1 parent ffa5b37 commit 2a64e89

File tree

6 files changed

+37
-14
lines changed

6 files changed

+37
-14
lines changed

applications/badslam/src/badslam/main.cc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,19 @@ int LIBVIS_QT_MAIN(int argc, char** argv) {
401401
CUDAAutoTuner::Instance().SetTuningIteration(auto_tuning_iteration);
402402
}
403403

404+
// Always create a QApplication, even if not using the GUI. It is required for
405+
// using libvis' Qt implementation for creating windowless OpenGL contexts.
406+
QSurfaceFormat surface_format;
407+
surface_format.setVersion(4, 4);
408+
surface_format.setProfile(QSurfaceFormat::CompatibilityProfile);
409+
surface_format.setSamples(4);
410+
surface_format.setAlphaBufferSize(0 /*8*/);
411+
QSurfaceFormat::setDefaultFormat(surface_format);
412+
QApplication qapp(argc, argv);
413+
QCoreApplication::setOrganizationName("ETH");
414+
QCoreApplication::setOrganizationDomain("eth3d.net");
415+
QCoreApplication::setApplicationName("BAD SLAM");
416+
404417
// Load the dataset, respectively start the live input or show the GUI.
405418
RealSenseInputThread rs_input;
406419
K4AInputThread k4a_input;
@@ -413,17 +426,6 @@ int LIBVIS_QT_MAIN(int argc, char** argv) {
413426
return EXIT_FAILURE;
414427
}
415428

416-
QSurfaceFormat surface_format;
417-
surface_format.setVersion(4, 4);
418-
surface_format.setProfile(QSurfaceFormat::CompatibilityProfile);
419-
surface_format.setSamples(4);
420-
surface_format.setAlphaBufferSize(0 /*8*/);
421-
QSurfaceFormat::setDefaultFormat(surface_format);
422-
QApplication qapp(argc, argv);
423-
QCoreApplication::setOrganizationName("ETH");
424-
QCoreApplication::setOrganizationDomain("eth3d.net");
425-
QCoreApplication::setApplicationName("BAD SLAM");
426-
427429
bool start_paused = false;
428430
if (!gui_run && !ShowSettingsWindow(&dataset_folder_path, &bad_slam_config, &start_paused)) {
429431
return EXIT_SUCCESS;

applications/badslam/src/badslam/test/test_pairwise_frame_tracking.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <libvis/mesh.h>
3838
#include <libvis/mesh_opengl.h>
3939
#include <libvis/renderer.h>
40+
#include <QApplication>
4041

4142
#include "badslam/cuda_depth_processing.cuh"
4243
#include "badslam/direct_ba.h"
@@ -282,6 +283,11 @@ TEST(Optimization, PairwiseFrameTracking) {
282283

283284
std::mt19937 generator(/*seed*/ 0);
284285

286+
// The QApplication is required if using libvis' Qt implementation for OpenGL contexts.
287+
int argc = 0;
288+
char** argv = nullptr;
289+
QApplication qapp(argc, argv);
290+
285291
// Initialize and switch to an OpenGL context.
286292
OpenGLContext opengl_context;
287293
OpenGLContext no_opengl_context;

applications/badslam/src/badslam/test/test_pose_optimization_geometric_residual.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ TEST(Optimization, PoseOptimizationWithGeometricResidual) {
165165
Matrix<float, 6, 1> error = (global_tr_frame_estimate.inverse() * global_tr_frame).log();
166166
// LOG(INFO) << "Case " << offset_index << " error: " << error.transpose();
167167
for (int i = 0; i < 6; ++ i) {
168-
constexpr float kTolerance = 1e-6f;
168+
constexpr float kTolerance = 1.1e-6f;
169169
EXPECT_NEAR(0.f, error(i), kTolerance) << "Error in test case " << offset_index;
170170
}
171171
}

libvis/src/libvis/opengl_context_qt.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ bool OpenGLContextQt::InitializeWindowless(OpenGLContextImpl* sharing_context) {
5555
return false;
5656
}
5757

58+
if (!qApp) {
59+
LOG(ERROR) << "A QApplication must be created before using OpenGLContextQt.";
60+
return false;
61+
}
62+
5863
context = new QOpenGLContext();
5964

6065
if (sharing_context_qt) {

libvis/src/libvis/qt_thread.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,16 @@
3939
#include <QThread>
4040
#include <QTimer>
4141

42+
#include "libvis/logging.h"
43+
4244
namespace vis {
4345

4446
// Runs the function in the Qt thread. Does not wait for it to complete.
4547
void RunInQtThread(const function<void()>& f) {
48+
if (!qApp) {
49+
LOG(ERROR) << "RunInQtThread(): No qApp exists. Not running the function.";
50+
return;
51+
}
4652
if (QThread::currentThread() == qApp->thread()) {
4753
f();
4854
return;
@@ -60,6 +66,10 @@ void RunInQtThread(const function<void()>& f) {
6066

6167
// Runs the function in the Qt thread. Blocks until it completes.
6268
void RunInQtThreadBlocking(const function<void()>& f) {
69+
if (!qApp) {
70+
LOG(ERROR) << "RunInQtThreadBlocking(): No qApp exists. Not running the function.";
71+
return;
72+
}
6373
if (QThread::currentThread() == qApp->thread()) {
6474
f();
6575
return;

libvis/src/libvis/test/dlt.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ TEST(DLT, KnownTransformsResult) {
132132
// DLT
133133
Mat3f H = DLT(input.data(), output.data(), input.size());
134134
Vec2f result = Vec3f(H * input_point.homogeneous()).hnormalized();
135-
for (int row = 0; row < 3; ++ row) {
135+
for (int row = 0; row < GT.rows(); ++ row) {
136136
EXPECT_NEAR(GT(row), result(row), kEpsilon) << " at (" << row << ")";
137137
}
138138

139139
// Normalized DLT
140140
H = NormalizedDLT(input.data(), output.data(), input.size());
141141
result = Vec3f(H * input_point.homogeneous()).hnormalized();
142-
for (int row = 0; row < 3; ++ row) {
142+
for (int row = 0; row < GT.rows(); ++ row) {
143143
EXPECT_NEAR(GT(row), result(row), kEpsilon) << " at (" << row << ")";
144144
}
145145
}

0 commit comments

Comments
 (0)