Mercurial > hg > orthanc
annotate UnitTestsSources/FromDcmtkTests.cpp @ 1118:3709c03ec9f0
ALLOW_DOWNLOADS for OS X builds
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 02 Sep 2014 23:13:59 +0200 |
parents | a66224eec125 |
children | 6e7e5ed91c2d |
rev | line source |
---|---|
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
1 /** |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
4 * Belgium |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
5 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
6 * This program is free software: you can redistribute it and/or |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
7 * modify it under the terms of the GNU General Public License as |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
8 * published by the Free Software Foundation, either version 3 of the |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
9 * License, or (at your option) any later version. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
10 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
11 * In addition, as a special exception, the copyright holders of this |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
12 * program give permission to link the code of its release with the |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
14 * that use the same license as the "OpenSSL" library), and distribute |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
15 * the linked executables. You must obey the GNU General Public License |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
16 * in all respects for all of the code used other than "OpenSSL". If you |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
17 * modify file(s) with this exception, you may extend this exception to |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
18 * your version of the file(s), but you are not obligated to do so. If |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
19 * you do not wish to do so, delete this exception statement from your |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
20 * version. If you delete this exception statement from all source files |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
21 * in the program, then also delete it here. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
22 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
23 * This program is distributed in the hope that it will be useful, but |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
24 * WITHOUT ANY WARRANTY; without even the implied warranty of |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
26 * General Public License for more details. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
27 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
28 * You should have received a copy of the GNU General Public License |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
30 **/ |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
31 |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
32 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
827
diff
changeset
|
33 #include "PrecompiledHeadersUnitTests.h" |
782 | 34 #include "gtest/gtest.h" |
35 | |
36 #include "../OrthancServer/FromDcmtkBridge.h" | |
37 #include "../OrthancServer/OrthancInitialization.h" | |
786 | 38 #include "../OrthancServer/DicomModification.h" |
784
efd0215736d9
start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
39 #include "../Core/OrthancException.h" |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
40 #include "../Core/ImageFormats/ImageBuffer.h" |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
41 #include "../Core/ImageFormats/PngReader.h" |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
42 #include "../Core/ImageFormats/PngWriter.h" |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
43 #include "../Core/Uuid.h" |
1088
6fd4434c1bcf
unit tests for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
44 #include "../Resources/EncodingTests.h" |
782 | 45 |
46 using namespace Orthanc; | |
47 | |
48 TEST(DicomFormat, Tag) | |
49 { | |
50 ASSERT_EQ("PatientName", FromDcmtkBridge::GetName(DicomTag(0x0010, 0x0010))); | |
51 | |
52 DicomTag t = FromDcmtkBridge::ParseTag("SeriesDescription"); | |
53 ASSERT_EQ(0x0008, t.GetGroup()); | |
54 ASSERT_EQ(0x103E, t.GetElement()); | |
55 | |
56 t = FromDcmtkBridge::ParseTag("0020-e040"); | |
57 ASSERT_EQ(0x0020, t.GetGroup()); | |
58 ASSERT_EQ(0xe040, t.GetElement()); | |
59 | |
60 // Test ==() and !=() operators | |
61 ASSERT_TRUE(DICOM_TAG_PATIENT_ID == DicomTag(0x0010, 0x0020)); | |
62 ASSERT_FALSE(DICOM_TAG_PATIENT_ID != DicomTag(0x0010, 0x0020)); | |
63 } | |
64 | |
65 | |
784
efd0215736d9
start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
66 TEST(DicomModification, Basic) |
efd0215736d9
start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
67 { |
efd0215736d9
start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
68 DicomModification m; |
efd0215736d9
start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
69 m.SetupAnonymization(); |
efd0215736d9
start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
70 //m.SetLevel(DicomRootLevel_Study); |
efd0215736d9
start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
71 //m.Replace(DICOM_TAG_PATIENT_ID, "coucou"); |
efd0215736d9
start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
72 //m.Replace(DICOM_TAG_PATIENT_NAME, "coucou"); |
efd0215736d9
start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
73 |
efd0215736d9
start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
74 ParsedDicomFile o; |
803
4689e400e0fa
directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
802
diff
changeset
|
75 o.SaveToFile("UnitTestsResults/anon.dcm"); |
784
efd0215736d9
start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
76 |
efd0215736d9
start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
77 for (int i = 0; i < 10; i++) |
efd0215736d9
start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
78 { |
efd0215736d9
start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
79 char b[1024]; |
803
4689e400e0fa
directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
802
diff
changeset
|
80 sprintf(b, "UnitTestsResults/anon%06d.dcm", i); |
784
efd0215736d9
start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
81 std::auto_ptr<ParsedDicomFile> f(o.Clone()); |
efd0215736d9
start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
82 if (i > 4) |
efd0215736d9
start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
83 o.Replace(DICOM_TAG_SERIES_INSTANCE_UID, "coucou"); |
efd0215736d9
start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
84 m.Apply(*f); |
efd0215736d9
start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
85 f->SaveToFile(b); |
efd0215736d9
start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
86 } |
efd0215736d9
start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
87 } |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
88 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
89 |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
90 TEST(DicomModification, Anonymization) |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
91 { |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
92 const DicomTag privateTag(0x0045, 0x0010); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
93 ASSERT_TRUE(FromDcmtkBridge::IsPrivateTag(privateTag)); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
94 |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
95 ParsedDicomFile o; |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
96 o.Replace(DICOM_TAG_PATIENT_NAME, "coucou"); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
97 o.Replace(privateTag, "private tag"); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
98 |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
99 std::string s; |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
100 ASSERT_TRUE(o.GetTagValue(s, DICOM_TAG_PATIENT_NAME)); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
101 ASSERT_FALSE(Toolbox::IsUuid(s)); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
102 |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
103 DicomModification m; |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
104 m.SetupAnonymization(); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
105 m.Keep(privateTag); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
106 |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
107 m.Apply(o); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
108 |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
109 ASSERT_TRUE(o.GetTagValue(s, DICOM_TAG_PATIENT_NAME)); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
110 ASSERT_TRUE(Toolbox::IsUuid(s)); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
111 ASSERT_TRUE(o.GetTagValue(s, privateTag)); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
112 ASSERT_EQ("private tag", s); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
113 |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
114 m.SetupAnonymization(); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
115 m.Apply(o); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
116 ASSERT_FALSE(o.GetTagValue(s, privateTag)); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
117 } |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
118 |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
119 |
802 | 120 #include <dcmtk/dcmdata/dcuid.h> |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
121 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
122 TEST(DicomModification, Png) |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
123 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
124 // Red dot in http://en.wikipedia.org/wiki/Data_URI_scheme (RGBA image) |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
125 std::string s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
126 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
127 std::string m, c; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
128 Toolbox::DecodeDataUriScheme(m, c, s); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
129 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
130 ASSERT_EQ("image/png", m); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
131 ASSERT_EQ(116, c.size()); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
132 |
809
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
804
diff
changeset
|
133 std::string cc; |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
804
diff
changeset
|
134 Toolbox::DecodeBase64(cc, c); |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
135 PngReader reader; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
136 reader.ReadFromMemory(cc); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
137 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
138 ASSERT_EQ(5, reader.GetHeight()); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
139 ASSERT_EQ(5, reader.GetWidth()); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
140 ASSERT_EQ(PixelFormat_RGBA32, reader.GetFormat()); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
141 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
142 ParsedDicomFile o; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
143 o.EmbedImage(s); |
803
4689e400e0fa
directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
802
diff
changeset
|
144 o.SaveToFile("UnitTestsResults/png1.dcm"); |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
145 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
146 // Red dot, without alpha channel |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
147 s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDTcIn2+8BgAAACJJREFUCNdj/P//PwMjIwME/P/P+J8BBTAxEOL/R9Lx/z8AynoKAXOeiV8AAAAASUVORK5CYII="; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
148 o.EmbedImage(s); |
803
4689e400e0fa
directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
802
diff
changeset
|
149 o.SaveToFile("UnitTestsResults/png2.dcm"); |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
150 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
151 // Check box in Graylevel8 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
152 s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDDcB53FulQAAAElJREFUGNNtj0sSAEEEQ1+U+185s1CtmRkblQ9CZldsKHJDk6DLGLJa6chjh0ooQmpjXMM86zPwydGEj6Ed/UGykkEM8X+p3u8/8LcOJIWLGeMAAAAASUVORK5CYII="; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
153 o.EmbedImage(s); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
154 //o.Replace(DICOM_TAG_SOP_CLASS_UID, UID_DigitalXRayImageStorageForProcessing); |
803
4689e400e0fa
directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
802
diff
changeset
|
155 o.SaveToFile("UnitTestsResults/png3.dcm"); |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
156 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
157 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
158 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
159 // Gradient in Graylevel16 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
160 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
161 ImageBuffer img; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
162 img.SetWidth(256); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
163 img.SetHeight(256); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
164 img.SetFormat(PixelFormat_Grayscale16); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
165 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
166 int v = 0; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
167 for (unsigned int y = 0; y < img.GetHeight(); y++) |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
168 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
169 uint16_t *p = reinterpret_cast<uint16_t*>(img.GetAccessor().GetRow(y)); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
170 for (unsigned int x = 0; x < img.GetWidth(); x++, p++, v++) |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
171 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
172 *p = v; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
173 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
174 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
175 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
176 o.EmbedImage(img.GetAccessor()); |
803
4689e400e0fa
directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
802
diff
changeset
|
177 o.SaveToFile("UnitTestsResults/png4.dcm"); |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
178 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
179 } |
1088
6fd4434c1bcf
unit tests for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
180 |
6fd4434c1bcf
unit tests for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
181 |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
182 TEST(FromDcmtkBridge, Encodings1) |
1088
6fd4434c1bcf
unit tests for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
183 { |
6fd4434c1bcf
unit tests for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
184 for (unsigned int i = 0; i < testEncodingsCount; i++) |
6fd4434c1bcf
unit tests for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
185 { |
6fd4434c1bcf
unit tests for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
186 std::string source(testEncodingsEncoded[i]); |
6fd4434c1bcf
unit tests for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
187 std::string expected(testEncodingsExpected[i]); |
6fd4434c1bcf
unit tests for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
188 std::string s = Toolbox::ConvertToUtf8(source, testEncodings[i]); |
1089 | 189 std::cout << EnumerationToString(testEncodings[i]) << std::endl; |
190 EXPECT_EQ(expected, s); | |
1088
6fd4434c1bcf
unit tests for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
191 } |
6fd4434c1bcf
unit tests for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
192 } |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
193 |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
194 |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
195 TEST(FromDcmtkBridge, Enumerations) |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
196 { |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
197 Encoding e; |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
198 |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
199 ASSERT_FALSE(GetDicomEncoding(e, "")); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
200 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 6")); ASSERT_EQ(Encoding_Utf8, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
201 |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
202 // http://www.dabsoft.ch/dicom/3/C.12.1.1.2/ - Table C.12-2 |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
203 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 100")); ASSERT_EQ(Encoding_Latin1, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
204 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 101")); ASSERT_EQ(Encoding_Latin2, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
205 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 109")); ASSERT_EQ(Encoding_Latin3, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
206 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 110")); ASSERT_EQ(Encoding_Latin4, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
207 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 144")); ASSERT_EQ(Encoding_Cyrillic, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
208 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 127")); ASSERT_EQ(Encoding_Arabic, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
209 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 126")); ASSERT_EQ(Encoding_Greek, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
210 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 138")); ASSERT_EQ(Encoding_Hebrew, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
211 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 148")); ASSERT_EQ(Encoding_Latin5, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
212 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 13")); ASSERT_EQ(Encoding_Japanese, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
213 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 166")); ASSERT_EQ(Encoding_Thai, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
214 |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
215 // http://www.dabsoft.ch/dicom/3/C.12.1.1.2/ - Table C.12-3 |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
216 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 6")); ASSERT_EQ(Encoding_Utf8, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
217 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 100")); ASSERT_EQ(Encoding_Latin1, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
218 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 101")); ASSERT_EQ(Encoding_Latin2, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
219 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 109")); ASSERT_EQ(Encoding_Latin3, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
220 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 110")); ASSERT_EQ(Encoding_Latin4, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
221 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 144")); ASSERT_EQ(Encoding_Cyrillic, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
222 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 127")); ASSERT_EQ(Encoding_Arabic, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
223 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 126")); ASSERT_EQ(Encoding_Greek, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
224 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 138")); ASSERT_EQ(Encoding_Hebrew, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
225 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 148")); ASSERT_EQ(Encoding_Latin5, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
226 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 13")); ASSERT_EQ(Encoding_Japanese, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
227 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 166")); ASSERT_EQ(Encoding_Thai, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
228 |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
229 // http://www.dabsoft.ch/dicom/3/C.12.1.1.2/ - Table C.12-4 |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
230 ASSERT_FALSE(GetDicomEncoding(e, "ISO 2022 IR 87")); //ASSERT_EQ(Encoding_JapaneseKanji, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
231 ASSERT_FALSE(GetDicomEncoding(e, "ISO 2022 IR 159")); //ASSERT_EQ(Encoding_JapaneseKanjiSupplementary, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
232 ASSERT_FALSE(GetDicomEncoding(e, "ISO 2022 IR 149")); //ASSERT_EQ(Encoding_Korean, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
233 |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
234 // http://www.dabsoft.ch/dicom/3/C.12.1.1.2/ - Table C.12-5 |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
235 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 192")); ASSERT_EQ(Encoding_Utf8, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
236 ASSERT_TRUE(GetDicomEncoding(e, "GB18030")); ASSERT_EQ(Encoding_Chinese, e); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
237 } |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
238 |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
239 |
1091 | 240 TEST(FromDcmtkBridge, Encodings3) |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
241 { |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
242 for (unsigned int i = 0; i < testEncodingsCount; i++) |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
243 { |
1091 | 244 std::cout << EnumerationToString(testEncodings[i]) << std::endl; |
245 std::string dicom; | |
246 | |
247 { | |
248 ParsedDicomFile f; | |
249 f.SetEncoding(testEncodings[i]); | |
250 f.Insert(DICOM_TAG_PATIENT_NAME, testEncodingsEncoded[i]); | |
251 f.SaveToMemoryBuffer(dicom); | |
252 } | |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
253 |
1091 | 254 { |
255 ParsedDicomFile g(dicom); | |
256 | |
257 if (testEncodings[i] != Encoding_Ascii) | |
258 { | |
259 ASSERT_EQ(testEncodings[i], g.GetEncoding()); | |
260 } | |
261 | |
262 std::string tag; | |
263 ASSERT_TRUE(g.GetTagValue(tag, DICOM_TAG_PATIENT_NAME)); | |
264 | |
265 std::string expected(); | |
266 ASSERT_EQ(std::string(testEncodingsExpected[i]), tag); | |
267 } | |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
268 } |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1089
diff
changeset
|
269 } |