diff --git a/cpp/sophus2/ceres/jet_helpers.h b/cpp/sophus2/ceres/jet_helpers.h index e33c5b0b..ee9c592f 100644 --- a/cpp/sophus2/ceres/jet_helpers.h +++ b/cpp/sophus2/ceres/jet_helpers.h @@ -26,7 +26,9 @@ struct GetValue { template struct GetValue<::ceres::Jet> { - static auto impl(TScalar const& t) -> TScalar { return t.a; } + static auto impl(::ceres::Jet const& t) -> TScalar { + return t.a; + } }; } // namespace jet_helpers diff --git a/cpp/sophus2/common/common.h b/cpp/sophus2/common/common.h index 0a170fa6..1a00ca32 100644 --- a/cpp/sophus2/common/common.h +++ b/cpp/sophus2/common/common.h @@ -72,7 +72,7 @@ template <> inline float const kEpsilon = float(1e-5); static float const kEpsilonF32 = kEpsilon; -static float const kEpsilonF64 = kEpsilon; +static double const kEpsilonF64 = kEpsilon; /// Slightly larger than kEpsilon. template diff --git a/cpp/sophus2/geometry/ray.h b/cpp/sophus2/geometry/ray.h index 346640f6..025a6992 100644 --- a/cpp/sophus2/geometry/ray.h +++ b/cpp/sophus2/geometry/ray.h @@ -64,7 +64,7 @@ class Ray { } struct IntersectionResult { - double lambda; + TScalar lambda; Eigen::Matrix point; }; diff --git a/cpp/sophus2/manifold/unit_vector.h b/cpp/sophus2/manifold/unit_vector.h index ab53020f..c8b3fbed 100644 --- a/cpp/sophus2/manifold/unit_vector.h +++ b/cpp/sophus2/manifold/unit_vector.h @@ -8,6 +8,7 @@ #pragma once +#include "sophus2/ceres/jet_helpers.h" #include "sophus2/common/common.h" #include "sophus2/concepts/manifold.h" @@ -77,9 +78,11 @@ class UnitVectorImpl { /// Returns false if the norm of the vector if not close to 1. static auto areParamsValid(Params const& unit_vector) -> sophus2::Expected { - static Scalar const kThr = kEpsilon; - Scalar const squared_norm = unit_vector.squaredNorm(); using std::abs; + static auto const kThr = + jet_helpers::GetValue::impl(kEpsilon); + auto const squared_norm = + jet_helpers::GetValue::impl(unit_vector.squaredNorm()); if (!(abs(squared_norm - 1.0) <= kThr)) { return SOPHUS_UNEXPECTED( "unit vector ({}) is not of unit length.\n" diff --git a/cpp/sophus2/sensor/CMakeLists.txt b/cpp/sophus2/sensor/CMakeLists.txt index d02785b6..138826eb 100644 --- a/cpp/sophus2/sensor/CMakeLists.txt +++ b/cpp/sophus2/sensor/CMakeLists.txt @@ -36,11 +36,10 @@ SOURCES target_link_libraries(sophus2_sensor sophus2_lie sophus2_image) -if(${BUILD_SOPHUS_TESTS}) - foreach(test_basename ${sophus2_sensor_src_prefixes}) - farm_ng_add_test(${test_basename} - PARENT_LIBRARY sophus2_sensor - LINK_LIBRARIES sophus2_sensor - LABELS small) - endforeach() -endif() + +foreach(test_basename ${sophus2_sensor_src_prefixes}) + farm_ng_add_test(${test_basename} + PARENT_LIBRARY sophus2_sensor + LINK_LIBRARIES sophus2_sensor + LABELS small) +endforeach() diff --git a/cpp/sophus2/sensor/camera_distortion/brown_conrady.h b/cpp/sophus2/sensor/camera_distortion/brown_conrady.h index f4cf29f5..08f10186 100644 --- a/cpp/sophus2/sensor/camera_distortion/brown_conrady.h +++ b/cpp/sophus2/sensor/camera_distortion/brown_conrady.h @@ -67,6 +67,8 @@ class BrownConradyTransform { static auto unprojImpl( DistorationParams const& distortion, PixelImage const& uv_normalized) -> PixelImage { + using std::abs; + // We had no luck with OpenCV's undistort. It seems not to be accurate if // "icdist" is close to 0. // https://github.com/opencv/opencv/blob/63bb2abadab875fc648a572faccafee134f06fc8/modules/calib3d/src/undistort.dispatch.cpp#L365 @@ -90,7 +92,6 @@ class BrownConradyTransform { PixelImage xy = uv_normalized; for (int i = 0; i < 50; ++i) { - using std::abs; TScalar x = xy[0]; TScalar y = xy[1]; @@ -116,27 +117,29 @@ class BrownConradyTransform { TScalar const c4 = c3 * c2; // pow(c2, 3); TScalar const c5 = c2 * d[5] + c3 * d[6] + c4 * d[7] + 1.0; TScalar const c6 = c5 * c5; // pow(c5, 2); - TScalar const c7 = 1.0 / c6; + TScalar const c7 = TScalar(1.0) / c6; TScalar const c8 = a * d[3]; - TScalar const c9 = 2.0 * d[2]; - TScalar const c10 = 2 * c2; - TScalar const c11 = 3 * c3; + TScalar const c9 = TScalar(2.0) * d[2]; + TScalar const c10 = TScalar(2) * c2; + TScalar const c11 = TScalar(3) * c3; TScalar const c12 = c2 * d[0]; TScalar const c13 = c3 * d[1]; TScalar const c14 = c4 * d[4]; - TScalar const c15 = - 2.0 * (c10 * d[6] + c11 * d[7] + d[5]) * (c12 + c13 + c14 + 1.0); - TScalar const c16 = 2.0 * c10 * d[1] + 2.0 * c11 * d[4] + 2.0 * d[0]; - TScalar const c17 = 1.0 * c12 + 1.0 * c13 + 1.0 * c14 + 1.0; + TScalar const c15 = TScalar(2.0) * (c10 * d[6] + c11 * d[7] + d[5]) * + (c12 + c13 + c14 + TScalar(1.0)); + TScalar const c16 = TScalar(2.0) * c10 * d[1] + + TScalar(2.0) * c11 * d[4] + TScalar(2.0) * d[0]; + TScalar const c17 = TScalar(1.0) * c12 + TScalar(1.0) * c13 + + TScalar(1.0) * c14 + TScalar(1.0); TScalar const c18 = b * d[3]; TScalar const c19 = a * b; TScalar const c20 = -c15 * c19 + c16 * c19 * c5; - du_dx = - c7 * (-c0 * c15 + c5 * (c0 * c16 + c17) + c6 * (b * c9 + 6.0 * c8)); - du_dy = c7 * (c20 + c6 * (a * c9 + 2 * c18)); - dv_dx = c7 * (c20 + c6 * (2 * a * d[2] + 2.0 * c18)); + du_dx = c7 * (-c0 * c15 + c5 * (c0 * c16 + c17) + + c6 * (b * c9 + TScalar(6.0) * c8)); + du_dy = c7 * (c20 + c6 * (a * c9 + TScalar(2) * c18)); + dv_dx = c7 * (c20 + c6 * (TScalar(2) * a * d[2] + TScalar(2.0) * c18)); dv_dy = c7 * (-c1 * c15 + c5 * (c1 * c16 + c17) + - c6 * (6.0 * b * d[2] + 2.0 * c8)); + c6 * (TScalar(6.0) * b * d[2] + TScalar(2.0) * c8)); } // | du_dx du_dy | | a b | @@ -161,7 +164,7 @@ class BrownConradyTransform { Eigen::Matrix j_inv = TScalar(1) / (a * d - b * c) * m; PixelImage step = j_inv * f_xy; - if (abs(jet_helpers::GetValue::impl(step.squaredNorm())) < + if (abs(step.squaredNorm()) < sophus2::kEpsilon * sophus2::kEpsilon) { break; } diff --git a/cpp/sophus2/sensor/camera_distortion/kannala_brandt.h b/cpp/sophus2/sensor/camera_distortion/kannala_brandt.h index 50feb1cc..7d156b1d 100644 --- a/cpp/sophus2/sensor/camera_distortion/kannala_brandt.h +++ b/cpp/sophus2/sensor/camera_distortion/kannala_brandt.h @@ -133,8 +133,7 @@ class KannalaBrandtK3Transform { const TScalar step = (thd - rth) / d_thd_wtr_th; th -= step; // has converged? - if (abs(jet_helpers::GetValue::impl(step)) < - sophus2::kEpsilon) { + if (abs(step) < sophus2::kEpsilon) { break; } }