diff --git a/apps/lidar_odometry_step_1/lidar_odometry_gui.cpp b/apps/lidar_odometry_step_1/lidar_odometry_gui.cpp index c16052ff..141e4235 100644 --- a/apps/lidar_odometry_step_1/lidar_odometry_gui.cpp +++ b/apps/lidar_odometry_step_1/lidar_odometry_gui.cpp @@ -2311,6 +2311,20 @@ int main(int argc, char* argv[]) try { + if (checkClHelp(argc, argv)) + { + std::cout << winTitle << "\n\n" + << "USAGE:\n" + << std::filesystem::path(argv[0]).stem().string() << " /?\n\n" + << "where\n" + << " Path where scan files are located (*.csv, *.laz, *.sn)\n" + << " Path to TOML parameter file (*.toml)\n" + << " Path where processed session should be stored\n" + << " -h, /h, --help, /? Show this help and exit\n\n"; + + return 0; + } + if (argc == 4) // runnning from command line { // Load parameters from file using original TomlIO class 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 f44303af..418a99de 100644 --- a/apps/mandeye_mission_recorder_calibration/mandeye_mission_recorder_calibration.cpp +++ b/apps/mandeye_mission_recorder_calibration/mandeye_mission_recorder_calibration.cpp @@ -53,10 +53,6 @@ namespace fs = std::filesystem; ImVec4 pc_color = ImVec4(1.0f, 0.0f, 0.0f, 1.00f); ImVec4 pc_color2 = ImVec4(0.0f, 0.0f, 1.0f, 1.00f); -float m_ortho_projection[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; - -float m_ortho_gizmo_view[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; - std::vector laz_files; std::vector csv_files; std::vector sn_files; @@ -659,50 +655,7 @@ void display() glLoadMatrixf(viewLocal.matrix().data()); } else - { - glOrtho( - -camera_ortho_xy_view_zoom, - camera_ortho_xy_view_zoom, - -camera_ortho_xy_view_zoom / ratio, - camera_ortho_xy_view_zoom / ratio, - -100000, - 100000); - - glm::mat4 proj = glm::orthoLH_ZO( - -camera_ortho_xy_view_zoom, - camera_ortho_xy_view_zoom, - -camera_ortho_xy_view_zoom / ratio, - camera_ortho_xy_view_zoom / ratio, - -100, - 100); - - std::copy(&proj[0][0], &proj[3][3], m_ortho_projection); - - Eigen::Vector3d v_eye_t(-camera_ortho_xy_view_shift_x, camera_ortho_xy_view_shift_y, camera_mode_ortho_z_center_h + 10); - Eigen::Vector3d v_center_t(-camera_ortho_xy_view_shift_x, camera_ortho_xy_view_shift_y, camera_mode_ortho_z_center_h); - Eigen::Vector3d v(0, 1, 0); - - TaitBryanPose pose_tb; - pose_tb.px = 0.0; - pose_tb.py = 0.0; - pose_tb.pz = 0.0; - pose_tb.om = 0.0; - pose_tb.fi = 0.0; - pose_tb.ka = -camera_ortho_xy_view_rotation_angle_deg * DEG_TO_RAD; - auto m = affine_matrix_from_pose_tait_bryan(pose_tb); - - Eigen::Vector3d v_t = m * v; - - gluLookAt(v_eye_t.x(), v_eye_t.y(), v_eye_t.z(), v_center_t.x(), v_center_t.y(), v_center_t.z(), v_t.x(), v_t.y(), v_t.z()); - glm::mat4 lookat = glm::lookAt( - glm::vec3(v_eye_t.x(), v_eye_t.y(), v_eye_t.z()), - glm::vec3(v_center_t.x(), v_center_t.y(), v_center_t.z()), - glm::vec3(v_t.x(), v_t.y(), v_t.z())); - std::copy(&lookat[0][0], &lookat[3][3], m_ortho_gizmo_view); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - } + updateOrthoView(); showAxes(); @@ -833,16 +786,18 @@ void display() } ImGui::EndDisabled(); - ImGui::MenuItem("Orthographic", "key O", &is_ortho); - if (is_ortho) + if (ImGui::MenuItem("Orthographic", "key O", &is_ortho)) { - new_rotation_center = rotation_center; - new_rotate_x = 0.0; - new_rotate_y = 0.0; - new_translate_x = translate_x; - new_translate_y = translate_y; - new_translate_z = translate_z; - camera_transition_active = true; + if (is_ortho) + { + new_rotation_center = rotation_center; + new_rotate_x = 0.0; + new_rotate_y = 0.0; + new_translate_x = translate_x; + new_translate_y = translate_y; + new_translate_z = translate_z; + camera_transition_active = true; + } } if (ImGui::IsItemHovered()) ImGui::SetTooltip("Switch between perspective view (3D) and orthographic view (2D/flat)"); 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 a3184f76..fb386485 100644 --- a/apps/mandeye_raw_data_viewer/mandeye_raw_data_viewer.cpp +++ b/apps/mandeye_raw_data_viewer/mandeye_raw_data_viewer.cpp @@ -57,10 +57,6 @@ namespace fs = std::filesystem; ImVec4 pc_color = ImVec4(1.0f, 0.0f, 0.0f, 1.00f); ImVec4 pc_color2 = ImVec4(0.0f, 0.0f, 1.0f, 1.00f); -float m_ortho_projection[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; - -float m_ortho_gizmo_view[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; - struct AllData { std::vector> timestamps; @@ -885,14 +881,8 @@ std::vector> get_mean_cov() return mc; } -void loadData() +void loadFiles(std::vector input_file_names) { - std::vector input_file_names = mandeye::fd::OpenFileDialog("Load all files", mandeye::fd::All_Filter, true); - - // no files selected, quit loading - if (input_file_names.empty()) - return; - LidarOdometryParams params; // dummy for load_data function params.save_calibration_validation = false; params.filter_threshold_xy_inner = filter_threshold_xy_inner; @@ -901,6 +891,10 @@ void loadData() std::vector> pointsPerFile; std::vector, FusionVector, FusionVector>> imu_data; + // no files selected, quit loading + if (input_file_names.empty()) + return; + if (load_data(input_file_names, params, pointsPerFile, imu_data, false)) { // clear possible previous data @@ -1209,6 +1203,31 @@ void loadData() } } +void openFolder() +{ + std::string input_folder_name; + std::vector input_file_names; + input_folder_name = mandeye::fd::SelectFolder("Select Mandeye data folder"); + + std::cout << "Selected folder: '" << input_folder_name << std::endl; + + if (fs::exists(input_folder_name)) + { + for (const auto& entry : fs::directory_iterator(input_folder_name)) + if (entry.is_regular_file()) + input_file_names.push_back(entry.path().string()); + + loadFiles(input_file_names); + } +} + +void openFiles() +{ + std::vector input_file_names = mandeye::fd::OpenFileDialog("Load all files", mandeye::fd::All_Filter, true); + + loadFiles(input_file_names); +} + void imu_data_gui() { ImGui::Begin("IMU data"); @@ -1463,7 +1482,6 @@ void display() glMatrixMode(GL_PROJECTION); glLoadIdentity(); - float ratio = float(io.DisplaySize.x) / float(io.DisplaySize.y); updateCameraTransition(); @@ -1487,50 +1505,7 @@ void display() glLoadMatrixf(viewLocal.matrix().data()); } else - { - glOrtho( - -camera_ortho_xy_view_zoom, - camera_ortho_xy_view_zoom, - -camera_ortho_xy_view_zoom / ratio, - camera_ortho_xy_view_zoom / ratio, - -100000, - 100000); - - glm::mat4 proj = glm::orthoLH_ZO( - -camera_ortho_xy_view_zoom, - camera_ortho_xy_view_zoom, - -camera_ortho_xy_view_zoom / ratio, - camera_ortho_xy_view_zoom / ratio, - -100, - 100); - - std::copy(&proj[0][0], &proj[3][3], m_ortho_projection); - - Eigen::Vector3d v_eye_t(-camera_ortho_xy_view_shift_x, camera_ortho_xy_view_shift_y, camera_mode_ortho_z_center_h + 10); - Eigen::Vector3d v_center_t(-camera_ortho_xy_view_shift_x, camera_ortho_xy_view_shift_y, camera_mode_ortho_z_center_h); - Eigen::Vector3d v(0, 1, 0); - - TaitBryanPose pose_tb; - pose_tb.px = 0.0; - pose_tb.py = 0.0; - pose_tb.pz = 0.0; - pose_tb.om = 0.0; - pose_tb.fi = 0.0; - pose_tb.ka = -camera_ortho_xy_view_rotation_angle_deg * DEG_TO_RAD; - auto m = affine_matrix_from_pose_tait_bryan(pose_tb); - - Eigen::Vector3d v_t = m * v; - - gluLookAt(v_eye_t.x(), v_eye_t.y(), v_eye_t.z(), v_center_t.x(), v_center_t.y(), v_center_t.z(), v_t.x(), v_t.y(), v_t.z()); - glm::mat4 lookat = glm::lookAt( - glm::vec3(v_eye_t.x(), v_eye_t.y(), v_eye_t.z()), - glm::vec3(v_center_t.x(), v_center_t.y(), v_center_t.z()), - glm::vec3(v_t.x(), v_t.y(), v_t.z())); - std::copy(&lookat[0][0], &lookat[3][3], m_ortho_gizmo_view); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - } + updateOrthoView(); // /* glPointSize(point_size); @@ -1722,10 +1697,25 @@ void display() { // if (!is_init) { - if (ImGui::Button("Load data")) - loadData(); + if (ImGui::Button("Open folder")) + openFolder(); if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Select session to open for analyze (Ctrl+O)"); + ImGui::SetTooltip("Select folder containing files for analyze (Ctrl+O)"); + + ImGui::SameLine(); + + if (ImGui::ArrowButton("##menuArrow", ImGuiDir_Down)) + ImGui::OpenPopup("OpenMenu"); + + if (ImGui::BeginPopup("OpenMenu")) + { + if (ImGui::MenuItem("Open files")) + openFiles(); + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("Select files for analyze"); + + ImGui::EndPopup(); + } ImGui::SameLine(); ImGui::Dummy(ImVec2(20, 0)); @@ -1745,17 +1735,20 @@ void display() ImGui::Separator(); - ImGui::MenuItem("Orthographic", "key O", &is_ortho); - if (is_ortho) + if (ImGui::MenuItem("Orthographic", "key O", &is_ortho)) { - new_rotation_center = rotation_center; - new_rotate_x = 0.0; - new_rotate_y = 0.0; - new_translate_x = translate_x; - new_translate_y = translate_y; - new_translate_z = translate_z; - camera_transition_active = true; + if (is_ortho) + { + new_rotation_center = rotation_center; + new_rotate_x = 0.0; + new_rotate_y = 0.0; + new_translate_x = translate_x; + new_translate_y = translate_y; + new_translate_z = translate_z; + camera_transition_active = true; + } } + if (ImGui::IsItemHovered()) ImGui::SetTooltip("Switch between perspective view (3D) and orthographic view (2D/flat)"); @@ -1953,8 +1946,34 @@ int main(int argc, char* argv[]) { try { + if (checkClHelp(argc, argv)) + { + std::cout << winTitle << "\n\n" + << "USAGE:\n" + << std::filesystem::path(argv[0]).stem().string() << " /?\n\n" + << "where\n" + << " Path where scan files are located (*.csv, *.laz, *.sn)\n" + << " -h, /h, --help, /? Show this help and exit\n\n"; + + return 0; + } + initGL(&argc, argv, winTitle, display, mouse); + if (argc == 2) + { + std::vector input_file_names; + + if (fs::exists(argv[1])) + { + for (const auto& entry : fs::directory_iterator(argv[1])) + if (entry.is_regular_file()) + input_file_names.push_back(entry.path().string()); + + loadFiles(input_file_names); + } + } + glutMainLoop(); ImGui_ImplOpenGL2_Shutdown(); 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 88090328..bf54be3e 100644 --- a/apps/mandeye_single_session_viewer/mandeye_single_session_viewer.cpp +++ b/apps/mandeye_single_session_viewer/mandeye_single_session_viewer.cpp @@ -132,10 +132,6 @@ namespace fs = std::filesystem; ImVec4 pc_neigbouring_color = ImVec4(0.5f, 0.5f, 0.5f, 1.0f); ImVec4 pc_color2 = ImVec4(0.0f, 0.0f, 1.0f, 1.0f); -float m_ortho_projection[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; - -float m_ortho_gizmo_view[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; - int index_rendered_points_local = -1; float offset_intensity = 0.0; bool show_neighbouring_scans = false; @@ -667,88 +663,96 @@ void gl_init() } /////////////////////////////////////////////////////////////////////////////////// -void openSession() -{ - info_gui = false; - std::string session_file_name = ""; - session_file_name = mandeye::fd::OpenFileDialogOneFile("Open session file", mandeye::fd::Session_filter); - if (session_file_name.size() > 0) - { - session_loaded = session.load(fs::path(session_file_name).string(), false, 0.0, 0.0, 0.0, false); - index_rendered_points_local = 0; - if (session_loaded) - { - std::string newTitle = winTitle + " - " + truncPath(session_file_name); - glutSetWindowTitle(newTitle.c_str()); +void loadSession(const std::string& session_file_name) +{ + session_loaded = session.load(fs::path(session_file_name).string(), false, 0.0, 0.0, 0.0, false); + index_rendered_points_local = 0; - for (const auto& pc : session.point_clouds_container.point_clouds) - session_total_number_of_points += pc.points_local.size(); + if (session_loaded) + { + std::string newTitle = winTitle + " - " + truncPath(session_file_name); + glutSetWindowTitle(newTitle.c_str()); - session_dims = session.point_clouds_container.compute_point_cloud_dimension(); - } + for (const auto& pc : session.point_clouds_container.point_clouds) + session_total_number_of_points += pc.points_local.size(); - if (gl_useVBOs) + session_dims = session.point_clouds_container.compute_point_cloud_dimension(); + } + + if (gl_useVBOs) + { + // clearing previous data + GLint offset = 0; + gl_clouds.clear(); + gl_clouds.shrink_to_fit(); + gl_cloudIndexSSBO.clear(); + gl_cloudIndexSSBO.shrink_to_fit(); + gl_cloudsSSBO.clear(); + gl_cloudsSSBO.shrink_to_fit(); + + // Convert point cloud data to gl_Points + for (size_t j = 0; j < session.point_clouds_container.point_clouds.size(); ++j) { - // clearing previous data - GLint offset = 0; - gl_clouds.clear(); - gl_clouds.shrink_to_fit(); - gl_cloudIndexSSBO.clear(); - gl_cloudIndexSSBO.shrink_to_fit(); - gl_cloudsSSBO.clear(); - gl_cloudsSSBO.shrink_to_fit(); - - // Convert point cloud data to gl_Points - for (size_t j = 0; j < session.point_clouds_container.point_clouds.size(); ++j) + const auto& pc = session.point_clouds_container.point_clouds[j]; + + for (size_t i = 0; i < pc.points_local.size(); ++i) { - const auto& pc = session.point_clouds_container.point_clouds[j]; + const auto& pt = pc.points_local[i]; - for (size_t i = 0; i < pc.points_local.size(); ++i) - { - const auto& pt = pc.points_local[i]; + gl_point gp; + gp.pos[0] = pt.x(); + gp.pos[1] = pt.y(); + gp.pos[2] = pt.z(); + gp.intensity = pc.intensities[i]; // same index - gl_point gp; - gp.pos[0] = pt.x(); - gp.pos[1] = pt.y(); - gp.pos[2] = pt.z(); - gp.intensity = pc.intensities[i]; // same index + gl_Points.push_back(gp); + gl_cloudIndexSSBO.push_back(static_cast(j)); // cloud index + } - gl_Points.push_back(gp); - gl_cloudIndexSSBO.push_back(static_cast(j)); // cloud index - } + gl_cloud gc; + gc.offset = offset; + gc.count = static_cast(pc.points_local.size()); + gc.visible = true; + gl_clouds.push_back(gc); + + gl_cloudSSBO gcSSBO; + Eigen::Matrix4f pose_f = pc.m_pose.matrix().cast(); + std::memcpy(gcSSBO.pose, pose_f.data(), 16 * sizeof(float)); + // gcSSBO.colorScheme = colorScheme; + // gcSSBO.fixedColor[0] = pc.render_color[0]; + // gcSSBO.fixedColor[1] = pc.render_color[1]; + // gcSSBO.fixedColor[2] = pc.render_color[2]; + oldcolorScheme = CS_FOLLOW; // force update with non-sense value + gl_cloudsSSBO.push_back(gcSSBO); + + offset += static_cast(pc.points_local.size()); + } - gl_cloud gc; - gc.offset = offset; - gc.count = static_cast(pc.points_local.size()); - gc.visible = true; - gl_clouds.push_back(gc); - - gl_cloudSSBO gcSSBO; - Eigen::Matrix4f pose_f = pc.m_pose.matrix().cast(); - std::memcpy(gcSSBO.pose, pose_f.data(), 16 * sizeof(float)); - // gcSSBO.colorScheme = colorScheme; - // gcSSBO.fixedColor[0] = pc.render_color[0]; - // gcSSBO.fixedColor[1] = pc.render_color[1]; - // gcSSBO.fixedColor[2] = pc.render_color[2]; - oldcolorScheme = CS_FOLLOW; // force update with non-sense value - gl_cloudsSSBO.push_back(gcSSBO); - - offset += static_cast(pc.points_local.size()); - } + // Load to OpenGL buffers + gl_loadPointCloudBuffer(gl_Points, VAO, VBO); - // Load to OpenGL buffers - gl_loadPointCloudBuffer(gl_Points, VAO, VBO); + // Clear CPU-side data after load to save memory + gl_Points.clear(); + gl_Points.shrink_to_fit(); - // Clear CPU-side data after load to save memory - gl_Points.clear(); - gl_Points.shrink_to_fit(); + // Prepare SSBO data + gl_updateSSBOs(); + } +} - // Prepare SSBO data - gl_updateSSBOs(); - } +void openSession() +{ + info_gui = false; + + std::string session_file_name = ""; + session_file_name = mandeye::fd::OpenFileDialogOneFile("Open session file", mandeye::fd::Session_filter); + + if (session_file_name.size() > 0) + { + loadSession(session_file_name); } } @@ -987,50 +991,7 @@ void display() glLoadMatrixf(viewLocal.matrix().data()); } else - { - glOrtho( - -camera_ortho_xy_view_zoom, - camera_ortho_xy_view_zoom, - -camera_ortho_xy_view_zoom / ratio, - camera_ortho_xy_view_zoom / ratio, - -100000, - 100000); - - glm::mat4 proj = glm::orthoLH_ZO( - -camera_ortho_xy_view_zoom, - camera_ortho_xy_view_zoom, - -camera_ortho_xy_view_zoom / ratio, - camera_ortho_xy_view_zoom / ratio, - -100, - 100); - - std::copy(&proj[0][0], &proj[3][3], m_ortho_projection); - - Eigen::Vector3d v_eye_t(-camera_ortho_xy_view_shift_x, camera_ortho_xy_view_shift_y, camera_mode_ortho_z_center_h + 10); - Eigen::Vector3d v_center_t(-camera_ortho_xy_view_shift_x, camera_ortho_xy_view_shift_y, camera_mode_ortho_z_center_h); - Eigen::Vector3d v(0, 1, 0); - - TaitBryanPose pose_tb; - pose_tb.px = 0.0; - pose_tb.py = 0.0; - pose_tb.pz = 0.0; - pose_tb.om = 0.0; - pose_tb.fi = 0.0; - pose_tb.ka = -camera_ortho_xy_view_rotation_angle_deg * DEG_TO_RAD; - auto m = affine_matrix_from_pose_tait_bryan(pose_tb); - - Eigen::Vector3d v_t = m * v; - - gluLookAt(v_eye_t.x(), v_eye_t.y(), v_eye_t.z(), v_center_t.x(), v_center_t.y(), v_center_t.z(), v_t.x(), v_t.y(), v_t.z()); - glm::mat4 lookat = glm::lookAt( - glm::vec3(v_eye_t.x(), v_eye_t.y(), v_eye_t.z()), - glm::vec3(v_center_t.x(), v_center_t.y(), v_center_t.z()), - glm::vec3(v_t.x(), v_t.y(), v_t.z())); - std::copy(&lookat[0][0], &lookat[3][3], m_ortho_gizmo_view); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - } + updateOrthoView(); showAxes(); @@ -1196,16 +1157,18 @@ void display() } ImGui::EndDisabled(); - ImGui::MenuItem("Orthographic", "key O", &is_ortho); - if (is_ortho) + if (ImGui::MenuItem("Orthographic", "key O", &is_ortho)) { - new_rotation_center = rotation_center; - new_rotate_x = 0.0; - new_rotate_y = 0.0; - new_translate_x = translate_x; - new_translate_y = translate_y; - new_translate_z = translate_z; - camera_transition_active = true; + if (is_ortho) + { + new_rotation_center = rotation_center; + new_rotate_x = 0.0; + new_rotate_y = 0.0; + new_translate_x = translate_x; + new_translate_y = translate_y; + new_translate_z = translate_z; + camera_transition_active = true; + } } if (ImGui::IsItemHovered()) ImGui::SetTooltip("Switch between perspective view (3D) and orthographic view (2D/flat)"); @@ -1512,8 +1475,37 @@ int main(int argc, char* argv[]) { try { + if (checkClHelp(argc, argv)) + { + std::cout << winTitle << "\n\n" + << "USAGE:\n" + << std::filesystem::path(argv[0]).stem().string() << " /?\n\n" + << "where\n" + << " Path to Mandeye JSON Session file (*.mjs)\n" + << " -h, /h, --help, /? Show this help and exit\n\n"; + + return 0; + } + initGL(&argc, argv, winTitle, display, mouse); gl_init(); + + if (argc > 1) + { + for (int i = 1; i < argc; i++) + { + std::string ext = fs::path(argv[i]).extension().string(); + std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); + + if (ext == ".mjs") + { + loadSession(argv[i]); + + break; + } + } + } + glutMainLoop(); ImGui_ImplOpenGL2_Shutdown(); diff --git a/apps/multi_session_registration/multi_session_registration.cpp b/apps/multi_session_registration/multi_session_registration.cpp index c0f348dd..d2334d33 100644 --- a/apps/multi_session_registration/multi_session_registration.cpp +++ b/apps/multi_session_registration/multi_session_registration.cpp @@ -137,8 +137,6 @@ static const std::vector appShortcuts = { { "Normal keys", "A", " { "", "Ctrl + right click", "" }, { "", "Ctrl + middle click", "" } }; -float m_ortho_projection[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; -float m_ortho_gizmo_view[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; float m_gizmo[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; bool is_decimate = true; @@ -1869,7 +1867,7 @@ Eigen::Vector3d GLWidgetGetOGLPos(int x, int y, const ObservationPicking& observ return pos; } -bool load_project_settings(const std::string& file_name, ProjectSettings& _project_settings) +bool loadProject(const std::string& file_name, ProjectSettings& _project_settings) { std::cout << "Opening project file: '" << file_name << "'\n"; @@ -1933,6 +1931,12 @@ bool load_project_settings(const std::string& file_name, ProjectSettings& _proje return false; } + std::string newTitle = winTitle + " - " + truncPath(file_name); + glutSetWindowTitle(newTitle.c_str()); + + loaded_sessions = false; + time_stamp_offset = 0.0; + return true; } @@ -1943,13 +1947,7 @@ void openProject() if (input_file_name.size() > 0) { - load_project_settings(fs::path(input_file_name).string(), project_settings); - - std::string newTitle = winTitle + " - " + truncPath(input_file_name); - glutSetWindowTitle(newTitle.c_str()); - - loaded_sessions = false; - time_stamp_offset = 0.0; + loadProject(fs::path(input_file_name).string(), project_settings); } } @@ -2423,50 +2421,7 @@ void display() glLoadMatrixf(viewLocal.matrix().data()); } else - { - glOrtho( - -camera_ortho_xy_view_zoom, - camera_ortho_xy_view_zoom, - -camera_ortho_xy_view_zoom / ratio, - camera_ortho_xy_view_zoom / ratio, - -100000, - 100000); - - glm::mat4 proj = glm::orthoLH_ZO( - -camera_ortho_xy_view_zoom, - camera_ortho_xy_view_zoom, - -camera_ortho_xy_view_zoom / ratio, - camera_ortho_xy_view_zoom / ratio, - -100, - 100); - - std::copy(&proj[0][0], &proj[3][3], m_ortho_projection); - - Eigen::Vector3d v_eye_t(-camera_ortho_xy_view_shift_x, camera_ortho_xy_view_shift_y, camera_mode_ortho_z_center_h + 10); - Eigen::Vector3d v_center_t(-camera_ortho_xy_view_shift_x, camera_ortho_xy_view_shift_y, camera_mode_ortho_z_center_h); - Eigen::Vector3d v(0, 1, 0); - - TaitBryanPose pose_tb; - pose_tb.px = 0.0; - pose_tb.py = 0.0; - pose_tb.pz = 0.0; - pose_tb.om = 0.0; - pose_tb.fi = 0.0; - pose_tb.ka = -camera_ortho_xy_view_rotation_angle_deg * DEG_TO_RAD; - auto m = affine_matrix_from_pose_tait_bryan(pose_tb); - - Eigen::Vector3d v_t = m * v; - - gluLookAt(v_eye_t.x(), v_eye_t.y(), v_eye_t.z(), v_center_t.x(), v_center_t.y(), v_center_t.z(), v_t.x(), v_t.y(), v_t.z()); - glm::mat4 lookat = glm::lookAt( - glm::vec3(v_eye_t.x(), v_eye_t.y(), v_eye_t.z()), - glm::vec3(v_center_t.x(), v_center_t.y(), v_center_t.z()), - glm::vec3(v_t.x(), v_t.y(), v_t.z())); - std::copy(&lookat[0][0], &lookat[3][3], m_ortho_gizmo_view); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - } + updateOrthoView(); showAxes(); @@ -3681,16 +3636,18 @@ pose_tait_bryan_from_affine_matrix(m_src.inverse() * m_g); } ImGui::EndDisabled(); - ImGui::MenuItem("Orthographic", "key O", &is_ortho); - if (is_ortho) + if (ImGui::MenuItem("Orthographic", "key O", &is_ortho)) { - new_rotation_center = rotation_center; - new_rotate_x = 0.0; - new_rotate_y = 0.0; - new_translate_x = translate_x; - new_translate_y = translate_y; - new_translate_z = translate_z; - camera_transition_active = true; + if (is_ortho) + { + new_rotation_center = rotation_center; + new_rotate_x = 0.0; + new_rotate_y = 0.0; + new_translate_x = translate_x; + new_translate_y = translate_y; + new_translate_z = translate_z; + camera_transition_active = true; + } } if (ImGui::IsItemHovered()) ImGui::SetTooltip("Switch between perspective view (3D) and orthographic view (2D/flat)"); @@ -3941,8 +3898,36 @@ int main(int argc, char* argv[]) { try { + if (checkClHelp(argc, argv)) + { + std::cout << winTitle << "\n\n" + << "USAGE:\n" + << std::filesystem::path(argv[0]).stem().string() << " /?\n\n" + << "where\n" + << " Path to Mandeye JSON Project file (*.mjp)\n" + << " -h, /h, --help, /? Show this help and exit\n\n"; + + return 0; + } + initGL(&argc, argv, winTitle, display, mouse); + if (argc > 1) + { + for (int i = 1; i < argc; i++) + { + std::string ext = fs::path(argv[i]).extension().string(); + std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); + + if (ext == ".mjp") + { + loadProject(argv[i], project_settings); + + break; + } + } + } + glutMainLoop(); ImGui_ImplOpenGL2_Shutdown(); 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 2ff47e6a..244aa9d6 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 @@ -209,10 +209,6 @@ ColorScheme csTrajectory = CS_SOLID; float m_gizmo[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; -float m_ortho_gizmo_view[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; - -float m_ortho_projection[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; - bool manipulate_only_marked_gizmo = false; Session session; @@ -1485,34 +1481,39 @@ void lio_segments_gui() ImGui::End(); } -void openSession() +void loadSession(const std::string& session_file_name) { - session_file_name = mandeye::fd::OpenFileDialogOneFile("Open session", mandeye::fd::Session_filter); - - if (session_file_name.size() > 0) + std::cout << "Session file: '" << session_file_name << "'" << std::endl; + + if (session.load( + fs::path(session_file_name).string(), + tls_registration.is_decimate, + tls_registration.bucket_x, + tls_registration.bucket_y, + tls_registration.bucket_z, + tls_registration.calculate_offset)) { - std::cout << "Session file: '" << session_file_name << "'" << std::endl; + session_loaded = true; + index_begin = 0; + index_end = session.point_clouds_container.point_clouds.size() - 1; - if (session.load( - fs::path(session_file_name).string(), - tls_registration.is_decimate, - tls_registration.bucket_x, - tls_registration.bucket_y, - tls_registration.bucket_z, - tls_registration.calculate_offset)) - { - session_loaded = true; - index_begin = 0; - index_end = session.point_clouds_container.point_clouds.size() - 1; + std::string newTitle = winTitle + " - " + truncPath(session_file_name); + glutSetWindowTitle(newTitle.c_str()); - std::string newTitle = winTitle + " - " + truncPath(session_file_name); - glutSetWindowTitle(newTitle.c_str()); + for (const auto& pc : session.point_clouds_container.point_clouds) + session_total_number_of_points += pc.points_local.size(); - for (const auto& pc : session.point_clouds_container.point_clouds) - session_total_number_of_points += pc.points_local.size(); + session_dims = session.point_clouds_container.compute_point_cloud_dimension(); + } +} - session_dims = session.point_clouds_container.compute_point_cloud_dimension(); - } +void openSession() +{ + session_file_name = mandeye::fd::OpenFileDialogOneFile("Open session", mandeye::fd::Session_filter); + + if (session_file_name.size() > 0) + { + loadSession(session_file_name); } } @@ -2248,50 +2249,7 @@ void display() glLoadMatrixf(viewLocal.matrix().data()); } else - { - glOrtho( - -camera_ortho_xy_view_zoom, - camera_ortho_xy_view_zoom, - -camera_ortho_xy_view_zoom / ratio, - camera_ortho_xy_view_zoom / ratio, - -100000, - 100000); - - glm::mat4 proj = glm::orthoLH_ZO( - -camera_ortho_xy_view_zoom, - camera_ortho_xy_view_zoom, - -camera_ortho_xy_view_zoom / ratio, - camera_ortho_xy_view_zoom / ratio, - -100, - 100); - - std::copy(&proj[0][0], &proj[3][3], m_ortho_projection); - - Eigen::Vector3d v_eye_t(-camera_ortho_xy_view_shift_x, camera_ortho_xy_view_shift_y, camera_mode_ortho_z_center_h + 10); - Eigen::Vector3d v_center_t(-camera_ortho_xy_view_shift_x, camera_ortho_xy_view_shift_y, camera_mode_ortho_z_center_h); - Eigen::Vector3d v(0, 1, 0); - - TaitBryanPose pose_tb; - pose_tb.px = 0.0; - pose_tb.py = 0.0; - pose_tb.pz = 0.0; - pose_tb.om = 0.0; - pose_tb.fi = 0.0; - pose_tb.ka = -camera_ortho_xy_view_rotation_angle_deg * DEG_TO_RAD; - auto m = affine_matrix_from_pose_tait_bryan(pose_tb); - - Eigen::Vector3d v_t = m * v; - - gluLookAt(v_eye_t.x(), v_eye_t.y(), v_eye_t.z(), v_center_t.x(), v_center_t.y(), v_center_t.z(), v_t.x(), v_t.y(), v_t.z()); - glm::mat4 lookat = glm::lookAt( - glm::vec3(v_eye_t.x(), v_eye_t.y(), v_eye_t.z()), - glm::vec3(v_center_t.x(), v_center_t.y(), v_center_t.z()), - glm::vec3(v_t.x(), v_t.y(), v_t.z())); - std::copy(&lookat[0][0], &lookat[3][3], m_ortho_gizmo_view); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - } + updateOrthoView(); showAxes(); @@ -3482,16 +3440,18 @@ void display() } ImGui::EndDisabled(); - ImGui::MenuItem("Orthographic", "key O", &is_ortho); - if (is_ortho) + if (ImGui::MenuItem("Orthographic", "key O", &is_ortho)) { - new_rotation_center = rotation_center; - new_rotate_x = 0.0; - new_rotate_y = 0.0; - new_translate_x = translate_x; - new_translate_y = translate_y; - new_translate_z = translate_z; - camera_transition_active = true; + if (is_ortho) + { + new_rotation_center = rotation_center; + new_rotate_x = 0.0; + new_rotate_y = 0.0; + new_translate_x = translate_x; + new_translate_y = translate_y; + new_translate_z = translate_z; + camera_transition_active = true; + } } if (ImGui::IsItemHovered()) ImGui::SetTooltip("Switch between perspective view (3D) and orthographic view (2D/flat)"); @@ -3790,8 +3750,36 @@ int main(int argc, char* argv[]) { try { + if (checkClHelp(argc, argv)) + { + std::cout << winTitle << "\n\n" + << "USAGE:\n" + << std::filesystem::path(argv[0]).stem().string() << " /?\n\n" + << "where\n" + << " Path to Mandeye JSON Session file (*.mjs)\n" + << " -h, /h, --help, /? Show this help and exit\n\n"; + + return 0; + } + initGL(&argc, argv, winTitle, display, mouse); + if (argc > 1) + { + for (int i = 1; i < argc; i++) + { + std::string ext = fs::path(argv[i]).extension().string(); + std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); + + if (ext == ".mjs") + { + loadSession(argv[i]); + + break; + } + } + } + glutMainLoop(); ImGui_ImplOpenGL2_Shutdown(); diff --git a/core/include/utils.hpp b/core/include/utils.hpp index 8f64617d..37da8e35 100644 --- a/core/include/utils.hpp +++ b/core/include/utils.hpp @@ -60,7 +60,6 @@ extern float mouse_sensitivity; extern bool is_ortho; extern bool lock_z; -void draw_ellipse(const Eigen::Matrix3d& covar, const Eigen::Vector3d& mean, Eigen::Vector3f color, float nstd); extern bool show_axes; extern ImVec4 bg_color; extern int point_size; @@ -77,7 +76,6 @@ extern float translate_x, translate_y, translate_z; extern double camera_ortho_xy_view_zoom; extern double camera_ortho_xy_view_shift_x; extern double camera_ortho_xy_view_shift_y; -extern double camera_ortho_xy_view_rotation_angle_deg; extern double camera_mode_ortho_z_center_h; // Target camera state for smooth transitions @@ -93,8 +91,10 @@ extern bool camera_transition_active; extern bool glLineWidthSupport; -struct ShortcutEntry -{ +extern float m_ortho_projection[]; +extern float m_ortho_gizmo_view[]; + +struct ShortcutEntry { std::string type; std::string shortcut; std::string description; @@ -111,6 +111,8 @@ void reshape(int w, int h); void ShowMainDockSpace(); bool initGL(int* argc, char** argv, const std::string& winTitle, void (*display)(), void (*mouse)(int, int, int, int)); +void draw_ellipse(const Eigen::Matrix3d& covar, const Eigen::Vector3d& mean, Eigen::Vector3f color, float nstd); + void showAxes(); void updateCameraTransition(); void breakCameraTransition(); @@ -139,4 +141,8 @@ void getClosestTrajectoriesPoint( int& index_loop_closure_target, bool KeyShift); -void setNewRotationCenter(int x, int y); \ No newline at end of file +void setNewRotationCenter(int x, int y); + +bool checkClHelp(int argc, char** argv); + +void updateOrthoView(); \ No newline at end of file diff --git a/core/src/utils.cpp b/core/src/utils.cpp index a71fcc8a..55d65a22 100644 --- a/core/src/utils.cpp +++ b/core/src/utils.cpp @@ -9,6 +9,9 @@ #include #include +#include +#include + #include "utils.hpp" #include @@ -16,7 +19,6 @@ #ifdef _WIN32 #include #include - #endif /////////////////////////////////////////////////////////////////////////////////// @@ -46,7 +48,6 @@ float translate_z = -50.0; double camera_ortho_xy_view_zoom = 10; double camera_ortho_xy_view_shift_x = 0.0; double camera_ortho_xy_view_shift_y = 0.0; -double camera_ortho_xy_view_rotation_angle_deg = 0; double camera_mode_ortho_z_center_h = 0.0; // Target camera state for smooth transitions @@ -72,6 +73,9 @@ bool show_about = false; bool glLineWidthSupport = true; +float m_ortho_projection[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; +float m_ortho_gizmo_view[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; + // General shortcuts applicable to any app static const std::vector shortcuts = { { "Normal keys", "A", "" }, { "", "Ctrl+A", "" }, @@ -274,9 +278,16 @@ void motion(int x, int y) dx = (float)(x - mouse_old_x); dy = (float)(y - mouse_old_y); - if (is_ortho) + if (mouse_buttons & 1) // left button { - if (mouse_buttons & 1) + rotate_x += dy * 0.2f; + rotate_y += dx * 0.2f; + breakCameraTransition(); + } + + if (mouse_buttons & 4) // right button + { + if (is_ortho) { float ratio = float(io.DisplaySize.x) / float(io.DisplaySize.y); Eigen::Vector3d v( @@ -289,28 +300,17 @@ void motion(int x, int y) pose_tb.pz = 0.0; pose_tb.om = 0.0; pose_tb.fi = 0.0; - pose_tb.ka = camera_ortho_xy_view_rotation_angle_deg * M_PI / 180.0; + pose_tb.ka = (rotate_x + rotate_y)*M_PI / 180.0; auto m = affine_matrix_from_pose_tait_bryan(pose_tb); Eigen::Vector3d v_t = m * v; camera_ortho_xy_view_shift_x += v_t.x(); camera_ortho_xy_view_shift_y += v_t.y(); } - } - else - { - if (mouse_buttons & 1) // left button - { - rotate_x += dy * 0.2f; // * mouse_sensitivity; - rotate_y += dx * 0.2f; // * mouse_sensitivity; - breakCameraTransition(); - // camera_transition_active = false; - } - if (mouse_buttons & 4) // right button + else { translate_x += dx * 0.1f * mouse_sensitivity; translate_y -= dy * 0.1f * mouse_sensitivity; breakCameraTransition(); - // camera_transition_active = false; } } @@ -683,7 +683,6 @@ void setCameraPreset(CameraPreset preset) camera_ortho_xy_view_zoom = 10; camera_ortho_xy_view_shift_x = 0.0; camera_ortho_xy_view_shift_y = 0.0; - camera_ortho_xy_view_rotation_angle_deg = 0; camera_mode_ortho_z_center_h = 0.0; viewer_decimate_point_cloud = 1000; @@ -809,46 +808,46 @@ void view_kbd_shortcuts() // translate camera if (io.KeyShift && ImGui::IsKeyPressed(ImGuiKey_RightArrow, true)) { - translate_x += 0.2f * mouse_sensitivity; + translate_x += 0.5f * mouse_sensitivity; breakCameraTransition(); } if (io.KeyShift && ImGui::IsKeyPressed(ImGuiKey_LeftArrow, true)) { - translate_x -= 0.2f * mouse_sensitivity; + translate_x -= 0.5f * mouse_sensitivity; breakCameraTransition(); } if (io.KeyShift && ImGui::IsKeyPressed(ImGuiKey_UpArrow, true)) { - translate_y += 0.2f * mouse_sensitivity; + translate_y += 0.5f * mouse_sensitivity; breakCameraTransition(); } if (io.KeyShift && ImGui::IsKeyPressed(ImGuiKey_DownArrow, true)) { - translate_y -= 0.2f * mouse_sensitivity; + translate_y -= 0.5f * mouse_sensitivity; breakCameraTransition(); } // rotate camera if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_RightArrow, true)) { - rotate_y -= mouse_sensitivity; + rotate_y -= 0.6; breakCameraTransition(); } if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_LeftArrow, true)) { - rotate_y += mouse_sensitivity; + rotate_y += 0.6; breakCameraTransition(); } if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_UpArrow, true)) { - rotate_x -= mouse_sensitivity; + rotate_x -= 0.6; breakCameraTransition(); } if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_DownArrow, true)) { - rotate_x += mouse_sensitivity; + rotate_x += 0.6; breakCameraTransition(); } @@ -1494,4 +1493,76 @@ void setNewRotationCenter(int x, int y) new_translate_z = translate_z; camera_transition_active = true; +} + + + +bool checkClHelp(int argc, char** argv) +{ + for (int i = 1; i < argc; ++i) + { + std::string arg(argv[i]); + + if (arg == "-h" || arg == "/h" || arg == "--help" || arg == "/?") + { + return true; + } + } + return false; +} + + + +void updateOrthoView() +{ + // still updating viewLocal for compass + viewLocal.rotate(Eigen::AngleAxisf((rotate_x + rotate_y) * DEG_TO_RAD, Eigen::Vector3f::UnitZ())); + + ImGuiIO& io = ImGui::GetIO(); + float ratio = float(io.DisplaySize.x) / float(io.DisplaySize.y); + + + + glOrtho( + -camera_ortho_xy_view_zoom, + camera_ortho_xy_view_zoom, + -camera_ortho_xy_view_zoom / ratio, + camera_ortho_xy_view_zoom / ratio, + -100000, + 100000); + + glm::mat4 proj = glm::orthoLH_ZO( + -camera_ortho_xy_view_zoom, + camera_ortho_xy_view_zoom, + -camera_ortho_xy_view_zoom / ratio, + camera_ortho_xy_view_zoom / ratio, + -100, + 100); + + std::copy(&proj[0][0], &proj[3][3], m_ortho_projection); + + Eigen::Vector3d v_eye_t(-camera_ortho_xy_view_shift_x, camera_ortho_xy_view_shift_y, camera_mode_ortho_z_center_h + 10); + Eigen::Vector3d v_center_t(-camera_ortho_xy_view_shift_x, camera_ortho_xy_view_shift_y, camera_mode_ortho_z_center_h); + Eigen::Vector3d v(0, 1, 0); + + TaitBryanPose pose_tb; + pose_tb.px = 0.0; + pose_tb.py = 0.0; + pose_tb.pz = 0.0; + pose_tb.om = 0.0; + pose_tb.fi = 0.0; + pose_tb.ka = -(rotate_x + rotate_y) * DEG_TO_RAD; + auto m = affine_matrix_from_pose_tait_bryan(pose_tb); + + Eigen::Vector3d v_t = m * v; + + gluLookAt(v_eye_t.x(), v_eye_t.y(), v_eye_t.z(), v_center_t.x(), v_center_t.y(), v_center_t.z(), v_t.x(), v_t.y(), v_t.z()); + glm::mat4 lookat = glm::lookAt( + glm::vec3(v_eye_t.x(), v_eye_t.y(), v_eye_t.z()), + glm::vec3(v_center_t.x(), v_center_t.y(), v_center_t.z()), + glm::vec3(v_t.x(), v_t.y(), v_t.z())); + std::copy(&lookat[0][0], &lookat[3][3], m_ortho_gizmo_view); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); } \ No newline at end of file