Mercurial > hg > orthanc
annotate OrthancServer/FromDcmtkBridge.cpp @ 399:4d5f0857ec9c
copyright update
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 30 Apr 2013 10:54:46 +0200 |
parents | 4632a044746e |
children | ab070786f478 |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
399 | 3 * Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege, |
0 | 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" |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
42 #include "../Core/Uuid.h" |
0 | 43 #include "../Core/DicomFormat/DicomString.h" |
44 #include "../Core/DicomFormat/DicomNullValue.h" | |
79 | 45 #include "../Core/DicomFormat/DicomIntegerPixelAccessor.h" |
0 | 46 |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
47 #include <list> |
71 | 48 #include <limits> |
49 | |
0 | 50 #include <boost/lexical_cast.hpp> |
51 | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
52 #include <dcmtk/dcmdata/dcchrstr.h> |
0 | 53 #include <dcmtk/dcmdata/dcdicent.h> |
54 #include <dcmtk/dcmdata/dcdict.h> | |
55 #include <dcmtk/dcmdata/dcfilefo.h> | |
56 #include <dcmtk/dcmdata/dcistrmb.h> | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
57 #include <dcmtk/dcmdata/dcuid.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
58 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
59 #include <dcmtk/dcmdata/dcvrae.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
60 #include <dcmtk/dcmdata/dcvras.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
61 #include <dcmtk/dcmdata/dcvrcs.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
62 #include <dcmtk/dcmdata/dcvrda.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
63 #include <dcmtk/dcmdata/dcvrds.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
64 #include <dcmtk/dcmdata/dcvrdt.h> |
0 | 65 #include <dcmtk/dcmdata/dcvrfd.h> |
66 #include <dcmtk/dcmdata/dcvrfl.h> | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
67 #include <dcmtk/dcmdata/dcvris.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
68 #include <dcmtk/dcmdata/dcvrlo.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
69 #include <dcmtk/dcmdata/dcvrlt.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
70 #include <dcmtk/dcmdata/dcvrpn.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
71 #include <dcmtk/dcmdata/dcvrsh.h> |
0 | 72 #include <dcmtk/dcmdata/dcvrsl.h> |
73 #include <dcmtk/dcmdata/dcvrss.h> | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
74 #include <dcmtk/dcmdata/dcvrst.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
75 #include <dcmtk/dcmdata/dcvrtm.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
76 #include <dcmtk/dcmdata/dcvrui.h> |
0 | 77 #include <dcmtk/dcmdata/dcvrul.h> |
78 #include <dcmtk/dcmdata/dcvrus.h> | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
79 #include <dcmtk/dcmdata/dcvrut.h> |
0 | 80 |
2 | 81 #include <boost/math/special_functions/round.hpp> |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
82 #include <glog/logging.h> |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
83 #include <dcmtk/dcmdata/dcostrmb.h> |
0 | 84 |
62 | 85 namespace Orthanc |
0 | 86 { |
304 | 87 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
|
88 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
89 DcmInputBufferStream is; |
304 | 90 if (size > 0) |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
91 { |
304 | 92 is.setBuffer(buffer, size); |
285
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 is.setEos(); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
95 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
96 file_.reset(new DcmFileFormat); |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
97 file_->transferInit(); |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
98 if (!file_->read(is).good()) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
99 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
100 throw OrthancException(ErrorCode_BadFileFormat); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
101 } |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
102 file_->loadAllDataIntoMemory(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
103 file_->transferEnd(); |
285
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 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
106 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
107 static void SendPathValueForDictionary(RestApiOutput& output, |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
108 DcmItem& dicom) |
285
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 Json::Value v = Json::arrayValue; |
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 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
|
113 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
114 DcmElement* element = dicom.getElement(i); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
115 if (element) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
116 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
117 char buf[16]; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
118 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
|
119 v.append(buf); |
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 } |
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 output.AnswerJson(v); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
124 } |
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 static inline uint16_t GetCharValue(char c) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
127 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
128 if (c >= '0' && c <= '9') |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
129 return c - '0'; |
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 if (c >= 'A' && c <= 'F') |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
133 return c - 'A' + 10; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
134 else |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
135 return 0; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
136 } |
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 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
|
139 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
140 return ((GetCharValue(c[0]) << 12) + |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
141 (GetCharValue(c[1]) << 8) + |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
142 (GetCharValue(c[2]) << 4) + |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
143 GetCharValue(c[3])); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
144 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
145 |
304 | 146 static void ParseTagAndGroup(DcmTagKey& key, |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
147 const std::string& tag) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
148 { |
304 | 149 DicomTag t = FromDcmtkBridge::ParseTag(tag); |
150 key = DcmTagKey(t.GetGroup(), t.GetElement()); | |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
151 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
152 |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
153 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
154 static void SendSequence(RestApiOutput& output, |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
155 DcmSequenceOfItems& sequence) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
156 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
157 // This element is a sequence |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
158 Json::Value v = Json::arrayValue; |
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 for (unsigned long i = 0; i < sequence.card(); 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 v.append(boost::lexical_cast<std::string>(i)); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
163 } |
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 output.AnswerJson(v); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
166 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
167 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
168 static void AnswerDicomField(RestApiOutput& output, |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
169 DcmElement& element) |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
170 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
171 // This element is not a sequence |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
172 std::string buffer; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
173 buffer.resize(65536); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
174 Uint32 length = element.getLength(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
175 Uint32 offset = 0; |
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 output.GetLowLevelOutput().SendOkHeader("application/octet-stream", true, length, NULL); |
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 while (offset < length) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
180 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
181 Uint32 nbytes; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
182 if (length - offset < buffer.size()) |
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 nbytes = length - offset; |
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 else |
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 nbytes = buffer.size(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
189 } |
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 if (element.getPartialValue(&buffer[0], offset, nbytes).good()) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
192 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
193 output.GetLowLevelOutput().Send(&buffer[0], nbytes); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
194 offset += nbytes; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
195 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
196 else |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
197 { |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
198 LOG(ERROR) << "Error while sending a DICOM field"; |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
199 return; |
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 } |
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 output.MarkLowLevelOutputDone(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
204 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
205 |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
206 static void SendPathValueForLeaf(RestApiOutput& output, |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
207 const std::string& tag, |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
208 DcmItem& dicom) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
209 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
210 DcmTagKey k; |
304 | 211 ParseTagAndGroup(k, tag); |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
212 |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
213 DcmSequenceOfItems* sequence = NULL; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
214 if (dicom.findAndGetSequence(k, sequence).good() && |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
215 sequence != NULL && |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
216 sequence->getVR() == EVR_SQ) |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
217 { |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
218 SendSequence(output, *sequence); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
219 return; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
220 } |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
221 |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
222 DcmElement* element = NULL; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
223 if (dicom.findAndGetElement(k, element).good() && |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
224 element != NULL && |
318
b83d85a85d69
fix for private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
225 //element->getVR() != EVR_UNKNOWN && // This would forbid private tags |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
226 element->getVR() != EVR_SQ) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
227 { |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
228 AnswerDicomField(output, *element); |
285
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 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
231 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
232 void ParsedDicomFile::SendPathValue(RestApiOutput& output, |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
233 const UriComponents& uri) |
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 DcmItem* dicom = file_->getDataset(); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
236 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
237 // 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
|
238 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
|
239 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
240 size_t index; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
241 try |
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 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
|
244 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
245 catch (boost::bad_lexical_cast&) |
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 return; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
248 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
249 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
250 DcmTagKey k; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
251 DcmItem *child = NULL; |
304 | 252 ParseTagAndGroup(k, uri[2 * pos]); |
253 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
|
254 child == NULL) |
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 return; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
257 } |
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 dicom = child; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
260 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
261 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
262 // 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
|
263 if (uri.size() % 2 == 0) |
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 SendPathValueForDictionary(output, *dicom); |
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 else |
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 SendPathValueForLeaf(output, uri.back(), *dicom); |
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 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
272 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
273 |
302
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 |
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 static DcmElement* CreateElementForTag(const DicomTag& tag) |
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 DcmTag key(tag.GetGroup(), tag.GetElement()); |
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 switch (key.getEVR()) |
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 // http://support.dcmtk.org/docs/dcvr_8h-source.html |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
284 |
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 * TODO. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
287 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
288 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
289 case EVR_OB: // other byte |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
290 case EVR_OF: // other float |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
291 case EVR_OW: // other word |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
292 case EVR_AT: // attribute tag |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
293 throw OrthancException(ErrorCode_NotImplemented); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
294 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
295 case EVR_UN: // unknown value representation |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
296 throw OrthancException(ErrorCode_ParameterOutOfRange); |
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 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
299 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
300 * String types. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
301 * http://support.dcmtk.org/docs/classDcmByteString.html |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
302 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
303 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
304 case EVR_AS: // age string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
305 return new DcmAgeString(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
306 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
307 case EVR_AE: // application entity title |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
308 return new DcmApplicationEntity(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
309 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
310 case EVR_CS: // code string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
311 return new DcmCodeString(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
312 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
313 case EVR_DA: // date string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
314 return new DcmDate(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
315 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
316 case EVR_DT: // date time string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
317 return new DcmDateTime(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
318 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
319 case EVR_DS: // decimal string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
320 return new DcmDecimalString(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
321 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
322 case EVR_IS: // integer string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
323 return new DcmIntegerString(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
324 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
325 case EVR_TM: // time string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
326 return new DcmTime(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
327 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
328 case EVR_UI: // unique identifier |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
329 return new DcmUniqueIdentifier(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
330 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
331 case EVR_ST: // short text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
332 return new DcmShortText(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
333 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
334 case EVR_LO: // long string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
335 return new DcmLongString(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
336 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
337 case EVR_LT: // long text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
338 return new DcmLongText(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
339 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
340 case EVR_UT: // unlimited text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
341 return new DcmUnlimitedText(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
342 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
343 case EVR_SH: // short string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
344 return new DcmShortString(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
345 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
346 case EVR_PN: // person name |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
347 return new DcmPersonName(key); |
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 |
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 * Numerical types |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
352 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
353 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
354 case EVR_SL: // signed long |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
355 return new DcmSignedLong(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
356 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
357 case EVR_SS: // signed short |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
358 return new DcmSignedShort(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
359 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
360 case EVR_UL: // unsigned long |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
361 return new DcmUnsignedLong(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
362 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
363 case EVR_US: // unsigned short |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
364 return new DcmUnsignedShort(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
365 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
366 case EVR_FL: // float single-precision |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
367 return new DcmFloatingPointSingle(key); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
368 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
369 case EVR_FD: // float double-precision |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
370 return new DcmFloatingPointDouble(key); |
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 |
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 * Sequence types, should never occur at this point. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
375 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
376 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
377 case EVR_SQ: // sequence of items |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
378 throw OrthancException(ErrorCode_ParameterOutOfRange); |
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 |
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 * Internal to DCMTK. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
383 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
384 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
385 case EVR_ox: // OB or OW depending on context |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
386 case EVR_xs: // SS or US depending on context |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
387 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
|
388 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
|
389 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
|
390 case EVR_item: // used internally for items |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
391 case EVR_metainfo: // used internally for meta info datasets |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
392 case EVR_dataset: // used internally for datasets |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
393 case EVR_fileFormat: // used internally for DICOM files |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
394 case EVR_dicomDir: // used internally for DICOMDIR objects |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
395 case EVR_dirRecord: // used internally for DICOMDIR records |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
396 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
|
397 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
|
398 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
|
399 case EVR_PixelData: // used internally for uncompressed pixeld data |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
400 case EVR_OverlayData: // used internally for overlay data |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
401 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
|
402 default: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
403 break; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
404 } |
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 throw OrthancException(ErrorCode_InternalError); |
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 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
410 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
411 static void FillElementWithString(DcmElement& element, |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
412 const DicomTag& tag, |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
413 const std::string& value) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
414 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
415 DcmTag key(tag.GetGroup(), tag.GetElement()); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
416 bool ok = false; |
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 try |
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 switch (key.getEVR()) |
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 // http://support.dcmtk.org/docs/dcvr_8h-source.html |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
423 |
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 * TODO. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
426 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
427 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
428 case EVR_OB: // other byte |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
429 case EVR_OF: // other float |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
430 case EVR_OW: // other word |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
431 case EVR_AT: // attribute tag |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
432 throw OrthancException(ErrorCode_NotImplemented); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
433 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
434 case EVR_UN: // unknown value representation |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
435 throw OrthancException(ErrorCode_ParameterOutOfRange); |
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 |
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 * String types. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
440 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
441 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
442 case EVR_DS: // decimal string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
443 case EVR_IS: // integer string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
444 case EVR_AS: // age string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
445 case EVR_DA: // date string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
446 case EVR_DT: // date time string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
447 case EVR_TM: // time string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
448 case EVR_AE: // application entity title |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
449 case EVR_CS: // code string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
450 case EVR_SH: // short string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
451 case EVR_LO: // long string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
452 case EVR_ST: // short text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
453 case EVR_LT: // long text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
454 case EVR_UT: // unlimited text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
455 case EVR_PN: // person name |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
456 case EVR_UI: // unique identifier |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
457 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
458 ok = element.putString(value.c_str()).good(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
459 break; |
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 |
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 * Numerical types |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
465 **/ |
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 case EVR_SL: // signed long |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
468 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
469 ok = element.putSint32(boost::lexical_cast<Sint32>(value)).good(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
470 break; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
471 } |
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 case EVR_SS: // signed short |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
474 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
475 ok = element.putSint16(boost::lexical_cast<Sint16>(value)).good(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
476 break; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
477 } |
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 case EVR_UL: // unsigned long |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
480 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
481 ok = element.putUint32(boost::lexical_cast<Uint32>(value)).good(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
482 break; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
483 } |
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 case EVR_US: // unsigned short |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
486 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
487 ok = element.putUint16(boost::lexical_cast<Uint16>(value)).good(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
488 break; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
489 } |
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 case EVR_FL: // float single-precision |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
492 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
493 ok = element.putFloat32(boost::lexical_cast<float>(value)).good(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
494 break; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
495 } |
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 case EVR_FD: // float double-precision |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
498 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
499 ok = element.putFloat64(boost::lexical_cast<double>(value)).good(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
500 break; |
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 |
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 * Sequence types, should never occur at this point. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
506 **/ |
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 case EVR_SQ: // sequence of items |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
509 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
510 ok = false; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
511 break; |
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 |
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 * Internal to DCMTK. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
517 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
518 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
519 case EVR_ox: // OB or OW depending on context |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
520 case EVR_xs: // SS or US depending on context |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
521 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
|
522 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
|
523 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
|
524 case EVR_item: // used internally for items |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
525 case EVR_metainfo: // used internally for meta info datasets |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
526 case EVR_dataset: // used internally for datasets |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
527 case EVR_fileFormat: // used internally for DICOM files |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
528 case EVR_dicomDir: // used internally for DICOMDIR objects |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
529 case EVR_dirRecord: // used internally for DICOMDIR records |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
530 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
|
531 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
|
532 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
|
533 case EVR_PixelData: // used internally for uncompressed pixeld data |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
534 case EVR_OverlayData: // used internally for overlay data |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
535 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
|
536 default: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
537 break; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
538 } |
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 catch (boost::bad_lexical_cast&) |
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 ok = false; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
543 } |
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 if (!ok) |
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 throw OrthancException(ErrorCode_InternalError); |
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 |
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 void ParsedDicomFile::Remove(const DicomTag& tag) |
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 DcmTagKey key(tag.GetGroup(), tag.GetElement()); |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
555 DcmElement* element = file_->getDataset()->remove(key); |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
556 if (element != NULL) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
557 { |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
558 delete element; |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
559 } |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
560 } |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
561 |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
562 |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
563 |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
564 void ParsedDicomFile::RemovePrivateTags() |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
565 { |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
566 typedef std::list<DcmElement*> Tags; |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
567 |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
568 Tags privateTags; |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
569 |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
570 DcmDataset& dataset = *file_->getDataset(); |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
571 for (unsigned long i = 0; i < dataset.card(); i++) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
572 { |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
573 DcmElement* element = dataset.getElement(i); |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
574 DcmTag tag(element->getTag()); |
311 | 575 if (!strcmp("PrivateCreator", tag.getTagName()) || // TODO - This may change with future versions of DCMTK |
576 tag.getPrivateCreator() != NULL) | |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
577 { |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
578 privateTags.push_back(element); |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
579 } |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
580 } |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
581 |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
582 for (Tags::iterator it = privateTags.begin(); |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
583 it != privateTags.end(); it++) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
584 { |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
585 DcmElement* tmp = dataset.remove(*it); |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
586 if (tmp != NULL) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
587 { |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
588 delete tmp; |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
589 } |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
590 } |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
591 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
592 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
593 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
594 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
595 void ParsedDicomFile::Insert(const DicomTag& tag, |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
596 const std::string& value) |
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 std::auto_ptr<DcmElement> element(CreateElementForTag(tag)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
599 FillElementWithString(*element, tag, value); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
600 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
601 if (!file_->getDataset()->insert(element.release(), false, false).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
602 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
603 // This field already exists |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
604 throw OrthancException(ErrorCode_InternalError); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
605 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
606 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
607 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
608 |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
609 void ParsedDicomFile::Replace(const DicomTag& tag, |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
610 const std::string& value, |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
611 DicomReplaceMode mode) |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
612 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
613 DcmTagKey key(tag.GetGroup(), tag.GetElement()); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
614 DcmElement* element = NULL; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
615 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
616 if (!file_->getDataset()->findAndGetElement(key, element).good() || |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
617 element == NULL) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
618 { |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
619 // 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
|
620 switch (mode) |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
621 { |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
622 case DicomReplaceMode_InsertIfAbsent: |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
623 Insert(tag, value); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
624 break; |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
625 |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
626 case DicomReplaceMode_ThrowIfAbsent: |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
627 throw OrthancException(ErrorCode_InexistentItem); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
628 |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
629 case DicomReplaceMode_IgnoreIfAbsent: |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
630 return; |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
631 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
632 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
633 else |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
634 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
635 FillElementWithString(*element, tag, value); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
636 } |
303
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
637 |
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
638 |
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
639 /** |
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
640 * dcmodify will automatically correct 'Media Storage SOP Class |
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
641 * 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
|
642 * 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
|
643 * UID' and 'SOP Instance UID') via insert or modify mode |
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
644 * options. You can disable this behaviour by using the -nmu |
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
645 * option. |
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
646 **/ |
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
647 if (tag == DICOM_TAG_SOP_CLASS_UID) |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
648 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
|
649 |
c76a35a85c69
ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
650 if (tag == DICOM_TAG_SOP_INSTANCE_UID) |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
651 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
|
652 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
653 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
654 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
655 void ParsedDicomFile::Answer(RestApiOutput& output) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
656 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
657 std::string serialized; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
658 if (FromDcmtkBridge::SaveToMemoryBuffer(serialized, file_->getDataset())) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
659 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
660 output.AnswerBuffer(serialized, "application/octet-stream"); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
661 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
662 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
663 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
664 |
308
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
665 |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
666 bool ParsedDicomFile::GetTagValue(std::string& value, |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
667 const DicomTag& tag) |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
668 { |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
669 DcmTagKey k(tag.GetGroup(), tag.GetElement()); |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
670 DcmDataset& dataset = *file_->getDataset(); |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
671 DcmElement* element = NULL; |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
672 if (!dataset.findAndGetElement(k, element).good() || |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
673 element == NULL) |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
674 { |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
675 return false; |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
676 } |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
677 |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
678 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(*element)); |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
679 |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
680 if (v.get() == NULL) |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
681 { |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
682 value = ""; |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
683 } |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
684 else |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
685 { |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
686 value = v->AsString(); |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
687 } |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
688 |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
689 return true; |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
690 } |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
691 |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
692 |
315 | 693 |
694 DicomInstanceHasher ParsedDicomFile::GetHasher() | |
695 { | |
696 std::string patientId, studyUid, seriesUid, instanceUid; | |
697 | |
698 if (!GetTagValue(patientId, DICOM_TAG_PATIENT_ID) || | |
699 !GetTagValue(studyUid, DICOM_TAG_STUDY_INSTANCE_UID) || | |
700 !GetTagValue(seriesUid, DICOM_TAG_SERIES_INSTANCE_UID) || | |
701 !GetTagValue(instanceUid, DICOM_TAG_SOP_INSTANCE_UID)) | |
702 { | |
703 throw OrthancException(ErrorCode_BadFileFormat); | |
704 } | |
705 | |
706 return DicomInstanceHasher(patientId, studyUid, seriesUid, instanceUid); | |
707 } | |
708 | |
709 | |
0 | 710 void FromDcmtkBridge::Convert(DicomMap& target, DcmDataset& dataset) |
711 { | |
712 target.Clear(); | |
713 for (unsigned long i = 0; i < dataset.card(); i++) | |
714 { | |
715 DcmElement* element = dataset.getElement(i); | |
716 if (element && element->isLeaf()) | |
717 { | |
718 target.SetValue(element->getTag().getGTag(), | |
719 element->getTag().getETag(), | |
720 ConvertLeafElement(*element)); | |
721 } | |
722 } | |
723 } | |
724 | |
725 | |
726 DicomTag FromDcmtkBridge::GetTag(const DcmElement& element) | |
727 { | |
728 return DicomTag(element.getGTag(), element.getETag()); | |
729 } | |
730 | |
731 | |
732 DicomValue* FromDcmtkBridge::ConvertLeafElement(DcmElement& element) | |
733 { | |
734 if (!element.isLeaf()) | |
735 { | |
62 | 736 throw OrthancException("Only applicable to leaf elements"); |
0 | 737 } |
738 | |
739 if (element.isaString()) | |
740 { | |
741 char *c; | |
742 if (element.getString(c).good() && | |
743 c != NULL) | |
744 { | |
745 std::string s(c); | |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
106
diff
changeset
|
746 std::string utf8 = Toolbox::ConvertToUtf8(s, "ISO-8859-1"); // TODO Parameter? |
0 | 747 return new DicomString(utf8); |
748 } | |
749 else | |
750 { | |
751 return new DicomNullValue; | |
752 } | |
753 } | |
754 | |
755 try | |
756 { | |
757 // http://support.dcmtk.org/docs/dcvr_8h-source.html | |
758 switch (element.getVR()) | |
759 { | |
760 | |
761 /** | |
762 * TODO. | |
763 **/ | |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
764 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
765 case EVR_OB: // other byte |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
766 case EVR_OF: // other float |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
767 case EVR_OW: // other word |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
768 case EVR_AT: // attribute tag |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
769 case EVR_UN: // unknown value representation |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
770 return new DicomNullValue(); |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
771 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
772 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
773 * 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
|
774 * "element.isaString()". |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
775 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
776 |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
777 case EVR_DS: // decimal string |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
778 case EVR_IS: // integer string |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
779 case EVR_AS: // age string |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
780 case EVR_DA: // date string |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
781 case EVR_DT: // date time string |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
782 case EVR_TM: // time string |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
783 case EVR_AE: // application entity title |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
784 case EVR_CS: // code string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
785 case EVR_SH: // short string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
786 case EVR_LO: // long string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
787 case EVR_ST: // short text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
788 case EVR_LT: // long text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
789 case EVR_UT: // unlimited text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
790 case EVR_PN: // person name |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
791 case EVR_UI: // unique identifier |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
792 return new DicomNullValue(); |
0 | 793 |
794 | |
302
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 * Numerical types |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
797 **/ |
0 | 798 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
799 case EVR_SL: // signed long |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
800 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
801 Sint32 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
802 if (dynamic_cast<DcmSignedLong&>(element).getSint32(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
803 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
804 else |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
805 return new DicomNullValue(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
806 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
807 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
808 case EVR_SS: // signed short |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
809 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
810 Sint16 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
811 if (dynamic_cast<DcmSignedShort&>(element).getSint16(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
812 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
813 else |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
814 return new DicomNullValue(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
815 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
816 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
817 case EVR_UL: // unsigned long |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
818 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
819 Uint32 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
820 if (dynamic_cast<DcmUnsignedLong&>(element).getUint32(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
821 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
822 else |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
823 return new DicomNullValue(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
824 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
825 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
826 case EVR_US: // unsigned short |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
827 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
828 Uint16 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
829 if (dynamic_cast<DcmUnsignedShort&>(element).getUint16(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
830 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
831 else |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
832 return new DicomNullValue(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
833 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
834 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
835 case EVR_FL: // float single-precision |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
836 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
837 Float32 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
838 if (dynamic_cast<DcmFloatingPointSingle&>(element).getFloat32(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
839 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
840 else |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
841 return new DicomNullValue(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
842 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
843 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
844 case EVR_FD: // float double-precision |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
845 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
846 Float64 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
847 if (dynamic_cast<DcmFloatingPointDouble&>(element).getFloat64(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
848 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
849 else |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
850 return new DicomNullValue(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
851 } |
0 | 852 |
853 | |
854 /** | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
855 * 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
|
856 * "element.isLeaf()". |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
857 **/ |
0 | 858 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
859 case EVR_SQ: // sequence of items |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
860 return new DicomNullValue; |
0 | 861 |
862 | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
863 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
864 * Internal to DCMTK. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
865 **/ |
0 | 866 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
867 case EVR_ox: // OB or OW depending on context |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
868 case EVR_xs: // SS or US depending on context |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
869 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
|
870 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
|
871 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
|
872 case EVR_item: // used internally for items |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
873 case EVR_metainfo: // used internally for meta info datasets |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
874 case EVR_dataset: // used internally for datasets |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
875 case EVR_fileFormat: // used internally for DICOM files |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
876 case EVR_dicomDir: // used internally for DICOMDIR objects |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
877 case EVR_dirRecord: // used internally for DICOMDIR records |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
878 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
|
879 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
|
880 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
|
881 case EVR_PixelData: // used internally for uncompressed pixeld data |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
882 case EVR_OverlayData: // used internally for overlay data |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
883 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
|
884 return new DicomNullValue; |
0 | 885 |
886 | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
887 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
888 * Default case. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
889 **/ |
0 | 890 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
891 default: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
892 return new DicomNullValue; |
0 | 893 } |
894 } | |
895 catch (boost::bad_lexical_cast) | |
896 { | |
897 return new DicomNullValue; | |
898 } | |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
899 catch (std::bad_cast) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
900 { |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
901 return new DicomNullValue; |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
902 } |
0 | 903 } |
904 | |
905 | |
906 static void StoreElement(Json::Value& target, | |
907 DcmElement& element, | |
908 unsigned int maxStringLength); | |
909 | |
910 static void StoreItem(Json::Value& target, | |
911 DcmItem& item, | |
912 unsigned int maxStringLength) | |
913 { | |
914 target = Json::Value(Json::objectValue); | |
915 | |
916 for (unsigned long i = 0; i < item.card(); i++) | |
917 { | |
918 DcmElement* element = item.getElement(i); | |
919 StoreElement(target, *element, maxStringLength); | |
920 } | |
921 } | |
922 | |
923 | |
924 static void StoreElement(Json::Value& target, | |
925 DcmElement& element, | |
926 unsigned int maxStringLength) | |
927 { | |
928 assert(target.type() == Json::objectValue); | |
929 | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
930 DicomTag tag(FromDcmtkBridge::GetTag(element)); |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
931 const std::string formattedTag = tag.Format(); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
932 |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
933 #if 0 |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
934 const std::string tagName = FromDcmtkBridge::GetName(tag); |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
935 #else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
936 // 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
|
937 DcmTag tagbis(element.getTag()); |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
938 const std::string tagName(tagbis.getTagName()); |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
939 #endif |
0 | 940 |
941 if (element.isLeaf()) | |
942 { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
943 Json::Value value(Json::objectValue); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
944 value["Name"] = tagName; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
945 |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
946 if (tagbis.getPrivateCreator() != NULL) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
947 { |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
948 value["PrivateCreator"] = tagbis.getPrivateCreator(); |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
949 } |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
950 |
0 | 951 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(element)); |
952 if (v->IsNull()) | |
953 { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
954 value["Type"] = "Null"; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
955 value["Value"] = Json::nullValue; |
0 | 956 } |
957 else | |
958 { | |
959 std::string s = v->AsString(); | |
960 if (maxStringLength == 0 || | |
961 s.size() <= maxStringLength) | |
962 { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
963 value["Type"] = "String"; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
964 value["Value"] = s; |
0 | 965 } |
966 else | |
967 { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
968 value["Type"] = "TooLong"; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
969 value["Value"] = Json::nullValue; |
0 | 970 } |
971 } | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
972 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
973 target[formattedTag] = value; |
0 | 974 } |
975 else | |
976 { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
977 Json::Value children(Json::arrayValue); |
0 | 978 |
979 // "All subclasses of DcmElement except for DcmSequenceOfItems | |
980 // are leaf nodes, while DcmSequenceOfItems, DcmItem, DcmDataset | |
981 // etc. are not." The following cast is thus OK. | |
982 DcmSequenceOfItems& sequence = dynamic_cast<DcmSequenceOfItems&>(element); | |
983 | |
984 for (unsigned long i = 0; i < sequence.card(); i++) | |
985 { | |
986 DcmItem* child = sequence.getItem(i); | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
987 Json::Value& v = children.append(Json::objectValue); |
0 | 988 StoreItem(v, *child, maxStringLength); |
989 } | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
990 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
991 target[formattedTag]["Name"] = tagName; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
992 target[formattedTag]["Type"] = "Sequence"; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
993 target[formattedTag]["Value"] = children; |
0 | 994 } |
995 } | |
996 | |
997 | |
998 void FromDcmtkBridge::ToJson(Json::Value& root, | |
999 DcmDataset& dataset, | |
1000 unsigned int maxStringLength) | |
1001 { | |
1002 StoreItem(root, dataset, maxStringLength); | |
1003 } | |
1004 | |
1005 | |
1006 | |
1007 void FromDcmtkBridge::ToJson(Json::Value& target, | |
1008 const std::string& path, | |
1009 unsigned int maxStringLength) | |
1010 { | |
1011 DcmFileFormat dicom; | |
1012 if (!dicom.loadFile(path.c_str()).good()) | |
1013 { | |
62 | 1014 throw OrthancException(ErrorCode_BadFileFormat); |
0 | 1015 } |
1016 else | |
1017 { | |
1018 FromDcmtkBridge::ToJson(target, *dicom.getDataset(), maxStringLength); | |
1019 } | |
1020 } | |
1021 | |
1022 | |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1023 static void ExtractPngImageColorPreview(std::string& result, |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1024 DicomIntegerPixelAccessor& accessor) |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1025 { |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1026 assert(accessor.GetChannelCount() == 3); |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1027 PngWriter w; |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1028 |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1029 std::vector<uint8_t> image(accessor.GetWidth() * accessor.GetHeight() * 3, 0); |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1030 uint8_t* pixel = &image[0]; |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1031 |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1032 for (unsigned int y = 0; y < accessor.GetHeight(); y++) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1033 { |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1034 for (unsigned int x = 0; x < accessor.GetWidth(); x++) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1035 { |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1036 for (unsigned int c = 0; c < 3; c++, pixel++) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1037 { |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1038 int32_t v = accessor.GetValue(x, y, c); |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1039 if (v < 0) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1040 *pixel = 0; |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1041 else if (v > 255) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1042 *pixel = 255; |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1043 else |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1044 *pixel = v; |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1045 } |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1046 } |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1047 } |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1048 |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1049 w.WriteToMemory(result, accessor.GetWidth(), accessor.GetHeight(), |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1050 accessor.GetWidth() * 3, PixelFormat_RGB24, &image[0]); |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1051 } |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1052 |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1053 |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1054 static void ExtractPngImageGrayscalePreview(std::string& result, |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1055 DicomIntegerPixelAccessor& accessor) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1056 { |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1057 assert(accessor.GetChannelCount() == 1); |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1058 PngWriter w; |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1059 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1060 int32_t min, max; |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1061 accessor.GetExtremeValues(min, max); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1062 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1063 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
|
1064 if (min != max) |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1065 { |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1066 uint8_t* pixel = &image[0]; |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1067 for (unsigned int y = 0; y < accessor.GetHeight(); y++) |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1068 { |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1069 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
|
1070 { |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1071 int32_t v = accessor.GetValue(x, y); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1072 *pixel = static_cast<uint8_t>( |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1073 boost::math::lround(static_cast<float>(v - min) / |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1074 static_cast<float>(max - min) * 255.0f)); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1075 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1076 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1077 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1078 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1079 w.WriteToMemory(result, accessor.GetWidth(), accessor.GetHeight(), |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1080 accessor.GetWidth(), PixelFormat_Grayscale8, &image[0]); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1081 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1082 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1083 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1084 template <typename T> |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1085 static void ExtractPngImageTruncate(std::string& result, |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1086 DicomIntegerPixelAccessor& accessor, |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1087 PixelFormat format) |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1088 { |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1089 assert(accessor.GetChannelCount() == 1); |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1090 |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1091 PngWriter w; |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1092 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1093 std::vector<T> image(accessor.GetWidth() * accessor.GetHeight(), 0); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1094 T* pixel = &image[0]; |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1095 for (unsigned int y = 0; y < accessor.GetHeight(); y++) |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1096 { |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1097 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
|
1098 { |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1099 int32_t v = accessor.GetValue(x, y); |
73 | 1100 if (v < std::numeric_limits<T>::min()) |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1101 *pixel = std::numeric_limits<T>::min(); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1102 else if (v > std::numeric_limits<T>::max()) |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1103 *pixel = std::numeric_limits<T>::max(); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1104 else |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1105 *pixel = static_cast<T>(v); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1106 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1107 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1108 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1109 w.WriteToMemory(result, accessor.GetWidth(), accessor.GetHeight(), |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1110 accessor.GetWidth() * sizeof(T), format, &image[0]); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1111 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1112 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1113 |
319 | 1114 static bool DecodePsmctRle1(std::string& output, |
1115 DcmDataset& dataset) | |
1116 { | |
1117 static const DicomTag tagContent(0x07a1, 0x100a); | |
1118 static const DicomTag tagCompressionType(0x07a1, 0x1011); | |
1119 | |
1120 DcmElement* e; | |
1121 char* c; | |
1122 | |
1123 // Check whether the DICOM instance contains an image encoded with | |
1124 // the PMSCT_RLE1 scheme. | |
1125 if (!dataset.findAndGetElement(ToDcmtkBridge::Convert(tagCompressionType), e).good() || | |
1126 e == NULL || | |
1127 !e->isaString() || | |
1128 !e->getString(c).good() || | |
1129 c == NULL || | |
1130 strcmp("PMSCT_RLE1", c)) | |
1131 { | |
1132 return false; | |
1133 } | |
1134 | |
1135 // OK, this is a custom RLE encoding from Philips. Get the pixel | |
1136 // data from the appropriate private DICOM tag. | |
1137 Uint8* pixData = NULL; | |
1138 if (!dataset.findAndGetElement(ToDcmtkBridge::Convert(tagContent), e).good() || | |
1139 e == NULL || | |
1140 e->getUint8Array(pixData) != EC_Normal) | |
1141 { | |
1142 return false; | |
1143 } | |
1144 | |
1145 // The "unsigned" below IS VERY IMPORTANT | |
1146 const uint8_t* inbuffer = reinterpret_cast<const uint8_t*>(pixData); | |
1147 const size_t length = e->getLength(); | |
1148 | |
1149 /** | |
1150 * The code below is an adaptation of a sample code for GDCM by | |
1151 * Mathieu Malaterre (under a BSD license). | |
1152 * http://gdcm.sourceforge.net/html/rle2img_8cxx-example.html | |
1153 **/ | |
1154 | |
1155 // RLE pass | |
1156 std::vector<uint8_t> temp; | |
1157 temp.reserve(length); | |
1158 for (size_t i = 0; i < length; i++) | |
1159 { | |
1160 if (inbuffer[i] == 0xa5) | |
1161 { | |
1162 temp.push_back(inbuffer[i+2]); | |
1163 for (uint8_t repeat = inbuffer[i + 1]; repeat != 0; repeat--) | |
1164 { | |
1165 temp.push_back(inbuffer[i+2]); | |
1166 } | |
1167 i += 2; | |
1168 } | |
1169 else | |
1170 { | |
1171 temp.push_back(inbuffer[i]); | |
1172 } | |
1173 } | |
1174 | |
1175 // Delta encoding pass | |
1176 uint16_t delta = 0; | |
1177 output.clear(); | |
1178 output.reserve(temp.size()); | |
1179 for (size_t i = 0; i < temp.size(); i++) | |
1180 { | |
1181 uint16_t value; | |
1182 | |
1183 if (temp[i] == 0x5a) | |
1184 { | |
1185 uint16_t v1 = temp[i + 1]; | |
1186 uint16_t v2 = temp[i + 2]; | |
1187 value = (v2 << 8) + v1; | |
1188 i += 2; | |
1189 } | |
1190 else | |
1191 { | |
1192 value = delta + (int8_t) temp[i]; | |
1193 } | |
1194 | |
1195 output.push_back(value & 0xff); | |
1196 output.push_back(value >> 8); | |
1197 delta = value; | |
1198 } | |
1199 | |
1200 if (output.size() % 2) | |
1201 { | |
1202 output.resize(output.size() - 1); | |
1203 } | |
1204 | |
1205 return true; | |
1206 } | |
1207 | |
1208 | |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1209 void FromDcmtkBridge::ExtractPngImage(std::string& result, |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1210 DcmDataset& dataset, |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
1211 unsigned int frame, |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1212 ImageExtractionMode mode) |
0 | 1213 { |
1214 // See also: http://support.dcmtk.org/wiki/dcmtk/howto/accessing-compressed-data | |
1215 | |
1216 std::auto_ptr<DicomIntegerPixelAccessor> accessor; | |
1217 | |
1218 DicomMap m; | |
1219 FromDcmtkBridge::Convert(m, dataset); | |
1220 | |
319 | 1221 std::string privateContent; |
1222 | |
0 | 1223 DcmElement* e; |
80 | 1224 if (dataset.findAndGetElement(ToDcmtkBridge::Convert(DICOM_TAG_PIXEL_DATA), e).good() && |
0 | 1225 e != NULL) |
1226 { | |
1227 Uint8* pixData = NULL; | |
1228 if (e->getUint8Array(pixData) == EC_Normal) | |
1229 { | |
1230 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
|
1231 accessor->SetCurrentFrame(frame); |
0 | 1232 } |
1233 } | |
319 | 1234 else if (DecodePsmctRle1(privateContent, dataset)) |
1235 { | |
1236 LOG(INFO) << "The PMSCT_RLE1 decoding has succeeded"; | |
1237 Uint8* pixData = NULL; | |
1238 if (privateContent.size() > 0) | |
1239 pixData = reinterpret_cast<Uint8*>(&privateContent[0]); | |
1240 accessor.reset(new DicomIntegerPixelAccessor(m, pixData, privateContent.size())); | |
1241 accessor->SetCurrentFrame(frame); | |
1242 } | |
0 | 1243 |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1244 PixelFormat format; |
369
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1245 bool supported = false; |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1246 |
369
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1247 if (accessor->GetChannelCount() == 1) |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1248 { |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1249 switch (mode) |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1250 { |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1251 case ImageExtractionMode_Preview: |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1252 supported = true; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1253 format = PixelFormat_Grayscale8; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1254 break; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1255 |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1256 case ImageExtractionMode_UInt8: |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1257 supported = true; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1258 format = PixelFormat_Grayscale8; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1259 break; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1260 |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1261 case ImageExtractionMode_UInt16: |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1262 supported = true; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1263 format = PixelFormat_Grayscale16; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1264 break; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1265 |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1266 default: |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1267 supported = false; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1268 break; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1269 } |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1270 } |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1271 else if (accessor->GetChannelCount() == 3) |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1272 { |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1273 switch (mode) |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1274 { |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1275 case ImageExtractionMode_Preview: |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1276 supported = true; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1277 format = PixelFormat_RGB24; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1278 break; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1279 |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1280 default: |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1281 supported = false; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1282 break; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1283 } |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1284 } |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1285 |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1286 if (!supported) |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1287 { |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1288 throw OrthancException(ErrorCode_NotImplemented); |
369
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
1289 } |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1290 |
0 | 1291 if (accessor.get() == NULL || |
1292 accessor->GetWidth() == 0 || | |
1293 accessor->GetHeight() == 0) | |
1294 { | |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1295 PngWriter w; |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1296 w.WriteToMemory(result, 0, 0, 0, format, NULL); |
0 | 1297 } |
1298 else | |
1299 { | |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1300 switch (mode) |
0 | 1301 { |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1302 case ImageExtractionMode_Preview: |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1303 if (format == PixelFormat_Grayscale8) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1304 ExtractPngImageGrayscalePreview(result, *accessor); |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1305 else |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
1306 ExtractPngImageColorPreview(result, *accessor); |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1307 break; |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1308 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1309 case ImageExtractionMode_UInt8: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1310 ExtractPngImageTruncate<uint8_t>(result, *accessor, format); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1311 break; |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1312 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1313 case ImageExtractionMode_UInt16: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1314 ExtractPngImageTruncate<uint16_t>(result, *accessor, format); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1315 break; |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1316 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1317 default: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1318 throw OrthancException(ErrorCode_NotImplemented); |
0 | 1319 } |
1320 } | |
1321 } | |
1322 | |
1323 | |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1324 void FromDcmtkBridge::ExtractPngImage(std::string& result, |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1325 const std::string& dicomContent, |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
1326 unsigned int frame, |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
1327 ImageExtractionMode mode) |
0 | 1328 { |
1329 DcmInputBufferStream is; | |
1330 if (dicomContent.size() > 0) | |
1331 { | |
1332 is.setBuffer(&dicomContent[0], dicomContent.size()); | |
1333 } | |
1334 is.setEos(); | |
1335 | |
1336 DcmFileFormat dicom; | |
1337 if (dicom.read(is).good()) | |
1338 { | |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
1339 ExtractPngImage(result, *dicom.getDataset(), frame, mode); |
0 | 1340 } |
1341 else | |
1342 { | |
62 | 1343 throw OrthancException(ErrorCode_BadFileFormat); |
0 | 1344 } |
1345 } | |
1346 | |
1347 | |
1348 | |
1349 std::string FromDcmtkBridge::GetName(const DicomTag& t) | |
1350 { | |
106 | 1351 // Some patches for important tags because of different DICOM |
1352 // dictionaries between DCMTK versions | |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1353 std::string n = t.GetMainTagsName(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1354 if (n.size() != 0) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1355 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1356 return n; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1357 } |
106 | 1358 // End of patches |
1359 | |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1360 #if 0 |
0 | 1361 DcmTagKey tag(t.GetGroup(), t.GetElement()); |
1362 const DcmDataDictionary& dict = dcmDataDict.rdlock(); | |
1363 const DcmDictEntry* entry = dict.findEntry(tag, NULL); | |
1364 | |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1365 std::string s(DcmTag_ERROR_TagName); |
0 | 1366 if (entry != NULL) |
1367 { | |
1368 s = std::string(entry->getTagName()); | |
1369 } | |
1370 | |
1371 dcmDataDict.unlock(); | |
1372 return s; | |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1373 #else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1374 DcmTag tag(t.GetGroup(), t.GetElement()); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1375 const char* name = tag.getTagName(); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1376 if (name == NULL) |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1377 { |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1378 return DcmTag_ERROR_TagName; |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1379 } |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1380 else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1381 { |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1382 return std::string(name); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1383 } |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1384 #endif |
0 | 1385 } |
1386 | |
1387 | |
304 | 1388 DicomTag FromDcmtkBridge::ParseTag(const char* name) |
0 | 1389 { |
304 | 1390 if (strlen(name) == 9 && |
1391 isxdigit(name[0]) && | |
1392 isxdigit(name[1]) && | |
1393 isxdigit(name[2]) && | |
1394 isxdigit(name[3]) && | |
1395 name[4] == '-' && | |
1396 isxdigit(name[5]) && | |
1397 isxdigit(name[6]) && | |
1398 isxdigit(name[7]) && | |
1399 isxdigit(name[8])) | |
1400 { | |
1401 uint16_t group = GetTagValue(name); | |
1402 uint16_t element = GetTagValue(name + 5); | |
1403 return DicomTag(group, element); | |
1404 } | |
1405 | |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1406 #if 0 |
0 | 1407 const DcmDataDictionary& dict = dcmDataDict.rdlock(); |
1408 const DcmDictEntry* entry = dict.findEntry(name); | |
1409 | |
1410 if (entry == NULL) | |
1411 { | |
1412 dcmDataDict.unlock(); | |
62 | 1413 throw OrthancException("Unknown DICOM tag"); |
0 | 1414 } |
1415 else | |
1416 { | |
1417 DcmTagKey key = entry->getKey(); | |
1418 DicomTag tag(key.getGroup(), key.getElement()); | |
1419 dcmDataDict.unlock(); | |
1420 return tag; | |
1421 } | |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1422 #else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1423 DcmTag tag; |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1424 if (DcmTag::findTagFromName(name, tag).good()) |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1425 { |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1426 return DicomTag(tag.getGTag(), tag.getETag()); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1427 } |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1428 else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1429 { |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1430 throw OrthancException("Unknown DICOM tag"); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1431 } |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1432 #endif |
0 | 1433 } |
1434 | |
1435 | |
1436 void FromDcmtkBridge::Print(FILE* fp, const DicomMap& m) | |
1437 { | |
1438 for (DicomMap::Map::const_iterator | |
1439 it = m.map_.begin(); it != m.map_.end(); it++) | |
1440 { | |
1441 DicomTag t = it->first; | |
1442 std::string s = it->second->AsString(); | |
319 | 1443 fprintf(fp, "0x%04x 0x%04x (%s) [%s]\n", t.GetGroup(), t.GetElement(), GetName(t).c_str(), s.c_str()); |
0 | 1444 } |
1445 } | |
1446 | |
1447 | |
1448 void FromDcmtkBridge::ToJson(Json::Value& result, | |
1449 const DicomMap& values) | |
1450 { | |
1451 if (result.type() != Json::objectValue) | |
1452 { | |
62 | 1453 throw OrthancException(ErrorCode_BadParameterType); |
0 | 1454 } |
1455 | |
1456 result.clear(); | |
1457 | |
1458 for (DicomMap::Map::const_iterator | |
1459 it = values.map_.begin(); it != values.map_.end(); it++) | |
1460 { | |
1461 result[GetName(it->first)] = it->second->AsString(); | |
1462 } | |
1463 } | |
176 | 1464 |
1465 | |
1466 std::string FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel level) | |
1467 { | |
1468 char uid[100]; | |
1469 | |
1470 switch (level) | |
1471 { | |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1472 case DicomRootLevel_Patient: |
311 | 1473 // The "PatientID" field is of type LO (Long String), 64 |
1474 // Bytes Maximum. An UUID is of length 36, thus it can be used | |
1475 // as a random PatientID. | |
1476 return Toolbox::GenerateUuid(); | |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1477 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1478 case DicomRootLevel_Instance: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1479 return dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT); |
176 | 1480 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1481 case DicomRootLevel_Series: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1482 return dcmGenerateUniqueIdentifier(uid, SITE_SERIES_UID_ROOT); |
176 | 1483 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1484 case DicomRootLevel_Study: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1485 return dcmGenerateUniqueIdentifier(uid, SITE_STUDY_UID_ROOT); |
176 | 1486 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1487 default: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
1488 throw OrthancException(ErrorCode_ParameterOutOfRange); |
176 | 1489 } |
1490 } | |
1491 | |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1492 bool FromDcmtkBridge::SaveToMemoryBuffer(std::string& buffer, |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1493 DcmDataset* dataSet) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1494 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1495 // 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
|
1496 // 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
|
1497 // syntax, with explicit length. |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1498 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1499 // http://support.dcmtk.org/docs/dcxfer_8h-source.html |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1500 E_TransferSyntax xfer = EXS_LittleEndianExplicit; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1501 E_EncodingType encodingType = /*opt_sequenceType*/ EET_ExplicitLength; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1502 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1503 uint32_t s = dataSet->getLength(xfer, encodingType); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1504 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1505 buffer.resize(s); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1506 DcmOutputBufferStream ob(&buffer[0], s); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1507 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1508 dataSet->transferInit(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1509 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1510 #if DCMTK_VERSION_NUMBER >= 360 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1511 OFCondition c = dataSet->write(ob, xfer, encodingType, NULL, |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1512 /*opt_groupLength*/ EGL_recalcGL, |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1513 /*opt_paddingType*/ EPD_withoutPadding); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1514 #else |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1515 OFCondition c = dataSet->write(ob, xfer, encodingType, NULL); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1516 #endif |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1517 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1518 dataSet->transferEnd(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1519 if (c.good()) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1520 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1521 return true; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1522 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1523 else |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1524 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1525 buffer.clear(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1526 return false; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1527 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1528 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1529 #if 0 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1530 OFCondition cond = cbdata->dcmff->saveFile(fileName.c_str(), xfer, |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1531 encodingType, |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1532 /*opt_groupLength*/ EGL_recalcGL, |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1533 /*opt_paddingType*/ EPD_withoutPadding, |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1534 OFstatic_cast(Uint32, /*opt_filepad*/ 0), |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1535 OFstatic_cast(Uint32, /*opt_itempad*/ 0), |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1536 (opt_useMetaheader) ? EWM_fileformat : EWM_dataset); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1537 #endif |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1538 } |
0 | 1539 } |