// Copyright 2026, Beyley Cardellio // SPDX-License-Identifier: BSL-1.0 /*! * @file * @brief Generic math helpers for constellation optimizer code. * @author Beyley Cardellio * @ingroup tracking */ #pragma once #include "math/m_eigen_interop.hpp" #include "math/m_quatexpmap.hpp" #include "math/m_quatexpmap_bigceres.hpp" #include #include #include #include #include #include "pose_optimize.hpp" namespace xrt::tracking::constellation::optimizer { using namespace xrt::auxiliary::math; // Covariance lives in the manifold's tangent space, which is one dimension smaller than the ambient // parameter block: the quaternion contributes 3 tangent dimensions, not 4. typedef Eigen::Matrix PoseStateCovarianceMatrix; //! Returns an Isometry3f from an @ref xrt_pose. inline Eigen::Isometry3f isometryFromPose(const xrt_pose &p) { return {Eigen::Translation3f{map_vec3(p.position)} * map_quat(p.orientation)}; } /*! * Right-multiplying quaternion manifold, matches our local convention. */ struct QuaternionManifoldFunctor { template bool Plus(const T *x, const T *delta, T *x_plus_delta) const { const Eigen::Map> q(x); const Eigen::Map> w(delta); Eigen::Map> result(x_plus_delta); result = q * quat_exp_so3(w); return true; } template bool Minus(const T *y, const T *x, T *y_minus_x) const { const Eigen::Map> q_y(y); const Eigen::Map> q_x(x); Eigen::Map> result(y_minus_x); result = quat_ln_so3(Eigen::Quaternion(q_x.conjugate() * q_y)); return true; } }; // Pose manifold, (tX, tY, tZ), (qX, qY, qZ, qW) typedef ceres::ProductManifold, ceres::AutoDiffManifold> PoseManifold; // Pose plus linear velocity, (tX, tY, tZ), (qX, qY, qZ, qW), (vX, vY, vZ). 10 ambient, 9 tangent. typedef ceres::ProductManifold, ceres::AutoDiffManifold, ceres::EuclideanManifold<3>> PoseWithVelocityManifold; }; // namespace xrt::tracking::constellation::optimizer