Blender V4.3
dogleg_test.cc
Go to the documentation of this file.
1// Copyright (c) 2009 libmv authors.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to
5// deal in the Software without restriction, including without limitation the
6// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7// sell copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19// IN THE SOFTWARE.
20
22#include "testing/testing.h"
23
24using namespace libmv;
25
26namespace {
27
28class F {
29 public:
30 typedef Vec4 FMatrixType;
31 typedef Vec3 XMatrixType;
32 Vec4 operator()(const Vec3& x) const {
33 double x1 = x.x() - 2;
34 double y1 = x.y() - 5;
35 double z1 = x.z();
36 Vec4 fx;
37 fx << x1 * x1 + z1 * z1, y1 * y1 + z1 * z1, z1 * z1, x1 * x1;
38 return fx;
39 }
40};
41
42TEST(Dogleg, SimpleCase) {
43 Vec3 x;
44 x << 0.76026643, -30.01799744, 0.55192142;
45 F f;
47 Dogleg<F> lm(f);
48 /* TODO(sergey): Better error handling. */
49 /* Dogleg<F>::Results results = */ lm.minimize(params, &x);
50 Vec3 expected_min_x;
51 expected_min_x << 2, 5, 0;
52
53 EXPECT_MATRIX_NEAR(expected_min_x, x, 1e-5);
54}
55
56// Example 3.2 from [1]; page 11 of the pdf, 20 of the document. This is a
57// tricky problem because of the singluar Jacobian near the origin.
58class F32 {
59 public:
60 typedef Vec2 FMatrixType;
61 typedef Vec2 XMatrixType;
62 Vec2 operator()(const Vec2& x) const {
63 double x1 = x(0);
64 double x2 = 10 * x(0) / (x(0) + 0.1) + 2 * x(1) * x(1);
65 Vec2 fx;
66 fx << x1, x2;
67 return fx;
68 }
69};
70
71class JF32 {
72 public:
73 JF32(const F32& f) { (void)f; }
74 Mat2 operator()(const Vec2& x) {
75 Mat2 J;
76 J << 1, 0, 1. / pow(x(0) + 0.1, 2), 4 * x(1) * x(1);
77 return J;
78 }
79};
80
81// TODO(keir): Re-enable this when the dogleg code properly handles singular
82// normal equations.
83/*
84TEST(Dogleg, Example32) {
85 Vec2 x; x << 3, 1;
86 F32 f;
87 CheckJacobian<F32, JF32>(f, x);
88 Dogleg<F32, JF32> dogleg(f);
89 Dogleg<F32, JF32>::Results results = dogleg.minimize(&x);
90 Vec2 expected_min_x; expected_min_x << 0, 0;
91
92 EXPECT_MATRIX_NEAR(expected_min_x, x, 1e-5);
93}
94*/
95
96} // namespace
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
SIMD_FORCE_INLINE btVector3 operator()(const btVector3 &x) const
Return the transform of the vector.
Definition btTransform.h:90
pow(value.r - subtrahend, 2.0)") .do_static_compilation(true)
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
Eigen::Vector4d Vec4
Definition numeric.h:107
Eigen::Vector2d Vec2
Definition numeric.h:105
TEST(PolynomialCameraIntrinsics2, ApplyOnFocalCenter)
Eigen::Vector3d Vec3
Definition numeric.h:106
Eigen::Matrix< double, 2, 2 > Mat2
Definition numeric.h:70