Mercurial > hg > orthanc
annotate OrthancServer/FromDcmtkBridge.cpp @ 305:86bb79522f19
name of the private tags
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 20 Dec 2012 13:01:46 +0100 |
parents | 4eea080e6e7a |
children | 326d5a4a5af3 |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
0 | 3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege, |
4 * Belgium | |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
136 | 10 * |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
0 | 22 * |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
71 | 32 #ifndef NOMINMAX |
33 #define NOMINMAX | |
34 #endif | |
0 | 35 |
36 #include "FromDcmtkBridge.h" | |
37 | |
38 #include "ToDcmtkBridge.h" | |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
106
diff
changeset
|
39 #include "../Core/Toolbox.h" |
62 | 40 #include "../Core/OrthancException.h" |
0 | 41 #include "../Core/PngWriter.h" |
42 #include "../Core/DicomFormat/DicomString.h" | |
43 #include "../Core/DicomFormat/DicomNullValue.h" | |
79 | 44 #include "../Core/DicomFormat/DicomIntegerPixelAccessor.h" |
0 | 45 |
71 | 46 #include <limits> |
47 | |
0 | 48 #include <boost/lexical_cast.hpp> |
49 | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
50 #include <dcmtk/dcmdata/dcchrstr.h> |
0 | 51 #include <dcmtk/dcmdata/dcdicent.h> |
52 #include <dcmtk/dcmdata/dcdict.h> | |
53 #include <dcmtk/dcmdata/dcfilefo.h> | |
54 #include <dcmtk/dcmdata/dcistrmb.h> | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
55 #include <dcmtk/dcmdata/dcuid.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
56 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
57 #include <dcmtk/dcmdata/dcvrae.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
58 #include <dcmtk/dcmdata/dcvras.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
59 #include <dcmtk/dcmdata/dcvrcs.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
60 #include <dcmtk/dcmdata/dcvrda.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
61 #include <dcmtk/dcmdata/dcvrds.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
62 #include <dcmtk/dcmdata/dcvrdt.h> |
0 | 63 #include <dcmtk/dcmdata/dcvrfd.h> |
64 #include <dcmtk/dcmdata/dcvrfl.h> | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
65 #include <dcmtk/dcmdata/dcvris.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
66 #include <dcmtk/dcmdata/dcvrlo.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
67 #include <dcmtk/dcmdata/dcvrlt.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
68 #include <dcmtk/dcmdata/dcvrpn.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
69 #include <dcmtk/dcmdata/dcvrsh.h> |
0 | 70 #include <dcmtk/dcmdata/dcvrsl.h> |
71 #include <dcmtk/dcmdata/dcvrss.h> | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
72 #include <dcmtk/dcmdata/dcvrst.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
73 #include <dcmtk/dcmdata/dcvrtm.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
74 #include <dcmtk/dcmdata/dcvrui.h> |
0 | 75 #include <dcmtk/dcmdata/dcvrul.h> |
76 #include <dcmtk/dcmdata/dcvrus.h> | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
77 #include <dcmtk/dcmdata/dcvrut.h> |
0 | 78 |
2 | 79 #include <boost/math/special_functions/round.hpp> |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
80 #include <glog/logging.h> |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
81 #include <dcmtk/dcmdata/dcostrmb.h> |
0 | 82 |
62 | 83 namespace Orthanc |
0 | 84 { |
304 | 85 void ParsedDicomFile::Setup(const char* buffer, size_t size) |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
86 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
87 DcmInputBufferStream is; |
304 | 88 if (size > 0) |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
89 { |
304 | 90 is.setBuffer(buffer, size); |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
91 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
92 is.setEos(); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
93 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
94 file_.reset(new DcmFileFormat); |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
95 file_->transferInit(); |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
96 if (!file_->read(is).good()) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
97 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
98 throw OrthancException(ErrorCode_BadFileFormat); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
99 } |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
100 file_->loadAllDataIntoMemory(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
101 file_->transferEnd(); |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
102 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
103 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
104 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
105 static void SendPathValueForDictionary(RestApiOutput& output, |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
106 DcmItem& dicom) |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
107 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
108 Json::Value v = Json::arrayValue; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
109 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
110 for (unsigned long i = 0; i < dicom.card(); i++) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
111 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
112 DcmElement* element = dicom.getElement(i); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
113 if (element) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
114 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
115 char buf[16]; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
116 sprintf(buf, "%04x-%04x", element->getTag().getGTag(), element->getTag().getETag()); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
117 v.append(buf); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
118 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
119 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
120 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
121 output.AnswerJson(v); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
122 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
123 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
124 static inline uint16_t GetCharValue(char c) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
125 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
126 if (c >= '0' && c <= '9') |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
127 return c - '0'; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
128 else if (c >= 'a' && c <= 'f') |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
129 return c - 'a' + 10; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
130 else if (c >= 'A' && c <= 'F') |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
131 return c - 'A' + 10; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
132 else |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
133 return 0; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
134 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
135 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
136 static inline uint16_t GetTagValue(const char* c) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
137 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
138 return ((GetCharValue(c[0]) << 12) + |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
139 (GetCharValue(c[1]) << 8) + |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
140 (GetCharValue(c[2]) << 4) + |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
141 GetCharValue(c[3])); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
142 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
143 |
304 | 144 static void ParseTagAndGroup(DcmTagKey& key, |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
145 const std::string& tag) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
146 { |
304 | 147 DicomTag t = FromDcmtkBridge::ParseTag(tag); |
148 key = DcmTagKey(t.GetGroup(), t.GetElement()); | |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
149 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
150 |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
151 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
152 static void SendSequence(RestApiOutput& output, |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
153 DcmSequenceOfItems& sequence) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
154 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
155 // This element is a sequence |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
156 Json::Value v = Json::arrayValue; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
157 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
158 for (unsigned long i = 0; i < sequence.card(); i++) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
159 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
160 v.append(boost::lexical_cast<std::string>(i)); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
161 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
162 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
163 output.AnswerJson(v); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
164 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
165 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
166 static void AnswerDicomField(RestApiOutput& output, |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
167 DcmElement& element) |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
168 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
169 // This element is not a sequence |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
170 std::string buffer; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
171 buffer.resize(65536); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
172 Uint32 length = element.getLength(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
173 Uint32 offset = 0; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
174 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
175 output.GetLowLevelOutput().SendOkHeader("application/octet-stream", true, length, NULL); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
176 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
177 while (offset < length) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
178 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
179 Uint32 nbytes; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
180 if (length - offset < buffer.size()) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
181 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
182 nbytes = length - offset; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
183 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
184 else |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
185 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
186 nbytes = buffer.size(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
187 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
188 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
189 if (element.getPartialValue(&buffer[0], offset, nbytes).good()) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
190 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
191 output.GetLowLevelOutput().Send(&buffer[0], nbytes); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
192 offset += nbytes; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
193 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
194 else |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
195 { |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
196 LOG(ERROR) << "Error while sending a DICOM field"; |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
197 return; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
198 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
199 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
200 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
201 output.MarkLowLevelOutputDone(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
202 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
203 |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
204 static void SendPathValueForLeaf(RestApiOutput& output, |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
205 const std::string& tag, |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
206 DcmItem& dicom) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
207 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
208 DcmTagKey k; |
304 | 209 ParseTagAndGroup(k, tag); |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
210 |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
211 DcmSequenceOfItems* sequence = NULL; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
212 if (dicom.findAndGetSequence(k, sequence).good() && |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
213 sequence != NULL && |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
214 sequence->getVR() == EVR_SQ) |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
215 { |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
216 SendSequence(output, *sequence); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
217 return; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
218 } |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
219 |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
220 DcmElement* element = NULL; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
221 if (dicom.findAndGetElement(k, element).good() && |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
222 element != NULL && |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
223 element->getVR() != EVR_UNKNOWN && |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
224 element->getVR() != EVR_SQ) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
225 { |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
226 AnswerDicomField(output, *element); |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
227 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
228 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
229 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
230 void ParsedDicomFile::SendPathValue(RestApiOutput& output, |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
231 const UriComponents& uri) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
232 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
233 DcmItem* dicom = file_->getDataset(); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
234 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
235 // Go down in the tag hierarchy according to the URI |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
236 for (size_t pos = 0; pos < uri.size() / 2; pos++) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
237 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
238 size_t index; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
239 try |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
240 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
241 index = boost::lexical_cast<size_t>(uri[2 * pos + 1]); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
242 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
243 catch (boost::bad_lexical_cast&) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
244 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
245 return; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
246 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
247 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
248 DcmTagKey k; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
249 DcmItem *child = NULL; |
304 | 250 ParseTagAndGroup(k, uri[2 * pos]); |
251 if (!dicom->findAndGetSequenceItem(k, child, index).good() || | |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
252 child == NULL) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
253 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
254 return; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
255 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
256 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
257 dicom = child; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
258 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
259 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
260 // We have reached the end of the URI |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
261 if (uri.size() % 2 == 0) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
262 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
263 SendPathValueForDictionary(output, *dicom); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
264 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
265 else |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
266 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
267 SendPathValueForLeaf(output, uri.back(), *dicom); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
268 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
269 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
270 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
271 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
272 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
273 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
274 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
275 static DcmElement* CreateElementForTag(const DicomTag& tag) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
276 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
277 DcmTag key(tag.GetGroup(), tag.GetElement()); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
278 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
279 switch (key.getEVR()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
280 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
281 // http://support.dcmtk.org/docs/dcvr_8h-source.html |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
282 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
283 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
284 * TODO. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
285 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
286 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
287 case EVR_OB: // other byte |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
288 case EVR_OF: // other float |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
289 case EVR_OW: // other word |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
290 case EVR_AT: // attribute tag |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
291 throw OrthancException(ErrorCode_NotImplemented); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
292 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
293 case EVR_UN: // unknown value representation |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
294 throw OrthancException(ErrorCode_ParameterOutOfRange); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
295 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
296 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
297 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
298 * String types. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
299 * http://support.dcmtk.org/docs/classDcmByteString.html |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
300 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
301 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
302 case EVR_AS: // age string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
303 return new DcmAgeString(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
304 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
305 case EVR_AE: // application entity title |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
306 return new DcmApplicationEntity(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
307 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
308 case EVR_CS: // code string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
309 return new DcmCodeString(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
310 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
311 case EVR_DA: // date string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
312 return new DcmDate(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
313 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
314 case EVR_DT: // date time string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
315 return new DcmDateTime(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
316 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
317 case EVR_DS: // decimal string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
318 return new DcmDecimalString(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
319 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
320 case EVR_IS: // integer string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
321 return new DcmIntegerString(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
322 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
323 case EVR_TM: // time string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
324 return new DcmTime(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
325 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
326 case EVR_UI: // unique identifier |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
327 return new DcmUniqueIdentifier(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
328 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
329 case EVR_ST: // short text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
330 return new DcmShortText(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
331 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
332 case EVR_LO: // long string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
333 return new DcmLongString(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
334 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
335 case EVR_LT: // long text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
336 return new DcmLongText(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
337 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
338 case EVR_UT: // unlimited text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
339 return new DcmUnlimitedText(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
340 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
341 case EVR_SH: // short string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
342 return new DcmShortString(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
343 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
344 case EVR_PN: // person name |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
345 return new DcmPersonName(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
346 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
347 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
348 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
349 * Numerical types |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
350 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
351 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
352 case EVR_SL: // signed long |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
353 return new DcmSignedLong(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
354 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
355 case EVR_SS: // signed short |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
356 return new DcmSignedShort(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
357 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
358 case EVR_UL: // unsigned long |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
359 return new DcmUnsignedLong(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
360 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
361 case EVR_US: // unsigned short |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
362 return new DcmUnsignedShort(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
363 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
364 case EVR_FL: // float single-precision |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
365 return new DcmFloatingPointSingle(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
366 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
367 case EVR_FD: // float double-precision |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
368 return new DcmFloatingPointDouble(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
369 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
370 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
371 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
372 * Sequence types, should never occur at this point. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
373 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
374 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
375 case EVR_SQ: // sequence of items |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
376 throw OrthancException(ErrorCode_ParameterOutOfRange); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
377 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
378 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
379 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
380 * Internal to DCMTK. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
381 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
382 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
383 case EVR_ox: // OB or OW depending on context |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
384 case EVR_xs: // SS or US depending on context |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
385 case EVR_lt: // US, SS or OW depending on context, used for LUT Data (thus the name) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
386 case EVR_na: // na="not applicable", for data which has no VR |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
387 case EVR_up: // up="unsigned pointer", used internally for DICOMDIR suppor |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
388 case EVR_item: // used internally for items |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
389 case EVR_metainfo: // used internally for meta info datasets |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
390 case EVR_dataset: // used internally for datasets |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
391 case EVR_fileFormat: // used internally for DICOM files |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
392 case EVR_dicomDir: // used internally for DICOMDIR objects |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
393 case EVR_dirRecord: // used internally for DICOMDIR records |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
394 case EVR_pixelSQ: // used internally for pixel sequences in a compressed image |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
395 case EVR_pixelItem: // used internally for pixel items in a compressed image |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
396 case EVR_UNKNOWN: // used internally for elements with unknown VR (encoded with 4-byte length field in explicit VR) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
397 case EVR_PixelData: // used internally for uncompressed pixeld data |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
398 case EVR_OverlayData: // used internally for overlay data |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
399 case EVR_UNKNOWN2B: // used internally for elements with unknown VR with 2-byte length field in explicit VR |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
400 default: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
401 break; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
402 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
403 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
404 throw OrthancException(ErrorCode_InternalError); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
405 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
406 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
407 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
408 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
409 static void FillElementWithString(DcmElement& element, |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
410 const DicomTag& tag, |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
411 const std::string& value) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
412 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
413 DcmTag key(tag.GetGroup(), tag.GetElement()); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
414 bool ok = false; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
415 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
416 try |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
417 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
418 switch (key.getEVR()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
419 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
420 // http://support.dcmtk.org/docs/dcvr_8h-source.html |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
421 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
422 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
423 * TODO. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
424 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
425 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
426 case EVR_OB: // other byte |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
427 case EVR_OF: // other float |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
428 case EVR_OW: // other word |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
429 case EVR_AT: // attribute tag |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
430 throw OrthancException(ErrorCode_NotImplemented); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
431 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
432 case EVR_UN: // unknown value representation |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
433 throw OrthancException(ErrorCode_ParameterOutOfRange); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
434 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
435 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
436 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
437 * String types. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
438 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
439 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
440 case EVR_DS: // decimal string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
441 case EVR_IS: // integer string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
442 case EVR_AS: // age string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
443 case EVR_DA: // date string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
444 case EVR_DT: // date time string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
445 case EVR_TM: // time string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
446 case EVR_AE: // application entity title |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
447 case EVR_CS: // code string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
448 case EVR_SH: // short string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
449 case EVR_LO: // long string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
450 case EVR_ST: // short text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
451 case EVR_LT: // long text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
452 case EVR_UT: // unlimited text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
453 case EVR_PN: // person name |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
454 case EVR_UI: // unique identifier |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
455 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
456 ok = element.putString(value.c_str()).good(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
457 break; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
458 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
459 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
460 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
461 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
462 * Numerical types |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
463 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
464 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
465 case EVR_SL: // signed long |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
466 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
467 ok = element.putSint32(boost::lexical_cast<Sint32>(value)).good(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
468 break; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
469 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
470 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
471 case EVR_SS: // signed short |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
472 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
473 ok = element.putSint16(boost::lexical_cast<Sint16>(value)).good(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
474 break; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
475 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
476 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
477 case EVR_UL: // unsigned long |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
478 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
479 ok = element.putUint32(boost::lexical_cast<Uint32>(value)).good(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
480 break; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
481 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
482 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
483 case EVR_US: // unsigned short |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
484 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
485 ok = element.putUint16(boost::lexical_cast<Uint16>(value)).good(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
486 break; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
487 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
488 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
489 case EVR_FL: // float single-precision |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
490 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
491 ok = element.putFloat32(boost::lexical_cast<float>(value)).good(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
492 break; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
493 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
494 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
495 case EVR_FD: // float double-precision |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
496 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
497 ok = element.putFloat64(boost::lexical_cast<double>(value)).good(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
498 break; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
499 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
500 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
501 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
502 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
503 * Sequence types, should never occur at this point. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
504 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
505 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
506 case EVR_SQ: // sequence of items |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
507 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
508 ok = false; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
509 break; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
510 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
511 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
512 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
513 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
514 * Internal to DCMTK. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
515 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
516 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
517 case EVR_ox: // OB or OW depending on context |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
518 case EVR_xs: // SS or US depending on context |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
519 case EVR_lt: // US, SS or OW depending on context, used for LUT Data (thus the name) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
520 case EVR_na: // na="not applicable", for data which has no VR |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
521 case EVR_up: // up="unsigned pointer", used internally for DICOMDIR suppor |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
522 case EVR_item: // used internally for items |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
523 case EVR_metainfo: // used internally for meta info datasets |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
524 case EVR_dataset: // used internally for datasets |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
525 case EVR_fileFormat: // used internally for DICOM files |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
526 case EVR_dicomDir: // used internally for DICOMDIR objects |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
527 case EVR_dirRecord: // used internally for DICOMDIR records |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
528 case EVR_pixelSQ: // used internally for pixel sequences in a compressed image |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
529 case EVR_pixelItem: // used internally for pixel items in a compressed image |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
530 case EVR_UNKNOWN: // used internally for elements with unknown VR (encoded with 4-byte length field in explicit VR) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
531 case EVR_PixelData: // used internally for uncompressed pixeld data |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
532 case EVR_OverlayData: // used internally for overlay data |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
533 case EVR_UNKNOWN2B: // used internally for elements with unknown VR with 2-byte length field in explicit VR |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
534 default: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
535 break; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
536 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
537 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
538 catch (boost::bad_lexical_cast&) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
539 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
540 ok = false; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
541 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
542 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
543 if (!ok) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
544 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
545 throw OrthancException(ErrorCode_InternalError); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
546 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
547 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
548 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
549 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
550 void ParsedDicomFile::Remove(const DicomTag& tag) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
551 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
552 DcmTagKey key(tag.GetGroup(), tag.GetElement()); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
553 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
554 // TODO This call results in memory leaks inside DCMTK |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
555 file_->getDataset()->remove(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
556 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
557 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
558 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
559 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
560 void ParsedDicomFile::Insert(const DicomTag& tag, |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
561 const std::string& value) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
562 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
563 std::auto_ptr<DcmElement> element(CreateElementForTag(tag)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
564 FillElementWithString(*element, tag, value); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
565 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
566 if (!file_->getDataset()->insert(element.release(), false, false).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
567 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
568 // This field already exists |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
569 throw OrthancException(ErrorCode_InternalError); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
570 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
571 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
572 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
573 |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
574 void ParsedDicomFile::Replace(const DicomTag& tag, |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
575 const std::string& value, |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
576 DicomReplaceMode mode) |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
577 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
578 DcmTagKey key(tag.GetGroup(), tag.GetElement()); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
579 DcmElement* element = NULL; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
580 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
581 if (!file_->getDataset()->findAndGetElement(key, element).good() || |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
582 element == NULL) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
583 { |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
584 // This field does not exist, act wrt. the specified "mode" |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
585 switch (mode) |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
586 { |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
587 case DicomReplaceMode_InsertIfAbsent: |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
588 Insert(tag, value); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
589 break; |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
590 |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
591 case DicomReplaceMode_ThrowIfAbsent: |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
592 throw OrthancException(ErrorCode_InexistentItem); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
593 |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
594 case DicomReplaceMode_IgnoreIfAbsent: |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
595 return; |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
596 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
597 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
598 else |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
599 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
600 FillElementWithString(*element, tag, value); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
601 } |
303
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
602 |
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
603 |
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
604 /** |
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
605 * dcmodify will automatically correct 'Media Storage SOP Class |
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
606 * UID' and 'Media Storage SOP Instance UID' in the metaheader, if |
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
607 * you make changes to the related tags in the dataset ('SOP Class |
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
608 * UID' and 'SOP Instance UID') via insert or modify mode |
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
609 * options. You can disable this behaviour by using the -nmu |
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
610 * option. |
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
611 **/ |
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
612 if (tag == DICOM_TAG_SOP_CLASS_UID) |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
613 Replace(DICOM_TAG_MEDIA_STORAGE_SOP_CLASS_UID, value, DicomReplaceMode_InsertIfAbsent); |
303
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
614 |
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
615 if (tag == DICOM_TAG_SOP_INSTANCE_UID) |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
616 Replace(DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID, value, DicomReplaceMode_InsertIfAbsent); |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
617 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
618 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
619 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
620 void ParsedDicomFile::Answer(RestApiOutput& output) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
621 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
622 std::string serialized; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
623 if (FromDcmtkBridge::SaveToMemoryBuffer(serialized, file_->getDataset())) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
624 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
625 output.AnswerBuffer(serialized, "application/octet-stream"); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
626 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
627 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
628 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
629 |
0 | 630 void FromDcmtkBridge::Convert(DicomMap& target, DcmDataset& dataset) |
631 { | |
632 target.Clear(); | |
633 for (unsigned long i = 0; i < dataset.card(); i++) | |
634 { | |
635 DcmElement* element = dataset.getElement(i); | |
636 if (element && element->isLeaf()) | |
637 { | |
638 target.SetValue(element->getTag().getGTag(), | |
639 element->getTag().getETag(), | |
640 ConvertLeafElement(*element)); | |
641 } | |
642 } | |
643 } | |
644 | |
645 | |
646 DicomTag FromDcmtkBridge::GetTag(const DcmElement& element) | |
647 { | |
648 return DicomTag(element.getGTag(), element.getETag()); | |
649 } | |
650 | |
651 | |
652 DicomValue* FromDcmtkBridge::ConvertLeafElement(DcmElement& element) | |
653 { | |
654 if (!element.isLeaf()) | |
655 { | |
62 | 656 throw OrthancException("Only applicable to leaf elements"); |
0 | 657 } |
658 | |
659 if (element.isaString()) | |
660 { | |
661 char *c; | |
662 if (element.getString(c).good() && | |
663 c != NULL) | |
664 { | |
665 std::string s(c); | |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
106
diff
changeset
|
666 std::string utf8 = Toolbox::ConvertToUtf8(s, "ISO-8859-1"); // TODO Parameter? |
0 | 667 return new DicomString(utf8); |
668 } | |
669 else | |
670 { | |
671 return new DicomNullValue; | |
672 } | |
673 } | |
674 | |
675 try | |
676 { | |
677 // http://support.dcmtk.org/docs/dcvr_8h-source.html | |
678 switch (element.getVR()) | |
679 { | |
680 | |
681 /** | |
682 * TODO. | |
683 **/ | |
684 | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
685 case EVR_DS: // decimal string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
686 case EVR_IS: // integer string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
687 case EVR_OB: // other byte |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
688 case EVR_OF: // other float |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
689 case EVR_OW: // other word |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
690 case EVR_AS: // age string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
691 case EVR_AT: // attribute tag |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
692 case EVR_DA: // date string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
693 case EVR_DT: // date time string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
694 case EVR_TM: // time string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
695 case EVR_UN: // unknown value representation |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
696 return new DicomNullValue(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
697 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
698 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
699 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
700 * String types, should never happen at this point because of |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
701 * "element.isaString()". |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
702 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
703 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
704 case EVR_AE: // application entity title |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
705 case EVR_CS: // code string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
706 case EVR_SH: // short string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
707 case EVR_LO: // long string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
708 case EVR_ST: // short text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
709 case EVR_LT: // long text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
710 case EVR_UT: // unlimited text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
711 case EVR_PN: // person name |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
712 case EVR_UI: // unique identifier |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
713 return new DicomNullValue(); |
0 | 714 |
715 | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
716 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
717 * Numerical types |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
718 **/ |
0 | 719 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
720 case EVR_SL: // signed long |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
721 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
722 Sint32 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
723 if (dynamic_cast<DcmSignedLong&>(element).getSint32(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
724 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
725 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
726 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
727 else |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
728 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
729 return new DicomNullValue(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
730 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
731 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
732 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
733 case EVR_SS: // signed short |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
734 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
735 Sint16 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
736 if (dynamic_cast<DcmSignedShort&>(element).getSint16(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
737 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
738 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
739 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
740 else |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
741 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
742 return new DicomNullValue(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
743 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
744 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
745 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
746 case EVR_UL: // unsigned long |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
747 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
748 Uint32 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
749 if (dynamic_cast<DcmUnsignedLong&>(element).getUint32(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
750 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
751 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
752 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
753 else |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
754 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
755 return new DicomNullValue(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
756 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
757 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
758 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
759 case EVR_US: // unsigned short |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
760 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
761 Uint16 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
762 if (dynamic_cast<DcmUnsignedShort&>(element).getUint16(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
763 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
764 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
765 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
766 else |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
767 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
768 return new DicomNullValue(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
769 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
770 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
771 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
772 case EVR_FL: // float single-precision |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
773 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
774 Float32 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
775 if (dynamic_cast<DcmFloatingPointSingle&>(element).getFloat32(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
776 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
777 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
778 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
779 else |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
780 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
781 return new DicomNullValue(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
782 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
783 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
784 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
785 case EVR_FD: // float double-precision |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
786 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
787 Float64 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
788 if (dynamic_cast<DcmFloatingPointDouble&>(element).getFloat64(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
789 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
790 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
791 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
792 else |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
793 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
794 return new DicomNullValue(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
795 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
796 } |
0 | 797 |
798 | |
799 /** | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
800 * Sequence types, should never occur at this point because of |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
801 * "element.isLeaf()". |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
802 **/ |
0 | 803 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
804 case EVR_SQ: // sequence of items |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
805 return new DicomNullValue; |
0 | 806 |
807 | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
808 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
809 * Internal to DCMTK. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
810 **/ |
0 | 811 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
812 case EVR_ox: // OB or OW depending on context |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
813 case EVR_xs: // SS or US depending on context |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
814 case EVR_lt: // US, SS or OW depending on context, used for LUT Data (thus the name) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
815 case EVR_na: // na="not applicable", for data which has no VR |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
816 case EVR_up: // up="unsigned pointer", used internally for DICOMDIR suppor |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
817 case EVR_item: // used internally for items |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
818 case EVR_metainfo: // used internally for meta info datasets |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
819 case EVR_dataset: // used internally for datasets |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
820 case EVR_fileFormat: // used internally for DICOM files |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
821 case EVR_dicomDir: // used internally for DICOMDIR objects |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
822 case EVR_dirRecord: // used internally for DICOMDIR records |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
823 case EVR_pixelSQ: // used internally for pixel sequences in a compressed image |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
824 case EVR_pixelItem: // used internally for pixel items in a compressed image |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
825 case EVR_UNKNOWN: // used internally for elements with unknown VR (encoded with 4-byte length field in explicit VR) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
826 case EVR_PixelData: // used internally for uncompressed pixeld data |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
827 case EVR_OverlayData: // used internally for overlay data |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
828 case EVR_UNKNOWN2B: // used internally for elements with unknown VR with 2-byte length field in explicit VR |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
829 return new DicomNullValue; |
0 | 830 |
831 | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
832 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
833 * Default case. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
834 **/ |
0 | 835 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
836 default: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
837 return new DicomNullValue; |
0 | 838 } |
839 } | |
840 catch (boost::bad_lexical_cast) | |
841 { | |
842 return new DicomNullValue; | |
843 } | |
844 } | |
845 | |
846 | |
847 static void StoreElement(Json::Value& target, | |
848 DcmElement& element, | |
849 unsigned int maxStringLength); | |
850 | |
851 static void StoreItem(Json::Value& target, | |
852 DcmItem& item, | |
853 unsigned int maxStringLength) | |
854 { | |
855 target = Json::Value(Json::objectValue); | |
856 | |
857 for (unsigned long i = 0; i < item.card(); i++) | |
858 { | |
859 DcmElement* element = item.getElement(i); | |
860 StoreElement(target, *element, maxStringLength); | |
861 } | |
862 } | |
863 | |
864 | |
865 static void StoreElement(Json::Value& target, | |
866 DcmElement& element, | |
867 unsigned int maxStringLength) | |
868 { | |
869 assert(target.type() == Json::objectValue); | |
870 | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
871 DicomTag tag(FromDcmtkBridge::GetTag(element)); |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
872 const std::string formattedTag = tag.Format(); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
873 |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
874 #if 0 |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
875 const std::string tagName = FromDcmtkBridge::GetName(tag); |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
876 #else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
877 // This version of the code gives access to the name of the private tags |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
878 DcmTag tagbis(element.getTag()); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
879 const std::string tagName(tagbis.getTagName()); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
880 #endif |
0 | 881 |
882 if (element.isLeaf()) | |
883 { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
884 Json::Value value(Json::objectValue); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
885 value["Name"] = tagName; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
886 |
0 | 887 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(element)); |
888 if (v->IsNull()) | |
889 { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
890 value["Type"] = "Null"; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
891 value["Value"] = Json::nullValue; |
0 | 892 } |
893 else | |
894 { | |
895 std::string s = v->AsString(); | |
896 if (maxStringLength == 0 || | |
897 s.size() <= maxStringLength) | |
898 { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
899 value["Type"] = "String"; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
900 value["Value"] = s; |
0 | 901 } |
902 else | |
903 { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
904 value["Type"] = "TooLong"; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
905 value["Value"] = Json::nullValue; |
0 | 906 } |
907 } | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
908 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
909 target[formattedTag] = value; |
0 | 910 } |
911 else | |
912 { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
913 Json::Value children(Json::arrayValue); |
0 | 914 |
915 // "All subclasses of DcmElement except for DcmSequenceOfItems | |
916 // are leaf nodes, while DcmSequenceOfItems, DcmItem, DcmDataset | |
917 // etc. are not." The following cast is thus OK. | |
918 DcmSequenceOfItems& sequence = dynamic_cast<DcmSequenceOfItems&>(element); | |
919 | |
920 for (unsigned long i = 0; i < sequence.card(); i++) | |
921 { | |
922 DcmItem* child = sequence.getItem(i); | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
923 Json::Value& v = children.append(Json::objectValue); |
0 | 924 StoreItem(v, *child, maxStringLength); |
925 } | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
926 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
927 target[formattedTag]["Name"] = tagName; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
928 target[formattedTag]["Type"] = "Sequence"; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
929 target[formattedTag]["Value"] = children; |
0 | 930 } |
931 } | |
932 | |
933 | |
934 void FromDcmtkBridge::ToJson(Json::Value& root, | |
935 DcmDataset& dataset, | |
936 unsigned int maxStringLength) | |
937 { | |
938 StoreItem(root, dataset, maxStringLength); | |
939 } | |
940 | |
941 | |
942 | |
943 void FromDcmtkBridge::ToJson(Json::Value& target, | |
944 const std::string& path, | |
945 unsigned int maxStringLength) | |
946 { | |
947 DcmFileFormat dicom; | |
948 if (!dicom.loadFile(path.c_str()).good()) | |
949 { | |
62 | 950 throw OrthancException(ErrorCode_BadFileFormat); |
0 | 951 } |
952 else | |
953 { | |
954 FromDcmtkBridge::ToJson(target, *dicom.getDataset(), maxStringLength); | |
955 } | |
956 } | |
957 | |
958 | |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
959 static void ExtractPngImagePreview(std::string& result, |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
960 DicomIntegerPixelAccessor& accessor) |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
961 { |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
962 PngWriter w; |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
963 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
964 int32_t min, max; |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
965 accessor.GetExtremeValues(min, max); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
966 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
967 std::vector<uint8_t> image(accessor.GetWidth() * accessor.GetHeight(), 0); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
968 if (min != max) |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
969 { |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
970 uint8_t* pixel = &image[0]; |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
971 for (unsigned int y = 0; y < accessor.GetHeight(); y++) |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
972 { |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
973 for (unsigned int x = 0; x < accessor.GetWidth(); x++, pixel++) |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
974 { |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
975 int32_t v = accessor.GetValue(x, y); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
976 *pixel = static_cast<uint8_t>( |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
977 boost::math::lround(static_cast<float>(v - min) / |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
978 static_cast<float>(max - min) * 255.0f)); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
979 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
980 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
981 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
982 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
983 w.WriteToMemory(result, accessor.GetWidth(), accessor.GetHeight(), |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
984 accessor.GetWidth(), PixelFormat_Grayscale8, &image[0]); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
985 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
986 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
987 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
988 template <typename T> |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
989 static void ExtractPngImageTruncate(std::string& result, |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
990 DicomIntegerPixelAccessor& accessor, |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
991 PixelFormat format) |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
992 { |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
993 PngWriter w; |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
994 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
995 std::vector<T> image(accessor.GetWidth() * accessor.GetHeight(), 0); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
996 T* pixel = &image[0]; |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
997 for (unsigned int y = 0; y < accessor.GetHeight(); y++) |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
998 { |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
999 for (unsigned int x = 0; x < accessor.GetWidth(); x++, pixel++) |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1000 { |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1001 int32_t v = accessor.GetValue(x, y); |
73 | 1002 if (v < std::numeric_limits<T>::min()) |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1003 *pixel = std::numeric_limits<T>::min(); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1004 else if (v > std::numeric_limits<T>::max()) |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1005 *pixel = std::numeric_limits<T>::max(); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1006 else |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1007 *pixel = static_cast<T>(v); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1008 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1009 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1010 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1011 w.WriteToMemory(result, accessor.GetWidth(), accessor.GetHeight(), |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1012 accessor.GetWidth() * sizeof(T), format, &image[0]); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1013 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1014 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1015 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1016 void FromDcmtkBridge::ExtractPngImage(std::string& result, |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1017 DcmDataset& dataset, |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
1018 unsigned int frame, |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1019 ImageExtractionMode mode) |
0 | 1020 { |
1021 // See also: http://support.dcmtk.org/wiki/dcmtk/howto/accessing-compressed-data | |
1022 | |
1023 std::auto_ptr<DicomIntegerPixelAccessor> accessor; | |
1024 | |
1025 DicomMap m; | |
1026 FromDcmtkBridge::Convert(m, dataset); | |
1027 | |
1028 DcmElement* e; | |
80 | 1029 if (dataset.findAndGetElement(ToDcmtkBridge::Convert(DICOM_TAG_PIXEL_DATA), e).good() && |
0 | 1030 e != NULL) |
1031 { | |
1032 Uint8* pixData = NULL; | |
1033 if (e->getUint8Array(pixData) == EC_Normal) | |
1034 { | |
1035 accessor.reset(new DicomIntegerPixelAccessor(m, pixData, e->getLength())); | |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
1036 accessor->SetCurrentFrame(frame); |
0 | 1037 } |
1038 } | |
1039 | |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1040 PixelFormat format; |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1041 switch (mode) |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1042 { |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1043 case ImageExtractionMode_Preview: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1044 case ImageExtractionMode_UInt8: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1045 format = PixelFormat_Grayscale8; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1046 break; |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1047 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1048 case ImageExtractionMode_UInt16: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1049 format = PixelFormat_Grayscale16; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1050 break; |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1051 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1052 default: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1053 throw OrthancException(ErrorCode_NotImplemented); |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1054 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1055 |
0 | 1056 if (accessor.get() == NULL || |
1057 accessor->GetWidth() == 0 || | |
1058 accessor->GetHeight() == 0) | |
1059 { | |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1060 PngWriter w; |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1061 w.WriteToMemory(result, 0, 0, 0, format, NULL); |
0 | 1062 } |
1063 else | |
1064 { | |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1065 switch (mode) |
0 | 1066 { |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1067 case ImageExtractionMode_Preview: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1068 ExtractPngImagePreview(result, *accessor); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1069 break; |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1070 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1071 case ImageExtractionMode_UInt8: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1072 ExtractPngImageTruncate<uint8_t>(result, *accessor, format); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1073 break; |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1074 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1075 case ImageExtractionMode_UInt16: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1076 ExtractPngImageTruncate<uint16_t>(result, *accessor, format); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1077 break; |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1078 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1079 default: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1080 throw OrthancException(ErrorCode_NotImplemented); |
0 | 1081 } |
1082 } | |
1083 } | |
1084 | |
1085 | |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1086 void FromDcmtkBridge::ExtractPngImage(std::string& result, |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1087 const std::string& dicomContent, |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
1088 unsigned int frame, |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1089 ImageExtractionMode mode) |
0 | 1090 { |
1091 DcmInputBufferStream is; | |
1092 if (dicomContent.size() > 0) | |
1093 { | |
1094 is.setBuffer(&dicomContent[0], dicomContent.size()); | |
1095 } | |
1096 is.setEos(); | |
1097 | |
1098 DcmFileFormat dicom; | |
1099 if (dicom.read(is).good()) | |
1100 { | |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
1101 ExtractPngImage(result, *dicom.getDataset(), frame, mode); |
0 | 1102 } |
1103 else | |
1104 { | |
62 | 1105 throw OrthancException(ErrorCode_BadFileFormat); |
0 | 1106 } |
1107 } | |
1108 | |
1109 | |
1110 | |
1111 std::string FromDcmtkBridge::GetName(const DicomTag& t) | |
1112 { | |
106 | 1113 // Some patches for important tags because of different DICOM |
1114 // dictionaries between DCMTK versions | |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1115 std::string n = t.GetMainTagsName(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1116 if (n.size() != 0) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1117 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1118 return n; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1119 } |
106 | 1120 // End of patches |
1121 | |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1122 #if 0 |
0 | 1123 DcmTagKey tag(t.GetGroup(), t.GetElement()); |
1124 const DcmDataDictionary& dict = dcmDataDict.rdlock(); | |
1125 const DcmDictEntry* entry = dict.findEntry(tag, NULL); | |
1126 | |
1127 std::string s("Unknown"); | |
1128 if (entry != NULL) | |
1129 { | |
1130 s = std::string(entry->getTagName()); | |
1131 } | |
1132 | |
1133 dcmDataDict.unlock(); | |
1134 return s; | |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1135 #else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1136 DcmTag tag(t.GetGroup(), t.GetElement()); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1137 const char* name = tag.getTagName(); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1138 if (name == NULL) |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1139 { |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1140 return "Unknown"; |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1141 } |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1142 else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1143 { |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1144 return std::string(name); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1145 } |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1146 #endif |
0 | 1147 } |
1148 | |
1149 | |
304 | 1150 DicomTag FromDcmtkBridge::ParseTag(const char* name) |
0 | 1151 { |
304 | 1152 if (strlen(name) == 9 && |
1153 isxdigit(name[0]) && | |
1154 isxdigit(name[1]) && | |
1155 isxdigit(name[2]) && | |
1156 isxdigit(name[3]) && | |
1157 name[4] == '-' && | |
1158 isxdigit(name[5]) && | |
1159 isxdigit(name[6]) && | |
1160 isxdigit(name[7]) && | |
1161 isxdigit(name[8])) | |
1162 { | |
1163 uint16_t group = GetTagValue(name); | |
1164 uint16_t element = GetTagValue(name + 5); | |
1165 return DicomTag(group, element); | |
1166 } | |
1167 | |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1168 #if 0 |
0 | 1169 const DcmDataDictionary& dict = dcmDataDict.rdlock(); |
1170 const DcmDictEntry* entry = dict.findEntry(name); | |
1171 | |
1172 if (entry == NULL) | |
1173 { | |
1174 dcmDataDict.unlock(); | |
62 | 1175 throw OrthancException("Unknown DICOM tag"); |
0 | 1176 } |
1177 else | |
1178 { | |
1179 DcmTagKey key = entry->getKey(); | |
1180 DicomTag tag(key.getGroup(), key.getElement()); | |
1181 dcmDataDict.unlock(); | |
1182 return tag; | |
1183 } | |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1184 #else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1185 DcmTag tag; |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1186 if (DcmTag::findTagFromName(name, tag).good()) |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1187 { |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1188 return DicomTag(tag.getGTag(), tag.getETag()); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1189 } |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1190 else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1191 { |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1192 throw OrthancException("Unknown DICOM tag"); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1193 } |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1194 #endif |
0 | 1195 } |
1196 | |
1197 | |
1198 void FromDcmtkBridge::Print(FILE* fp, const DicomMap& m) | |
1199 { | |
1200 for (DicomMap::Map::const_iterator | |
1201 it = m.map_.begin(); it != m.map_.end(); it++) | |
1202 { | |
1203 DicomTag t = it->first; | |
1204 std::string s = it->second->AsString(); | |
1205 printf("0x%04x 0x%04x (%s) [%s]\n", t.GetGroup(), t.GetElement(), GetName(t).c_str(), s.c_str()); | |
1206 } | |
1207 } | |
1208 | |
1209 | |
1210 void FromDcmtkBridge::ToJson(Json::Value& result, | |
1211 const DicomMap& values) | |
1212 { | |
1213 if (result.type() != Json::objectValue) | |
1214 { | |
62 | 1215 throw OrthancException(ErrorCode_BadParameterType); |
0 | 1216 } |
1217 | |
1218 result.clear(); | |
1219 | |
1220 for (DicomMap::Map::const_iterator | |
1221 it = values.map_.begin(); it != values.map_.end(); it++) | |
1222 { | |
1223 result[GetName(it->first)] = it->second->AsString(); | |
1224 } | |
1225 } | |
176 | 1226 |
1227 | |
1228 std::string FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel level) | |
1229 { | |
1230 char uid[100]; | |
1231 | |
1232 switch (level) | |
1233 { | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1234 case DicomRootLevel_Instance: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1235 return dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT); |
176 | 1236 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1237 case DicomRootLevel_Series: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1238 return dcmGenerateUniqueIdentifier(uid, SITE_SERIES_UID_ROOT); |
176 | 1239 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1240 case DicomRootLevel_Study: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1241 return dcmGenerateUniqueIdentifier(uid, SITE_STUDY_UID_ROOT); |
176 | 1242 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1243 default: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1244 throw OrthancException(ErrorCode_ParameterOutOfRange); |
176 | 1245 } |
1246 } | |
1247 | |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1248 bool FromDcmtkBridge::SaveToMemoryBuffer(std::string& buffer, |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1249 DcmDataset* dataSet) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1250 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1251 // Determine the transfer syntax which shall be used to write the |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1252 // information to the file. We always switch to the Little Endian |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1253 // syntax, with explicit length. |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1254 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1255 // http://support.dcmtk.org/docs/dcxfer_8h-source.html |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1256 E_TransferSyntax xfer = EXS_LittleEndianExplicit; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1257 E_EncodingType encodingType = /*opt_sequenceType*/ EET_ExplicitLength; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1258 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1259 uint32_t s = dataSet->getLength(xfer, encodingType); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1260 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1261 buffer.resize(s); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1262 DcmOutputBufferStream ob(&buffer[0], s); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1263 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1264 dataSet->transferInit(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1265 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1266 #if DCMTK_VERSION_NUMBER >= 360 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1267 OFCondition c = dataSet->write(ob, xfer, encodingType, NULL, |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1268 /*opt_groupLength*/ EGL_recalcGL, |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1269 /*opt_paddingType*/ EPD_withoutPadding); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1270 #else |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1271 OFCondition c = dataSet->write(ob, xfer, encodingType, NULL); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1272 #endif |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1273 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1274 dataSet->transferEnd(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1275 if (c.good()) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1276 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1277 return true; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1278 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1279 else |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1280 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1281 buffer.clear(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1282 return false; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1283 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1284 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1285 #if 0 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1286 OFCondition cond = cbdata->dcmff->saveFile(fileName.c_str(), xfer, |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1287 encodingType, |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1288 /*opt_groupLength*/ EGL_recalcGL, |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1289 /*opt_paddingType*/ EPD_withoutPadding, |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1290 OFstatic_cast(Uint32, /*opt_filepad*/ 0), |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1291 OFstatic_cast(Uint32, /*opt_itempad*/ 0), |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1292 (opt_useMetaheader) ? EWM_fileformat : EWM_dataset); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1293 #endif |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1294 } |
0 | 1295 } |