Mercurial > hg > orthanc-stone
annotate Framework/Toolbox/FiniteProjectiveCamera.h @ 1229:b9f2a111c5b9 broker
fix compilation of WebAssemblyOracle
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 09 Dec 2019 14:41:37 +0100 |
parents | fa5febe0f0c2 |
children | 2d8ab34c8c91 |
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 | |
439 | 5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
161 | 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" |
742
fa5febe0f0c2
moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
26 #include "../Volumes/VolumeImageGeometry.h" |
161 | 27 |
28 namespace OrthancStone | |
29 { | |
30 // Reference: "Multiple View Geometry in Computer Vision (2nd Edition)" | |
31 class FiniteProjectiveCamera : public boost::noncopyable | |
32 { | |
33 private: | |
34 Matrix p_; // 3x4 matrix - Equation (6.11) - page 157 | |
35 Matrix k_; // 3x3 matrix of intrinsic parameters - Equation (6.10) - page 157 | |
36 Matrix r_; // 3x3 rotation matrix in 3D space | |
37 Vector c_; // 3x1 vector in 3D space corresponding to camera center | |
38 Matrix minv_; // Inverse of the M = P(1:3,1:3) submatrix | |
39 | |
40 void ComputeMInverse(); | |
41 | |
42 void Setup(const Matrix& k, | |
43 const Matrix& r, | |
44 const Vector& c); | |
45 | |
46 void Setup(const Matrix& p); | |
47 | |
48 public: | |
49 FiniteProjectiveCamera(const Matrix& k, | |
50 const Matrix& r, | |
51 const Vector& c) | |
52 { | |
53 Setup(k, r, c); | |
54 } | |
55 | |
56 FiniteProjectiveCamera(const Matrix& p) | |
57 { | |
58 Setup(p); | |
59 } | |
60 | |
61 FiniteProjectiveCamera(const double k[9], | |
62 const double r[9], | |
63 const double c[3]); | |
64 | |
65 FiniteProjectiveCamera(const double p[12]); | |
66 | |
188
45b03b04a777
calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
161
diff
changeset
|
67 // Constructor that implements camera calibration |
45b03b04a777
calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
161
diff
changeset
|
68 FiniteProjectiveCamera(const Vector& camera, |
45b03b04a777
calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
161
diff
changeset
|
69 const Vector& principalPoint, |
45b03b04a777
calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
161
diff
changeset
|
70 double angle, |
45b03b04a777
calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
161
diff
changeset
|
71 unsigned int imageWidth, |
45b03b04a777
calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
161
diff
changeset
|
72 unsigned int imageHeight, |
45b03b04a777
calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
161
diff
changeset
|
73 double pixelSpacingX, |
45b03b04a777
calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
161
diff
changeset
|
74 double pixelSpacingY); |
45b03b04a777
calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
161
diff
changeset
|
75 |
161 | 76 const Matrix& GetMatrix() const |
77 { | |
78 return p_; | |
79 } | |
80 | |
81 const Matrix& GetRotation() const | |
82 { | |
83 return r_; | |
84 } | |
85 | |
86 const Vector& GetCenter() const | |
87 { | |
88 return c_; | |
89 } | |
90 | |
91 const Matrix& GetIntrinsicParameters() const | |
92 { | |
93 return k_; | |
94 } | |
95 | |
96 // Computes the 3D vector that represents the direction from the | |
97 // camera center to the (x,y) imaged point | |
98 Vector GetRayDirection(double x, | |
99 double y) const; | |
100 | |
101 // Apply the camera to a 3D point "v" that is not at infinity. "v" | |
102 // can be encoded either as a non-homogeneous vector (3 | |
103 // components), or as a homogeneous vector (4 components). | |
104 void ApplyFinite(double& x, | |
105 double& y, | |
106 const Vector& v) const; | |
107 | |
108 // Apply the camera to a 3D point "v" that is possibly at | |
109 // infinity. The result is a 2D point in homogeneous coordinates. | |
110 Vector ApplyGeneral(const Vector& v) const; | |
192
371da7fe2c0e
FiniteProjectiveCamera::ApplyRaytracer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
188
diff
changeset
|
111 |
371da7fe2c0e
FiniteProjectiveCamera::ApplyRaytracer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
188
diff
changeset
|
112 Orthanc::ImageAccessor* ApplyRaytracer(const ImageBuffer3D& source, |
735
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
113 const VolumeImageGeometry& geometry, |
192
371da7fe2c0e
FiniteProjectiveCamera::ApplyRaytracer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
188
diff
changeset
|
114 Orthanc::PixelFormat targetFormat, |
371da7fe2c0e
FiniteProjectiveCamera::ApplyRaytracer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
188
diff
changeset
|
115 unsigned int targetWidth, |
371da7fe2c0e
FiniteProjectiveCamera::ApplyRaytracer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
188
diff
changeset
|
116 unsigned int targetHeight, |
371da7fe2c0e
FiniteProjectiveCamera::ApplyRaytracer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
188
diff
changeset
|
117 bool mip) const; |
161 | 118 }; |
119 } |