Mercurial > hg > orthanc
annotate OrthancServer/FromDcmtkBridge.cpp @ 799:777b6b694da6
rename folder
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 06 May 2014 12:55:41 +0200 |
parents | 331eaf9d9d69 |
children | a811bdf8b8eb |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
689 | 3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, |
0 | 4 * Belgium |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
136 | 10 * |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
0 | 22 * |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
448
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
32 |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
33 |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
34 /*========================================================================= |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
35 |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
36 This file is based on portions of the following project: |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
37 |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
38 Program: GDCM (Grassroots DICOM). A DICOM library |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
39 Module: http://gdcm.sourceforge.net/Copyright.html |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
40 |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
41 Copyright (c) 2006-2011 Mathieu Malaterre |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
42 Copyright (c) 1993-2005 CREATIS |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
43 (CREATIS = Centre de Recherche et d'Applications en Traitement de l'Image) |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
44 All rights reserved. |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
45 |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
46 Redistribution and use in source and binary forms, with or without |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
47 modification, are permitted provided that the following conditions are met: |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
48 |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
49 * Redistributions of source code must retain the above copyright notice, |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
50 this list of conditions and the following disclaimer. |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
51 |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
52 * Redistributions in binary form must reproduce the above copyright notice, |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
53 this list of conditions and the following disclaimer in the documentation |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
54 and/or other materials provided with the distribution. |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
55 |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
56 * Neither name of Mathieu Malaterre, or CREATIS, nor the names of any |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
57 contributors (CNRS, INSERM, UCB, Universite Lyon I), may be used to |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
58 endorse or promote products derived from this software without specific |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
59 prior written permission. |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
60 |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
61 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
62 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
63 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
64 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
65 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
66 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
67 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
68 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
69 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
70 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
71 |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
72 =========================================================================*/ |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
73 |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
74 |
71 | 75 #ifndef NOMINMAX |
76 #define NOMINMAX | |
77 #endif | |
0 | 78 |
79 #include "FromDcmtkBridge.h" | |
80 | |
81 #include "ToDcmtkBridge.h" | |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
106
diff
changeset
|
82 #include "../Core/Toolbox.h" |
62 | 83 #include "../Core/OrthancException.h" |
799 | 84 #include "../Core/ImageFormats/PngWriter.h" |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
85 #include "../Core/Uuid.h" |
0 | 86 #include "../Core/DicomFormat/DicomString.h" |
87 #include "../Core/DicomFormat/DicomNullValue.h" | |
79 | 88 #include "../Core/DicomFormat/DicomIntegerPixelAccessor.h" |
0 | 89 |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
90 #include <list> |
71 | 91 #include <limits> |
92 | |
0 | 93 #include <boost/lexical_cast.hpp> |
94 | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
95 #include <dcmtk/dcmdata/dcchrstr.h> |
0 | 96 #include <dcmtk/dcmdata/dcdicent.h> |
97 #include <dcmtk/dcmdata/dcdict.h> | |
98 #include <dcmtk/dcmdata/dcfilefo.h> | |
99 #include <dcmtk/dcmdata/dcistrmb.h> | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
100 #include <dcmtk/dcmdata/dcuid.h> |
661
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
101 #include <dcmtk/dcmdata/dcmetinf.h> |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
102 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
103 #include <dcmtk/dcmdata/dcvrae.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
104 #include <dcmtk/dcmdata/dcvras.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
105 #include <dcmtk/dcmdata/dcvrcs.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
106 #include <dcmtk/dcmdata/dcvrda.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
107 #include <dcmtk/dcmdata/dcvrds.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
108 #include <dcmtk/dcmdata/dcvrdt.h> |
0 | 109 #include <dcmtk/dcmdata/dcvrfd.h> |
110 #include <dcmtk/dcmdata/dcvrfl.h> | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
111 #include <dcmtk/dcmdata/dcvris.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
112 #include <dcmtk/dcmdata/dcvrlo.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
113 #include <dcmtk/dcmdata/dcvrlt.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
114 #include <dcmtk/dcmdata/dcvrpn.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
115 #include <dcmtk/dcmdata/dcvrsh.h> |
0 | 116 #include <dcmtk/dcmdata/dcvrsl.h> |
117 #include <dcmtk/dcmdata/dcvrss.h> | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
118 #include <dcmtk/dcmdata/dcvrst.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
119 #include <dcmtk/dcmdata/dcvrtm.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
120 #include <dcmtk/dcmdata/dcvrui.h> |
0 | 121 #include <dcmtk/dcmdata/dcvrul.h> |
122 #include <dcmtk/dcmdata/dcvrus.h> | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
123 #include <dcmtk/dcmdata/dcvrut.h> |
676
aa5ca7a2166f
experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
661
diff
changeset
|
124 #include <dcmtk/dcmdata/dcpixel.h> |
aa5ca7a2166f
experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
661
diff
changeset
|
125 #include <dcmtk/dcmdata/dcpixseq.h> |
aa5ca7a2166f
experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
661
diff
changeset
|
126 #include <dcmtk/dcmdata/dcpxitem.h> |
aa5ca7a2166f
experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
661
diff
changeset
|
127 |
0 | 128 |
2 | 129 #include <boost/math/special_functions/round.hpp> |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
130 #include <glog/logging.h> |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
131 #include <dcmtk/dcmdata/dcostrmb.h> |
0 | 132 |
682
efc4928be6fb
Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
677
diff
changeset
|
133 |
62 | 134 namespace Orthanc |
0 | 135 { |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
136 static inline uint16_t GetCharValue(char c) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
137 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
138 if (c >= '0' && c <= '9') |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
139 return c - '0'; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
140 else if (c >= 'a' && c <= 'f') |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
141 return c - 'a' + 10; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
142 else if (c >= 'A' && c <= 'F') |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
143 return c - 'A' + 10; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
144 else |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
145 return 0; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
146 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
147 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
148 static inline uint16_t GetTagValue(const char* c) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
149 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
150 return ((GetCharValue(c[0]) << 12) + |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
151 (GetCharValue(c[1]) << 8) + |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
152 (GetCharValue(c[2]) << 4) + |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
153 GetCharValue(c[3])); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
154 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
155 |
0 | 156 void FromDcmtkBridge::Convert(DicomMap& target, DcmDataset& dataset) |
157 { | |
158 target.Clear(); | |
159 for (unsigned long i = 0; i < dataset.card(); i++) | |
160 { | |
161 DcmElement* element = dataset.getElement(i); | |
162 if (element && element->isLeaf()) | |
163 { | |
164 target.SetValue(element->getTag().getGTag(), | |
165 element->getTag().getETag(), | |
166 ConvertLeafElement(*element)); | |
167 } | |
168 } | |
169 } | |
170 | |
171 | |
172 DicomTag FromDcmtkBridge::GetTag(const DcmElement& element) | |
173 { | |
174 return DicomTag(element.getGTag(), element.getETag()); | |
175 } | |
176 | |
177 | |
178 DicomValue* FromDcmtkBridge::ConvertLeafElement(DcmElement& element) | |
179 { | |
180 if (!element.isLeaf()) | |
181 { | |
62 | 182 throw OrthancException("Only applicable to leaf elements"); |
0 | 183 } |
184 | |
185 if (element.isaString()) | |
186 { | |
187 char *c; | |
188 if (element.getString(c).good() && | |
189 c != NULL) | |
190 { | |
191 std::string s(c); | |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
106
diff
changeset
|
192 std::string utf8 = Toolbox::ConvertToUtf8(s, "ISO-8859-1"); // TODO Parameter? |
0 | 193 return new DicomString(utf8); |
194 } | |
195 else | |
196 { | |
197 return new DicomNullValue; | |
198 } | |
199 } | |
200 | |
201 try | |
202 { | |
203 // http://support.dcmtk.org/docs/dcvr_8h-source.html | |
204 switch (element.getVR()) | |
205 { | |
206 | |
207 /** | |
208 * TODO. | |
209 **/ | |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
210 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
211 case EVR_OB: // other byte |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
212 case EVR_OF: // other float |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
213 case EVR_OW: // other word |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
214 case EVR_AT: // attribute tag |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
215 case EVR_UN: // unknown value representation |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
216 return new DicomNullValue(); |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
217 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
218 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
219 * String types, should never happen at this point because of |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
220 * "element.isaString()". |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
221 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
222 |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
223 case EVR_DS: // decimal string |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
224 case EVR_IS: // integer string |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
225 case EVR_AS: // age string |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
226 case EVR_DA: // date string |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
227 case EVR_DT: // date time string |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
228 case EVR_TM: // time string |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
229 case EVR_AE: // application entity title |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
230 case EVR_CS: // code string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
231 case EVR_SH: // short string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
232 case EVR_LO: // long string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
233 case EVR_ST: // short text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
234 case EVR_LT: // long text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
235 case EVR_UT: // unlimited text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
236 case EVR_PN: // person name |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
237 case EVR_UI: // unique identifier |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
238 return new DicomNullValue(); |
0 | 239 |
240 | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
241 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
242 * Numerical types |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
243 **/ |
0 | 244 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
245 case EVR_SL: // signed long |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
246 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
247 Sint32 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
248 if (dynamic_cast<DcmSignedLong&>(element).getSint32(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
249 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
250 else |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
251 return new DicomNullValue(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
252 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
253 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
254 case EVR_SS: // signed short |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
255 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
256 Sint16 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
257 if (dynamic_cast<DcmSignedShort&>(element).getSint16(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
258 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
259 else |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
260 return new DicomNullValue(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
261 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
262 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
263 case EVR_UL: // unsigned long |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
264 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
265 Uint32 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
266 if (dynamic_cast<DcmUnsignedLong&>(element).getUint32(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
267 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
268 else |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
269 return new DicomNullValue(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
270 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
271 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
272 case EVR_US: // unsigned short |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
273 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
274 Uint16 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
275 if (dynamic_cast<DcmUnsignedShort&>(element).getUint16(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
276 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
277 else |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
278 return new DicomNullValue(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
279 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
280 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
281 case EVR_FL: // float single-precision |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
282 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
283 Float32 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
284 if (dynamic_cast<DcmFloatingPointSingle&>(element).getFloat32(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
285 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
286 else |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
287 return new DicomNullValue(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
288 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
289 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
290 case EVR_FD: // float double-precision |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
291 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
292 Float64 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
293 if (dynamic_cast<DcmFloatingPointDouble&>(element).getFloat64(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
294 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
295 else |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
296 return new DicomNullValue(); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
297 } |
0 | 298 |
299 | |
300 /** | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
301 * Sequence types, should never occur at this point because of |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
302 * "element.isLeaf()". |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
303 **/ |
0 | 304 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
305 case EVR_SQ: // sequence of items |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
306 return new DicomNullValue; |
0 | 307 |
308 | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
309 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
310 * Internal to DCMTK. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
311 **/ |
0 | 312 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
313 case EVR_ox: // OB or OW depending on context |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
314 case EVR_xs: // SS or US depending on context |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
315 case EVR_lt: // US, SS or OW depending on context, used for LUT Data (thus the name) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
316 case EVR_na: // na="not applicable", for data which has no VR |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
317 case EVR_up: // up="unsigned pointer", used internally for DICOMDIR suppor |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
318 case EVR_item: // used internally for items |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
319 case EVR_metainfo: // used internally for meta info datasets |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
320 case EVR_dataset: // used internally for datasets |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
321 case EVR_fileFormat: // used internally for DICOM files |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
322 case EVR_dicomDir: // used internally for DICOMDIR objects |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
323 case EVR_dirRecord: // used internally for DICOMDIR records |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
324 case EVR_pixelSQ: // used internally for pixel sequences in a compressed image |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
325 case EVR_pixelItem: // used internally for pixel items in a compressed image |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
326 case EVR_UNKNOWN: // used internally for elements with unknown VR (encoded with 4-byte length field in explicit VR) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
327 case EVR_PixelData: // used internally for uncompressed pixeld data |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
328 case EVR_OverlayData: // used internally for overlay data |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
329 case EVR_UNKNOWN2B: // used internally for elements with unknown VR with 2-byte length field in explicit VR |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
330 return new DicomNullValue; |
0 | 331 |
332 | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
333 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
334 * Default case. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
335 **/ |
0 | 336 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
337 default: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
338 return new DicomNullValue; |
0 | 339 } |
340 } | |
341 catch (boost::bad_lexical_cast) | |
342 { | |
343 return new DicomNullValue; | |
344 } | |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
345 catch (std::bad_cast) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
346 { |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
347 return new DicomNullValue; |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
348 } |
0 | 349 } |
350 | |
351 | |
352 static void StoreElement(Json::Value& target, | |
353 DcmElement& element, | |
354 unsigned int maxStringLength); | |
355 | |
356 static void StoreItem(Json::Value& target, | |
357 DcmItem& item, | |
358 unsigned int maxStringLength) | |
359 { | |
360 target = Json::Value(Json::objectValue); | |
361 | |
362 for (unsigned long i = 0; i < item.card(); i++) | |
363 { | |
364 DcmElement* element = item.getElement(i); | |
365 StoreElement(target, *element, maxStringLength); | |
366 } | |
367 } | |
368 | |
369 | |
370 static void StoreElement(Json::Value& target, | |
371 DcmElement& element, | |
372 unsigned int maxStringLength) | |
373 { | |
374 assert(target.type() == Json::objectValue); | |
375 | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
376 DicomTag tag(FromDcmtkBridge::GetTag(element)); |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
377 const std::string formattedTag = tag.Format(); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
378 |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
379 #if 0 |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
380 const std::string tagName = FromDcmtkBridge::GetName(tag); |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
381 #else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
382 // This version of the code gives access to the name of the private tags |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
383 DcmTag tagbis(element.getTag()); |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
384 const std::string tagName(tagbis.getTagName()); |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
385 #endif |
0 | 386 |
387 if (element.isLeaf()) | |
388 { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
389 Json::Value value(Json::objectValue); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
390 value["Name"] = tagName; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
391 |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
392 if (tagbis.getPrivateCreator() != NULL) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
393 { |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
394 value["PrivateCreator"] = tagbis.getPrivateCreator(); |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
395 } |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
396 |
0 | 397 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(element)); |
398 if (v->IsNull()) | |
399 { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
400 value["Type"] = "Null"; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
401 value["Value"] = Json::nullValue; |
0 | 402 } |
403 else | |
404 { | |
405 std::string s = v->AsString(); | |
406 if (maxStringLength == 0 || | |
407 s.size() <= maxStringLength) | |
408 { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
409 value["Type"] = "String"; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
410 value["Value"] = s; |
0 | 411 } |
412 else | |
413 { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
414 value["Type"] = "TooLong"; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
415 value["Value"] = Json::nullValue; |
0 | 416 } |
417 } | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
418 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
419 target[formattedTag] = value; |
0 | 420 } |
421 else | |
422 { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
423 Json::Value children(Json::arrayValue); |
0 | 424 |
425 // "All subclasses of DcmElement except for DcmSequenceOfItems | |
426 // are leaf nodes, while DcmSequenceOfItems, DcmItem, DcmDataset | |
427 // etc. are not." The following cast is thus OK. | |
428 DcmSequenceOfItems& sequence = dynamic_cast<DcmSequenceOfItems&>(element); | |
429 | |
430 for (unsigned long i = 0; i < sequence.card(); i++) | |
431 { | |
432 DcmItem* child = sequence.getItem(i); | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
433 Json::Value& v = children.append(Json::objectValue); |
0 | 434 StoreItem(v, *child, maxStringLength); |
435 } | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
436 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
437 target[formattedTag]["Name"] = tagName; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
438 target[formattedTag]["Type"] = "Sequence"; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
439 target[formattedTag]["Value"] = children; |
0 | 440 } |
441 } | |
442 | |
443 | |
444 void FromDcmtkBridge::ToJson(Json::Value& root, | |
445 DcmDataset& dataset, | |
446 unsigned int maxStringLength) | |
447 { | |
448 StoreItem(root, dataset, maxStringLength); | |
449 } | |
450 | |
451 | |
452 | |
453 void FromDcmtkBridge::ToJson(Json::Value& target, | |
454 const std::string& path, | |
455 unsigned int maxStringLength) | |
456 { | |
457 DcmFileFormat dicom; | |
458 if (!dicom.loadFile(path.c_str()).good()) | |
459 { | |
62 | 460 throw OrthancException(ErrorCode_BadFileFormat); |
0 | 461 } |
462 else | |
463 { | |
464 FromDcmtkBridge::ToJson(target, *dicom.getDataset(), maxStringLength); | |
465 } | |
466 } | |
467 | |
468 | |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
469 static void ExtractPngImageColorPreview(std::string& result, |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
470 DicomIntegerPixelAccessor& accessor) |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
471 { |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
472 assert(accessor.GetChannelCount() == 3); |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
473 PngWriter w; |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
474 |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
475 std::vector<uint8_t> image(accessor.GetWidth() * accessor.GetHeight() * 3, 0); |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
476 uint8_t* pixel = &image[0]; |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
477 |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
478 for (unsigned int y = 0; y < accessor.GetHeight(); y++) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
479 { |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
480 for (unsigned int x = 0; x < accessor.GetWidth(); x++) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
481 { |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
482 for (unsigned int c = 0; c < 3; c++, pixel++) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
483 { |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
484 int32_t v = accessor.GetValue(x, y, c); |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
485 if (v < 0) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
486 *pixel = 0; |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
487 else if (v > 255) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
488 *pixel = 255; |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
489 else |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
490 *pixel = v; |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
491 } |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
492 } |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
493 } |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
494 |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
495 w.WriteToMemory(result, accessor.GetWidth(), accessor.GetHeight(), |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
496 accessor.GetWidth() * 3, PixelFormat_RGB24, &image[0]); |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
497 } |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
498 |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
499 |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
500 static void ExtractPngImageGrayscalePreview(std::string& result, |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
501 DicomIntegerPixelAccessor& accessor) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
502 { |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
503 assert(accessor.GetChannelCount() == 1); |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
504 PngWriter w; |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
505 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
506 int32_t min, max; |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
507 accessor.GetExtremeValues(min, max); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
508 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
509 std::vector<uint8_t> image(accessor.GetWidth() * accessor.GetHeight(), 0); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
510 if (min != max) |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
511 { |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
512 uint8_t* pixel = &image[0]; |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
513 for (unsigned int y = 0; y < accessor.GetHeight(); y++) |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
514 { |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
515 for (unsigned int x = 0; x < accessor.GetWidth(); x++, pixel++) |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
516 { |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
517 int32_t v = accessor.GetValue(x, y); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
518 *pixel = static_cast<uint8_t>( |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
519 boost::math::lround(static_cast<float>(v - min) / |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
520 static_cast<float>(max - min) * 255.0f)); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
521 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
522 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
523 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
524 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
525 w.WriteToMemory(result, accessor.GetWidth(), accessor.GetHeight(), |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
526 accessor.GetWidth(), PixelFormat_Grayscale8, &image[0]); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
527 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
528 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
529 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
530 template <typename T> |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
531 static void ExtractPngImageTruncate(std::string& result, |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
532 DicomIntegerPixelAccessor& accessor, |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
533 PixelFormat format) |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
534 { |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
535 assert(accessor.GetChannelCount() == 1); |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
536 |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
537 PngWriter w; |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
538 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
539 std::vector<T> image(accessor.GetWidth() * accessor.GetHeight(), 0); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
540 T* pixel = &image[0]; |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
541 for (unsigned int y = 0; y < accessor.GetHeight(); y++) |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
542 { |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
543 for (unsigned int x = 0; x < accessor.GetWidth(); x++, pixel++) |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
544 { |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
545 int32_t v = accessor.GetValue(x, y); |
464
5987dd8e0776
fix reading signed values in dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
454
diff
changeset
|
546 if (v < static_cast<int32_t>(std::numeric_limits<T>::min())) |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
547 *pixel = std::numeric_limits<T>::min(); |
464
5987dd8e0776
fix reading signed values in dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
454
diff
changeset
|
548 else if (v > static_cast<int32_t>(std::numeric_limits<T>::max())) |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
549 *pixel = std::numeric_limits<T>::max(); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
550 else |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
551 *pixel = static_cast<T>(v); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
552 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
553 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
554 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
555 w.WriteToMemory(result, accessor.GetWidth(), accessor.GetHeight(), |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
556 accessor.GetWidth() * sizeof(T), format, &image[0]); |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
557 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
558 |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
559 |
319 | 560 static bool DecodePsmctRle1(std::string& output, |
561 DcmDataset& dataset) | |
562 { | |
563 static const DicomTag tagContent(0x07a1, 0x100a); | |
564 static const DicomTag tagCompressionType(0x07a1, 0x1011); | |
565 | |
566 DcmElement* e; | |
567 char* c; | |
568 | |
569 // Check whether the DICOM instance contains an image encoded with | |
570 // the PMSCT_RLE1 scheme. | |
571 if (!dataset.findAndGetElement(ToDcmtkBridge::Convert(tagCompressionType), e).good() || | |
572 e == NULL || | |
573 !e->isaString() || | |
574 !e->getString(c).good() || | |
575 c == NULL || | |
576 strcmp("PMSCT_RLE1", c)) | |
577 { | |
578 return false; | |
579 } | |
580 | |
581 // OK, this is a custom RLE encoding from Philips. Get the pixel | |
582 // data from the appropriate private DICOM tag. | |
583 Uint8* pixData = NULL; | |
584 if (!dataset.findAndGetElement(ToDcmtkBridge::Convert(tagContent), e).good() || | |
585 e == NULL || | |
586 e->getUint8Array(pixData) != EC_Normal) | |
587 { | |
588 return false; | |
589 } | |
590 | |
591 // The "unsigned" below IS VERY IMPORTANT | |
592 const uint8_t* inbuffer = reinterpret_cast<const uint8_t*>(pixData); | |
593 const size_t length = e->getLength(); | |
594 | |
595 /** | |
596 * The code below is an adaptation of a sample code for GDCM by | |
597 * Mathieu Malaterre (under a BSD license). | |
598 * http://gdcm.sourceforge.net/html/rle2img_8cxx-example.html | |
599 **/ | |
600 | |
601 // RLE pass | |
602 std::vector<uint8_t> temp; | |
603 temp.reserve(length); | |
604 for (size_t i = 0; i < length; i++) | |
605 { | |
606 if (inbuffer[i] == 0xa5) | |
607 { | |
608 temp.push_back(inbuffer[i+2]); | |
609 for (uint8_t repeat = inbuffer[i + 1]; repeat != 0; repeat--) | |
610 { | |
611 temp.push_back(inbuffer[i+2]); | |
612 } | |
613 i += 2; | |
614 } | |
615 else | |
616 { | |
617 temp.push_back(inbuffer[i]); | |
618 } | |
619 } | |
620 | |
621 // Delta encoding pass | |
622 uint16_t delta = 0; | |
623 output.clear(); | |
624 output.reserve(temp.size()); | |
625 for (size_t i = 0; i < temp.size(); i++) | |
626 { | |
627 uint16_t value; | |
628 | |
629 if (temp[i] == 0x5a) | |
630 { | |
631 uint16_t v1 = temp[i + 1]; | |
632 uint16_t v2 = temp[i + 2]; | |
633 value = (v2 << 8) + v1; | |
634 i += 2; | |
635 } | |
636 else | |
637 { | |
638 value = delta + (int8_t) temp[i]; | |
639 } | |
640 | |
641 output.push_back(value & 0xff); | |
642 output.push_back(value >> 8); | |
643 delta = value; | |
644 } | |
645 | |
646 if (output.size() % 2) | |
647 { | |
648 output.resize(output.size() - 1); | |
649 } | |
650 | |
651 return true; | |
652 } | |
653 | |
654 | |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
655 void FromDcmtkBridge::ExtractPngImage(std::string& result, |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
656 DcmDataset& dataset, |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
657 unsigned int frame, |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
658 ImageExtractionMode mode) |
0 | 659 { |
660 // See also: http://support.dcmtk.org/wiki/dcmtk/howto/accessing-compressed-data | |
661 | |
662 std::auto_ptr<DicomIntegerPixelAccessor> accessor; | |
663 | |
664 DicomMap m; | |
665 FromDcmtkBridge::Convert(m, dataset); | |
666 | |
319 | 667 std::string privateContent; |
668 | |
0 | 669 DcmElement* e; |
80 | 670 if (dataset.findAndGetElement(ToDcmtkBridge::Convert(DICOM_TAG_PIXEL_DATA), e).good() && |
0 | 671 e != NULL) |
672 { | |
673 Uint8* pixData = NULL; | |
674 if (e->getUint8Array(pixData) == EC_Normal) | |
675 { | |
676 accessor.reset(new DicomIntegerPixelAccessor(m, pixData, e->getLength())); | |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
677 accessor->SetCurrentFrame(frame); |
0 | 678 } |
679 } | |
319 | 680 else if (DecodePsmctRle1(privateContent, dataset)) |
681 { | |
682 LOG(INFO) << "The PMSCT_RLE1 decoding has succeeded"; | |
683 Uint8* pixData = NULL; | |
684 if (privateContent.size() > 0) | |
685 pixData = reinterpret_cast<Uint8*>(&privateContent[0]); | |
686 accessor.reset(new DicomIntegerPixelAccessor(m, pixData, privateContent.size())); | |
687 accessor->SetCurrentFrame(frame); | |
688 } | |
419 | 689 |
690 if (accessor.get() == NULL) | |
691 { | |
692 throw OrthancException(ErrorCode_BadFileFormat); | |
693 } | |
0 | 694 |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
695 PixelFormat format; |
369
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
696 bool supported = false; |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
697 |
369
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
698 if (accessor->GetChannelCount() == 1) |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
699 { |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
700 switch (mode) |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
701 { |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
702 case ImageExtractionMode_Preview: |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
703 supported = true; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
704 format = PixelFormat_Grayscale8; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
705 break; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
706 |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
707 case ImageExtractionMode_UInt8: |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
708 supported = true; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
709 format = PixelFormat_Grayscale8; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
710 break; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
711 |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
712 case ImageExtractionMode_UInt16: |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
713 supported = true; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
714 format = PixelFormat_Grayscale16; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
715 break; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
716 |
465
7a966b440f19
signed images to PNG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
464
diff
changeset
|
717 case ImageExtractionMode_Int16: |
7a966b440f19
signed images to PNG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
464
diff
changeset
|
718 supported = true; |
7a966b440f19
signed images to PNG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
464
diff
changeset
|
719 format = PixelFormat_SignedGrayscale16; |
7a966b440f19
signed images to PNG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
464
diff
changeset
|
720 break; |
7a966b440f19
signed images to PNG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
464
diff
changeset
|
721 |
369
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
722 default: |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
723 supported = false; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
724 break; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
725 } |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
726 } |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
727 else if (accessor->GetChannelCount() == 3) |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
728 { |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
729 switch (mode) |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
730 { |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
731 case ImageExtractionMode_Preview: |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
732 supported = true; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
733 format = PixelFormat_RGB24; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
734 break; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
735 |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
736 default: |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
737 supported = false; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
738 break; |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
739 } |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
740 } |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
741 |
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
742 if (!supported) |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
743 { |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
744 throw OrthancException(ErrorCode_NotImplemented); |
369
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
745 } |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
746 |
0 | 747 if (accessor.get() == NULL || |
748 accessor->GetWidth() == 0 || | |
749 accessor->GetHeight() == 0) | |
750 { | |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
751 PngWriter w; |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
752 w.WriteToMemory(result, 0, 0, 0, format, NULL); |
0 | 753 } |
754 else | |
755 { | |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
756 switch (mode) |
0 | 757 { |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
758 case ImageExtractionMode_Preview: |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
759 if (format == PixelFormat_Grayscale8) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
760 ExtractPngImageGrayscalePreview(result, *accessor); |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
761 else |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
762 ExtractPngImageColorPreview(result, *accessor); |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
763 break; |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
764 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
765 case ImageExtractionMode_UInt8: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
766 ExtractPngImageTruncate<uint8_t>(result, *accessor, format); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
767 break; |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
768 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
769 case ImageExtractionMode_UInt16: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
770 ExtractPngImageTruncate<uint16_t>(result, *accessor, format); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
771 break; |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
772 |
465
7a966b440f19
signed images to PNG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
464
diff
changeset
|
773 case ImageExtractionMode_Int16: |
7a966b440f19
signed images to PNG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
464
diff
changeset
|
774 ExtractPngImageTruncate<int16_t>(result, *accessor, format); |
7a966b440f19
signed images to PNG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
464
diff
changeset
|
775 break; |
7a966b440f19
signed images to PNG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
464
diff
changeset
|
776 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
777 default: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
778 throw OrthancException(ErrorCode_NotImplemented); |
0 | 779 } |
780 } | |
781 } | |
782 | |
783 | |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
784 void FromDcmtkBridge::ExtractPngImage(std::string& result, |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
785 const std::string& dicomContent, |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
786 unsigned int frame, |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
787 ImageExtractionMode mode) |
0 | 788 { |
789 DcmInputBufferStream is; | |
790 if (dicomContent.size() > 0) | |
791 { | |
792 is.setBuffer(&dicomContent[0], dicomContent.size()); | |
793 } | |
794 is.setEos(); | |
795 | |
796 DcmFileFormat dicom; | |
797 if (dicom.read(is).good()) | |
798 { | |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
799 ExtractPngImage(result, *dicom.getDataset(), frame, mode); |
0 | 800 } |
801 else | |
802 { | |
62 | 803 throw OrthancException(ErrorCode_BadFileFormat); |
0 | 804 } |
805 } | |
806 | |
807 | |
808 | |
809 std::string FromDcmtkBridge::GetName(const DicomTag& t) | |
810 { | |
106 | 811 // Some patches for important tags because of different DICOM |
812 // dictionaries between DCMTK versions | |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
813 std::string n = t.GetMainTagsName(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
814 if (n.size() != 0) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
815 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
816 return n; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
817 } |
106 | 818 // End of patches |
819 | |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
820 #if 0 |
0 | 821 DcmTagKey tag(t.GetGroup(), t.GetElement()); |
822 const DcmDataDictionary& dict = dcmDataDict.rdlock(); | |
823 const DcmDictEntry* entry = dict.findEntry(tag, NULL); | |
824 | |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
825 std::string s(DcmTag_ERROR_TagName); |
0 | 826 if (entry != NULL) |
827 { | |
828 s = std::string(entry->getTagName()); | |
829 } | |
830 | |
831 dcmDataDict.unlock(); | |
832 return s; | |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
833 #else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
834 DcmTag tag(t.GetGroup(), t.GetElement()); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
835 const char* name = tag.getTagName(); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
836 if (name == NULL) |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
837 { |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
838 return DcmTag_ERROR_TagName; |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
839 } |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
840 else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
841 { |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
842 return std::string(name); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
843 } |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
844 #endif |
0 | 845 } |
846 | |
847 | |
304 | 848 DicomTag FromDcmtkBridge::ParseTag(const char* name) |
0 | 849 { |
304 | 850 if (strlen(name) == 9 && |
851 isxdigit(name[0]) && | |
852 isxdigit(name[1]) && | |
853 isxdigit(name[2]) && | |
854 isxdigit(name[3]) && | |
855 name[4] == '-' && | |
856 isxdigit(name[5]) && | |
857 isxdigit(name[6]) && | |
858 isxdigit(name[7]) && | |
859 isxdigit(name[8])) | |
860 { | |
861 uint16_t group = GetTagValue(name); | |
862 uint16_t element = GetTagValue(name + 5); | |
863 return DicomTag(group, element); | |
864 } | |
865 | |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
866 #if 0 |
0 | 867 const DcmDataDictionary& dict = dcmDataDict.rdlock(); |
868 const DcmDictEntry* entry = dict.findEntry(name); | |
869 | |
870 if (entry == NULL) | |
871 { | |
872 dcmDataDict.unlock(); | |
62 | 873 throw OrthancException("Unknown DICOM tag"); |
0 | 874 } |
875 else | |
876 { | |
877 DcmTagKey key = entry->getKey(); | |
878 DicomTag tag(key.getGroup(), key.getElement()); | |
879 dcmDataDict.unlock(); | |
880 return tag; | |
881 } | |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
882 #else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
883 DcmTag tag; |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
884 if (DcmTag::findTagFromName(name, tag).good()) |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
885 { |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
886 return DicomTag(tag.getGTag(), tag.getETag()); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
887 } |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
888 else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
889 { |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
890 throw OrthancException("Unknown DICOM tag"); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
891 } |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
892 #endif |
0 | 893 } |
894 | |
895 | |
896 void FromDcmtkBridge::Print(FILE* fp, const DicomMap& m) | |
897 { | |
898 for (DicomMap::Map::const_iterator | |
656 | 899 it = m.map_.begin(); it != m.map_.end(); ++it) |
0 | 900 { |
901 DicomTag t = it->first; | |
902 std::string s = it->second->AsString(); | |
319 | 903 fprintf(fp, "0x%04x 0x%04x (%s) [%s]\n", t.GetGroup(), t.GetElement(), GetName(t).c_str(), s.c_str()); |
0 | 904 } |
905 } | |
906 | |
907 | |
908 void FromDcmtkBridge::ToJson(Json::Value& result, | |
909 const DicomMap& values) | |
910 { | |
911 if (result.type() != Json::objectValue) | |
912 { | |
62 | 913 throw OrthancException(ErrorCode_BadParameterType); |
0 | 914 } |
915 | |
916 result.clear(); | |
917 | |
918 for (DicomMap::Map::const_iterator | |
656 | 919 it = values.map_.begin(); it != values.map_.end(); ++it) |
0 | 920 { |
921 result[GetName(it->first)] = it->second->AsString(); | |
922 } | |
923 } | |
176 | 924 |
925 | |
788 | 926 std::string FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType level) |
176 | 927 { |
928 char uid[100]; | |
929 | |
930 switch (level) | |
931 { | |
788 | 932 case ResourceType_Patient: |
311 | 933 // The "PatientID" field is of type LO (Long String), 64 |
934 // Bytes Maximum. An UUID is of length 36, thus it can be used | |
935 // as a random PatientID. | |
936 return Toolbox::GenerateUuid(); | |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
937 |
788 | 938 case ResourceType_Instance: |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
939 return dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT); |
176 | 940 |
788 | 941 case ResourceType_Series: |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
942 return dcmGenerateUniqueIdentifier(uid, SITE_SERIES_UID_ROOT); |
176 | 943 |
788 | 944 case ResourceType_Study: |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
945 return dcmGenerateUniqueIdentifier(uid, SITE_STUDY_UID_ROOT); |
176 | 946 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
947 default: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
948 throw OrthancException(ErrorCode_ParameterOutOfRange); |
176 | 949 } |
950 } | |
951 | |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
952 bool FromDcmtkBridge::SaveToMemoryBuffer(std::string& buffer, |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
953 DcmDataset* dataSet) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
954 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
955 // Determine the transfer syntax which shall be used to write the |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
956 // information to the file. We always switch to the Little Endian |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
957 // syntax, with explicit length. |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
958 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
959 // http://support.dcmtk.org/docs/dcxfer_8h-source.html |
661
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
960 |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
961 |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
962 /** |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
963 * Note that up to Orthanc 0.7.1 (inclusive), the |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
964 * "EXS_LittleEndianExplicit" was always used to save the DICOM |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
965 * dataset into memory. We now keep the original transfer syntax |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
966 * (if available). |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
967 **/ |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
968 E_TransferSyntax xfer = dataSet->getOriginalXfer(); |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
969 if (xfer == EXS_Unknown) |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
970 { |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
971 // No information about the original transfer syntax: This is |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
972 // most probably a DICOM dataset that was read from memory. |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
973 xfer = EXS_LittleEndianExplicit; |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
974 } |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
975 |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
976 E_EncodingType encodingType = /*opt_sequenceType*/ EET_ExplicitLength; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
977 |
661
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
978 // Create the meta-header information |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
979 DcmFileFormat ff(dataSet); |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
980 ff.validateMetaInfo(xfer); |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
981 |
661
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
982 // Create a memory buffer with the proper size |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
983 uint32_t s = ff.calcElementLength(xfer, encodingType); |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
984 buffer.resize(s); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
985 DcmOutputBufferStream ob(&buffer[0], s); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
986 |
661
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
987 // Fill the memory buffer with the meta-header and the dataset |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
988 ff.transferInit(); |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
989 OFCondition c = ff.write(ob, xfer, encodingType, NULL, |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
990 /*opt_groupLength*/ EGL_recalcGL, |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
991 /*opt_paddingType*/ EPD_withoutPadding); |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
992 ff.transferEnd(); |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
993 |
661
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
994 // Handle errors |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
995 if (c.good()) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
996 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
997 return true; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
998 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
999 else |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1000 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1001 buffer.clear(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1002 return false; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1003 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
1004 } |
0 | 1005 } |