Skip to content

Commit

Permalink
MAINT: remove old code.
Browse files Browse the repository at this point in the history
  • Loading branch information
oddkiva committed Apr 29, 2024
1 parent 4d2abff commit 39b3149
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 942 deletions.
11 changes: 5 additions & 6 deletions cpp/examples/Sara/MultiViewGeometry/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ target_link_libraries(essential_5_point_example PRIVATE tinyply)

# Visual odometry.
sara_add_example(visual_odometry_example)
target_link_libraries(visual_odometry_example PRIVATE DO::Kalpana::EasyGL #
fmt::fmt glfw)

sara_add_example(visual_odometry_example_v2)
target_link_libraries(visual_odometry_example_v2 PRIVATE DO::Kalpana::EasyGL #
fmt::fmt glfw)
target_link_libraries(
visual_odometry_example
PRIVATE DO::Kalpana::EasyGL #
fmt::fmt #
glfw)

# Bundle adjustment.
sara_add_example(two_view_bundle_adjustment_example)
Expand Down
79 changes: 70 additions & 9 deletions cpp/examples/Sara/MultiViewGeometry/visual_odometry_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <DO/Kalpana/Math/Projection.hpp>
#include <DO/Kalpana/Math/Viewport.hpp>

#include <DO/Sara/Logging/Logger.hpp>
#include <DO/Sara/SfM/Odometry/OdometryPipeline.hpp>

#if defined(_WIN32)
Expand Down Expand Up @@ -71,6 +72,7 @@ class SingleWindowApp
glfwSetWindowUserPointer(_window, this);
// Register callbacks.
glfwSetWindowSizeCallback(_window, window_size_callback);
glfwSetKeyCallback(_window, key_callback);
}

~SingleWindowApp()
Expand Down Expand Up @@ -114,12 +116,24 @@ class SingleWindowApp
glfwSwapInterval(1);
while (!glfwWindowShouldClose(_window))
{
if (!_pipeline.read())
break;
if (!_pause)
{
if (!_pipeline.read())
break;

_pipeline.process();
// Load data to OpenGL.
upload_point_cloud_data_to_opengl();
if (!_pipeline._video_streamer.skip())
{
_pipeline.process();

// Load data to OpenGL.
//
// TODO: upload only if we have a new image frame to process and only
// if the absolute pose estimation is successful.
upload_point_cloud_data_to_opengl();

_pause = true;
}
}

// Clear the color buffer and the buffer testing.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Expand Down Expand Up @@ -170,8 +184,24 @@ class SingleWindowApp

auto upload_point_cloud_data_to_opengl() -> void
{
_point_cloud.upload_host_data_to_gl(
_pipeline._triangulator->_colored_point_cloud);
const auto& point_cloud = _pipeline.point_cloud();

static constexpr auto dim = 6;
const auto num_points = static_cast<int>(point_cloud.size());
if (num_points == 0)
return;

const auto ptr =
const_cast<sara::PointCloudGenerator::ScenePoint*>(point_cloud.data());
const auto ptrd = reinterpret_cast<double*>(ptr);
const auto pc_tview = sara::TensorView_<double, 2>{
ptrd, //
{num_points, dim} //
};

auto& logger = sara::Logger::get();
SARA_LOGI(logger, "point cloud dimensions: {} ", pc_tview.sizes());
_point_cloud.upload_host_data_to_gl(pc_tview.cast<float>());
}

auto render_video() -> void
Expand Down Expand Up @@ -257,6 +287,22 @@ class SingleWindowApp
self._point_cloud_projection = self._point_cloud_viewport.perspective();
}

static auto key_callback(GLFWwindow* window, //
int key, //
int /* scancode */, //
int action, //
int /* mods */) -> void
{
auto& app = get_self(window);
if (app._pause && key == GLFW_KEY_SPACE &&
(action == GLFW_RELEASE || action == GLFW_REPEAT))
{
app._pause = false;
std::cout << "RESUME" << std::endl;
return;
}
}

private:
static auto init_glfw() -> void
{
Expand Down Expand Up @@ -328,19 +374,33 @@ class SingleWindowApp
Eigen::Matrix4f _point_cloud_projection;
// kgl::Camera _point_cloud_camera;
float _point_size = 5.f;

//! @brief User interaction.
bool _pause = false;
};

bool SingleWindowApp::_glfw_initialized = false;


auto main(int const argc, char** const argv) -> int
auto main([[maybe_unused]] int const argc, [[maybe_unused]] char** const argv)
-> int
{
#if defined(_OPENMP)
const auto num_threads = omp_get_max_threads();
omp_set_num_threads(num_threads);
Eigen::setNbThreads(num_threads);
#endif

#define USE_HARDCODED_VIDEO_PATH
#if defined(USE_HARDCODED_VIDEO_PATH) && defined(__APPLE__)
const auto video_path =
fs::path{"/Users/oddkiva/Desktop/datasets/sample-1.mp4"};
if (!fs::exists(video_path))
{
fmt::print("Video {} does not exist", video_path.string());
return EXIT_FAILURE;
}
#else
if (argc < 2)
{
std::cout << fmt::format("Usage: {} VIDEO_PATH\n",
Expand All @@ -349,6 +409,7 @@ auto main(int const argc, char** const argv) -> int
}

const auto video_path = fs::path{argv[1]};
#endif
auto camera = sara::v2::BrownConradyDistortionModel<double>{};
{
camera.fx() = 917.2878392016245;
Expand All @@ -359,7 +420,7 @@ auto main(int const argc, char** const argv) -> int
// clang-format off
camera.k() <<
-0.2338367557617234,
0.05952465745165465,
+0.05952465745165465,
-0.007947847982157091;
// clang-format on
camera.p() << -0.0003137658969742134, 0.00021943576376532096;
Expand Down
Loading

0 comments on commit 39b3149

Please sign in to comment.