annotate Framework/Toolbox/LinearAlgebra.cpp @ 984:35ed6812d639 toa2019090602

Build fix
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 06 Sep 2019 11:46:51 +0200
parents 32eaf4929b08
children 1f74bc3459ba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
439
b70e9be013e4 preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 392
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "LinearAlgebra.h"
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
949
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
24 #include "../StoneException.h"
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
25
212
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
26 #include <Core/Logging.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
27 #include <Core/OrthancException.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
28 #include <Core/Toolbox.h>
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
804
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
30 #include <boost/lexical_cast.hpp>
164
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
31 #include <boost/numeric/ublas/lu.hpp>
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
949
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
33 #include <stdio.h>
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
34 #include <iostream>
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
35
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 namespace OrthancStone
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 namespace LinearAlgebra
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 void Print(const Vector& v)
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 for (size_t i = 0; i < v.size(); i++)
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 printf("%g\n", v[i]);
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 //printf("%8.2f\n", v[i]);
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 }
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 printf("\n");
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 }
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 void Print(const Matrix& m)
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 for (size_t i = 0; i < m.size1(); i++)
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 for (size_t j = 0; j < m.size2(); j++)
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 printf("%g ", m(i,j));
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 //printf("%8.2f ", m(i,j));
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 printf("\n");
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 }
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 printf("\n");
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 bool ParseVector(Vector& target,
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 const std::string& value)
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 std::vector<std::string> items;
786
5aa728500586 optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
70 Orthanc::Toolbox::TokenizeString(items, Orthanc::Toolbox::StripSpaces(value), '\\');
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 target.resize(items.size());
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 for (size_t i = 0; i < items.size(); i++)
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
804
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
76 /**
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
77 * We try and avoid the use of "boost::lexical_cast<>" here,
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
78 * as it is very slow. As we are parsing many doubles, we
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
79 * prefer to use the standard "std::stod" function if
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
80 * available: http://www.cplusplus.com/reference/string/stod/
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
81 **/
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
82
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
83 #if __cplusplus >= 201103L // Is C++11 enabled?
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 try
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
790
9f68155c75b0 speeding up LinearAlgebra::ParseVector()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
86 target[i] = std::stod(items[i]);
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
790
9f68155c75b0 speeding up LinearAlgebra::ParseVector()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
88 catch (std::exception&)
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 target.clear();
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 return false;
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 }
804
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
93 #else // Fallback implementation using Boost
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
94 try
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
95 {
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
96 target[i] = boost::lexical_cast<double>(items[i]);
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
97 }
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
98 catch (boost::bad_lexical_cast&)
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
99 {
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
100 target.clear();
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
101 return false;
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
102 }
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
103 #endif
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 }
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 return true;
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 }
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 bool ParseVector(Vector& target,
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 const Orthanc::DicomMap& dataset,
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 const Orthanc::DicomTag& tag)
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 std::string value;
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 return (dataset.CopyToString(value, tag, false) &&
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 ParseVector(target, value));
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 void NormalizeVector(Vector& u)
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 double norm = boost::numeric::ublas::norm_2(u);
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 if (!IsCloseToZero(norm))
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 u = u / norm;
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 }
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 }
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 void CrossProduct(Vector& result,
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 const Vector& u,
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 const Vector& v)
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 {
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 if (u.size() != 3 ||
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 v.size() != 3)
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 {
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 }
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 result.resize(3);
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 result[0] = u[1] * v[2] - u[2] * v[1];
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 result[1] = u[2] * v[0] - u[0] * v[2];
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 result[2] = u[0] * v[1] - u[1] * v[0];
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 }
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 void FillMatrix(Matrix& target,
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 size_t rows,
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 size_t columns,
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 const double values[])
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 {
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 target.resize(rows, columns);
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 size_t index = 0;
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 for (size_t y = 0; y < rows; y++)
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 {
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 for (size_t x = 0; x < columns; x++, index++)
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 {
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 target(y, x) = values[index];
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 }
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 }
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 void FillVector(Vector& target,
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 size_t size,
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 const double values[])
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 {
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 target.resize(size);
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 for (size_t i = 0; i < size; i++)
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 {
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 target[i] = values[i];
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 }
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 }
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 void Convert(Matrix& target,
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 const Vector& source)
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 {
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 const size_t n = source.size();
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 target.resize(n, 1);
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 for (size_t i = 0; i < n; i++)
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 {
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 target(i, 0) = source[i];
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 }
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 }
159
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
192
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
193
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
194 double ComputeDeterminant(const Matrix& a)
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
195 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
196 if (a.size1() != a.size2())
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
197 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
198 LOG(ERROR) << "Determinant only exists for square matrices";
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
199 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
200 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
201
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
202 // https://en.wikipedia.org/wiki/Rule_of_Sarrus
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
203 if (a.size1() == 1)
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
204 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
205 return a(0,0);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
206 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
207 else if (a.size1() == 2)
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
208 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
209 return a(0,0) * a(1,1) - a(0,1) * a(1,0);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
210 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
211 else if (a.size1() == 3)
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
212 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
213 return (a(0,0) * a(1,1) * a(2,2) +
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
214 a(0,1) * a(1,2) * a(2,0) +
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
215 a(0,2) * a(1,0) * a(2,1) -
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
216 a(2,0) * a(1,1) * a(0,2) -
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
217 a(2,1) * a(1,2) * a(0,0) -
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
218 a(2,2) * a(1,0) * a(0,1));
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
219 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
220 else
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
221 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
222 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
223 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
224 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
225
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
226
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
227 bool IsOrthogonalMatrix(const Matrix& q,
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
228 double threshold)
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
229 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
230 // https://en.wikipedia.org/wiki/Orthogonal_matrix
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
231
392
d87fe075d31b to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
232 if (q.size1() != q.size2())
d87fe075d31b to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
233 {
d87fe075d31b to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
234 LOG(ERROR) << "An orthogonal matrix must be squared";
d87fe075d31b to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
235 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
d87fe075d31b to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
236 }
d87fe075d31b to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
237
159
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
238 using namespace boost::numeric::ublas;
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
239
392
d87fe075d31b to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
240 const Matrix check = prod(trans(q), q) - identity_matrix<double>(q.size1());
159
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
241
160
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 159
diff changeset
242 type_traits<double>::real_type norm = norm_inf(check);
159
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
243
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
244 return (norm <= threshold);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
245 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
246
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
247
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
248 bool IsOrthogonalMatrix(const Matrix& q)
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
249 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
250 return IsOrthogonalMatrix(q, 10.0 * std::numeric_limits<float>::epsilon());
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
251 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
252
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
253
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
254 bool IsRotationMatrix(const Matrix& r,
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
255 double threshold)
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
256 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
257 return (IsOrthogonalMatrix(r, threshold) &&
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
258 IsNear(ComputeDeterminant(r), 1.0, threshold));
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
259 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
260
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
261
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
262 bool IsRotationMatrix(const Matrix& r)
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
263 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
264 return IsRotationMatrix(r, 10.0 * std::numeric_limits<float>::epsilon());
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
265 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
266
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
267
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
268 void InvertUpperTriangularMatrix(Matrix& output,
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
269 const Matrix& k)
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
270 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
271 if (k.size1() != k.size2())
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
272 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
273 LOG(ERROR) << "Determinant only exists for square matrices";
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
274 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
275 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
276
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
277 output.resize(k.size1(), k.size2());
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
278
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
279 for (size_t i = 1; i < k.size1(); i++)
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
280 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
281 for (size_t j = 0; j < i; j++)
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
282 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
283 if (!IsCloseToZero(k(i, j)))
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
284 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
285 LOG(ERROR) << "Not an upper triangular matrix";
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
286 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
287 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
288
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
289 output(i, j) = 0; // The output is also upper triangular
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
290 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
291 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
292
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
293 if (k.size1() == 3)
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
294 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
295 // https://math.stackexchange.com/a/1004181
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
296 double a = k(0, 0);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
297 double b = k(0, 1);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
298 double c = k(0, 2);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
299 double d = k(1, 1);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
300 double e = k(1, 2);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
301 double f = k(2, 2);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
302
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
303 if (IsCloseToZero(a) ||
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
304 IsCloseToZero(d) ||
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
305 IsCloseToZero(f))
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
306 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
307 LOG(ERROR) << "Singular upper triangular matrix";
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
308 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
309 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
310 else
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
311 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
312 output(0, 0) = 1.0 / a;
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
313 output(0, 1) = -b / (a * d);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
314 output(0, 2) = (b * e - c * d) / (a * f * d);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
315 output(1, 1) = 1.0 / d;
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
316 output(1, 2) = -e / (f * d);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
317 output(2, 2) = 1.0 / f;
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
318 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
319 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
320 else
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
321 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
322 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
323 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
324 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
325
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
326
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
327 static void GetGivensComponent(double& c,
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
328 double& s,
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
329 const Matrix& a,
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
330 size_t i,
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
331 size_t j)
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
332 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
333 assert(i < 3 && j < 3);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
334
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
335 double x = a(i, i);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
336 double y = a(i, j);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
337 double n = sqrt(x * x + y * y);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
338
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
339 if (IsCloseToZero(n))
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
340 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
341 c = 1;
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
342 s = 0;
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
343 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
344 else
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
345 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
346 c = x / n;
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
347 s = -y / n;
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
348 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
349 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
350
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
351
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
352 /**
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
353 * This function computes the RQ decomposition of a 3x3 matrix,
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
354 * using Givens rotations. Reference: Algorithm A4.1 (page 579) of
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
355 * "Multiple View Geometry in Computer Vision" (2nd edition). The
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
356 * output matrix "Q" is a rotation matrix, and "R" is upper
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
357 * triangular.
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
358 **/
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
359 void RQDecomposition3x3(Matrix& r,
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
360 Matrix& q,
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
361 const Matrix& a)
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
362 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
363 using namespace boost::numeric::ublas;
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
364
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
365 if (a.size1() != 3 ||
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
366 a.size2() != 3)
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
367 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
368 LOG(ERROR) << "Only applicable to a 3x3 matrix";
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
369 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
370 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
371
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
372 r.resize(3, 3);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
373 q.resize(3, 3);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
374
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
375 r = a;
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
376 q = identity_matrix<double>(3);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
377
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
378 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
379 // Set A(2,1) to zero
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
380 double c, s;
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
381 GetGivensComponent(c, s, r, 2, 1);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
382
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
383 double v[9] = { 1, 0, 0,
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
384 0, c, -s,
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
385 0, s, c };
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
386
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
387 Matrix g;
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
388 FillMatrix(g, 3, 3, v);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
389
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
390 r = prod(r, g);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
391 q = prod(trans(g), q);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
392 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
393
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
394
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
395 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
396 // Set A(2,0) to zero
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
397 double c, s;
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
398 GetGivensComponent(c, s, r, 2, 0);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
399
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
400 double v[9] = { c, 0, -s,
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
401 0, 1, 0,
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
402 s, 0, c };
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
403
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
404 Matrix g;
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
405 FillMatrix(g, 3, 3, v);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
406
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
407 r = prod(r, g);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
408 q = prod(trans(g), q);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
409 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
410
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
411
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
412 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
413 // Set A(1,0) to zero
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
414 double c, s;
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
415 GetGivensComponent(c, s, r, 1, 0);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
416
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
417 double v[9] = { c, -s, 0,
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
418 s, c, 0,
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
419 0, 0, 1 };
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
420
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
421 Matrix g;
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
422 FillMatrix(g, 3, 3, v);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
423
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
424 r = prod(r, g);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
425 q = prod(trans(g), q);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
426 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
427
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
428 if (!IsCloseToZero(norm_inf(prod(r, q) - a)) ||
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
429 !IsRotationMatrix(q) ||
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
430 !IsCloseToZero(r(1, 0)) ||
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
431 !IsCloseToZero(r(2, 0)) ||
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
432 !IsCloseToZero(r(2, 1)))
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
433 {
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
434 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
435 }
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
436 }
163
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
437
169
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
438
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
439 bool InvertMatrixUnsafe(Matrix& target,
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
440 const Matrix& source)
163
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
441 {
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
442 if (source.size1() != source.size2())
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
443 {
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
444 LOG(ERROR) << "Inverse only exists for square matrices";
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
445 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
446 }
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
447
164
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
448 if (source.size1() < 4)
163
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
449 {
164
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
450 // For matrices with size below 4, use direct computations
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
451 // instead of LU decomposition
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
452
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
453 if (source.size1() == 0)
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
454 {
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
455 // By convention, the inverse of the empty matrix, is itself the empty matrix
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
456 target.resize(0, 0);
169
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
457 return true;
164
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
458 }
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
459
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
460 double determinant = ComputeDeterminant(source);
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
461
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
462 if (IsCloseToZero(determinant))
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
463 {
169
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
464 return false;
164
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
465 }
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
466
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
467 double denominator = 1.0 / determinant;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
468
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
469 target.resize(source.size1(), source.size2());
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
470
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
471 if (source.size1() == 1)
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
472 {
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
473 target(0, 0) = denominator;
169
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
474
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
475 return true;
164
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
476 }
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
477 else if (source.size1() == 2)
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
478 {
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
479 // https://en.wikipedia.org/wiki/Invertible_matrix#Inversion_of_2_%C3%97_2_matrices
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
480 target(0, 0) = source(1, 1) * denominator;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
481 target(0, 1) = -source(0, 1) * denominator;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
482 target(1, 0) = -source(1, 0) * denominator;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
483 target(1, 1) = source(0, 0) * denominator;
169
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
484
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
485 return true;
164
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
486 }
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
487 else if (source.size1() == 3)
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
488 {
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
489 // https://en.wikipedia.org/wiki/Invertible_matrix#Inversion_of_3_%C3%97_3_matrices
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
490 const double a = source(0, 0);
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
491 const double b = source(0, 1);
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
492 const double c = source(0, 2);
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
493 const double d = source(1, 0);
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
494 const double e = source(1, 1);
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
495 const double f = source(1, 2);
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
496 const double g = source(2, 0);
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
497 const double h = source(2, 1);
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
498 const double i = source(2, 2);
163
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
499
164
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
500 target(0, 0) = (e * i - f * h) * denominator;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
501 target(0, 1) = -(b * i - c * h) * denominator;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
502 target(0, 2) = (b * f - c * e) * denominator;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
503 target(1, 0) = -(d * i - f * g) * denominator;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
504 target(1, 1) = (a * i - c * g) * denominator;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
505 target(1, 2) = -(a * f - c * d) * denominator;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
506 target(2, 0) = (d * h - e * g) * denominator;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
507 target(2, 1) = -(a * h - b * g) * denominator;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
508 target(2, 2) = (a * e - b * d) * denominator;
169
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
509
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
510 return true;
164
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
511 }
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
512 else
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
513 {
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
514 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
515 }
163
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
516 }
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
517 else
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
518 {
164
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
519 // General case, using LU decomposition
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
520
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
521 Matrix a = source; // Copy the source matrix, as "lu_factorize()" modifies it
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
522
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
523 boost::numeric::ublas::permutation_matrix<size_t> permutation(source.size1());
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
524
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
525 if (boost::numeric::ublas::lu_factorize(a, permutation) != 0)
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
526 {
169
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
527 return false;
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
528 }
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
529 else
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
530 {
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
531 target = boost::numeric::ublas::identity_matrix<double>(source.size1());
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
532 lu_substitute(a, permutation, target);
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
533 return true;
164
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
534 }
169
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
535 }
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
536 }
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
537
164
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
538
169
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
539
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
540 void InvertMatrix(Matrix& target,
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
541 const Matrix& source)
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
542 {
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
543 if (!InvertMatrixUnsafe(target, source))
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
544 {
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
545 LOG(ERROR) << "Cannot invert singular matrix";
7105e51e4907 InvertMatrixUnsafe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
546 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
163
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
547 }
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
548 }
165
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
549
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
550
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
551 void CreateSkewSymmetric(Matrix& s,
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
552 const Vector& v)
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
553 {
392
d87fe075d31b to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
554 if (v.size() != 3)
d87fe075d31b to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
555 {
d87fe075d31b to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
556 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
d87fe075d31b to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
557 }
165
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
558
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
559 s.resize(3, 3);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
560 s(0,0) = 0;
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
561 s(0,1) = -v[2];
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
562 s(0,2) = v[1];
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
563 s(1,0) = v[2];
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
564 s(1,1) = 0;
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
565 s(1,2) = -v[0];
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
566 s(2,0) = -v[1];
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
567 s(2,1) = v[0];
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
568 s(2,2) = 0;
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
569 }
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
570
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
571
166
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 165
diff changeset
572 Matrix InvertScalingTranslationMatrix(const Matrix& t)
165
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
573 {
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
574 if (t.size1() != 4 ||
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
575 t.size2() != 4 ||
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
576 !LinearAlgebra::IsCloseToZero(t(0,1)) ||
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
577 !LinearAlgebra::IsCloseToZero(t(0,2)) ||
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
578 !LinearAlgebra::IsCloseToZero(t(1,0)) ||
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
579 !LinearAlgebra::IsCloseToZero(t(1,2)) ||
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
580 !LinearAlgebra::IsCloseToZero(t(2,0)) ||
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
581 !LinearAlgebra::IsCloseToZero(t(2,1)) ||
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
582 !LinearAlgebra::IsCloseToZero(t(3,0)) ||
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
583 !LinearAlgebra::IsCloseToZero(t(3,1)) ||
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
584 !LinearAlgebra::IsCloseToZero(t(3,2)))
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
585 {
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
586 LOG(ERROR) << "This matrix is more than a zoom/translate transform";
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
587 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
588 }
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
589
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
590 const double sx = t(0,0);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
591 const double sy = t(1,1);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
592 const double sz = t(2,2);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
593 const double w = t(3,3);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
594
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
595 if (LinearAlgebra::IsCloseToZero(sx) ||
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
596 LinearAlgebra::IsCloseToZero(sy) ||
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
597 LinearAlgebra::IsCloseToZero(sz) ||
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
598 LinearAlgebra::IsCloseToZero(w))
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
599 {
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
600 LOG(ERROR) << "Singular transform";
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
601 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
602 }
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
603
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
604 const double tx = t(0,3);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
605 const double ty = t(1,3);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
606 const double tz = t(2,3);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
607
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
608 Matrix m = IdentityMatrix(4);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
609
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
610 m(0,0) = 1.0 / sx;
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
611 m(1,1) = 1.0 / sy;
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
612 m(2,2) = 1.0 / sz;
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
613 m(3,3) = 1.0 / w;
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
614
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
615 m(0,3) = -tx / (sx * w);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
616 m(1,3) = -ty / (sy * w);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
617 m(2,3) = -tz / (sz * w);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
618
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
619 return m;
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
620 }
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
621
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
622
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
623 bool IsShearMatrix(const Matrix& shear)
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
624 {
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
625 return (shear.size1() == 4 &&
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
626 shear.size2() == 4 &&
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
627 LinearAlgebra::IsNear(1.0, shear(0,0)) &&
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
628 LinearAlgebra::IsNear(0.0, shear(0,1)) &&
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
629 LinearAlgebra::IsNear(0.0, shear(0,3)) &&
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
630 LinearAlgebra::IsNear(0.0, shear(1,0)) &&
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
631 LinearAlgebra::IsNear(1.0, shear(1,1)) &&
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
632 LinearAlgebra::IsNear(0.0, shear(1,3)) &&
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
633 LinearAlgebra::IsNear(0.0, shear(2,0)) &&
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
634 LinearAlgebra::IsNear(0.0, shear(2,1)) &&
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
635 LinearAlgebra::IsNear(1.0, shear(2,2)) &&
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
636 LinearAlgebra::IsNear(0.0, shear(2,3)) &&
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
637 LinearAlgebra::IsNear(0.0, shear(3,0)) &&
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
638 LinearAlgebra::IsNear(0.0, shear(3,1)) &&
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
639 LinearAlgebra::IsNear(1.0, shear(3,3)));
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
640 }
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
641
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
642
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
643 Matrix InvertShearMatrix(const Matrix& shear)
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
644 {
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
645 if (!IsShearMatrix(shear))
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
646 {
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
647 LOG(ERROR) << "Not a valid shear matrix";
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
648 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
649 }
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
650
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
651 Matrix m = IdentityMatrix(4);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
652 m(0,2) = -shear(0,2);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
653 m(1,2) = -shear(1,2);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
654 m(3,2) = -shear(3,2);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
655
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
656 return m;
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
657 }
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658 }
949
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
659
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
660 std::ostream& operator<<(std::ostream& s, const Vector& vec)
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
661 {
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
662 s << "(";
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
663 for (size_t i = 0; i < vec.size(); ++i)
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
664 {
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
665 s << vec(i);
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
666 if (i < (vec.size() - 1))
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
667 s << ", ";
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
668 }
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
669 s << ")";
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
670 return s;
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
671 }
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
672
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
673 std::ostream& operator<<(std::ostream& s, const Matrix& m)
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
674 {
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
675 ORTHANC_ASSERT(m.size1() == m.size2());
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
676 s << "(";
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
677 for (size_t i = 0; i < m.size1(); ++i)
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
678 {
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
679 s << "(";
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
680 for (size_t j = 0; j < m.size2(); ++j)
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
681 {
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
682 s << m(i,j);
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
683 if (j < (m.size2() - 1))
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
684 s << ", ";
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
685 }
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
686 s << ")";
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
687 if (i < (m.size1() - 1))
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
688 s << ", ";
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
689 }
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
690 s << ")";
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
691 return s;
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
692 }
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693 }