annotate UnitTestsSources/UnitTestsMain.cpp @ 1487:75ac66d5f4b2 bgo-timing-tests

Added timing test for dose loading and histogram computation
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 09 Jun 2020 09:50:03 +0200
parents cde379b9d1d2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
1270
2d8ab34c8c91 upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
20
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
47
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
10 * the License, or (at your option) any later version.
20
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
47
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
15 * Affero General Public License for more details.
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
16 *
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
20
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "gtest/gtest.h"
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
1167
ad4e21df4e40 enriching OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
24 #include "../Framework/StoneInitialization.h"
161
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
25 #include "../Framework/Toolbox/FiniteProjectiveCamera.h"
732
c35e98d22764 move Deprecated classes to a separate folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
26 #include "../Framework/Toolbox/GeometryToolbox.h"
87
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
27 #include "../Framework/Volumes/ImageBuffer3D.h"
1413
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
28 #include "../Framework/Loaders/LoaderCache.h"
1487
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
29 #include "../Framework/Loaders/OrthancMultiframeVolumeLoader.h"
113
2eca030792aa using the Orthanc Framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
30
212
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
31 #include <Core/HttpClient.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
32 #include <Core/Images/ImageProcessing.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
33 #include <Core/Logging.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
34 #include <Core/MultiThreading/SharedMessageQueue.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
35 #include <Core/OrthancException.h>
87
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
36
68
1526d38ef6da SliceSorter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
37 #include <boost/lexical_cast.hpp>
70
f73aed014bde OrthancAsynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
38 #include <boost/date_time/posix_time/posix_time.hpp>
f73aed014bde OrthancAsynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
39 #include <boost/thread/thread.hpp>
102
fcec0ab44054 display volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 93
diff changeset
40 #include <boost/math/special_functions/round.hpp>
1487
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
41 #include "Framework/Loaders/GenericLoadersContext.h"
102
fcec0ab44054 display volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 93
diff changeset
42
68
1526d38ef6da SliceSorter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
43
144
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
44 TEST(GeometryToolbox, Interpolation)
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
45 {
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
46 using namespace OrthancStone::GeometryToolbox;
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
47
144
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
48 // https://en.wikipedia.org/wiki/Bilinear_interpolation#Application_in_image_processing
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
49 ASSERT_FLOAT_EQ(146.1f, ComputeBilinearInterpolationUnitSquare(0.5f, 0.2f, 91, 210, 162, 95));
176
ab9c799f5de1 fix interpolation with negative coordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 165
diff changeset
50
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
51 ASSERT_FLOAT_EQ(91, ComputeBilinearInterpolationUnitSquare(0, 0, 91, 210, 162, 95));
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
52 ASSERT_FLOAT_EQ(210, ComputeBilinearInterpolationUnitSquare(1, 0, 91, 210, 162, 95));
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
53 ASSERT_FLOAT_EQ(162, ComputeBilinearInterpolationUnitSquare(0, 1, 91, 210, 162, 95));
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
54 ASSERT_FLOAT_EQ(95, ComputeBilinearInterpolationUnitSquare(1, 1, 91, 210, 162, 95));
176
ab9c799f5de1 fix interpolation with negative coordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 165
diff changeset
55
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
56 ASSERT_FLOAT_EQ(123.35f, ComputeTrilinearInterpolationUnitSquare
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
57 (0.5f, 0.2f, 0.7f,
161
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
58 91, 210, 162, 95,
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
59 51, 190, 80, 92));
176
ab9c799f5de1 fix interpolation with negative coordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 165
diff changeset
60
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
61 ASSERT_FLOAT_EQ(ComputeBilinearInterpolationUnitSquare(0.5f, 0.2f, 91, 210, 162, 95),
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
62 ComputeTrilinearInterpolationUnitSquare(0.5f, 0.2f, 0,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
63 91, 210, 162, 95,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
64 51, 190, 80, 92));
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
65
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
66 ASSERT_FLOAT_EQ(ComputeBilinearInterpolationUnitSquare(0.5f, 0.2f, 51, 190, 80, 92),
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
67 ComputeTrilinearInterpolationUnitSquare(0.5f, 0.2f, 1,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
68 91, 210, 162, 95,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
69 51, 190, 80, 92));
161
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
70 }
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
71
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
72
162
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
73 static bool CompareMatrix(const OrthancStone::Matrix& a,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
74 const OrthancStone::Matrix& b,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
75 double threshold = 0.00000001)
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
76 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
77 if (a.size1() != b.size1() ||
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
78 a.size2() != b.size2())
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
79 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
80 return false;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
81 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
82
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
83 for (size_t i = 0; i < a.size1(); i++)
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
84 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
85 for (size_t j = 0; j < a.size2(); j++)
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
86 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
87 if (fabs(a(i, j) - b(i, j)) > threshold)
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
88 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
89 LOG(ERROR) << "Too large difference in component ("
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
90 << i << "," << j << "): " << a(i,j) << " != " << b(i,j);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
91 return false;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
92 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
93 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
94 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
95
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
96 return true;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
97 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
98
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
99
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
100 static bool CompareVector(const OrthancStone::Vector& a,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
101 const OrthancStone::Vector& b,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
102 double threshold = 0.00000001)
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
103 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
104 if (a.size() != b.size())
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
105 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
106 return false;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
107 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
108
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
109 for (size_t i = 0; i < a.size(); i++)
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
110 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
111 if (fabs(a(i) - b(i)) > threshold)
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
112 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
113 LOG(ERROR) << "Too large difference in component "
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
114 << i << ": " << a(i) << " != " << b(i);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
115 return false;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
116 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
117 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
118
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
119 return true;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
120 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
121
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
122
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
123
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
124 TEST(FiniteProjectiveCamera, Decomposition1)
161
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
125 {
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
126 // Example 6.2 of "Multiple View Geometry in Computer Vision - 2nd
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
127 // edition" (page 163)
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
128 const double p[12] = {
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
129 3.53553e+2, 3.39645e+2, 2.77744e+2, -1.44946e+6,
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
130 -1.03528e+2, 2.33212e+1, 4.59607e+2, -6.32525e+5,
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
131 7.07107e-1, -3.53553e-1, 6.12372e-1, -9.18559e+2
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
132 };
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
133
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
134 OrthancStone::FiniteProjectiveCamera camera(p);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
135 ASSERT_EQ(3u, camera.GetMatrix().size1());
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
136 ASSERT_EQ(4u, camera.GetMatrix().size2());
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
137 ASSERT_EQ(3u, camera.GetIntrinsicParameters().size1());
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
138 ASSERT_EQ(3u, camera.GetIntrinsicParameters().size2());
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
139 ASSERT_EQ(3u, camera.GetRotation().size1());
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
140 ASSERT_EQ(3u, camera.GetRotation().size2());
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
141 ASSERT_EQ(3u, camera.GetCenter().size());
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
142
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
143 ASSERT_NEAR(1000.0, camera.GetCenter()[0], 0.01);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
144 ASSERT_NEAR(2000.0, camera.GetCenter()[1], 0.01);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
145 ASSERT_NEAR(1500.0, camera.GetCenter()[2], 0.01);
144
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
146
161
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
147 ASSERT_NEAR(468.2, camera.GetIntrinsicParameters() (0, 0), 0.1);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
148 ASSERT_NEAR(91.2, camera.GetIntrinsicParameters() (0, 1), 0.1);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
149 ASSERT_NEAR(300.0, camera.GetIntrinsicParameters() (0, 2), 0.1);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
150 ASSERT_NEAR(427.2, camera.GetIntrinsicParameters() (1, 1), 0.1);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
151 ASSERT_NEAR(200.0, camera.GetIntrinsicParameters() (1, 2), 0.1);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
152 ASSERT_NEAR(1.0, camera.GetIntrinsicParameters() (2, 2), 0.1);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
153
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
154 ASSERT_NEAR(0, camera.GetIntrinsicParameters() (1, 0), 0.0000001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
155 ASSERT_NEAR(0, camera.GetIntrinsicParameters() (2, 0), 0.0000001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
156 ASSERT_NEAR(0, camera.GetIntrinsicParameters() (2, 1), 0.0000001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
157
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
158 ASSERT_NEAR(0.41380, camera.GetRotation() (0, 0), 0.00001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
159 ASSERT_NEAR(0.90915, camera.GetRotation() (0, 1), 0.00001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
160 ASSERT_NEAR(0.04708, camera.GetRotation() (0, 2), 0.00001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
161 ASSERT_NEAR(-0.57338, camera.GetRotation() (1, 0), 0.00001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
162 ASSERT_NEAR(0.22011, camera.GetRotation() (1, 1), 0.00001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
163 ASSERT_NEAR(0.78917, camera.GetRotation() (1, 2), 0.00001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
164 ASSERT_NEAR(0.70711, camera.GetRotation() (2, 0), 0.00001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
165 ASSERT_NEAR(-0.35355, camera.GetRotation() (2, 1), 0.00001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
166 ASSERT_NEAR(0.61237, camera.GetRotation() (2, 2), 0.00001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
167
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
168 ASSERT_TRUE(OrthancStone::LinearAlgebra::IsRotationMatrix(camera.GetRotation()));
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
169
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
170 OrthancStone::FiniteProjectiveCamera camera2(camera.GetIntrinsicParameters(),
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
171 camera.GetRotation(),
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
172 camera.GetCenter());
162
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
173
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
174 ASSERT_TRUE(CompareMatrix(camera.GetMatrix(), camera2.GetMatrix()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
175 ASSERT_TRUE(CompareMatrix(camera.GetIntrinsicParameters(), camera2.GetIntrinsicParameters()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
176 ASSERT_TRUE(CompareMatrix(camera.GetRotation(), camera2.GetRotation()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
177 ASSERT_TRUE(CompareVector(camera.GetCenter(), camera2.GetCenter()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
178 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
179
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
180
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
181 TEST(FiniteProjectiveCamera, Decomposition2)
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
182 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
183 const double p[] = { 1188.111986, 580.205341, -808.445330, 128000.000000, -366.466264, 1446.510501, 418.499736, 128000.000000, -0.487118, 0.291726, -0.823172, 500.000000 };
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
184 const double k[] = { -1528.494743, 0.000000, 256.000000, 0.000000, 1528.494743, 256.000000, 0.000000, 0.000000, 1.000000 };
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
185 const double r[] = { -0.858893, -0.330733, 0.391047, -0.158171, 0.897503, 0.411668, -0.487118, 0.291726, -0.823172 };
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
186 const double c[] = { 243.558936, -145.863085, 411.585964 };
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
187
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
188 OrthancStone::FiniteProjectiveCamera camera(p);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
189 ASSERT_TRUE(OrthancStone::LinearAlgebra::IsRotationMatrix(camera.GetRotation()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
190
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
191 OrthancStone::FiniteProjectiveCamera camera2(k, r, c);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
192 ASSERT_TRUE(CompareMatrix(camera.GetMatrix(), camera2.GetMatrix(), 1));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
193 ASSERT_TRUE(CompareMatrix(camera.GetIntrinsicParameters(), camera2.GetIntrinsicParameters(), 0.001));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
194 ASSERT_TRUE(CompareMatrix(camera.GetRotation(), camera2.GetRotation(), 0.000001));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
195 ASSERT_TRUE(CompareVector(camera.GetCenter(), camera2.GetCenter(), 0.0001));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
196 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
197
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
198
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
199 TEST(FiniteProjectiveCamera, Decomposition3)
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
200 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
201 const double p[] = { 10, 0, 0, 0,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
202 0, 20, 0, 0,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
203 0, 0, 30, 0 };
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
204
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
205 OrthancStone::FiniteProjectiveCamera camera(p);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
206 ASSERT_TRUE(OrthancStone::LinearAlgebra::IsRotationMatrix(camera.GetRotation()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
207 ASSERT_DOUBLE_EQ(10, camera.GetIntrinsicParameters() (0, 0));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
208 ASSERT_DOUBLE_EQ(20, camera.GetIntrinsicParameters() (1, 1));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
209 ASSERT_DOUBLE_EQ(30, camera.GetIntrinsicParameters() (2, 2));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
210 ASSERT_DOUBLE_EQ(1, camera.GetRotation() (0, 0));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
211 ASSERT_DOUBLE_EQ(1, camera.GetRotation() (1, 1));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
212 ASSERT_DOUBLE_EQ(1, camera.GetRotation() (2, 2));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
213 ASSERT_DOUBLE_EQ(0, camera.GetCenter() (0));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
214 ASSERT_DOUBLE_EQ(0, camera.GetCenter() (1));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
215 ASSERT_DOUBLE_EQ(0, camera.GetCenter() (2));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
216 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
217
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
218
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
219 TEST(FiniteProjectiveCamera, Decomposition4)
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
220 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
221 const double p[] = { 1, 0, 0, 10,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
222 0, 1, 0, 20,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
223 0, 0, 1, 30 };
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
224
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
225 OrthancStone::FiniteProjectiveCamera camera(p);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
226 ASSERT_TRUE(OrthancStone::LinearAlgebra::IsRotationMatrix(camera.GetRotation()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
227 ASSERT_DOUBLE_EQ(1, camera.GetIntrinsicParameters() (0, 0));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
228 ASSERT_DOUBLE_EQ(1, camera.GetIntrinsicParameters() (1, 1));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
229 ASSERT_DOUBLE_EQ(1, camera.GetIntrinsicParameters() (2, 2));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
230 ASSERT_DOUBLE_EQ(1, camera.GetRotation() (0, 0));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
231 ASSERT_DOUBLE_EQ(1, camera.GetRotation() (1, 1));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
232 ASSERT_DOUBLE_EQ(1, camera.GetRotation() (2, 2));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
233 ASSERT_DOUBLE_EQ(-10, camera.GetCenter() (0));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
234 ASSERT_DOUBLE_EQ(-20, camera.GetCenter() (1));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
235 ASSERT_DOUBLE_EQ(-30, camera.GetCenter() (2));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
236 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
237
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
238
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
239 TEST(FiniteProjectiveCamera, Decomposition5)
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
240 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
241 const double p[] = { 0, 0, 10, 0,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
242 0, 20, 0, 0,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
243 30, 0, 0, 0 };
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
244
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
245 OrthancStone::FiniteProjectiveCamera camera(p);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
246 ASSERT_TRUE(OrthancStone::LinearAlgebra::IsRotationMatrix(camera.GetRotation()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
247 ASSERT_DOUBLE_EQ(-10, camera.GetIntrinsicParameters() (0, 0));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
248 ASSERT_DOUBLE_EQ(20, camera.GetIntrinsicParameters() (1, 1));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
249 ASSERT_DOUBLE_EQ(30, camera.GetIntrinsicParameters() (2, 2));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
250 ASSERT_DOUBLE_EQ(-1, camera.GetRotation() (0, 2));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
251 ASSERT_DOUBLE_EQ(1, camera.GetRotation() (1, 1));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
252 ASSERT_DOUBLE_EQ(1, camera.GetRotation() (2, 0));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
253 ASSERT_DOUBLE_EQ(0, camera.GetCenter() (0));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
254 ASSERT_DOUBLE_EQ(0, camera.GetCenter() (1));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
255 ASSERT_DOUBLE_EQ(0, camera.GetCenter() (2));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
256
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
257 OrthancStone::FiniteProjectiveCamera camera2(camera.GetIntrinsicParameters(),
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
258 camera.GetRotation(),
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
259 camera.GetCenter());
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
260 ASSERT_TRUE(CompareMatrix(camera.GetMatrix(), camera2.GetMatrix()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
261 ASSERT_TRUE(CompareMatrix(camera.GetIntrinsicParameters(), camera2.GetIntrinsicParameters()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
262 ASSERT_TRUE(CompareMatrix(camera.GetRotation(), camera2.GetRotation()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
263 ASSERT_TRUE(CompareVector(camera.GetCenter(), camera2.GetCenter()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
264 }
161
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
265
162
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
266
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
267 static double GetCosAngle(const OrthancStone::Vector& a,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
268 const OrthancStone::Vector& b)
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
269 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
270 // Returns the cosine of the angle between two vectors
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
271 // https://en.wikipedia.org/wiki/Dot_product#Geometric_definition
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
272 return boost::numeric::ublas::inner_prod(a, b) /
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
273 (boost::numeric::ublas::norm_2(a) * boost::numeric::ublas::norm_2(b));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
274 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
275
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
276
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
277 TEST(FiniteProjectiveCamera, Ray)
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
278 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
279 const double pp[] = { -1499.650894, 2954.618773, -259.737419, 637891.819097,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
280 -2951.517707, -1501.019129, -285.785281, 637891.819097,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
281 0.008528, 0.003067, -0.999959, 2491.764918 };
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
282
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
283 const OrthancStone::FiniteProjectiveCamera camera(pp);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
284
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
285 ASSERT_NEAR(-21.2492, camera.GetCenter() (0), 0.0001);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
286 ASSERT_NEAR(-7.64234, camera.GetCenter() (1), 0.00001);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
287 ASSERT_NEAR(2491.66, camera.GetCenter() (2), 0.01);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
288
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
289 // Image plane that led to these parameters, with principal point at
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
290 // (256,256). The image has dimensions 512x512.
165
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
291 OrthancStone::Vector o =
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
292 OrthancStone::LinearAlgebra::CreateVector(7.009620, 2.521030, -821.942000);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
293 OrthancStone::Vector ax =
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
294 OrthancStone::LinearAlgebra::CreateVector(-0.453219, 0.891399, -0.001131);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
295 OrthancStone::Vector ay =
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
296 OrthancStone::LinearAlgebra::CreateVector(-0.891359, -0.453210, -0.008992);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
297
162
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
298 OrthancStone::CoordinateSystem3D imagePlane(o, ax, ay);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
299
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
300 // Back-projection of the principal point
161
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
301 {
162
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
302 OrthancStone::Vector ray = camera.GetRayDirection(256, 256);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
303
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
304 // The principal axis vector is orthogonal to the image plane
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
305 // (i.e. parallel to the plane normal), in the opposite direction
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
306 // ("-1" corresponds to "cos(pi)").
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
307 ASSERT_NEAR(-1, GetCosAngle(ray, imagePlane.GetNormal()), 0.0000001);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
308
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
309 // Forward projection of principal axis, resulting in the principal point
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
310 double x, y;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
311 camera.ApplyFinite(x, y, camera.GetCenter() - ray);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
312
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
313 ASSERT_NEAR(256, x, 0.00001);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
314 ASSERT_NEAR(256, y, 0.00001);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
315 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
316
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
317 // Back-projection of the 4 corners of the image
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
318 std::vector<double> cx, cy;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
319 cx.push_back(0);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
320 cy.push_back(0);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
321 cx.push_back(512);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
322 cy.push_back(0);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
323 cx.push_back(512);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
324 cy.push_back(512);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
325 cx.push_back(0);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
326 cy.push_back(512);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
327
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
328 bool first = true;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
329 double angle;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
330
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
331 for (size_t i = 0; i < cx.size(); i++)
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
332 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
333 OrthancStone::Vector ray = camera.GetRayDirection(cx[i], cy[i]);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
334
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
335 // Check that the angle wrt. principal axis is the same for all
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
336 // the 4 corners
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
337 double a = GetCosAngle(ray, imagePlane.GetNormal());
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
338 if (first)
161
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
339 {
162
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
340 first = false;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
341 angle = a;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
342 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
343 else
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
344 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
345 ASSERT_NEAR(angle, a, 0.000001);
161
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
346 }
162
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
347
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
348 // Forward projection of the ray, going back to the original point
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
349 double x, y;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
350 camera.ApplyFinite(x, y, camera.GetCenter() - ray);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
351
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
352 ASSERT_NEAR(cx[i], x, 0.00001);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
353 ASSERT_NEAR(cy[i], y, 0.00001);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
354
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
355 // Alternative construction, by computing the intersection of the
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
356 // ray with the image plane
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
357 OrthancStone::Vector p;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
358 ASSERT_TRUE(imagePlane.IntersectLine(p, camera.GetCenter(), -ray));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
359 imagePlane.ProjectPoint(x, y, p);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
360 ASSERT_NEAR(cx[i], x + 256, 0.01);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
361 ASSERT_NEAR(cy[i], y + 256, 0.01);
161
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
362 }
144
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
363 }
87
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
364
20
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365
163
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
366 TEST(Matrix, Inverse1)
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
367 {
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
368 OrthancStone::Matrix a, b;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
369
164
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
370 a.resize(0, 0);
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
371 OrthancStone::LinearAlgebra::InvertMatrix(b, a);
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
372 ASSERT_EQ(0u, b.size1());
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
373 ASSERT_EQ(0u, b.size2());
163
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
374
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
375 a.resize(2, 3);
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
376 ASSERT_THROW(OrthancStone::LinearAlgebra::InvertMatrix(b, a), Orthanc::OrthancException);
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
377
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
378 a.resize(1, 1);
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
379 a(0, 0) = 45.0;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
380
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
381 ASSERT_DOUBLE_EQ(45, OrthancStone::LinearAlgebra::ComputeDeterminant(a));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
382 OrthancStone::LinearAlgebra::InvertMatrix(b, a);
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
383 ASSERT_EQ(1u, b.size1());
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
384 ASSERT_EQ(1u, b.size2());
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
385 ASSERT_DOUBLE_EQ(1.0 / 45.0, b(0, 0));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
386
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
387 a(0, 0) = 0;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
388 ASSERT_DOUBLE_EQ(0, OrthancStone::LinearAlgebra::ComputeDeterminant(a));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
389 ASSERT_THROW(OrthancStone::LinearAlgebra::InvertMatrix(b, a), Orthanc::OrthancException);
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
390 }
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
391
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
392
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
393 TEST(Matrix, Inverse2)
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
394 {
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
395 OrthancStone::Matrix a, b;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
396 a.resize(2, 2);
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
397 a(0, 0) = 4;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
398 a(0, 1) = 3;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
399 a(1, 0) = 3;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
400 a(1, 1) = 2;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
401
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
402 ASSERT_DOUBLE_EQ(-1, OrthancStone::LinearAlgebra::ComputeDeterminant(a));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
403 OrthancStone::LinearAlgebra::InvertMatrix(b, a);
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
404 ASSERT_EQ(2u, b.size1());
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
405 ASSERT_EQ(2u, b.size2());
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
406
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
407 ASSERT_DOUBLE_EQ(-2, b(0, 0));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
408 ASSERT_DOUBLE_EQ(3, b(0, 1));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
409 ASSERT_DOUBLE_EQ(3, b(1, 0));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
410 ASSERT_DOUBLE_EQ(-4, b(1, 1));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
411
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
412 a(0, 0) = 1;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
413 a(0, 1) = 2;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
414 a(1, 0) = 3;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
415 a(1, 1) = 4;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
416
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
417 ASSERT_DOUBLE_EQ(-2, OrthancStone::LinearAlgebra::ComputeDeterminant(a));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
418 OrthancStone::LinearAlgebra::InvertMatrix(b, a);
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
419
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
420 ASSERT_DOUBLE_EQ(-2, b(0, 0));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
421 ASSERT_DOUBLE_EQ(1, b(0, 1));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
422 ASSERT_DOUBLE_EQ(1.5, b(1, 0));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
423 ASSERT_DOUBLE_EQ(-0.5, b(1, 1));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
424 }
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
425
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
426
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
427 TEST(Matrix, Inverse3)
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
428 {
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
429 OrthancStone::Matrix a, b;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
430 a.resize(3, 3);
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
431 a(0, 0) = 7;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
432 a(0, 1) = 2;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
433 a(0, 2) = 1;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
434 a(1, 0) = 0;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
435 a(1, 1) = 3;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
436 a(1, 2) = -1;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
437 a(2, 0) = -3;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
438 a(2, 1) = 4;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
439 a(2, 2) = -2;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
440
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
441 ASSERT_DOUBLE_EQ(1, OrthancStone::LinearAlgebra::ComputeDeterminant(a));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
442 OrthancStone::LinearAlgebra::InvertMatrix(b, a);
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
443 ASSERT_EQ(3u, b.size1());
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
444 ASSERT_EQ(3u, b.size2());
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
445
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
446 ASSERT_DOUBLE_EQ(-2, b(0, 0));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
447 ASSERT_DOUBLE_EQ(8, b(0, 1));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
448 ASSERT_DOUBLE_EQ(-5, b(0, 2));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
449 ASSERT_DOUBLE_EQ(3, b(1, 0));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
450 ASSERT_DOUBLE_EQ(-11, b(1, 1));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
451 ASSERT_DOUBLE_EQ(7, b(1, 2));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
452 ASSERT_DOUBLE_EQ(9, b(2, 0));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
453 ASSERT_DOUBLE_EQ(-34, b(2, 1));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
454 ASSERT_DOUBLE_EQ(21, b(2, 2));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
455
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
456
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
457 a(0, 0) = 1;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
458 a(0, 1) = 2;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
459 a(0, 2) = 2;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
460 a(1, 0) = 1;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
461 a(1, 1) = 0;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
462 a(1, 2) = 1;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
463 a(2, 0) = 1;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
464 a(2, 1) = 2;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
465 a(2, 2) = 1;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
466
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
467 ASSERT_DOUBLE_EQ(2, OrthancStone::LinearAlgebra::ComputeDeterminant(a));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
468 OrthancStone::LinearAlgebra::InvertMatrix(b, a);
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
469 ASSERT_EQ(3u, b.size1());
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
470 ASSERT_EQ(3u, b.size2());
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
471
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
472 ASSERT_DOUBLE_EQ(-1, b(0, 0));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
473 ASSERT_DOUBLE_EQ(1, b(0, 1));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
474 ASSERT_DOUBLE_EQ(1, b(0, 2));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
475 ASSERT_DOUBLE_EQ(0, b(1, 0));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
476 ASSERT_DOUBLE_EQ(-0.5, b(1, 1));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
477 ASSERT_DOUBLE_EQ(0.5, b(1, 2));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
478 ASSERT_DOUBLE_EQ(1, b(2, 0));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
479 ASSERT_DOUBLE_EQ(0, b(2, 1));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
480 ASSERT_DOUBLE_EQ(-1, b(2, 2));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
481 }
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
482
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
483
164
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
484 TEST(Matrix, Inverse4)
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
485 {
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
486 OrthancStone::Matrix a, b;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
487 a.resize(4, 4);
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
488 a(0, 0) = 2;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
489 a(0, 1) = 1;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
490 a(0, 2) = 2;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
491 a(0, 3) = -3;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
492 a(1, 0) = -2;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
493 a(1, 1) = 2;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
494 a(1, 2) = -1;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
495 a(1, 3) = -1;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
496 a(2, 0) = 2;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
497 a(2, 1) = 2;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
498 a(2, 2) = -3;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
499 a(2, 3) = -1;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
500 a(3, 0) = 3;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
501 a(3, 1) = -2;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
502 a(3, 2) = -3;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
503 a(3, 3) = -1;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
504
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
505 OrthancStone::LinearAlgebra::InvertMatrix(b, a);
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
506 ASSERT_EQ(4u, b.size1());
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
507 ASSERT_EQ(4u, b.size2());
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
508
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
509 b *= 134.0; // This is the determinant
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
510
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
511 ASSERT_DOUBLE_EQ(8, b(0, 0));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
512 ASSERT_DOUBLE_EQ(-44, b(0, 1));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
513 ASSERT_DOUBLE_EQ(30, b(0, 2));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
514 ASSERT_DOUBLE_EQ(-10, b(0, 3));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
515 ASSERT_DOUBLE_EQ(2, b(1, 0));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
516 ASSERT_DOUBLE_EQ(-11, b(1, 1));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
517 ASSERT_DOUBLE_EQ(41, b(1, 2));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
518 ASSERT_DOUBLE_EQ(-36, b(1, 3));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
519 ASSERT_DOUBLE_EQ(16, b(2, 0));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
520 ASSERT_DOUBLE_EQ(-21, b(2, 1));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
521 ASSERT_DOUBLE_EQ(-7, b(2, 2));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
522 ASSERT_DOUBLE_EQ(-20, b(2, 3));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
523 ASSERT_DOUBLE_EQ(-28, b(3, 0));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
524 ASSERT_DOUBLE_EQ(-47, b(3, 1));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
525 ASSERT_DOUBLE_EQ(29, b(3, 2));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
526 ASSERT_DOUBLE_EQ(-32, b(3, 3));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
527 }
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
528
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
529
188
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
530 TEST(FiniteProjectiveCamera, Calibration)
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
531 {
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
532 unsigned int volumeWidth = 512;
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
533 unsigned int volumeHeight = 512;
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
534 unsigned int volumeDepth = 110;
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
535
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
536 OrthancStone::Vector camera = OrthancStone::LinearAlgebra::CreateVector
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
537 (-1000, -5000, -static_cast<double>(volumeDepth) * 32);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
538
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
539 OrthancStone::Vector principalPoint = OrthancStone::LinearAlgebra::CreateVector
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
540 (volumeWidth/2, volumeHeight/2, volumeDepth * 2);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
541
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
542 OrthancStone::FiniteProjectiveCamera c(camera, principalPoint, 0, 512, 512, 1, 1);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
543
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
544 double swapv[9] = { 1, 0, 0,
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
545 0, -1, 512,
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
546 0, 0, 1 };
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
547 OrthancStone::Matrix swap;
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
548 OrthancStone::LinearAlgebra::FillMatrix(swap, 3, 3, swapv);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
549
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
550 OrthancStone::Matrix p = OrthancStone::LinearAlgebra::Product(swap, c.GetMatrix());
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
551 p /= p(2,3);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
552
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
553 ASSERT_NEAR( 1.04437, p(0,0), 0.00001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
554 ASSERT_NEAR(-0.0703111, p(0,1), 0.00000001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
555 ASSERT_NEAR(-0.179283, p(0,2), 0.000001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
556 ASSERT_NEAR( 61.7431, p(0,3), 0.0001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
557 ASSERT_NEAR( 0.11127, p(1,0), 0.000001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
558 ASSERT_NEAR(-0.595541, p(1,1), 0.000001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
559 ASSERT_NEAR( 0.872211, p(1,2), 0.000001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
560 ASSERT_NEAR( 203.748, p(1,3), 0.001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
561 ASSERT_NEAR( 3.08593e-05, p(2,0), 0.0000000001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
562 ASSERT_NEAR( 0.000129138, p(2,1), 0.000000001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
563 ASSERT_NEAR( 9.18901e-05, p(2,2), 0.0000000001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
564 ASSERT_NEAR( 1, p(2,3), 0.0000001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
565 }
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
566
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
567
1172
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
568 static bool IsEqualRotationVector(OrthancStone::Vector a,
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
569 OrthancStone::Vector b)
189
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
570 {
1172
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
571 if (a.size() != b.size() ||
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
572 a.size() != 3)
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
573 {
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
574 return false;
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
575 }
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
576 else
189
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
577 {
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
578 OrthancStone::LinearAlgebra::NormalizeVector(a);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
579 OrthancStone::LinearAlgebra::NormalizeVector(b);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
580 return OrthancStone::LinearAlgebra::IsCloseToZero(boost::numeric::ublas::norm_2(a - b));
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
581 }
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
582 }
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
583
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
584
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
585 TEST(GeometryToolbox, AlignVectorsWithRotation)
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
586 {
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
587 OrthancStone::Vector a, b;
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
588 OrthancStone::Matrix r;
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
589
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
590 OrthancStone::LinearAlgebra::AssignVector(a, -200, 200, -846.63);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
591 OrthancStone::LinearAlgebra::AssignVector(b, 0, 0, 1);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
592
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
593 OrthancStone::GeometryToolbox::AlignVectorsWithRotation(r, a, b);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
594 ASSERT_TRUE(OrthancStone::LinearAlgebra::IsRotationMatrix(r));
1172
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
595 ASSERT_TRUE(IsEqualRotationVector(OrthancStone::LinearAlgebra::Product(r, a), b));
189
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
596
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
597 OrthancStone::GeometryToolbox::AlignVectorsWithRotation(r, b, a);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
598 ASSERT_TRUE(OrthancStone::LinearAlgebra::IsRotationMatrix(r));
1172
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
599 ASSERT_TRUE(IsEqualRotationVector(OrthancStone::LinearAlgebra::Product(r, b), a));
189
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
600
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
601 OrthancStone::LinearAlgebra::AssignVector(a, 1, 0, 0);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
602 OrthancStone::LinearAlgebra::AssignVector(b, 0, 0, 1);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
603 OrthancStone::GeometryToolbox::AlignVectorsWithRotation(r, a, b);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
604 ASSERT_TRUE(OrthancStone::LinearAlgebra::IsRotationMatrix(r));
1172
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
605 ASSERT_TRUE(IsEqualRotationVector(OrthancStone::LinearAlgebra::Product(r, a), b));
189
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
606
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
607 OrthancStone::LinearAlgebra::AssignVector(a, 0, 1, 0);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
608 OrthancStone::LinearAlgebra::AssignVector(b, 0, 0, 1);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
609 OrthancStone::GeometryToolbox::AlignVectorsWithRotation(r, a, b);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
610 ASSERT_TRUE(OrthancStone::LinearAlgebra::IsRotationMatrix(r));
1172
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
611 ASSERT_TRUE(IsEqualRotationVector(OrthancStone::LinearAlgebra::Product(r, a), b));
189
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
612
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
613 OrthancStone::LinearAlgebra::AssignVector(a, 0, 0, 1);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
614 OrthancStone::LinearAlgebra::AssignVector(b, 0, 0, 1);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
615 OrthancStone::GeometryToolbox::AlignVectorsWithRotation(r, a, b);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
616 ASSERT_TRUE(OrthancStone::LinearAlgebra::IsRotationMatrix(r));
1172
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
617 ASSERT_TRUE(IsEqualRotationVector(OrthancStone::LinearAlgebra::Product(r, a), b));
189
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
618
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
619 OrthancStone::LinearAlgebra::AssignVector(a, 0, 0, 0);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
620 OrthancStone::LinearAlgebra::AssignVector(b, 0, 0, 1);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
621 ASSERT_THROW(OrthancStone::GeometryToolbox::AlignVectorsWithRotation(r, a, b), Orthanc::OrthancException);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
622
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
623 // TODO: Deal with opposite vectors
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
624
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
625 /*
1172
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
626 OrthancStone::LinearAlgebra::AssignVector(a, 0, 0, -1);
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
627 OrthancStone::LinearAlgebra::AssignVector(b, 0, 0, 1);
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
628 OrthancStone::GeometryToolbox::AlignVectorsWithRotation(r, a, b);
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
629 OrthancStone::LinearAlgebra::Print(r);
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
630 OrthancStone::LinearAlgebra::Print(boost::numeric::ublas::prod(r, a));
189
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
631 */
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
632 }
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
633
1172
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
634
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
635 static bool IsEqualVectorL1(OrthancStone::Vector a,
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
636 OrthancStone::Vector b)
189
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
637 {
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
638 if (a.size() != b.size())
189
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
639 {
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
640 return false;
189
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
641 }
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
642 else
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
643 {
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
644 for (size_t i = 0; i < a.size(); i++)
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
645 {
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
646 if (!OrthancStone::LinearAlgebra::IsNear(a[i], b[i], 0.0001))
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
647 {
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
648 return false;
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
649 }
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
650 }
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
651
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
652 return true;
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
653 }
189
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
654 }
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
655
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
656
685
ea1a5b963798 unit test: VolumeImageGeometry.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
657 TEST(VolumeImageGeometry, Basic)
ea1a5b963798 unit test: VolumeImageGeometry.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
658 {
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
659 using namespace OrthancStone;
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
660
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
661 VolumeImageGeometry g;
953
118fc5c85d07 Fixed call to renamed method SetSize --> SetSizeInVoxels
Benjamin Golinvaux <bgo@osimis.io>
parents: 809
diff changeset
662 g.SetSizeInVoxels(10, 20, 30);
685
ea1a5b963798 unit test: VolumeImageGeometry.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
663 g.SetVoxelDimensions(1, 2, 3);
ea1a5b963798 unit test: VolumeImageGeometry.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
664
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
665 Vector p = g.GetCoordinates(0, 0, 0);
685
ea1a5b963798 unit test: VolumeImageGeometry.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
666 ASSERT_EQ(3u, p.size());
999
2d69b8bee484 Added tests for Dicom structure set classes (loaders and utils)
Benjamin Golinvaux <bgo@osimis.io>
parents: 953
diff changeset
667 ASSERT_DOUBLE_EQ(-1.0 / 2.0, p[0]);
2d69b8bee484 Added tests for Dicom structure set classes (loaders and utils)
Benjamin Golinvaux <bgo@osimis.io>
parents: 953
diff changeset
668 ASSERT_DOUBLE_EQ(-2.0 / 2.0, p[1]);
2d69b8bee484 Added tests for Dicom structure set classes (loaders and utils)
Benjamin Golinvaux <bgo@osimis.io>
parents: 953
diff changeset
669 ASSERT_DOUBLE_EQ(-3.0 / 2.0, p[2]);
685
ea1a5b963798 unit test: VolumeImageGeometry.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
670
ea1a5b963798 unit test: VolumeImageGeometry.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
671 p = g.GetCoordinates(1, 1, 1);
999
2d69b8bee484 Added tests for Dicom structure set classes (loaders and utils)
Benjamin Golinvaux <bgo@osimis.io>
parents: 953
diff changeset
672 ASSERT_DOUBLE_EQ(-1.0 / 2.0 + 10.0 * 1.0, p[0]);
2d69b8bee484 Added tests for Dicom structure set classes (loaders and utils)
Benjamin Golinvaux <bgo@osimis.io>
parents: 953
diff changeset
673 ASSERT_DOUBLE_EQ(-2.0 / 2.0 + 20.0 * 2.0, p[1]);
2d69b8bee484 Added tests for Dicom structure set classes (loaders and utils)
Benjamin Golinvaux <bgo@osimis.io>
parents: 953
diff changeset
674 ASSERT_DOUBLE_EQ(-3.0 / 2.0 + 30.0 * 3.0, p[2]);
685
ea1a5b963798 unit test: VolumeImageGeometry.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
675
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
676 VolumeProjection proj;
689
93a8949a1ef7 VolumeImageGeometry::DetectSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 685
diff changeset
677 ASSERT_TRUE(g.DetectProjection(proj, g.GetAxialGeometry().GetNormal()));
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
678 ASSERT_EQ(VolumeProjection_Axial, proj);
689
93a8949a1ef7 VolumeImageGeometry::DetectSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 685
diff changeset
679 ASSERT_TRUE(g.DetectProjection(proj, g.GetCoronalGeometry().GetNormal()));
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
680 ASSERT_EQ(VolumeProjection_Coronal, proj);
689
93a8949a1ef7 VolumeImageGeometry::DetectSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 685
diff changeset
681 ASSERT_TRUE(g.DetectProjection(proj, g.GetSagittalGeometry().GetNormal()));
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
682 ASSERT_EQ(VolumeProjection_Sagittal, proj);
689
93a8949a1ef7 VolumeImageGeometry::DetectSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 685
diff changeset
683
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
684 ASSERT_EQ(10u, g.GetProjectionWidth(VolumeProjection_Axial));
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
685 ASSERT_EQ(20u, g.GetProjectionHeight(VolumeProjection_Axial));
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
686 ASSERT_EQ(30u, g.GetProjectionDepth(VolumeProjection_Axial));
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
687 ASSERT_EQ(10u, g.GetProjectionWidth(VolumeProjection_Coronal));
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
688 ASSERT_EQ(30u, g.GetProjectionHeight(VolumeProjection_Coronal));
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
689 ASSERT_EQ(20u, g.GetProjectionDepth(VolumeProjection_Coronal));
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
690 ASSERT_EQ(20u, g.GetProjectionWidth(VolumeProjection_Sagittal));
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
691 ASSERT_EQ(30u, g.GetProjectionHeight(VolumeProjection_Sagittal));
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
692 ASSERT_EQ(10u, g.GetProjectionDepth(VolumeProjection_Sagittal));
689
93a8949a1ef7 VolumeImageGeometry::DetectSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 685
diff changeset
693
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
694 p = g.GetVoxelDimensions(VolumeProjection_Axial);
689
93a8949a1ef7 VolumeImageGeometry::DetectSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 685
diff changeset
695 ASSERT_EQ(3u, p.size());
999
2d69b8bee484 Added tests for Dicom structure set classes (loaders and utils)
Benjamin Golinvaux <bgo@osimis.io>
parents: 953
diff changeset
696 ASSERT_DOUBLE_EQ(1, p[0]);
2d69b8bee484 Added tests for Dicom structure set classes (loaders and utils)
Benjamin Golinvaux <bgo@osimis.io>
parents: 953
diff changeset
697 ASSERT_DOUBLE_EQ(2, p[1]);
2d69b8bee484 Added tests for Dicom structure set classes (loaders and utils)
Benjamin Golinvaux <bgo@osimis.io>
parents: 953
diff changeset
698 ASSERT_DOUBLE_EQ(3, p[2]);
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
699 p = g.GetVoxelDimensions(VolumeProjection_Coronal);
689
93a8949a1ef7 VolumeImageGeometry::DetectSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 685
diff changeset
700 ASSERT_EQ(3u, p.size());
999
2d69b8bee484 Added tests for Dicom structure set classes (loaders and utils)
Benjamin Golinvaux <bgo@osimis.io>
parents: 953
diff changeset
701 ASSERT_DOUBLE_EQ(1, p[0]);
2d69b8bee484 Added tests for Dicom structure set classes (loaders and utils)
Benjamin Golinvaux <bgo@osimis.io>
parents: 953
diff changeset
702 ASSERT_DOUBLE_EQ(3, p[1]);
2d69b8bee484 Added tests for Dicom structure set classes (loaders and utils)
Benjamin Golinvaux <bgo@osimis.io>
parents: 953
diff changeset
703 ASSERT_DOUBLE_EQ(2, p[2]);
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
704 p = g.GetVoxelDimensions(VolumeProjection_Sagittal);
689
93a8949a1ef7 VolumeImageGeometry::DetectSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 685
diff changeset
705 ASSERT_EQ(3u, p.size());
999
2d69b8bee484 Added tests for Dicom structure set classes (loaders and utils)
Benjamin Golinvaux <bgo@osimis.io>
parents: 953
diff changeset
706 ASSERT_DOUBLE_EQ(2, p[0]);
2d69b8bee484 Added tests for Dicom structure set classes (loaders and utils)
Benjamin Golinvaux <bgo@osimis.io>
parents: 953
diff changeset
707 ASSERT_DOUBLE_EQ(3, p[1]);
2d69b8bee484 Added tests for Dicom structure set classes (loaders and utils)
Benjamin Golinvaux <bgo@osimis.io>
parents: 953
diff changeset
708 ASSERT_DOUBLE_EQ(1, p[2]);
689
93a8949a1ef7 VolumeImageGeometry::DetectSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 685
diff changeset
709
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
710 // Loop over all the voxels of the volume
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
711 for (unsigned int z = 0; z < g.GetDepth(); z++)
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
712 {
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
713 const float zz = (0.5f + static_cast<float>(z)) / static_cast<float>(g.GetDepth()); // Z-center of the voxel
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
714
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
715 for (unsigned int y = 0; y < g.GetHeight(); y++)
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
716 {
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
717 const float yy = (0.5f + static_cast<float>(y)) / static_cast<float>(g.GetHeight()); // Y-center of the voxel
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
718
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
719 for (unsigned int x = 0; x < g.GetWidth(); x++)
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
720 {
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
721 const float xx = (0.5f + static_cast<float>(x)) / static_cast<float>(g.GetWidth()); // X-center of the voxel
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
722
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
723 const float sx = 1.0f;
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
724 const float sy = 2.0f;
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
725 const float sz = 3.0f;
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
726
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
727 Vector p = g.GetCoordinates(xx, yy, zz);
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
728
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
729 Vector q = (g.GetAxialGeometry().MapSliceToWorldCoordinates(
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
730 static_cast<double>(x) * sx,
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
731 static_cast<double>(y) * sy) +
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
732 z * sz * g.GetAxialGeometry().GetNormal());
1172
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
733 ASSERT_TRUE(IsEqualVectorL1(p, q));
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
734
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
735 q = (g.GetCoronalGeometry().MapSliceToWorldCoordinates(
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
736 static_cast<double>(x) * sx,
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
737 static_cast<double>(g.GetDepth() - 1 - z) * sz) +
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
738 y * sy * g.GetCoronalGeometry().GetNormal());
1172
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
739 ASSERT_TRUE(IsEqualVectorL1(p, q));
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
740
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
741 /**
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
742 * WARNING: In sagittal geometry, the normal points to
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
743 * REDUCING X-axis in the 3D world. This is necessary to keep
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
744 * the right-hand coordinate system. Hence the "-".
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
745 **/
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
746 q = (g.GetSagittalGeometry().MapSliceToWorldCoordinates(
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
747 static_cast<double>(y) * sy,
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
748 static_cast<double>(g.GetDepth() - 1 - z) * sz) +
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
749 x * sx * (-g.GetSagittalGeometry().GetNormal()));
1172
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
750 ASSERT_TRUE(IsEqualVectorL1(p, q));
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
751 }
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
752 }
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
753 }
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
754
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
755 ASSERT_EQ(0, (int) VolumeProjection_Axial);
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
756 ASSERT_EQ(1, (int) VolumeProjection_Coronal);
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
757 ASSERT_EQ(2, (int) VolumeProjection_Sagittal);
689
93a8949a1ef7 VolumeImageGeometry::DetectSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 685
diff changeset
758
93a8949a1ef7 VolumeImageGeometry::DetectSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 685
diff changeset
759 for (int p = 0; p < 3; p++)
93a8949a1ef7 VolumeImageGeometry::DetectSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 685
diff changeset
760 {
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
761 VolumeProjection projection = (VolumeProjection) p;
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
762 const CoordinateSystem3D& s = g.GetProjectionGeometry(projection);
689
93a8949a1ef7 VolumeImageGeometry::DetectSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 685
diff changeset
763
809
e8fdf29cd0ca VolumeImageGeometry::GetProjectionSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
764 ASSERT_THROW(g.GetProjectionSlice(projection, g.GetProjectionDepth(projection)), Orthanc::OrthancException);
e8fdf29cd0ca VolumeImageGeometry::GetProjectionSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
765
689
93a8949a1ef7 VolumeImageGeometry::DetectSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 685
diff changeset
766 for (unsigned int i = 0; i < g.GetProjectionDepth(projection); i++)
93a8949a1ef7 VolumeImageGeometry::DetectSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 685
diff changeset
767 {
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
768 CoordinateSystem3D plane = g.GetProjectionSlice(projection, i);
809
e8fdf29cd0ca VolumeImageGeometry::GetProjectionSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
769
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
770 if (projection == VolumeProjection_Sagittal)
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
771 {
1172
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
772 ASSERT_TRUE(IsEqualVectorL1(plane.GetOrigin(), s.GetOrigin() + static_cast<double>(i) *
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
773 (-s.GetNormal()) * g.GetVoxelDimensions(projection)[2]));
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
774 }
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
775 else
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
776 {
1172
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
777 ASSERT_TRUE(IsEqualVectorL1(plane.GetOrigin(), s.GetOrigin() + static_cast<double>(i) *
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
778 s.GetNormal() * g.GetVoxelDimensions(projection)[2]));
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
779 }
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
780
1172
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
781 ASSERT_TRUE(IsEqualVectorL1(plane.GetAxisX(), s.GetAxisX()));
6def5bfba867 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
782 ASSERT_TRUE(IsEqualVectorL1(plane.GetAxisY(), s.GetAxisY()));
689
93a8949a1ef7 VolumeImageGeometry::DetectSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 685
diff changeset
783
93a8949a1ef7 VolumeImageGeometry::DetectSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 685
diff changeset
784 unsigned int slice;
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1167
diff changeset
785 VolumeProjection q;
689
93a8949a1ef7 VolumeImageGeometry::DetectSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 685
diff changeset
786 ASSERT_TRUE(g.DetectSlice(q, slice, plane));
93a8949a1ef7 VolumeImageGeometry::DetectSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 685
diff changeset
787 ASSERT_EQ(projection, q);
1167
ad4e21df4e40 enriching OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
788 ASSERT_EQ(i, slice);
689
93a8949a1ef7 VolumeImageGeometry::DetectSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 685
diff changeset
789 }
93a8949a1ef7 VolumeImageGeometry::DetectSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 685
diff changeset
790 }
685
ea1a5b963798 unit test: VolumeImageGeometry.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
791 }
ea1a5b963798 unit test: VolumeImageGeometry.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
792
1167
ad4e21df4e40 enriching OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
793
ad4e21df4e40 enriching OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
794 TEST(LinearAlgebra, ParseVectorLocale)
ad4e21df4e40 enriching OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
795 {
ad4e21df4e40 enriching OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
796 OrthancStone::Vector v;
ad4e21df4e40 enriching OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
797
ad4e21df4e40 enriching OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
798 ASSERT_TRUE(OrthancStone::LinearAlgebra::ParseVector(v, "1.2"));
ad4e21df4e40 enriching OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
799 ASSERT_EQ(1u, v.size());
1309
1f877e0846fe Fixed some warnings + fixed build for C++03
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
800 ASSERT_DOUBLE_EQ(1.2, v[0]);
1167
ad4e21df4e40 enriching OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
801
ad4e21df4e40 enriching OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
802 ASSERT_TRUE(OrthancStone::LinearAlgebra::ParseVector(v, "-1.2e+2"));
ad4e21df4e40 enriching OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
803 ASSERT_EQ(1u, v.size());
1309
1f877e0846fe Fixed some warnings + fixed build for C++03
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
804 ASSERT_DOUBLE_EQ(-120.0, v[0]);
1167
ad4e21df4e40 enriching OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
805
ad4e21df4e40 enriching OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
806 ASSERT_TRUE(OrthancStone::LinearAlgebra::ParseVector(v, "-1e-2\\2"));
ad4e21df4e40 enriching OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
807 ASSERT_EQ(2u, v.size());
1309
1f877e0846fe Fixed some warnings + fixed build for C++03
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
808 ASSERT_DOUBLE_EQ(-0.01, v[0]);
1f877e0846fe Fixed some warnings + fixed build for C++03
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
809 ASSERT_DOUBLE_EQ(2.0, v[1]);
1167
ad4e21df4e40 enriching OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
810
ad4e21df4e40 enriching OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
811 ASSERT_TRUE(OrthancStone::LinearAlgebra::ParseVector(v, "1.3671875\\1.3671875"));
ad4e21df4e40 enriching OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
812 ASSERT_EQ(2u, v.size());
1309
1f877e0846fe Fixed some warnings + fixed build for C++03
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
813 ASSERT_DOUBLE_EQ(1.3671875, v[0]);
1f877e0846fe Fixed some warnings + fixed build for C++03
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
814 ASSERT_DOUBLE_EQ(1.3671875, v[1]);
1167
ad4e21df4e40 enriching OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
815 }
ad4e21df4e40 enriching OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
816
1413
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
817 TEST(LoaderCache, NormalizeUuid)
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
818 {
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
819 std::string ref("44ca5051-14ef-4d2f-8bd7-db20bfb61fbb");
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
820
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
821 {
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
822 std::string u("44ca5051-14ef-4d2f-8bd7-db20bfb61fbb");
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
823 OrthancStone::LoaderCache::NormalizeUuid(u);
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
824 ASSERT_EQ(ref, u);
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
825 }
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
826
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
827 // space left
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
828 {
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
829 std::string u(" 44ca5051-14ef-4d2f-8bd7-db20bfb61fbb");
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
830 OrthancStone::LoaderCache::NormalizeUuid(u);
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
831 ASSERT_EQ(ref, u);
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
832 }
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
833
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
834 // space right
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
835 {
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
836 std::string u("44ca5051-14ef-4d2f-8bd7-db20bfb61fbb ");
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
837 OrthancStone::LoaderCache::NormalizeUuid(u);
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
838 ASSERT_EQ(ref, u);
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
839 }
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
840
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
841 // space l & r
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
842 {
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
843 std::string u(" 44ca5051-14ef-4d2f-8bd7-db20bfb61fbb ");
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
844 OrthancStone::LoaderCache::NormalizeUuid(u);
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
845 ASSERT_EQ(ref, u);
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
846 }
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
847
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
848 // space left + case
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
849 {
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
850 std::string u(" 44CA5051-14ef-4d2f-8bd7-dB20bfb61fbb");
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
851 OrthancStone::LoaderCache::NormalizeUuid(u);
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
852 ASSERT_EQ(ref, u);
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
853 }
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
854
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
855 // space right + case
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
856 {
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
857 std::string u("44ca5051-14EF-4D2f-8bd7-db20bfb61fbB ");
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
858 OrthancStone::LoaderCache::NormalizeUuid(u);
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
859 ASSERT_EQ(ref, u);
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
860 }
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
861
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
862 // space l & r + case
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
863 {
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
864 std::string u(" 44cA5051-14Ef-4d2f-8bD7-db20bfb61fbb ");
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
865 OrthancStone::LoaderCache::NormalizeUuid(u);
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
866 ASSERT_EQ(ref, u);
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
867 }
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
868
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
869 // no
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
870 {
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
871 std::string u(" 44ca5051-14ef-4d2f-8bd7- db20bfb61fbb");
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
872 OrthancStone::LoaderCache::NormalizeUuid(u);
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
873 ASSERT_NE(ref, u);
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
874 }
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
875
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
876 // no
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
877 {
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
878 std::string u("44ca5051-14ef-4d2f-8bd7-db20bfb61fb");
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
879 OrthancStone::LoaderCache::NormalizeUuid(u);
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
880 ASSERT_NE(ref, u);
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
881 }
cde379b9d1d2 LoaderCache is now extensible + factored the uuid normalizing
Benjamin Golinvaux <bgo@osimis.io>
parents: 1403
diff changeset
882 }
1167
ad4e21df4e40 enriching OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
883
1487
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
884 void LoadRtDoseBlocking(boost::shared_ptr<OrthancStone::OrthancMultiframeVolumeLoader> doseLoader, std::string instanceId)
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
885 {
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
886 namespace pt = boost::posix_time;
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
887
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
888 // Load RTSTRUCT
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
889 doseLoader->LoadInstance(instanceId);
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
890
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
891 pt::ptime initialTime = pt::second_clock::local_time();
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
892
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
893 // Wait for the loading process to complete
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
894 {
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
895 bool bContinue(true);
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
896 while (bContinue)
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
897 {
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
898 bContinue = !doseLoader->IsPixelDataLoaded();
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
899 boost::this_thread::sleep_for(boost::chrono::milliseconds(1000));
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
900
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
901 {
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
902 pt::ptime nowTime = pt::second_clock::local_time();
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
903 pt::time_duration diff = nowTime - initialTime;
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
904 double seconds = static_cast<double>(diff.total_milliseconds()) * 0.001;
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
905 std::cout << seconds << " seconds elapsed...\n";
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
906 if (seconds > 30)
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
907 {
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
908 const char* msg = "More than 30 seconds elapsed when waiting for RTSTRUCT... Aborting test :(\n";
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
909 GTEST_FATAL_FAILURE_(msg);
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
910 bContinue = false;
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
911 }
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
912 }
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
913 }
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
914 }
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
915 }
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
916
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
917 static void InitializeLoadersContext(const char* orthancApiUrl, OrthancStone::ILoadersContext& loadersContext)
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
918 {
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
919 Orthanc::WebServiceParameters p;
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
920
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
921 OrthancStone::GenericLoadersContext& typedLoadersContext =
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
922 dynamic_cast<OrthancStone::GenericLoadersContext&>(loadersContext);
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
923 // Default is http://localhost:8042
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
924 // Here's how you may change it
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
925 p.SetUrl(orthancApiUrl);
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
926 p.SetCredentials("orthanc", "orthanc");
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
927 typedLoadersContext.SetOrthancParameters(p);
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
928
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
929 typedLoadersContext.StartOracle();
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
930 }
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
931
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
932 void ExitializeLoadersContext(OrthancStone::ILoadersContext& loadersContext)
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
933 {
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
934 OrthancStone::GenericLoadersContext& typedLoadersContext =
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
935 dynamic_cast<OrthancStone::GenericLoadersContext&>(loadersContext);
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
936
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
937 typedLoadersContext.StopOracle();
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
938 }
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
939
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
940 TEST(DoseLoader, DISABLED_DoseLoadingTiming)
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
941 {
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
942 using namespace OrthancStone;
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
943
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
944 // create loaders context
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
945 std::unique_ptr<OrthancStone::ILoadersContext> loadersContext(new GenericLoadersContext(1,4,1));
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
946 InitializeLoadersContext("http://localhost:8042/", *loadersContext);
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
947
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
948 auto doseVolume = boost::make_shared<DicomVolumeImage>();
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
949 auto doseLoader = OrthancMultiframeVolumeLoader::Create(*loadersContext, doseVolume);
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
950
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
951 LoadRtDoseBlocking(doseLoader, "830a69ff-8e4b5ee3-b7f966c8-bccc20fb-d322dceb");
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
952
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
953
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
954 std::map<std::string,uint64_t> timing = doseLoader->GetTimingInfo();
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
955
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
956 for (std::map<std::string, uint64_t>::iterator it = timing.begin(); it != timing.end(); ++it)
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
957 {
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
958 const std::string& checkPtName = it->first;
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
959 uint64_t value = it->second;
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
960 double valueSec = static_cast<double>(value)/1000000.0;
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
961 std::cout << checkPtName << " : " << value << " usec (" << valueSec << " secs)" << std::endl;
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
962 }
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
963
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
964 //auto ti = doseLoader->GetTimingInfo();
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
965
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
966 //Register<DicomVolumeImage::ContentUpdatedMessage>(*doseLoader_, &RtViewerApp::HandleDoseLoaded);
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
967 ExitializeLoadersContext(*loadersContext);
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
968 }
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
969
75ac66d5f4b2 Added timing test for dose loading and histogram computation
Benjamin Golinvaux <bgo@osimis.io>
parents: 1413
diff changeset
970
20
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
971 int main(int argc, char **argv)
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
972 {
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
973 Orthanc::Logging::Initialize();
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
974 Orthanc::Logging::EnableInfoLevel(true);
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
975
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
976 ::testing::InitGoogleTest(&argc, argv);
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
977 int result = RUN_ALL_TESTS();
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
978
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
979 Orthanc::Logging::Finalize();
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
980
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
981 return result;
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
982 }