Mercurial > hg > orthanc
annotate OrthancServer/ParsedDicomFile.cpp @ 2150:9a272d552c27
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 14 Nov 2016 12:10:07 +0100 |
parents | 5a8840920121 |
children | 9b373b7d6713 |
rev | line source |
---|---|
790 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
790 | 5 * |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
22 * | |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
33 | |
34 /*========================================================================= | |
35 | |
36 This file is based on portions of the following project: | |
37 | |
38 Program: GDCM (Grassroots DICOM). A DICOM library | |
39 Module: http://gdcm.sourceforge.net/Copyright.html | |
40 | |
41 Copyright (c) 2006-2011 Mathieu Malaterre | |
42 Copyright (c) 1993-2005 CREATIS | |
43 (CREATIS = Centre de Recherche et d'Applications en Traitement de l'Image) | |
44 All rights reserved. | |
45 | |
46 Redistribution and use in source and binary forms, with or without | |
47 modification, are permitted provided that the following conditions are met: | |
48 | |
49 * Redistributions of source code must retain the above copyright notice, | |
50 this list of conditions and the following disclaimer. | |
51 | |
52 * Redistributions in binary form must reproduce the above copyright notice, | |
53 this list of conditions and the following disclaimer in the documentation | |
54 and/or other materials provided with the distribution. | |
55 | |
56 * Neither name of Mathieu Malaterre, or CREATIS, nor the names of any | |
57 contributors (CNRS, INSERM, UCB, Universite Lyon I), may be used to | |
58 endorse or promote products derived from this software without specific | |
59 prior written permission. | |
60 | |
61 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' | |
62 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
63 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
64 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR | |
65 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
66 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
67 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
68 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
69 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
70 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
71 | |
72 =========================================================================*/ | |
73 | |
74 | |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
75 #include "PrecompiledHeadersServer.h" |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
817
diff
changeset
|
76 |
790 | 77 #ifndef NOMINMAX |
78 #define NOMINMAX | |
79 #endif | |
80 | |
81 #include "ParsedDicomFile.h" | |
82 | |
1818
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
83 #include "OrthancInitialization.h" |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
84 #include "ServerToolbox.h" |
790 | 85 #include "FromDcmtkBridge.h" |
86 #include "ToDcmtkBridge.h" | |
1924
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
87 #include "Internals/DicomFrameIndex.h" |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1737
diff
changeset
|
88 #include "../Core/Images/JpegReader.h" |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1737
diff
changeset
|
89 #include "../Core/Images/PngReader.h" |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1737
diff
changeset
|
90 #include "../Core/Logging.h" |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1737
diff
changeset
|
91 #include "../Core/OrthancException.h" |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1737
diff
changeset
|
92 #include "../Core/Toolbox.h" |
790 | 93 |
94 #include <list> | |
95 #include <limits> | |
96 | |
97 #include <boost/lexical_cast.hpp> | |
98 | |
99 #include <dcmtk/dcmdata/dcchrstr.h> | |
100 #include <dcmtk/dcmdata/dcdicent.h> | |
101 #include <dcmtk/dcmdata/dcdict.h> | |
102 #include <dcmtk/dcmdata/dcfilefo.h> | |
103 #include <dcmtk/dcmdata/dcuid.h> | |
104 #include <dcmtk/dcmdata/dcmetinf.h> | |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
105 #include <dcmtk/dcmdata/dcdeftag.h> |
790 | 106 |
107 #include <dcmtk/dcmdata/dcvrae.h> | |
108 #include <dcmtk/dcmdata/dcvras.h> | |
109 #include <dcmtk/dcmdata/dcvrcs.h> | |
110 #include <dcmtk/dcmdata/dcvrda.h> | |
111 #include <dcmtk/dcmdata/dcvrds.h> | |
112 #include <dcmtk/dcmdata/dcvrdt.h> | |
113 #include <dcmtk/dcmdata/dcvrfd.h> | |
114 #include <dcmtk/dcmdata/dcvrfl.h> | |
115 #include <dcmtk/dcmdata/dcvris.h> | |
116 #include <dcmtk/dcmdata/dcvrlo.h> | |
117 #include <dcmtk/dcmdata/dcvrlt.h> | |
118 #include <dcmtk/dcmdata/dcvrpn.h> | |
119 #include <dcmtk/dcmdata/dcvrsh.h> | |
120 #include <dcmtk/dcmdata/dcvrsl.h> | |
121 #include <dcmtk/dcmdata/dcvrss.h> | |
122 #include <dcmtk/dcmdata/dcvrst.h> | |
123 #include <dcmtk/dcmdata/dcvrtm.h> | |
124 #include <dcmtk/dcmdata/dcvrui.h> | |
125 #include <dcmtk/dcmdata/dcvrul.h> | |
126 #include <dcmtk/dcmdata/dcvrus.h> | |
127 #include <dcmtk/dcmdata/dcvrut.h> | |
128 #include <dcmtk/dcmdata/dcpixel.h> | |
129 #include <dcmtk/dcmdata/dcpixseq.h> | |
130 #include <dcmtk/dcmdata/dcpxitem.h> | |
131 | |
132 | |
133 #include <boost/math/special_functions/round.hpp> | |
134 #include <dcmtk/dcmdata/dcostrmb.h> | |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
135 #include <boost/algorithm/string/predicate.hpp> |
790 | 136 |
137 | |
1945
76ff6eecf07f
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1941
diff
changeset
|
138 #if DCMTK_VERSION_NUMBER <= 360 |
76ff6eecf07f
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1941
diff
changeset
|
139 # define EXS_JPEGProcess1 EXS_JPEGProcess1TransferSyntax |
76ff6eecf07f
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1941
diff
changeset
|
140 #endif |
76ff6eecf07f
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1941
diff
changeset
|
141 |
76ff6eecf07f
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1941
diff
changeset
|
142 |
790 | 143 static const char* CONTENT_TYPE_OCTET_STREAM = "application/octet-stream"; |
144 | |
145 | |
146 | |
147 namespace Orthanc | |
148 { | |
794 | 149 struct ParsedDicomFile::PImpl |
150 { | |
151 std::auto_ptr<DcmFileFormat> file_; | |
1924
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
152 std::auto_ptr<DicomFrameIndex> frameIndex_; |
794 | 153 }; |
154 | |
155 | |
790 | 156 static void SendPathValueForDictionary(RestApiOutput& output, |
157 DcmItem& dicom) | |
158 { | |
159 Json::Value v = Json::arrayValue; | |
160 | |
161 for (unsigned long i = 0; i < dicom.card(); i++) | |
162 { | |
163 DcmElement* element = dicom.getElement(i); | |
164 if (element) | |
165 { | |
166 char buf[16]; | |
167 sprintf(buf, "%04x-%04x", element->getTag().getGTag(), element->getTag().getETag()); | |
168 v.append(buf); | |
169 } | |
170 } | |
171 | |
172 output.AnswerJson(v); | |
173 } | |
174 | |
175 static inline uint16_t GetCharValue(char c) | |
176 { | |
177 if (c >= '0' && c <= '9') | |
178 return c - '0'; | |
179 else if (c >= 'a' && c <= 'f') | |
180 return c - 'a' + 10; | |
181 else if (c >= 'A' && c <= 'F') | |
182 return c - 'A' + 10; | |
183 else | |
184 return 0; | |
185 } | |
186 | |
187 static inline uint16_t GetTagValue(const char* c) | |
188 { | |
189 return ((GetCharValue(c[0]) << 12) + | |
190 (GetCharValue(c[1]) << 8) + | |
191 (GetCharValue(c[2]) << 4) + | |
192 GetCharValue(c[3])); | |
193 } | |
194 | |
195 static void ParseTagAndGroup(DcmTagKey& key, | |
196 const std::string& tag) | |
197 { | |
198 DicomTag t = FromDcmtkBridge::ParseTag(tag); | |
199 key = DcmTagKey(t.GetGroup(), t.GetElement()); | |
200 } | |
201 | |
202 | |
203 static void SendSequence(RestApiOutput& output, | |
204 DcmSequenceOfItems& sequence) | |
205 { | |
206 // This element is a sequence | |
207 Json::Value v = Json::arrayValue; | |
208 | |
209 for (unsigned long i = 0; i < sequence.card(); i++) | |
210 { | |
211 v.append(boost::lexical_cast<std::string>(i)); | |
212 } | |
213 | |
214 output.AnswerJson(v); | |
215 } | |
216 | |
217 | |
218 static unsigned int GetPixelDataBlockCount(DcmPixelData& pixelData, | |
219 E_TransferSyntax transferSyntax) | |
220 { | |
221 DcmPixelSequence* pixelSequence = NULL; | |
222 if (pixelData.getEncapsulatedRepresentation | |
223 (transferSyntax, NULL, pixelSequence).good() && pixelSequence) | |
224 { | |
225 return pixelSequence->card(); | |
226 } | |
227 else | |
228 { | |
229 return 1; | |
230 } | |
231 } | |
232 | |
233 | |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
234 namespace |
790 | 235 { |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
236 class DicomFieldStream : public IHttpStreamAnswer |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
237 { |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
238 private: |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
239 DcmElement& element_; |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
240 uint32_t length_; |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
241 uint32_t offset_; |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
242 std::string chunk_; |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
243 size_t chunkSize_; |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
244 |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
245 public: |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
246 DicomFieldStream(DcmElement& element, |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
247 E_TransferSyntax transferSyntax) : |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
248 element_(element), |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
249 length_(element.getLength(transferSyntax)), |
1616 | 250 offset_(0), |
251 chunkSize_(0) | |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
252 { |
1521 | 253 static const size_t CHUNK_SIZE = 64 * 1024; // Use chunks of max 64KB |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
254 chunk_.resize(CHUNK_SIZE); |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
255 } |
790 | 256 |
1523
c388502a066d
testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1521
diff
changeset
|
257 virtual HttpCompression SetupHttpCompression(bool /*gzipAllowed*/, |
c388502a066d
testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1521
diff
changeset
|
258 bool /*deflateAllowed*/) |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
259 { |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
260 // No support for compression |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
261 return HttpCompression_None; |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
262 } |
790 | 263 |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
264 virtual bool HasContentFilename(std::string& filename) |
790 | 265 { |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
266 return false; |
790 | 267 } |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
268 |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
269 virtual std::string GetContentType() |
790 | 270 { |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
271 return ""; |
790 | 272 } |
273 | |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
274 virtual uint64_t GetContentLength() |
790 | 275 { |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
276 return length_; |
790 | 277 } |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
278 |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
279 virtual bool ReadNextChunk() |
790 | 280 { |
1520 | 281 assert(offset_ <= length_); |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
282 |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
283 if (offset_ == length_) |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
284 { |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
285 return false; |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
286 } |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
287 else |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
288 { |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
289 if (length_ - offset_ < chunk_.size()) |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
290 { |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
291 chunkSize_ = length_ - offset_; |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
292 } |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
293 else |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
294 { |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
295 chunkSize_ = chunk_.size(); |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
296 } |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
297 |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
298 OFCondition cond = element_.getPartialValue(&chunk_[0], offset_, chunkSize_); |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
299 |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
300 offset_ += chunkSize_; |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
301 |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
302 if (!cond.good()) |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
303 { |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
304 LOG(ERROR) << "Error while sending a DICOM field: " << cond.text(); |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
305 throw OrthancException(ErrorCode_InternalError); |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
306 } |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
307 |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
308 return true; |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
309 } |
790 | 310 } |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
311 |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
312 virtual const char *GetChunkContent() |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
313 { |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
314 return chunk_.c_str(); |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
315 } |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
316 |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
317 virtual size_t GetChunkSize() |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
318 { |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
319 return chunkSize_; |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
320 } |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
321 }; |
790 | 322 } |
323 | |
324 | |
325 static bool AnswerPixelData(RestApiOutput& output, | |
326 DcmItem& dicom, | |
327 E_TransferSyntax transferSyntax, | |
328 const std::string* blockUri) | |
329 { | |
330 DcmTag k(DICOM_TAG_PIXEL_DATA.GetGroup(), | |
331 DICOM_TAG_PIXEL_DATA.GetElement()); | |
332 | |
333 DcmElement *element = NULL; | |
334 if (!dicom.findAndGetElement(k, element).good() || | |
335 element == NULL) | |
336 { | |
337 return false; | |
338 } | |
339 | |
340 try | |
341 { | |
342 DcmPixelData& pixelData = dynamic_cast<DcmPixelData&>(*element); | |
343 if (blockUri == NULL) | |
344 { | |
1913
41e402cd7b3a
do not generate RC files for non-Windows builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1902
diff
changeset
|
345 // The user asks how many blocks are present in this pixel data |
790 | 346 unsigned int blocks = GetPixelDataBlockCount(pixelData, transferSyntax); |
347 | |
348 Json::Value result(Json::arrayValue); | |
349 for (unsigned int i = 0; i < blocks; i++) | |
350 { | |
351 result.append(boost::lexical_cast<std::string>(i)); | |
352 } | |
353 | |
354 output.AnswerJson(result); | |
355 return true; | |
356 } | |
357 | |
358 | |
359 unsigned int block = boost::lexical_cast<unsigned int>(*blockUri); | |
360 | |
361 if (block < GetPixelDataBlockCount(pixelData, transferSyntax)) | |
362 { | |
363 DcmPixelSequence* pixelSequence = NULL; | |
364 if (pixelData.getEncapsulatedRepresentation | |
365 (transferSyntax, NULL, pixelSequence).good() && pixelSequence) | |
366 { | |
367 // This is the case for JPEG transfer syntaxes | |
368 if (block < pixelSequence->card()) | |
369 { | |
370 DcmPixelItem* pixelItem = NULL; | |
371 if (pixelSequence->getItem(pixelItem, block).good() && pixelItem) | |
372 { | |
373 if (pixelItem->getLength() == 0) | |
374 { | |
375 output.AnswerBuffer(NULL, 0, CONTENT_TYPE_OCTET_STREAM); | |
376 return true; | |
377 } | |
378 | |
379 Uint8* buffer = NULL; | |
380 if (pixelItem->getUint8Array(buffer).good() && buffer) | |
381 { | |
382 output.AnswerBuffer(buffer, pixelItem->getLength(), CONTENT_TYPE_OCTET_STREAM); | |
383 return true; | |
384 } | |
385 } | |
386 } | |
387 } | |
388 else | |
389 { | |
390 // This is the case for raw, uncompressed image buffers | |
391 assert(*blockUri == "0"); | |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
392 DicomFieldStream stream(*element, transferSyntax); |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
393 output.AnswerStream(stream); |
790 | 394 } |
395 } | |
396 } | |
397 catch (boost::bad_lexical_cast&) | |
398 { | |
399 // The URI entered by the user is not a number | |
400 } | |
401 catch (std::bad_cast&) | |
402 { | |
403 // This should never happen | |
404 } | |
405 | |
406 return false; | |
407 } | |
408 | |
409 | |
410 | |
411 static void SendPathValueForLeaf(RestApiOutput& output, | |
412 const std::string& tag, | |
413 DcmItem& dicom, | |
414 E_TransferSyntax transferSyntax) | |
415 { | |
416 DcmTagKey k; | |
417 ParseTagAndGroup(k, tag); | |
418 | |
419 DcmSequenceOfItems* sequence = NULL; | |
420 if (dicom.findAndGetSequence(k, sequence).good() && | |
421 sequence != NULL && | |
422 sequence->getVR() == EVR_SQ) | |
423 { | |
424 SendSequence(output, *sequence); | |
425 return; | |
426 } | |
427 | |
428 DcmElement* element = NULL; | |
429 if (dicom.findAndGetElement(k, element).good() && | |
430 element != NULL && | |
431 //element->getVR() != EVR_UNKNOWN && // This would forbid private tags | |
432 element->getVR() != EVR_SQ) | |
433 { | |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
434 DicomFieldStream stream(*element, transferSyntax); |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
435 output.AnswerStream(stream); |
790 | 436 } |
437 } | |
438 | |
439 void ParsedDicomFile::SendPathValue(RestApiOutput& output, | |
440 const UriComponents& uri) | |
441 { | |
794 | 442 DcmItem* dicom = pimpl_->file_->getDataset(); |
443 E_TransferSyntax transferSyntax = pimpl_->file_->getDataset()->getOriginalXfer(); | |
790 | 444 |
445 // Special case: Accessing the pixel data | |
446 if (uri.size() == 1 || | |
447 uri.size() == 2) | |
448 { | |
449 DcmTagKey tag; | |
450 ParseTagAndGroup(tag, uri[0]); | |
451 | |
452 if (tag.getGroup() == DICOM_TAG_PIXEL_DATA.GetGroup() && | |
453 tag.getElement() == DICOM_TAG_PIXEL_DATA.GetElement()) | |
454 { | |
455 AnswerPixelData(output, *dicom, transferSyntax, uri.size() == 1 ? NULL : &uri[1]); | |
456 return; | |
457 } | |
458 } | |
459 | |
460 // Go down in the tag hierarchy according to the URI | |
461 for (size_t pos = 0; pos < uri.size() / 2; pos++) | |
462 { | |
463 size_t index; | |
464 try | |
465 { | |
466 index = boost::lexical_cast<size_t>(uri[2 * pos + 1]); | |
467 } | |
468 catch (boost::bad_lexical_cast&) | |
469 { | |
470 return; | |
471 } | |
472 | |
473 DcmTagKey k; | |
474 DcmItem *child = NULL; | |
475 ParseTagAndGroup(k, uri[2 * pos]); | |
476 if (!dicom->findAndGetSequenceItem(k, child, index).good() || | |
477 child == NULL) | |
478 { | |
479 return; | |
480 } | |
481 | |
482 dicom = child; | |
483 } | |
484 | |
485 // We have reached the end of the URI | |
486 if (uri.size() % 2 == 0) | |
487 { | |
488 SendPathValueForDictionary(output, *dicom); | |
489 } | |
490 else | |
491 { | |
492 SendPathValueForLeaf(output, uri.back(), *dicom, transferSyntax); | |
493 } | |
494 } | |
495 | |
496 | |
497 void ParsedDicomFile::Remove(const DicomTag& tag) | |
498 { | |
1924
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
499 InvalidateCache(); |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
500 |
790 | 501 DcmTagKey key(tag.GetGroup(), tag.GetElement()); |
794 | 502 DcmElement* element = pimpl_->file_->getDataset()->remove(key); |
790 | 503 if (element != NULL) |
504 { | |
505 delete element; | |
506 } | |
507 } | |
508 | |
509 | |
510 | |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
511 void ParsedDicomFile::RemovePrivateTagsInternal(const std::set<DicomTag>* toKeep) |
790 | 512 { |
1924
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
513 InvalidateCache(); |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
514 |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
515 DcmDataset& dataset = *pimpl_->file_->getDataset(); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
516 |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
517 // Loop over the dataset to detect its private tags |
790 | 518 typedef std::list<DcmElement*> Tags; |
519 Tags privateTags; | |
520 | |
521 for (unsigned long i = 0; i < dataset.card(); i++) | |
522 { | |
523 DcmElement* element = dataset.getElement(i); | |
524 DcmTag tag(element->getTag()); | |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
525 |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
526 // Is this a private tag? |
1694 | 527 if (tag.isPrivate()) |
790 | 528 { |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
529 bool remove = true; |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
530 |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
531 // Check whether this private tag is to be kept |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
532 if (toKeep != NULL) |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
533 { |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
534 DicomTag tmp = FromDcmtkBridge::Convert(tag); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
535 if (toKeep->find(tmp) != toKeep->end()) |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
536 { |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
537 remove = false; // Keep it |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
538 } |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
539 } |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
540 |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
541 if (remove) |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
542 { |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
543 privateTags.push_back(element); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
544 } |
790 | 545 } |
546 } | |
547 | |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
548 // Loop over the detected private tags to remove them |
790 | 549 for (Tags::iterator it = privateTags.begin(); |
550 it != privateTags.end(); ++it) | |
551 { | |
552 DcmElement* tmp = dataset.remove(*it); | |
553 if (tmp != NULL) | |
554 { | |
555 delete tmp; | |
556 } | |
557 } | |
558 } | |
559 | |
560 | |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
561 static void InsertInternal(DcmDataset& dicom, |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
562 DcmElement* element) |
790 | 563 { |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
564 OFCondition cond = dicom.insert(element, false, false); |
1307
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
565 if (!cond.good()) |
790 | 566 { |
567 // This field already exists | |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
568 delete element; |
790 | 569 throw OrthancException(ErrorCode_InternalError); |
570 } | |
571 } | |
572 | |
573 | |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
574 void ParsedDicomFile::Insert(const DicomTag& tag, |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
575 const Json::Value& value, |
1818
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
576 bool decodeDataUriScheme) |
790 | 577 { |
1980
ebce5f456b8e
new error code: ErrorCode_AlreadyExistingTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
578 if (pimpl_->file_->getDataset()->tagExists(ToDcmtkBridge::Convert(tag))) |
ebce5f456b8e
new error code: ErrorCode_AlreadyExistingTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
579 { |
ebce5f456b8e
new error code: ErrorCode_AlreadyExistingTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
580 throw OrthancException(ErrorCode_AlreadyExistingTag); |
ebce5f456b8e
new error code: ErrorCode_AlreadyExistingTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
581 } |
ebce5f456b8e
new error code: ErrorCode_AlreadyExistingTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
582 |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
583 if (decodeDataUriScheme && |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
584 value.type() == Json::stringValue && |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
585 (tag == DICOM_TAG_ENCAPSULATED_DOCUMENT || |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
586 tag == DICOM_TAG_PIXEL_DATA)) |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
587 { |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
588 if (EmbedContentInternal(value.asString())) |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
589 { |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
590 return; |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
591 } |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
592 } |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
593 |
1924
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
594 InvalidateCache(); |
1818
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
595 std::auto_ptr<DcmElement> element(FromDcmtkBridge::FromJson(tag, value, decodeDataUriScheme, GetEncoding())); |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
596 InsertInternal(*pimpl_->file_->getDataset(), element.release()); |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
597 } |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
598 |
790 | 599 |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
600 static bool CanReplaceProceed(DcmDataset& dicom, |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
601 const DcmTagKey& tag, |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
602 DicomReplaceMode mode) |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
603 { |
1979 | 604 if (dicom.findAndDeleteElement(tag).good()) |
790 | 605 { |
1979 | 606 // This tag was existing, it has been deleted |
607 return true; | |
608 } | |
609 else | |
610 { | |
611 // This tag was absent, act wrt. the specified "mode" | |
790 | 612 switch (mode) |
613 { | |
614 case DicomReplaceMode_InsertIfAbsent: | |
1979 | 615 return true; |
790 | 616 |
617 case DicomReplaceMode_ThrowIfAbsent: | |
618 throw OrthancException(ErrorCode_InexistentItem); | |
619 | |
620 case DicomReplaceMode_IgnoreIfAbsent: | |
1979 | 621 return false; |
622 | |
623 default: | |
624 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
790 | 625 } |
626 } | |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
627 } |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
628 |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
629 |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
630 void ParsedDicomFile::UpdateStorageUid(const DicomTag& tag, |
1695 | 631 const std::string& utf8Value, |
1818
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
632 bool decodeDataUriScheme) |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
633 { |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
634 if (tag != DICOM_TAG_SOP_CLASS_UID && |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
635 tag != DICOM_TAG_SOP_INSTANCE_UID) |
790 | 636 { |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
637 return; |
790 | 638 } |
639 | |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
640 std::string binary; |
1695 | 641 const std::string* decoded = &utf8Value; |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
642 |
1818
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
643 if (decodeDataUriScheme && |
1695 | 644 boost::starts_with(utf8Value, "data:application/octet-stream;base64,")) |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
645 { |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
646 std::string mime; |
1981
4b545a8b1f95
return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
647 if (!Toolbox::DecodeDataUriScheme(mime, binary, utf8Value)) |
4b545a8b1f95
return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
648 { |
4b545a8b1f95
return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
649 throw OrthancException(ErrorCode_BadFileFormat); |
4b545a8b1f95
return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
650 } |
4b545a8b1f95
return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
651 |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
652 decoded = &binary; |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
653 } |
1695 | 654 else |
655 { | |
656 Encoding encoding = GetEncoding(); | |
657 if (GetEncoding() != Encoding_Utf8) | |
658 { | |
659 binary = Toolbox::ConvertFromUtf8(utf8Value, encoding); | |
660 decoded = &binary; | |
661 } | |
662 } | |
790 | 663 |
664 /** | |
665 * dcmodify will automatically correct 'Media Storage SOP Class | |
666 * UID' and 'Media Storage SOP Instance UID' in the metaheader, if | |
667 * you make changes to the related tags in the dataset ('SOP Class | |
668 * UID' and 'SOP Instance UID') via insert or modify mode | |
669 * options. You can disable this behaviour by using the -nmu | |
670 * option. | |
671 **/ | |
672 | |
673 if (tag == DICOM_TAG_SOP_CLASS_UID) | |
674 { | |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
675 ReplacePlainString(DICOM_TAG_MEDIA_STORAGE_SOP_CLASS_UID, *decoded); |
790 | 676 } |
677 | |
678 if (tag == DICOM_TAG_SOP_INSTANCE_UID) | |
679 { | |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
680 ReplacePlainString(DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID, *decoded); |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
681 } |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
682 } |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
683 |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
684 |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
685 void ParsedDicomFile::Replace(const DicomTag& tag, |
1695 | 686 const std::string& utf8Value, |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
687 bool decodeDataUriScheme, |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
688 DicomReplaceMode mode) |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
689 { |
1924
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
690 InvalidateCache(); |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
691 |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
692 DcmDataset& dicom = *pimpl_->file_->getDataset(); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
693 if (CanReplaceProceed(dicom, ToDcmtkBridge::Convert(tag), mode)) |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
694 { |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
695 // Either the tag was previously existing (and now removed), or |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
696 // the replace mode was set to "InsertIfAbsent" |
1979 | 697 |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
698 if (decodeDataUriScheme && |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
699 (tag == DICOM_TAG_ENCAPSULATED_DOCUMENT || |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
700 tag == DICOM_TAG_PIXEL_DATA)) |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
701 { |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
702 if (EmbedContentInternal(utf8Value)) |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
703 { |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
704 return; |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
705 } |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
706 } |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
707 |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
708 std::auto_ptr<DcmElement> element(FromDcmtkBridge::CreateElementForTag(tag)); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
709 FromDcmtkBridge::FillElementWithString(*element, tag, utf8Value, decodeDataUriScheme, GetEncoding()); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
710 |
1979 | 711 InsertInternal(dicom, element.release()); |
712 UpdateStorageUid(tag, utf8Value, false); | |
713 } | |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
714 } |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
715 |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
716 |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
717 void ParsedDicomFile::Replace(const DicomTag& tag, |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
718 const Json::Value& value, |
1818
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
719 bool decodeDataUriScheme, |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
720 DicomReplaceMode mode) |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
721 { |
1924
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
722 InvalidateCache(); |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
723 |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
724 DcmDataset& dicom = *pimpl_->file_->getDataset(); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
725 if (CanReplaceProceed(dicom, ToDcmtkBridge::Convert(tag), mode)) |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
726 { |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
727 // Either the tag was previously existing (and now removed), or |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
728 // the replace mode was set to "InsertIfAbsent" |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
729 |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
730 if (decodeDataUriScheme && |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
731 value.type() == Json::stringValue && |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
732 (tag == DICOM_TAG_ENCAPSULATED_DOCUMENT || |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
733 tag == DICOM_TAG_PIXEL_DATA)) |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
734 { |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
735 if (EmbedContentInternal(value.asString())) |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
736 { |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
737 return; |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
738 } |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
739 } |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
740 |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
741 InsertInternal(dicom, FromDcmtkBridge::FromJson(tag, value, decodeDataUriScheme, GetEncoding())); |
1979 | 742 |
743 if (tag == DICOM_TAG_SOP_CLASS_UID || | |
744 tag == DICOM_TAG_SOP_INSTANCE_UID) | |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
745 { |
1979 | 746 if (value.type() != Json::stringValue) |
747 { | |
748 throw OrthancException(ErrorCode_BadParameterType); | |
749 } | |
750 | |
751 UpdateStorageUid(tag, value.asString(), decodeDataUriScheme); | |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
752 } |
790 | 753 } |
754 } | |
755 | |
756 | |
757 void ParsedDicomFile::Answer(RestApiOutput& output) | |
758 { | |
759 std::string serialized; | |
1004
a226e0959d8b
DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
760 if (FromDcmtkBridge::SaveToMemoryBuffer(serialized, *pimpl_->file_->getDataset())) |
790 | 761 { |
762 output.AnswerBuffer(serialized, CONTENT_TYPE_OCTET_STREAM); | |
763 } | |
764 } | |
765 | |
766 | |
767 | |
768 bool ParsedDicomFile::GetTagValue(std::string& value, | |
769 const DicomTag& tag) | |
770 { | |
771 DcmTagKey k(tag.GetGroup(), tag.GetElement()); | |
794 | 772 DcmDataset& dataset = *pimpl_->file_->getDataset(); |
1307
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
773 |
1818
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
774 if (tag.IsPrivate() || |
1655
e40fd0d925c5
/tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1641
diff
changeset
|
775 FromDcmtkBridge::IsUnknownTag(tag) || |
1556
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
776 tag == DICOM_TAG_PIXEL_DATA || |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
777 tag == DICOM_TAG_ENCAPSULATED_DOCUMENT) |
790 | 778 { |
1307
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
779 const Uint8* data = NULL; // This is freed in the destructor of the dataset |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
780 long unsigned int count = 0; |
790 | 781 |
1307
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
782 if (dataset.findAndGetUint8Array(k, data, &count).good()) |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
783 { |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
784 if (count > 0) |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
785 { |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
786 assert(data != NULL); |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
787 value.assign(reinterpret_cast<const char*>(data), count); |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
788 } |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
789 else |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
790 { |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
791 value.clear(); |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
792 } |
790 | 793 |
1307
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
794 return true; |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
795 } |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
796 else |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
797 { |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
798 return false; |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
799 } |
790 | 800 } |
801 else | |
802 { | |
1307
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
803 DcmElement* element = NULL; |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
804 if (!dataset.findAndGetElement(k, element).good() || |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
805 element == NULL) |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
806 { |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
807 return false; |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
808 } |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
809 |
1736
b953c6eef28d
ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1735
diff
changeset
|
810 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement |
1929
cda5b0ab4ce5
ORTHANC_MAXIMUM_TAG_LENGTH made explicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1928
diff
changeset
|
811 (*element, DicomToJsonFlags_Default, |
cda5b0ab4ce5
ORTHANC_MAXIMUM_TAG_LENGTH made explicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1928
diff
changeset
|
812 ORTHANC_MAXIMUM_TAG_LENGTH, GetEncoding())); |
1556
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
813 |
1737
ec66a16aa398
removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1736
diff
changeset
|
814 if (v.get() == NULL || |
ec66a16aa398
removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1736
diff
changeset
|
815 v->IsNull()) |
1307
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
816 { |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
817 value = ""; |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
818 } |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
819 else |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
820 { |
1737
ec66a16aa398
removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1736
diff
changeset
|
821 // TODO v->IsBinary() |
ec66a16aa398
removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1736
diff
changeset
|
822 value = v->GetContent(); |
1307
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
823 } |
1556
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
824 |
1307
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
825 return true; |
790 | 826 } |
827 } | |
828 | |
829 | |
830 DicomInstanceHasher ParsedDicomFile::GetHasher() | |
831 { | |
832 std::string patientId, studyUid, seriesUid, instanceUid; | |
833 | |
834 if (!GetTagValue(patientId, DICOM_TAG_PATIENT_ID) || | |
835 !GetTagValue(studyUid, DICOM_TAG_STUDY_INSTANCE_UID) || | |
836 !GetTagValue(seriesUid, DICOM_TAG_SERIES_INSTANCE_UID) || | |
837 !GetTagValue(instanceUid, DICOM_TAG_SOP_INSTANCE_UID)) | |
838 { | |
839 throw OrthancException(ErrorCode_BadFileFormat); | |
840 } | |
841 | |
842 return DicomInstanceHasher(patientId, studyUid, seriesUid, instanceUid); | |
843 } | |
844 | |
845 | |
846 void ParsedDicomFile::SaveToMemoryBuffer(std::string& buffer) | |
847 { | |
1004
a226e0959d8b
DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
848 FromDcmtkBridge::SaveToMemoryBuffer(buffer, *pimpl_->file_->getDataset()); |
790 | 849 } |
850 | |
851 | |
852 void ParsedDicomFile::SaveToFile(const std::string& path) | |
853 { | |
854 // TODO Avoid using a temporary memory buffer, write directly on disk | |
855 std::string content; | |
856 SaveToMemoryBuffer(content); | |
2140 | 857 SystemToolbox::WriteFile(content, path); |
790 | 858 } |
859 | |
860 | |
1805
f08978b1f45b
c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1800
diff
changeset
|
861 ParsedDicomFile::ParsedDicomFile(bool createIdentifiers) : pimpl_(new PImpl) |
790 | 862 { |
794 | 863 pimpl_->file_.reset(new DcmFileFormat); |
1805
f08978b1f45b
c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1800
diff
changeset
|
864 |
f08978b1f45b
c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1800
diff
changeset
|
865 if (createIdentifiers) |
f08978b1f45b
c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1800
diff
changeset
|
866 { |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
867 ReplacePlainString(DICOM_TAG_PATIENT_ID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Patient)); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
868 ReplacePlainString(DICOM_TAG_STUDY_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Study)); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
869 ReplacePlainString(DICOM_TAG_SERIES_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Series)); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
870 ReplacePlainString(DICOM_TAG_SOP_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Instance)); |
1805
f08978b1f45b
c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1800
diff
changeset
|
871 } |
790 | 872 } |
873 | |
791 | 874 |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1786
diff
changeset
|
875 ParsedDicomFile::ParsedDicomFile(const DicomMap& map) : pimpl_(new PImpl) |
1786
164d78911382
primitives to handle dicom worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
876 { |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1786
diff
changeset
|
877 std::auto_ptr<DcmDataset> dataset(ToDcmtkBridge::Convert(map)); |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1786
diff
changeset
|
878 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1786
diff
changeset
|
879 // NOTE: This implies an unnecessary memory copy of the dataset, but no way to get around |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1786
diff
changeset
|
880 // http://support.dcmtk.org/redmine/issues/544 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1786
diff
changeset
|
881 std::auto_ptr<DcmFileFormat> fileFormat(new DcmFileFormat(dataset.get())); |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1786
diff
changeset
|
882 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1786
diff
changeset
|
883 pimpl_->file_.reset(fileFormat.release()); |
1786
164d78911382
primitives to handle dicom worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
884 } |
164d78911382
primitives to handle dicom worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
885 |
164d78911382
primitives to handle dicom worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
886 |
1800
30e97a1f4093
callback for handling worklists with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1788
diff
changeset
|
887 ParsedDicomFile::ParsedDicomFile(const void* content, |
30e97a1f4093
callback for handling worklists with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1788
diff
changeset
|
888 size_t size) : pimpl_(new PImpl) |
791 | 889 { |
1935
e251606c1433
FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
890 pimpl_->file_.reset(FromDcmtkBridge::LoadFromMemoryBuffer(content, size)); |
791 | 891 } |
892 | |
794 | 893 ParsedDicomFile::ParsedDicomFile(const std::string& content) : pimpl_(new PImpl) |
791 | 894 { |
895 if (content.size() == 0) | |
896 { | |
1935
e251606c1433
FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
897 pimpl_->file_.reset(FromDcmtkBridge::LoadFromMemoryBuffer(NULL, 0)); |
791 | 898 } |
899 else | |
900 { | |
1935
e251606c1433
FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
901 pimpl_->file_.reset(FromDcmtkBridge::LoadFromMemoryBuffer(&content[0], content.size())); |
791 | 902 } |
903 } | |
792 | 904 |
905 | |
794 | 906 ParsedDicomFile::ParsedDicomFile(ParsedDicomFile& other) : |
907 pimpl_(new PImpl) | |
792 | 908 { |
794 | 909 pimpl_->file_.reset(dynamic_cast<DcmFileFormat*>(other.pimpl_->file_->clone())); |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
910 |
1564
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
911 // Create a new instance-level identifier |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
912 ReplacePlainString(DICOM_TAG_SOP_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Instance)); |
792 | 913 } |
914 | |
915 | |
1788
6a2d507ef064
getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1787
diff
changeset
|
916 ParsedDicomFile::ParsedDicomFile(DcmDataset& dicom) : pimpl_(new PImpl) |
6a2d507ef064
getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1787
diff
changeset
|
917 { |
6a2d507ef064
getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1787
diff
changeset
|
918 pimpl_->file_.reset(new DcmFileFormat(&dicom)); |
6a2d507ef064
getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1787
diff
changeset
|
919 } |
6a2d507ef064
getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1787
diff
changeset
|
920 |
6a2d507ef064
getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1787
diff
changeset
|
921 |
6a2d507ef064
getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1787
diff
changeset
|
922 ParsedDicomFile::ParsedDicomFile(DcmFileFormat& dicom) : pimpl_(new PImpl) |
6a2d507ef064
getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1787
diff
changeset
|
923 { |
6a2d507ef064
getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1787
diff
changeset
|
924 pimpl_->file_.reset(new DcmFileFormat(dicom)); |
6a2d507ef064
getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1787
diff
changeset
|
925 } |
6a2d507ef064
getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1787
diff
changeset
|
926 |
6a2d507ef064
getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1787
diff
changeset
|
927 |
792 | 928 ParsedDicomFile::~ParsedDicomFile() |
929 { | |
794 | 930 delete pimpl_; |
792 | 931 } |
932 | |
793 | 933 |
1824
b530c3dfe2a6
refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
934 DcmFileFormat& ParsedDicomFile::GetDcmtkObject() const |
793 | 935 { |
1788
6a2d507ef064
getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1787
diff
changeset
|
936 return *pimpl_->file_.get(); |
793 | 937 } |
938 | |
939 | |
940 ParsedDicomFile* ParsedDicomFile::Clone() | |
941 { | |
794 | 942 return new ParsedDicomFile(*this); |
793 | 943 } |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
944 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
945 |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
946 bool ParsedDicomFile::EmbedContentInternal(const std::string& dataUriScheme) |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
947 { |
1641
4e56b5a206b7
Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
948 std::string mime, content; |
1981
4b545a8b1f95
return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
949 if (!Toolbox::DecodeDataUriScheme(mime, content, dataUriScheme)) |
4b545a8b1f95
return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
950 { |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
951 return false; |
1981
4b545a8b1f95
return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
952 } |
4b545a8b1f95
return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
953 |
1562 | 954 Toolbox::ToLowerCase(mime); |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
955 |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1737
diff
changeset
|
956 if (mime == "image/png" || |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1737
diff
changeset
|
957 mime == "image/jpeg") |
1562 | 958 { |
959 EmbedImage(mime, content); | |
960 } | |
961 else if (mime == "application/pdf") | |
962 { | |
963 EmbedPdf(content); | |
964 } | |
965 else | |
966 { | |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1689
diff
changeset
|
967 LOG(ERROR) << "Unsupported MIME type for the content of a new DICOM file: " << mime; |
1562 | 968 throw OrthancException(ErrorCode_NotImplemented); |
969 } | |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
970 |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
971 return true; |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
972 } |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
973 |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
974 |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
975 void ParsedDicomFile::EmbedContent(const std::string& dataUriScheme) |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
976 { |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
977 if (!EmbedContentInternal(dataUriScheme)) |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
978 { |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
979 throw OrthancException(ErrorCode_BadFileFormat); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
980 } |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
981 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
982 |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
983 |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
984 void ParsedDicomFile::EmbedImage(const std::string& mime, |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
985 const std::string& content) |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
986 { |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
987 if (mime == "image/png") |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
988 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
989 PngReader reader; |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
990 reader.ReadFromMemory(content); |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
991 EmbedImage(reader); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
992 } |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1737
diff
changeset
|
993 else if (mime == "image/jpeg") |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1737
diff
changeset
|
994 { |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1737
diff
changeset
|
995 JpegReader reader; |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1737
diff
changeset
|
996 reader.ReadFromMemory(content); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1737
diff
changeset
|
997 EmbedImage(reader); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1737
diff
changeset
|
998 } |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
999 else |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1000 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1001 throw OrthancException(ErrorCode_NotImplemented); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1002 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1003 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1004 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1005 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1006 void ParsedDicomFile::EmbedImage(const ImageAccessor& accessor) |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1007 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1008 if (accessor.GetFormat() != PixelFormat_Grayscale8 && |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1009 accessor.GetFormat() != PixelFormat_Grayscale16 && |
1941
d7b176f7dd1b
test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1935
diff
changeset
|
1010 accessor.GetFormat() != PixelFormat_SignedGrayscale16 && |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1011 accessor.GetFormat() != PixelFormat_RGB24 && |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1012 accessor.GetFormat() != PixelFormat_RGBA32) |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1013 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1014 throw OrthancException(ErrorCode_NotImplemented); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1015 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1016 |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1017 InvalidateCache(); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1018 |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1019 if (accessor.GetFormat() == PixelFormat_RGBA32) |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1020 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1021 LOG(WARNING) << "Getting rid of the alpha channel when embedding a RGBA image inside DICOM"; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1022 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1023 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1024 // http://dicomiseasy.blogspot.be/2012/08/chapter-12-pixel-data.html |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1025 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1026 Remove(DICOM_TAG_PIXEL_DATA); |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1027 ReplacePlainString(DICOM_TAG_COLUMNS, boost::lexical_cast<std::string>(accessor.GetWidth())); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1028 ReplacePlainString(DICOM_TAG_ROWS, boost::lexical_cast<std::string>(accessor.GetHeight())); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1029 ReplacePlainString(DICOM_TAG_SAMPLES_PER_PIXEL, "1"); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1030 ReplacePlainString(DICOM_TAG_NUMBER_OF_FRAMES, "1"); |
1941
d7b176f7dd1b
test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1935
diff
changeset
|
1031 |
d7b176f7dd1b
test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1935
diff
changeset
|
1032 if (accessor.GetFormat() == PixelFormat_SignedGrayscale16) |
d7b176f7dd1b
test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1935
diff
changeset
|
1033 { |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1034 ReplacePlainString(DICOM_TAG_PIXEL_REPRESENTATION, "1"); |
1941
d7b176f7dd1b
test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1935
diff
changeset
|
1035 } |
d7b176f7dd1b
test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1935
diff
changeset
|
1036 else |
d7b176f7dd1b
test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1935
diff
changeset
|
1037 { |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1038 ReplacePlainString(DICOM_TAG_PIXEL_REPRESENTATION, "0"); // Unsigned pixels |
1941
d7b176f7dd1b
test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1935
diff
changeset
|
1039 } |
d7b176f7dd1b
test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1935
diff
changeset
|
1040 |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1041 ReplacePlainString(DICOM_TAG_PLANAR_CONFIGURATION, "0"); // Color channels are interleaved |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1042 ReplacePlainString(DICOM_TAG_PHOTOMETRIC_INTERPRETATION, "MONOCHROME2"); |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1043 |
1941
d7b176f7dd1b
test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1935
diff
changeset
|
1044 unsigned int bytesPerPixel = 0; |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1045 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1046 switch (accessor.GetFormat()) |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1047 { |
1941
d7b176f7dd1b
test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1935
diff
changeset
|
1048 case PixelFormat_Grayscale8: |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1049 ReplacePlainString(DICOM_TAG_BITS_ALLOCATED, "8"); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1050 ReplacePlainString(DICOM_TAG_BITS_STORED, "8"); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1051 ReplacePlainString(DICOM_TAG_HIGH_BIT, "7"); |
1941
d7b176f7dd1b
test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1935
diff
changeset
|
1052 bytesPerPixel = 1; |
d7b176f7dd1b
test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1935
diff
changeset
|
1053 break; |
d7b176f7dd1b
test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1935
diff
changeset
|
1054 |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1055 case PixelFormat_RGB24: |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1056 case PixelFormat_RGBA32: |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1057 ReplacePlainString(DICOM_TAG_PHOTOMETRIC_INTERPRETATION, "RGB"); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1058 ReplacePlainString(DICOM_TAG_SAMPLES_PER_PIXEL, "3"); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1059 ReplacePlainString(DICOM_TAG_BITS_ALLOCATED, "8"); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1060 ReplacePlainString(DICOM_TAG_BITS_STORED, "8"); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1061 ReplacePlainString(DICOM_TAG_HIGH_BIT, "7"); |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1062 bytesPerPixel = 3; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1063 break; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1064 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1065 case PixelFormat_Grayscale16: |
1941
d7b176f7dd1b
test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1935
diff
changeset
|
1066 case PixelFormat_SignedGrayscale16: |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1067 ReplacePlainString(DICOM_TAG_BITS_ALLOCATED, "16"); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1068 ReplacePlainString(DICOM_TAG_BITS_STORED, "16"); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1069 ReplacePlainString(DICOM_TAG_HIGH_BIT, "15"); |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1070 bytesPerPixel = 2; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1071 break; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1072 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1073 default: |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1074 throw OrthancException(ErrorCode_NotImplemented); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1075 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1076 |
1941
d7b176f7dd1b
test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1935
diff
changeset
|
1077 assert(bytesPerPixel != 0); |
d7b176f7dd1b
test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1935
diff
changeset
|
1078 |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1079 DcmTag key(DICOM_TAG_PIXEL_DATA.GetGroup(), |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1080 DICOM_TAG_PIXEL_DATA.GetElement()); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1081 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1082 std::auto_ptr<DcmPixelData> pixels(new DcmPixelData(key)); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1083 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1084 unsigned int pitch = accessor.GetWidth() * bytesPerPixel; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1085 Uint8* target = NULL; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1086 pixels->createUint8Array(accessor.GetHeight() * pitch, target); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1087 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1088 for (unsigned int y = 0; y < accessor.GetHeight(); y++) |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1089 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1090 switch (accessor.GetFormat()) |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1091 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1092 case PixelFormat_RGB24: |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1093 case PixelFormat_Grayscale8: |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1094 case PixelFormat_Grayscale16: |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1095 case PixelFormat_SignedGrayscale16: |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1096 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1097 memcpy(target, reinterpret_cast<const Uint8*>(accessor.GetConstRow(y)), pitch); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1098 target += pitch; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1099 break; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1100 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1101 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1102 case PixelFormat_RGBA32: |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1103 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1104 // The alpha channel is not supported by the DICOM standard |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1105 const Uint8* source = reinterpret_cast<const Uint8*>(accessor.GetConstRow(y)); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1106 for (unsigned int x = 0; x < accessor.GetWidth(); x++, target += 3, source += 4) |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1107 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1108 target[0] = source[0]; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1109 target[1] = source[1]; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1110 target[2] = source[2]; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1111 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1112 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1113 break; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1114 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1115 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1116 default: |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1117 throw OrthancException(ErrorCode_NotImplemented); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1118 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1119 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1120 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1121 if (!pimpl_->file_->getDataset()->insert(pixels.release(), false, false).good()) |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1122 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1123 throw OrthancException(ErrorCode_InternalError); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1124 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1125 } |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1126 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1127 |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
1128 Encoding ParsedDicomFile::GetEncoding() const |
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
1129 { |
1928
84c7eaeb5244
Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1924
diff
changeset
|
1130 return FromDcmtkBridge::DetectEncoding(*pimpl_->file_->getDataset(), |
84c7eaeb5244
Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1924
diff
changeset
|
1131 Configuration::GetDefaultEncoding()); |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
1132 } |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1018
diff
changeset
|
1133 |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1018
diff
changeset
|
1134 |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1018
diff
changeset
|
1135 void ParsedDicomFile::SetEncoding(Encoding encoding) |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1018
diff
changeset
|
1136 { |
1558
124de28b32ed
fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
1137 if (encoding == Encoding_Windows1251) |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1018
diff
changeset
|
1138 { |
1558
124de28b32ed
fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
1139 // This Cyrillic codepage is not officially supported by the |
124de28b32ed
fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
1140 // DICOM standard. Do not set the SpecificCharacterSet tag. |
124de28b32ed
fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
1141 return; |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1018
diff
changeset
|
1142 } |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1018
diff
changeset
|
1143 |
1565
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
1144 std::string s = GetDicomSpecificCharacterSet(encoding); |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1145 ReplacePlainString(DICOM_TAG_SPECIFIC_CHARACTER_SET, s); |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1018
diff
changeset
|
1146 } |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1018
diff
changeset
|
1147 |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2126
diff
changeset
|
1148 void ParsedDicomFile::DatasetToJson(Json::Value& target, |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2126
diff
changeset
|
1149 DicomToJsonFormat format, |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2126
diff
changeset
|
1150 DicomToJsonFlags flags, |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2126
diff
changeset
|
1151 unsigned int maxStringLength) |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1152 { |
2126 | 1153 FromDcmtkBridge::ExtractDicomAsJson(target, *pimpl_->file_->getDataset(), |
2131 | 1154 format, flags, maxStringLength, Configuration::GetDefaultEncoding()); |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1155 } |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1156 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1157 |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2126
diff
changeset
|
1158 void ParsedDicomFile::DatasetToJson(Json::Value& target) |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2126
diff
changeset
|
1159 { |
2131 | 1160 Configuration::ExtractDicomAsJson(target, *pimpl_->file_->getDataset()); |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2126
diff
changeset
|
1161 } |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2126
diff
changeset
|
1162 |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2126
diff
changeset
|
1163 |
1831
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1827
diff
changeset
|
1164 void ParsedDicomFile::HeaderToJson(Json::Value& target, |
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1827
diff
changeset
|
1165 DicomToJsonFormat format) |
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1827
diff
changeset
|
1166 { |
2126 | 1167 FromDcmtkBridge::ExtractHeaderAsJson(target, *pimpl_->file_->getMetaInfo(), format, DicomToJsonFlags_None, 0); |
1831
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1827
diff
changeset
|
1168 } |
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1827
diff
changeset
|
1169 |
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1827
diff
changeset
|
1170 |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1171 bool ParsedDicomFile::HasTag(const DicomTag& tag) const |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1172 { |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1173 DcmTag key(tag.GetGroup(), tag.GetElement()); |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1174 return pimpl_->file_->getDataset()->tagExists(key); |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1175 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1176 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1177 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1178 void ParsedDicomFile::EmbedPdf(const std::string& pdf) |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1179 { |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1180 if (pdf.size() < 5 || // (*) |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1181 strncmp("%PDF-", pdf.c_str(), 5) != 0) |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1182 { |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1183 LOG(ERROR) << "Not a PDF file"; |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1184 throw OrthancException(ErrorCode_BadFileFormat); |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1185 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1186 |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1187 InvalidateCache(); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1188 |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1189 ReplacePlainString(DICOM_TAG_SOP_CLASS_UID, UID_EncapsulatedPDFStorage); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1190 ReplacePlainString(FromDcmtkBridge::Convert(DCM_Modality), "OT"); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1191 ReplacePlainString(FromDcmtkBridge::Convert(DCM_ConversionType), "WSD"); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1192 ReplacePlainString(FromDcmtkBridge::Convert(DCM_MIMETypeOfEncapsulatedDocument), "application/pdf"); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1193 //ReplacePlainString(FromDcmtkBridge::Convert(DCM_SeriesNumber), "1"); |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1194 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1195 std::auto_ptr<DcmPolymorphOBOW> element(new DcmPolymorphOBOW(DCM_EncapsulatedDocument)); |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1196 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1197 size_t s = pdf.size(); |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1198 if (s & 1) |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1199 { |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1200 // The size of the buffer must be even |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1201 s += 1; |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1202 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1203 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1204 Uint8* bytes = NULL; |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1205 OFCondition result = element->createUint8Array(s, bytes); |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1206 if (!result.good() || bytes == NULL) |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1207 { |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1208 throw OrthancException(ErrorCode_NotEnoughMemory); |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1209 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1210 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1211 // Blank pad byte (no access violation, as "pdf.size() >= 5" because of (*) ) |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1212 bytes[s - 1] = 0; |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1213 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1214 memcpy(bytes, pdf.c_str(), pdf.size()); |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1215 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1216 DcmPolymorphOBOW* obj = element.release(); |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1217 result = pimpl_->file_->getDataset()->insert(obj); |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1218 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1219 if (!result.good()) |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1220 { |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1221 delete obj; |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1222 throw OrthancException(ErrorCode_NotEnoughMemory); |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1223 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1224 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1523
diff
changeset
|
1225 |
1556
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1226 |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1227 bool ParsedDicomFile::ExtractPdf(std::string& pdf) |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1228 { |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1229 std::string sop, mime; |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1230 |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1231 if (!GetTagValue(sop, DICOM_TAG_SOP_CLASS_UID) || |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1232 !GetTagValue(mime, FromDcmtkBridge::Convert(DCM_MIMETypeOfEncapsulatedDocument)) || |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1233 sop != UID_EncapsulatedPDFStorage || |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1234 mime != "application/pdf") |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1235 { |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1236 return false; |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1237 } |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1238 |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1239 if (!GetTagValue(pdf, DICOM_TAG_ENCAPSULATED_DOCUMENT)) |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1240 { |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1241 return false; |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1242 } |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1243 |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1244 // Strip the possible pad byte at the end of file, because the |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1245 // encapsulated documents must always have an even length. The PDF |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1246 // format expects files to end with %%EOF followed by CR/LF. If |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1247 // the last character of the file is not a CR or LF, we assume it |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1248 // is a pad byte and remove it. |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1249 if (pdf.size() > 0) |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1250 { |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1251 char last = *pdf.rbegin(); |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1252 |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1253 if (last != 10 && last != 13) |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1254 { |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1255 pdf.resize(pdf.size() - 1); |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1256 } |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1257 } |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1258 |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1259 return true; |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
1260 } |
1662
09be34b2f30e
ParsedDicomFile::Convert()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1655
diff
changeset
|
1261 |
09be34b2f30e
ParsedDicomFile::Convert()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1655
diff
changeset
|
1262 |
09be34b2f30e
ParsedDicomFile::Convert()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1655
diff
changeset
|
1263 void ParsedDicomFile::Convert(DicomMap& tags) |
09be34b2f30e
ParsedDicomFile::Convert()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1655
diff
changeset
|
1264 { |
2131 | 1265 Configuration::ExtractDicomSummary(tags, *pimpl_->file_->getDataset()); |
1662
09be34b2f30e
ParsedDicomFile::Convert()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1655
diff
changeset
|
1266 } |
1818
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1267 |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1268 |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1269 ParsedDicomFile* ParsedDicomFile::CreateFromJson(const Json::Value& json, |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1270 DicomFromJsonFlags flags) |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1271 { |
2028 | 1272 const bool generateIdentifiers = (flags & DicomFromJsonFlags_GenerateIdentifiers) ? true : false; |
1273 const bool decodeDataUriScheme = (flags & DicomFromJsonFlags_DecodeDataUriScheme) ? true : false; | |
1818
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1274 |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1275 std::auto_ptr<ParsedDicomFile> result(new ParsedDicomFile(generateIdentifiers)); |
1934
72a2fd7fed8b
FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
1276 result->SetEncoding(FromDcmtkBridge::ExtractEncoding(json, Configuration::GetDefaultEncoding())); |
1818
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1277 |
1934
72a2fd7fed8b
FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
1278 const Json::Value::Members tags = json.getMemberNames(); |
72a2fd7fed8b
FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
1279 |
1818
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1280 for (size_t i = 0; i < tags.size(); i++) |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1281 { |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1282 DicomTag tag = FromDcmtkBridge::ParseTag(tags[i]); |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1283 const Json::Value& value = json[tags[i]]; |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1284 |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1285 if (tag == DICOM_TAG_PIXEL_DATA || |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1286 tag == DICOM_TAG_ENCAPSULATED_DOCUMENT) |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1287 { |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1288 if (value.type() != Json::stringValue) |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1289 { |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1290 throw OrthancException(ErrorCode_BadRequest); |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1291 } |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1292 else |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1293 { |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1294 result->EmbedContent(value.asString()); |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1295 } |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1296 } |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1297 else if (tag != DICOM_TAG_SPECIFIC_CHARACTER_SET) |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1298 { |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1299 result->Replace(tag, value, decodeDataUriScheme, DicomReplaceMode_InsertIfAbsent); |
1818
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1300 } |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1301 } |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1302 |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1303 return result.release(); |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
1304 } |
1924
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1305 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1306 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1307 void ParsedDicomFile::GetRawFrame(std::string& target, |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1308 std::string& mime, |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1309 unsigned int frameId) |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1310 { |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1311 if (pimpl_->frameIndex_.get() == NULL) |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1312 { |
1956 | 1313 pimpl_->frameIndex_.reset(new DicomFrameIndex(*pimpl_->file_)); |
1924
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1314 } |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1315 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1316 pimpl_->frameIndex_->GetRawFrame(target, frameId); |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1317 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1318 E_TransferSyntax transferSyntax = pimpl_->file_->getDataset()->getOriginalXfer(); |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1319 switch (transferSyntax) |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1320 { |
1946
40b7a0176305
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
1321 case EXS_JPEGProcess1: |
1924
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1322 mime = "image/jpeg"; |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1323 break; |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1324 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1325 case EXS_JPEG2000LosslessOnly: |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1326 case EXS_JPEG2000: |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1327 mime = "image/jp2"; |
2016 | 1328 break; |
1924
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1329 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1330 default: |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1331 mime = "application/octet-stream"; |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1332 break; |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1333 } |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1334 } |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1335 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1336 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1337 void ParsedDicomFile::InvalidateCache() |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1338 { |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1339 pimpl_->frameIndex_.reset(NULL); |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1913
diff
changeset
|
1340 } |
1950
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1946
diff
changeset
|
1341 |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1946
diff
changeset
|
1342 |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1946
diff
changeset
|
1343 unsigned int ParsedDicomFile::GetFramesCount() const |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1946
diff
changeset
|
1344 { |
1956 | 1345 return DicomFrameIndex::GetFramesCount(*pimpl_->file_); |
1950
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1946
diff
changeset
|
1346 } |
790 | 1347 } |