diff --git a/AGENTS.md b/AGENTS.md index fc20f073..357223aa 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -11,8 +11,7 @@ platforms, see "Platforms and portability" below. - `shared/include/HDMapping/`: header-only utilities (`Assert.h` with `HDMAPPING_ASSERT`, `PoseInterpolation.h`, `SessionPaths.h`). - `apps/`: the tools. Main workflow: `mandeye_raw_data_viewer`, `lidar_odometry_step_1`, `multi_view_tls_registration` - (step 2), `multi_session_registration` (step 3). The `*_legacy` apps are the GLUT versions kept next to the raylib - ports. New rendering work goes into the raylib code. + (step 2), `multi_session_registration` (step 3). New rendering work goes into the raylib code. - `3rdparty/`: git submodules built from source. `3rdpartyBinary/`: prebuilt OpenCV and PROJ. Both are wired up in `cmake/dependencies.cmake`. - `scripts/`: developer tooling, documented in `scripts/README.md`. diff --git a/CMakeLists.txt b/CMakeLists.txt index e7995d7d..afe6564a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,14 +142,10 @@ endif() # Applications for typical workflow - see images/workflow.png add_subdirectory(apps/mandeye_raw_data_viewer) -add_subdirectory(apps/mandeye_raw_data_viewer_legacy) add_subdirectory(apps/lidar_odometry_step_1) -add_subdirectory(apps/lidar_odometry_step_1_legacy) add_subdirectory(apps/mandeye_single_session_viewer) add_subdirectory(apps/multi_view_tls_registration) -add_subdirectory(apps/multi_view_tls_registration_legacy) add_subdirectory(apps/multi_session_registration) -add_subdirectory(apps/multi_session_registration_legacy) add_subdirectory(apps/session_uncertainty_calculation) add_subdirectory(apps/session_to_session_rigid_registration) add_subdirectory(apps/camera_lidar_trajectory_viewer) diff --git a/apps/lidar_odometry_step_1/CMakeLists.txt b/apps/lidar_odometry_step_1/CMakeLists.txt index 518add39..15054aa5 100644 --- a/apps/lidar_odometry_step_1/CMakeLists.txt +++ b/apps/lidar_odometry_step_1/CMakeLists.txt @@ -38,9 +38,6 @@ add_executable( target_compile_definitions(lidar_odometry_step_1 PRIVATE WITH_GUI=1) target_apply_hdmapping_profiler(lidar_odometry_step_1) -# lidar_odometry_gui.cpp is raylib-based (ported off GLUT; the GLUT build is kept as -# apps/lidar_odometry_step_1_legacy): (core_raylib_utils) replaces -# with the same names, so only the GL calls changed. target_include_directories( lidar_odometry_step_1 PRIVATE include diff --git a/apps/lidar_odometry_step_1_legacy/CMakeLists.txt b/apps/lidar_odometry_step_1_legacy/CMakeLists.txt deleted file mode 100644 index 373979a8..00000000 --- a/apps/lidar_odometry_step_1_legacy/CMakeLists.txt +++ /dev/null @@ -1,86 +0,0 @@ -cmake_minimum_required(VERSION 4.0.0) - -# Legacy GLUT + legacy immediate-mode OpenGL build of step1, kept side by -# side with apps/lidar_odometry_step_1 (raylib-based since it was ported off -# GLUT), the same way step2/step3 keep their *_legacy builds. Only the GUI -# translation unit is copied: the odometry sources it builds on carry no -# GL/GLUT code, so they are compiled from apps/lidar_odometry_step_1 as-is. -project(lidar_odometry_step_1_legacy) - -set(STEP1_DIR ${REPOSITORY_DIRECTORY}/apps/lidar_odometry_step_1) - -set(SOURCES - lidar_odometry_gui.cpp - ${STEP1_DIR}/lidar_odometry_utils.cpp - ${STEP1_DIR}/lidar_odometry_utils_optimizers.cpp - ${STEP1_DIR}/lidar_odometry.cpp - ${STEP1_DIR}/points_global_spill.cpp - ${STEP1_DIR}/raw_cloud_loader.cpp - ${STEP1_DIR}/toml_io.cpp - "../../core/src/utils.cpp" -) - -# Windows: add resource file -if(WIN32) - list(APPEND SOURCES "resource.rc") -endif() - -add_executable(lidar_odometry_step_1_legacy ${SOURCES}) - -target_compile_definitions(lidar_odometry_step_1_legacy PRIVATE WITH_GUI=1) -# target_apply_hdmapping_profiler() is defined by apps/lidar_odometry_step_1. -target_apply_hdmapping_profiler(lidar_odometry_step_1_legacy) - -target_include_directories( - lidar_odometry_step_1_legacy - PRIVATE ${STEP1_DIR} - ${REPOSITORY_DIRECTORY}/core/include - ${REPOSITORY_DIRECTORY}/core_hd_mapping/include - ${THIRDPARTY_DIRECTORY} - ${THIRDPARTY_DIRECTORY}/glm - ${EIGEN3_INCLUDE_DIR} - ${THIRDPARTY_DIRECTORY}/tomlplusplus/include - ${THIRDPARTY_DIRECTORY}/imgui - ${THIRDPARTY_DIRECTORY}/imgui/backends - ${THIRDPARTY_DIRECTORY}/ImGuizmo - ${THIRDPARTY_DIRECTORY}/glew-cmake/include - ${FREEGLUT_INCLUDE_DIR} - ${THIRDPARTY_DIRECTORY}/json/include - ${THIRDPARTY_DIRECTORY}/portable-file-dialogs-master - ${LASZIP_INCLUDE_DIR}/LASzip/include - ${THIRDPARTY_DIRECTORY}/observation_equations/codes - ${THIRDPARTY_DIRECTORY}/vqf/vqf/cpp - ${THIRDPARTY_DIRECTORY}/Fusion/Fusion) - -target_link_libraries( - lidar_odometry_step_1_legacy - PRIVATE - step1_run_report - vqf - Fusion - unordered_dense::unordered_dense - spdlog::spdlog - UTL::include - OpenGL::GLU - ${FREEGLUT_LIBRARY} - ${OPENGL_gl_LIBRARY} - ${PLATFORM_LASZIP_LIB} - ${PLATFORM_MISCELLANEOUS_LIBS} - ${CORE_LIBRARIES} - ${GUI_LIBRARIES}) - -if(WIN32) - add_custom_command( - TARGET lidar_odometry_step_1_legacy - POST_BUILD - COMMAND - ${CMAKE_COMMAND} -E copy $ - $ - COMMAND_EXPAND_LISTS) -endif() - -if (MSVC) - target_compile_options(lidar_odometry_step_1_legacy PRIVATE /bigobj) -endif() - -hdmapping_install_app(lidar_odometry_step_1_legacy) diff --git a/apps/lidar_odometry_step_1_legacy/icon.ico b/apps/lidar_odometry_step_1_legacy/icon.ico deleted file mode 100644 index 14e65190..00000000 Binary files a/apps/lidar_odometry_step_1_legacy/icon.ico and /dev/null differ diff --git a/apps/lidar_odometry_step_1_legacy/lidar_odometry_gui.cpp b/apps/lidar_odometry_step_1_legacy/lidar_odometry_gui.cpp deleted file mode 100644 index 40e1531f..00000000 --- a/apps/lidar_odometry_step_1_legacy/lidar_odometry_gui.cpp +++ /dev/null @@ -1,2835 +0,0 @@ -#include -#include -#include -#include - -#include - -#include -#include - -#include "lidar_odometry.h" -#include "lidar_odometry_utils.h" - -#include -#include -#include -#include -#include -#include - -#include "toml_io.h" -#include -#include -#include -#include -#include -#include - -#ifdef _WIN32 -#include "resource.h" -#include -#endif - -/////////////////////////////////////////////////////////////////////////////////// - -// This is LiDAR odometry (step 1) -// This program calculates trajectory based on IMU and LiDAR data provided by MANDEYE mobile mapping system -// https://github.com/JanuszBedkowski/mandeye_controller The output is a session proving trajekctory and point clouds that can be further -// processed by "multi_view_tls_registration" program. - -std::string winTitle = std::string("Step 1 (Lidar odometry) ") + HDMAPPING_CONFIGURE_PROJECT_VERSION; - -std::vector infoLines = { - "This program is first step in MANDEYE process.", - "", - "It results trajectory and point clouds as single session for 'multi_view_tls_registration_step_2' program.", - "", - "Next step will be to load session.json file with 'multi_view_tls_registration_step_2' program." -}; - -// App specific shortcuts (Type and Shortcut are just for easy reference) -static const std::vector appShortcuts = { { "Normal keys", "A", "" }, - { "", "Ctrl+A", "" }, - { "", "B", "" }, - { "", "Ctrl+B", "" }, - { "", "C", "" }, - { "", "Ctrl+C", "" }, - { "", "D", "" }, - { "", "Ctrl+D", "" }, - { "", "E", "" }, - { "", "Ctrl+E", "" }, - { "", "F", "" }, - { "", "Ctrl+F", "" }, - { "", "G", "" }, - { "", "Ctrl+G", "" }, - { "", "H", "" }, - { "", "Ctrl+H", "" }, - { "", "I", "" }, - { "", "Ctrl+I", "" }, - { "", "J", "" }, - { "", "Ctrl+K", "" }, - { "", "K", "" }, - { "", "Ctrl+K", "" }, - { "", "L", "" }, - { "", "Ctrl+L", "" }, - { "", "M", "" }, - { "", "Ctrl+M", "" }, - { "", "N", "" }, - { "", "Ctrl+N", "" }, - { "", "O", "" }, - { "", "Ctrl+O", "Open data" }, - { "", "P", "" }, - { "", "Ctrl+P", "" }, - { "", "Q", "" }, - { "", "Ctrl+Q", "" }, - { "", "R", "" }, - { "", "Ctrl+R", "" }, - { "", "Shift+R", "" }, - { "", "S", "" }, - { "", "Ctrl+S", "" }, - { "", "Ctrl+Shift+S", "" }, - { "", "T", "" }, - { "", "Ctrl+T", "" }, - { "", "U", "" }, - { "", "Ctrl+U", "" }, - { "", "V", "" }, - { "", "Ctrl+V", "" }, - { "", "W", "" }, - { "", "Ctrl+W", "" }, - { "", "X", "" }, - { "", "Ctrl+X", "" }, - { "", "Y", "" }, - { "", "Ctrl+Y", "" }, - { "", "Z", "" }, - { "", "Ctrl+Z", "" }, - { "", "Shift+Z", "" }, - { "", "1-9", "" }, - { "Special keys", "Up arrow", "" }, - { "", "Shift + up arrow", "" }, - { "", "Ctrl + up arrow", "" }, - { "", "Down arrow", "" }, - { "", "Shift + down arrow", "" }, - { "", "Ctrl + down arrow", "" }, - { "", "Left arrow", "" }, - { "", "Shift + left arrow", "" }, - { "", "Ctrl + left arrow", "" }, - { "", "Right arrow", "" }, - { "", "Shift + right arrow", "" }, - { "", "Ctrl + right arrow", "" }, - { "", "Pg down", "" }, - { "", "Pg up", "" }, - { "", "- key", "" }, - { "", "+ key", "" }, - { "Mouse related", "Left click + drag", "" }, - { "", "Right click + drag", "n" }, - { "", "Scroll", "" }, - { "", "Shift + scroll", "" }, - { "", "Shift + drag", "" }, - { "", "Ctrl + left click", "" }, - { "", "Ctrl + right click", "" }, - { "", "Ctrl + middle click", "" } }; - -namespace fs = std::filesystem; - -bool is_settings_gui = false; -bool full_debug_messages = false; -NDT ndt; -bool show_reference_buckets_indoor = false; -bool show_reference_buckets_outdoor = false; -bool show_reference_points = false; -int dec_reference_points = 100; -bool show_initial_points = true; -bool show_trajectory = true; -bool show_trajectory_as_axes = false; -bool show_prediction_vectors = false; -bool intermediate_trajectory_prediction_axes = false; -bool show_covs_indoor = false; -bool show_covs_outdoor = false; -int dec_covs = 10; -bool simple_gui = true; -bool step_1_done = false; -bool step_2_done = false; -bool step_3_done = false; -bool calculations_failed = false; -bool show_without_filtered_buckets = false; -bool show_normal_vectors_indoor = false; -bool show_normal_vectors_outdoor = false; - -int lastPar = 1; - -std::vector worker_data; - -std::string working_directory = ""; -bool initial_transformation_gizmo = false; - -float m_gizmo[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; - -float x_displacement = 0.01; - -int index_begin = -1; -int index_end = -1; -bool gizmo_stretch_interval = false; -Eigen::Affine3d stretch_gizmo_m = Eigen::Affine3d::Identity(); - -LidarOdometryParams params; -std::vector csv_files; -std::vector sn_files; -std::string imuSnToUse; -Session session; - -std::vector> pointsPerFile; -Imu imu_data; -Trajectory trajectory; -std::atomic loRunning{ false }; -std::atomic loProgress{ 0.0 }; -std::atomic loPause{ false }; -std::chrono::time_point loStartTime; -std::atomic loElapsedSeconds{ 0.0 }; -std::atomic loEstimatedTimeRemaining{ 0.0 }; - -fs::path outwd; - -#if _WIN32 -#define DEFAULT_PATH "C:\\" -#else -#define DEFAULT_PATH "~" -#endif - -/////////////////////////////////////////////////////////////////////////////////// - -void set_lidar_odometry_default_params(LidarOdometryParams& params) -{ - params.decimation = 0.01; - params.in_out_params_indoor.resolution_X = 0.1; - params.in_out_params_indoor.resolution_Y = 0.1; - params.in_out_params_indoor.resolution_Z = 0.1; - - params.in_out_params_outdoor.resolution_X = 0.3; - params.in_out_params_outdoor.resolution_Y = 0.3; - params.in_out_params_outdoor.resolution_Z = 0.3; - - params.filter_threshold_xy_inner = 0.3; - params.filter_threshold_xy_outer = 70.0; - params.threshould_output_filter = 0.3; - - params.use_robust_and_accurate_lidar_odometry = false; - params.distance_bucket = 0.2; - params.polar_angle_deg = 10.0; - params.azimutal_angle_deg = 10.0; - params.robust_and_accurate_lidar_odometry_iterations = 20; - - params.max_distance_lidar = 70.0; - params.nr_iter = 1000; - params.sliding_window_trajectory_length_threshold = 200; - params.real_time_threshold_seconds = 10; -} - -// Helper function to format time in human-readable format -std::string formatTime(double seconds) -{ - if (seconds < 0) - return "Calculating..."; - - int hours = static_cast(seconds / 3600); - int minutes = static_cast((seconds - hours * 3600) / 60); - int secs = static_cast(seconds - hours * 3600 - minutes * 60); - - std::ostringstream oss; - - if (hours > 0) - { - oss << std::setw(2) << std::setfill('0') << hours << "h "; - } - if (minutes > 0 || hours > 0) - { - oss << std::setw(2) << std::setfill('0') << minutes << "m "; - } - - oss << std::setw(2) << std::setfill('0') << secs << "s"; - - return oss.str(); -} - -// Helper function to format estimated completion time -std::string formatCompletionTime(double remainingSeconds) -{ - if (remainingSeconds < 0) - return "Calculating..."; - - auto now = std::chrono::system_clock::now(); - auto estimatedCompletion = now + std::chrono::seconds(static_cast(remainingSeconds)); - auto completion_time_t = std::chrono::system_clock::to_time_t(estimatedCompletion); - - // Format as HH:MM:SS - Cross-platform time formatting - struct tm completion_tm; -#ifdef _WIN32 - localtime_s(&completion_tm, &completion_time_t); -#else - localtime_r(&completion_time_t, &completion_tm); -#endif - - char timeStr[32]; - strftime(timeStr, sizeof(timeStr), "%H:%M", &completion_tm); - - return std::string(timeStr); -} - -#if 0 -std::vector> get_batches_of_points(std::string laz_file, int point_count_threshold, conststd::vector& prev_points) -{ - std::vector> res_points; - std::vector points = load_point_cloud(laz_file, false, 0, 10000, {}); - - std::vector tmp_points = prev_points; - int counter = tmp_points.size(); - for (size_t i = 0; i < points.size(); i++) - { - counter++; - tmp_points.push_back(points[i]); - if (counter > point_count_threshold) - { - res_points.push_back(tmp_points); - tmp_points.clear(); - counter = 0; - } - } - - if (tmp_points.size() > 0) - { - res_points.push_back(tmp_points); - } - return res_points; -} -#endif - -void find_best_stretch( - std::vector points, std::vector timestamps, std::vector poses, std::string fn1, std::string fn2) -{ - for (size_t i = 0; i < points.size(); i++) - { - auto lower = std::lower_bound(timestamps.begin(), timestamps.end(), points[i].timestamp); - points[i].index_pose = std::distance(timestamps.begin(), lower); - } - - std::set indexes; - - for (size_t i = 0; i < points.size(); i++) - { - indexes.insert(points[i].index_pose); - } - // build trajectory - std::vector trajectory; - std::vector ts; - - for (auto& s : indexes) - { - trajectory.push_back(poses[s]); - ts.push_back(timestamps[s]); - } - - std::cout << "trajectory.size() " << trajectory.size() << std::endl; - // Sleep(2000); - - std::vector points_reindexed = points; - for (size_t i = 0; i < points_reindexed.size(); i++) - { - points_reindexed[i].index_pose = get_index_in_set(indexes, points[i].index_pose); - } - /// - std::vector best_trajectory = trajectory; - uint64_t min_buckets = ULLONG_MAX; - - for (double x = 0.0; x < 0.2; x += 0.0005) - { - std::vector trajectory_stretched; - - Eigen::Affine3d m_x_offset = Eigen::Affine3d::Identity(); - m_x_offset(0, 3) = x; - - Eigen::Affine3d m = trajectory[0]; - trajectory_stretched.push_back(m); - for (size_t i = 1; i < trajectory.size(); i++) - { - Eigen::Affine3d m_update = trajectory[i - 1].inverse() * trajectory[i] * (m_x_offset); - m = m * m_update; - trajectory_stretched.push_back(m); - } - - NDT::GridParameters rgd_params; - rgd_params.resolution_X = 0.3; - rgd_params.resolution_Y = 0.3; - rgd_params.resolution_Z = 0.3; - NDTBucketMapType my_buckets; - - std::vector points_global = points_reindexed; - - std::vector points_global2; - - for (auto& p : points_global) - { - if (p.point.z() > 0) - { - p.point = trajectory_stretched[p.index_pose] * p.point; - points_global2.push_back(p); - // if (p.point.norm() > 6 && p.point.norm() < 15) - //{ - // points_global.push_back(p); - // } - } - } - std::scoped_lock lock(params.mutex_buckets_indoor, params.mutex_buckets_outdoor); - - update_rgd(rgd_params, my_buckets, points_global2, trajectory_stretched[0].translation()); - - std::cout << "number of buckets [" << x << "]: " << my_buckets.size() << std::endl; - if (my_buckets.size() < min_buckets) - { - min_buckets = my_buckets.size(); - best_trajectory = trajectory_stretched; - } - } - - std::map trajectory_for_interpolation; - for (size_t i = 0; i < best_trajectory.size(); i++) - { - trajectory_for_interpolation[ts[i]] = best_trajectory[i].matrix(); - } - - std::vector pointcloud_global; - std::vector intensity; - std::vector timestamps_; - for (const auto& p : points_reindexed) - { - Eigen::Matrix4d pose = getInterpolatedPose(trajectory_for_interpolation, p.timestamp); - Eigen::Affine3d b; - b.matrix() = pose; - Eigen::Vector3d vec = b * p.point; - pointcloud_global.push_back(vec); - intensity.push_back(p.intensity); - timestamps_.push_back(p.timestamp); - } - - std::cout << "saving file: " << fn1 << std::endl; - exportLaz(fn1, pointcloud_global, intensity, timestamps_); - - pointcloud_global.clear(); - for (const auto& p : points_reindexed) - { - Eigen::Vector3d vec = trajectory[p.index_pose] * p.point; - pointcloud_global.push_back(vec); - } - exportLaz(fn2, pointcloud_global, intensity, timestamps_); -} - -#if 0 -void alternative_approach() -{ - int point_count_threshold = 10000; - - std::cout << "aternative_approach" << std::endl; - - std::vector input_file_names; - input_file_names = mandeye::fd::OpenFileDialog("Load las files", {}, true); - std::sort(std::begin(input_file_names), std::end(input_file_names)); - - std::vector csv_files; - std::vector laz_files; - std::for_each(std::begin(input_file_names), std::end(input_file_names), [&](const std::string& fileName) - { - if (fileName.ends_with(".laz") || fileName.ends_with(".las")) - { - laz_files.push_back(fileName); - } - if (fileName.ends_with(".csv")) - { - csv_files.push_back(fileName); - } }); - - std::cout << "imu files: " << std::endl; - for (const auto& fn : csv_files) - { - std::cout << fn << std::endl; - } - - std::cout << "loading imu" << std::endl; - Imu imu_data; - - std::for_each(std::begin(csv_files), std::end(csv_files), [&imu_data](const std::string& fn) - { - auto imu = load_imu(fn.c_str(), 0); - std::cout << fn << std::endl; - imu_data.insert(std::end(imu_data), std::begin(imu), std::end(imu)); }); - - std::map trajectory; - int counter = 1; - const float RAD_TO_DEG = 180.0f / static_cast(M_PI); - - if (params.use_vqf) - { - double avg_dt = 1.0 / 200.0; - if (imu_data.size() >= 2) - { - double t0 = std::get<0>(imu_data.front()).first; - double t1 = std::get<0>(imu_data.back()).first; - if (t1 > t0) - avg_dt = (t1 - t0) / static_cast(imu_data.size() - 1); - } - - VQFParams vqf_params = buildVQFParams(params); - VQF vqf(vqf_params, avg_dt); - - for (const auto& [timestamp_pair, gyr, acc] : imu_data) - { - const double g = 9.80665; - vqf_real_t gyr_vqf[3] = { static_cast(gyr.x()), static_cast(gyr.y()), static_cast(gyr.z()) }; - vqf_real_t acc_vqf[3] = { static_cast(acc.x()) * g, static_cast(acc.y()) * g, static_cast(acc.z()) * g }; - - vqf.update(gyr_vqf, acc_vqf); - - vqf_real_t quat[4]; - if (params.vqf_useMagnetometer) - vqf.getQuat9D(quat); - else - vqf.getQuat6D(quat); - Eigen::Quaterniond d(quat[0], quat[1], quat[2], quat[3]); - Eigen::Affine3d t{ Eigen::Matrix4d::Identity() }; - t.rotate(d); - trajectory[timestamp_pair.first] = t.matrix(); - counter++; - if (counter % 100 == 0) - { - Eigen::Vector3d euler = d.toRotationMatrix().eulerAngles(0, 1, 2) * (180.0 / M_PI); - std::cout << "Roll " << euler.x() << ", Pitch " << euler.y() << ", Yaw " << euler.z() << " [" << counter << " of " << imu_data.size() << "]" << std::endl; - } - } - } - else - { - FusionAhrs ahrs; - FusionAhrsInitialise(&ahrs); - if (params.fusionConventionNwu) ahrs.settings.convention = FusionConventionNwu; - else if (params.fusionConventionEnu) ahrs.settings.convention = FusionConventionEnu; - else if (params.fusionConventionNed) ahrs.settings.convention = FusionConventionNed; - ahrs.settings.gain = params.fusion_gain; - - bool first = true; - double last_ts = 0.0; - - for (const auto& [timestamp_pair, gyr, acc] : imu_data) - { - const FusionVector gyroscope = { static_cast(gyr.x() * RAD_TO_DEG), - static_cast(gyr.y() * RAD_TO_DEG), - static_cast(gyr.z() * RAD_TO_DEG) }; - const FusionVector accelerometer = { acc.x(), acc.y(), acc.z() }; - - if (first) - { - FusionAhrsUpdateNoMagnetometer(&ahrs, gyroscope, accelerometer, 1.0f / 200.0f); - first = false; - } - else - { - float ts_diff = static_cast(timestamp_pair.first - last_ts); - if (ts_diff < 0.01f) - FusionAhrsUpdateNoMagnetometer(&ahrs, gyroscope, accelerometer, ts_diff); - else - FusionAhrsUpdateNoMagnetometer(&ahrs, gyroscope, accelerometer, 1.0f / 200.0f); - } - last_ts = timestamp_pair.first; - - FusionQuaternion quat = FusionAhrsGetQuaternion(&ahrs); - Eigen::Quaterniond d{ quat.element.w, quat.element.x, quat.element.y, quat.element.z }; - Eigen::Affine3d t{ Eigen::Matrix4d::Identity() }; - t.rotate(d); - trajectory[timestamp_pair.first] = t.matrix(); - counter++; - if (counter % 100 == 0) - { - const FusionEuler euler = FusionQuaternionToEuler(quat); - std::cout << "Roll " << euler.angle.roll << ", Pitch " << euler.angle.pitch << ", Yaw " << euler.angle.yaw - << " [" << counter << " of " << imu_data.size() << "]" << std::endl; - } - } - } - - /////////////////////////////////////////////////////////////////////////////// - std::cout << "point cloud file names" << std::endl; - for (const auto& fn : laz_files) - { - std::cout << fn << std::endl; - } - - std::vector prev_points; - std::vector> all_points; - std::vector> tmp_points = get_batches_of_points(laz_files[0], point_count_threshold, prev_points); - - for (size_t i = 0; i < tmp_points.size() - 1; i++) - { - all_points.push_back(tmp_points[i]); - } - - for (size_t i = 1; i < laz_files.size(); i++) - { - prev_points = tmp_points[tmp_points.size() - 1]; - tmp_points = get_batches_of_points(laz_files[i], point_count_threshold, prev_points); - for (size_t j = 0; j < tmp_points.size() - 1; j++) - { - all_points.push_back(tmp_points[j]); - } - } - - ////////// - std::vector timestamps; - std::vector poses; - for (const auto& t : trajectory) - { - timestamps.push_back(t.first); - Eigen::Affine3d m; - m.matrix() = t.second; - poses.push_back(m); - } - - for (size_t i = 0; i < all_points.size(); i++) - { - std::cout << all_points[i].size() << std::endl; - std::string fn1 = "C:/data/tmp/" + std::to_string(i) + "_best.laz"; - std::string fn2 = "C:/data/tmp/" + std::to_string(i) + "_original.laz"; - - find_best_stretch(all_points[i], timestamps, poses, fn1, fn2); - } -} -#endif - -Eigen::Vector3d GLWidgetGetOGLPos(int x, int y, const ObservationPicking& observation_picking) -{ - const auto laser_beam = GetLaserBeam(x, y); - - RegistrationPlaneFeature::Plane pl; - - pl.a = 0; - pl.b = 0; - pl.c = 1; - pl.d = -observation_picking.picking_plane_height; - - Eigen::Vector3d pos = rayIntersection(laser_beam, pl); - - std::cout << "intersection: " << pos.x() << " " << pos.y() << " " << pos.z() << std::endl; - - return pos; -} - -void step1(const std::atomic& loPause) -{ - 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)) - { - 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()); - - 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, full_debug_messages); - if (compute_step_1(pointsPerFile, params, trajectory, worker_data, loPause)) - { - release_raw_clouds(pointsPerFile, params); // nothing after step 1 reads them - step_1_done = true; - } - else - std::cerr << "Lidar odometry step 1 failed (see the messages above)" << std::endl; - } - 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(); - - exit(1); - } - } -} - -void step2(const std::atomic& loPause) -{ - double ts_failure = 0.0; - std::atomic parked{ false }; - if (compute_step_2(worker_data, params, ts_failure, loProgress, loPause, full_debug_messages, parked)) - step_2_done = true; - else - { - for (size_t fileNo = 0; fileNo < csv_files.size(); fileNo++) - { - const std::string& imufn = csv_files.at(fileNo); - const std::string snFn = (fileNo >= sn_files.size()) ? ("") : (sn_files.at(fileNo)); - const auto idToSn = MLvxCalib::GetIdToSnMapping(snFn); - // GetId of Imu to use - int imuNumberToUse = MLvxCalib::GetImuIdToUse(idToSn, imuSnToUse); - auto imu = load_imu(imufn.c_str(), imuNumberToUse); - - if (imu.size() > 0) - { - if (std::get<0>(imu[imu.size() - 1]).first > ts_failure) - break; - } - std::cout << "file: '" << imufn << "' [OK]" << std::endl; - } - calculations_failed = true; - } -} - -void save_results(bool info, double elapsed_seconds) -{ - outwd = get_next_result_path(working_directory); - save_result(worker_data, params, outwd, elapsed_seconds); - if (info) - { - std::string message_info = "Results saved to folder: '" + outwd.string() + "'"; - std::cout << message_info << std::endl; - [[maybe_unused]] pfd::message message("Information", message_info.c_str(), pfd::choice::ok, pfd::icon::info); - message.result(); - } -} - -void settings_gui() -{ - if (ImGui::Begin("Settings", &is_settings_gui)) - { - ImGui::Checkbox("simple_gui", &simple_gui); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Show even more parameters"); - - ImGui::NewLine(); - - if (!loRunning) - { - // TaitBryanPose motion_model_correction; - ImGui::Text("motion_model_correction [deg]:"); - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::InputDouble("om, rotation via X", ¶ms.motion_model_correction.om); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(omText); - ImGui::InputDouble("fi, rotation via Y", ¶ms.motion_model_correction.fi); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(fiText); - ImGui::InputDouble("ka, rotation via Z", ¶ms.motion_model_correction.ka); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(kaText); - ImGui::PopItemWidth(); - - if (ImGui::Button("Set example")) - { - params.motion_model_correction.om = 0.0; - params.motion_model_correction.fi = 0.05; - params.motion_model_correction.ka = 0.0; - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("motion_model_corrections for LiDAR X-axis (forward direction)"); - - ImGui::NewLine(); - - ImGui::Text("lidar_odometry_motion_model sigmas [m] / [deg]:"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("position/rotational uncertainties"); - - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::InputDouble("x_1", ¶ms.lidar_odometry_motion_model_x_1_sigma_m, 0.0, 0.0, "%.4f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(xText); - ImGui::SameLine(); - ImGui::InputDouble("om_1", ¶ms.lidar_odometry_motion_model_om_1_sigma_deg, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(omText); - - ImGui::InputDouble("y_1", ¶ms.lidar_odometry_motion_model_y_1_sigma_m, 0.0, 0.0, "%.4f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(yText); - ImGui::SameLine(); - ImGui::InputDouble("fi_1", ¶ms.lidar_odometry_motion_model_fi_1_sigma_deg, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(fiText); - - ImGui::InputDouble("z_1", ¶ms.lidar_odometry_motion_model_z_1_sigma_m, 0.0, 0.0, "%.4f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(zText); - ImGui::SameLine(); - ImGui::InputDouble("ka_1", ¶ms.lidar_odometry_motion_model_ka_1_sigma_deg, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(kaText); - - ImGui::PopItemWidth(); - - ImGui::Text("lidar_odometry_motion_model_fix_origin sigmas [m] / [deg]:"); - - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::InputDouble("x_1##o", ¶ms.lidar_odometry_motion_model_fix_origin_x_1_sigma_m); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(xText); - ImGui::SameLine(); - ImGui::InputDouble("om_1##o", ¶ms.lidar_odometry_motion_model_fix_origin_om_1_sigma_deg); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(omText); - - ImGui::InputDouble("y_1##o", ¶ms.lidar_odometry_motion_model_fix_origin_y_1_sigma_m); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(yText); - ImGui::SameLine(); - ImGui::InputDouble("fi_1##o", ¶ms.lidar_odometry_motion_model_fix_origin_fi_1_sigma_deg); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(fiText); - - ImGui::InputDouble("z_1##o", ¶ms.lidar_odometry_motion_model_fix_origin_z_1_sigma_m); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(zText); - ImGui::SameLine(); - ImGui::InputDouble("ka_1##o", ¶ms.lidar_odometry_motion_model_fix_origin_ka_1_sigma_deg); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(kaText); - - ImGui::PopItemWidth(); - } - - ImGui::NewLine(); - - if (!simple_gui) - { - ImGui::SetNextItemWidth(ImGuiNumberWidth); - ImGui::InputInt("Threshold nr poses", ¶ms.threshold_nr_poses); - if (params.threshold_nr_poses < 1) - { - params.threshold_nr_poses = 1; - } - - ImGui::NewLine(); - } - - // ImGui::Checkbox("show_all_points", &show_all_points); - - if (calculations_failed) - { - ImGui::Text("CALCULATIONS FAILED... please read information in console"); - ImGui::End(); - return; - } - - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::InputDouble("Filter threshold XY inner [m]", ¶ms.filter_threshold_xy_inner, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text("all local points inside lidar xy_circle radius will be removed during load"); - ImGui::Text("Minimum value is given by Lidar's specs (Close Proximity Blind Zone)"); - ImGui::Text("Value can be higher to filter out close range permanent obstacles"); - ImGui::Text("e.g.: 0.1[m] for Livox Mid-360"); - ImGui::EndTooltip(); - } - ImGui::InputDouble("Filter threshold XY outer [m]", ¶ms.filter_threshold_xy_outer, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text("all local points outside lidar xy_circle radius will be removed during load"); - ImGui::Text("Maximum value is given by Lidar's specs (Detection Range)"); - ImGui::Text("Value can be lower to adapt for different reflectivity or real world contrains"); - ImGui::Text("e.g.: 70[m] @ 80%% reflectivity for Livox Mid-360"); - ImGui::EndTooltip(); - } - ImGui::InputDouble("Threshold output filter [m]", ¶ms.threshould_output_filter, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("all local points inside lidar xy_circle radius will be removed during save"); - ImGui::PopItemWidth(); - - if (!simple_gui) - { - ImGui::NewLine(); - ImGui::Text("NDT bucket size (inner/outer)"); - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::InputDouble("##x", ¶ms.in_out_params_indoor.resolution_X, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(xText); - if (params.in_out_params_indoor.resolution_X < 0.01) - { - params.in_out_params_indoor.resolution_X = 0.01; - } - ImGui::SameLine(); - ImGui::InputDouble("X##ndt", ¶ms.in_out_params_outdoor.resolution_X, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(xText); - if (params.in_out_params_outdoor.resolution_X < 0.01) - { - params.in_out_params_outdoor.resolution_X = 0.01; - } - - ImGui::InputDouble("##y", ¶ms.in_out_params_indoor.resolution_Y, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(yText); - if (params.in_out_params_indoor.resolution_Y < 0.01) - { - params.in_out_params_indoor.resolution_Y = 0.01; - } - ImGui::SameLine(); - ImGui::InputDouble("Y##ndt", ¶ms.in_out_params_outdoor.resolution_Y, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(yText); - if (params.in_out_params_outdoor.resolution_Y < 0.01) - { - params.in_out_params_outdoor.resolution_Y = 0.01; - } - - ImGui::InputDouble("##z", ¶ms.in_out_params_indoor.resolution_Z, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(zText); - if (params.in_out_params_indoor.resolution_Z < 0.01) - { - params.in_out_params_indoor.resolution_Z = 0.01; - } - ImGui::SameLine(); - ImGui::InputDouble("Z##ndt", ¶ms.in_out_params_outdoor.resolution_Z, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(zText); - if (params.in_out_params_outdoor.resolution_Z < 0.01) - { - params.in_out_params_outdoor.resolution_Z = 0.01; - } - - ImGui::NewLine(); - - ImGui::InputDouble("Downsampling", ¶ms.decimation, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Larger value of downsampling better performance, but worse accuracy"); - - ImGui::InputDouble("Max distance of processed points [m]", ¶ms.max_distance_lidar, 0.0, 0.0, "%.2f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Local LiDAR coordinates"); - - ImGui::InputInt("Number of iterations", ¶ms.nr_iter); - ImGui::InputDouble( - "Sliding window trajectory length threshold [m]", ¶ms.sliding_window_trajectory_length_threshold, 0.0, 0.0, "%.2f"); - ImGui::InputInt("Threshold initial points", ¶ms.threshold_initial_points); - - ImGui::NewLine(); - - // AHRS type selection - ImGui::Checkbox("Use VQF (instead of Fusion/Madgwick)", ¶ms.use_vqf); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Unchecked = Fusion (Madgwick complementary filter, default)\nChecked = VQF (Versatile Quaternion-based Filter)"); - - if (!params.use_vqf) - { - // Fusion-specific parameters - static int fusionConvention; // 0=NWU, 1=ENU, 2=NED - if (fusionConvention < 0 || fusionConvention > 2) - fusionConvention = 0; - - ImGui::Text("Fusion convention: "); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Coordinate system conventions for sensor fusion defining how the axes are oriented relative to world frame"); - - ImGui::SameLine(); - ImGui::RadioButton("NWU", &fusionConvention, 0); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("North West Up"); - ImGui::SameLine(); - ImGui::RadioButton("ENU", &fusionConvention, 1); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("East North Up"); - ImGui::SameLine(); - ImGui::RadioButton("NED", &fusionConvention, 2); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("North East Down"); - - params.fusionConventionNwu = (fusionConvention == 0); - params.fusionConventionEnu = (fusionConvention == 1); - params.fusionConventionNed = (fusionConvention == 2); - - ImGui::InputDouble("Fusion gain", ¶ms.fusion_gain, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Complementary filter gain (0-1). Higher = more accelerometer trust."); - } - - ImGui::NewLine(); - - ImGui::Checkbox("Use motion from previous step", ¶ms.use_motion_from_previous_step); - ImGui::Checkbox("Lidar-only odometry (no IMU)", ¶ms.lidar_only_odometry); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Predict each window's rotation and translation from the previous one (constant velocity) instead of from " - "the IMU. For recordings without a usable IMU, e.g. a synthetic stationary one."); - ImGui::Checkbox("Use IMU preintegration", ¶ms.use_imu_preintegration); - if (params.use_imu_preintegration) - { - const char* methods[] = { "Euler, no gravity comp., SM velocity", "Trapezoidal, no gravity comp., SM velocity", - "Euler, gravity comp., SM velocity", "Trapezoidal, gravity comp., SM velocity", - "Kalman, gravity comp., SM velocity", "Euler, gravity comp., AHRS velocity", - "Trapezoidal, gravity comp., AHRS velocity", "Kalman, gravity comp., AHRS velocity" }; - ImGui::Combo("IMU preintegration method", ¶ms.imu_preintegration_method, methods, IM_ARRAYSIZE(methods)); - } - if (params.use_vqf) - { - ImGui::InputDouble("VQF tauAcc [s]", ¶ms.vqf_tauAcc, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text("VQF accelerometer time constant (tauAcc) in seconds."); - ImGui::Text("Controls how strongly accelerometer corrects the gyroscope-based orientation."); - ImGui::Text("Higher = more gyro trust (stable but may drift). Lower = more acc trust (noisy but no drift)."); - ImGui::EndTooltip(); - } - - if (ImGui::TreeNode("VQF Gyro Bias Estimation")) - { - ImGui::Checkbox("Motion bias estimation", ¶ms.vqf_motionBiasEstEnabled); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Enables gyroscope bias estimation during motion phases,\nbased on the inclination correction only (without " - "magnetometer)."); - - if (params.vqf_motionBiasEstEnabled) - { - ImGui::InputDouble("Bias sigma motion [deg/s]", ¶ms.vqf_biasSigmaMotion, 0.0, 0.0, "%.4f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Std dev of converged bias estimation uncertainty during motion.\nDetermines trust on motion bias " - "estimation " - "updates.\nSmall value leads to fast convergence. Default: 0.1"); - ImGui::InputDouble("Bias vertical forgetting", ¶ms.vqf_biasVerticalForgettingFactor, 0.0, 0.0, "%.6f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Forgetting factor for unobservable bias in vertical direction during motion.\nGyro bias is not observable " - "vertically without magnetometer.\nRelative weight of artificial zero measurement ensuring\nbias estimate " - "decays to zero. Default: 0.0001"); - } - - ImGui::InputDouble("Bias sigma init [deg/s]", ¶ms.vqf_biasSigmaInit, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Std dev of the initial bias estimation uncertainty. Default: 0.5 deg/s"); - ImGui::InputDouble("Bias forgetting time [s]", ¶ms.vqf_biasForgettingTime, 0.0, 0.0, "%.1f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Time in which bias estimation uncertainty increases from 0 to 0.1 deg/s.\nDetermines the system noise assumed " - "by " - "the Kalman filter. Default: 100.0"); - ImGui::InputDouble("Bias clip [deg/s]", ¶ms.vqf_biasClip, 0.0, 0.0, "%.2f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Maximum expected gyroscope bias.\nUsed to clip bias estimate and measurement error in update step.\nAlso used " - "by " - "rest detection to not regard large constant angular rate as rest.\nDefault: 2.0"); - - ImGui::Checkbox("Rest bias estimation", ¶ms.vqf_restBiasEstEnabled); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Enables rest detection and gyroscope bias estimation during rest phases.\nDuring rest, gyro bias is estimated " - "from low-pass filtered gyro readings."); - - if (params.vqf_restBiasEstEnabled) - { - ImGui::InputDouble("Bias sigma rest [deg/s]", ¶ms.vqf_biasSigmaRest, 0.0, 0.0, "%.4f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Std dev of converged bias estimation uncertainty during rest.\nDetermines trust on rest bias estimation " - "updates.\nSmall value leads to fast convergence. Default: 0.03"); - ImGui::InputDouble("Rest min time [s]", ¶ms.vqf_restMinT, 0.0, 0.0, "%.2f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Time threshold for rest detection.\nRest is detected when measurements have been close to\nthe low-pass " - "filtered reference for the given time. Default: 1.5"); - ImGui::InputDouble("Rest filter tau [s]", ¶ms.vqf_restFilterTau, 0.0, 0.0, "%.2f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Time constant for the second-order Butterworth low-pass filter\nused to obtain the reference for rest " - "detection. Default: 0.5"); - ImGui::InputDouble("Rest threshold gyro [deg/s]", ¶ms.vqf_restThGyr, 0.0, 0.0, "%.2f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Angular velocity threshold for rest detection.\nDeviation norm between measurement and reference must be " - "below threshold.\nEach component must also be below biasClip. Default: 2.0"); - ImGui::InputDouble("Rest threshold acc [m/s2]", ¶ms.vqf_restThAcc, 0.0, 0.0, "%.2f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Acceleration threshold for rest detection.\nDeviation norm between measurement and reference must be " - "below threshold.\nDefault: 0.5"); - } - - ImGui::TreePop(); - } - - ImGui::Checkbox("Use magnetometer", ¶ms.vqf_useMagnetometer); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Enable 9D mode (gyro+acc+mag) for absolute heading correction.\nDefault: off (6D mode, gyro+acc only, heading " - "from " - "gyro integration)."); - - if (params.vqf_useMagnetometer && ImGui::TreeNode("VQF Magnetometer")) - { - ImGui::InputDouble("tauMag [s]", ¶ms.vqf_tauMag, 0.0, 0.0, "%.2f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Time constant for magnetometer update.\nSmall values imply trust on magnetometer, large values trust on " - "gyroscope.\nCorresponds to cutoff frequency of first-order LP filter\nfor heading correction. Default: 9.0"); - ImGui::Checkbox("Mag disturbance rejection", ¶ms.vqf_magDistRejectionEnabled); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Enables magnetic disturbance detection and rejection.\nFor short disturbances, mag correction is fully " - "disabled.\nFor long disturbances (>magMaxRejectionTime), correction uses\nincreased time constant " - "(magRejectionFactor)."); - ImGui::InputDouble("Mag current tau [s]", ¶ms.vqf_magCurrentTau, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Time constant for current norm/dip value in disturbance detection.\nFast LP filter for robustness with noisy " - "or " - "async mag measurements.\nSet to -1 to disable. Default: 0.05"); - ImGui::InputDouble("Mag ref tau [s]", ¶ms.vqf_magRefTau, 0.0, 0.0, "%.1f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Time constant for adjustment of the magnetic field reference.\nAllows reference to converge to observed " - "undisturbed field. Default: 20.0"); - ImGui::InputDouble("Mag norm threshold", ¶ms.vqf_magNormTh, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Relative threshold for magnetic field strength for disturbance detection.\nRelative to the reference norm. " - "Default: 0.1 (10%%)"); - ImGui::InputDouble("Mag dip threshold [deg]", ¶ms.vqf_magDipTh, 0.0, 0.0, "%.1f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Threshold for the magnetic field dip angle for disturbance detection. Default: 10.0"); - ImGui::InputDouble("Mag new time [s]", ¶ms.vqf_magNewTime, 0.0, 0.0, "%.1f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Duration after which to accept a different homogeneous magnetic field.\nNew reference accepted when within " - "magNormTh and magDipTh for this time.\nOnly phases with sufficient movement (magNewMinGyr) count. Default: " - "20.0"); - ImGui::InputDouble("Mag new first time [s]", ¶ms.vqf_magNewFirstTime, 0.0, 0.0, "%.1f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Duration after which to accept a homogeneous magnetic field for the first time.\nUsed instead of magNewTime " - "when " - "no current estimate exists,\nto allow faster initial reference acquisition. Default: 5.0"); - ImGui::InputDouble("Mag new min gyro [deg/s]", ¶ms.vqf_magNewMinGyr, 0.0, 0.0, "%.1f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Minimum angular velocity needed to count time for new mag field acceptance.\nPeriods with angular velocity " - "norm " - "below this threshold\ndo not count towards magNewTime. Default: 20.0"); - ImGui::InputDouble("Mag min undisturbed [s]", ¶ms.vqf_magMinUndisturbedTime, 0.0, 0.0, "%.2f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Minimum duration within thresholds after which to regard\nthe field as undisturbed again. Default: 0.5"); - ImGui::InputDouble("Mag max rejection [s]", ¶ms.vqf_magMaxRejectionTime, 0.0, 0.0, "%.1f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Maximum duration of full magnetic disturbance rejection.\nUp to this duration, heading correction is fully " - "disabled\nand tracked by gyroscope only. After this, correction uses\nincreased time constant " - "(magRejectionFactor). Default: 60.0"); - ImGui::InputDouble("Mag rejection factor", ¶ms.vqf_magRejectionFactor, 0.0, 0.0, "%.2f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Factor by which to slow heading correction during long disturbed phases.\nAfter magMaxRejectionTime of full " - "rejection, correction uses\nthis factor to increase the time constant. Default: 2.0"); - ImGui::TreePop(); - } - } // end if (params.use_vqf) - - ImGui::PopItemWidth(); - } - ImGui::NewLine(); - if (!step_1_done) - { - if (ImGui::Button("Load data")) - { - loStartTime = std::chrono::system_clock::now(); - - step1(loPause); - std::cout << "Load data done please click 'Compute all' to continue calculations" << std::endl; - - std::chrono::duration elapsed = std::chrono::system_clock::now() - loStartTime; - double elapsedSeconds = elapsed.count(); - - std::cout << "Elapsed time: " << formatTime(elapsedSeconds).c_str() << std::endl; - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "Select folder containing IMU *.csv and LiDAR *.laz files produced by MANDEYE (e.g.: 'continousScanning_*')"); - } - if (step_1_done && !step_2_done) - { - if (ImGui::Button("Compute all")) - step2(loPause); - - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Press this button for automatic LiDAR odometry calculation -> it will produce trajectory"); - } - - if (step_1_done && step_2_done) - { - if (ImGui::Button("Point cloud consistency and trajectory smoothness")) - run_consistency(worker_data, params); - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text("This process makes trajectory smooth, point cloud will be more consistent"); - ImGui::Text("Press optionally before pressing 'Save result'"); - ImGui::EndTooltip(); - } - - ImGui::SameLine(); - ImGui::Checkbox("Use multiple Gaussians for each bucket", ¶ms.use_mutliple_gaussian); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Multiple Gaussians suppose to work better in floor plan indoor scenarios (multiple neighbouring rooms)"); - - if (ImGui::Button("Save result")) - save_results(true, 0.0); - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text("Press this button for saving resulting trajectory and point clouds"); - ImGui::Text("as single session for 'multi_view_tls_registration_step_2' program"); - ImGui::EndTooltip(); - } - } - if (step_1_done && step_2_done) - { - if (ImGui::Button("Save all point clouds to single las/laz file")) - { - const auto output_file_name = mandeye::fd::SaveFileDialog("Save las/laz file", mandeye::fd::LAS_LAZ_filter, ".laz"); - - if (output_file_name.size() > 0) - { - session.fill_session_from_worker_data(worker_data, false, true, true, params.threshould_output_filter); - // save_all_to_las(session, output_file_name, false); - save_all_to_las(session, output_file_name, true, true); - } - } - } - if (!simple_gui) - { - ImGui::NewLine(); - ImGui::Checkbox("Use robust and accurate lidar odometry", ¶ms.use_robust_and_accurate_lidar_odometry); - - if (params.use_robust_and_accurate_lidar_odometry) - { - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::InputDouble("Distance bucket [m]", ¶ms.distance_bucket, 0.0, 0.0, "%.3f"); - ImGui::InputDouble("Polar angle [deg]", ¶ms.polar_angle_deg, 0.0, 0.0, "%.3f"); - ImGui::InputDouble("Azimutal angle [deg]", ¶ms.azimutal_angle_deg, 0.0, 0.0, "%.3f"); - ImGui::InputInt("Number of iterations", ¶ms.robust_and_accurate_lidar_odometry_iterations); - // ImGui::InputDouble("Max distance lidar", ¶ms.max_distance_lidar); - ImGui::PopItemWidth(); - } - - ImGui::NewLine(); - - ImGui::Text("Rigid ICP using spherical coordinates"); - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::InputDouble("Distance bucket [m]##ricp", ¶ms.distance_bucket_rigid_sf, 0.0, 0.0, "%.3f"); - ImGui::InputDouble("Polar angle [deg]##ricp", ¶ms.polar_angle_deg_rigid_sf, 0.0, 0.0, "%.3f"); - ImGui::InputDouble("azimutal angle [deg]##ricp", ¶ms.azimutal_angle_deg_rigid_sf, 0.0, 0.0, "%.3f"); - ImGui::InputInt("Number of iterations##ricp", ¶ms.robust_and_accurate_lidar_odometry_rigid_sf_iterations); - ImGui::InputDouble("Max distance [m]##ricp", ¶ms.max_distance_lidar_rigid_sf, 0.0, 0.0, "%.2f"); - ImGui::PopItemWidth(); - - ImGui::NewLine(); - - ImGui::Text("Rigid spherical feature sigmas [m] / [deg]:"); - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::InputDouble("x##rgdsfs", ¶ms.rgd_sf_sigma_x_m, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(xText); - ImGui::SameLine(); - ImGui::InputDouble("om##rgdsfs", ¶ms.rgd_sf_sigma_om_deg, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(omText); - - ImGui::InputDouble("y##rgdsfs", ¶ms.rgd_sf_sigma_y_m, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(yText); - ImGui::SameLine(); - ImGui::InputDouble("fi##rgdsfs", ¶ms.rgd_sf_sigma_fi_deg, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(fiText); - - ImGui::InputDouble("z##rgdsfs", ¶ms.rgd_sf_sigma_z_m, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(zText); - ImGui::SameLine(); - ImGui::InputDouble("ka##rgdsfs", ¶ms.rgd_sf_sigma_ka_deg, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(kaText); - - ImGui::PopItemWidth(); - - ImGui::NewLine(); - - if (ImGui::Button("Save trajectory to ASCII (x y z)")) - { - std::string output_file_name = ""; - output_file_name = mandeye::fd::SaveFileDialog("Save trajectory", {}, ""); - std::cout << "File to save: '" << output_file_name << "'" << std::endl; - - if (output_file_name.size() > 0) - { - save_trajectory_to_ascii(worker_data, output_file_name); - } - } - - ImGui::NewLine(); - ImGui::Text("Reference point clouds for initial alignment:"); - - static std::vector input_file_names; - - if (ImGui::Button("Load laz/las files")) - { - input_file_names = mandeye::fd::OpenFileDialog("Load laz/las files", mandeye::fd::LAS_LAZ_filter, true); - if (input_file_names.size() > 0) - { - show_reference_points = true; - load_reference_point_clouds(input_file_names, params); - } - } - - if (ImGui::Button("Set parameters for drone with Ouster (https://ntu-aris.github.io/ntu_viral_dataset/)")) - { - params.decimation = 1.0; - params.in_out_params_indoor.resolution_X = 1.0; - params.in_out_params_indoor.resolution_Y = 1.0; - params.in_out_params_indoor.resolution_Z = 1.0; - - params.in_out_params_outdoor.resolution_X = 2.0; - params.in_out_params_outdoor.resolution_Y = 2.0; - params.in_out_params_outdoor.resolution_Z = 2.0; - } - - if (!input_file_names.empty()) - { - ImGui::Checkbox("Show points", &show_reference_points); - ImGui::SameLine(); - // ImGui::Checkbox("Show buckets ", &show_reference_buckets); - ImGui::SetNextItemWidth(ImGuiNumberWidth); - ImGui::InputInt("Downsamplingn###ref", &dec_reference_points); - - if (ImGui::Button("Filter reference buckets")) - { - filter_reference_buckets(params); - } - } - - if (params.initial_points.size() > 0) - { - ImGui::NewLine(); - ImGui::Text("Manipulate initial transformation:"); - ImGui::Checkbox("Show gizmo", &initial_transformation_gizmo); - // gizmo_stretch_interval - if (initial_transformation_gizmo) - { - m_gizmo[0] = (float)params.m_g(0, 0); - m_gizmo[1] = (float)params.m_g(1, 0); - m_gizmo[2] = (float)params.m_g(2, 0); - m_gizmo[3] = (float)params.m_g(3, 0); - m_gizmo[4] = (float)params.m_g(0, 1); - m_gizmo[5] = (float)params.m_g(1, 1); - m_gizmo[6] = (float)params.m_g(2, 1); - m_gizmo[7] = (float)params.m_g(3, 1); - m_gizmo[8] = (float)params.m_g(0, 2); - m_gizmo[9] = (float)params.m_g(1, 2); - m_gizmo[10] = (float)params.m_g(2, 2); - m_gizmo[11] = (float)params.m_g(3, 2); - m_gizmo[12] = (float)params.m_g(0, 3); - m_gizmo[13] = (float)params.m_g(1, 3); - m_gizmo[14] = (float)params.m_g(2, 3); - m_gizmo[15] = (float)params.m_g(3, 3); - } - else - { - if (ImGui::Button("Align to reference")) - { - for (int i = 0; i < 30; i++) - { - align_to_reference(params.in_out_params_indoor, params.initial_points, params.m_g, params.buckets_indoor); - } - } - } - } - - if (worker_data.size() > 0) - { - ImGui::NewLine(); - - ImGui::Text("Scans selection:"); - - ImGui::Text("index from: "); - ImGui::SameLine(); - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::SliderInt("##fs", &index_begin, 0, index_end); - ImGui::SameLine(); - ImGui::InputInt("##fi", &index_begin, 1, 5); - if (index_begin < 0) - index_begin = 0; - if (index_begin >= index_end) - index_begin = std::min(index_end, static_cast(worker_data.size() - 1)); - - ImGui::SameLine(); - ImGui::Text(" to: "); - ImGui::SameLine(); - - int prev = index_end; - ImGui::SliderInt("##ts", &index_end, index_begin, static_cast(worker_data.size() - 1)); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("max %zu", worker_data.size() - 1); - ImGui::SameLine(); - ImGui::InputInt("##ti", &index_end, 1, 5); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("max %zu", worker_data.size() - 1); - if (index_end < index_begin) - index_end = index_begin; - if (index_end >= worker_data.size() - 1) - index_end = worker_data.size() - 1; - if (prev != index_end) - { - stretch_gizmo_m = worker_data[index_end].intermediate_trajectory[0]; - } - - ImGui::PopItemWidth(); - - ImGui::Text("Selection: "); - if (ImGui::Button("Select all")) - { - for (size_t k = 0; k < worker_data.size(); k++) - { - worker_data[k].show = true; - } - } - ImGui::SameLine(); - if (ImGui::Button("Unselect")) - { - for (size_t k = 0; k < worker_data.size(); k++) - { - worker_data[k].show = false; - } - } - - ImGui::Text("Select scans from range:"); - ImGui::SameLine(); - if (ImGui::Button("")) - { - for (size_t k = 0; k < worker_data.size(); k++) - worker_data[k].show = (k >= index_begin && k <= index_end); - } - - if (ImGui::Button("")) - { - if (index_begin > 1 && index_end > 1) - { - index_begin--; - index_end--; - - for (size_t k = 0; k < worker_data.size(); k++) - worker_data[k].show = (k >= index_begin && k <= index_end); - } - } - ImGui::SameLine(); - if (ImGui::Button("")) - { - if (index_begin + 1 < worker_data.size() && index_end + 1 < worker_data.size()) - { - index_begin++; - index_end++; - - for (size_t k = 0; k < worker_data.size(); k++) - worker_data[k].show = (k >= index_begin && k <= index_end); - } - } - - if (ImGui::Button("from - 10, to - 10>")) - { - if (index_begin > 10 && index_end > 10) - { - index_begin -= 10; - index_end -= 10; - - for (size_t k = 0; k < worker_data.size(); k++) - worker_data[k].show = (k >= index_begin && k <= index_end); - } - } - ImGui::SameLine(); - if (ImGui::Button("")) - { - if (index_begin + 10 < worker_data.size() && index_end + 10 < worker_data.size()) - { - index_begin += 10; - index_end += 10; - - for (size_t k = 0; k < worker_data.size(); k++) - worker_data[k].show = (k >= index_begin && k <= index_end); - } - } - - if (ImGui::Button("Export selected scans")) - { - auto output_file_name = mandeye::fd::SaveFileDialog("Save las/laz file", mandeye::fd::LAS_LAZ_filter, ".laz"); - Eigen::Affine3d pose; - if (output_file_name.size() > 0) - { - session.fill_session_from_worker_data(worker_data, true, false, false, params.threshould_output_filter); - save_all_to_las(session, output_file_name, false, true); - } - // TODO: give value to pose even if output_file_name is wrong - - std::cout << "----------------------------------------" << std::endl; - std::cout << "please add following lines to RESSO file:" << std::endl; - std::cout << fs::path(output_file_name).filename() << "(!!!please remove brackets!!!)" << std::endl; - std::cout << pose.matrix() << std::endl; - - std::cout << "example RESSO file" << std::endl; - std::cout << ".................................................." << std::endl; - std::cout << "3" << std::endl - << "scan_0.laz" << std::endl - << "0.999775 0.000552479 -0.0212158 -0.0251188" << std::endl - << "0.000834612 0.997864 0.0653156 -0.0381429" << std::endl - << "0.0212066 - 0.0653186 0.997639 -0.000757752" - << "0 0 0 1" << std::endl - << "scan_1.laz" << std::endl - << "0.999783 0.00178963 -0.0207603 -0.0309683" << std::endl - << "-0.000467341 0.99798 0.0635239 -0.0517512" << std::endl - << "0.0208321 -0.0635004 0.997764 0.00331449" << std::endl - << "0 0 0 1" << std::endl - << "scan_2.laz" << std::endl - << "0.999783 0.00163449 -0.0207736 -0.0309985" << std::endl - << "-0.000312224 0.997982 0.0634957 -0.0506113" << std::endl - << "0.0208355 -0.0634754 0.997766 0.0028499" << std::endl - << "0 0 0 1" << std::endl; - std::cout << "................................................." << std::endl; - } - - ImGui::SameLine(); - - if (ImGui::Button("Save RESSO file")) - { - auto output_file_name = mandeye::fd::SaveFileDialog("Save RESSO file", {}, ""); - std::cout << "RESSO file to save: '" << output_file_name << "'" << std::endl; - - if (output_file_name.size() > 0) - { - session.point_clouds_container.save_poses(fs::path(output_file_name).string(), false); - } - } - - if (index_end > index_begin) - { - ImGui::Separator(); - ImGui::Checkbox("Gizmo_stretch_interval", &gizmo_stretch_interval); - } - - // gizmo_stretch_interval - if (gizmo_stretch_interval) - { - if (index_end < worker_data.size()) - { - if (worker_data[index_end].intermediate_trajectory.size() > 0) - { - m_gizmo[0] = (float)stretch_gizmo_m(0, 0); - m_gizmo[1] = (float)stretch_gizmo_m(1, 0); - m_gizmo[2] = (float)stretch_gizmo_m(2, 0); - m_gizmo[3] = (float)stretch_gizmo_m(3, 0); - m_gizmo[4] = (float)stretch_gizmo_m(0, 1); - m_gizmo[5] = (float)stretch_gizmo_m(1, 1); - m_gizmo[6] = (float)stretch_gizmo_m(2, 1); - m_gizmo[7] = (float)stretch_gizmo_m(3, 1); - m_gizmo[8] = (float)stretch_gizmo_m(0, 2); - m_gizmo[9] = (float)stretch_gizmo_m(1, 2); - m_gizmo[10] = (float)stretch_gizmo_m(2, 2); - m_gizmo[11] = (float)stretch_gizmo_m(3, 2); - m_gizmo[12] = (float)stretch_gizmo_m(0, 3); - m_gizmo[13] = (float)stretch_gizmo_m(1, 3); - m_gizmo[14] = (float)stretch_gizmo_m(2, 3); - m_gizmo[15] = (float)stretch_gizmo_m(3, 3); - } - } - - if (ImGui::Button("Accept Gizmo (only translation)")) - { - if (index_end < worker_data.size()) - { - if (worker_data[index_end].intermediate_trajectory.size() > 0) - { - Eigen::Affine3d current_gizmo = Eigen::Affine3d::Identity(); - current_gizmo(0, 0) = m_gizmo[0]; - current_gizmo(1, 0) = m_gizmo[1]; - current_gizmo(2, 0) = m_gizmo[2]; - current_gizmo(3, 0) = m_gizmo[3]; - current_gizmo(0, 1) = m_gizmo[4]; - current_gizmo(1, 1) = m_gizmo[5]; - current_gizmo(2, 1) = m_gizmo[6]; - current_gizmo(3, 1) = m_gizmo[7]; - current_gizmo(0, 2) = m_gizmo[8]; - current_gizmo(1, 2) = m_gizmo[9]; - current_gizmo(2, 2) = m_gizmo[10]; - current_gizmo(3, 2) = m_gizmo[11]; - current_gizmo(0, 3) = m_gizmo[12]; - current_gizmo(1, 3) = m_gizmo[13]; - current_gizmo(2, 3) = m_gizmo[14]; - current_gizmo(3, 3) = m_gizmo[15]; - - auto first_pose = worker_data[index_begin].intermediate_trajectory[0]; - - Eigen::Vector3d translation = current_gizmo.translation() - first_pose.translation(); - - float number_all_nodes_inside_interval = 0; - for (int i = index_begin; i < index_end; i++) - { - number_all_nodes_inside_interval += (float)worker_data[i].intermediate_trajectory.size(); - } - - std::vector> all_poses; - for (size_t i = 0; i < worker_data.size(); i++) - { - std::vector poses; - for (size_t j = 0; j < worker_data[i].intermediate_trajectory.size(); j++) - { - poses.push_back(worker_data[i].intermediate_trajectory[j]); - } - all_poses.push_back(poses); - } - - float counter = 0; - - Eigen::Affine3d last_m = Eigen::Affine3d::Identity(); - - for (int i = index_begin; i < index_end; i++) - { - for (size_t j = 0; j < worker_data[i].intermediate_trajectory.size(); j++) - { - TaitBryanPose pose = pose_tait_bryan_from_affine_matrix(worker_data[i].intermediate_trajectory[j]); - - pose.px = - first_pose.translation().x() + translation.x() * (counter / number_all_nodes_inside_interval); - pose.py = - first_pose.translation().y() + translation.y() * (counter / number_all_nodes_inside_interval); - pose.pz = - first_pose.translation().z() + translation.z() * (counter / number_all_nodes_inside_interval); - - counter += 1.0f; - - worker_data[i].intermediate_trajectory[j] = affine_matrix_from_pose_tait_bryan(pose); - - last_m = worker_data[i].intermediate_trajectory[j]; - } - } - - for (size_t i = index_end; i < worker_data.size(); i++) - { - for (size_t j = 0; j < worker_data[i].intermediate_trajectory.size(); j++) - { - Eigen::Affine3d m_update = Eigen::Affine3d::Identity(); - - if (j == 0) - { - m_update = all_poses[i - 1][all_poses[i - 1].size() - 1].inverse() * all_poses[i][0]; - } - else - { - m_update = all_poses[i][j - 1].inverse() * all_poses[i][j]; - } - last_m = last_m * m_update; - worker_data[i].intermediate_trajectory[j] = last_m; - } - } - } - } - } - ImGui::Separator(); - } - - ImGui::NewLine(); - ImGui::Text("Show/hide individual scans:"); - - int n_items = (int)worker_data.size(); - int digits = (n_items > 0) ? (int)std::log10(n_items - 1) + 1 : 1; - - for (int i = 0; i < n_items; i++) - { - // std::string text = "[" + std::to_string(i) + "]"; - // ImGui::Checkbox(text.c_str(), &worker_data[i].show); - std::stringstream ss; - ss << "[" << std::setw(digits) << std::setfill('0') << i << "]"; - - ImGui::Checkbox(ss.str().c_str(), &worker_data[i].show); - - // Arrange checkboxes in rows of 5 - if ((i + 1) % 5 != 0) - ImGui::SameLine(); - } - } - } - } - - ImGui::End(); -} - -void progress_window() -{ - ImGui::Begin("Progress", nullptr, ImGuiWindowFlags_AlwaysAutoResize); - - ImGui::Text(("Working directory:\n'" + working_directory + "'").c_str()); - - // Calculate elapsed time and ETA - auto currentTime = std::chrono::system_clock::now(); - std::chrono::duration elapsed = currentTime - loStartTime; - double elapsedSeconds = elapsed.count(); - loElapsedSeconds.store(elapsedSeconds); - - float progress = loProgress.load(); - double estimatedTimeRemaining = 0.0; - - if (progress > 0.01f && progress < 100.0f) - { // Only estimate when we have meaningful progress - double totalEstimatedTime = elapsedSeconds / progress; - estimatedTimeRemaining = totalEstimatedTime - elapsedSeconds; - loEstimatedTimeRemaining.store(estimatedTimeRemaining); - } - - // Format progress text with time information - char progressText[256]; - char timeInfo[512]; - - if (progress > 0.01f) - { - std::string completionTime = formatCompletionTime(estimatedTimeRemaining); - snprintf(progressText, sizeof(progressText), "Processing: %.1f%%", progress * 100.0f); - snprintf( - timeInfo, - sizeof(timeInfo), - "Elapsed: %s | Remaining: %s | Estimated finish: ~%s", - formatTime(elapsedSeconds).c_str(), - formatTime(estimatedTimeRemaining).c_str(), - completionTime.c_str()); - } - else - { - snprintf(progressText, sizeof(progressText), "Processing: %.1f%%", progress * 100.0f); - snprintf(timeInfo, sizeof(timeInfo), "Elapsed: %s | Calculating completion time...", formatTime(elapsedSeconds).c_str()); - } - - ImGui::ProgressBar(progress, ImVec2(-1.0f, 0.0f), progressText); - ImGui::Text("%s", timeInfo); - -#ifdef _WIN32 - // Update Windows taskbar progress - if (progress > 0.01f && progress < 1.0f) - { - SetTaskbarProgress(progress); - } - else if (progress >= 1.0f) - { - ClearTaskbarProgress(); - } -#endif - - ImGui::NewLine(); - - if (!loPause) - { - if (ImGui::Button("Pause")) - loPause.store(true); - - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text("Pausing calculation will not save intermediate state!"); - ImGui::Text("You can't resume if you close the program!"); - ImGui::EndTooltip(); - } - } - else - { - if (ImGui::Button("Resume")) - loPause.store(false); - } - ImGui::SameLine(); - ImGui::Text("Also check console for progress.."); - - ImGui::Checkbox("Show reference buckets indoor", &show_reference_buckets_indoor); - ImGui::Checkbox("Show reference buckets outdoor", &show_reference_buckets_outdoor); - ImGui::Checkbox("Show initial points", &show_initial_points); - ImGui::Checkbox("Show trajectory", &show_trajectory); - ImGui::Checkbox("Show trajectory as axes", &show_trajectory_as_axes); - ImGui::Checkbox("Show prediction vectors", &show_prediction_vectors); - ImGui::Checkbox("Show intermediate trajectory prediction axes", &intermediate_trajectory_prediction_axes); - ImGui::Checkbox("Show without filtered buckets", &show_without_filtered_buckets); - ImGui::Checkbox("Show normal vectors indoor", &show_normal_vectors_indoor); - ImGui::Checkbox("Show normal vectors outdoor", &show_normal_vectors_outdoor); - // ImGui::Checkbox("Show covs indoor", &show_covs_indoor); - // ImGui::Checkbox("Show covs outdoor", &show_covs_outdoor); - - ImGui::End(); -} - -void openData() -{ - is_settings_gui = false; - info_gui = false; - - loRunning.store(true); - loProgress.store(0.0f); - loElapsedSeconds.store(0.0); - loEstimatedTimeRemaining.store(0.0); - loStartTime = std::chrono::system_clock::now(); - - step1(loPause); - - if (step_1_done) - { - std::thread loThread( - []() - { - std::chrono::time_point start, end; - start = std::chrono::system_clock::now(); - - step2(loPause); - if (!step_2_done) - { - loRunning = false; - std::cerr << "Lidar odometry step 2 failed: no results saved" << std::endl; - return; - } - - end = std::chrono::system_clock::now(); - std::chrono::duration elapsed_seconds = end - start; - - save_results(false, elapsed_seconds.count()); - - loRunning = false; - - std::ostringstream oss; - oss << "Data saved to folder:\n'" << outwd.string() << "'\n" - << "Calculated trajectory length: " << std::fixed << std::setprecision(1) - << params.total_length_of_calculated_trajectory << "[m]\n" - << "Elapsed time: " << formatTime(elapsed_seconds.count()).c_str(); - - [[maybe_unused]] pfd::message message("Information", oss.str(), pfd::choice::ok, pfd::icon::info); - message.result(); - }); - - loThread.detach(); - } - else // no data loaded - loRunning = false; -} - -bool step1( - const std::string& folder, - LidarOdometryParams& params, - std::vector>& pointsPerFile, - Imu& imu_data, - std::string& working_directory, - Trajectory& trajectory, - std::vector& worker_data, - const std::atomic& loPause) -{ - std::vector input_file_names; - - for (const auto& entry : fs::directory_iterator(folder)) - { - if (!entry.is_directory()) - { - std::cout << entry.path() << std::endl; - input_file_names.push_back(entry.path().string()); - } - } - - 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, full_debug_messages); - if (!compute_step_1(pointsPerFile, params, trajectory, worker_data, loPause)) - return false; - release_raw_clouds(pointsPerFile, params); // nothing after step 1 reads them - std::cout << "step_1_done" << std::endl; - return true; - } - return false; -} - -bool step2(std::vector& worker_data, LidarOdometryParams& params, const std::atomic& loPause) -{ - double ts_failure = 0.0; - std::atomic loProgress; - std::atomic parked{ false }; - return compute_step_2(worker_data, params, ts_failure, loProgress, loPause, full_debug_messages, parked); -} - -void save_results( - bool info, - double elapsed_seconds, - std::string& working_directory, - std::vector& worker_data, - LidarOdometryParams& params, - fs::path outwd) -{ - save_result(worker_data, params, outwd, elapsed_seconds); -} - -void display() -{ - ImGuiIO& io = ImGui::GetIO(); - glViewport(0, 0, (GLsizei)io.DisplaySize.x, (GLsizei)io.DisplaySize.y); - - 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); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - float ratio = float(io.DisplaySize.x) / float(io.DisplaySize.y); - - updateCameraTransition(); - - reshape((GLsizei)io.DisplaySize.x, (GLsizei)io.DisplaySize.y); - - viewLocal = Eigen::Affine3f::Identity(); - - viewLocal.translate(rotation_center); - - viewLocal.translate(Eigen::Vector3f(translate_x, translate_y, translate_z)); - if (!lock_z) - viewLocal.rotate(Eigen::AngleAxisf(rotate_x * DEG_TO_RAD, Eigen::Vector3f::UnitX())); - else - viewLocal.rotate(Eigen::AngleAxisf(-90.0 * DEG_TO_RAD, Eigen::Vector3f::UnitX())); - viewLocal.rotate(Eigen::AngleAxisf(rotate_y * DEG_TO_RAD, Eigen::Vector3f::UnitZ())); - - viewLocal.translate(-rotation_center); - - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf(viewLocal.matrix().data()); - - showAxes(); - - if (show_initial_points) - { - glColor3d(0.0, 1.0, 0.0); - glPointSize(point_size); - glBegin(GL_POINTS); - for (const auto& p : params.initial_points) - { - auto pp = params.m_g * p.point; - glVertex3d(pp.x(), pp.y(), pp.z()); - } - glEnd(); - } - -#if 0 // ToDo - for (size_t i = 0; i < worker_data.size(); i++) - { - if (worker_data[i].show) - { - glPointSize(1); - glColor3d(0.0, 0.0, 1.0); - glBegin(GL_POINTS); - for (const auto &p : worker_data[i].intermediate_points) - { - Eigen::Vector3d pt = worker_data[i].intermediate_trajectory[p.index_pose] * p.point; - glVertex3d(pt.x(), pt.y(), pt.z()); - } - glEnd(); - glPointSize(1); - - glLineWidth(1); - glBegin(GL_LINES); - const auto &it = worker_data[i].intermediate_trajectory[0]; - glColor3f(1, 0, 0); - glVertex3f(it(0, 3), it(1, 3), it(2, 3)); - glVertex3f(it(0, 3) + it(0, 0), it(1, 3) + it(1, 0), it(2, 3) + it(2, 0)); - - glColor3f(0, 1, 0); - glVertex3f(it(0, 3), it(1, 3), it(2, 3)); - glVertex3f(it(0, 3) + it(0, 1), it(1, 3) + it(1, 1), it(2, 3) + it(2, 1)); - - glEnd(); - } - } -#endif - - if (show_reference_points) - { - glColor3f(1, 0, 0); - glBegin(GL_POINTS); - for (size_t i = 0; i < params.reference_points.size(); i += dec_reference_points) - glVertex3f(params.reference_points[i].point.x(), params.reference_points[i].point.y(), params.reference_points[i].point.z()); - glEnd(); - } - - if (show_trajectory_as_axes) - { - // glBegin(GL_LINE_STRIP); - glBegin(GL_LINES); - for (const auto& wd : worker_data) - { - for (const auto& it : wd.intermediate_trajectory) - { - glColor3f(1, 0, 0); - glVertex3f(it(0, 3), it(1, 3), it(2, 3)); - glVertex3f(it(0, 3) + it(0, 0) * 0.1, it(1, 3) + it(1, 0) * 0.1, it(2, 3) + it(2, 0) * 0.1); - - glColor3f(0, 1, 0); - glVertex3f(it(0, 3), it(1, 3), it(2, 3)); - glVertex3f(it(0, 3) + it(0, 1) * 0.1, it(1, 3) + it(1, 1) * 0.1, it(2, 3) + it(2, 1) * 0.1); - - glColor3f(0, 0, 1); - glVertex3f(it(0, 3), it(1, 3), it(2, 3)); - glVertex3f(it(0, 3) + it(0, 2) * 0.1, it(1, 3) + it(1, 2) * 0.1, it(2, 3) + it(2, 2) * 0.1); - } - } - glEnd(); - } - - if (show_prediction_vectors) - { - glDisable(GL_DEPTH_TEST); - glLineWidth(3.0f); - glBegin(GL_LINES); - for (const auto& wd : worker_data) - { - if (wd.intermediate_trajectory.empty() || wd.imu_prediction_vector.norm() < 1e-6) - continue; - - Eigen::Vector3d start = wd.intermediate_trajectory.front().translation(); - Eigen::Vector3d end = start + wd.imu_prediction_vector; - - glColor3f(1.0f, 0.0f, 1.0f); // magenta - glVertex3d(start.x(), start.y(), start.z()); - glVertex3d(end.x(), end.y(), end.z()); - } - glEnd(); - glLineWidth(1.0f); - glEnable(GL_DEPTH_TEST); - } - - if (intermediate_trajectory_prediction_axes) - { - glLineWidth(1.0f); - glBegin(GL_LINES); - for (const auto& wd : worker_data) - { - if (wd.intermediate_trajectory.empty() || wd.intermediate_trajectory_prediction.empty()) - continue; - - for (size_t i = 0; i < std::min(wd.intermediate_trajectory.size(), wd.intermediate_trajectory_prediction.size()); i++) - { - const auto& it = wd.intermediate_trajectory[i]; - const auto& pred_axis = wd.intermediate_trajectory_prediction[i]; - - glColor3f(1, 0, 0); - glVertex3f(it(0, 3), it(1, 3), it(2, 3)); - glVertex3f(it(0, 3) + pred_axis(0, 0) * 0.05, it(1, 3) + pred_axis(1, 0) * 0.05, it(2, 3) + pred_axis(2, 0) * 0.05); - - glColor3f(0, 1, 0); - glVertex3f(it(0, 3), it(1, 3), it(2, 3)); - glVertex3f(it(0, 3) + pred_axis(0, 1) * 0.05, it(1, 3) + pred_axis(1, 1) * 0.05, it(2, 3) + pred_axis(2, 1) * 0.05); - - glColor3f(0, 0, 1); - glVertex3f(it(0, 3), it(1, 3), it(2, 3)); - glVertex3f(it(0, 3) + pred_axis(0, 2) * 0.05, it(1, 3) + pred_axis(1, 2) * 0.05, it(2, 3) + pred_axis(2, 2) * 0.05); - } - } - glEnd(); - glLineWidth(1.0f); - } - - if (show_trajectory) - { - glPointSize(3); - glColor3f(0, 1, 1); - glBegin(GL_POINTS); - for (const auto& wd : worker_data) - { - for (const auto& it : wd.intermediate_trajectory) - glVertex3f(it(0, 3), it(1, 3), it(2, 3)); - } - glEnd(); - glPointSize(1); - - glColor3f(1, 0, 0); - glBegin(GL_LINES); - if (worker_data.size() > 0) - { - const auto& wd = worker_data[worker_data.size() - 1]; - if (wd.intermediate_trajectory.size() > 0) - { - const auto& it = wd.intermediate_trajectory[wd.intermediate_trajectory.size() - 1]; - - glVertex3f(it(0, 3) - 1, it(1, 3), it(2, 3)); - glVertex3f(it(0, 3) + 1, it(1, 3), it(2, 3)); - - glVertex3f(it(0, 3), it(1, 3) - 1, it(2, 3)); - glVertex3f(it(0, 3), it(1, 3) + 1, it(2, 3)); - - glVertex3f(it(0, 3), it(1, 3), it(2, 3) - 1); - glVertex3f(it(0, 3), it(1, 3), it(2, 3) + 1); - } - } - glEnd(); - } - - if (show_reference_buckets_indoor) - { - std::scoped_lock lock(params.mutex_buckets_indoor); - glColor3f(1, 0, 0); - glBegin(GL_POINTS); - for (const auto& b : params.buckets_indoor) - { - if (b.second.number_of_points == -1) - { - glColor3f(0, 1, 1); - } - else - { - glColor3f(1, 0, 0); - } - if (!show_without_filtered_buckets) - { - glVertex3f(b.second.mean.x(), b.second.mean.y(), b.second.mean.z()); - } - else - { - if (b.second.number_of_hits < 20) - { - glVertex3f(b.second.mean.x(), b.second.mean.y(), b.second.mean.z()); - } - } - } - glEnd(); - } - - if (show_reference_buckets_outdoor) - { - std::scoped_lock lock2(params.mutex_buckets_outdoor); - glColor3f(0, 0, 1); - glBegin(GL_POINTS); - for (const auto& b : params.buckets_outdoor) - { - if (b.second.number_of_points == -1) - { - glColor3f(1, 0, 1); - } - else - { - glColor3f(0, 0, 1); - } - // glVertex3f(b.second.mean.x(), b.second.mean.y(), b.second.mean.z()); - if (!show_without_filtered_buckets) - { - glVertex3f(b.second.mean.x(), b.second.mean.y(), b.second.mean.z()); - } - else - { - if (b.second.number_of_hits < 20) - { - glVertex3f(b.second.mean.x(), b.second.mean.y(), b.second.mean.z()); - } - } - } - glEnd(); - } - - if (show_normal_vectors_indoor) - { - std::scoped_lock lock2(params.mutex_buckets_indoor); - glColor3f(0, 0, 1); - glBegin(GL_LINES); - for (const auto& b : params.buckets_indoor) - { - glColor3f(fabs(b.second.normal_vector.x()), fabs(b.second.normal_vector.y()), fabs(b.second.normal_vector.z())); - - glVertex3f(b.second.mean.x(), b.second.mean.y(), b.second.mean.z()); - glVertex3f( - b.second.mean.x() + b.second.normal_vector.x(), - b.second.mean.y() + b.second.normal_vector.y(), - b.second.mean.z() + b.second.normal_vector.z()); - } - glEnd(); - } - - if (show_normal_vectors_outdoor) - { - std::scoped_lock lock2(params.mutex_buckets_outdoor); - glColor3f(0, 0, 1); - glBegin(GL_LINES); - for (const auto& b : params.buckets_outdoor) - { - glColor3f(fabs(b.second.normal_vector.x()), fabs(b.second.normal_vector.y()), fabs(b.second.normal_vector.z())); - - glVertex3f(b.second.mean.x(), b.second.mean.y(), b.second.mean.z()); - glVertex3f( - b.second.mean.x() + b.second.normal_vector.x(), - b.second.mean.y() + b.second.normal_vector.y(), - b.second.mean.z() + b.second.normal_vector.z()); - } - glEnd(); - } - - if (show_covs_indoor) - { - std::scoped_lock lock(params.mutex_buckets_indoor); - for (const auto& b : params.buckets_indoor) - draw_ellipse(b.second.cov, b.second.mean, Eigen::Vector3f(1.0f, 0.0f, 0.0f), 3); - } - - if (show_covs_outdoor) - { - std::scoped_lock lock2(params.mutex_buckets_outdoor); - for (const auto& b : params.buckets_outdoor) - draw_ellipse(b.second.cov, b.second.mean, Eigen::Vector3f(0.0f, 0.0f, 1.0f), 3); - } - - // - if (worker_data.size() > 0) - { - if (index_begin < worker_data.size()) - { - glColor3f(1, 1, 0); - glBegin(GL_LINES); - if (worker_data[index_begin].intermediate_trajectory.size() > 0) - { - auto p = worker_data[index_begin].intermediate_trajectory[0].translation(); - glVertex3f(p.x() - 1, p.y(), p.z()); - glVertex3f(p.x() + 1, p.y(), p.z()); - - glVertex3f(p.x(), p.y() - 1, p.z()); - glVertex3f(p.x(), p.y() + 1, p.z()); - - glVertex3f(p.x(), p.y(), p.z() - 1); - glVertex3f(p.x(), p.y(), p.z() + 1); - } - glEnd(); - } - - if (index_end < worker_data.size()) - { - glColor3f(0, 1, 1); - glBegin(GL_LINES); - if (worker_data[index_end].intermediate_trajectory.size() > 0) - { - auto p = worker_data[index_end].intermediate_trajectory[0].translation(); - glVertex3f(p.x() - 1, p.y(), p.z()); - glVertex3f(p.x() + 1, p.y(), p.z()); - - glVertex3f(p.x(), p.y() - 1, p.z()); - glVertex3f(p.x(), p.y() + 1, p.z()); - - glVertex3f(p.x(), p.y(), p.z() - 1); - glVertex3f(p.x(), p.y(), p.z() + 1); - } - glEnd(); - } - } - - 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) - { - if (ImGui::BeginMainMenuBar()) - { - if (ImGui::BeginMenu("Presets")) - { - if (ImGui::MenuItem("1 Velocity < 8km/h, tiny spaces (default)", nullptr, (lastPar == 1))) - { - lastPar = 1; - - set_lidar_odometry_default_params(params); - - std::cout << "clicked: Set parameters for velocity up to 8km/h, tiny spaces" << std::endl; - } - if (ImGui::MenuItem("2 Velocity < 8km/h, larger spaces, precise forestry (generic)", nullptr, (lastPar == 2))) - { - lastPar = 2; - - params.decimation = 0.01; - params.in_out_params_indoor.resolution_X = 0.1; - params.in_out_params_indoor.resolution_Y = 0.1; - params.in_out_params_indoor.resolution_Z = 0.1; - - params.in_out_params_outdoor.resolution_X = 0.3; - params.in_out_params_outdoor.resolution_Y = 0.3; - params.in_out_params_outdoor.resolution_Z = 0.3; - - params.filter_threshold_xy_inner = 1.0; - params.filter_threshold_xy_outer = 70.0; - params.threshould_output_filter = 1.5; - - params.use_robust_and_accurate_lidar_odometry = false; - params.distance_bucket = 0.2; - params.polar_angle_deg = 10.0; - params.azimutal_angle_deg = 10.0; - params.robust_and_accurate_lidar_odometry_iterations = 20; - - params.max_distance_lidar = 70.0; - params.nr_iter = 500; - params.sliding_window_trajectory_length_threshold = 10000; - params.real_time_threshold_seconds = 10; - - std::cout << "clicked: Set parameters for velocity < 8km/h, larger spaces, precise forestry (generic)" << std::endl; - } - if (ImGui::MenuItem("3 Velocity < 30 km/h, largest open spaces, fast motion", nullptr, (lastPar == 3))) - { - lastPar = 3; - - params.decimation = 0.03; - params.in_out_params_indoor.resolution_X = 0.3; - params.in_out_params_indoor.resolution_Y = 0.3; - params.in_out_params_indoor.resolution_Z = 0.3; - - params.in_out_params_outdoor.resolution_X = 0.5; - params.in_out_params_outdoor.resolution_Y = 0.5; - params.in_out_params_outdoor.resolution_Z = 0.5; - - params.filter_threshold_xy_inner = 1.0; - params.filter_threshold_xy_outer = 70.0; - params.threshould_output_filter = 3.0; - - params.use_robust_and_accurate_lidar_odometry = false; - params.distance_bucket = 0.2; - params.polar_angle_deg = 10.0; - params.azimutal_angle_deg = 10.0; - params.robust_and_accurate_lidar_odometry_iterations = 20; - - params.max_distance_lidar = 70.0; - params.nr_iter = 500; - params.sliding_window_trajectory_length_threshold = 200; - params.real_time_threshold_seconds = 10; - - std::cout << "clicked: Set parameters for velocity < 30 km/h, largest open spaces, fast motion" << std::endl; - } - ImGui::Separator(); - if (ImGui::MenuItem( - "4: Best accuracy, precision, and robustness (uncheck to calculate faster)", - nullptr, - params.ablation_study_use_anisotropic_weighting)) - { - params.ablation_study_use_anisotropic_weighting = !params.ablation_study_use_anisotropic_weighting; - } - ImGui::MenuItem("5: No IMU, lidar-only odometry (combine with 1-3)", nullptr, ¶ms.lidar_only_odometry); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "For recordings without IMU data, written with a synthetic stationary IMU (e.g. ouster_pcap_to_laz " - "--stationary-imu): each window's rotation and translation are predicted from the previous window instead of " - "from the IMU."); - - ImGui::EndMenu(); - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Set parameters for MANDEYE data processing"); - - if (ImGui::BeginMenu("Parameters")) - { - ImGui::MenuItem( - "Remove IMU bias from first stationary scan", nullptr, ¶ms.use_removie_imu_bias_from_first_stationary_scan); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("IMU bias will be removed given there's a stationary period at the start of the recording"); - - ImGui::MenuItem("Multithread", nullptr, ¶ms.useMultithread); - ImGui::SetNextItemWidth(ImGuiNumberWidth / 2); - ImGui::InputDouble("Time threshold [s]", ¶ms.real_time_threshold_seconds, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text("Optimization timeout"); - ImGui::Text("smaller value gives faster calculations, less precise results"); - ImGui::Text("e.g.: 0.1 [s] will make processing time aprox equal to scan time"); - ImGui::Text("0.3 [s] will make processing time aprox equal to 3x scan time"); - ImGui::EndTooltip(); - } - - if (ImGui::MenuItem("Set real time performance")) - params.real_time_threshold_seconds = 0.1; - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("For IMU 200Hz, 20 nodes in optimization window"); - - ImGui::Separator(); - - ImGui::Text("Debug:"); - - ImGui::MenuItem("Full processing messages", nullptr, &full_debug_messages); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Show more messages during processing in console window"); - ImGui::MenuItem("Save calibration validation file", nullptr, ¶ms.save_calibration_validation); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Save calibrated points from first laz file in 'calibrationValidation.asc' file"); - ImGui::SetNextItemWidth(ImGuiNumberWidth); - ImGui::InputInt("Number of calibration validation points", ¶ms.calibration_validation_points); - - ImGui::Separator(); - if (ImGui::BeginMenu("Ablation study")) - { - ImGui::MenuItem("Use planarity", nullptr, ¶ms.ablation_study_use_planarity); - ImGui::MenuItem("Use norm", nullptr, ¶ms.ablation_study_use_norm); - ImGui::MenuItem("Use hierarchical RGD (outer RGD turned on)", nullptr, ¶ms.ablation_study_use_hierarchical_rgd); - ImGui::MenuItem("Use view point and normal vectors", nullptr, ¶ms.ablation_study_use_view_point_and_normal_vectors); - ImGui::MenuItem("Use threshold '1e-6' outer RGD", nullptr, ¶ms.ablation_study_use_threshold_outer_rgd); - ImGui::MenuItem("Use anisotropic weighting", nullptr, ¶ms.ablation_study_use_anisotropic_weighting); - ImGui::EndMenu(); - } - - ImGui::Separator(); - - ImGui::MenuItem("Saving results with index pose", nullptr, ¶ms.save_index_pose); - - ImGui::Separator(); - - if (ImGui::MenuItem("Load parameters")) - { - auto input_file_names = mandeye::fd::OpenFileDialog("Load parameters file", mandeye::fd::Toml_filter, ".toml"); - - if (input_file_names.size() > 0) - { - try - { - // Use the original TomlIO class for loading parameters in GUI - TomlIO toml_io; - toml_io.LoadParametersFromTomlFile(input_file_names[0], params); - std::cout << "Parameters loaded from: " << input_file_names[0] << std::endl; - } catch (const std::exception& e) - { - std::cerr << "Error loading TOML file: " << e.what() << std::endl; - } - } - } - - if (ImGui::MenuItem("Save parameters")) - { - auto output_file_name = mandeye::fd::SaveFileDialog("Save parameters file", mandeye::fd::Toml_filter, ".toml"); - std::cout << "Parameters file to save: '" << output_file_name << "'" << std::endl; - - if (!output_file_name.empty()) - { - // Use the original TomlIO class for saving parameters in GUI - TomlIO toml_io; - bool success = toml_io.SaveParametersToTomlFile(output_file_name, params); - if (success) - std::cout << "Parameters file generated: " << output_file_name << std::endl; - else - std::cerr << "Failed to save parameters." << std::endl; - } - } - - ImGui::EndMenu(); - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Processing parameter list"); - - ImGui::SameLine(); - ImGui::Dummy(ImVec2(20, 0)); - ImGui::SameLine(); - - if (ImGui::Button("Load & process scanning")) - openData(); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Select folder from where to load data and start processing (Ctrl+O)"); - - ImGui::SameLine(); - ImGui::Dummy(ImVec2(20, 0)); - ImGui::SameLine(); - - if (ImGui::BeginMenu("View")) - { - ImGui::BeginDisabled(!(session.point_clouds_container.point_clouds.size() > 0)); - { - auto tmp = point_size; - ImGui::SetNextItemWidth(ImGuiNumberWidth); - ImGui::InputInt("Points size", &point_size); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("keyboard 1-9 keys"); - if (point_size < 1) - point_size = 1; - else if (point_size > 10) - point_size = 10; - - if (tmp != point_size) - for (auto& point_cloud : session.point_clouds_container.point_clouds) - point_cloud.point_size = point_size; - - ImGui::Separator(); - } - ImGui::EndDisabled(); - - ImGui::MenuItem("Show initial points", nullptr, &show_initial_points); - ImGui::MenuItem("Show trajectory", nullptr, &show_trajectory); - ImGui::MenuItem("Show trajectory as axes", nullptr, &show_trajectory_as_axes); - ImGui::MenuItem("Show prediction vectors", nullptr, &show_prediction_vectors); - ImGui::MenuItem("Show intermediate trajectory prediction axes", nullptr, &intermediate_trajectory_prediction_axes); - - ImGui::MenuItem("Show compass/ruler", "key C", &compass_ruler); - - ImGui::MenuItem("Lock Z", "Shift + Z", &lock_z, !is_ortho); - - // ImGui::MenuItem("show_covs", nullptr, &show_covs); - - ImGui::Separator(); - - ImGui::Text("Colors:"); - - ImGui::ColorEdit3("Background", (float*)¶ms.clear_color, ImGuiColorEditFlags_NoInputs); - - bg_color = params.clear_color; - - ImGui::Separator(); - - ImGui::MenuItem("Settings", nullptr, &is_settings_gui); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Show power user settings window with more parameters"); - - ImGui::EndMenu(); - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Scene view relevant parameters"); - - camMenu(); - - ImGui::SameLine( - ImGui::GetWindowWidth() - ImGui::CalcTextSize("Info").x - ImGui::GetStyle().ItemSpacing.x * 2 - - ImGui::GetStyle().FramePadding.x * 2); - - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(4, 2)); - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::GetStyleColorVec4(ImGuiCol_HeaderHovered)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImGui::GetStyleColorVec4(ImGuiCol_Header)); - if (ImGui::SmallButton("Info")) - info_gui = !info_gui; - - ImGui::PopStyleVar(2); - ImGui::PopStyleColor(3); - - ImGui::EndMainMenuBar(); - } - } - - if (initial_transformation_gizmo) - { - ImGuiIO& io = ImGui::GetIO(); - // ImGuizmo ----------------------------------------------- - ImGuizmo::BeginFrame(); - ImGuizmo::Enable(true); - ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y); - - GLfloat projection[16]; - glGetFloatv(GL_PROJECTION_MATRIX, projection); - - GLfloat modelview[16]; - glGetFloatv(GL_MODELVIEW_MATRIX, modelview); - - ImGuizmo::Manipulate( - &modelview[0], - &projection[0], - ImGuizmo::TRANSLATE | ImGuizmo::ROTATE_Z | ImGuizmo::ROTATE_X | ImGuizmo::ROTATE_Y, - ImGuizmo::WORLD, - m_gizmo, - NULL); - - params.m_g(0, 0) = m_gizmo[0]; - params.m_g(1, 0) = m_gizmo[1]; - params.m_g(2, 0) = m_gizmo[2]; - params.m_g(3, 0) = m_gizmo[3]; - params.m_g(0, 1) = m_gizmo[4]; - params.m_g(1, 1) = m_gizmo[5]; - params.m_g(2, 1) = m_gizmo[6]; - params.m_g(3, 1) = m_gizmo[7]; - params.m_g(0, 2) = m_gizmo[8]; - params.m_g(1, 2) = m_gizmo[9]; - params.m_g(2, 2) = m_gizmo[10]; - params.m_g(3, 2) = m_gizmo[11]; - params.m_g(0, 3) = m_gizmo[12]; - params.m_g(1, 3) = m_gizmo[13]; - params.m_g(2, 3) = m_gizmo[14]; - params.m_g(3, 3) = m_gizmo[15]; - } - - if (gizmo_stretch_interval) - { - ImGuiIO& io = ImGui::GetIO(); - // ImGuizmo ----------------------------------------------- - ImGuizmo::BeginFrame(); - ImGuizmo::Enable(true); - ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y); - - GLfloat projection[16]; - glGetFloatv(GL_PROJECTION_MATRIX, projection); - - GLfloat modelview[16]; - glGetFloatv(GL_MODELVIEW_MATRIX, modelview); - - ImGuizmo::Manipulate( - &modelview[0], - &projection[0], - ImGuizmo::TRANSLATE | ImGuizmo::ROTATE_Z | ImGuizmo::ROTATE_X | ImGuizmo::ROTATE_Y, - ImGuizmo::WORLD, - m_gizmo, - NULL); - - stretch_gizmo_m(0, 0) = m_gizmo[0]; - stretch_gizmo_m(1, 0) = m_gizmo[1]; - stretch_gizmo_m(2, 0) = m_gizmo[2]; - stretch_gizmo_m(3, 0) = m_gizmo[3]; - stretch_gizmo_m(0, 1) = m_gizmo[4]; - stretch_gizmo_m(1, 1) = m_gizmo[5]; - stretch_gizmo_m(2, 1) = m_gizmo[6]; - stretch_gizmo_m(3, 1) = m_gizmo[7]; - stretch_gizmo_m(0, 2) = m_gizmo[8]; - stretch_gizmo_m(1, 2) = m_gizmo[9]; - stretch_gizmo_m(2, 2) = m_gizmo[10]; - stretch_gizmo_m(3, 2) = m_gizmo[11]; - stretch_gizmo_m(0, 3) = m_gizmo[12]; - stretch_gizmo_m(1, 3) = m_gizmo[13]; - stretch_gizmo_m(2, 3) = m_gizmo[14]; - stretch_gizmo_m(3, 3) = m_gizmo[15]; - } - - if (is_settings_gui) - { - lastPar = 0; - - settings_gui(); - } - - if (loRunning) - progress_window(); - - cor_window(); - - if (info_gui) - { - infoLines[infoLines.size() - 2] = "It saves session file in " + working_directory + "\\lio_result_*"; - info_window(infoLines, appShortcuts); - } - - if (compass_ruler) - drawMiniCompassWithRuler(); - - ImGui::Render(); - ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData()); - - glutSwapBuffers(); - glutPostRedisplay(); -} - -void on_exit() -{ - remove_cache(params); -} - -void mouse(int glut_button, int state, int x, int y) -{ - ImGuiIO& io = ImGui::GetIO(); - io.MousePos = ImVec2((float)x, (float)y); - - int button = -1; - if (glut_button == GLUT_LEFT_BUTTON) - button = 0; - if (glut_button == GLUT_RIGHT_BUTTON) - button = 1; - if (glut_button == GLUT_MIDDLE_BUTTON) - button = 2; - if (button != -1 && state == GLUT_DOWN) - io.MouseDown[button] = true; - if (button != -1 && state == GLUT_UP) - io.MouseDown[button] = false; - - static int glutMajorVersion = glutGet(GLUT_VERSION) / 10000; - if (state == GLUT_DOWN && (glut_button == 3 || glut_button == 4) && glutMajorVersion < 3) - wheel(glut_button, glut_button == 3 ? 1 : -1, x, y); - - if (!io.WantCaptureMouse) - { - if ((glut_button == GLUT_MIDDLE_BUTTON || glut_button == GLUT_RIGHT_BUTTON) && state == GLUT_DOWN && io.KeyCtrl) - setNewRotationCenter(x, y); - - if (state == GLUT_DOWN) - mouse_buttons |= 1 << glut_button; - else if (state == GLUT_UP) - mouse_buttons = 0; - - mouse_old_x = x; - mouse_old_y = y; - } -} - -int main(int argc, char* argv[]) -{ - spdlog::cfg::load_env_levels(); - spdlog::flush_on(spdlog::level::warn); - set_lidar_odometry_default_params(params); - - try - { - if (checkClHelp(argc, argv)) - { - std::cout << winTitle << "\n\n" - << "USAGE:\n" - << std::filesystem::path(argv[0]).stem().string() << " /?\n" - << std::filesystem::path(argv[0]).stem().string() << " \n" - << std::filesystem::path(argv[0]).stem().string() << " --dump-default-params \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" - << " (with alone, default parameters are used and the\n" - << " session is stored in the next free /lio_result_N,\n" - << " as the GUI does)\n" - << " --dump-default-params \n" - << " Write the default parameters to and exit\n" - << " -h, /h, --help, /? Show this help and exit\n\n"; - - return 0; - } - - for (int i = 1; i < argc; ++i) - { - if (std::string(argv[i]) == "--dump-default-params") - { - if (i + 1 >= argc) - { - std::cerr << "--dump-default-params requires an output file (*.toml)" << std::endl; - return 1; - } - const fs::path out_file(argv[i + 1]); - // Value-initialised, as the static `params` is: the NDT grid members carry no - // initialisers, and a default-initialised local would dump stack garbage. - LidarOdometryParams default_params{}; - set_lidar_odometry_default_params(default_params); - TomlIO toml_io; - toml_io.SaveParametersToTomlFile(out_file.string(), default_params); - std::error_code ec; - if (!fs::exists(out_file, ec) || fs::file_size(out_file, ec) == 0 || ec) - { - std::cerr << "Could not write default parameters to: " << out_file.string() << std::endl; - return 1; - } - std::cout << "Default parameters saved to: " << out_file.string() << std::endl; - return 0; - } - } - - if (argc == 2) // running from command line - { - auto path = fs::path(argv[1]); - if (is_directory(path)) - { - std::string working_directory; - std::vector worker_data; - - std::chrono::time_point start, end; - start = std::chrono::system_clock::now(); - - std::atomic loPause{ false }; - if (!step1(path.string(), params, pointsPerFile, imu_data, working_directory, trajectory, worker_data, loPause) || - !step2(worker_data, params, loPause)) - { - std::cerr << "Lidar odometry failed: no results saved" << std::endl; - return 1; - } - - end = std::chrono::system_clock::now(); - std::chrono::duration elapsed_seconds = end - start; - std::time_t end_time = std::chrono::system_clock::to_time_t(end); - std::cout << "calculations finished computation at " << std::ctime(&end_time) - << "Elapsed time: " << formatTime(elapsed_seconds.count()).c_str() << "s\n"; - - // Only the input folder was given: store the session where the GUI would, - // in the next free lio_result_N under the working directory. - if (working_directory.empty()) - { - std::cerr << "No Mandeye data could be loaded from: '" << path.string() << "'" << std::endl; - return 1; - } - const fs::path result_dir = get_next_result_path(working_directory); - save_results(false, elapsed_seconds.count(), working_directory, worker_data, params, result_dir); - std::cout << "Results saved to folder: '" << result_dir.string() << "'" << std::endl; - remove_cache(params); - } - } - else if (argc == 4) // runnning from command line with custom params - { - // Load parameters from file using original TomlIO class - TomlIO toml_io; - toml_io.LoadParametersFromTomlFile(argv[2], params); - std::cout << "Parameters loaded OK from: " << argv[2] << std::endl; - - std::string working_directory; - std::vector worker_data; - - std::chrono::time_point start, end; - start = std::chrono::system_clock::now(); - - std::atomic loPause{ false }; - if (!step1(argv[1], params, pointsPerFile, imu_data, working_directory, trajectory, worker_data, loPause) || - !step2(worker_data, params, loPause)) - { - std::cerr << "Lidar odometry failed: no results saved" << std::endl; - return 1; - } - - end = std::chrono::system_clock::now(); - std::chrono::duration elapsed_seconds = end - start; - std::time_t end_time = std::chrono::system_clock::to_time_t(end); - std::cout << "calculations finished computation at " << std::ctime(&end_time) - << "Elapsed time: " << formatTime(elapsed_seconds.count()).c_str() << "s\n"; - - save_results(false, elapsed_seconds.count(), working_directory, worker_data, params, argv[3]); - remove_cache(params); - } - else // full GUI mode - { - std::cout << argv[0] << " input_folder parameters(*.toml) output_folder" << std::endl; - - initGL(&argc, argv, winTitle, display, mouse); - glutCloseFunc(on_exit); - -#ifdef _WIN32 - InitTaskbarProgress(); -#endif - - glutMainLoop(); - - ImGui_ImplOpenGL2_Shutdown(); - ImGui_ImplGLUT_Shutdown(); - ImGui::DestroyContext(); - } - } catch (const std::bad_alloc& e) - { - std::cerr << "System is out of memory : " << e.what() << std::endl; - mandeye::fd::OutOfMemMessage(); - } catch (const std::exception& e) - { - std::cout << e.what(); - } catch (...) - { - std::cerr << "Unknown fatal error occurred." << std::endl; - } - - return 0; -} \ No newline at end of file diff --git a/apps/lidar_odometry_step_1_legacy/resource.h b/apps/lidar_odometry_step_1_legacy/resource.h deleted file mode 100644 index 4f3204ca..00000000 --- a/apps/lidar_odometry_step_1_legacy/resource.h +++ /dev/null @@ -1,17 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by resource.rc -// -#define IDI_ICON1 101 // application icon -#define VS_VERSION_INFO 1 // version info - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 106 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1000 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/apps/lidar_odometry_step_1_legacy/resource.rc b/apps/lidar_odometry_step_1_legacy/resource.rc deleted file mode 100644 index ac2be718..00000000 --- a/apps/lidar_odometry_step_1_legacy/resource.rc +++ /dev/null @@ -1,54 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "resource.h" -///////////////////////////////////////////////////////////////////////////// -// English (United States) resources - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -IDI_ICON1 ICON "icon.ico" - -// GLFW (used by raylib) only picks up a window/taskbar icon from a -// resource named exactly GLFW_ICON on Windows; without it GLFW falls -// back to the generic IDI_WINLOGO icon at runtime. -GLFW_ICON ICON "icon.ico" - - -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO -FILEVERSION 0, 0, 100, 1 -PRODUCTVERSION 0, 0, 100, 1 -FILEFLAGSMASK 0x3fL -FILEOS 0x40004 -FILETYPE 0x1 -BEGIN -BLOCK "StringFileInfo" -BEGIN -BLOCK "040904B0" -BEGIN -VALUE "CompanyName", "Mandeye\0" -VALUE "FileDescription", "HDMapping Step 1\0" -VALUE "FileVersion", "0.100.1\0" -VALUE "InternalName", "Odometry\0" -VALUE "LegalCopyright", "(c) 2026 github.com/MapsHD/HDMapping\0" -VALUE "OriginalFilename", "lidar_odometry_step_1.exe\0" -VALUE "ProductVersion", "0.100.1\0" -VALUE "ProgramID", "github.com/MapsHD/HDMapping\0" -VALUE "ProductName", "HDMapping\0" -END -END -BLOCK "VarFileInfo" -BEGIN -VALUE "Translation", 0x409, 0x04B0 -END -END -///////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/apps/mandeye_raw_data_viewer/CMakeLists.txt b/apps/mandeye_raw_data_viewer/CMakeLists.txt index f87435a4..b29c1027 100644 --- a/apps/mandeye_raw_data_viewer/CMakeLists.txt +++ b/apps/mandeye_raw_data_viewer/CMakeLists.txt @@ -22,8 +22,6 @@ add_executable( mandeye_raw_data_viewer ${SOURCES} ) -# raylib-based (ported off GLUT; the GLUT build is kept as apps/mandeye_raw_data_viewer_legacy): -# (core_raylib_utils) replaces with the same names. target_include_directories( mandeye_raw_data_viewer PRIVATE include diff --git a/apps/mandeye_raw_data_viewer_legacy/CMakeLists.txt b/apps/mandeye_raw_data_viewer_legacy/CMakeLists.txt deleted file mode 100644 index 403e4c7c..00000000 --- a/apps/mandeye_raw_data_viewer_legacy/CMakeLists.txt +++ /dev/null @@ -1,79 +0,0 @@ -cmake_minimum_required(VERSION 4.0.0) - -# Legacy GLUT + legacy immediate-mode OpenGL build of the raw data viewer, -# kept side by side with apps/mandeye_raw_data_viewer (raylib-based since it -# was ported off GLUT), the same way step2/step3 keep their *_legacy builds. -project(mandeye_raw_data_viewer_legacy) - -# Source files -set(SOURCES - mandeye_raw_data_viewer.cpp - ../lidar_odometry_step_1/toml_io.cpp - ../lidar_odometry_step_1/lidar_odometry.cpp - ../lidar_odometry_step_1/lidar_odometry_utils.cpp - ../lidar_odometry_step_1/lidar_odometry_utils_optimizers.cpp - ../lidar_odometry_step_1/points_global_spill.cpp - ../lidar_odometry_step_1/raw_cloud_loader.cpp - "../../core/src/utils.cpp" -) - -# Windows: add resource file -if(WIN32) - list(APPEND SOURCES resource.rc) -endif() - -add_executable( - mandeye_raw_data_viewer_legacy ${SOURCES} -) - -target_include_directories( - mandeye_raw_data_viewer_legacy - PRIVATE include - ${REPOSITORY_DIRECTORY}/core/include - ${REPOSITORY_DIRECTORY}/core_hd_mapping/include - ${THIRDPARTY_DIRECTORY} - ${THIRDPARTY_DIRECTORY}/glm - ${EIGEN3_INCLUDE_DIR} - ${THIRDPARTY_DIRECTORY}/tomlplusplus/include - ${THIRDPARTY_DIRECTORY}/imgui - ${THIRDPARTY_DIRECTORY}/imgui/backends - ${THIRDPARTY_DIRECTORY}/ImGuizmo - ${THIRDPARTY_DIRECTORY}/glew-cmake/include - ${FREEGLUT_INCLUDE_DIR} - ${THIRDPARTY_DIRECTORY}/json/include - ${THIRDPARTY_DIRECTORY}/portable-file-dialogs-master - ${LASZIP_INCLUDE_DIR}/LASzip/include - ${THIRDPARTY_DIRECTORY}/observation_equations/codes - ${THIRDPARTY_DIRECTORY}/vqf/vqf/cpp - ${THIRDPARTY_DIRECTORY}/Fusion/Fusion) - -target_link_libraries( - mandeye_raw_data_viewer_legacy - PRIVATE step1_run_report vqf Fusion - unordered_dense::unordered_dense - spdlog::spdlog - UTL::include - ${FREEGLUT_LIBRARY} - ${OPENGL_gl_LIBRARY} - OpenGL::GLU - ${PLATFORM_LASZIP_LIB} - ${CORE_LIBRARIES} - ${GUI_LIBRARIES} - ${PLATFORM_MISCELLANEOUS_LIBS} - ${OpenCV_LIBS}) - -if(WIN32) - add_custom_command( - TARGET mandeye_raw_data_viewer_legacy - POST_BUILD - COMMAND - ${CMAKE_COMMAND} -E copy $ - $ - COMMAND_EXPAND_LISTS) -endif() - -if (MSVC) - target_compile_options(mandeye_raw_data_viewer_legacy PRIVATE /bigobj) -endif() - -hdmapping_install_app(mandeye_raw_data_viewer_legacy) diff --git a/apps/mandeye_raw_data_viewer_legacy/icon.ico b/apps/mandeye_raw_data_viewer_legacy/icon.ico deleted file mode 100644 index 710913e3..00000000 Binary files a/apps/mandeye_raw_data_viewer_legacy/icon.ico and /dev/null differ diff --git a/apps/mandeye_raw_data_viewer_legacy/mandeye_raw_data_viewer.cpp b/apps/mandeye_raw_data_viewer_legacy/mandeye_raw_data_viewer.cpp deleted file mode 100644 index a938e25f..00000000 --- a/apps/mandeye_raw_data_viewer_legacy/mandeye_raw_data_viewer.cpp +++ /dev/null @@ -1,2080 +0,0 @@ -// clang-format off -#include -#include -// clang-format on - -#include -#include -#include -#include -#include - -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include - -#include "../lidar_odometry_step_1/lidar_odometry.h" -#include "../lidar_odometry_step_1/lidar_odometry_utils.h" -#include -#include -#include - -#include - -#include "tbb/tbb.h" -#include - -#include - -#ifdef _WIN32 -#include "resource.h" -#include // <-- Required for ShellExecuteA -#include -#endif - -/////////////////////////////////////////////////////////////////////////////////// - -std::string winTitle = std::string("Raw data viewer ") + HDMAPPING_CONFIGURE_PROJECT_VERSION; - -std::vector infoLines = { "This program is optional step in MANDEYE process", - "", - "It analyzes LiDAR data created by Mission Recorder", - "Next step will be to load data with 'lidar_odometry_step_1' app" }; - -// App specific shortcuts (using empty dummy until needed) -std::vector appShortcuts(80, { "", "", "" }); - -#define SAMPLE_PERIOD (1.0 / 200.0) -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); - -struct AllData -{ - std::vector> timestamps; - std::vector poses; - std::vector points_local; - std::vector lidar_ids; -}; -std::vector all_data; - -struct ImuData -{ - std::vector timestampLidar; - std::vector timestampRel; // timestampLidar shifted so the dataset starts at 0 [s] - double datasetStart = 0.0; // absolute timestamp of the first IMU sample [s] - std::vector angX; - std::vector angY; - std::vector angZ; - std::vector accX; - std::vector accY; - std::vector accZ; - std::vector yaw; - std::vector pitch; - std::vector roll; -}; -ImuData imu_data_plot; - -std::vector laz_files; -std::vector photos_files; -std::map photo_files_ts; - -double filter_threshold_xy_inner = 0.0; // no filtering for raw viewing -double filter_threshold_xy_outer = 300.0; // no filtering for raw viewing -bool fusionConventionNwu = true; -bool fusionConventionEnu = false; -bool fusionConventionNed = false; -int number_of_points_threshold = 20000; -bool is_init = false; -int index_rendered_points_local = -1; -// std::vector> all_points_local; -// std::vector> all_points_local; -// std::vector> all_lidar_ids; -std::vector indexes_to_filename; - -// cached inputs to the chunking pass below, kept around so number_of_points_threshold -// can be changed and re-applied (rebuildAllData) without reloading files from disk -std::vector> g_points_per_file; -std::vector> g_timestamps_cache; -std::vector g_poses_cache; -double vqf_tauAcc = 0.5; -double wx = 1000000.0; -double wy = 1000000.0; -double wz = 1000000.0; -double wom = 1000000.0; -double wfi = 1000000.0; -double wka = 1000000.0; -// bool is_slerp = false; - -double distance_bucket = 0.5; -double polar_angle_deg = 5; -double azimutal_angle_deg = 5; -double max_distance_lidar = 70.0; -int robust_and_accurate_lidar_odometry_iterations = 20; -bool useMultithread = true; - -std::vector> rgd_nn; -std::vector> mean_cov; -bool show_mean_cov = false; -bool show_rgd_nn = false; -bool show_imu_data = false; -bool show_cameras_data = true; -bool is_settings_gui = false; -bool color_by_intensity = false; -float intensity_gamma = 1.0f; - -namespace photos -{ - cv::Mat imgToShow; - std::string imgToShowFn; - GLuint photo_texture_cam0 = 0; - double nearestTs = 0; - int photo_width_cam0 = 0; - int photo_height_cam0 = 0; -} // namespace photos - -/////////////////////////////////////////////////////////////////////////////////// - -static ImVec2 DisplayImageFit(ImTextureID tex, int tex_w, int tex_h, bool allow_upscale = true) -{ - ImVec2 avail = ImGui::GetContentRegionAvail(); - if (tex_w <= 0 || tex_h <= 0 || avail.x <= 0.0f || avail.y <= 0.0f) - return ImVec2(0, 0); - - float sx = avail.x / float(tex_w); - float sy = avail.y / float(tex_h); - float scale = std::min(sx, sy); - if (!allow_upscale) - scale = std::min(scale, 1.0f); - - ImVec2 disp(scale * tex_w, scale * tex_h); - - ImVec2 cur = ImGui::GetCursorPos(); - ImGui::SetCursorPosX(cur.x + (avail.x - disp.x) * 0.5f); // center horizontally - ImGui::Image(tex, disp); - // cursor Y is already advanced by Image; no restore needed - - return disp; -} - -void render_nearest_photo(double ts) -{ - using namespace photos; - // find closest photo - if (photo_files_ts.empty()) - { - return; - } - uint64_t ts_uint64 = static_cast(ts * 1e9); - auto it = photo_files_ts.lower_bound(ts_uint64); - if (it == photo_files_ts.end()) - { - return; - } - const std::string& photo_file = it->second; - if (photo_file == imgToShowFn) - { - return; - } - spdlog::info("render_nearest_photo: {}", photo_file); - cv::Mat img = cv::imread(photo_file); - if (img.empty()) - { - return; - } - cv::Mat img_rgb; - cv::cvtColor(img, img_rgb, cv::COLOR_BGR2RGB); - imgToShow = img_rgb; - imgToShowFn = photo_file; - photos::nearestTs = double(it->first) / 1e9; - // upload to OpenGL texture - photo_width_cam0 = imgToShow.cols; - photo_height_cam0 = imgToShow.rows; - if (photo_texture_cam0 == 0) - { - glGenTextures(1, &photo_texture_cam0); - } - glBindTexture(GL_TEXTURE_2D, photo_texture_cam0); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, photo_width_cam0, photo_height_cam0, 0, GL_RGB, GL_UNSIGNED_BYTE, imgToShow.data); - glBindTexture(GL_TEXTURE_2D, 0); -} - -void optimize() -{ -#if 0 - rgd_nn.clear(); - - // NDT::GridParameters rgd_params_sc; - - // rgd_params_sc.resolution_X = distance_bucket; - // rgd_params_sc.resolution_Y = polar_angle_deg; - // rgd_params_sc.resolution_Z = azimutal_angle_deg; - - if (index_rendered_points_local >= 0 && index_rendered_points_local < all_data.size()) - { - // std::vector points_local_sf; - std::vector points_local; - auto tr = all_data[index_rendered_points_local].poses; - auto trmm = all_data[index_rendered_points_local].poses; - - for (size_t i = 0; i < all_data[index_rendered_points_local].points_local.size(); i++) - { - auto lower = std::lower_bound(all_data[index_rendered_points_local].timestamps.begin(), all_data[index_rendered_points_local].timestamps.end(), all_data[index_rendered_points_local].points_local[i].timestamp, - [](std::pair lhs, double rhs) -> bool - { return lhs.first < rhs; }); - - int index_pose = std::distance(all_data[index_rendered_points_local].timestamps.begin(), lower) - 1; - - if (index_pose >= 0 && index_pose < all_data[index_rendered_points_local].poses.size()) - { - // Eigen::Affine3d m = all_data[index_rendered_points_local].poses[index_pose]; - // Eigen::Vector3d p = m * all_data[index_rendered_points_local].points_local[i].point; - double r_l = all_data[index_rendered_points_local].points_local[i].point.norm(); - if (r_l > 0.5 && all_data[index_rendered_points_local].points_local[i].index_pose != -1 && r_l < max_distance_lidar) - { - // double polar_angle_deg_l = atan2(all_data[index_rendered_points_local].points_local[i].point.y(), all_data[index_rendered_points_local].points_local[i].point.x()) / M_PI * 180.0; - // double azimutal_angle_deg_l = acos(all_data[index_rendered_points_local].points_local[i].point.z() / r_l) / M_PI * 180.0; - all_data[index_rendered_points_local].points_local[i].index_pose = index_pose; - points_local.push_back(all_data[index_rendered_points_local].points_local[i]); - - /////////////////////////////////////////////////////// - // Point3Di p_sl = all_data[index_rendered_points_local].points_local[i]; - // p_sl.point.x() = r_l; - // p_sl.point.y() = polar_angle_deg_l; - // p_sl.point.z() = azimutal_angle_deg_l; - - // points_local_sf.push_back(p_sl); - } - } - } - - //spdlog::info("points_local.size(): {}", points_local.size()); - // points_local - // points_local_sf - - std::vector - point_cloud_global; - std::vector point_cloud_global_sc; - - for (size_t i = 0; i < points_local.size(); i++) - { - Point3Di pg = points_local[i]; - pg.point = tr[points_local[i].index_pose] * pg.point; - point_cloud_global.push_back(pg); - double r_g = pg.point.norm(); - point_cloud_global_sc.emplace_back(r_g, atan2(pg.point.y(), pg.point.x()) / M_PI * 180.0, acos(pg.point.z() / r_g) / M_PI * 180.0); - } - - NDT::GridParameters rgd_params_sc; - - rgd_params_sc.resolution_X = distance_bucket; - rgd_params_sc.resolution_Y = polar_angle_deg; - rgd_params_sc.resolution_Z = azimutal_angle_deg; - Eigen::Vector3d b(rgd_params_sc.resolution_X, rgd_params_sc.resolution_Y, rgd_params_sc.resolution_Z); - - NDTBucketMapType buckets; - update_rgd_spherical_coordinates(rgd_params_sc, buckets, point_cloud_global, point_cloud_global_sc, false); - //update_rgd(rgd_params_sc, buckets, point_cloud_global, {0, 0, 0}); - - std::vector> tripletListA; - std::vector> tripletListP; - std::vector> tripletListB; - - for (size_t i = 0; i < point_cloud_global.size(); i++) - { - - auto index_of_bucket = get_rgd_index_3d(point_cloud_global_sc[i], b); - //auto index_of_bucket = get_rgd_index_3d(point_cloud_global[i].point, b); - auto bucket_it = buckets.find(index_of_bucket); - // no bucket found - if (bucket_it == buckets.end()) - { - continue; - } - auto& this_bucket = bucket_it->second; - - rgd_nn.emplace_back(point_cloud_global[i].point, this_bucket.mean); - - const Eigen::Matrix3d& infm = this_bucket.cov.inverse(); - const double threshold = 100000.0; - - if ((infm.array() > threshold).any()) - { - continue; - } - if ((infm.array() < -threshold).any()) - { - continue; - } - - const Eigen::Affine3d& m_pose = tr[points_local[i].index_pose]; - //spdlog::info("points_local[i].index_pose {}", points_local[i].index_pose); - const Eigen::Vector3d& p_s = points_local[i].point; - const TaitBryanPose pose_s = pose_tait_bryan_from_affine_matrix(m_pose); - double delta_x; - double delta_y; - double delta_z; - - //// - Eigen::Matrix jacobian; - // TaitBryanPose pose_s = pose_tait_bryan_from_affine_matrix((*mposes)[p.index_pose]); - - point_to_point_source_to_target_tait_bryan_wc(delta_x, delta_y, delta_z, - pose_s.px, pose_s.py, pose_s.pz, pose_s.om, pose_s.fi, pose_s.ka, - p_s.x(), p_s.y(), p_s.z(), this_bucket.mean.x(), this_bucket.mean.y(), this_bucket.mean.z()); - - // spdlog::info("delta_x: {}", delta_x); - // spdlog::info("delta_y: {}", delta_y); - // spdlog::info("delta_z: {}", delta_z); - - if (sqrt(delta_x * delta_x + delta_y * delta_y + delta_z * delta_z) < 0.001) - { - continue; - } - - point_to_point_source_to_target_tait_bryan_wc_jacobian(jacobian, pose_s.px, pose_s.py, pose_s.pz, pose_s.om, pose_s.fi, pose_s.ka, p_s.x(), p_s.y(), p_s.z()); - - int c = points_local[i].index_pose * 6; - - // std::mutex &m = my_mutex[0]; // mutexes[intermediate_points_i.index_pose]; - // std::unique_lock lck(m); - int ir = tripletListB.size(); - - for (int row = 0; row < 3; row++) - { - for (int col = 0; col < 6; col++) - { - if (jacobian(row, col) != 0.0) - { - tripletListA.emplace_back(ir + row, c + col, -jacobian(row, col)); - } - } - } - tripletListB.emplace_back(ir, 0, delta_x); - tripletListB.emplace_back(ir + 1, 0, delta_y); - tripletListB.emplace_back(ir + 2, 0, delta_z); - - tripletListP.emplace_back(ir, ir, infm(0, 0)); - tripletListP.emplace_back(ir, ir + 1, infm(0, 1)); - tripletListP.emplace_back(ir, ir + 2, infm(0, 2)); - tripletListP.emplace_back(ir + 1, ir, infm(1, 0)); - tripletListP.emplace_back(ir + 1, ir + 1, infm(1, 1)); - tripletListP.emplace_back(ir + 1, ir + 2, infm(1, 2)); - tripletListP.emplace_back(ir + 2, ir, infm(2, 0)); - tripletListP.emplace_back(ir + 2, ir + 1, infm(2, 1)); - tripletListP.emplace_back(ir + 2, ir + 2, infm(2, 2)); - - /// - } - - std::vector> odo_edges; - for (size_t i = 1; i < tr.size(); i++) - { - odo_edges.emplace_back(i - 1, i); - } - - std::vector poses; - std::vector poses_desired; - - for (size_t i = 0; i < tr.size(); i++) - { - poses.push_back(pose_tait_bryan_from_affine_matrix(tr[i])); - } - for (size_t i = 0; i < trmm.size(); i++) - { - poses_desired.push_back(pose_tait_bryan_from_affine_matrix(trmm[i])); - } - - for (size_t i = 0; i < odo_edges.size(); i++) - { - Eigen::Matrix relative_pose_measurement_odo; - relative_pose_tait_bryan_wc_case1(relative_pose_measurement_odo, - poses_desired[odo_edges[i].first].px, - poses_desired[odo_edges[i].first].py, - poses_desired[odo_edges[i].first].pz, - poses_desired[odo_edges[i].first].om, - poses_desired[odo_edges[i].first].fi, - poses_desired[odo_edges[i].first].ka, - poses_desired[odo_edges[i].second].px, - poses_desired[odo_edges[i].second].py, - poses_desired[odo_edges[i].second].pz, - poses_desired[odo_edges[i].second].om, - poses_desired[odo_edges[i].second].fi, - poses_desired[odo_edges[i].second].ka); - - Eigen::Matrix delta; - relative_pose_obs_eq_tait_bryan_wc_case1( - delta, - poses[odo_edges[i].first].px, - poses[odo_edges[i].first].py, - poses[odo_edges[i].first].pz, - poses[odo_edges[i].first].om, - poses[odo_edges[i].first].fi, - poses[odo_edges[i].first].ka, - poses[odo_edges[i].second].px, - poses[odo_edges[i].second].py, - poses[odo_edges[i].second].pz, - poses[odo_edges[i].second].om, - poses[odo_edges[i].second].fi, - poses[odo_edges[i].second].ka, - relative_pose_measurement_odo(0, 0), - relative_pose_measurement_odo(1, 0), - relative_pose_measurement_odo(2, 0), - relative_pose_measurement_odo(3, 0), - relative_pose_measurement_odo(4, 0), - relative_pose_measurement_odo(5, 0)); - - Eigen::Matrix jacobian; - relative_pose_obs_eq_tait_bryan_wc_case1_jacobian(jacobian, - poses[odo_edges[i].first].px, - poses[odo_edges[i].first].py, - poses[odo_edges[i].first].pz, - poses[odo_edges[i].first].om, - poses[odo_edges[i].first].fi, - poses[odo_edges[i].first].ka, - poses[odo_edges[i].second].px, - poses[odo_edges[i].second].py, - poses[odo_edges[i].second].pz, - poses[odo_edges[i].second].om, - poses[odo_edges[i].second].fi, - poses[odo_edges[i].second].ka); - - int ir = tripletListB.size(); - - int ic_1 = odo_edges[i].first * 6; - int ic_2 = odo_edges[i].second * 6; - - for (size_t row = 0; row < 6; row++) - { - tripletListA.emplace_back(ir + row, ic_1, -jacobian(row, 0)); - tripletListA.emplace_back(ir + row, ic_1 + 1, -jacobian(row, 1)); - tripletListA.emplace_back(ir + row, ic_1 + 2, -jacobian(row, 2)); - tripletListA.emplace_back(ir + row, ic_1 + 3, -jacobian(row, 3)); - tripletListA.emplace_back(ir + row, ic_1 + 4, -jacobian(row, 4)); - tripletListA.emplace_back(ir + row, ic_1 + 5, -jacobian(row, 5)); - - tripletListA.emplace_back(ir + row, ic_2, -jacobian(row, 6)); - tripletListA.emplace_back(ir + row, ic_2 + 1, -jacobian(row, 7)); - tripletListA.emplace_back(ir + row, ic_2 + 2, -jacobian(row, 8)); - tripletListA.emplace_back(ir + row, ic_2 + 3, -jacobian(row, 9)); - tripletListA.emplace_back(ir + row, ic_2 + 4, -jacobian(row, 10)); - tripletListA.emplace_back(ir + row, ic_2 + 5, -jacobian(row, 11)); - } - - tripletListB.emplace_back(ir, 0, delta(0, 0)); - tripletListB.emplace_back(ir + 1, 0, delta(1, 0)); - tripletListB.emplace_back(ir + 2, 0, delta(2, 0)); - tripletListB.emplace_back(ir + 3, 0, delta(3, 0)); - tripletListB.emplace_back(ir + 4, 0, delta(4, 0)); - tripletListB.emplace_back(ir + 5, 0, delta(5, 0)); - - tripletListP.emplace_back(ir, ir, wx); - tripletListP.emplace_back(ir + 1, ir + 1, wy); - tripletListP.emplace_back(ir + 2, ir + 2, wz); - tripletListP.emplace_back(ir + 3, ir + 3, wom); - tripletListP.emplace_back(ir + 4, ir + 4, wfi); - tripletListP.emplace_back(ir + 5, ir + 5, wka); - } - - int ic = 0; - int ir = tripletListB.size(); - tripletListA.emplace_back(ir, ic * 6 + 0, 1); - tripletListA.emplace_back(ir + 1, ic * 6 + 1, 1); - tripletListA.emplace_back(ir + 2, ic * 6 + 2, 1); - tripletListA.emplace_back(ir + 3, ic * 6 + 3, 1); - tripletListA.emplace_back(ir + 4, ic * 6 + 4, 1); - tripletListA.emplace_back(ir + 5, ic * 6 + 5, 1); - - /*tripletListP.emplace_back(ir, ir, 1000000); - tripletListP.emplace_back(ir + 1, ir + 1, 1000000); - tripletListP.emplace_back(ir + 2, ir + 2, 1000000); - tripletListP.emplace_back(ir + 3, ir + 3, 1000000); - tripletListP.emplace_back(ir + 4, ir + 4, 1000000); - tripletListP.emplace_back(ir + 5, ir + 5, 1000000);*/ - tripletListP.emplace_back(ir, ir, 1); - tripletListP.emplace_back(ir + 1, ir + 1, 1); - tripletListP.emplace_back(ir + 2, ir + 2, 1); - tripletListP.emplace_back(ir + 3, ir + 3, 1); - tripletListP.emplace_back(ir + 4, ir + 4, 1); - tripletListP.emplace_back(ir + 5, ir + 5, 1); - - tripletListB.emplace_back(ir, 0, 0); - tripletListB.emplace_back(ir + 1, 0, 0); - tripletListB.emplace_back(ir + 2, 0, 0); - tripletListB.emplace_back(ir + 3, 0, 0); - tripletListB.emplace_back(ir + 4, 0, 0); - tripletListB.emplace_back(ir + 5, 0, 0); - - Eigen::SparseMatrix matA(tripletListB.size(), tr.size() * 6); - Eigen::SparseMatrix matP(tripletListB.size(), tripletListB.size()); - Eigen::SparseMatrix matB(tripletListB.size(), 1); - - matA.setFromTriplets(tripletListA.begin(), tripletListA.end()); - matP.setFromTriplets(tripletListP.begin(), tripletListP.end()); - matB.setFromTriplets(tripletListB.begin(), tripletListB.end()); - - Eigen::SparseMatrix AtPA(tr.size() * 6, tr.size() * 6); - Eigen::SparseMatrix AtPB(tr.size() * 6, 1); - - { - Eigen::SparseMatrix AtP = matA.transpose() * matP; - AtPA = (AtP)*matA; - AtPB = (AtP)*matB; - } - - tripletListA.clear(); - tripletListP.clear(); - tripletListB.clear(); - - // AtPA += AtPAndt.sparseView(); - // AtPB += AtPBndt.sparseView(); - - // Eigen::SparseMatrix AtPA_I(tr.size() * 6, tr.size() * 6); - // AtPA_I.setIdentity(); - // AtPA += AtPA_I; - - Eigen::SimplicialCholesky> - solver(AtPA); - Eigen::SparseMatrix x = solver.solve(AtPB); - std::vector h_x; - for (int k = 0; k < x.outerSize(); ++k) - { - for (Eigen::SparseMatrix::InnerIterator it(x, k); it; ++it) - { - h_x.push_back(it.value()); - - std::cout << it.value() << " "; - } - } - - if (h_x.size() == 6 * tr.size()) - { - int counter = 0; - - for (size_t i = 0; i < tr.size(); i++) - { - TaitBryanPose pose = pose_tait_bryan_from_affine_matrix(tr[i]); - auto prev_pose = pose; - pose.px += h_x[counter++]; - pose.py += h_x[counter++]; - pose.pz += h_x[counter++]; - pose.om += h_x[counter++]; - pose.fi += h_x[counter++]; - pose.ka += h_x[counter++]; - - // Eigen::Vector3d p1(prev_pose.px, prev_pose.py, prev_pose.pz); - // Eigen::Vector3d p2(pose.px, pose.py, pose.pz); - - // if ((p1 - p2).norm() < 1.0) - //{ - tr[i] = affine_matrix_from_pose_tait_bryan(pose); - //} - } - all_data[index_rendered_points_local].poses = tr; - } - } -#endif - - NDT::GridParameters rgd_params_sc; - - rgd_params_sc.resolution_X = distance_bucket; - rgd_params_sc.resolution_Y = polar_angle_deg; - rgd_params_sc.resolution_Z = azimutal_angle_deg; - - if (index_rendered_points_local >= 0 && index_rendered_points_local < all_data.size()) - { - std::vector tr = all_data[index_rendered_points_local].poses; // = worker_data[i].intermediate_trajectory; - std::vector trmm = - all_data[index_rendered_points_local].poses; // = worker_data[i].intermediate_trajectory_motion_model; - - std::vector points_local_sf; - std::vector points_local; - - for (size_t i = 0; i < all_data[index_rendered_points_local].points_local.size(); i++) - { - auto lower = std::lower_bound( - all_data[index_rendered_points_local].timestamps.begin(), - all_data[index_rendered_points_local].timestamps.end(), - all_data[index_rendered_points_local].points_local[i].timestamp, - [](std::pair lhs, double rhs) -> bool - { - return lhs.first < rhs; - }); - - int index_pose = std::distance(all_data[index_rendered_points_local].timestamps.begin(), lower) - 1; - - if (index_pose >= 0 && index_pose < all_data[index_rendered_points_local].poses.size()) - { - all_data[index_rendered_points_local].points_local[i].index_pose = index_pose; - // Eigen::Affine3d m = all_data[index_rendered_points_local].poses[index_pose]; - // Eigen::Vector3d p = m * all_data[index_rendered_points_local].points_local[i].point; - double r_l = all_data[index_rendered_points_local].points_local[i].point.norm(); - if (r_l > 0.5 && all_data[index_rendered_points_local].points_local[i].index_pose != -1 && r_l < max_distance_lidar) - { - double polar_angle_deg_l = atan2( - all_data[index_rendered_points_local].points_local[i].point.y(), - all_data[index_rendered_points_local].points_local[i].point.x()) / - M_PI * 180.0; - double azimutal_angle_deg_l = - acos(all_data[index_rendered_points_local].points_local[i].point.z() / r_l) / M_PI * 180.0; - - points_local.push_back(all_data[index_rendered_points_local].points_local[i]); - - /////////////////////////////////////////////////////// - Point3Di p_sl = all_data[index_rendered_points_local].points_local[i]; - p_sl.point.x() = r_l; - p_sl.point.y() = polar_angle_deg_l; - p_sl.point.z() = azimutal_angle_deg_l; - - points_local_sf.push_back(p_sl); - } - } - } - - spdlog::info("optimize_sf2"); - for (int iter = 0; iter < robust_and_accurate_lidar_odometry_iterations; iter++) - { - optimize_sf2(points_local, points_local_sf, tr, trmm, rgd_params_sc, useMultithread, wx, wy, wz, wom, wfi, wka); - trmm = tr; - } - - all_data[index_rendered_points_local].poses = tr; - } - - return; -} - -std::vector> get_nn() -{ - std::vector> nn; - if (index_rendered_points_local >= 0 && index_rendered_points_local < all_data.size()) - { - // for (size_t i = 0; i < all_data[index_rendered_points_local].poses.size(); i++){ - // all_data[index_rendered_points_local].poses[i](0, 3) += 1.0; - // } - - auto worker_data = all_data[index_rendered_points_local]; - - // index data - for (size_t i = 0; i < worker_data.points_local.size(); i++) - { - auto lower = std::lower_bound( - worker_data.timestamps.begin(), - worker_data.timestamps.end(), - worker_data.points_local[i].timestamp, - [](std::pair lhs, double rhs) -> bool - { - return lhs.first < rhs; - }); - - int index_pose = std::distance(worker_data.timestamps.begin(), lower) - 1; - - if (index_pose >= 0 && index_pose < worker_data.poses.size()) - { - worker_data.points_local[i].index_pose = index_pose; - } - else - { - worker_data.points_local[i].index_pose = -1; - } - } - - NDT::GridParameters rgd_params; - // rgd_params.resolution_X = 0.3; // distance bucket - // rgd_params.resolution_Y = 0.3; // polar angle deg - // rgd_params.resolution_Z = 0.3; // azimutal angle deg - - rgd_params.resolution_X = distance_bucket; // distance bucket - rgd_params.resolution_Y = polar_angle_deg; // polar angle deg - rgd_params.resolution_Z = azimutal_angle_deg; // azimutal angle deg - - std::vector point_cloud_global; - std::vector points_local; - - std::vector point_cloud_global_sc; - std::vector points_local_sc; - - for (size_t i = 0; i < worker_data.points_local.size(); i++) - { - double r_l = worker_data.points_local[i].point.norm(); - if (r_l > 0.5 && worker_data.points_local[i].index_pose != -1 && r_l < max_distance_lidar) - { - double polar_angle_deg_l = - atan2(worker_data.points_local[i].point.y(), worker_data.points_local[i].point.x()) / M_PI * 180.0; - double azimutal_angle_deg_l = acos(worker_data.points_local[i].point.z() / r_l) / M_PI * 180.0; - - Eigen::Vector3d pp = worker_data.points_local[i].point; - // pps.x() = r; - // pps.y() = polar_angle_deg; - // pps.z() = azimutal_angle_deg; - // point_cloud_spherical_coordinates.push_back(pps); - - Eigen::Affine3d pose = worker_data.poses[worker_data.points_local[i].index_pose]; - - pp = pose * pp; - - Point3Di pg = worker_data.points_local[i]; - pg.point = pp; - - point_cloud_global.push_back(pg); - points_local.push_back(worker_data.points_local[i]); - - /////////////////////////////////////////////////////// - Point3Di p_sl = worker_data.points_local[i]; - p_sl.point.x() = r_l; - p_sl.point.y() = polar_angle_deg_l; - p_sl.point.z() = azimutal_angle_deg_l; - - points_local_sc.push_back(p_sl); - // - double r_g = pg.point.norm(); - double polar_angle_deg_g = atan2(pg.point.y(), pg.point.x()) / M_PI * 180.0; - double azimutal_angle_deg_g = acos(pg.point.z() / r_l) / M_PI * 180.0; - - Eigen::Vector3d p_sg = worker_data.points_local[i].point; - p_sg.x() = r_g; - p_sg.y() = polar_angle_deg_g; - p_sg.z() = azimutal_angle_deg_g; - - point_cloud_global_sc.push_back(p_sg); - } - } - - NDTBucketMapType buckets; - update_rgd_spherical_coordinates(rgd_params, buckets, point_cloud_global, point_cloud_global_sc); - - ///////////// - // std::vector> nn; - Eigen::Vector3d b(rgd_params.resolution_X, rgd_params.resolution_Y, rgd_params.resolution_Z); - - for (size_t i = 0; i < point_cloud_global_sc.size(); i++) - { - auto index_of_bucket = get_rgd_index_3d(point_cloud_global_sc[i], b); - - auto bucket_it = buckets.find(index_of_bucket); - - if (bucket_it != buckets.end()) - { - auto& this_bucket = bucket_it->second; - this_bucket.number_of_points++; - // const auto &curr_mean = points_global[i].point; - const auto& mean = this_bucket.mean; - - nn.emplace_back(point_cloud_global[i].point, mean); - - ////////////// - } - } - } - return nn; -} - -std::vector> get_mean_cov() -{ - std::vector> mc; - if (index_rendered_points_local >= 0 && index_rendered_points_local < all_data.size()) - { - // for (size_t i = 0; i < all_data[index_rendered_points_local].poses.size(); i++){ - // all_data[index_rendered_points_local].poses[i](0, 3) += 1.0; - // } - - auto worker_data = all_data[index_rendered_points_local]; - - // index data - for (size_t i = 0; i < worker_data.points_local.size(); i++) - { - auto lower = std::lower_bound( - worker_data.timestamps.begin(), - worker_data.timestamps.end(), - worker_data.points_local[i].timestamp, - [](std::pair lhs, double rhs) -> bool - { - return lhs.first < rhs; - }); - - int index_pose = std::distance(worker_data.timestamps.begin(), lower) - 1; - - if (index_pose >= 0 && index_pose < worker_data.poses.size()) - worker_data.points_local[i].index_pose = index_pose; - else - worker_data.points_local[i].index_pose = -1; - } - - NDT::GridParameters rgd_params; - // rgd_params.resolution_X = 0.3; // distance bucket - // rgd_params.resolution_Y = 0.3; // polar angle deg - // rgd_params.resolution_Z = 0.3; // azimutal angle deg - - rgd_params.resolution_X = distance_bucket; // distance bucket - rgd_params.resolution_Y = polar_angle_deg; // polar angle deg - rgd_params.resolution_Z = azimutal_angle_deg; // azimutal angle deg - - std::vector point_cloud_global; - std::vector points_local; - - std::vector point_cloud_global_sc; - std::vector points_local_sc; - - for (size_t i = 0; i < worker_data.points_local.size(); i++) - { - double r_l = worker_data.points_local[i].point.norm(); - if (r_l > 0.5 && worker_data.points_local[i].index_pose != -1 && r_l < max_distance_lidar) - { - double polar_angle_deg_l = - atan2(worker_data.points_local[i].point.y(), worker_data.points_local[i].point.x()) / M_PI * 180.0; - double azimutal_angle_deg_l = acos(worker_data.points_local[i].point.z() / r_l) / M_PI * 180.0; - - Eigen::Vector3d pp = worker_data.points_local[i].point; - // pps.x() = r; - // pps.y() = polar_angle_deg; - // pps.z() = azimutal_angle_deg; - // point_cloud_spherical_coordinates.push_back(pps); - - Eigen::Affine3d pose = worker_data.poses[worker_data.points_local[i].index_pose]; - - pp = pose * pp; - - Point3Di pg = worker_data.points_local[i]; - pg.point = pp; - - point_cloud_global.push_back(pg); - points_local.push_back(worker_data.points_local[i]); - - /////////////////////////////////////////////////////// - Point3Di p_sl = worker_data.points_local[i]; - p_sl.point.x() = r_l; - p_sl.point.y() = polar_angle_deg_l; - p_sl.point.z() = azimutal_angle_deg_l; - - points_local_sc.push_back(p_sl); - // - double r_g = pg.point.norm(); - double polar_angle_deg_g = atan2(pg.point.y(), pg.point.x()) / M_PI * 180.0; - double azimutal_angle_deg_g = acos(pg.point.z() / r_l) / M_PI * 180.0; - - Eigen::Vector3d p_sg = worker_data.points_local[i].point; - p_sg.x() = r_g; - p_sg.y() = polar_angle_deg_g; - p_sg.z() = azimutal_angle_deg_g; - - point_cloud_global_sc.push_back(p_sg); - } - } - - NDTBucketMapType buckets; - update_rgd_spherical_coordinates(rgd_params, buckets, point_cloud_global, point_cloud_global_sc); - - ///////////// - Eigen::Vector3d b(rgd_params.resolution_X, rgd_params.resolution_Y, rgd_params.resolution_Z); - - for (const auto& b : buckets) - { - auto& this_bucket = b.second; - - mc.emplace_back(this_bucket.mean, this_bucket.cov); - } - } - - return mc; -} - -// Re-chunks the already-loaded points (g_points_per_file / g_timestamps_cache / g_poses_cache) -// into all_data using the current number_of_points_threshold. Smaller thresholds mean each -// Index step in the toolbar covers less time, giving finer time navigation. -void rebuildAllData(bool preserve_position) -{ - double preserved_time = 0.0; - bool have_preserved_time = false; - if (preserve_position && index_rendered_points_local >= 0 && index_rendered_points_local < static_cast(all_data.size()) && - !all_data[index_rendered_points_local].timestamps.empty()) - { - preserved_time = all_data[index_rendered_points_local].timestamps.front().first; - have_preserved_time = true; - } - - all_data.clear(); - all_data.shrink_to_fit(); - indexes_to_filename.clear(); - indexes_to_filename.shrink_to_fit(); - - if (number_of_points_threshold < 1) - number_of_points_threshold = 1; - - const auto& pointsPerFile = g_points_per_file; - const auto& timestamps = g_timestamps_cache; - const auto& poses = g_poses_cache; - - int number_of_points = 0; - for (const auto& pp : pointsPerFile) - number_of_points += static_cast(pp.size()); - - spdlog::info("Number of points: {}", number_of_points); - spdlog::info("Start indexing points"); - - std::vector points_local; - std::vector lidar_ids; - - for (size_t i = 0; i < pointsPerFile.size(); i++) - { - std::cout << "Indexed file " << i + 1 << "/" << pointsPerFile.size() << "\r"; - - for (const auto& pp : pointsPerFile[i]) - { - auto lower = std::lower_bound( - timestamps.begin(), - timestamps.end(), - pp.timestamp, - [](std::pair lhs, double rhs) -> bool - { - return lhs.first < rhs; - }); - - int index_pose = static_cast(std::distance(timestamps.begin(), lower)) - 1; - - if (index_pose >= 0 && index_pose < static_cast(poses.size())) - { - points_local.push_back(pp); - lidar_ids.push_back(pp.lidarid); - } - - if (points_local.size() > static_cast(number_of_points_threshold)) - { - indexes_to_filename.push_back(static_cast(i)); - - AllData data; - data.points_local = points_local; - data.lidar_ids = lidar_ids; - - for (size_t k = 0; k < timestamps.size(); k++) - { - if (timestamps[k].first >= points_local[0].timestamp && - timestamps[k].first <= points_local[points_local.size() - 1].timestamp) - { - data.timestamps.push_back(timestamps[k]); - data.poses.push_back(poses[k]); - } - } - - // correct points timestamps - if (data.timestamps.size() > 2) - { - double ts_begin = data.timestamps[0].first; - double ts_step = - (data.timestamps[data.timestamps.size() - 1].first - data.timestamps[0].first) / data.points_local.size(); - - for (size_t pp_i = 0; pp_i < data.points_local.size(); pp_i++) - data.points_local[pp_i].timestamp = ts_begin + pp_i * ts_step; - } - - all_data.push_back(data); - - points_local.clear(); - lidar_ids.clear(); - } - } - } - - spdlog::info("Indexing points finished\n"); - - if (all_data.size() > 0) - { - is_init = true; - index_rendered_points_local = 0; - - if (have_preserved_time) - { - for (size_t i = 0; i < all_data.size(); i++) - { - if (!all_data[i].timestamps.empty() && preserved_time >= all_data[i].timestamps.front().first && - preserved_time <= all_data[i].timestamps.back().first) - { - index_rendered_points_local = static_cast(i); - break; - } - } - } - } - else - { - is_init = false; - index_rendered_points_local = -1; - } -} - -void loadFiles(std::vector input_file_names) -{ - LidarOdometryParams params; // dummy for load_data function - params.save_calibration_validation = false; - params.lazy_load_raw_clouds = false; // the viewer shows every cloud - params.filter_threshold_xy_inner = filter_threshold_xy_inner; - params.filter_threshold_xy_outer = filter_threshold_xy_outer; - - std::vector> pointsPerFile; - Imu 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 - - all_data.clear(); - all_data.shrink_to_fit(); - - imu_data_plot.timestampLidar.clear(); - imu_data_plot.timestampRel.clear(); - imu_data_plot.datasetStart = 0.0; - imu_data_plot.angX.clear(); - imu_data_plot.angY.clear(); - imu_data_plot.angZ.clear(); - imu_data_plot.accX.clear(); - imu_data_plot.accY.clear(); - imu_data_plot.accZ.clear(); - imu_data_plot.yaw.clear(); - imu_data_plot.pitch.clear(); - imu_data_plot.roll.clear(); - - imu_data_plot.timestampLidar.shrink_to_fit(); - imu_data_plot.timestampRel.shrink_to_fit(); - imu_data_plot.angX.shrink_to_fit(); - imu_data_plot.angY.shrink_to_fit(); - imu_data_plot.angZ.shrink_to_fit(); - imu_data_plot.accX.shrink_to_fit(); - imu_data_plot.accY.shrink_to_fit(); - imu_data_plot.accZ.shrink_to_fit(); - imu_data_plot.yaw.shrink_to_fit(); - imu_data_plot.pitch.shrink_to_fit(); - imu_data_plot.roll.shrink_to_fit(); - - photo_files_ts.clear(); - - laz_files.clear(); - - // specific processing for RAW data viewer - - std::sort(input_file_names.begin(), input_file_names.end()); - for (const auto& fileName : input_file_names) - { - std::string ext = fs::path(fileName).extension().string(); - std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); - - if (ext == ".laz" || ext == ".las") - laz_files.push_back(fileName); - else if (ext == ".jpg" || ext == ".jpeg") - { - photos_files.push_back(fileName); - // decode filename e.g.: ` cam0_1761264773592270949.jpg` - const std::string filename = fs::path(fileName).stem().string(); - std::string cam_id = filename.substr(0, filename.find("_")); - std::string timestamp = filename.substr(filename.find("_") + 1, filename.size()); - - spdlog::info("cam_id: {}", cam_id); - spdlog::info("timestamp: {}", timestamp); - spdlog::info("filename: {}", filename); - - if (cam_id == "cam0" && !timestamp.empty()) - { - try - { - uint64_t ts = std::stoull(timestamp); - photo_files_ts[ts] = fileName; - } catch (const std::exception& e) - { - spdlog::error("Error parsing timestamp from filename: {} - {}", filename, e.what()); - } - } - } - } - - // rest of RAW data viewer processing - - // VQF initialization - double avg_dt = SAMPLE_PERIOD; - if (imu_data.size() >= 2) - { - const double t0 = std::get<0>(imu_data.front()).first; - const double t1 = std::get<0>(imu_data.back()).first; - const double duration = t1 - t0; - - if (t1 > t0) - avg_dt = duration / static_cast(imu_data.size() - 1); - - if (duration > 24 * 60 * 60) - { - spdlog::error("Session is absurdly long : start time : {}, end time {}", t0, t1); - spdlog::error("Setting rate to {}", SAMPLE_PERIOD); - avg_dt = SAMPLE_PERIOD; - } - } - - VQFParams vqf_params; - vqf_params.tauAcc = vqf_tauAcc > 0.0 ? vqf_tauAcc : 3.0; - // produce warning - if (std::fabs(avg_dt - SAMPLE_PERIOD) > 0.01) - { - spdlog::warn("The dt found is strange : {}", avg_dt); - } - spdlog::info("avg_dt: {}", avg_dt); - VQF vqf(vqf_params, avg_dt); - - std::map> trajectory; - - int counter = 1; - - for (const auto& [timestamp_pair, gyr, acc] : imu_data) - { - const double g = 9.81; - vqf_real_t gyr_vqf[3] = { static_cast(gyr.x()), static_cast(gyr.y()), static_cast(gyr.z()) }; - vqf_real_t acc_vqf[3] = { static_cast(acc.x()) * g, - static_cast(acc.y()) * g, - static_cast(acc.z()) * g }; - - vqf.update(gyr_vqf, acc_vqf); - - vqf_real_t quat[4]; - vqf.getQuat6D(quat); - Eigen::Quaterniond d(quat[0], quat[1], quat[2], quat[3]); - Eigen::Affine3d t{ Eigen::Matrix4d::Identity() }; - t.rotate(d); - - trajectory[timestamp_pair.first] = std::pair(t.matrix(), timestamp_pair.second); - - Eigen::Vector3d euler = d.toRotationMatrix().eulerAngles(0, 1, 2) * (180.0 / M_PI); - counter++; - if (counter % 100 == 0) - { - spdlog::info("[{} of {}]: Roll {}, Pitch {}, Yaw {}", counter, imu_data.size(), euler.x(), euler.y(), euler.z()); - } - - // log it for implot - imu_data_plot.timestampLidar.push_back(timestamp_pair.first); - imu_data_plot.angX.push_back(gyr.x()); - imu_data_plot.angY.push_back(gyr.y()); - imu_data_plot.angZ.push_back(gyr.z()); - imu_data_plot.accX.push_back(acc.x()); - imu_data_plot.accY.push_back(acc.y()); - imu_data_plot.accZ.push_back(acc.z()); - imu_data_plot.yaw.push_back(euler.z()); - imu_data_plot.pitch.push_back(euler.y()); - imu_data_plot.roll.push_back(euler.x()); - } - - // timeline x-axis is shown relative to the first IMU sample so it starts at 0 [s]; - // datasetStart keeps the absolute value for reference / annotations - if (!imu_data_plot.timestampLidar.empty()) - { - imu_data_plot.datasetStart = imu_data_plot.timestampLidar.front(); - imu_data_plot.timestampRel.reserve(imu_data_plot.timestampLidar.size()); - for (double ts : imu_data_plot.timestampLidar) - imu_data_plot.timestampRel.push_back(ts - imu_data_plot.datasetStart); - } - - std::vector> timestamps; - std::vector poses; - for (const auto& t : trajectory) - { - timestamps.emplace_back(t.first, t.second.second); - Eigen::Affine3d m; - m.matrix() = t.second.first; - poses.push_back(m); - } - - g_points_per_file = std::move(pointsPerFile); - g_timestamps_cache = std::move(timestamps); - g_poses_cache = std::move(poses); - - rebuildAllData(false); - } -} - -void openFolder() -{ - std::string input_folder_name; - std::vector input_file_names; - input_folder_name = mandeye::fd::SelectFolder("Select Mandeye data folder"); - - spdlog::info("Selected folder: '{}'", input_folder_name); - - const std::vector subDirs{ "", "CAMERA_0" }; - for (const auto& subdir : subDirs) - { - const auto location = std::filesystem::path(input_folder_name) / subdir; - if (fs::exists(location)) - { - for (const auto& entry : fs::directory_iterator(location)) - 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", &show_imu_data); - { - if (imu_data_plot.timestampRel.size() > 0) - { - // All timelines below use time relative to the start of the dataset (t = 0 s). - // t0 is that start expressed as an absolute LiDAR timestamp in seconds. - const double t0 = imu_data_plot.datasetStart; - - ImGui::TextDisabled("Time axis is relative to dataset start."); - ImGui::Text("Dataset start (t = 0 s) = %.6f s absolute LiDAR time", t0); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Add this offset to any x-axis value to get the absolute LiDAR timestamp [s]"); - ImGui::Text("Dataset duration: %.3f s", imu_data_plot.timestampRel.back()); - ImGui::Separator(); - - static double x_min = 0.0; - static double x_max = 20.0; - - // currently rendered point block, expressed on the relative time axis - double annotation = 0; - bool has_annotation = false; - if (index_rendered_points_local >= 0 && index_rendered_points_local < all_data.size()) - { - if (all_data[index_rendered_points_local].timestamps.size() > 0) - { - annotation = all_data[index_rendered_points_local].timestamps.front().first - t0; - has_annotation = true; - } - } - - const double* ts = imu_data_plot.timestampRel.data(); - const int ts_n = (int)imu_data_plot.timestampRel.size(); - - if (ImPlot::BeginPlot("IMU - acceleration 'm/s^2", ImVec2(-1, 0))) - { - ImPlot::SetupAxisLimits(ImAxis_X1, x_min, x_max, ImGuiCond_Once); - ImPlot::SetupAxisLinks(ImAxis_X1, &x_min, &x_max); - ImPlot::SetupAxis(ImAxis_X1, "time since dataset start [s]"); - ImPlot::PlotLine("accX", ts, imu_data_plot.accX.data(), ts_n); - ImPlot::PlotLine("accY", ts, imu_data_plot.accY.data(), ts_n); - ImPlot::PlotLine("accZ", ts, imu_data_plot.accZ.data(), ts_n); - if (has_annotation) - ImPlot::TagX(annotation, ImVec4(1, 0, 0, 1)); - ImPlot::EndPlot(); - } - - if (ImPlot::BeginPlot("Imu - gyro", ImVec2(-1, 0))) - { - ImPlot::SetupAxisLimits(ImAxis_X1, x_min, x_max, ImGuiCond_Once); - ImPlot::SetupAxisLinks(ImAxis_X1, &x_min, &x_max); - ImPlot::SetupAxis(ImAxis_X1, "time since dataset start [s]"); - ImPlot::PlotLine("angX", ts, imu_data_plot.angX.data(), ts_n); - ImPlot::PlotLine("angY", ts, imu_data_plot.angY.data(), ts_n); - ImPlot::PlotLine("angZ", ts, imu_data_plot.angZ.data(), ts_n); - if (has_annotation) - ImPlot::TagX(annotation, ImVec4(1, 0, 0, 1)); - ImPlot::EndPlot(); - } - - if (ImPlot::BeginPlot("IMU - AHRS angles [deg]", ImVec2(-1, 0))) - { - ImPlot::SetupAxisLimits(ImAxis_X1, x_min, x_max, ImGuiCond_Once); - ImPlot::SetupAxisLinks(ImAxis_X1, &x_min, &x_max); - ImPlot::SetupAxis(ImAxis_X1, "time since dataset start [s]"); - ImPlot::PlotLine("yaw", ts, imu_data_plot.yaw.data(), ts_n); - ImPlot::PlotLine("pitch", ts, imu_data_plot.pitch.data(), ts_n); - ImPlot::PlotLine("roll", ts, imu_data_plot.roll.data(), ts_n); - if (has_annotation) - ImPlot::TagX(annotation, ImVec4(1, 0, 0, 1)); - ImPlot::EndPlot(); - } - - if (!photo_files_ts.empty() && ImPlot::BeginPlot("Photos")) - { - ImPlot::SetupAxisLimits(ImAxis_X1, x_min, x_max, ImGuiCond_Once); - ImPlot::SetupAxisLinks(ImAxis_X1, &x_min, &x_max); - ImPlot::SetupAxis(ImAxis_X1, "time since dataset start [s]"); - // plot photos timestamps, also relative to the dataset start - std::vector photo_timestamps; - std::vector dummy; - for (const auto& [ts_ns, fn] : photo_files_ts) - { - photo_timestamps.push_back(static_cast(ts_ns) / 1e9 - t0); - dummy.push_back(0.0); - } - ImPlot::PlotScatter("photos", photo_timestamps.data(), dummy.data(), (int)photo_timestamps.size()); - if (has_annotation) - ImPlot::TagX(annotation, ImVec4(1, 0, 0, 1)); - ImPlot::EndPlot(); - } - } - - if (ImGui::Button("Save 'ts gyr_x gyr_y gyr_z acc_x acc_y acc_z yaw_rad pitch_rad roll_rad' to csv")) - { - std::string output_file_name = ""; - output_file_name = mandeye::fd::SaveFileDialog("Save IMU data", {}, ""); - spdlog::info("file to save: '{}'", output_file_name); - - ofstream file; - file.open(output_file_name); - file << std::setprecision(20); - for (size_t i = 0; i < imu_data_plot.timestampLidar.size(); i++) - { - file << imu_data_plot.timestampLidar[i] << " " << imu_data_plot.angX[i] << " " << imu_data_plot.angY[i] << " " - << imu_data_plot.angZ[i] << " " << imu_data_plot.accX[i] << " " << imu_data_plot.accY[i] << " " - << imu_data_plot.accZ[i] << " " << imu_data_plot.yaw[i] << " " << imu_data_plot.pitch[i] << " " - << imu_data_plot.roll[i] << std::endl; - } - - file.close(); - } - } - - ImGui::End(); -} - -void settings_gui() -{ - if (ImGui::Begin("Settings", &is_settings_gui)) - { - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::InputInt("number_of_points_threshold", &number_of_points_threshold); - if (number_of_points_threshold < 1) - number_of_points_threshold = 1; - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text("Max number of points per rendered chunk (one 'Index' step)."); - ImGui::Text("Lower = shorter time span per chunk = finer time navigation with the Index slider."); - ImGui::EndTooltip(); - } - ImGui::BeginDisabled(!is_init); - ImGui::SameLine(); - if (ImGui::Button("Rebin")) - rebuildAllData(true); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Re-chunk the already loaded data with the new threshold, keeping the current time position"); - ImGui::EndDisabled(); - if (is_init) - ImGui::Text("Chunks: %d", static_cast(all_data.size())); - - ImGui::InputDouble("VQF tauAcc [s]", &vqf_tauAcc); - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text("VQF accelerometer time constant (tauAcc) in seconds."); - ImGui::Text("Controls how strongly accelerometer corrects the gyroscope-based orientation."); - ImGui::Text("Higher = more gyro trust (stable but may drift). Lower = more acc trust (noisy but no drift)."); - ImGui::EndTooltip(); - } - - // ImGui::Checkbox("is_slerp", &is_slerp); - - ImGui::PopItemWidth(); - - ImGui::BeginDisabled(!is_init); - if (ImGui::Button("Save point cloud")) - { - std::string output_file_name = ""; - output_file_name = mandeye::fd::SaveFileDialog("Save las or laz file", mandeye::fd::LAS_LAZ_filter); - - if (output_file_name.size() > 0) - { - spdlog::info("las or laz file to save: '{}'", output_file_name); - - std::vector pointcloud; - std::vector intensity; - std::vector timestamps; - - /*if (index_rendered_points_local >= 0 && index_rendered_points_local < all_points_local.size()) - { - for (size_t i = 0; i < all_points_local[index_rendered_points_local].size(); i++) - { - pointcloud.emplace_back(all_points_local[index_rendered_points_local][i].point.x(), - all_points_local[index_rendered_points_local][i].point.y(), all_points_local[index_rendered_points_local][i].point.z()); - intensity.push_back(all_points_local[index_rendered_points_local][i].intensity); - timestamps.push_back(all_points_local[index_rendered_points_local][i].timestamp); - } - }*/ - - if (!exportLaz(output_file_name, pointcloud, intensity, timestamps, 0, 0, 0)) - spdlog::error("problem with saving file: '{}'", output_file_name); - } - } - ImGui::EndDisabled(); - - ImGui::Separator(); - - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::InputDouble("Distance bucket [m]", &distance_bucket); - ImGui::InputDouble("Polar angle [deg]", &polar_angle_deg); - ImGui::InputDouble("Azimutal angle [deg]", &azimutal_angle_deg); - ImGui::InputDouble("Max distance LiDAR", &max_distance_lidar); - ImGui::InputInt("robust_and_accurate_lidar_odometry_iterations", &robust_and_accurate_lidar_odometry_iterations); - ImGui::Checkbox("Use multithread", &useMultithread); - ImGui::Text("Pose component weights for optimization:"); - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text("Value guideline:"); - ImGui::Text("1e6: almost rigid motion, prior dominates (default)"); - ImGui::Text("1e4: small corrections allowed"); - ImGui::Text("1e2: free alignment"); - ImGui::Text(" 0: motion model ignored"); - ImGui::EndTooltip(); - } - ImGui::InputDouble("wx", &wx); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Translation penaltie for %s", xText); - ImGui::InputDouble("wy", &wy); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Translation penaltie for %s", yText); - ImGui::InputDouble("wz", &wz); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Translation penaltie for %s", zText); - ImGui::InputDouble("wom", &wom); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(omText); - ImGui::InputDouble("wfi", &wfi); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(fiText); - ImGui::InputDouble("wka", &wka); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(kaText); - ImGui::PopItemWidth(); - - ImGui::NewLine(); - - if (ImGui::Button("Optimize")) - optimize(); - - ImGui::Separator(); - - if (ImGui::Button("Print to console debug text")) - { - double max_diff = 0; - if (index_rendered_points_local >= 0 && index_rendered_points_local < all_data.size()) - { - for (size_t i = 0; i < all_data[index_rendered_points_local].points_local.size(); i++) - { - auto lower = std::lower_bound( - all_data[index_rendered_points_local].timestamps.begin(), - all_data[index_rendered_points_local].timestamps.end(), - all_data[index_rendered_points_local].points_local[i].timestamp, - [](std::pair lhs, double rhs) -> bool - { - return lhs.first < rhs; - }); - - int index_pose = std::distance(all_data[index_rendered_points_local].timestamps.begin(), lower) - 1; - - spdlog::info( - "poses {}/{}: point TS [s] - pose TS [s] = ... [s]", - index_pose, - all_data[index_rendered_points_local].poses.size()); - - if (index_pose >= 0 && index_pose < all_data[index_rendered_points_local].poses.size()) - { - spdlog::info( - "{:.20g} - {:.20g} = {:.20g}", - all_data[index_rendered_points_local].points_local[i].timestamp, - all_data[index_rendered_points_local].timestamps[index_pose].first, - all_data[index_rendered_points_local].points_local[i].timestamp - - all_data[index_rendered_points_local].timestamps[index_pose].first); - - if (fabs( - all_data[index_rendered_points_local].points_local[i].timestamp - - all_data[index_rendered_points_local].timestamps[index_pose].first) > max_diff) - { - // spdlog::info("{:.20g}", all_data[index_rendered_points_local].points_local[i].timestamp); - max_diff = fabs( - all_data[index_rendered_points_local].points_local[i].timestamp - - all_data[index_rendered_points_local].timestamps[index_pose].first); - } - } - } - spdlog::info("max_diff: {} [s]", max_diff); - spdlog::info("----------------"); - for (size_t k = 0; k < all_data[index_rendered_points_local].timestamps.size(); k++) - spdlog::info("{:.20g}", all_data[index_rendered_points_local].timestamps[k].first); - } - } - } - - ImGui::End(); -} - -void display() -{ - ImGuiIO& io = ImGui::GetIO(); - glViewport(0, 0, (GLsizei)io.DisplaySize.x, (GLsizei)io.DisplaySize.y); - - 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); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - updateCameraTransition(); - - viewLocal = Eigen::Affine3f::Identity(); - - if (!is_ortho) - { - reshape((GLsizei)io.DisplaySize.x, (GLsizei)io.DisplaySize.y); - - viewLocal.translate(rotation_center); - - viewLocal.translate(Eigen::Vector3f(translate_x, translate_y, translate_z)); - if (!lock_z) - viewLocal.rotate(Eigen::AngleAxisf(rotate_x * DEG_TO_RAD, Eigen::Vector3f::UnitX())); - else - viewLocal.rotate(Eigen::AngleAxisf(-90.0 * DEG_TO_RAD, Eigen::Vector3f::UnitX())); - viewLocal.rotate(Eigen::AngleAxisf(rotate_y * DEG_TO_RAD, Eigen::Vector3f::UnitZ())); - - viewLocal.translate(-rotation_center); - - glLoadMatrixf(viewLocal.matrix().data()); - } - else - updateOrthoView(); - - // - /* glPointSize(point_size); - glBegin(GL_POINTS); - if (index_rendered_points_local >= 0 && index_rendered_points_local < all_points_local.size()) - { - for (size_t i = 0; i < all_points_local[index_rendered_points_local].size(); i++) - { - if (all_lidar_ids[index_rendered_points_local][i] == 0) - { - glColor3f(pc_color.x, pc_color.y, pc_color.z); - } - else - { - glColor3f(pc_color2.x, pc_color2.y, pc_color2.z); - } - glVertex3f(all_points_local[index_rendered_points_local][i].point.x(), - all_points_local[index_rendered_points_local][i].point.y(), all_points_local[index_rendered_points_local][i].point.z()); - } - } - glEnd(); - glPointSize(1);*/ - - glPointSize(point_size); - glBegin(GL_POINTS); - if (index_rendered_points_local >= 0 && index_rendered_points_local < all_data.size()) - { - double max_diff = 0.0; - float max_intensity = 0.0f; - for (size_t i = 0; i < all_data[index_rendered_points_local].points_local.size(); i++) - { - if (color_by_intensity && all_data[index_rendered_points_local].points_local[i].intensity > max_intensity) - max_intensity = all_data[index_rendered_points_local].points_local[i].intensity; - - auto lower = std::lower_bound( - all_data[index_rendered_points_local].timestamps.begin(), - all_data[index_rendered_points_local].timestamps.end(), - all_data[index_rendered_points_local].points_local[i].timestamp, - [](std::pair lhs, double rhs) -> bool - { - return lhs.first < rhs; - }); - int index_pose = std::distance(all_data[index_rendered_points_local].timestamps.begin(), lower) - 1; - if (index_pose >= 0 && index_pose < all_data[index_rendered_points_local].poses.size()) - { - if (fabs( - all_data[index_rendered_points_local].points_local[i].timestamp - - all_data[index_rendered_points_local].timestamps[index_pose].first) > max_diff) - { - max_diff = fabs( - all_data[index_rendered_points_local].points_local[i].timestamp - - all_data[index_rendered_points_local].timestamps[index_pose].first); - } - } - } - const float inv_max_intensity = max_intensity > 0.0f ? 1.0f / max_intensity : 0.0f; - - for (size_t i = 0; i < all_data[index_rendered_points_local].points_local.size(); i++) - { - auto lower = std::lower_bound( - all_data[index_rendered_points_local].timestamps.begin(), - all_data[index_rendered_points_local].timestamps.end(), - all_data[index_rendered_points_local].points_local[i].timestamp, - [](std::pair lhs, double rhs) -> bool - { - return lhs.first < rhs; - }); - - int index_pose = std::distance(all_data[index_rendered_points_local].timestamps.begin(), lower) - 1; - - if (max_diff < 0.1) - { - if (index_pose >= 0 && index_pose < all_data[index_rendered_points_local].poses.size()) - { - // if (fabs(all_data[index_rendered_points_local].timestamps[index_pose].first - - // all_data[index_rendered_points_local].points_local[i].timestamp) < 0.001) - //{ - Eigen::Affine3d m = all_data[index_rendered_points_local].poses[index_pose]; - Eigen::Vector3d p = m * all_data[index_rendered_points_local].points_local[i].point; - - if (color_by_intensity) - { - float ii = all_data[index_rendered_points_local].points_local[i].intensity * inv_max_intensity; - ii = std::clamp(ii, 0.0f, 1.0f); - if (intensity_gamma != 1.0f) - ii = std::pow(ii, intensity_gamma); - glColor3f(ii, ii, ii); - } - else if (all_data[index_rendered_points_local].lidar_ids[i] == 0) - glColor3f(pc_color.x, pc_color.y, pc_color.z); - else - glColor3f(pc_color2.x, pc_color2.y, pc_color2.z); - - glVertex3f(p.x(), p.y(), p.z()); - //} - } - } - } - } - glEnd(); - glPointSize(1); - - if (index_rendered_points_local >= 0 && index_rendered_points_local < all_data.size()) - { - for (size_t i = 0; i < all_data[index_rendered_points_local].points_local.size(); i++) - { - auto lower = std::lower_bound( - all_data[index_rendered_points_local].timestamps.begin(), - all_data[index_rendered_points_local].timestamps.end(), - all_data[index_rendered_points_local].points_local[i].timestamp, - [](std::pair lhs, double rhs) -> bool - { - return lhs.first < rhs; - }); - - int index_pose = std::distance(all_data[index_rendered_points_local].timestamps.begin(), lower) - 1; - - if (index_pose >= 0 && index_pose < all_data[index_rendered_points_local].poses.size()) - { - /*Eigen::Affine3d m = all_data[index_rendered_points_local].poses[index_pose]; - Eigen::Vector3d p = m * all_data[index_rendered_points_local].points_local[i].point; - - if (all_data[index_rendered_points_local].lidar_ids[i] == 0) - { - glColor3f(pc_color.x, pc_color.y, pc_color.z); - } - else - { - glColor3f(pc_color2.x, pc_color2.y, pc_color2.z); - } - glVertex3f(p.x(), p.y(), p.z());*/ - - Eigen::Affine3d m = all_data[index_rendered_points_local].poses[index_pose]; - glLineWidth(2.0); - glBegin(GL_LINES); - glColor3f(1.0f, 0.0f, 0.0f); - glVertex3f(m(0, 3), m(1, 3), m(2, 3)); - glVertex3f(m(0, 3) + m(0, 0), m(1, 3) + m(1, 0), m(2, 3) + m(2, 0)); - - glColor3f(0.0f, 1.0f, 0.0f); - glVertex3f(m(0, 3), m(1, 3), m(2, 3)); - glVertex3f(m(0, 3) + m(0, 1), m(1, 3) + m(1, 1), m(2, 3) + m(2, 1)); - - glColor3f(0.0f, 0.0f, 1.0f); - glVertex3f(m(0, 3), m(1, 3), m(2, 3)); - glVertex3f(m(0, 3) + m(0, 2), m(1, 3) + m(1, 2), m(2, 3) + m(2, 2)); - glEnd(); - glLineWidth(1.0); - break; - } - } - } - - if (show_rgd_nn) - { - glColor3f(0, 0, 0); - glBegin(GL_LINES); - for (const auto& nn : rgd_nn) - { - glVertex3f(nn.first.x(), nn.first.y(), nn.first.z()); - glVertex3f(nn.second.x(), nn.second.y(), nn.second.z()); - } - glEnd(); - } - - if (show_mean_cov) - { - for (const auto& mc : mean_cov) - draw_ellipse(mc.second, mc.first, Eigen::Vector3f(1, 0, 0), 1); - } - - showAxes(); - - ImGui_ImplOpenGL2_NewFrame(); - ImGui_ImplGLUT_NewFrame(); - ImGui::NewFrame(); - - ShowMainDockSpace(); - - view_kbd_shortcuts(); - - if (all_data.size() > 0) - { - 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 >= all_data.size()) - index_rendered_points_local = all_data.size() - 1; - } - - // ask to load the nearest photo - if (show_cameras_data && index_rendered_points_local >= 0 && index_rendered_points_local < indexes_to_filename.size()) - { - double ts = all_data[index_rendered_points_local].points_local[0].timestamp; // * 1e9; - render_nearest_photo(ts); - } - - if (ImGui::BeginMainMenuBar()) - { - { - if (ImGui::Button("Open folder")) - openFolder(); - if (ImGui::IsItemHovered()) - 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)); - ImGui::SameLine(); - } - - if (ImGui::BeginMenu("View")) - { - ImGui::SetNextItemWidth(ImGuiNumberWidth); - ImGui::InputInt("Points size", &point_size); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("keyboard 1-9 keys"); - if (point_size < 1) - point_size = 1; - else if (point_size > 10) - point_size = 10; - - ImGui::Separator(); - - if (ImGui::MenuItem("Orthographic", "key O", &is_ortho)) - { - 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)"); - - ImGui::MenuItem("Show axes", "key X", &show_axes); - ImGui::MenuItem("Show compass/ruler", "key C", &compass_ruler); - - ImGui::MenuItem("Lock Z", "Shift + Z", &lock_z, !is_ortho); - - ImGui::Separator(); - - ImGui::BeginDisabled(!is_init); - if (ImGui::MenuItem("Show RGD / NN", nullptr, &show_rgd_nn)) - { - if (show_rgd_nn) - rgd_nn = get_nn(); - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Show Regular/Range Grid Data / Nearest Neighbors"); - - if (ImGui::MenuItem("Show mean covs", nullptr, &show_mean_cov)) - { - if (show_mean_cov) - mean_cov = get_mean_cov(); - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Show the mean and covariance ellipsoid representation"); - - ImGui::MenuItem("Show IMU data", nullptr, &show_imu_data); - ImGui::MenuItem("Show cameras data", nullptr, &show_cameras_data); - - ImGui::MenuItem("Color by intensity", nullptr, &color_by_intensity); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Render points as grayscale from LiDAR intensity (normalized to current block max)"); - if (color_by_intensity) - { - ImGui::SetNextItemWidth(ImGuiNumberWidth); - ImGui::SliderFloat("Intensity gamma", &intensity_gamma, 0.1f, 3.0f, "%.2f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Gamma applied to normalized intensity (<1 brightens, >1 darkens)"); - } - ImGui::EndDisabled(); - - ImGui::Separator(); - - if (ImGui::BeginMenu("Colors")) - { - ImGui::ColorEdit3("Background", (float*)&bg_color, ImGuiColorEditFlags_NoInputs); - ImGui::ColorEdit3("Point cloud 1", (float*)&pc_color, ImGuiColorEditFlags_NoInputs); - ImGui::ColorEdit3("Point cloud 2", (float*)&pc_color2, ImGuiColorEditFlags_NoInputs); - - ImGui::EndMenu(); - } - - ImGui::Separator(); - - ImGui::MenuItem("Settings", nullptr, &is_settings_gui); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Show power user settings window with more parameters"); - - ImGui::EndMenu(); - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Scene view relevant parameters"); - - camMenu(); - - ImGui::SameLine(); - ImGui::Dummy(ImVec2(20, 0)); - ImGui::SameLine(); - - if (all_data.size() > 0) - { - int tempIndex = index_rendered_points_local; - ImGui::Text("Index: "); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Index of rendered points local"); - ImGui::SameLine(); - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::SliderInt("##irpls", &tempIndex, 0, static_cast(all_data.size() - 1)); - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - std::string fn = laz_files[indexes_to_filename[index_rendered_points_local]]; - ImGui::Text(fn.c_str()); - ImGui::EndTooltip(); - } - ImGui::SameLine(); - ImGui::InputInt("##irpli", &tempIndex, 1, 10); - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - std::string fn = laz_files[indexes_to_filename[index_rendered_points_local]]; - ImGui::Text(fn.c_str()); - ImGui::EndTooltip(); - } - ImGui::PopItemWidth(); - - if ((tempIndex >= 0) && (tempIndex < all_data.size())) - index_rendered_points_local = tempIndex; - - ImGui::SameLine(); - double ts = all_data[index_rendered_points_local].points_local[0].timestamp; // * 1e9; - ImGui::Text("Timestamp: %.6f [ns]", ts); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Click to copy to clipboard"); - if (ImGui::IsItemClicked()) - { - char tmp[64]; - snprintf(tmp, sizeof(tmp), "%.6f", ts); - ImGui::SetClipboardText(tmp); - } - - ImGui::SameLine(); - ImGui::Dummy(ImVec2(20, 0)); - ImGui::SameLine(); - } - - ImGui::SameLine(); - ImGui::Text("(%.1f FPS)", ImGui::GetIO().Framerate); - - ImGui::SameLine( - ImGui::GetWindowWidth() - ImGui::CalcTextSize("Info").x - ImGui::GetStyle().ItemSpacing.x * 2 - - ImGui::GetStyle().FramePadding.x * 2); - - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(4, 2)); - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::GetStyleColorVec4(ImGuiCol_HeaderHovered)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImGui::GetStyleColorVec4(ImGuiCol_Header)); - if (ImGui::SmallButton("Info")) - info_gui = !info_gui; - - ImGui::PopStyleVar(2); - ImGui::PopStyleColor(3); - - ImGui::EndMainMenuBar(); - } - - info_window(infoLines, appShortcuts); - - if (compass_ruler) - drawMiniCompassWithRuler(); - - if (show_cameras_data && photos::photo_texture_cam0) - { - if (ImGui::Begin("CAM0")) - { - using namespace photos; - ImGui::Text("fn name: %s ", photos::imgToShowFn.c_str()); - ImGui::Text("timestamp: %s", std::to_string(photos::nearestTs).c_str()); - // get available size - DisplayImageFit((ImTextureID)photos::photo_texture_cam0, photo_width_cam0, photo_height_cam0); - } - - ImGui::End(); - } - - if (show_imu_data) - imu_data_gui(); - - if (is_settings_gui) - settings_gui(); - - ImGui::Render(); - ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData()); - - glutSwapBuffers(); - glutPostRedisplay(); -} - -void mouse(int glut_button, int state, int x, int y) -{ - ImGuiIO& io = ImGui::GetIO(); - io.MousePos = ImVec2((float)x, (float)y); - int button = -1; - if (glut_button == GLUT_LEFT_BUTTON) - button = 0; - if (glut_button == GLUT_RIGHT_BUTTON) - button = 1; - if (glut_button == GLUT_MIDDLE_BUTTON) - button = 2; - if (button != -1 && state == GLUT_DOWN) - io.MouseDown[button] = true; - if (button != -1 && state == GLUT_UP) - io.MouseDown[button] = false; - - static int glutMajorVersion = glutGet(GLUT_VERSION) / 10000; - if (state == GLUT_DOWN && (glut_button == 3 || glut_button == 4) && glutMajorVersion < 3) - { - wheel(glut_button, glut_button == 3 ? 1 : -1, x, y); - } - - if (!io.WantCaptureMouse) - { - if (glut_button == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN && io.KeyCtrl) - { - } - - if (state == GLUT_DOWN) - { - mouse_buttons |= 1 << glut_button; - } - else if (state == GLUT_UP) - { - mouse_buttons = 0; - } - mouse_old_x = x; - mouse_old_y = y; - } -} - -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); - ImPlot::CreateContext(); - - if (argc == 2) - { - std::vector input_file_names; - - if (fs::exists(argv[1])) - { - for (const auto& entry : fs::recursive_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(); - ImGui_ImplGLUT_Shutdown(); - ImGui::DestroyContext(); - ImPlot::DestroyContext(); - } catch (const std::bad_alloc& e) - { - spdlog::error("System is out of memory : {}", e.what()); - mandeye::fd::OutOfMemMessage(); - } catch (const std::exception& e) - { - spdlog::error(e.what()); - } catch (...) - { - spdlog::error("Unknown fatal error occurred!"); - } - - return 0; -} \ No newline at end of file diff --git a/apps/mandeye_raw_data_viewer_legacy/resource.h b/apps/mandeye_raw_data_viewer_legacy/resource.h deleted file mode 100644 index 4f3204ca..00000000 --- a/apps/mandeye_raw_data_viewer_legacy/resource.h +++ /dev/null @@ -1,17 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by resource.rc -// -#define IDI_ICON1 101 // application icon -#define VS_VERSION_INFO 1 // version info - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 106 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1000 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/apps/mandeye_raw_data_viewer_legacy/resource.rc b/apps/mandeye_raw_data_viewer_legacy/resource.rc deleted file mode 100644 index fcf8049b..00000000 --- a/apps/mandeye_raw_data_viewer_legacy/resource.rc +++ /dev/null @@ -1,50 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "resource.h" -///////////////////////////////////////////////////////////////////////////// -// English (United States) resources - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -IDI_ICON1 ICON "icon.ico" - - -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO - FILEVERSION 0,0,100,1 - PRODUCTVERSION 0,0,100,1 - FILEFLAGSMASK 0x3fL - FILEOS 0x40004 - FILETYPE 0x1 -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904B0" - BEGIN - VALUE "CompanyName", "Mandeye\0" - VALUE "FileDescription", "HDMapping Raw Data Viewer\0" - VALUE "FileVersion", "0.100.1\0" - VALUE "InternalName", "Raw data viewer\0" - VALUE "LegalCopyright", "(c) 2026 github.com/MapsHD/HDMapping\0" - VALUE "OriginalFilename", "mandeye_raw_data_viewer.exe\0" - VALUE "ProductVersion", "0.100.1\0" - VALUE "ProgramID", "github.com/MapsHD/HDMapping\0" - VALUE "ProductName", "HDMapping\0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 0x04B0 - END -END -///////////////////////////////////////////////////////////////////////////// - diff --git a/apps/multi_session_registration_legacy/CMakeLists.txt b/apps/multi_session_registration_legacy/CMakeLists.txt deleted file mode 100644 index 01c03fbe..00000000 --- a/apps/multi_session_registration_legacy/CMakeLists.txt +++ /dev/null @@ -1,73 +0,0 @@ -cmake_minimum_required(VERSION 4.0.0) - -# Legacy GLUT + legacy immediate-mode OpenGL build of step3, kept side by -# side with apps/multi_session_registration (raylib-based since it was -# ported off GLUT), the same way step2 keeps multi_view_tls_registration_legacy. -# This is a full, independent copy of the app as it was before that port -- -# not sharing translation units with apps/multi_session_registration -- so -# the two can diverge or be retired independently. -project(multi_session_registration_step_3_legacy) - -# Source files -set(SOURCES - multi_session_registration.cpp - multi_session_factor_graph.cpp - "../../core/src/utils.cpp" -) - -# Windows: add resource file -if(WIN32) - list(APPEND SOURCES "resource.rc") -endif() - -add_executable( - multi_session_registration_step_3_legacy ${SOURCES} - ) - -target_compile_definitions(multi_session_registration_step_3_legacy PRIVATE -DWITH_GUI=1) - -target_include_directories( - multi_session_registration_step_3_legacy - PRIVATE include - ${REPOSITORY_DIRECTORY}/core/include - ${REPOSITORY_DIRECTORY}/core_hd_mapping/include - ${THIRDPARTY_DIRECTORY} - ${THIRDPARTY_DIRECTORY}/glm - ${EIGEN3_INCLUDE_DIR} - ${THIRDPARTY_DIRECTORY}/imgui - ${THIRDPARTY_DIRECTORY}/imgui/backends - ${THIRDPARTY_DIRECTORY}/ImGuizmo - ${THIRDPARTY_DIRECTORY}/json/include - ${THIRDPARTY_DIRECTORY}/portable-file-dialogs-master - ${THIRDPARTY_DIRECTORY}/glew-cmake/include - ${THIRDPARTY_DIRECTORY}/observation_equations/codes - ${THIRDPARTY_DIRECTORY}/freeglut/include - ${LASZIP_INCLUDE_DIR}/LASzip/include) - -target_link_libraries( - multi_session_registration_step_3_legacy - # PRIVATE ${THIRDPARTY_DIRECTORY}/glew-2.2.0/lib/Release/x64/glew32s.lib - ${FREEGLUT_LIBRARY} - ${OPENGL_gl_LIBRARY} - OpenGL::GLU - ${PLATFORM_LASZIP_LIB} - ${PLATFORM_MISCELLANEOUS_LIBS} - ${CORE_LIBRARIES} - ${GUI_LIBRARIES}) - -if(WIN32) - add_custom_command( - TARGET multi_session_registration_step_3_legacy - POST_BUILD - COMMAND - ${CMAKE_COMMAND} -E copy - $ - $ - COMMAND_EXPAND_LISTS) -endif() - -if (MSVC) - target_compile_options(multi_session_registration_step_3_legacy PRIVATE /bigobj) -endif() - -hdmapping_install_app(multi_session_registration_step_3_legacy) \ No newline at end of file diff --git a/apps/multi_session_registration_legacy/icon.ico b/apps/multi_session_registration_legacy/icon.ico deleted file mode 100644 index f8a2cb27..00000000 Binary files a/apps/multi_session_registration_legacy/icon.ico and /dev/null differ diff --git a/apps/multi_session_registration_legacy/multi_session_factor_graph.cpp b/apps/multi_session_registration_legacy/multi_session_factor_graph.cpp deleted file mode 100644 index e4afff84..00000000 --- a/apps/multi_session_registration_legacy/multi_session_factor_graph.cpp +++ /dev/null @@ -1,928 +0,0 @@ -#include "multi_session_factor_graph.h" - -#include -#include - -#include -#include -#include -#include -#include - -bool optimize(std::vector& sessions, const std::vector& edges, TaitBryanPose motion_model_weights) -{ - for (auto& session : sessions) - { - for (auto& pc : session.point_clouds_container.point_clouds) - pc.m_pose_temp = pc.m_pose; - } - - std::vector sums; - sums.push_back(0); - int sum = 0; - std::vector vfixed_x; - std::vector vfixed_y; - std::vector vfixed_z; - std::vector vfixed_om; - std::vector vfixed_fi; - std::vector vfixed_ka; - - for (size_t i = 0; i < sessions.size(); i++) - { - sum += sessions[i].point_clouds_container.point_clouds.size(); - sums.push_back(sum); - - for (size_t j = 0; j < sessions[i].point_clouds_container.point_clouds.size(); j++) - { - vfixed_x.push_back(sessions[i].point_clouds_container.point_clouds[j].fixed_x); - vfixed_y.push_back(sessions[i].point_clouds_container.point_clouds[j].fixed_y); - vfixed_z.push_back(sessions[i].point_clouds_container.point_clouds[j].fixed_z); - - vfixed_om.push_back(sessions[i].point_clouds_container.point_clouds[j].fixed_om); - vfixed_fi.push_back(sessions[i].point_clouds_container.point_clouds[j].fixed_fi); - vfixed_ka.push_back(sessions[i].point_clouds_container.point_clouds[j].fixed_ka); - } - } - - bool is_ok = true; - std::vector m_poses; - std::vector poses_motion_model; - std::vector index_trajectory; - - for (size_t j = 0; j < sessions.size(); j++) - { - for (size_t i = 0; i < sessions[j].point_clouds_container.point_clouds.size(); i++) - { - m_poses.push_back(sessions[j].point_clouds_container.point_clouds[i].m_pose); - poses_motion_model.push_back(sessions[j].point_clouds_container.point_clouds[i].m_initial_pose); - // poses_motion_model.push_back(sessions[j].point_clouds_container.point_clouds[i].m_pose); - index_trajectory.push_back(j); - } - } - - std::vector poses; - - bool is_wc = true; - bool is_cw = false; - int iterations = 1; - bool is_fix_first_node = true; - // std::vector indexes_ground_truth; - for (size_t j = 0; j < sessions.size(); j++) - { - for (size_t i = 0; i < sessions[j].point_clouds_container.point_clouds.size(); i++) - { - if (is_wc) - { - poses.push_back(pose_tait_bryan_from_affine_matrix(sessions[j].point_clouds_container.point_clouds[i].m_pose)); - } - else if (is_cw) - { - poses.push_back(pose_tait_bryan_from_affine_matrix(sessions[j].point_clouds_container.point_clouds[i].m_pose.inverse())); - } - // if (sessions[j].is_ground_truth) - //{ - // indexes_ground_truth.push_back(poses.size() - 1); - // } - } - } - - std::vector all_edges; - - // motion model edges; - // double angle = * DEG_TO_RAD; - // double wangle = 1.0 / (angle * angle); - - for (size_t i = 1; i < poses_motion_model.size(); i++) - { - if (index_trajectory[i - 1] == index_trajectory[i]) - { - Eigen::Affine3d m_rel = poses_motion_model[i - 1].inverse() * poses_motion_model[i]; - Edge edge; - edge.index_from = i - 1; - edge.index_to = i; - edge.index_session_from = -1; - edge.index_session_to = -1; - edge.relative_pose_tb = pose_tait_bryan_from_affine_matrix(m_rel); - edge.relative_pose_tb_weights.om = 1.0 / (motion_model_weights.om * DEG_TO_RAD * motion_model_weights.om * DEG_TO_RAD); - edge.relative_pose_tb_weights.fi = 1.0 / (motion_model_weights.fi * DEG_TO_RAD * motion_model_weights.fi * DEG_TO_RAD); - edge.relative_pose_tb_weights.ka = 1.0 / (motion_model_weights.ka * DEG_TO_RAD * motion_model_weights.ka * DEG_TO_RAD); - edge.relative_pose_tb_weights.px = - motion_model_weights.px > 0 ? 1.0 / (motion_model_weights.px * motion_model_weights.px) : 1000000.0; - edge.relative_pose_tb_weights.py = - motion_model_weights.py > 0 ? 1.0 / (motion_model_weights.py * motion_model_weights.py) : 1000000.0; - edge.relative_pose_tb_weights.pz = - motion_model_weights.pz > 0 ? 1.0 / (motion_model_weights.pz * motion_model_weights.pz) : 1000000.0; - all_edges.push_back(edge); - } - } - - for (size_t i = 0; i < sessions.size(); i++) - { - for (size_t j = 0; j < sessions[i].pose_graph_loop_closure.edges.size(); j++) - { - Edge edge; - edge.index_from = sessions[i].pose_graph_loop_closure.edges[j].index_from + sums[i]; - edge.index_to = sessions[i].pose_graph_loop_closure.edges[j].index_to + sums[i]; - edge.relative_pose_tb = sessions[i].pose_graph_loop_closure.edges[j].relative_pose_tb; - edge.relative_pose_tb_weights = sessions[i].pose_graph_loop_closure.edges[j].relative_pose_tb_weights; - // edge.is_fixed_fi = ToDo - all_edges.push_back(edge); - } - } - - for (size_t i = 0; i < edges.size(); i++) - { - Edge edge; - edge.index_from = edges[i].index_from + sums[edges[i].index_session_from]; - edge.index_to = edges[i].index_to + sums[edges[i].index_session_to]; - edge.relative_pose_tb = edges[i].relative_pose_tb; - edge.relative_pose_tb_weights = edges[i].relative_pose_tb_weights; - // edge.is_fixed_fi = ToDo - all_edges.push_back(edge); - } - - for (int iter = 0; iter < iterations; iter++) - { - std::vector> tripletListA; - std::vector> tripletListP; - std::vector> tripletListB; - - for (size_t i = 0; i < all_edges.size(); i++) - { - Eigen::Matrix delta; - Eigen::Matrix jacobian; - // auto relative_pose = pose_tait_bryan_from_affine_matrix(all_edges[i].relative_pose_tb); - if (is_wc) - { - relative_pose_obs_eq_tait_bryan_wc_case1( - delta, - poses[all_edges[i].index_from].px, - poses[all_edges[i].index_from].py, - poses[all_edges[i].index_from].pz, - normalize_angle(poses[all_edges[i].index_from].om), - normalize_angle(poses[all_edges[i].index_from].fi), - normalize_angle(poses[all_edges[i].index_from].ka), - poses[all_edges[i].index_to].px, - poses[all_edges[i].index_to].py, - poses[all_edges[i].index_to].pz, - normalize_angle(poses[all_edges[i].index_to].om), - normalize_angle(poses[all_edges[i].index_to].fi), - normalize_angle(poses[all_edges[i].index_to].ka), - all_edges[i].relative_pose_tb.px, - all_edges[i].relative_pose_tb.py, - all_edges[i].relative_pose_tb.pz, - normalize_angle(all_edges[i].relative_pose_tb.om), - normalize_angle(all_edges[i].relative_pose_tb.fi), - normalize_angle(all_edges[i].relative_pose_tb.ka)); - relative_pose_obs_eq_tait_bryan_wc_case1_jacobian( - jacobian, - poses[all_edges[i].index_from].px, - poses[all_edges[i].index_from].py, - poses[all_edges[i].index_from].pz, - normalize_angle(poses[all_edges[i].index_from].om), - normalize_angle(poses[all_edges[i].index_from].fi), - normalize_angle(poses[all_edges[i].index_from].ka), - poses[all_edges[i].index_to].px, - poses[all_edges[i].index_to].py, - poses[all_edges[i].index_to].pz, - normalize_angle(poses[all_edges[i].index_to].om), - normalize_angle(poses[all_edges[i].index_to].fi), - normalize_angle(poses[all_edges[i].index_to].ka)); - } - else if (is_cw) - { - relative_pose_obs_eq_tait_bryan_cw_case1( - delta, - poses[all_edges[i].index_from].px, - poses[all_edges[i].index_from].py, - poses[all_edges[i].index_from].pz, - normalize_angle(poses[all_edges[i].index_from].om), - normalize_angle(poses[all_edges[i].index_from].fi), - normalize_angle(poses[all_edges[i].index_from].ka), - poses[all_edges[i].index_to].px, - poses[all_edges[i].index_to].py, - poses[all_edges[i].index_to].pz, - normalize_angle(poses[all_edges[i].index_to].om), - normalize_angle(poses[all_edges[i].index_to].fi), - normalize_angle(poses[all_edges[i].index_to].ka), - all_edges[i].relative_pose_tb.px, - all_edges[i].relative_pose_tb.py, - all_edges[i].relative_pose_tb.pz, - normalize_angle(all_edges[i].relative_pose_tb.om), - normalize_angle(all_edges[i].relative_pose_tb.fi), - normalize_angle(all_edges[i].relative_pose_tb.ka)); - relative_pose_obs_eq_tait_bryan_cw_case1_jacobian( - jacobian, - poses[all_edges[i].index_from].px, - poses[all_edges[i].index_from].py, - poses[all_edges[i].index_from].pz, - normalize_angle(poses[all_edges[i].index_from].om), - normalize_angle(poses[all_edges[i].index_from].fi), - normalize_angle(poses[all_edges[i].index_from].ka), - poses[all_edges[i].index_to].px, - poses[all_edges[i].index_to].py, - poses[all_edges[i].index_to].pz, - normalize_angle(poses[all_edges[i].index_to].om), - normalize_angle(poses[all_edges[i].index_to].fi), - normalize_angle(poses[all_edges[i].index_to].ka)); - } - - int ir = tripletListB.size(); - - int ic_1 = all_edges[i].index_from * 6; - int ic_2 = all_edges[i].index_to * 6; - - for (size_t row = 0; row < 6; row++) - { - tripletListA.emplace_back(ir + row, ic_1, -jacobian(row, 0)); - tripletListA.emplace_back(ir + row, ic_1 + 1, -jacobian(row, 1)); - tripletListA.emplace_back(ir + row, ic_1 + 2, -jacobian(row, 2)); - tripletListA.emplace_back(ir + row, ic_1 + 3, -jacobian(row, 3)); - tripletListA.emplace_back(ir + row, ic_1 + 4, -jacobian(row, 4)); - tripletListA.emplace_back(ir + row, ic_1 + 5, -jacobian(row, 5)); - - tripletListA.emplace_back(ir + row, ic_2, -jacobian(row, 6)); - tripletListA.emplace_back(ir + row, ic_2 + 1, -jacobian(row, 7)); - tripletListA.emplace_back(ir + row, ic_2 + 2, -jacobian(row, 8)); - tripletListA.emplace_back(ir + row, ic_2 + 3, -jacobian(row, 9)); - tripletListA.emplace_back(ir + row, ic_2 + 4, -jacobian(row, 10)); - tripletListA.emplace_back(ir + row, ic_2 + 5, -jacobian(row, 11)); - } - - tripletListB.emplace_back(ir, 0, delta(0, 0)); - tripletListB.emplace_back(ir + 1, 0, delta(1, 0)); - tripletListB.emplace_back(ir + 2, 0, delta(2, 0)); - tripletListB.emplace_back(ir + 3, 0, normalize_angle(delta(3, 0))); - tripletListB.emplace_back(ir + 4, 0, normalize_angle(delta(4, 0))); - tripletListB.emplace_back(ir + 5, 0, normalize_angle(delta(5, 0))); - - tripletListP.emplace_back(ir, ir, all_edges[i].relative_pose_tb_weights.px * get_cauchy_w(delta(0, 0), 1)); - tripletListP.emplace_back(ir + 1, ir + 1, all_edges[i].relative_pose_tb_weights.py * get_cauchy_w(delta(1, 0), 1)); - tripletListP.emplace_back(ir + 2, ir + 2, all_edges[i].relative_pose_tb_weights.pz * get_cauchy_w(delta(2, 0), 1)); - tripletListP.emplace_back(ir + 3, ir + 3, all_edges[i].relative_pose_tb_weights.om * get_cauchy_w(delta(3, 0), 1)); - tripletListP.emplace_back(ir + 4, ir + 4, all_edges[i].relative_pose_tb_weights.fi * get_cauchy_w(delta(4, 0), 1)); - tripletListP.emplace_back(ir + 5, ir + 5, all_edges[i].relative_pose_tb_weights.ka * get_cauchy_w(delta(5, 0), 1)); - } - - if (is_fix_first_node) - { - int ir = tripletListB.size(); - tripletListA.emplace_back(ir, 0, 1); - tripletListA.emplace_back(ir + 1, 1, 1); - tripletListA.emplace_back(ir + 2, 2, 1); - tripletListA.emplace_back(ir + 3, 3, 1); - tripletListA.emplace_back(ir + 4, 4, 1); - tripletListA.emplace_back(ir + 5, 5, 1); - - tripletListP.emplace_back(ir, ir, 0.0001); - tripletListP.emplace_back(ir + 1, ir + 1, 0.0001); - tripletListP.emplace_back(ir + 2, ir + 2, 0.0001); - tripletListP.emplace_back(ir + 3, ir + 3, 0.0001); - tripletListP.emplace_back(ir + 4, ir + 4, 0.0001); - tripletListP.emplace_back(ir + 5, ir + 5, 0.0001); - - tripletListB.emplace_back(ir, 0, 0); - tripletListB.emplace_back(ir + 1, 0, 0); - tripletListB.emplace_back(ir + 2, 0, 0); - tripletListB.emplace_back(ir + 3, 0, 0); - tripletListB.emplace_back(ir + 4, 0, 0); - tripletListB.emplace_back(ir + 5, 0, 0); - - for (size_t i = 1; i < index_trajectory.size(); i++) - { - if (index_trajectory[i - 1] != index_trajectory[i]) - { - ir = tripletListB.size(); - tripletListA.emplace_back(ir, i * 6 + 0, 1); - tripletListA.emplace_back(ir + 1, i * 6 + 1, 1); - tripletListA.emplace_back(ir + 2, i * 6 + 2, 1); - tripletListA.emplace_back(ir + 3, i * 6 + 3, 1); - tripletListA.emplace_back(ir + 4, i * 6 + 4, 1); - tripletListA.emplace_back(ir + 5, i * 6 + 5, 1); - - tripletListP.emplace_back(ir, ir, 0.0001); - tripletListP.emplace_back(ir + 1, ir + 1, 0.0001); - tripletListP.emplace_back(ir + 2, ir + 2, 0.0001); - tripletListP.emplace_back(ir + 3, ir + 3, 0.0001); - tripletListP.emplace_back(ir + 4, ir + 4, 0.0001); - tripletListP.emplace_back(ir + 5, ir + 5, 0.0001); - - tripletListB.emplace_back(ir, 0, 0); - tripletListB.emplace_back(ir + 1, 0, 0); - tripletListB.emplace_back(ir + 2, 0, 0); - tripletListB.emplace_back(ir + 3, 0, 0); - tripletListB.emplace_back(ir + 4, 0, 0); - tripletListB.emplace_back(ir + 5, 0, 0); - } - } - } - - /*double angle = 1.0 * DEG_TO_RAD; - double wangle = 1.0 / (angle * angle); - - for (size_t index = 0; index < indexes_ground_truth.size(); index++) - { - int ir = tripletListB.size(); - int ic = indexes_ground_truth[index] * 6; - tripletListA.emplace_back(ir, ic + 0, 1); - tripletListA.emplace_back(ir + 1, ic + 1, 1); - tripletListA.emplace_back(ir + 2, ic + 2, 1); - tripletListA.emplace_back(ir + 3, ic + 3, 1); - tripletListA.emplace_back(ir + 4, ic + 4, 1); - tripletListA.emplace_back(ir + 5, ic + 5, 1); - - tripletListP.emplace_back(ir , ir , 10000.0); - tripletListP.emplace_back(ir + 1, ir + 1, 10000.0); - tripletListP.emplace_back(ir + 2, ir + 2, 10000.0); - tripletListP.emplace_back(ir + 3, ir + 3, wangle); - tripletListP.emplace_back(ir + 4, ir + 4, wangle); - tripletListP.emplace_back(ir + 5, ir + 5, wangle); - - tripletListB.emplace_back(ir, 0, 0); - tripletListB.emplace_back(ir + 1, 0, 0); - tripletListB.emplace_back(ir + 2, 0, 0); - tripletListB.emplace_back(ir + 3, 0, 0); - tripletListB.emplace_back(ir + 4, 0, 0); - tripletListB.emplace_back(ir + 5, 0, 0); - }*/ - - // gnss - // for (const auto &pc : point_clouds_container.point_clouds) - /*for (size_t index_pose = 0; index_pose < point_clouds_container.point_clouds.size(); index_pose++) - { - const auto &pc = point_clouds_container.point_clouds[index_pose]; - for (size_t i = 0; i < gnss.gnss_poses.size(); i++) - { - double time_stamp = gnss.gnss_poses[i].timestamp; - - auto it = std::lower_bound(pc.local_trajectory.begin(), pc.local_trajectory.end(), - time_stamp, [](const PointCloud::LocalTrajectoryNode &lhs, const double &time) -> bool - { return lhs.timestamp < time; }); - - int index = it - pc.local_trajectory.begin(); - - if (index > 0 && index < pc.local_trajectory.size()) - { - - if (fabs(time_stamp - pc.local_trajectory[index].timestamp) < 10e12) - { - - Eigen::Matrix jacobian; - TaitBryanPose pose_s; - pose_s = pose_tait_bryan_from_affine_matrix(m_poses[index_pose]); - Eigen::Vector3d p_s = pc.local_trajectory[index].m_pose.translation(); - point_to_point_source_to_target_tait_bryan_wc_jacobian(jacobian, pose_s.px, pose_s.py, pose_s.pz, pose_s.om, - pose_s.fi, pose_s.ka, p_s.x(), p_s.y(), p_s.z()); - - double delta_x; - double delta_y; - double delta_z; - Eigen::Vector3d p_t(gnss.gnss_poses[i].x - gnss.offset_x, gnss.gnss_poses[i].y - gnss.offset_y, - gnss.gnss_poses[i].alt - gnss.offset_alt); point_to_point_source_to_target_tait_bryan_wc(delta_x, delta_y, delta_z, pose_s.px, - pose_s.py, pose_s.pz, pose_s.om, pose_s.fi, pose_s.ka, p_s.x(), p_s.y(), p_s.z(), p_t.x(), p_t.y(), p_t.z()); - - std::cout << " delta_x " << delta_x << " delta_y " << delta_y << " delta_z " << delta_z << std::endl; - - int ir = tripletListB.size(); - int ic = index_pose * 6; - for (int row = 0; row < 3; row++) - { - for (int col = 0; col < 6; col++) - { - if (jacobian(row, col) != 0.0) - { - tripletListA.emplace_back(ir + row, ic + col, -jacobian(row, col)); - } - } - } - tripletListP.emplace_back(ir, ir, get_cauchy_w(delta_x, 1)); - tripletListP.emplace_back(ir + 1, ir + 1, get_cauchy_w(delta_y, 1)); - tripletListP.emplace_back(ir + 2, ir + 2, get_cauchy_w(delta_z, 1)); - - tripletListB.emplace_back(ir, 0, delta_x); - tripletListB.emplace_back(ir + 1, 0, delta_y); - tripletListB.emplace_back(ir + 2, 0, delta_z); - - // jacobian3x6 = get_point_to_point_jacobian_tait_bryan(pose_convention, - point_clouds_container.point_clouds[i].m_pose, p_s, p_t); - - // auto m = pc.m_pose * pc.local_trajectory[index].m_pose; - // glVertex3f(m(0, 3), m(1, 3), m(2, 3)); - // glVertex3f(gnss_poses[i].x - offset_x, gnss_poses[i].y - offset_y, gnss_poses[i].alt - offset_alt); - } - } - } - }*/ - // - - for (size_t j = 0; j < sessions.size(); j++) - { - for (size_t jj = 0; jj < sessions[j].ground_control_points.gpcs.size(); jj++) - { - Eigen::Vector3d p_s = - sessions[j] - .point_clouds_container.point_clouds[sessions[j].ground_control_points.gpcs[jj].index_to_node_inner] - .local_trajectory[sessions[j].ground_control_points.gpcs[jj].index_to_node_outer] - .m_pose.translation(); - Eigen::Matrix jacobian; - TaitBryanPose pose_s; - pose_s = pose_tait_bryan_from_affine_matrix( - sessions[j].point_clouds_container.point_clouds[sessions[j].ground_control_points.gpcs[jj].index_to_node_inner].m_pose); - point_to_point_source_to_target_tait_bryan_wc_jacobian( - jacobian, pose_s.px, pose_s.py, pose_s.pz, pose_s.om, pose_s.fi, pose_s.ka, p_s.x(), p_s.y(), p_s.z()); - - double delta_x; - double delta_y; - double delta_z; - Eigen::Vector3d p_t( - sessions[j].ground_control_points.gpcs[jj].x, - sessions[j].ground_control_points.gpcs[jj].y, - sessions[j].ground_control_points.gpcs[jj].z + sessions[j].ground_control_points.gpcs[jj].lidar_height_above_ground); - point_to_point_source_to_target_tait_bryan_wc( - delta_x, - delta_y, - delta_z, - pose_s.px, - pose_s.py, - pose_s.pz, - pose_s.om, - pose_s.fi, - pose_s.ka, - p_s.x(), - p_s.y(), - p_s.z(), - p_t.x(), - p_t.y(), - p_t.z()); - - int ir = tripletListB.size(); - int ic = sessions[j].ground_control_points.gpcs[jj].index_to_node_inner * 6 + sums[j] * 6; - - for (int row = 0; row < 3; row++) - { - for (int col = 0; col < 6; col++) - { - if (jacobian(row, col) != 0.0) - { - tripletListA.emplace_back(ir + row, ic + col, -jacobian(row, col)); - } - } - } - tripletListP.emplace_back( - ir + 0, - ir + 0, - (1.0 / (sessions[j].ground_control_points.gpcs[jj].sigma_x * sessions[j].ground_control_points.gpcs[jj].sigma_x)) * - get_cauchy_w(delta_x, 1)); - tripletListP.emplace_back( - ir + 1, - ir + 1, - (1.0 / (sessions[j].ground_control_points.gpcs[jj].sigma_y * sessions[j].ground_control_points.gpcs[jj].sigma_y)) * - get_cauchy_w(delta_y, 1)); - tripletListP.emplace_back( - ir + 2, - ir + 2, - (1.0 / (sessions[j].ground_control_points.gpcs[jj].sigma_z * sessions[j].ground_control_points.gpcs[jj].sigma_z)) * - get_cauchy_w(delta_z, 1)); - - tripletListB.emplace_back(ir, 0, delta_x); - tripletListB.emplace_back(ir + 1, 0, delta_y); - tripletListB.emplace_back(ir + 2, 0, delta_z); - - std::cout << "gcp: delta_x " << delta_x << " delta_y " << delta_y << " delta_z " << delta_z << std::endl; - } - } - - /////////////////////////////////////////////////////// - for (size_t i = 0; i < sessions.size(); i++) - { - for (size_t index_pose = 0; index_pose < sessions[i].point_clouds_container.point_clouds.size(); index_pose++) - { - if (sessions[i].point_clouds_container.point_clouds[index_pose].fixed_x || sessions[i].is_ground_truth) - { - int ir = tripletListB.size(); - int ic = (index_pose + sums[i]) * 6; - tripletListA.emplace_back(ir + 0, ic, 1000000000000); - tripletListP.emplace_back(ir, ir, 1); - tripletListB.emplace_back(ir, 0, 0); - } - - if (sessions[i].point_clouds_container.point_clouds[index_pose].fixed_y || sessions[i].is_ground_truth) - { - int ir = tripletListB.size(); - int ic = (index_pose + sums[i]) * 6 + 1; - tripletListA.emplace_back(ir + 0, ic, 1000000000000); - tripletListP.emplace_back(ir, ir, 1); - tripletListB.emplace_back(ir, 0, 0); - } - - if (sessions[i].point_clouds_container.point_clouds[index_pose].fixed_z || sessions[i].is_ground_truth) - { - int ir = tripletListB.size(); - int ic = (index_pose + sums[i]) * 6 + 2; - tripletListA.emplace_back(ir + 0, ic, 1000000000000); - tripletListP.emplace_back(ir, ir, 1); - tripletListB.emplace_back(ir, 0, 0); - } - - if (sessions[i].point_clouds_container.point_clouds[index_pose].fixed_om || sessions[i].is_ground_truth) - { - int ir = tripletListB.size(); - int ic = (index_pose + sums[i]) * 6 + 3; - tripletListA.emplace_back(ir + 0, ic, 1000000000000); - tripletListP.emplace_back(ir, ir, 1); - tripletListB.emplace_back(ir, 0, 0); - } - - if (sessions[i].point_clouds_container.point_clouds[index_pose].fixed_fi || sessions[i].is_ground_truth) - { - int ir = tripletListB.size(); - int ic = (index_pose + sums[i]) * 6 + 4; - tripletListA.emplace_back(ir + 0, ic, 1000000000000); - tripletListP.emplace_back(ir, ir, 1); - tripletListB.emplace_back(ir, 0, 0); - } - - if (sessions[i].point_clouds_container.point_clouds[index_pose].fixed_ka || sessions[i].is_ground_truth) - { - int ir = tripletListB.size(); - int ic = (index_pose + sums[i]) * 6 + 5; - tripletListA.emplace_back(ir + 0, ic, 1000000000000); - tripletListP.emplace_back(ir, ir, 1); - tripletListB.emplace_back(ir, 0, 0); - } - } - } - - double error_imu = 0; - double error_imu_sum = 0; - - for (size_t j = 0; j < sessions.size(); j++) - { - for (size_t index_pose = 0; index_pose < sessions[j].point_clouds_container.point_clouds.size(); index_pose++) - { - const auto& pc = sessions[j].point_clouds_container.point_clouds[index_pose]; - if (!pc.fuse_inclination_from_IMU) - { - continue; - } - if (pc.local_trajectory.size() == 0) - { - continue; - } - - TaitBryanPose target_pose; - target_pose.om = pc.local_trajectory[0].imu_om_fi_ka.x(); - target_pose.fi = pc.local_trajectory[0].imu_om_fi_ka.y(); - target_pose.ka = pc.local_trajectory[0].imu_om_fi_ka.z(); - target_pose.px = pc.m_pose(0, 3); - target_pose.py = pc.m_pose(1, 3); - target_pose.pz = pc.m_pose(2, 3); - - Eigen::Affine3d target_mpose = affine_matrix_from_pose_tait_bryan(target_pose); - - double xtg = target_mpose(0, 3); - double ytg = target_mpose(1, 3); - double ztg = target_mpose(2, 3); - double vzx = target_mpose(0, 2); - double vzy = target_mpose(1, 2); - double vzz = target_mpose(2, 2); - - TaitBryanPose current_pose = pose_tait_bryan_from_affine_matrix(pc.m_pose); - - Eigen::Matrix delta; - point_to_plane_tait_bryan_wc( - delta, - current_pose.px, - current_pose.py, - current_pose.pz, - current_pose.om, - current_pose.fi, - current_pose.ka, - 1, - 0, - 0, // add 0,1,0 - xtg, - ytg, - ztg, - vzx, - vzy, - vzz); - - Eigen::Matrix delta_jacobian; - point_to_plane_tait_bryan_wc_jacobian( - delta_jacobian, - current_pose.px, - current_pose.py, - current_pose.pz, - current_pose.om, - current_pose.fi, - current_pose.ka, - 1, - 0, - 0, - xtg, - ytg, - ztg, - vzx, - vzy, - vzz); - - int ir = tripletListB.size(); - int ic = (index_pose + sums[j]) * 6; - tripletListA.emplace_back(ir + 0, ic + 3, -delta_jacobian(0, 3)); - tripletListA.emplace_back(ir + 0, ic + 4, -delta_jacobian(0, 4)); - - tripletListP.emplace_back(ir, ir, /*get_cauchy_w(delta(0, 0), 1) * 10000*/ 1); - - tripletListB.emplace_back(ir, 0, delta(0, 0)); - - /////////////////////////////// - point_to_plane_tait_bryan_wc( - delta, - current_pose.px, - current_pose.py, - current_pose.pz, - current_pose.om, - current_pose.fi, - current_pose.ka, - 0, - 1, - 0, - xtg, - ytg, - ztg, - vzx, - vzy, - vzz); - - point_to_plane_tait_bryan_wc_jacobian( - delta_jacobian, - current_pose.px, - current_pose.py, - current_pose.pz, - current_pose.om, - current_pose.fi, - current_pose.ka, - 0, - 1, - 0, - xtg, - ytg, - ztg, - vzx, - vzy, - vzz); - - ir = tripletListB.size(); - // ic = index_pose * 6; - ic = (index_pose + sums[j]) * 6; - - tripletListA.emplace_back(ir + 0, ic + 3, -delta_jacobian(0, 3)); - tripletListA.emplace_back(ir + 0, ic + 4, -delta_jacobian(0, 4)); - - tripletListP.emplace_back(ir, ir, /*get_cauchy_w(delta(0, 0), 1) * 10000*/ 1); - - tripletListB.emplace_back(ir, 0, delta(0, 0)); - } - } - - // fuse control points - for (size_t j = 0; j < sessions.size(); j++) - { - // CPs - auto& cps = sessions[j].control_points; - auto& point_clouds_container = sessions[j].point_clouds_container; - - for (int i = 0; i < cps.cps.size(); i++) - { - if (!cps.cps[i].is_z_0) - { - Eigen::Vector3d p_s(cps.cps[i].x_source_local, cps.cps[i].y_source_local, cps.cps[i].z_source_local); - - Eigen::Matrix jacobian; - TaitBryanPose pose_s; - pose_s = pose_tait_bryan_from_affine_matrix(point_clouds_container.point_clouds[cps.cps[i].index_to_pose].m_pose); - - point_to_point_source_to_target_tait_bryan_wc_jacobian( - jacobian, pose_s.px, pose_s.py, pose_s.pz, pose_s.om, pose_s.fi, pose_s.ka, p_s.x(), p_s.y(), p_s.z()); - - double delta_x; - double delta_y; - double delta_z; - Eigen::Vector3d p_t(cps.cps[i].x_target_global, cps.cps[i].y_target_global, cps.cps[i].z_target_global); - point_to_point_source_to_target_tait_bryan_wc( - delta_x, - delta_y, - delta_z, - pose_s.px, - pose_s.py, - pose_s.pz, - pose_s.om, - pose_s.fi, - pose_s.ka, - p_s.x(), - p_s.y(), - p_s.z(), - p_t.x(), - p_t.y(), - p_t.z()); - - int ir = tripletListB.size(); - - //(index_pose + sums[j]) * 6; - int ic = (cps.cps[i].index_to_pose + sums[j]) * 6; - - for (int row = 0; row < 3; row++) - { - for (int col = 0; col < 6; col++) - { - if (jacobian(row, col) != 0.0) - { - tripletListA.emplace_back(ir + row, ic + col, -jacobian(row, col)); - } - } - } - tripletListP.emplace_back(ir + 0, ir + 0, (1.0 / (cps.cps[i].sigma_x * cps.cps[i].sigma_x)) * get_cauchy_w(delta_x, 1)); - tripletListP.emplace_back(ir + 1, ir + 1, (1.0 / (cps.cps[i].sigma_y * cps.cps[i].sigma_y)) * get_cauchy_w(delta_y, 1)); - tripletListP.emplace_back(ir + 2, ir + 2, (1.0 / (cps.cps[i].sigma_z * cps.cps[i].sigma_z)) * get_cauchy_w(delta_z, 1)); - - tripletListB.emplace_back(ir, 0, delta_x); - tripletListB.emplace_back(ir + 1, 0, delta_y); - tripletListB.emplace_back(ir + 2, 0, delta_z); - - std::cout << "cp [not z == 0]: delta_x " << delta_x << " delta_y " << delta_y << " delta_z " << delta_z << std::endl; - } - else - { - Eigen::Vector3d p_s(cps.cps[i].x_source_local, cps.cps[i].y_source_local, cps.cps[i].z_source_local); - - Eigen::Matrix jacobian; - TaitBryanPose pose_s; - pose_s = pose_tait_bryan_from_affine_matrix(point_clouds_container.point_clouds[cps.cps[i].index_to_pose].m_pose); - - point_to_point_source_to_target_tait_bryan_wc_jacobian( - jacobian, pose_s.px, pose_s.py, pose_s.pz, pose_s.om, pose_s.fi, pose_s.ka, p_s.x(), p_s.y(), p_s.z()); - - double delta_x; - double delta_y; - double delta_z; - Eigen::Vector3d p_t(cps.cps[i].x_target_global, cps.cps[i].y_target_global, 0.0 /*cps.cps[i].z_target_global*/); - point_to_point_source_to_target_tait_bryan_wc( - delta_x, - delta_y, - delta_z, - pose_s.px, - pose_s.py, - pose_s.pz, - pose_s.om, - pose_s.fi, - pose_s.ka, - p_s.x(), - p_s.y(), - p_s.z(), - p_t.x(), - p_t.y(), - p_t.z()); - - int ir = tripletListB.size(); - // int ic = cps.cps[i].index_to_pose * 6; - int ic = (cps.cps[i].index_to_pose + sums[j]) * 6; - - for (int row = 2; row < 3; row++) - { - for (int col = 0; col < 6; col++) - { - if (jacobian(row, col) != 0.0) - { - tripletListA.emplace_back(ir, ic + col, -jacobian(row, col)); - } - } - } - // tripletListP.emplace_back(ir + 0, ir + 0, (1.0 / (cps.cps[i].sigma_x * cps.cps[i].sigma_x)) * get_cauchy_w(delta_x, - // 1)); tripletListP.emplace_back(ir + 1, ir + 1, (1.0 / (cps.cps[i].sigma_y * cps.cps[i].sigma_y)) * - // get_cauchy_w(delta_y, 1)); - tripletListP.emplace_back(ir, ir, (1.0 / (cps.cps[i].sigma_z * cps.cps[i].sigma_z))); - - // tripletListB.emplace_back(ir, 0, delta_x); - // tripletListB.emplace_back(ir + 1, 0, delta_y); - tripletListB.emplace_back(ir, 0, delta_z); - - std::cout << "cp [not z == 0]: delta_z " << delta_z << std::endl; - } - } - } - - ////////////////////////////////////////////////////// - // for (size_t i = 0; i < gcps.gpcs.size(); i++) - //{ - - Eigen::SparseMatrix matA(tripletListB.size(), poses.size() * 6); - Eigen::SparseMatrix matP(tripletListB.size(), tripletListB.size()); - Eigen::SparseMatrix matB(tripletListB.size(), 1); - - matA.setFromTriplets(tripletListA.begin(), tripletListA.end()); - matP.setFromTriplets(tripletListP.begin(), tripletListP.end()); - matB.setFromTriplets(tripletListB.begin(), tripletListB.end()); - - Eigen::SparseMatrix AtPA(poses.size() * 6, poses.size() * 6); - Eigen::SparseMatrix AtPB(poses.size() * 6, 1); - - { - Eigen::SparseMatrix AtP = matA.transpose() * matP; - AtPA = (AtP)*matA; - AtPB = (AtP)*matB; - } - - tripletListA.clear(); - tripletListP.clear(); - tripletListB.clear(); - - Eigen::SimplicialCholesky> solver(AtPA); - - Eigen::SparseMatrix x = solver.solve(AtPB); - - std::vector h_x; - - for (int k = 0; k < x.outerSize(); ++k) - { - for (Eigen::SparseMatrix::InnerIterator it(x, k); it; ++it) - { - h_x.push_back(it.value()); - } - } - - if (h_x.size() == 6 * poses.size()) - { - int counter = 0; - - for (size_t i = 0; i < poses.size(); i++) - { - TaitBryanPose pose = poses[i]; - pose.px += h_x[counter++] * 0.1; - pose.py += h_x[counter++] * 0.1; - pose.pz += h_x[counter++] * 0.1; - pose.om += h_x[counter++] * 0.1; - pose.fi += h_x[counter++] * 0.1; - pose.ka += h_x[counter++] * 0.1; - - poses[i].px = pose.px; - poses[i].py = pose.py; - poses[i].pz = pose.pz; - poses[i].om = pose.om; - poses[i].fi = pose.fi; - poses[i].ka = pose.ka; - } - } - else - { - std::cout << "optimizing with tait bryan FAILED" << std::endl; - std::cout << "h_x.size(): " << h_x.size() << " should be: " << 6 * poses.size() << std::endl; - is_ok = false; - break; - } - - if (is_ok) - { - for (size_t i = 0; i < m_poses.size(); i++) - { - if (is_wc) - m_poses[i] = affine_matrix_from_pose_tait_bryan(poses[i]); - else if (is_cw) - m_poses[i] = affine_matrix_from_pose_tait_bryan(poses[i]).inverse(); - } - } - - if (is_ok) - { - int index = 0; - for (size_t i = 0; i < m_poses.size(); i++) - { - if (i > 0) - { - if (index_trajectory[i - 1] != index_trajectory[i]) - index = 0; - } - // if (!sessions[index_trajectory[i]].is_ground_truth) - //{ - sessions[index_trajectory[i]].point_clouds_container.point_clouds[index].m_pose = m_poses[i]; - sessions[index_trajectory[i]].point_clouds_container.point_clouds[index].pose = - pose_tait_bryan_from_affine_matrix(sessions[index_trajectory[i]].point_clouds_container.point_clouds[index].m_pose); - sessions[index_trajectory[i]].point_clouds_container.point_clouds[index].gui_translation[0] = - sessions[index_trajectory[i]].point_clouds_container.point_clouds[index].pose.px; - sessions[index_trajectory[i]].point_clouds_container.point_clouds[index].gui_translation[1] = - sessions[index_trajectory[i]].point_clouds_container.point_clouds[index].pose.py; - sessions[index_trajectory[i]].point_clouds_container.point_clouds[index].gui_translation[2] = - sessions[index_trajectory[i]].point_clouds_container.point_clouds[index].pose.pz; - sessions[index_trajectory[i]].point_clouds_container.point_clouds[index].gui_rotation[0] = - rad2deg(sessions[index_trajectory[i]].point_clouds_container.point_clouds[index].pose.om); - sessions[index_trajectory[i]].point_clouds_container.point_clouds[index].gui_rotation[1] = - rad2deg(sessions[index_trajectory[i]].point_clouds_container.point_clouds[index].pose.fi); - sessions[index_trajectory[i]].point_clouds_container.point_clouds[index].gui_rotation[2] = - rad2deg(sessions[index_trajectory[i]].point_clouds_container.point_clouds[index].pose.ka); - //} - index++; - } - } - } - return true; -} \ No newline at end of file diff --git a/apps/multi_session_registration_legacy/multi_session_factor_graph.h b/apps/multi_session_registration_legacy/multi_session_factor_graph.h deleted file mode 100644 index b173f04e..00000000 --- a/apps/multi_session_registration_legacy/multi_session_factor_graph.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include - -struct Edge -{ - TaitBryanPose relative_pose_tb; - TaitBryanPose relative_pose_tb_weights; - int index_session_from; - int index_session_to; - int index_from; - int index_to; - bool is_fixed_px = false; - bool is_fixed_py = false; - bool is_fixed_pz = false; - bool is_fixed_om = false; - bool is_fixed_fi = false; - bool is_fixed_ka = false; -}; - -bool optimize(std::vector& sessions, const std::vector& edges, TaitBryanPose motion_model_weights); diff --git a/apps/multi_session_registration_legacy/multi_session_registration.cpp b/apps/multi_session_registration_legacy/multi_session_registration.cpp deleted file mode 100644 index eae68a79..00000000 --- a/apps/multi_session_registration_legacy/multi_session_registration.cpp +++ /dev/null @@ -1,4392 +0,0 @@ -#include -#include - -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -#ifdef _WIN32 -#include "resource.h" -#include - -#endif - -#include "multi_session_factor_graph.h" - -std::string winTitle = std::string("Step 3 (Multi session registration) ") + HDMAPPING_CONFIGURE_PROJECT_VERSION; - -std::vector infoLines = { - "This program is third/final step in MANDEYE process", - "", - "First step: create project by adding sessions (result of 'multi_view_tls_registration_step_2' program)", - "Last step: save project", - "To produce map use 'multi_view_tls_registration_step_2' export functionality" -}; - -// App specific shortcuts (Type and Shortcut are just for easy reference) -static const std::vector appShortcuts = { { "Normal keys", "A", "" }, - { "", "Ctrl+A", "Add session(s)" }, - { "", "B", "" }, - { "", "Ctrl+B", "" }, - { "", "C", "" }, - { "", "Ctrl+C", "" }, - { "", "D", "" }, - { "", "Ctrl+D", "" }, - { "", "E", "" }, - { "", "Ctrl+E", "" }, - { "", "F", "" }, - { "", "Ctrl+F", "" }, - { "", "G", "" }, - { "", "Ctrl+G", "" }, - { "", "H", "" }, - { "", "Ctrl+H", "" }, - { "", "I", "" }, - { "", "Ctrl+I", "" }, - { "", "J", "" }, - { "", "Ctrl+K", "" }, - { "", "K", "" }, - { "", "Ctrl+K", "" }, - { "", "L", "" }, - { "", "Ctrl+L", "Load sessions" }, - { "", "M", "" }, - { "", "Ctrl+M", "" }, - { "", "N", "" }, - { "", "Ctrl+N", "" }, - { "", "O", "" }, - { "", "Ctrl+O", "Open project" }, - { "", "P", "" }, - { "", "Ctrl+P", "" }, - { "", "Q", "" }, - { "", "Ctrl+Q", "" }, - { "", "R", "" }, - { "", "Ctrl+R", "Remove session(s)" }, - { "", "Shift+R", "" }, - { "", "S", "" }, - { "", "Ctrl+S", "Save project" }, - { "", "Ctrl+Shift+S", "" }, - { "", "T", "" }, - { "", "Ctrl+T", "" }, - { "", "U", "" }, - { "", "Ctrl+U", "" }, - { "", "V", "" }, - { "", "Ctrl+V", "" }, - { "", "W", "" }, - { "", "Ctrl+W", "" }, - { "", "X", "" }, - { "", "Ctrl+X", "" }, - { "", "Y", "" }, - { "", "Ctrl+Y", "" }, - { "", "Z", "" }, - { "", "Ctrl+Z", "" }, - { "", "Shift+Z", "" }, - { "", "1-9", "" }, - { "Special keys", "Up arrow", "" }, - { "", "Shift + up arrow", "" }, - { "", "Ctrl + up arrow", "" }, - { "", "Down arrow", "" }, - { "", "Shift + down arrow", "" }, - { "", "Ctrl + down arrow", "" }, - { "", "Left arrow", "" }, - { "", "Shift + left arrow", "" }, - { "", "Ctrl + left arrow", "" }, - { "", "Right arrow", "" }, - { "", "Shift + right arrow", "" }, - { "", "Ctrl + right arrow", "" }, - { "", "Pg down", "" }, - { "", "Pg up", "" }, - { "", "- key", "" }, - { "", "+ key", "" }, - { "Mouse related", "Left click + drag", "" }, - { "", "Right click + drag", "n" }, - { "", "Scroll", "" }, - { "", "Shift + scroll", "" }, - { "", "Shift + drag", "" }, - { "", "Ctrl + left click", "" }, - { "", "Ctrl + right click", "" }, - { "", "Ctrl + middle click", "" } }; - -float m_gizmo[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; - -bool is_decimate = true; -double bucket_x = 0.1; -double bucket_y = 0.1; -double bucket_z = 0.1; -bool calculate_offset = false; -ObservationPicking observation_picking; -int index_loop_closure_source = -1; -int index_loop_closure_target = -1; -int first_session_index = -1; -int second_session_index = -1; -double search_radius = 0.3; -bool loaded_sessions = false; -bool optimized = false; -bool gizmo_all_sessions = false; -bool is_ndt_gui = false; -bool is_loop_closure_gui = false; -bool remove_gui = false; -NDT ndt; - -bool update_rotation_center = false; - -bool is_settings_gui = true; - -int number_visible_sessions = 0; -int index_gt = -1; -int old_index_gt = -1; -int index_gizmo = -1; -int old_index_gizmo = -1; - -double time_stamp_offset = 0.0; - -struct ProjectSettings -{ - std::vector session_file_names; -}; - -std::vector edges; -int index_active_edge = -1; -bool manipulate_active_edge = false; -bool edge_gizmo = false; - -ProjectSettings project_settings; -std::vector sessions; - -int viewer_reduce_rendered_trajectory = 1; -namespace fs = std::filesystem; - -int num_edge_extended_before = 0; -int num_edge_extended_after = 0; - -int gui_point_size = 2; - -TaitBryanPose motion_model_weights = { 0.01, 0.01, 0.01, 0.1, 0.1, 0.1 }; -/////////////////////////////////////////////////////////////////////////////////// - -void ndt_gui() -{ - static bool compute_mean_and_cov_for_bucket = false; - if (ImGui::Begin("Normal Distributions Transform", &is_ndt_gui, ImGuiWindowFlags_AlwaysAutoResize)) - { - ImGui::InputFloat3("Bucket size [m] (x, y,z)", ndt.bucket_size); - if (ndt.bucket_size[0] < 0.01) - ndt.bucket_size[0] = 0.01f; - if (ndt.bucket_size[1] < 0.01) - ndt.bucket_size[1] = 0.01f; - if (ndt.bucket_size[2] < 0.01) - ndt.bucket_size[2] = 0.01f; - - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::InputInt("Number of threads", &ndt.number_of_threads); - if (ndt.number_of_threads < 1) - ndt.number_of_threads = 1; - ImGui::SameLine(); - ImGui::InputInt("Number of iterations", &ndt.number_of_iterations); - if (ndt.number_of_iterations < 1) - ndt.number_of_iterations = 1; - ImGui::PopItemWidth(); - - if (ImGui::Button("NDT optimization")) - { - for (auto& s : sessions) - { - s.is_gizmo = false; - } - - double rms_initial = 0.0; - double rms_final = 0.0; - double mui = 0.0; - - ndt.optimize(sessions, false, compute_mean_and_cov_for_bucket); - } - ImGui::End(); - } - -#if 0 - ImGui::Checkbox("ndt fix_first_node (add I to first pose in Hessian)", &ndt.is_fix_first_node); - - ImGui::Checkbox("ndt Gauss-Newton", &ndt.is_gauss_newton); - if (ndt.is_gauss_newton) - { - ndt.is_levenberg_marguardt = false; - } - - ImGui::SameLine(); - ImGui::Checkbox("ndt Levenberg-Marguardt", &ndt.is_levenberg_marguardt); - if (ndt.is_levenberg_marguardt) - { - ndt.is_gauss_newton = false; - } - - ImGui::Checkbox("ndt poses expressed as camera<-world (cw)", &ndt.is_cw); - if (ndt.is_cw) - { - ndt.is_wc = false; - } - ImGui::SameLine(); - ImGui::Checkbox("ndt poses expressed as camera->world (wc)", &ndt.is_wc); - if (ndt.is_wc) - { - ndt.is_cw = false; - } - - ImGui::Checkbox("ndt Tait-Bryan angles (om fi ka: RxRyRz)", &ndt.is_tait_bryan_angles); - if (ndt.is_tait_bryan_angles) - { - ndt.is_quaternion = false; - ndt.is_rodrigues = false; - } - - ImGui::SameLine(); - ImGui::Checkbox("ndt Quaternion (q0 q1 q2 q3)", &ndt.is_quaternion); - if (ndt.is_quaternion) - { - ndt.is_tait_bryan_angles = false; - ndt.is_rodrigues = false; - } - - ImGui::SameLine(); - ImGui::Checkbox("ndt Rodrigues (sx sy sz)", &ndt.is_rodrigues); - if (ndt.is_rodrigues) - { - ndt.is_tait_bryan_angles = false; - ndt.is_quaternion = false; - } - - if (ImGui::Button("compute mean mahalanobis distance")) - { - double rms_initial = 0.0; - double rms_final = 0.0; - double mui = 0.0; - ndt.optimize(session.point_clouds_container.point_clouds, true, compute_mean_and_cov_for_bucket); - } - - ImGui::Text("--------------------------------------------------------------------------------------------------------"); - - if (ImGui::Button("ndt_optimization(Lie-algebra left Jacobian)")) - { - // icp.optimize_source_to_target_lie_algebra_left_jacobian(point_clouds_container); - ndt.optimize_lie_algebra_left_jacobian(session.point_clouds_container.point_clouds, compute_mean_and_cov_for_bucket); - } - if (ImGui::Button("ndt_optimization(Lie-algebra right Jacobian)")) - { - // icp.optimize_source_to_target_lie_algebra_right_jacobian(point_clouds_container); - ndt.optimize_lie_algebra_right_jacobian(session.point_clouds_container.point_clouds, compute_mean_and_cov_for_bucket); - } - - ImGui::Text("--------------------------------------------------------------------------------------------------------"); - - ImGui::Checkbox("generalized", &ndt.is_generalized); - - if (ndt.is_generalized) - { - ImGui::InputDouble("sigma_r", &ndt.sigma_r, 0.01, 0.01); - ImGui::InputDouble("sigma_polar_angle_rad", &ndt.sigma_polar_angle, 0.0001, 0.0001); - ImGui::InputDouble("sigma_azimuthal_angle_rad", &ndt.sigma_azimuthal_angle, 0.0001, 0.0001); - ImGui::InputInt("num_extended_points", &ndt.num_extended_points, 1, 1); - - ImGui::Checkbox("compute_mean_and_cov_for_bucket", &compute_mean_and_cov_for_bucket); - } - - if (ImGui::Button("Set Zoller+Fröhlich TLS Imager 5006i errors")) - { - ndt.sigma_r = 0.0068; - ndt.sigma_polar_angle = 0.007 * DEG_TO_RAD; - ndt.sigma_azimuthal_angle = 0.007 * DEG_TO_RAD; - } - - if (ImGui::Button("Set Zoller+Fröhlich TLS Imager 5010C errors")) - { - ndt.sigma_r = 0.01; - ndt.sigma_polar_angle = 0.007 * DEG_TO_RAD; - ndt.sigma_azimuthal_angle = 0.007 * DEG_TO_RAD; - } - - if (ImGui::Button("Set Zoller+Fröhlich TLS Imager 5016 errors")) - { - ndt.sigma_r = 0.00025; - ndt.sigma_polar_angle = 0.004 * DEG_TO_RAD; - ndt.sigma_azimuthal_angle = 0.004 * DEG_TO_RAD; - } - if (ImGui::Button("Set Faro Focus3D errors")) - { - ndt.sigma_r = 0.001; - ndt.sigma_polar_angle = 19.0 * (1.0 / 3600.0) * DEG_TO_RAD; - ndt.sigma_azimuthal_angle = 19.0 * (1.0 / 3600.0) * DEG_TO_RAD; - } - if (ImGui::Button("Set Leica ScanStation C5 C10 errors")) - { - ndt.sigma_r = 0.006; - ndt.sigma_polar_angle = 0.00006; - ndt.sigma_azimuthal_angle = 0.00006; - } - if (ImGui::Button("Set Riegl VZ400 errors")) - { - ndt.sigma_r = 0.005; - ndt.sigma_polar_angle = 0.0005 * DEG_TO_RAD + 0.0003; // Laser Beam Dicvergence - ndt.sigma_azimuthal_angle = 0.0005 * DEG_TO_RAD + 0.0003; // Laser Beam Dicvergence - } - if (ImGui::Button("Set Leica HDS6100 errors")) - { - ndt.sigma_r = 0.009; - ndt.sigma_polar_angle = 0.000125; - ndt.sigma_azimuthal_angle = 0.000125; - } - if (ImGui::Button("Set Leica P40 errors")) - { - ndt.sigma_r = 0.0012; - ndt.sigma_polar_angle = 8.0 / 3600; - ndt.sigma_azimuthal_angle = 8.0 / 3600; - } -#endif -} - -void loop_closure_gui() -{ - if (ImGui::Begin("Manual Pose Graph Loop Closure Mode", &is_loop_closure_gui, ImGuiWindowFlags_AlwaysAutoResize)) - { - if (ImGui::Button("Optimize GRAPH")) - { - for (int i = 0; i < 100; i++) - { - std::cout << "Iteration [" << i + 1 << "] of: " << 100 << std::endl; - optimize(sessions, edges, motion_model_weights); - } - optimized = true; - } - - ImGui::Checkbox("update_rotation_center", &update_rotation_center); - - // - auto point_cloud_upper = sessions[first_session_index].point_clouds_container.point_clouds.size() - 1; - - ImGui::InputInt("gui_point_size", &gui_point_size); - if (gui_point_size < 1) - gui_point_size = 1; - - ImGui::Text("Num edge extended:"); - - ImGui::Text("before: "); - ImGui::SameLine(); - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::SliderInt("##fs", &num_edge_extended_before, 0, point_cloud_upper); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("min 0; max %zu", point_cloud_upper); - ImGui::SameLine(); - ImGui::InputInt("##fi", &num_edge_extended_before, 1, 5); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("min 0; max %zu", point_cloud_upper); - if (num_edge_extended_before < 0) - num_edge_extended_before = 0; - if (num_edge_extended_before >= point_cloud_upper) - num_edge_extended_before = point_cloud_upper; - - point_cloud_upper = sessions[second_session_index].point_clouds_container.point_clouds.size() - 1; - - ImGui::Text(" after: "); - ImGui::SameLine(); - - ImGui::SliderInt("##ts", &num_edge_extended_after, index_loop_closure_target, static_cast(point_cloud_upper)); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("min 0; max %zu", point_cloud_upper); - ImGui::SameLine(); - ImGui::InputInt("##ti", &num_edge_extended_after, 1, 5); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("min 0; max %zu", point_cloud_upper); - if (num_edge_extended_after < 0) - num_edge_extended_after = 0; - if (num_edge_extended_after >= point_cloud_upper) - num_edge_extended_after = point_cloud_upper; - ImGui::PopItemWidth(); - // - - if (!manipulate_active_edge) - { - ImGui::InputInt("index_loop_closure_source", &index_loop_closure_source); - if (index_loop_closure_source < 0) - index_loop_closure_source = 0; - if (index_loop_closure_source >= sessions[first_session_index].point_clouds_container.point_clouds.size() - 1) - index_loop_closure_source = sessions[first_session_index].point_clouds_container.point_clouds.size() - 1; - ImGui::InputInt("index_loop_closure_target", &index_loop_closure_target); - if (index_loop_closure_target < 0) - index_loop_closure_target = 0; - if (index_loop_closure_target >= sessions[second_session_index].point_clouds_container.point_clouds.size() - 1) - index_loop_closure_target = sessions[second_session_index].point_clouds_container.point_clouds.size() - 1; - } - if (ImGui::Button("Add edge")) - { - Edge edge; - edge.index_from = index_loop_closure_source; - edge.index_to = index_loop_closure_target; - edge.index_session_from = first_session_index; - edge.index_session_to = second_session_index; - - edge.relative_pose_tb = pose_tait_bryan_from_affine_matrix( - sessions[first_session_index].point_clouds_container.point_clouds[index_loop_closure_source].m_pose.inverse() * - sessions[second_session_index].point_clouds_container.point_clouds[index_loop_closure_target].m_pose); - - edge.relative_pose_tb_weights.px = 1000000.0; - edge.relative_pose_tb_weights.py = 1000000.0; - edge.relative_pose_tb_weights.pz = 1000000.0; - edge.relative_pose_tb_weights.om = 1000000.0; - edge.relative_pose_tb_weights.fi = 1000000.0; - edge.relative_pose_tb_weights.ka = 1000000.0; - - edges.push_back(edge); - - index_active_edge = edges.size() - 1; - } - - std::string number_active_edges = "number_edges: " + std::to_string(edges.size()); - ImGui::Text(number_active_edges.c_str()); - if (edges.size() > 0) - { - ImGui::Checkbox("manipulate_active_edge", &manipulate_active_edge); - if (manipulate_active_edge) - { - int remove_edge_index = -1; - if (ImGui::Button("remove active edge")) - { - edge_gizmo = false; - remove_edge_index = index_active_edge; - } - - int prev_index_active_edge = index_active_edge; - - if (!edge_gizmo) - { - bool is_gizmo = false; - - for (const auto& s : sessions) - { - if (s.is_gizmo) - is_gizmo = true; - } - - if (!is_gizmo) - { - ImGui::InputInt("index_active_edge", &index_active_edge); - - if (index_active_edge < 0) - index_active_edge = 0; - if (index_active_edge >= (int)edges.size()) - index_active_edge = (int)edges.size() - 1; - } - } - - std::string txt = "index_session_from: " + std::to_string(edges[index_active_edge].index_session_from); - ImGui::Text(txt.c_str()); - txt = "index_session_to: " + std::to_string(edges[index_active_edge].index_session_to); - ImGui::Text(txt.c_str()); - txt = "index_from: " + std::to_string(edges[index_active_edge].index_from); - ImGui::Text(txt.c_str()); - txt = "index_to: " + std::to_string(edges[index_active_edge].index_to); - ImGui::Text(txt.c_str()); - - if (remove_edge_index != -1) - { - std::vector new_edges; - for (size_t i = 0; i < edges.size(); i++) - { - if (remove_edge_index != i) - new_edges.push_back(edges[i]); - } - edges = new_edges; - - index_active_edge = remove_edge_index - 1; - manipulate_active_edge = false; - } - - bool prev_gizmo = edge_gizmo; - ImGui::Checkbox("gizmo", &edge_gizmo); - - if (prev_gizmo != edge_gizmo) - { - auto m_to = sessions[edges[index_active_edge].index_session_from] - .point_clouds_container.point_clouds[edges[index_active_edge].index_from] - .m_pose * - affine_matrix_from_pose_tait_bryan(edges[index_active_edge].relative_pose_tb); - - m_gizmo[0] = (float)m_to(0, 0); - m_gizmo[1] = (float)m_to(1, 0); - m_gizmo[2] = (float)m_to(2, 0); - m_gizmo[3] = (float)m_to(3, 0); - m_gizmo[4] = (float)m_to(0, 1); - m_gizmo[5] = (float)m_to(1, 1); - m_gizmo[6] = (float)m_to(2, 1); - m_gizmo[7] = (float)m_to(3, 1); - m_gizmo[8] = (float)m_to(0, 2); - m_gizmo[9] = (float)m_to(1, 2); - m_gizmo[10] = (float)m_to(2, 2); - m_gizmo[11] = (float)m_to(3, 2); - m_gizmo[12] = (float)m_to(0, 3); - m_gizmo[13] = (float)m_to(1, 3); - m_gizmo[14] = (float)m_to(2, 3); - m_gizmo[15] = (float)m_to(3, 3); - } - if (!edge_gizmo) - { - if (ImGui::Button("ICP")) - { - std::cout << "Iterative Closest Point" << std::endl; - if (sessions[edges[index_active_edge].index_session_from].is_ground_truth && - sessions[edges[index_active_edge].index_session_to].is_ground_truth) - { - std::cout << "Two sessions are ground truth!!! ICP is disabled" << std::endl; - } - else - { - bool is_with_ground_truth = false; - if (sessions[edges[index_active_edge].index_session_from].is_ground_truth || - sessions[edges[index_active_edge].index_session_to].is_ground_truth) - { - is_with_ground_truth = true; - } - - if (is_with_ground_truth) - { - int index_session_from = -1; - int index_session_to = -1; - int index_from = -1; - int index_to = -1; - - if (sessions[edges[index_active_edge].index_session_from].is_ground_truth) - { - index_session_from = edges[index_active_edge].index_session_from; - index_session_to = edges[index_active_edge].index_session_to; - index_from = edges[index_active_edge].index_from; - index_to = edges[index_active_edge].index_to; - } - else - { - index_session_from = edges[index_active_edge].index_session_to; - index_session_to = edges[index_active_edge].index_session_from; - index_from = edges[index_active_edge].index_to; - index_to = edges[index_active_edge].index_from; - } - - double x_min = 1000000000000.0; - double y_min = 1000000000000.0; - double z_min = 1000000000000.0; - double x_max = -1000000000000.0; - double y_max = -1000000000000.0; - double z_max = -1000000000000.0; - - auto& points_to = sessions[index_session_to].point_clouds_container.point_clouds[index_to]; - - for (const auto& p : points_to.points_local) - { - auto pg = points_to.m_pose * p; - if (pg.x() < x_min) - x_min = pg.x(); - if (pg.y() < y_min) - y_min = pg.y(); - if (pg.z() < z_min) - z_min = pg.z(); - - if (pg.x() > x_max) - x_max = pg.x(); - if (pg.y() > y_max) - y_max = pg.y(); - if (pg.z() > z_max) - z_max = pg.z(); - } - auto& points_from = sessions[index_session_from].point_clouds_container.point_clouds[index_from]; - std::vector ground_truth; - for (const auto& p : points_from.points_local) - { - auto pg = points_from.m_pose * p; - if (pg.x() > x_min && pg.x() < x_max) - { - if (pg.y() > y_min && pg.y() < y_max) - { - if (pg.z() > z_min && pg.z() < z_max) - ground_truth.push_back(p); - } - } - } - - int number_of_iterations = 10; - PairWiseICP icp; - auto m_pose = affine_matrix_from_pose_tait_bryan(edges[index_active_edge].relative_pose_tb); - - std::vector source = - sessions[edges[index_active_edge].index_session_to] - .point_clouds_container.point_clouds[edges[index_active_edge].index_to] - .points_local; - std::vector target = - ground_truth; // sessions[edges[index_active_edge].index_session_from].point_clouds_container.point_clouds[edges[index_active_edge].index_from].points_local; - - if (icp.compute(source, target, search_radius, number_of_iterations, m_pose)) - edges[index_active_edge].relative_pose_tb = pose_tait_bryan_from_affine_matrix(m_pose); - } - else - { - int number_of_iterations = 10; - PairWiseICP icp; - auto m_pose = affine_matrix_from_pose_tait_bryan(edges[index_active_edge].relative_pose_tb); - - std::vector source; - auto& e = edges[index_active_edge]; - for (int i = -num_edge_extended_before; i <= num_edge_extended_after; i++) - { - int index_src = e.index_to + i; - if (index_src >= 0 && - index_src < - sessions[edges[index_active_edge].index_session_to].point_clouds_container.point_clouds.size()) - { - Eigen::Affine3d m_src = sessions[edges[index_active_edge].index_session_to] - .point_clouds_container.point_clouds.at(index_src) - .m_pose; - for (int k = 0; k < sessions[edges[index_active_edge].index_session_to] - .point_clouds_container.point_clouds[index_src] - .points_local.size(); - k++) - { - Eigen::Vector3d p_g = m_src * - sessions[edges[index_active_edge].index_session_to] - .point_clouds_container.point_clouds[index_src] - .points_local[k]; - source.push_back(p_g); - } - // point_clouds_container.point_clouds.at(index_src).render(m_src, 1); - } - } - std::vector target; - - for (int i = -num_edge_extended_before; i <= num_edge_extended_after; i++) - { - int index_trg = e.index_from + i; - if (index_trg >= 0 && - index_trg < sessions[edges[index_active_edge].index_session_from] - .point_clouds_container.point_clouds.size()) - { - Eigen::Affine3d m_trg = sessions[edges[index_active_edge].index_session_from] - .point_clouds_container.point_clouds.at(index_trg) - .m_pose; - for (int k = 0; k < sessions[edges[index_active_edge].index_session_from] - .point_clouds_container.point_clouds[index_trg] - .points_local.size(); - k++) - { - Eigen::Vector3d p_g = m_trg * - sessions[edges[index_active_edge].index_session_from] - .point_clouds_container.point_clouds[index_trg] - .points_local[k]; - target.push_back(p_g); - } - // point_clouds_container.point_clouds.at(index_src).render(m_src, 1); - } - } - - Eigen::Affine3d m_src_inv = sessions[edges[index_active_edge].index_session_to] - .point_clouds_container.point_clouds[e.index_to] - .m_pose.inverse(); - - for (auto& p : source) - { - p = m_src_inv * p; - } - - Eigen::Affine3d m_trg_inv = sessions[edges[index_active_edge].index_session_from] - .point_clouds_container.point_clouds[e.index_from] - .m_pose.inverse(); - - for (auto& p : target) - { - p = m_trg_inv * p; - } - - if (icp.compute(source, target, search_radius, number_of_iterations, m_pose)) - edges[index_active_edge].relative_pose_tb = pose_tait_bryan_from_affine_matrix(m_pose); - } - } - } - ImGui::SameLine(); - ImGui::InputDouble("search_radius", &search_radius); - if (search_radius < 0.01) - search_radius = 0.01; - - ///////////////////////////////// - if (ImGui::Button("ICP [search radius 2m]")) - { - float sr = 2.0; - std::cout << "Iterative Closest Point" << std::endl; - if (sessions[edges[index_active_edge].index_session_from].is_ground_truth && - sessions[edges[index_active_edge].index_session_to].is_ground_truth) - { - std::cout << "Two sessions are ground truth!!! ICP is disabled" << std::endl; - } - else - { - bool is_with_ground_truth = false; - if (sessions[edges[index_active_edge].index_session_from].is_ground_truth || - sessions[edges[index_active_edge].index_session_to].is_ground_truth) - { - is_with_ground_truth = true; - } - - if (is_with_ground_truth) - { - int index_session_from = -1; - int index_session_to = -1; - int index_from = -1; - int index_to = -1; - - if (sessions[edges[index_active_edge].index_session_from].is_ground_truth) - { - index_session_from = edges[index_active_edge].index_session_from; - index_session_to = edges[index_active_edge].index_session_to; - index_from = edges[index_active_edge].index_from; - index_to = edges[index_active_edge].index_to; - } - else - { - index_session_from = edges[index_active_edge].index_session_to; - index_session_to = edges[index_active_edge].index_session_from; - index_from = edges[index_active_edge].index_to; - index_to = edges[index_active_edge].index_from; - } - - double x_min = 1000000000000.0; - double y_min = 1000000000000.0; - double z_min = 1000000000000.0; - double x_max = -1000000000000.0; - double y_max = -1000000000000.0; - double z_max = -1000000000000.0; - - auto& points_to = sessions[index_session_to].point_clouds_container.point_clouds[index_to]; - - for (const auto& p : points_to.points_local) - { - auto pg = points_to.m_pose * p; - if (pg.x() < x_min) - x_min = pg.x(); - if (pg.y() < y_min) - y_min = pg.y(); - if (pg.z() < z_min) - z_min = pg.z(); - - if (pg.x() > x_max) - x_max = pg.x(); - if (pg.y() > y_max) - y_max = pg.y(); - if (pg.z() > z_max) - z_max = pg.z(); - } - auto& points_from = sessions[index_session_from].point_clouds_container.point_clouds[index_from]; - std::vector ground_truth; - for (const auto& p : points_from.points_local) - { - auto pg = points_from.m_pose * p; - if (pg.x() > x_min && pg.x() < x_max) - { - if (pg.y() > y_min && pg.y() < y_max) - { - if (pg.z() > z_min && pg.z() < z_max) - ground_truth.push_back(p); - } - } - } - - int number_of_iterations = 30; - PairWiseICP icp; - auto m_pose = affine_matrix_from_pose_tait_bryan(edges[index_active_edge].relative_pose_tb); - - const std::vector& source = - sessions[edges[index_active_edge].index_session_to] - .point_clouds_container.point_clouds[edges[index_active_edge].index_to] - .points_local; - const std::vector& target = - ground_truth; // sessions[edges[index_active_edge].index_session_from].point_clouds_container.point_clouds[edges[index_active_edge].index_from].points_local; - - if (icp.compute(source, target, sr, number_of_iterations, m_pose)) - edges[index_active_edge].relative_pose_tb = pose_tait_bryan_from_affine_matrix(m_pose); - } - else - { - int number_of_iterations = 30; - PairWiseICP icp; - auto m_pose = affine_matrix_from_pose_tait_bryan(edges[index_active_edge].relative_pose_tb); - - const std::vector& source = - sessions[edges[index_active_edge].index_session_to] - .point_clouds_container.point_clouds[edges[index_active_edge].index_to] - .points_local; - const std::vector& target = - sessions[edges[index_active_edge].index_session_from] - .point_clouds_container.point_clouds[edges[index_active_edge].index_from] - .points_local; - - if (icp.compute(source, target, sr, number_of_iterations, m_pose)) - edges[index_active_edge].relative_pose_tb = pose_tait_bryan_from_affine_matrix(m_pose); - } - } - } - - ImGui::SameLine(); - if (ImGui::Button("ICP [search radius 1m]")) - { - float sr = 1.0; - std::cout << "Iterative Closest Point" << std::endl; - if (sessions[edges[index_active_edge].index_session_from].is_ground_truth && - sessions[edges[index_active_edge].index_session_to].is_ground_truth) - { - std::cout << "Two sessions are ground truth!!! ICP is disabled" << std::endl; - } - else - { - bool is_with_ground_truth = false; - if (sessions[edges[index_active_edge].index_session_from].is_ground_truth || - sessions[edges[index_active_edge].index_session_to].is_ground_truth) - { - is_with_ground_truth = true; - } - - if (is_with_ground_truth) - { - int index_session_from = -1; - int index_session_to = -1; - int index_from = -1; - int index_to = -1; - - if (sessions[edges[index_active_edge].index_session_from].is_ground_truth) - { - index_session_from = edges[index_active_edge].index_session_from; - index_session_to = edges[index_active_edge].index_session_to; - index_from = edges[index_active_edge].index_from; - index_to = edges[index_active_edge].index_to; - } - else - { - index_session_from = edges[index_active_edge].index_session_to; - index_session_to = edges[index_active_edge].index_session_from; - index_from = edges[index_active_edge].index_to; - index_to = edges[index_active_edge].index_from; - } - - double x_min = 1000000000000.0; - double y_min = 1000000000000.0; - double z_min = 1000000000000.0; - double x_max = -1000000000000.0; - double y_max = -1000000000000.0; - double z_max = -1000000000000.0; - - auto& points_to = sessions[index_session_to].point_clouds_container.point_clouds[index_to]; - - for (const auto& p : points_to.points_local) - { - auto pg = points_to.m_pose * p; - if (pg.x() < x_min) - x_min = pg.x(); - if (pg.y() < y_min) - y_min = pg.y(); - if (pg.z() < z_min) - z_min = pg.z(); - - if (pg.x() > x_max) - x_max = pg.x(); - if (pg.y() > y_max) - y_max = pg.y(); - if (pg.z() > z_max) - z_max = pg.z(); - } - auto& points_from = sessions[index_session_from].point_clouds_container.point_clouds[index_from]; - std::vector ground_truth; - for (const auto& p : points_from.points_local) - { - auto pg = points_from.m_pose * p; - if (pg.x() > x_min && pg.x() < x_max) - { - if (pg.y() > y_min && pg.y() < y_max) - { - if (pg.z() > z_min && pg.z() < z_max) - ground_truth.push_back(p); - } - } - } - - int number_of_iterations = 30; - PairWiseICP icp; - auto m_pose = affine_matrix_from_pose_tait_bryan(edges[index_active_edge].relative_pose_tb); - - const std::vector& source = - sessions[edges[index_active_edge].index_session_to] - .point_clouds_container.point_clouds[edges[index_active_edge].index_to] - .points_local; - const std::vector& target = - ground_truth; // sessions[edges[index_active_edge].index_session_from].point_clouds_container.point_clouds[edges[index_active_edge].index_from].points_local; - - if (icp.compute(source, target, sr, number_of_iterations, m_pose)) - edges[index_active_edge].relative_pose_tb = pose_tait_bryan_from_affine_matrix(m_pose); - } - else - { - int number_of_iterations = 30; - PairWiseICP icp; - auto m_pose = affine_matrix_from_pose_tait_bryan(edges[index_active_edge].relative_pose_tb); - - const std::vector& source = - sessions[edges[index_active_edge].index_session_to] - .point_clouds_container.point_clouds[edges[index_active_edge].index_to] - .points_local; - const std::vector& target = - sessions[edges[index_active_edge].index_session_from] - .point_clouds_container.point_clouds[edges[index_active_edge].index_from] - .points_local; - - if (icp.compute(source, target, sr, number_of_iterations, m_pose)) - edges[index_active_edge].relative_pose_tb = pose_tait_bryan_from_affine_matrix(m_pose); - } - } - } - ImGui::SameLine(); - if (ImGui::Button("ICP [search radius 0.5m]")) - { - float sr = 0.5; - std::cout << "Iterative Closest Point" << std::endl; - if (sessions[edges[index_active_edge].index_session_from].is_ground_truth && - sessions[edges[index_active_edge].index_session_to].is_ground_truth) - { - std::cout << "Two sessions are ground truth!!! ICP is disabled" << std::endl; - } - else - { - bool is_with_ground_truth = false; - if (sessions[edges[index_active_edge].index_session_from].is_ground_truth || - sessions[edges[index_active_edge].index_session_to].is_ground_truth) - { - is_with_ground_truth = true; - } - - if (is_with_ground_truth) - { - int index_session_from = -1; - int index_session_to = -1; - int index_from = -1; - int index_to = -1; - - if (sessions[edges[index_active_edge].index_session_from].is_ground_truth) - { - index_session_from = edges[index_active_edge].index_session_from; - index_session_to = edges[index_active_edge].index_session_to; - index_from = edges[index_active_edge].index_from; - index_to = edges[index_active_edge].index_to; - } - else - { - index_session_from = edges[index_active_edge].index_session_to; - index_session_to = edges[index_active_edge].index_session_from; - index_from = edges[index_active_edge].index_to; - index_to = edges[index_active_edge].index_from; - } - - double x_min = 1000000000000.0; - double y_min = 1000000000000.0; - double z_min = 1000000000000.0; - double x_max = -1000000000000.0; - double y_max = -1000000000000.0; - double z_max = -1000000000000.0; - - auto& points_to = sessions[index_session_to].point_clouds_container.point_clouds[index_to]; - - for (const auto& p : points_to.points_local) - { - auto pg = points_to.m_pose * p; - if (pg.x() < x_min) - x_min = pg.x(); - if (pg.y() < y_min) - y_min = pg.y(); - if (pg.z() < z_min) - z_min = pg.z(); - - if (pg.x() > x_max) - x_max = pg.x(); - if (pg.y() > y_max) - y_max = pg.y(); - if (pg.z() > z_max) - z_max = pg.z(); - } - auto& points_from = sessions[index_session_from].point_clouds_container.point_clouds[index_from]; - std::vector ground_truth; - for (const auto& p : points_from.points_local) - { - auto pg = points_from.m_pose * p; - if (pg.x() > x_min && pg.x() < x_max) - { - if (pg.y() > y_min && pg.y() < y_max) - { - if (pg.z() > z_min && pg.z() < z_max) - ground_truth.push_back(p); - } - } - } - - int number_of_iterations = 30; - PairWiseICP icp; - auto m_pose = affine_matrix_from_pose_tait_bryan(edges[index_active_edge].relative_pose_tb); - - const std::vector& source = - sessions[edges[index_active_edge].index_session_to] - .point_clouds_container.point_clouds[edges[index_active_edge].index_to] - .points_local; - const std::vector& target = - ground_truth; // sessions[edges[index_active_edge].index_session_from].point_clouds_container.point_clouds[edges[index_active_edge].index_from].points_local; - - if (icp.compute(source, target, sr, number_of_iterations, m_pose)) - { - edges[index_active_edge].relative_pose_tb = pose_tait_bryan_from_affine_matrix(m_pose); - } - } - else - { - int number_of_iterations = 30; - PairWiseICP icp; - auto m_pose = affine_matrix_from_pose_tait_bryan(edges[index_active_edge].relative_pose_tb); - - const std::vector& source = - sessions[edges[index_active_edge].index_session_to] - .point_clouds_container.point_clouds[edges[index_active_edge].index_to] - .points_local; - const std::vector& target = - sessions[edges[index_active_edge].index_session_from] - .point_clouds_container.point_clouds[edges[index_active_edge].index_from] - .points_local; - - if (icp.compute(source, target, sr, number_of_iterations, m_pose)) - { - edges[index_active_edge].relative_pose_tb = pose_tait_bryan_from_affine_matrix(m_pose); - } - } - } - } - ImGui::SameLine(); - if (ImGui::Button("ICP [search radius 0.25m]")) - { - float sr = 0.25; - std::cout << "Iterative Closest Point" << std::endl; - if (sessions[edges[index_active_edge].index_session_from].is_ground_truth && - sessions[edges[index_active_edge].index_session_to].is_ground_truth) - { - std::cout << "Two sessions are ground truth!!! ICP is disabled" << std::endl; - } - else - { - bool is_with_ground_truth = false; - if (sessions[edges[index_active_edge].index_session_from].is_ground_truth || - sessions[edges[index_active_edge].index_session_to].is_ground_truth) - { - is_with_ground_truth = true; - } - - if (is_with_ground_truth) - { - int index_session_from = -1; - int index_session_to = -1; - int index_from = -1; - int index_to = -1; - - if (sessions[edges[index_active_edge].index_session_from].is_ground_truth) - { - index_session_from = edges[index_active_edge].index_session_from; - index_session_to = edges[index_active_edge].index_session_to; - index_from = edges[index_active_edge].index_from; - index_to = edges[index_active_edge].index_to; - } - else - { - index_session_from = edges[index_active_edge].index_session_to; - index_session_to = edges[index_active_edge].index_session_from; - index_from = edges[index_active_edge].index_to; - index_to = edges[index_active_edge].index_from; - } - - double x_min = 1000000000000.0; - double y_min = 1000000000000.0; - double z_min = 1000000000000.0; - double x_max = -1000000000000.0; - double y_max = -1000000000000.0; - double z_max = -1000000000000.0; - - auto& points_to = sessions[index_session_to].point_clouds_container.point_clouds[index_to]; - - for (const auto& p : points_to.points_local) - { - auto pg = points_to.m_pose * p; - if (pg.x() < x_min) - x_min = pg.x(); - if (pg.y() < y_min) - y_min = pg.y(); - if (pg.z() < z_min) - z_min = pg.z(); - - if (pg.x() > x_max) - x_max = pg.x(); - if (pg.y() > y_max) - y_max = pg.y(); - if (pg.z() > z_max) - z_max = pg.z(); - } - auto& points_from = sessions[index_session_from].point_clouds_container.point_clouds[index_from]; - std::vector ground_truth; - for (const auto& p : points_from.points_local) - { - auto pg = points_from.m_pose * p; - if (pg.x() > x_min && pg.x() < x_max) - { - if (pg.y() > y_min && pg.y() < y_max) - { - if (pg.z() > z_min && pg.z() < z_max) - ground_truth.push_back(p); - } - } - } - - int number_of_iterations = 30; - PairWiseICP icp; - auto m_pose = affine_matrix_from_pose_tait_bryan(edges[index_active_edge].relative_pose_tb); - - const std::vector& source = - sessions[edges[index_active_edge].index_session_to] - .point_clouds_container.point_clouds[edges[index_active_edge].index_to] - .points_local; - const std::vector& target = - ground_truth; // sessions[edges[index_active_edge].index_session_from].point_clouds_container.point_clouds[edges[index_active_edge].index_from].points_local; - - if (icp.compute(source, target, sr, number_of_iterations, m_pose)) - { - edges[index_active_edge].relative_pose_tb = pose_tait_bryan_from_affine_matrix(m_pose); - } - } - else - { - int number_of_iterations = 30; - PairWiseICP icp; - auto m_pose = affine_matrix_from_pose_tait_bryan(edges[index_active_edge].relative_pose_tb); - - const std::vector& source = - sessions[edges[index_active_edge].index_session_to] - .point_clouds_container.point_clouds[edges[index_active_edge].index_to] - .points_local; - const std::vector& target = - sessions[edges[index_active_edge].index_session_from] - .point_clouds_container.point_clouds[edges[index_active_edge].index_from] - .points_local; - - if (icp.compute(source, target, sr, number_of_iterations, m_pose)) - { - edges[index_active_edge].relative_pose_tb = pose_tait_bryan_from_affine_matrix(m_pose); - } - } - } - } - ImGui::SameLine(); - if (ImGui::Button("ICP [search radius 0.1m]")) - { - float sr = 0.1; - std::cout << "Iterative Closest Point" << std::endl; - if (sessions[edges[index_active_edge].index_session_from].is_ground_truth && - sessions[edges[index_active_edge].index_session_to].is_ground_truth) - { - std::cout << "Two sessions are ground truth!!! ICP is disabled" << std::endl; - } - else - { - bool is_with_ground_truth = false; - if (sessions[edges[index_active_edge].index_session_from].is_ground_truth || - sessions[edges[index_active_edge].index_session_to].is_ground_truth) - { - is_with_ground_truth = true; - } - - if (is_with_ground_truth) - { - int index_session_from = -1; - int index_session_to = -1; - int index_from = -1; - int index_to = -1; - - if (sessions[edges[index_active_edge].index_session_from].is_ground_truth) - { - index_session_from = edges[index_active_edge].index_session_from; - index_session_to = edges[index_active_edge].index_session_to; - index_from = edges[index_active_edge].index_from; - index_to = edges[index_active_edge].index_to; - } - else - { - index_session_from = edges[index_active_edge].index_session_to; - index_session_to = edges[index_active_edge].index_session_from; - index_from = edges[index_active_edge].index_to; - index_to = edges[index_active_edge].index_from; - } - - double x_min = 1000000000000.0; - double y_min = 1000000000000.0; - double z_min = 1000000000000.0; - double x_max = -1000000000000.0; - double y_max = -1000000000000.0; - double z_max = -1000000000000.0; - - auto& points_to = sessions[index_session_to].point_clouds_container.point_clouds[index_to]; - - for (const auto& p : points_to.points_local) - { - auto pg = points_to.m_pose * p; - if (pg.x() < x_min) - x_min = pg.x(); - if (pg.y() < y_min) - y_min = pg.y(); - if (pg.z() < z_min) - z_min = pg.z(); - - if (pg.x() > x_max) - x_max = pg.x(); - if (pg.y() > y_max) - y_max = pg.y(); - if (pg.z() > z_max) - z_max = pg.z(); - } - auto& points_from = sessions[index_session_from].point_clouds_container.point_clouds[index_from]; - std::vector ground_truth; - for (const auto& p : points_from.points_local) - { - auto pg = points_from.m_pose * p; - if (pg.x() > x_min && pg.x() < x_max) - { - if (pg.y() > y_min && pg.y() < y_max) - { - if (pg.z() > z_min && pg.z() < z_max) - ground_truth.push_back(p); - } - } - } - - int number_of_iterations = 30; - PairWiseICP icp; - auto m_pose = affine_matrix_from_pose_tait_bryan(edges[index_active_edge].relative_pose_tb); - - const std::vector& source = - sessions[edges[index_active_edge].index_session_to] - .point_clouds_container.point_clouds[edges[index_active_edge].index_to] - .points_local; - const std::vector& target = - ground_truth; // sessions[edges[index_active_edge].index_session_from].point_clouds_container.point_clouds[edges[index_active_edge].index_from].points_local; - - if (icp.compute(source, target, sr, number_of_iterations, m_pose)) - { - edges[index_active_edge].relative_pose_tb = pose_tait_bryan_from_affine_matrix(m_pose); - } - } - else - { - int number_of_iterations = 30; - PairWiseICP icp; - auto m_pose = affine_matrix_from_pose_tait_bryan(edges[index_active_edge].relative_pose_tb); - - const std::vector& source = - sessions[edges[index_active_edge].index_session_to] - .point_clouds_container.point_clouds[edges[index_active_edge].index_to] - .points_local; - const std::vector& target = - sessions[edges[index_active_edge].index_session_from] - .point_clouds_container.point_clouds[edges[index_active_edge].index_from] - .points_local; - - if (icp.compute(source, target, sr, number_of_iterations, m_pose)) - { - edges[index_active_edge].relative_pose_tb = pose_tait_bryan_from_affine_matrix(m_pose); - } - } - } - } -#if 0 - if (ImGui::Button("Save src")) - { - const auto output_file_name = mandeye::fd::SaveFileDialog("Output file name", mandeye::fd::LAS_LAZ_filter, ".laz"); - std::cout << "laz file to save: '" << output_file_name << "'" << std::endl; - - if (output_file_name.size() > 0) - { - std::vector source = sessions[edges[index_active_edge].index_session_to].point_clouds_container.point_clouds[edges[index_active_edge].index_to].points_local; - std::vector pointcloud; - std::vector intensity; - std::vector timestamps; - - for (size_t i = 0; i < source.size(); i++) - { - pointcloud.push_back(source[i]); - intensity.push_back(0); - timestamps.push_back(0.0); - } - - exportLaz( - output_file_name[0], - pointcloud, - intensity, - timestamps); - } - - /*int number_of_iterations = 30; - PairWiseICP icp; - auto m_pose = affine_matrix_from_pose_tait_bryan(edges[index_active_edge].relative_pose_tb); - - std::vector source = sessions[edges[index_active_edge].index_session_to].point_clouds_container.point_clouds[edges[index_active_edge].index_to].points_local; - std::vector target = sessions[edges[index_active_edge].index_session_from].point_clouds_container.point_clouds[edges[index_active_edge].index_from].points_local; - - if (icp.compute(source, target, sr, number_of_iterations, m_pose)) - { - edges[index_active_edge].relative_pose_tb = pose_tait_bryan_from_affine_matrix(m_pose); - }*/ - //save - } - ImGui::SameLine(); - if (ImGui::Button("Save trg (transfromed only by rotation)")) - { - } -#endif - ////////////////////////////////// - } - } - } - - ImGui::End(); - } -} - -void save_trajectories_to_laz( - const Session& session, - const std::string& output_file_name, - float curve_consecutive_distance_meters, - float not_curve_consecutive_distance_meters, - bool is_trajectory_export_downsampling) -{ - std::vector pointcloud; - std::vector intensity; - std::vector timestamps; - - float consecutive_distance = 0; - for (auto& p : session.point_clouds_container.point_clouds) - { - if (p.visible) - { - for (size_t i = 0; i < p.local_trajectory.size(); i++) - { - const auto& pp = p.local_trajectory[i].m_pose.translation(); - Eigen::Vector3d vp; - vp = p.m_pose * pp; // + session.point_clouds_container.offset; - - if (i > 0) - { - double dist = (p.local_trajectory[i].m_pose.translation() - p.local_trajectory[i - 1].m_pose.translation()).norm(); - consecutive_distance += dist; - } - - bool is_curve = false; - - if (i > 100 && i < p.local_trajectory.size() - 100) - { - Eigen::Vector3d position_prev = p.local_trajectory[i - 100].m_pose.translation(); - Eigen::Vector3d position_curr = p.local_trajectory[i].m_pose.translation(); - Eigen::Vector3d position_next = p.local_trajectory[i + 100].m_pose.translation(); - - Eigen::Vector3d v1 = position_curr - position_prev; - Eigen::Vector3d v2 = position_next - position_curr; - - if (v1.norm() > 0 && v2.norm() > 0) - { - double angle_deg = fabs(acos(v1.dot(v2) / (v1.norm() * v2.norm())) * RAD_TO_DEG); - - if (angle_deg > 10.0) - { - is_curve = true; - } - } - } - double tol = not_curve_consecutive_distance_meters; - - if (is_curve) - { - tol = curve_consecutive_distance_meters; - } - - if (!is_trajectory_export_downsampling) - { - pointcloud.push_back(vp); - intensity.push_back(0); - timestamps.push_back(p.local_trajectory[i].timestamps.first); - } - else - { - if (consecutive_distance >= tol) - { - consecutive_distance = 0; - pointcloud.push_back(vp); - intensity.push_back(0); - timestamps.push_back(p.local_trajectory[i].timestamps.first); - } - } - } - } - } - // if (!exportLaz(output_file_name, pointcloud, intensity, gnss.offset_x, gnss.offset_y, gnss.offset_alt)) - if (!exportLaz( - output_file_name, - pointcloud, - intensity, - timestamps, - session.point_clouds_container.offset.x(), - session.point_clouds_container.offset.y(), - session.point_clouds_container.offset.z())) - { - std::cout << "problem with saving file: " << output_file_name << std::endl; - } -} - -void createDXFPolyline(const std::string& filename, const std::vector& points) -{ - std::ofstream dxfFile(filename); - dxfFile << std::setprecision(20); - if (!dxfFile.is_open()) - { - std::cerr << "Failed to open file: " << filename << std::endl; - return; - } - - // DXF header - dxfFile << "0\nSECTION\n2\nHEADER\n0\nENDSEC\n"; - dxfFile << "0\nSECTION\n2\nTABLES\n0\nENDSEC\n"; - - // Start the ENTITIES section - dxfFile << "0\nSECTION\n2\nENTITIES\n"; - - // Start the POLYLINE entity - dxfFile << "0\nPOLYLINE\n"; - dxfFile << "8\n0\n"; // Layer 0 - dxfFile << "66\n1\n"; // Indicates the presence of vertices - dxfFile << "70\n8\n"; // 1 = Open polyline - - // Write the VERTEX entities - for (const auto& point : points) - { - dxfFile << "0\nVERTEX\n"; - dxfFile << "8\n0\n"; // Layer 0 - dxfFile << "10\n" << point.x() << "\n"; // X coordinate - dxfFile << "20\n" << point.y() << "\n"; // Y coordinate - dxfFile << "30\n" << point.z() << "\n"; // Z coordinate - } - - // End the POLYLINE - dxfFile << "0\nSEQEND\n"; - - // End the ENTITIES section - dxfFile << "0\nENDSEC\n"; - - // End the DXF file - dxfFile << "0\nEOF\n"; - - dxfFile.close(); - std::cout << "DXF file created: " << filename << std::endl; -} - -void save_trajectories( - Session& session, - const std::string& output_file_name, - float curve_consecutive_distance_meters, - float not_curve_consecutive_distance_meters, - bool is_trajectory_export_downsampling, - bool write_lidar_timestamp, - bool write_unix_timestamp, - bool use_quaternions, - bool save_to_dxf) -{ - std::ofstream outfile; - if (!save_to_dxf) - { - outfile.open(output_file_name); - } - if (save_to_dxf || outfile.good()) - { - float consecutive_distance = 0; - std::vector polylinePoints; - for (auto& p : session.point_clouds_container.point_clouds) - { - if (p.visible) - { - for (size_t i = 0; i < p.local_trajectory.size(); i++) - { - const auto& m = p.local_trajectory[i].m_pose; - Eigen::Affine3d pose = p.m_pose * m; - pose.translation() += session.point_clouds_container.offset; - - if (i > 0) - { - double dist = (p.local_trajectory[i].m_pose.translation() - p.local_trajectory[i - 1].m_pose.translation()).norm(); - consecutive_distance += dist; - } - - bool is_curve = false; - - if (i > 100 && i < p.local_trajectory.size() - 100) - { - Eigen::Vector3d position_prev = p.local_trajectory[i - 100].m_pose.translation(); - Eigen::Vector3d position_curr = p.local_trajectory[i].m_pose.translation(); - Eigen::Vector3d position_next = p.local_trajectory[i + 100].m_pose.translation(); - - Eigen::Vector3d v1 = position_curr - position_prev; - Eigen::Vector3d v2 = position_next - position_curr; - - if (v1.norm() > 0 && v2.norm() > 0) - { - double angle_deg = fabs(acos(v1.dot(v2) / (v1.norm() * v2.norm())) * RAD_TO_DEG); - - if (angle_deg > 10.0) - is_curve = true; - } - } - double tol = not_curve_consecutive_distance_meters; - - if (is_curve) - tol = curve_consecutive_distance_meters; - - if (!is_trajectory_export_downsampling || (is_trajectory_export_downsampling && consecutive_distance >= tol)) - { - if (is_trajectory_export_downsampling) - consecutive_distance = 0; - if (save_to_dxf) - polylinePoints.push_back(pose.translation()); - else - { - outfile << std::setprecision(20); - - if (write_lidar_timestamp) - outfile << p.local_trajectory[i].timestamps.first << ","; - if (write_unix_timestamp) - outfile << p.local_trajectory[i].timestamps.second << ","; - - outfile << pose(0, 3) << "," << pose(1, 3) << "," << pose(2, 3) << ","; - if (use_quaternions) - { - Eigen::Quaterniond q(pose.rotation()); - outfile << q.x() << "," << q.y() << "," << q.z() << "," << q.w() << std::endl; - } - else - outfile << pose(0, 0) << "," << pose(0, 1) << "," << pose(0, 2) << "," << pose(1, 0) << "," << pose(1, 1) - << "," << pose(1, 2) << "," << pose(2, 0) << "," << pose(2, 1) << "," << pose(2, 2) << std::endl; - } - } - } - } - } - if (!save_to_dxf) - outfile.close(); - else - createDXFPolyline(output_file_name, polylinePoints); - } -} - -bool save_project_settings(const std::string& file_name, const ProjectSettings& _project_settings) -{ - std::cout << "saving file: '" << file_name << "'" << std::endl; - - nlohmann::json jj; - - nlohmann::json jsession_file_names; - for (const auto& pc : _project_settings.session_file_names) - { - nlohmann::json jfn{ { "session_file_name", toSessionPath(pc, file_name) } }; - jsession_file_names.push_back(jfn); - } - jj["session_file_names"] = jsession_file_names; - - nlohmann::json jloop_closure_edges; - for (const auto& edge : edges) - { - nlohmann::json jloop_closure_edge{ - { "px", edge.relative_pose_tb.px }, - { "py", edge.relative_pose_tb.py }, - { "pz", edge.relative_pose_tb.pz }, - { "om", edge.relative_pose_tb.om }, - { "fi", edge.relative_pose_tb.fi }, - { "ka", edge.relative_pose_tb.ka }, - { "w_px", edge.relative_pose_tb_weights.px }, - { "w_py", edge.relative_pose_tb_weights.py }, - { "w_pz", edge.relative_pose_tb_weights.pz }, - { "w_om", edge.relative_pose_tb_weights.om }, - { "w_fi", edge.relative_pose_tb_weights.fi }, - { "w_ka", edge.relative_pose_tb_weights.ka }, - { "index_from", edge.index_from }, - { "index_to", edge.index_to }, - { "is_fixed_px", edge.is_fixed_px }, - { "is_fixed_py", edge.is_fixed_py }, - { "is_fixed_pz", edge.is_fixed_pz }, - { "is_fixed_om", edge.is_fixed_om }, - { "is_fixed_fi", edge.is_fixed_fi }, - { "is_fixed_ka", edge.is_fixed_ka }, - { "index_session_from", edge.index_session_from }, - { "index_session_to", edge.index_session_to }, - }; - jloop_closure_edges.push_back(jloop_closure_edge); - } - jj["loop_closure_edges"] = jloop_closure_edges; - - std::ofstream fs(file_name); - if (!fs.good()) - return false; - fs << jj.dump(2); - fs.close(); - - return true; -} - -void update_timestamp_offset() -{ - std::cout << "update_timestamp" << std::endl; - time_stamp_offset = std::numeric_limits::max(); - - for (const auto& s : sessions) - { - if (!s.point_clouds_container.point_clouds.empty() && !s.point_clouds_container.point_clouds[0].local_trajectory.empty()) - { - double ts = s.point_clouds_container.point_clouds[0].local_trajectory[0].timestamps.first; - if (ts < time_stamp_offset) - time_stamp_offset = ts; - } - } - - std::cout << "new time_stamp_offset = " << time_stamp_offset << std::endl; -} - -bool revert(std::vector& sessions) -{ - for (auto& session : sessions) - { - for (auto& pc : session.point_clouds_container.point_clouds) - pc.m_pose = pc.m_pose_temp; - } - return true; -} - -bool revert_to_initial(std::vector& sessions) -{ - for (auto& session : sessions) - { - for (auto& pc : session.point_clouds_container.point_clouds) - pc.m_pose = pc.m_initial_pose; - } - return true; -} - -bool save_results(std::vector& sessions) -{ - for (auto& session : sessions) - { - if (!session.is_ground_truth) - { - std::cout << "saving result to: " << session.point_clouds_container.poses_file_name << std::endl; - session.point_clouds_container.save_poses(fs::path(session.point_clouds_container.poses_file_name).string(), false); - } - } - return true; -} - -Eigen::Vector3d GLWidgetGetOGLPos(int x, int y, const ObservationPicking& observation_picking) -{ - const auto laser_beam = GetLaserBeam(x, y); - - RegistrationPlaneFeature::Plane pl; - - pl.a = 0; - pl.b = 0; - pl.c = 1; - pl.d = -observation_picking.picking_plane_height; - - Eigen::Vector3d pos = rayIntersection(laser_beam, pl); - - std::cout << "intersection: " << pos.x() << " " << pos.y() << " " << pos.z() << std::endl; - - return pos; -} - -bool loadProject(const std::string& file_name, ProjectSettings& _project_settings) -{ - std::cout << "Opening project file: '" << file_name << "'\n"; - - try - { - std::ifstream fs(file_name); - if (!fs.good()) - return false; - nlohmann::json data = nlohmann::json::parse(fs); - fs.close(); - - _project_settings.session_file_names.clear(); - - std::cout << "Contained sessions:\n"; - - for (const auto& fn_json : data["session_file_names"]) - { - const std::string fn = resolveProjectPath(fn_json["session_file_name"].get(), file_name); - _project_settings.session_file_names.push_back(fn); - std::cout << "'" << fn << "'"; - if (!fs::exists(fn)) - std::cout << " (WARNING: session file does not exist! Please manually adapt path)"; - std::cout << "\n"; - } - - edges.clear(); - for (const auto& edge_json : data["loop_closure_edges"]) - { - Edge edge; - edge.index_from = edge_json["index_from"]; - edge.index_to = edge_json["index_to"]; - edge.is_fixed_fi = edge_json["is_fixed_fi"]; - edge.is_fixed_ka = edge_json["is_fixed_ka"]; - edge.is_fixed_om = edge_json["is_fixed_om"]; - edge.is_fixed_px = edge_json["is_fixed_px"]; - edge.is_fixed_py = edge_json["is_fixed_py"]; - edge.is_fixed_pz = edge_json["is_fixed_pz"]; - edge.relative_pose_tb.fi = edge_json["fi"]; - edge.relative_pose_tb.ka = edge_json["ka"]; - edge.relative_pose_tb.om = edge_json["om"]; - edge.relative_pose_tb.px = edge_json["px"]; - edge.relative_pose_tb.py = edge_json["py"]; - edge.relative_pose_tb.pz = edge_json["pz"]; - edge.relative_pose_tb_weights.fi = edge_json["w_fi"]; - edge.relative_pose_tb_weights.ka = edge_json["w_ka"]; - edge.relative_pose_tb_weights.om = edge_json["w_om"]; - edge.relative_pose_tb_weights.px = edge_json["w_px"]; - edge.relative_pose_tb_weights.py = edge_json["w_py"]; - edge.relative_pose_tb_weights.pz = edge_json["w_pz"]; - edge.index_session_from = edge_json["index_session_from"]; - edge.index_session_to = edge_json["index_session_to"]; - edges.push_back(edge); - } - - std::cout << "Found " << edges.size() << "edges\nOpening done\n"; - - return true; - } catch (std::exception& e) - { - std::cout << "can't load project settings: " << e.what() << std::endl; - return false; - } - - std::string newTitle = winTitle + " - " + truncPath(file_name); - glutSetWindowTitle(newTitle.c_str()); - - loaded_sessions = false; - time_stamp_offset = 0.0; - - return true; -} - -void openProject() -{ - std::string input_file_name = ""; - input_file_name = mandeye::fd::OpenFileDialogOneFile("Open project", mandeye::fd::Project_filter); - - if (input_file_name.size() > 0) - { - loadProject(fs::path(input_file_name).string(), project_settings); - } -} - -void saveProject() -{ - std::string output_file_name = ""; - output_file_name = mandeye::fd::SaveFileDialog("Save project file", mandeye::fd::Project_filter, ".mjp", "project"); - - if (output_file_name.size() > 0) - if (save_project_settings(fs::path(output_file_name).string(), project_settings)) - { - std::string newTitle = winTitle + " - " + truncPath(output_file_name); - glutSetWindowTitle(newTitle.c_str()); - } -} - -void addSession() -{ - auto input_file_names = mandeye::fd::OpenFileDialog("Add session(s)", mandeye::fd::Session_filter, true); - - if (input_file_names.size() > 0) - { - for (const auto& input_file_name : input_file_names) - { - std::cout << "Adding session file: '" << input_file_name << "'" << std::endl; - project_settings.session_file_names.push_back(input_file_name); - } - - loaded_sessions = false; - time_stamp_offset = 0.0; - } -} - -void loadSessions() -{ - sessions.clear(); - for (const auto& ps : project_settings.session_file_names) - { - Session session; - session.load(fs::path(ps).string(), is_decimate, bucket_x, bucket_y, bucket_z, calculate_offset); - - // making sure irelevant session specific settings that could affect rendering are off - session.point_clouds_container.xz_intersection = false; - session.point_clouds_container.yz_intersection = false; - session.point_clouds_container.xy_intersection = false; - session.point_clouds_container.xz_grid_10x10 = false; - session.point_clouds_container.xz_grid_1x1 = false; - session.point_clouds_container.xz_grid_01x01 = false; - session.point_clouds_container.yz_grid_10x10 = false; - session.point_clouds_container.yz_grid_1x1 = false; - session.point_clouds_container.yz_grid_01x01 = false; - session.point_clouds_container.xy_grid_10x10 = false; - session.point_clouds_container.xy_grid_1x1 = false; - session.point_clouds_container.xy_grid_01x01 = false; - - sessions.push_back(session); - if (session.is_ground_truth) - index_gt = sessions.size() - 1; - } - loaded_sessions = true; - - // reorder - std::vector sessions_reorder; - std::vector session_file_names_reordered; - - std::map map_reorder; - // project_settings.session_file_names. - int new_index = 0; - for (size_t i = 0; i < sessions.size(); i++) - { - if (sessions[i].is_ground_truth) - { - sessions_reorder.push_back(sessions[i]); - session_file_names_reordered.push_back(project_settings.session_file_names[i]); - map_reorder[i] = new_index++; - } - } - for (size_t i = 0; i < sessions.size(); i++) - { - if (!sessions[i].is_ground_truth) - { - sessions_reorder.push_back(sessions[i]); - session_file_names_reordered.push_back(project_settings.session_file_names[i]); - map_reorder[i] = new_index++; - } - } - sessions = sessions_reorder; - project_settings.session_file_names = session_file_names_reordered; - - for (auto& e : edges) - { - e.index_session_from = map_reorder[e.index_session_from]; - e.index_session_to = map_reorder[e.index_session_to]; - } - - std::cout << "sessions reordered, ground truth should be in front" << std::endl; - for (const auto& s : sessions) - { - std::cout << "session: '" << s.session_file_name << "' ground truth [" << int(s.is_ground_truth) << "]" << std::endl; - } - - // update time_stamp_offset - std::cout << "update time_stamp_offset" << std::endl; - for (const auto& s : sessions) - { - if (s.point_clouds_container.point_clouds.size() > 0) - { - if (s.point_clouds_container.point_clouds[0].local_trajectory.size() > 0) - { - if (s.point_clouds_container.point_clouds[0].local_trajectory[0].timestamps.first > time_stamp_offset) - { - time_stamp_offset = s.point_clouds_container.point_clouds[0].local_trajectory[0].timestamps.first; - } - } - } - } -} - -void generate_loop_closures(const std::vector& sessions, std::vector& edges) -{ - edges.clear(); - // Implementation for generating loop closures - - // bool found_edge = false; - - for (int i1 = 0; i1 < sessions.size(); i1++) - { - for (int j1 = 0; j1 < sessions[i1].point_clouds_container.point_clouds.size(); j1++) - { - Eigen::Affine3d pose_i = sessions[i1].point_clouds_container.point_clouds[j1].m_pose; - - for (int i2 = i1 + 1; i2 < sessions.size(); i2++) - { - for (int j2 = 0; j2 < sessions[i2].point_clouds_container.point_clouds.size(); j2++) - { - Eigen::Affine3d pose_j = sessions[i2].point_clouds_container.point_clouds[j2].m_pose; - - if ((pose_i.translation() - pose_j.translation()).norm() < 10.0) // Example threshold for proximity - { - // found_edge = true; - // Create a loop closure edge between pose_i and pose_j - /*Edge edge; - edge.index_session_from = i1; - edge.index_from = j1; - edge.index_session_to = i2; - edge.index_to = j2; - - // Initialize other edge parameters as needed - edges.push_back(edge);*/ - - Edge edge; - - edge.index_session_from = i1; - edge.index_session_to = i2; - - edge.index_from = j1; - edge.index_to = j2; - - std::cout << "Found loop closure edge between session " << i1 << " (pose " << j1 << ") and session " << i2 - << " (pose " << j2 << ")" << std::endl; - - edge.relative_pose_tb = pose_tait_bryan_from_affine_matrix( - sessions[edge.index_session_from].point_clouds_container.point_clouds[edge.index_from].m_pose.inverse() * - sessions[edge.index_session_to].point_clouds_container.point_clouds[edge.index_to].m_pose); - - edge.relative_pose_tb_weights.px = 1.0; - edge.relative_pose_tb_weights.py = 1.0; - edge.relative_pose_tb_weights.pz = 1.0; - edge.relative_pose_tb_weights.om = 1.0; - edge.relative_pose_tb_weights.fi = 1.0; - edge.relative_pose_tb_weights.ka = 1.0; - - edges.push_back(edge); - - // j1 += 20; - // j2 += 20; - } - } - } // for(int i2 = i1 + 1; i2 < sessions.size(); i2++) - } // for(int j1 = 0; j1 < sessions[i1].point_clouds_container.point_clouds.size(); j1++) - } // for(int i1 = 0; i1 < sessions.size(); i1++) -} - -void icp_all_edges(std::vector& sessions, std::vector& edges, float sr) -{ - std::cout << "icp_all_edges" << std::endl; - - int number_of_iterations = 10; - - for (size_t index_active_edge = 0; index_active_edge < edges.size(); index_active_edge++) - { - PairWiseICP icp; - auto m_pose = affine_matrix_from_pose_tait_bryan(edges[index_active_edge].relative_pose_tb); - - std::vector source; - auto& e = edges[index_active_edge]; - for (int i = -num_edge_extended_before; i <= num_edge_extended_after; i++) - { - int index_src = e.index_to + i; - if (index_src >= 0 && - index_src < sessions[edges[index_active_edge].index_session_to].point_clouds_container.point_clouds.size()) - { - Eigen::Affine3d m_src = - sessions[edges[index_active_edge].index_session_to].point_clouds_container.point_clouds.at(index_src).m_pose; - for (int k = 0; k < - sessions[edges[index_active_edge].index_session_to].point_clouds_container.point_clouds[index_src].points_local.size(); - k++) - { - Eigen::Vector3d p_g = m_src * - sessions[edges[index_active_edge].index_session_to].point_clouds_container.point_clouds[index_src].points_local[k]; - source.push_back(p_g); - } - // point_clouds_container.point_clouds.at(index_src).render(m_src, 1); - } - } - std::vector target; - - for (int i = -num_edge_extended_before; i <= num_edge_extended_after; i++) - { - int index_trg = e.index_from + i; - if (index_trg >= 0 && - index_trg < sessions[edges[index_active_edge].index_session_from].point_clouds_container.point_clouds.size()) - { - Eigen::Affine3d m_trg = - sessions[edges[index_active_edge].index_session_from].point_clouds_container.point_clouds.at(index_trg).m_pose; - for (int k = 0; k < sessions[edges[index_active_edge].index_session_from] - .point_clouds_container.point_clouds[index_trg] - .points_local.size(); - k++) - { - Eigen::Vector3d p_g = m_trg * - sessions[edges[index_active_edge].index_session_from] - .point_clouds_container.point_clouds[index_trg] - .points_local[k]; - target.push_back(p_g); - } - // point_clouds_container.point_clouds.at(index_src).render(m_src, 1); - } - } - - Eigen::Affine3d m_src_inv = - sessions[edges[index_active_edge].index_session_to].point_clouds_container.point_clouds[e.index_to].m_pose.inverse(); - - for (auto& p : source) - { - p = m_src_inv * p; - } - - Eigen::Affine3d m_trg_inv = - sessions[edges[index_active_edge].index_session_from].point_clouds_container.point_clouds[e.index_from].m_pose.inverse(); - - for (auto& p : target) - { - p = m_trg_inv * p; - } - - if (icp.compute(source, target, sr, number_of_iterations, m_pose)) - edges[index_active_edge].relative_pose_tb = pose_tait_bryan_from_affine_matrix(m_pose); - } -} - -void settings_gui() -{ - if (ImGui::Begin("Settings", &is_settings_gui)) - { - ImGui::Checkbox("Downsample during load", &is_decimate); - ImGui::SameLine(); - ImGui::Text("Bucket [m]:"); - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::InputDouble("X##b", &bucket_x, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(xText); - ImGui::SameLine(); - ImGui::InputDouble("Y##b", &bucket_y, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(yText); - ImGui::SameLine(); - ImGui::InputDouble("Z##b", &bucket_z, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(zText); - ImGui::PopItemWidth(); - - ImGui::NewLine(); - - ImGui::Separator(); - - ImGui::Text("Benchmark settings:"); - - ImGui::PushItemWidth(ImGuiNumberWidth * 2); - - static double fast_plus = 100000000.0; - static double fast_plus_plus = 1000000000.0; - - ImGui::InputDouble("Increment", &fast_plus); - ImGui::InputDouble("Fast increment", &fast_plus_plus); - ImGui::InputDouble("Timestamp offset", &time_stamp_offset, fast_plus, fast_plus_plus); - ImGui::PopItemWidth(); - ImGui::SameLine(); - if (ImGui::Button("Set to origin")) - { - bool is_first_gt = false; - - if (sessions.size() > 0) - { - if (sessions[0].is_ground_truth) - is_first_gt = true; - } - - Eigen::Affine3d m_gt = Eigen::Affine3d::Identity(); - if (sessions.size() > 0) - { - int index_point_clouds = -1; - int index_local_trajectory = -1; - bool found = false; - for (size_t a = 0; a < sessions[0].point_clouds_container.point_clouds.size(); a++) - { - for (size_t b = 0; b < sessions[0].point_clouds_container.point_clouds[a].local_trajectory.size(); b++) - { - if (sessions[0].point_clouds_container.point_clouds[a].local_trajectory[b].timestamps.first > time_stamp_offset) - { - if (!found) - { - found = true; - index_point_clouds = a; - index_local_trajectory = b; - break; - } - } - } - } - - if (index_point_clouds != -1 && index_local_trajectory != -1) - { - m_gt = sessions[0].point_clouds_container.point_clouds[index_point_clouds].m_pose * - sessions[0].point_clouds_container.point_clouds[index_point_clouds].local_trajectory[index_local_trajectory].m_pose; - } - } - - // for (auto& session : sessions) - for (auto& session : sessions) - { - if (is_first_gt) - { - if (session.is_ground_truth) - continue; - } - - int index_point_clouds = -1; - int index_local_trajectory = -1; - bool found = false; - for (size_t a = 0; a < session.point_clouds_container.point_clouds.size(); a++) - { - for (size_t b = 0; b < session.point_clouds_container.point_clouds[a].local_trajectory.size(); b++) - { - if (session.point_clouds_container.point_clouds[a].local_trajectory[b].timestamps.first > time_stamp_offset) - { - if (!found) - { - found = true; - index_point_clouds = a; - index_local_trajectory = b; - break; - } - } - } - } - - if (index_point_clouds != -1 && index_local_trajectory != -1) - { - auto m1 = session.point_clouds_container.point_clouds[index_point_clouds].m_pose; - auto m2 = - session.point_clouds_container.point_clouds[index_point_clouds].local_trajectory[index_local_trajectory].m_pose; - - auto inv = Eigen::Affine3d::Identity(); - inv = (m1 * m2).inverse(); - for (size_t index = 0; index < session.point_clouds_container.point_clouds.size(); index++) - session.point_clouds_container.point_clouds[index].m_pose = - inv * session.point_clouds_container.point_clouds[index].m_pose; - - for (size_t index = 0; index < session.point_clouds_container.point_clouds.size(); index++) - session.point_clouds_container.point_clouds[index].m_pose = - m_gt * session.point_clouds_container.point_clouds[index].m_pose; - } - } - } - - static bool open_import_popup = false; - static bool show_instruction = false; - - ImGui::Dummy(ImVec2(0, 10)); - - if (ImGui::Button("Import Benchmark Output Folders")) - { - open_import_popup = true; - ImGui::OpenPopup("Import Benchmark"); - } - - if (ImGui::BeginPopupModal("Import Benchmark", NULL, ImGuiWindowFlags_AlwaysAutoResize)) - { - ImGui::Text("Import benchmark sessions"); - ImGui::Separator(); - ImGui::SetNextWindowSize(ImVec2(740, 340), ImGuiCond_Once); - if (ImGui::Button("Instruction")) - { - show_instruction = !show_instruction; - } - - ImGui::Dummy(ImVec2(0, 10)); - if (ImGui::Button("Select Folder")) - { - const std::string algorithms[] = { "ct-icp", "glim", "super-lio", "dlio", - "i2ekf-lo", "superOdom", "lego-loam", "faster-lio", - "kiss-icp", "fast-lio", "lio-ekf", "genz-icp", - "point-lio", "ig-lio", "dlo", "lidar_odometry_ros_wrapper" }; - - std::vector missing; - std::unordered_map algo_map; - - for (const auto& algo : algorithms) - { - if (algo == "kiss-icp") - { - algo_map[algo] = "output_hdmapping-kiss"; - } - else if (algo == "genz-icp") - { - algo_map[algo] = "output_hdmapping-genz"; - } - else if (algo == "lidar_odometry_ros_wrapper") - { - algo_map[algo] = "output_hdmapping-lidar-odometry-ros"; - } - else - { - algo_map[algo] = "output_hdmapping-" + algo; - } - } - - fs::path path = fs::path(mandeye::fd::SelectFolder("Add sessions")); - - for (const auto& algo : algorithms) - { - fs::path output_folder = path / algo / algo_map[algo]; - fs::path session_file = output_folder / "session.json"; - - if (fs::is_directory(output_folder)) - { - auto it = - std::find(project_settings.session_file_names.begin(), project_settings.session_file_names.end(), session_file); - - if (it == project_settings.session_file_names.end()) - { - std::cout << "Adding session file: '" << session_file << "'" << std::endl; - project_settings.session_file_names.push_back(session_file.string()); - } - } - else - { - missing.push_back(output_folder); - } - } - - for (const auto& miss : missing) - { - std::cout << miss << " doesn't exist" << std::endl; - } - } - - ImGui::SameLine(); - - if (ImGui::Button("Close")) - { - ImGui::CloseCurrentPopup(); - show_instruction = false; - } - - if (show_instruction) - { - ImGui::BeginChild("InstructionChild", ImVec2(720, 300), true, ImGuiWindowFlags_HorizontalScrollbar); - ImGui::Separator(); - - ImGui::TextWrapped("Required folder structure:"); - - ImGui::Spacing(); - - ImGui::TextWrapped("Folders must follow the structure generated in benchmark-HDMapping-Orchestration (step 3):"); - ImGui::TextWrapped("https://github.com/MapsHD/benchmark-HDMapping-Orchestration"); - - ImGui::Spacing(); - ImGui::Separator(); - - ImGui::BulletText("chosen_folder/"); - ImGui::BulletText(" ct-icp/output_hdmapping-ct-icp/session.json"); - ImGui::BulletText(" glim/output_hdmapping-glim/session.json"); - ImGui::BulletText(" kiss-icp/output_hdmapping-kiss/session.json"); - ImGui::BulletText(" fast-lio/output_hdmapping-fast-lio/session.json"); - ImGui::BulletText(" ... (same pattern for other algorithms)"); - - ImGui::Spacing(); - ImGui::EndChild(); - } - - ImGui::EndPopup(); - } - if (project_settings.session_file_names.size() > 0) - { - ImGui::Separator(); - - ImGui::Text("Sessions:"); - - for (size_t i = 0; i < project_settings.session_file_names.size(); i++) - { - ImGui::Text(truncPath(project_settings.session_file_names[i]).c_str()); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(project_settings.session_file_names[i].c_str()); - - if (project_settings.session_file_names.size() == sessions.size()) - { - ImGui::BeginDisabled(is_loop_closure_gui); - { - ImGui::SameLine(); - ImGui::Checkbox(("Visible##" + std::to_string(i)).c_str(), &sessions[i].visible); - } - ImGui::EndDisabled(); - - ImGui::SameLine(); - if (ImGui::RadioButton(("Ground truth##" + std::to_string(i)).c_str(), &index_gt, i)) - if (old_index_gt == i) - index_gt = -1; // unselect - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Select session as unmovable reference"); - - ImGui::BeginDisabled(!sessions[i].visible); - { - ImGui::BeginDisabled(sessions[i].is_ground_truth); - { - ImGui::SameLine(); - if (ImGui::RadioButton(("Gizmo##" + std::to_string(i)).c_str(), &index_gizmo, i)) - if (old_index_gizmo == i) - index_gizmo = -1; // unselect - } - ImGui::EndDisabled(); - - ImGui::SameLine(); - ImGui::ColorEdit3( - ("Color##" + std::to_string(i)).c_str(), (float*)&sessions[i].render_color, ImGuiColorEditFlags_NoInputs); - for (auto& pc : sessions[i].point_clouds_container.point_clouds) - { - pc.traj_color[0] = sessions[i].render_color[0]; - pc.traj_color[1] = sessions[i].render_color[1]; - pc.traj_color[2] = sessions[i].render_color[2]; - pc.render_color[0] = sessions[i].render_color[0]; - pc.render_color[1] = sessions[i].render_color[1]; - pc.render_color[2] = sessions[i].render_color[2]; - } - } - ImGui::EndDisabled(); - - // - if (sessions[i].point_clouds_container.point_clouds.size() > 0) - { - if (sessions[i].point_clouds_container.point_clouds[0].local_trajectory.size() > 0) - { - if (sessions[i] - .point_clouds_container.point_clouds[sessions[i].point_clouds_container.point_clouds.size() - 1] - .local_trajectory.size() > 0) - { - ImGui::SameLine(); - - int index_last = sessions[i].point_clouds_container.point_clouds.size() - 1; - int index_last2 = sessions[i].point_clouds_container.point_clouds[index_last].local_trajectory.size() - 1; - - ImGui::Text( - "Timestamp range: <%.0f, %.0f>", - sessions[i].point_clouds_container.point_clouds[0].local_trajectory[0].timestamps.first, - sessions[i] - .point_clouds_container.point_clouds[index_last] - .local_trajectory[index_last2] - .timestamps.first); - } - } - } - } - } - - if (project_settings.session_file_names.size() == sessions.size()) - { - if ((old_index_gt != index_gt) || (old_index_gizmo != index_gizmo)) - { - for (size_t i = 0; i < sessions.size(); i++) - { - sessions[i].is_ground_truth = (i == index_gt); - sessions[i].is_gizmo = (i == index_gizmo); - } - - old_index_gt = index_gt; - old_index_gizmo = index_gizmo; - } - - if (index_gizmo != -1 && index_gizmo < sessions.size()) - { - // sessions[index_gizmo].is_gizmo = true; - m_gizmo[0] = (float)sessions[index_gizmo].point_clouds_container.point_clouds[0].m_pose(0, 0); - m_gizmo[1] = (float)sessions[index_gizmo].point_clouds_container.point_clouds[0].m_pose(1, 0); - m_gizmo[2] = (float)sessions[index_gizmo].point_clouds_container.point_clouds[0].m_pose(2, 0); - m_gizmo[3] = (float)sessions[index_gizmo].point_clouds_container.point_clouds[0].m_pose(3, 0); - m_gizmo[4] = (float)sessions[index_gizmo].point_clouds_container.point_clouds[0].m_pose(0, 1); - m_gizmo[5] = (float)sessions[index_gizmo].point_clouds_container.point_clouds[0].m_pose(1, 1); - m_gizmo[6] = (float)sessions[index_gizmo].point_clouds_container.point_clouds[0].m_pose(2, 1); - m_gizmo[7] = (float)sessions[index_gizmo].point_clouds_container.point_clouds[0].m_pose(3, 1); - m_gizmo[8] = (float)sessions[index_gizmo].point_clouds_container.point_clouds[0].m_pose(0, 2); - m_gizmo[9] = (float)sessions[index_gizmo].point_clouds_container.point_clouds[0].m_pose(1, 2); - m_gizmo[10] = (float)sessions[index_gizmo].point_clouds_container.point_clouds[0].m_pose(2, 2); - m_gizmo[11] = (float)sessions[index_gizmo].point_clouds_container.point_clouds[0].m_pose(3, 2); - m_gizmo[12] = (float)sessions[index_gizmo].point_clouds_container.point_clouds[0].m_pose(0, 3); - m_gizmo[13] = (float)sessions[index_gizmo].point_clouds_container.point_clouds[0].m_pose(1, 3); - m_gizmo[14] = (float)sessions[index_gizmo].point_clouds_container.point_clouds[0].m_pose(2, 3); - m_gizmo[15] = (float)sessions[index_gizmo].point_clouds_container.point_clouds[0].m_pose(3, 3); - } - } - - ImGui::BeginDisabled((project_settings.session_file_names.size() < 2) || (index_gizmo == -1)); - { - ImGui::Checkbox("Gizmo all sessions", &gizmo_all_sessions); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Gizmo will move all sessions except ground truth one"); - } - ImGui::EndDisabled(); - - ImGui::Separator(); - - ImGui::NewLine(); - - if (project_settings.session_file_names.size() == sessions.size()) - { - number_visible_sessions = 0; - - bool first_session_index_found = false; - for (size_t index = 0; index < sessions.size(); index++) - { - if (sessions[index].visible) - { - number_visible_sessions++; - if (!first_session_index_found) - { - first_session_index = index; - second_session_index = index; - first_session_index_found = true; - } - else - { - second_session_index = index; - } - } - } - - if (!is_loop_closure_gui) - { - static int nr_iter = 100; - ImGui::SetNextItemWidth(ImGuiNumberWidth); - ImGui::InputInt("Number of iterations", &nr_iter); - if (nr_iter < 1) - nr_iter = 1; - - ImGui::InputDouble("Motion Model Weight (1 sigma m): position x [px]", &motion_model_weights.px, 0.0, 0.0, "%.3f"); - ImGui::InputDouble("Motion Model Weight (1 sigma m): position y [py]", &motion_model_weights.py, 0.0, 0.0, "%.3f"); - ImGui::InputDouble("Motion Model Weight (1 sigma m): position z [pz]", &motion_model_weights.pz, 0.0, 0.0, "%.3f"); - ImGui::InputDouble( - "Motion Model Weight (1 sigma degree): orientation om [om]", &motion_model_weights.om, 0.0, 0.0, "%.3f"); - ImGui::InputDouble( - "Motion Model Weight (1 sigma degree): orientation fi [fi]", &motion_model_weights.fi, 0.0, 0.0, "%.3f"); - ImGui::InputDouble( - "Motion Model Weight (1 sigma degree): orientation ka [ka]", &motion_model_weights.ka, 0.0, 0.0, "%.3f"); - - std::string bn = "Optimize (number of iterations: " + std::to_string(nr_iter) + ")"; - - if (ImGui::Button(bn.c_str())) - { - for (int i = 0; i < nr_iter; i++) - { - std::cout << "Iteration [" << i + 1 << "] of: " << nr_iter << std::endl; - optimize(sessions, edges, motion_model_weights); - } - optimized = true; - } - - // if (optimized) - //{ - ImGui::SameLine(); - if (ImGui::Button("Revert")) - revert(sessions); - ImGui::SameLine(); - if (ImGui::Button("Save results")) - save_results(sessions); - ImGui::SameLine(); - if (ImGui::Button("Revert to initial")) - revert_to_initial(sessions); - //} - - if (ImGui::Button("Generate loop closures")) - { - generate_loop_closures(sessions, edges); - } - - if (ImGui::Button("ICP all edges")) - { - icp_all_edges(sessions, edges, search_radius); - } - ImGui::SameLine(); - ImGui::InputDouble("search_radius", &search_radius); - if (search_radius < 0.01) - search_radius = 0.01; - } - - // if (!is_loop_closure_gui && prev_is_loop_closure_gui) - //{ - // exit(1); - // } - } - } - } - - ImGui::End(); -} - -void display() -{ - ImGuiIO& io = ImGui::GetIO(); - glViewport(0, 0, (GLsizei)io.DisplaySize.x, (GLsizei)io.DisplaySize.y); - - 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); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - float ratio = float(io.DisplaySize.x) / float(io.DisplaySize.y); - - updateCameraTransition(); - - viewLocal = Eigen::Affine3f::Identity(); - - for (auto& s : sessions) - { - for (auto& pc : s.point_clouds_container.point_clouds) - { - pc.point_size = gui_point_size; - } - } - - if (!is_ortho) - { - reshape((GLsizei)io.DisplaySize.x, (GLsizei)io.DisplaySize.y); - glTranslatef(translate_x, translate_y, translate_z); - - // janusz - if (is_loop_closure_gui) - { - // sessions[first_session_index].point_clouds_container.point_clouds.at(index_loop_closure_source).render(false, - // observation_picking, viewer_decmiate_point_cloud, false, false, false, false, false, false, false, false, false, false, - // false, false, 100000); - // sessions[second_session_index].point_clouds_container.point_clouds.at(index_loop_closure_target).render(false, - // observation_picking, viewer_decmiate_point_cloud, false, false, false, false, false, false, false, false, false, false, - // false, false, 100000); - - if (first_session_index < sessions[first_session_index].point_clouds_container.point_clouds.size()) - { - if (update_rotation_center) - { - rotation_center.x() = sessions[first_session_index] - .point_clouds_container.point_clouds[index_loop_closure_source] - .m_pose.translation() - .x(); - rotation_center.y() = sessions[first_session_index] - .point_clouds_container.point_clouds[index_loop_closure_source] - .m_pose.translation() - .y(); - rotation_center.z() = sessions[first_session_index] - .point_clouds_container.point_clouds[index_loop_closure_source] - .m_pose.translation() - .z(); - } - } - - if (manipulate_active_edge) - { - if (edges.size() > 0) - { - int index_src = edges[index_active_edge].index_from; - Eigen::Affine3d m_src = - sessions[edges[index_active_edge].index_session_from].point_clouds_container.point_clouds.at(index_src).m_pose; - - if (update_rotation_center) - { - rotation_center.x() = m_src(0, 3); - rotation_center.y() = m_src(1, 3); - rotation_center.z() = m_src(2, 3); - } - } - } - - /*if (session.pose_graph_loop_closure.manipulate_active_edge) - { - if (session.pose_graph_loop_closure.edges.size() > 0) - { - if (session.pose_graph_loop_closure.index_active_edge < session.pose_graph_loop_closure.edges.size()) - { - rotation_center.x() = - session.point_clouds_container.point_clouds[session.pose_graph_loop_closure.edges[session.pose_graph_loop_closure.index_active_edge].index_from].m_pose(0, - 3); rotation_center.y() = - session.point_clouds_container.point_clouds[session.pose_graph_loop_closure.edges[session.pose_graph_loop_closure.index_active_edge].index_from].m_pose(1, - 3); rotation_center.z() = - session.point_clouds_container.point_clouds[session.pose_graph_loop_closure.edges[session.pose_graph_loop_closure.index_active_edge].index_from].m_pose(2, - 3); - } - } - }*/ - } - - viewLocal.translate(rotation_center); - - viewLocal.translate(Eigen::Vector3f(translate_x, translate_y, translate_z)); - if (!lock_z) - viewLocal.rotate(Eigen::AngleAxisf(rotate_x * DEG_TO_RAD, Eigen::Vector3f::UnitX())); - else - viewLocal.rotate(Eigen::AngleAxisf(-90.0 * DEG_TO_RAD, Eigen::Vector3f::UnitX())); - viewLocal.rotate(Eigen::AngleAxisf(rotate_y * DEG_TO_RAD, Eigen::Vector3f::UnitZ())); - - viewLocal.translate(-rotation_center); - - glLoadMatrixf(viewLocal.matrix().data()); - } - else - updateOrthoView(); - - showAxes(); - - if (is_loop_closure_gui) - { - if (manipulate_active_edge) - { - if (edges.size() > 0) - { - /*int index_src = edges[index_active_edge].index_from; - int index_trg = edges[index_active_edge].index_to; - - Eigen::Affine3d m_src = - sessions[edges[index_active_edge].index_session_from].point_clouds_container.point_clouds.at(index_src).m_pose; - Eigen::Affine3d m_trg = m_src * affine_matrix_from_pose_tait_bryan(edges[index_active_edge].relative_pose_tb); - - sessions[edges[index_active_edge].index_session_from].point_clouds_container.point_clouds.at(index_src).render( - m_src, - viewer_decimate_point_cloud, - viewer_reduce_rendered_trajectory, - sessions[edges[index_active_edge].index_session_from].point_clouds_container.point_clouds.at(index_src).render_color); - sessions[edges[index_active_edge].index_session_to].point_clouds_container.point_clouds.at(index_trg).render( - m_trg, - viewer_decimate_point_cloud, - viewer_reduce_rendered_trajectory, - sessions[edges[index_active_edge].index_session_to].point_clouds_container.point_clouds.at(index_trg).render_color);*/ - - int index_src = edges[index_active_edge].index_from; - int index_trg = edges[index_active_edge].index_to; - - Eigen::Affine3d _m_src = - sessions[edges[index_active_edge].index_session_from].point_clouds_container.point_clouds.at(index_src).m_pose; - Eigen::Affine3d _m_trg = _m_src * affine_matrix_from_pose_tait_bryan(edges[index_active_edge].relative_pose_tb); - - Eigen::Affine3d m_src_0 = - sessions[first_session_index].point_clouds_container.point_clouds.at(index_loop_closure_source).m_pose; // Todo - - for (int i = index_loop_closure_source - num_edge_extended_before; i <= index_loop_closure_source + num_edge_extended_after; - i++) - { - if (i >= 0 && i < sessions[first_session_index].point_clouds_container.point_clouds.size() && - sessions[first_session_index].point_clouds_container.point_clouds.size() > 0) - { - // ObservationPicking observation_picking; - // point_clouds_container.point_clouds.at(i).render(false, observation_picking, 1, 1, false, false, false, 10000, - // false); - - Eigen::Affine3d m_src_curr = sessions[first_session_index].point_clouds_container.point_clouds.at(i).m_pose; // Todo - Eigen::Affine3d m_src = _m_src * (m_src_0.inverse() * m_src_curr); - - // sessions[first_session_index].point_clouds_container.point_clouds.at(i).point_size = gui_point_size; - - sessions[first_session_index].point_clouds_container.point_clouds.at(i).render( - m_src, - viewer_decimate_point_cloud, - viewer_reduce_rendered_trajectory, - sessions[edges[index_active_edge].index_session_from].point_clouds_container.point_clouds.at(i).render_color); - } - } - - Eigen::Affine3d m_trg_0 = - sessions[second_session_index].point_clouds_container.point_clouds.at(index_loop_closure_target).m_pose; // Todo - - for (int i = index_loop_closure_target - num_edge_extended_before; i <= index_loop_closure_target + num_edge_extended_after; - i++) - { - if (i >= 0 && i < sessions[second_session_index].point_clouds_container.point_clouds.size() && - sessions[second_session_index].point_clouds_container.point_clouds.size() > 0) - { - // ObservationPicking observation_picking; - // point_clouds_container.point_clouds.at(i).render(false, observation_picking, 1, 1, false, false, false, 10000, - // false); - Eigen::Affine3d m_trg_curr = - sessions[second_session_index].point_clouds_container.point_clouds.at(i).m_pose; // Todo - Eigen::Affine3d m_trg = _m_trg * (m_trg_0.inverse() * m_trg_curr); - - // sessions[second_session_index].point_clouds_container.point_clouds.at(i).point_size = gui_point_size; - sessions[second_session_index].point_clouds_container.point_clouds.at(i).render( - m_trg, - viewer_decimate_point_cloud, - viewer_reduce_rendered_trajectory, - sessions[edges[index_active_edge].index_session_to].point_clouds_container.point_clouds.at(i).render_color); - } - } - } - } - else - { - ObservationPicking observation_picking; - - /*sessions[first_session_index] - .point_clouds_container.point_clouds.at(index_loop_closure_source) - .render( - false, - observation_picking, - viewer_decimate_point_cloud, - viewer_reduce_rendered_trajectory, - false, - false, - false, - 100000, - false);*/ - - for (int i = index_loop_closure_source - num_edge_extended_before; i <= index_loop_closure_source + num_edge_extended_after; - i++) - { - if (i >= 0 && i < sessions[first_session_index].point_clouds_container.point_clouds.size() && - sessions[first_session_index].point_clouds_container.point_clouds.size() > 0) - { - // ObservationPicking observation_picking; - // point_clouds_container.point_clouds.at(i).render(false, observation_picking, 1, 1, false, false, false, 10000, - // false); - Eigen::Affine3d m_src = sessions[first_session_index].point_clouds_container.point_clouds.at(i).m_pose; - - sessions[first_session_index].point_clouds_container.point_clouds.at(i).render( - false, - observation_picking, - viewer_decimate_point_cloud, - viewer_reduce_rendered_trajectory, - false, - false, - false, - 100000, - false); - } - } - - /*sessions[second_session_index] - .point_clouds_container.point_clouds.at(index_loop_closure_target) - .render( - false, - observation_picking, - viewer_decimate_point_cloud, - viewer_reduce_rendered_trajectory, - false, - false, - false, - 100000, - false);*/ - - for (int i = index_loop_closure_target - num_edge_extended_before; i <= index_loop_closure_target + num_edge_extended_after; - i++) - { - if (i >= 0 && i < sessions[second_session_index].point_clouds_container.point_clouds.size() && - sessions[second_session_index].point_clouds_container.point_clouds.size() > 0) - { - // ObservationPicking observation_picking; - // point_clouds_container.point_clouds.at(i).render(false, observation_picking, 1, 1, false, false, false, 10000, - // false); - Eigen::Affine3d m_src = sessions[second_session_index].point_clouds_container.point_clouds.at(i).m_pose; - - sessions[second_session_index].point_clouds_container.point_clouds.at(i).render( - false, - observation_picking, - viewer_decimate_point_cloud, - viewer_reduce_rendered_trajectory, - false, - false, - false, - 100000, - false); - } - } - } - - // sessions[first_session_index].point_clouds_container.render(); - - glBegin(GL_LINE_STRIP); - for (auto& pc : sessions[first_session_index].point_clouds_container.point_clouds) - { - glColor3f(pc.render_color[0], pc.render_color[1], pc.render_color[2]); - glVertex3f(pc.m_pose(0, 3), pc.m_pose(1, 3), pc.m_pose(2, 3)); - } - glEnd(); - - int i = 0; - for (auto& pc : sessions[first_session_index].point_clouds_container.point_clouds) - { - glColor3f(pc.render_color[0], pc.render_color[1], pc.render_color[2]); - glRasterPos3f(pc.m_pose(0, 3), pc.m_pose(1, 3), pc.m_pose(2, 3) + 0.1); - glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)std::to_string(i).c_str()); - i++; - } - - glBegin(GL_LINE_STRIP); - for (auto& pc : sessions[second_session_index].point_clouds_container.point_clouds) - { - glColor3f(pc.render_color[0], pc.render_color[1], pc.render_color[2]); - glVertex3f(pc.m_pose(0, 3), pc.m_pose(1, 3), pc.m_pose(2, 3)); - } - glEnd(); - - i = 0; - for (auto& pc : sessions[second_session_index].point_clouds_container.point_clouds) - { - glColor3f(pc.render_color[0], pc.render_color[1], pc.render_color[2]); - glRasterPos3f(pc.m_pose(0, 3), pc.m_pose(1, 3), pc.m_pose(2, 3) + 0.1); - glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)std::to_string(i).c_str()); - i++; - } - - for (size_t i = 0; i < sessions.size(); i++) - { - for (size_t j = 0; j < sessions[i].pose_graph_loop_closure.edges.size(); j++) - { - int index_src = sessions[i].pose_graph_loop_closure.edges[j].index_from; - int index_trg = sessions[i].pose_graph_loop_closure.edges[j].index_to; - - glColor3f(0.0f, 0.0f, 1.0f); - glBegin(GL_LINES); - auto v1 = sessions[i].point_clouds_container.point_clouds.at(index_src).m_pose.translation(); - auto v2 = sessions[i].point_clouds_container.point_clouds.at(index_trg).m_pose.translation(); - glVertex3f(v1.x(), v1.y(), v1.z()); - glVertex3f(v2.x(), v2.y(), v2.z()); - - glVertex3f((v1.x() + v2.x()) * 0.5, (v1.y() + v2.y()) * 0.5, (v1.z() + v2.z()) * 0.5); - glVertex3f((v1.x() + v2.x()) * 0.5, (v1.y() + v2.y()) * 0.5, (v1.z() + v2.z()) * 0.5 + 10); - glEnd(); - - glRasterPos3f((v1.x() + v2.x()) * 0.5, (v1.y() + v2.y()) * 0.5, (v1.z() + v2.z()) * 0.5 + 10 + 0.1); - glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)std::to_string(j).c_str()); - } - } - - for (size_t i = 0; i < edges.size(); i++) - { - int index_src = edges[i].index_from; - int index_trg = edges[i].index_to; - - int index_session_from = edges[i].index_session_from; - int index_session_to = edges[i].index_session_to; - - if (sessions[index_session_from].is_ground_truth || sessions[index_session_to].is_ground_truth) - glColor3f(0.0f, 1.0f, 1.0f); - else - glColor3f(1.0f, 1.0f, 0.0f); - - glBegin(GL_LINES); - auto v1 = sessions[index_session_from].point_clouds_container.point_clouds.at(index_src).m_pose.translation(); - auto v2 = sessions[index_session_to].point_clouds_container.point_clouds.at(index_trg).m_pose.translation(); - glVertex3f(v1.x(), v1.y(), v1.z()); - glVertex3f(v2.x(), v2.y(), v2.z()); - - glVertex3f((v1.x() + v2.x()) * 0.5, (v1.y() + v2.y()) * 0.5, (v1.z() + v2.z()) * 0.5); - glVertex3f((v1.x() + v2.x()) * 0.5, (v1.y() + v2.y()) * 0.5, (v1.z() + v2.z()) * 0.5 + 10); - glEnd(); - - glRasterPos3f((v1.x() + v2.x()) * 0.5, (v1.y() + v2.y()) * 0.5, (v1.z() + v2.z()) * 0.5 + 10 + 0.1); - glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)std::to_string(i).c_str()); - } - } - else - { - for (auto& session : sessions) - { - if (session.visible) - { - session.point_clouds_container.render(observation_picking, viewer_decimate_point_cloud, viewer_reduce_rendered_trajectory); - session.ground_control_points.render(session.point_clouds_container); - session.control_points.render(session.point_clouds_container, false); - - //// - int index_point_clouds = -1; - int index_local_trajectory = -1; - bool found = false; - for (size_t a = 0; a < session.point_clouds_container.point_clouds.size(); a++) - { - for (size_t b = 0; b < session.point_clouds_container.point_clouds[a].local_trajectory.size(); b++) - { - if (session.point_clouds_container.point_clouds[a].local_trajectory[b].timestamps.first > time_stamp_offset) - { - if (!found) - { - found = true; - index_point_clouds = a; - index_local_trajectory = b; - break; - } - } - } - } - - if (index_point_clouds != -1 && index_local_trajectory != -1) - { - if (index_local_trajectory < session.point_clouds_container.point_clouds[index_point_clouds].local_trajectory.size()) - { - glColor3f( - session.point_clouds_container.point_clouds[index_point_clouds].render_color[0], - session.point_clouds_container.point_clouds[index_point_clouds].render_color[1], - session.point_clouds_container.point_clouds[index_point_clouds].render_color[2]); - glBegin(GL_LINES); - - auto m1 = session.point_clouds_container.point_clouds[index_point_clouds].m_pose; - auto m2 = - session.point_clouds_container.point_clouds[index_point_clouds].local_trajectory[index_local_trajectory].m_pose; - - auto v1 = (m1 * m2).translation(); - - glVertex3f(v1.x() - 5.0, v1.y(), v1.z()); - glVertex3f(v1.x() + 5.0, v1.y(), v1.z()); - - glVertex3f(v1.x(), v1.y() - 5.0, v1.z()); - glVertex3f(v1.x(), v1.y() + 5.0, v1.z()); - - glVertex3f(v1.x(), v1.y(), v1.z() - 5.0); - glVertex3f(v1.x(), v1.y(), v1.z() + 5.0); - - glEnd(); - } - } - } - } - } - - /*if (is_loop_closure_gui) - { - session.manual_pose_graph_loop_closure.Render(session.point_clouds_container, index_loop_closure_source, index_loop_closure_target); - } - else - { - for (const auto &g : available_geo_points) - { - glBegin(GL_LINES); - glColor3f(1.0f, 0.0f, 0.0f); - auto c = g.coordinates - session.point_clouds_container.offset; - glVertex3f(c.x() - 0.5, c.y(), c.z()); - glVertex3f(c.x() + 0.5, c.y(), c.z()); - - glVertex3f(c.x(), c.y() - 0.5, c.z()); - glVertex3f(c.x(), c.y() + 0.5, c.z()); - - glVertex3f(c.x(), c.y(), c.z() - 0.5); - glVertex3f(c.x(), c.y(), c.z() + 0.5); - glEnd(); - } - - // - for (const auto &pc : session.point_clouds_container.point_clouds) - { - for (const auto &gp : pc.available_geo_points) - { - if (gp.choosen) - { - auto c = pc.m_pose * gp.coordinates; - glBegin(GL_LINES); - glColor3f(1.0f, 0.0f, 0.0f); - glVertex3f(c.x() - 0.5, c.y(), c.z()); - glVertex3f(c.x() + 0.5, c.y(), c.z()); - - glVertex3f(c.x(), c.y() - 0.5, c.z()); - glVertex3f(c.x(), c.y() + 0.5, c.z()); - - glVertex3f(c.x(), c.y(), c.z() - 0.5); - glVertex3f(c.x(), c.y(), c.z() + 0.5); - glEnd(); - - glBegin(GL_LINES); - glColor3f(0.0f, 1.0f, 0.0f); - glVertex3f(c.x(), c.y(), c.z()); - glVertex3f(gp.coordinates.x(), gp.coordinates.y(), gp.coordinates.z()); - glEnd(); - - glColor3f(0.0f, 0.0f, 0.0f); - glBegin(GL_LINES); - glVertex3f(c.x(), c.y(), c.z()); - glVertex3f(c.x() + 10, c.y(), c.z()); - glEnd(); - - glRasterPos3f(c.x() + 10, c.y(), c.z()); - glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char *)gp.name.c_str()); - } - } - } - }*/ - - // gnss.render(session.point_clouds_container); - - ImGui_ImplOpenGL2_NewFrame(); - ImGui_ImplGLUT_NewFrame(); - ImGui::NewFrame(); - - ShowMainDockSpace(); - - if (!is_loop_closure_gui) - { - Eigen::Affine3d prev_pose_manipulated = Eigen::Affine3d::Identity(); - Eigen::Affine3d prev_pose_after_gismo = Eigen::Affine3d::Identity(); - - for (size_t i = 0; i < sessions.size(); i++) - { - // guizmo_all_sessions; - if (sessions[i].is_gizmo && !sessions[i].is_ground_truth) - { - if (sessions[i].point_clouds_container.point_clouds.size() > 0) - { - prev_pose_manipulated = sessions[i].point_clouds_container.point_clouds[0].m_pose; - std::vector all_m_poses; - for (size_t 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); - - ImGuiIO& io = ImGui::GetIO(); - - ImGuizmo::BeginFrame(); - ImGuizmo::Enable(true); - ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y); - - if (!is_ortho) - { - GLfloat projection[16]; - glGetFloatv(GL_PROJECTION_MATRIX, projection); - - GLfloat modelview[16]; - glGetFloatv(GL_MODELVIEW_MATRIX, modelview); - - ImGuizmo::Manipulate( - modelview, - projection, - 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); - - sessions[i].point_clouds_container.point_clouds[0].m_pose = Eigen::Map(m_gizmo).cast(); - prev_pose_after_gismo = sessions[i].point_clouds_container.point_clouds[0].m_pose; - sessions[i].point_clouds_container.point_clouds[0].pose = - pose_tait_bryan_from_affine_matrix(sessions[i].point_clouds_container.point_clouds[0].m_pose); - - sessions[i].point_clouds_container.point_clouds[0].gui_translation[0] = - (float)sessions[i].point_clouds_container.point_clouds[0].pose.px; - sessions[i].point_clouds_container.point_clouds[0].gui_translation[1] = - (float)sessions[i].point_clouds_container.point_clouds[0].pose.py; - sessions[i].point_clouds_container.point_clouds[0].gui_translation[2] = - (float)sessions[i].point_clouds_container.point_clouds[0].pose.pz; - - sessions[i].point_clouds_container.point_clouds[0].gui_rotation[0] = - (float)(sessions[i].point_clouds_container.point_clouds[0].pose.om * RAD_TO_DEG); - 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); - - Eigen::Affine3d curr_m_pose = sessions[i].point_clouds_container.point_clouds[0].m_pose; - for (size_t j = 1; j < sessions[i].point_clouds_container.point_clouds.size(); j++) - { - curr_m_pose = curr_m_pose * (all_m_poses[j - 1].inverse() * all_m_poses[j]); - sessions[i].point_clouds_container.point_clouds[j].m_pose = curr_m_pose; - sessions[i].point_clouds_container.point_clouds[j].pose = - pose_tait_bryan_from_affine_matrix(sessions[i].point_clouds_container.point_clouds[j].m_pose); - - sessions[i].point_clouds_container.point_clouds[j].gui_translation[0] = - (float)sessions[i].point_clouds_container.point_clouds[j].pose.px; - sessions[i].point_clouds_container.point_clouds[j].gui_translation[1] = - (float)sessions[i].point_clouds_container.point_clouds[j].pose.py; - sessions[i].point_clouds_container.point_clouds[j].gui_translation[2] = - (float)sessions[i].point_clouds_container.point_clouds[j].pose.pz; - - sessions[i].point_clouds_container.point_clouds[j].gui_rotation[0] = - (float)(sessions[i].point_clouds_container.point_clouds[j].pose.om * RAD_TO_DEG); - sessions[i].point_clouds_container.point_clouds[j].gui_rotation[1] = - (float)(sessions[i].point_clouds_container.point_clouds[j].pose.fi * RAD_TO_DEG); - sessions[i].point_clouds_container.point_clouds[j].gui_rotation[2] = - (float)(sessions[i].point_clouds_container.point_clouds[j].pose.ka * RAD_TO_DEG); - } - //} - } - } - } - if (gizmo_all_sessions) - { - for (size_t i = 0; i < sessions.size(); i++) - { - // guizmo_all_sessions; - if (!sessions[i].is_gizmo && !sessions[i].is_ground_truth) - { - std::vector all_m_poses; - for (size_t 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); - - Eigen::Affine3d m_rel_org = prev_pose_manipulated.inverse() * sessions[i].point_clouds_container.point_clouds[0].m_pose; - - Eigen::Affine3d m_new = prev_pose_after_gismo * m_rel_org; - - sessions[i].point_clouds_container.point_clouds[0].m_pose = m_new; - sessions[i].point_clouds_container.point_clouds[0].pose = - pose_tait_bryan_from_affine_matrix(sessions[i].point_clouds_container.point_clouds[0].m_pose); - - sessions[i].point_clouds_container.point_clouds[i].gui_translation[0] = - (float)sessions[i].point_clouds_container.point_clouds[0].pose.px; - sessions[i].point_clouds_container.point_clouds[i].gui_translation[1] = - (float)sessions[i].point_clouds_container.point_clouds[0].pose.py; - sessions[i].point_clouds_container.point_clouds[i].gui_translation[2] = - (float)sessions[i].point_clouds_container.point_clouds[0].pose.pz; - - sessions[i].point_clouds_container.point_clouds[i].gui_rotation[0] = - (float)(sessions[i].point_clouds_container.point_clouds[0].pose.om * RAD_TO_DEG); - sessions[i].point_clouds_container.point_clouds[i].gui_rotation[1] = - (float)(sessions[i].point_clouds_container.point_clouds[0].pose.fi * RAD_TO_DEG); - sessions[i].point_clouds_container.point_clouds[i].gui_rotation[2] = - (float)(sessions[i].point_clouds_container.point_clouds[0].pose.ka * RAD_TO_DEG); - - Eigen::Affine3d curr_m_pose = sessions[i].point_clouds_container.point_clouds[0].m_pose; - for (size_t j = 1; j < sessions[i].point_clouds_container.point_clouds.size(); j++) - { - curr_m_pose = curr_m_pose * (all_m_poses[j - 1].inverse() * all_m_poses[j]); - sessions[i].point_clouds_container.point_clouds[j].m_pose = curr_m_pose; - sessions[i].point_clouds_container.point_clouds[j].pose = - pose_tait_bryan_from_affine_matrix(sessions[i].point_clouds_container.point_clouds[j].m_pose); - - sessions[i].point_clouds_container.point_clouds[j].gui_translation[0] = - (float)sessions[i].point_clouds_container.point_clouds[j].pose.px; - sessions[i].point_clouds_container.point_clouds[j].gui_translation[1] = - (float)sessions[i].point_clouds_container.point_clouds[j].pose.py; - sessions[i].point_clouds_container.point_clouds[j].gui_translation[2] = - (float)sessions[i].point_clouds_container.point_clouds[j].pose.pz; - - sessions[i].point_clouds_container.point_clouds[j].gui_rotation[0] = - (float)(sessions[i].point_clouds_container.point_clouds[j].pose.om * RAD_TO_DEG); - sessions[i].point_clouds_container.point_clouds[j].gui_rotation[1] = - (float)(sessions[i].point_clouds_container.point_clouds[j].pose.fi * RAD_TO_DEG); - sessions[i].point_clouds_container.point_clouds[j].gui_rotation[2] = - (float)(sessions[i].point_clouds_container.point_clouds[j].pose.ka * RAD_TO_DEG); - } - } - } - } - } - else - { - // ImGuizmo ----------------------------------------------- - if (edge_gizmo && edges.size() > 0) - { - ImGuizmo::BeginFrame(); - ImGuizmo::Enable(true); - ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y); - - if (!is_ortho) - { - GLfloat projection[16]; - glGetFloatv(GL_PROJECTION_MATRIX, projection); - - GLfloat modelview[16]; - glGetFloatv(GL_MODELVIEW_MATRIX, modelview); - - 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(); - - m_g.matrix() = Eigen::Map(m_gizmo).cast(); - - const int& index_src = edges[index_active_edge].index_from; - - 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); - } - } - - /*if (!is_loop_closure_gui) -{ - for (size_t i = 0; i < session.point_clouds_container.point_clouds.size(); i++) - { - if (session.point_clouds_container.point_clouds[i].gizmo) - { - std::vector all_m_poses; - for (size_t j = 0; j < session.point_clouds_container.point_clouds.size(); j++) - all_m_poses.push_back(session.point_clouds_container.point_clouds[j].m_pose); - - ImGuiIO &io = ImGui::GetIO(); - // ImGuizmo ----------------------------------------------- - ImGuizmo::BeginFrame(); - ImGuizmo::Enable(true); - ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y); - - if (!is_ortho) - { - GLfloat projection[16]; - glGetFloatv(GL_PROJECTION_MATRIX, projection); - - GLfloat modelview[16]; - glGetFloatv(GL_MODELVIEW_MATRIX, modelview); - - 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); - - session.point_clouds_container.point_clouds[i].m_pose(0, 0) = m_gizmo[0]; - session.point_clouds_container.point_clouds[i].m_pose(1, 0) = m_gizmo[1]; - session.point_clouds_container.point_clouds[i].m_pose(2, 0) = m_gizmo[2]; - session.point_clouds_container.point_clouds[i].m_pose(3, 0) = m_gizmo[3]; - session.point_clouds_container.point_clouds[i].m_pose(0, 1) = m_gizmo[4]; - session.point_clouds_container.point_clouds[i].m_pose(1, 1) = m_gizmo[5]; - session.point_clouds_container.point_clouds[i].m_pose(2, 1) = m_gizmo[6]; - session.point_clouds_container.point_clouds[i].m_pose(3, 1) = m_gizmo[7]; - session.point_clouds_container.point_clouds[i].m_pose(0, 2) = m_gizmo[8]; - session.point_clouds_container.point_clouds[i].m_pose(1, 2) = m_gizmo[9]; - session.point_clouds_container.point_clouds[i].m_pose(2, 2) = m_gizmo[10]; - session.point_clouds_container.point_clouds[i].m_pose(3, 2) = m_gizmo[11]; - session.point_clouds_container.point_clouds[i].m_pose(0, 3) = m_gizmo[12]; - session.point_clouds_container.point_clouds[i].m_pose(1, 3) = m_gizmo[13]; - session.point_clouds_container.point_clouds[i].m_pose(2, 3) = m_gizmo[14]; - session.point_clouds_container.point_clouds[i].m_pose(3, 3) = m_gizmo[15]; - session.point_clouds_container.point_clouds[i].pose = -pose_tait_bryan_from_affine_matrix(session.point_clouds_container.point_clouds[i].m_pose); - - session.point_clouds_container.point_clouds[i].gui_translation[0] = -(float)session.point_clouds_container.point_clouds[i].pose.px; session.point_clouds_container.point_clouds[i].gui_translation[1] = -(float)session.point_clouds_container.point_clouds[i].pose.py; session.point_clouds_container.point_clouds[i].gui_translation[2] = -(float)session.point_clouds_container.point_clouds[i].pose.pz; - - session.point_clouds_container.point_clouds[i].gui_rotation[0] = (float)(session.point_clouds_container.point_clouds[i].pose.om -* RAD_TO_DEG); 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); - - if (!manipulate_only_marked_gizmo) - { - Eigen::Affine3d curr_m_pose = session.point_clouds_container.point_clouds[i].m_pose; - for (size_t j = i + 1; j < session.point_clouds_container.point_clouds.size(); j++) - { - curr_m_pose = curr_m_pose * (all_m_poses[j - 1].inverse() * all_m_poses[j]); - session.point_clouds_container.point_clouds[j].m_pose = curr_m_pose; - session.point_clouds_container.point_clouds[j].pose = -pose_tait_bryan_from_affine_matrix(session.point_clouds_container.point_clouds[j].m_pose); - - session.point_clouds_container.point_clouds[j].gui_translation[0] = -(float)session.point_clouds_container.point_clouds[j].pose.px; session.point_clouds_container.point_clouds[j].gui_translation[1] = -(float)session.point_clouds_container.point_clouds[j].pose.py; session.point_clouds_container.point_clouds[j].gui_translation[2] = -(float)session.point_clouds_container.point_clouds[j].pose.pz; - - session.point_clouds_container.point_clouds[j].gui_rotation[0] = -(float)(session.point_clouds_container.point_clouds[j].pose.om * RAD_TO_DEG); session.point_clouds_container.point_clouds[j].gui_rotation[1] -= (float)(session.point_clouds_container.point_clouds[j].pose.fi * RAD_TO_DEG); - session.point_clouds_container.point_clouds[j].gui_rotation[2] = -(float)(session.point_clouds_container.point_clouds[j].pose.ka * RAD_TO_DEG); - } - } - } - } - - session.point_clouds_container.render(observation_picking, viewer_decmiate_point_cloud); - observation_picking.render(); - - glPushAttrib(GL_ALL_ATTRIB_BITS); - glPointSize(5); - for (const auto &obs : observation_picking.observations) - { - for (const auto &[key1, value1] : obs) - { - for (const auto &[key2, value2] : obs) - { - if (key1 != key2) - { - Eigen::Vector3d p1, p2; - if (session.point_clouds_container.show_with_initial_pose) - { - p1 = session.point_clouds_container.point_clouds[key1].m_initial_pose * value1; - p2 = session.point_clouds_container.point_clouds[key2].m_initial_pose * value2; - } - else - { - p1 = session.point_clouds_container.point_clouds[key1].m_pose * value1; - p2 = session.point_clouds_container.point_clouds[key2].m_pose * value2; - } - glColor3f(0, 1, 0); - glBegin(GL_POINTS); - glVertex3f(p1.x(), p1.y(), p1.z()); - glVertex3f(p2.x(), p2.y(), p2.z()); - glEnd(); - glColor3f(1, 0, 0); - glBegin(GL_LINES); - glVertex3f(p1.x(), p1.y(), p1.z()); - glVertex3f(p2.x(), p2.y(), p2.z()); - glEnd(); - } - } - } - } - glPopAttrib(); - - for (const auto &obs : observation_picking.observations) - { - Eigen::Vector3d mean(0, 0, 0); - int counter = 0; - for (const auto &[key1, value1] : obs) - { - mean += session.point_clouds_container.point_clouds[key1].m_initial_pose * value1; - counter++; - } - if (counter > 0) - { - mean /= counter; - - glColor3f(1, 0, 0); - glBegin(GL_LINE_STRIP); - glVertex3f(mean.x() - 1, mean.y() - 1, mean.z()); - glVertex3f(mean.x() + 1, mean.y() - 1, mean.z()); - glVertex3f(mean.x() + 1, mean.y() + 1, mean.z()); - glVertex3f(mean.x() - 1, mean.y() + 1, mean.z()); - glVertex3f(mean.x() - 1, mean.y() - 1, mean.z()); - glEnd();F - } - } - - glColor3f(1, 0, 1); - glBegin(GL_POINTS); - for (auto p : picked_points) - { - glVertex3f(p.x(), p.y(), p.z()); - } - glEnd(); -} -else -{ - // ImGuizmo ----------------------------------------------- - if (session.manual_pose_graph_loop_closure.gizmo && session.manual_pose_graph_loop_closure.edges.size() > 0) - { - ImGuizmo::BeginFrame(); - ImGuizmo::Enable(true); - ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y); - - if (!is_ortho) - { - GLfloat projection[16]; - glGetFloatv(GL_PROJECTION_MATRIX, projection); - - GLfloat modelview[16]; - glGetFloatv(GL_MODELVIEW_MATRIX, modelview); - - 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(); - - m_g(0, 0) = m_gizmo[0]; - m_g(1, 0) = m_gizmo[1]; - m_g(2, 0) = m_gizmo[2]; - m_g(3, 0) = m_gizmo[3]; - m_g(0, 1) = m_gizmo[4]; - m_g(1, 1) = m_gizmo[5]; - m_g(2, 1) = m_gizmo[6]; - m_g(3, 1) = m_gizmo[7]; - m_g(0, 2) = m_gizmo[8]; - m_g(1, 2) = m_gizmo[9]; - m_g(2, 2) = m_gizmo[10]; - m_g(3, 2) = m_gizmo[11]; - m_g(0, 3) = m_gizmo[12]; - m_g(1, 3) = m_gizmo[13]; - m_g(2, 3) = m_gizmo[14]; - m_g(3, 3) = m_gizmo[15]; - - const int &index_src = -session.manual_pose_graph_loop_closure.edges[session.manual_pose_graph_loop_closure.index_active_edge].index_from; - - 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); - } -}*/ - - 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()) - { - if (ImGui::BeginMenu("File")) - { - if (ImGui::MenuItem("Open project", "Ctrl+O")) - openProject(); - if (ImGui::MenuItem("Save project", "Ctrl+S", nullptr, project_settings.session_file_names.size() > 0)) - saveProject(); - - ImGui::Separator(); - - if (ImGui::MenuItem("Add session(s)", "Ctrl+A")) - addSession(); - if (ImGui::MenuItem("Remove session(s)", "Ctrl+R", nullptr, project_settings.session_file_names.size() > 0)) - remove_gui = true; - - if (ImGui::MenuItem("Load sessions", "Ctrl+L", nullptr, (project_settings.session_file_names.size() > 0) && !loaded_sessions)) - loadSessions(); - - ImGui::Separator(); - - if (ImGui::BeginMenu("Save all marked trajectories", sessions.size() > 0)) - { - if (ImGui::MenuItem("Save all as las/laz files")) - { - for (size_t i = 0; i < project_settings.session_file_names.size(); ++i) - { - const auto& session_path = project_settings.session_file_names[i]; - - if (i >= sessions.size()) - { - std::cerr << "No loaded session for: " << session_path << std::endl; - continue; - } - - Session& session = sessions[i]; - - std::filesystem::path dir = std::filesystem::path(session_path).parent_path(); - std::string folder_name = dir.filename().string(); - std::string laz_path = (dir / (folder_name + "_trajectory_laz.laz")).string(); - - std::cout << "Saving trajectory to LAZ: " << laz_path << std::endl; - - save_trajectories_to_laz(session, laz_path, 0.0f, 0.0f, false); - } - - std::cout << "Finished saving all trajectories to .laz files." << std::endl; - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("As one global scan"); - - ImGui::Separator(); - - ImGui::Text("(x,y,z,r00,r01,r02,r10,r11,r12,r20,r21,r22)"); - if (ImGui::MenuItem("Save all as csv (timestamp Lidar)##1")) - { - for (size_t i = 0; i < project_settings.session_file_names.size(); ++i) - { - const auto& session_path = project_settings.session_file_names[i]; - - if (i >= sessions.size()) - { - std::cerr << "No loaded session for: " << session_path << std::endl; - continue; - } - - Session& session = sessions[i]; - std::filesystem::path dir = std::filesystem::path(session_path).parent_path(); - std::string folder_name = dir.filename().string(); - std::string csv_path = (dir / (folder_name + "_trajectory_timestampLidar_r.csv")).string(); - - std::cout << "Saving trajectory to CSV: " << csv_path << std::endl; - - try - { - std::ofstream outfile(csv_path); - if (!outfile.is_open()) - { - std::cerr << "Failed to create file: " << csv_path << std::endl; - continue; - } - - outfile << "timestampLidar,x,y,z," << "r00,r01,r02," << "r10,r11,r12," << "r20,r21,r22\n"; - - for (const auto& pc : session.point_clouds_container.point_clouds) - { - if (!pc.visible) - continue; - - for (const auto& traj : pc.local_trajectory) - { - Eigen::Affine3d pose = pc.m_pose * traj.m_pose; - Eigen::Vector3d pos = pose.translation(); - Eigen::Matrix3d rot = pose.rotation(); - - outfile << std::fixed << std::setprecision(0) << traj.timestamps.first << "," << std::setprecision(10) - << pos.x() << "," << pos.y() << "," << pos.z() << "," << rot(0, 0) << "," << rot(0, 1) << "," - << rot(0, 2) << "," << rot(1, 0) << "," << rot(1, 1) << "," << rot(1, 2) << "," << rot(2, 0) - << "," << rot(2, 1) << "," << rot(2, 2) << "\n"; - } - } - - outfile.close(); - std::cout << "Saved: " << csv_path << std::endl; - } catch (const std::exception& e) - { - std::cerr << "Error creating " << csv_path << ": " << e.what() << std::endl; - } - } - - std::cout << "Finished saving all trajectories to CSV files." << std::endl; - } - if (ImGui::MenuItem("Save all as csv (timestamp Unix)##1")) - { - for (size_t i = 0; i < project_settings.session_file_names.size(); ++i) - { - const auto& session_path = project_settings.session_file_names[i]; - if (i >= sessions.size()) - { - std::cerr << "No loaded session for: " << session_path << std::endl; - continue; - } - - Session& session = sessions[i]; - std::filesystem::path dir = std::filesystem::path(session_path).parent_path(); - std::string folder_name = dir.filename().string(); - std::string csv_path = (dir / (folder_name + "_trajectory_timestampUnix_r.csv")).string(); - - try - { - std::ofstream outfile(csv_path); - if (!outfile.is_open()) - { - std::cerr << "Failed to create file: " << csv_path << std::endl; - continue; - } - - outfile << "timestampUnix,x,y,z," << "r00,r01,r02,r10,r11,r12,r20,r21,r22\n"; - - for (const auto& pc : session.point_clouds_container.point_clouds) - { - if (!pc.visible) - continue; - for (const auto& traj : pc.local_trajectory) - { - Eigen::Affine3d pose = pc.m_pose * traj.m_pose; - Eigen::Vector3d pos = pose.translation(); - Eigen::Matrix3d rot = pose.rotation(); - outfile << std::fixed << std::setprecision(0) << traj.timestamps.second << "," // Unix timestamp - << std::setprecision(10) << pos.x() << "," << pos.y() << "," << pos.z() << "," << rot(0, 0) - << "," << rot(0, 1) << "," << rot(0, 2) << "," << rot(1, 0) << "," << rot(1, 1) << "," - << rot(1, 2) << "," << rot(2, 0) << "," << rot(2, 1) << "," << rot(2, 2) << "\n"; - } - } - - outfile.close(); - std::cout << "Saved: " << csv_path << std::endl; - } catch (const std::exception& e) - { - std::cerr << "Error creating " << csv_path << ": " << e.what() << std::endl; - } - } - } - if (ImGui::MenuItem("Save all as csv (timestamp Lidar, Unix)##1")) - { - for (size_t i = 0; i < project_settings.session_file_names.size(); ++i) - { - const auto& session_path = project_settings.session_file_names[i]; - if (i >= sessions.size()) - { - std::cerr << "No loaded session for: " << session_path << std::endl; - continue; - } - - Session& session = sessions[i]; - std::filesystem::path dir = std::filesystem::path(session_path).parent_path(); - std::string folder_name = dir.filename().string(); - std::string csv_path = (dir / (folder_name + "_trajectory_timestampLidarUnix_r.csv")).string(); - - try - { - std::ofstream outfile(csv_path); - if (!outfile.is_open()) - { - std::cerr << "Failed to create file: " << csv_path << std::endl; - continue; - } - - outfile << "timestampLidar,timestampUnix,x,y,z," << "r00,r01,r02,r10,r11,r12,r20,r21,r22\n"; - - for (const auto& pc : session.point_clouds_container.point_clouds) - { - if (!pc.visible) - continue; - for (const auto& traj : pc.local_trajectory) - { - Eigen::Affine3d pose = pc.m_pose * traj.m_pose; - Eigen::Vector3d pos = pose.translation(); - Eigen::Matrix3d rot = pose.rotation(); - outfile << std::fixed << std::setprecision(0) << traj.timestamps.first << "," // Lidar timestamp - << traj.timestamps.second << "," // Unix timestamp - << std::setprecision(10) << pos.x() << "," << pos.y() << "," << pos.z() << "," << rot(0, 0) - << "," << rot(0, 1) << "," << rot(0, 2) << "," << rot(1, 0) << "," << rot(1, 1) << "," - << rot(1, 2) << "," << rot(2, 0) << "," << rot(2, 1) << "," << rot(2, 2) << "\n"; - } - } - - outfile.close(); - std::cout << "Saved: " << csv_path << std::endl; - } catch (const std::exception& e) - { - std::cerr << "Error creating " << csv_path << ": " << e.what() << std::endl; - } - } - } - - ImGui::Separator(); - ImGui::Text("(x,y,z,qx,qy,qz,qw)"); - - if (ImGui::MenuItem("Save all as csv (timestamp Lidar)##2")) - { - for (size_t i = 0; i < project_settings.session_file_names.size(); ++i) - { - const auto& session_path = project_settings.session_file_names[i]; - - if (i >= sessions.size()) - { - std::cerr << "No loaded session for: " << session_path << std::endl; - continue; - } - - Session& session = sessions[i]; - std::filesystem::path dir = std::filesystem::path(session_path).parent_path(); - std::string folder_name = dir.filename().string(); - std::string csv_path = (dir / (folder_name + "_trajectory_timestampLidar_q.csv")).string(); - - std::cout << "Saving trajectory to CSV: " << csv_path << std::endl; - - try - { - std::ofstream outfile(csv_path); - if (!outfile.is_open()) - { - std::cerr << "Failed to create file: " << csv_path << std::endl; - continue; - } - - outfile << "timestampLidar,x,y,z,qx,qy,qz,qw\n"; - - for (const auto& pc : session.point_clouds_container.point_clouds) - { - if (!pc.visible) - continue; - - for (const auto& traj : pc.local_trajectory) - { - Eigen::Affine3d pose = pc.m_pose * traj.m_pose; - Eigen::Vector3d pos = pose.translation(); - Eigen::Quaterniond q(pose.rotation()); - - outfile << std::fixed << std::setprecision(0) << traj.timestamps.first << "," // Lidar timestamp - << std::setprecision(10) << pos.x() << "," << pos.y() << "," << pos.z() << "," << q.x() << "," - << q.y() << "," << q.z() << "," << q.w() << "\n"; - } - } - - outfile.close(); - std::cout << "Saved: " << csv_path << std::endl; - } catch (const std::exception& e) - { - std::cerr << "Error creating " << csv_path << ": " << e.what() << std::endl; - } - } - - std::cout << "Finished saving all trajectories to CSV files." << std::endl; - } - if (ImGui::MenuItem("Save all as csv (timestamp Unix)##2")) - { - for (size_t i = 0; i < project_settings.session_file_names.size(); ++i) - { - const auto& session_path = project_settings.session_file_names[i]; - - if (i >= sessions.size()) - { - std::cerr << "No loaded session for: " << session_path << std::endl; - continue; - } - - Session& session = sessions[i]; - std::filesystem::path dir = std::filesystem::path(session_path).parent_path(); - std::string folder_name = dir.filename().string(); - std::string csv_path = (dir / (folder_name + "_trajectory_timestampUnix_q.csv")).string(); - - std::cout << "Saving trajectory to CSV: " << csv_path << std::endl; - - try - { - std::ofstream outfile(csv_path); - if (!outfile.is_open()) - { - std::cerr << "Failed to create file: " << csv_path << std::endl; - continue; - } - - outfile << "timestampUnix,x,y,z,qx,qy,qz,qw\n"; - - for (const auto& pc : session.point_clouds_container.point_clouds) - { - if (!pc.visible) - continue; - - for (const auto& traj : pc.local_trajectory) - { - Eigen::Affine3d pose = pc.m_pose * traj.m_pose; - Eigen::Vector3d pos = pose.translation(); - Eigen::Quaterniond q(pose.rotation()); - - outfile << std::fixed << std::setprecision(0) << traj.timestamps.second << "," // Unix timestamp - << std::setprecision(10) << pos.x() << "," << pos.y() << "," << pos.z() << "," << q.x() << "," - << q.y() << "," << q.z() << "," << q.w() << "\n"; - } - } - - outfile.close(); - std::cout << "Saved: " << csv_path << std::endl; - } catch (const std::exception& e) - { - std::cerr << "Error creating " << csv_path << ": " << e.what() << std::endl; - } - } - - std::cout << "Finished saving all trajectories to CSV files." << std::endl; - } - if (ImGui::MenuItem("Save all as csv (timestamp Lidar, Unix)##2")) - { - for (size_t i = 0; i < project_settings.session_file_names.size(); ++i) - { - const auto& session_path = project_settings.session_file_names[i]; - - if (i >= sessions.size()) - { - std::cerr << "No loaded session for: " << session_path << std::endl; - continue; - } - - Session& session = sessions[i]; - std::filesystem::path dir = std::filesystem::path(session_path).parent_path(); - std::string folder_name = dir.filename().string(); - std::string csv_path = (dir / (folder_name + "_trajectory_timestampLidarUnix_q.csv")).string(); - - std::cout << "Saving trajectory to CSV: " << csv_path << std::endl; - - try - { - std::ofstream outfile(csv_path); - if (!outfile.is_open()) - { - std::cerr << "Failed to create file: " << csv_path << std::endl; - continue; - } - - outfile << "timestampLidar,timestampUnix,x,y,z,qx,qy,qz,qw\n"; - - for (const auto& pc : session.point_clouds_container.point_clouds) - { - if (!pc.visible) - continue; - - for (const auto& traj : pc.local_trajectory) - { - Eigen::Affine3d pose = pc.m_pose * traj.m_pose; - Eigen::Vector3d pos = pose.translation(); - Eigen::Quaterniond q(pose.rotation()); - - outfile << std::fixed << std::setprecision(0) << traj.timestamps.first << "," // Lidar timestamp - << traj.timestamps.second << "," // Unix timestamp - << std::setprecision(10) << pos.x() << "," << pos.y() << "," << pos.z() << "," << q.x() << "," - << q.y() << "," << q.z() << "," << q.w() << "\n"; - } - } - - outfile.close(); - std::cout << "Saved: " << csv_path << std::endl; - } catch (const std::exception& e) - { - std::cerr << "Error creating " << csv_path << ": " << e.what() << std::endl; - } - } - - std::cout << "Finished saving all trajectories to CSV files." << std::endl; - } - if (ImGui::MenuItem("Save all as TUM TXT")) - { - for (size_t i = 0; i < project_settings.session_file_names.size(); ++i) - { - const auto& session_path = project_settings.session_file_names[i]; - if (i >= sessions.size()) - { - std::cerr << "No loaded session for: " << session_path << std::endl; - continue; - } - Session& session = sessions[i]; - std::filesystem::path dir = std::filesystem::path(session_path).parent_path(); - std::string folder_name = dir.filename().string(); - std::string txt_path = (dir / (folder_name + "_trajectory_tum.txt")).string(); - - std::cout << "Saving trajectory to TUM TXT: " << txt_path << std::endl; - try - { - std::ofstream outfile(txt_path); - if (!outfile.is_open()) - { - std::cerr << "Failed to create file: " << txt_path << std::endl; - continue; - } - - for (const auto& pc : session.point_clouds_container.point_clouds) - { - if (!pc.visible) - continue; - for (const auto& traj : pc.local_trajectory) - { - Eigen::Affine3d pose = pc.m_pose * traj.m_pose; - Eigen::Vector3d pos = pose.translation(); - Eigen::Quaterniond q(pose.rotation()); - - double t_s = static_cast(traj.timestamps.first) / 1e9; - - outfile << std::fixed << std::setprecision(9) << t_s << " " << std::setprecision(10) << pos.x() << " " - << pos.y() << " " << pos.z() << " " << q.x() << " " << q.y() << " " << q.z() << " " << q.w() - << "\n"; - } - } - - outfile.close(); - std::cout << "Saved: " << txt_path << std::endl; - } catch (const std::exception& e) - { - std::cerr << "Error creating " << txt_path << ": " << e.what() << std::endl; - } - } - std::cout << "Finished saving all trajectories to TUM TXT files." << std::endl; - } - if (ImGui::MenuItem("Save all as TUM TXT (single folder)")) - { - for (size_t i = 0; i < project_settings.session_file_names.size(); ++i) - { - const auto& session_path = project_settings.session_file_names[i]; - - if (i >= sessions.size()) - { - std::cerr << "No loaded session for: " << session_path << std::endl; - continue; - } - - Session& session = sessions[i]; - - std::filesystem::path session_dir = std::filesystem::path(session_path).parent_path(); - - std::filesystem::path base_dir = session_dir.parent_path(); - - std::filesystem::path output_dir = base_dir / "all_tum_files"; - - try - { - std::filesystem::create_directories(output_dir); - } catch (const std::exception& e) - { - std::cerr << "Failed to create export directory: " << e.what() << std::endl; - continue; - } - - std::string folder_name = session_dir.filename().string(); - - std::filesystem::path txt_path = output_dir / (folder_name + "_trajectory_tum.txt"); - - std::cout << "Saving trajectory to TUM TXT: " << txt_path << std::endl; - - try - { - std::ofstream outfile(txt_path); - - if (!outfile.is_open()) - { - std::cerr << "Failed to create file: " << txt_path << std::endl; - continue; - } - - for (const auto& pc : session.point_clouds_container.point_clouds) - { - if (!pc.visible) - continue; - - for (const auto& traj : pc.local_trajectory) - { - Eigen::Affine3d pose = pc.m_pose * traj.m_pose; - - Eigen::Vector3d pos = pose.translation(); - - Eigen::Quaterniond q(pose.rotation()); - - double t_s = static_cast(traj.timestamps.first) / 1e9; - - outfile << std::fixed << std::setprecision(9) << t_s << " " << std::setprecision(10) << pos.x() << " " - << pos.y() << " " << pos.z() << " " << q.x() << " " << q.y() << " " << q.z() << " " << q.w() - << "\n"; - } - } - - outfile.close(); - - std::cout << "Saved: " << txt_path << std::endl; - } catch (const std::exception& e) - { - std::cerr << "Error creating " << txt_path << ": " << e.what() << std::endl; - } - } - std::cout << "Finished saving all trajectories to single folder." << std::endl; - } - - ImGui::EndMenu(); - } - - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("Tools")) - { - ImGui::MenuItem("Normal Distributions Transform", nullptr, &is_ndt_gui, !is_loop_closure_gui && (sessions.size() > 0)); - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text("Point cloud alignment (registration) algorithm"); - ImGui::Text( - "Probabilistic alternative to ICP that models one cloud (the target)\nas a set of Gaussian distributions " - "rather than raw points"); - ImGui::Text( - "Robust for rough initial poses but can converge to a local optimum\nif the initial misalignment is very large"); - ImGui::Text( - "Known for being faster and smoother in optimization because\nit replaces discrete point-point correspondences " - "with continuous probability density functions."); - ImGui::EndTooltip(); - } - - // bool prev_is_loop_closure_gui - ImGui::MenuItem( - "Manual Loop Closure", "Ctrl+L", &is_loop_closure_gui, (number_visible_sessions == 1 || number_visible_sessions == 2)); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Manually connect overlapping scan sections"); - - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("View")) - { - ImGui::BeginDisabled(!(sessions.size() > 0)); - { - auto tmp = point_size; - ImGui::SetNextItemWidth(ImGuiNumberWidth); - ImGui::InputInt("Points size", &point_size); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("keyboard 1-9 keys"); - if (point_size < 1) - point_size = 1; - else if (point_size > 10) - point_size = 10; - - if (tmp != point_size) - for (auto& session : sessions) - for (auto& point_cloud : session.point_clouds_container.point_clouds) - point_cloud.point_size = point_size; - - ImGui::Separator(); - } - ImGui::EndDisabled(); - - if (ImGui::MenuItem("Orthographic", "key O", &is_ortho)) - { - 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)"); - - ImGui::MenuItem("Show axes", "key X", &show_axes); - ImGui::MenuItem("Show compass/ruler", "key C", &compass_ruler); - - ImGui::MenuItem("Lock Z", "Shift + Z", &lock_z, !is_ortho); - - // ImGui::MenuItem("show_covs", nullptr, &show_covs); - - ImGui::Separator(); - - ImGui::Text("Colors:"); - - ImGui::ColorEdit3("Background", (float*)&bg_color, ImGuiColorEditFlags_NoInputs); - - ImGui::Separator(); - - ImGui::MenuItem("Settings", nullptr, &is_settings_gui); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Show power user settings window with more parameters"); - - ImGui::EndMenu(); - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Scene view relevant parameters"); - - camMenu(); - - ImGui::BeginDisabled(sessions.size() <= 0); - { - ImGui::SameLine(); - ImGui::Dummy(ImVec2(20, 0)); - ImGui::SameLine(); - - ImGui::SetNextItemWidth(ImGuiNumberWidth); - ImGui::InputInt("Points render downsampling", &viewer_decimate_point_cloud, 10, 100); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("increase for better performance, decrease for rendering more points"); - // ImGui::SameLine(); - - if (viewer_decimate_point_cloud < 1) - viewer_decimate_point_cloud = 1; - - ImGui::SameLine(); - - ImGui::InputInt("Trajectory reduce render", &viewer_reduce_rendered_trajectory, 10, 100); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("increase for better performance, decrease for rendering more nodes in the trajectory"); - // ImGui::SameLine(); - - if (viewer_reduce_rendered_trajectory < 1) - viewer_reduce_rendered_trajectory = 1; - - ImGui::SameLine(); - - ImGui::Text("(%.1f FPS)", ImGui::GetIO().Framerate); - } - ImGui::EndDisabled(); - - ImGui::SameLine(); - ImGui::Dummy(ImVec2(20, 0)); - ImGui::SameLine(); - - ImGui::SameLine( - ImGui::GetWindowWidth() - ImGui::CalcTextSize("Info").x - ImGui::GetStyle().ItemSpacing.x * 2 - - ImGui::GetStyle().FramePadding.x * 2); - - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(4, 2)); - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::GetStyleColorVec4(ImGuiCol_HeaderHovered)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImGui::GetStyleColorVec4(ImGuiCol_Header)); - if (ImGui::SmallButton("Info")) - info_gui = !info_gui; - - ImGui::PopStyleVar(2); - ImGui::PopStyleColor(3); - - ImGui::EndMainMenuBar(); - } - - if (remove_gui) - { - ImGui::OpenPopup("Remove session(s)"); - remove_gui = false; - } - - if (ImGui::BeginPopupModal("Remove session(s)", NULL, ImGuiWindowFlags_AlwaysAutoResize)) - { - static std::vector session_marked_for_removal; - if (session_marked_for_removal.size() != project_settings.session_file_names.size()) - session_marked_for_removal.resize(project_settings.session_file_names.size(), false); - - ImGui::Text("Select session(s) to remove:"); - ImGui::Separator(); - - for (size_t i = 0; i < project_settings.session_file_names.size(); i++) - { - bool checked = session_marked_for_removal[i]; - if (ImGui::Checkbox(project_settings.session_file_names[i].c_str(), &checked)) - session_marked_for_removal[i] = checked; - } - - ImGui::Separator(); - - if (ImGui::Button("Remove")) - { - for (size_t i = project_settings.session_file_names.size(); i > 0; --i) - { - size_t idx = i - 1; - - if (session_marked_for_removal[idx]) - { - std::cout << "Removing session: " << project_settings.session_file_names[idx] << std::endl; - - project_settings.session_file_names.erase(project_settings.session_file_names.begin() + idx); - - if (idx < sessions.size()) - sessions.erase(sessions.begin() + idx); - } - } - session_marked_for_removal.clear(); - - if (!sessions.empty()) - update_timestamp_offset(); - else - { - loaded_sessions = false; - time_stamp_offset = 0.0; - } - - ImGui::CloseCurrentPopup(); - } - - ImGui::SameLine(); - if (ImGui::Button("Cancel")) - { - session_marked_for_removal.clear(); - ImGui::CloseCurrentPopup(); - } - - ImGui::EndPopup(); - } - - if (is_ndt_gui) - ndt_gui(); - - if (is_loop_closure_gui) - loop_closure_gui(); - - cor_window(); - - info_window(infoLines, appShortcuts); - - if (compass_ruler) - drawMiniCompassWithRuler(); - - // my_display_code(); - /*if (is_ndt_gui) - ndt_gui(); - if (is_icp_gui) - icp_gui(); - if (is_pose_graph_slam) - pose_graph_slam_gui(); - if (is_registration_plane_feature) - registration_plane_feature_gui(); - if (is_manual_analisys) - observation_picking_gui();*/ - // if (is_loop_closure_gui) - // manual_pose_graph_loop_closure.Gui(); - - if (is_settings_gui) - settings_gui(); - - ImGui::Render(); - ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData()); - - glutSwapBuffers(); - glutPostRedisplay(); -} - -void mouse(int glut_button, int state, int x, int y) -{ - ImGuiIO& io = ImGui::GetIO(); - io.MousePos = ImVec2((float)x, (float)y); - int button = -1; - if (glut_button == GLUT_LEFT_BUTTON) - button = 0; - if (glut_button == GLUT_RIGHT_BUTTON) - button = 1; - if (glut_button == GLUT_MIDDLE_BUTTON) - button = 2; - if (button != -1 && state == GLUT_DOWN) - io.MouseDown[button] = true; - if (button != -1 && state == GLUT_UP) - io.MouseDown[button] = false; - - static int glutMajorVersion = glutGet(GLUT_VERSION) / 10000; - if (state == GLUT_DOWN && (glut_button == 3 || glut_button == 4) && glutMajorVersion < 3) - wheel(glut_button, glut_button == 3 ? 1 : -1, x, y); - - if (!io.WantCaptureMouse) - { - if ((glut_button == GLUT_MIDDLE_BUTTON || glut_button == GLUT_RIGHT_BUTTON) && state == GLUT_DOWN && (io.KeyCtrl || io.KeyShift) && - !manipulate_active_edge) - { - // if (s_loop_closure_gui) - if ((sessions.size() > 0) && (number_visible_sessions > 0) && update_rotation_center) - { - getClosestTrajectoriesPoint( - sessions, - x, - y, - first_session_index, - second_session_index, - number_visible_sessions, - index_loop_closure_source, - index_loop_closure_target, - io.KeyShift, - time_stamp_offset); - } - else - { - if (update_rotation_center) - { - setNewRotationCenter(x, y); - } - } - } - - if (state == GLUT_DOWN) - { - mouse_buttons |= 1 << glut_button; - - /*if (observation_picking.is_observation_picking_mode) - { - Eigen::Vector3d p = GLWidgetGetOGLPos(x, y, observation_picking); - int number_active_pcs = 0; - int index_picked = -1; - for (size_t i = 0; i < session.point_clouds_container.point_clouds.size(); i++) - { - if (session.point_clouds_container.point_clouds[i].visible) - { - number_active_pcs++; - index_picked = i; - } - } - if (number_active_pcs == 1) - { - observation_picking.add_picked_to_current_observation(index_picked, p); - } - }*/ - } - else if (state == GLUT_UP) - { - mouse_buttons = 0; - } - mouse_old_x = x; - mouse_old_y = y; - } -} - -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(); - ImGui_ImplGLUT_Shutdown(); - ImGui::DestroyContext(); - } catch (const std::bad_alloc& e) - { - std::cerr << "System is out of memory : " << e.what() << std::endl; - mandeye::fd::OutOfMemMessage(); - } catch (const std::exception& e) - { - std::cout << e.what(); - } catch (...) - { - std::cerr << "Unknown fatal error occurred." << std::endl; - } - - return 0; -} \ No newline at end of file diff --git a/apps/multi_session_registration_legacy/resource.h b/apps/multi_session_registration_legacy/resource.h deleted file mode 100644 index 4f3204ca..00000000 --- a/apps/multi_session_registration_legacy/resource.h +++ /dev/null @@ -1,17 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by resource.rc -// -#define IDI_ICON1 101 // application icon -#define VS_VERSION_INFO 1 // version info - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 106 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1000 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/apps/multi_session_registration_legacy/resource.rc b/apps/multi_session_registration_legacy/resource.rc deleted file mode 100644 index e8821486..00000000 --- a/apps/multi_session_registration_legacy/resource.rc +++ /dev/null @@ -1,49 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "resource.h" -///////////////////////////////////////////////////////////////////////////// -// English (United States) resources - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -IDI_ICON1 ICON "icon.ico" - - -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO -FILEVERSION 0, 0, 100, 1 -PRODUCTVERSION 0, 0, 100, 1 -FILEFLAGSMASK 0x3fL -FILEOS 0x40004 -FILETYPE 0x1 -BEGIN -BLOCK "StringFileInfo" -BEGIN -BLOCK "040904B0" -BEGIN -VALUE "CompanyName", "Mandeye\0" -VALUE "FileDescription", "HDMapping Step 3\0" -VALUE "FileVersion", "0.100.1\0" -VALUE "InternalName", "Multi session registration\0" -VALUE "LegalCopyright", "(c) 2026 github.com/MapsHD/HDMapping\0" -VALUE "OriginalFilename", "multi_session_registration_step_3.exe\0" -VALUE "ProductVersion", "0.100.1\0" -VALUE "ProgramID", "github.com/MapsHD/HDMapping\0" -VALUE "ProductName", "HDMapping\0" -END -END -BLOCK "VarFileInfo" -BEGIN -VALUE "Translation", 0x409, 0x04B0 -END -END -///////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/apps/multi_view_tls_registration_legacy/CMakeLists.txt b/apps/multi_view_tls_registration_legacy/CMakeLists.txt deleted file mode 100644 index 51331851..00000000 --- a/apps/multi_view_tls_registration_legacy/CMakeLists.txt +++ /dev/null @@ -1,80 +0,0 @@ -cmake_minimum_required(VERSION 4.0.0) - -# Legacy GLUT + legacy immediate-mode OpenGL build of step2, kept side by -# side with apps/multi_view_tls_registration (raylib-based since it was -# ported off GLUT) at a stakeholder's request. This is a full, independent -# copy of the app as it was before that port -- not sharing translation -# units with apps/multi_view_tls_registration -- so the two can diverge or -# be retired independently. -project(multi_view_tls_registration_step_2_legacy) - -# Source files -set(SOURCES - multi_view_tls_registration.cpp perform_experiment.cpp - multi_view_tls_registration_gui.cpp multi_view_tls_registration.h - ../lidar_odometry_step_1/lidar_odometry_utils.cpp - "../../core/src/utils.cpp" -) - -# Windows: add resource file -if(WIN32) - list(APPEND SOURCES "resource.rc") -endif() - -add_executable( - multi_view_tls_registration_step_2_legacy ${SOURCES} - ) - -target_compile_definitions(multi_view_tls_registration_step_2_legacy PRIVATE -DWITH_GUI=1) - -target_include_directories( - multi_view_tls_registration_step_2_legacy - PRIVATE include - ${REPOSITORY_DIRECTORY}/core/include - ${THIRDPARTY_DIRECTORY}/glm - ${EIGEN3_INCLUDE_DIR} - ${THIRDPARTY_DIRECTORY} - ${THIRDPARTY_DIRECTORY}/imgui - ${THIRDPARTY_DIRECTORY}/imgui/backends - ${THIRDPARTY_DIRECTORY}/ImGuizmo - ${THIRDPARTY_DIRECTORY}/glew-cmake/include - ${FREEGLUT_INCLUDE_DIR} - ${THIRDPARTY_DIRECTORY}/json/include - ${THIRDPARTY_DIRECTORY}/portable-file-dialogs-master - ${LASZIP_INCLUDE_DIR}/LASzip/include - ${THIRDPARTY_DIRECTORY}/observation_equations/codes - ${THIRDPARTY_DIRECTORY}/vqf/vqf/cpp - ${EXTERNAL_LIBRARIES_DIRECTORY}/include) - - target_link_libraries( - multi_view_tls_registration_step_2_legacy - PRIVATE - WGS84toCartesian - wgs84_do_puwg92 - unordered_dense::unordered_dense - spdlog::spdlog - OpenGL::GLU - ${FREEGLUT_LIBRARY} - ${OPENGL_gl_LIBRARY} - ${PLATFORM_LASZIP_LIB} - ${PLATFORM_MISCELLANEOUS_LIBS} - ${CORE_LIBRARIES} - ${GUI_LIBRARIES} - PROJ::proj) - -if(WIN32) - add_custom_command( - TARGET multi_view_tls_registration_step_2_legacy - POST_BUILD - COMMAND - ${CMAKE_COMMAND} -E copy - $ - $ - COMMAND_EXPAND_LISTS) -endif() - -if (MSVC) - target_compile_options(multi_view_tls_registration_step_2_legacy PRIVATE /bigobj) -endif() - -hdmapping_install_app(multi_view_tls_registration_step_2_legacy) diff --git a/apps/multi_view_tls_registration_legacy/icon.ico b/apps/multi_view_tls_registration_legacy/icon.ico deleted file mode 100644 index 310689ec..00000000 Binary files a/apps/multi_view_tls_registration_legacy/icon.ico and /dev/null differ diff --git a/apps/multi_view_tls_registration_legacy/multi_view_tls_registration.cpp b/apps/multi_view_tls_registration_legacy/multi_view_tls_registration.cpp deleted file mode 100644 index 941ca1be..00000000 --- a/apps/multi_view_tls_registration_legacy/multi_view_tls_registration.cpp +++ /dev/null @@ -1,799 +0,0 @@ -#include "multi_view_tls_registration.h" -#include -#include -#include - -bool has_extension(const std::string file_path, const std::string extension) -{ - std::string::size_type dot_pos = file_path.find_last_of('.'); - if (dot_pos == std::string::npos) - { - return false; // No extension found - } - std::string file_extension = file_path.substr(dot_pos); - return file_extension == extension; -} - -void initial_pose_to_identity(Session& session) -{ - if (session.point_clouds_container.point_clouds.size() > 0) - { - auto m_inv = session.point_clouds_container.point_clouds[0].m_pose.inverse(); - for (int i = 0; i < session.point_clouds_container.point_clouds.size(); i++) - { - session.point_clouds_container.point_clouds[i].m_pose = m_inv * session.point_clouds_container.point_clouds[i].m_pose; - } - } -} - -void save_separately_to_las(const Session& session, fs::path outwd, std::string extension) -{ - const auto& clouds = session.point_clouds_container.point_clouds; - if (clouds.size() > 65535) - { - std::cerr << "warning: more than 65535 scans, point_source_ID capped at 65535\n"; - } - for (size_t scan_idx = 0; scan_idx < clouds.size(); ++scan_idx) - { - const auto& p = clouds[scan_idx]; - if (p.visible) - { - const unsigned short psid = static_cast(std::min(scan_idx, 65535)); - fs::path file_path_in = p.file_name; - fs::path file_path_put = outwd; - file_path_put /= (file_path_in.stem().string() + "_processed" + extension); - std::cout << "file_in: " << file_path_in << std::endl; - std::cout << "file_out: " << file_path_put << std::endl; - std::cout << "start save_processed_pc" << std::endl; - bool compressed = (extension == ".laz"); - save_processed_pc(file_path_in, file_path_put, p.m_pose, session.point_clouds_container.offset, compressed, psid); - std::cout << "save_processed_pc finished" << std::endl; - } - } -} - -void save_trajectories_to_laz( - const Session& session, - std::string output_file_name, - float curve_consecutive_distance_meters, - float not_curve_consecutive_distance_meters, - bool is_trajectory_export_downsampling) -{ - std::vector pointcloud; - std::vector intensity; - std::vector timestamps; - std::vector point_source_ids; - - const auto& clouds = session.point_clouds_container.point_clouds; - if (clouds.size() > 65535) - { - std::cerr << "warning: more than 65535 scans, point_source_ID capped at 65535\n"; - } - - float consecutive_distance = 0; - for (size_t scan_idx = 0; scan_idx < clouds.size(); ++scan_idx) - { - const auto& p = clouds[scan_idx]; - if (p.visible) - { - const unsigned short psid = static_cast(std::min(scan_idx, 65535)); - for (int i = 0; i < p.local_trajectory.size(); i++) - { - const auto& pp = p.local_trajectory[i].m_pose.translation(); - Eigen::Vector3d vp; - vp = p.m_pose * pp; // + session.point_clouds_container.offset; - - if (i > 0) - { - double dist = (p.local_trajectory[i].m_pose.translation() - p.local_trajectory[i - 1].m_pose.translation()).norm(); - consecutive_distance += dist; - } - - bool is_curve = false; - - if (i > 100 && i < p.local_trajectory.size() - 100) - { - Eigen::Vector3d position_prev = p.local_trajectory[i - 100].m_pose.translation(); - Eigen::Vector3d position_curr = p.local_trajectory[i].m_pose.translation(); - Eigen::Vector3d position_next = p.local_trajectory[i + 100].m_pose.translation(); - - Eigen::Vector3d v1 = position_curr - position_prev; - Eigen::Vector3d v2 = position_next - position_curr; - - if (v1.norm() > 0 && v2.norm() > 0) - { - double angle_deg = fabs(acos(v1.dot(v2) / (v1.norm() * v2.norm())) * 180.0 / M_PI); - - if (angle_deg > 10.0) - { - is_curve = true; - } - } - } - double tol = not_curve_consecutive_distance_meters; - - if (is_curve) - { - tol = curve_consecutive_distance_meters; - } - - if (!is_trajectory_export_downsampling) - { - pointcloud.push_back(vp); - intensity.push_back(0); - timestamps.push_back(p.local_trajectory[i].timestamps.first); - point_source_ids.push_back(psid); - } - else - { - if (consecutive_distance >= tol) - { - consecutive_distance = 0; - pointcloud.push_back(vp); - intensity.push_back(0); - timestamps.push_back(p.local_trajectory[i].timestamps.first); - point_source_ids.push_back(psid); - } - } - } - } - } - // if (!exportLaz(output_file_name, pointcloud, intensity, gnss.offset_x, gnss.offset_y, gnss.offset_alt)) - if (!exportLaz( - output_file_name, - pointcloud, - intensity, - timestamps, - session.point_clouds_container.offset.x(), - session.point_clouds_container.offset.y(), - session.point_clouds_container.offset.z(), - &point_source_ids)) - { - std::cout << "problem with saving file: " << output_file_name << std::endl; - } -} - -void createDXFPolyline(const std::string& filename, const std::vector& points) -{ - std::ofstream dxfFile(filename); - dxfFile << std::setprecision(20); - if (!dxfFile.is_open()) - { - std::cerr << "Failed to open file: " << filename << std::endl; - return; - } - - // DXF header - dxfFile << "0\nSECTION\n2\nHEADER\n0\nENDSEC\n"; - dxfFile << "0\nSECTION\n2\nTABLES\n0\nENDSEC\n"; - - // Start the ENTITIES section - dxfFile << "0\nSECTION\n2\nENTITIES\n"; - - // Start the POLYLINE entity - dxfFile << "0\nPOLYLINE\n"; - dxfFile << "8\n0\n"; // Layer 0 - dxfFile << "66\n1\n"; // Indicates the presence of vertices - dxfFile << "70\n8\n"; // 1 = Open polyline - - // Write the VERTEX entities - for (const auto& point : points) - { - dxfFile << "0\nVERTEX\n"; - dxfFile << "8\n0\n"; // Layer 0 - dxfFile << "10\n" << point.x() << "\n"; // X coordinate - dxfFile << "20\n" << point.y() << "\n"; // Y coordinate - dxfFile << "30\n" << point.z() << "\n"; // Z coordinate - } - - // End the POLYLINE - dxfFile << "0\nSEQEND\n"; - - // End the ENTITIES section - dxfFile << "0\nENDSEC\n"; - - // End the DXF file - dxfFile << "0\nEOF\n"; - - dxfFile.close(); - std::cout << "DXF file created: " << filename << std::endl; -} - -void save_trajectories( - Session& session, - std::string output_file_name, - float curve_consecutive_distance_meters, - float not_curve_consecutive_distance_meters, - bool is_trajectory_export_downsampling, - bool write_lidar_timestamp, - bool write_unix_timestamp, - bool use_quaternions, - bool save_to_dxf) -{ - std::ofstream outfile; - if (!save_to_dxf) - { - outfile.open(output_file_name); - } - if (save_to_dxf || outfile.good()) - { - float consecutive_distance = 0; - std::vector polylinePoints; - for (auto& p : session.point_clouds_container.point_clouds) - { - if (p.visible) - { - for (int i = 0; i < p.local_trajectory.size(); i++) - { - const auto& m = p.local_trajectory[i].m_pose; - Eigen::Affine3d pose = p.m_pose * m; - pose.translation() += session.point_clouds_container.offset; - - if (i > 0) - { - double dist = (p.local_trajectory[i].m_pose.translation() - p.local_trajectory[i - 1].m_pose.translation()).norm(); - consecutive_distance += dist; - } - - bool is_curve = false; - - if (i > 100 && i < p.local_trajectory.size() - 100) - { - Eigen::Vector3d position_prev = p.local_trajectory[i - 100].m_pose.translation(); - Eigen::Vector3d position_curr = p.local_trajectory[i].m_pose.translation(); - Eigen::Vector3d position_next = p.local_trajectory[i + 100].m_pose.translation(); - - Eigen::Vector3d v1 = position_curr - position_prev; - Eigen::Vector3d v2 = position_next - position_curr; - - if (v1.norm() > 0 && v2.norm() > 0) - { - double angle_deg = fabs(acos(v1.dot(v2) / (v1.norm() * v2.norm())) * 180.0 / M_PI); - - if (angle_deg > 10.0) - { - is_curve = true; - } - } - } - double tol = not_curve_consecutive_distance_meters; - - if (is_curve) - { - tol = curve_consecutive_distance_meters; - } - - if (!is_trajectory_export_downsampling || (is_trajectory_export_downsampling && consecutive_distance >= tol)) - { - if (is_trajectory_export_downsampling) - { - consecutive_distance = 0; - } - if (save_to_dxf) - { - polylinePoints.push_back(pose.translation()); - } - else - { - outfile << std::setprecision(20); - if (write_lidar_timestamp) - { - outfile << p.local_trajectory[i].timestamps.first << ","; - } - if (write_unix_timestamp) - { - outfile << p.local_trajectory[i].timestamps.second << ","; - } - outfile << pose(0, 3) << "," << pose(1, 3) << "," << pose(2, 3) << ","; - if (use_quaternions) - { - Eigen::Quaterniond q(pose.rotation()); - outfile << q.x() << "," << q.y() << "," << q.z() << "," << q.w() << std::endl; - } - else - { - outfile << pose(0, 0) << "," << pose(0, 1) << "," << pose(0, 2) << "," << pose(1, 0) << "," << pose(1, 1) - << "," << pose(1, 2) << "," << pose(2, 0) << "," << pose(2, 1) << "," << pose(2, 2) << std::endl; - } - } - } - } - } - } - if (!save_to_dxf) - { - outfile.close(); - } - else - { - createDXFPolyline(output_file_name, polylinePoints); - } - } -} - -void save_scale_board_to_laz(const Session& session, std::string output_file_name, float dec, float side_len) -{ - std::vector pointcloud; - std::vector intensity; - std::vector timestamps; - - float min_x = 1000000000.0; - float max_x = -1000000000.0; - float min_y = 1000000000.0; - float max_y = -1000000000.0; - float min_z = 1000000000.0; - float max_z = -1000000000.0; - float xy_incr = 0.001; - float z = 0.0; - if (side_len < 0.0) - { - for (auto& p : session.point_clouds_container.point_clouds) - { - if (p.visible) - { - for (int i = 0; i < p.local_trajectory.size(); i++) - { - const auto& pp = p.local_trajectory[i].m_pose.translation(); - Eigen::Vector3d vp; - vp = p.m_pose * pp; - if (vp.x() < min_x) - { - min_x = vp.x(); - } - if (vp.x() > max_x) - { - max_x = vp.x(); - } - if (vp.y() < min_y) - { - min_y = vp.y(); - } - if (vp.y() > max_y) - { - max_y = vp.y(); - } - if (vp.z() < min_z) - { - min_z = vp.z(); - } - if (vp.z() > max_z) - { - max_z = vp.z(); - } - } - } - } - min_x -= 100.0; - min_y -= 100.0; - max_x += 100.0; - max_y += 100.0; - z = (max_z + min_z) / 2.0; - } - else - { - min_x = -side_len / 2.0; - min_y = -side_len / 2.0; - max_x = side_len / 2.0; - max_y = side_len / 2.0; - xy_incr = 0.2; - z = 0.0; - } - - for (float x = min_x; x <= max_x; x += dec) - { - for (float y = min_y; y <= max_y; y += xy_incr) - { - Eigen::Vector3d vp(x, y, z); - pointcloud.push_back(vp); - intensity.push_back(0); - timestamps.push_back(0.0); - } - } - - for (float y = min_y; y <= max_y; y += dec) - { - for (float x = min_x; x <= max_x; x += xy_incr) - { - Eigen::Vector3d vp(x, y, z); - pointcloud.push_back(vp); - intensity.push_back(0); - timestamps.push_back(0.0); - } - } - - if (!exportLaz( - output_file_name, - pointcloud, - intensity, - timestamps, - session.point_clouds_container.offset.x(), - session.point_clouds_container.offset.y(), - session.point_clouds_container.offset.z())) - { - std::cout << "problem with saving file: " << output_file_name << std::endl; - } -} - -std::vector get_matching_files(const std::string& directory, const std::string& pattern) -{ - std::vector matching_files; - std::regex regex_pattern(pattern); - try - { - for (const auto& entry : fs::directory_iterator(directory)) - { - if (entry.is_regular_file()) - { // Ensure it's a regular file - const std::string filename = entry.path().filename().string(); - if (std::regex_match(filename, regex_pattern)) - { - matching_files.push_back(entry.path().string()); - } - } - } - } catch (const std::exception& e) - { - std::cerr << "Error accessing directory: " << e.what() << std::endl; - } - - return matching_files; -} - -void run_multi_view_tls_registration(std::string input_file_name, TLSRegistration& tls_registration, std::string output_dir) -{ - fs::path outwd = fs::path(output_dir); - Session session; - if (!fs::exists(input_file_name)) - { - std::cout << "Provided input path does not exist." << std::endl; - return; - } - if (has_extension(input_file_name, ".json") || has_extension(input_file_name, ".mjs")) - { - std::cout << "Session file: '" << input_file_name << "'" << std::endl; - session.working_directory = fs::path(input_file_name).parent_path().string(); - session.load( - fs::path(input_file_name).string(), - tls_registration.is_decimate, - tls_registration.bucket_x, - tls_registration.bucket_y, - tls_registration.bucket_z, - tls_registration.calculate_offset); - } - else if (has_extension(input_file_name, ".reg") || has_extension(input_file_name, ".mjp")) - { - std::cout << "RESSO file: '" << input_file_name << "'" << std::endl; - session.working_directory = fs::path(input_file_name).parent_path().string(); - session.point_clouds_container.load( - session.working_directory.c_str(), - input_file_name.c_str(), - tls_registration.is_decimate, - tls_registration.bucket_x, - tls_registration.bucket_y, - tls_registration.bucket_z, - session.load_cache_mode); - } - else if (has_extension(input_file_name, ".txt")) - { - std::cout << "ETH file: '" << input_file_name << "'" << std::endl; - session.working_directory = fs::path(input_file_name).parent_path().string(); - session.point_clouds_container.load_eth( - session.working_directory.c_str(), - input_file_name.c_str(), - tls_registration.is_decimate, - tls_registration.bucket_x, - tls_registration.bucket_y, - tls_registration.bucket_z); - } - else if (!has_extension(input_file_name, "")) - { - session.point_clouds_container.point_clouds.clear(); - session.working_directory = fs::path(input_file_name).string(); - std::vector las_files; - std::vector txt_files; - for (const auto& entry : std::filesystem::directory_iterator(input_file_name)) - { - auto file_name = entry.path().string(); - if (has_extension(file_name, ".laz") || (has_extension(file_name, ".las"))) - { - las_files.push_back(file_name); - } - else if (has_extension(file_name, ".txt")) - { - txt_files.push_back(file_name); - } - } - if (las_files.size() > 0) - { - std::cout << "Las/Laz files:" << std::endl; - for (size_t i = 0; i < las_files.size(); i++) - { - std::cout << las_files[i] << std::endl; - } - session.point_clouds_container.load_whu_tls( - las_files, - tls_registration.is_decimate, - tls_registration.bucket_x, - tls_registration.bucket_y, - tls_registration.bucket_z, - tls_registration.calculate_offset, - session.load_cache_mode); - } - else if (txt_files.size() > 0) - { - std::cout << "txt files:" << std::endl; - for (size_t i = 0; i < txt_files.size(); i++) - { - std::cout << txt_files[i] << std::endl; - } - session.point_clouds_container.load_3DTK_tls( - txt_files, tls_registration.is_decimate, tls_registration.bucket_x, tls_registration.bucket_y, tls_registration.bucket_z); - } - else - { - std::cout << "No WHU-TLS / 3DTK files available in the given directory, check path." << std::endl; - return; - } - } - else - { - std::cout << "Session file: '" << input_file_name << "'" << std::endl; - session.load( - fs::path(input_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 << "loaded: " << session.point_clouds_container.point_clouds.size() << " point_clouds" << std::endl; - - int number_of_point = 0; - for (const auto& pc : session.point_clouds_container.point_clouds) - { - number_of_point += pc.points_local.size(); - } - session.point_clouds_container.print_point_cloud_dimension(); - - if (tls_registration.resso_upd_init.size() > 0) - { - std::cout << "RESSO file: '" << tls_registration.resso_upd_init << "'" << std::endl; - session.working_directory = fs::path(tls_registration.resso_upd_init).parent_path().string(); - if (!session.point_clouds_container.update_initial_poses_from_RESSO( - session.working_directory.c_str(), tls_registration.resso_upd_init.c_str())) - { - std::cout << "check input files" << std::endl; - return; - } - else - { - session.point_clouds_container.initial_poses_file_name = tls_registration.resso_upd_init; - std::cout << "updated: " << session.point_clouds_container.point_clouds.size() << " point_clouds" << std::endl; - } - } - if (tls_registration.resso_upd.size() > 0) - { - std::cout << "RESSO file: '" << tls_registration.resso_upd << "'" << std::endl; - session.working_directory = fs::path(tls_registration.resso_upd).parent_path().string(); - if (!session.point_clouds_container.update_poses_from_RESSO(session.working_directory.c_str(), tls_registration.resso_upd.c_str())) - { - std::cout << "check input files" << std::endl; - return; - } - else - { - std::cout << "updated: " << session.point_clouds_container.point_clouds.size() << " point_clouds" << std::endl; - session.point_clouds_container.poses_file_name = tls_registration.resso_upd; - } - } - if (tls_registration.resso_upd_inv.size() > 0) - { - std::cout << "RESSO file: '" << tls_registration.resso_upd_inv << "'" << std::endl; - session.working_directory = fs::path(tls_registration.resso_upd_inv).parent_path().string(); - if (!session.point_clouds_container.update_poses_from_RESSO_inverse( - session.working_directory.c_str(), tls_registration.resso_upd_inv.c_str())) - { - std::cout << "check input files" << std::endl; - return; - } - else - { - std::cout << "updated: " << session.point_clouds_container.point_clouds.size() << " point_clouds" << std::endl; - session.point_clouds_container.poses_file_name = tls_registration.resso_upd_inv; - } - } - - if (tls_registration.initial_pose_to_identity) - { - initial_pose_to_identity(session); - } - - if (tls_registration.use_ndt) - { - if (tls_registration.compute_only_mahalanobis_distance) - { - tls_registration.ndt.optimize( - session.point_clouds_container.point_clouds, true, tls_registration.compute_mean_and_cov_for_bucket); - } - else if (tls_registration.use_lie_algebra_left_jacobian_ndt) - { - tls_registration.ndt.optimize_lie_algebra_left_jacobian( - session.point_clouds_container.point_clouds, tls_registration.compute_mean_and_cov_for_bucket); - } - else if (tls_registration.use_lie_algebra_right_jacobian_ndt) - { - tls_registration.ndt.optimize_lie_algebra_right_jacobian( - session.point_clouds_container.point_clouds, tls_registration.compute_mean_and_cov_for_bucket); - } - else - { - std::cout << "No additional optimization option selected for NDT: using default..." << std::endl; - tls_registration.ndt.optimize( - session.point_clouds_container.point_clouds, false, tls_registration.compute_mean_and_cov_for_bucket); - } - } - - if (tls_registration.use_icp) - { - if (tls_registration.point_to_point_source_to_target) - { - tls_registration.icp.optimization_point_to_point_source_to_target(session.point_clouds_container); - } - else if (tls_registration.use_lie_algebra_left_jacobian_icp) - { - tls_registration.icp.optimize_source_to_target_lie_algebra_left_jacobian(session.point_clouds_container); - } - else if (tls_registration.use_lie_algebra_right_jacobian_icp) - { - tls_registration.icp.optimize_source_to_target_lie_algebra_right_jacobian(session.point_clouds_container); - } - else if (tls_registration.point_to_point_source_to_target_compute_rms) - { - double rms = 0.0; - tls_registration.icp.optimization_point_to_point_source_to_target_compute_rms(session.point_clouds_container, rms); - std::cout << "rms(optimization_point_to_point_source_to_target): " << rms << std::endl; - } - else - { - std::cout << "No optimization option selected for ICP: skipping..." << std::endl; - } - } - - if (tls_registration.use_plane_features) - { - if (tls_registration.point_to_projection_onto_plane_source_to_target) - { - tls_registration.registration_plane_feature.optimize_point_to_projection_onto_plane_source_to_target( - session.point_clouds_container); - } - else if (tls_registration.use_lie_algebra_left_jacobian_plane_features) - { - tls_registration.registration_plane_feature.optimize_point_to_projection_onto_plane_source_to_target_lie_algebra_left_jacobian( - session.point_clouds_container); - } - else if (tls_registration.use_lie_algebra_right_jacobian_plane_features) - { - tls_registration.registration_plane_feature.optimize_point_to_projection_onto_plane_source_to_target_lie_algebra_right_jacobian( - session.point_clouds_container); - } - else if (tls_registration.point_to_plane_source_to_target_dot_product) - { - tls_registration.registration_plane_feature.optimize_point_to_plane_source_to_target(session.point_clouds_container); - } - else if (tls_registration.point_to_plane_source_to_target) - { - tls_registration.registration_plane_feature.optimize_distance_point_to_plane_source_to_target(session.point_clouds_container); - } - else if (tls_registration.plane_to_plane_source_to_target) - { - tls_registration.registration_plane_feature.optimize_plane_to_plane_source_to_target(session.point_clouds_container); - } - else - { - std::cout << "No optimization option selected for the plane features: skipping..." << std::endl; - } - } - - // TODO: add with GTSAM and with MANIF - if (tls_registration.use_pgslam) - { - tls_registration.pose_graph_slam.ndt_bucket_size[0] = tls_registration.ndt.bucket_size[0]; - tls_registration.pose_graph_slam.ndt_bucket_size[1] = tls_registration.ndt.bucket_size[1]; - tls_registration.pose_graph_slam.ndt_bucket_size[2] = tls_registration.ndt.bucket_size[2]; - tls_registration.pose_graph_slam.optimize(session.point_clouds_container); - } - - if (output_dir.length() > 0) - { - if (session.point_clouds_container.initial_poses_file_name.empty() && tls_registration.save_initial_poses) - { - std::string initial_poses_file_name = (outwd / "session_step2_ini_poses.mri").string(); - std::cout << "saving initial poses to: " << initial_poses_file_name << std::endl; - session.point_clouds_container.save_poses(initial_poses_file_name, false); - } - - if (session.point_clouds_container.poses_file_name.empty() && tls_registration.save_poses) - { - std::string poses_file_name = (outwd / "session_step2_poses.mrp").string(); - std::cout << "saving poses to: " << poses_file_name << std::endl; - session.point_clouds_container.save_poses(poses_file_name, false); - } - - session.save( - (outwd / "session_step2.mjs").string(), - session.point_clouds_container.poses_file_name, - session.point_clouds_container.initial_poses_file_name, - false); - std::cout << "saving result to: " << session.point_clouds_container.poses_file_name << std::endl; - session.point_clouds_container.save_poses(fs::path(session.point_clouds_container.poses_file_name).string(), false); - } - - if (tls_registration.save_laz) - { - save_all_to_las(session, (outwd / "all_step_2.laz").string(), false, true); - } - if (tls_registration.save_las) - { - save_all_to_las(session, (outwd / "all_step_2.las").string(), false, true); - } - if (tls_registration.save_as_separate_las) - { - save_separately_to_las(session, outwd, ".las"); - } - if (tls_registration.save_as_separate_laz) - { - save_separately_to_las(session, outwd, ".laz"); - } - - if (tls_registration.save_trajectories_laz) - { - save_trajectories_to_laz( - session, - (outwd / "trajectories.laz").string(), - tls_registration.curve_consecutive_distance_meters, - tls_registration.not_curve_consecutive_distance_meters, - tls_registration.is_trajectory_export_downsampling); - } - - if (tls_registration.save_gnss_laz) - { - tls_registration.gnss.save_to_laz( - (outwd / "gnss.laz").string(), - session.point_clouds_container.offset.x(), - session.point_clouds_container.offset.y(), - session.point_clouds_container.offset.z()); - } - - if (tls_registration.save_scale_board_laz) - { - save_scale_board_to_laz( - session, (outwd / "scale_board.laz").string(), tls_registration.scale_board_dec, tls_registration.scale_board_side_len); - } - - if (tls_registration.save_trajectories_csv) - { - save_trajectories( - session, - (outwd / "trajectories.csv").string(), - tls_registration.curve_consecutive_distance_meters, - tls_registration.not_curve_consecutive_distance_meters, - tls_registration.is_trajectory_export_downsampling, - tls_registration.write_lidar_timestamp, - tls_registration.write_unix_timestamp, - tls_registration.use_quaternions, - false); - } - if (tls_registration.save_trajectories_dxf) - { - save_trajectories( - session, - (outwd / "trajectories.dxf").string(), - tls_registration.curve_consecutive_distance_meters, - tls_registration.not_curve_consecutive_distance_meters, - tls_registration.is_trajectory_export_downsampling, - tls_registration.write_lidar_timestamp, - tls_registration.write_unix_timestamp, - tls_registration.use_quaternions, - true); - } -} \ No newline at end of file diff --git a/apps/multi_view_tls_registration_legacy/multi_view_tls_registration.h b/apps/multi_view_tls_registration_legacy/multi_view_tls_registration.h deleted file mode 100644 index 26e32189..00000000 --- a/apps/multi_view_tls_registration_legacy/multi_view_tls_registration.h +++ /dev/null @@ -1,177 +0,0 @@ - -#pragma once - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace fs = std::filesystem; - -struct TLSRegistration -{ - // NDT - bool use_ndt = false; - NDT ndt; - bool compute_only_mahalanobis_distance = false; - bool compute_mean_and_cov_for_bucket = false; - bool use_lie_algebra_left_jacobian_ndt = false; - bool use_lie_algebra_right_jacobian_ndt = false; - void set_zoller_frohlich_tls_imager_5006i_errors() - { - ndt.sigma_r = 0.0068; - ndt.sigma_polar_angle = 0.007 / 180.0 * M_PI; - ndt.sigma_azimuthal_angle = 0.007 / 180.0 * M_PI; - } - void set_zoller_frohlich_tls_imager_5010c_errors() - { - ndt.sigma_r = 0.01; - ndt.sigma_polar_angle = 0.007 / 180.0 * M_PI; - ndt.sigma_azimuthal_angle = 0.007 / 180.0 * M_PI; - } - void set_zoller_frohlich_tls_imager_5016_errors() - { - ndt.sigma_r = 0.00025; - ndt.sigma_polar_angle = 0.004 / 180.0 * M_PI; - ndt.sigma_azimuthal_angle = 0.004 / 180.0 * M_PI; - } - void set_faro_focus3d_errors() - { - ndt.sigma_r = 0.001; - ndt.sigma_polar_angle = 19.0 * (1.0 / 3600.0) / 180.0 * M_PI; - ndt.sigma_azimuthal_angle = 19.0 * (1.0 / 3600.0) / 180.0 * M_PI; - } - void set_leica_scanstation_c5_c10_errors() - { - ndt.sigma_r = 0.006; - ndt.sigma_polar_angle = 0.00006; - ndt.sigma_azimuthal_angle = 0.00006; - } - void set_riegl_vz400_errors() - { - ndt.sigma_r = 0.005; - ndt.sigma_polar_angle = 0.0005 / 180.0 * M_PI + 0.0003; // Laser Beam Dicvergence - ndt.sigma_azimuthal_angle = 0.0005 / 180.0 * M_PI + 0.0003; // Laser Beam Dicvergence - } - void set_leica_hds6100_errors() - { - ndt.sigma_r = 0.009; - ndt.sigma_polar_angle = 0.000125; - ndt.sigma_azimuthal_angle = 0.000125; - } - void set_leica_p40_errors() - { - ndt.sigma_r = 0.0012; - ndt.sigma_polar_angle = 8.0 / 3600; - ndt.sigma_azimuthal_angle = 8.0 / 3600; - } - - void set_livox_mid360_errors() - { - ndt.sigma_r = 0.02; - ndt.sigma_polar_angle = 0.15 / 180.0 * M_PI; - ndt.sigma_azimuthal_angle = 0.15 / 180.0 * M_PI; - } - - // ICP - bool use_icp = false; - ICP icp; - bool point_to_point_source_to_target = true; - bool use_lie_algebra_left_jacobian_icp = false; - bool use_lie_algebra_right_jacobian_icp = false; - bool point_to_point_source_to_target_compute_rms = false; - - // Plane features - bool use_plane_features = false; - RegistrationPlaneFeature registration_plane_feature; - bool point_to_projection_onto_plane_source_to_target = true; - bool use_lie_algebra_left_jacobian_plane_features = false; - bool use_lie_algebra_right_jacobian_plane_features = false; - bool point_to_plane_source_to_target_dot_product = false; - bool point_to_plane_source_to_target = false; - bool plane_to_plane_source_to_target = false; - - // PGSLAM - bool use_pgslam = false; - PoseGraphSLAM pose_graph_slam; - - // GNSS - GNSS gnss; - - // TUM trajectory - TUM tum; - - // Loading - bool calculate_offset; // Whether to calculate offset to point cloud on loading - bool is_decimate = true; // Whether to decimate point clouds on loading - double bucket_x = 0.1; // Bucket size for decimation in x dimension - double bucket_y = 0.1; // Bucket size for decimation in y dimension - double bucket_z = 0.1; // Bucket size for decimation in z dimension - std::string resso_upd_init = ""; // Path to RESSO initial poses - std::string resso_upd = ""; // Path to RESSO poses - std::string resso_upd_inv = ""; // Path to RESSO inverse poses - - // Registration - bool initial_pose_to_identity = true; // Whether to set first pose as identity and recalculate the rest relatively to it - - // Export - bool save_las = false; // Save resulting point cloud as las - bool save_laz = false; // Save resulting point cloud as laz - bool save_as_separate_las = false; // Whether to save all scans as separate global scans in las format - bool save_as_separate_laz = false; // Whether to save all scans as separate global scans in laz format - bool save_trajectories_laz = false; // Save laz with all trajectories - bool save_gnss_laz = false; // Save laz with GNSS data - bool save_scale_board_laz = false; // Save laz with scale board - float scale_board_dec = 0.1; // Decimation for scale board laz export - float scale_board_side_len = -1.0; // Range covered in x and y dimensions - bool save_initial_poses = false; // Path where initial poses are saved - bool save_poses = false; // Path where poses are saved - bool is_trajectory_export_downsampling = false; // Whether to downsample trajectory on export - float curve_consecutive_distance_meters = 1.0f; // Meters after which trajectory point is saved (if downsampling and curve is detected) - float not_curve_consecutive_distance_meters = - 0.05f; // Meters after which trajectory point is saved (if downsampling and no curve detected) - bool save_trajectories_csv = false; // Save trajectories as csv - bool save_trajectories_dxf = false; // Save trajectories as dxf - bool write_lidar_timestamp = true; // Whether lidar timestamp is wrriten to csv trajectory output - bool write_unix_timestamp = false; // Whether unix timestamp is written to csv trajectory - bool use_quaternions = true; // Whether quaternions are used when writing csv trajectory -}; - -bool has_extension(const std::string file_path, const std::string extension); - -void initial_pose_to_identity(Session& session); - -void save_separately_to_las(const Session& session, fs::path outwd, std::string extension = ".las"); - -void save_trajectories_to_laz( - const Session& session, - std::string output_file_name, - float curve_consecutive_distance_meters, - float not_curve_consecutive_distance_meters, - bool is_trajectory_export_downsampling); - -void save_scale_board_to_laz(const Session& session, std::string output_file_name, float dec, float side_len = -1.0); - -void createDXFPolyline(const std::string& filename, const std::vector& points); - -// void load_available_geo_points(Session& session, std::string input_file_name); - -void save_trajectories( - Session& session, - std::string output_file_name, - float curve_consecutive_distance_meters, - float not_curve_consecutive_distance_meters, - bool is_trajectory_export_downsampling, - bool write_lidar_timestamp = true, - bool write_unix_timestamp = false, - bool use_quaternions = true, - bool save_to_dxf = false); - -void run_multi_view_tls_registration(std::string input_file_name, TLSRegistration& tls_registration, std::string output_dir = ""); diff --git a/apps/multi_view_tls_registration_legacy/multi_view_tls_registration_gui.cpp b/apps/multi_view_tls_registration_legacy/multi_view_tls_registration_gui.cpp deleted file mode 100644 index 0db4f1df..00000000 --- a/apps/multi_view_tls_registration_legacy/multi_view_tls_registration_gui.cpp +++ /dev/null @@ -1,4253 +0,0 @@ -#include - -#include - -#include -#include -#include -#include - -#include - -#include - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include -#include -#include -#include - -#include "../lidar_odometry_step_1/lidar_odometry_utils.h" -#include "multi_view_tls_registration.h" - -#include - -#include "WGS84toCartesian/WGS84toCartesian.hpp" -#include "wgs84_do_puwg92/wgs84_do_puwg92.h" - -#include -#ifdef _WIN32 -#include "resource.h" -#include - -#endif - -/////////////////////////////////////////////////////////////////////////////////// - -#ifdef _WIN32 -bool consWin = true; -#endif -bool consImGui = false; - -std::string winTitle = std::string("Step 2 (Multi view TSL registration) ") + HDMAPPING_CONFIGURE_PROJECT_VERSION; - -std::vector infoLines = { - "This program is second step in MANDEYE process", - "", - "It refines trajectory (e.g with loop closure)", - "It refines trajectory with many approaches (e.g. Iterative Closest Point, Normal Distributions Transform)", - "It exports session as rigid point cloud to single LAZ file", - "LAZ files are the product of MANDEYE process (open them with Cloud Compare)", -}; - -// App specific shortcuts (Type and Shortcut are just for easy reference) -static const std::vector appShortcuts = { { "Normal keys", "A", "" }, - { "", "Ctrl+A", "point cloud Alignment" }, - { "", "B", "" }, - { "", "Ctrl+B", "" }, - { "", "C", "" }, - { "", "Ctrl+C", "Control points" }, - { "", "D", "" }, - { "", "Ctrl+D", "" }, - { "", "E", "" }, - { "", "Ctrl+E", "lio segments Editor" }, - { "", "F", "" }, - { "", "Ctrl+F", "" }, - { "", "G", "" }, - { "", "Ctrl+G", "Ground control points" }, - { "", "H", "" }, - { "", "Ctrl+H", "" }, - { "", "I", "" }, - { "", "Ctrl+I", "" }, - { "", "J", "" }, - { "", "Ctrl+K", "" }, - { "", "K", "" }, - { "", "Ctrl+K", "" }, - { "", "L", "" }, - { "", "Ctrl+L", "manual Loop closure" }, - { "", "M", "" }, - { "", "Ctrl+M", "" }, - { "", "N", "Next active edge (manual loop closure)" }, - { "", "Ctrl+N", "" }, - { "", "O", "" }, - { "", "Ctrl+O", "Open session" }, - { "", "P", "Previous active edge (manual loop closure)" }, - { "", "Ctrl+P", "Pose graph slam" }, - { "", "Q", "" }, - { "", "Ctrl+Q", "" }, - { "", "R", "" }, - { "", "Ctrl+R", "Random cloud colors" }, - { "", "Shift+R", "" }, - { "", "S", "" }, - { "", "Ctrl+S", "Save session" }, - { "", "Ctrl+Shift+S", "Save subsession" }, - { "", "T", "" }, - { "", "Ctrl+T", "Solid cloud color" }, - { "", "U", "" }, - { "", "Ctrl+U", "" }, - { "", "V", "" }, - { "", "Ctrl+V", "" }, - { "", "W", "" }, - { "", "Ctrl+W", "" }, - { "", "X", "" }, - { "", "Ctrl+X", "" }, - { "", "Y", "" }, - { "", "Ctrl+Y", "" }, - { "", "Z", "" }, - { "", "Ctrl+Z", "" }, - { "", "Shift+Z", "" }, - { "", "1-9", "" }, - { "Special keys", "Up arrow", "" }, - { "", "Shift + up arrow", "" }, - { "", "Ctrl + up arrow", "" }, - { "", "Down arrow", "" }, - { "", "Shift + down arrow", "" }, - { "", "Ctrl + down arrow", "" }, - { "", "Left arrow", "" }, - { "", "Shift + left arrow", "" }, - { "", "Ctrl + left arrow", "" }, - { "", "Right arrow", "" }, - { "", "Shift + right arrow", "" }, - { "", "Ctrl + right arrow", "" }, - { "", "Pg down", "" }, - { "", "Pg up", "" }, - { "", "- key", "" }, - { "", "+ key", "" }, - { "Mouse related", "Left click + drag", "" }, - { "", "Right click + drag", "n" }, - { "", "Scroll", "" }, - { "", "Shift + scroll", "" }, - { "", "Shift + drag", "" }, - { "", "Ctrl + left click", "" }, - { "", "Ctrl + right click", "" }, - { "", "Ctrl + middle click", "" } }; - -namespace fs = std::filesystem; - -static bool show_demo_window = true; -static bool show_another_window = false; - -bool gnssWithOffset = false; - -// radio button selectors -static int NDTnomSelection = 0; -static int NDTpeSelection = 0; -static int NDT3dSelection = 0; -static int ICPnomSelection = 0; -static int ICPpeSelection = 0; -static int ICP3dSelection = 0; -static int RPFnomSelection = 0; -static int RPFpeSelection = 0; -static int RPF3dSelection = 0; -static int PGSnomSelection = 0; -static int PGSpeSelection = 0; -static int PGS3dSelection = 0; -static int PGSpwmtSelection = 0; - -std::string session_file_name = ""; -int session_total_number_of_points = 0; -// bool dynamicSubsampling = true; -// static double lastAdjustTime = 0.0; // last time we changed subsampling -// const double cooldownSeconds = 1; // wait between auto adjustments -// static float fps_avg = 60.0f; - -bool is_pca_gui = false; -bool is_ndt_gui = true; -bool is_icp_gui = false; -bool is_rpf_gui = false; -bool is_pose_graph_slam = false; -bool is_manual_analisys = false; -bool is_loop_closure_gui = false; -bool is_lio_segments_gui = false; -bool is_settings_gui = true; -bool is_translate_gui = false; - -struct TranslateTool -{ - enum class Step - { - Idle, - PickOrigin, - PickXAxis, - PickYHint, - Ready - }; - Step step = Step::Idle; - Eigen::Vector3d origin = Eigen::Vector3d::Zero(); - Eigen::Vector3d x_point = Eigen::Vector3d::Zero(); - Eigen::Vector3d y_hint = Eigen::Vector3d::Zero(); - Eigen::Affine3d transform = Eigen::Affine3d::Identity(); - bool has_transform = false; - float plane_z = 0.0f; -}; -TranslateTool translate_tool; - -bool fillInSession = true; - -TLSRegistration tls_registration; -ObservationPicking observation_picking; -std::vector picked_points; - -bool new_loop_closure_index = false; -int num_edge_extended_before = 0; -int num_edge_extended_after = 0; -int index_loop_closure_source = 0; -int index_loop_closure_target = 0; -int index_begin = 0; -int index_end = 0; - -ColorScheme csPointCloud = CS_SOLID; -ColorScheme csTrajectory = CS_SOLID; - -float m_gizmo[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; - -bool manipulate_only_marked_gizmo = false; - -Session session; -PointClouds::PointCloudDimensions session_dims; -bool session_loaded = false; -std::vector geoids; -std::string selected_geoid_model; - -// these functions performs experiment from paper -//@article -//{BEDKOWSKI2023113199, -// title = {Benchmark of multi-view Terrestrial Laser Scanning Point Cloud data registration algorithms}, -// journal = {Measurement}, -// pages = {113199}, -// year = {2023}, -// issn = {0263-2241}, -// doi = {https://doi.org/10.1016/j.measurement.2023.113199}, -// url = {https://www.sciencedirect.com/science/article/pii/S0263224123007637}, -// author = {Janusz Będkowski}, -// keywords = {TLS, Point cloud, Open-source, Multi-view data registration, LiDAR data metrics, Robust loss function, Tait-bryan -// angles, Quaternions, Rodrigues’ formula, Lie algebra, Rotation matrix parameterization}, abstract = {This study addresses multi-view -// Terrestrial Laser Scanning Point Cloud data registration methods. Multiple rigid point cloud data registration is mandatory for -// aligning all scans into a common reference frame and it is still considered a challenge looking from a large-scale surveys point of -// view. The goal of this work is to support the development of cutting-edge registration methods in geoscience and mobile robotics -// domains. This work evaluates 3 data sets of total 20 scenes available in the literature. This paper provides a novel open-source -// framework for multi-view Terrestrial Laser Scanning Point Cloud data registration benchmarks. The goal was to verify experimentally -// which registration variant can improve the open-source data looking from the quantitative and qualitative points of view. In -// particular, the following scanners provided measurement data: Z+F TLS Imager 5006i, Z+F TLS Imager 5010C, Leica ScanStation C5, -// Leica ScanStation C10, Leica P40 and Riegl VZ-400. The benchmark shows an impact of the metric e.g. point to point, point to -// projection onto a plane, plane to plane etc..., rotation matrix parameterization (Tait-Bryan, quaternion, Rodrigues) and other -// implementation variations (e.g. multi-view Normal Distributions Transform, Pose Graph SLAM approach) onto the multi-view data -// registration accuracy and performance. An open-source project is created and it can be used for improving existing data sets -// reported in the literature, it is the added value of the presented research. The combination of metrics, rotation matrix -// parameterization and optimization algorithms creates hundreds of possible approaches. It is shown that chosen metric is a dominant -// factor in data registration. The rotation parameterization and other degrees of freedom of proposed variants are rather negligible -// compared with chosen metric. Most of the proposed approaches improve registered reference data provided by other researchers. Only -// for 2 from 20 scenes it was not possible to provide significant improvement. The largest improvements are evident for large-scale -// scenes. The project is available and maintained at https://github.com/MapsHD/HDMapping.} -// } - -void export_result_to_folder(std::string output_folder_name, ObservationPicking& observation_picking, Session& session); -void perform_experiment_on_windows( - Session& session, - ObservationPicking& observation_picking, - ICP& icp, - NDT& ndt, - RegistrationPlaneFeature& registration_plane_feature, - PoseGraphSLAM& pose_graph_slam); -void perform_experiment_on_linux( - Session& session, - ObservationPicking& observation_picking, - ICP& icp, - NDT& ndt, - RegistrationPlaneFeature& registration_plane_feature, - PoseGraphSLAM& pose_graph_slam); -double compute_rms(bool initial, Session& session, ObservationPicking& observation_picking); -void reset_poses(Session& session); -void translate_gui(); -void draw_translate_preview(); - -/////////////////////////////////////////////////////////////////////////////////// - -void ndt_gui() -{ - ImGui::InputFloat3("Bucket size (x,y,z) [m]", tls_registration.ndt.bucket_size); - if (tls_registration.ndt.bucket_size[0] < 0.01) - tls_registration.ndt.bucket_size[0] = 0.01f; - if (tls_registration.ndt.bucket_size[1] < 0.01) - tls_registration.ndt.bucket_size[1] = 0.01f; - if (tls_registration.ndt.bucket_size[2] < 0.01) - tls_registration.ndt.bucket_size[2] = 0.01f; - - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::InputInt("Number of threads", &tls_registration.ndt.number_of_threads); - if (tls_registration.ndt.number_of_threads < 1) - tls_registration.ndt.number_of_threads = 1; - ImGui::SameLine(); - ImGui::InputInt("Number of iterations", &tls_registration.ndt.number_of_iterations); - if (tls_registration.ndt.number_of_iterations < 1) - tls_registration.ndt.number_of_iterations = 1; - ImGui::PopItemWidth(); - - ImGui::Checkbox("Fix first node (add I to first pose in Hessian)", &tls_registration.ndt.is_fix_first_node); - - ImGui::Text("Nonlinear optimization method:"); - ImGui::SameLine(); - ImGui::RadioButton("Gauss-Newton", &NDTnomSelection, 0); - ImGui::SameLine(); - ImGui::RadioButton("Levenberg-Marguardt", &NDTnomSelection, 1); - - tls_registration.ndt.is_gauss_newton = (NDTnomSelection == 0); - tls_registration.ndt.is_levenberg_marguardt = (NDTnomSelection == 1); - - ImGui::Text("Poses expressed as:"); - ImGui::SameLine(); - ImGui::RadioButton("camera<-world (cw)", &NDTpeSelection, 0); - ImGui::SameLine(); - ImGui::RadioButton("camera->world (wc)", &NDTpeSelection, 1); - - tls_registration.ndt.is_cw = (NDTpeSelection == 0); - tls_registration.ndt.is_wc = (NDTpeSelection == 1); - - ImGui::Text("Parameterizations of 3D rotation:"); - ImGui::RadioButton("Tait-Bryan angles (om fi ka: RxRyRz)", &NDT3dSelection, 0); - ImGui::SameLine(); - ImGui::RadioButton("Quaternion (q0 q1 q2 q3)", &NDT3dSelection, 1); - ImGui::SameLine(); - ImGui::RadioButton("Rodrigues (sx sy sz)", &NDT3dSelection, 2); - - tls_registration.ndt.is_tait_bryan_angles = (NDT3dSelection == 0); - tls_registration.ndt.is_quaternion = (NDT3dSelection == 1); - tls_registration.ndt.is_rodrigues = (NDT3dSelection == 2); - - if (ImGui::Button("Optimization")) - { - double rms_initial = 0.0; - double rms_final = 0.0; - double mui = 0.0; - // ndt.optimize(point_clouds_container.point_clouds, rms_initial, rms_final, mui); - // spdlog::info("mui: " << mui << " rms_initial: " << rms_initial << " rms_final: " << rms_final << std::endl; - tls_registration.ndt.optimize(session.point_clouds_container.point_clouds, false, tls_registration.compute_mean_and_cov_for_bucket); - } - - if (ImGui::Button("Compute mean Mahalanobis distance")) - { - double rms_initial = 0.0; - double rms_final = 0.0; - double mui = 0.0; - - tls_registration.ndt.optimize(session.point_clouds_container.point_clouds, true, tls_registration.compute_mean_and_cov_for_bucket); - } - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text( - "Average of all Mahalanobis distances between transformed source points\nand their corresponding Gaussian cells, where:"); - ImGui::Text( - "Mahalanobis distance measures how far a point is from the mean of a multivariate Gaussian distribution,\ntaking into " - "account the covariance (shape and orientation) of that distribution"); - ImGui::EndTooltip(); - } - - ImGui::Separator(); - - ImGui::Text("NDT optimization Lie algebra:"); - ImGui::SameLine(); - if (ImGui::Button("left Jacobian")) - { - tls_registration.ndt.optimize_lie_algebra_left_jacobian( - session.point_clouds_container.point_clouds, tls_registration.compute_mean_and_cov_for_bucket); - } - ImGui::SameLine(); - if (ImGui::Button("right Jacobian")) - { - tls_registration.ndt.optimize_lie_algebra_right_jacobian( - session.point_clouds_container.point_clouds, tls_registration.compute_mean_and_cov_for_bucket); - } - - ImGui::Separator(); - - ImGui::Checkbox("Generalized", &tls_registration.ndt.is_generalized); - ImGui::BeginDisabled(!tls_registration.ndt.is_generalized); - { - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::InputDouble("sigma_r", &tls_registration.ndt.sigma_r, 0.01, 0.01); - ImGui::InputDouble("sigma_polar_angle_rad", &tls_registration.ndt.sigma_polar_angle, 0.0001, 0.0001); - ImGui::InputDouble("sigma_azimuthal_angle_rad", &tls_registration.ndt.sigma_azimuthal_angle, 0.0001, 0.0001); - ImGui::InputInt("num_extended_points", &tls_registration.ndt.num_extended_points, 1, 1); - ImGui::PopItemWidth(); - - ImGui::Checkbox("compute_mean_and_cov_for_bucket", &tls_registration.compute_mean_and_cov_for_bucket); - } - ImGui::EndDisabled(); - - ImGui::Text("Set error presets:"); - ImGui::Text("Zoller+Fröhlich TLS Imager"); - ImGui::SameLine(); - if (ImGui::Button("5006i")) - tls_registration.set_zoller_frohlich_tls_imager_5006i_errors(); - ImGui::SameLine(); - if (ImGui::Button("5010C")) - tls_registration.set_zoller_frohlich_tls_imager_5010c_errors(); - ImGui::SameLine(); - if (ImGui::Button("5016")) - tls_registration.set_zoller_frohlich_tls_imager_5016_errors(); - - ImGui::Text("Leica"); - ImGui::SameLine(); - if (ImGui::Button("ScanStation C5 C10")) - tls_registration.set_leica_scanstation_c5_c10_errors(); - ImGui::SameLine(); - if (ImGui::Button("Leica HDS6100")) - tls_registration.set_leica_hds6100_errors(); - ImGui::SameLine(); - if (ImGui::Button("Leica P40")) - tls_registration.set_leica_p40_errors(); - - if (ImGui::Button("Faro Focus3D")) - tls_registration.set_faro_focus3d_errors(); - ImGui::SameLine(); - if (ImGui::Button("Riegl VZ400")) - tls_registration.set_riegl_vz400_errors(); - ImGui::SameLine(); - if (ImGui::Button("Livox mid360")) - tls_registration.set_livox_mid360_errors(); -} - -void icp_gui() -{ - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::InputFloat("Search radius", &tls_registration.icp.search_radius, 0.01f, 0.1f); - if (tls_registration.icp.search_radius < 0.01f) - tls_registration.icp.search_radius = 0.01f; - if (tls_registration.icp.search_radius > 2.0f) - tls_registration.icp.search_radius = 2.0f; - - ImGui::InputInt("Number of threads", &tls_registration.icp.number_of_threads); - if (tls_registration.icp.number_of_threads < 1) - tls_registration.icp.number_of_threads = 1; - ImGui::SameLine(); - ImGui::InputInt("Number of iterations", &tls_registration.icp.number_of_iterations); - if (tls_registration.icp.number_of_iterations < 1) - tls_registration.icp.number_of_iterations = 1; - ImGui::PopItemWidth(); - - ImGui::Checkbox("Adaptive robust kernel", &tls_registration.icp.is_adaptive_robust_kernel); - ImGui::SameLine(); - ImGui::Checkbox("Fix first node (add I to first pose in Hessian)", &tls_registration.icp.is_fix_first_node); - - ImGui::Text("Nonlinear optimization method:"); - ImGui::SameLine(); - ImGui::RadioButton("Gauss-Newton", &ICPnomSelection, 0); - ImGui::SameLine(); - ImGui::RadioButton("Levenberg-Marguardt", &ICPnomSelection, 1); - - tls_registration.icp.is_gauss_newton = (ICPnomSelection == 0); - tls_registration.icp.is_levenberg_marguardt = (ICPnomSelection == 1); - - ImGui::Text("Poses expressed as:"); - ImGui::SameLine(); - ImGui::RadioButton("camera<-world (cw)", &ICPpeSelection, 0); - ImGui::SameLine(); - ImGui::RadioButton("camera->world (wc)", &ICPpeSelection, 1); - - tls_registration.icp.is_cw = (ICPpeSelection == 0); - tls_registration.icp.is_wc = (ICPpeSelection == 1); - - ImGui::Text("Parameterizations of 3D rotation:"); - ImGui::RadioButton("Tait-Bryan angles (om fi ka: RxRyRz)", &ICP3dSelection, 0); - ImGui::SameLine(); - ImGui::RadioButton("Quaternion (q0 q1 q2 q3)", &ICP3dSelection, 1); - ImGui::SameLine(); - ImGui::RadioButton("Rodrigues (sx sy sz)", &ICP3dSelection, 2); - - tls_registration.icp.is_tait_bryan_angles = (ICP3dSelection == 0); - tls_registration.icp.is_quaternion = (ICP3dSelection == 1); - tls_registration.icp.is_rodrigues = (ICP3dSelection == 2); - - if (ImGui::Button("Optimization point to point source to target")) - tls_registration.icp.optimization_point_to_point_source_to_target(session.point_clouds_container); - - ImGui::Separator(); - - ImGui::Text("Optimization source to target Lie-algebra:"); - ImGui::SameLine(); - if (ImGui::Button("left Jacobian")) - tls_registration.icp.optimize_source_to_target_lie_algebra_left_jacobian(session.point_clouds_container); - - ImGui::SameLine(); - if (ImGui::Button("right Jacobian")) - tls_registration.icp.optimize_source_to_target_lie_algebra_right_jacobian(session.point_clouds_container); - - ImGui::Separator(); - - if (ImGui::Button("Compute RMS (optimization_point_to_point_source_to_target)")) - { - double rms = 0.0; - tls_registration.icp.optimization_point_to_point_source_to_target_compute_rms(session.point_clouds_container, rms); - spdlog::info("RMS (optimization_point_to_point_source_to_target): {}", rms); - } -} - -void rpf_gui() -{ - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::InputFloat("Search radius", &tls_registration.registration_plane_feature.search_radius, 0.01, 2.0); - if (tls_registration.registration_plane_feature.search_radius < 0.01) - tls_registration.registration_plane_feature.search_radius = 0.01; - if (tls_registration.registration_plane_feature.search_radius > 2.0) - tls_registration.registration_plane_feature.search_radius = 2.0; - - ImGui::InputInt("Number of threads", &tls_registration.registration_plane_feature.number_of_threads); - if (tls_registration.registration_plane_feature.number_of_threads < 1) - tls_registration.registration_plane_feature.number_of_threads = 1; - ImGui::SameLine(); - ImGui::InputInt("Number of iterations", &tls_registration.registration_plane_feature.number_of_iterations); - if (tls_registration.registration_plane_feature.number_of_iterations < 1) - tls_registration.registration_plane_feature.number_of_iterations = 1; - ImGui::PopItemWidth(); - - ImGui::Checkbox("Adaptive robust kernel", &tls_registration.registration_plane_feature.is_adaptive_robust_kernel); - ImGui::SameLine(); - ImGui::Checkbox("Fix first node (add I to first pose in Hessian)", &tls_registration.registration_plane_feature.is_fix_first_node); - - ImGui::Text("Nonlinear optimization method:"); - ImGui::SameLine(); - ImGui::RadioButton("Gauss-Newton", &RPFnomSelection, 0); - ImGui::SameLine(); - ImGui::RadioButton("Levenberg-Marguardt", &RPFnomSelection, 1); - - tls_registration.registration_plane_feature.is_gauss_newton = (RPFnomSelection == 0); - tls_registration.registration_plane_feature.is_levenberg_marguardt = (RPFnomSelection == 1); - - ImGui::Text("Poses expressed as:"); - ImGui::SameLine(); - ImGui::RadioButton("camera<-world (cw)", &RPFpeSelection, 0); - ImGui::SameLine(); - ImGui::RadioButton("camera->world (wc)", &RPFpeSelection, 1); - - tls_registration.registration_plane_feature.is_cw = (RPFpeSelection == 0); - tls_registration.registration_plane_feature.is_wc = (RPFpeSelection == 1); - - ImGui::Text("Parameterizations of 3D rotation:"); - ImGui::RadioButton("Tait-Bryan angles (om fi ka: RxRyRz)", &RPF3dSelection, 0); - ImGui::SameLine(); - ImGui::RadioButton("Quaternion (q0 q1 q2 q3)", &RPF3dSelection, 1); - ImGui::SameLine(); - ImGui::RadioButton("Rodrigues (sx sy sz)", &RPF3dSelection, 2); - - tls_registration.registration_plane_feature.is_tait_bryan_angles = (RPF3dSelection == 0); - tls_registration.registration_plane_feature.is_quaternion = (RPF3dSelection == 1); - tls_registration.registration_plane_feature.is_rodrigues = (RPF3dSelection == 2); - - ImGui::Separator(); - ImGui::Text("Optimize point to projection onto plane source to target:"); - if (ImGui::Button("Basic Jacobian")) - tls_registration.registration_plane_feature.optimize_point_to_projection_onto_plane_source_to_target( - session.point_clouds_container); - ImGui::SameLine(); - if (ImGui::Button("Lie-algebra left Jacobian")) - tls_registration.registration_plane_feature.optimize_point_to_projection_onto_plane_source_to_target_lie_algebra_left_jacobian( - session.point_clouds_container); - ImGui::SameLine(); - if (ImGui::Button("Lie-algebra right Jacobian")) - tls_registration.registration_plane_feature.optimize_point_to_projection_onto_plane_source_to_target_lie_algebra_right_jacobian( - session.point_clouds_container); - - ImGui::Separator(); - - ImGui::Text("Optimize source to target:"); - if (ImGui::Button("point to plane (using dot product)")) - tls_registration.registration_plane_feature.optimize_point_to_plane_source_to_target(session.point_clouds_container); - ImGui::SameLine(); - if (ImGui::Button("distance point to plane")) - tls_registration.registration_plane_feature.optimize_distance_point_to_plane_source_to_target(session.point_clouds_container); - ImGui::SameLine(); - if (ImGui::Button("plane to plane")) - tls_registration.registration_plane_feature.optimize_plane_to_plane_source_to_target(session.point_clouds_container); -} - -void pca_gui() -{ - ImGui::Begin("Point cloud alignment", &is_pca_gui, ImGuiWindowFlags_MenuBar); - { - if (ImGui::BeginMenuBar()) - { - bool justPushed = false; - - if (is_ndt_gui) - ImGui::PushStyleColor(ImGuiCol_Button, orangeBorder); - if (ImGui::Button("Normal Distributions Transform")) - { - if (!is_ndt_gui) - { - is_ndt_gui = true; - is_icp_gui = false; - is_rpf_gui = false; - justPushed = true; - } - } - if (is_ndt_gui && !justPushed) - ImGui::PopStyleColor(); - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text( - "Probabilistic alternative to ICP that models one cloud (the target)\nas a set of Gaussian distributions " - "rather than raw points"); - ImGui::Text( - "Robust for rough initial poses but can converge to a local optimum\nif the initial misalignment is very large"); - ImGui::Text( - "Known for being faster and smoother in optimization because\nit replaces discrete point-point correspondences " - "with continuous probability density functions."); - ImGui::EndTooltip(); - } - - ImGui::SameLine(); - - if (is_icp_gui) - ImGui::PushStyleColor(ImGuiCol_Button, orangeBorder); - if (ImGui::Button("Iterative Closest Point")) - { - if (!is_icp_gui) - { - is_ndt_gui = false; - is_icp_gui = true; - is_rpf_gui = false; - justPushed = true; - } - } - if (is_icp_gui && !justPushed) - ImGui::PopStyleColor(); - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text( - "Geometric registration algorithm that aligns two point clouds\nby minimizing the Euclidean distances between " - "corresponding points"); - ImGui::Text( - "Very precise at local refinement, especially point-to-plane ICP,\nbut it struggles if the starting alignment " - "is too far off"); - ImGui::EndTooltip(); - } - - ImGui::SameLine(); - - if (is_rpf_gui) - ImGui::PushStyleColor(ImGuiCol_Button, orangeBorder); - if (ImGui::Button("Registration Plane Feature")) - { - if (!is_rpf_gui) - { - is_ndt_gui = false; - is_icp_gui = false; - is_rpf_gui = true; - justPushed = true; - } - } - if (is_rpf_gui && !justPushed) - ImGui::PopStyleColor(); - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text( - "Feature based registration technique that uses detected\nplanar surfaces in the environment (walls, floors, " - "ceilings, etc.) as constraints for alignment"); - ImGui::Text( - "Can be much more robust to noise and partial overlap,\nrequire far fewer correspondences (just a few planes " - "can define a full 6 DOF pose),\nhandle low texture regions better than ICP"); - ImGui::EndTooltip(); - } - - ImGui::EndMenuBar(); - } - - if (is_ndt_gui) - ndt_gui(); - if (is_icp_gui) - icp_gui(); - if (is_rpf_gui) - rpf_gui(); - } - - ImGui::End(); -} - -void pose_graph_slam_gui() -{ - ImGui::Begin("Pose Graph SLAM", &is_pose_graph_slam); - { - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::InputFloat("Search radius", &tls_registration.pose_graph_slam.search_radius, 0.01f, 2.0f); - if (tls_registration.pose_graph_slam.search_radius < 0.01f) - tls_registration.pose_graph_slam.search_radius = 0.01f; - - ImGui::InputInt("Number of threads", &tls_registration.pose_graph_slam.number_of_threads); - if (tls_registration.pose_graph_slam.number_of_threads < 1) - tls_registration.pose_graph_slam.number_of_threads = 1; - - ImGui::InputInt( - "Number of iterations (pair wise matching)", &tls_registration.pose_graph_slam.number_of_iterations_pair_wise_matching); - if (tls_registration.pose_graph_slam.number_of_iterations_pair_wise_matching < 1) - tls_registration.pose_graph_slam.number_of_iterations_pair_wise_matching = 1; - - ImGui::InputFloat("Overlap threshold", &tls_registration.pose_graph_slam.overlap_threshold, 0.1f, 0.8f); - if (tls_registration.pose_graph_slam.overlap_threshold < 0.1f) - tls_registration.pose_graph_slam.overlap_threshold = 0.1f; - ImGui::PopItemWidth(); - - // ImGui::Checkbox("pgslam adaptive_robust_kernel", &pose_graph_slam.icp.is_adaptive_robust_kernel); - - //-- - ImGui::Checkbox("Adaptive robust kernel", &tls_registration.pose_graph_slam.is_adaptive_robust_kernel); - ImGui::SameLine(); - ImGui::Checkbox("Fix first node (add I to first pose in Hessian)", &tls_registration.pose_graph_slam.is_fix_first_node); - - ImGui::Text("Nonlinear optimization method:"); - ImGui::SameLine(); - ImGui::RadioButton("Gauss-Newton", &PGSnomSelection, 0); - ImGui::SameLine(); - ImGui::RadioButton("Levenberg-Marguardt", &PGSnomSelection, 1); - - tls_registration.pose_graph_slam.is_gauss_newton = (PGSnomSelection == 0); - tls_registration.pose_graph_slam.is_levenberg_marguardt = (PGSnomSelection == 1); - - ImGui::Text("Poses expressed as:"); - ImGui::SameLine(); - ImGui::RadioButton("camera<-world (cw)", &PGSpeSelection, 0); - ImGui::SameLine(); - ImGui::RadioButton("camera->world (wc)", &PGSpeSelection, 1); - - tls_registration.pose_graph_slam.is_cw = (PGSpeSelection == 0); - tls_registration.pose_graph_slam.is_wc = (PGSpeSelection == 1); - - ImGui::Text("Parameterizations of 3D rotation:"); - ImGui::RadioButton("Tait-Bryan angles (om fi ka: RxRyRz)", &PGS3dSelection, 0); - ImGui::SameLine(); - ImGui::RadioButton("Quaternion (q0 q1 q2 q3)", &PGS3dSelection, 1); - ImGui::SameLine(); - ImGui::RadioButton("Rodrigues (sx sy sz)", &PGS3dSelection, 2); - - tls_registration.pose_graph_slam.is_tait_bryan_angles = (PGS3dSelection == 0); - tls_registration.pose_graph_slam.is_quaternion = (PGS3dSelection == 1); - tls_registration.pose_graph_slam.is_rodrigues = (PGS3dSelection == 2); - - ImGui::Separator(); - - ImGui::Text("Method for pair wise matching (general):"); - ImGui::RadioButton("NDT", &PGSpwmtSelection, 0); - ImGui::RadioButton("Optimization_point_to_point_source_to_target", &PGSpwmtSelection, 1); - ImGui::RadioButton("Optimize_point_to_projection_onto_plane_source_to_target", &PGSpwmtSelection, 2); - ImGui::RadioButton("Optimize_point_to_plane_source_to_target", &PGSpwmtSelection, 3); - ImGui::RadioButton("Optimize_distance_point_to_plane_source_to_target", &PGSpwmtSelection, 4); - ImGui::RadioButton("Optimize_plane_to_plane_source_to_target", &PGSpwmtSelection, 5); - - ImGui::Separator(); - - ImGui::Text("Method for pair wise matching (with Lie-algebra):"); - ImGui::RadioButton("Optimize NDT (Lie-algebra left Jacobian)", &PGSpwmtSelection, 6); - ImGui::RadioButton("Optimize NDT (Lie-algebra right Jacobian)", &PGSpwmtSelection, 7); - ImGui::RadioButton("Optimize point to point source to target (Lie-algebra left Jacobian)", &PGSpwmtSelection, 8); - ImGui::RadioButton("Optimize point to point source to target (Lie-algebra right Jacobian)", &PGSpwmtSelection, 9); - ImGui::RadioButton("Optimize point to projection onto plane source to target (Lie-algebra left Jacobian)", &PGSpwmtSelection, 10); - ImGui::RadioButton("Optimize point to projection onto plane source to target (Lie-algebra right Jacobian)", &PGSpwmtSelection, 11); - -#ifdef WITH_PCL - ImGui::Separator(); - ImGui::Text("Method for pair wise matching (with PCL):"); - ImGui::RadioButton("Optimize with PCL (NDT based pair wise matching)", &PGSpwmtSelection, 12); - ImGui::RadioButton("Optimize with PCL (ICP based pair wise matching)", &PGSpwmtSelection, 13); -#endif - - // tls_registration.pose_graph_slam.set_all_to_false(); - tls_registration.pose_graph_slam.is_ndt = (PGSpwmtSelection == 0); - tls_registration.pose_graph_slam.is_optimization_point_to_point_source_to_target = (PGSpwmtSelection == 1); - tls_registration.pose_graph_slam.is_optimize_point_to_projection_onto_plane_source_to_target = (PGSpwmtSelection == 2); - tls_registration.pose_graph_slam.is_optimize_point_to_plane_source_to_target = (PGSpwmtSelection == 3); - tls_registration.pose_graph_slam.is_optimize_distance_point_to_plane_source_to_target = (PGSpwmtSelection == 4); - tls_registration.pose_graph_slam.is_optimize_plane_to_plane_source_to_target = (PGSpwmtSelection == 5); - - tls_registration.pose_graph_slam.is_ndt_lie_algebra_left_jacobian = (PGSpwmtSelection == 6); - tls_registration.pose_graph_slam.is_ndt_lie_algebra_right_jacobian = (PGSpwmtSelection == 7); - tls_registration.pose_graph_slam.is_optimize_point_to_point_source_to_target_lie_algebra_left_jacobian = (PGSpwmtSelection == 8); - tls_registration.pose_graph_slam.is_optimize_point_to_point_source_to_target_lie_algebra_right_jacobian = (PGSpwmtSelection == 9); - tls_registration.pose_graph_slam.is_optimize_point_to_projection_onto_plane_source_to_target_lie_algebra_left_jacobian = - (PGSpwmtSelection == 10); - tls_registration.pose_graph_slam.is_optimize_point_to_projection_onto_plane_source_to_target_lie_algebra_right_jacobian = - (PGSpwmtSelection == 11); - - tls_registration.pose_graph_slam.is_optimize_pcl_ndt = (PGSpwmtSelection == 12); - tls_registration.pose_graph_slam.is_optimize_pcl_icp = (PGSpwmtSelection == 13); - - if (PGSpwmtSelection >= 0 && PGSpwmtSelection <= 11) - tls_registration.pose_graph_slam.pair_wise_matching_type = PoseGraphSLAM::PairWiseMatchingType::general; - if (PGSpwmtSelection == 6) - tls_registration.pose_graph_slam.pair_wise_matching_type = PoseGraphSLAM::PairWiseMatchingType::pcl_ndt; - if (PGSpwmtSelection == 7) - tls_registration.pose_graph_slam.pair_wise_matching_type = PoseGraphSLAM::PairWiseMatchingType::pcl_icp; - - ImGui::Separator(); - if (ImGui::Button("Optimize")) - { - tls_registration.pose_graph_slam.ndt_bucket_size[0] = tls_registration.ndt.bucket_size[0]; - tls_registration.pose_graph_slam.ndt_bucket_size[1] = tls_registration.ndt.bucket_size[1]; - tls_registration.pose_graph_slam.ndt_bucket_size[2] = tls_registration.ndt.bucket_size[2]; - // double rms_initial = 0.0; - // double rms_final = 0.0; - // double mui = 0.0; - tls_registration.pose_graph_slam.optimize(session.point_clouds_container); - // pose_graph_slam.optimize(point_clouds_container, rms_initial, rms_final, mui); - // spdlog::info("mean uncertainty impact: " << mui << " rms_initial: " << rms_initial << " rms_final: " << rms_final << - // std::endl; - } - -#if WITH_GTSAM - if (ImGui::Button("Optimize with GTSAM")) - { - ImGui::Separator(); - ImGui::Text("With GTSAM:"); - tls_registration.pose_graph_slam.ndt_bucket_size[0] = tls_registration.ndt.bucket_size[0]; - tls_registration.pose_graph_slam.ndt_bucket_size[1] = tls_registration.ndt.bucket_size[1]; - tls_registration.pose_graph_slam.ndt_bucket_size[2] = tls_registration.ndt.bucket_size[2]; - double rms_initial = 0.0; - double rms_final = 0.0; - double mui = 0.0; - tls_registration.pose_graph_slam.optimize_with_GTSAM(session.point_clouds_container); - // spdlog::info("mean uncertainty impact: " << mui << " rms_initial: " << rms_initial << " rms_final: " << rms_final << - // std::endl; - } -#endif - -#if WITH_MANIF - ImGui::Separator(); - ImGui::Text("With MANIF:"); - if (ImGui::Button("Optimize with manif (a small header-only library for Lie theory)")) - { - tls_registration.pose_graph_slam.optimize_with_manif(session.point_clouds_container); - spdlog::info("Optimize with manif (a small header-only library for Lie theory) DONE" << std::endl; - } -#endif - } - - ImGui::End(); -} - -void observation_picking_gui() -{ - static std::string observations_file_name = ""; - - ImGui::Begin("Observations", &is_manual_analisys); - { - ImGui::Checkbox("Observation picking mode", &observation_picking.is_observation_picking_mode); - ImGui::BeginDisabled(!observation_picking.is_observation_picking_mode); - { - ImGui::Text("Grid [m]:"); - ImGui::Checkbox("10x10", &observation_picking.grid10x10m); - ImGui::SameLine(); - ImGui::Checkbox("1x1", &observation_picking.grid1x1m); - ImGui::SameLine(); - ImGui::Checkbox("0.1x0.1", &observation_picking.grid01x01m); - ImGui::SameLine(); - ImGui::Checkbox("0.01x0.01", &observation_picking.grid001x001m); - - ImGui::Text("Picking plane:"); - ImGui::PushItemWidth(ImGuiNumberWidth); - // ImGui::SliderFloat("picking_plane_height", &observation_picking.picking_plane_height, -20.0f, 20.0f); - ImGui::InputFloat("Height [m]", &observation_picking.picking_plane_height); - // ImGui::SliderFloat("picking_plane_threshold", &observation_picking.picking_plane_threshold, 0.01f, 200.0f); - ImGui::InputFloat("Threshold [m]", &observation_picking.picking_plane_threshold); - // ImGui::SliderFloat("picking_plane_max_xy", &observation_picking.max_xy, 10.0f, 1000.0f); - ImGui::InputFloat("Grid size [m]", &observation_picking.max_xy); - // ImGui::SliderInt("point_size", &observation_picking.point_size, 1, 10); - ImGui::InputInt("Point size", &observation_picking.point_size); - ImGui::PopItemWidth(); - if (observation_picking.point_size < 1) - observation_picking.point_size = 1; - if (observation_picking.point_size > 20) - observation_picking.point_size = 20; - - if (ImGui::Button("Accept current observation")) - { - std::vector m_poses; - for (size_t i = 0; i < session.point_clouds_container.point_clouds.size(); i++) - m_poses.push_back(session.point_clouds_container.point_clouds[i].m_pose); - observation_picking.accept_current_observation(m_poses); - } - ImGui::SameLine(); - if (ImGui::Button("Clear current observation")) - observation_picking.current_observation.clear(); - - if (ImGui::Button("Reset view")) - { - 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; - } - } - ImGui::EndDisabled(); - - ImGui::Text((std::string("Number of observations: ") + std::to_string(observation_picking.observations.size())).c_str()); - - if (ImGui::Button("Load observations")) - { - std::string input_file_name = ""; - input_file_name = mandeye::fd::OpenFileDialogOneFile("Load observations", {}); - - if (input_file_name.size() > 0) - { - observations_file_name = input_file_name; - observation_picking.import_observations(input_file_name); - - for (const auto& obs : observation_picking.observations) - { - for (const auto& [key, value] : obs) - { - if (session.point_clouds_container.show_with_initial_pose) - { - auto p = session.point_clouds_container.point_clouds[key].m_initial_pose * value; - observation_picking.add_intersection(p); - } - else - { - auto p = session.point_clouds_container.point_clouds[key].m_pose * value; - observation_picking.add_intersection(p); - } - break; - } - } - } - } - ImGui::SameLine(); - if (ImGui::Button("Save observations")) - { - const auto output_file_name = mandeye::fd::SaveFileDialog("Save observations", {}, ".json"); - spdlog::info("JSON file to save: '{}'", output_file_name); - - if (output_file_name.size() > 0) - observation_picking.export_observation(output_file_name); - } - - ImGui::Text((std::string("Loaded observations from file: '") + observations_file_name + std::string("'")).c_str()); - - if (ImGui::Button("Compute RMS (xy)")) - { - double rms = compute_rms(true, session, observation_picking); - spdlog::info("RMS (initial poses): {}", rms); - rms = compute_rms(false, session, observation_picking); - spdlog::info("RMS (current poses): {}", rms); - } - - ImGui::Separator(); - if (ImGui::Button("Add intersection")) - observation_picking.add_intersection(Eigen::Vector3d(0.0, 0.0, 0.0)); - - int index_intersection_to_remove = -1; - for (size_t i = 0; i < observation_picking.intersections.size(); i++) - { - ImGui::Separator(); - ImGui::SetWindowFontScale(1.25f); - ImGui::Text("Intersection %zu", i); - ImGui::SetWindowFontScale(1.0f); - ImGui::SameLine(); - ImGui::ColorEdit3( - std::string("Color##" + std::to_string(i)).c_str(), - observation_picking.intersections[i].color, - ImGuiColorEditFlags_NoInputs); - ImGui::SameLine(); - if (ImGui::Button(std::string("Remove##" + std::to_string(i)).c_str())) - index_intersection_to_remove = i; - - ImGui::InputFloat3( - std::string("Translation [m]##" + std::to_string(i)).c_str(), observation_picking.intersections[i].translation); - ImGui::InputFloat3(std::string("Rotation [deg]##" + std::to_string(i)).c_str(), observation_picking.intersections[i].rotation); - ImGui::InputFloat3( - std::string("Width length height [m]##" + std::to_string(i)).c_str(), - observation_picking.intersections[i].width_length_height); - } - - if (index_intersection_to_remove != -1) - { - std::vector intersections; - for (size_t i = 0; i < observation_picking.intersections.size(); i++) - { - if (i != index_intersection_to_remove) - intersections.push_back(observation_picking.intersections[i]); - } - observation_picking.intersections = intersections; - } - - ImGui::Separator(); - - ImGui::BeginDisabled(observation_picking.intersections.size() <= 0); - { - if (ImGui::Button("Export point clouds inside intersections, RMS and poses")) - { - std::string output_folder_name = ""; - output_folder_name = mandeye::fd::SelectFolder("Choose folder"); - spdlog::info("folder: '{}'", output_folder_name); - - if (output_folder_name.size() > 0) - export_result_to_folder(output_folder_name, observation_picking, session); - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("in RESSO format to folder"); - ImGui::SetNextItemWidth(ImGuiNumberWidth); - ImGui::InputFloat("Label distance [m]", &observation_picking.label_dist); - } - ImGui::EndDisabled(); - } - - ImGui::End(); -} - -void loop_closure_gui() -{ - ImGui::Begin("Manual Pose Graph Loop Closure", &is_loop_closure_gui); - { - const auto point_cloud_upper = session.point_clouds_container.point_clouds.size() - 1; - - ImGui::Checkbox("Render source as red target as blue", &session.pose_graph_loop_closure.render_source_as_red_target_as_blue); - - ImGui::Text("Num edge extended:"); - - ImGui::Text("before: "); - ImGui::SameLine(); - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::SliderInt("##fs", &num_edge_extended_before, 0, point_cloud_upper); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("min 0; max %zu", point_cloud_upper); - ImGui::SameLine(); - ImGui::InputInt("##fi", &num_edge_extended_before, 1, 5); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("min 0; max %zu", point_cloud_upper); - if (num_edge_extended_before < 0) - num_edge_extended_before = 0; - if (num_edge_extended_before >= point_cloud_upper) - num_edge_extended_before = point_cloud_upper; - - ImGui::Text(" after: "); - ImGui::SameLine(); - - ImGui::SliderInt("##ts", &num_edge_extended_after, index_loop_closure_target, static_cast(point_cloud_upper)); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("min 0; max %zu", point_cloud_upper); - ImGui::SameLine(); - ImGui::InputInt("##ti", &num_edge_extended_after, 1, 5); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("min 0; max %zu", point_cloud_upper); - if (num_edge_extended_after < 0) - num_edge_extended_after = 0; - if (num_edge_extended_after >= point_cloud_upper) - num_edge_extended_after = point_cloud_upper; - ImGui::PopItemWidth(); - - int prev_index_active_edge = session.pose_graph_loop_closure.index_active_edge; - session.pose_graph_loop_closure.Gui( - session.point_clouds_container, - index_loop_closure_source, - index_loop_closure_target, - m_gizmo, - tls_registration.gnss, - tls_registration.tum, - session.ground_control_points, - session.control_points, - num_edge_extended_before, - num_edge_extended_after); - - new_loop_closure_index = (prev_index_active_edge != session.pose_graph_loop_closure.index_active_edge); - } - - ImGui::End(); -} - -void lio_segments_gui() -{ - ImGui::Begin("LIO segments editor", &is_lio_segments_gui); - { - ImGui::Text("index from: "); - ImGui::SameLine(); - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::SliderInt("##fs", &index_begin, 0, index_end); - ImGui::SameLine(); - ImGui::InputInt("##fi", &index_begin, 1, 5); - if (index_begin < 0) - index_begin = 0; - if (index_begin >= index_end) - index_begin = index_end; - - ImGui::SameLine(); - ImGui::Text(" to: "); - ImGui::SameLine(); - - ImGui::SliderInt("##ts", &index_end, index_begin, static_cast(session.point_clouds_container.point_clouds.size() - 1)); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("max %zu", session.point_clouds_container.point_clouds.size() - 1); - ImGui::SameLine(); - ImGui::InputInt("##ti", &index_end, 1, 5); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("max %zu", session.point_clouds_container.point_clouds.size() - 1); - if (index_end < index_begin) - index_end = index_begin; - if (index_end >= session.point_clouds_container.point_clouds.size() - 1) - index_end = session.point_clouds_container.point_clouds.size() - 1; - ImGui::PopItemWidth(); - - ImGui::Text("Selection: "); - ImGui::SameLine(); - if (ImGui::Button("show ")) - session.point_clouds_container.show_all_from_range(index_begin, index_end); - ImGui::SameLine(); - if (ImGui::Button("shift -")) - { - int step = index_end - index_begin; - index_begin -= step; - index_end -= step; - - if (index_begin < 0) - index_begin = 0; - if (index_end < 0) - index_end = 0; - - rotation_center.x() = session.point_clouds_container.point_clouds[index_begin].m_pose(0, 3); - rotation_center.y() = session.point_clouds_container.point_clouds[index_begin].m_pose(1, 3); - rotation_center.z() = session.point_clouds_container.point_clouds[index_begin].m_pose(2, 3); - session.point_clouds_container.show_all_from_range(index_begin, index_end); - } - ImGui::SameLine(); - if (ImGui::Button("shift +")) - { - int step = index_end - index_begin; - index_begin += step; - index_end += step; - - if (index_begin > session.point_clouds_container.point_clouds.size() - 1) - index_begin = session.point_clouds_container.point_clouds.size() - 1; - if (index_end > session.point_clouds_container.point_clouds.size() - 1) - index_end = session.point_clouds_container.point_clouds.size() - 1; - - rotation_center.x() = session.point_clouds_container.point_clouds[index_begin].m_pose(0, 3); - rotation_center.y() = session.point_clouds_container.point_clouds[index_begin].m_pose(1, 3); - rotation_center.z() = session.point_clouds_container.point_clouds[index_begin].m_pose(2, 3); - session.point_clouds_container.show_all_from_range(index_begin, index_end); - } - ImGui::SameLine(); - if (ImGui::Button("Show all")) - session.point_clouds_container.show_all(); - ImGui::SameLine(); - if (ImGui::Button("Hide all")) - session.point_clouds_container.hide_all(); - ImGui::SameLine(); - if (ImGui::Button("Reset poses")) - reset_poses(session); - - ImGui::Checkbox("Show with initial pose", &session.point_clouds_container.show_with_initial_pose); - ImGui::SameLine(); - ImGui::Checkbox("Manipulate only marked gizmo", &manipulate_only_marked_gizmo); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("false: move also succesive nodes"); - - ImGui::SameLine(); - - if (ImGui::Button("Set fuse IMU inclination for picked trajectory node")) - { - if (index_loop_closure_target >= 0 && index_loop_closure_target < session.point_clouds_container.point_clouds.size()) - { - session.point_clouds_container.point_clouds[index_loop_closure_target].fuse_inclination_from_IMU = true; - } - - // picked_index - /*int tmp = -1; - getClosestTrajectoryPoint(session, x, y, false, tmp); - - if (io.KeyCtrl) - { - if (tmp != -1) - index_loop_closure_target = tmp; - } - else if (io.KeyShift) - { - if (tmp != -1) - index_loop_closure_source = tmp; - } - - januszjanusz*/ - } - - ImGui::Text("Fuse IMU inclination: "); - ImGui::SameLine(); - - static double angle_diff = 5.0; - - if (ImGui::Button("Set those that satisfy acceptable angle")) - { - for (size_t i = 0; i < session.point_clouds_container.point_clouds.size(); i++) - { - double om = session.point_clouds_container.point_clouds[i].local_trajectory[0].imu_om_fi_ka.x() * RAD_TO_DEG; - double fi = session.point_clouds_container.point_clouds[i].local_trajectory[0].imu_om_fi_ka.y() * RAD_TO_DEG; - - spdlog::info("om: {}, fi {}", om, fi); - if (fabs(om) > angle_diff || fabs(fi) > angle_diff) - { - } - else - session.point_clouds_container.point_clouds[i].fuse_inclination_from_IMU = true; - } - } - ImGui::SameLine(); - if (ImGui::Button("unset all")) - { - for (size_t i = 0; i < session.point_clouds_container.point_clouds.size(); i++) - session.point_clouds_container.point_clouds[i].fuse_inclination_from_IMU = false; - } - - ImGui::SameLine(); - ImGui::SetNextItemWidth(ImGuiNumberWidth); - ImGui::InputDouble("acceptable angle [deg]", &angle_diff); - - ImGui::Separator(); - // ImGui::Text("motion model"); - - // session.pose_graph_loop_closure.edges. - - // ImGui::InputDouble("motion_model_w_px_1_sigma_m", &session.pose_graph_loop_closure.motion_model_w_px_1_sigma_m); - // ImGui::InputDouble("motion_model_w_py_1_sigma_m", &session.pose_graph_loop_closure.motion_model_w_py_1_sigma_m); - // ImGui::InputDouble("motion_model_w_pz_1_sigma_m", &session.pose_graph_loop_closure.motion_model_w_pz_1_sigma_m); - // ImGui::InputDouble("motion_model_w_om_1_sigma_deg", &session.pose_graph_loop_closure.motion_model_w_om_1_sigma_deg); - // ImGui::InputDouble("motion_model_w_fi_1_sigma_deg", &session.pose_graph_loop_closure.motion_model_w_fi_1_sigma_deg); - // ImGui::InputDouble("motion_model_w_ka_1_sigma_deg", &session.pose_graph_loop_closure.motion_model_w_ka_1_sigma_deg); - - // ImGui::Separator(); - - ImGui::BeginChild("LIO segments", ImVec2(0, 0), true); - { - for (size_t i = 0; i < session.point_clouds_container.point_clouds.size(); i++) - { - if (i > 0) - ImGui::Separator(); - ImGui::SetWindowFontScale(1.25f); - ImGui::Checkbox( - std::filesystem::path(session.point_clouds_container.point_clouds[i].file_name).filename().string().c_str(), - &session.point_clouds_container.point_clouds[i].visible); - ImGui::SetWindowFontScale(1.0f); - ImGui::SameLine(); - ImGui::Checkbox(("gizmo##" + std::to_string(i)).c_str(), &session.point_clouds_container.point_clouds[i].gizmo); - -#if 0 - ImGui::SameLine(); - ImGui::Checkbox(("fixed##" + std::to_string(i)).c_str(), &session.point_clouds_container.point_clouds[i].fixed); - ImGui::SameLine(); - ImGui::PushButtonRepeat(true); - float spacing = ImGui::GetStyle().ItemInnerSpacing.x; - if (ImGui::ArrowButton(("left##" + std::to_string(i)).c_str(), ImGuiDir_Left)) - { - (session.point_clouds_container.point_clouds[i].point_size)--; - } - ImGui::SameLine(0.0f, spacing); - if (ImGui::ArrowButton(("right##" + std::to_string(i)).c_str(), ImGuiDir_Right)) - { - (session.point_clouds_container.point_clouds[i].point_size)++; - } - ImGui::PopButtonRepeat(); - ImGui::SameLine(); - ImGui::Text("point size %d", session.point_clouds_container.point_clouds[i].point_size); - if (session.point_clouds_container.point_clouds[i].point_size < 1) - { - session.point_clouds_container.point_clouds[i].point_size = 1; - } - - ImGui::SameLine(); - if (ImGui::Button(std::string("#" + std::to_string(i) + " save scan(global reference frame)").c_str())) - { - const auto output_file_name = mandeye::fd::SaveFileDialog("Choose folder", {}); - spdlog::info("Scan file to save: '" << output_file_name << "'" << std::endl; - if (output_file_name.size() > 0) - { - session.point_clouds_container.point_clouds[i].save_as_global(output_file_name); - } - } - ImGui::SameLine(); - if (ImGui::Button(std::string("#" + std::to_string(i) + " shift points to center").c_str())) - { - session.point_clouds_container.point_clouds[i].shift_to_center(); - } -#endif - if (session.point_clouds_container.point_clouds[i].gizmo) - { - for (size_t j = 0; j < session.point_clouds_container.point_clouds.size(); j++) - { - if (i != j) - { - session.point_clouds_container.point_clouds[j].gizmo = false; - } - } - m_gizmo[0] = (float)session.point_clouds_container.point_clouds[i].m_pose(0, 0); - m_gizmo[1] = (float)session.point_clouds_container.point_clouds[i].m_pose(1, 0); - m_gizmo[2] = (float)session.point_clouds_container.point_clouds[i].m_pose(2, 0); - m_gizmo[3] = (float)session.point_clouds_container.point_clouds[i].m_pose(3, 0); - m_gizmo[4] = (float)session.point_clouds_container.point_clouds[i].m_pose(0, 1); - m_gizmo[5] = (float)session.point_clouds_container.point_clouds[i].m_pose(1, 1); - m_gizmo[6] = (float)session.point_clouds_container.point_clouds[i].m_pose(2, 1); - m_gizmo[7] = (float)session.point_clouds_container.point_clouds[i].m_pose(3, 1); - m_gizmo[8] = (float)session.point_clouds_container.point_clouds[i].m_pose(0, 2); - m_gizmo[9] = (float)session.point_clouds_container.point_clouds[i].m_pose(1, 2); - m_gizmo[10] = (float)session.point_clouds_container.point_clouds[i].m_pose(2, 2); - m_gizmo[11] = (float)session.point_clouds_container.point_clouds[i].m_pose(3, 2); - m_gizmo[12] = (float)session.point_clouds_container.point_clouds[i].m_pose(0, 3); - m_gizmo[13] = (float)session.point_clouds_container.point_clouds[i].m_pose(1, 3); - m_gizmo[14] = (float)session.point_clouds_container.point_clouds[i].m_pose(2, 3); - m_gizmo[15] = (float)session.point_clouds_container.point_clouds[i].m_pose(3, 3); - } - - if (session.point_clouds_container.point_clouds[i].visible) - { - ImGui::SameLine(); - ImGui::ColorEdit3( - ("color##" + std::to_string(i)).c_str(), - session.point_clouds_container.point_clouds[i].render_color, - ImGuiColorEditFlags_NoInputs); - -#if 0 - ImGui::SameLine(); - if (ImGui::Button(std::string(("ICP##" + std::to_string(i)).c_str()) - { - size_t index_target = i; - PointClouds pcs; - for (size_t k = 0; k < index_target; k++) - { - if (session.point_clouds_container.point_clouds[k].visible) - { - pcs.point_clouds.push_back(session.point_clouds_container.point_clouds[k]); - } - } - - if (pcs.point_clouds.size() > 0) - { - for (size_t k = 0; k < pcs.point_clouds.size(); k++) - { - pcs.point_clouds[k].fixed = true; - } - } - pcs.point_clouds.push_back(session.point_clouds_container.point_clouds[index_target]); - pcs.point_clouds[pcs.point_clouds.size() - 1].fixed = false; - - ICP icp; - icp.search_radious = 0.3; // ToDo move to params - for (auto& pc : pcs.point_clouds) - { - pc.rgd_params.resolution_X = icp.search_radious; - pc.rgd_params.resolution_Y = icp.search_radious; - pc.rgd_params.resolution_Z = icp.search_radious; - - pc.build_rgd(); - pc.cout_rgd(); - pc.compute_normal_vectors(0.5); - } - - icp.number_of_threads = std::thread::hardware_concurrency(); - - icp.number_of_iterations = 10; - icp.is_adaptive_robust_kernel = false; - - icp.is_ballanced_horizontal_vs_vertical = false; - icp.is_fix_first_node = false; - icp.is_gauss_newton = true; - icp.is_levenberg_marguardt = false; - icp.is_cw = false; - icp.is_wc = true; - icp.is_tait_bryan_angles = true; - icp.is_quaternion = false; - icp.is_rodrigues = false; - spdlog::info("optimization_point_to_point_source_to_target" << std::endl; - - icp.optimization_point_to_point_source_to_target(pcs); - - spdlog::info("pose before: " << session.point_clouds_container.point_clouds[index_target].m_pose.matrix() << std::endl; - - std::vector all_m_poses; - for (size_t j = 0; j < session.point_clouds_container.point_clouds.size(); j++) - { - all_m_poses.push_back(session.point_clouds_container.point_clouds[j].m_pose); - } - - session.point_clouds_container.point_clouds[index_target].m_pose = pcs.point_clouds[pcs.point_clouds.size() - 1].m_pose; - - spdlog::info("pose after ICP: " << session.point_clouds_container.point_clouds[index_target].m_pose.matrix() << std::endl; - - // like gizmo - if (!manipulate_only_marked_gizmo) - { - spdlog::info("Update all poses after current pose" << std::endl; - - Eigen::Affine3d curr_m_pose = session.point_clouds_container.point_clouds[index_target].m_pose; - for (size_t j = index_target + 1; j < session.point_clouds_container.point_clouds.size(); j++) - { - curr_m_pose = curr_m_pose * (all_m_poses[j - 1].inverse() * all_m_poses[j]); - session.point_clouds_container.point_clouds[j].m_pose = curr_m_pose; - } - } - } -#endif - - ImGui::SameLine(); - ImGui::Checkbox( - ("fuse IMU inclination##" + std::to_string(i)).c_str(), - &session.point_clouds_container.point_clouds[i].fuse_inclination_from_IMU); - - ImGui::SameLine(); - ImGui::Checkbox(("show IMU##" + std::to_string(i)).c_str(), &session.point_clouds_container.point_clouds[i].show_IMU); - - ImGui::SameLine(); - ImGui::Checkbox(("show pose##" + std::to_string(i)).c_str(), &session.point_clouds_container.point_clouds[i].show_pose); - - /*ImGui::SameLine(); - if (ImGui::Button(("set IMU inclination##" + std::to_string(i)).c_str())) - { - //session.point_clouds_container.point_clouds[i].m_initial_pose - //session.point_clouds_container.point_clouds[i].m_pose - //session.point_clouds_container.point_clouds[i].m_pose_temp - - TaitBryanPose target_pose = - pose_tait_bryan_from_affine_matrix(session.point_clouds_container.point_clouds[i].m_pose); - - target_pose.om = session.point_clouds_container.point_clouds[i].local_trajectory[0].imu_om_fi_ka.x(); - target_pose.fi = session.point_clouds_container.point_clouds[i].local_trajectory[0].imu_om_fi_ka.y(); - - Eigen::Affine3d m_pose = affine_matrix_from_pose_tait_bryan(target_pose); - - session.point_clouds_container.point_clouds[i].m_initial_pose = m_pose; - session.point_clouds_container.point_clouds[i].m_pose = m_pose; - session.point_clouds_container.point_clouds[i].m_pose_temp = m_pose; - - //session.point_clouds_container.point_clouds[i].m_pose = m_pose; - //session.point_clouds_container.point_clouds[i].pose = - pose_tait_bryan_from_affine_matrix(session.point_clouds_container.point_clouds[i].m_pose); - //session.point_clouds_container.point_clouds[i].gui_translation[0] = - session.point_clouds_container.point_clouds[i].pose.px; - //session.point_clouds_container.point_clouds[i].gui_translation[1] = - session.point_clouds_container.point_clouds[i].pose.py; - //session.point_clouds_container.point_clouds[i].gui_translation[2] = - session.point_clouds_container.point_clouds[i].pose.pz; - //session.point_clouds_container.point_clouds[i].gui_rotation[0] = - rad2deg(session.point_clouds_container.point_clouds[i].pose.om); - //session.point_clouds_container.point_clouds[i].gui_rotation[1] = - rad2deg(session.point_clouds_container.point_clouds[i].pose.fi); - //session.point_clouds_container.point_clouds[i].gui_rotation[2] = - rad2deg(session.point_clouds_container.point_clouds[i].pose.ka); - }*/ - - ImGui::Text("fixed: "); - - ImGui::SameLine(); - ImGui::Checkbox(("X##" + std::to_string(i)).c_str(), &session.point_clouds_container.point_clouds[i].fixed_x); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(xText); - - ImGui::SameLine(); - ImGui::Checkbox(("Y##" + std::to_string(i)).c_str(), &session.point_clouds_container.point_clouds[i].fixed_y); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(yText); - - ImGui::SameLine(); - ImGui::Checkbox(("Z##" + std::to_string(i)).c_str(), &session.point_clouds_container.point_clouds[i].fixed_z); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(zText); - - ImGui::SameLine(); - ImGui::Checkbox(("om##" + std::to_string(i)).c_str(), &session.point_clouds_container.point_clouds[i].fixed_om); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(omText); - - ImGui::SameLine(); - ImGui::Checkbox(("fi##" + std::to_string(i)).c_str(), &session.point_clouds_container.point_clouds[i].fixed_fi); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(fiText); - - ImGui::SameLine(); - ImGui::Checkbox(("ka##" + std::to_string(i)).c_str(), &session.point_clouds_container.point_clouds[i].fixed_ka); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(kaText); - } -#if 0 - ImGui::SameLine(); - if (ImGui::Button(std::string("#" + std::to_string(i) + " print frame to console").c_str())) - { - spdlog::info(session.point_clouds_container.point_clouds[i].m_pose.matrix() << std::endl; - } -#endif - } - } - ImGui::EndChild(); - } - - ImGui::End(); -} - -void loadSession(const std::string& session_file_name) -{ - spdlog::info("Session file: '{}'", session_file_name); - - 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()); - - 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(); - } -} - -void openSession() -{ - session_file_name = mandeye::fd::OpenFileDialogOneFile("Open session", mandeye::fd::Session_filter); - - if (session_file_name.size() > 0) - { - loadSession(session_file_name); - } -} - -std::string saveSession() -{ - const std::string output_file_name = - mandeye::fd::SaveFileDialog("Save session as", mandeye::fd::Session_filter, ".mjs", session_file_name); - - if (output_file_name.size() > 0) - { - spdlog::info("Session file to save: '{}'", output_file_name); - - // creating filenames proposal based on current selection - std::filesystem::path path(output_file_name); - // Extract parts - const auto dir = path.parent_path(); - const auto stem = path.stem().string(); - - // Build new names - std::string initial_poses_file_name = (dir / (stem + "_ini_poses.mri")).string(); - std::string poses_file_name = (dir / (stem + "_poses.mrp")).string(); - - if (session.point_clouds_container.initial_poses_file_name.empty()) - { - spdlog::info("Please assign initial_poses_file_name to session"); - spdlog::warn("Session is not saved!"); - - [[maybe_unused]] pfd::message message( - "Please assign initial_poses_file_name to session", - "Session is not saved. Please assign initial_poses_file_name to session. " - "Follow guidlines available here : " - "https://github.com/MapsHD/HDMapping/tree/main/doc/, " - "You can do this using button 'update initial poses from RESSO file'", - pfd::choice::ok, - pfd::icon::error); - message.result(); - - initial_poses_file_name = - mandeye::fd::SaveFileDialog("Initial poses file name", mandeye::fd::IniPoses_filter, initial_poses_file_name); - spdlog::info("Resso file to save: '{}'", initial_poses_file_name); - - if (initial_poses_file_name.size() > 0) - { - spdlog::info("Saving initial poses to: '{}'", initial_poses_file_name); - session.point_clouds_container.save_poses(initial_poses_file_name, false); - } - } - - if (session.point_clouds_container.poses_file_name.empty()) - { - spdlog::info("Please assign poses_file_name to session"); - spdlog::warn("Session is not saved!"); - - [[maybe_unused]] pfd::message message( - "Please assign poses_file_name to session", - "Session is not saved. Please assign poses_file_name to session. " - "Follow guidlines available here : " - "https://github.com/MapsHD/HDMapping/tree/main/doc/," - "You can do this using button 'update poses from RESSO file'", - pfd::choice::ok, - pfd::icon::error); - message.result(); - - poses_file_name = mandeye::fd::SaveFileDialog("Poses file name", mandeye::fd::Poses_filter, poses_file_name); - spdlog::info("Resso file to save: '{}'", poses_file_name); - if (poses_file_name.size() > 0) - { - spdlog::info("Saving poses to: '{}'", poses_file_name); - session.point_clouds_container.save_poses(poses_file_name, false); - } - } - - session.save(output_file_name, poses_file_name, initial_poses_file_name, false); - spdlog::info("Saving result to: '{}'", poses_file_name); - session.point_clouds_container.save_poses(poses_file_name, false); - - try - { - fs::copy_file(poses_file_name, initial_poses_file_name, fs::copy_options::overwrite_existing); - } catch (const fs::filesystem_error& e) - { - spdlog::error("Error copying poses file: {}", e.what()); - } - - return output_file_name; - } - else - { - spdlog::info("Saving canceled"); - - return ""; - } -} - -void openLaz(bool fillInSession) -{ - session.point_clouds_container.point_clouds.clear(); - std::vector input_file_names; - input_file_names = mandeye::fd::OpenFileDialog("Load las/laz files", mandeye::fd::LAS_LAZ_filter, true); - if (input_file_names.size() > 0) - { - session.working_directory = fs::path(input_file_names[0]).parent_path().string(); - - spdlog::info("Creating session from las/laz files:"); - for (size_t i = 0; i < input_file_names.size(); i++) - spdlog::info("{}", input_file_names[i]); - - if (!session.point_clouds_container.load_whu_tls( - input_file_names, - tls_registration.is_decimate, - tls_registration.bucket_x, - tls_registration.bucket_y, - tls_registration.bucket_z, - tls_registration.calculate_offset, - session.load_cache_mode)) - spdlog::error("Error loading session! Check input files laz/las"); - else - spdlog::info("Loaded: {} point_clouds", session.point_clouds_container.point_clouds.size()); - - session_loaded = true; - index_begin = 0; - index_end = session.point_clouds_container.point_clouds.size() - 1; - - std::string newTitle = winTitle + " - " + fs::path(input_file_names[0]).parent_path().string(); - glutSetWindowTitle(newTitle.c_str()); - - 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(); - - if (fillInSession) - { - int counter = 1; - Eigen::Vector3d mean(session.point_clouds_container.point_clouds[0].points_local[0]); - for (auto& pc : session.point_clouds_container.point_clouds) - { - if (pc.points_local.size() > 100) - { - // spdlog::info("mean " << mean << std::endl; - for (size_t i = 100; i < pc.points_local.size(); i += 100) - { - mean += pc.points_local[i]; - counter++; - } - } - } - mean /= counter; - - for (auto& pc : session.point_clouds_container.point_clouds) - { - Eigen::Affine3d m = Eigen::Affine3d::Identity(); - if (pc.points_local.size() > 100) - { - // int counter = 1; - - // spdlog::info("mean " << mean << std::endl; - // for (size_t i = 100; i < pc.points_local.size(); i += 100) - //{ - // mean += pc.points_local[i]; - // counter++; - //} - - // mean /= counter; - m.translation() = mean; - - PointCloud::LocalTrajectoryNode node; - node.imu_diff_angle_om_fi_ka_deg = { 0, 0, 0 }; - node.imu_om_fi_ka = { 0, 0, 0 }; - node.m_pose = Eigen::Affine3d::Identity(); - node.timestamps = { 0, 0 }; - - pc.local_trajectory.push_back(node); - - for (auto& p : pc.points_local) - { - p -= mean; - } - } - - pc.m_initial_pose = m; - pc.m_pose = m; - pc.m_pose_temp = m; - - pc.pose = pose_tait_bryan_from_affine_matrix(m); - } - - std::string session_fn = get_next_result_path(session.working_directory).string(); - std::filesystem::create_directory(session_fn); - - session_file_name = (fs::path(session_fn) / "newSession.mjs").string(); - session.point_clouds_container.initial_poses_file_name = - "dummy"; // non empty file names signal poses present, new file names will be created on save - session.point_clouds_container.poses_file_name = - "dummy"; // non empty file names signal poses present, new file names will be created on save - - std::string output_file_name = saveSession(); - - if (output_file_name.size() > 0) - { - // creating filenames proposal based on current selection - std::filesystem::path path(output_file_name); - // Extract parts - const auto dir = path.parent_path(); - const auto stem = path.stem().string(); - - // save to folder - for (size_t i = 0; i < session.point_clouds_container.point_clouds.size(); i++) - { - auto pc = session.point_clouds_container.point_clouds[i]; - auto fpath = dir / fs::path(pc.file_name).filename(); - - session.point_clouds_container.point_clouds[i].file_name = fpath.string(); - exportLaz(fpath.string(), pc.points_local, pc.intensities, pc.timestamps); - - // saving terajectory file - auto pathtrj = dir / ("trajectory_lio_" + std::to_string(i) + ".csv"); - spdlog::info("Saving trajectory: '{}'", pathtrj); - - std::ofstream outfile; - outfile.open(pathtrj); - if (!outfile.good()) - { - spdlog::error("Error saving file: '{}'", pathtrj); - return; - } - - outfile << "timestamp_nanoseconds pose00 pose01 pose02 pose03 pose10 pose11 pose12 pose13 pose20 pose21 pose22 pose23 " - "timestampUnix_nanoseconds om_rad fi_rad ka_rad" - << std::endl; - for (int j = 0; j < 1; j++) - { - auto pose = Eigen::Affine3d::Identity(); - - outfile << std::setprecision(20) << 0.0 << " " << std::setprecision(10) << pose(0, 0) << " " << pose(0, 1) << " " - << pose(0, 2) << " " << pose(0, 3) << " " << pose(1, 0) << " " << pose(1, 1) << " " << pose(1, 2) << " " - << pose(1, 3) << " " << pose(2, 0) << " " << pose(2, 1) << " " << pose(2, 2) << " " << pose(2, 3) << " " - << std::setprecision(20) << 0.0 << " " << 0.0 << " " << 0.0 << " " << 0.0 << " " << std::endl; - } - outfile.close(); - } - } - - [[maybe_unused]] pfd::message message( - "Information", - "If you can not see point cloud --> 1. Change 'Points render subsampling', 2. Check console 'min max coordinates " - "should be " - "small numbers to see points in our local coordinate system'. 3. Set checkbox 'calculate_offset for WHU-TLS'. 4. Later " - "on " - "You can change offset directly in session json file.", - pfd::choice::ok, - pfd::icon::info); - message.result(); - - // std::string mes = "Session saved to folder '" + path_ground_truth_session_folder.string() + "'"; - //[[maybe_unused]] pfd::message message( - // "Ground truth session info", mes, - // pfd::choice::ok, pfd::icon::info); - // message.result(); - } - } -} - -void saveSubsession() -{ - int inx_begin = 0; - int inx_end = 0; - - for (size_t i = 0; i < session.point_clouds_container.point_clouds.size(); i++) - { - if (session.point_clouds_container.point_clouds[i].visible) - { - inx_begin = i; - break; - } - } - - for (size_t i = 0; i < session.point_clouds_container.point_clouds.size(); i++) - if (session.point_clouds_container.point_clouds[i].visible) - inx_end = i; - - // creating filename proposal based on current selection - fs::path path(session_file_name); - // Extract parts - fs::path dir = path.parent_path(); - std::string stem = path.stem().string(); - const auto ext = ".mjs"; // forcing new extension even if original session was .json - const std::string indexpart = " " + std::to_string(inx_begin) + "-" + std::to_string(inx_end); - - // Build new name - std::string indexed_file_name = (dir / (stem + indexpart + ext)).string(); - - const auto output_file_name = mandeye::fd::SaveFileDialog("Save subsession", mandeye::fd::Session_filter, ".mjs", indexed_file_name); - - if (output_file_name.size() > 0) - { - spdlog::info("Subsession file to save: '{}'", output_file_name); - - path = fs::path(output_file_name); - dir = path.parent_path(); - stem = path.stem().string(); - - const auto initial_poses_file_name = (dir / (stem + "_ini_poses" + ".mri")).string(); - const auto poses_file_name = (dir / (stem + "_poses" + ".mrp")).string(); - - session.save(fs::path(output_file_name).string(), poses_file_name, initial_poses_file_name, true); - spdlog::info("Saving poses to: '{}'", poses_file_name); - session.point_clouds_container.save_poses(fs::path(poses_file_name).string(), true); - - try - { - fs::copy_file(poses_file_name, initial_poses_file_name, fs::copy_options::overwrite_existing); - } catch (const fs::filesystem_error& e) - { - spdlog::error("Error copying poses file: {}", e.what()); - } - } - else - spdlog::info("Saving canceled"); -} - -void settings_gui() -{ - ImGui::Begin("Settings", &is_settings_gui); - { - std::string wd = "Working directory: '" + session.working_directory + "'"; - ImGui::Text(wd.c_str()); - - ImGui::NewLine(); - - ImGui::InputFloat("camera_x", &new_rotation_center.x()); - ImGui::InputFloat("camera_y", &new_rotation_center.y()); - ImGui::InputFloat("camera_z", &new_rotation_center.z()); - - if (ImGui::Button("set camera")) - { - // new_rotate_x = rotate_x; - // new_rotate_y = rotate_y; - // new_translate_x = -new_rotation_center.x(); - // new_translate_y = -new_rotation_center.y(); - // new_translate_z = -new_rotation_center.z(); - camera_transition_active = true; - } - - if (ImGui::Button("Set initial pose to Identity and update other poses")) - initial_pose_to_identity(session); - - ImGui::NewLine(); - - ImGui::Checkbox("Downsample during load", &tls_registration.is_decimate); - ImGui::Checkbox("Loading Point Cloud Cache Mode", &session.load_cache_mode); - - ImGui::Text("Bucket [m]:"); - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::InputDouble("X##b", &tls_registration.bucket_x, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(xText); - ImGui::SameLine(); - ImGui::InputDouble("Y##b", &tls_registration.bucket_y, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(yText); - ImGui::SameLine(); - ImGui::InputDouble("Z##b", &tls_registration.bucket_z, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(zText); - ImGui::PopItemWidth(); - - ImGui::Separator(); - // common_data - // manual_pose_graph_loop_closure_mode - - if (ImGui::Button("Load RESSO file (transformation_GroundTruth.reg)")) - { - std::string input_file_name = ""; - input_file_name = mandeye::fd::OpenFileDialogOneFile("Load RESSO", mandeye::fd::Resso_filter); - spdlog::info("RESSO file: '{}'", input_file_name); - - if (input_file_name.size() > 0) - { - session.working_directory = fs::path(input_file_name).parent_path().string(); - - if (!session.point_clouds_container.load( - session.working_directory.c_str(), - input_file_name.c_str(), - tls_registration.is_decimate, - tls_registration.bucket_x, - tls_registration.bucket_y, - tls_registration.bucket_z, - session.load_cache_mode)) - { - spdlog::error("Error loading file!"); - return; - } - else - spdlog::info("Loaded: {} point_clouds", session.point_clouds_container.point_clouds.size()); - } - } - ImGui::SameLine(); - if (ImGui::Button("Save RESSO file")) - { - const auto output_file_name = mandeye::fd::SaveFileDialog("Save RESSO file", mandeye::fd::Resso_filter); - spdlog::info("RESSO file to save: '{}'", output_file_name); - if (output_file_name.size() > 0) - session.point_clouds_container.save_poses(fs::path(output_file_name).string(), false); - } - ImGui::Text("RESSO dataset: "); - ImGui::SameLine(); - ImGuiHyperlink("https://3d.bk.tudelft.nl/liangliang/publications/2019/plade/resso.html"); - - ImGui::NewLine(); - - if (ImGui::Button("Load ETH file (pairs.txt)")) - { - std::string input_file_name = ""; - input_file_name = mandeye::fd::OpenFileDialogOneFile("Load ETH file", {}); - if (input_file_name.size() > 0) - { - session.working_directory = fs::path(input_file_name).parent_path().string(); - - if (!session.point_clouds_container.load_eth( - session.working_directory.c_str(), - input_file_name.c_str(), - tls_registration.is_decimate, - tls_registration.bucket_x, - tls_registration.bucket_y, - tls_registration.bucket_z)) - { - spdlog::error("Error loading file!"); - return; - } - else - spdlog::info("Loaded: {} point_clouds", session.point_clouds_container.point_clouds.size()); - } - } - ImGui::Text("ETH dataset: "); - ImGui::SameLine(); - ImGuiHyperlink("https://prs.igp.ethz.ch/research/completed_projects/automatic_registration_of_point_clouds.html"); - - ImGui::NewLine(); - - if (ImGui::Button("Load 3DTK files (select all *.txt files)")) - { - session.point_clouds_container.point_clouds.clear(); - std::vector input_file_names; - input_file_names = mandeye::fd::OpenFileDialog("Load txt files", {}, true); - - if (input_file_names.size() > 0) - { - session.working_directory = fs::path(input_file_names[0]).parent_path().string(); - - spdlog::info("TXT files:"); - for (size_t i = 0; i < input_file_names.size(); i++) - spdlog::info("{}", input_file_names[i]); - - if (!session.point_clouds_container.load_3DTK_tls( - input_file_names, - tls_registration.is_decimate, - tls_registration.bucket_x, - tls_registration.bucket_y, - tls_registration.bucket_z)) - { - spdlog::error("Error loading file!"); - return; - } - else - spdlog::info("Loaded: {} point_clouds", session.point_clouds_container.point_clouds.size()); - } - } - ImGui::Text("3DTK dataset (18: the campus of the Jacobs University Bremen)"); - ImGui::SameLine(); - ImGuiHyperlink("http://kos.informatik.uni-osnabrueck.de/3Dscans/"); - - ImGui::NewLine(); - - if (ImGui::Button("Update initial poses from RESSO file")) - { - std::string input_file_name; - input_file_name = mandeye::fd::OpenFileDialogOneFile("Load RESSO file", {}); - if (input_file_name.size() > 0) - { - session.working_directory = fs::path(input_file_name).parent_path().string(); - - if (!session.point_clouds_container.update_initial_poses_from_RESSO( - session.working_directory.c_str(), input_file_name.c_str())) - { - spdlog::error("Error loading file!"); - return; - } - else - { - session.point_clouds_container.initial_poses_file_name = input_file_name; - spdlog::info("Updated: {} point_clouds", session.point_clouds_container.point_clouds.size()); - } - } - } - ImGui::SameLine(); - ImGui::Text(session.point_clouds_container.initial_poses_file_name.c_str()); - - if (ImGui::Button("Update poses from RESSO file")) - { - std::string input_file_name; - input_file_name = mandeye::fd::OpenFileDialogOneFile("Load RESSO file", {}); - - if (input_file_name.size() > 0) - { - session.working_directory = fs::path(input_file_name).parent_path().string(); - - if (!session.point_clouds_container.update_poses_from_RESSO(session.working_directory.c_str(), input_file_name.c_str())) - { - spdlog::error("Error loading file!"); - return; - } - else - { - spdlog::info("Updated: {} point_clouds", session.point_clouds_container.point_clouds.size()); - session.point_clouds_container.poses_file_name = input_file_name; - } - } - } - ImGui::SameLine(); - - if (ImGui::Button("Update poses from RESSO file (inverse)")) - { - std::string input_file_name; - input_file_name = mandeye::fd::OpenFileDialogOneFile("Load RESSO file", {}); - - if (input_file_name.size() > 0) - { - session.working_directory = fs::path(input_file_name).parent_path().string(); - - if (!session.point_clouds_container.update_poses_from_RESSO_inverse( - session.working_directory.c_str(), input_file_name.c_str())) - { - spdlog::error("Error loading file!"); - return; - } - else - { - spdlog::info("Updated: {} point_clouds", session.point_clouds_container.point_clouds.size()); - session.point_clouds_container.poses_file_name = input_file_name; - } - } - } - ImGui::SameLine(); - ImGui::Text(session.point_clouds_container.poses_file_name.c_str()); - - ImGui::Separator(); - - if (!is_loop_closure_gui) - { - static double x_origin = 0.0; - static double y_origin = 0.0; - static double z_origin = 0.0; - - ImGui::Text("Origin [m]: "); - ImGui::SameLine(); - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::InputDouble("X##o", &x_origin, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(xText); - ImGui::SameLine(); - ImGui::InputDouble("Y##o", &y_origin, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(yText); - ImGui::SameLine(); - ImGui::InputDouble("Z##o", &z_origin, 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(zText); - ImGui::PopItemWidth(); - ImGui::SameLine(); - if (ImGui::Button("Set XYZ origin")) - { - if (session.point_clouds_container.point_clouds.size() != 0) - { - std::vector all_m_poses2; - for (size_t j = 0; j < session.point_clouds_container.point_clouds.size(); j++) - { - all_m_poses2.push_back(session.point_clouds_container.point_clouds[j].m_pose); - } - - session.point_clouds_container.point_clouds[0].m_pose(0, 3) = x_origin; - session.point_clouds_container.point_clouds[0].m_pose(1, 3) = y_origin; - session.point_clouds_container.point_clouds[0].m_pose(2, 3) = z_origin; - - session.point_clouds_container.point_clouds[0].pose = - pose_tait_bryan_from_affine_matrix(session.point_clouds_container.point_clouds[0].m_pose); - - session.point_clouds_container.point_clouds[0].gui_translation[0] = - (float)session.point_clouds_container.point_clouds[0].pose.px; - session.point_clouds_container.point_clouds[0].gui_translation[1] = - (float)session.point_clouds_container.point_clouds[0].pose.py; - session.point_clouds_container.point_clouds[0].gui_translation[2] = - (float)session.point_clouds_container.point_clouds[0].pose.pz; - - session.point_clouds_container.point_clouds[0].gui_rotation[0] = - (float)(session.point_clouds_container.point_clouds[0].pose.om * RAD_TO_DEG); - session.point_clouds_container.point_clouds[0].gui_rotation[1] = - (float)(session.point_clouds_container.point_clouds[0].pose.fi * RAD_TO_DEG); - session.point_clouds_container.point_clouds[0].gui_rotation[2] = - (float)(session.point_clouds_container.point_clouds[0].pose.ka * RAD_TO_DEG); - - Eigen::Affine3d curr_m_pose2 = session.point_clouds_container.point_clouds[0].m_pose; - for (size_t j = 1; j < session.point_clouds_container.point_clouds.size(); j++) - { - curr_m_pose2 = curr_m_pose2 * (all_m_poses2[j - 1].inverse() * all_m_poses2[j]); - - // spdlog::info(curr_m_pose2.matrix() << std::endl; - session.point_clouds_container.point_clouds[j].m_pose = curr_m_pose2; - session.point_clouds_container.point_clouds[j].pose = - pose_tait_bryan_from_affine_matrix(session.point_clouds_container.point_clouds[j].m_pose); - - session.point_clouds_container.point_clouds[j].gui_translation[0] = - (float)session.point_clouds_container.point_clouds[j].pose.px; - session.point_clouds_container.point_clouds[j].gui_translation[1] = - (float)session.point_clouds_container.point_clouds[j].pose.py; - session.point_clouds_container.point_clouds[j].gui_translation[2] = - (float)session.point_clouds_container.point_clouds[j].pose.pz; - - session.point_clouds_container.point_clouds[j].gui_rotation[0] = - (float)(session.point_clouds_container.point_clouds[j].pose.om * RAD_TO_DEG); - session.point_clouds_container.point_clouds[j].gui_rotation[1] = - (float)(session.point_clouds_container.point_clouds[j].pose.fi * RAD_TO_DEG); - session.point_clouds_container.point_clouds[j].gui_rotation[2] = - (float)(session.point_clouds_container.point_clouds[j].pose.ka * RAD_TO_DEG); - } - } - } - - ImGui::Separator(); - - ImGui::Text("Set offsets to export point cloud in global coordinate system [m]:"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("each local coordinate of the point += offset"); - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::InputDouble("X##t", &session.point_clouds_container.offset.x(), 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(xText); - ImGui::SameLine(); - ImGui::InputDouble("Y##t", &session.point_clouds_container.offset.y(), 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(yText); - ImGui::SameLine(); - ImGui::InputDouble("Z##t", &session.point_clouds_container.offset.z(), 0.0, 0.0, "%.3f"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(zText); - ImGui::PopItemWidth(); - - if (ImGui::Button("Set offset_to_apply --> from session (X, Y, Z)")) - session.point_clouds_container.offset = session.point_clouds_container.offset_to_apply; - /* - ImGui::NewLine(); - ImGui::NewLine(); - ImGui::NewLine(); - ImGui::NewLine(); - ImGui::NewLine(); - ImGui::NewLine(); - ImGui::Separator(); - ImGui::Text("Perform experiment on:"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Experiments to compare methods and approaches for multi-view TLS registration"); - ImGui::SameLine(); - if (ImGui::Button("WINDOWS")) - perform_experiment_on_windows(session, observation_picking, tls_registration.icp, tls_registration.ndt, - tls_registration.registration_plane_feature, tls_registration.pose_graph_slam); ImGui::SameLine(); if (ImGui::Button("LINUX")) - perform_experiment_on_linux(session, observation_picking, tls_registration.icp, tls_registration.ndt, - tls_registration.registration_plane_feature, tls_registration.pose_graph_slam); - */ - } - } - - ImGui::End(); -} - -void display() -{ - ImGuiIO& io = ImGui::GetIO(); - glViewport(0, 0, (GLsizei)io.DisplaySize.x, (GLsizei)io.DisplaySize.y); - - 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); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - float ratio = float(io.DisplaySize.x) / float(io.DisplaySize.y); - - updateCameraTransition(); - - viewLocal = Eigen::Affine3f::Identity(); - - if (!is_ortho) - { - reshape((GLsizei)io.DisplaySize.x, (GLsizei)io.DisplaySize.y); - - // janusz - if (is_loop_closure_gui) - { - if (new_loop_closure_index) - { - // if (index_loop_closure_source < session.point_clouds_container.point_clouds.size()) - //{ - // new_rotation_center.x() = - // session.point_clouds_container.point_clouds[index_loop_closure_source].m_pose.translation().x(); - // new_rotation_center.y() = - // session.point_clouds_container.point_clouds[index_loop_closure_source].m_pose.translation().y(); - // new_rotation_center.z() = - // session.point_clouds_container.point_clouds[index_loop_closure_source].m_pose.translation().z(); - // - // new_translate_x = -new_rotation_center.x(); - // new_translate_y = -new_rotation_center.y(); - // camera_transition_active = true; - //} - - if (session.pose_graph_loop_closure.manipulate_active_edge) - { - if (session.pose_graph_loop_closure.edges.size() > 0) - { - if (session.pose_graph_loop_closure.index_active_edge < session.pose_graph_loop_closure.edges.size()) - { - new_rotation_center.x() = - session.point_clouds_container - .point_clouds[session.pose_graph_loop_closure.edges[session.pose_graph_loop_closure.index_active_edge] - .index_from] - .m_pose.translation() - .x(); - new_rotation_center.y() = - session.point_clouds_container - .point_clouds[session.pose_graph_loop_closure.edges[session.pose_graph_loop_closure.index_active_edge] - .index_from] - .m_pose.translation() - .y(); - new_rotation_center.z() = - session.point_clouds_container - .point_clouds[session.pose_graph_loop_closure.edges[session.pose_graph_loop_closure.index_active_edge] - .index_from] - .m_pose.translation() - .z(); - } - } - - new_rotate_x = rotate_x; - new_rotate_y = rotate_y; - new_translate_x = -new_rotation_center.x(); - new_translate_y = -new_rotation_center.y(); - new_translate_z = translate_z; - camera_transition_active = true; - } - - new_loop_closure_index = false; - } - } - - viewLocal.translate(rotation_center); - - viewLocal.translate(Eigen::Vector3f(translate_x, translate_y, translate_z)); - if (!lock_z) - viewLocal.rotate(Eigen::AngleAxisf(rotate_x * DEG_TO_RAD, Eigen::Vector3f::UnitX())); - else - viewLocal.rotate(Eigen::AngleAxisf(-90.0 * DEG_TO_RAD, Eigen::Vector3f::UnitX())); - viewLocal.rotate(Eigen::AngleAxisf(rotate_y * DEG_TO_RAD, Eigen::Vector3f::UnitZ())); - - viewLocal.translate(-rotation_center); - - glLoadMatrixf(viewLocal.matrix().data()); - } - else - updateOrthoView(); - - showAxes(); - - if (session.control_points.is_imgui) - session.control_points.render(session.point_clouds_container, true); - else - { - if (is_loop_closure_gui) - session.pose_graph_loop_closure.Render( - session.point_clouds_container, - index_loop_closure_source, - index_loop_closure_target, - num_edge_extended_before, - num_edge_extended_after); - - tls_registration.gnss.render(session.point_clouds_container); - session.ground_control_points.render(session.point_clouds_container); - session.control_points.render(session.point_clouds_container, false); - } - - int prev_index_pose = session.control_points.index_pose; - - if (prev_index_pose != session.control_points.index_pose) - { - session.control_points.index_picked_point = -1; // reset picked point when pose changes - - new_rotation_center.x() = session.point_clouds_container.point_clouds[session.control_points.index_pose].m_pose.translation().x(); - new_rotation_center.y() = session.point_clouds_container.point_clouds[session.control_points.index_pose].m_pose.translation().y(); - new_rotation_center.z() = session.point_clouds_container.point_clouds[session.control_points.index_pose].m_pose.translation().z(); - - new_rotate_x = rotate_x; - new_rotate_y = rotate_y; - if (session.control_points.track_pose_with_camera) - { - new_translate_x = -new_rotation_center.x(); - new_translate_y = -new_rotation_center.y(); - } - else - { - new_translate_x = translate_x; - new_translate_y = translate_y; - } - new_translate_z = translate_z; - camera_transition_active = true; - } - - ImGui_ImplOpenGL2_NewFrame(); - ImGui_ImplGLUT_NewFrame(); - ImGui::NewFrame(); - - ShowMainDockSpace(); - - if (session.control_points.is_imgui) - session.control_points.imgui(session.point_clouds_container, rotation_center); - - if (session.ground_control_points.is_imgui) - session.ground_control_points.imgui(session.point_clouds_container); - - if (!session.control_points.is_imgui) - { - if (!is_loop_closure_gui) - { - for (size_t i = 0; i < session.point_clouds_container.point_clouds.size(); i++) - { - if (session.point_clouds_container.point_clouds[i].gizmo) - { - std::vector all_m_poses; - for (size_t j = 0; j < session.point_clouds_container.point_clouds.size(); j++) - { - all_m_poses.push_back(session.point_clouds_container.point_clouds[j].m_pose); - } - - ImGuiIO& io = ImGui::GetIO(); - // ImGuizmo ----------------------------------------------- - ImGuizmo::BeginFrame(); - ImGuizmo::Enable(true); - ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y); - - if (!is_ortho) - { - GLfloat projection[16]; - glGetFloatv(GL_PROJECTION_MATRIX, projection); - - GLfloat modelview[16]; - glGetFloatv(GL_MODELVIEW_MATRIX, modelview); - - 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); - - session.point_clouds_container.point_clouds[i].m_pose(0, 0) = m_gizmo[0]; - session.point_clouds_container.point_clouds[i].m_pose(1, 0) = m_gizmo[1]; - session.point_clouds_container.point_clouds[i].m_pose(2, 0) = m_gizmo[2]; - session.point_clouds_container.point_clouds[i].m_pose(3, 0) = m_gizmo[3]; - session.point_clouds_container.point_clouds[i].m_pose(0, 1) = m_gizmo[4]; - session.point_clouds_container.point_clouds[i].m_pose(1, 1) = m_gizmo[5]; - session.point_clouds_container.point_clouds[i].m_pose(2, 1) = m_gizmo[6]; - session.point_clouds_container.point_clouds[i].m_pose(3, 1) = m_gizmo[7]; - session.point_clouds_container.point_clouds[i].m_pose(0, 2) = m_gizmo[8]; - session.point_clouds_container.point_clouds[i].m_pose(1, 2) = m_gizmo[9]; - session.point_clouds_container.point_clouds[i].m_pose(2, 2) = m_gizmo[10]; - session.point_clouds_container.point_clouds[i].m_pose(3, 2) = m_gizmo[11]; - session.point_clouds_container.point_clouds[i].m_pose(0, 3) = m_gizmo[12]; - session.point_clouds_container.point_clouds[i].m_pose(1, 3) = m_gizmo[13]; - session.point_clouds_container.point_clouds[i].m_pose(2, 3) = m_gizmo[14]; - session.point_clouds_container.point_clouds[i].m_pose(3, 3) = m_gizmo[15]; - session.point_clouds_container.point_clouds[i].pose = - pose_tait_bryan_from_affine_matrix(session.point_clouds_container.point_clouds[i].m_pose); - - session.point_clouds_container.point_clouds[i].gui_translation[0] = - (float)session.point_clouds_container.point_clouds[i].pose.px; - session.point_clouds_container.point_clouds[i].gui_translation[1] = - (float)session.point_clouds_container.point_clouds[i].pose.py; - session.point_clouds_container.point_clouds[i].gui_translation[2] = - (float)session.point_clouds_container.point_clouds[i].pose.pz; - - session.point_clouds_container.point_clouds[i].gui_rotation[0] = - (float)(session.point_clouds_container.point_clouds[i].pose.om * RAD_TO_DEG); - 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); - - if (!manipulate_only_marked_gizmo) - { - Eigen::Affine3d curr_m_pose = session.point_clouds_container.point_clouds[i].m_pose; - for (size_t j = i + 1; j < session.point_clouds_container.point_clouds.size(); j++) - { - curr_m_pose = curr_m_pose * (all_m_poses[j - 1].inverse() * all_m_poses[j]); - session.point_clouds_container.point_clouds[j].m_pose = curr_m_pose; - session.point_clouds_container.point_clouds[j].pose = - pose_tait_bryan_from_affine_matrix(session.point_clouds_container.point_clouds[j].m_pose); - - session.point_clouds_container.point_clouds[j].gui_translation[0] = - (float)session.point_clouds_container.point_clouds[j].pose.px; - session.point_clouds_container.point_clouds[j].gui_translation[1] = - (float)session.point_clouds_container.point_clouds[j].pose.py; - session.point_clouds_container.point_clouds[j].gui_translation[2] = - (float)session.point_clouds_container.point_clouds[j].pose.pz; - - session.point_clouds_container.point_clouds[j].gui_rotation[0] = - (float)(session.point_clouds_container.point_clouds[j].pose.om * RAD_TO_DEG); - session.point_clouds_container.point_clouds[j].gui_rotation[1] = - (float)(session.point_clouds_container.point_clouds[j].pose.fi * RAD_TO_DEG); - session.point_clouds_container.point_clouds[j].gui_rotation[2] = - (float)(session.point_clouds_container.point_clouds[j].pose.ka * RAD_TO_DEG); - } - } - } - } - - session.point_clouds_container.render(observation_picking, viewer_decimate_point_cloud, 1, session_dims); - - // spdlog::info("session.point_clouds_container.xy_grid_10x10 " << (int)session.point_clouds_container.xy_grid_10x10 << - // std::endl; - - observation_picking.render(); - - glPushAttrib(GL_ALL_ATTRIB_BITS); - glPointSize(5); - for (const auto& obs : observation_picking.observations) - { - for (const auto& [key1, value1] : obs) - { - for (const auto& [key2, value2] : obs) - { - if (key1 != key2) - { - Eigen::Vector3d p1, p2; - if (session.point_clouds_container.show_with_initial_pose) - { - p1 = session.point_clouds_container.point_clouds[key1].m_initial_pose * value1; - p2 = session.point_clouds_container.point_clouds[key2].m_initial_pose * value2; - } - else - { - p1 = session.point_clouds_container.point_clouds[key1].m_pose * value1; - p2 = session.point_clouds_container.point_clouds[key2].m_pose * value2; - } - glColor3f(0, 1, 0); - glBegin(GL_POINTS); - glVertex3f(p1.x(), p1.y(), p1.z()); - glVertex3f(p2.x(), p2.y(), p2.z()); - glEnd(); - glColor3f(1, 0, 0); - glBegin(GL_LINES); - glVertex3f(p1.x(), p1.y(), p1.z()); - glVertex3f(p2.x(), p2.y(), p2.z()); - glEnd(); - } - } - } - } - glPopAttrib(); - - for (const auto& obs : observation_picking.observations) - { - Eigen::Vector3d mean(0, 0, 0); - int counter = 0; - for (const auto& [key1, value1] : obs) - { - mean += session.point_clouds_container.point_clouds[key1].m_initial_pose * value1; - counter++; - } - if (counter > 0) - { - mean /= counter; - - glColor3f(1, 0, 0); - glBegin(GL_LINE_STRIP); - glVertex3f(mean.x() - 1, mean.y() - 1, mean.z()); - glVertex3f(mean.x() + 1, mean.y() - 1, mean.z()); - glVertex3f(mean.x() + 1, mean.y() + 1, mean.z()); - glVertex3f(mean.x() - 1, mean.y() + 1, mean.z()); - glVertex3f(mean.x() - 1, mean.y() - 1, mean.z()); - glEnd(); - } - } - - glColor3f(1, 0, 1); - glBegin(GL_POINTS); - for (auto p : picked_points) - { - glVertex3f(p.x(), p.y(), p.z()); - } - glEnd(); - } - else - { - // ImGuizmo ----------------------------------------------- - if (session.pose_graph_loop_closure.gizmo && session.pose_graph_loop_closure.edges.size() > 0) - { - ImGuizmo::BeginFrame(); - ImGuizmo::Enable(true); - ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y); - - if (!is_ortho) - { - GLfloat projection[16]; - glGetFloatv(GL_PROJECTION_MATRIX, projection); - - GLfloat modelview[16]; - glGetFloatv(GL_MODELVIEW_MATRIX, modelview); - - 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(); - - m_g(0, 0) = m_gizmo[0]; - m_g(1, 0) = m_gizmo[1]; - m_g(2, 0) = m_gizmo[2]; - m_g(3, 0) = m_gizmo[3]; - m_g(0, 1) = m_gizmo[4]; - m_g(1, 1) = m_gizmo[5]; - m_g(2, 1) = m_gizmo[6]; - m_g(3, 1) = m_gizmo[7]; - m_g(0, 2) = m_gizmo[8]; - m_g(1, 2) = m_gizmo[9]; - m_g(2, 2) = m_gizmo[10]; - m_g(3, 2) = m_gizmo[11]; - m_g(0, 3) = m_gizmo[12]; - m_g(1, 3) = m_gizmo[13]; - m_g(2, 3) = m_gizmo[14]; - m_g(3, 3) = m_gizmo[15]; - - const int& index_src = session.pose_graph_loop_closure.edges[session.pose_graph_loop_closure.index_active_edge].index_from; - - 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); - } - } - } - - 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; - - if (csTrajectory == CS_FOLLOW) - { - pc.traj_color[0] = pc.render_color[0]; - pc.traj_color[1] = pc.render_color[1]; - pc.traj_color[2] = pc.render_color[2]; - } - } - - // 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 (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_T)) // solid colors - { - csPointCloud = CS_SOLID; - - float color[3]; - if (session_loaded) - { - color[0] = session.point_clouds_container.point_clouds[0].render_color[0]; - color[1] = session.point_clouds_container.point_clouds[0].render_color[1]; - color[2] = session.point_clouds_container.point_clouds[0].render_color[2]; - } - - for (auto& pc : session.point_clouds_container.point_clouds) - { - pc.render_color[0] = color[0]; - pc.render_color[1] = color[1]; - pc.render_color[2] = color[2]; - - if (csTrajectory == CS_FOLLOW) - { - pc.traj_color[0] = pc.render_color[0]; - pc.traj_color[1] = pc.render_color[1]; - pc.traj_color[2] = pc.render_color[2]; - } - } - - // workaround - io.AddKeyEvent(ImGuiKey_T, false); - io.AddKeyEvent(ImGuiMod_Ctrl, false); - } - - if (ImGui::BeginMainMenuBar()) - { - if (!session_loaded) - { - if (ImGui::Button("Open session")) - openSession(); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Select session to open (Ctrl+O)"); - - ImGui::SameLine(); - - if (ImGui::ArrowButton("##menuArrow", ImGuiDir_Down)) - ImGui::OpenPopup("OpenMenu"); - - if (ImGui::BeginPopup("OpenMenu")) - { - ImGui::MenuItem("Calculate_offset", nullptr, &tls_registration.calculate_offset); - ImGui::MenuItem("Fill in session", nullptr, &fillInSession); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Fill in data for trajectory and pose to create complete session"); - - if (ImGui::MenuItem("Open las/laz")) - openLaz(fillInSession); - - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Create session from las/laz file(s)"); - - ImGui::EndPopup(); - } - - ImGui::SameLine(); - ImGui::Dummy(ImVec2(20, 0)); - ImGui::SameLine(); - } - else - { - if (ImGui::BeginMenu("File")) - { - if (ImGui::MenuItem("Save session as", "Ctrl+S")) - saveSession(); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Save changes of full session with posibility to change filename"); - - // ImGui::BeginDisabled(!((index_begin > 0) || (index_end < - // static_cast(session.point_clouds_container.point_clouds.size() - 1)))); - //{ - if (ImGui::MenuItem("Save subsession", "Ctrl+Shift+S")) - saveSubsession(); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Save session according to selections from 'LIO segments editor' window"); - //} - // ImGui::EndDisabled(); - - ImGui::Separator(); - if (ImGui::BeginMenu("Save all marked scans")) - { - static bool skip_ts_0 = true; - ImGui::Checkbox("Skip points with zero ts", &skip_ts_0); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Invalid points with zero timestamp will be skipped during export"); - - if (ImGui::MenuItem("Local scan")) - { - const auto output_file_name = mandeye::fd::SaveFileDialog(out_fn.c_str(), mandeye::fd::LAS_LAZ_filter, ".laz"); - spdlog::info("laz file to save: '{}'", output_file_name); - - if (output_file_name.size() > 0) - save_all_to_las(session, output_file_name, true, skip_ts_0); - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("As one local scan transformed via inverse pose of first scan"); - - if (ImGui::MenuItem("Global scan")) - { - const auto output_file_name = mandeye::fd::SaveFileDialog(out_fn.c_str(), mandeye::fd::LAS_LAZ_filter, ".laz"); - spdlog::info("laz file to save: '{}'", output_file_name); - - if (output_file_name.size() > 0) - save_all_to_las(session, output_file_name, false, skip_ts_0); - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip( - "To export in full resolution, close the program and open again and unmark 'downsample during " - "load' before loading session"); - ImGui::Separator(); - if (ImGui::MenuItem("Separate global scans (laz)")) - { - std::string output_folder_name_separately = ""; - output_folder_name_separately = mandeye::fd::SelectFolder("Choose folder"); - save_separately_to_las(session, output_folder_name_separately, ".laz"); - } - - if (ImGui::MenuItem("Separate global scans (las)")) - { - std::string output_folder_name_separately = ""; - output_folder_name_separately = mandeye::fd::SelectFolder("Choose folder"); - save_separately_to_las(session, output_folder_name_separately, ".las"); - } - - ImGui::EndMenu(); - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Save all marked scans as las/laz files"); - - if (ImGui::BeginMenu("Save all marked trajectories")) - { - ImGui::MenuItem("is_trajectory_export_downsampling", nullptr, &tls_registration.is_trajectory_export_downsampling); - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::InputFloat("curve_consecutive_distance [m]", &tls_registration.curve_consecutive_distance_meters); - ImGui::InputFloat("not_curve_consecutive_distance [m]", &tls_registration.not_curve_consecutive_distance_meters); - ImGui::PopItemWidth(); - - if (ImGui::MenuItem("Save all as las/laz files")) - { - const auto output_file_name = mandeye::fd::SaveFileDialog(out_fn.c_str(), mandeye::fd::LAS_LAZ_filter, ".laz"); - spdlog::info("laz file to save: '{}'", output_file_name); - if (output_file_name.size() > 0) - save_trajectories_to_laz( - session, - output_file_name, - tls_registration.curve_consecutive_distance_meters, - tls_registration.not_curve_consecutive_distance_meters, - tls_registration.is_trajectory_export_downsampling); - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("As one global scan"); - - ImGui::Separator(); - - ImGui::Text("(x,y,z,r00,r01,r02,r10,r11,r12,r20,r21,r22)"); - if (ImGui::MenuItem("Save all as csv (timestamp Lidar)##1")) - { - const auto output_file_name = mandeye::fd::SaveFileDialog(out_fn.c_str(), mandeye::fd::Csv_filter, ".csv"); - spdlog::info("csv file to save: '{}'", output_file_name); - - if (output_file_name.size() > 0) - save_trajectories( - session, - output_file_name, - tls_registration.curve_consecutive_distance_meters, - tls_registration.not_curve_consecutive_distance_meters, - tls_registration.is_trajectory_export_downsampling, - true, - false, - false, - false); - } - if (ImGui::MenuItem("Save all as csv (timestamp Unix)##1")) - { - const auto output_file_name = mandeye::fd::SaveFileDialog(out_fn.c_str(), mandeye::fd::Csv_filter, ".csv"); - spdlog::info("csv file to save: '{}'", output_file_name); - - if (output_file_name.size() > 0) - save_trajectories( - session, - output_file_name, - tls_registration.curve_consecutive_distance_meters, - tls_registration.not_curve_consecutive_distance_meters, - tls_registration.is_trajectory_export_downsampling, - false, - true, - false, - false); - } - if (ImGui::MenuItem("Save all as csv (timestamp Lidar, Unix)##1")) - { - const auto output_file_name = mandeye::fd::SaveFileDialog(out_fn.c_str(), mandeye::fd::Csv_filter, ".csv"); - spdlog::info("csv file to save: '{}'", output_file_name); - - if (output_file_name.size() > 0) - save_trajectories( - session, - output_file_name, - tls_registration.curve_consecutive_distance_meters, - tls_registration.not_curve_consecutive_distance_meters, - tls_registration.is_trajectory_export_downsampling, - true, - true, - false, - false); - } - - ImGui::Separator(); - ImGui::Text("(x,y,z,qx,qy,qz,qw)"); - - if (ImGui::MenuItem("Save all as csv (timestamp Lidar)##2")) - { - const auto output_file_name = mandeye::fd::SaveFileDialog(out_fn.c_str(), mandeye::fd::Csv_filter, ".csv"); - spdlog::info("csv file to save: '{}'", output_file_name); - - if (output_file_name.size() > 0) - save_trajectories( - session, - output_file_name, - tls_registration.curve_consecutive_distance_meters, - tls_registration.not_curve_consecutive_distance_meters, - tls_registration.is_trajectory_export_downsampling, - true, - false, - true, - false); - } - if (ImGui::MenuItem("Save all as csv (timestamp Unix)##2")) - { - const auto output_file_name = mandeye::fd::SaveFileDialog(out_fn.c_str(), mandeye::fd::Csv_filter, ".csv"); - spdlog::info("csv file to save: '{}'", output_file_name); - - if (output_file_name.size() > 0) - save_trajectories( - session, - output_file_name, - tls_registration.curve_consecutive_distance_meters, - tls_registration.not_curve_consecutive_distance_meters, - tls_registration.is_trajectory_export_downsampling, - false, - true, - true, - false); - } - if (ImGui::MenuItem("Save all as csv (timestamp Lidar, Unix)##2")) - { - const auto output_file_name = mandeye::fd::SaveFileDialog(out_fn.c_str(), mandeye::fd::Csv_filter, ".csv"); - spdlog::info("csv file to save: '{}'", output_file_name); - - if (output_file_name.size() > 0) - save_trajectories( - session, - output_file_name, - tls_registration.curve_consecutive_distance_meters, - tls_registration.not_curve_consecutive_distance_meters, - tls_registration.is_trajectory_export_downsampling, - true, - true, - true, - false); - } - - ImGui::Separator(); - - if (ImGui::MenuItem("Save all as dxf as polyline")) - { - const auto output_file_name = mandeye::fd::SaveFileDialog("Ouput file name", mandeye::fd::Dxf_filter, ".dxf"); - spdlog::info("dxf file to save: '{}'", output_file_name); - - if (output_file_name.size() > 0) - save_trajectories( - session, - output_file_name, - tls_registration.curve_consecutive_distance_meters, - tls_registration.not_curve_consecutive_distance_meters, - tls_registration.is_trajectory_export_downsampling, - false, - false, - false, - true); - } - - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("Save scale board")) - { - ImGui::Text("For all marked trajectories as one global scan to laz"); - - if (ImGui::MenuItem("> dec 0.1")) - { - const auto output_file_name = mandeye::fd::SaveFileDialog(out_fn.c_str(), mandeye::fd::LAS_LAZ_filter, ".laz"); - spdlog::info("laz file to save: '{}'", output_file_name); - - if (output_file_name.size() > 0) - save_scale_board_to_laz(session, output_file_name, 0.1); - } - - if (ImGui::MenuItem("> dec 1.0")) - { - const auto output_file_name = mandeye::fd::SaveFileDialog(out_fn.c_str(), mandeye::fd::LAS_LAZ_filter, ".laz"); - spdlog::info("laz file to save: '{}'", output_file_name); - - if (output_file_name.size() > 0) - save_scale_board_to_laz(session, output_file_name, 1.0); - } - - if (ImGui::MenuItem("> dec 10.0")) - { - const auto output_file_name = mandeye::fd::SaveFileDialog(out_fn.c_str(), mandeye::fd::LAS_LAZ_filter, ".laz"); - spdlog::info("laz file to save: '{}'", output_file_name); - - if (output_file_name.size() > 0) - save_scale_board_to_laz(session, output_file_name, 10.0); - } - - ImGui::Separator(); - ImGui::Text("10km x 10km to laz"); - - if (ImGui::MenuItem("> 10m")) - { - const auto output_file_name = mandeye::fd::SaveFileDialog(out_fn.c_str(), mandeye::fd::LAS_LAZ_filter, ".laz"); - spdlog::info("laz file to save: '{}'", output_file_name); - - if (output_file_name.size() > 0) - save_scale_board_to_laz(session, output_file_name, 10.0, 10000.0); - } - - if (ImGui::MenuItem("> 100m")) - { - const auto output_file_name = mandeye::fd::SaveFileDialog(out_fn.c_str(), mandeye::fd::LAS_LAZ_filter, ".laz"); - spdlog::info("laz file to save: '{}'", output_file_name); - - if (output_file_name.size() > 0) - save_scale_board_to_laz(session, output_file_name, 100.0, 10000.0); - } - - if (ImGui::MenuItem("> 1000m")) - { - const auto output_file_name = mandeye::fd::SaveFileDialog(out_fn.c_str(), mandeye::fd::LAS_LAZ_filter, ".laz"); - spdlog::info("laz file to save: '{}'", output_file_name); - - if (output_file_name.size() > 0) - save_scale_board_to_laz(session, output_file_name, 1000.0, 10000.0); - } - - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("GNSS")) - { - ImGui::MenuItem("Load with offset -> move to (0,0,0)", nullptr, &gnssWithOffset); - - if (ImGui::MenuItem("Load GNSS files and convert WGS84 to PUWG92")) - { - std::vector input_file_names; - input_file_names = mandeye::fd::OpenFileDialog("Load gnss files", mandeye::fd::Gnss_filter, true); - - if (input_file_names.size() > 0) - { - Eigen::Vector3d out_offset(0.0, 0.0, 0.0); - if (!tls_registration.gnss.load_data_from_gnss_and_convert_to_92(input_file_names, out_offset, gnssWithOffset)) - { - spdlog::error("Error loading GNSS files!"); - } - else - { - session.point_clouds_container.offset_to_apply = out_offset; - } - } - } - - ImGui::MenuItem("Set WGS84 reference from 1st pose", nullptr, &tls_registration.gnss.setWGS84ReferenceFromFirstPose); - - ImGui::Text("Load & convert WGS84 to Cartesian by Mercator projection"); - - if (ImGui::MenuItem("Load GNSS (deprecated)")) - { - std::vector input_file_names; - input_file_names = mandeye::fd::OpenFileDialog("Load gnss files", mandeye::fd::Gnss_filter, true); - - if (input_file_names.size() > 0) - { - if (!tls_registration.gnss.load_raw_data_from_gnss(input_file_names)) - { - spdlog::error("Error loading GNSS files!"); - } - if (!tls_registration.gnss.project_to_mercator_projection()) - { - spdlog::error("Error converting WGS84 to Mercator projection!"); - } - } - } - if (ImGui::MenuItem("Load GNSS")) - { - std::vector input_file_names; - input_file_names = mandeye::fd::OpenFileDialog("Load gnss files", mandeye::fd::Gnss_filter, true); - - if (input_file_names.size() > 0) - { - if (!tls_registration.gnss.load_raw_data_from_gnss(input_file_names)) - { - spdlog::error("Error loading GNSS files!"); - } - if (!tls_registration.gnss.project_using_proj()) - { - spdlog::error("Error converting WGS84 to PROJ projection!"); - } - } - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Load structured GNSS dataset and decode it into coordinates, using PROJ library"); - - if (ImGui::MenuItem("Load NMEA (deprecated)")) - { - std::vector input_file_names; - input_file_names = mandeye::fd::OpenFileDialog("Load nmea files", mandeye::fd::Nmea_filter, true); - - if (input_file_names.size() > 0) - { - if (!tls_registration.gnss.load_raw_data_from_nmea(input_file_names)) - spdlog::error("Error loading NMEA files!"); - } - if (!tls_registration.gnss.project_to_mercator_projection()) - { - spdlog::error("Error converting WGS84 to Mercator projection!"); - } - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Load raw GNSS serial output and decode it into coordinates"); - if (ImGui::MenuItem("Load NMEA")) - { - std::vector input_file_names; - input_file_names = mandeye::fd::OpenFileDialog("Load nmea files", mandeye::fd::Nmea_filter, true); - - if (input_file_names.size() > 0) - { - if (!tls_registration.gnss.load_raw_data_from_nmea(input_file_names)) - spdlog::error("Error loading NMEA files!"); - } - if (!tls_registration.gnss.project_using_proj()) - { - spdlog::error("Error converting WGS84 to PROJ projection!"); - } - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Load raw GNSS serial output and decode it into coordinates, using PROJ library"); - - ImGui::Separator(); - - if (ImGui::MenuItem("Save GNSS data to las/laz file")) - { - const auto output_file_name = - mandeye::fd::SaveFileDialog("Save las or laz file", mandeye::fd::LAS_LAZ_filter, ".laz"); - spdlog::info("las or laz file to save: '{}'", output_file_name); - - if (output_file_name.size() > 0) - tls_registration.gnss.save_to_laz( - output_file_name, - session.point_clouds_container.offset.x(), - session.point_clouds_container.offset.y(), - session.point_clouds_container.offset.z()); - } - const auto prepareVisibleData = [&]() - { - std::vector pointcloud; - std::vector intensity; - std::vector timestamps; - - for (auto& p : session.point_clouds_container.point_clouds) - { - if (p.visible) - { - for (size_t i = 0; i < p.points_local.size(); i++) - { - const auto& pp = p.points_local[i]; - Eigen::Vector3d vp; - vp = p.m_pose * pp; - - pointcloud.push_back(vp); - if (i < p.intensities.size()) - intensity.push_back(p.intensities[i]); - else - intensity.push_back(0); - if (i < p.timestamps.size()) - timestamps.push_back(p.timestamps[i]); - } - } - } - return std::tuple(pointcloud, intensity, timestamps); - }; - - if (ImGui::MenuItem("Save metascan points in PUWG92(dep!)")) - { - const auto output_file_name = mandeye::fd::SaveFileDialog(out_fn.c_str(), mandeye::fd::LAS_LAZ_filter, ".laz"); - const auto [pointcloud, intensity, timestamps] = prepareVisibleData(); - - const auto lat = tls_registration.gnss.WGS84ReferenceLatitude; - const auto lon = tls_registration.gnss.WGS84ReferenceLongitude; - const auto alt = tls_registration.gnss.gnss_poses[0].alt; - - double Xpuwg92 = 0.0; - double Ypuwg92 = 0.0; - wgs84_do_puwg92(lat, lon, &Xpuwg92, &Ypuwg92); - Eigen::Vector3d offset(Ypuwg92, Xpuwg92, alt); - exportLaz(output_file_name, pointcloud, intensity, timestamps, offset.x(), offset.y(), offset.z()); - } - ImGui::Separator(); - for (const auto& geoid : geoids) - { - if (ImGui::MenuItem(std::string("Set geoid to " + geoid).c_str(), nullptr, selected_geoid_model == geoid)) - { - selected_geoid_model = geoid; - } - } - ImGui::Separator(); - - for (const auto& crtName : CRTs::SupportedCRTs) - { - std::string itemName = "Save metascan points in " + crtName + " (PROJ)"; - if (ImGui::MenuItem(itemName.c_str())) - { - const auto output_file_name = mandeye::fd::SaveFileDialog(out_fn.c_str(), mandeye::fd::LAS_LAZ_filter, ".laz"); - - const auto [pointcloud, intensity, timestamps] = prepareVisibleData(); - const auto lla_points = tls_registration.gnss.unproject_using_proj(pointcloud); - auto crt_points = tls_registration.gnss.CRTConvert(lla_points, crtName, selected_geoid_model); - Eigen::Vector3d offset = crt_points.front(); - for (auto& p : crt_points) - { - p = p - offset; - } - exportLaz(output_file_name, crt_points, intensity, timestamps, offset.x(), offset.y(), offset.z()); - } - } - - for (const auto& crtName : CRTs::SupportedCRTs) - { - std::string itemName = "Save GNSS data to las/laz in " + crtName + " (PROJ)"; - if (ImGui::MenuItem(itemName.c_str())) - { - const auto output_file_name = mandeye::fd::SaveFileDialog(out_fn.c_str(), mandeye::fd::LAS_LAZ_filter, ".laz"); - - std::vector lla_points; - std::vector intensity; - std::vector timestamps; - for (const auto& gnss : tls_registration.gnss.gnss_poses) - { - lla_points.emplace_back(gnss.lat, gnss.lon, gnss.h_wgs84); - intensity.push_back(gnss.hdop); - timestamps.push_back(gnss.timestamp); - } - - auto crt_points = tls_registration.gnss.CRTConvert(lla_points, crtName, selected_geoid_model); - Eigen::Vector3d offset = crt_points.front(); - for (auto& p : crt_points) - { - p = p - offset; - } - exportLaz(output_file_name, crt_points, intensity, timestamps, offset.x(), offset.y(), offset.z()); - } - } - - ImGui::EndMenu(); - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("GNSS (GPS, etc.) related open/save commands"); - - ImGui::EndMenu(); - } - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text("Loaded session:"); - ImGui::Text(std::string(session.session_file_name).c_str()); - ImGui::Separator(); - ImGui::Text("Total number of points: %zu", session_total_number_of_points); - - if (ImGui::BeginTable("Dimensions", 4)) - { - ImGui::TableSetupColumn("Coord [m]"); - ImGui::TableSetupColumn("min"); - ImGui::TableSetupColumn("max"); - ImGui::TableSetupColumn("size"); - ImGui::TableHeadersRow(); - - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - - std::string text = "X"; - float centered = ImGui::GetColumnWidth() - ImGui::CalcTextSize(text.c_str()).x; - // Set cursor so text is centered - ImGui::SetCursorPosX(ImGui::GetCursorPosX() + centered * 0.5f); - - ImGui::Text("X"); - - ImGui::TableSetColumnIndex(1); - ImGui::Text("%.3f", session_dims.x_min); - ImGui::TableSetColumnIndex(2); - ImGui::Text("%.3f", session_dims.x_max); - ImGui::TableSetColumnIndex(3); - ImGui::Text("%.3f", session_dims.length); - - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - ImGui::SetCursorPosX(ImGui::GetCursorPosX() + centered * 0.5f); - ImGui::Text("Y"); - - ImGui::TableSetColumnIndex(1); - ImGui::Text("%.3f", session_dims.y_min); - ImGui::TableSetColumnIndex(2); - ImGui::Text("%.3f", session_dims.y_max); - ImGui::TableSetColumnIndex(3); - ImGui::Text("%.3f", session_dims.width); - - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - ImGui::SetCursorPosX(ImGui::GetCursorPosX() + centered * 0.5f); - ImGui::Text("Z"); - - ImGui::TableSetColumnIndex(1); - ImGui::Text("%.3f", session_dims.z_min); - ImGui::TableSetColumnIndex(2); - ImGui::Text("%.3f", session_dims.z_max); - ImGui::TableSetColumnIndex(3); - ImGui::Text("%.3f", session_dims.height); - - ImGui::EndTable(); - } - - ImGui::EndTooltip(); - } - - if (ImGui::BeginMenu("Tools")) - { - ImGui::MenuItem("Point Cloud Alignment", "Ctrl+A", &is_pca_gui); - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text("Point cloud alignment (registration) algorithms:"); - ImGui::Text( - "(aligning two 3D point sets from LiDAR scans, by estimating\nthe relative pose(translation and rotation) " - "between them)"); - ImGui::Text("- Normal Distributions Transform"); - ImGui::Text("- Iterative Closest Point"); - ImGui::Text("- Registration Plane Feature"); - ImGui::EndTooltip(); - } - ImGui::Separator(); - ImGui::MenuItem("Pose Graph SLAM", "Ctrl+P", &is_pose_graph_slam); - ImGui::MenuItem("Observations", nullptr, &is_manual_analisys); - - ImGui::Separator(); - - ImGui::MenuItem("Control Points", "Ctrl+C", &session.control_points.is_imgui, !session.ground_control_points.is_imgui); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Known reference points used to align or verify the scan"); - - ImGui::MenuItem( - "Ground Control Points", "Ctrl+G", &session.ground_control_points.is_imgui, !session.control_points.is_imgui); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Accurate real-world points used to georeference the scan"); - - ImGui::MenuItem("Manual Loop Closure", "Ctrl+L", &is_loop_closure_gui, !is_lio_segments_gui); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Manually connect overlapping scan sections"); - - ImGui::Separator(); - ImGui::MenuItem("LIO segments editor", "Ctrl+E", &is_lio_segments_gui, !is_loop_closure_gui); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Manually adjust or review Lidar Inertial Odometry trajectory segments"); - - ImGui::Separator(); - ImGui::MenuItem("Translate", nullptr, &is_translate_gui); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Define new coordinate frame from 3 picked points and transform all clouds"); - - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("Intersections")) - { - ImGui::SetNextItemWidth(ImGuiNumberWidth); - ImGui::InputDouble("Intersection width [m]", &session.point_clouds_container.intersection_width, 0.0, 0.0, "%.2f"); - if (session.point_clouds_container.intersection_width < 0.001) - session.point_clouds_container.intersection_width = 0.001; - - ImGui::Separator(); - - ImGui::MenuItem("xz_intersection", nullptr, &session.point_clouds_container.xz_intersection); - ImGui::MenuItem("10m grid##xz", nullptr, &session.point_clouds_container.xz_grid_10x10); - ImGui::MenuItem("1m grid##xz", nullptr, &session.point_clouds_container.xz_grid_1x1); - ImGui::MenuItem("0.1m grid##xz", nullptr, &session.point_clouds_container.xz_grid_01x01); - - if (ImGui::MenuItem("Export xz intersection", nullptr, false, session.point_clouds_container.xz_intersection)) - { - const auto output_file_name = mandeye::fd::SaveFileDialog(out_fn.c_str(), mandeye::fd::LAS_LAZ_filter, ".laz"); - spdlog::info("laz file to save: '{}'", output_file_name); - - if (output_file_name.size() > 0) - { - save_intersection( - session, - output_file_name, - /*xz_intersection=*/true, - /*yz_intersection=*/false, - /*xy_intersection=*/false, - session.point_clouds_container.intersection_width); - } - } - - ImGui::Separator(); - - ImGui::MenuItem("yz_intersection", nullptr, &session.point_clouds_container.yz_intersection); - ImGui::MenuItem("10m grid##yz", nullptr, &session.point_clouds_container.yz_grid_10x10); - ImGui::MenuItem("1m grid##yz", nullptr, &session.point_clouds_container.yz_grid_1x1); - ImGui::MenuItem("0.1m grid##yz", nullptr, &session.point_clouds_container.yz_grid_01x01); - - if (ImGui::MenuItem("Export yz intersection", nullptr, false, session.point_clouds_container.yz_intersection)) - { - const auto output_file_name = mandeye::fd::SaveFileDialog(out_fn.c_str(), mandeye::fd::LAS_LAZ_filter, ".laz"); - spdlog::info("laz file to save: '{}'", output_file_name); - - if (output_file_name.size() > 0) - { - save_intersection( - session, - output_file_name, - /*xz_intersection=*/false, - /*yz_intersection=*/true, - /*xy_intersection=*/false, - session.point_clouds_container.intersection_width); - } - } - - ImGui::Separator(); - - ImGui::MenuItem("xy_intersection", nullptr, &session.point_clouds_container.xy_intersection); - ImGui::MenuItem("10m grid##xy", nullptr, &session.point_clouds_container.xy_grid_10x10); - ImGui::MenuItem("1m grid##xy", nullptr, &session.point_clouds_container.xy_grid_1x1); - ImGui::MenuItem("0.1m grid##xy", nullptr, &session.point_clouds_container.xy_grid_01x01); - - if (ImGui::MenuItem("Export xy intersection", nullptr, false, session.point_clouds_container.xy_intersection)) - { - const auto output_file_name = mandeye::fd::SaveFileDialog(out_fn.c_str(), mandeye::fd::LAS_LAZ_filter, ".laz"); - spdlog::info("laz file to save: '{}'", output_file_name); - - if (output_file_name.size() > 0) - { - save_intersection( - session, - output_file_name, - /*xz_intersection=*/false, - /*yz_intersection=*/false, - /*xy_intersection=*/true, - session.point_clouds_container.intersection_width); - } - } - - ImGui::EndMenu(); - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Intersection menu"); - } - - if (ImGui::BeginMenu("View")) - { - ImGui::BeginDisabled(!session_loaded); - { - if (ImGui::BeginMenu("Point cloud")) - { - auto tmp = point_size; - ImGui::SetNextItemWidth(ImGuiNumberWidth); - ImGui::InputInt("Points size", &point_size); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("keyboard 1-9 keys"); - if (point_size < 1) - point_size = 1; - else if (point_size > 10) - point_size = 10; - - if (tmp != point_size) - for (auto& point_cloud : session.point_clouds_container.point_clouds) - point_cloud.point_size = point_size; - - ImGui::Separator(); - - ImGui::Text("Color:"); - - float color[3]; - if (session_loaded) - { - color[0] = session.point_clouds_container.point_clouds[0].render_color[0]; - color[1] = session.point_clouds_container.point_clouds[0].render_color[1]; - color[2] = session.point_clouds_container.point_clouds[0].render_color[2]; - } - - if (ImGui::ColorEdit3("", (float*)&color, ImGuiColorEditFlags_NoInputs)) - { - csPointCloud = CS_SOLID; - - for (auto& pc : session.point_clouds_container.point_clouds) - { - pc.render_color[0] = color[0]; - pc.render_color[1] = color[1]; - pc.render_color[2] = color[2]; - - if (csTrajectory == CS_FOLLOW) - { - pc.traj_color[0] = pc.render_color[0]; - pc.traj_color[1] = pc.render_color[1]; - pc.traj_color[2] = pc.render_color[2]; - } - } - } - ImGui::SameLine(); - if (ImGui::MenuItem("> Solid", nullptr, (csPointCloud == CS_SOLID))) - csPointCloud = CS_SOLID; - - if (ImGui::MenuItem("> Random per segment", "Ctrl+R", (csPointCloud == CS_RANDOM))) - { - csPointCloud = CS_RANDOM; - - 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; - - if (csTrajectory == CS_FOLLOW) - { - pc.traj_color[0] = pc.render_color[0]; - pc.traj_color[1] = pc.render_color[1]; - pc.traj_color[2] = pc.render_color[2]; - } - } - } - - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("Trajectory")) - { - if (session_loaded) - { - auto tmp = session.point_clouds_container.point_clouds[0].line_width; - - ImGui::BeginDisabled(!glLineWidthSupport); - { - ImGui::SetNextItemWidth(ImGuiNumberWidth); - ImGui::InputInt("Line width", &tmp); - } - ImGui::EndDisabled(); - - if (tmp < 0) - tmp = 0; - else if (tmp > 5) - tmp = 5; - - if (tmp != session.point_clouds_container.point_clouds[0].line_width) - for (auto& point_cloud : session.point_clouds_container.point_clouds) - point_cloud.line_width = tmp; - } - - ImGui::MenuItem("Show IMU to LIO difference", nullptr, &session.point_clouds_container.show_imu_to_lio_diff); - if (session.point_clouds_container.show_imu_to_lio_diff) - { - ImGui::SetNextItemWidth(ImGuiNumberWidth); - ImGui::InputFloat( - "IMU to LIO diff scale", &session.point_clouds_container.imu_to_lio_diff_scale, 1.0f, 10.0f, "%.1f"); - if (session.point_clouds_container.imu_to_lio_diff_scale < 0.0f) - session.point_clouds_container.imu_to_lio_diff_scale = 0.0f; - } - - ImGui::Separator(); - - ImGui::Text("Color:"); - - float color[3]; - if (session_loaded) - { - color[0] = session.point_clouds_container.point_clouds[0].traj_color[0]; - color[1] = session.point_clouds_container.point_clouds[0].traj_color[1]; - color[2] = session.point_clouds_container.point_clouds[0].traj_color[2]; - } - - if (ImGui::ColorEdit3("", (float*)&color, ImGuiColorEditFlags_NoInputs)) - { - csTrajectory = CS_SOLID; - - for (auto& pc : session.point_clouds_container.point_clouds) - { - pc.traj_color[0] = color[0]; - pc.traj_color[1] = color[1]; - pc.traj_color[2] = color[2]; - } - } - ImGui::SameLine(); - if (ImGui::MenuItem("> Solid", nullptr, (csTrajectory == CS_SOLID))) - csTrajectory = CS_SOLID; - - if (ImGui::MenuItem("> Random per segment", nullptr, (csTrajectory == CS_RANDOM))) - { - csTrajectory = CS_RANDOM; - - for (auto& pc : session.point_clouds_container.point_clouds) - { - pc.traj_color[0] = float(rand() % 255) / 255.0f; - pc.traj_color[1] = float(rand() % 255) / 255.0f; - pc.traj_color[2] = float(rand() % 255) / 255.0f; - } - } - - if (ImGui::MenuItem("> Follow cloud color", nullptr, (csTrajectory == CS_FOLLOW))) - { - csTrajectory = CS_FOLLOW; - - for (auto& pc : session.point_clouds_container.point_clouds) - { - pc.traj_color[0] = pc.render_color[0]; - pc.traj_color[1] = pc.render_color[1]; - pc.traj_color[2] = pc.render_color[2]; - } - } - - ImGui::EndMenu(); - } - - ImGui::ColorEdit3("Background color", (float*)&bg_color, ImGuiColorEditFlags_NoInputs); - - ImGui::BeginDisabled(tls_registration.gnss.gnss_poses.size() <= 0); - { - ImGui::MenuItem("Show GNSS correspondences", nullptr, &tls_registration.gnss.show_correspondences); - } - ImGui::EndDisabled(); - - ImGui::Separator(); - } - ImGui::EndDisabled(); - - if (ImGui::MenuItem("Orthographic", "key O", &is_ortho)) - { - 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)"); - - ImGui::MenuItem("Show axes", "key X", &show_axes); - ImGui::MenuItem("Show compass/ruler", "key C", &compass_ruler); - - ImGui::MenuItem("Lock Z", "Shift + Z", &lock_z, !is_ortho); - - ImGui::Separator(); - - ImGui::MenuItem("Settings", nullptr, &is_settings_gui); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Show power user settings window with more parameters"); - - if (ImGui::BeginMenu("Console")) - { -#ifdef _WIN32 - if (ImGui::MenuItem("Use Windows console", nullptr, &consWin)) - { - if (consWin) - { - AllocConsole(); - freopen("CONOUT$", "w", stdout); - freopen("CONOUT$", "w", stderr); - freopen("CONIN$", "r", stdin); - } - else - FreeConsole(); - } - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text("!!! If not used.. !!!"); - ImGui::Text("- old console output is lost"); - ImGui::Text("- new console output can only be seen in subwindow"); - ImGui::Text("- app might run faster"); - ImGui::EndTooltip(); - } -#endif - // ImGui::MenuItem("Subwindow", nullptr, &consImGui); - // if (ImGui::IsItemHovered()) - // ImGui::SetTooltip("Show/hide console output as GUI window"); - - ImGui::EndMenu(); - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Control console output"); - - ImGui::EndMenu(); - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Scene view relevant parameters"); - - camMenu(); - - ImGui::BeginDisabled(session.point_clouds_container.point_clouds.size() <= 0); - { - ImGui::SameLine(); - ImGui::Dummy(ImVec2(20, 0)); - ImGui::SameLine(); - - ImGui::SetNextItemWidth(ImGuiNumberWidth); - ImGui::InputInt("Points render downsampling", &viewer_decimate_point_cloud, 10, 100); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("increase for better performance, decrease for rendering more points"); - ImGui::SameLine(); - - // fps_avg = fps_avg * 0.7f + ImGui::GetIO().Framerate * 0.3f; // exponential smoothing - - // double now = ImGui::GetTime(); // ImGui’s built-in timer (in seconds) - - // ImGui::Checkbox("dynamic", &dynamicSubsampling); - // if (ImGui::IsItemHovered()) - // ImGui::SetTooltip("automatically control subsampling vs FPS: increase bellow 10, decrease above 60"); - // if (dynamicSubsampling && (fps_avg < 15) && (now - lastAdjustTime > cooldownSeconds)) - //{ - // viewer_decimate_point_cloud += 1; - // lastAdjustTime = now; - //} - // ImGui::SameLine(); - // ImGui::Text("(avg %.1f)", fps_avg); - - if (viewer_decimate_point_cloud < 1) - viewer_decimate_point_cloud = 1; - - ImGui::SameLine(); - ImGui::Text("(%.1f FPS)", ImGui::GetIO().Framerate); - } - ImGui::EndDisabled(); - - ImGui::SameLine( - ImGui::GetWindowWidth() - ImGui::CalcTextSize("Info").x - ImGui::GetStyle().ItemSpacing.x * 2 - - ImGui::GetStyle().FramePadding.x * 2); - - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(4, 2)); - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::GetStyleColorVec4(ImGuiCol_HeaderHovered)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImGui::GetStyleColorVec4(ImGuiCol_Header)); - - if (ImGui::SmallButton("Info")) - info_gui = !info_gui; - - ImGui::PopStyleVar(2); - ImGui::PopStyleColor(3); - - ImGui::EndMainMenuBar(); - } - - if (is_settings_gui) - settings_gui(); - - // my_display_code(); - - if (is_pca_gui) - pca_gui(); - - if (is_pose_graph_slam) - pose_graph_slam_gui(); - - if (is_manual_analisys) - observation_picking_gui(); - - if (is_loop_closure_gui) - loop_closure_gui(); - - if (is_lio_segments_gui) - lio_segments_gui(); - - if (is_translate_gui) - { - translate_gui(); - } - else if (translate_tool.step != TranslateTool::Step::Idle) - { - translate_tool.step = TranslateTool::Step::Idle; - translate_tool.has_transform = false; - translate_tool.transform = Eigen::Affine3d::Identity(); - glutSetCursor(GLUT_CURSOR_INHERIT); - } - - cor_window(); - - info_window(infoLines, appShortcuts); - - draw_translate_preview(); - - if (compass_ruler) - drawMiniCompassWithRuler(); - - ImGui::Render(); - ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData()); - - glutSwapBuffers(); - glutPostRedisplay(); -} - -void draw_translate_preview() -{ - if (translate_tool.step != TranslateTool::Step::PickXAxis && translate_tool.step != TranslateTool::Step::PickYHint) - return; - - ImGuiIO& io = ImGui::GetIO(); - if (io.WantCaptureMouse) - return; - - const auto laser_beam = GetLaserBeam((int)io.MousePos.x, (int)io.MousePos.y); - RegistrationPlaneFeature::Plane pl; - pl.a = 0; - pl.b = 0; - pl.c = 1; - pl.d = -translate_tool.plane_z; - Eigen::Vector3d cursor_world = rayIntersection(laser_beam, pl); - - const Eigen::Vector3d O = translate_tool.origin; - - Eigen::Vector3d x_dir; - if (translate_tool.step == TranslateTool::Step::PickXAxis) - x_dir = cursor_world - O; - else - x_dir = translate_tool.x_point - O; - x_dir.z() = 0.0; - if (x_dir.norm() < 1e-9) - return; - double x_len = x_dir.norm(); - Eigen::Vector3d x_n = x_dir / x_len; - Eigen::Vector3d y_n(-x_n.y(), x_n.x(), 0.0); - - if (translate_tool.step == TranslateTool::Step::PickYHint) - { - Eigen::Vector3d v = cursor_world - O; - if (v.dot(y_n) < 0.0) - y_n = -y_n; - } - - double y_len = x_len * 0.5; - double z_len = x_len * 0.25; - - glLineWidth(3.0f); - glBegin(GL_LINES); - glColor3f(1.0f, 0.0f, 0.0f); - glVertex3d(O.x(), O.y(), O.z()); - glVertex3d(O.x() + x_n.x() * x_len, O.y() + x_n.y() * x_len, O.z()); - - glColor3f(0.0f, 1.0f, 0.0f); - glVertex3d(O.x(), O.y(), O.z()); - glVertex3d(O.x() + y_n.x() * y_len, O.y() + y_n.y() * y_len, O.z()); - - glColor3f(0.0f, 0.0f, 1.0f); - glVertex3d(O.x(), O.y(), O.z()); - glVertex3d(O.x(), O.y(), O.z() + z_len); - glEnd(); - glLineWidth(1.0f); -} - -Eigen::Affine3d compute_translate_matrix(const Eigen::Vector3d& O, const Eigen::Vector3d& X, const Eigen::Vector3d& Y_hint) -{ - Eigen::Vector3d dx = X - O; - dx.z() = 0.0; - if (dx.norm() < 1e-9) - return Eigen::Affine3d::Identity(); - dx.normalize(); - - double theta = -std::atan2(dx.y(), dx.x()); - - Eigen::Affine3d T = Eigen::Affine3d::Identity(); - T.prerotate(Eigen::AngleAxisd(theta, Eigen::Vector3d::UnitZ())); - T.pretranslate(-(T.linear() * O)); - - Eigen::Vector3d y_h_new = T * Y_hint; - if (y_h_new.y() < 0.0) - { - Eigen::Affine3d flip = Eigen::Affine3d::Identity(); - Eigen::Matrix3d R; - R << 1, 0, 0, 0, -1, 0, 0, 0, -1; - flip.linear() = R; - T = flip * T; - } - return T; -} - -void translate_gui() -{ - ImGui::Begin("Translate", &is_translate_gui); - - ImGui::PushItemWidth(ImGuiNumberWidth); - ImGui::InputFloat("Plane Z [m]", &translate_tool.plane_z); - ImGui::PopItemWidth(); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Height of the horizontal pick plane used to project mouse clicks into 3D"); - - if (ImGui::Button("Start picking")) - { - translate_tool.step = TranslateTool::Step::PickOrigin; - translate_tool.has_transform = false; - translate_tool.transform = Eigen::Affine3d::Identity(); - - is_ortho = true; - 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; - - glutSetCursor(GLUT_CURSOR_CROSSHAIR); - } - ImGui::SameLine(); - if (ImGui::Button("Reset")) - { - translate_tool.step = TranslateTool::Step::Idle; - translate_tool.has_transform = false; - translate_tool.transform = Eigen::Affine3d::Identity(); - glutSetCursor(GLUT_CURSOR_INHERIT); - } - - const char* step_text = "Idle"; - switch (translate_tool.step) - { - case TranslateTool::Step::PickOrigin: - step_text = "Pick origin (new 0,0)"; - break; - case TranslateTool::Step::PickXAxis: - step_text = "Pick point on +X axis"; - break; - case TranslateTool::Step::PickYHint: - step_text = "Pick point on +Y side"; - break; - case TranslateTool::Step::Ready: - step_text = "Ready - press Translate"; - break; - default: - break; - } - ImGui::Text("Step: %s", step_text); - - ImGui::Text("Origin : %.3f %.3f %.3f", translate_tool.origin.x(), translate_tool.origin.y(), translate_tool.origin.z()); - ImGui::Text("X point: %.3f %.3f %.3f", translate_tool.x_point.x(), translate_tool.x_point.y(), translate_tool.x_point.z()); - ImGui::Text("Y hint : %.3f %.3f %.3f", translate_tool.y_hint.x(), translate_tool.y_hint.y(), translate_tool.y_hint.z()); - - if (translate_tool.has_transform) - { - ImGui::Separator(); - ImGui::Text("Transformation matrix:"); - const Eigen::Matrix4d M = translate_tool.transform.matrix(); - for (int r = 0; r < 4; r++) - ImGui::Text("%8.4f %8.4f %8.4f %8.4f", M(r, 0), M(r, 1), M(r, 2), M(r, 3)); - } - - ImGui::Separator(); - ImGui::BeginDisabled(!translate_tool.has_transform); - { - if (ImGui::Button("Translate")) - { - for (auto& pc : session.point_clouds_container.point_clouds) - pc.m_pose = translate_tool.transform * pc.m_pose; - - for (auto& cp : session.control_points.cps) - { - Eigen::Vector3d g(cp.x_target_global, cp.y_target_global, cp.z_target_global); - g = translate_tool.transform * g; - cp.x_target_global = g.x(); - cp.y_target_global = g.y(); - cp.z_target_global = g.z(); - } - - translate_tool.step = TranslateTool::Step::Idle; - translate_tool.has_transform = false; - translate_tool.transform = Eigen::Affine3d::Identity(); - glutSetCursor(GLUT_CURSOR_INHERIT); - } - } - ImGui::EndDisabled(); - - ImGui::End(); -} - -Eigen::Vector3d GLWidgetGetOGLPos(int x, int y, const ObservationPicking& observation_picking) -{ - const auto laser_beam = GetLaserBeam(x, y); - - RegistrationPlaneFeature::Plane pl; - - pl.a = 0; - pl.b = 0; - pl.c = 1; - pl.d = -observation_picking.picking_plane_height; - - Eigen::Vector3d pos = rayIntersection(laser_beam, pl); - - spdlog::info("intersection: {}, {}, {}", pos.x(), pos.y(), pos.z()); - - return pos; -} - -void mouse(int glut_button, int state, int x, int y) -{ - ImGuiIO& io = ImGui::GetIO(); - io.MousePos = ImVec2((float)x, (float)y); - - int button = -1; - if (glut_button == GLUT_LEFT_BUTTON) - button = 0; - if (glut_button == GLUT_RIGHT_BUTTON) - button = 1; - if (glut_button == GLUT_MIDDLE_BUTTON) - button = 2; - if (button != -1 && state == GLUT_DOWN) - io.MouseDown[button] = true; - if (button != -1 && state == GLUT_UP) - io.MouseDown[button] = false; - - static int glutMajorVersion = glutGet(GLUT_VERSION) / 10000; - if (state == GLUT_DOWN && (glut_button == 3 || glut_button == 4) && glutMajorVersion < 3) - wheel(glut_button, glut_button == 3 ? 1 : -1, x, y); - - if (!io.WantCaptureMouse) - { - if (glut_button == GLUT_LEFT_BUTTON && state == GLUT_DOWN && !io.KeyCtrl && !io.KeyShift && - translate_tool.step != TranslateTool::Step::Idle && translate_tool.step != TranslateTool::Step::Ready) - { - const auto laser_beam = GetLaserBeam(x, y); - RegistrationPlaneFeature::Plane pl; - pl.a = 0; - pl.b = 0; - pl.c = 1; - pl.d = -translate_tool.plane_z; - Eigen::Vector3d p = rayIntersection(laser_beam, pl); - - switch (translate_tool.step) - { - case TranslateTool::Step::PickOrigin: - translate_tool.origin = p; - translate_tool.step = TranslateTool::Step::PickXAxis; - break; - case TranslateTool::Step::PickXAxis: - translate_tool.x_point = p; - translate_tool.step = TranslateTool::Step::PickYHint; - break; - case TranslateTool::Step::PickYHint: - translate_tool.y_hint = p; - translate_tool.transform = compute_translate_matrix(translate_tool.origin, translate_tool.x_point, translate_tool.y_hint); - translate_tool.has_transform = true; - translate_tool.step = TranslateTool::Step::Ready; - break; - default: - break; - } - - mouse_old_x = x; - mouse_old_y = y; - return; - } - - if ((glut_button == GLUT_MIDDLE_BUTTON || glut_button == GLUT_LEFT_BUTTON) && state == GLUT_DOWN && (io.KeyCtrl || io.KeyShift)) - { - if (session.ground_control_points.is_imgui) - { - spdlog::info("GCP picking"); - int tmp; - getClosestTrajectoryPoint(session, x, y, true, tmp); - } - else if (session.control_points.is_imgui) - { - spdlog::info("Control point picking"); - const auto laser_beam = GetLaserBeam(x, y); - double min_distance = std::numeric_limits::max(); - - session.control_points.index_picked_point = -1; - - int i = session.control_points.index_pose; - if (session.control_points.index_pose >= 0 && - session.control_points.index_pose < session.point_clouds_container.point_clouds.size()) - { - for (size_t j = 0; j < session.point_clouds_container.point_clouds[i].points_local.size(); j++) - { - const auto& p = session.point_clouds_container.point_clouds[i].points_local[j]; - Eigen::Vector3d vp = session.point_clouds_container.point_clouds[i].m_pose * p; - - double dist = distance_point_to_line(vp, laser_beam); - - if (dist < min_distance && dist < 0.1) - { - min_distance = dist; - - new_rotation_center.x() = vp.x(); - new_rotation_center.y() = vp.y(); - new_rotation_center.z() = vp.z(); - - session.control_points.index_picked_point = j; - } - } - - new_rotate_x = rotate_x; - new_rotate_y = rotate_y; - new_translate_x = -new_rotation_center.x(); - new_translate_y = -new_rotation_center.y(); - new_translate_z = translate_z; - camera_transition_active = true; - } - } - else - { - if (glut_button == GLUT_MIDDLE_BUTTON) - if (session_loaded) - { - int tmp = -1; - getClosestTrajectoryPoint(session, x, y, false, tmp); - - if (io.KeyCtrl) - { - if (tmp != -1) - index_loop_closure_target = tmp; - } - else if (io.KeyShift) - { - if (tmp != -1) - index_loop_closure_source = tmp; - } - } - else - setNewRotationCenter(x, y); - } - } - - if (glut_button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN && io.KeyCtrl) - { - int tmp; - if (session_loaded) - getClosestTrajectoryPoint(session, x, y, false, tmp); - else - setNewRotationCenter(x, y); - } - - if (state == GLUT_DOWN) - { - mouse_buttons |= 1 << glut_button; - - if (observation_picking.is_observation_picking_mode) - { - Eigen::Vector3d p = GLWidgetGetOGLPos(x, y, observation_picking); - int number_active_pcs = 0; - int index_picked = -1; - for (size_t i = 0; i < session.point_clouds_container.point_clouds.size(); i++) - { - if (session.point_clouds_container.point_clouds[i].visible) - { - number_active_pcs++; - index_picked = i; - } - } - if (number_active_pcs == 1) - observation_picking.add_picked_to_current_observation(index_picked, p); - } - } - else if (state == GLUT_UP) - mouse_buttons = 0; - - mouse_old_x = x; - mouse_old_y = y; - } -} - -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; - } - - // search for available geoid models in the system and populate the menu - geoids = GNSS::get_available_geoids(); - - 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" || ext == ".json") - { - loadSession(argv[i]); - - break; - } - } - } - - glutMainLoop(); - - ImGui_ImplOpenGL2_Shutdown(); - ImGui_ImplGLUT_Shutdown(); - ImGui::DestroyContext(); - } catch (const std::bad_alloc& e) - { - spdlog::error("System is out of memory : {}", e.what()); - mandeye::fd::OutOfMemMessage(); - } catch (const std::exception& e) - { - spdlog::error(e.what()); - } catch (...) - { - spdlog::error("Unknown fatal error occurred!"); - } - - return 0; -} \ No newline at end of file diff --git a/apps/multi_view_tls_registration_legacy/perform_experiment.cpp b/apps/multi_view_tls_registration_legacy/perform_experiment.cpp deleted file mode 100644 index 3d09d804..00000000 --- a/apps/multi_view_tls_registration_legacy/perform_experiment.cpp +++ /dev/null @@ -1,2428 +0,0 @@ -#include -#include -#include -#include - -// clang-format off -#include -#include -// clang-format on - -#include -#include -#include -#include - -#include - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include - -namespace fs = std::filesystem; - -void export_result_to_folder(std::string output_folder_name, ObservationPicking& observation_picking, Session& session) -{ - fs::path path(output_folder_name); - std::string file_name_rms = "rms.csv"; - auto path_rms = path; - path_rms /= file_name_rms; - std::cout << "exporting to file: '" << path_rms.string() << "'" << std::endl; - std::ofstream outfile_rms; - outfile_rms.open(path_rms, std::ios_base::app); - outfile_rms << "index_roi, rms_initial, rms_result" << std::endl; - - for (int i = 0; i < observation_picking.intersections.size(); i++) - { - std::string file_name_initial = "intersection_" + std::to_string(i) + "_initial.csv"; - std::string file_name_result = "intersection_" + std::to_string(i) + "_result.csv"; - - auto path_initial = path; - auto path_result = path; - - path_initial /= file_name_initial; - path_result /= file_name_result; - - std::cout << "exporting to file: '" << path_initial.string() << "'" << std::endl; - std::cout << "exporting to file: '" << path_result.string() << "'" << std::endl; - - std::ofstream outfile_initial; - std::ofstream outfile_result; - - outfile_initial.open(path_initial, std::ios_base::app); - outfile_result.open(path_result, std::ios_base::app); - - const auto& intersection = observation_picking.intersections[i]; - TaitBryanPose pose; - pose.px = intersection.translation[0]; - pose.py = intersection.translation[1]; - pose.pz = intersection.translation[2]; - pose.om = intersection.rotation[0]; - pose.fi = intersection.rotation[1]; - pose.ka = intersection.rotation[2]; - Eigen::Affine3d m_pose_inv = affine_matrix_from_pose_tait_bryan(pose).inverse(); - - double w = intersection.width_length_height[0] * 0.5; - double l = intersection.width_length_height[1] * 0.5; - double h = intersection.width_length_height[2] * 0.5; - - outfile_initial << "x;y;z;pc_index;is_initial;index_intersection;file" << std::endl; - outfile_result << "x;y;z;pc_index;is_initial;index_intersection;file" << std::endl; - - for (int pc_index = 0; pc_index < session.point_clouds_container.point_clouds.size(); pc_index++) - { - const auto& pc = session.point_clouds_container.point_clouds[pc_index]; - for (const auto& p : pc.points_local) - { - Eigen::Vector3d vpi = pc.m_initial_pose * p; - Eigen::Vector3d vpr = pc.m_pose * p; - - Eigen::Vector3d vpit = m_pose_inv * vpi; - Eigen::Vector3d vprt = m_pose_inv * vpr; - - if (fabs(vpit.x()) < w) - { - if (fabs(vpit.y()) < l) - { - if (fabs(vpit.z()) < h) - { - outfile_initial << vpit.x() << ";" << vpit.y() << ";" << vpit.z() << ";" << pc_index << ";1;" << i << ";" - << pc.file_name << std::endl; - } - } - } - if (fabs(vprt.x()) < w) - { - if (fabs(vprt.y()) < l) - { - if (fabs(vprt.z()) < h) - { - outfile_result << vprt.x() << ";" << vprt.y() << ";" << vprt.z() << ";" << pc_index << ";0;" << i << ";" - << pc.file_name << std::endl; - } - } - } - } - } - outfile_initial.close(); - outfile_result.close(); - - const auto& obs = observation_picking.observations[i]; - double rms_initial = 0.0; - int sum = 0; - double rms_result = 0.0; - - for (const auto& [key1, value1] : obs) - { - for (const auto& [key2, value2] : obs) - { - if (key1 != key2) - { - Eigen::Vector3d p1, p2; - p1 = session.point_clouds_container.point_clouds[key1].m_initial_pose * value1; - p2 = session.point_clouds_container.point_clouds[key2].m_initial_pose * value2; - rms_initial += (p2.x() - p1.x()) * (p2.x() - p1.x()); - rms_initial += (p2.y() - p1.y()) * (p2.y() - p1.y()); - - p1 = session.point_clouds_container.point_clouds[key1].m_pose * value1; - p2 = session.point_clouds_container.point_clouds[key2].m_pose * value2; - rms_result += (p2.x() - p1.x()) * (p2.x() - p1.x()); - rms_result += (p2.y() - p1.y()) * (p2.y() - p1.y()); - - sum += 2; - } - } - } - std::cout << "sum: " << sum << std::endl; - if (sum > 0) - { - rms_initial = sqrt(rms_initial / sum); - rms_result = sqrt(rms_result / sum); - outfile_rms << i << ";" << rms_initial << ";" << rms_result << std::endl; - } - } - outfile_rms.close(); - - std::string file_name_poses = "poses_RESSO.reg"; - auto path_poses = path; - path_poses /= file_name_poses; - std::cout << "saving poses to: " << path_poses << std::endl; - session.point_clouds_container.save_poses(path_poses.string(), false); -} - -void export_result_to_folder(std::string output_folder_name, int method_id, ObservationPicking& observation_picking, Session& session) -{ - fs::path path(output_folder_name); - path /= std::to_string(method_id); - create_directory(path); - export_result_to_folder(path.string(), observation_picking, session); -} - -template -void append_to_result_file( - std::string file_name, std::string method, const T& t, float rms, int id_method, std::chrono::milliseconds elapsed) -{ - std::ofstream outfile; - outfile.open(file_name, std::ios_base::app); - outfile << method << ";" << id_method << ";" << int(t.is_gauss_newton) << ";" << int(t.is_levenberg_marguardt) << ";" << int(t.is_wc) - << ";" << int(t.is_cw) << ";" << int(t.is_tait_bryan_angles) << ";" << int(t.is_quaternion) << ";" << int(t.is_rodrigues) << ";" - << int(t.is_lie_algebra_left_jacobian) << ";" << int(t.is_lie_algebra_right_jacobian) << ";" << rms << ";" << elapsed.count() - << std::endl; - outfile.close(); -} - -void create_header(std::string file_name) -{ - std::ofstream outfile; - outfile.open(file_name); - outfile << "method;id_method;gauss_newton;levenberg_marguardt;wc;cw;tait_bryan_angles;quaternion;rodrigues;Lie_algebra_left_jacobian;" - "Lie_algebra_right_jacobian;rms;elapsed_time_miliseconds" - << std::endl; - outfile.close(); -} - -void add_initial_rms_to_file(std::string file_name, float rms) -{ - std::ofstream outfile; - outfile.open(file_name, std::ios_base::app); - // outfile << - // "method;is_gauss_newton;is_levenberg_marguardt;is_wc;is_cw;is_tait_bryan_angles;is_quaternion;is_rodrigues;is_Lie_algebra_left;Lie_algebra_right;rms;elapsed_time_miliseconds" - // << std::endl; - outfile << "initial_rms;0;0;0;0;0;0;0;0;0;0;" << rms << ";0" << std::endl; - outfile.close(); -} - -void reset_poses(Session& session) -{ - for (size_t i = 0; i < session.point_clouds_container.point_clouds.size(); i++) - { - session.point_clouds_container.point_clouds[i].m_pose = session.point_clouds_container.point_clouds[i].m_initial_pose; - session.point_clouds_container.point_clouds[i].pose = - pose_tait_bryan_from_affine_matrix(session.point_clouds_container.point_clouds[i].m_pose); - session.point_clouds_container.point_clouds[i].gui_translation[0] = (float)session.point_clouds_container.point_clouds[i].pose.px; - session.point_clouds_container.point_clouds[i].gui_translation[1] = (float)session.point_clouds_container.point_clouds[i].pose.py; - session.point_clouds_container.point_clouds[i].gui_translation[2] = (float)session.point_clouds_container.point_clouds[i].pose.pz; - session.point_clouds_container.point_clouds[i].gui_rotation[0] = - (float)rad2deg(session.point_clouds_container.point_clouds[i].pose.om); - session.point_clouds_container.point_clouds[i].gui_rotation[1] = - (float)rad2deg(session.point_clouds_container.point_clouds[i].pose.fi); - session.point_clouds_container.point_clouds[i].gui_rotation[2] = - (float)rad2deg(session.point_clouds_container.point_clouds[i].pose.ka); - } -} - -double compute_rms(bool initial, Session& session, ObservationPicking& observation_picking) -{ - double rms = 0.0; - int sum = 0; - for (const auto& obs : observation_picking.observations) - { - for (const auto& [key1, value1] : obs) - { - for (const auto& [key2, value2] : obs) - { - if (key1 != key2) - { - Eigen::Vector3d p1, p2; - if (initial) - { - p1 = session.point_clouds_container.point_clouds[key1].m_initial_pose * value1; - p2 = session.point_clouds_container.point_clouds[key2].m_initial_pose * value2; - } - else - { - p1 = session.point_clouds_container.point_clouds[key1].m_pose * value1; - p2 = session.point_clouds_container.point_clouds[key2].m_pose * value2; - } - rms += (p2.x() - p1.x()) * (p2.x() - p1.x()); - sum++; - rms += (p2.y() - p1.y()) * (p2.y() - p1.y()); - sum++; - } - } - } - } - if (sum == 0) - { - std::cout << "sum == 0" << std::endl; - return -1; - } - else - { - rms = sqrt(rms / sum); - return rms; - } -} - -void perform_experiment_on_windows( - Session& session, - ObservationPicking& observation_picking, - ICP& icp, - NDT& ndt, - RegistrationPlaneFeature& registration_plane_feature, - PoseGraphSLAM& pose_graph_slam) -{ - bool compute_mean_and_cov_for_bucket = false; - session.point_clouds_container.show_with_initial_pose = false; - auto temp_data = session.point_clouds_container; - reset_poses(session); - double rms = 0.0f; - std::string result_file = session.working_directory + "/result_win.csv"; - float search_radius = 0.1f; - int number_of_threads = 16; - int number_of_iterations = 6; - int id_method = 0; - - create_header(result_file); - double initial_rms = compute_rms(false, session, observation_picking); - std::cout << "initial rms: " << initial_rms << std::endl; - add_initial_rms_to_file(result_file, initial_rms); - - // void export_result_to_folder(std::string output_folder_name, int method_id) { - // fs::path path(output_folder_name); - // path /= std::to_string(method_id); - // create_directory(path); - // export_result_to_folder(path.string()); - // } - - fs::path path_result(session.working_directory); - path_result /= "results_win"; - create_directory(path_result); - - //--0-- - icp.is_adaptive_robust_kernel = false; - icp.is_fix_first_node = false; - icp.search_radius = search_radius; - icp.number_of_threads = number_of_threads; - icp.number_of_iterations = number_of_iterations; - icp.is_adaptive_robust_kernel = false; - - icp.is_gauss_newton = true; - icp.is_levenberg_marguardt = false; - - icp.is_wc = true; - icp.is_cw = false; - - icp.is_tait_bryan_angles = true; - icp.is_quaternion = false; - icp.is_rodrigues = false; - icp.is_lie_algebra_left_jacobian = false; - icp.is_lie_algebra_right_jacobian = false; - - auto start = std::chrono::system_clock::now(); - icp.optimization_point_to_point_source_to_target(session.point_clouds_container); - auto end = std::chrono::system_clock::now(); - auto elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - std::cout << "final RMS: " << rms << std::endl; - - append_to_result_file(result_file, "point_to_point", icp, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - id_method++; - - //--1-- - icp.is_tait_bryan_angles = false; - icp.is_quaternion = true; - icp.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - icp.optimization_point_to_point_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 1; - - append_to_result_file(result_file, "point_to_point", icp, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - // id_method++; - //--2-- - icp.is_tait_bryan_angles = false; - icp.is_quaternion = false; - icp.is_rodrigues = true; - - start = std::chrono::system_clock::now(); - icp.optimization_point_to_point_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 2; - append_to_result_file(result_file, "point_to_point", icp, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--3-- - icp.is_wc = false; - icp.is_cw = true; - - icp.is_tait_bryan_angles = true; - icp.is_quaternion = false; - icp.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - icp.optimization_point_to_point_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 3; - append_to_result_file(result_file, "point_to_point", icp, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--4-- - icp.is_tait_bryan_angles = false; - icp.is_quaternion = true; - icp.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - icp.optimization_point_to_point_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 4; - append_to_result_file(result_file, "point_to_point", icp, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--5-- - icp.is_tait_bryan_angles = false; - icp.is_quaternion = false; - icp.is_rodrigues = true; - - start = std::chrono::system_clock::now(); - icp.optimization_point_to_point_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 5; - append_to_result_file(result_file, "point_to_point", icp, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--6-- - icp.is_gauss_newton = false; - icp.is_levenberg_marguardt = true; - - icp.is_wc = true; - icp.is_cw = false; - - icp.is_tait_bryan_angles = true; - icp.is_quaternion = false; - icp.is_rodrigues = false; - icp.is_lie_algebra_left_jacobian = false; - icp.is_lie_algebra_right_jacobian = false; - - start = std::chrono::system_clock::now(); - icp.optimization_point_to_point_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 6; - append_to_result_file(result_file, "point_to_point", icp, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--7-- - icp.is_tait_bryan_angles = false; - icp.is_quaternion = true; - icp.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - icp.optimization_point_to_point_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 7; - append_to_result_file(result_file, "point_to_point", icp, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--8-- - icp.is_tait_bryan_angles = false; - icp.is_quaternion = false; - icp.is_rodrigues = true; - - start = std::chrono::system_clock::now(); - icp.optimization_point_to_point_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 8; - append_to_result_file(result_file, "point_to_point", icp, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--9-- - icp.is_wc = false; - icp.is_cw = true; - - icp.is_tait_bryan_angles = true; - icp.is_quaternion = false; - icp.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - icp.optimization_point_to_point_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 9; - append_to_result_file(result_file, "point_to_point", icp, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--10-- - icp.is_wc = false; - icp.is_cw = true; - - icp.is_tait_bryan_angles = false; - icp.is_quaternion = true; - icp.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - icp.optimization_point_to_point_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 10; - append_to_result_file(result_file, "point_to_point", icp, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--11-- - icp.is_wc = false; - icp.is_cw = true; - - icp.is_tait_bryan_angles = false; - icp.is_quaternion = false; - icp.is_rodrigues = true; - - start = std::chrono::system_clock::now(); - icp.optimization_point_to_point_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 11; - append_to_result_file(result_file, "point_to_point", icp, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--12-- - icp.is_gauss_newton = true; - icp.is_levenberg_marguardt = false; - - icp.is_wc = true; - icp.is_cw = false; - - icp.is_tait_bryan_angles = false; - icp.is_quaternion = false; - icp.is_rodrigues = true; - - icp.is_lie_algebra_left_jacobian = true; - icp.is_lie_algebra_right_jacobian = false; - - start = std::chrono::system_clock::now(); - icp.optimize_source_to_target_lie_algebra_left_jacobian(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 12; - append_to_result_file(result_file, "point_to_point", icp, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--13-- - icp.is_lie_algebra_left_jacobian = false; - icp.is_lie_algebra_right_jacobian = true; - start = std::chrono::system_clock::now(); - icp.optimize_source_to_target_lie_algebra_right_jacobian(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 13; - append_to_result_file(result_file, "point_to_point", icp, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //---NDT--- - //--14-- - // - ndt.is_fix_first_node = false; - ndt.bucket_size[0] = 0.5; - ndt.bucket_size[1] = 0.5; - ndt.bucket_size[2] = 0.5; - ndt.number_of_threads = number_of_threads; - ndt.number_of_iterations = number_of_iterations; - - ndt.is_gauss_newton = true; - ndt.is_levenberg_marguardt = false; - - ndt.is_wc = true; - ndt.is_cw = false; - - ndt.is_tait_bryan_angles = true; - ndt.is_quaternion = false; - ndt.is_rodrigues = false; - ndt.is_lie_algebra_left_jacobian = false; - ndt.is_lie_algebra_right_jacobian = false; - - start = std::chrono::system_clock::now(); - ndt.optimize(session.point_clouds_container.point_clouds, true, compute_mean_and_cov_for_bucket); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - std::cout << "final rms: " << rms << std::endl; - - id_method = 14; - append_to_result_file(result_file, "normal_distributions_transform", ndt, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--15-- - ndt.is_tait_bryan_angles = false; - ndt.is_quaternion = true; - ndt.is_rodrigues = false; - start = std::chrono::system_clock::now(); - ndt.optimize(session.point_clouds_container.point_clouds, true, compute_mean_and_cov_for_bucket); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - - id_method = 15; - append_to_result_file(result_file, "normal_distributions_transform", ndt, rms, id_method, elapsed); - session.point_clouds_container = temp_data; - - //--16-- - ndt.is_tait_bryan_angles = false; - ndt.is_quaternion = false; - ndt.is_rodrigues = true; - start = std::chrono::system_clock::now(); - ndt.optimize(session.point_clouds_container.point_clouds, true, compute_mean_and_cov_for_bucket); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - - id_method = 16; - append_to_result_file(result_file, "normal_distributions_transform", ndt, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--17-- - ndt.is_wc = false; - ndt.is_cw = true; - - ndt.is_tait_bryan_angles = true; - ndt.is_quaternion = false; - ndt.is_rodrigues = false; - start = std::chrono::system_clock::now(); - ndt.optimize(session.point_clouds_container.point_clouds, true, compute_mean_and_cov_for_bucket); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 17; - append_to_result_file(result_file, "normal_distributions_transform", ndt, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--18-- - ndt.is_tait_bryan_angles = false; - ndt.is_quaternion = true; - ndt.is_rodrigues = false; - start = std::chrono::system_clock::now(); - ndt.optimize(session.point_clouds_container.point_clouds, true, compute_mean_and_cov_for_bucket); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - - id_method = 18; - append_to_result_file(result_file, "normal_distributions_transform", ndt, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--19-- - ndt.is_tait_bryan_angles = false; - ndt.is_quaternion = false; - ndt.is_rodrigues = true; - start = std::chrono::system_clock::now(); - ndt.optimize(session.point_clouds_container.point_clouds, true, compute_mean_and_cov_for_bucket); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - - id_method = 19; - append_to_result_file(result_file, "normal_distributions_transform", ndt, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--20-- - ndt.is_gauss_newton = false; - ndt.is_levenberg_marguardt = true; - - ndt.is_wc = true; - ndt.is_cw = false; - - ndt.is_tait_bryan_angles = true; - ndt.is_quaternion = false; - ndt.is_rodrigues = false; - start = std::chrono::system_clock::now(); - ndt.optimize(session.point_clouds_container.point_clouds, true, compute_mean_and_cov_for_bucket); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - - id_method = 20; - append_to_result_file(result_file, "normal_distributions_transform", ndt, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--21-- - ndt.is_tait_bryan_angles = false; - ndt.is_quaternion = true; - ndt.is_rodrigues = false; - start = std::chrono::system_clock::now(); - ndt.optimize(session.point_clouds_container.point_clouds, true, compute_mean_and_cov_for_bucket); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - - id_method = 21; - append_to_result_file(result_file, "normal_distributions_transform", ndt, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--22-- - ndt.is_tait_bryan_angles = false; - ndt.is_quaternion = false; - ndt.is_rodrigues = true; - start = std::chrono::system_clock::now(); - ndt.optimize(session.point_clouds_container.point_clouds, true, compute_mean_and_cov_for_bucket); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - - id_method = 22; - append_to_result_file(result_file, "normal_distributions_transform", ndt, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--23-- - ndt.is_wc = false; - ndt.is_cw = true; - - ndt.is_tait_bryan_angles = true; - ndt.is_quaternion = false; - ndt.is_rodrigues = false; - start = std::chrono::system_clock::now(); - ndt.optimize(session.point_clouds_container.point_clouds, true, compute_mean_and_cov_for_bucket); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - - id_method = 23; - append_to_result_file(result_file, "normal_distributions_transform", ndt, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--24-- - ndt.is_tait_bryan_angles = false; - ndt.is_quaternion = true; - ndt.is_rodrigues = false; - start = std::chrono::system_clock::now(); - ndt.optimize(session.point_clouds_container.point_clouds, true, compute_mean_and_cov_for_bucket); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - - id_method = 24; - - append_to_result_file(result_file, "normal_distributions_transform", ndt, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--25-- - ndt.is_tait_bryan_angles = false; - ndt.is_quaternion = false; - ndt.is_rodrigues = true; - start = std::chrono::system_clock::now(); - ndt.optimize(session.point_clouds_container.point_clouds, true, compute_mean_and_cov_for_bucket); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - - id_method = 25; - - append_to_result_file(result_file, "normal_distributions_transform", ndt, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--26-- - ndt.is_gauss_newton = true; - ndt.is_levenberg_marguardt = false; - - ndt.is_wc = true; - ndt.is_cw = false; - - ndt.is_tait_bryan_angles = false; - ndt.is_quaternion = false; - ndt.is_rodrigues = false; - - ndt.is_lie_algebra_left_jacobian = true; - ndt.is_lie_algebra_right_jacobian = false; - start = std::chrono::system_clock::now(); - ndt.optimize(session.point_clouds_container.point_clouds, true, compute_mean_and_cov_for_bucket); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - - id_method = 26; - - ndt.is_rodrigues = true; - - append_to_result_file(result_file, "normal_distributions_transform", ndt, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--27-- - ndt.is_gauss_newton = false; - ndt.is_levenberg_marguardt = true; - ndt.is_rodrigues = false; - start = std::chrono::system_clock::now(); - ndt.optimize(session.point_clouds_container.point_clouds, true, compute_mean_and_cov_for_bucket); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - - id_method = 27; - ndt.is_rodrigues = true; - append_to_result_file(result_file, "normal_distributions_transform", ndt, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--28-- - ndt.is_lie_algebra_left_jacobian = false; - ndt.is_lie_algebra_right_jacobian = true; - ndt.is_rodrigues = false; - - ndt.is_gauss_newton = true; - ndt.is_levenberg_marguardt = false; - start = std::chrono::system_clock::now(); - ndt.optimize(session.point_clouds_container.point_clouds, true, compute_mean_and_cov_for_bucket); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - - id_method = 28; - ndt.is_rodrigues = true; - append_to_result_file(result_file, "normal_distributions_transform", ndt, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--29-- - ndt.is_gauss_newton = false; - ndt.is_levenberg_marguardt = true; - ndt.is_rodrigues = false; - start = std::chrono::system_clock::now(); - ndt.optimize(session.point_clouds_container.point_clouds, true, compute_mean_and_cov_for_bucket); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - - id_method = 29; - ndt.is_rodrigues = true; - append_to_result_file(result_file, "normal_distributions_transform", ndt, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //---------------------------------------------------------------------------- - - registration_plane_feature.search_radius = search_radius; - registration_plane_feature.number_of_threads = number_of_threads; - registration_plane_feature.number_of_iterations = number_of_iterations; - registration_plane_feature.is_adaptive_robust_kernel = false; - registration_plane_feature.is_fix_first_node = false; - - //--30-- - registration_plane_feature.is_gauss_newton = true; - registration_plane_feature.is_levenberg_marguardt = false; - - registration_plane_feature.is_wc = true; - registration_plane_feature.is_cw = false; - - registration_plane_feature.is_tait_bryan_angles = true; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_projection_onto_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 30; - append_to_result_file(result_file, "point_to_projection_onto_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--31-- - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = true; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_projection_onto_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 31; - append_to_result_file(result_file, "point_to_projection_onto_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--32-- - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = true; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_projection_onto_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 32; - append_to_result_file(result_file, "point_to_projection_onto_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--33-- - registration_plane_feature.is_wc = false; - registration_plane_feature.is_cw = true; - - registration_plane_feature.is_tait_bryan_angles = true; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_projection_onto_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 33; - append_to_result_file(result_file, "point_to_projection_onto_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--34-- - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = true; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_projection_onto_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 34; - append_to_result_file(result_file, "point_to_projection_onto_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--35-- - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = true; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_projection_onto_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 35; - append_to_result_file(result_file, "point_to_projection_onto_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //------------------------------------------------------ - //--36-- - registration_plane_feature.is_gauss_newton = false; - registration_plane_feature.is_levenberg_marguardt = true; - - registration_plane_feature.is_wc = true; - registration_plane_feature.is_cw = false; - - registration_plane_feature.is_tait_bryan_angles = true; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_projection_onto_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 36; - append_to_result_file(result_file, "point_to_projection_onto_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--37-- - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = true; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_projection_onto_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 37; - append_to_result_file(result_file, "point_to_projection_onto_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--38-- - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = true; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_projection_onto_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 38; - append_to_result_file(result_file, "point_to_projection_onto_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--39-- - registration_plane_feature.is_wc = false; - registration_plane_feature.is_cw = true; - - registration_plane_feature.is_tait_bryan_angles = true; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_projection_onto_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 39; - append_to_result_file(result_file, "point_to_projection_onto_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--40-- - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = true; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_projection_onto_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 40; - append_to_result_file(result_file, "point_to_projection_onto_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--41-- - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = true; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_projection_onto_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 41; - append_to_result_file(result_file, "point_to_projection_onto_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--42-- Lie - registration_plane_feature.is_gauss_newton = true; - registration_plane_feature.is_levenberg_marguardt = false; - - registration_plane_feature.is_wc = true; - registration_plane_feature.is_cw = false; - - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = true; - - registration_plane_feature.is_lie_algebra_left_jacobian = true; - registration_plane_feature.is_lie_algebra_right_jacobian = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_projection_onto_plane_source_to_target_lie_algebra_left_jacobian( - session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 42; - append_to_result_file(result_file, "point_to_projection_onto_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--43-- - registration_plane_feature.is_gauss_newton = false; - registration_plane_feature.is_levenberg_marguardt = true; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_projection_onto_plane_source_to_target_lie_algebra_left_jacobian( - session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 43; - append_to_result_file(result_file, "point_to_projection_onto_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--44-- - registration_plane_feature.is_gauss_newton = true; - registration_plane_feature.is_levenberg_marguardt = false; - registration_plane_feature.is_lie_algebra_left_jacobian = false; - registration_plane_feature.is_lie_algebra_right_jacobian = true; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_projection_onto_plane_source_to_target_lie_algebra_right_jacobian( - session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 44; - append_to_result_file(result_file, "point_to_projection_onto_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--45-- - registration_plane_feature.is_gauss_newton = false; - registration_plane_feature.is_levenberg_marguardt = true; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_projection_onto_plane_source_to_target_lie_algebra_right_jacobian( - session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 45; - append_to_result_file(result_file, "point_to_projection_onto_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--46--using dot product - registration_plane_feature.is_lie_algebra_left_jacobian = false; - registration_plane_feature.is_lie_algebra_right_jacobian = false; - - registration_plane_feature.is_gauss_newton = true; - registration_plane_feature.is_levenberg_marguardt = false; - - registration_plane_feature.is_wc = true; - registration_plane_feature.is_cw = false; - - registration_plane_feature.is_tait_bryan_angles = true; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 46; - append_to_result_file(result_file, "point_to_plane_using_dot_product", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--47 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = true; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 47; - append_to_result_file(result_file, "point_to_plane_using_dot_product", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--48 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = true; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 48; - append_to_result_file(result_file, "point_to_plane_using_dot_product", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--49 - registration_plane_feature.is_wc = false; - registration_plane_feature.is_cw = true; - - registration_plane_feature.is_tait_bryan_angles = true; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 49; - append_to_result_file(result_file, "point_to_plane_using_dot_product", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--50 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = true; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 50; - append_to_result_file(result_file, "point_to_plane_using_dot_product", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--51 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = true; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 51; - append_to_result_file(result_file, "point_to_plane_using_dot_product", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--52 - registration_plane_feature.is_gauss_newton = false; - registration_plane_feature.is_levenberg_marguardt = true; - - registration_plane_feature.is_wc = true; - registration_plane_feature.is_cw = false; - - registration_plane_feature.is_tait_bryan_angles = true; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 52; - append_to_result_file(result_file, "point_to_plane_using_dot_product", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--53 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = true; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 53; - append_to_result_file(result_file, "point_to_plane_using_dot_product", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--54 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = true; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 54; - append_to_result_file(result_file, "point_to_plane_using_dot_product", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--55 - registration_plane_feature.is_wc = false; - registration_plane_feature.is_cw = true; - - registration_plane_feature.is_tait_bryan_angles = true; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 55; - append_to_result_file(result_file, "point_to_plane_using_dot_product", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--56 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = true; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 56; - append_to_result_file(result_file, "point_to_plane_using_dot_product", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--57 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = true; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 57; - append_to_result_file(result_file, "point_to_plane_using_dot_product", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--58 optimize_distance_point_to_plane_source_to_target - registration_plane_feature.is_gauss_newton = true; - registration_plane_feature.is_levenberg_marguardt = false; - - registration_plane_feature.is_wc = true; - registration_plane_feature.is_cw = false; - - registration_plane_feature.is_tait_bryan_angles = true; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_distance_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 58; - append_to_result_file(result_file, "distance_point_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--59 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = true; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_distance_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 59; - append_to_result_file(result_file, "distance_point_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--60 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = true; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_distance_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 60; - append_to_result_file(result_file, "distance_point_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--61 - registration_plane_feature.is_wc = false; - registration_plane_feature.is_cw = true; - - registration_plane_feature.is_tait_bryan_angles = true; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_distance_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 61; - append_to_result_file(result_file, "distance_point_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--62 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = true; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_distance_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 62; - append_to_result_file(result_file, "distance_point_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--63 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = true; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_distance_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 63; - append_to_result_file(result_file, "distance_point_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--64 - registration_plane_feature.is_gauss_newton = false; - registration_plane_feature.is_levenberg_marguardt = true; - - registration_plane_feature.is_wc = true; - registration_plane_feature.is_cw = false; - - registration_plane_feature.is_tait_bryan_angles = true; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_distance_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 64; - append_to_result_file(result_file, "distance_point_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--65 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = true; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_distance_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 65; - append_to_result_file(result_file, "distance_point_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--66 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = true; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_distance_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 66; - append_to_result_file(result_file, "distance_point_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--67 - registration_plane_feature.is_wc = false; - registration_plane_feature.is_cw = true; - - registration_plane_feature.is_tait_bryan_angles = true; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_distance_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 67; - append_to_result_file(result_file, "distance_point_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--68 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = true; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_distance_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 68; - append_to_result_file(result_file, "distance_point_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--69 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = true; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_distance_point_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 69; - append_to_result_file(result_file, "distance_point_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--70 optimize_plane_to_plane_source_to_target - registration_plane_feature.is_adaptive_robust_kernel = true; - - registration_plane_feature.is_gauss_newton = true; - registration_plane_feature.is_levenberg_marguardt = false; - - registration_plane_feature.is_wc = true; - registration_plane_feature.is_cw = false; - - registration_plane_feature.is_tait_bryan_angles = true; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_plane_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 70; - append_to_result_file(result_file, "plane_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--71 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = true; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_plane_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 71; - append_to_result_file(result_file, "plane_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--72 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = true; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_plane_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 72; - append_to_result_file(result_file, "plane_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--73 - registration_plane_feature.is_wc = false; - registration_plane_feature.is_cw = true; - - registration_plane_feature.is_tait_bryan_angles = true; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_plane_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 73; - append_to_result_file(result_file, "plane_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--74 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = true; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_plane_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 74; - append_to_result_file(result_file, "plane_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--75 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = true; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_plane_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 75; - append_to_result_file(result_file, "plane_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--76 - registration_plane_feature.is_gauss_newton = false; - registration_plane_feature.is_levenberg_marguardt = true; - - registration_plane_feature.is_wc = true; - registration_plane_feature.is_cw = false; - - registration_plane_feature.is_tait_bryan_angles = true; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_plane_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 76; - append_to_result_file(result_file, "plane_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--77 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = true; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_plane_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 77; - append_to_result_file(result_file, "plane_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--78 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = true; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_plane_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 78; - append_to_result_file(result_file, "plane_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--79 - registration_plane_feature.is_wc = false; - registration_plane_feature.is_cw = true; - - registration_plane_feature.is_tait_bryan_angles = true; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_plane_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 79; - append_to_result_file(result_file, "plane_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--80 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = true; - registration_plane_feature.is_rodrigues = false; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_plane_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 80; - append_to_result_file(result_file, "plane_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--81 - registration_plane_feature.is_tait_bryan_angles = false; - registration_plane_feature.is_quaternion = false; - registration_plane_feature.is_rodrigues = true; - - start = std::chrono::system_clock::now(); - registration_plane_feature.optimize_plane_to_plane_source_to_target(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 81; - append_to_result_file(result_file, "plane_to_plane", registration_plane_feature, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - // pose graph slam - //--82-- - pose_graph_slam.overlap_threshold = 0.3; - pose_graph_slam.iterations = 6; - - pose_graph_slam.search_radius = search_radius; - pose_graph_slam.number_of_threads = number_of_threads; - pose_graph_slam.number_of_iterations_pair_wise_matching = number_of_iterations; - - //-- - pose_graph_slam.is_adaptive_robust_kernel = false; - pose_graph_slam.is_fix_first_node = true; - pose_graph_slam.is_gauss_newton = true; - pose_graph_slam.is_levenberg_marguardt = false; - pose_graph_slam.is_cw = false; - pose_graph_slam.is_wc = true; - pose_graph_slam.is_tait_bryan_angles = true; - pose_graph_slam.is_quaternion = false; - pose_graph_slam.is_rodrigues = false; - - session.point_clouds_container = temp_data; - pose_graph_slam.set_all_to_false(); - pose_graph_slam.is_ndt = true; - pose_graph_slam.pair_wise_matching_type = PoseGraphSLAM::PairWiseMatchingType::general; - pose_graph_slam.ndt_bucket_size[0] = ndt.bucket_size[0]; - pose_graph_slam.ndt_bucket_size[1] = ndt.bucket_size[1]; - pose_graph_slam.ndt_bucket_size[2] = ndt.bucket_size[2]; - start = std::chrono::system_clock::now(); - pose_graph_slam.optimize(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 82; - append_to_result_file(result_file, "pose_graph_slam (normal_distributions_transform)", pose_graph_slam, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - - //--83 - session.point_clouds_container = temp_data; - pose_graph_slam.set_all_to_false(); - pose_graph_slam.is_optimization_point_to_point_source_to_target = true; - pose_graph_slam.pair_wise_matching_type = PoseGraphSLAM::PairWiseMatchingType::general; - start = std::chrono::system_clock::now(); - pose_graph_slam.optimize(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 83; - append_to_result_file(result_file, "pose_graph_slam (point_to_point)", pose_graph_slam, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--84 - session.point_clouds_container = temp_data; - pose_graph_slam.set_all_to_false(); - pose_graph_slam.is_optimize_point_to_projection_onto_plane_source_to_target = true; - pose_graph_slam.pair_wise_matching_type = PoseGraphSLAM::PairWiseMatchingType::general; - start = std::chrono::system_clock::now(); - pose_graph_slam.optimize(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 84; - append_to_result_file(result_file, "pose_graph_slam (point_to_projection_onto_plane)", pose_graph_slam, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - - //--85 - session.point_clouds_container = temp_data; - pose_graph_slam.set_all_to_false(); - pose_graph_slam.is_optimize_point_to_plane_source_to_target = true; - pose_graph_slam.pair_wise_matching_type = PoseGraphSLAM::PairWiseMatchingType::general; - start = std::chrono::system_clock::now(); - pose_graph_slam.optimize(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 85; - append_to_result_file(result_file, "pose_graph_slam (point_to_plane_using_dot_product)", pose_graph_slam, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - - //--86 - session.point_clouds_container = temp_data; - pose_graph_slam.set_all_to_false(); - pose_graph_slam.is_optimize_distance_point_to_plane_source_to_target = true; - pose_graph_slam.pair_wise_matching_type = PoseGraphSLAM::PairWiseMatchingType::general; - start = std::chrono::system_clock::now(); - pose_graph_slam.optimize(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 86; - append_to_result_file(result_file, "pose_graph_slam (distance_point_to_plane)", pose_graph_slam, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--87 - pose_graph_slam.is_adaptive_robust_kernel = true; - - pose_graph_slam.set_all_to_false(); - pose_graph_slam.is_optimize_plane_to_plane_source_to_target = true; - pose_graph_slam.pair_wise_matching_type = PoseGraphSLAM::PairWiseMatchingType::general; - start = std::chrono::system_clock::now(); - pose_graph_slam.optimize(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 87; - append_to_result_file(result_file, "pose_graph_slam (plane_to_plane)", pose_graph_slam, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - - //--88 - pose_graph_slam.set_all_to_false(); - session.point_clouds_container = temp_data; - pose_graph_slam.is_adaptive_robust_kernel = false; - pose_graph_slam.is_ndt_lie_algebra_left_jacobian = true; - pose_graph_slam.is_lie_algebra_left_jacobian = true; - pose_graph_slam.pair_wise_matching_type = PoseGraphSLAM::PairWiseMatchingType::general; - start = std::chrono::system_clock::now(); - pose_graph_slam.optimize(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 88; - append_to_result_file(result_file, "pose_graph_slam (ndt_lie_algebra_left_jacobian)", pose_graph_slam, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - - //--89 - pose_graph_slam.set_all_to_false(); - session.point_clouds_container = temp_data; - pose_graph_slam.is_ndt_lie_algebra_right_jacobian = true; - pose_graph_slam.is_lie_algebra_right_jacobian = true; - pose_graph_slam.pair_wise_matching_type = PoseGraphSLAM::PairWiseMatchingType::general; - start = std::chrono::system_clock::now(); - pose_graph_slam.optimize(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 89; - append_to_result_file(result_file, "pose_graph_slam (ndt_lie_algebra_right_jacobian)", pose_graph_slam, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - - //--90 - pose_graph_slam.set_all_to_false(); - session.point_clouds_container = temp_data; - pose_graph_slam.is_optimize_point_to_point_source_to_target_lie_algebra_left_jacobian = true; - pose_graph_slam.is_lie_algebra_left_jacobian = true; - pose_graph_slam.pair_wise_matching_type = PoseGraphSLAM::PairWiseMatchingType::general; - start = std::chrono::system_clock::now(); - pose_graph_slam.optimize(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 90; - append_to_result_file( - result_file, "pose_graph_slam (point_to_point_lie_algebra_left_jacobian)", pose_graph_slam, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - - //--91 - pose_graph_slam.set_all_to_false(); - session.point_clouds_container = temp_data; - pose_graph_slam.is_optimize_point_to_point_source_to_target_lie_algebra_right_jacobian = true; - pose_graph_slam.is_lie_algebra_right_jacobian = true; - pose_graph_slam.pair_wise_matching_type = PoseGraphSLAM::PairWiseMatchingType::general; - start = std::chrono::system_clock::now(); - pose_graph_slam.optimize(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 91; - append_to_result_file( - result_file, "pose_graph_slam (point_to_point_lie_algebra_right_jacobian)", pose_graph_slam, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - - //--92 - pose_graph_slam.set_all_to_false(); - session.point_clouds_container = temp_data; - pose_graph_slam.is_optimize_point_to_projection_onto_plane_source_to_target_lie_algebra_left_jacobian = true; - pose_graph_slam.is_lie_algebra_left_jacobian = true; - pose_graph_slam.pair_wise_matching_type = PoseGraphSLAM::PairWiseMatchingType::general; - start = std::chrono::system_clock::now(); - pose_graph_slam.optimize(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 92; - append_to_result_file( - result_file, - "pose_graph_slam (point_to_projection_onto_plane_lie_algebra_left_jacobian)", - pose_graph_slam, - rms, - id_method, - elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - - //--93 - pose_graph_slam.set_all_to_false(); - session.point_clouds_container = temp_data; - pose_graph_slam.is_optimize_point_to_projection_onto_plane_source_to_target_lie_algebra_right_jacobian = true; - pose_graph_slam.is_lie_algebra_right_jacobian = true; - pose_graph_slam.pair_wise_matching_type = PoseGraphSLAM::PairWiseMatchingType::general; - start = std::chrono::system_clock::now(); - pose_graph_slam.optimize(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 93; - append_to_result_file( - result_file, - "pose_graph_slam (point_to_projection_onto_plane_lie_algebra_right_jacobian)", - pose_graph_slam, - rms, - id_method, - elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); -} - -void perform_experiment_on_linux( - Session& session, - ObservationPicking& observation_picking, - ICP& icp, - NDT& ndt, - RegistrationPlaneFeature& registration_plane_feature, - PoseGraphSLAM& pose_graph_slam) -{ - fs::path path_result(session.working_directory); - path_result /= "results_linux"; - create_directory(path_result); - - session.point_clouds_container.show_with_initial_pose = false; - auto temp_data = session.point_clouds_container; - // reset_poses(); - float rms = 0.0f; - std::string result_file = session.working_directory + "/result_linux.csv"; - create_header(result_file); - double initial_rms = compute_rms(false, session, observation_picking); - std::cout << "initial rms: " << initial_rms << std::endl; - add_initial_rms_to_file(result_file, initial_rms); - - float search_radius = 0.1f; - int number_of_threads = 16; - int number_of_iterations = 6; - int id_method = 0; - - // pose graph slam - //--94-- - pose_graph_slam.overlap_threshold = 0.3; - pose_graph_slam.iterations = 6; - - pose_graph_slam.search_radius = search_radius; - pose_graph_slam.number_of_threads = number_of_threads; - pose_graph_slam.number_of_iterations_pair_wise_matching = number_of_iterations; - - //-- - pose_graph_slam.is_adaptive_robust_kernel = false; - pose_graph_slam.is_fix_first_node = true; - pose_graph_slam.is_gauss_newton = true; - pose_graph_slam.is_levenberg_marguardt = false; - pose_graph_slam.is_cw = false; - pose_graph_slam.is_wc = true; - pose_graph_slam.is_tait_bryan_angles = false; - pose_graph_slam.is_quaternion = false; - pose_graph_slam.is_rodrigues = true; - - session.point_clouds_container = temp_data; - - // pose_graph_slam.is_ndt = true; - // pose_graph_slam.pair_wise_matching_type = PoseGraphSLAM::PairWiseMatchingType::general; - // pose_graph_slam.ndt_bucket_size[0] = ndt.bucket_size[0]; - // pose_graph_slam.ndt_bucket_size[1] = ndt.bucket_size[1]; - // pose_graph_slam.ndt_bucket_size[2] = ndt.bucket_size[2]; - // pose_graph_slam.optimize(point_clouds_container); - // rms = compute_rms(); - // id_method = 94; - // append_to_result_file(result_file, "pose_graph_slam (normal_distributions_transform)", pose_graph_slam, rms, id_method); - -#ifdef WITH_PCL - pose_graph_slam.set_all_to_false(); - pose_graph_slam.is_optimize_pcl_ndt = true; - pose_graph_slam.pair_wise_matching_type = PoseGraphSLAM::PairWiseMatchingType::pcl_ndt; - - auto start = std::chrono::system_clock::now(); - pose_graph_slam.optimize(session.point_clouds_container); - auto end = std::chrono::system_clock::now(); - auto elapsed = std::chrono::duration_cast(end - start); - - rms = compute_rms(false, session, observation_picking); - id_method = 94; - append_to_result_file(result_file, "pose_graph_slam (pcl_ndt)", pose_graph_slam, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--95-- - pose_graph_slam.set_all_to_false(); - pose_graph_slam.is_optimize_pcl_icp = true; - pose_graph_slam.pair_wise_matching_type = PoseGraphSLAM::PairWiseMatchingType::pcl_icp; - - start = std::chrono::system_clock::now(); - pose_graph_slam.optimize(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - - rms = compute_rms(false, session, observation_picking); - id_method = 95; - append_to_result_file(result_file, "pose_graph_slam (pcl_icp)", pose_graph_slam, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; -#endif - -#if WITH_GTSAM - //--96-- - try - { - pose_graph_slam.ndt_bucket_size[0] = ndt.bucket_size[0]; - pose_graph_slam.ndt_bucket_size[1] = ndt.bucket_size[1]; - pose_graph_slam.ndt_bucket_size[2] = ndt.bucket_size[2]; - - pose_graph_slam.set_all_to_false(); - pose_graph_slam.is_optimize_pcl_ndt = true; - pose_graph_slam.is_lie_algebra_right_jacobian = true; - pose_graph_slam.pair_wise_matching_type = PoseGraphSLAM::PairWiseMatchingType::pcl_ndt; - - auto start = std::chrono::system_clock::now(); - pose_graph_slam.optimize_with_GTSAM(session.point_clouds_container); - auto end = std::chrono::system_clock::now(); - auto elapsed = std::chrono::duration_cast(end - start); - rms = compute_rms(false, session, observation_picking); - id_method = 96; - append_to_result_file(result_file, "pose_graph_slam (GTSAM pcl_ndt)", pose_graph_slam, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - } catch (std::exception& e) - { - std::cout << e.what() << std::endl; - rms = compute_rms(false, session, observation_picking); - // append_to_result_file(result_file, "pose_graph_slam (GTSAM pcl_ndt)", pose_graph_slam, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - } - //--97-- - try - { - pose_graph_slam.set_all_to_false(); - pose_graph_slam.is_optimize_pcl_icp = true; - pose_graph_slam.is_lie_algebra_right_jacobian = true; - pose_graph_slam.pair_wise_matching_type = PoseGraphSLAM::PairWiseMatchingType::pcl_icp; - - auto start = std::chrono::system_clock::now(); - pose_graph_slam.optimize_with_GTSAM(session.point_clouds_container); - auto end = std::chrono::system_clock::now(); - auto elapsed = std::chrono::duration_cast(end - start); - - rms = compute_rms(false, session, observation_picking); - id_method = 97; - append_to_result_file(result_file, "pose_graph_slam (GTSAM pcl_icp)", pose_graph_slam, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - } catch (std::exception& e) - { - std::cout << e.what() << std::endl; - rms = compute_rms(false, session, observation_picking); - // append_to_result_file(result_file, "pose_graph_slam (GTSAM pcl_icp)", pose_graph_slam, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - } -#endif -#if WITH_MANIF - //--98-- - { - pose_graph_slam.set_all_to_false(); - pose_graph_slam.is_optimize_pcl_ndt = true; - pose_graph_slam.is_lie_algebra_right_jacobian = true; - pose_graph_slam.pair_wise_matching_type = PoseGraphSLAM::PairWiseMatchingType::pcl_ndt; - - auto start = std::chrono::system_clock::now(); - pose_graph_slam.optimize_with_manif(session.point_clouds_container); - auto end = std::chrono::system_clock::now(); - auto elapsed = std::chrono::duration_cast(end - start); - - rms = compute_rms(false, session, observation_picking); - id_method = 98; - append_to_result_file(result_file, "pose_graph_slam (manif pcl_ndt)", pose_graph_slam, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - - //--99-- - pose_graph_slam.set_all_to_false(); - pose_graph_slam.is_optimize_pcl_icp = true; - pose_graph_slam.is_lie_algebra_right_jacobian = true; - pose_graph_slam.pair_wise_matching_type = PoseGraphSLAM::PairWiseMatchingType::pcl_icp; - - start = std::chrono::system_clock::now(); - pose_graph_slam.optimize_with_manif(session.point_clouds_container); - end = std::chrono::system_clock::now(); - elapsed = std::chrono::duration_cast(end - start); - - rms = compute_rms(false, session, observation_picking); - id_method = 99; - append_to_result_file(result_file, "pose_graph_slam (manif pcl_icp)", pose_graph_slam, rms, id_method, elapsed); - export_result_to_folder(path_result.string(), id_method, observation_picking, session); - session.point_clouds_container = temp_data; - } -#endif -} - -#if 0 -bool exportLaz(const std::string &filename, - const std::vector &pointcloud, - const std::vector &intensity, double offset_x, double offset_y, double offset_alt) -{ - - constexpr float scale = 0.0001f; // one tenth of milimeter - // find max - Eigen::Vector3d max(std::numeric_limits::lowest(), std::numeric_limits::lowest(), std::numeric_limits::lowest()); - Eigen::Vector3d min(std::numeric_limits::max(), std::numeric_limits::max(), std::numeric_limits::max()); - for (auto &p : pointcloud) - { - max.x() = std::max(max.x(), p.x()); - max.y() = std::max(max.y(), p.y()); - max.z() = std::max(max.z(), p.z()); - - min.x() = std::min(min.x(), p.x()); - min.y() = std::min(min.y(), p.y()); - min.z() = std::min(min.z(), p.z()); - } - - std::cout << "exportLaz to file: '" << filename << "'" << std::endl; - std::cout << std::setprecision(20) << "min.x " << min.x() << " " << max.x() << std::endl; - std::cout << "min.y " << min.y() << " " << max.y() << std::endl; - std::cout << "min.z " << min.z() << " " << max.z() << std::endl; - - // create the writer - laszip_POINTER laszip_writer; - if (laszip_create(&laszip_writer)) - { - spdlog::error("DLL ERROR: creating laszip writer"); - return false; - } - - // get a pointer to the header of the writer so we can populate it - - laszip_header *header; - - if (laszip_get_header_pointer(laszip_writer, &header)) - { - spdlog::error("DLL ERROR: getting header pointer from laszip writer"); - return false; - } - - // populate the header - - header->file_source_ID = 4711; - header->global_encoding = (1 << 0); // see LAS specification for details - header->version_major = 1; - header->version_minor = 2; - // header->file_creation_day = 120; - // header->file_creation_year = 2013; - header->point_data_format = 1; - header->point_data_record_length = 0; - header->number_of_point_records = pointcloud.size(); - header->number_of_points_by_return[0] = pointcloud.size(); - header->number_of_points_by_return[1] = 0; - header->point_data_record_length = 28; - header->x_scale_factor = scale; - header->y_scale_factor = scale; - header->z_scale_factor = scale; - - header->max_x = max.x() + offset_x; - header->min_x = min.x() + offset_x; - header->max_y = max.y() + offset_y; - header->min_y = min.y() + offset_y; - header->max_z = max.z() + offset_alt; - header->min_z = min.z() + offset_alt; - - header->x_offset = offset_x; - header->y_offset = offset_y; - header->z_offset = offset_alt; - - // optional: use the bounding box and the scale factor to create a "good" offset - // open the writer - laszip_BOOL compress = (strstr(filename.c_str(), ".laz") != 0); - - if (laszip_open_writer(laszip_writer, filename.c_str(), compress)) - { - spdlog::error("DLL ERROR: opening laszip writer for '{}'", filename ); - return false; - } - - spdlog::info("writing file '{}' {}compressed", filename, (compress ? "" : "un")); - - // get a pointer to the point of the writer that we will populate and write - - laszip_point *point; - if (laszip_get_point_pointer(laszip_writer, &point)) - { - spdlog::error("DLL ERROR: getting point pointer from laszip writer"); - return false; - } - - laszip_I64 p_count = 0; - laszip_F64 coordinates[3]; - - for (int i = 0; i < pointcloud.size(); i++) - { - point->intensity = intensity[i]; - - const auto &p = pointcloud[i]; - p_count++; - coordinates[0] = p.x();// + offset_x; - coordinates[1] = p.y();// + offset_y; - coordinates[2] = p.z();// + offset_alt; - if (laszip_set_coordinates(laszip_writer, coordinates)) - { - spdlog::error("DLL ERROR: setting coordinates for point {}", p_count); - return false; - } - - // p.SetIntensity(pp.intensity); - - // if (i < intensity.size()) { - // point->intensity = intensity[i]; - // } - // laszip_set_point - - if (laszip_write_point(laszip_writer)) - { - spdlog::error("DLL ERROR: writing point {}", p_count); - return false; - } - } - - if (laszip_get_point_count(laszip_writer, &p_count)) - { - spdlog::error("DLL ERROR: getting point count"); - return false; - } - - spdlog::info("successfully written {} points", p_count); - - // close the writer - - if (laszip_close_writer(laszip_writer)) - { - spdlog::error("DLL ERROR: closing laszip writer"); - return false; - } - - // destroy the writer - - if (laszip_destroy(laszip_writer)) - { - spdlog::error("DLL ERROR: destroying laszip writer"); - return false; - } - - std::cout << "exportLaz DONE" << std::endl; - return true; -} -#endif - -#if 0 -//void export_result_to_folder(std::string output_folder_name, ObservationPicking &observation_picking, Session &session); -void export_result_to_folder(std::string output_folder_name, ObservationPicking &observation_picking, Session &session) -{ - fs::path path(output_folder_name); - std::string file_name_rms = "rms.csv"; - auto path_rms = path; - path_rms /= file_name_rms; - std::cout << "exporting to file: '" << path_rms.string() << "'" << std::endl; - std::ofstream outfile_rms; - outfile_rms.open(path_rms, std::ios_base::app); - outfile_rms << "index_roi, rms_initial, rms_result" << std::endl; - - for (int i = 0; i < observation_picking.intersections.size(); i++) - { - std::string file_name_initial = "intersection_" + std::to_string(i) + "_initial.csv"; - std::string file_name_result = "intersection_" + std::to_string(i) + "_result.csv"; - - auto path_initial = path; - auto path_result = path; - - path_initial /= file_name_initial; - path_result /= file_name_result; - - std::cout << "exporting to file: '" << path_initial.string() << "'" << std::endl; - std::cout << "exporting to file: '" << path_result.string() << "'" << std::endl; - - std::ofstream outfile_initial; - std::ofstream outfile_result; - - outfile_initial.open(path_initial, std::ios_base::app); - outfile_result.open(path_result, std::ios_base::app); - - const auto &intersection = observation_picking.intersections[i]; - TaitBryanPose pose; - pose.px = intersection.translation[0]; - pose.py = intersection.translation[1]; - pose.pz = intersection.translation[2]; - pose.om = intersection.rotation[0]; - pose.fi = intersection.rotation[1]; - pose.ka = intersection.rotation[2]; - Eigen::Affine3d m_pose_inv = affine_matrix_from_pose_tait_bryan(pose).inverse(); - - double w = intersection.width_length_height[0] * 0.5; - double l = intersection.width_length_height[1] * 0.5; - double h = intersection.width_length_height[2] * 0.5; - - outfile_initial << "x;y;z;pc_index;is_initial;index_intersection;file" << std::endl; - outfile_result << "x;y;z;pc_index;is_initial;index_intersection;file" << std::endl; - - for (int pc_index = 0; pc_index < session.point_clouds_container.point_clouds.size(); pc_index++) - { - const auto &pc = session.point_clouds_container.point_clouds[pc_index]; - for (const auto &p : pc.points_local) - { - Eigen::Vector3d vpi = pc.m_initial_pose * p; - Eigen::Vector3d vpr = pc.m_pose * p; - - Eigen::Vector3d vpit = m_pose_inv * vpi; - Eigen::Vector3d vprt = m_pose_inv * vpr; - - if (fabs(vpit.x()) < w) - { - if (fabs(vpit.y()) < l) - { - if (fabs(vpit.z()) < h) - { - outfile_initial << vpit.x() << ";" << vpit.y() << ";" << vpit.z() << ";" << pc_index << ";1;" << i << ";" << pc.file_name << std::endl; - } - } - } - if (fabs(vprt.x()) < w) - { - if (fabs(vprt.y()) < l) - { - if (fabs(vprt.z()) < h) - { - outfile_result << vprt.x() << ";" << vprt.y() << ";" << vprt.z() << ";" << pc_index << ";0;" << i << ";" << pc.file_name << std::endl; - } - } - } - } - } - outfile_initial.close(); - outfile_result.close(); - - const auto &obs = observation_picking.observations[i]; - double rms_initial = 0.0; - int sum = 0; - double rms_result = 0.0; - - for (const auto &[key1, value1] : obs) - { - for (const auto &[key2, value2] : obs) - { - if (key1 != key2) - { - Eigen::Vector3d p1, p2; - p1 = session.point_clouds_container.point_clouds[key1].m_initial_pose * value1; - p2 = session.point_clouds_container.point_clouds[key2].m_initial_pose * value2; - rms_initial += (p2.x() - p1.x()) * (p2.x() - p1.x()); - rms_initial += (p2.y() - p1.y()) * (p2.y() - p1.y()); - - p1 = session.point_clouds_container.point_clouds[key1].m_pose * value1; - p2 = session.point_clouds_container.point_clouds[key2].m_pose * value2; - rms_result += (p2.x() - p1.x()) * (p2.x() - p1.x()); - rms_result += (p2.y() - p1.y()) * (p2.y() - p1.y()); - - sum += 2; - } - } - } - std::cout << "sum: " << sum << std::endl; - if (sum > 0) - { - rms_initial = sqrt(rms_initial / sum); - rms_result = sqrt(rms_result / sum); - outfile_rms << i << ";" << rms_initial << ";" << rms_result << std::endl; - } - } - outfile_rms.close(); - - std::string file_name_poses = "poses_RESSO.reg"; - auto path_poses = path; - path_poses /= file_name_poses; - std::cout << "saving poses to: " << path_poses << std::endl; - session.point_clouds_container.save_poses(path_poses.string(), false); -} - - -//void export_result_to_folder(std::string output_folder_name, ObservationPicking &observation_picking, Session &session) -void export_result_to_folder(std::string output_folder_name, int method_id, ObservationPicking &observation_picking) -{ - fs::path path(output_folder_name); - path /= std::to_string(method_id); - create_directory(path); - export_result_to_folder(path.string(), observation_picking); -} - -#endif \ No newline at end of file diff --git a/apps/multi_view_tls_registration_legacy/resource.h b/apps/multi_view_tls_registration_legacy/resource.h deleted file mode 100644 index 4f3204ca..00000000 --- a/apps/multi_view_tls_registration_legacy/resource.h +++ /dev/null @@ -1,17 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by resource.rc -// -#define IDI_ICON1 101 // application icon -#define VS_VERSION_INFO 1 // version info - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 106 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1000 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/apps/multi_view_tls_registration_legacy/resource.rc b/apps/multi_view_tls_registration_legacy/resource.rc deleted file mode 100644 index 77dce10d..00000000 --- a/apps/multi_view_tls_registration_legacy/resource.rc +++ /dev/null @@ -1,49 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "resource.h" -///////////////////////////////////////////////////////////////////////////// -// English (United States) resources - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -IDI_ICON1 ICON "icon.ico" - - -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO -FILEVERSION 0, 0, 100, 1 -PRODUCTVERSION 0, 0, 100, 1 -FILEFLAGSMASK 0x3fL -FILEOS 0x40004 -FILETYPE 0x1 -BEGIN -BLOCK "StringFileInfo" -BEGIN -BLOCK "040904B0" -BEGIN -VALUE "CompanyName", "Mandeye\0" -VALUE "FileDescription", "HDMapping Step 2\0" -VALUE "FileVersion", "0.100.1\0" -VALUE "InternalName", "Multi view TLS registration\0" -VALUE "LegalCopyright", "(c) 2026 github.com/MapsHD/HDMapping\0" -VALUE "OriginalFilename", "multi_view_tls_registration_step_2.exe\0" -VALUE "ProductVersion", "0.100.1\0" -VALUE "ProgramID", "github.com/MapsHD/HDMapping\0" -VALUE "ProductName", "HDMapping\0" -END -END -BLOCK "VarFileInfo" -BEGIN -VALUE "Translation", 0x409, 0x04B0 -END -END -///////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/cmake/raylib.cmake b/cmake/raylib.cmake index 2f46fb3d..9f0eb0b3 100644 --- a/cmake/raylib.cmake +++ b/cmake/raylib.cmake @@ -3,11 +3,6 @@ include_guard() # raylib + Dear ImGui + rlImGui, for the raylib-based step2 viewer # (apps/multi_view_tls_registration_raylib). Mirrors the integration pattern # established in the sibling mandeye-colors project. -# -# NOTE: cmake/imgui.cmake already defines a target named `imgui`, statically -# linked with the GLUT/OpenGL2 backend baked in for the legacy GLUT apps. -# That target cannot be reused here (rlImGui needs a plain ImGui core with no -# backend baked in), so this file builds a separate `imgui_raylib` target. include(FetchContent) @@ -50,11 +45,10 @@ add_library(imgui_raylib STATIC target_include_directories(imgui_raylib PUBLIC ${IMGUI_RAYLIB_DIR}) # 32-bit indices: rlImGui ignores ImDrawCmd::VtxOffset, so with 16-bit indices a # draw list over 65535 vertices (e.g. ImPlot lines of a long IMU log) wraps -# around and renders garbage. Same setting as the legacy `imgui` target. +# around and renders garbage. target_compile_definitions(imgui_raylib PUBLIC ImDrawIdx=unsigned\ int) # NOTE: deliberately NOT defining IMGUI_DISABLE_OBSOLETE_FUNCTIONS (unlike -# mandeye-colors) -- core's WITH_GUI=1 sources (manual_pose_graph_loop_closure.cpp -# etc, shared unchanged with the legacy GLUT app) call a few of ImGui's +# mandeye-colors) -- core's WITH_GUI=1 sources call a few of ImGui's # "obsolete" functions (e.g. SetWindowFontScale), which that flag compiles # out entirely (declaration included), breaking the link against core.a. diff --git a/core/src/raylib_render.cpp b/core/src/raylib_render.cpp index 56664f10..175a1f4b 100644 --- a/core/src/raylib_render.cpp +++ b/core/src/raylib_render.cpp @@ -136,8 +136,7 @@ void ScanRenderer::rebuild(size_t index, const PointCloud& pc) // Every point in points_local is uploaded -- no stride/skip here, so // loading a session always renders it at full point density. // Session::load's own voxel-bucket decimation, controlled by the - // Settings panel's "Downsample during load" checkbox, is unrelated and - // untouched -- it's shared unchanged with the legacy GLUT app. + // Settings panel's "Downsample during load" checkbox, is unrelated. const bool hasIntensity = pc.intensities.size() == pc.points_local.size(); float minIntensity = std::numeric_limits::max(); float maxIntensity = -std::numeric_limits::max(); diff --git a/deploy_mandeye.bat b/deploy_mandeye.bat index dd2106c3..71db3e37 100644 --- a/deploy_mandeye.bat +++ b/deploy_mandeye.bat @@ -60,7 +60,7 @@ rem This list has to be kept in sync by hand with the hdmapping_install_app() rem calls in apps/*/CMakeLists.txt. hd_mapper is deliberately absent: it is rem gated behind BUILD_WITH_HD_MAPPER_APPLICATION, which defaults to OFF, so rem listing it would warn on every normal build. -set "EXPECTED=camera_lidar_calibration.exe camera_lidar_intrinsics_calib.exe camera_lidar_trajectory_viewer.exe concatenate_multi_livox.exe drag_folder_with_mandeye_data_and_drop_here-precision_forestry.exe laz_to_mcap.exe laz_to_pcd.exe laz_to_ply.exe laz_to_txt.exe lidar_odometry_step_1.exe lidar_odometry_step_1_legacy.exe livox_mid_360_intrinsic_calibration.exe mandeye_compare_trajectories.exe mandeye_mission_recorder_calibration.exe mandeye_raw_data_viewer.exe mandeye_raw_data_viewer_legacy.exe mandeye_single_session_viewer.exe matrix_mul.exe mcap_to_laz.exe multiply_timestamps_session_point_cloud_laz.exe multiply_timestamps_session_trajectory_csv.exe multi_session_registration_step_3.exe multi_session_registration_step_3_legacy.exe multi_view_tls_registration_step_2.exe multi_view_tls_registration_step_2_legacy.exe ouster_pcap_to_laz.exe pcd_to_laz.exe precision_forestry_tools.exe session_intensity_panoramas.exe session_to_mcap.exe split_multi_livox.exe freeglut.dll laszip3.dll opencv_world4130.dll proj_9_3.dll tbb12.dll z.dll" +set "EXPECTED=camera_lidar_calibration.exe camera_lidar_intrinsics_calib.exe camera_lidar_trajectory_viewer.exe concatenate_multi_livox.exe drag_folder_with_mandeye_data_and_drop_here-precision_forestry.exe laz_to_mcap.exe laz_to_pcd.exe laz_to_ply.exe laz_to_txt.exe lidar_odometry_step_1.exe livox_mid_360_intrinsic_calibration.exe mandeye_compare_trajectories.exe mandeye_mission_recorder_calibration.exe mandeye_raw_data_viewer.exe mandeye_single_session_viewer.exe matrix_mul.exe mcap_to_laz.exe multiply_timestamps_session_point_cloud_laz.exe multiply_timestamps_session_trajectory_csv.exe multi_session_registration_step_3.exe multi_view_tls_registration_step_2.exe ouster_pcap_to_laz.exe pcd_to_laz.exe precision_forestry_tools.exe session_intensity_panoramas.exe session_to_mcap.exe split_multi_livox.exe freeglut.dll laszip3.dll opencv_world4130.dll proj_9_3.dll tbb12.dll z.dll" set "MISSING=" for %%F in (%EXPECTED%) do ( diff --git a/doc/processing_report.md b/doc/processing_report.md index 5f2050ca..8f97e641 100644 --- a/doc/processing_report.md +++ b/doc/processing_report.md @@ -112,5 +112,4 @@ cleanup. Failed or cancelled runs write a diagnostic report when an output directory is available; an unwritable destination cannot retain its own failure report. Fatal process termination cannot guarantee finalization. -This change covers the raylib Step 1 workflow. Shared processing sources also -build for the older GLUT entry points, whose legacy UI is not redesigned here. +This change covers the raylib Step 1 workflow.