From 8dacb8630e86046e9d27d9f70f4c9d550338f972 Mon Sep 17 00:00:00 2001 From: Dmitriy Korchemkin Date: Fri, 5 Feb 2021 22:32:07 +0300 Subject: [PATCH] Local parameterization header & tests --- sophus/ceres_local_parameterization.hpp | 96 ++++++++ test/ceres/CMakeLists.txt | 2 +- test/ceres/test_ceres_rxso2.cpp | 36 +++ test/ceres/test_ceres_rxso3.cpp | 41 ++++ test/ceres/test_ceres_se2.cpp | 35 +++ test/ceres/test_ceres_se3.cpp | 211 +++-------------- test/ceres/test_ceres_sim2.cpp | 50 ++++ test/ceres/test_ceres_sim3.cpp | 43 ++++ test/ceres/test_ceres_so2.cpp | 31 +++ test/ceres/test_ceres_so3.cpp | 34 +++ test/ceres/tests.hpp | 302 ++++++++++++++++++++++++ 11 files changed, 699 insertions(+), 182 deletions(-) create mode 100644 sophus/ceres_local_parameterization.hpp create mode 100644 test/ceres/test_ceres_rxso2.cpp create mode 100644 test/ceres/test_ceres_rxso3.cpp create mode 100644 test/ceres/test_ceres_se2.cpp create mode 100644 test/ceres/test_ceres_sim2.cpp create mode 100644 test/ceres/test_ceres_sim3.cpp create mode 100644 test/ceres/test_ceres_so2.cpp create mode 100644 test/ceres/test_ceres_so3.cpp create mode 100644 test/ceres/tests.hpp diff --git a/sophus/ceres_local_parameterization.hpp b/sophus/ceres_local_parameterization.hpp new file mode 100644 index 000000000..4bdad9f68 --- /dev/null +++ b/sophus/ceres_local_parameterization.hpp @@ -0,0 +1,96 @@ +#ifndef SOPHUS_CERES_LOCAL_PARAMETERIZATION_HPP +#define SOPHUS_CERES_LOCAL_PARAMETERIZATION_HPP + +namespace Sophus { + +/// Type trait used to distinguish mappable vector types from scalars +/// We use this class to distinguish Sophus::Vector from Scalar types +/// in LieGroup::Tangent +/// +/// Fortunately, ceres::Jet is not mappable +template +struct is_mappable_type_t { + template + using EigenTraits = Eigen::internal::traits; + // Eigen::Map requires Eigen::internal::traits type to be complete + template + static auto map_test(U*) + -> std::integral_constant) == + sizeof(EigenTraits)>; + static auto map_test(...) -> std::false_type; + + using type = decltype(map_test((T*)nullptr)); + static constexpr bool value = type::value; +}; + +template +constexpr bool is_mappable_type_v = is_mappable_type_t::value; + +/// Helper for mapping tangent vectors (scalars) over pointers to data +template +struct Mapper { + using Scalar = T; + using Map = Scalar&; + using CMap = const Scalar&; + + static Map map(Scalar* ptr) { return *ptr; } + static CMap map(const Scalar* ptr) { return *ptr; } +}; + +template +struct Mapper>::type> { + using Scalar = typename T::Scalar; + using Map = Eigen::Map; + using CMap = Eigen::Map; + + static Map map(Scalar* ptr) { return Map(ptr); } + static CMap map(const Scalar* ptr) { return CMap(ptr); } +}; + +/// Templated local parameterization for LieGroup [with implemented +/// LieGroup::Dx_this_mul_exp_x_at_0() ] +template