comparison OrthancStone/UnitTestsSources/DicomTests.cpp @ 1877:a2955abe4c2e

skeleton for the RenderingPlugin
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 12 Jan 2022 08:23:38 +0100
parents UnitTestsSources/DicomTests.cpp@7053b8a0aaec
children 990f396484b1
comparison
equal deleted inserted replaced
1876:b1f510e601d2 1877:a2955abe4c2e
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
7 *
8 * This program is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation, either version 3 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
21 **/
22
23
24 #include <gtest/gtest.h>
25
26 #include "../Sources/Toolbox/DicomInstanceParameters.h"
27 #include "../Sources/Loaders/DicomSource.h"
28
29 #include <OrthancException.h>
30
31
32 static void SetupUids(Orthanc::DicomMap& m)
33 {
34 m.SetValue(Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, "my_study", false);
35 m.SetValue(Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, "my_series", false);
36 m.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "my_sop", false);
37 }
38
39
40 TEST(DicomInstanceParameters, Basic)
41 {
42 Orthanc::DicomMap m;
43 SetupUids(m);
44
45 std::unique_ptr<OrthancStone::DicomInstanceParameters> p;
46 p.reset(OrthancStone::DicomInstanceParameters(m).Clone());
47
48 ASSERT_TRUE(p->GetOrthancInstanceIdentifier().empty());
49 ASSERT_EQ(3u, p->GetTags().GetSize());
50 ASSERT_EQ("my_study", p->GetStudyInstanceUid());
51 ASSERT_EQ("my_series", p->GetSeriesInstanceUid());
52 ASSERT_EQ("my_sop", p->GetSopInstanceUid());
53 ASSERT_EQ(OrthancStone::SopClassUid_Other, p->GetSopClassUid());
54 ASSERT_EQ(1u, p->GetNumberOfFrames());
55 ASSERT_EQ(0u, p->GetWidth());
56 ASSERT_EQ(0u, p->GetHeight());
57 ASSERT_TRUE(OrthancStone::LinearAlgebra::IsCloseToZero(p->GetSliceThickness()));
58 ASSERT_FLOAT_EQ(1, p->GetPixelSpacingX());
59 ASSERT_FLOAT_EQ(1, p->GetPixelSpacingY());
60 ASSERT_FALSE(p->GetGeometry().IsValid());
61 ASSERT_THROW(p->GetImageInformation(), Orthanc::OrthancException);
62 ASSERT_FALSE(p->GetFrameGeometry(0).IsValid());
63 ASSERT_THROW(p->IsColor(), Orthanc::OrthancException); // Accesses DicomImageInformation
64 ASSERT_FALSE(p->HasRescale());
65 ASSERT_THROW(p->GetRescaleIntercept(), Orthanc::OrthancException);
66 ASSERT_THROW(p->GetRescaleSlope(), Orthanc::OrthancException);
67 ASSERT_EQ(0u, p->GetWindowingPresetsCount());
68 ASSERT_THROW(p->GetWindowingPresetCenter(0), Orthanc::OrthancException);
69 ASSERT_THROW(p->GetWindowingPresetWidth(0), Orthanc::OrthancException);
70
71 float c, w;
72 p->GetWindowingPresetsUnion(c, w);
73 ASSERT_FLOAT_EQ(128.0f, c);
74 ASSERT_FLOAT_EQ(256.0f, w);
75
76 ASSERT_THROW(p->GetExpectedPixelFormat(), Orthanc::OrthancException);
77 ASSERT_FALSE(p->HasIndexInSeries());
78 ASSERT_THROW(p->GetIndexInSeries(), Orthanc::OrthancException);
79 ASSERT_TRUE(p->GetDoseUnits().empty());
80 ASSERT_DOUBLE_EQ(1.0, p->GetDoseGridScaling());
81 ASSERT_DOUBLE_EQ(1.0, p->ApplyRescale(1.0));
82
83 double s;
84 ASSERT_FALSE(p->ComputeRegularSpacing(s));
85 ASSERT_TRUE(p->GetFrameOfReferenceUid().empty());
86 }
87
88
89 TEST(DicomInstanceParameters, Windowing)
90 {
91 Orthanc::DicomMap m;
92 SetupUids(m);
93 m.SetValue(Orthanc::DICOM_TAG_WINDOW_CENTER, "10\\100\\1000", false);
94 m.SetValue(Orthanc::DICOM_TAG_WINDOW_WIDTH, "50\\60\\70", false);
95
96 OrthancStone::DicomInstanceParameters p(m);
97 ASSERT_EQ(3u, p.GetWindowingPresetsCount());
98 ASSERT_FLOAT_EQ(10, p.GetWindowingPresetCenter(0));
99 ASSERT_FLOAT_EQ(100, p.GetWindowingPresetCenter(1));
100 ASSERT_FLOAT_EQ(1000, p.GetWindowingPresetCenter(2));
101 ASSERT_FLOAT_EQ(50, p.GetWindowingPresetWidth(0));
102 ASSERT_FLOAT_EQ(60, p.GetWindowingPresetWidth(1));
103 ASSERT_FLOAT_EQ(70, p.GetWindowingPresetWidth(2));
104
105 const float a = 10.0f - 50.0f / 2.0f;
106 const float b = 1000.0f + 70.0f / 2.0f;
107
108 float c, w;
109 p.GetWindowingPresetsUnion(c, w);
110 ASSERT_FLOAT_EQ((a + b) / 2.0f, c);
111 ASSERT_FLOAT_EQ(b - a, w);
112 }
113
114
115 TEST(DicomSource, Equality)
116 {
117 {
118 OrthancStone::DicomSource s1;
119
120 {
121 OrthancStone::DicomSource s2;
122 ASSERT_TRUE(s1.IsSameSource(s2));
123
124 s2.SetDicomDirSource();
125 ASSERT_FALSE(s1.IsSameSource(s2));
126
127 s2.SetDicomWebSource("toto");
128 ASSERT_FALSE(s1.IsSameSource(s2));
129
130 s2.SetDicomWebThroughOrthancSource("toto");
131 ASSERT_FALSE(s1.IsSameSource(s2));
132
133 s2.SetOrthancSource();
134 ASSERT_TRUE(s1.IsSameSource(s2));
135 }
136 }
137
138 {
139 OrthancStone::DicomSource s1;
140
141 {
142 Orthanc::WebServiceParameters p;
143 p.SetUrl("http://localhost:8042/");
144
145 OrthancStone::DicomSource s2;
146 s2.SetOrthancSource(p);
147 ASSERT_TRUE(s1.IsSameSource(s2));
148
149 p.SetCredentials("toto", "tutu");
150 s2.SetOrthancSource(p);
151 ASSERT_FALSE(s1.IsSameSource(s2));
152
153 p.ClearCredentials();
154 s2.SetOrthancSource(p);
155 ASSERT_TRUE(s1.IsSameSource(s2));
156
157 p.SetUrl("http://localhost:8043/");
158 s2.SetOrthancSource(p);
159 ASSERT_FALSE(s1.IsSameSource(s2));
160 }
161 }
162
163 {
164 OrthancStone::DicomSource s1;
165 s1.SetDicomDirSource();
166
167 {
168 OrthancStone::DicomSource s2;
169 ASSERT_FALSE(s1.IsSameSource(s2));
170
171 s2.SetDicomDirSource();
172 ASSERT_TRUE(s1.IsSameSource(s2));
173
174 s2.SetDicomWebSource("toto");
175 ASSERT_FALSE(s1.IsSameSource(s2));
176
177 s2.SetDicomWebThroughOrthancSource("toto");
178 ASSERT_FALSE(s1.IsSameSource(s2));
179 }
180 }
181
182 {
183 OrthancStone::DicomSource s1;
184 s1.SetDicomWebSource("http");
185
186 {
187 OrthancStone::DicomSource s2;
188 ASSERT_FALSE(s1.IsSameSource(s2));
189
190 s2.SetDicomDirSource();
191 ASSERT_FALSE(s1.IsSameSource(s2));
192
193 s2.SetDicomWebSource("http");
194 ASSERT_TRUE(s1.IsSameSource(s2));
195
196 s2.SetDicomWebSource("http2");
197 ASSERT_FALSE(s1.IsSameSource(s2));
198
199 s2.SetDicomWebThroughOrthancSource("toto");
200 ASSERT_FALSE(s1.IsSameSource(s2));
201 }
202 }
203
204 {
205 OrthancStone::DicomSource s1;
206 s1.SetDicomWebThroughOrthancSource("server");
207
208 {
209 OrthancStone::DicomSource s2;
210 ASSERT_FALSE(s1.IsSameSource(s2));
211
212 s2.SetDicomDirSource();
213 ASSERT_FALSE(s1.IsSameSource(s2));
214
215 s2.SetDicomWebSource("http");
216 ASSERT_FALSE(s1.IsSameSource(s2));
217
218 s2.SetDicomWebThroughOrthancSource("server");
219 ASSERT_TRUE(s1.IsSameSource(s2));
220
221 s2.SetDicomWebThroughOrthancSource("server2");
222 ASSERT_FALSE(s1.IsSameSource(s2));
223 }
224 }
225 }