|
| 1 | +/* |
| 2 | + * This file is part of the GreasePad distribution (https://github.com/FraunhoferIOSB/GreasePad). |
| 3 | + * Copyright (c) 2022-2026 Jochen Meidow, Fraunhofer IOSB |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | + |
| 19 | + |
| 20 | +#ifndef KERNEL_H |
| 21 | +#define KERNEL_H |
| 22 | + |
| 23 | +#include <Eigen/Core> |
| 24 | + |
| 25 | +#include <cassert> |
| 26 | + |
| 27 | +namespace Matfun { |
| 28 | + |
| 29 | +using Eigen::Matrix; |
| 30 | +using Eigen::Vector; |
| 31 | + |
| 32 | + |
| 33 | +//! Basis vectors for the nullspace of a row vector |
| 34 | +//! |
| 35 | +//! Förstner & Wrobel (2016) Photogrammetric Computer Vision, eq. (A.120) |
| 36 | +template<int N> |
| 37 | +[[nodiscard]] static Matrix<double,N,N-1> |
| 38 | +null( const Vector<double,N> & xs ) |
| 39 | +{ |
| 40 | + constexpr double T_zero = 1e-6; |
| 41 | + assert( std::fabs( xs.norm()-1. ) < T_zero && "vector norm not 1"); |
| 42 | + |
| 43 | + Vector<double,N-1> x0 = xs.head(N-1); |
| 44 | + double xN = xs(N-1); |
| 45 | + if ( xN < 0 ) { |
| 46 | + x0 = -x0; |
| 47 | + xN = -xN; |
| 48 | + } |
| 49 | + |
| 50 | + const Matrix<double,N,N-1> JJ = (Matrix<double,N,N-1>() << |
| 51 | + Matrix<double,N-1,N-1>::Identity(N-1,N-1) -x0*x0.transpose()/(1.+xN), |
| 52 | + -x0.transpose() ).finished(); |
| 53 | + |
| 54 | + const Vector<double,N-1> check = JJ.adjoint()*xs; |
| 55 | + assert( check.norm() < T_zero && "not a zero vector"); |
| 56 | + |
| 57 | + return JJ; |
| 58 | +} |
| 59 | + |
| 60 | +} // namespace Matfun |
| 61 | + |
| 62 | +#endif // KERNEL_H |
0 commit comments