├── examples ├── batch │ ├── gitignore │ └── gitattributes └── config │ ├── rootba_config_example.toml │ └── rootba_config_default.toml ├── external ├── clipp │ └── include │ │ └── clipp ├── nameof │ └── include │ │ └── nameof ├── download_copied_sources.sh └── CMakeLists.txt ├── AUTHORS ├── .style.yapf ├── src ├── CMakeLists.txt ├── rootba │ ├── options │ │ └── CMakeLists.txt │ ├── cli │ │ ├── CMakeLists.txt │ │ ├── bal_cli_utils.hpp │ │ └── cli_options.hpp │ ├── pangolin │ │ ├── CMakeLists.txt │ │ ├── gui_helpers.hpp │ │ ├── gui_helpers.cpp │ │ └── bal_image_overlay.hpp │ ├── testing │ │ ├── CMakeLists.txt │ │ └── test_types.hpp │ ├── sc │ │ └── CMakeLists.txt │ ├── cg │ │ ├── CMakeLists.txt │ │ └── utils.hpp │ ├── ceres │ │ ├── CMakeLists.txt │ │ ├── types.hpp │ │ ├── bal_bundle_adjustment.hpp │ │ ├── option_utils.hpp │ │ ├── loss_function.hpp │ │ ├── loss_function.cpp │ │ ├── ba_log_utils.hpp │ │ ├── bal_iteration_callback.hpp │ │ └── bal_residuals.hpp │ ├── solver │ │ ├── CMakeLists.txt │ │ ├── bal_bundle_adjustment.hpp │ │ ├── linearizor_base.hpp │ │ ├── linearizor_sc.hpp │ │ ├── linearizor_power_sc.hpp │ │ ├── linearizor.cpp │ │ ├── linearizor_qr.hpp │ │ └── linearizor.hpp │ ├── util │ │ ├── CMakeLists.txt │ │ ├── json_utils.hpp │ │ ├── system_utils.hpp │ │ ├── system_utils.test.cpp │ │ ├── pprint_utils.hpp │ │ ├── assert.hpp │ │ ├── container_traits.hpp │ │ ├── cast.hpp │ │ ├── typesafe_utils.hpp │ │ ├── format.hpp │ │ ├── system_utils.cpp │ │ ├── time_utils.hpp │ │ ├── visit_struct_utils.hpp │ │ └── template_utils.hpp │ ├── bal │ │ ├── CMakeLists.txt │ │ ├── common_types.hpp │ │ ├── bal_problem_io.test.cpp │ │ ├── bal_app_options.hpp │ │ ├── solver_options.cpp │ │ ├── ba_log_utils.hpp │ │ ├── ba_log_options.hpp │ │ ├── bal_residual_options.hpp │ │ ├── bal_pipeline_summary.hpp │ │ └── bal_problem_io.hpp │ ├── qr │ │ ├── CMakeLists.txt │ │ ├── impl │ │ │ ├── landmark_block_dynamic.cpp │ │ │ ├── landmark_block_static_2.cpp │ │ │ ├── landmark_block_static_3.cpp │ │ │ ├── landmark_block_static_4.cpp │ │ │ ├── landmark_block_static_5.cpp │ │ │ ├── landmark_block_static_6.cpp │ │ │ ├── landmark_block_static_7.cpp │ │ │ └── landmark_block_static_8.cpp │ │ ├── linearization_utils.hpp │ │ └── landmark_block.cpp │ └── CMakeLists.txt └── app │ └── CMakeLists.txt ├── docs ├── images │ ├── bal_gui.png │ ├── teaser.jpg │ ├── plot-logs.png │ ├── cvpr-preview.jpg │ └── tutorial-preview.jpg └── scripts │ └── generate-pdf-previews.sh ├── ci ├── scripts │ ├── docker-setup-ccache.sh │ └── install-dependencies.sh └── docker │ ├── build.sh │ ├── Dockerfile_22.04 │ └── Dockerfile_20.04 ├── scripts ├── num_ops │ ├── bal_numbers.csv │ ├── compute_num_ops_symbolic.py │ ├── operation_counts.py │ ├── compute_num_ops_example.py │ ├── compute_num_ops_latex.py │ └── compute_num_ops.py ├── templates │ └── license-py-sh.tmpl ├── plot-logs.py ├── rerun-failed-in.sh ├── generate-tables.py ├── yapf-all.sh ├── rerun-one-in.sh ├── utils │ └── on-slurm-detect-cpu.sh ├── update-license-headers.sh ├── clang-format-all.sh ├── run-all-in.sh ├── query-config.py ├── show-sparsity.py ├── run-one.sh └── build-rootba.sh ├── python └── rootba │ ├── __init__.py │ ├── latex │ ├── util.py │ ├── templates.py │ └── summarize_sequences_table.py │ └── util.py ├── .gitignore ├── test ├── smoke_tests │ ├── test_bal.sh │ ├── test_bal_qr.sh │ ├── test_bal_sc.sh │ └── test_bal_ceres.sh └── CMakeLists.txt ├── cmake ├── PreventInSourceBuild.cmake └── Utils.cmake ├── CHANGELOG ├── .clang-format ├── .github └── workflows │ └── build_docker_images.yml ├── LICENSE ├── .gitmodules └── ACKNOWLEDGEMENTS /examples/batch/gitignore: -------------------------------------------------------------------------------- 1 | /tables 2 | -------------------------------------------------------------------------------- /external/clipp/include/clipp: -------------------------------------------------------------------------------- 1 | ../clipp/include/ -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Nikolaus Demmel 2 | Simon Weber 3 | Tin Chon Chan -------------------------------------------------------------------------------- /external/nameof/include/nameof: -------------------------------------------------------------------------------- 1 | ../../nameof/nameof/include/ -------------------------------------------------------------------------------- /.style.yapf: -------------------------------------------------------------------------------- 1 | [style] 2 | based_on_style = google 3 | column_limit = 120 4 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_subdirectory(rootba) 3 | add_subdirectory(app) 4 | -------------------------------------------------------------------------------- /docs/images/bal_gui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolausDemmel/rootba/HEAD/docs/images/bal_gui.png -------------------------------------------------------------------------------- /docs/images/teaser.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolausDemmel/rootba/HEAD/docs/images/teaser.jpg -------------------------------------------------------------------------------- /docs/images/plot-logs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolausDemmel/rootba/HEAD/docs/images/plot-logs.png -------------------------------------------------------------------------------- /docs/images/cvpr-preview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolausDemmel/rootba/HEAD/docs/images/cvpr-preview.jpg -------------------------------------------------------------------------------- /docs/images/tutorial-preview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolausDemmel/rootba/HEAD/docs/images/tutorial-preview.jpg -------------------------------------------------------------------------------- /ci/scripts/docker-setup-ccache.sh: -------------------------------------------------------------------------------- 1 | # to be sourced in .gitlab-ci.yml 2 | mkdir -p ccache 3 | export CCACHE_BASEDIR=${PWD} 4 | export CCACHE_DIR=${PWD}/ccache 5 | ccache -M 50G 6 | ccache -s 7 | -------------------------------------------------------------------------------- /scripts/num_ops/bal_numbers.csv: -------------------------------------------------------------------------------- 1 | Ladybug; 1723; 156502; 678718 2 | Trafalgar; 257; 65132; 225911 3 | Dubrovnik; 356; 226730; 1255268 4 | Venice; 1778; 993923; 5001946 5 | Final; 13682; 4456117; 28987644 -------------------------------------------------------------------------------- /scripts/templates/license-py-sh.tmpl: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | This file is part of the RootBA project. 4 | https://github.com/NikolausDemmel/rootba 5 | 6 | Copyright (c) ${years}, ${owner}. 7 | All rights reserved. 8 | -------------------------------------------------------------------------------- /python/rootba/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # BSD 3-Clause License 3 | # 4 | # This file is part of the RootBA project. 5 | # https://github.com/NikolausDemmel/rootba 6 | # 7 | # Copyright (c) 2021, Nikolaus Demmel. 8 | # All rights reserved. 9 | # 10 | -------------------------------------------------------------------------------- /src/rootba/options/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(rootba 2 | PUBLIC 3 | enum_ref.hpp 4 | flags_ref.hpp 5 | options_interface.hpp 6 | visitable_options.hpp 7 | wise_enum_ref.hpp 8 | PRIVATE 9 | options_interface.cpp 10 | ) 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | cmake-build* 2 | .idea 3 | CMakeLists.txt.user 4 | /build 5 | /build-* 6 | /build_* 7 | /bin 8 | /external/build 9 | external/install* 10 | ba_log.json 11 | ba_log.ubjson 12 | __pycache__ 13 | /*.cereal 14 | /rootba_config.toml 15 | 16 | # generic: 17 | .DS_Store 18 | *~ 19 | -------------------------------------------------------------------------------- /examples/batch/gitattributes: -------------------------------------------------------------------------------- 1 | *.fig filter=lfs diff=lfs merge=lfs -text 2 | *.png filter=lfs diff=lfs merge=lfs -text 3 | *.cereal filter=lfs diff=lfs merge=lfs -text 4 | *.log filter=lfs diff=lfs merge=lfs -text 5 | *.ubjson filter=lfs diff=lfs merge=lfs -text 6 | *.json filter=lfs diff=lfs merge=lfs -text 7 | -------------------------------------------------------------------------------- /src/rootba/cli/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(rootba_cli) 2 | 3 | target_sources(rootba_cli 4 | PUBLIC 5 | bal_cli_utils.hpp 6 | cli_options.hpp 7 | PRIVATE 8 | bal_cli_utils.cpp 9 | cli_options.cpp 10 | ) 11 | 12 | target_link_libraries(rootba_cli 13 | PUBLIC 14 | rootba 15 | rootba::clipp 16 | ) 17 | -------------------------------------------------------------------------------- /docs/scripts/generate-pdf-previews.sh: -------------------------------------------------------------------------------- 1 | 2 | # generating preview jpg images from experiments pdfs 3 | 4 | convert tables/experiments-tutorial.pdf -thumbnail 500x500 -background white +smush 20 -bordercolor white -border 10 tutorial-preview.jpg 5 | 6 | convert tables/experiments-cvpr.pdf tables/experiments-cvpr-supplementary.pdf -thumbnail 500x500 -background white +smush 20 -bordercolor white -border 10 cvpr-preview.jpg 7 | -------------------------------------------------------------------------------- /src/rootba/pangolin/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(rootba_pangolin) 2 | 3 | target_sources(rootba_pangolin 4 | PUBLIC 5 | bal_image_overlay.hpp 6 | bal_map_display.hpp 7 | gui_helpers.hpp 8 | PRIVATE 9 | bal_image_overlay.cpp 10 | bal_map_display.cpp 11 | gui_helpers.cpp 12 | ) 13 | 14 | target_link_libraries(rootba_pangolin 15 | PUBLIC 16 | rootba 17 | pango_display 18 | ) 19 | -------------------------------------------------------------------------------- /ci/scripts/install-dependencies.sh: -------------------------------------------------------------------------------- 1 | # to be sourced in .gitlab-ci.yml 2 | 3 | if [ "$UBUNTU_INSTALL_LATEST_TBB" = 1 ]; then 4 | wget -O - https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB | apt-key add - 5 | wget https://apt.repos.intel.com/setup/intelproducts.list -O /etc/apt/sources.list.d/intelproducts.list 6 | apt-get update 7 | apt-get install -y intel-tbb-2020.2-102 8 | fi 9 | -------------------------------------------------------------------------------- /src/rootba/testing/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | if(ROOTBA_ENABLE_TESTING) 3 | 4 | add_library(rootba_testing) 5 | 6 | target_link_libraries(rootba_testing 7 | PUBLIC 8 | rootba # make sure we inherit all compile options 9 | gtest 10 | ) 11 | 12 | target_sources(rootba_testing 13 | PUBLIC 14 | eigen_utils.hpp 15 | float_utils.hpp 16 | test_jacobian.hpp 17 | test_types.hpp 18 | ) 19 | 20 | endif() 21 | -------------------------------------------------------------------------------- /scripts/plot-logs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # BSD 3-Clause License 4 | # 5 | # This file is part of the RootBA project. 6 | # https://github.com/NikolausDemmel/rootba 7 | # 8 | # Copyright (c) 2021, Nikolaus Demmel. 9 | # All rights reserved. 10 | # 11 | 12 | import os 13 | import sys 14 | 15 | sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "python"))) 16 | 17 | import rootba.plot_logs 18 | 19 | rootba.plot_logs.main() 20 | -------------------------------------------------------------------------------- /test/smoke_tests/test_bal.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | BIN_DIR="$SCRIPT_DIR/../../bin" 5 | TEST_DATA="$SCRIPT_DIR/../../data/rootba/test/bal-ladybug-problem-49-7776-pre-shrink-1800.txt" 6 | 7 | set -x 8 | set -e 9 | 10 | cd "$SCRIPT_DIR" 11 | rm -f ba_log.json 12 | time "$BIN_DIR"/bal --input "$TEST_DATA" --max-num-iterations 2 13 | [ -f ba_log.json ] && echo ok 14 | rm -f ba_log.json 15 | -------------------------------------------------------------------------------- /test/smoke_tests/test_bal_qr.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | BIN_DIR="$SCRIPT_DIR/../../bin" 5 | TEST_DATA="$SCRIPT_DIR/../../data/rootba/test/bal-ladybug-problem-49-7776-pre-shrink-1800.txt" 6 | 7 | set -x 8 | set -e 9 | 10 | cd "$SCRIPT_DIR" 11 | rm -f ba_log.json 12 | time "$BIN_DIR"/bal_qr --input "$TEST_DATA" --max-num-iterations 2 13 | [ -f ba_log.json ] && echo ok 14 | rm -f ba_log.json 15 | -------------------------------------------------------------------------------- /test/smoke_tests/test_bal_sc.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | BIN_DIR="$SCRIPT_DIR/../../bin" 5 | TEST_DATA="$SCRIPT_DIR/../../data/rootba/test/bal-ladybug-problem-49-7776-pre-shrink-1800.txt" 6 | 7 | set -x 8 | set -e 9 | 10 | cd "$SCRIPT_DIR" 11 | rm -f ba_log.json 12 | time "$BIN_DIR"/bal_sc --input "$TEST_DATA" --max-num-iterations 2 13 | [ -f ba_log.json ] && echo ok 14 | rm -f ba_log.json 15 | -------------------------------------------------------------------------------- /test/smoke_tests/test_bal_ceres.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | BIN_DIR="$SCRIPT_DIR/../../bin" 5 | TEST_DATA="$SCRIPT_DIR/../../data/rootba/test/bal-ladybug-problem-49-7776-pre-shrink-1800.txt" 6 | 7 | set -x 8 | set -e 9 | 10 | cd "$SCRIPT_DIR" 11 | rm -f ba_log.json 12 | time "$BIN_DIR"/bal_ceres --input "$TEST_DATA" --max-num-iterations 2 13 | [ -f ba_log.json ] && echo ok 14 | rm -f ba_log.json 15 | -------------------------------------------------------------------------------- /src/rootba/sc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(rootba_sc) 2 | 3 | target_sources(rootba_sc 4 | PUBLIC 5 | linearization_sc.hpp 6 | landmark_block.hpp 7 | linearization_power_sc.hpp 8 | PRIVATE 9 | ) 10 | 11 | target_link_libraries(rootba_sc 12 | PUBLIC 13 | rootba 14 | ) 15 | 16 | if(ROOTBA_ENABLE_TESTING) 17 | 18 | rootba_add_test(test_librootba_power_sc 19 | linearization_power_sc.test.cpp 20 | LINK_LIBRARIES 21 | rootba_cg 22 | rootba_testing 23 | ) 24 | 25 | endif() 26 | -------------------------------------------------------------------------------- /cmake/PreventInSourceBuild.cmake: -------------------------------------------------------------------------------- 1 | 2 | # disallow in-source builds since it creates a lot of generated 3 | # files in all subdirectories that are a pain to clean 4 | function(prevent_in_source_build) 5 | get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH) 6 | get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH) 7 | 8 | if("${srcdir}" STREQUAL "${bindir}") 9 | message(FATAL_ERROR "In source build is disallowed. Please run cmake from 'build' directory. Quitting configuration!") 10 | endif() 11 | endfunction() 12 | 13 | prevent_in_source_build() 14 | -------------------------------------------------------------------------------- /scripts/rerun-failed-in.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ## 3 | ## BSD 3-Clause License 4 | ## 5 | ## This file is part of the RootBA project. 6 | ## https://github.com/NikolausDemmel/rootba 7 | ## 8 | ## Copyright (c) 2021, Nikolaus Demmel. 9 | ## All rights reserved. 10 | ## 11 | 12 | # 13 | # Usage: 14 | # rerun-failed-in.sh FOLDER 15 | # 16 | # Reruns all failed experiments that are found in a given folder. 17 | 18 | set -e 19 | 20 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 21 | 22 | "$SCRIPT_DIR"/list-jobs.sh "$1" -s -o failed | while read f; do 23 | echo "$f" 24 | "$SCRIPT_DIR"/rerun-one-in.sh "$f" || true 25 | done 26 | -------------------------------------------------------------------------------- /src/rootba/cg/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(rootba_cg) 2 | 3 | target_sources(rootba_cg 4 | PUBLIC 5 | block_sparse_matrix.hpp 6 | conjugate_gradient.hpp 7 | preconditioner.hpp 8 | utils.hpp 9 | ) 10 | 11 | target_link_libraries(rootba_cg 12 | PUBLIC 13 | rootba 14 | ) 15 | 16 | if(ROOTBA_ENABLE_TESTING) 17 | 18 | rootba_add_test(test_librootba_block_sparse_matrix 19 | block_sparse_matrix.test.cpp 20 | LINK_LIBRARIES 21 | rootba_cg 22 | rootba_testing 23 | ) 24 | 25 | rootba_add_test(test_librootba_preconditioner 26 | preconditioner.test.cpp 27 | LINK_LIBRARIES 28 | rootba_cg 29 | rootba_testing 30 | ) 31 | 32 | endif() 33 | -------------------------------------------------------------------------------- /scripts/generate-tables.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # BSD 3-Clause License 4 | # 5 | # This file is part of the RootBA project. 6 | # https://github.com/NikolausDemmel/rootba 7 | # 8 | # Copyright (c) 2021, Nikolaus Demmel. 9 | # All rights reserved. 10 | # 11 | 12 | # Dependencies: 13 | # pip3 install -U --user py_ubjson matplotlib numpy munch scipy pylatex toml 14 | 15 | # also: latexmk and latex 16 | # 17 | # Ubuntu: 18 | # sudo apt install texlive-latex-extra latexmk 19 | 20 | import os 21 | import sys 22 | 23 | sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "python"))) 24 | 25 | import rootba.generate_tables 26 | 27 | rootba.generate_tables.main() 28 | -------------------------------------------------------------------------------- /scripts/yapf-all.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ## 3 | ## BSD 3-Clause License 4 | ## 5 | ## This file is part of the RootBA project. 6 | ## https://github.com/NikolausDemmel/rootba 7 | ## 8 | ## Copyright (c) 2021, Nikolaus Demmel. 9 | ## All rights reserved. 10 | ## 11 | 12 | 13 | # Format all python source files in the project. 14 | # Optionally take folder as argument; default are `python` and `script` dirs. 15 | 16 | set -e 17 | 18 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 19 | 20 | # default folders if not passed 21 | if [ $# -lt 1 ]; then 22 | set -- "$SCRIPT_DIR"/../python "$SCRIPT_DIR" 23 | fi 24 | 25 | echo "Formatting: $@" 26 | 27 | yapf -i -r "$@" 28 | -------------------------------------------------------------------------------- /src/rootba/ceres/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(rootba_ceres) 2 | 3 | target_sources(rootba_ceres 4 | PUBLIC 5 | ba_log_utils.hpp 6 | loss_function.hpp 7 | bal_bundle_adjustment.hpp 8 | bal_iteration_callback.hpp 9 | bal_residuals.hpp 10 | option_utils.hpp 11 | types.hpp 12 | PRIVATE 13 | ba_log_utils.cpp 14 | loss_function.cpp 15 | bal_bundle_adjustment.cpp 16 | bal_iteration_callback.cpp 17 | option_utils.cpp 18 | ) 19 | 20 | # include order: ceres first; ensure ceres is found first in the specified location, not in /usr/local (on macOS with homebrew) 21 | target_link_libraries(rootba_ceres PUBLIC Ceres::ceres) 22 | 23 | target_link_libraries(rootba_ceres 24 | PUBLIC 25 | rootba 26 | ) 27 | -------------------------------------------------------------------------------- /ci/docker/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | REPO=registry.gitlab.vision.in.tum.de/rootba/rootba 4 | #REPO=ghcr.io/nikolausdemmel/rootba 5 | 6 | if [[ $(uname -m) == 'x86_64' ]]; then 7 | BUILD_CMD="docker build" 8 | else 9 | # make sure to build for x86 on ARM and other platforms 10 | BUILD_CMD="docker buildx build --platform=linux/amd64" 11 | fi 12 | 13 | $BUILD_CMD --pull -f Dockerfile_20.04 -t $REPO/ubuntu-ci-rootba:20.04 . 14 | $BUILD_CMD --pull -f Dockerfile_22.04 -t $REPO/ubuntu-ci-rootba:22.04 . 15 | 16 | #docker push $REPO/ubuntu-ci-rootba:20.04 17 | #docker push $REPO/ubuntu-ci-rootba:22.04 18 | 19 | #docker tag $REPO/ubuntu-ci-rootba:22.04 $REPO/ubuntu-ci-rootba:latest 20 | #docker push $REPO/ubuntu-ci-rootba:latest 21 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 7 | ## [Unreleased] 8 | 9 | ## [0.10.0] - 2023-06-18 10 | ### Added 11 | - Open source release of the PoBA implementation for CVPR 2023. 12 | 13 | ## [0.9.0] - 2021-05-31 14 | ### Added 15 | - Open source release of the RootBA project for CVPR 2021. 16 | 17 | [Unreleased]: https://github.com/NikolausDemmel/rootba/compare/v0.10.0...HEAD 18 | [0.10.0]: https://github.com/NikolausDemmel/rootba/compare/v0.9.0...v0.10.0 19 | [0.9.0]: https://github.com/NikolausDemmel/rootba/releases/tag/v0.9.0 20 | -------------------------------------------------------------------------------- /examples/config/rootba_config_example.toml: -------------------------------------------------------------------------------- 1 | 2 | [dataset] 3 | #rotation_sigma = 0.01 4 | #translation_sigma = 0.01 5 | #point_sigma = 0.01 6 | #random_seed = 38401 7 | init_depth_threshold = 0.1 8 | #save_output = true 9 | 10 | 11 | [solver] 12 | #verbosity_level = 2 13 | #log.save_log_flags = ["UBJSON"] 14 | 15 | #staged_execution = false 16 | use_double = true 17 | 18 | #solver_type = "CERES" 19 | #linear_solver_type = "ITERATIVE_SCHUR" 20 | #linear_solver_type = "CGNR" 21 | #preconditioner_type = "JACOBI" 22 | #use_explicit_schur_complement = true 23 | 24 | #optimized_cost = "ERROR" 25 | #min_linear_solver_iterations = 20 26 | 27 | max_num_iterations = 20 28 | function_tolerance = 1e-6 29 | 30 | #residual.robust_norm = "NONE" 31 | residual.robust_norm = "HUBER" 32 | residual.huber_parameter = 1.0 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /scripts/rerun-one-in.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ## 3 | ## BSD 3-Clause License 4 | ## 5 | ## This file is part of the RootBA project. 6 | ## https://github.com/NikolausDemmel/rootba 7 | ## 8 | ## Copyright (c) 2021, Nikolaus Demmel. 9 | ## All rights reserved. 10 | ## 11 | 12 | set -e 13 | set -x 14 | 15 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 16 | 17 | FOLDER="${1}" 18 | 19 | cd "$FOLDER" 20 | 21 | # backup previous files 22 | DATE=`date +'%Y%m%d-%H%M%S'` 23 | BACKUP_FOLDER=results-backup-$DATE 24 | for f in *.jobid *.log *log.*json; do 25 | if [ -f $f ]; then 26 | mkdir -p $BACKUP_FOLDER 27 | mv $f $BACKUP_FOLDER/ 28 | fi 29 | done 30 | 31 | echo "Created" > status.log 32 | echo "Restarted" >> status.log 33 | 34 | echo "Starting run in $PWD" 35 | "$SCRIPT_DIR"/run-one.sh "$PWD" 36 | -------------------------------------------------------------------------------- /src/rootba/solver/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(rootba_solver) 2 | 3 | target_sources(rootba_solver 4 | PUBLIC 5 | bal_bundle_adjustment.hpp 6 | linearizor.hpp 7 | linearizor_base.hpp 8 | linearizor_power_sc.hpp 9 | linearizor_qr.hpp 10 | linearizor_sc.hpp 11 | solver_summary.hpp 12 | PRIVATE 13 | bal_bundle_adjustment.cpp 14 | linearizor.cpp 15 | linearizor_base.cpp 16 | linearizor_power_sc.cpp 17 | linearizor_qr.cpp 18 | linearizor_sc.cpp 19 | ) 20 | 21 | target_link_libraries(rootba_solver 22 | PUBLIC 23 | rootba 24 | rootba_cg 25 | rootba_qr 26 | rootba_sc 27 | ) 28 | 29 | if(ROOTBA_ENABLE_TESTING) 30 | 31 | rootba_add_test(test_librootba_solver 32 | bal_bundle_adjustment.test.cpp 33 | LINK_LIBRARIES 34 | rootba_solver 35 | rootba_testing 36 | ) 37 | 38 | endif() 39 | -------------------------------------------------------------------------------- /src/rootba/util/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(rootba 2 | PUBLIC 3 | assert.hpp 4 | cast.hpp 5 | container_traits.hpp 6 | eigen_types.hpp 7 | enum_utils.hpp 8 | format.hpp 9 | json_utils.hpp 10 | own_or_reference.hpp 11 | pprint_utils.hpp 12 | serialization.hpp 13 | stl_utils.hpp 14 | system_utils.hpp 15 | tbb_utils.hpp 16 | template_utils.hpp 17 | test_io_utils.hpp 18 | time_utils.hpp 19 | toml_utils.hpp 20 | typesafe_utils.hpp 21 | visit_struct_utils.hpp 22 | PRIVATE 23 | system_utils.cpp 24 | tbb_utils.cpp 25 | ) 26 | 27 | if(ROOTBA_ENABLE_TESTING) 28 | 29 | rootba_add_test(test_librootba_util 30 | own_or_reference.test.cpp 31 | stl_utils.test.cpp 32 | system_utils.test.cpp 33 | LINK_LIBRARIES 34 | rootba 35 | ) 36 | 37 | endif() 38 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | Language: Cpp 2 | BasedOnStyle: Google 3 | Standard: Cpp11 4 | 5 | IndentWidth: 2 6 | ColumnLimit: 80 7 | 8 | # force the alignment of pointer/reference declarations 9 | DerivePointerAlignment: false 10 | PointerAlignment: Left 11 | 12 | # group header blocks 13 | IncludeBlocks: Regroup 14 | IncludeCategories: 15 | # rootba headers 16 | - Regex: '^"rootba.*\.hpp"' 17 | Priority: 4 18 | # external libraries 19 | - Regex: '^<.*/.*>' 20 | Priority: 3 21 | # standard C headers 22 | - Regex: '^<.*\.h>' 23 | Priority: 2 24 | # standard STL headers 25 | - Regex: '^<.*' 26 | Priority: 1 27 | # leftover 28 | - Regex: '.*' 29 | Priority: 5 30 | IncludeIsMainRegex: '([-_.](test|unittest))?$' 31 | IncludeIsMainSourceRegex: '' 32 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10 FATAL_ERROR) 2 | # Note: We need 3.10 or later for gtest_discover_tests 3 | 4 | # Note: Some unit tests are defined directly in subfolders in the src folder 5 | 6 | add_test(NAME smoke_test_bal 7 | COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/smoke_tests/test_bal.sh 8 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) 9 | 10 | add_test(NAME smoke_test_bal_qr 11 | COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/smoke_tests/test_bal_qr.sh 12 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) 13 | 14 | add_test(NAME smoke_test_bal_sc 15 | COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/smoke_tests/test_bal_sc.sh 16 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) 17 | 18 | add_test(NAME smoke_test_bal_ceres 19 | COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/smoke_tests/test_bal_ceres.sh 20 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) 21 | -------------------------------------------------------------------------------- /scripts/utils/on-slurm-detect-cpu.sh: -------------------------------------------------------------------------------- 1 | ## 2 | ## BSD 3-Clause License 3 | ## 4 | ## This file is part of the RootBA project. 5 | ## https://github.com/NikolausDemmel/rootba 6 | ## 7 | ## Copyright (c) 2021, Nikolaus Demmel. 8 | ## All rights reserved. 9 | ## 10 | 11 | # helper to detect the CPU type for our slurm machines 12 | case `LC_ALL=C lscpu | grep 'Model name'` in 13 | *"Intel(R) Xeon(R) CPU E5-26"*) 14 | ARCH_SUFFIX=sbep 15 | ;; 16 | *"Intel(R) Xeon(R) Gold 6148"*) 17 | ARCH_SUFFIX=skyl 18 | ;; 19 | *"Intel(R) Xeon(R) Gold 6248"*) 20 | ARCH_SUFFIX=cl 21 | ;; 22 | *"Intel(R) Xeon(R) Gold 6254"*) 23 | ARCH_SUFFIX=cl 24 | ;; 25 | *) 26 | ARCH_SUFFIX=unknown 27 | ;; 28 | esac 29 | 30 | if [ "$ARCH_SUFFIX" == unknown ]; then 31 | echo "Could not detect CPU architecture. Are you running this on slurm?" 32 | exit 1 33 | fi 34 | 35 | -------------------------------------------------------------------------------- /scripts/update-license-headers.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ## 3 | ## BSD 3-Clause License 4 | ## 5 | ## This file is part of the RootBA project. 6 | ## https://github.com/NikolausDemmel/rootba 7 | ## 8 | ## Copyright (c) 2021, Nikolaus Demmel. 9 | ## All rights reserved. 10 | ## 11 | 12 | # Update license headers in source files. 13 | 14 | # Dependency: licenseheaders python package (install with pip) 15 | 16 | # TODO: Make it also update C++ files automatically. (Consider files with multiple headers, e.g. SolverSummary.hpp) 17 | 18 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 19 | 20 | DIRS=( 21 | "$SCRIPT_DIR/../python/" 22 | "$SCRIPT_DIR/../scripts" 23 | ) 24 | 25 | YEAR=2021 26 | OWNER="Nikolaus Demmel" 27 | TEMPLATE="$SCRIPT_DIR/templates/license-py-sh.tmpl" 28 | 29 | for d in "${DIRS[@]}" 30 | do 31 | licenseheaders -d "$d" -y $YEAR -o "$OWNER" -t "$TEMPLATE" -vv 32 | done 33 | 34 | -------------------------------------------------------------------------------- /src/rootba/bal/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | target_sources(rootba 3 | PUBLIC 4 | ba_log.hpp 5 | ba_log_options.hpp 6 | ba_log_utils.hpp 7 | bal_app_options.hpp 8 | bal_bundle_adjustment_helper.hpp 9 | bal_dataset_options.hpp 10 | bal_pipeline_summary.hpp 11 | bal_residual_options.hpp 12 | common_types.hpp 13 | bal_problem.hpp 14 | bal_problem_io.hpp 15 | residual_info.hpp 16 | snavely_projection.hpp 17 | solver_options.hpp 18 | PRIVATE 19 | ba_log.cpp 20 | ba_log_utils.cpp 21 | bal_bundle_adjustment_helper.cpp 22 | bal_problem.cpp 23 | residual_info.cpp 24 | solver_options.cpp 25 | ) 26 | 27 | if(ROOTBA_ENABLE_TESTING) 28 | 29 | rootba_add_test(test_librootba_bal 30 | bal_bundle_adjustment_helper.test.cpp 31 | bal_problem_io.test.cpp 32 | snavely_projection.test.cpp 33 | LINK_LIBRARIES 34 | rootba 35 | rootba_testing 36 | ) 37 | 38 | endif() 39 | -------------------------------------------------------------------------------- /src/app/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # IPO seems to result in strange crashes in some configuration; also hard to debug even in Debug build... 2 | 3 | #include(CheckIPOSupported) 4 | #check_ipo_supported(LANGUAGES CXX RESULT IPO_SUPPORTED OUTPUT IPO_OUTPUT) 5 | #message(STATUS "Link-time optimization support: ${IPO_SUPPORTED}") 6 | #if(IPO_SUPPORTED) 7 | # set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) 8 | #else() 9 | # message(STATUS "${IPO_OUTPUT}") 10 | #endif() 11 | 12 | add_executable(bal bal.cpp) 13 | target_link_libraries(bal rootba_solver rootba_ceres rootba_cli) 14 | 15 | add_executable(bal_gui bal_gui.cpp) 16 | target_link_libraries(bal_gui rootba_pangolin rootba_solver rootba_ceres rootba_cli) 17 | 18 | add_executable(bal_ceres bal_ceres.cpp) 19 | target_link_libraries(bal_ceres rootba_ceres rootba_cli) 20 | 21 | add_executable(bal_qr bal_qr.cpp) 22 | target_link_libraries(bal_qr rootba_solver rootba_cli) 23 | 24 | add_executable(bal_sc bal_sc.cpp) 25 | target_link_libraries(bal_sc rootba_solver rootba_cli) 26 | -------------------------------------------------------------------------------- /external/download_copied_sources.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # This is here for future reference, to document which source files, 4 | # that are included as a copy (and not e.g. submodule), are downloaded 5 | # from where and with which version. 6 | 7 | # paths are relative to the directory containing this script 8 | THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 9 | cd "$THIS_DIR" 10 | 11 | # magic_enum 12 | curl https://raw.githubusercontent.com/Neargye/magic_enum/v0.9.2/include/magic_enum.hpp --create-dirs -o magic_enum/magic_enum/magic_enum.hpp 13 | 14 | # json 15 | curl https://raw.githubusercontent.com/nlohmann/json/v3.11.2/single_include/nlohmann/json.hpp --create-dirs -o json/nlohmann/json.hpp 16 | curl https://raw.githubusercontent.com/nlohmann/json/v3.11.2/single_include/nlohmann/json_fwd.hpp -o json/nlohmann/json_fwd.hpp 17 | 18 | # pprint 19 | curl https://raw.githubusercontent.com/p-ranav/pprint/0ee09c8d8a9eebc944d07ac69e3b86d41f2304df/include/pprint.hpp --create-dirs -o pprint/pprint/pprint.hpp 20 | -------------------------------------------------------------------------------- /src/rootba/qr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(rootba_qr) 2 | 3 | target_sources(rootba_qr 4 | PUBLIC 5 | landmark_block.hpp 6 | linearization_qr.hpp 7 | linearization_utils.hpp 8 | PRIVATE 9 | landmark_block.cpp 10 | landmark_block_base.hpp 11 | landmark_block_dynamic.hpp 12 | impl/landmark_block_base.ipp 13 | impl/landmark_block_dynamic.cpp 14 | ) 15 | 16 | if(ROOTBA_INSTANTIATIONS_STATIC_LMB) 17 | target_sources(rootba_qr 18 | PRIVATE 19 | landmark_block_static.hpp 20 | impl/landmark_block_static_2.cpp 21 | impl/landmark_block_static_3.cpp 22 | impl/landmark_block_static_4.cpp 23 | impl/landmark_block_static_5.cpp 24 | impl/landmark_block_static_6.cpp 25 | impl/landmark_block_static_7.cpp 26 | impl/landmark_block_static_8.cpp 27 | ) 28 | endif() 29 | 30 | target_link_libraries(rootba_qr 31 | PUBLIC 32 | rootba 33 | ) 34 | 35 | 36 | if(ROOTBA_ENABLE_TESTING) 37 | 38 | rootba_add_test(test_librootba_qr 39 | linearization_qr.test.cpp 40 | LINK_LIBRARIES 41 | rootba_qr 42 | rootba_testing 43 | ) 44 | 45 | endif() 46 | -------------------------------------------------------------------------------- /external/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(BUILD_SHARED_LIBS OFF) 3 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) 4 | 5 | # for subprojects 6 | set(CMAKE_CXX_STANDARD ${ROOTBA_CXX_STANDARD}) 7 | 8 | # Abseil 9 | #add_subdirectory(abseil-cpp EXCLUDE_FROM_ALL) 10 | 11 | if(ROOTBA_ENABLE_TESTING) 12 | set(BUILD_SHARED_LIBS Off) 13 | # TODO: check CMP0077 error 14 | #set(INSTALL_GTEST Off) 15 | # TODO: check CMP0048 and fix upstream 16 | 17 | message(STATUS "Configuring external 'googletest'") 18 | add_subdirectory(googletest EXCLUDE_FROM_ALL) 19 | # link to gtest and gtest_main to use gtest 20 | 21 | 22 | # ensure gtest include directory is added before any of the 23 | # system-wide include directories that might contain gtest 24 | 25 | #include_directories(BEFORE ${gtest_SOURCE_DIR}/include) 26 | #set_property(TARGET gtest PROPERTY BEFORE INTERFACE_INCLUDE_DIRECTORIES ${gtest_SOURCE_DIR}/include) 27 | #target_include_directories(gtest BEFORE INTERFACE ${gtest_SOURCE_DIR}/include) 28 | 29 | # TODO: check if this is still the right way... 30 | #target_include_directories(gtest BEFORE INTERFACE googletest/googletest/include) 31 | endif() 32 | 33 | message(STATUS "Done configuring externals") 34 | -------------------------------------------------------------------------------- /.github/workflows/build_docker_images.yml: -------------------------------------------------------------------------------- 1 | name: Build Docker Images 2 | 3 | on: workflow_dispatch 4 | 5 | jobs: 6 | build-docker: 7 | name: Build docker images for CI 8 | runs-on: ubuntu-latest 9 | permissions: 10 | packages: write 11 | contents: read 12 | env: 13 | IMAGE: "ghcr.io/nikolausdemmel/rootba/ubuntu-ci-rootba" 14 | steps: 15 | - name: Check out the repo 16 | uses: actions/checkout@v3 17 | - name: Login to GitHub Container Registry 18 | uses: docker/login-action@v2 19 | with: 20 | registry: ghcr.io 21 | username: ${{ github.repository_owner }} 22 | password: ${{ secrets.GITHUB_TOKEN }} 23 | - name: Build docker images 24 | shell: bash 25 | run: | 26 | cd ci/docker 27 | for tag in 20.04 22.04; do 28 | # fetches the latest image for cache (not failing if image is not found) 29 | docker pull $IMAGE:$tag || true 30 | docker build --pull --cache-from $IMAGE:$tag -f Dockerfile_$tag -t $IMAGE:$tag . 31 | docker push $IMAGE:$tag 32 | done 33 | # tag the last image as 'latest' 34 | docker tag $IMAGE:$tag $IMAGE:latest 35 | docker push $IMAGE:latest 36 | -------------------------------------------------------------------------------- /scripts/num_ops/compute_num_ops_symbolic.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # BSD 3-Clause License 4 | # 5 | # This file is part of the RootBA project. 6 | # https://github.com/NikolausDemmel/rootba 7 | # 8 | # Copyright (c) 2021, Nikolaus Demmel. 9 | # All rights reserved. 10 | # 11 | 12 | from sympy import * 13 | from operation_counts import * 14 | 15 | n_landmarks = symbols('n_l') 16 | num_iter_cg = symbols('n_i') 17 | dim_poses = symbols('d_p') 18 | N_p, N_r = symbols('N_p N_r') 19 | 20 | # cost of QR decomposition 21 | n_qr = ops_nm_decomposition(n_landmarks, N_p, N_r) 22 | print('n_qr\t\t', expand(n_qr)) 23 | 24 | # cost of Schur complement computation 25 | n_sc = ops_schur_complement(n_landmarks, dim_poses, N_p, N_r) 26 | print('n_sc\t\t', expand(n_sc)) 27 | 28 | # # # cost of explicit Hessian computation 29 | # # print('qr_h\t\t', qr_h, '\t', qr_h * 1e-12) 30 | 31 | # cost of CGNR (on QR-reduced system) 32 | lscg_mat_op_all = ops_cgnr(N_r - 3 * n_landmarks, N_p, num_iter_cg) 33 | print('lscg_mat_op_all\t', expand(lscg_mat_op_all)) 34 | 35 | # total QR cost (decomposition + CGNR) 36 | n_qr_lscg = n_qr + lscg_mat_op_all 37 | print('n_qr_lscg\t', expand(n_qr_lscg)) 38 | 39 | # cost of CG (on Schur-reduced system) 40 | cg_mat_op_all = ops_conjugate_gradient(N_p, num_iter_cg) 41 | print('cg_mat_op_all\t', expand(cg_mat_op_all)) 42 | 43 | # total Schur cost (SC computation + CG) 44 | n_sc_cg = n_sc + cg_mat_op_all 45 | print('n_sc_cg\t\t', expand(n_sc_cg)) 46 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2021-2023, Nikolaus Demmel. 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /scripts/num_ops/operation_counts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # BSD 3-Clause License 4 | # 5 | # This file is part of the RootBA project. 6 | # https://github.com/NikolausDemmel/rootba 7 | # 8 | # Copyright (c) 2021, Nikolaus Demmel. 9 | # All rights reserved. 10 | # 11 | 12 | 13 | def ops_nm_decomposition(n_l, N_p, N_r): 14 | "Compute number of flops for nullspace marginalization (excluding linear system solution)" 15 | N_qr = 72 * (N_r - 2 * n_l) # QR decomposition of block-sparse landmark Jacobian 16 | N_qj = 18 * (N_r - 2 * n_l) * (N_p + 1) # multiplication of Q' with (Jp|r) 17 | N_bs = 6 * n_l * (N_p + 2) # back substitution step 18 | return N_qr + N_qj + N_bs 19 | 20 | 21 | def ops_schur_complement(n_l, d_p, N_p, N_r): 22 | "Compute number of flops for setting up Schur-reduced system and back-substitution" 23 | N_bl = 2 * N_r * (d_p * d_p + 4 * d_p + 12) # compute sub-blocks of Hessian and RHS vector 24 | N_red = 6 * n_l * (N_p * N_p + 4 * N_p + 7) # compute reduced system 25 | N_bs = 6 * n_l * (N_p + 3) # back substitution step 26 | return N_bl + N_red + N_bs 27 | 28 | 29 | def ops_conjugate_gradient(n_r, n_i): 30 | "Compute number of flops for performing CG on a linear system" 31 | N_init = 2 * n_r # initialization (only once) 32 | N_loop = 2 * n_r * n_r + 8 * n_r + 1 # loop (in each step) 33 | return N_init + n_i * N_loop 34 | 35 | 36 | def ops_cgnr(n_r, n_c, n_i): 37 | N_init = 4 * n_r * n_c + 2 * n_c # initialization (only once) 38 | N_loop = 4 * n_r * n_c + 4 * n_r + 6 * n_c + 1 # loop (in each step) 39 | return N_init + n_i * N_loop 40 | -------------------------------------------------------------------------------- /examples/config/rootba_config_default.toml: -------------------------------------------------------------------------------- 1 | 2 | [dataset] 3 | input = "" 4 | input_type = "AUTO" 5 | save_output = false 6 | output_optimized_path = "optimized.cereal" 7 | normalize = true 8 | normalization_scale = 100.0 9 | rotation_sigma = 0.0 10 | translation_sigma = 0.0 11 | point_sigma = 0.0 12 | random_seed = 38401 13 | init_depth_threshold = 0.0 14 | quiet = false 15 | 16 | [solver] 17 | solver_type = "SQUARE_ROOT" 18 | verbosity_level = 2 19 | debug = false 20 | num_threads = 0 21 | optimized_cost = "ERROR" 22 | max_num_iterations = 20 23 | min_relative_decrease = 0.0 24 | initial_trust_region_radius = 10000.0 25 | min_trust_region_radius = 1e-32 26 | max_trust_region_radius = 1e+16 27 | min_lm_diagonal = 1e-06 28 | max_lm_diagonal = 1e+32 29 | min_linear_solver_iterations = 0 30 | max_linear_solver_iterations = 500 31 | eta = 0.1 32 | jacobi_scaling = true 33 | jacobi_scaling_epsilon = 0.0 34 | preconditioner_type = "SCHUR_JACOBI" 35 | linear_solver_type = "ITERATIVE_SCHUR" 36 | use_explicit_schur_complement = false 37 | function_tolerance = 1e-06 38 | gradient_tolerance = 0.0 39 | parameter_tolerance = 0.0 40 | check_gradients = false 41 | gradient_check_relative_precision = 1e-08 42 | gradient_check_numeric_derivative_relative_step_size = 1e-06 43 | use_double = true 44 | use_householder_marginalization = true 45 | staged_execution = true 46 | reduction_alg = 1 47 | power_order = 10 48 | initial_vee = 2.0 49 | vee_factor = 2.0 50 | 51 | [solver.residual] 52 | robust_norm = "NONE" 53 | huber_parameter = 1.0 54 | 55 | [solver.log] 56 | log_path = "ba_log.json" 57 | save_log_flags = [ 58 | "JSON", 59 | ] 60 | disable_all = false 61 | 62 | 63 | -------------------------------------------------------------------------------- /scripts/num_ops/compute_num_ops_example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # BSD 3-Clause License 4 | # 5 | # This file is part of the RootBA project. 6 | # https://github.com/NikolausDemmel/rootba 7 | # 8 | # Copyright (c) 2021, Nikolaus Demmel. 9 | # All rights reserved. 10 | # 11 | 12 | from operation_counts import * 13 | 14 | n_poses = 1778 15 | n_landmarks = 993923 16 | n_obs = 5001946 17 | 18 | num_iter_cg = 100 19 | 20 | dim_poses = 9 21 | dim_landmarks = 3 22 | dim_res = 2 23 | 24 | N_p = n_poses * dim_poses 25 | # N_l = n_landmarks * dim_landmarks 26 | N_r = n_obs * dim_res 27 | 28 | # cost of QR decomposition 29 | n_qr = ops_nm_decomposition(n_landmarks, N_p, N_r) 30 | print('n_qr\t\t', n_qr, '\t\t', n_qr * 1e-12) 31 | 32 | # cost of Schur complement computation 33 | n_sc = ops_schur_complement(n_landmarks, dim_poses, N_p, N_r) 34 | print('n_sc\t\t', n_sc, '\t', n_sc * 1e-12) 35 | 36 | # # cost of explicit Hessian computation 37 | # print('qr_h\t\t', qr_h, '\t', qr_h * 1e-12) 38 | 39 | # cost of CGNR (on QR-reduced system) 40 | lscg_mat_op_all = ops_cgnr(N_r - 3 * n_landmarks, N_p, num_iter_cg) 41 | print('lscg_mat_op_all\t', lscg_mat_op_all, '\t', lscg_mat_op_all * 1e-12) 42 | 43 | # total QR cost (decomposition + CGNR) 44 | n_qr_lscg = n_qr + lscg_mat_op_all 45 | print('n_qr_lscg\t', n_qr_lscg, '\t', n_qr_lscg * 1e-12) 46 | 47 | # cost of CG (on Schur-reduced system) 48 | cg_mat_op_all = ops_conjugate_gradient(N_p, num_iter_cg) 49 | print('cg_mat_op_all\t', cg_mat_op_all, '\t\t', cg_mat_op_all * 1e-12) 50 | 51 | # total Schur cost (SC computation + CG) 52 | n_sc_cg = n_sc + cg_mat_op_all 53 | print('n_sc_cg\t\t', n_sc_cg, '\t', n_sc_cg * 1e-12) 54 | -------------------------------------------------------------------------------- /scripts/clang-format-all.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ## 3 | ## BSD 3-Clause License 4 | ## 5 | ## This file is part of the RootBA project. 6 | ## https://github.com/NikolausDemmel/rootba 7 | ## 8 | ## Copyright (c) 2021-2023, Nikolaus Demmel. 9 | ## All rights reserved. 10 | ## 11 | 12 | 13 | # Format all source files in the project. 14 | # Optionally take folder as argument; default is full inlude and src dirs. 15 | 16 | set -e 17 | 18 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 19 | 20 | FOLDER="${1:-$SCRIPT_DIR/../src}" 21 | 22 | CLANG_FORMAT_COMMANDS="clang-format-17 clang-format-16 clang-format-15 clang-format-14 clang-format-13 clang-format-12 clang-format-11 clang-format-10 clang-format" 23 | 24 | # find the first available command: 25 | for CMD in $CLANG_FORMAT_COMMANDS; do 26 | if hash $CMD 2>/dev/null; then 27 | CLANG_FORMAT_CMD=$CMD 28 | break 29 | fi 30 | done 31 | 32 | if [ -z $CLANG_FORMAT_CMD ]; then 33 | echo "clang-format not installed..." 34 | exit 1 35 | fi 36 | 37 | # clang format check version 38 | MAJOR_VERSION_NEEDED=10 39 | 40 | MAJOR_VERSION_DETECTED=`$CLANG_FORMAT_CMD -version | sed -n -E 's/.*version ([0-9]+).*/\1/p'` 41 | if [ -z $MAJOR_VERSION_DETECTED ]; then 42 | echo "Failed to parse major version (`$CLANG_FORMAT_CMD -version`)" 43 | exit 1 44 | fi 45 | 46 | echo "clang-format version $MAJOR_VERSION_DETECTED (`$CLANG_FORMAT_CMD -version`)" 47 | 48 | if [ $MAJOR_VERSION_DETECTED -lt $MAJOR_VERSION_NEEDED ]; then 49 | echo "Looks like your clang format is too old; need at least version $MAJOR_VERSION_NEEDED" 50 | exit 1 51 | fi 52 | 53 | find $FOLDER -iname "*.?pp" | xargs $CLANG_FORMAT_CMD -verbose -i 54 | -------------------------------------------------------------------------------- /python/rootba/latex/util.py: -------------------------------------------------------------------------------- 1 | # 2 | # BSD 3-Clause License 3 | # 4 | # This file is part of the RootBA project. 5 | # https://github.com/NikolausDemmel/rootba 6 | # 7 | # Copyright (c) 2021, Nikolaus Demmel. 8 | # All rights reserved. 9 | # 10 | import math 11 | import numpy as np 12 | 13 | 14 | def best_two_non_repeating(array, reverse=False): 15 | if reverse: 16 | best = -math.inf 17 | second = -math.inf 18 | for v in array: 19 | if v > best: 20 | second = best 21 | best = v 22 | elif v < best and v > second: 23 | second = v 24 | else: 25 | best = math.inf 26 | second = math.inf 27 | for v in array: 28 | if v < best: 29 | second = best 30 | best = v 31 | elif v > best and v < second: 32 | second = v 33 | 34 | return best, second 35 | 36 | 37 | def format_ratio(val, val_ref=None, decimals=0): 38 | if val_ref == 0: 39 | return "{}".format(math.inf) 40 | else: 41 | if val_ref is not None: 42 | val = float(val) / float(val_ref) 43 | return "{:.{prec}f}".format(val, prec=decimals) 44 | 45 | 46 | def format_ratio_percent(val, val_ref=None, decimals=0): 47 | if val_ref == 0: 48 | return "{}".format(val) 49 | else: 50 | if val_ref is not None: 51 | val = float(val) / float(val_ref) 52 | val = 100 * val 53 | return "{:.{prec}f}%".format(val, prec=decimals) 54 | 55 | 56 | def rotation2d(theta_deg): 57 | theta = np.radians(theta_deg) 58 | 59 | R = np.array(((np.cos(theta), -np.sin(theta)), (np.sin(theta), np.cos(theta)))) 60 | 61 | return R 62 | -------------------------------------------------------------------------------- /src/rootba/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13 FATAL_ERROR) 2 | # Note: 3.13 for target_sources with relative paths 3 | 4 | add_library(rootba) 5 | 6 | target_include_directories(rootba PUBLIC "${CMAKE_SOURCE_DIR}/src") 7 | target_compile_features(rootba PUBLIC cxx_std_${ROOTBA_CXX_STANDARD}) 8 | set_target_properties(rootba PROPERTIES CXX_EXTENSIONS OFF) 9 | if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU") 10 | # don't use pedantic for GCC, since it warns on extra ';' --> fix wise enum 11 | target_compile_options(rootba PUBLIC -Wpedantic) 12 | endif() 13 | target_compile_options(rootba PUBLIC -ftemplate-backtrace-limit=0 -Wall -Wextra -Wnon-virtual-dtor -Wsign-compare -Wno-unused-parameter ${ROOTBA_MARCH_FLAG}) 14 | target_compile_definitions(rootba PUBLIC ${ROOTBA_COMPILE_DEFINITIONS}) 15 | 16 | if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") 17 | # offsetof is fine even for non POD types... 18 | target_compile_options(rootba PUBLIC -Wno-invalid-offsetof) 19 | endif() 20 | 21 | target_link_libraries(rootba 22 | PUBLIC 23 | rootba::Sophus 24 | rootba::visit_struct 25 | rootba::wise_enum 26 | rootba::enum_flags 27 | rootba::nameof 28 | rootba::toml11 29 | rootba::nlohmann_json 30 | rootba::basalt_headers 31 | rootba::magic_enum 32 | rootba::pprint 33 | rootba::Cereal 34 | fmt::fmt 35 | absl::flat_hash_map 36 | Eigen3::Eigen 37 | glog::glog 38 | TBB::tbb 39 | ) 40 | 41 | add_subdirectory(testing) 42 | add_subdirectory(util) 43 | add_subdirectory(options) 44 | add_subdirectory(bal) 45 | add_subdirectory(qr) 46 | add_subdirectory(sc) 47 | add_subdirectory(solver) 48 | add_subdirectory(cg) 49 | add_subdirectory(ceres) 50 | add_subdirectory(pangolin) 51 | add_subdirectory(cli) 52 | -------------------------------------------------------------------------------- /scripts/run-all-in.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ## 3 | ## BSD 3-Clause License 4 | ## 5 | ## This file is part of the RootBA project. 6 | ## https://github.com/NikolausDemmel/rootba 7 | ## 8 | ## Copyright (c) 2021, Nikolaus Demmel. 9 | ## All rights reserved. 10 | ## 11 | 12 | 13 | # given folder with rootba_config_*.toml, run optimization for each config in 14 | # corresponding subfolder 15 | 16 | set -e 17 | set -x 18 | 19 | # number of logical cores on linux and macos 20 | NUM_CORES=`(which nproc > /dev/null && nproc) || sysctl -n hw.logicalcpu || echo 1` 21 | 22 | echo "Running on '`hostname`', nproc: $NUM_CORES" 23 | 24 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 25 | 26 | # loop over all arguments, and in each folder find configs and run them 27 | for FOLDER in "$@" 28 | do 29 | 30 | pushd "$FOLDER" 31 | 32 | FILE_PATTERN='rootba_config_*.toml' 33 | FILE_REGEX='rootba_config_(.*)\.toml' 34 | 35 | DATE=`date +'%Y%m%d-%H%M%S'` 36 | mkdir -p $DATE 37 | 38 | declare -a RUN_DIRS=() 39 | 40 | for f in `find . -name "$FILE_PATTERN" -type f | sort`; do 41 | if [[ `basename $f` =~ $FILE_REGEX ]]; then 42 | RUN_DIR=${DATE}/`dirname $f`/${BASH_REMATCH[1]} 43 | echo "Creating run with config $f in $RUN_DIR" 44 | mkdir -p "$RUN_DIR" 45 | cp $f "$RUN_DIR"/rootba_config.toml 46 | echo "Created" > "$RUN_DIR"/status.log 47 | RUN_DIRS+=($RUN_DIR) 48 | else 49 | echo "Skipping $f" 50 | fi 51 | done 52 | 53 | for RUN_DIR in "${RUN_DIRS[@]}"; do 54 | echo "Starting run in $RUN_DIR" 55 | "$SCRIPT_DIR"/run-one.sh "$RUN_DIR" || true 56 | done 57 | 58 | popd 59 | 60 | done 61 | -------------------------------------------------------------------------------- /src/rootba/ceres/types.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | namespace rootba { 39 | 40 | enum BalReprojectionErrorOptions { 41 | VALID_PROJECTIONS_ONLY = 1 << 0, 42 | }; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/rootba/util/json_utils.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | 40 | namespace rootba { 41 | 42 | template 43 | constexpr bool is_basic_json_v = nlohmann::detail::is_basic_json::value; 44 | 45 | } // namespace rootba 46 | -------------------------------------------------------------------------------- /scripts/query-config.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # BSD 3-Clause License 4 | # 5 | # This file is part of the RootBA project. 6 | # https://github.com/NikolausDemmel/rootba 7 | # 8 | # Copyright (c) 2021, Nikolaus Demmel. 9 | # All rights reserved. 10 | # 11 | 12 | # 13 | # Example usage: 14 | # $ ./query-config.py path/to/rooba_config.toml slurm.mem 15 | # 10G 16 | 17 | import toml 18 | import argparse 19 | import munch 20 | import sys 21 | 22 | 23 | def query_config(path, query, default_value=None, format_env=False): 24 | cfg = munch.munchify(toml.load(path)) 25 | try: 26 | result = munch.unmunchify(eval("cfg.{}".format(query))) 27 | except: 28 | if default_value is None: 29 | result = "" 30 | else: 31 | result = default_value 32 | if isinstance(result, dict): 33 | if format_env: 34 | lines = [] 35 | for k, v in result.items(): 36 | # NOTE: assumes no special escaping is necessary 37 | lines.append("{}='{}'".format(k, v)) 38 | return "\n".join(lines) 39 | else: 40 | result = toml.dumps(result) 41 | else: 42 | result = "{}".format(result) 43 | return result 44 | 45 | 46 | def main(): 47 | parser = argparse.ArgumentParser("Parse toml file and print content of query key.") 48 | parser.add_argument("config_path", help="path to toml file") 49 | parser.add_argument("query", help="query string") 50 | parser.add_argument("default_value", help="value printed if query is not successful", nargs='?') 51 | parser.add_argument( 52 | "--format-env", 53 | action="store_true", 54 | help="Expect dictionary as query result and output like environment variables, i.e. VAR='VALUE' lines.") 55 | args = parser.parse_args() 56 | 57 | res = query_config(args.config_path, args.query, default_value=args.default_value, format_env=args.format_env) 58 | print(res) 59 | 60 | 61 | if __name__ == "__main__": 62 | main() 63 | -------------------------------------------------------------------------------- /src/rootba/cli/bal_cli_utils.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include "rootba/bal/bal_app_options.hpp" 39 | 40 | namespace rootba { 41 | 42 | bool parse_bal_app_arguments(const std::string& application_summary, int argc, 43 | char** argv, BalAppOptions& options); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/rootba/pangolin/gui_helpers.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | #include 40 | 41 | namespace rootba { 42 | 43 | void render_camera(const Eigen::Matrix4d& T_w_c, float line_width, 44 | const u_int8_t* color, float size_factor); 45 | 46 | } // namespace rootba 47 | -------------------------------------------------------------------------------- /src/rootba/util/system_utils.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | 40 | namespace rootba { 41 | 42 | struct MemoryInfo { 43 | uint64_t resident_memory = 0; //!< in bytes 44 | uint64_t resident_memory_peak = 0; //!< in bytes 45 | }; 46 | 47 | bool get_memory_info(MemoryInfo& info); 48 | 49 | } // namespace rootba 50 | -------------------------------------------------------------------------------- /ci/docker/Dockerfile_22.04: -------------------------------------------------------------------------------- 1 | FROM ubuntu:22.04 2 | 3 | # non-persistent environment variables 4 | ARG DEBIAN_FRONTEND=noninteractive 5 | 6 | # Basic packages 7 | RUN apt-get update && apt-get install -y \ 8 | apt-utils \ 9 | apt-transport-https \ 10 | software-properties-common \ 11 | locales \ 12 | wget \ 13 | curl 14 | 15 | # Set the locale 16 | RUN locale-gen en_US.UTF-8 17 | ENV LANG en_US.UTF-8 18 | ENV LANGUAGE en_US:en 19 | ENV LC_ALL en_US.UTF-8 20 | 21 | # PPAs 22 | RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key| apt-key add - && \ 23 | apt-add-repository -y "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main" 24 | 25 | # updates from clang repo 26 | RUN apt-get update && apt-get dist-upgrade -y 27 | 28 | # Install base C++ dev tools 29 | RUN apt-get update && apt-get install -y \ 30 | build-essential \ 31 | clang-14 \ 32 | clang-15 \ 33 | clang-16 \ 34 | g++-11 \ 35 | g++-12 \ 36 | libc++-15-dev \ 37 | clang-format-15 \ 38 | clang-tidy-15 \ 39 | cmake \ 40 | pkg-config \ 41 | git-core \ 42 | git-lfs \ 43 | ccache 44 | 45 | # cannot install libc++-dev due to imcompatibility with libgoogle-glog-dev 46 | # https://bugs.launchpad.net/ubuntu/+source/google-glog/+bug/1991919 47 | # libc++-dev \ 48 | 49 | # Python 50 | RUN apt-get update && apt-get install -y \ 51 | python3 \ 52 | python3-pip \ 53 | libpython3-all-dev 54 | RUN pip3 install -U pip setuptools 55 | RUN pip3 install -U cmake cmake_format 56 | RUN pip3 install -U yapf 57 | ENV PATH="/usr/local/bin:${PATH}" 58 | 59 | # Install libraries 60 | RUN apt-get update && apt-get install -y \ 61 | libgoogle-glog-dev \ 62 | libgflags-dev \ 63 | libtbb-dev \ 64 | libeigen3-dev \ 65 | libatlas-base-dev \ 66 | libsuitesparse-dev \ 67 | libglew-dev \ 68 | ffmpeg \ 69 | libavcodec-dev \ 70 | libavutil-dev \ 71 | libavformat-dev \ 72 | libswscale-dev \ 73 | libavdevice-dev \ 74 | libjpeg-dev \ 75 | libpng-dev \ 76 | libtiff5-dev \ 77 | libopenexr-dev 78 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "data/rootba"] 2 | path = data/rootba 3 | url = https://github.com/NikolausDemmel/rootba_test_data.git 4 | [submodule "external/Sophus"] 5 | path = external/Sophus 6 | url = https://github.com/strasdat/Sophus.git 7 | [submodule "external/eigen"] 8 | path = external/eigen 9 | url = https://gitlab.com/libeigen/eigen.git 10 | [submodule "external/Pangolin"] 11 | path = external/Pangolin 12 | # url = https://github.com/stevenlovegrove/Pangolin.git 13 | url = https://github.com/NikolausDemmel/Pangolin.git 14 | [submodule "external/cereal"] 15 | path = external/cereal 16 | url = https://github.com/USCiLab/cereal.git 17 | [submodule "external/visit_struct"] 18 | path = external/visit_struct 19 | # url = https://github.com/cbeck88/visit_struct.git 20 | url = https://github.com/NikolausDemmel/visit_struct.git 21 | [submodule "external/fmt"] 22 | path = external/fmt 23 | url = https://github.com/fmtlib/fmt.git 24 | [submodule "external/basalt-headers"] 25 | path = external/basalt-headers 26 | url = https://gitlab.com/VladyslavUsenko/basalt-headers.git 27 | [submodule "external/abseil-cpp"] 28 | path = external/abseil-cpp 29 | url = https://github.com/abseil/abseil-cpp.git 30 | [submodule "external/clipp/clipp"] 31 | path = external/clipp/clipp 32 | url = https://github.com/muellan/clipp.git 33 | [submodule "external/ceres-solver"] 34 | path = external/ceres-solver 35 | url = https://github.com/ceres-solver/ceres-solver.git 36 | [submodule "external/googletest"] 37 | path = external/googletest 38 | url = https://github.com/google/googletest.git 39 | [submodule "external/wise_enum/wise_enum"] 40 | path = external/wise_enum/wise_enum 41 | url = https://github.com/quicknir/wise_enum.git 42 | [submodule "external/enum-flags"] 43 | path = external/enum-flags 44 | url = https://github.com/grisumbras/enum-flags.git 45 | [submodule "external/toml11/toml11"] 46 | path = external/toml11/toml11 47 | url = https://github.com/ToruNiina/toml11.git 48 | [submodule "external/nameof/nameof"] 49 | path = external/nameof/nameof 50 | url = https://github.com/Neargye/nameof.git 51 | -------------------------------------------------------------------------------- /src/rootba/bal/common_types.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | 40 | #include "rootba/util/eigen_types.hpp" 41 | 42 | namespace rootba { 43 | 44 | using FrameIdx = int; 45 | using LandmarkIdx = int; 46 | 47 | static constexpr FrameIdx INVALID_FRAME_IDX = -1; 48 | static constexpr LandmarkIdx INVALID_LANDMARK_IDX = -1; 49 | 50 | } // namespace rootba 51 | -------------------------------------------------------------------------------- /src/rootba/ceres/bal_bundle_adjustment.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include "rootba/bal/bal_problem.hpp" 39 | #include "rootba/bal/solver_options.hpp" 40 | 41 | namespace rootba { 42 | 43 | void bundle_adjust_ceres(BalProblem& bal_problem, 44 | const SolverOptions& solver_options, 45 | BaLog* log = nullptr); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/rootba/util/system_utils.test.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | #include "rootba/util/system_utils.hpp" 38 | 39 | #include 40 | 41 | namespace rootba { 42 | 43 | TEST(SystemUtils, MemoryInfo) { 44 | MemoryInfo info; 45 | get_memory_info(info); 46 | EXPECT_GT(info.resident_memory, 0); 47 | EXPECT_GE(info.resident_memory_peak, info.resident_memory); 48 | } 49 | 50 | } // namespace rootba 51 | -------------------------------------------------------------------------------- /src/rootba/util/pprint_utils.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | 40 | namespace rootba { 41 | 42 | template 43 | std::string pprint_compact(const T& obj) { 44 | std::ostringstream ss; 45 | pprint::PrettyPrinter printer(ss); 46 | printer.compact(true); 47 | printer.line_terminator(""); 48 | printer.print(obj); 49 | return ss.str(); 50 | } 51 | 52 | } // namespace rootba 53 | -------------------------------------------------------------------------------- /src/rootba/qr/impl/landmark_block_dynamic.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | #include "rootba/qr/landmark_block_dynamic.hpp" 38 | 39 | #include "rootba/qr/impl/landmark_block_base.ipp" 40 | 41 | namespace rootba { 42 | 43 | #ifdef ROOTBA_INSTANTIATIONS_FLOAT 44 | template class LandmarkBlockDynamic; 45 | #endif 46 | 47 | #ifdef ROOTBA_INSTANTIATIONS_DOUBLE 48 | template class LandmarkBlockDynamic; 49 | #endif 50 | 51 | } // namespace rootba 52 | -------------------------------------------------------------------------------- /src/rootba/qr/impl/landmark_block_static_2.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | #include "rootba/qr/landmark_block_static.hpp" 38 | 39 | #include "rootba/qr/impl/landmark_block_base.ipp" 40 | 41 | namespace rootba { 42 | 43 | #ifdef ROOTBA_INSTANTIATIONS_FLOAT 44 | template class LandmarkBlockStatic; 45 | #endif 46 | 47 | #ifdef ROOTBA_INSTANTIATIONS_DOUBLE 48 | template class LandmarkBlockStatic; 49 | #endif 50 | 51 | } // namespace rootba 52 | -------------------------------------------------------------------------------- /src/rootba/qr/impl/landmark_block_static_3.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | #include "rootba/qr/landmark_block_static.hpp" 38 | 39 | #include "rootba/qr/impl/landmark_block_base.ipp" 40 | 41 | namespace rootba { 42 | 43 | #ifdef ROOTBA_INSTANTIATIONS_FLOAT 44 | template class LandmarkBlockStatic; 45 | #endif 46 | 47 | #ifdef ROOTBA_INSTANTIATIONS_DOUBLE 48 | template class LandmarkBlockStatic; 49 | #endif 50 | 51 | } // namespace rootba 52 | -------------------------------------------------------------------------------- /src/rootba/qr/impl/landmark_block_static_4.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | #include "rootba/qr/landmark_block_static.hpp" 38 | 39 | #include "rootba/qr/impl/landmark_block_base.ipp" 40 | 41 | namespace rootba { 42 | 43 | #ifdef ROOTBA_INSTANTIATIONS_FLOAT 44 | template class LandmarkBlockStatic; 45 | #endif 46 | 47 | #ifdef ROOTBA_INSTANTIATIONS_DOUBLE 48 | template class LandmarkBlockStatic; 49 | #endif 50 | 51 | } // namespace rootba 52 | -------------------------------------------------------------------------------- /src/rootba/qr/impl/landmark_block_static_5.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | #include "rootba/qr/landmark_block_static.hpp" 38 | 39 | #include "rootba/qr/impl/landmark_block_base.ipp" 40 | 41 | namespace rootba { 42 | 43 | #ifdef ROOTBA_INSTANTIATIONS_FLOAT 44 | template class LandmarkBlockStatic; 45 | #endif 46 | 47 | #ifdef ROOTBA_INSTANTIATIONS_DOUBLE 48 | template class LandmarkBlockStatic; 49 | #endif 50 | 51 | } // namespace rootba 52 | -------------------------------------------------------------------------------- /src/rootba/qr/impl/landmark_block_static_6.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | #include "rootba/qr/landmark_block_static.hpp" 38 | 39 | #include "rootba/qr/impl/landmark_block_base.ipp" 40 | 41 | namespace rootba { 42 | 43 | #ifdef ROOTBA_INSTANTIATIONS_FLOAT 44 | template class LandmarkBlockStatic; 45 | #endif 46 | 47 | #ifdef ROOTBA_INSTANTIATIONS_DOUBLE 48 | template class LandmarkBlockStatic; 49 | #endif 50 | 51 | } // namespace rootba 52 | -------------------------------------------------------------------------------- /src/rootba/qr/impl/landmark_block_static_7.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | #include "rootba/qr/landmark_block_static.hpp" 38 | 39 | #include "rootba/qr/impl/landmark_block_base.ipp" 40 | 41 | namespace rootba { 42 | 43 | #ifdef ROOTBA_INSTANTIATIONS_FLOAT 44 | template class LandmarkBlockStatic; 45 | #endif 46 | 47 | #ifdef ROOTBA_INSTANTIATIONS_DOUBLE 48 | template class LandmarkBlockStatic; 49 | #endif 50 | 51 | } // namespace rootba 52 | -------------------------------------------------------------------------------- /src/rootba/qr/impl/landmark_block_static_8.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | #include "rootba/qr/landmark_block_static.hpp" 38 | 39 | #include "rootba/qr/impl/landmark_block_base.ipp" 40 | 41 | namespace rootba { 42 | 43 | #ifdef ROOTBA_INSTANTIATIONS_FLOAT 44 | template class LandmarkBlockStatic; 45 | #endif 46 | 47 | #ifdef ROOTBA_INSTANTIATIONS_DOUBLE 48 | template class LandmarkBlockStatic; 49 | #endif 50 | 51 | } // namespace rootba 52 | -------------------------------------------------------------------------------- /scripts/show-sparsity.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # BSD 3-Clause License 4 | # 5 | # This file is part of the RootBA project. 6 | # https://github.com/NikolausDemmel/rootba 7 | # 8 | # Copyright (c) 2021, Nikolaus Demmel. 9 | # All rights reserved. 10 | # 11 | 12 | import matplotlib.pyplot as plt 13 | import numpy as np 14 | 15 | num_res = 150 16 | num_poses = 12 17 | num_landmarks = 25 18 | 19 | obs = set() 20 | 21 | while len(obs) < num_res: 22 | rand_pose = np.random.randint(0, high=num_poses) 23 | rand_lm = np.random.randint(0, high=num_landmarks) 24 | obs.add((rand_pose, rand_lm)) 25 | 26 | obs_sorted = sorted(obs, key=lambda x: (x[1], x[0])) 27 | 28 | #print(np.array(obs_sorted)) 29 | 30 | obs_map = {} 31 | 32 | for o in obs_sorted: 33 | if o[1] not in obs_map: 34 | obs_map[o[1]] = [] 35 | obs_map[o[1]].append(o[0]) 36 | 37 | #print(obs_map) 38 | 39 | Jp = np.ones((num_res, num_poses, 3)) 40 | Jl = np.ones((num_res, num_landmarks, 3)) 41 | 42 | i = 0 43 | for lm_id in sorted(obs_map.keys()): 44 | poses = obs_map[lm_id] 45 | 46 | for p1 in poses: 47 | for p2 in poses: 48 | if p1 == p2: 49 | Jp[i, p1, :] = np.array([86, 193, 255]) / 255. 50 | else: 51 | Jp[i, p2] = np.array([213, 213, 213]) / 255. 52 | Jl[i, lm_id] = np.array([86, 193, 255]) / 255. 53 | i += 1 54 | 55 | fig, axs = plt.subplots(1, 2) 56 | ax1 = axs[0] 57 | ax2 = axs[1] 58 | 59 | 60 | def disable_ticks(ax1): 61 | for xlabel_i in ax1.axes.get_xticklabels(): 62 | xlabel_i.set_visible(False) 63 | xlabel_i.set_fontsize(0.0) 64 | for xlabel_i in ax1.axes.get_yticklabels(): 65 | xlabel_i.set_fontsize(0.0) 66 | xlabel_i.set_visible(False) 67 | for tick in ax1.axes.get_xticklines(): 68 | tick.set_visible(False) 69 | for tick in ax1.axes.get_yticklines(): 70 | tick.set_visible(False) 71 | 72 | 73 | disable_ticks(ax1) 74 | disable_ticks(ax2) 75 | 76 | ax1.imshow(Jp, aspect=.15) 77 | ax2.imshow(Jl, aspect=.15 * num_landmarks / num_poses) 78 | 79 | plt.savefig('jacobian_sparsity.pdf', format='pdf', dpi=300) 80 | 81 | plt.show() 82 | -------------------------------------------------------------------------------- /src/rootba/bal/bal_problem_io.test.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | #include "rootba/bal/bal_problem_io.hpp" 38 | 39 | #include "rootba/util/test_io_utils.hpp" 40 | 41 | namespace rootba { 42 | 43 | TEST(BalProblemIoImpl, Observation) { 44 | test_io_impl::Observation>(); 45 | test_io_impl::Camera>(); 46 | test_io_impl::Landmark>(); 47 | test_io_impl>(); 48 | } 49 | 50 | } // namespace rootba 51 | -------------------------------------------------------------------------------- /scripts/num_ops/compute_num_ops_latex.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # BSD 3-Clause License 4 | # 5 | # This file is part of the RootBA project. 6 | # https://github.com/NikolausDemmel/rootba 7 | # 8 | # Copyright (c) 2021, Nikolaus Demmel. 9 | # All rights reserved. 10 | # 11 | 12 | from operation_counts import * 13 | 14 | # here, import data! 15 | 16 | num_iter_cg = 100 17 | 18 | dim_poses = 9 19 | dim_landmarks = 3 20 | dim_res = 2 21 | 22 | file_numbers = "bal_numbers.csv" 23 | 24 | # LaTeX table headline 25 | print("\\toprule") 26 | print(" & $n_p$ & $n_l$ & $n_o$ & SC + CG & QR + CGNR \\\\") 27 | print("\\midrule") 28 | 29 | # loop over datasets 30 | lines = open(file_numbers).readlines() 31 | for line in lines: 32 | # error / empty line handling 33 | line2 = line.strip() 34 | if not line2: 35 | continue 36 | data = line2.split(';') 37 | dataset = data[0] 38 | n_poses = int(data[1]) 39 | n_landmarks = int(data[2]) 40 | n_obs = int(data[3]) 41 | 42 | N_p = n_poses * dim_poses 43 | # N_l = n_landmarks * dim_landmarks 44 | N_r = n_obs * dim_res 45 | 46 | # cost of QR decomposition 47 | n_qr = ops_nm_decomposition(n_landmarks, N_p, N_r) 48 | # cost of Schur complement computation 49 | n_sc = ops_schur_complement(n_landmarks, dim_poses, N_p, N_r) 50 | # cost of CGNR (on QR-reduced system) 51 | lscg_mat_op_all = ops_cgnr(N_r - 3 * n_landmarks, N_p, num_iter_cg) 52 | # total QR cost (decomposition + CGNR) 53 | n_qr_lscg = n_qr + lscg_mat_op_all 54 | # cost of CG (on Schur-reduced system) 55 | cg_mat_op_all = ops_conjugate_gradient(N_p, num_iter_cg) 56 | # total Schur cost (SC computation + CG) 57 | n_sc_cg = n_sc + cg_mat_op_all 58 | 59 | # fill LaTeX table 60 | # syntax for scientific notation: "{:.2e}".format(...) 61 | # syntax for commas as 1000 separator: "{:,}".format(...) 62 | print(dataset, " & ", \ 63 | "{:,}".format(n_poses), " & ", \ 64 | "{:,}".format(n_landmarks), " & ", \ 65 | "{:,}".format(n_obs), " & ", \ 66 | "{:.2e}".format(n_sc_cg), " & ", \ 67 | "{:.2e}".format(n_qr_lscg), " \\\\") 68 | 69 | print("\\bottomrule") 70 | -------------------------------------------------------------------------------- /src/rootba/util/assert.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | 40 | #define ROOTBA_UNUSED(x) (void)(x) 41 | 42 | #define ROOTBA_LIKELY(x) __builtin_expect(x, 1) 43 | 44 | #ifdef ROOTBA_DISABLE_ASSERTS 45 | 46 | #define ROOTBA_ASSERT(expr) ((void)0) 47 | 48 | #define ROOTBA_ASSERT_MSG(expr, msg) ((void)0) 49 | 50 | #else 51 | 52 | #define ROOTBA_ASSERT(expr) CHECK(expr) 53 | 54 | #define ROOTBA_ASSERT_MSG(expr, msg) CHECK(expr) << msg 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /ci/docker/Dockerfile_20.04: -------------------------------------------------------------------------------- 1 | FROM ubuntu:20.04 2 | 3 | # non-persistent environment variables 4 | ARG DEBIAN_FRONTEND=noninteractive 5 | 6 | # Basic packages 7 | RUN apt-get update && apt-get install -y \ 8 | apt-utils \ 9 | apt-transport-https \ 10 | software-properties-common \ 11 | locales \ 12 | wget \ 13 | curl 14 | 15 | # Set the locale 16 | RUN locale-gen en_US.UTF-8 17 | ENV LANG en_US.UTF-8 18 | ENV LANGUAGE en_US:en 19 | ENV LC_ALL en_US.UTF-8 20 | 21 | # PPAs 22 | RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key| apt-key add - && \ 23 | apt-add-repository -y "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-10 main" && \ 24 | apt-add-repository -y "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-11 main" && \ 25 | apt-add-repository -y "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-12 main" && \ 26 | add-apt-repository -y ppa:ubuntu-toolchain-r/ppa 27 | 28 | # updates from toolchain and clang repo 29 | RUN apt-get update && apt-get dist-upgrade -y 30 | 31 | # Install base C++ dev tools 32 | RUN apt-get update && apt-get install -y \ 33 | build-essential \ 34 | clang-10 \ 35 | clang-11 \ 36 | clang-12 \ 37 | g++-9 \ 38 | g++-10 \ 39 | libc++-dev \ 40 | clang-format-11 \ 41 | clang-tidy-11 \ 42 | clang-format-12 \ 43 | clang-tidy-12 \ 44 | cmake \ 45 | pkg-config \ 46 | git-core \ 47 | git-lfs \ 48 | ccache 49 | 50 | # Python 51 | RUN apt-get update && apt-get install -y \ 52 | python3 \ 53 | python3-pip \ 54 | libpython3-all-dev 55 | RUN pip3 install -U pip setuptools 56 | RUN pip3 install -U cmake cmake_format 57 | RUN pip3 install -U yapf 58 | ENV PATH="/usr/local/bin:${PATH}" 59 | 60 | # Install libraries 61 | RUN apt-get update && apt-get install -y \ 62 | libgoogle-glog-dev \ 63 | libgflags-dev \ 64 | libtbb-dev \ 65 | libeigen3-dev \ 66 | libatlas-base-dev \ 67 | libsuitesparse-dev \ 68 | libglew-dev \ 69 | ffmpeg \ 70 | libavcodec-dev \ 71 | libavutil-dev \ 72 | libavformat-dev \ 73 | libswscale-dev \ 74 | libavdevice-dev \ 75 | libjpeg-dev \ 76 | libpng-dev \ 77 | libtiff5-dev \ 78 | libopenexr-dev 79 | -------------------------------------------------------------------------------- /src/rootba/util/container_traits.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | #include 40 | 41 | namespace rootba { 42 | 43 | template 44 | struct is_vector { 45 | constexpr static bool value = false; 46 | }; 47 | 48 | template 49 | struct is_vector> { 50 | constexpr static bool value = true; 51 | }; 52 | 53 | template 54 | constexpr bool is_vector_v = is_vector::value; 55 | 56 | } // namespace rootba 57 | -------------------------------------------------------------------------------- /src/rootba/bal/bal_app_options.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include "rootba/bal/bal_dataset_options.hpp" 39 | #include "rootba/bal/solver_options.hpp" 40 | 41 | namespace rootba { 42 | 43 | /// aggregates dataset and solver options 44 | struct BalAppOptions : public VisitableOptions { 45 | BEGIN_VISITABLES(BalAppOptions); 46 | 47 | VISITABLE(BalDatasetOptions, dataset); 48 | VISITABLE(SolverOptions, solver); 49 | 50 | END_VISITABLES; 51 | }; 52 | 53 | } // namespace rootba 54 | -------------------------------------------------------------------------------- /src/rootba/bal/solver_options.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | #include "rootba/bal/solver_options.hpp" 38 | 39 | namespace rootba { 40 | 41 | bool rootba::SolverOptions::use_projection_validity_check() const { 42 | switch (optimized_cost) { 43 | case SolverOptions::OptimizedCost::ERROR: 44 | return false; 45 | case SolverOptions::OptimizedCost::ERROR_VALID: 46 | case SolverOptions::OptimizedCost::ERROR_VALID_AVG: 47 | return true; 48 | default: 49 | LOG(FATAL) << "unreachable"; 50 | } 51 | } 52 | 53 | } // namespace rootba 54 | -------------------------------------------------------------------------------- /src/rootba/util/cast.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | 40 | namespace rootba { 41 | 42 | template 43 | typename std::make_signed_t signed_cast(I v) { 44 | static_assert(std::is_unsigned_v, "no unsigned"); 45 | return static_cast>(v); 46 | } 47 | 48 | template 49 | typename std::make_unsigned_t unsigned_cast(I v) { 50 | static_assert(std::is_signed_v, "no signed"); 51 | return static_cast>(v); 52 | } 53 | 54 | } // namespace rootba 55 | -------------------------------------------------------------------------------- /src/rootba/solver/bal_bundle_adjustment.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include "rootba/bal/bal_pipeline_summary.hpp" 39 | #include "rootba/bal/bal_problem.hpp" 40 | #include "rootba/bal/solver_options.hpp" 41 | #include "rootba/solver/solver_summary.hpp" 42 | 43 | namespace rootba { 44 | 45 | template 46 | void bundle_adjust_manual( 47 | BalProblem& bal_problem, const SolverOptions& solver_options, 48 | SolverSummary* output_solver_summary = nullptr, 49 | PipelineTimingSummary* output_timing_summary = nullptr); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/rootba/ceres/option_utils.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | 40 | #include "rootba/bal/solver_options.hpp" 41 | 42 | namespace rootba { 43 | 44 | void set_ceres_options(ceres::Solver::Options& out, const SolverOptions& in); 45 | 46 | bool ceres_use_projection_validity_check(const SolverOptions& options); 47 | 48 | ceres::LossFunction* ceres_create_loss_function( 49 | const BalResidualOptions& options); 50 | 51 | void print_ceres_summary(const ceres::Solver::Summary& summary, 52 | const SolverOptions& in); 53 | 54 | } // namespace rootba 55 | -------------------------------------------------------------------------------- /src/rootba/ceres/loss_function.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | 40 | namespace rootba { 41 | 42 | // Like ceres::HuberLoss, but with 2nd derivate set to 0, which results in ceres 43 | // applying the first order residual/jacobian weighting scheme. 44 | class HuberLossFirstOrderCorrection : public ceres::LossFunction { 45 | public: 46 | inline explicit HuberLossFirstOrderCorrection(double a) : a_(a), b_(a * a) {} 47 | void Evaluate(double /*s*/, double* /*rho*/) const override; 48 | 49 | private: 50 | const double a_; 51 | // b = a^2. 52 | const double b_; 53 | }; 54 | 55 | } // namespace rootba 56 | -------------------------------------------------------------------------------- /scripts/num_ops/compute_num_ops.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # BSD 3-Clause License 4 | # 5 | # This file is part of the RootBA project. 6 | # https://github.com/NikolausDemmel/rootba 7 | # 8 | # Copyright (c) 2021, Nikolaus Demmel. 9 | # All rights reserved. 10 | # 11 | 12 | n_poses = 1778 13 | n_lanmarks = 993923 14 | n_obs = 5001946 15 | 16 | num_iter_cg = 100 17 | 18 | dim_poses = 9 19 | dim_landmarks = 3 20 | dim_res = 2 21 | 22 | n_p = n_poses * dim_poses 23 | n_l = n_lanmarks * dim_landmarks 24 | n_r = n_obs * dim_res 25 | 26 | # QR marginalization 27 | num_givens_rotations = 3 * n_r - 6 * n_lanmarks 28 | 29 | compute_givens_flops = 6 30 | 31 | J_p_row_len = n_p 32 | res_row_len = 1 33 | J_l_row_len = dim_landmarks 34 | all_row_len = J_p_row_len + res_row_len + J_l_row_len 35 | 36 | num_flops_per_row_element = 6 37 | 38 | givens_operations = all_row_len * num_flops_per_row_element + compute_givens_flops 39 | 40 | back_subs = 9 * n_lanmarks + n_l + 2 * n_p * n_l 41 | 42 | n_qr = num_givens_rotations * givens_operations + back_subs 43 | 44 | print('n_qr\t\t', n_qr, '\t\t', n_qr * 1e-12) 45 | 46 | # Schur marginalization 47 | 48 | form_hessian = 144 * n_r 49 | inv_H_ll = 42 * n_lanmarks 50 | H_pl_inv_H_ll_mult = n_lanmarks * 2 * n_p * dim_landmarks * dim_landmarks 51 | H_pl_inv_H_ll_H_lp_mult = 2 * n_p * n_p * n_l 52 | H_pl_inv_H_ll_b_l_mult = 2 * n_p * n_l 53 | 54 | back_subs_sc = n_lanmarks * 2 * dim_landmarks * dim_landmarks + 2 * n_l * n_p 55 | 56 | n_sc = form_hessian + inv_H_ll + H_pl_inv_H_ll_mult + H_pl_inv_H_ll_H_lp_mult + H_pl_inv_H_ll_b_l_mult + back_subs_sc 57 | 58 | print('n_sc\t\t', n_sc, '\t', n_sc * 1e-12) 59 | 60 | # Form H explicitly for QR 61 | 62 | qr_h = 2 * n_p * n_p * (n_r - n_l) 63 | print('qr_h\t\t', qr_h, '\t', qr_h * 1e-12) 64 | 65 | # LSCG for QR 66 | 67 | lscg_mat_op_per_iter = 2 * 2 * n_p * (n_r - n_l) 68 | lscg_mat_op_all = lscg_mat_op_per_iter * num_iter_cg 69 | 70 | n_qr_lscg = n_qr + lscg_mat_op_all 71 | print('lscg_mat_op_all\t', lscg_mat_op_all, '\t', lscg_mat_op_all * 1e-12) 72 | print('n_qr_lscg\t', n_qr_lscg, '\t', n_qr_lscg * 1e-12) 73 | 74 | # CG for Schur complement 75 | 76 | cg_mat_op_per_iter = 2 * n_p * n_p 77 | cg_mat_op_all = cg_mat_op_per_iter * num_iter_cg 78 | 79 | n_sc_cg = n_sc + cg_mat_op_all 80 | print('cg_mat_op_all\t', cg_mat_op_all, '\t\t', cg_mat_op_all * 1e-12) 81 | print('n_sc_cg\t\t', n_sc_cg, '\t', n_sc_cg * 1e-12) 82 | -------------------------------------------------------------------------------- /src/rootba/bal/ba_log_utils.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include "rootba/bal/ba_log.hpp" 39 | #include "rootba/bal/bal_pipeline_summary.hpp" 40 | 41 | namespace rootba { 42 | 43 | void log_summary(BaLog::ProblemInfo& log, const DatasetSummary& summary); 44 | 45 | void log_summary(BaLog::PipelineTiming& log, 46 | const PipelineTimingSummary& summary); 47 | 48 | void log_summary(BaLog::BaSolver& log, const SolverSummary& summary); 49 | 50 | void log_summary(BaLog::BaIteration& log, const BaLog::BaIteration* prev_it, 51 | const IterationSummary& summary); 52 | 53 | void log_summary(BaLog& log, const BalPipelineSummary& summary); 54 | 55 | } // namespace rootba 56 | -------------------------------------------------------------------------------- /src/rootba/ceres/loss_function.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | #include "rootba/ceres/loss_function.hpp" 38 | 39 | #include 40 | 41 | namespace rootba { 42 | 43 | void HuberLossFirstOrderCorrection::Evaluate(double s, double rho[3]) const { 44 | if (s > b_) { 45 | // Outlier region. 46 | // 'r' is always positive. 47 | const double r = std::sqrt(s); 48 | rho[0] = 2.0 * a_ * r - b_; 49 | rho[1] = std::max(std::numeric_limits::min(), a_ / r); 50 | // Don't do 2nd order correction: 51 | // rho[2] = - rho[1] / (2.0 * s); 52 | rho[2] = 0.0; 53 | } else { 54 | // Inlier region. 55 | rho[0] = s; 56 | rho[1] = 1.0; 57 | rho[2] = 0.0; 58 | } 59 | } 60 | 61 | } // namespace rootba 62 | -------------------------------------------------------------------------------- /src/rootba/testing/test_types.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021-2023, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | 40 | namespace rootba { 41 | 42 | // ////////////////////////////////////////////////////////////////////////// 43 | // Test types for float / double depending on cmake option 44 | // ////////////////////////////////////////////////////////////////////////// 45 | #if defined(ROOTBA_INSTANTIATIONS_FLOAT) && \ 46 | defined(ROOTBA_INSTANTIATIONS_DOUBLE) 47 | 48 | using ScalarTestTypes = ::testing::Types; 49 | 50 | #elif (defined ROOTBA_INSTANTIATIONS_FLOAT) 51 | 52 | using ScalarTestTypes = ::testing::Types; 53 | 54 | #elif (defined ROOTBA_INSTANTIATIONS_DOUBLE) 55 | 56 | using ScalarTestTypes = ::testing::Types; 57 | 58 | #endif 59 | 60 | } // namespace rootba 61 | -------------------------------------------------------------------------------- /src/rootba/qr/linearization_utils.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021-2023, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | #include 40 | 41 | namespace rootba { 42 | 43 | // TODO: move to some common header and also use in Linearizor? 44 | /// Compute jacobain scaling from squared jacobian column norms and epsilon 45 | template 46 | Eigen::Matrix compute_jacobi_scaling( 47 | const Eigen::Matrix& jacobian_scale2, 48 | Scalar jacobi_scaling_eps) { 49 | return (jacobi_scaling_eps + jacobian_scale2.array().sqrt()).inverse(); 50 | } 51 | 52 | // TODO: move to test utils? 53 | template 54 | Scalar default_testing_jacobi_scaling_eps() { 55 | return Sophus::Constants::epsilonSqrt(); 56 | } 57 | 58 | } // namespace rootba 59 | -------------------------------------------------------------------------------- /src/rootba/util/typesafe_utils.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | /////////////////////////////////////////////////////////////////////////////// 39 | // no move, no copy 40 | 41 | #define ROOTBA_DELETE_COPY_MOVE_CONSTR(NAME) \ 42 | NAME(const NAME&) = delete; \ 43 | NAME(NAME&&) = delete 44 | 45 | #define ROOTBA_DELETE_COPY_MOVE_ASSIGN_OP(NAME) \ 46 | NAME& operator=(const NAME&) = delete; \ 47 | NAME& operator=(NAME&&) = delete 48 | 49 | /////////////////////////////////////////////////////////////////////////////// 50 | // default move, no copy 51 | 52 | // Note: Default copy operations are autoamtically disabled if move operation is 53 | // defined 54 | 55 | #define ROOTBA_MOVE_ONLY_CONSTR(NAME) NAME(NAME&&) = default 56 | 57 | #define ROOTBA_MOVE_ONLY_ASSIGN_OP(NAME) NAME& operator=(NAME&&) = default 58 | -------------------------------------------------------------------------------- /src/rootba/cg/utils.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021-2023, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | 40 | namespace rootba { 41 | 42 | template 43 | bool is_zero_or_infinity(Scalar x) { 44 | return ((x == Scalar(0)) || std::isinf(x)); 45 | } 46 | 47 | template 48 | class LinearOperator { 49 | public: 50 | using VecX = Eigen::Matrix; 51 | 52 | virtual ~LinearOperator() = default; 53 | 54 | virtual size_t num_cols() const = 0; 55 | virtual VecX right_multiply(const VecX& x) const = 0; 56 | }; 57 | 58 | template 59 | class Preconditioner { 60 | public: 61 | using VecX = Eigen::Matrix; 62 | 63 | virtual ~Preconditioner() = default; 64 | 65 | virtual void solve_assign(const VecX& b, VecX& x) const = 0; 66 | }; 67 | 68 | } // namespace rootba 69 | -------------------------------------------------------------------------------- /python/rootba/util.py: -------------------------------------------------------------------------------- 1 | # 2 | # BSD 3-Clause License 3 | # 4 | # This file is part of the RootBA project. 5 | # https://github.com/NikolausDemmel/rootba 6 | # 7 | # Copyright (c) 2021, Nikolaus Demmel. 8 | # All rights reserved. 9 | # 10 | import os 11 | import json 12 | import toml 13 | import platform 14 | import subprocess 15 | import re 16 | import numpy as np 17 | 18 | from munch import munchify 19 | 20 | 21 | def copy_subdict(d, keys): 22 | res = dict() 23 | for k in keys: 24 | if k in d: 25 | res[k] = d[k] 26 | return res 27 | 28 | 29 | def load_toml_if_exists(filepath): 30 | if os.path.isfile(filepath): 31 | return munchify(toml.load(filepath)) 32 | return None 33 | 34 | 35 | def load_json_if_exists(filepath): 36 | if os.path.isfile(filepath): 37 | with open(filepath, 'r') as f: 38 | return munchify(json.load(f)) 39 | return None 40 | 41 | 42 | def load_text_if_exists(filepath): 43 | if os.path.isfile(filepath): 44 | with open(filepath, 'r') as f: 45 | return f.read() 46 | return None 47 | 48 | 49 | def load_trajectory_tum(filepath): 50 | # first row is header 51 | # format for each row is: ts x y z qz qy qz qw 52 | traj = np.loadtxt(filepath, delimiter=" ", skiprows=1) 53 | # return just translation for now 54 | traj = traj[:, 1:4] 55 | return traj 56 | 57 | 58 | def load_trajectory_tum_if_exists(filepath): 59 | if os.path.isfile(filepath): 60 | return load_trajectory_tum(filepath) 61 | return None 62 | 63 | 64 | def os_open_file(filepath): 65 | if platform.system() == 'Darwin': 66 | subprocess.call(('open', filepath)) 67 | elif platform.system() == 'Windows': 68 | os.startfile(filepath) 69 | else: 70 | subprocess.call(('xdg-open', filepath)) 71 | 72 | 73 | # key for 'human' sorting 74 | def alphanum(key): 75 | 76 | def convert(text): 77 | return float(text) if text.isdigit() else text 78 | 79 | return [convert(c) for c in re.split('([-+]?[0-9]*\.?[0-9]*)', key)] 80 | 81 | 82 | # key for 'bal dataset' sorting 83 | def bal_order(key): 84 | 85 | # manually rank group names 86 | order_groups = ["ladybug", "trafalgar", "dubrovnik", "venice", "final"] 87 | for i, name in enumerate(order_groups): 88 | key = key.replace(name, "_{}_".format(i)) 89 | 90 | # first split into list of tokens for alphanumeric sorting 91 | def convert(text): 92 | return float(text) if text.isdigit() else text 93 | 94 | return [convert(c) for c in re.split('([-+]?[0-9]*\.?[0-9]*)', key)] 95 | -------------------------------------------------------------------------------- /ACKNOWLEDGEMENTS: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------ 2 | General 3 | ------------------------------------------------------------------------------ 4 | 5 | We build on top of many third-party libraries, see the list of 6 | dependencies in the README and in particular the submodules in the 7 | `external` folder. Please observe the respective licenses. 8 | 9 | 10 | ------------------------------------------------------------------------------ 11 | Ceres-Solver 12 | ------------------------------------------------------------------------------ 13 | 14 | Some of our own code derives directly from Ceres, in particular the 15 | ConjugateGradientSolver class, but also our SolverOptions and 16 | SolverSummary classes, cmake modules, and part of the logic in our 17 | Levenberg-Marquardt loop in the `solver` module (e.g. the lambda 18 | update). These parts of Ceres are licensed under the following BSD 19 | 3-clause license: 20 | 21 | 22 | Ceres Solver - A fast non-linear least squares minimizer 23 | Copyright 2015 Google Inc. All rights reserved. 24 | http://ceres-solver.org/ 25 | 26 | Redistribution and use in source and binary forms, with or without 27 | modification, are permitted provided that the following conditions are met: 28 | 29 | * Redistributions of source code must retain the above copyright notice, 30 | this list of conditions and the following disclaimer. 31 | * Redistributions in binary form must reproduce the above copyright notice, 32 | this list of conditions and the following disclaimer in the documentation 33 | and/or other materials provided with the distribution. 34 | * Neither the name of Google Inc. nor the names of its contributors may be 35 | used to endorse or promote products derived from this software without 36 | specific prior written permission. 37 | 38 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 39 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 40 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 41 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 42 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 43 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 44 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 45 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 46 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 47 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 48 | POSSIBILITY OF SUCH DAMAGE. 49 | -------------------------------------------------------------------------------- /src/rootba/bal/ba_log_options.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include "rootba/bal/ba_log.hpp" 39 | #include "rootba/options/visitable_options.hpp" 40 | 41 | namespace rootba { 42 | 43 | struct BaLogOptions : public VisitableOptions { 44 | BEGIN_VISITABLES(BaLogOptions); 45 | 46 | VISITABLE_META(std::string, log_path, 47 | init("ba_log.json").help("path of BA log file")); 48 | VISITABLE_META(SaveLogFlags, save_log_flags, 49 | init(SaveLogFlag::JSON) 50 | .help("which file types to save; can be 0 or multiple")); 51 | 52 | VISITABLE_META( 53 | bool, disable_all, 54 | init(false).help( 55 | "don't log anything; currently only affects the Ceres solver, where " 56 | "it skips the custom iteration callback completely")); 57 | 58 | END_VISITABLES; 59 | }; 60 | 61 | } // namespace rootba 62 | -------------------------------------------------------------------------------- /src/rootba/ceres/ba_log_utils.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | #include 40 | 41 | #include "rootba/bal/ba_log.hpp" 42 | #include "rootba/bal/residual_info.hpp" 43 | 44 | namespace rootba { 45 | 46 | void log_ceres_summary(BaLog& log, const std::string& solver_type, 47 | const ceres::Solver::Summary& summary); 48 | 49 | void log_ceres_iteration_summary(BaLog::BaIteration& it, 50 | const BaLog::BaIteration* prev_it, 51 | const ceres::IterationSummary& summary, 52 | bool ceres_use_projection_validity_check); 53 | 54 | void log_ceres_error(BaLog::BaIteration& it, const BaLog::BaIteration* prev_it, 55 | const ResidualInfo& ri); 56 | 57 | void log_memory(BaLog::BaIteration& it); 58 | 59 | } // namespace rootba 60 | -------------------------------------------------------------------------------- /src/rootba/util/format.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021-2023, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | #include 40 | 41 | namespace rootba { 42 | 43 | // libfmt's string literal formatter implementation was deprecated in 2021-12, 44 | // so provide our own (see also: 45 | // https://github.com/fmtlib/fmt/issues/2640#issuecomment-1048894376) 46 | 47 | namespace literals { 48 | 49 | inline auto operator"" _format(const char* s, size_t n) { 50 | return [=](auto&&... args) { 51 | #if FMT_VERSION < 50000 52 | return fmt::format(s, args...); 53 | #elif FMT_VERSION < 80100 54 | return fmt::format(std::string_view(s, n), args...); 55 | #else 56 | return fmt::format(fmt::runtime(std::string_view(s, n)), args...); 57 | #endif 58 | }; 59 | } 60 | 61 | } // namespace literals 62 | 63 | // make the _format string literal available in the whole namespace 64 | using namespace literals; 65 | 66 | } // namespace rootba 67 | -------------------------------------------------------------------------------- /src/rootba/pangolin/gui_helpers.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | #include "rootba/pangolin/gui_helpers.hpp" 38 | 39 | #include 40 | #include 41 | 42 | namespace rootba { 43 | 44 | void render_camera(const Eigen::Matrix4d& T_w_c, float line_width, 45 | const u_int8_t* color, float size_factor) { 46 | const double sz = size_factor; 47 | const int width = 640; 48 | const int height = 480; 49 | const float fx = 500; 50 | const float fy = 500; 51 | const float cx = 320; 52 | const float cy = 240; // choose an arbitrary intrinsics because we don't need 53 | // the camera be exactly same as the original one 54 | 55 | Eigen::Matrix3d Kinv; 56 | Kinv << 1 / fx, 0, -cx / fx, 0, 1 / fy, -cy / fy, 0, 0, 1; 57 | 58 | glColor3ubv(color); 59 | glLineWidth(line_width); 60 | pangolin::glDrawFrustum(Kinv, width, height, T_w_c, sz); 61 | } 62 | 63 | } // namespace rootba 64 | -------------------------------------------------------------------------------- /src/rootba/ceres/bal_iteration_callback.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | 40 | #include "rootba/bal/ba_log.hpp" 41 | #include "rootba/bal/bal_problem.hpp" 42 | #include "rootba/bal/solver_options.hpp" 43 | 44 | namespace rootba { 45 | 46 | // iteration callback for logging optimization progress to BaLog 47 | class BalIterationCallback : public ceres::IterationCallback { 48 | public: 49 | explicit BalIterationCallback(BaLog& log, BalProblem& bal_problem, 50 | const VecXd& camera_state, 51 | const SolverOptions& options); 52 | 53 | ceres::CallbackReturnType operator()( 54 | const ceres::IterationSummary& summary) override; 55 | 56 | private: 57 | BaLog& log_; 58 | 59 | BalProblem& bal_problem_; 60 | const VecXd& camera_state_; 61 | 62 | const SolverOptions& options_; 63 | }; 64 | 65 | } // namespace rootba 66 | -------------------------------------------------------------------------------- /scripts/run-one.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ## 3 | ## BSD 3-Clause License 4 | ## 5 | ## This file is part of the RootBA project. 6 | ## https://github.com/NikolausDemmel/rootba 7 | ## 8 | ## Copyright (c) 2021, Nikolaus Demmel. 9 | ## All rights reserved. 10 | ## 11 | 12 | # 13 | # This script runs on the slurm nodes to run rootba for one config. 14 | 15 | set -e 16 | set -o pipefail 17 | set -x 18 | 19 | error() { 20 | local parent_lineno="$1" 21 | local message="$2" 22 | local code="${3:-1}" 23 | if [[ -n "$message" ]] ; then 24 | echo "Error on or near line ${parent_lineno}: ${message}; exiting with status ${code}" 25 | else 26 | echo "Error on or near line ${parent_lineno}; exiting with status ${code}" 27 | fi 28 | echo "Failed" >> status.log 29 | exit "${code}" 30 | } 31 | trap 'error ${LINENO}' ERR 32 | 33 | # number of logical cores on linux and macos 34 | NUM_CORES=`(which nproc > /dev/null && nproc) || sysctl -n hw.logicalcpu || echo 1` 35 | 36 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 37 | 38 | ROOTBA_BIN_DIR="${ROOTBA_BIN_DIR:-$SCRIPT_DIR/../bin}" 39 | 40 | # if running on slurm node, add arch suffix to executable path 41 | if [ -n "$SLURM_NODEID" ]; then 42 | source "$SCRIPT_DIR"/utils/on-slurm-detect-cpu.sh 43 | EXE_SUFFIX="-$ARCH_SUFFIX" 44 | else 45 | EXE_SUFFIX="" 46 | ARCH_SUFFIX="" 47 | fi 48 | 49 | FOLDER="${1}" 50 | 51 | cd "$FOLDER" 52 | 53 | if ! which time 2> /dev/null; then 54 | echo "Did not find 'time' executable. Not installed?" 55 | exit 1 56 | fi 57 | 58 | if [[ "$OSTYPE" == "darwin"* ]]; then 59 | TIMECMD="`which time` -lp" 60 | else 61 | TIMECMD="`which time` -v" 62 | fi 63 | 64 | echo "Started" >> status.log 65 | 66 | # set environment variables according to config 67 | while read l; do 68 | if [ -n "$l" ]; then 69 | eval "export $l" 70 | fi 71 | done <<< `"$SCRIPT_DIR"/query-config.py rootba_config.toml batch_run.env --format-env` 72 | 73 | # lookup executable to run 74 | EXECUTABLE=`"$SCRIPT_DIR"/query-config.py rootba_config.toml batch_run.executable bal` 75 | 76 | CMD="$ROOTBA_BIN_DIR/$EXECUTABLE$EXE_SUFFIX" 77 | 78 | echo "Running on '`hostname`', arch: $ARCH_SUFFIX, nproc: $NUM_CORES, bin: $CMD" 79 | 80 | # run as many times as specified (for timing tests to make sure filecache is hot); default is once 81 | rm -f output.log 82 | NUM_RUNS=`"$SCRIPT_DIR"/query-config.py rootba_config.toml batch_run.num_runs 1` 83 | echo "Will run $NUM_RUNS times." 84 | for i in $(seq $NUM_RUNS); do 85 | echo ">>> Run $i" |& tee -a output.log 86 | { $TIMECMD "$CMD"; } |& tee -a output.log 87 | done 88 | 89 | echo "Completed" >> status.log 90 | -------------------------------------------------------------------------------- /src/rootba/bal/bal_residual_options.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include "rootba/options/visitable_options.hpp" 39 | 40 | namespace rootba { 41 | 42 | /// Options relevant for evaluation the BA residuals, e.g., which robust norm to 43 | /// use. 44 | struct BalResidualOptions : public VisitableOptions { 45 | WISE_ENUM_CLASS_MEMBER(RobustNorm, 46 | NONE, //!< squared norm (not robust) 47 | HUBER //!< huber norm 48 | ); 49 | 50 | BEGIN_VISITABLES(BalResidualOptions); 51 | 52 | VISITABLE_META(RobustNorm, robust_norm, 53 | init(RobustNorm::NONE) 54 | .help("which robust norm to use. NONE: squared norm, " 55 | "HUBER: Huber norm.")); 56 | 57 | // ceres uses value of 1.0 in bundle_adjuster example 58 | VISITABLE_META( 59 | double, huber_parameter, 60 | init(1).range(0, 10).help("huber parameter for robust norm in pixels")); 61 | 62 | END_VISITABLES; 63 | }; 64 | 65 | } // namespace rootba 66 | -------------------------------------------------------------------------------- /src/rootba/bal/bal_pipeline_summary.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021-2023, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include "rootba/solver/solver_summary.hpp" 39 | 40 | namespace rootba { 41 | 42 | struct DatasetSummary { 43 | struct Stats { 44 | double mean = 0; 45 | double min = 0; 46 | double max = 0; 47 | double stddev = 0; 48 | }; 49 | 50 | // type and source 51 | std::string type; 52 | std::string input_path; 53 | 54 | // basic problem info 55 | int num_cameras = 0; 56 | int num_landmarks = 0; 57 | int num_observations = 0; 58 | double rcs_sparsity = 0; 59 | 60 | // per landmark observation stats 61 | Stats per_lm_obs; 62 | 63 | // per host-frame landmark stats (for achored landmark representation) 64 | Stats per_host_lms; 65 | }; 66 | 67 | struct PipelineTimingSummary { 68 | double load_time = 0; // load from file 69 | double preprocess_time = 0; // normalize, perturb, convert 70 | double optimize_time = 0; // run bundle adjustment 71 | double postprocess_time = 0; // save result 72 | }; 73 | 74 | struct BalPipelineSummary { 75 | DatasetSummary dataset; 76 | PipelineTimingSummary timing; 77 | SolverSummary solver; 78 | }; 79 | 80 | } // namespace rootba 81 | -------------------------------------------------------------------------------- /src/rootba/pangolin/bal_image_overlay.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021-2023, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | #include 40 | 41 | #include "rootba/bal/bal_problem.hpp" 42 | 43 | namespace rootba { 44 | 45 | class BalImageOverlay { 46 | public: 47 | struct Options { 48 | int min_image_size = 500; 49 | int max_image_size = 2000; 50 | double circle_radius = 3.0; 51 | }; 52 | 53 | BalImageOverlay(); 54 | 55 | void set_options(const Options& options); 56 | 57 | template 58 | void update(pangolin::ImageView& view, const BalProblem& bal_problem, 59 | FrameIdx frame_id); 60 | 61 | void draw() const; 62 | 63 | private: 64 | pangolin::ManagedImage make_background_image(Vec2d image_size); 65 | 66 | Options options_; 67 | 68 | // for current image 69 | FrameIdx frame_id_; 70 | Vec2d image_size_; //!< image size w/o border 71 | Vec2d center_; //!< center of image w/ border 72 | double scale_factor_; //!< scale factor for image coordindates 73 | 74 | std::vector kpts_detected_; 75 | std::vector kpts_projected_; 76 | }; 77 | 78 | } // namespace rootba 79 | -------------------------------------------------------------------------------- /python/rootba/latex/templates.py: -------------------------------------------------------------------------------- 1 | # 2 | # BSD 3-Clause License 3 | # 4 | # This file is part of the RootBA project. 5 | # https://github.com/NikolausDemmel/rootba 6 | # 7 | # Copyright (c) 2021, Nikolaus Demmel. 8 | # All rights reserved. 9 | # 10 | screenread_sty = r""" 11 | \ProvidesPackage{screenread} 12 | % Copyright (C) 2012 John Collins, collins@phys.psu.edu 13 | % License: LPPL 1.2 14 | 15 | % Note: To avoid compatibility issues between geometry and at least one 16 | % class file, it may be better to set all the dimensions by hand. 17 | 18 | % 20 Nov 2014 - use `pageBreakSection` instead of clobbering `section` 19 | % - increase longest page size to 575cm 20 | % - make top, right, and left margins something sensible and 21 | % a bit more aesthetically pleasing 22 | % 24 Jan 2012 Argument to \SetScreen is screen width 23 | % 23 Jan 2012 Remove package showlayout 24 | % 22 Jan 2012 Initial version, based on ideas in 25 | % B. Veytsman amd M. Ware, Tugboat 32 (2011) 261. 26 | 27 | \RequirePackage{everyshi} 28 | \RequirePackage{geometry} 29 | 30 | %======================= 31 | 32 | \pagestyle{empty} 33 | 34 | \EveryShipout{% 35 | \pdfpageheight=\pagetotal 36 | \advance\pdfpageheight by 2in 37 | \advance\pdfpageheight by \topmargin 38 | \advance\pdfpageheight by \textheight % This and next allow for footnotes 39 | \advance\pdfpageheight by -\pagegoal 40 | } 41 | 42 | \AtEndDocument{\pagebreak} 43 | 44 | \def\pageBreakSection{\pagebreak\section} 45 | 46 | \newlength\screenwidth 47 | \newlength{\savedscreenwidth} 48 | 49 | \newcommand\SetScreen[1]{% 50 | % Argument #1 is the screen width. 51 | % Set appropriate layout parameters, with only a little white space 52 | % around the text. 53 | \setlength\screenwidth{#1}% 54 | \setlength\savedscreenwidth{#1}% 55 | \setlength\textwidth{#1}% 56 | \addtolength\textwidth{-2cm}% 57 | \geometry{layoutwidth=\screenwidth, 58 | paperwidth=\screenwidth, 59 | textwidth=\textwidth, 60 | layoutheight=575cm, 61 | paperheight=575cm, 62 | textheight=575cm, 63 | top=1cm, 64 | left=1cm, 65 | right=1cm, 66 | hcentering=true 67 | }% 68 | } 69 | 70 | \newcommand\SetPageScreenWidth[1]{% 71 | \setlength\savedscreenwidth{\screenwidth}% 72 | \setlength\screenwidth{#1}% 73 | \pdfpagewidth\screenwidth% 74 | \setlength\textwidth{\screenwidth}% 75 | \addtolength\textwidth{-2cm}% 76 | } 77 | 78 | \newcommand\RestorePageScreenWidth{% 79 | \setlength\screenwidth{\savedscreenwidth}% 80 | \pdfpagewidth\screenwidth% 81 | \setlength\textwidth{\screenwidth}% 82 | \addtolength\textwidth{-2cm}% 83 | } 84 | 85 | 86 | % Compute a reasonable default screen width, and set it 87 | \setlength\screenwidth{\textwidth} 88 | \addtolength\screenwidth{1cm} 89 | \SetScreen{\screenwidth} 90 | 91 | \endinput 92 | 93 | """ 94 | -------------------------------------------------------------------------------- /src/rootba/solver/linearizor_base.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | #pragma once 38 | 39 | #include "rootba/cg/conjugate_gradient.hpp" 40 | #include "rootba/solver/linearizor.hpp" 41 | 42 | namespace rootba { 43 | 44 | template 45 | class LinearizorBase : public Linearizor { 46 | public: 47 | using Scalar = Scalar_; 48 | using Base = Linearizor; 49 | 50 | using VecX = Eigen::Matrix; 51 | 52 | public: // public interface 53 | LinearizorBase(BalProblem& bal_problem, const SolverOptions& options, 54 | SolverSummary* summary = nullptr); 55 | 56 | void start_iteration(IterationSummary* it_summary = nullptr) override; 57 | 58 | void compute_error(ResidualInfo& ri) override; 59 | 60 | void finish_iteration() override; 61 | 62 | protected: // helpers 63 | Scalar get_effective_jacobi_scaling_epsilon(); 64 | 65 | // solve H(-x) = b with PCG 66 | typename ConjugateGradientsSolver::Summary pcg( 67 | const LinearOperator& H_pp, const VecX& b_p, 68 | std::unique_ptr>&& preconditioner, VecX& xref); 69 | 70 | protected: 71 | SolverOptions options_; 72 | BalProblem& bal_problem_; 73 | 74 | // summary pointers are optional (e.g. for unit testing we can skip them) 75 | SolverSummary* summary_ = nullptr; 76 | IterationSummary* it_summary_ = nullptr; 77 | }; 78 | 79 | } // namespace rootba 80 | -------------------------------------------------------------------------------- /src/rootba/solver/linearizor_sc.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021-2023, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include "rootba/solver/linearizor_base.hpp" 39 | 40 | namespace rootba { 41 | 42 | template 43 | class LinearizationSC; 44 | 45 | template 46 | class LinearizorSC : public LinearizorBase { 47 | public: 48 | using Scalar = Scalar_; 49 | using Base = LinearizorBase; 50 | constexpr static int POSE_SIZE = 9; 51 | 52 | using VecX = Eigen::Matrix; 53 | 54 | public: // public interface 55 | LinearizorSC(BalProblem& bal_problem, const SolverOptions& options, 56 | SolverSummary* summary = nullptr); 57 | 58 | ~LinearizorSC() override; 59 | 60 | void linearize() override; 61 | 62 | VecX solve(Scalar lambda) override; 63 | 64 | Scalar apply(VecX&& inc) override; 65 | 66 | private: 67 | using Base::bal_problem_; 68 | using Base::it_summary_; 69 | using Base::options_; 70 | using Base::summary_; 71 | 72 | std::unique_ptr> lsc_; 73 | 74 | // set during linearization, used in solve 75 | VecX pose_jacobian_scaling_; 76 | 77 | // indicates if we call solve the first time since the last linearization 78 | // (first inner iteration for LM-backtracking); true after `linearize`, false 79 | // after `solve`; 80 | bool new_linearization_point_ = false; 81 | }; 82 | 83 | } // namespace rootba 84 | -------------------------------------------------------------------------------- /src/rootba/solver/linearizor_power_sc.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021-2023, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include "rootba/solver/linearizor_base.hpp" 39 | 40 | namespace rootba { 41 | 42 | template 43 | class LinearizationPowerSC; 44 | 45 | template 46 | class LinearizorPowerSC : public LinearizorBase { 47 | public: 48 | using Scalar = Scalar_; 49 | using Base = LinearizorBase; 50 | constexpr static int POSE_SIZE = 9; 51 | 52 | using VecX = Eigen::Matrix; 53 | 54 | public: // public interface 55 | LinearizorPowerSC(BalProblem& bal_problem, 56 | const SolverOptions& options, 57 | SolverSummary* summary = nullptr); 58 | 59 | ~LinearizorPowerSC() override; 60 | 61 | void linearize() override; 62 | 63 | VecX solve(Scalar lambda) override; 64 | 65 | Scalar apply(VecX&& inc) override; 66 | 67 | private: 68 | using Base::bal_problem_; 69 | using Base::it_summary_; 70 | using Base::options_; 71 | using Base::summary_; 72 | 73 | std::unique_ptr> lsc_; 74 | 75 | // set during linearization, used in solve 76 | VecX pose_jacobian_scaling_; 77 | 78 | // indicates if we call solve the first time since the last linearization 79 | // (first inner iteration for LM-backtracking); true after `linearize`, false 80 | // after `solve`; 81 | bool new_linearization_point_ = false; 82 | }; 83 | 84 | } // namespace rootba 85 | -------------------------------------------------------------------------------- /src/rootba/bal/bal_problem_io.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include "rootba/bal/bal_problem.hpp" 44 | #include "rootba/util/serialization.hpp" 45 | 46 | namespace rootba { 47 | 48 | static const auto BAL_PROBLEM_FILE_INFO = FileInfo{"rootba::BalProblem", "1.0"}; 49 | 50 | } 51 | 52 | namespace cereal { 53 | 54 | // TODO: why does it not work when we add a Scalar template argument for 55 | // serializers? 56 | 57 | template 58 | void serialize(Archive& ar, 59 | typename rootba::BalProblem::Observation& obj) { 60 | ar(CEREAL_NVP_("pos", obj.pos)); 61 | } 62 | 63 | template 64 | void serialize(Archive& ar, typename rootba::BalProblem::Camera& obj) { 65 | ar(CEREAL_NVP_("T_c_w", obj.T_c_w), 66 | CEREAL_NVP_("intrinsics", obj.intrinsics)); 67 | // NOTE: we don't serialize the 'backup' variables 68 | } 69 | 70 | template 71 | void serialize(Archive& ar, 72 | typename rootba::BalProblem::Landmark& obj) { 73 | ar(CEREAL_NVP_("p_w", obj.p_w), CEREAL_NVP_("obs", obj.obs)); 74 | // NOTE: we don't serialize the 'backup' variables 75 | } 76 | 77 | template 78 | void serialize(Archive& ar, rootba::BalProblem& obj) { 79 | ar(make_nvp("cameras", obj.cameras()), 80 | make_nvp("landmarks", obj.landmarks())); 81 | } 82 | 83 | } // namespace cereal 84 | -------------------------------------------------------------------------------- /src/rootba/solver/linearizor.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021-2023, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #include "rootba/solver/linearizor.hpp" 37 | 38 | #include 39 | 40 | #include "rootba/solver/linearizor_power_sc.hpp" 41 | #include "rootba/solver/linearizor_qr.hpp" 42 | #include "rootba/solver/linearizor_sc.hpp" 43 | #include "rootba/util/format.hpp" 44 | 45 | namespace rootba { 46 | 47 | template 48 | std::unique_ptr> Linearizor::create( 49 | BalProblem& bal_problem, const SolverOptions& options, 50 | SolverSummary* summary) { 51 | switch (options.solver_type) { 52 | case SolverOptions::SolverType::SQUARE_ROOT: 53 | return std::make_unique>(bal_problem, options, 54 | summary); 55 | case SolverOptions::SolverType::SCHUR_COMPLEMENT: 56 | return std::make_unique>(bal_problem, options, 57 | summary); 58 | case SolverOptions::SolverType::POWER_SCHUR_COMPLEMENT: 59 | return std::make_unique>(bal_problem, options, 60 | summary); 61 | default: 62 | LOG(FATAL) << "Invalid LinearizorType {}"_format( 63 | magic_enum::enum_name(options.solver_type)); 64 | } 65 | } 66 | 67 | #ifdef ROOTBA_INSTANTIATIONS_FLOAT 68 | template class Linearizor; 69 | #endif 70 | 71 | #ifdef ROOTBA_INSTANTIATIONS_DOUBLE 72 | template class Linearizor; 73 | #endif 74 | 75 | } // namespace rootba 76 | -------------------------------------------------------------------------------- /src/rootba/solver/linearizor_qr.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021-2023, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include "rootba/cg/block_sparse_matrix.hpp" 39 | #include "rootba/solver/linearizor_base.hpp" 40 | 41 | namespace rootba { 42 | 43 | template 44 | class LinearizationQR; 45 | 46 | template 47 | class LinearizorQR : public LinearizorBase { 48 | public: 49 | using Scalar = Scalar_; 50 | using Base = LinearizorBase; 51 | constexpr static int POSE_SIZE = 9; 52 | 53 | using VecX = Eigen::Matrix; 54 | 55 | public: // public interface 56 | LinearizorQR(BalProblem& bal_problem, const SolverOptions& options, 57 | SolverSummary* summary = nullptr); 58 | 59 | ~LinearizorQR() override; 60 | 61 | void linearize() override; 62 | 63 | VecX solve(Scalar lambda) override; 64 | 65 | Scalar apply(VecX&& inc) override; 66 | 67 | private: 68 | using Base::bal_problem_; 69 | using Base::it_summary_; 70 | using Base::options_; 71 | using Base::summary_; 72 | 73 | std::unique_ptr> lqr_; 74 | 75 | // set during linearization, used in solve 76 | VecX pose_jacobian_scaling_; 77 | 78 | // diagonal blocks for JACOBI or SCHUR_JACOBI preconditioner 79 | IndexedBlocks precond_blocks_; 80 | 81 | // indicates if we call solve the first time since the last linearization 82 | // (first inner iteration for LM-backtracking); true after `linearize`, false 83 | // after `solve`; 84 | bool new_linearization_point_ = false; 85 | }; 86 | 87 | } // namespace rootba 88 | -------------------------------------------------------------------------------- /src/rootba/util/system_utils.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | #include "rootba/util/system_utils.hpp" 38 | 39 | #include 40 | 41 | #if __APPLE__ 42 | #include 43 | #include 44 | #elif __linux__ 45 | #include 46 | 47 | #include 48 | #endif 49 | 50 | namespace rootba { 51 | 52 | bool get_memory_info(MemoryInfo& info) { 53 | #if __APPLE__ 54 | mach_task_basic_info_data_t t_info; 55 | mach_msg_type_number_t t_info_count = MACH_TASK_BASIC_INFO_COUNT; 56 | 57 | if (KERN_SUCCESS != task_info(mach_task_self(), MACH_TASK_BASIC_INFO, 58 | (task_info_t)&t_info, &t_info_count)) { 59 | return false; 60 | } 61 | info.resident_memory = t_info.resident_size; 62 | info.resident_memory_peak = t_info.resident_size_max; 63 | 64 | /* 65 | struct rusage resource_usage; 66 | getrusage(RUSAGE_SELF, &resource_usage); 67 | info.resident_memory_peak = resource_usage.ru_maxrss; 68 | */ 69 | 70 | return true; 71 | #elif __linux__ 72 | 73 | // get current memory first 74 | std::size_t program_size = 0; 75 | std::size_t resident_size = 0; 76 | 77 | std::ifstream fs("/proc/self/statm"); 78 | if (fs.fail()) { 79 | return false; 80 | } 81 | fs >> program_size; 82 | fs >> resident_size; 83 | 84 | info.resident_memory = resident_size * sysconf(_SC_PAGESIZE); 85 | 86 | // get peak memory after that 87 | struct rusage resource_usage; 88 | getrusage(RUSAGE_SELF, &resource_usage); 89 | info.resident_memory_peak = resource_usage.ru_maxrss * 1024; 90 | 91 | return true; 92 | #else 93 | return false; 94 | #endif 95 | } 96 | 97 | } // namespace rootba 98 | -------------------------------------------------------------------------------- /scripts/build-rootba.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ## 3 | ## BSD 3-Clause License 4 | ## 5 | ## This file is part of the RootBA project. 6 | ## https://github.com/NikolausDemmel/rootba 7 | ## 8 | ## Copyright (c) 2021-2023, Nikolaus Demmel. 9 | ## All rights reserved. 10 | ## 11 | 12 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 13 | PROJECT_DIR="$SCRIPT_DIR/.." 14 | 15 | set -x 16 | set -e 17 | 18 | BUILD_TYPE="${1:-Release}" 19 | if [ "$#" -ge 1 ]; then 20 | shift 21 | fi 22 | 23 | echo "$BUILD_TYPE build" 24 | 25 | ############################################################################### 26 | ## setup 27 | 28 | # determine build dir 29 | BUILD_DIR_SUFFIX="" 30 | if [ -n "$ROOTBA_ARCH_SUFFIX" ]; then 31 | BUILD_DIR_SUFFIX=-$ROORTBA_ARCH_SUFFIX 32 | EXTRA_CMAKE_FLAGS="-DROOTBA_EXTERNAL_BUILD_DIR_SUFFIX=$BUILD_DIR_SUFFIX -DROOTBA_DEVELOPER_MODE=Off" 33 | fi 34 | BUILD_DIR="$PROJECT_DIR/build$BUILD_DIR_SUFFIX" 35 | 36 | if [ `uname -s` == Darwin ]; then 37 | # macOS 38 | 39 | product_version=$(sw_vers -productVersion) 40 | os_vers=( ${product_version//./ } ) 41 | os_vers_major="${os_vers[0]}" 42 | os_vers_minor="${os_vers[1]}" 43 | 44 | if [ $od_vers_major == 10 && $os_vers_minor -lt 15 ]; then 45 | echo "ERROR: macOS before 10.15 Catalina not supported" 46 | fi 47 | else 48 | # Linux 49 | 50 | # determine correct default compiler 51 | 52 | # TODO: more flexibility when determining correct default compiler, depending on what is installed 53 | # GCC version 9 is minimum for decent C++17 support 54 | if [ -z "$CXX" ]; then 55 | for VER in 9 10 11; do 56 | if hash g++-$VER 2> /dev/null; then 57 | export CC=gcc-$VER 58 | export CXX=g++-$VER 59 | break 60 | fi 61 | done 62 | fi 63 | 64 | # if no GCC, try clang; minimum version is 9 65 | if [ -z "$CXX" ]; then 66 | for VER in 9 10 11 12; do 67 | if hash clang++-$VER 2> /dev/null; then 68 | export CC=clang-$VER 69 | export CXX=clang++-$VER 70 | break 71 | fi 72 | done 73 | fi 74 | fi 75 | 76 | # check that compiler can be found if set 77 | if [ -n "$CXX" ]; then 78 | which "$CXX" 79 | fi 80 | if [ -n "$CC" ]; then 81 | which "$CC" 82 | fi 83 | 84 | if [ -n "$ROOTBA_CXXFLAGS" ]; then 85 | export CXXFLAGS="$CXXFLAGS $ROOTBA_CXXFLAGS" 86 | fi 87 | 88 | # number of logical cores on linux and macos 89 | NUM_CORES=`(which nproc > /dev/null && nproc) || sysctl -n hw.logicalcpu || echo 1` 90 | #NUM_CORES=1 91 | 92 | # Prefer ninja if available 93 | if which ninja; then 94 | EXTRA_CMAKE_FLAGS="${EXTRA_CMAKE_FLAGS} -GNinja" 95 | else 96 | export MAKEFLAGS=-j$NUM_CORES 97 | fi 98 | 99 | #export VERBOSE=1 100 | 101 | # NOTE: Newer versions of Clang / AppleClang support -march=native on Apple Silicon, 102 | # so at some point we can remove this workaround. 103 | if [ $(uname -m) = "x86_64" ]; then 104 | CXX_MARCH="${CXX_MARCH:-native}" 105 | fi 106 | 107 | ############################################################################### 108 | ## execute 109 | 110 | mkdir -p "$BUILD_DIR" 111 | cd "$BUILD_DIR" 112 | cmake $EXTRA_CMAKE_FLAGS -DCXX_MARCH="$CXX_MARCH" -DCMAKE_BUILD_TYPE="$BUILD_TYPE" "$@" .. 113 | cmake --build . 114 | -------------------------------------------------------------------------------- /src/rootba/ceres/bal_residuals.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | #include 40 | 41 | #include "rootba/ceres/types.hpp" 42 | #include "rootba/util/eigen_types.hpp" 43 | 44 | namespace rootba { 45 | 46 | // ceres residual 47 | template 48 | class BalSnavelyReprojectionError { 49 | public: 50 | explicit BalSnavelyReprojectionError(const Vec2d& obs) : obs_(obs) {} 51 | 52 | template 53 | bool operator()(const T* camera, const T* landmark, T* residual) const { 54 | Eigen::Map> T_c_w(camera); 55 | Eigen::Map> intrinsics(camera + 7); 56 | Eigen::Map> p_w(landmark); 57 | Eigen::Map> res_vec(residual); 58 | 59 | const basalt::BalCamera cam(intrinsics); 60 | 61 | auto p_cam = T_c_w * p_w; 62 | if constexpr (Options & VALID_PROJECTIONS_ONLY) { 63 | if (p_cam.z() < Sophus::Constants::epsilonSqrt()) { 64 | // invalid projection 65 | res_vec.setZero(); 66 | } else { 67 | Eigen::Matrix p_proj; 68 | cam.project(p_cam.homogeneous(), p_proj); 69 | res_vec = p_proj - obs_; 70 | } 71 | } else { 72 | Eigen::Matrix p_proj; 73 | cam.project(p_cam.homogeneous(), p_proj); 74 | res_vec = p_proj - obs_; 75 | } 76 | 77 | return true; 78 | } 79 | 80 | static ceres::CostFunction* create(const Vec2d& obs) { 81 | return ( 82 | new ceres::AutoDiffCostFunction( 83 | new BalSnavelyReprojectionError(obs))); 84 | } 85 | 86 | private: 87 | Vec2d obs_; 88 | }; 89 | 90 | } // namespace rootba 91 | -------------------------------------------------------------------------------- /src/rootba/qr/landmark_block.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #include "rootba/qr/landmark_block.hpp" 37 | 38 | #include "rootba/qr/landmark_block_dynamic.hpp" 39 | 40 | #ifdef ROOTBA_INSTANTIATIONS_STATIC_LMB 41 | #include "rootba/qr/landmark_block_static.hpp" 42 | #endif 43 | 44 | namespace rootba { 45 | 46 | template 47 | std::unique_ptr> 48 | LandmarkBlockFactory::get_landmark_block(size_t obs_size) { 49 | std::unique_ptr> lb; 50 | 51 | switch (obs_size) { 52 | case 0: 53 | case 1: 54 | LOG(FATAL) << "landmark.obs.size() " << obs_size << " is not supported."; 55 | #ifdef ROOTBA_INSTANTIATIONS_STATIC_LMB 56 | case 2: 57 | lb.reset(new LandmarkBlockStatic); 58 | break; 59 | case 3: 60 | lb.reset(new LandmarkBlockStatic); 61 | break; 62 | case 4: 63 | lb.reset(new LandmarkBlockStatic); 64 | break; 65 | case 5: 66 | lb.reset(new LandmarkBlockStatic); 67 | break; 68 | case 6: 69 | lb.reset(new LandmarkBlockStatic); 70 | break; 71 | case 7: 72 | lb.reset(new LandmarkBlockStatic); 73 | break; 74 | case 8: 75 | lb.reset(new LandmarkBlockStatic); 76 | break; 77 | #endif 78 | default: 79 | lb.reset(new LandmarkBlockDynamic); 80 | } 81 | 82 | return lb; 83 | } 84 | 85 | #ifdef ROOTBA_INSTANTIATIONS_FLOAT 86 | template class LandmarkBlockFactory; 87 | #endif 88 | 89 | #ifdef ROOTBA_INSTANTIATIONS_DOUBLE 90 | template class LandmarkBlockFactory; 91 | #endif 92 | 93 | } // namespace rootba 94 | -------------------------------------------------------------------------------- /src/rootba/solver/linearizor.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include "rootba/bal/bal_problem.hpp" 39 | #include "rootba/bal/residual_info.hpp" 40 | #include "rootba/bal/solver_options.hpp" 41 | #include "rootba/solver/solver_summary.hpp" 42 | 43 | namespace rootba { 44 | 45 | // TODO: can we find a better name than Linearizor? Linearization is already 46 | // taken for the more low-level API in LinearizationQR and LinearizationSC. 47 | template 48 | class Linearizor { 49 | public: 50 | using Scalar = Scalar_; 51 | 52 | using VecX = Eigen::Matrix; 53 | 54 | public: 55 | // factory method 56 | static std::unique_ptr> create( 57 | BalProblem& bal_problem, const SolverOptions& options, 58 | SolverSummary* summary = nullptr); 59 | 60 | virtual ~Linearizor() = default; 61 | 62 | // start a new solver iteration and set (optional) summary for logging 63 | virtual void start_iteration(IterationSummary* it_summary = nullptr) = 0; 64 | 65 | // compute error (with logging; use after `start_iteration`) 66 | virtual void compute_error(ResidualInfo& ri) = 0; 67 | 68 | // called once for every new linearization point 69 | // TODO: add optional output parameter `ResidualInfo* ri` 70 | virtual void linearize() = 0; 71 | 72 | // maybe be called multiple times with different lambda for the same 73 | // linearization point (no call of `linearize` in between); returns camera 74 | // increment 75 | virtual VecX solve(Scalar lambda) = 0; 76 | 77 | // apply camera increment (backsubstitute and update cameras) 78 | // returns model cost change l_diff 79 | virtual Scalar apply(VecX&& inc) = 0; 80 | 81 | // finalize logging for a single solver iteration 82 | virtual void finish_iteration() = 0; 83 | }; 84 | 85 | } // namespace rootba 86 | -------------------------------------------------------------------------------- /src/rootba/util/time_utils.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | 40 | namespace rootba { 41 | 42 | template 43 | class Timer { 44 | public: 45 | /// start timer 46 | Timer() : start_(Clock::now()) {} 47 | 48 | /// return elapsed time in seconds 49 | double elapsed() const { 50 | return std::chrono::duration(Clock::now() - start_).count(); 51 | } 52 | 53 | /// return elapsed time in seconds and reset timer 54 | double reset() { 55 | const auto now = Clock::now(); 56 | const double elapsed = std::chrono::duration(now - start_).count(); 57 | start_ = now; 58 | return elapsed; 59 | } 60 | 61 | private: 62 | std::chrono::time_point start_; 63 | }; 64 | 65 | template 66 | struct AssignOp { 67 | void operator()(Scalar& lhs, const Scalar& rhs) { lhs = rhs; } 68 | }; 69 | 70 | template 71 | struct PlusAssignOp { 72 | void operator()(Scalar& lhs, const Scalar& rhs) { lhs += rhs; } 73 | }; 74 | 75 | template , class Assign = AssignOp<>> 76 | class ScopedTimer { 77 | public: 78 | explicit ScopedTimer(double& dest) : dest_(dest) {} 79 | ~ScopedTimer() { Assign()(dest_, timer_.elapsed()); } 80 | 81 | private: 82 | double& dest_; 83 | T timer_; 84 | }; 85 | 86 | using ScopedTimerAdd = ScopedTimer, PlusAssignOp<>>; 87 | 88 | template 89 | void log_timing(double& time, F fun) { 90 | Timer timer; 91 | fun(); 92 | time = timer.elapsed(); 93 | } 94 | 95 | template 96 | void log_timing_add(double& time, F fun) { 97 | Timer timer; 98 | fun(); 99 | time += timer.elapsed(); 100 | } 101 | 102 | } // namespace rootba 103 | -------------------------------------------------------------------------------- /cmake/Utils.cmake: -------------------------------------------------------------------------------- 1 | macro(set_default_build_type build_type) 2 | # Set default build type if not specified otherwise. 3 | # See https://cmake.org/pipermail/cmake/2012-May/050243.html 4 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 5 | set(CMAKE_BUILD_TYPE ${build_type} CACHE STRING "Choose the type of build." FORCE) 6 | message(STATUS "Setting build type to '${CMAKE_BUILD_TYPE}' as none was specified.") 7 | # Set the possible values of build type for cmake-gui 8 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" 9 | "MinSizeRel" "RelWithDebInfo") 10 | endif() 11 | endmacro() 12 | 13 | macro(set_default_compiler_launcher) 14 | if(NOT CMAKE_C_COMPILER_LAUNCHER AND NOT CMAKE_CXX_COMPILER_LAUNCHER) 15 | find_program(CCACHE_PROGRAM ccache) 16 | if(CCACHE_PROGRAM) 17 | message(STATUS "Found ccache: ${CCACHE_PROGRAM}") 18 | set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM}) 19 | set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM}) 20 | else() 21 | message(STATUS "Dind't find ccache") 22 | endif() 23 | else() 24 | message(STATUS "Compiler launcher already set. Not configuring ccache.") 25 | message(STATUS "CMAKE_C_COMPILER_LAUNCHER: ${CMAKE_C_COMPILER_LAUNCHER}") 26 | message(STATUS "CMAKE_CXX_COMPILER_LAUNCHER: ${CMAKE_CXX_COMPILER_LAUNCHER}") 27 | endif() 28 | endmacro() 29 | 30 | # Custom macro for adding unit tests. 31 | # Inspired by: https://cliutils.gitlab.io/modern-cmake/chapters/testing/googletest.html 32 | macro(rootba_add_test) 33 | set(options "") 34 | set(oneValueArgs "") 35 | set(multiValueArgs "LINK_LIBRARIES;INCLUDE_DIRECTORIES") 36 | cmake_parse_arguments(ROOTBA_TEST 37 | "${options}" 38 | "${oneValueArgs}" 39 | "${multiValueArgs}" 40 | ${ARGN} 41 | ) 42 | 43 | list(POP_FRONT ROOTBA_TEST_UNPARSED_ARGUMENTS ROOTBA_TEST_NAME) 44 | set(ROOTBA_TEST_SOURCES ${ROOTBA_TEST_UNPARSED_ARGUMENTS}) 45 | 46 | add_executable(${ROOTBA_TEST_NAME} ${ROOTBA_TEST_SOURCES}) 47 | 48 | # we cannot directly use target_compile_options on ${ROOTBA_TEST_NAME}, since then they would 49 | # appear before the warning flags inherited from any libraries in ${ROOTBA_TEST_LINK_LIBRARIES} 50 | # and the -Wno-... arguments would be overwritten again 51 | add_library(${ROOTBA_TEST_NAME}_compile_options INTERFACE) 52 | if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU") 53 | # no-gnu-zero-variadic-macro-arguments: see https://github.com/google/googletest/issues/2271 54 | target_compile_options(${ROOTBA_TEST_NAME}_compile_options INTERFACE -Wno-gnu-zero-variadic-macro-arguments) 55 | endif() 56 | 57 | target_link_libraries(${ROOTBA_TEST_NAME} PRIVATE gtest gmock gtest_main ${ROOTBA_TEST_LINK_LIBRARIES} ${ROOTBA_TEST_NAME}_compile_options) 58 | 59 | target_include_directories(${ROOTBA_TEST_NAME} PRIVATE ${ROOTBA_TEST_INCLUDE_DIRECTORIES}) 60 | 61 | # Note on test discovery timeout: the default of 5 seconds was sometimes hit on 62 | # the build server, thus we increase it liberally. 63 | gtest_discover_tests(${ROOTBA_TEST_NAME} 64 | WORKING_DIRECTORY 65 | ${CMAKE_SOURCE_DIR} 66 | DISCOVERY_TIMEOUT 67 | 60 68 | ) 69 | 70 | set_target_properties(${ROOTBA_TEST_NAME} PROPERTIES FOLDER tests) 71 | endmacro() 72 | 73 | function(TARGET_COMPILE_FLAG_OPTION TARGET DEFINE_NAME DOCSTRING DEFAULT_VALUE ) 74 | option(${DEFINE_NAME} "${DOCSTRING}" ${DEFAULT_VALUE}) 75 | message(STATUS "${DEFINE_NAME}: ${${DEFINE_NAME}}") 76 | if(${DEFINE_NAME}) 77 | target_compile_definitions(${TARGET} PUBLIC ${DEFINE_NAME}) 78 | endif() 79 | endfunction() 80 | -------------------------------------------------------------------------------- /src/rootba/util/visit_struct_utils.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | #include "rootba/util/container_traits.hpp" 43 | #include "rootba/util/template_utils.hpp" 44 | 45 | namespace rootba { 46 | 47 | // general equality with visit_struct 48 | struct eq_visitor { // NOLINT 49 | bool result = true; 50 | 51 | template 52 | void operator()(const char* /*member_name*/, const T& t1, const T& t2) { 53 | result = result && (t1 == t2); 54 | } 55 | }; 56 | 57 | // general equality with visit_struct 58 | template 59 | bool struct_eq(const T& t1, const T& t2) { 60 | eq_visitor vis; 61 | visit_struct::for_each(t1, t2, vis); 62 | return vis.result; 63 | } 64 | 65 | // convert visitable struct to json; supports types that can be assigned to 66 | // nlohmann::json, such as strings, doubles, as well as recursive std::vector 67 | // and visistable structs; 68 | template 69 | auto visitable_to_json(const Value& value) { 70 | nlohmann::json result; 71 | if constexpr (visit_struct::traits::is_visitable::value) { 72 | // visitable struct --> visit each member and save as json object 73 | visit_struct::for_each(value, [&](const char* name, const auto& member) { 74 | result[name] = visitable_to_json(member); 75 | }); 76 | } else if constexpr (is_vector_v) { 77 | // vector --> recursively save elements to json array 78 | for (const auto& elem : value) { 79 | result.push_back(visitable_to_json(elem)); 80 | } 81 | } else if constexpr (wise_enum::is_wise_enum_v) { 82 | // enum --> save as string 83 | result = wise_enum::to_string(value); 84 | } else { 85 | // other basic value (string, number, ...) 86 | result = value; 87 | } 88 | return result; 89 | } 90 | 91 | } // namespace rootba 92 | -------------------------------------------------------------------------------- /python/rootba/latex/summarize_sequences_table.py: -------------------------------------------------------------------------------- 1 | # 2 | # BSD 3-Clause License 3 | # 4 | # This file is part of the RootBA project. 5 | # https://github.com/NikolausDemmel/rootba 6 | # 7 | # Copyright (c) 2021, Nikolaus Demmel. 8 | # All rights reserved. 9 | # 10 | import numbers 11 | import os 12 | import scipy.stats 13 | import numpy as np 14 | 15 | from pylatex import Subsection, FootnoteText, Tabular, NoEscape, escape_latex 16 | from pylatex.utils import italic, bold 17 | 18 | from .containers import ExperimentsTable 19 | from .util import best_two_non_repeating 20 | 21 | 22 | class SummarizeSequencesTable(ExperimentsTable): 23 | 24 | def __init__(self, exps, spec, show_values_failed_runs, seq_displayname_mapping, export_basepath): 25 | super().__init__(exps, spec, show_values_failed_runs, seq_displayname_mapping, export_basepath) 26 | 27 | self.doit() 28 | 29 | def doit(self): 30 | 31 | def render_metric(value, best, second, decimals, format_string): 32 | if isinstance(value, numbers.Number): 33 | rendered = format_string.format(value, prec=decimals) 34 | if value == best: 35 | rendered = bold(rendered) 36 | elif value == second: 37 | rendered = italic(rendered) 38 | return rendered 39 | else: 40 | return value 41 | 42 | values = np.empty((self.num_metrics, self.num_seqs, self.num_exps)) 43 | 44 | for i, seq in enumerate(self.seq_names): 45 | for j, s in enumerate(self.experiment_specs): 46 | values[:, i, j] = np.array(self.get_metrics(self.exps[s.name], seq, s.it)) 47 | 48 | means = np.empty((self.num_metrics, self.num_exps)) 49 | for i, m in enumerate(self.metrics): 50 | if m.geometric_mean: 51 | means[i, :] = scipy.stats.gmean(values[i, :, :], axis=0) 52 | else: 53 | means[i, :] = np.mean(values[i, :, :], axis=0) 54 | 55 | t = Tabular('l' + 'c' * self.num_exps) 56 | 57 | t.add_hline() 58 | escape_header_fun = lambda text: text if self.spec.escape_latex_header else NoEscape(text) 59 | if self.spec.rotate_header: 60 | t.add_row([self.spec.header] + [ 61 | NoEscape(r"\rotatebox{90}{%s}" % escape_latex(escape_header_fun(s.display_name(self.exps[s.name])))) 62 | for s in self.experiment_specs 63 | ]) 64 | else: 65 | t.add_row([self.spec.header] + 66 | [escape_header_fun(s.display_name(self.exps[s.name])) for s in self.experiment_specs]) 67 | t.add_hline() 68 | 69 | for i, m in enumerate(self.metrics): 70 | row_values = np.around(means[i, :], m.decimals) 71 | top_values = best_two_non_repeating(row_values, reverse=m.larger_is_better) 72 | row = [m.display_name] 73 | for v in row_values: 74 | # TODO: use NoEscape only if certain flag is enabled? 75 | row.append( 76 | NoEscape( 77 | render_metric(v, top_values[0], top_values[1], m.effective_display_decimals(), 78 | m.format_string))) 79 | t.add_row(row) 80 | 81 | t.add_hline() 82 | 83 | if self.spec.export_latex: 84 | os.makedirs(self.export_basepath, exist_ok=True) 85 | t.generate_tex(os.path.join(self.export_basepath, self.spec.export_latex)) 86 | 87 | with self.create(Subsection(self.spec.name, numbering=False)) as p: 88 | p.append(FootnoteText(t)) 89 | -------------------------------------------------------------------------------- /src/rootba/cli/cli_options.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | #include 40 | 41 | #include "rootba/options/options_interface.hpp" 42 | 43 | namespace rootba { 44 | 45 | inline std::string to_cli_name(std::string name) { 46 | std::replace(name.begin(), name.end(), '_', '-'); 47 | return name; 48 | } 49 | 50 | // std::string to_upper(std::string str) { 51 | // for (auto& c : str) c = toupper((unsigned char)c); 52 | // return str; 53 | //} 54 | 55 | template 56 | std::string cli_placeholder() { 57 | if constexpr (std::is_same_v) { 58 | return "INT"; 59 | } else if constexpr (std::is_same_v) { 60 | return "FLOAT"; 61 | } else if constexpr (std::is_same_v) { 62 | return "STR"; 63 | } 64 | } 65 | 66 | class CliArgumentsOptionsVisitor : public ConstOptionsVisitor { 67 | using json = nlohmann::json; 68 | 69 | public: 70 | CliArgumentsOptionsVisitor(json& output_node, const std::string& cli_prefix); 71 | 72 | void operator()(const char* name, OptionsVariableConstRef var, 73 | const OptionsMeta& meta) override; 74 | 75 | void operator()(const char* name, const OptionsInterface& child) override; 76 | 77 | inline clipp::group get_cli_group() const { return cli_; } 78 | 79 | private: 80 | std::vector json_prefix_stack_; 81 | std::vector cli_prefix_stack_; 82 | json& output_node_; 83 | clipp::group cli_; 84 | }; 85 | 86 | // Returns cli group for given options (recursive). When parsing cli arguments, 87 | // the actually passed arguments are then stored in the json object 88 | // parse_output. You can then pass this json object to options._load() to set 89 | // the parsed values. 90 | clipp::group cli_options(nlohmann::json& parse_output, 91 | const OptionsInterface& options, 92 | const std::string& prefix); 93 | 94 | } // namespace rootba 95 | -------------------------------------------------------------------------------- /src/rootba/util/template_utils.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | BSD 3-Clause License 3 | 4 | This file is part of the RootBA project. 5 | https://github.com/NikolausDemmel/rootba 6 | 7 | Copyright (c) 2021-2023, Nikolaus Demmel. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | #pragma once 37 | 38 | #include 39 | #include 40 | 41 | // mp (meta programming) namespace to allow concise and short name that don't 42 | // clutter the main namespace 43 | namespace rootba::mp { 44 | 45 | // //////////////////////////////////////////////////////////////////////////// 46 | // overloads for generic lambdas 47 | // See also: https://stackoverflow.com/q/55087826/1813258 48 | template 49 | struct overload : Ts... { // NOLINT 50 | using Ts::operator()...; 51 | }; 52 | template 53 | overload(Ts...) -> overload; 54 | 55 | // //////////////////////////////////////////////////////////////////////////// 56 | // generic trait that is always false 57 | template 58 | struct always_false : std::integral_constant {}; // NOLINT 59 | 60 | template 61 | static constexpr bool always_false_v = always_false::value; 62 | 63 | // //////////////////////////////////////////////////////////////////////////// 64 | // add const based on boolean 65 | template 66 | using maybe_const = std::conditional_t; 67 | 68 | // //////////////////////////////////////////////////////////////////////////// 69 | // Type trait is_instance for template instatiations 70 | // See also: https://stackoverflow.com/a/61040973/1813258 71 | namespace detail { 72 | template typename> 73 | struct is_instance_impl : public std::false_type {}; 74 | 75 | template