Mercurial > hg > orthanc
comparison UnitTestsSources/FromDcmtkTests.cpp @ 994:b3d4f8a30324 lua-scripting
integration mainline->lua-scripting
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 02 Jul 2014 14:42:49 +0200 |
parents | 2f76b92addd4 |
children | 6fd4434c1bcf |
comparison
equal
deleted
inserted
replaced
954:a91e7b4080d1 | 994:b3d4f8a30324 |
---|---|
1 /** | |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, | |
4 * Belgium | |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
22 * | |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
33 #include "PrecompiledHeadersUnitTests.h" | |
34 #include "gtest/gtest.h" | |
35 | |
36 #include "../OrthancServer/FromDcmtkBridge.h" | |
37 #include "../OrthancServer/OrthancInitialization.h" | |
38 #include "../OrthancServer/DicomModification.h" | |
39 #include "../Core/OrthancException.h" | |
40 #include "../Core/ImageFormats/ImageBuffer.h" | |
41 #include "../Core/ImageFormats/PngReader.h" | |
42 #include "../Core/ImageFormats/PngWriter.h" | |
43 #include "../Core/Uuid.h" | |
44 | |
45 using namespace Orthanc; | |
46 | |
47 TEST(DicomFormat, Tag) | |
48 { | |
49 ASSERT_EQ("PatientName", FromDcmtkBridge::GetName(DicomTag(0x0010, 0x0010))); | |
50 | |
51 DicomTag t = FromDcmtkBridge::ParseTag("SeriesDescription"); | |
52 ASSERT_EQ(0x0008, t.GetGroup()); | |
53 ASSERT_EQ(0x103E, t.GetElement()); | |
54 | |
55 t = FromDcmtkBridge::ParseTag("0020-e040"); | |
56 ASSERT_EQ(0x0020, t.GetGroup()); | |
57 ASSERT_EQ(0xe040, t.GetElement()); | |
58 | |
59 // Test ==() and !=() operators | |
60 ASSERT_TRUE(DICOM_TAG_PATIENT_ID == DicomTag(0x0010, 0x0020)); | |
61 ASSERT_FALSE(DICOM_TAG_PATIENT_ID != DicomTag(0x0010, 0x0020)); | |
62 } | |
63 | |
64 | |
65 TEST(DicomModification, Basic) | |
66 { | |
67 DicomModification m; | |
68 m.SetupAnonymization(); | |
69 //m.SetLevel(DicomRootLevel_Study); | |
70 //m.Replace(DICOM_TAG_PATIENT_ID, "coucou"); | |
71 //m.Replace(DICOM_TAG_PATIENT_NAME, "coucou"); | |
72 | |
73 ParsedDicomFile o; | |
74 o.SaveToFile("UnitTestsResults/anon.dcm"); | |
75 | |
76 for (int i = 0; i < 10; i++) | |
77 { | |
78 char b[1024]; | |
79 sprintf(b, "UnitTestsResults/anon%06d.dcm", i); | |
80 std::auto_ptr<ParsedDicomFile> f(o.Clone()); | |
81 if (i > 4) | |
82 o.Replace(DICOM_TAG_SERIES_INSTANCE_UID, "coucou"); | |
83 m.Apply(*f); | |
84 f->SaveToFile(b); | |
85 } | |
86 } | |
87 | |
88 | |
89 TEST(DicomModification, Anonymization) | |
90 { | |
91 const DicomTag privateTag(0x0045, 0x0010); | |
92 ASSERT_TRUE(FromDcmtkBridge::IsPrivateTag(privateTag)); | |
93 | |
94 ParsedDicomFile o; | |
95 o.Replace(DICOM_TAG_PATIENT_NAME, "coucou"); | |
96 o.Replace(privateTag, "private tag"); | |
97 | |
98 std::string s; | |
99 ASSERT_TRUE(o.GetTagValue(s, DICOM_TAG_PATIENT_NAME)); | |
100 ASSERT_FALSE(Toolbox::IsUuid(s)); | |
101 | |
102 DicomModification m; | |
103 m.SetupAnonymization(); | |
104 m.Keep(privateTag); | |
105 | |
106 m.Apply(o); | |
107 | |
108 ASSERT_TRUE(o.GetTagValue(s, DICOM_TAG_PATIENT_NAME)); | |
109 ASSERT_TRUE(Toolbox::IsUuid(s)); | |
110 ASSERT_TRUE(o.GetTagValue(s, privateTag)); | |
111 ASSERT_EQ("private tag", s); | |
112 | |
113 m.SetupAnonymization(); | |
114 m.Apply(o); | |
115 ASSERT_FALSE(o.GetTagValue(s, privateTag)); | |
116 } | |
117 | |
118 | |
119 #include <dcmtk/dcmdata/dcuid.h> | |
120 | |
121 TEST(DicomModification, Png) | |
122 { | |
123 // Red dot in http://en.wikipedia.org/wiki/Data_URI_scheme (RGBA image) | |
124 std::string s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="; | |
125 | |
126 std::string m, c; | |
127 Toolbox::DecodeDataUriScheme(m, c, s); | |
128 | |
129 ASSERT_EQ("image/png", m); | |
130 ASSERT_EQ(116, c.size()); | |
131 | |
132 std::string cc; | |
133 Toolbox::DecodeBase64(cc, c); | |
134 PngReader reader; | |
135 reader.ReadFromMemory(cc); | |
136 | |
137 ASSERT_EQ(5, reader.GetHeight()); | |
138 ASSERT_EQ(5, reader.GetWidth()); | |
139 ASSERT_EQ(PixelFormat_RGBA32, reader.GetFormat()); | |
140 | |
141 ParsedDicomFile o; | |
142 o.EmbedImage(s); | |
143 o.SaveToFile("UnitTestsResults/png1.dcm"); | |
144 | |
145 // Red dot, without alpha channel | |
146 s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDTcIn2+8BgAAACJJREFUCNdj/P//PwMjIwME/P/P+J8BBTAxEOL/R9Lx/z8AynoKAXOeiV8AAAAASUVORK5CYII="; | |
147 o.EmbedImage(s); | |
148 o.SaveToFile("UnitTestsResults/png2.dcm"); | |
149 | |
150 // Check box in Graylevel8 | |
151 s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDDcB53FulQAAAElJREFUGNNtj0sSAEEEQ1+U+185s1CtmRkblQ9CZldsKHJDk6DLGLJa6chjh0ooQmpjXMM86zPwydGEj6Ed/UGykkEM8X+p3u8/8LcOJIWLGeMAAAAASUVORK5CYII="; | |
152 o.EmbedImage(s); | |
153 //o.Replace(DICOM_TAG_SOP_CLASS_UID, UID_DigitalXRayImageStorageForProcessing); | |
154 o.SaveToFile("UnitTestsResults/png3.dcm"); | |
155 | |
156 | |
157 { | |
158 // Gradient in Graylevel16 | |
159 | |
160 ImageBuffer img; | |
161 img.SetWidth(256); | |
162 img.SetHeight(256); | |
163 img.SetFormat(PixelFormat_Grayscale16); | |
164 | |
165 int v = 0; | |
166 for (unsigned int y = 0; y < img.GetHeight(); y++) | |
167 { | |
168 uint16_t *p = reinterpret_cast<uint16_t*>(img.GetAccessor().GetRow(y)); | |
169 for (unsigned int x = 0; x < img.GetWidth(); x++, p++, v++) | |
170 { | |
171 *p = v; | |
172 } | |
173 } | |
174 | |
175 o.EmbedImage(img.GetAccessor()); | |
176 o.SaveToFile("UnitTestsResults/png4.dcm"); | |
177 } | |
178 } |