Mercurial > hg > orthanc-stone
comparison UnitTestsSources/DicomTests.cpp @ 1679:5b8b88e5bfd6
successfully running unit tests in WebAssembly
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 24 Nov 2020 12:59:10 +0100 |
parents | |
children | c8d0ffb3047d |
comparison
equal
deleted
inserted
replaced
1678:1393e3393a0b | 1679:5b8b88e5bfd6 |
---|---|
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-2020 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include <gtest/gtest.h> | |
23 | |
24 #include "../OrthancStone/Sources/Toolbox/DicomInstanceParameters.h" | |
25 | |
26 #include <OrthancException.h> | |
27 | |
28 | |
29 static void SetupUids(Orthanc::DicomMap& m) | |
30 { | |
31 m.SetValue(Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, "my_study", false); | |
32 m.SetValue(Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, "my_series", false); | |
33 m.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "my_sop", false); | |
34 } | |
35 | |
36 | |
37 TEST(DicomInstanceParameters, Basic) | |
38 { | |
39 Orthanc::DicomMap m; | |
40 SetupUids(m); | |
41 | |
42 std::unique_ptr<OrthancStone::DicomInstanceParameters> p; | |
43 p.reset(OrthancStone::DicomInstanceParameters(m).Clone()); | |
44 | |
45 ASSERT_TRUE(p->GetOrthancInstanceIdentifier().empty()); | |
46 ASSERT_EQ(3u, p->GetTags().GetSize()); | |
47 ASSERT_EQ("my_study", p->GetStudyInstanceUid()); | |
48 ASSERT_EQ("my_series", p->GetSeriesInstanceUid()); | |
49 ASSERT_EQ("my_sop", p->GetSopInstanceUid()); | |
50 ASSERT_EQ(OrthancStone::SopClassUid_Other, p->GetSopClassUid()); | |
51 ASSERT_EQ(1u, p->GetNumberOfFrames()); | |
52 ASSERT_EQ(0u, p->GetWidth()); | |
53 ASSERT_EQ(0u, p->GetHeight()); | |
54 ASSERT_TRUE(OrthancStone::LinearAlgebra::IsCloseToZero(p->GetSliceThickness())); | |
55 ASSERT_FLOAT_EQ(1, p->GetPixelSpacingX()); | |
56 ASSERT_FLOAT_EQ(1, p->GetPixelSpacingY()); | |
57 ASSERT_FALSE(p->GetGeometry().IsValid()); | |
58 ASSERT_THROW(p->GetImageInformation(), Orthanc::OrthancException); | |
59 ASSERT_FALSE(p->GetFrameGeometry(0).IsValid()); | |
60 ASSERT_THROW(p->IsColor(), Orthanc::OrthancException); // Accesses DicomImageInformation | |
61 ASSERT_FALSE(p->HasRescale()); | |
62 ASSERT_THROW(p->GetRescaleIntercept(), Orthanc::OrthancException); | |
63 ASSERT_THROW(p->GetRescaleSlope(), Orthanc::OrthancException); | |
64 ASSERT_EQ(0u, p->GetWindowingPresetsCount()); | |
65 ASSERT_THROW(p->GetWindowingPresetCenter(0), Orthanc::OrthancException); | |
66 ASSERT_THROW(p->GetWindowingPresetWidth(0), Orthanc::OrthancException); | |
67 | |
68 float c, w; | |
69 p->GetWindowingPresetsUnion(c, w); | |
70 ASSERT_FLOAT_EQ(128.0f, c); | |
71 ASSERT_FLOAT_EQ(256.0f, w); | |
72 | |
73 ASSERT_THROW(p->GetExpectedPixelFormat(), Orthanc::OrthancException); | |
74 ASSERT_FALSE(p->HasIndexInSeries()); | |
75 ASSERT_THROW(p->GetIndexInSeries(), Orthanc::OrthancException); | |
76 ASSERT_TRUE(p->GetDoseUnits().empty()); | |
77 ASSERT_DOUBLE_EQ(1.0, p->GetDoseGridScaling()); | |
78 ASSERT_DOUBLE_EQ(1.0, p->ApplyRescale(1.0)); | |
79 | |
80 double s; | |
81 ASSERT_FALSE(p->ComputeRegularSpacing(s)); | |
82 ASSERT_TRUE(p->GetFrameOfReferenceUid().empty()); | |
83 } | |
84 | |
85 | |
86 TEST(DicomInstanceParameters, Windowing) | |
87 { | |
88 Orthanc::DicomMap m; | |
89 SetupUids(m); | |
90 m.SetValue(Orthanc::DICOM_TAG_WINDOW_CENTER, "10\\100\\1000", false); | |
91 m.SetValue(Orthanc::DICOM_TAG_WINDOW_WIDTH, "50\\60\\70", false); | |
92 | |
93 OrthancStone::DicomInstanceParameters p(m); | |
94 ASSERT_EQ(3u, p.GetWindowingPresetsCount()); | |
95 ASSERT_FLOAT_EQ(10, p.GetWindowingPresetCenter(0)); | |
96 ASSERT_FLOAT_EQ(100, p.GetWindowingPresetCenter(1)); | |
97 ASSERT_FLOAT_EQ(1000, p.GetWindowingPresetCenter(2)); | |
98 ASSERT_FLOAT_EQ(50, p.GetWindowingPresetWidth(0)); | |
99 ASSERT_FLOAT_EQ(60, p.GetWindowingPresetWidth(1)); | |
100 ASSERT_FLOAT_EQ(70, p.GetWindowingPresetWidth(2)); | |
101 | |
102 const float a = 10.0f - 50.0f / 2.0f; | |
103 const float b = 1000.0f + 70.0f / 2.0f; | |
104 | |
105 float c, w; | |
106 p.GetWindowingPresetsUnion(c, w); | |
107 ASSERT_FLOAT_EQ((a + b) / 2.0f, c); | |
108 ASSERT_FLOAT_EQ(b - a, w); | |
109 } |