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