Skip to content

Commit 4e40205

Browse files
committed
method null revised and moved to new file kernel.h
1 parent d7089f1 commit 4e40205

File tree

6 files changed

+73
-31
lines changed

6 files changed

+73
-31
lines changed

src/adjustment.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "constraints.h"
2222
#include "geometry/minrot.h"
2323
#include "global.h"
24+
#include "kernel.h"
2425
#include "matfun.h"
2526
#include "matrix.h"
2627

@@ -54,6 +55,7 @@ using Eigen::Vector3d;
5455
using Eigen::MatrixXd;
5556
using Eigen::Matrix3d;
5657
using Eigen::SparseMatrix;
58+
using Eigen::Matrix;
5759

5860
using Geometry::Rot_ab;
5961

@@ -92,7 +94,8 @@ void AdjustmentFramework::update( const VectorXd &x)
9294
// m.segment(idx3,3).normalize();
9395

9496
// (2) via retraction ......................................................
95-
const Vector3d v = null( l0_.segment(idx3, 3) ) * x.segment(2 * s, 2);
97+
const Vector3d l0 = l0_.segment(idx3,3);
98+
const Vector3d v = null( l0 ) * x.segment(2 * s, 2);
9699
const double nv = v.norm();
97100
if ( nv > T_zero ) {
98101
const Vector3d p = l0_.segment(idx3, 3);
@@ -235,7 +238,8 @@ void AdjustmentFramework::reduce (
235238
const Index offset3 = 3 * s;
236239
const Index offset2 = 2 * s;
237240

238-
const Eigen::Matrix<double, 3, 2> NN = null( l0_.segment(offset3, 3) );
241+
const Vector3d l0 = l0_.segment(offset3,3);
242+
const Matrix<double, 3, 2> NN = null( l0 );
239243

240244
// (i) reduced coordinates of observations
241245
lr.segment(offset2,2) = NN.adjoint() * l_.segment(offset3,3);

src/constraints.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626

2727
#include "geometry/minrot.h"
2828
#include "geometry/skew.h"
29+
#include "kernel.h"
2930
#include "matfun.h"
3031

32+
3133
using Geometry::skew;
3234
using Geometry::Rot_ab;
3335

src/greasepad.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ HEADERS += \
5858
geometry/minrot.h \
5959
geometry/skew.h \
6060
global.h \
61+
kernel.h \
6162
mainwindow.h \
6263
mainscene.h \
6364
mainview.h \

src/kernel.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

src/matfun.h

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
#include <algorithm>
2929
#include <cassert>
30-
#include <cmath>
3130

3231

3332
namespace Matfun {
@@ -39,35 +38,9 @@ using Eigen::SparseMatrix;
3938
using Eigen::SparseVector;
4039
using Eigen::Matrix3d;
4140
using Eigen::Index;
41+
using Eigen::Matrix;
4242
using Eigen::Vector;
4343
using Eigen::Dynamic;
44-
using Eigen::placeholders::last;
45-
46-
47-
//! Nullspace of row vector
48-
[[nodiscard,maybe_unused]] static MatrixXd null( const VectorXd & xs )
49-
{
50-
// cf. PCV, eq. (A.120)
51-
constexpr double T_zero = 1e-6;
52-
assert( std::fabs( xs.norm()-1. ) < T_zero && "vector norm not 1");
53-
54-
const Index N = xs.size();
55-
VectorXd x0 = xs.head(N-1);
56-
double xN = xs(last);
57-
if ( xN < 0.0 ) {
58-
x0 = -x0;
59-
xN = -xN;
60-
}
61-
62-
const MatrixXd JJ = ( MatrixXd(N,N-1)
63-
<< MatrixXd::Identity(N-1,N-1) -x0*x0.adjoint()/(1.+xN),
64-
-x0.adjoint() ).finished();
65-
66-
const VectorXd check = JJ.adjoint()*xs;
67-
assert( check.norm() < T_zero && "not a zero vector");
68-
69-
return JJ;
70-
}
7144

7245

7346
//! check if the matrix AA is rank-deficient

src/uncertain/uncertain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
1818

19-
19+
#include "kernel.h"
2020
#include "matfun.h"
2121
#include "uncertain.h"
2222

0 commit comments

Comments
 (0)