Skip to content

Commit fde8266

Browse files
author
Fabien Servant
committed
Cleaning intrinsicBase
1 parent 44add21 commit fde8266

File tree

3 files changed

+94
-77
lines changed

3 files changed

+94
-77
lines changed

src/aliceVision/calibration/distortionEstimationGeometry.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "distortionEstimationGeometry.hpp"
88

99
#include <aliceVision/system/Logger.hpp>
10+
#include <aliceVision/numeric/algebra.hpp>
1011
#include <aliceVision/sfm/bundle/manifolds/so3.hpp>
1112
#include <ceres/ceres.h>
1213
#include <cmath>

src/aliceVision/camera/IntrinsicBase.hpp

Lines changed: 16 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,12 @@ class IntrinsicBase
434434
*/
435435
virtual double getVerticalFov() const = 0;
436436

437+
/**
438+
* @brief Initialize state with default values
439+
* The estimator state is used in the bundle adjustment to decide if we update it.
440+
* It is set to constant if the intrinsic is locked
441+
* It is set to refined if unlocked
442+
*/
437443
virtual void initializeState()
438444
{
439445
if (_locked)
@@ -445,9 +451,17 @@ class IntrinsicBase
445451
_state = EEstimatorParameterState::REFINED;
446452
}
447453
}
448-
454+
455+
/**
456+
* @brief accessor to estimator state
457+
* @return a state
458+
*/
449459
EEstimatorParameterState getState() const { return _state; }
450460

461+
/**
462+
* @brief mutator for the estimator state
463+
* @param state the new state of the intrinsic
464+
*/
451465
void setState(EEstimatorParameterState state) { _state = state; }
452466

453467
protected:
@@ -456,6 +470,7 @@ class IntrinsicBase
456470
/// intrinsic lock
457471
bool _locked = false;
458472
EEstimatorParameterState _state = EEstimatorParameterState::REFINED;
473+
459474
unsigned int _w = 0;
460475
unsigned int _h = 0;
461476
double _sensorWidth = 36.0;
@@ -531,81 +546,5 @@ inline double angleBetweenRays(const geometry::Pose3& pose1, const geometry::Pos
531546

532547
} // namespace camera
533548

534-
template<size_t M, size_t N>
535-
Eigen::Matrix<double, M * N, M * N> getJacobian_At_wrt_A()
536-
{
537-
Eigen::Matrix<double, M * N, M * N> ret;
538-
539-
/** vec(M1*M2*M3) = kron(M3.t, M1) * vec(M2) */
540-
/** vec(IAtB) = kron(B.t, I) * vec(A) */
541-
/** dvec(IAtB)/dA = kron(B.t, I) * dvec(At)/dA */
542-
543-
ret.fill(0);
544-
545-
size_t pos_at = 0;
546-
for (size_t i = 0; i < M; i++)
547-
{
548-
for (size_t j = 0; j < N; j++)
549-
{
550-
size_t pos_a = N * j + i;
551-
ret(pos_at, pos_a) = 1;
552-
553-
pos_at++;
554-
}
555-
}
556-
557-
return ret;
558-
}
559-
560-
template<size_t M, size_t N, size_t K>
561-
Eigen::Matrix<double, M * K, M * N> getJacobian_AB_wrt_A(const Eigen::Matrix<double, M, N>& A, const Eigen::Matrix<double, N, K>& B)
562-
{
563-
Eigen::Matrix<double, M * K, M * N> ret;
564-
565-
/** vec(M1*M2*M3) = kron(M3.t, M1) * vec(M2) */
566-
/** vec(IAB) = kron(B.t, I) * vec(A) */
567-
/** dvec(IAB)/dA = kron(B.t, I) * dvec(A)/dA */
568-
/** dvec(IAB)/dA = kron(B.t, I) */
569-
570-
ret.fill(0);
571-
572-
Eigen::Matrix<double, K, N> Bt = B.transpose();
573-
574-
for (size_t row = 0; row < K; row++)
575-
{
576-
for (size_t col = 0; col < N; col++)
577-
{
578-
ret.template block<M, M>(row * M, col * M) = Bt(row, col) * Eigen::Matrix<double, M, M>::Identity();
579-
}
580-
}
581-
582-
return ret;
583-
}
584-
585-
template<size_t M, size_t N, size_t K>
586-
Eigen::Matrix<double, M * K, M * N> getJacobian_AtB_wrt_A(const Eigen::Matrix<double, M, N>& A, const Eigen::Matrix<double, M, K>& B)
587-
{
588-
return getJacobian_AB_wrt_A<M, N, K>(A.transpose(), B) * getJacobian_At_wrt_A<M, N>();
589-
}
590-
591-
template<size_t M, size_t N, size_t K>
592-
Eigen::Matrix<double, M * K, N * K> getJacobian_AB_wrt_B(const Eigen::Matrix<double, M, N>& A, const Eigen::Matrix<double, N, K>& B)
593-
{
594-
Eigen::Matrix<double, M * K, N * K> ret;
595-
596-
/** vec(M1*M2*M3) = kron(M3.t, M1) * vec(M2) */
597-
/** vec(ABI) = kron(I, A) * vec(B) */
598-
/** dvec(ABI)/dB = kron(I, A) * dvec(B)/dB */
599-
/** dvec(ABI)/dB = kron(I, A) */
600-
601-
ret.fill(0);
602-
603-
for (size_t index = 0; index < K; index++)
604-
{
605-
ret.template block<M, N>(M * index, N * index) = A;
606-
}
607-
608-
return ret;
609-
}
610549

