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