Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Toolbox/FiniteProjectiveCamera.h @ 1653:2e3b2ed239b9
Fixed usage of object cookie
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 16 Nov 2020 22:17:01 +0100 |
parents | 8563ea5d8ae4 |
children | 9ac2a65d4172 |
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 | |
1270
2d8ab34c8c91
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
742
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
161 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
161 | 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 | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
15 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
16 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
18 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
161 | 20 **/ |
21 | |
22 | |
23 #pragma once | |
24 | |
25 #include "LinearAlgebra.h" | |
192
371da7fe2c0e
FiniteProjectiveCamera::ApplyRaytracer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
188
diff
changeset
|
26 #include "../Volumes/ImageBuffer3D.h" |
742
fa5febe0f0c2
moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
27 #include "../Volumes/VolumeImageGeometry.h" |
161 | 28 |
29 namespace OrthancStone | |
30 { | |
31 // Reference: "Multiple View Geometry in Computer Vision (2nd Edition)" | |
32 class FiniteProjectiveCamera : public boost::noncopyable | |
33 { | |
34 private: | |
35 Matrix p_; // 3x4 matrix - Equation (6.11) - page 157 | |
36 Matrix k_; // 3x3 matrix of intrinsic parameters - Equation (6.10) - page 157 | |
37 Matrix r_; // 3x3 rotation matrix in 3D space | |
38 Vector c_; // 3x1 vector in 3D space corresponding to camera center | |
39 Matrix minv_; // Inverse of the M = P(1:3,1:3) submatrix | |
40 | |
41 void ComputeMInverse(); | |
42 | |
43 void Setup(const Matrix& k, | |
44 const Matrix& r, | |
45 const Vector& c); | |
46 | |
47 void Setup(const Matrix& p); | |
48 | |
49 public: | |
50 FiniteProjectiveCamera(const Matrix& k, | |
51 const Matrix& r, | |
52 const Vector& c) | |
53 { | |
54 Setup(k, r, c); | |
55 } | |
56 | |
1571 | 57 explicit FiniteProjectiveCamera(const Matrix& p) |
161 | 58 { |
59 Setup(p); | |
60 } | |
61 | |
62 FiniteProjectiveCamera(const double k[9], | |
63 const double r[9], | |
64 const double c[3]); | |
65 | |
1571 | 66 explicit FiniteProjectiveCamera(const double p[12]); |
161 | 67 |
188
45b03b04a777
calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
161
diff
changeset
|
68 // Constructor that implements camera calibration |
45b03b04a777
calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
161
diff
changeset
|
69 FiniteProjectiveCamera(const Vector& camera, |
45b03b04a777
calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
161
diff
changeset
|
70 const Vector& principalPoint, |
45b03b04a777
calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
161
diff
changeset
|
71 double angle, |
45b03b04a777
calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
161
diff
changeset
|
72 unsigned int imageWidth, |
45b03b04a777
calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
161
diff
changeset
|
73 unsigned int imageHeight, |
45b03b04a777
calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
161
diff
changeset
|
74 double pixelSpacingX, |
45b03b04a777
calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
161
diff
changeset
|
75 double pixelSpacingY); |
45b03b04a777
calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
161
diff
changeset
|
76 |
161 | 77 const Matrix& GetMatrix() const |
78 { | |
79 return p_; | |
80 } | |
81 | |
82 const Matrix& GetRotation() const | |
83 { | |
84 return r_; | |
85 } | |
86 | |
87 const Vector& GetCenter() const | |
88 { | |
89 return c_; | |
90 } | |
91 | |
92 const Matrix& GetIntrinsicParameters() const | |
93 { | |
94 return k_; | |
95 } | |
96 | |
97 // Computes the 3D vector that represents the direction from the | |
98 // camera center to the (x,y) imaged point | |
99 Vector GetRayDirection(double x, | |
100 double y) const; | |
101 | |
102 // Apply the camera to a 3D point "v" that is not at infinity. "v" | |
103 // can be encoded either as a non-homogeneous vector (3 | |
104 // components), or as a homogeneous vector (4 components). | |
105 void ApplyFinite(double& x, | |
106 double& y, | |
107 const Vector& v) const; | |
108 | |
109 // Apply the camera to a 3D point "v" that is possibly at | |
110 // infinity. The result is a 2D point in homogeneous coordinates. | |
111 Vector ApplyGeneral(const Vector& v) const; | |
192
371da7fe2c0e
FiniteProjectiveCamera::ApplyRaytracer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
188
diff
changeset
|
112 |
371da7fe2c0e
FiniteProjectiveCamera::ApplyRaytracer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
188
diff
changeset
|
113 Orthanc::ImageAccessor* ApplyRaytracer(const ImageBuffer3D& source, |
735
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
114 const VolumeImageGeometry& geometry, |
192
371da7fe2c0e
FiniteProjectiveCamera::ApplyRaytracer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
188
diff
changeset
|
115 Orthanc::PixelFormat targetFormat, |
371da7fe2c0e
FiniteProjectiveCamera::ApplyRaytracer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
188
diff
changeset
|
116 unsigned int targetWidth, |
371da7fe2c0e
FiniteProjectiveCamera::ApplyRaytracer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
188
diff
changeset
|
117 unsigned int targetHeight, |
371da7fe2c0e
FiniteProjectiveCamera::ApplyRaytracer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
188
diff
changeset
|
118 bool mip) const; |
161 | 119 }; |
120 } |