Mercurial > hg > orthanc-stone
annotate Framework/Toolbox/LinearAlgebra.h @ 159:0a73d76333db wasm
populating LinearAlgebra
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 14 Feb 2018 09:15:08 +0100 |
parents | a053ca7fa5c6 |
children | 197a5ddaf68c |
rev | line source |
---|---|
158 | 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 // Patch for ublas in Boost 1.64.0 | |
25 // https://github.com/dealii/dealii/issues/4302 | |
26 #include <boost/version.hpp> | |
27 #if BOOST_VERSION >= 106300 // or 64, need to check | |
28 # include <boost/serialization/array_wrapper.hpp> | |
29 #endif | |
30 | |
31 #include <Core/DicomFormat/DicomMap.h> | |
32 | |
33 #include <boost/numeric/ublas/matrix.hpp> | |
34 #include <boost/numeric/ublas/vector.hpp> | |
35 | |
36 namespace OrthancStone | |
37 { | |
38 typedef boost::numeric::ublas::matrix<double> Matrix; | |
39 typedef boost::numeric::ublas::vector<double> Vector; | |
40 | |
41 namespace LinearAlgebra | |
42 { | |
43 void Print(const Vector& v); | |
44 | |
45 void Print(const Matrix& m); | |
46 | |
47 bool ParseVector(Vector& target, | |
48 const std::string& s); | |
49 | |
50 bool ParseVector(Vector& target, | |
51 const Orthanc::DicomMap& dataset, | |
52 const Orthanc::DicomTag& tag); | |
53 | |
54 void AssignVector(Vector& v, | |
55 double v1, | |
56 double v2); | |
57 | |
58 void AssignVector(Vector& v, | |
59 double v1, | |
60 double v2, | |
61 double v3); | |
62 | |
63 inline bool IsNear(double x, | |
64 double y, | |
65 double threshold) | |
66 { | |
67 return fabs(x - y) < threshold; | |
68 } | |
69 | |
70 bool IsNear(double x, | |
71 double y); | |
72 | |
73 inline bool IsCloseToZero(double x) | |
74 { | |
75 return IsNear(x, 0.0); | |
76 } | |
77 | |
78 void NormalizeVector(Vector& u); | |
79 | |
80 void CrossProduct(Vector& result, | |
81 const Vector& u, | |
82 const Vector& v); | |
83 | |
84 void FillMatrix(Matrix& target, | |
85 size_t rows, | |
86 size_t columns, | |
87 const double values[]); | |
88 | |
89 void FillVector(Vector& target, | |
90 size_t size, | |
91 const double values[]); | |
92 | |
93 void Convert(Matrix& target, | |
94 const Vector& source); | |
159
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
95 |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
96 double ComputeDeterminant(const Matrix& a); |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
97 |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
98 bool IsOrthogonalMatrix(const Matrix& q, |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
99 double threshold); |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
100 |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
101 bool IsOrthogonalMatrix(const Matrix& q); |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
102 |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
103 bool IsRotationMatrix(const Matrix& r, |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
104 double threshold); |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
105 |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
106 bool IsRotationMatrix(const Matrix& r); |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
107 |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
108 void InvertUpperTriangularMatrix(Matrix& output, |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
109 const Matrix& k); |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
110 |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
111 /** |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
112 * This function computes the RQ decomposition of a 3x3 matrix, |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
113 * using Givens rotations. Reference: Algorithm A4.1 (page 579) of |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
114 * "Multiple View Geometry in Computer Vision" (2nd edition). The |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
115 * output matrix "Q" is a rotation matrix, and "R" is upper |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
116 * triangular. |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
117 **/ |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
118 void RQDecomposition3x3(Matrix& r, |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
119 Matrix& q, |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
120 const Matrix& a); |
158 | 121 }; |
122 } |