annotate UnitTestsSources/UnitTestsMain.cpp @ 347:cd65103c9172 am-2

RotateBitmapTracker
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 23 Oct 2018 10:50:46 +0200
parents be2660b6e40a
children ed7146fa2c98
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
134
4cff7b1ed31d upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
5 * Copyright (C) 2017-2018 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
102
fcec0ab44054 display volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 93
diff changeset
22 #include "../Framework/dev.h"
20
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "gtest/gtest.h"
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
113
2eca030792aa using the Orthanc Framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
25 #include "../Framework/Layers/FrameRenderer.h"
2eca030792aa using the Orthanc Framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
26 #include "../Framework/Layers/LayerSourceBase.h"
2eca030792aa using the Orthanc Framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
27 #include "../Framework/Toolbox/DownloadStack.h"
161
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
28 #include "../Framework/Toolbox/FiniteProjectiveCamera.h"
307
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 257
diff changeset
29 #include "../Framework/Toolbox/MessagingToolbox.h"
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 72
diff changeset
30 #include "../Framework/Toolbox/OrthancSlicesLoader.h"
87
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
31 #include "../Framework/Volumes/ImageBuffer3D.h"
88
90bf4116a23c ISlicedVolume
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
32 #include "../Framework/Volumes/SlicedVolumeBase.h"
113
2eca030792aa using the Orthanc Framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
33 #include "../Platforms/Generic/OracleWebService.h"
2eca030792aa using the Orthanc Framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
34
212
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
35 #include <Core/HttpClient.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
36 #include <Core/Images/ImageProcessing.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
37 #include <Core/Logging.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
38 #include <Core/MultiThreading/SharedMessageQueue.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
39 #include <Core/OrthancException.h>
87
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
40
68
1526d38ef6da SliceSorter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
41 #include <boost/lexical_cast.hpp>
70
f73aed014bde OrthancAsynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
42 #include <boost/date_time/posix_time/posix_time.hpp>
f73aed014bde OrthancAsynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
43 #include <boost/thread/thread.hpp>
102
fcec0ab44054 display volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 93
diff changeset
44 #include <boost/math/special_functions/round.hpp>
fcec0ab44054 display volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 93
diff changeset
45
68
1526d38ef6da SliceSorter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
46
144
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
47 #if 0
65
885932a893de OrthancFrameLayerSource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
48 namespace OrthancStone
885932a893de OrthancFrameLayerSource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
49 {
72
c1cc3bdba18c cleaning up OrthancSlicesLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 71
diff changeset
50 class Tata : public OrthancSlicesLoader::ICallback
67
acb60cbb8301 refactoring SeriesLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 66
diff changeset
51 {
acb60cbb8301 refactoring SeriesLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 66
diff changeset
52 public:
72
c1cc3bdba18c cleaning up OrthancSlicesLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 71
diff changeset
53 virtual void NotifyGeometryReady(const OrthancSlicesLoader& loader)
67
acb60cbb8301 refactoring SeriesLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 66
diff changeset
54 {
80
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
55 printf(">> %d\n", (int) loader.GetSliceCount());
70
f73aed014bde OrthancAsynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
56
f73aed014bde OrthancAsynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
57 for (size_t i = 0; i < loader.GetSliceCount(); i++)
f73aed014bde OrthancAsynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
58 {
257
9afafb192180 using PAM
am@osimis.io
parents: 212
diff changeset
59 const_cast<OrthancSlicesLoader&>(loader).ScheduleLoadSliceImage(i, SliceImageQuality_FullPng);
70
f73aed014bde OrthancAsynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
60 }
68
1526d38ef6da SliceSorter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
61 }
1526d38ef6da SliceSorter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
62
72
c1cc3bdba18c cleaning up OrthancSlicesLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 71
diff changeset
63 virtual void NotifyGeometryError(const OrthancSlicesLoader& loader)
68
1526d38ef6da SliceSorter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
64 {
1526d38ef6da SliceSorter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
65 printf("Error\n");
67
acb60cbb8301 refactoring SeriesLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 66
diff changeset
66 }
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 65
diff changeset
67
72
c1cc3bdba18c cleaning up OrthancSlicesLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 71
diff changeset
68 virtual void NotifySliceImageReady(const OrthancSlicesLoader& loader,
68
1526d38ef6da SliceSorter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
69 unsigned int sliceIndex,
1526d38ef6da SliceSorter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
70 const Slice& slice,
102
fcec0ab44054 display volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 93
diff changeset
71 std::auto_ptr<Orthanc::ImageAccessor>& image,
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
72 SliceImageQuality quality)
67
acb60cbb8301 refactoring SeriesLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 66
diff changeset
73 {
68
1526d38ef6da SliceSorter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
74 std::auto_ptr<Orthanc::ImageAccessor> tmp(image);
70
f73aed014bde OrthancAsynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
75 printf("Slice OK %dx%d\n", tmp->GetWidth(), tmp->GetHeight());
68
1526d38ef6da SliceSorter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
76 }
1526d38ef6da SliceSorter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
77
72
c1cc3bdba18c cleaning up OrthancSlicesLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 71
diff changeset
78 virtual void NotifySliceImageError(const OrthancSlicesLoader& loader,
68
1526d38ef6da SliceSorter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
79 unsigned int sliceIndex,
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
80 const Slice& slice,
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
81 SliceImageQuality quality)
68
1526d38ef6da SliceSorter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
82 {
1526d38ef6da SliceSorter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
83 printf("ERROR 2\n");
67
acb60cbb8301 refactoring SeriesLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 66
diff changeset
84 }
acb60cbb8301 refactoring SeriesLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 66
diff changeset
85 };
65
885932a893de OrthancFrameLayerSource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
86 }
885932a893de OrthancFrameLayerSource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
87
885932a893de OrthancFrameLayerSource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
88
87
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
89 TEST(Toto, DISABLED_Tutu)
65
885932a893de OrthancFrameLayerSource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
90 {
80
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
91 OrthancStone::Oracle oracle(4);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
92 oracle.Start();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
93
65
885932a893de OrthancFrameLayerSource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
94 Orthanc::WebServiceParameters web;
80
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
95 //OrthancStone::OrthancAsynchronousWebService orthanc(web, 4);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
96 OrthancStone::OracleWebService orthanc(oracle, web);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
97 //orthanc.Start();
65
885932a893de OrthancFrameLayerSource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
98
885932a893de OrthancFrameLayerSource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
99 OrthancStone::Tata tata;
72
c1cc3bdba18c cleaning up OrthancSlicesLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 71
diff changeset
100 OrthancStone::OrthancSlicesLoader loader(tata, orthanc);
80
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
101 loader.ScheduleLoadSeries("c1c4cb95-05e3bd11-8da9f5bb-87278f71-0b2b43f5");
77
f5f54ed8d307 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
102 //loader.ScheduleLoadSeries("67f1b334-02c16752-45026e40-a5b60b6b-030ecab5");
71
30c768873d47 OrthancSliceLoader::ScheduleLoadInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 70
diff changeset
103
80
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
104 //loader.ScheduleLoadInstance("19816330-cb02e1cf-df3a8fe8-bf510623-ccefe9f5", 0);
68
1526d38ef6da SliceSorter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
105
70
f73aed014bde OrthancAsynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
106 /*printf(">> %d\n", loader.GetSliceCount());
f73aed014bde OrthancAsynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
107 loader.ScheduleLoadSliceImage(31);*/
f73aed014bde OrthancAsynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
108
f73aed014bde OrthancAsynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
109 boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
f73aed014bde OrthancAsynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
110
80
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
111 //orthanc.Stop();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
112 oracle.Stop();
65
885932a893de OrthancFrameLayerSource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
113 }
885932a893de OrthancFrameLayerSource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
114
885932a893de OrthancFrameLayerSource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
115
87
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
116 TEST(Toto, Tata)
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
117 {
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
118 OrthancStone::Oracle oracle(4);
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
119 oracle.Start();
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
120
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
121 Orthanc::WebServiceParameters web;
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
122 OrthancStone::OracleWebService orthanc(oracle, web);
121
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
123 OrthancStone::OrthancVolumeImage volume(orthanc, true);
87
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
124
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
125 //volume.ScheduleLoadInstance("19816330-cb02e1cf-df3a8fe8-bf510623-ccefe9f5", 0);
87
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
126 //volume.ScheduleLoadSeries("318603c5-03e8cffc-a82b6ee1-3ccd3c1e-18d7e3bb"); // COMUNIX PET
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
127 //volume.ScheduleLoadSeries("7124dba7-09803f33-98b73826-33f14632-ea842d29"); // COMUNIX CT
87
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
128 //volume.ScheduleLoadSeries("5990e39c-51e5f201-fe87a54c-31a55943-e59ef80e"); // Delphine sagital
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
129 volume.ScheduleLoadSeries("6f1b492a-e181e200-44e51840-ef8db55e-af529ab6"); // Delphine ax 2.5
87
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
130
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
131 boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
132
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
133 oracle.Stop();
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
134 }
144
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
135 #endif
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
136
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
137
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
138 TEST(GeometryToolbox, Interpolation)
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
139 {
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
140 using namespace OrthancStone::GeometryToolbox;
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
141
144
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
142 // 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
143 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
144
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
145 ASSERT_FLOAT_EQ(91, ComputeBilinearInterpolationUnitSquare(0, 0, 91, 210, 162, 95));
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
146 ASSERT_FLOAT_EQ(210, ComputeBilinearInterpolationUnitSquare(1, 0, 91, 210, 162, 95));
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
147 ASSERT_FLOAT_EQ(162, ComputeBilinearInterpolationUnitSquare(0, 1, 91, 210, 162, 95));
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
148 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
149
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
150 ASSERT_FLOAT_EQ(123.35f, ComputeTrilinearInterpolationUnitSquare
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
151 (0.5f, 0.2f, 0.7f,
161
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
152 91, 210, 162, 95,
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
153 51, 190, 80, 92));
176
ab9c799f5de1 fix interpolation with negative coordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 165
diff changeset
154
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
155 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
156 ComputeTrilinearInterpolationUnitSquare(0.5f, 0.2f, 0,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
157 91, 210, 162, 95,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
158 51, 190, 80, 92));
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
159
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
160 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
161 ComputeTrilinearInterpolationUnitSquare(0.5f, 0.2f, 1,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
162 91, 210, 162, 95,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
163 51, 190, 80, 92));
161
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
164 }
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
165
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
166
162
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
167 static bool CompareMatrix(const OrthancStone::Matrix& a,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
168 const OrthancStone::Matrix& b,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
169 double threshold = 0.00000001)
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
170 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
171 if (a.size1() != b.size1() ||
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
172 a.size2() != b.size2())
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 return false;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
175 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
176
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
177 for (size_t i = 0; i < a.size1(); i++)
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 for (size_t j = 0; j < a.size2(); j++)
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 if (fabs(a(i, j) - b(i, j)) > threshold)
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 LOG(ERROR) << "Too large difference in component ("
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
184 << i << "," << j << "): " << a(i,j) << " != " << b(i,j);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
185 return false;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
186 }
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 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
189
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
190 return true;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
191 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
192
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
193
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
194 static bool CompareVector(const OrthancStone::Vector& a,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
195 const OrthancStone::Vector& b,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
196 double threshold = 0.00000001)
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 if (a.size() != b.size())
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
199 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
200 return false;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
201 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
202
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
203 for (size_t i = 0; i < a.size(); i++)
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 if (fabs(a(i) - b(i)) > threshold)
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
206 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
207 LOG(ERROR) << "Too large difference in component "
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
208 << i << ": " << a(i) << " != " << b(i);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
209 return false;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
210 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
211 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
212
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
213 return true;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
214 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
215
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 TEST(FiniteProjectiveCamera, Decomposition1)
161
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
219 {
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
220 // Example 6.2 of "Multiple View Geometry in Computer Vision - 2nd
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
221 // edition" (page 163)
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
222 const double p[12] = {
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
223 3.53553e+2, 3.39645e+2, 2.77744e+2, -1.44946e+6,
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
224 -1.03528e+2, 2.33212e+1, 4.59607e+2, -6.32525e+5,
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
225 7.07107e-1, -3.53553e-1, 6.12372e-1, -9.18559e+2
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
226 };
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
227
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
228 OrthancStone::FiniteProjectiveCamera camera(p);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
229 ASSERT_EQ(3u, camera.GetMatrix().size1());
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
230 ASSERT_EQ(4u, camera.GetMatrix().size2());
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
231 ASSERT_EQ(3u, camera.GetIntrinsicParameters().size1());
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
232 ASSERT_EQ(3u, camera.GetIntrinsicParameters().size2());
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
233 ASSERT_EQ(3u, camera.GetRotation().size1());
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
234 ASSERT_EQ(3u, camera.GetRotation().size2());
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
235 ASSERT_EQ(3u, camera.GetCenter().size());
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
236
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
237 ASSERT_NEAR(1000.0, camera.GetCenter()[0], 0.01);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
238 ASSERT_NEAR(2000.0, camera.GetCenter()[1], 0.01);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
239 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
240
161
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
241 ASSERT_NEAR(468.2, camera.GetIntrinsicParameters() (0, 0), 0.1);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
242 ASSERT_NEAR(91.2, camera.GetIntrinsicParameters() (0, 1), 0.1);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
243 ASSERT_NEAR(300.0, camera.GetIntrinsicParameters() (0, 2), 0.1);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
244 ASSERT_NEAR(427.2, camera.GetIntrinsicParameters() (1, 1), 0.1);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
245 ASSERT_NEAR(200.0, camera.GetIntrinsicParameters() (1, 2), 0.1);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
246 ASSERT_NEAR(1.0, camera.GetIntrinsicParameters() (2, 2), 0.1);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
247
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
248 ASSERT_NEAR(0, camera.GetIntrinsicParameters() (1, 0), 0.0000001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
249 ASSERT_NEAR(0, camera.GetIntrinsicParameters() (2, 0), 0.0000001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
250 ASSERT_NEAR(0, camera.GetIntrinsicParameters() (2, 1), 0.0000001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
251
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
252 ASSERT_NEAR(0.41380, camera.GetRotation() (0, 0), 0.00001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
253 ASSERT_NEAR(0.90915, camera.GetRotation() (0, 1), 0.00001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
254 ASSERT_NEAR(0.04708, camera.GetRotation() (0, 2), 0.00001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
255 ASSERT_NEAR(-0.57338, camera.GetRotation() (1, 0), 0.00001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
256 ASSERT_NEAR(0.22011, camera.GetRotation() (1, 1), 0.00001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
257 ASSERT_NEAR(0.78917, camera.GetRotation() (1, 2), 0.00001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
258 ASSERT_NEAR(0.70711, camera.GetRotation() (2, 0), 0.00001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
259 ASSERT_NEAR(-0.35355, camera.GetRotation() (2, 1), 0.00001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
260 ASSERT_NEAR(0.61237, camera.GetRotation() (2, 2), 0.00001);
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
261
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
262 ASSERT_TRUE(OrthancStone::LinearAlgebra::IsRotationMatrix(camera.GetRotation()));
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
263
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
264 OrthancStone::FiniteProjectiveCamera camera2(camera.GetIntrinsicParameters(),
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
265 camera.GetRotation(),
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
266 camera.GetCenter());
162
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
267
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
268 ASSERT_TRUE(CompareMatrix(camera.GetMatrix(), camera2.GetMatrix()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
269 ASSERT_TRUE(CompareMatrix(camera.GetIntrinsicParameters(), camera2.GetIntrinsicParameters()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
270 ASSERT_TRUE(CompareMatrix(camera.GetRotation(), camera2.GetRotation()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
271 ASSERT_TRUE(CompareVector(camera.GetCenter(), camera2.GetCenter()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
272 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
273
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 TEST(FiniteProjectiveCamera, Decomposition2)
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 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
278 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
279 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
280 const double c[] = { 243.558936, -145.863085, 411.585964 };
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
281
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
282 OrthancStone::FiniteProjectiveCamera camera(p);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
283 ASSERT_TRUE(OrthancStone::LinearAlgebra::IsRotationMatrix(camera.GetRotation()));
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 OrthancStone::FiniteProjectiveCamera camera2(k, r, c);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
286 ASSERT_TRUE(CompareMatrix(camera.GetMatrix(), camera2.GetMatrix(), 1));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
287 ASSERT_TRUE(CompareMatrix(camera.GetIntrinsicParameters(), camera2.GetIntrinsicParameters(), 0.001));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
288 ASSERT_TRUE(CompareMatrix(camera.GetRotation(), camera2.GetRotation(), 0.000001));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
289 ASSERT_TRUE(CompareVector(camera.GetCenter(), camera2.GetCenter(), 0.0001));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
290 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
291
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
292
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
293 TEST(FiniteProjectiveCamera, Decomposition3)
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
294 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
295 const double p[] = { 10, 0, 0, 0,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
296 0, 20, 0, 0,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
297 0, 0, 30, 0 };
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
298
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
299 OrthancStone::FiniteProjectiveCamera camera(p);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
300 ASSERT_TRUE(OrthancStone::LinearAlgebra::IsRotationMatrix(camera.GetRotation()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
301 ASSERT_DOUBLE_EQ(10, camera.GetIntrinsicParameters() (0, 0));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
302 ASSERT_DOUBLE_EQ(20, camera.GetIntrinsicParameters() (1, 1));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
303 ASSERT_DOUBLE_EQ(30, camera.GetIntrinsicParameters() (2, 2));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
304 ASSERT_DOUBLE_EQ(1, camera.GetRotation() (0, 0));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
305 ASSERT_DOUBLE_EQ(1, camera.GetRotation() (1, 1));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
306 ASSERT_DOUBLE_EQ(1, camera.GetRotation() (2, 2));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
307 ASSERT_DOUBLE_EQ(0, camera.GetCenter() (0));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
308 ASSERT_DOUBLE_EQ(0, camera.GetCenter() (1));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
309 ASSERT_DOUBLE_EQ(0, camera.GetCenter() (2));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
310 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
311
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 TEST(FiniteProjectiveCamera, Decomposition4)
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
314 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
315 const double p[] = { 1, 0, 0, 10,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
316 0, 1, 0, 20,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
317 0, 0, 1, 30 };
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
318
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
319 OrthancStone::FiniteProjectiveCamera camera(p);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
320 ASSERT_TRUE(OrthancStone::LinearAlgebra::IsRotationMatrix(camera.GetRotation()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
321 ASSERT_DOUBLE_EQ(1, camera.GetIntrinsicParameters() (0, 0));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
322 ASSERT_DOUBLE_EQ(1, camera.GetIntrinsicParameters() (1, 1));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
323 ASSERT_DOUBLE_EQ(1, camera.GetIntrinsicParameters() (2, 2));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
324 ASSERT_DOUBLE_EQ(1, camera.GetRotation() (0, 0));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
325 ASSERT_DOUBLE_EQ(1, camera.GetRotation() (1, 1));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
326 ASSERT_DOUBLE_EQ(1, camera.GetRotation() (2, 2));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
327 ASSERT_DOUBLE_EQ(-10, camera.GetCenter() (0));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
328 ASSERT_DOUBLE_EQ(-20, camera.GetCenter() (1));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
329 ASSERT_DOUBLE_EQ(-30, camera.GetCenter() (2));
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
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 TEST(FiniteProjectiveCamera, Decomposition5)
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 const double p[] = { 0, 0, 10, 0,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
336 0, 20, 0, 0,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
337 30, 0, 0, 0 };
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
338
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
339 OrthancStone::FiniteProjectiveCamera camera(p);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
340 ASSERT_TRUE(OrthancStone::LinearAlgebra::IsRotationMatrix(camera.GetRotation()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
341 ASSERT_DOUBLE_EQ(-10, camera.GetIntrinsicParameters() (0, 0));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
342 ASSERT_DOUBLE_EQ(20, camera.GetIntrinsicParameters() (1, 1));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
343 ASSERT_DOUBLE_EQ(30, camera.GetIntrinsicParameters() (2, 2));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
344 ASSERT_DOUBLE_EQ(-1, camera.GetRotation() (0, 2));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
345 ASSERT_DOUBLE_EQ(1, camera.GetRotation() (1, 1));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
346 ASSERT_DOUBLE_EQ(1, camera.GetRotation() (2, 0));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
347 ASSERT_DOUBLE_EQ(0, camera.GetCenter() (0));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
348 ASSERT_DOUBLE_EQ(0, camera.GetCenter() (1));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
349 ASSERT_DOUBLE_EQ(0, camera.GetCenter() (2));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
350
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
351 OrthancStone::FiniteProjectiveCamera camera2(camera.GetIntrinsicParameters(),
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
352 camera.GetRotation(),
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
353 camera.GetCenter());
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
354 ASSERT_TRUE(CompareMatrix(camera.GetMatrix(), camera2.GetMatrix()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
355 ASSERT_TRUE(CompareMatrix(camera.GetIntrinsicParameters(), camera2.GetIntrinsicParameters()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
356 ASSERT_TRUE(CompareMatrix(camera.GetRotation(), camera2.GetRotation()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
357 ASSERT_TRUE(CompareVector(camera.GetCenter(), camera2.GetCenter()));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
358 }
161
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
359
162
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
360
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
361 static double GetCosAngle(const OrthancStone::Vector& a,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
362 const OrthancStone::Vector& b)
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
363 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
364 // Returns the cosine of the angle between two vectors
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
365 // https://en.wikipedia.org/wiki/Dot_product#Geometric_definition
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
366 return boost::numeric::ublas::inner_prod(a, b) /
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
367 (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
368 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
369
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
370
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
371 TEST(FiniteProjectiveCamera, Ray)
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
372 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
373 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
374 -2951.517707, -1501.019129, -285.785281, 637891.819097,
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
375 0.008528, 0.003067, -0.999959, 2491.764918 };
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
376
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
377 const OrthancStone::FiniteProjectiveCamera camera(pp);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
378
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
379 ASSERT_NEAR(-21.2492, camera.GetCenter() (0), 0.0001);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
380 ASSERT_NEAR(-7.64234, camera.GetCenter() (1), 0.00001);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
381 ASSERT_NEAR(2491.66, camera.GetCenter() (2), 0.01);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
382
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
383 // 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
384 // (256,256). The image has dimensions 512x512.
165
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
385 OrthancStone::Vector o =
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
386 OrthancStone::LinearAlgebra::CreateVector(7.009620, 2.521030, -821.942000);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
387 OrthancStone::Vector ax =
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
388 OrthancStone::LinearAlgebra::CreateVector(-0.453219, 0.891399, -0.001131);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
389 OrthancStone::Vector ay =
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
390 OrthancStone::LinearAlgebra::CreateVector(-0.891359, -0.453210, -0.008992);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 164
diff changeset
391
162
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
392 OrthancStone::CoordinateSystem3D imagePlane(o, ax, ay);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
393
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
394 // Back-projection of the principal point
161
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
395 {
162
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
396 OrthancStone::Vector ray = camera.GetRayDirection(256, 256);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
397
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
398 // The principal axis vector is orthogonal to the image plane
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
399 // (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
400 // ("-1" corresponds to "cos(pi)").
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
401 ASSERT_NEAR(-1, GetCosAngle(ray, imagePlane.GetNormal()), 0.0000001);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
402
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
403 // Forward projection of principal axis, resulting in the principal point
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
404 double x, y;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
405 camera.ApplyFinite(x, y, camera.GetCenter() - ray);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
406
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
407 ASSERT_NEAR(256, x, 0.00001);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
408 ASSERT_NEAR(256, y, 0.00001);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
409 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
410
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
411 // Back-projection of the 4 corners of the image
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
412 std::vector<double> cx, cy;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
413 cx.push_back(0);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
414 cy.push_back(0);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
415 cx.push_back(512);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
416 cy.push_back(0);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
417 cx.push_back(512);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
418 cy.push_back(512);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
419 cx.push_back(0);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
420 cy.push_back(512);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
421
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
422 bool first = true;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
423 double angle;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
424
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
425 for (size_t i = 0; i < cx.size(); i++)
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
426 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
427 OrthancStone::Vector ray = camera.GetRayDirection(cx[i], cy[i]);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
428
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
429 // 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
430 // the 4 corners
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
431 double a = GetCosAngle(ray, imagePlane.GetNormal());
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
432 if (first)
161
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
433 {
162
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
434 first = false;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
435 angle = a;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
436 }
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
437 else
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
438 {
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
439 ASSERT_NEAR(angle, a, 0.000001);
161
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
440 }
162
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
441
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
442 // 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
443 double x, y;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
444 camera.ApplyFinite(x, y, camera.GetCenter() - ray);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
445
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
446 ASSERT_NEAR(cx[i], x, 0.00001);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
447 ASSERT_NEAR(cy[i], y, 0.00001);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
448
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
449 // Alternative construction, by computing the intersection of the
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
450 // ray with the image plane
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
451 OrthancStone::Vector p;
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
452 ASSERT_TRUE(imagePlane.IntersectLine(p, camera.GetCenter(), -ray));
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
453 imagePlane.ProjectPoint(x, y, p);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
454 ASSERT_NEAR(cx[i], x + 256, 0.01);
77715c340767 unit testing FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 161
diff changeset
455 ASSERT_NEAR(cy[i], y + 256, 0.01);
161
197a5ddaf68c FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
456 }
144
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
457 }
87
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
458
20
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459
163
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
460 TEST(Matrix, Inverse1)
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
461 {
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
462 OrthancStone::Matrix a, b;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
463
164
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
464 a.resize(0, 0);
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
465 OrthancStone::LinearAlgebra::InvertMatrix(b, a);
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
466 ASSERT_EQ(0u, b.size1());
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
467 ASSERT_EQ(0u, b.size2());
163
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
468
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
469 a.resize(2, 3);
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
470 ASSERT_THROW(OrthancStone::LinearAlgebra::InvertMatrix(b, a), Orthanc::OrthancException);
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 a.resize(1, 1);
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
473 a(0, 0) = 45.0;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
474
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
475 ASSERT_DOUBLE_EQ(45, OrthancStone::LinearAlgebra::ComputeDeterminant(a));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
476 OrthancStone::LinearAlgebra::InvertMatrix(b, a);
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
477 ASSERT_EQ(1u, b.size1());
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
478 ASSERT_EQ(1u, b.size2());
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
479 ASSERT_DOUBLE_EQ(1.0 / 45.0, b(0, 0));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
480
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
481 a(0, 0) = 0;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
482 ASSERT_DOUBLE_EQ(0, OrthancStone::LinearAlgebra::ComputeDeterminant(a));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
483 ASSERT_THROW(OrthancStone::LinearAlgebra::InvertMatrix(b, a), Orthanc::OrthancException);
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
484 }
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
485
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
486
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
487 TEST(Matrix, Inverse2)
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
488 {
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
489 OrthancStone::Matrix a, b;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
490 a.resize(2, 2);
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
491 a(0, 0) = 4;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
492 a(0, 1) = 3;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
493 a(1, 0) = 3;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
494 a(1, 1) = 2;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
495
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
496 ASSERT_DOUBLE_EQ(-1, OrthancStone::LinearAlgebra::ComputeDeterminant(a));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
497 OrthancStone::LinearAlgebra::InvertMatrix(b, a);
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
498 ASSERT_EQ(2u, b.size1());
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
499 ASSERT_EQ(2u, b.size2());
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
500
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
501 ASSERT_DOUBLE_EQ(-2, b(0, 0));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
502 ASSERT_DOUBLE_EQ(3, b(0, 1));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
503 ASSERT_DOUBLE_EQ(3, b(1, 0));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
504 ASSERT_DOUBLE_EQ(-4, b(1, 1));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
505
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
506 a(0, 0) = 1;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
507 a(0, 1) = 2;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
508 a(1, 0) = 3;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
509 a(1, 1) = 4;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
510
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
511 ASSERT_DOUBLE_EQ(-2, OrthancStone::LinearAlgebra::ComputeDeterminant(a));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
512 OrthancStone::LinearAlgebra::InvertMatrix(b, a);
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
513
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
514 ASSERT_DOUBLE_EQ(-2, b(0, 0));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
515 ASSERT_DOUBLE_EQ(1, b(0, 1));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
516 ASSERT_DOUBLE_EQ(1.5, b(1, 0));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
517 ASSERT_DOUBLE_EQ(-0.5, b(1, 1));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
518 }
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
519
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
520
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
521 TEST(Matrix, Inverse3)
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
522 {
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
523 OrthancStone::Matrix a, b;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
524 a.resize(3, 3);
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
525 a(0, 0) = 7;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
526 a(0, 1) = 2;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
527 a(0, 2) = 1;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
528 a(1, 0) = 0;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
529 a(1, 1) = 3;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
530 a(1, 2) = -1;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
531 a(2, 0) = -3;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
532 a(2, 1) = 4;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
533 a(2, 2) = -2;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
534
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
535 ASSERT_DOUBLE_EQ(1, OrthancStone::LinearAlgebra::ComputeDeterminant(a));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
536 OrthancStone::LinearAlgebra::InvertMatrix(b, a);
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
537 ASSERT_EQ(3u, b.size1());
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
538 ASSERT_EQ(3u, b.size2());
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
539
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
540 ASSERT_DOUBLE_EQ(-2, b(0, 0));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
541 ASSERT_DOUBLE_EQ(8, b(0, 1));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
542 ASSERT_DOUBLE_EQ(-5, b(0, 2));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
543 ASSERT_DOUBLE_EQ(3, b(1, 0));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
544 ASSERT_DOUBLE_EQ(-11, b(1, 1));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
545 ASSERT_DOUBLE_EQ(7, b(1, 2));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
546 ASSERT_DOUBLE_EQ(9, b(2, 0));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
547 ASSERT_DOUBLE_EQ(-34, b(2, 1));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
548 ASSERT_DOUBLE_EQ(21, b(2, 2));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
549
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
550
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
551 a(0, 0) = 1;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
552 a(0, 1) = 2;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
553 a(0, 2) = 2;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
554 a(1, 0) = 1;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
555 a(1, 1) = 0;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
556 a(1, 2) = 1;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
557 a(2, 0) = 1;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
558 a(2, 1) = 2;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
559 a(2, 2) = 1;
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
560
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
561 ASSERT_DOUBLE_EQ(2, OrthancStone::LinearAlgebra::ComputeDeterminant(a));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
562 OrthancStone::LinearAlgebra::InvertMatrix(b, a);
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
563 ASSERT_EQ(3u, b.size1());
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
564 ASSERT_EQ(3u, b.size2());
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
565
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
566 ASSERT_DOUBLE_EQ(-1, b(0, 0));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
567 ASSERT_DOUBLE_EQ(1, b(0, 1));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
568 ASSERT_DOUBLE_EQ(1, b(0, 2));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
569 ASSERT_DOUBLE_EQ(0, b(1, 0));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
570 ASSERT_DOUBLE_EQ(-0.5, b(1, 1));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
571 ASSERT_DOUBLE_EQ(0.5, b(1, 2));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
572 ASSERT_DOUBLE_EQ(1, b(2, 0));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
573 ASSERT_DOUBLE_EQ(0, b(2, 1));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
574 ASSERT_DOUBLE_EQ(-1, b(2, 2));
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
575 }
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
576
8c5b24892ed2 LinearAlgebra::InvertMatrix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 162
diff changeset
577
164
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
578 TEST(Matrix, Inverse4)
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
579 {
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
580 OrthancStone::Matrix a, b;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
581 a.resize(4, 4);
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
582 a(0, 0) = 2;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
583 a(0, 1) = 1;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
584 a(0, 2) = 2;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
585 a(0, 3) = -3;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
586 a(1, 0) = -2;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
587 a(1, 1) = 2;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
588 a(1, 2) = -1;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
589 a(1, 3) = -1;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
590 a(2, 0) = 2;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
591 a(2, 1) = 2;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
592 a(2, 2) = -3;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
593 a(2, 3) = -1;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
594 a(3, 0) = 3;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
595 a(3, 1) = -2;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
596 a(3, 2) = -3;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
597 a(3, 3) = -1;
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
598
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
599 OrthancStone::LinearAlgebra::InvertMatrix(b, a);
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
600 ASSERT_EQ(4u, b.size1());
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
601 ASSERT_EQ(4u, b.size2());
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
602
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
603 b *= 134.0; // This is the determinant
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
604
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
605 ASSERT_DOUBLE_EQ(8, b(0, 0));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
606 ASSERT_DOUBLE_EQ(-44, b(0, 1));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
607 ASSERT_DOUBLE_EQ(30, b(0, 2));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
608 ASSERT_DOUBLE_EQ(-10, b(0, 3));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
609 ASSERT_DOUBLE_EQ(2, b(1, 0));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
610 ASSERT_DOUBLE_EQ(-11, b(1, 1));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
611 ASSERT_DOUBLE_EQ(41, b(1, 2));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
612 ASSERT_DOUBLE_EQ(-36, b(1, 3));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
613 ASSERT_DOUBLE_EQ(16, b(2, 0));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
614 ASSERT_DOUBLE_EQ(-21, b(2, 1));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
615 ASSERT_DOUBLE_EQ(-7, b(2, 2));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
616 ASSERT_DOUBLE_EQ(-20, b(2, 3));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
617 ASSERT_DOUBLE_EQ(-28, b(3, 0));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
618 ASSERT_DOUBLE_EQ(-47, b(3, 1));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
619 ASSERT_DOUBLE_EQ(29, b(3, 2));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
620 ASSERT_DOUBLE_EQ(-32, b(3, 3));
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
621 }
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
622
432b1f812d14 inversion of general matrices
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
623
188
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
624 TEST(FiniteProjectiveCamera, Calibration)
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
625 {
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
626 unsigned int volumeWidth = 512;
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
627 unsigned int volumeHeight = 512;
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
628 unsigned int volumeDepth = 110;
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
629
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
630 OrthancStone::Vector camera = OrthancStone::LinearAlgebra::CreateVector
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
631 (-1000, -5000, -static_cast<double>(volumeDepth) * 32);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
632
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
633 OrthancStone::Vector principalPoint = OrthancStone::LinearAlgebra::CreateVector
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
634 (volumeWidth/2, volumeHeight/2, volumeDepth * 2);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
635
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
636 OrthancStone::FiniteProjectiveCamera c(camera, principalPoint, 0, 512, 512, 1, 1);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
637
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
638 double swapv[9] = { 1, 0, 0,
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
639 0, -1, 512,
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
640 0, 0, 1 };
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
641 OrthancStone::Matrix swap;
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
642 OrthancStone::LinearAlgebra::FillMatrix(swap, 3, 3, swapv);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
643
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
644 OrthancStone::Matrix p = OrthancStone::LinearAlgebra::Product(swap, c.GetMatrix());
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
645 p /= p(2,3);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
646
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
647 ASSERT_NEAR( 1.04437, p(0,0), 0.00001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
648 ASSERT_NEAR(-0.0703111, p(0,1), 0.00000001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
649 ASSERT_NEAR(-0.179283, p(0,2), 0.000001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
650 ASSERT_NEAR( 61.7431, p(0,3), 0.0001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
651 ASSERT_NEAR( 0.11127, p(1,0), 0.000001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
652 ASSERT_NEAR(-0.595541, p(1,1), 0.000001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
653 ASSERT_NEAR( 0.872211, p(1,2), 0.000001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
654 ASSERT_NEAR( 203.748, p(1,3), 0.001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
655 ASSERT_NEAR( 3.08593e-05, p(2,0), 0.0000000001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
656 ASSERT_NEAR( 0.000129138, p(2,1), 0.000000001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
657 ASSERT_NEAR( 9.18901e-05, p(2,2), 0.0000000001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
658 ASSERT_NEAR( 1, p(2,3), 0.0000001);
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
659 }
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
660
45b03b04a777 calibration of FiniteProjectiveCamera
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
661
189
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
662 static bool IsEqualVector(OrthancStone::Vector a,
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
663 OrthancStone::Vector b)
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
664 {
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
665 if (a.size() == 3 &&
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
666 b.size() == 3)
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
667 {
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
668 OrthancStone::LinearAlgebra::NormalizeVector(a);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
669 OrthancStone::LinearAlgebra::NormalizeVector(b);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
670 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
671 }
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
672 else
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
673 {
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
674 return false;
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
675 }
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
676 }
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
677
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
678
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
679 TEST(GeometryToolbox, AlignVectorsWithRotation)
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
680 {
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
681 OrthancStone::Vector a, b;
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
682 OrthancStone::Matrix r;
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
683
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
684 OrthancStone::LinearAlgebra::AssignVector(a, -200, 200, -846.63);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
685 OrthancStone::LinearAlgebra::AssignVector(b, 0, 0, 1);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
686
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
687 OrthancStone::GeometryToolbox::AlignVectorsWithRotation(r, a, b);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
688 ASSERT_TRUE(OrthancStone::LinearAlgebra::IsRotationMatrix(r));
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
689 ASSERT_TRUE(IsEqualVector(OrthancStone::LinearAlgebra::Product(r, a), b));
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
690
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
691 OrthancStone::GeometryToolbox::AlignVectorsWithRotation(r, b, a);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
692 ASSERT_TRUE(OrthancStone::LinearAlgebra::IsRotationMatrix(r));
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
693 ASSERT_TRUE(IsEqualVector(OrthancStone::LinearAlgebra::Product(r, b), a));
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
694
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
695 OrthancStone::LinearAlgebra::AssignVector(a, 1, 0, 0);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
696 OrthancStone::LinearAlgebra::AssignVector(b, 0, 0, 1);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
697 OrthancStone::GeometryToolbox::AlignVectorsWithRotation(r, a, b);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
698 ASSERT_TRUE(OrthancStone::LinearAlgebra::IsRotationMatrix(r));
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
699 ASSERT_TRUE(IsEqualVector(OrthancStone::LinearAlgebra::Product(r, a), b));
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
700
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
701 OrthancStone::LinearAlgebra::AssignVector(a, 0, 1, 0);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
702 OrthancStone::LinearAlgebra::AssignVector(b, 0, 0, 1);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
703 OrthancStone::GeometryToolbox::AlignVectorsWithRotation(r, a, b);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
704 ASSERT_TRUE(OrthancStone::LinearAlgebra::IsRotationMatrix(r));
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
705 ASSERT_TRUE(IsEqualVector(OrthancStone::LinearAlgebra::Product(r, a), b));
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
706
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
707 OrthancStone::LinearAlgebra::AssignVector(a, 0, 0, 1);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
708 OrthancStone::LinearAlgebra::AssignVector(b, 0, 0, 1);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
709 OrthancStone::GeometryToolbox::AlignVectorsWithRotation(r, a, b);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
710 ASSERT_TRUE(OrthancStone::LinearAlgebra::IsRotationMatrix(r));
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
711 ASSERT_TRUE(IsEqualVector(OrthancStone::LinearAlgebra::Product(r, a), b));
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
712
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
713 OrthancStone::LinearAlgebra::AssignVector(a, 0, 0, 0);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
714 OrthancStone::LinearAlgebra::AssignVector(b, 0, 0, 1);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
715 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
716
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
717 // TODO: Deal with opposite vectors
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
718
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
719 /*
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
720 OrthancStone::LinearAlgebra::AssignVector(a, 0, 0, -1);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
721 OrthancStone::LinearAlgebra::AssignVector(b, 0, 0, 1);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
722 OrthancStone::GeometryToolbox::AlignVectorsWithRotation(r, a, b);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
723 OrthancStone::LinearAlgebra::Print(r);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
724 OrthancStone::LinearAlgebra::Print(boost::numeric::ublas::prod(r, a));
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
725 */
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
726 }
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
727
307
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 257
diff changeset
728 TEST(MessagingToolbox, ParseJson)
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 257
diff changeset
729 {
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 257
diff changeset
730 Json::Value response;
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 257
diff changeset
731 std::string source = "{\"command\":\"panel:takeDarkImage\",\"commandType\":\"simple\",\"args\":{}}";
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 257
diff changeset
732 ASSERT_TRUE(OrthancStone::MessagingToolbox::ParseJson(response, source.c_str(), source.size()));
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 257
diff changeset
733 }
20
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735 int main(int argc, char **argv)
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736 {
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737 Orthanc::Logging::Initialize();
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 Orthanc::Logging::EnableInfoLevel(true);
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740 ::testing::InitGoogleTest(&argc, argv);
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 int result = RUN_ALL_TESTS();
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743 Orthanc::Logging::Finalize();
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
745 return result;
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746 }