annotate Framework/Toolbox/FiniteProjectiveCamera.h @ 169:7105e51e4907 wasm

InvertMatrixUnsafe
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 02 Mar 2018 12:35:27 +0100
parents 197a5ddaf68c
children 45b03b04a777
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
161
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #pragma once
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "LinearAlgebra.h"
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 namespace OrthancStone
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 {
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 // Reference: "Multiple View Geometry in Computer Vision (2nd Edition)"
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 class FiniteProjectiveCamera : public boost::noncopyable
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 {
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 private:
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 Matrix p_; // 3x4 matrix - Equation (6.11) - page 157
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 Matrix k_; // 3x3 matrix of intrinsic parameters - Equation (6.10) - page 157
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 Matrix r_; // 3x3 rotation matrix in 3D space
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 Vector c_; // 3x1 vector in 3D space corresponding to camera center
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 Matrix minv_; // Inverse of the M = P(1:3,1:3) submatrix
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 void ComputeMInverse();
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 void Setup(const Matrix& k,
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 const Matrix& r,
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 const Vector& c);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 void Setup(const Matrix& p);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 public:
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 FiniteProjectiveCamera(const Matrix& k,
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 const Matrix& r,
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 const Vector& c)
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 Setup(k, r, c);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 }
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 FiniteProjectiveCamera(const Matrix& p)
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 Setup(p);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 }
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 FiniteProjectiveCamera(const double k[9],
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 const double r[9],
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 const double c[3]);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 FiniteProjectiveCamera(const double p[12]);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 const Matrix& GetMatrix() const
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 return p_;
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 const Matrix& GetRotation() const
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 return r_;
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 }
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 const Vector& GetCenter() const
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 {
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 return c_;
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 const Matrix& GetIntrinsicParameters() const
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 return k_;
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 }
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 // Computes the 3D vector that represents the direction from the
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 // camera center to the (x,y) imaged point
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 Vector GetRayDirection(double x,
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 double y) const;
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 // Apply the camera to a 3D point "v" that is not at infinity. "v"
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 // can be encoded either as a non-homogeneous vector (3
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 // components), or as a homogeneous vector (4 components).
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 void ApplyFinite(double& x,
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 double& y,
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 const Vector& v) const;
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 // Apply the camera to a 3D point "v" that is possibly at
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 // infinity. The result is a 2D point in homogeneous coordinates.
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 Vector ApplyGeneral(const Vector& v) const;
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 };
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 }