annotate OrthancFramework/UnitTestsSources/DicomMapTests.cpp @ 4215:28e9457dc7ab

working on sequences
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 29 Sep 2020 16:30:24 +0200
parents 7b011cfda135
children 61585d8a9faf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 711
diff changeset
1 /**
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 711
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1850
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
4 * Department, University Hospital of Liege, Belgium
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3581
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 711
diff changeset
6 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 711
diff changeset
7 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
10 * the License, or (at your option) any later version.
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 711
diff changeset
11 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 711
diff changeset
12 * 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: 711
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 711
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
15 * Lesser General Public License for more details.
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 711
diff changeset
16 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
18 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
19 * <http://www.gnu.org/licenses/>.
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 711
diff changeset
20 **/
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 711
diff changeset
21
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 711
diff changeset
22
4057
8b7cd69806f2 move DicomMapTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
23 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK == 1
4063
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
24 // Must be the first to be sure to use the Orthanc framework shared library
4057
8b7cd69806f2 move DicomMapTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
25 # include <OrthancFramework.h>
8b7cd69806f2 move DicomMapTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
26 #endif
8b7cd69806f2 move DicomMapTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
27
4063
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
28 #if !defined(DCMTK_VERSION_NUMBER)
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
29 # error DCMTK_VERSION_NUMBER is not defined
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
30 #endif
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
31
4062
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4057
diff changeset
32 #include <gtest/gtest.h>
711
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
4057
8b7cd69806f2 move DicomMapTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
34 #include "../Sources/Compatibility.h"
8b7cd69806f2 move DicomMapTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
35 #include "../Sources/OrthancException.h"
8b7cd69806f2 move DicomMapTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
36 #include "../Sources/DicomFormat/DicomMap.h"
8b7cd69806f2 move DicomMapTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
37 #include "../Sources/DicomParsing/FromDcmtkBridge.h"
8b7cd69806f2 move DicomMapTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
38 #include "../Sources/DicomParsing/ToDcmtkBridge.h"
8b7cd69806f2 move DicomMapTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
39 #include "../Sources/DicomParsing/ParsedDicomFile.h"
8b7cd69806f2 move DicomMapTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
40 #include "../Sources/DicomParsing/DicomWebJsonVisitor.h"
711
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 using namespace Orthanc;
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 TEST(DicomMap, MainTags)
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_PATIENT_ID));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_PATIENT_ID, ResourceType_Patient));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 ASSERT_FALSE(DicomMap::IsMainDicomTag(DICOM_TAG_PATIENT_ID, ResourceType_Study));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_STUDY_INSTANCE_UID));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_ACCESSION_NUMBER));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_SERIES_INSTANCE_UID));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_SOP_INSTANCE_UID));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 std::set<DicomTag> s;
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 DicomMap::GetMainDicomTags(s);
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_PATIENT_ID));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_STUDY_INSTANCE_UID));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_ACCESSION_NUMBER));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_SERIES_INSTANCE_UID));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_SOP_INSTANCE_UID));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 DicomMap::GetMainDicomTags(s, ResourceType_Patient);
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_PATIENT_ID));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 ASSERT_TRUE(s.end() == s.find(DICOM_TAG_STUDY_INSTANCE_UID));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 DicomMap::GetMainDicomTags(s, ResourceType_Study);
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_STUDY_INSTANCE_UID));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_ACCESSION_NUMBER));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 ASSERT_TRUE(s.end() == s.find(DICOM_TAG_PATIENT_ID));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 DicomMap::GetMainDicomTags(s, ResourceType_Series);
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_SERIES_INSTANCE_UID));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 ASSERT_TRUE(s.end() == s.find(DICOM_TAG_PATIENT_ID));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 DicomMap::GetMainDicomTags(s, ResourceType_Instance);
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_SOP_INSTANCE_UID));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 ASSERT_TRUE(s.end() == s.find(DICOM_TAG_PATIENT_ID));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 TEST(DicomMap, Tags)
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
85 std::set<DicomTag> s;
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
86
711
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 DicomMap m;
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
88 m.GetTags(s);
1492
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1368
diff changeset
89 ASSERT_EQ(0u, s.size());
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
90
711
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 ASSERT_FALSE(m.HasTag(DICOM_TAG_PATIENT_NAME));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 ASSERT_FALSE(m.HasTag(0x0010, 0x0010));
2007
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
93 m.SetValue(0x0010, 0x0010, "PatientName", false);
711
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 ASSERT_TRUE(m.HasTag(DICOM_TAG_PATIENT_NAME));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 ASSERT_TRUE(m.HasTag(0x0010, 0x0010));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
97 m.GetTags(s);
1492
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1368
diff changeset
98 ASSERT_EQ(1u, s.size());
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
99 ASSERT_EQ(DICOM_TAG_PATIENT_NAME, *s.begin());
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
100
711
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 ASSERT_FALSE(m.HasTag(DICOM_TAG_PATIENT_ID));
2007
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
102 m.SetValue(DICOM_TAG_PATIENT_ID, "PatientID", false);
711
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 ASSERT_TRUE(m.HasTag(0x0010, 0x0020));
2007
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
104 m.SetValue(DICOM_TAG_PATIENT_ID, "PatientID2", false);
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1704
diff changeset
105 ASSERT_EQ("PatientID2", m.GetValue(0x0010, 0x0020).GetContent());
711
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
107 m.GetTags(s);
1492
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1368
diff changeset
108 ASSERT_EQ(2u, s.size());
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
109
711
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 m.Remove(DICOM_TAG_PATIENT_ID);
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 ASSERT_THROW(m.GetValue(0x0010, 0x0020), OrthancException);
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
113 m.GetTags(s);
1492
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1368
diff changeset
114 ASSERT_EQ(1u, s.size());
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
115 ASSERT_EQ(DICOM_TAG_PATIENT_NAME, *s.begin());
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
116
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3694
diff changeset
117 std::unique_ptr<DicomMap> mm(m.Clone());
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1704
diff changeset
118 ASSERT_EQ("PatientName", mm->GetValue(DICOM_TAG_PATIENT_NAME).GetContent());
711
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
2007
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
120 m.SetValue(DICOM_TAG_PATIENT_ID, "Hello", false);
711
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 ASSERT_THROW(mm->GetValue(DICOM_TAG_PATIENT_ID), OrthancException);
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 mm->CopyTagIfExists(m, DICOM_TAG_PATIENT_ID);
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1704
diff changeset
123 ASSERT_EQ("Hello", mm->GetValue(DICOM_TAG_PATIENT_ID).GetContent());
711
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1704
diff changeset
125 DicomValue v;
711
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 ASSERT_TRUE(v.IsNull());
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 }
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 TEST(DicomMap, FindTemplates)
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 {
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 DicomMap m;
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 DicomMap::SetupFindPatientTemplate(m);
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 ASSERT_TRUE(m.HasTag(DICOM_TAG_PATIENT_ID));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 DicomMap::SetupFindStudyTemplate(m);
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 ASSERT_TRUE(m.HasTag(DICOM_TAG_STUDY_INSTANCE_UID));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 ASSERT_TRUE(m.HasTag(DICOM_TAG_ACCESSION_NUMBER));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 DicomMap::SetupFindSeriesTemplate(m);
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 ASSERT_TRUE(m.HasTag(DICOM_TAG_SERIES_INSTANCE_UID));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 DicomMap::SetupFindInstanceTemplate(m);
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 ASSERT_TRUE(m.HasTag(DICOM_TAG_SOP_INSTANCE_UID));
8f62e8d5a384 test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 }
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
147
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
148
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
149
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
150
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
151 static void TestModule(ResourceType level,
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
152 DicomModule module)
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
153 {
1848
e39716f71d67 new main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
154 // REFERENCE: DICOM PS3.3 2015c - Information Object Definitions
e39716f71d67 new main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
155 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html
e39716f71d67 new main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
156
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
157 std::set<DicomTag> moduleTags, main;
1368
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
158 DicomTag::AddTagsForModule(moduleTags, module);
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
159 DicomMap::GetMainDicomTags(main, level);
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
160
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
161 // The main dicom tags are a subset of the module
1304
7b6925b0890d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
162 for (std::set<DicomTag>::const_iterator it = main.begin(); it != main.end(); ++it)
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
163 {
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
164 bool ok = moduleTags.find(*it) != moduleTags.end();
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
165
1848
e39716f71d67 new main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
166 // Exceptions for the Study level
e39716f71d67 new main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
167 if (level == ResourceType_Study &&
e39716f71d67 new main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
168 (*it == DicomTag(0x0008, 0x0080) || /* InstitutionName, from Visit identification module, related to Visit */
e39716f71d67 new main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
169 *it == DicomTag(0x0032, 0x1032) || /* RequestingPhysician, from Imaging Service Request module, related to Study */
e39716f71d67 new main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
170 *it == DicomTag(0x0032, 0x1060))) /* RequestedProcedureDescription, from Requested Procedure module, related to Study */
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
171 {
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
172 ok = true;
1848
e39716f71d67 new main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
173 }
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
174
1849
6394a2f8f1e1 test main dicom tags at series level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1848
diff changeset
175 // Exceptions for the Series level
6394a2f8f1e1 test main dicom tags at series level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1848
diff changeset
176 if (level == ResourceType_Series &&
6394a2f8f1e1 test main dicom tags at series level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1848
diff changeset
177 (*it == DicomTag(0x0008, 0x0070) || /* Manufacturer, from General Equipment Module */
6394a2f8f1e1 test main dicom tags at series level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1848
diff changeset
178 *it == DicomTag(0x0008, 0x1010) || /* StationName, from General Equipment Module */
6394a2f8f1e1 test main dicom tags at series level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1848
diff changeset
179 *it == DicomTag(0x0018, 0x0024) || /* SequenceName, from MR Image Module (SIMPLIFICATION => Series) */
6394a2f8f1e1 test main dicom tags at series level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1848
diff changeset
180 *it == DicomTag(0x0018, 0x1090) || /* CardiacNumberOfImages, from MR Image Module (SIMPLIFICATION => Series) */
6394a2f8f1e1 test main dicom tags at series level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1848
diff changeset
181 *it == DicomTag(0x0020, 0x0037) || /* ImageOrientationPatient, from Image Plane Module (SIMPLIFICATION => Series) */
6394a2f8f1e1 test main dicom tags at series level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1848
diff changeset
182 *it == DicomTag(0x0020, 0x0105) || /* NumberOfTemporalPositions, from MR Image Module (SIMPLIFICATION => Series) */
6394a2f8f1e1 test main dicom tags at series level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1848
diff changeset
183 *it == DicomTag(0x0020, 0x1002) || /* ImagesInAcquisition, from General Image Module (SIMPLIFICATION => Series) */
6394a2f8f1e1 test main dicom tags at series level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1848
diff changeset
184 *it == DicomTag(0x0054, 0x0081) || /* NumberOfSlices, from PET Series module */
6394a2f8f1e1 test main dicom tags at series level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1848
diff changeset
185 *it == DicomTag(0x0054, 0x0101) || /* NumberOfTimeSlices, from PET Series module */
1850
68854412c7bc new main dicomtags: AcquisitionDeviceProcessingDescription and ContrastBolusAgent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1849
diff changeset
186 *it == DicomTag(0x0054, 0x1000) || /* SeriesType, from PET Series module */
68854412c7bc new main dicomtags: AcquisitionDeviceProcessingDescription and ContrastBolusAgent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1849
diff changeset
187 *it == DicomTag(0x0018, 0x1400) || /* AcquisitionDeviceProcessingDescription, from CR/X-Ray/DX/WholeSlideMicro Image (SIMPLIFICATION => Series) */
68854412c7bc new main dicomtags: AcquisitionDeviceProcessingDescription and ContrastBolusAgent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1849
diff changeset
188 *it == DicomTag(0x0018, 0x0010))) /* ContrastBolusAgent, from Contrast/Bolus module (SIMPLIFICATION => Series) */
1849
6394a2f8f1e1 test main dicom tags at series level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1848
diff changeset
189 {
6394a2f8f1e1 test main dicom tags at series level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1848
diff changeset
190 ok = true;
6394a2f8f1e1 test main dicom tags at series level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1848
diff changeset
191 }
6394a2f8f1e1 test main dicom tags at series level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1848
diff changeset
192
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
193 // Exceptions for the Instance level
1704
d2268c7a7ede fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
194 if (level == ResourceType_Instance &&
1848
e39716f71d67 new main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
195 (*it == DicomTag(0x0020, 0x0012) || /* AccessionNumber, from General Image module */
e39716f71d67 new main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
196 *it == DicomTag(0x0054, 0x1330) || /* ImageIndex, from PET Image module */
e39716f71d67 new main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
197 *it == DicomTag(0x0020, 0x0100) || /* TemporalPositionIdentifier, from MR Image module */
e39716f71d67 new main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
198 *it == DicomTag(0x0028, 0x0008) || /* NumberOfFrames, from Multi-frame module attributes, related to Image */
e39716f71d67 new main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
199 *it == DicomTag(0x0020, 0x0032) || /* ImagePositionPatient, from Image Plan module, related to Image */
2804
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
200 *it == DicomTag(0x0020, 0x0037) || /* ImageOrientationPatient, from Image Plane Module (Orthanc 1.4.2) */
1848
e39716f71d67 new main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
201 *it == DicomTag(0x0020, 0x4000))) /* ImageComments, from General Image module */
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
202 {
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
203 ok = true;
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
204 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
205
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
206 if (!ok)
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
207 {
2115
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2007
diff changeset
208 std::cout << it->Format() << ": " << FromDcmtkBridge::GetTagName(*it, "")
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
209 << " not expected at level " << EnumerationToString(level) << std::endl;
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
210 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
211
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
212 EXPECT_TRUE(ok);
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
213 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
214 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
215
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
216
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
217 TEST(DicomMap, Modules)
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
218 {
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
219 TestModule(ResourceType_Patient, DicomModule_Patient);
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
220 TestModule(ResourceType_Study, DicomModule_Study);
1849
6394a2f8f1e1 test main dicom tags at series level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1848
diff changeset
221 TestModule(ResourceType_Series, DicomModule_Series); // TODO
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
222 TestModule(ResourceType_Instance, DicomModule_Instance);
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
223 }
2410
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
224
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
225
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
226 TEST(DicomMap, Parse)
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
227 {
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
228 DicomMap m;
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
229 float f;
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
230 double d;
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
231 int32_t i;
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
232 int64_t j;
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
233 uint32_t k;
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
234 uint64_t l;
3519
fc26659493b6 added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents: 3497
diff changeset
235 unsigned int ui;
2412
cad393b41bc3 handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2410
diff changeset
236 std::string s;
2410
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
237
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
238 m.SetValue(DICOM_TAG_PATIENT_NAME, " ", false); // Empty value
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
239 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseFloat(f));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
240 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseDouble(d));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
241 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger32(i));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
242 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger64(j));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
243 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger32(k));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
244 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger64(l));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
245
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
246 m.SetValue(DICOM_TAG_PATIENT_NAME, "0", true); // Binary value
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
247 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseFloat(f));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
248 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseDouble(d));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
249 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger32(i));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
250 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger64(j));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
251 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger32(k));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
252 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger64(l));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
253
3518
a57c8163d9ae DicomMap::GetStringValue()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
254 ASSERT_FALSE(m.LookupStringValue(s, DICOM_TAG_PATIENT_NAME, false));
a57c8163d9ae DicomMap::GetStringValue()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
255 ASSERT_TRUE(m.LookupStringValue(s, DICOM_TAG_PATIENT_NAME, true));
2412
cad393b41bc3 handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2410
diff changeset
256 ASSERT_EQ("0", s);
cad393b41bc3 handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2410
diff changeset
257
cad393b41bc3 handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2410
diff changeset
258
2410
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
259 // 2**31-1
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
260 m.SetValue(DICOM_TAG_PATIENT_NAME, "2147483647", false);
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
261 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseFloat(f));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
262 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseDouble(d));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
263 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger32(i));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
264 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger64(j));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
265 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger32(k));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
266 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger64(l));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
267 ASSERT_FLOAT_EQ(2147483647.0f, f);
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
268 ASSERT_DOUBLE_EQ(2147483647.0, d);
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
269 ASSERT_EQ(2147483647, i);
2416
feb0d2dcfa9b try and fix compiler bugs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2412
diff changeset
270 ASSERT_EQ(2147483647ll, j);
2410
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
271 ASSERT_EQ(2147483647u, k);
2418
abc275c0a44d fix msvc 2008
jodogne
parents: 2416
diff changeset
272 ASSERT_EQ(2147483647ull, l);
2412
cad393b41bc3 handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2410
diff changeset
273
cad393b41bc3 handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2410
diff changeset
274 // Test shortcuts
cad393b41bc3 handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2410
diff changeset
275 m.SetValue(DICOM_TAG_PATIENT_NAME, "42", false);
cad393b41bc3 handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2410
diff changeset
276 ASSERT_TRUE(m.ParseFloat(f, DICOM_TAG_PATIENT_NAME));
cad393b41bc3 handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2410
diff changeset
277 ASSERT_TRUE(m.ParseDouble(d, DICOM_TAG_PATIENT_NAME));
cad393b41bc3 handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2410
diff changeset
278 ASSERT_TRUE(m.ParseInteger32(i, DICOM_TAG_PATIENT_NAME));
cad393b41bc3 handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2410
diff changeset
279 ASSERT_TRUE(m.ParseInteger64(j, DICOM_TAG_PATIENT_NAME));
cad393b41bc3 handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2410
diff changeset
280 ASSERT_TRUE(m.ParseUnsignedInteger32(k, DICOM_TAG_PATIENT_NAME));
cad393b41bc3 handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2410
diff changeset
281 ASSERT_TRUE(m.ParseUnsignedInteger64(l, DICOM_TAG_PATIENT_NAME));
cad393b41bc3 handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2410
diff changeset
282 ASSERT_FLOAT_EQ(42.0f, f);
cad393b41bc3 handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2410
diff changeset
283 ASSERT_DOUBLE_EQ(42.0, d);
cad393b41bc3 handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2410
diff changeset
284 ASSERT_EQ(42, i);
2416
feb0d2dcfa9b try and fix compiler bugs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2412
diff changeset
285 ASSERT_EQ(42ll, j);
2412
cad393b41bc3 handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2410
diff changeset
286 ASSERT_EQ(42u, k);
2418
abc275c0a44d fix msvc 2008
jodogne
parents: 2416
diff changeset
287 ASSERT_EQ(42ull, l);
2412
cad393b41bc3 handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2410
diff changeset
288
3518
a57c8163d9ae DicomMap::GetStringValue()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
289 ASSERT_TRUE(m.LookupStringValue(s, DICOM_TAG_PATIENT_NAME, false));
2412
cad393b41bc3 handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2410
diff changeset
290 ASSERT_EQ("42", s);
3518
a57c8163d9ae DicomMap::GetStringValue()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
291 ASSERT_TRUE(m.LookupStringValue(s, DICOM_TAG_PATIENT_NAME, true));
2412
cad393b41bc3 handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2410
diff changeset
292 ASSERT_EQ("42", s);
cad393b41bc3 handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2410
diff changeset
293
2410
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
294
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
295 // 2**31
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
296 m.SetValue(DICOM_TAG_PATIENT_NAME, "2147483648", false);
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
297 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseFloat(f));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
298 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseDouble(d));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
299 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger32(i));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
300 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger64(j));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
301 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger32(k));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
302 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger64(l));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
303 ASSERT_FLOAT_EQ(2147483648.0f, f);
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
304 ASSERT_DOUBLE_EQ(2147483648.0, d);
2416
feb0d2dcfa9b try and fix compiler bugs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2412
diff changeset
305 ASSERT_EQ(2147483648ll, j);
2410
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
306 ASSERT_EQ(2147483648u, k);
2418
abc275c0a44d fix msvc 2008
jodogne
parents: 2416
diff changeset
307 ASSERT_EQ(2147483648ull, l);
2410
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
308
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
309 // 2**32-1
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
310 m.SetValue(DICOM_TAG_PATIENT_NAME, "4294967295", false);
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
311 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseFloat(f));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
312 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseDouble(d));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
313 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger32(i));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
314 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger64(j));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
315 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger32(k));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
316 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger64(l));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
317 ASSERT_FLOAT_EQ(4294967295.0f, f);
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
318 ASSERT_DOUBLE_EQ(4294967295.0, d);
2416
feb0d2dcfa9b try and fix compiler bugs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2412
diff changeset
319 ASSERT_EQ(4294967295ll, j);
2410
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
320 ASSERT_EQ(4294967295u, k);
2418
abc275c0a44d fix msvc 2008
jodogne
parents: 2416
diff changeset
321 ASSERT_EQ(4294967295ull, l);
2410
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
322
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
323 // 2**32
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
324 m.SetValue(DICOM_TAG_PATIENT_NAME, "4294967296", false);
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
325 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseFloat(f));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
326 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseDouble(d));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
327 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger32(i));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
328 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger64(j));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
329 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger32(k));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
330 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger64(l));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
331 ASSERT_FLOAT_EQ(4294967296.0f, f);
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
332 ASSERT_DOUBLE_EQ(4294967296.0, d);
2416
feb0d2dcfa9b try and fix compiler bugs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2412
diff changeset
333 ASSERT_EQ(4294967296ll, j);
2418
abc275c0a44d fix msvc 2008
jodogne
parents: 2416
diff changeset
334 ASSERT_EQ(4294967296ull, l);
2410
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
335
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
336 m.SetValue(DICOM_TAG_PATIENT_NAME, "-1", false);
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
337 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseFloat(f));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
338 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseDouble(d));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
339 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger32(i));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
340 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger64(j));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
341 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger32(k));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
342 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger64(l));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
343 ASSERT_FLOAT_EQ(-1.0f, f);
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
344 ASSERT_DOUBLE_EQ(-1.0, d);
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
345 ASSERT_EQ(-1, i);
2416
feb0d2dcfa9b try and fix compiler bugs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2412
diff changeset
346 ASSERT_EQ(-1ll, j);
2410
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
347
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
348 // -2**31
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
349 m.SetValue(DICOM_TAG_PATIENT_NAME, "-2147483648", false);
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
350 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseFloat(f));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
351 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseDouble(d));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
352 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger32(i));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
353 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger64(j));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
354 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger32(k));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
355 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger64(l));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
356 ASSERT_FLOAT_EQ(-2147483648.0f, f);
2829
61fdb06e389a fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2804
diff changeset
357 ASSERT_DOUBLE_EQ(-2147483648.0, d);
61fdb06e389a fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2804
diff changeset
358 ASSERT_EQ(static_cast<int32_t>(-2147483648ll), i);
2416
feb0d2dcfa9b try and fix compiler bugs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2412
diff changeset
359 ASSERT_EQ(-2147483648ll, j);
2410
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
360
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
361 // -2**31 - 1
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
362 m.SetValue(DICOM_TAG_PATIENT_NAME, "-2147483649", false);
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
363 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseFloat(f));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
364 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseDouble(d));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
365 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger32(i));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
366 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger64(j));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
367 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger32(k));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
368 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger64(l));
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
369 ASSERT_FLOAT_EQ(-2147483649.0f, f);
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
370 ASSERT_DOUBLE_EQ(-2147483649.0, d);
2416
feb0d2dcfa9b try and fix compiler bugs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2412
diff changeset
371 ASSERT_EQ(-2147483649ll, j);
3519
fc26659493b6 added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents: 3497
diff changeset
372
fc26659493b6 added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents: 3497
diff changeset
373
fc26659493b6 added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents: 3497
diff changeset
374 // "800\0" in US COLMUNS tag
fc26659493b6 added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents: 3497
diff changeset
375 m.SetValue(DICOM_TAG_COLUMNS, "800\0", false);
fc26659493b6 added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents: 3497
diff changeset
376 ASSERT_TRUE(m.GetValue(DICOM_TAG_COLUMNS).ParseFirstUnsignedInteger(ui));
3541
4beabcea3a5c Orthanc-1.5.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3520
diff changeset
377 ASSERT_EQ(800u, ui);
3519
fc26659493b6 added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents: 3497
diff changeset
378 m.SetValue(DICOM_TAG_COLUMNS, "800", false);
fc26659493b6 added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents: 3497
diff changeset
379 ASSERT_TRUE(m.GetValue(DICOM_TAG_COLUMNS).ParseFirstUnsignedInteger(ui));
3541
4beabcea3a5c Orthanc-1.5.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3520
diff changeset
380 ASSERT_EQ(800u, ui);
2410
3590c936e56f parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
381 }
2863
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
382
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
383
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
384 TEST(DicomMap, Serialize)
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
385 {
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
386 Json::Value s;
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
387
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
388 {
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
389 DicomMap m;
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
390 m.SetValue(DICOM_TAG_PATIENT_NAME, "Hello", false);
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
391 m.SetValue(DICOM_TAG_STUDY_DESCRIPTION, "Binary", true);
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
392 m.SetNullValue(DICOM_TAG_SERIES_DESCRIPTION);
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
393 m.Serialize(s);
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
394 }
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
395
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
396 {
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
397 DicomMap m;
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
398 m.Unserialize(s);
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
399
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
400 const DicomValue* v = m.TestAndGetValue(DICOM_TAG_ACCESSION_NUMBER);
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
401 ASSERT_TRUE(v == NULL);
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
402
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
403 v = m.TestAndGetValue(DICOM_TAG_PATIENT_NAME);
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
404 ASSERT_TRUE(v != NULL);
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
405 ASSERT_FALSE(v->IsNull());
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
406 ASSERT_FALSE(v->IsBinary());
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
407 ASSERT_EQ("Hello", v->GetContent());
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
408
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
409 v = m.TestAndGetValue(DICOM_TAG_STUDY_DESCRIPTION);
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
410 ASSERT_TRUE(v != NULL);
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
411 ASSERT_FALSE(v->IsNull());
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
412 ASSERT_TRUE(v->IsBinary());
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
413 ASSERT_EQ("Binary", v->GetContent());
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
414
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
415 v = m.TestAndGetValue(DICOM_TAG_SERIES_DESCRIPTION);
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
416 ASSERT_TRUE(v != NULL);
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
417 ASSERT_TRUE(v->IsNull());
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
418 ASSERT_FALSE(v->IsBinary());
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
419 ASSERT_THROW(v->GetContent(), OrthancException);
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
420 }
da12ba232119 serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2829
diff changeset
421 }
3005
8265a6b56100 DicomMap::FromDicomAsJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2863
diff changeset
422
8265a6b56100 DicomMap::FromDicomAsJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2863
diff changeset
423
8265a6b56100 DicomMap::FromDicomAsJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2863
diff changeset
424
3006
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
425 TEST(DicomMap, ExtractMainDicomTags)
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
426 {
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
427 DicomMap b;
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
428 b.SetValue(DICOM_TAG_PATIENT_NAME, "E", false);
3015
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3006
diff changeset
429 ASSERT_TRUE(b.HasOnlyMainDicomTags());
3006
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
430
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
431 {
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
432 DicomMap a;
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
433 a.SetValue(DICOM_TAG_PATIENT_NAME, "A", false);
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
434 a.SetValue(DICOM_TAG_STUDY_DESCRIPTION, "B", false);
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
435 a.SetValue(DICOM_TAG_SERIES_DESCRIPTION, "C", false);
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
436 a.SetValue(DICOM_TAG_NUMBER_OF_FRAMES, "D", false);
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
437 a.SetValue(DICOM_TAG_SLICE_THICKNESS, "F", false);
3015
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3006
diff changeset
438 ASSERT_FALSE(a.HasOnlyMainDicomTags());
3006
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
439 b.ExtractMainDicomTags(a);
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
440 }
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
441
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
442 ASSERT_EQ(4u, b.GetSize());
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
443 ASSERT_EQ("A", b.GetValue(DICOM_TAG_PATIENT_NAME).GetContent());
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
444 ASSERT_EQ("B", b.GetValue(DICOM_TAG_STUDY_DESCRIPTION).GetContent());
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
445 ASSERT_EQ("C", b.GetValue(DICOM_TAG_SERIES_DESCRIPTION).GetContent());
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
446 ASSERT_EQ("D", b.GetValue(DICOM_TAG_NUMBER_OF_FRAMES).GetContent());
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
447 ASSERT_FALSE(b.HasTag(DICOM_TAG_SLICE_THICKNESS));
3015
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3006
diff changeset
448 ASSERT_TRUE(b.HasOnlyMainDicomTags());
3006
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
449
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
450 b.SetValue(DICOM_TAG_PATIENT_NAME, "G", false);
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
451
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
452 {
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
453 DicomMap a;
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
454 a.SetValue(DICOM_TAG_PATIENT_NAME, "A", false);
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
455 a.SetValue(DICOM_TAG_SLICE_THICKNESS, "F", false);
3015
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3006
diff changeset
456 ASSERT_FALSE(a.HasOnlyMainDicomTags());
3006
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
457 b.Merge(a);
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
458 }
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
459
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
460 ASSERT_EQ(5u, b.GetSize());
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
461 ASSERT_EQ("G", b.GetValue(DICOM_TAG_PATIENT_NAME).GetContent());
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
462 ASSERT_EQ("B", b.GetValue(DICOM_TAG_STUDY_DESCRIPTION).GetContent());
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
463 ASSERT_EQ("C", b.GetValue(DICOM_TAG_SERIES_DESCRIPTION).GetContent());
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
464 ASSERT_EQ("D", b.GetValue(DICOM_TAG_NUMBER_OF_FRAMES).GetContent());
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
465 ASSERT_EQ("F", b.GetValue(DICOM_TAG_SLICE_THICKNESS).GetContent());
3015
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3006
diff changeset
466 ASSERT_FALSE(b.HasOnlyMainDicomTags());
3006
0e1755e5efd0 DicomMap::ExtractMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
467 }
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
468
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
469
3551
173c7f363d8f DicomMap::RemoveBinaryTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3541
diff changeset
470 TEST(DicomMap, RemoveBinary)
173c7f363d8f DicomMap::RemoveBinaryTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3541
diff changeset
471 {
173c7f363d8f DicomMap::RemoveBinaryTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3541
diff changeset
472 DicomMap b;
173c7f363d8f DicomMap::RemoveBinaryTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3541
diff changeset
473 b.SetValue(DICOM_TAG_PATIENT_NAME, "A", false);
173c7f363d8f DicomMap::RemoveBinaryTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3541
diff changeset
474 b.SetValue(DICOM_TAG_PATIENT_ID, "B", true);
173c7f363d8f DicomMap::RemoveBinaryTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3541
diff changeset
475 b.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, DicomValue()); // NULL
173c7f363d8f DicomMap::RemoveBinaryTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3541
diff changeset
476 b.SetValue(DICOM_TAG_SERIES_INSTANCE_UID, DicomValue("C", false));
173c7f363d8f DicomMap::RemoveBinaryTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3541
diff changeset
477 b.SetValue(DICOM_TAG_SOP_INSTANCE_UID, DicomValue("D", true));
173c7f363d8f DicomMap::RemoveBinaryTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3541
diff changeset
478
173c7f363d8f DicomMap::RemoveBinaryTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3541
diff changeset
479 b.RemoveBinaryTags();
173c7f363d8f DicomMap::RemoveBinaryTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3541
diff changeset
480
173c7f363d8f DicomMap::RemoveBinaryTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3541
diff changeset
481 std::string s;
173c7f363d8f DicomMap::RemoveBinaryTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3541
diff changeset
482 ASSERT_EQ(2u, b.GetSize());
173c7f363d8f DicomMap::RemoveBinaryTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3541
diff changeset
483 ASSERT_TRUE(b.LookupStringValue(s, DICOM_TAG_PATIENT_NAME, false)); ASSERT_EQ("A", s);
173c7f363d8f DicomMap::RemoveBinaryTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3541
diff changeset
484 ASSERT_TRUE(b.LookupStringValue(s, DICOM_TAG_SERIES_INSTANCE_UID, false)); ASSERT_EQ("C", s);
173c7f363d8f DicomMap::RemoveBinaryTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3541
diff changeset
485 }
173c7f363d8f DicomMap::RemoveBinaryTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3541
diff changeset
486
173c7f363d8f DicomMap::RemoveBinaryTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3541
diff changeset
487
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
488
3198
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
489 TEST(DicomWebJson, Multiplicity)
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
490 {
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
491 // http://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_F.2.4.html
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
492
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
493 ParsedDicomFile dicom(false);
3201
b69fe409cb4d dicomweb json to xml
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3200
diff changeset
494 dicom.ReplacePlainString(DICOM_TAG_PATIENT_NAME, "SB1^SB2^SB3^SB4^SB5");
3198
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
495 dicom.ReplacePlainString(DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "1\\2.3\\4");
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
496 dicom.ReplacePlainString(DICOM_TAG_IMAGE_POSITION_PATIENT, "");
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
497
3581
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
498 DicomWebJsonVisitor visitor;
3198
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
499 dicom.Apply(visitor);
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
500
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
501 {
3496
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
502 const Json::Value& tag = visitor.GetResult() ["00200037"]; // ImageOrientationPatient
3198
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
503 const Json::Value& value = tag["Value"];
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
504
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
505 ASSERT_EQ(EnumerationToString(ValueRepresentation_DecimalString), tag["vr"].asString());
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
506 ASSERT_EQ(2u, tag.getMemberNames().size());
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
507 ASSERT_EQ(3u, value.size());
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
508 ASSERT_EQ(Json::realValue, value[1].type());
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
509 ASSERT_FLOAT_EQ(1.0f, value[0].asFloat());
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
510 ASSERT_FLOAT_EQ(2.3f, value[1].asFloat());
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
511 ASSERT_FLOAT_EQ(4.0f, value[2].asFloat());
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
512 }
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
513
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
514 {
3496
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
515 const Json::Value& tag = visitor.GetResult() ["00200032"]; // ImagePositionPatient
3198
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
516 ASSERT_EQ(EnumerationToString(ValueRepresentation_DecimalString), tag["vr"].asString());
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
517 ASSERT_EQ(1u, tag.getMemberNames().size());
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
518 }
3201
b69fe409cb4d dicomweb json to xml
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3200
diff changeset
519
3203
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3202
diff changeset
520 std::string xml;
3201
b69fe409cb4d dicomweb json to xml
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3200
diff changeset
521 visitor.FormatXml(xml);
3496
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
522
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
523 {
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
524 DicomMap m;
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
525 m.FromDicomWeb(visitor.GetResult());
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
526 ASSERT_EQ(3u, m.GetSize());
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
527
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
528 std::string s;
3518
a57c8163d9ae DicomMap::GetStringValue()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
529 ASSERT_TRUE(m.LookupStringValue(s, DICOM_TAG_PATIENT_NAME, false));
3496
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
530 ASSERT_EQ("SB1^SB2^SB3^SB4^SB5", s);
3518
a57c8163d9ae DicomMap::GetStringValue()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
531 ASSERT_TRUE(m.LookupStringValue(s, DICOM_TAG_IMAGE_POSITION_PATIENT, false));
3496
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
532 ASSERT_TRUE(s.empty());
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
533
3518
a57c8163d9ae DicomMap::GetStringValue()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
534 ASSERT_TRUE(m.LookupStringValue(s, DICOM_TAG_IMAGE_ORIENTATION_PATIENT, false));
3496
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
535
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
536 std::vector<std::string> v;
3581
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
537 Toolbox::TokenizeString(v, s, '\\');
3496
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
538 ASSERT_FLOAT_EQ(1.0f, boost::lexical_cast<float>(v[0]));
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
539 ASSERT_FLOAT_EQ(2.3f, boost::lexical_cast<float>(v[1]));
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
540 ASSERT_FLOAT_EQ(4.0f, boost::lexical_cast<float>(v[2]));
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
541 }
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
542 }
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
543
3198
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
544
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
545 TEST(DicomWebJson, NullValue)
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
546 {
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
547 // http://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_F.2.5.html
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
548
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
549 ParsedDicomFile dicom(false);
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
550 dicom.ReplacePlainString(DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "1.5\\\\\\2.5");
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
551
3581
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
552 DicomWebJsonVisitor visitor;
3198
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
553 dicom.Apply(visitor);
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
554
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
555 {
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
556 const Json::Value& tag = visitor.GetResult() ["00200037"];
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
557 const Json::Value& value = tag["Value"];
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
558
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
559 ASSERT_EQ(EnumerationToString(ValueRepresentation_DecimalString), tag["vr"].asString());
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
560 ASSERT_EQ(2u, tag.getMemberNames().size());
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
561 ASSERT_EQ(4u, value.size());
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
562 ASSERT_EQ(Json::realValue, value[0].type());
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
563 ASSERT_EQ(Json::nullValue, value[1].type());
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
564 ASSERT_EQ(Json::nullValue, value[2].type());
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
565 ASSERT_EQ(Json::realValue, value[3].type());
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
566 ASSERT_FLOAT_EQ(1.5f, value[0].asFloat());
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
567 ASSERT_FLOAT_EQ(2.5f, value[3].asFloat());
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
568 }
3201
b69fe409cb4d dicomweb json to xml
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3200
diff changeset
569
3203
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3202
diff changeset
570 std::string xml;
3201
b69fe409cb4d dicomweb json to xml
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3200
diff changeset
571 visitor.FormatXml(xml);
3496
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
572
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
573 {
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
574 DicomMap m;
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
575 m.FromDicomWeb(visitor.GetResult());
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
576 ASSERT_EQ(1u, m.GetSize());
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
577
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
578 std::string s;
3518
a57c8163d9ae DicomMap::GetStringValue()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
579 ASSERT_TRUE(m.LookupStringValue(s, DICOM_TAG_IMAGE_ORIENTATION_PATIENT, false));
3496
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
580
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
581 std::vector<std::string> v;
3581
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
582 Toolbox::TokenizeString(v, s, '\\');
3496
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
583 ASSERT_FLOAT_EQ(1.5f, boost::lexical_cast<float>(v[0]));
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
584 ASSERT_TRUE(v[1].empty());
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
585 ASSERT_TRUE(v[2].empty());
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
586 ASSERT_FLOAT_EQ(2.5f, boost::lexical_cast<float>(v[3]));
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
587 }
3198
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
588 }
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
589
7724ed267b5c unit testing dicomweb conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3197
diff changeset
590
3581
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
591 TEST(DicomWebJson, PixelSpacing)
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
592 {
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
593 // Test related to locales: Make sure that decimal separator is
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
594 // correctly handled (dot "." vs comma ",")
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
595 ParsedDicomFile source(false);
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
596 source.ReplacePlainString(DICOM_TAG_PIXEL_SPACING, "1.5\\1.3");
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
597
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
598 DicomWebJsonVisitor visitor;
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
599 source.Apply(visitor);
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
600
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
601 DicomMap target;
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
602 target.FromDicomWeb(visitor.GetResult());
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
603
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
604 ASSERT_EQ("DS", visitor.GetResult() ["00280030"]["vr"].asString());
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
605 ASSERT_FLOAT_EQ(1.5f, visitor.GetResult() ["00280030"]["Value"][0].asFloat());
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
606 ASSERT_FLOAT_EQ(1.3f, visitor.GetResult() ["00280030"]["Value"][1].asFloat());
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
607
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
608 std::string s;
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
609 ASSERT_TRUE(target.LookupStringValue(s, DICOM_TAG_PIXEL_SPACING, false));
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
610 ASSERT_EQ(s, "1.5\\1.3");
4de1b019ca71 unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3551
diff changeset
611 }
3651
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
612
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
613
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
614 TEST(DicomMap, MainTagNames)
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
615 {
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
616 ASSERT_EQ(3, ResourceType_Instance - ResourceType_Patient);
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
617
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
618 for (int i = ResourceType_Patient; i <= ResourceType_Instance; i++)
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
619 {
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
620 ResourceType level = static_cast<ResourceType>(i);
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
621
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
622 std::set<DicomTag> tags;
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
623 DicomMap::GetMainDicomTags(tags, level);
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
624
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
625 for (std::set<DicomTag>::const_iterator it = tags.begin(); it != tags.end(); ++it)
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
626 {
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
627 DicomMap a;
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
628 a.SetValue(*it, "TEST", false);
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
629
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
630 Json::Value json;
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
631 a.DumpMainDicomTags(json, level);
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
632
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
633 ASSERT_EQ(Json::objectValue, json.type());
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
634 ASSERT_EQ(1u, json.getMemberNames().size());
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
635
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
636 std::string name = json.getMemberNames() [0];
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
637 EXPECT_EQ(name, FromDcmtkBridge::GetTagName(*it, ""));
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
638
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
639 DicomMap b;
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
640 b.ParseMainDicomTags(json, level);
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
641
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
642 ASSERT_EQ(1u, b.GetSize());
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
643 ASSERT_EQ("TEST", b.GetStringValue(*it, "", false));
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
644
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
645 std::string main = it->GetMainTagsName();
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
646 if (!main.empty())
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
647 {
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
648 ASSERT_EQ(main, name);
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
649 }
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
650 }
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
651 }
46cb00e4adbb DicomMap::DumpMainDicomTags() and DicomMap::ParseMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
652 }
4213
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
653
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
654
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
655
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
656
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
657 #include "../Sources/SystemToolbox.h"
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
658
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
659 TEST(DicomMap, DISABLED_ParseDicomMetaInformation)
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
660 {
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
661 static const std::string PATH = "/home/jodogne/Subversion/orthanc-tests/Database/TransferSyntaxes/";
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
662
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
663 std::map<std::string, DicomTransferSyntax> f;
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
664 f.insert(std::make_pair(PATH + "../ColorTestMalaterre.dcm", DicomTransferSyntax_LittleEndianImplicit)); // 1.2.840.10008.1.2
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
665 f.insert(std::make_pair(PATH + "1.2.840.10008.1.2.1.dcm", DicomTransferSyntax_LittleEndianExplicit));
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
666 f.insert(std::make_pair(PATH + "1.2.840.10008.1.2.2.dcm", DicomTransferSyntax_BigEndianExplicit));
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
667 f.insert(std::make_pair(PATH + "1.2.840.10008.1.2.4.50.dcm", DicomTransferSyntax_JPEGProcess1));
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
668 f.insert(std::make_pair(PATH + "1.2.840.10008.1.2.4.51.dcm", DicomTransferSyntax_JPEGProcess2_4));
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
669 f.insert(std::make_pair(PATH + "1.2.840.10008.1.2.4.57.dcm", DicomTransferSyntax_JPEGProcess14));
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
670 f.insert(std::make_pair(PATH + "1.2.840.10008.1.2.4.70.dcm", DicomTransferSyntax_JPEGProcess14SV1));
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
671 f.insert(std::make_pair(PATH + "1.2.840.10008.1.2.4.80.dcm", DicomTransferSyntax_JPEGLSLossless));
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
672 f.insert(std::make_pair(PATH + "1.2.840.10008.1.2.4.81.dcm", DicomTransferSyntax_JPEGLSLossy));
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
673 f.insert(std::make_pair(PATH + "1.2.840.10008.1.2.4.90.dcm", DicomTransferSyntax_JPEG2000LosslessOnly));
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
674 f.insert(std::make_pair(PATH + "1.2.840.10008.1.2.4.91.dcm", DicomTransferSyntax_JPEG2000));
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
675 f.insert(std::make_pair(PATH + "1.2.840.10008.1.2.5.dcm", DicomTransferSyntax_RLELossless));
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
676
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
677 for (std::map<std::string, DicomTransferSyntax>::const_iterator it = f.begin(); it != f.end(); ++it)
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
678 {
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
679 printf("\n== %s ==\n\n", it->first.c_str());
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
680
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
681 std::string dicom;
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
682 SystemToolbox::ReadFile(dicom, it->first, false);
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
683
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
684 DicomMap d;
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
685 ASSERT_TRUE(DicomMap::ParseDicomMetaInformation(d, dicom.c_str(), dicom.size()));
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
686 d.Print(stdout);
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
687
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
688 std::string s;
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
689 ASSERT_TRUE(d.LookupStringValue(s, DICOM_TAG_TRANSFER_SYNTAX_UID, false));
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
690
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
691 DicomTransferSyntax ts;
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
692 ASSERT_TRUE(LookupTransferSyntax(ts, s));
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
693 ASSERT_EQ(ts, it->second);
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
694 }
be2eca8b02e1 testing DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
695 }
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
696
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
697
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
698 namespace
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
699 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
700 class StreamBlockReader : public boost::noncopyable
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
701 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
702 private:
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
703 std::istream& stream_;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
704 std::string block_;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
705 size_t blockPos_;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
706 uint64_t processedBytes_;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
707
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
708 public:
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
709 StreamBlockReader(std::istream& stream) :
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
710 stream_(stream),
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
711 blockPos_(0),
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
712 processedBytes_(0)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
713 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
714 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
715
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
716 void Schedule(size_t blockSize)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
717 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
718 if (!block_.empty())
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
719 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
720 throw OrthancException(ErrorCode_BadSequenceOfCalls);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
721 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
722 else
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
723 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
724 block_.resize(blockSize);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
725 blockPos_ = 0;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
726 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
727 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
728
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
729 bool Read(std::string& block)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
730 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
731 if (block_.empty())
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
732 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
733 if (blockPos_ != 0)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
734 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
735 throw OrthancException(ErrorCode_BadSequenceOfCalls);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
736 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
737
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
738 block.clear();
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
739 return true;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
740 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
741 else
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
742 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
743 while (blockPos_ < block_.size())
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
744 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
745 char c;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
746 stream_.get(c);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
747
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
748 if (stream_.good())
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
749 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
750 block_[blockPos_] = c;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
751 blockPos_++;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
752 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
753 else
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
754 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
755 return false;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
756 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
757 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
758
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
759 processedBytes_ += block_.size();
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
760
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
761 block.swap(block_);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
762 block_.clear();
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
763 return true;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
764 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
765 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
766
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
767 uint64_t GetProcessedBytes() const
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
768 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
769 return processedBytes_;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
770 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
771 };
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
772
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
773
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
774
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
775
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
776 /**
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
777 * This class parses a stream containing a DICOM instance. It does
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
778 * *not* support the visit of sequences (it only works at the first
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
779 * level of the hierarchy), and it stops the processing once pixel
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
780 * data is reached in compressed transfer syntaxes.
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
781 **/
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
782 class DicomStreamReader : public boost::noncopyable
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
783 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
784 public:
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
785 class IVisitor : public boost::noncopyable
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
786 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
787 public:
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
788 virtual ~IVisitor()
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
789 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
790 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
791
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
792 // The data from this function will always be Little Endian (as
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
793 // specified by the DICOM standard)
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
794 virtual void VisitMetaHeaderTag(const DicomTag& tag,
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
795 const ValueRepresentation& vr,
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
796 const std::string& value) = 0;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
797
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
798 // Return "false" to stop processing
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
799 virtual bool VisitDatasetTag(const DicomTag& tag,
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
800 const ValueRepresentation& vr,
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
801 DicomTransferSyntax transferSyntax,
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
802 const std::string& value,
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
803 bool isLittleEndian) = 0;
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
804 };
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
805
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
806 private:
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
807 enum State
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
808 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
809 State_Preamble,
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
810 State_MetaHeader,
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
811 State_DatasetTag,
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
812 State_DatasetExplicitLength,
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
813 State_DatasetValue,
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
814 State_Done
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
815 };
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
816
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
817 StreamBlockReader reader_;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
818 State state_;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
819 DicomTransferSyntax transferSyntax_;
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
820 DicomTag previousTag_;
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
821 DicomTag danglingTag_;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
822 ValueRepresentation danglingVR_;
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
823 unsigned int sequenceDepth_;
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
824
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
825 static uint16_t ReadUnsignedInteger16(const char* dicom,
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
826 bool littleEndian)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
827 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
828 const uint8_t* p = reinterpret_cast<const uint8_t*>(dicom);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
829
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
830 if (littleEndian)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
831 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
832 return (static_cast<uint16_t>(p[0]) |
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
833 (static_cast<uint16_t>(p[1]) << 8));
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
834 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
835 else
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
836 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
837 return (static_cast<uint16_t>(p[1]) |
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
838 (static_cast<uint16_t>(p[0]) << 8));
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
839 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
840 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
841
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
842
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
843 static uint32_t ReadUnsignedInteger32(const char* dicom,
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
844 bool littleEndian)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
845 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
846 const uint8_t* p = reinterpret_cast<const uint8_t*>(dicom);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
847
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
848 if (littleEndian)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
849 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
850 return (static_cast<uint32_t>(p[0]) |
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
851 (static_cast<uint32_t>(p[1]) << 8) |
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
852 (static_cast<uint32_t>(p[2]) << 16) |
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
853 (static_cast<uint32_t>(p[3]) << 24));
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
854 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
855 else
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
856 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
857 return (static_cast<uint32_t>(p[3]) |
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
858 (static_cast<uint32_t>(p[2]) << 8) |
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
859 (static_cast<uint32_t>(p[1]) << 16) |
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
860 (static_cast<uint32_t>(p[0]) << 24));
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
861 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
862 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
863
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
864
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
865 static DicomTag ReadTag(const char* dicom,
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
866 bool littleEndian)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
867 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
868 return DicomTag(ReadUnsignedInteger16(dicom, littleEndian),
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
869 ReadUnsignedInteger16(dicom + 2, littleEndian));
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
870 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
871
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
872
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
873 static bool IsShortExplicitTag(ValueRepresentation vr)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
874 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
875 /**
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
876 * Are we in the case of Table 7.1-2? "Data Element with
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
877 * Explicit VR of AE, AS, AT, CS, DA, DS, DT, FL, FD, IS, LO,
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
878 * LT, PN, SH, SL, SS, ST, TM, UI, UL and US"
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
879 * http://dicom.nema.org/medical/dicom/current/output/chtml/part05/chapter_7.html#sect_7.1.2
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
880 **/
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
881 return (vr == ValueRepresentation_ApplicationEntity /* AE */ ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
882 vr == ValueRepresentation_AgeString /* AS */ ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
883 vr == ValueRepresentation_AttributeTag /* AT */ ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
884 vr == ValueRepresentation_CodeString /* CS */ ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
885 vr == ValueRepresentation_Date /* DA */ ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
886 vr == ValueRepresentation_DecimalString /* DS */ ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
887 vr == ValueRepresentation_DateTime /* DT */ ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
888 vr == ValueRepresentation_FloatingPointSingle /* FL */ ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
889 vr == ValueRepresentation_FloatingPointDouble /* FD */ ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
890 vr == ValueRepresentation_IntegerString /* IS */ ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
891 vr == ValueRepresentation_LongString /* LO */ ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
892 vr == ValueRepresentation_LongText /* LT */ ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
893 vr == ValueRepresentation_PersonName /* PN */ ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
894 vr == ValueRepresentation_ShortString /* SH */ ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
895 vr == ValueRepresentation_SignedLong /* SL */ ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
896 vr == ValueRepresentation_SignedShort /* SS */ ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
897 vr == ValueRepresentation_ShortText /* ST */ ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
898 vr == ValueRepresentation_Time /* TM */ ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
899 vr == ValueRepresentation_UniqueIdentifier /* UI */ ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
900 vr == ValueRepresentation_UnsignedLong /* UL */ ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
901 vr == ValueRepresentation_UnsignedShort /* US */);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
902 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
903
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
904
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
905 bool IsLittleEndian() const
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
906 {
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
907 return (transferSyntax_ != DicomTransferSyntax_BigEndianExplicit);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
908 }
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
909
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
910
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
911 void PrintBlock(const std::string& block)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
912 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
913 for (size_t i = 0; i < block.size(); i++)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
914 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
915 printf("%02x ", static_cast<uint8_t>(block[i]));
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
916 if (i % 16 == 15)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
917 printf("\n");
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
918 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
919 printf("\n");
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
920 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
921
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
922 void HandlePreamble(IVisitor& visitor,
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
923 const std::string& block)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
924 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
925 printf("PREAMBLE:\n");
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
926 PrintBlock(block);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
927
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
928 assert(block.size() == 144u);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
929 assert(reader_.GetProcessedBytes() == 144u);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
930
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
931 /**
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
932 * The "DICOM file meta information" is always encoded using
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
933 * "Explicit VR Little Endian Transfer Syntax"
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
934 * http://dicom.nema.org/medical/dicom/current/output/chtml/part10/chapter_7.html
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
935 **/
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
936 if (block[128] != 'D' ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
937 block[129] != 'I' ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
938 block[130] != 'C' ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
939 block[131] != 'M' ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
940 ReadTag(block.c_str() + 132, true) != DicomTag(0x0002, 0x0000) ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
941 block[136] != 'U' ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
942 block[137] != 'L' ||
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
943 ReadUnsignedInteger16(block.c_str() + 138, true) != 4)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
944 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
945 throw OrthancException(ErrorCode_BadFileFormat);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
946 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
947
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
948 uint32_t length = ReadUnsignedInteger32(block.c_str() + 140, true);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
949
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
950 reader_.Schedule(length);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
951 state_ = State_MetaHeader;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
952 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
953
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
954
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
955 void HandleMetaHeader(IVisitor& visitor,
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
956 const std::string& block)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
957 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
958 printf("META-HEADER:\n");
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
959 PrintBlock(block);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
960
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
961 size_t pos = 0;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
962 const char* p = block.c_str();
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
963
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
964 bool hasTransferSyntax = false;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
965
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
966 while (pos + 8 <= block.size())
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
967 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
968 DicomTag tag = ReadTag(p + pos, true);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
969
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
970 ValueRepresentation vr = StringToValueRepresentation(std::string(p + pos + 4, 2), true);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
971
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
972 if (IsShortExplicitTag(vr))
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
973 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
974 uint16_t length = ReadUnsignedInteger16(p + pos + 6, true);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
975
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
976 std::string value;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
977 value.assign(p + pos + 8, length);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
978
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
979 if (tag.GetGroup() == 0x0002)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
980 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
981 visitor.VisitMetaHeaderTag(tag, vr, value);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
982 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
983
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
984 if (tag == DICOM_TAG_TRANSFER_SYNTAX_UID)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
985 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
986 // Remove possible padding byte
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
987 if (!value.empty() &&
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
988 value[value.size() - 1] == '\0')
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
989 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
990 value.resize(value.size() - 1);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
991 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
992
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
993 if (LookupTransferSyntax(transferSyntax_, value))
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
994 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
995 hasTransferSyntax = true;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
996 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
997 else
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
998 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
999 throw OrthancException(ErrorCode_NotImplemented, "Unsupported transfer syntax: " + value);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1000 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1001 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1002
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1003 pos += length + 8;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1004 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1005 else if (pos + 12 <= block.size())
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1006 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1007 uint16_t reserved = ReadUnsignedInteger16(p + pos + 6, true);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1008 if (reserved != 0)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1009 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1010 break;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1011 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1012
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1013 uint32_t length = ReadUnsignedInteger32(p + pos + 8, true);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1014
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1015 std::string value;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1016 value.assign(p + pos + 12, length);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1017
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1018 if (tag.GetGroup() == 0x0002)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1019 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1020 visitor.VisitMetaHeaderTag(tag, vr, value);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1021 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1022
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1023 pos += length + 12;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1024 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1025 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1026
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1027 if (pos != block.size())
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1028 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1029 throw OrthancException(ErrorCode_BadFileFormat);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1030 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1031
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1032 if (!hasTransferSyntax)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1033 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1034 throw OrthancException(ErrorCode_BadFileFormat, "DICOM file meta-header without transfer syntax UID");
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1035 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1036
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1037 reader_.Schedule(8);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1038 state_ = State_DatasetTag;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1039 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1040
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1041
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1042 void HandleDatasetTag(IVisitor& visitor,
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1043 const std::string& block)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1044 {
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1045 static const DicomTag DICOM_TAG_SEQUENCE_ITEM(0xfffe, 0xe000);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1046 static const DicomTag DICOM_TAG_SEQUENCE_DELIMITATION_ITEM(0xfffe, 0xe00d);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1047 static const DicomTag DICOM_TAG_SEQUENCE_DELIMITATION_SEQUENCE(0xfffe, 0xe0dd);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1048
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1049 //printf("DATASET TAG:\n");
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1050 //PrintBlock(block);
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1051
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1052 assert(block.size() == 8u);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1053
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1054 const bool littleEndian = IsLittleEndian();
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1055 DicomTag tag = ReadTag(block.c_str(), littleEndian);
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1056
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1057 if (tag == DICOM_TAG_SEQUENCE_ITEM ||
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1058 tag == DICOM_TAG_SEQUENCE_DELIMITATION_ITEM ||
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1059 tag == DICOM_TAG_SEQUENCE_DELIMITATION_SEQUENCE)
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1060 {
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1061 printf("SEQUENCE TAG:\n");
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1062 PrintBlock(block);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1063
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1064 // The special sequence items are encoded like "Implicit VR"
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1065 uint32_t length = ReadUnsignedInteger32(block.c_str() + 4, littleEndian);
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1066
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1067 if (tag == DICOM_TAG_SEQUENCE_ITEM)
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1068 {
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1069 for (unsigned int i = 0; i <= sequenceDepth_; i++)
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1070 printf(" ");
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1071 if (length == 0xffffffffu)
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1072 {
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1073 // Undefined length: Need to loop over the tags of the nested dataset
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1074 printf("...next dataset in sequence...\n");
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1075 reader_.Schedule(8);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1076 state_ = State_DatasetTag;
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1077 }
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1078 else
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1079 {
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1080 // Explicit length: Can skip the full sequence at once
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1081 printf("...next dataset in sequence... %u bytes\n", length);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1082 reader_.Schedule(length);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1083 state_ = State_DatasetValue;
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1084 }
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1085 }
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1086 else if (tag == DICOM_TAG_SEQUENCE_DELIMITATION_ITEM ||
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1087 tag == DICOM_TAG_SEQUENCE_DELIMITATION_SEQUENCE)
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1088 {
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1089 if (length != 0 ||
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1090 sequenceDepth_ == 0)
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1091 {
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1092 throw OrthancException(ErrorCode_BadFileFormat);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1093 }
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1094
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1095 if (tag == DICOM_TAG_SEQUENCE_DELIMITATION_SEQUENCE)
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1096 {
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1097 sequenceDepth_ --;
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1098
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1099 for (unsigned int i = 0; i <= sequenceDepth_; i++)
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1100 printf(" ");
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1101 printf("...leaving sequence...\n");
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1102 }
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1103
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1104 reader_.Schedule(8);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1105 state_ = State_DatasetTag;
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1106 }
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1107 else
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1108 {
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1109 throw OrthancException(ErrorCode_InternalError);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1110 }
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1111 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1112 else
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1113 {
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1114 ValueRepresentation vr = ValueRepresentation_Unknown;
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1115
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1116 if (transferSyntax_ == DicomTransferSyntax_LittleEndianImplicit)
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1117 {
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1118 uint32_t length = ReadUnsignedInteger32(block.c_str() + 4, true /* little endian */);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1119
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1120 reader_.Schedule(length);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1121 state_ = State_DatasetValue;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1122 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1123 else
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1124 {
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1125 // This in an explicit transfer syntax
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1126
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1127 vr = StringToValueRepresentation(
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1128 std::string(block.c_str() + 4, 2), false /* ignore unknown VR */);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1129
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1130 if (vr == ValueRepresentation_Sequence)
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1131 {
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1132 for (unsigned int i = 0; i <= sequenceDepth_; i++)
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1133 printf(" ");
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1134 printf("...entering sequence... %s\n", previousTag_.Format().c_str());
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1135 sequenceDepth_ ++;
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1136 reader_.Schedule(4);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1137 state_ = State_DatasetExplicitLength;
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1138 }
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1139 else if (IsShortExplicitTag(vr))
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1140 {
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1141 uint16_t length = ReadUnsignedInteger16(block.c_str() + 6, littleEndian);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1142
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1143 reader_.Schedule(length);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1144 state_ = State_DatasetValue;
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1145 }
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1146 else
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1147 {
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1148 uint16_t reserved = ReadUnsignedInteger16(block.c_str() + 6, littleEndian);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1149 if (reserved != 0)
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1150 {
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1151 throw OrthancException(ErrorCode_BadFileFormat);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1152 }
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1153
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1154 reader_.Schedule(4);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1155 state_ = State_DatasetExplicitLength;
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1156 }
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1157 }
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1158
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1159 previousTag_ = tag;
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1160
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1161 if (sequenceDepth_ == 0)
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1162 {
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1163 danglingTag_ = tag;
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1164 danglingVR_ = vr;
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1165 }
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1166 else
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1167 {
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1168 for (unsigned int i = 0; i <= sequenceDepth_; i++)
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1169 printf(" ");
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1170 printf(" %s\n", tag.Format().c_str());
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1171 }
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1172 }
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1173 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1174
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1175
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1176 void HandleDatasetExplicitLength(IVisitor& visitor,
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1177 const std::string& block)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1178 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1179 //printf("DATASET TAG LENGTH:\n");
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1180 //PrintBlock(block);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1181
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1182 assert(block.size() == 4);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1183
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1184 uint32_t length = ReadUnsignedInteger32(block.c_str(), IsLittleEndian());
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1185 if (length == 0xffffffffu)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1186 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1187 /**
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1188 * This is the case of sequences, or pixel data with
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1189 * compressed transfer syntaxes. Schedule the reading of the
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1190 * first tag of the nested dataset.
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1191 * http://dicom.nema.org/medical/dicom/current/output/chtml/part05/sect_7.5.html
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1192 **/
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1193
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1194 state_ = State_DatasetTag;
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1195 reader_.Schedule(8);
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1196 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1197 else
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1198 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1199 reader_.Schedule(length);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1200 state_ = State_DatasetValue;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1201 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1202 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1203
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1204
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1205 public:
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1206 DicomStreamReader(std::istream& stream) :
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1207 reader_(stream),
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1208 state_(State_Preamble),
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1209 transferSyntax_(DicomTransferSyntax_LittleEndianImplicit), // Dummy
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1210 previousTag_(0x0000, 0x0000), // Dummy
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1211 danglingTag_(0x0000, 0x0000), // Dummy
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1212 danglingVR_(ValueRepresentation_Unknown), // Dummy
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1213 sequenceDepth_(0)
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1214 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1215 reader_.Schedule(128 /* empty header */ +
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1216 4 /* "DICM" magic value */ +
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1217 4 /* (0x0002, 0x0000) tag */ +
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1218 2 /* value representation of (0x0002, 0x0000) == "UL" */ +
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1219 2 /* length of "UL" value == 4 */ +
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1220 4 /* actual length of the meta-header */);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1221 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1222
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1223 void Consume(IVisitor& visitor)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1224 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1225 while (state_ != State_Done)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1226 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1227 std::string block;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1228 if (reader_.Read(block))
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1229 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1230 switch (state_)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1231 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1232 case State_Preamble:
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1233 HandlePreamble(visitor, block);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1234 break;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1235
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1236 case State_MetaHeader:
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1237 HandleMetaHeader(visitor, block);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1238 break;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1239
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1240 case State_DatasetTag:
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1241 HandleDatasetTag(visitor, block);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1242 break;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1243
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1244 case State_DatasetExplicitLength:
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1245 HandleDatasetExplicitLength(visitor, block);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1246 break;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1247
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1248 case State_DatasetValue:
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1249 if (sequenceDepth_ == 0 &&
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1250 !visitor.VisitDatasetTag(danglingTag_, danglingVR_, transferSyntax_, block, IsLittleEndian()))
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1251 {
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1252 state_ = State_Done;
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1253 }
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1254 else
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1255 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1256 reader_.Schedule(8);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1257 state_ = State_DatasetTag;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1258 }
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1259
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1260 break;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1261
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1262 default:
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1263 throw OrthancException(ErrorCode_InternalError);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1264 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1265 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1266 else
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1267 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1268 return; // No more data in the stream
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1269 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1270 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1271 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1272
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1273 bool IsDone() const
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1274 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1275 return (state_ == State_Done);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1276 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1277
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1278 uint64_t GetProcessedBytes() const
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1279 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1280 return reader_.GetProcessedBytes();
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1281 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1282 };
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1283
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1284
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1285
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1286 class V : public DicomStreamReader::IVisitor
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1287 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1288 public:
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1289 virtual void VisitMetaHeaderTag(const DicomTag& tag,
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1290 const ValueRepresentation& vr,
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1291 const std::string& value) ORTHANC_OVERRIDE
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1292 {
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1293 std::cout << "Header: " << tag.Format() << " [" << Toolbox::ConvertToAscii(value).c_str() << "] (" << value.size() << ")" << std::endl;
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1294 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1295
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1296 virtual bool VisitDatasetTag(const DicomTag& tag,
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1297 const ValueRepresentation& vr,
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1298 DicomTransferSyntax transferSyntax,
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1299 const std::string& value,
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1300 bool isLittleEndian) ORTHANC_OVERRIDE
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1301 {
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1302 if (!isLittleEndian)
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1303 printf("** ");
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1304 if (tag.GetGroup() < 0x7f00)
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1305 std::cout << "Dataset: " << tag.Format() << " [" << Toolbox::ConvertToAscii(value).c_str() << "] (" << value.size() << ")" << std::endl;
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1306 else
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1307 std::cout << "Dataset: " << tag.Format() << " [PIXEL] (" << value.size() << ")" << std::endl;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1308
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1309 return true;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1310 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1311 };
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1312 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1313
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1314
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1315
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1316 TEST(DicomStreamReader, DISABLED_Tutu)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1317 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1318 static const std::string PATH = "/home/jodogne/Subversion/orthanc-tests/Database/TransferSyntaxes/";
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1319
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1320 std::string dicom;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1321 //SystemToolbox::ReadFile(dicom, PATH + "../ColorTestMalaterre.dcm", false);
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1322 //SystemToolbox::ReadFile(dicom, PATH + "1.2.840.10008.1.2.1.dcm", false);
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1323 //SystemToolbox::ReadFile(dicom, PATH + "1.2.840.10008.1.2.2.dcm", false); // Big Endian
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1324 //SystemToolbox::ReadFile(dicom, PATH + "1.2.840.10008.1.2.4.50.dcm", false);
4215
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1325 //SystemToolbox::ReadFile(dicom, PATH + "1.2.840.10008.1.2.4.51.dcm", false);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1326 //SystemToolbox::ReadFile(dicom, PATH + "1.2.840.10008.1.2.4.57.dcm", false);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1327 //SystemToolbox::ReadFile(dicom, PATH + "1.2.840.10008.1.2.4.70.dcm", false);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1328 //SystemToolbox::ReadFile(dicom, PATH + "1.2.840.10008.1.2.4.80.dcm", false);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1329 //SystemToolbox::ReadFile(dicom, PATH + "1.2.840.10008.1.2.4.81.dcm", false);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1330 //SystemToolbox::ReadFile(dicom, PATH + "1.2.840.10008.1.2.4.90.dcm", false);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1331 //SystemToolbox::ReadFile(dicom, PATH + "1.2.840.10008.1.2.4.91.dcm", false);
28e9457dc7ab working on sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4214
diff changeset
1332 SystemToolbox::ReadFile(dicom, PATH + "1.2.840.10008.1.2.5.dcm", false);
4214
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1333
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1334 std::stringstream stream;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1335 size_t pos = 0;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1336
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1337 DicomStreamReader r(stream);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1338 V visitor;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1339
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1340 while (pos < dicom.size() &&
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1341 !r.IsDone())
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1342 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1343 //printf(".");
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1344 //printf("%d\n", pos);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1345 r.Consume(visitor);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1346 stream.clear();
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1347 stream.put(dicom[pos++]);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1348 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1349
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1350 r.Consume(visitor);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1351
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1352 printf(">> %d\n", r.GetProcessedBytes());
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1353 }
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1354
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1355 TEST(DicomStreamReader, DISABLED_Tutu2)
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1356 {
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1357 static const std::string PATH = "/home/jodogne/Subversion/orthanc-tests/Database/TransferSyntaxes/";
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1358
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1359 //std::ifstream stream(PATH + "1.2.840.10008.1.2.4.50.dcm");
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1360 std::ifstream stream(PATH + "1.2.840.10008.1.2.2.dcm");
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1361
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1362 DicomStreamReader r(stream);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1363 V visitor;
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1364
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1365 r.Consume(visitor);
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1366
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1367 printf(">> %d\n", r.GetProcessedBytes());
7b011cfda135 working on DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4213
diff changeset
1368 }