From f9eac64dc9ba14a9acbde2226c8f65eb22e314fe Mon Sep 17 00:00:00 2001 From: yuckinus <40965122+yuckinus@users.noreply.github.com> Date: Sat, 22 Nov 2025 01:15:55 +0200 Subject: [PATCH] Updates - updated submodules: ImGUI, ImGuizmo, ImPlot - updated apps accordingly (fixed issues with keyboard handling under freeGLUT, fixed ImGuizmo usage) - step1 / stop closing app when data load canceled - step3 / fixed bug with Gizmo all sessions not working - all / added basic docking support --- 3rdparty/ImGuizmo | 2 +- 3rdparty/imgui | 2 +- 3rdparty/implot | 2 +- .../mandeye_compare_trajectories.cpp | 1 + apps/hd_mapper/hd_mapper.cpp | 1 + .../lidar_odometry_gui.cpp | 74 +++----- .../livox_mid_360_intrinsic_calibration.cpp | 1 + .../mandeye_mission_recorder_calibration.cpp | 17 +- .../mandeye_raw_data_viewer.cpp | 1 + .../mandeye_single_session_viewer.cpp | 93 +++++----- apps/manual_color/manual_color.cpp | 30 ++-- .../multi_session_registration.cpp | 117 ++++++++----- .../multi_view_tls_registration_gui.cpp | 160 +++++++++++------- .../precision_forestry_tools.cpp | 1 + .../single_session_manual_coloring.cpp | 1 + core/include/utils.hpp | 4 +- core/src/utils.cpp | 160 +++++++++++------- 17 files changed, 384 insertions(+), 283 deletions(-) diff --git a/3rdparty/ImGuizmo b/3rdparty/ImGuizmo index ef5b3c0d..71f14292 160000 --- a/3rdparty/ImGuizmo +++ b/3rdparty/ImGuizmo @@ -1 +1 @@ -Subproject commit ef5b3c0db73548427eb4af2f58e057989f11a27b +Subproject commit 71f14292205c3317122b39627ed98efce137086a diff --git a/3rdparty/imgui b/3rdparty/imgui index 55d35d83..3912b3d9 160000 --- a/3rdparty/imgui +++ b/3rdparty/imgui @@ -1 +1 @@ -Subproject commit 55d35d8387c15bf0cfd71861df67af8cfbda7456 +Subproject commit 3912b3d9a9c1b3f17431aebafd86d2f40ee6e59c diff --git a/3rdparty/implot b/3rdparty/implot index 18c72431..285df953 160000 --- a/3rdparty/implot +++ b/3rdparty/implot @@ -1 +1 @@ -Subproject commit 18c72431f8265e2b0b5378a3a73d8a883b2175ff +Subproject commit 285df95318a4af7c2fe2da265572bdf1020ade49 diff --git a/apps/compare_trajectories/mandeye_compare_trajectories.cpp b/apps/compare_trajectories/mandeye_compare_trajectories.cpp index b028ae57..588f219e 100644 --- a/apps/compare_trajectories/mandeye_compare_trajectories.cpp +++ b/apps/compare_trajectories/mandeye_compare_trajectories.cpp @@ -891,6 +891,7 @@ void display() ImGui_ImplOpenGL2_NewFrame(); ImGui_ImplGLUT_NewFrame(); + ImGui::NewFrame(); ImGuizmo::BeginFrame(); ImGuizmo::Enable(true); diff --git a/apps/hd_mapper/hd_mapper.cpp b/apps/hd_mapper/hd_mapper.cpp index db1b300e..3a4eb36b 100644 --- a/apps/hd_mapper/hd_mapper.cpp +++ b/apps/hd_mapper/hd_mapper.cpp @@ -151,6 +151,7 @@ void display() { ImGui_ImplOpenGL2_NewFrame(); ImGui_ImplGLUT_NewFrame(); + ImGui::NewFrame(); //my_display_code(); project_setings.imgui(odo_with_gnss_fusion, laz_wrapper.sectors, roi_exporter.rois_with_constraints, common_data); diff --git a/apps/lidar_odometry_step_1/lidar_odometry_gui.cpp b/apps/lidar_odometry_step_1/lidar_odometry_gui.cpp index 2a86df21..e6cfdf43 100644 --- a/apps/lidar_odometry_step_1/lidar_odometry_gui.cpp +++ b/apps/lidar_odometry_step_1/lidar_odometry_gui.cpp @@ -604,35 +604,19 @@ void step1(const std::atomic &loPause) if (fs::exists(input_folder_name)) { - if (!input_folder_name.empty()) - { - std::string newTitle = winTitle + " - ..\\" + std::filesystem::path(input_folder_name).filename().string(); - glutSetWindowTitle(newTitle.c_str()); - - for (const auto &entry : fs::directory_iterator(input_folder_name)) - if (entry.is_regular_file()) - input_file_names.push_back(entry.path().string()); + std::string newTitle = winTitle + " - ..\\" + std::filesystem::path(input_folder_name).filename().string(); + glutSetWindowTitle(newTitle.c_str()); - if (load_data(input_file_names, params, pointsPerFile, imu_data, full_debug_messages)) - { - working_directory = fs::path(input_file_names[0]).parent_path().string(); - calculate_trajectory(trajectory, imu_data, params.fusionConventionNwu, params.fusionConventionEnu, params.fusionConventionNed, params.ahrs_gain, full_debug_messages, params.use_removie_imu_bias_from_first_stationary_scan); - compute_step_1(pointsPerFile, params, trajectory, worker_data, loPause); - step_1_done = true; - } - else - { - std::string message_info = "Problem with loading data from folder '" + input_folder_name + "' (Pease check if folder exists). Program will close once You click OK!!!"; - std::cout << message_info << std::endl; - [[maybe_unused]] - pfd::message message( - "Information", - message_info.c_str(), - pfd::choice::ok, pfd::icon::info); - message.result(); + for (const auto &entry : fs::directory_iterator(input_folder_name)) + if (entry.is_regular_file()) + input_file_names.push_back(entry.path().string()); - exit(1); - } + if (load_data(input_file_names, params, pointsPerFile, imu_data, full_debug_messages)) + { + working_directory = fs::path(input_file_names[0]).parent_path().string(); + calculate_trajectory(trajectory, imu_data, params.fusionConventionNwu, params.fusionConventionEnu, params.fusionConventionNed, params.ahrs_gain, full_debug_messages, params.use_removie_imu_bias_from_first_stationary_scan); + compute_step_1(pointsPerFile, params, trajectory, worker_data, loPause); + step_1_done = true; } else { @@ -648,19 +632,6 @@ void step1(const std::atomic &loPause) exit(1); } } - else - { - std::string message_info = "Problem with loading data from folder '" + input_folder_name + "' Pease check if folder name is composed of ASCII symbols, if not --> please change folder name. Program will close once You click OK!!!"; - std::cout << message_info << std::endl; - [[maybe_unused]] - pfd::message message( - "Information", - message_info.c_str(), - pfd::choice::ok, pfd::icon::info); - message.result(); - - exit(1); - } } void step2(const std::atomic &loPause) @@ -1656,14 +1627,9 @@ void save_results(bool info, double elapsed_seconds, std::string &working_direct void display() { - ImGuiIO &io = ImGui::GetIO(); - - view_kbd_shortcuts(); - - if (io.KeyCtrl && ImGui::IsKeyPressed('O', false)) - openData(); - updateCameraTransition(); + + ImGuiIO &io = ImGui::GetIO(); glViewport(0, 0, (GLsizei)io.DisplaySize.x, (GLsizei)io.DisplaySize.y); glMatrixMode(GL_PROJECTION); @@ -1879,6 +1845,20 @@ void display() ImGui_ImplOpenGL2_NewFrame(); ImGui_ImplGLUT_NewFrame(); + ImGui::NewFrame(); + + ShowMainDockSpace(); + + view_kbd_shortcuts(); + + if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_O, false)) + { + openData(); + + //workaround + io.AddKeyEvent(ImGuiKey_O, false); + io.AddKeyEvent(ImGuiMod_Ctrl, false); + } if (!loRunning) { diff --git a/apps/livox_mid_360_intrinsic_calibration/livox_mid_360_intrinsic_calibration.cpp b/apps/livox_mid_360_intrinsic_calibration/livox_mid_360_intrinsic_calibration.cpp index e9e90d35..22cb3443 100644 --- a/apps/livox_mid_360_intrinsic_calibration/livox_mid_360_intrinsic_calibration.cpp +++ b/apps/livox_mid_360_intrinsic_calibration/livox_mid_360_intrinsic_calibration.cpp @@ -1238,6 +1238,7 @@ void display() #endif ImGui_ImplOpenGL2_NewFrame(); ImGui_ImplGLUT_NewFrame(); + ImGui::NewFrame(); project_gui(); diff --git a/apps/mandeye_mission_recorder_calibration/mandeye_mission_recorder_calibration.cpp b/apps/mandeye_mission_recorder_calibration/mandeye_mission_recorder_calibration.cpp index 53e6e047..59d34d1d 100644 --- a/apps/mandeye_mission_recorder_calibration/mandeye_mission_recorder_calibration.cpp +++ b/apps/mandeye_mission_recorder_calibration/mandeye_mission_recorder_calibration.cpp @@ -626,15 +626,10 @@ void project_gui() void display() { - ImGuiIO &io = ImGui::GetIO(); - - view_kbd_shortcuts(); - - if (ImGui::IsKeyPressed('G', false)) - show_grid = !show_grid; - updateCameraTransition(); + ImGuiIO& io = ImGui::GetIO(); + glViewport(0, 0, (GLsizei)io.DisplaySize.x, (GLsizei)io.DisplaySize.y); glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -814,6 +809,14 @@ void display() ImGui_ImplOpenGL2_NewFrame(); ImGui_ImplGLUT_NewFrame(); + ImGui::NewFrame(); + + ShowMainDockSpace(); + + view_kbd_shortcuts(); + + if (ImGui::IsKeyPressed(ImGuiKey_G, false)) + show_grid = !show_grid; if (ImGui::BeginMainMenuBar()) { diff --git a/apps/mandeye_raw_data_viewer/mandeye_raw_data_viewer.cpp b/apps/mandeye_raw_data_viewer/mandeye_raw_data_viewer.cpp index 422f2741..9f4e7e39 100644 --- a/apps/mandeye_raw_data_viewer/mandeye_raw_data_viewer.cpp +++ b/apps/mandeye_raw_data_viewer/mandeye_raw_data_viewer.cpp @@ -1217,6 +1217,7 @@ void display() ImGui_ImplOpenGL2_NewFrame(); ImGui_ImplGLUT_NewFrame(); + ImGui::NewFrame(); project_gui(); diff --git a/apps/mandeye_single_session_viewer/mandeye_single_session_viewer.cpp b/apps/mandeye_single_session_viewer/mandeye_single_session_viewer.cpp index 5d5d4a7c..c9217243 100644 --- a/apps/mandeye_single_session_viewer/mandeye_single_session_viewer.cpp +++ b/apps/mandeye_single_session_viewer/mandeye_single_session_viewer.cpp @@ -762,8 +762,6 @@ void openSession() void display() { - ImGuiIO& io = ImGui::GetIO(); - glClearColor(bg_color.x * bg_color.w, bg_color.y * bg_color.w, bg_color.z * bg_color.w, bg_color.w); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); @@ -775,45 +773,10 @@ void display() gl_renderPointCloud(); } - - view_kbd_shortcuts(); - - if (io.KeyCtrl && ImGui::IsKeyPressed('O', false)) - openSession(); - - if (session.point_clouds_container.point_clouds.size() > 0) - { - if (io.KeyCtrl && ImGui::IsKeyPressed('N')) - show_neighbouring_scans = !show_neighbouring_scans; - if (ImGui::IsKeyPressed(ImGuiKey_UpArrow, true)) - offset_intensity += 0.01; - if (ImGui::IsKeyPressed(ImGuiKey_DownArrow, true)) - offset_intensity -= 0.01; - - if (offset_intensity < 0) - offset_intensity = 0; - else if (offset_intensity > 1) - offset_intensity = 1; - - if ((!io.KeyCtrl && !io.KeyShift && ImGui::IsKeyPressed(ImGuiKey_RightArrow, true)) - || ImGui::IsKeyPressed(ImGuiKey_PageUp, true) - || ImGui::IsKeyPressed('+', true) - ) - index_rendered_points_local += 1; - if ((!io.KeyCtrl && !io.KeyShift && ImGui::IsKeyPressed(ImGuiKey_LeftArrow, true)) - || ImGui::IsKeyPressed(ImGuiKey_PageDown, true) - || ImGui::IsKeyPressed('-', true) - ) - index_rendered_points_local -= 1; - - if (index_rendered_points_local < 0) - index_rendered_points_local = 0; - if (index_rendered_points_local >= session.point_clouds_container.point_clouds.size()) - index_rendered_points_local = session.point_clouds_container.point_clouds.size() - 1; - } - updateCameraTransition(); + ImGuiIO& io = ImGui::GetIO(); + glViewport(0, 0, (GLsizei)io.DisplaySize.x, (GLsizei)io.DisplaySize.y); glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -955,6 +918,58 @@ void display() ImGui_ImplOpenGL2_NewFrame(); ImGui_ImplGLUT_NewFrame(); + ImGui::NewFrame(); + + ShowMainDockSpace(); + + view_kbd_shortcuts(); + + if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_O, false)) + { + openSession(); + + //workaround + io.AddKeyEvent(ImGuiKey_O, false); + io.AddKeyEvent(ImGuiMod_Ctrl, false); + } + + if (session.point_clouds_container.point_clouds.size() > 0) + { + if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_N, false)) + { + show_neighbouring_scans = !show_neighbouring_scans; + + //workaround + io.AddKeyEvent(ImGuiKey_N, false); + io.AddKeyEvent(ImGuiMod_Ctrl, false); + } + + if (ImGui::IsKeyPressed(ImGuiKey_UpArrow, true)) + offset_intensity += 0.01; + if (ImGui::IsKeyPressed(ImGuiKey_DownArrow, true)) + offset_intensity -= 0.01; + + if (offset_intensity < 0) + offset_intensity = 0; + else if (offset_intensity > 1) + offset_intensity = 1; + + if ((!io.KeyCtrl && !io.KeyShift && ImGui::IsKeyPressed(ImGuiKey_RightArrow, true)) + || ImGui::IsKeyPressed(ImGuiKey_PageUp, true) + || ImGui::IsKeyPressed(ImGuiKey_KeypadAdd, true) + ) + index_rendered_points_local += 1; + if ((!io.KeyCtrl && !io.KeyShift && ImGui::IsKeyPressed(ImGuiKey_LeftArrow, true)) + || ImGui::IsKeyPressed(ImGuiKey_PageDown, true) + || ImGui::IsKeyPressed(ImGuiKey_KeypadSubtract, true) + ) + index_rendered_points_local -= 1; + + if (index_rendered_points_local < 0) + index_rendered_points_local = 0; + if (index_rendered_points_local >= session.point_clouds_container.point_clouds.size()) + index_rendered_points_local = session.point_clouds_container.point_clouds.size() - 1; + } if (ImGui::BeginMainMenuBar()) { diff --git a/apps/manual_color/manual_color.cpp b/apps/manual_color/manual_color.cpp index 1dc3e5ba..54787eba 100644 --- a/apps/manual_color/manual_color.cpp +++ b/apps/manual_color/manual_color.cpp @@ -170,31 +170,24 @@ void imagePicker(const std::string &name, ImTextureID tex1, std::vector float speed = io.KeyShift ? 10.f : 1.f; int transX = 0; int transY = 0; - if (io.KeysDown[io.KeyMap[ImGuiKey_UpArrow]]) - { + + if (ImGui::IsKeyDown(ImGuiKey_UpArrow)) transY = -10 * speed; - } - if (io.KeysDown[io.KeyMap[ImGuiKey_DownArrow]]) - { + + if (ImGui::IsKeyDown(ImGuiKey_DownArrow)) transY = 10 * speed; - } - if (io.KeysDown[io.KeyMap[ImGuiKey_LeftArrow]]) - { + + if (ImGui::IsKeyDown(ImGuiKey_LeftArrow)) transX = -10 * speed; - } - if (io.KeysDown[io.KeyMap[ImGuiKey_RightArrow]]) - { + + if (ImGui::IsKeyDown(ImGuiKey_RightArrow)) transX = 10 * speed; - } - if (io.KeysDown[io.KeyMap[ImGuiKey_PageUp]]) - { + + if (ImGui::IsKeyDown(ImGuiKey_PageUp)) zoom *= 1.0f + 0.01f * speed; - } - if (io.KeysDown[io.KeyMap[ImGuiKey_PageDown]]) - { + if (ImGui::IsKeyDown(ImGuiKey_PageDown)) zoom /= 1.00f + 0.01f * speed; - } ImVec2 uv_min = ImVec2(0.0f, 0.0f); // Top-left ImVec2 uv_max = ImVec2(1.0f, 1.0f); // Lower-right @@ -934,6 +927,7 @@ void display() } ImGui_ImplOpenGL2_NewFrame(); ImGui_ImplGLUT_NewFrame(); + ImGui::NewFrame(); std::vector picked3DPoints(SystemData::pointPickedPointCloud.size()); std::transform(SystemData::pointPickedPointCloud.begin(), SystemData::pointPickedPointCloud.end(), picked3DPoints.begin(), UnprojectPoint); diff --git a/apps/multi_session_registration/multi_session_registration.cpp b/apps/multi_session_registration/multi_session_registration.cpp index 47aa577e..0e1a6986 100644 --- a/apps/multi_session_registration/multi_session_registration.cpp +++ b/apps/multi_session_registration/multi_session_registration.cpp @@ -177,6 +177,8 @@ bool remove_gui = false; NDT ndt; int number_visible_sessions = 0; +int index_gizmo = -1; +int old_index_gizmo = -1; double time_stamp_offset = 0.0; @@ -2773,8 +2775,6 @@ void project_gui() ImGui::Text("Session file names:"); - int index_gizmo = -1; - for (int i = 0; i < project_settings.session_file_names.size(); i++) { ImGui::Text(truncPath(project_settings.session_file_names[i]).c_str()); @@ -2791,17 +2791,12 @@ void project_gui() ImGui::BeginDisabled(sessions[i].is_ground_truth); { ImGui::SameLine(); - if (ImGui::Checkbox(("Gizmo##" + std::to_string(i)).c_str(), &sessions[i].is_gizmo)) + if (ImGui::RadioButton(("Gizmo##" + std::to_string(i)).c_str(), &index_gizmo, i)) { - if (sessions[i].is_gizmo) - { - for (int ii = 0; ii < sessions.size(); ii++) - if (i != ii) - sessions[ii].is_gizmo = false; - index_gizmo = i; - } + if (old_index_gizmo == i) + index_gizmo = -1; // unselect else - index_gizmo = -1; + index_gizmo = i; } } ImGui::EndDisabled(); @@ -2858,10 +2853,17 @@ void project_gui() // } } + if (project_settings.session_file_names.size() == sessions.size()) { - // for (int i = 0; i < sessions.size(); i++) - // sessions[i].is_gizmo = false; + if (old_index_gizmo != index_gizmo) + { + for (int i = 0; i < sessions.size(); i++) + sessions[i].is_gizmo = (i == index_gizmo); + + old_index_gizmo = index_gizmo; + } + if (index_gizmo != -1 && index_gizmo < sessions.size()) { // sessions[index_gizmo].is_gizmo = true; @@ -2965,28 +2967,10 @@ void project_gui() void display() { - ImGuiIO &io = ImGui::GetIO(); - - view_kbd_shortcuts(); - - if (io.KeyCtrl && ImGui::IsKeyPressed('A', false)) - addSession(); - if ((project_settings.session_file_names.size() > 0) && !loaded_sessions) - if (io.KeyCtrl && ImGui::IsKeyPressed('L', false)) - loadSessions(); - if (io.KeyCtrl && ImGui::IsKeyPressed('O', false)) - openProject(); - - if (project_settings.session_file_names.size() > 0) - if (io.KeyCtrl && ImGui::IsKeyPressed('R', false)) - remove_gui = true; - - if (sessions.size() > 0) - if (io.KeyCtrl && ImGui::IsKeyPressed('S', false)) - saveProject(); - updateCameraTransition(); + ImGuiIO& io = ImGui::GetIO(); + glViewport(0, 0, (GLsizei)io.DisplaySize.x, (GLsizei)io.DisplaySize.y); glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -3343,6 +3327,57 @@ void display() ImGui_ImplOpenGL2_NewFrame(); ImGui_ImplGLUT_NewFrame(); + ImGui::NewFrame(); + + ShowMainDockSpace(); + + view_kbd_shortcuts(); + + if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_A, false)) + { + addSession(); + + //workaround + io.AddKeyEvent(ImGuiKey_A, false); + io.AddKeyEvent(ImGuiMod_Ctrl, false); + } + if ((project_settings.session_file_names.size() > 0) && !loaded_sessions) + if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_L, false)) + { + loadSessions(); + + //workaround + io.AddKeyEvent(ImGuiKey_L, false); + io.AddKeyEvent(ImGuiMod_Ctrl, false); + } + if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_O, false)) + { + openProject(); + + //workaround + io.AddKeyEvent(ImGuiKey_O, false); + io.AddKeyEvent(ImGuiMod_Ctrl, false); + } + + if (project_settings.session_file_names.size() > 0) + if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_R, false)) + { + remove_gui = true; + + //workaround + io.AddKeyEvent(ImGuiKey_R, false); + io.AddKeyEvent(ImGuiMod_Ctrl, false); + } + + if (sessions.size() > 0) + if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_S, false)) + { + saveProject(); + + //workaround + io.AddKeyEvent(ImGuiKey_S, false); + io.AddKeyEvent(ImGuiMod_Ctrl, false); + } if (ImGui::BeginMainMenuBar()) { @@ -4034,7 +4069,7 @@ void display() for (size_t i = 0; i < sessions.size(); i++) { - // gizmo_all_sessions; + // guizmo_all_sessions; if (sessions[i].is_gizmo && !sessions[i].is_ground_truth) { if (sessions[i].point_clouds_container.point_clouds.size() > 0) @@ -4042,9 +4077,7 @@ void display() prev_pose_manipulated = sessions[i].point_clouds_container.point_clouds[0].m_pose; std::vector all_m_poses; for (int j = 0; j < sessions[i].point_clouds_container.point_clouds.size(); j++) - { all_m_poses.push_back(sessions[i].point_clouds_container.point_clouds[j].m_pose); - } // if (all_m_poses.size() > 1) //{ @@ -4081,8 +4114,6 @@ void display() sessions[i].point_clouds_container.point_clouds[0].gui_rotation[1] = (float)(sessions[i].point_clouds_container.point_clouds[0].pose.fi * RAD_TO_DEG); sessions[i].point_clouds_container.point_clouds[0].gui_rotation[2] = (float)(sessions[i].point_clouds_container.point_clouds[0].pose.ka * RAD_TO_DEG); - ImGui::End(); - Eigen::Affine3d curr_m_pose = sessions[i].point_clouds_container.point_clouds[0].m_pose; for (int j = 1; j < sessions[i].point_clouds_container.point_clouds.size(); j++) { @@ -4106,7 +4137,7 @@ void display() { for (size_t i = 0; i < sessions.size(); i++) { - // gizmo_all_sessions; + // guizmo_all_sessions; if (!sessions[i].is_gizmo && !sessions[i].is_ground_truth) { std::vector all_m_poses; @@ -4167,9 +4198,7 @@ void display() ImGuizmo::Manipulate(&modelview[0], &projection[0], ImGuizmo::TRANSLATE | ImGuizmo::ROTATE_Z | ImGuizmo::ROTATE_X | ImGuizmo::ROTATE_Y, ImGuizmo::WORLD, m_gizmo, NULL); } else - { ImGuizmo::Manipulate(m_ortho_gizmo_view, m_ortho_projection, ImGuizmo::TRANSLATE_X | ImGuizmo::TRANSLATE_Y | ImGuizmo::ROTATE_Z, ImGuizmo::WORLD, m_gizmo, NULL); - } Eigen::Affine3d m_g = Eigen::Affine3d::Identity(); @@ -4179,8 +4208,6 @@ void display() const Eigen::Affine3d &m_src = sessions[edges[index_active_edge].index_session_from].point_clouds_container.point_clouds.at(index_src).m_pose; edges[index_active_edge].relative_pose_tb = pose_tait_bryan_from_affine_matrix(m_src.inverse() * m_g); - - ImGui::End(); } } @@ -4249,8 +4276,6 @@ void display() session.point_clouds_container.point_clouds[i].gui_rotation[1] = (float)(session.point_clouds_container.point_clouds[i].pose.fi * RAD_TO_DEG); session.point_clouds_container.point_clouds[i].gui_rotation[2] = (float)(session.point_clouds_container.point_clouds[i].pose.ka * RAD_TO_DEG); - ImGui::End(); - if (!manipulate_only_marked_gizmo) { Eigen::Affine3d curr_m_pose = session.point_clouds_container.point_clouds[i].m_pose; @@ -4391,8 +4416,6 @@ void display() const Eigen::Affine3d &m_src = session.point_clouds_container.point_clouds.at(index_src).m_pose; session.manual_pose_graph_loop_closure.edges[session.manual_pose_graph_loop_closure.index_active_edge].relative_pose_tb = pose_tait_bryan_from_affine_matrix(m_src.inverse() * m_g); - - ImGui::End(); } }*/ diff --git a/apps/multi_view_tls_registration/multi_view_tls_registration_gui.cpp b/apps/multi_view_tls_registration/multi_view_tls_registration_gui.cpp index afd81bdc..bb7e5199 100644 --- a/apps/multi_view_tls_registration/multi_view_tls_registration_gui.cpp +++ b/apps/multi_view_tls_registration/multi_view_tls_registration_gui.cpp @@ -1952,66 +1952,10 @@ void project_gui() void display() { - ImGuiIO& io = ImGui::GetIO(); - - view_kbd_shortcuts(); - - if (io.KeyCtrl && ImGui::IsKeyPressed('A')) - is_pca_gui = !is_pca_gui; - if (io.KeyCtrl && ImGui::IsKeyPressed('C')) - { - if (session.control_points.is_imgui) - session.control_points.is_imgui = false; - else if (!session.ground_control_points.is_imgui) - session.control_points.is_imgui = true; - } - if (io.KeyCtrl && ImGui::IsKeyPressed('E')) - { - if (is_lio_segments_gui) - is_lio_segments_gui = false; - else if (!is_loop_closure_gui) - is_lio_segments_gui = true; - } - - if (io.KeyCtrl && ImGui::IsKeyPressed('G')) - { - if (session.ground_control_points.is_imgui) - session.ground_control_points.is_imgui = false; - else if (!session.control_points.is_imgui) - session.ground_control_points.is_imgui = true; - } - - if (io.KeyCtrl && ImGui::IsKeyPressed('L')) - { - if (is_loop_closure_gui) - is_loop_closure_gui = false; - else if (!is_lio_segments_gui) - is_loop_closure_gui = true; - } - - if (io.KeyCtrl && ImGui::IsKeyPressed('O', false)) - openSession(); - if (io.KeyCtrl && ImGui::IsKeyPressed('P')) - is_pose_graph_slam = !is_pose_graph_slam; - - if (io.KeyCtrl && ImGui::IsKeyPressed('R')) //random colors - { - for (auto& pc : session.point_clouds_container.point_clouds) - { - pc.render_color[0] = float(rand() % 255) / 255.0f; - pc.render_color[1] = float(rand() % 255) / 255.0f; - pc.render_color[2] = float(rand() % 255) / 255.0f; - pc.show_color = false; - } - } - - if (io.KeyCtrl && ImGui::IsKeyPressed('S', false)) - saveSession(); - if (io.KeyCtrl && io.KeyShift && ImGui::IsKeyPressed('S', false)) - saveSubsession(); - updateCameraTransition(); + ImGuiIO& io = ImGui::GetIO(); + glViewport(0, 0, (GLsizei)io.DisplaySize.x, (GLsizei)io.DisplaySize.y); glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -2147,6 +2091,102 @@ void display() ImGui_ImplOpenGL2_NewFrame(); ImGui_ImplGLUT_NewFrame(); + ImGui::NewFrame(); + + ShowMainDockSpace(); + + view_kbd_shortcuts(); + + if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_A, false)) + { + is_pca_gui = !is_pca_gui; + + //workaround + io.AddKeyEvent(ImGuiKey_A, false); + io.AddKeyEvent(ImGuiMod_Ctrl, false); + } + + if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_C, false)) + { + session.control_points.is_imgui = !session.control_points.is_imgui; + + //workaround + io.AddKeyEvent(ImGuiKey_C, false); + io.AddKeyEvent(ImGuiMod_Ctrl, false); + } + + if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_E, false)) + { + is_lio_segments_gui = !is_lio_segments_gui; + + //workaround + io.AddKeyEvent(ImGuiKey_E, false); + io.AddKeyEvent(ImGuiMod_Ctrl, false); + } + + if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_G, false)) + { + session.ground_control_points.is_imgui = !session.ground_control_points.is_imgui; + + //workaround + io.AddKeyEvent(ImGuiKey_G, false); + io.AddKeyEvent(ImGuiMod_Ctrl, false); + } + + if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_L, false)) + { + is_loop_closure_gui = !is_loop_closure_gui; + + //workaround + io.AddKeyEvent(ImGuiKey_L, false); + io.AddKeyEvent(ImGuiMod_Ctrl, false); + } + + if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_O, false)) + { + openSession(); + + //workaround + io.AddKeyEvent(ImGuiKey_O, false); + io.AddKeyEvent(ImGuiMod_Ctrl, false); + } + + + if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_P, false)) + { + is_pose_graph_slam = !is_pose_graph_slam; + + //workaround + io.AddKeyEvent(ImGuiKey_P, false); + io.AddKeyEvent(ImGuiMod_Ctrl, false); + } + + if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_R)) //random colors + { + for (auto& pc : session.point_clouds_container.point_clouds) + { + pc.render_color[0] = float(rand() % 255) / 255.0f; + pc.render_color[1] = float(rand() % 255) / 255.0f; + pc.render_color[2] = float(rand() % 255) / 255.0f; + pc.show_color = false; + } + + //workaround + io.AddKeyEvent(ImGuiKey_R, false); + io.AddKeyEvent(ImGuiMod_Ctrl, false); + } + + if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_S, false)) + { + if (io.KeyShift) + saveSubsession(); + else + saveSession(); + + //workaround + io.AddKeyEvent(ImGuiKey_S, false); + io.AddKeyEvent(ImGuiMod_Ctrl, false); + } if (ImGui::BeginMainMenuBar()) { @@ -2958,8 +2998,6 @@ void display() session.point_clouds_container.point_clouds[i].gui_rotation[1] = (float)(session.point_clouds_container.point_clouds[i].pose.fi * RAD_TO_DEG); session.point_clouds_container.point_clouds[i].gui_rotation[2] = (float)(session.point_clouds_container.point_clouds[i].pose.ka * RAD_TO_DEG); - ImGui::End(); - if (!manipulate_only_marked_gizmo) { Eigen::Affine3d curr_m_pose = session.point_clouds_container.point_clouds[i].m_pose; @@ -3106,8 +3144,6 @@ void display() const Eigen::Affine3d &m_src = session.point_clouds_container.point_clouds.at(index_src).m_pose; session.pose_graph_loop_closure.edges[session.pose_graph_loop_closure.index_active_edge].relative_pose_tb = pose_tait_bryan_from_affine_matrix(m_src.inverse() * m_g); - - ImGui::End(); } } } diff --git a/apps/precision_forestry_tools/precision_forestry_tools.cpp b/apps/precision_forestry_tools/precision_forestry_tools.cpp index 3553ec87..3c92eca7 100644 --- a/apps/precision_forestry_tools/precision_forestry_tools.cpp +++ b/apps/precision_forestry_tools/precision_forestry_tools.cpp @@ -550,6 +550,7 @@ void display() ImGui_ImplOpenGL2_NewFrame(); ImGui_ImplGLUT_NewFrame(); + ImGui::NewFrame(); project_gui(); diff --git a/apps/single_session_manual_coloring/single_session_manual_coloring.cpp b/apps/single_session_manual_coloring/single_session_manual_coloring.cpp index 6f030e06..42ed5e3d 100644 --- a/apps/single_session_manual_coloring/single_session_manual_coloring.cpp +++ b/apps/single_session_manual_coloring/single_session_manual_coloring.cpp @@ -923,6 +923,7 @@ void display() ImGui_ImplOpenGL2_NewFrame(); ImGui_ImplGLUT_NewFrame(); + ImGui::NewFrame(); project_gui(); diff --git a/core/include/utils.hpp b/core/include/utils.hpp index b86d46a3..e745441c 100644 --- a/core/include/utils.hpp +++ b/core/include/utils.hpp @@ -89,9 +89,7 @@ std::string truncPath(const std::string& fullPath); void wheel(int button, int dir, int x, int y); void reshape(int w, int h); -void motion(int x, int y); -void specialDown(int key, int x, int y); -void specialUp(int key, int x, int y); +void ShowMainDockSpace(); bool initGL(int* argc, char** argv, const std::string& winTitle, void (*display)(), void (*mouse)(int, int, int, int)); void showAxes(); diff --git a/core/src/utils.cpp b/core/src/utils.cpp index 13de5186..dd330fc8 100644 --- a/core/src/utils.cpp +++ b/core/src/utils.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -308,43 +308,83 @@ void motion(int x, int y) glutPostRedisplay(); } -//SpecialKeys handlers needed because of ImGui version <1.89 bug in handling keys -void specialDown(int key, int x, int y) -{ - ImGuiIO& io = ImGui::GetIO(); - switch (key) - { - case GLUT_KEY_UP: io.KeysDown[ImGuiKey_UpArrow] = true; break; - case GLUT_KEY_DOWN: io.KeysDown[ImGuiKey_DownArrow] = true; break; - case GLUT_KEY_LEFT: io.KeysDown[ImGuiKey_LeftArrow] = true; break; - case GLUT_KEY_RIGHT: io.KeysDown[ImGuiKey_RightArrow] = true; break; - case GLUT_KEY_PAGE_UP: io.KeysDown[ImGuiKey_PageUp] = true; break; - case GLUT_KEY_PAGE_DOWN: io.KeysDown[ImGuiKey_PageDown] = true; break; +ImGuiKey keyToImGuiKey(unsigned char key) { + if (key >= 'a' && key <= 'z') return ImGuiKey(ImGuiKey_A + (key - 'a')); + if (key >= 'A' && key <= 'Z') return ImGuiKey(ImGuiKey_A + (key - 'A')); + if (key >= '0' && key <= '9') return ImGuiKey(ImGuiKey_0 + (key - '0')); + switch (key) { + case 27: return ImGuiKey_Escape; + case 13: return ImGuiKey_Enter; + case 32: return ImGuiKey_Space; + default: return ImGuiKey_None; } +} + +void keyboardDown(unsigned char key, int x, int y) { + ImGuiIO& io = ImGui::GetIO(); int mods = glutGetModifiers(); - io.KeyCtrl = (mods & GLUT_ACTIVE_CTRL) != 0; - io.KeyShift = (mods & GLUT_ACTIVE_SHIFT) != 0; - io.KeyAlt = (mods & GLUT_ACTIVE_ALT) != 0; + // Update modifier keys using the new API + io.AddKeyEvent(ImGuiMod_Ctrl, (mods & GLUT_ACTIVE_CTRL) != 0); + io.AddKeyEvent(ImGuiMod_Shift, (mods & GLUT_ACTIVE_SHIFT) != 0); + io.AddKeyEvent(ImGuiMod_Alt, (mods & GLUT_ACTIVE_ALT) != 0); + + // Handle Ctrl+letter (ASCII 1-26) (FreeGLUT “lost key” problem) + if ( (mods & GLUT_ACTIVE_CTRL) && (key >= 1 && key <= 26) ) + key = 'A' + (key - 1); + + io.AddKeyEvent(keyToImGuiKey(key), true); + + //std::cout << "Down key: " << key << ", mod: " << mods << std::endl; } -void specialUp(int key, int x, int y) -{ +void keyboardUp(unsigned char key, int x, int y) { ImGuiIO& io = ImGui::GetIO(); - switch (key) - { - case GLUT_KEY_UP: io.KeysDown[ImGuiKey_UpArrow] = false; break; - case GLUT_KEY_DOWN: io.KeysDown[ImGuiKey_DownArrow] = false; break; - case GLUT_KEY_LEFT: io.KeysDown[ImGuiKey_LeftArrow] = false; break; - case GLUT_KEY_RIGHT: io.KeysDown[ImGuiKey_RightArrow] = false; break; - case GLUT_KEY_PAGE_UP: io.KeysDown[ImGuiKey_PageUp] = false; break; - case GLUT_KEY_PAGE_DOWN: io.KeysDown[ImGuiKey_PageDown] = false; break; - } int mods = glutGetModifiers(); - io.KeyCtrl = (mods & GLUT_ACTIVE_CTRL) != 0; - io.KeyShift = (mods & GLUT_ACTIVE_SHIFT) != 0; - io.KeyAlt = (mods & GLUT_ACTIVE_ALT) != 0; + // Update modifier keys using the new API + io.AddKeyEvent(ImGuiMod_Ctrl, (mods & GLUT_ACTIVE_CTRL) != 0); + io.AddKeyEvent(ImGuiMod_Shift, (mods & GLUT_ACTIVE_SHIFT) != 0); + io.AddKeyEvent(ImGuiMod_Alt, (mods & GLUT_ACTIVE_ALT) != 0); + + // Handle Ctrl+letter (ASCII 1-26) (FreeGLUT “lost key” problem) + if ((mods & GLUT_ACTIVE_CTRL) && (key >= 1 && key <= 26)) + key = 'A' + (key - 1); + + io.AddKeyEvent(keyToImGuiKey(key), false); + + //std::cout << "Up key: " << key << ", mod: " << mods << std::endl; +} + +void ShowMainDockSpace() +{ + ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDocking + | ImGuiWindowFlags_NoTitleBar + | ImGuiWindowFlags_NoCollapse + | ImGuiWindowFlags_NoResize + | ImGuiWindowFlags_NoMove + | ImGuiWindowFlags_NoBringToFrontOnFocus + | ImGuiWindowFlags_NoNavFocus + | ImGuiWindowFlags_NoBackground + | ImGuiWindowFlags_NoInputs; + + ImGuiViewport* viewport = ImGui::GetMainViewport(); + ImGui::SetNextWindowPos(viewport->WorkPos); + ImGui::SetNextWindowSize(viewport->WorkSize); + ImGui::SetNextWindowViewport(viewport->ID); + + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); + + ImGui::Begin("MainDockSpace", nullptr, window_flags); + + ImGui::PopStyleVar(2); + + // This is the dockspace! + ImGuiID dockspace_id = ImGui::GetID("MyDockSpace"); + ImGui::DockSpace(dockspace_id, ImVec2(0, 0), ImGuiDockNodeFlags_PassthruCentralNode); + + ImGui::End(); } bool initGL(int* argc, char** argv, const std::string& winTitle, void (*display)(), void (*mouse)(int, int, int, int)) @@ -378,22 +418,28 @@ bool initGL(int* argc, char** argv, const std::string& winTitle, void (*display) glLoadIdentity(); gluPerspective(60.0, (GLfloat)window_width / (GLfloat)window_height, 0.01, 10000.0); glutReshapeFunc(reshape); + ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; - // io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls + io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard // Enable Keyboard Controls + | ImGuiConfigFlags_NavEnableGamepad + | ImGuiConfigFlags_DockingEnable; ImGui::StyleColorsDark(); ImGui_ImplGLUT_Init(); - ImGui_ImplGLUT_InstallFuncs(); ImGui_ImplOpenGL2_Init(); + ImGui_ImplGLUT_InstallFuncs(); + glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); glutMouseWheelFunc(wheel); - glutSpecialFunc(specialDown); - glutSpecialUpFunc(specialUp); + glutKeyboardFunc(keyboardDown); + glutKeyboardUpFunc(keyboardUp); + //glutSpecialFunc(specialDown); + //glutSpecialUpFunc(specialUp); return (glGetError() == GL_NO_ERROR); } @@ -714,55 +760,55 @@ void view_kbd_shortcuts() breakCameraTransition(); } - if (io.KeyShift && ImGui::IsKeyPressed('Z', false) && !is_ortho) + if (io.KeyShift && ImGui::IsKeyPressed(ImGuiKey_Z, false) && !is_ortho) lock_z = !lock_z; //only checking for single key press (no modifiers) from this point - if (io.KeyCtrl || io.KeyShift) return; + if (io.KeyCtrl || io.KeyAlt || io.KeyShift) return; - if (ImGui::IsKeyPressed('B')) + if (ImGui::IsKeyPressed(ImGuiKey_B)) setCameraPreset(CAMERA_BACK); - if (ImGui::IsKeyPressed('F')) + if (ImGui::IsKeyPressed(ImGuiKey_F)) setCameraPreset(CAMERA_FRONT); - if (ImGui::IsKeyPressed('I')) + if (ImGui::IsKeyPressed(ImGuiKey_I)) setCameraPreset(CAMERA_ISO); - if (ImGui::IsKeyPressed('L')) + if (ImGui::IsKeyPressed(ImGuiKey_L)) setCameraPreset(CAMERA_LEFT); - if (ImGui::IsKeyPressed('R')) + if (ImGui::IsKeyPressed(ImGuiKey_R)) setCameraPreset(CAMERA_RIGHT); - if (ImGui::IsKeyPressed('T')) + if (ImGui::IsKeyPressed(ImGuiKey_T)) setCameraPreset(CAMERA_TOP); - if (ImGui::IsKeyPressed('U')) + if (ImGui::IsKeyPressed(ImGuiKey_U)) setCameraPreset(CAMERA_BOTTOM); - if (ImGui::IsKeyPressed('Z')) + if (ImGui::IsKeyPressed(ImGuiKey_Z)) setCameraPreset(CAMERA_RESET); - if (ImGui::IsKeyPressed('C'), false) + if (ImGui::IsKeyPressed(ImGuiKey_C, false)) compass_ruler = !compass_ruler; - if (ImGui::IsKeyPressed('O'), false) + if (ImGui::IsKeyPressed(ImGuiKey_O, false)) is_ortho = !is_ortho; - if (ImGui::IsKeyPressed('X'), false) + if (ImGui::IsKeyPressed(ImGuiKey_X, false)) show_axes = !show_axes; - if (ImGui::IsKeyPressed('1')) + if (ImGui::IsKeyPressed(ImGuiKey_1)) point_size = 1; - if (ImGui::IsKeyPressed('2')) + if (ImGui::IsKeyPressed(ImGuiKey_2)) point_size = 2; - if (ImGui::IsKeyPressed('3')) + if (ImGui::IsKeyPressed(ImGuiKey_3)) point_size = 3; - if (ImGui::IsKeyPressed('4')) + if (ImGui::IsKeyPressed(ImGuiKey_4)) point_size = 4; - if (ImGui::IsKeyPressed('5')) + if (ImGui::IsKeyPressed(ImGuiKey_5)) point_size = 5; - if (ImGui::IsKeyPressed('6')) + if (ImGui::IsKeyPressed(ImGuiKey_6)) point_size = 6; - if (ImGui::IsKeyPressed('7')) + if (ImGui::IsKeyPressed(ImGuiKey_7)) point_size = 7; - if (ImGui::IsKeyPressed('8')) + if (ImGui::IsKeyPressed(ImGuiKey_8)) point_size = 8; - if (ImGui::IsKeyPressed('9')) + if (ImGui::IsKeyPressed(ImGuiKey_9)) point_size = 9; } @@ -976,7 +1022,7 @@ void drawMiniCompassWithRuler( float miniAxisLength = 1.0f; - // Snap ruler length to a "nice" round number (1, 2, or 5 10^n) + // Snap ruler length to a "nice" round number (1, 2, or 5 × 10^n) float rawUnit = 0.1f * translate_z; // adjust factor to taste float base = pow(10.0f, floor(log10(rawUnit))); float normalized = rawUnit / base;