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