611550
} // namespace aliceVision

src/aliceVision/numeric/algebra.hpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,81 @@ inline double Nullspace2(const TMat& A, TVec1& x1, TVec2& x2)
8080
return vec(vec.rows() - 1);
8181
}
8282

83+
template<size_t M, size_t N>
84+
Eigen::Matrix<double, M * N, M * N> getJacobian_At_wrt_A()
85+
{
86+
Eigen::Matrix<double, M * N, M * N> ret;
87+
88+
/** vec(M1*M2*M3) = kron(M3.t, M1) * vec(M2) */
89+
/** vec(IAtB) = kron(B.t, I) * vec(A) */
90+
/** dvec(IAtB)/dA = kron(B.t, I) * dvec(At)/dA */
91+
92+
ret.fill(0);
93+
94+
size_t pos_at = 0;
95+
for (size_t i = 0; i < M; i++)
96+
{
97+
for (size_t j = 0; j < N; j++)
98+
{
99+
size_t pos_a = N * j + i;
100+
ret(pos_at, pos_a) = 1;
101+
102+
pos_at++;
103+
}
104+
}
105+
106+
return ret;
107+
}
108+
109+
template<size_t M, size_t N, size_t K>
110+
Eigen::Matrix<double, M * K, M * N> getJacobian_AB_wrt_A(const Eigen::Matrix<double, M, N>& A, const Eigen::Matrix<double, N, K>& B)
111+
{
112+
Eigen::Matrix<double, M * K, M * N> ret;
113+
114+
/** vec(M1*M2*M3) = kron(M3.t, M1) * vec(M2) */
115+
/** vec(IAB) = kron(B.t, I) * vec(A) */
116+
/** dvec(IAB)/dA = kron(B.t, I) * dvec(A)/dA */
117+
/** dvec(IAB)/dA = kron(B.t, I) */
118+
119+
ret.fill(0);
120+
121+
Eigen::Matrix<double, K, N> Bt = B.transpose();
122+
123+
for (size_t row = 0; row < K; row++)
124+
{
125+
for (size_t col = 0; col < N; col++)
126+
{
127+
ret.template block<M, M>(row * M, col * M) = Bt(row, col) * Eigen::Matrix<double, M, M>::Identity();
128+
}
129+
}
130+
131+
return ret;
132+
}
133+
134+
template<size_t M, size_t N, size_t K>
135+
Eigen::Matrix<double, M * K, M * N> getJacobian_AtB_wrt_A(const Eigen::Matrix<double, M, N>& A, const Eigen::Matrix<double, M, K>& B)
136+
{
137+
return getJacobian_AB_wrt_A<M, N, K>(A.transpose(), B) * getJacobian_At_wrt_A<M, N>();
138+
}
139+
140+
template<size_t M, size_t N, size_t K>
141+
Eigen::Matrix<double, M * K, N * K> getJacobian_AB_wrt_B(const Eigen::Matrix<double, M, N>& A, const Eigen::Matrix<double, N, K>& B)
142+
{
143+
Eigen::Matrix<double, M * K, N * K> ret;
144+
145+
/** vec(M1*M2*M3) = kron(M3.t, M1) * vec(M2) */
146+
/** vec(ABI) = kron(I, A) * vec(B) */
147+
/** dvec(ABI)/dB = kron(I, A) * dvec(B)/dB */
148+
/** dvec(ABI)/dB = kron(I, A) */
149+
150+
ret.fill(0);
151+
152+
for (size_t index = 0; index < K; index++)
153+
{
154+
ret.template block<M, N>(M * index, N * index) = A;
155+
}
156+
157+
return ret;
158+
}
159+
83160
} // namespace aliceVision

0 commit comments

Comments
 (0)