annotate OrthancServer/FromDcmtkBridge.cpp @ 977:2a9e08136860 plugins

cont
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 30 Jun 2014 16:09:41 +0200
parents 63973b76a51f
children 2f76b92addd4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
689
2d0a347e8cfc switch to 2014
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 682
diff changeset
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
136
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
10 *
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
11 * In addition, as a special exception, the copyright holders of this
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
12 * program give permission to link the code of its release with the
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
15 * the linked executables. You must obey the GNU General Public License
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
19 * you do not wish to do so, delete this exception statement from your
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
20 * version. If you delete this exception statement from all source files
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
21 * in the program, then also delete it here.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
34 #include "PrecompiledHeadersServer.h"
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
35
71
aa65ced5f0f0 fix for visual studio
jodogne
parents: 62
diff changeset
36 #ifndef NOMINMAX
aa65ced5f0f0 fix for visual studio
jodogne
parents: 62
diff changeset
37 #define NOMINMAX
aa65ced5f0f0 fix for visual studio
jodogne
parents: 62
diff changeset
38 #endif
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
40 #include "Internals/DicomImageDecoder.h"
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
41
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #include "FromDcmtkBridge.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 #include "ToDcmtkBridge.h"
107
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 106
diff changeset
44 #include "../Core/Toolbox.h"
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
45 #include "../Core/OrthancException.h"
799
777b6b694da6 rename folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
46 #include "../Core/ImageFormats/PngWriter.h"
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
47 #include "../Core/Uuid.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 #include "../Core/DicomFormat/DicomString.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 #include "../Core/DicomFormat/DicomNullValue.h"
79
297bad4e1019 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
50 #include "../Core/DicomFormat/DicomIntegerPixelAccessor.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
52 #include <list>
71
aa65ced5f0f0 fix for visual studio
jodogne
parents: 62
diff changeset
53 #include <limits>
aa65ced5f0f0 fix for visual studio
jodogne
parents: 62
diff changeset
54
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 #include <boost/lexical_cast.hpp>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
57 #include <dcmtk/dcmdata/dcchrstr.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 #include <dcmtk/dcmdata/dcdicent.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 #include <dcmtk/dcmdata/dcdict.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 #include <dcmtk/dcmdata/dcfilefo.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 #include <dcmtk/dcmdata/dcistrmb.h>
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
62 #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
63 #include <dcmtk/dcmdata/dcmetinf.h>
957
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
64 #include <dcmtk/dcmdata/dcdeftag.h>
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
65
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
66 #include <dcmtk/dcmdata/dcvrae.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
67 #include <dcmtk/dcmdata/dcvras.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
68 #include <dcmtk/dcmdata/dcvrcs.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
69 #include <dcmtk/dcmdata/dcvrda.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
70 #include <dcmtk/dcmdata/dcvrds.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
71 #include <dcmtk/dcmdata/dcvrdt.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 #include <dcmtk/dcmdata/dcvrfd.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 #include <dcmtk/dcmdata/dcvrfl.h>
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
74 #include <dcmtk/dcmdata/dcvris.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
75 #include <dcmtk/dcmdata/dcvrlo.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
76 #include <dcmtk/dcmdata/dcvrlt.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
77 #include <dcmtk/dcmdata/dcvrpn.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
78 #include <dcmtk/dcmdata/dcvrsh.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 #include <dcmtk/dcmdata/dcvrsl.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 #include <dcmtk/dcmdata/dcvrss.h>
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
81 #include <dcmtk/dcmdata/dcvrst.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
82 #include <dcmtk/dcmdata/dcvrtm.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
83 #include <dcmtk/dcmdata/dcvrui.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 #include <dcmtk/dcmdata/dcvrul.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 #include <dcmtk/dcmdata/dcvrus.h>
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
86 #include <dcmtk/dcmdata/dcvrut.h>
676
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
87 #include <dcmtk/dcmdata/dcpixel.h>
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
88 #include <dcmtk/dcmdata/dcpixseq.h>
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
89 #include <dcmtk/dcmdata/dcpxitem.h>
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
90
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
92 #include <boost/math/special_functions/round.hpp>
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
93 #include <glog/logging.h>
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
94 #include <dcmtk/dcmdata/dcostrmb.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
682
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
96
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
97 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
99 static inline uint16_t GetCharValue(char c)
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
100 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
101 if (c >= '0' && c <= '9')
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
102 return c - '0';
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
103 else if (c >= 'a' && c <= 'f')
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
104 return c - 'a' + 10;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
105 else if (c >= 'A' && c <= 'F')
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
106 return c - 'A' + 10;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
107 else
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
108 return 0;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
109 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
110
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
111 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
112 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
113 return ((GetCharValue(c[0]) << 12) +
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
114 (GetCharValue(c[1]) << 8) +
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
115 (GetCharValue(c[2]) << 4) +
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
116 GetCharValue(c[3]));
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
117 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
118
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
119
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
120 Encoding FromDcmtkBridge::DetectEncoding(DcmDataset& dataset)
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
121 {
957
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
122 // By default, assume UTF-8 encoding (as in dcm2xml.cc)
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
123 Encoding encoding = Encoding_Utf8;
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
124
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
125 OFString tmp;
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
126 if (dataset.findAndGetOFString(DCM_SpecificCharacterSet, tmp).good())
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
127 {
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
128 std::string characterSet = Toolbox::StripSpaces(std::string(tmp.c_str()));
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
129
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
130 // TODO Add more encodings
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
131
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
132 if (characterSet == "ISO_IR 6" ||
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
133 characterSet == "ISO_IR 192")
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
134 {
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
135 encoding = Encoding_Utf8;
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
136 }
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
137 else if (characterSet == "ISO_IR 100")
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
138 {
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
139 encoding = Encoding_Latin1;
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
140 }
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
141 else if (!characterSet.empty())
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
142 {
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
143 LOG(WARNING) << "Value of Specific Character Set (0008,0005) is not supported: " << characterSet;
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
144 // Fallback to ASCII (remove all special characters)
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
145 encoding = Encoding_Ascii;
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
146 }
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
147 }
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
148
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
149 return encoding;
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
150 }
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
151
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
152
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 void FromDcmtkBridge::Convert(DicomMap& target, DcmDataset& dataset)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 {
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
155 Encoding encoding = DetectEncoding(dataset);
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
156
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 target.Clear();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 for (unsigned long i = 0; i < dataset.card(); i++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 DcmElement* element = dataset.getElement(i);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 if (element && element->isLeaf())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 target.SetValue(element->getTag().getGTag(),
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 element->getTag().getETag(),
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
165 ConvertLeafElement(*element, encoding));
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 DicomTag FromDcmtkBridge::GetTag(const DcmElement& element)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 return DicomTag(element.getGTag(), element.getETag());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
177 DicomValue* FromDcmtkBridge::ConvertLeafElement(DcmElement& element,
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
178 Encoding encoding)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 if (!element.isLeaf())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
182 throw OrthancException("Only applicable to leaf elements");
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 if (element.isaString())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 char *c;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 if (element.getString(c).good() &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 c != NULL)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 std::string s(c);
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
192 std::string utf8 = Toolbox::ConvertToUtf8(s, encoding);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 return new DicomString(utf8);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 return new DicomNullValue;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 try
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 // http://support.dcmtk.org/docs/dcvr_8h-source.html
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 switch (element.getVR())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 /**
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 * TODO.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 catch (boost::bad_lexical_cast)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 return new DicomNullValue;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 static void StoreElement(Json::Value& target,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 DcmElement& element,
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
354 unsigned int maxStringLength,
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
355 Encoding encoding);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 static void StoreItem(Json::Value& target,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 DcmItem& item,
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
359 unsigned int maxStringLength,
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
360 Encoding encoding)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 target = Json::Value(Json::objectValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 for (unsigned long i = 0; i < item.card(); i++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 DcmElement* element = item.getElement(i);
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
367 StoreElement(target, *element, maxStringLength, encoding);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 static void StoreElement(Json::Value& target,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 DcmElement& element,
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
374 unsigned int maxStringLength,
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
375 Encoding encoding)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 assert(target.type() == Json::objectValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
379 DicomTag tag(FromDcmtkBridge::GetTag(element));
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
380 const std::string formattedTag = tag.Format();
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
381
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
382 #if 0
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
383 const std::string tagName = FromDcmtkBridge::GetName(tag);
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
384 #else
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
385 // 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
386 DcmTag tagbis(element.getTag());
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
387 const std::string tagName(tagbis.getTagName());
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
388 #endif
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 if (element.isLeaf())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 {
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
392 Json::Value value(Json::objectValue);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
393 value["Name"] = tagName;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
394
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
395 if (tagbis.getPrivateCreator() != NULL)
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
396 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
397 value["PrivateCreator"] = tagbis.getPrivateCreator();
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
398 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
399
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
400 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(element, encoding));
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 if (v->IsNull())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 {
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
403 value["Type"] = "Null";
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
404 value["Value"] = Json::nullValue;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 std::string s = v->AsString();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 if (maxStringLength == 0 ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 s.size() <= maxStringLength)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 {
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
412 value["Type"] = "String";
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
413 value["Value"] = s;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 {
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
417 value["Type"] = "TooLong";
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
418 value["Value"] = Json::nullValue;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 }
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
421
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
422 target[formattedTag] = value;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 {
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
426 Json::Value children(Json::arrayValue);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 // "All subclasses of DcmElement except for DcmSequenceOfItems
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 // are leaf nodes, while DcmSequenceOfItems, DcmItem, DcmDataset
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 // etc. are not." The following cast is thus OK.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 DcmSequenceOfItems& sequence = dynamic_cast<DcmSequenceOfItems&>(element);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 for (unsigned long i = 0; i < sequence.card(); i++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 DcmItem* child = sequence.getItem(i);
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
436 Json::Value& v = children.append(Json::objectValue);
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
437 StoreItem(v, *child, maxStringLength, encoding);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 }
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
439
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
440 target[formattedTag]["Name"] = tagName;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
441 target[formattedTag]["Type"] = "Sequence";
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
442 target[formattedTag]["Value"] = children;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 void FromDcmtkBridge::ToJson(Json::Value& root,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 DcmDataset& dataset,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 unsigned int maxStringLength)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 {
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
451 StoreItem(root, dataset, maxStringLength, DetectEncoding(dataset));
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 void FromDcmtkBridge::ToJson(Json::Value& target,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 const std::string& path,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 unsigned int maxStringLength)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 DcmFileFormat dicom;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 if (!dicom.loadFile(path.c_str()).good())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
463 throw OrthancException(ErrorCode_BadFileFormat);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 FromDcmtkBridge::ToJson(target, *dicom.getDataset(), maxStringLength);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 std::string FromDcmtkBridge::GetName(const DicomTag& t)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 {
106
332fec038d52 patch for dcmtk dictionaries
jodogne
parents: 80
diff changeset
475 // Some patches for important tags because of different DICOM
332fec038d52 patch for dcmtk dictionaries
jodogne
parents: 80
diff changeset
476 // dictionaries between DCMTK versions
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
477 std::string n = t.GetMainTagsName();
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
478 if (n.size() != 0)
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
479 {
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
480 return n;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
481 }
106
332fec038d52 patch for dcmtk dictionaries
jodogne
parents: 80
diff changeset
482 // End of patches
332fec038d52 patch for dcmtk dictionaries
jodogne
parents: 80
diff changeset
483
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
484 #if 0
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 DcmTagKey tag(t.GetGroup(), t.GetElement());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 const DcmDataDictionary& dict = dcmDataDict.rdlock();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 const DcmDictEntry* entry = dict.findEntry(tag, NULL);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
489 std::string s(DcmTag_ERROR_TagName);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 if (entry != NULL)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 s = std::string(entry->getTagName());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 dcmDataDict.unlock();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 return s;
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
497 #else
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
498 DcmTag tag(t.GetGroup(), t.GetElement());
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
499 const char* name = tag.getTagName();
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
500 if (name == NULL)
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
501 {
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
502 return DcmTag_ERROR_TagName;
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
503 }
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
504 else
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
505 {
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
506 return std::string(name);
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
507 }
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
508 #endif
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
512 DicomTag FromDcmtkBridge::ParseTag(const char* name)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 {
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
514 if (strlen(name) == 9 &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
515 isxdigit(name[0]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
516 isxdigit(name[1]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
517 isxdigit(name[2]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
518 isxdigit(name[3]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
519 name[4] == '-' &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
520 isxdigit(name[5]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
521 isxdigit(name[6]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
522 isxdigit(name[7]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
523 isxdigit(name[8]))
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
524 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
525 uint16_t group = GetTagValue(name);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
526 uint16_t element = GetTagValue(name + 5);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
527 return DicomTag(group, element);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
528 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
529
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
530 #if 0
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 const DcmDataDictionary& dict = dcmDataDict.rdlock();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532 const DcmDictEntry* entry = dict.findEntry(name);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 if (entry == NULL)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 dcmDataDict.unlock();
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
537 throw OrthancException("Unknown DICOM tag");
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 DcmTagKey key = entry->getKey();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 DicomTag tag(key.getGroup(), key.getElement());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 dcmDataDict.unlock();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 return tag;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 }
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
546 #else
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
547 DcmTag tag;
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
548 if (DcmTag::findTagFromName(name, tag).good())
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
549 {
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
550 return DicomTag(tag.getGTag(), tag.getETag());
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
551 }
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
552 else
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
553 {
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
554 throw OrthancException("Unknown DICOM tag");
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
555 }
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
556 #endif
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 void FromDcmtkBridge::Print(FILE* fp, const DicomMap& m)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 for (DicomMap::Map::const_iterator
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 465
diff changeset
563 it = m.map_.begin(); it != m.map_.end(); ++it)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 DicomTag t = it->first;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 std::string s = it->second->AsString();
319
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
567 fprintf(fp, "0x%04x 0x%04x (%s) [%s]\n", t.GetGroup(), t.GetElement(), GetName(t).c_str(), s.c_str());
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 void FromDcmtkBridge::ToJson(Json::Value& result,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 const DicomMap& values)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 if (result.type() != Json::objectValue)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
577 throw OrthancException(ErrorCode_BadParameterType);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 result.clear();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 for (DicomMap::Map::const_iterator
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 465
diff changeset
583 it = values.map_.begin(); it != values.map_.end(); ++it)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 result[GetName(it->first)] = it->second->AsString();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587 }
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
588
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
589
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
590 std::string FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType level)
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
591 {
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
592 char uid[100];
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
593
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
594 switch (level)
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
595 {
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
596 case ResourceType_Patient:
311
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
597 // The "PatientID" field is of type LO (Long String), 64
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
598 // Bytes Maximum. An UUID is of length 36, thus it can be used
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
599 // as a random PatientID.
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
600 return Toolbox::GenerateUuid();
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
601
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
602 case ResourceType_Instance:
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
603 return dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT);
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
604
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
605 case ResourceType_Series:
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
606 return dcmGenerateUniqueIdentifier(uid, SITE_SERIES_UID_ROOT);
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
607
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
608 case ResourceType_Study:
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
609 return dcmGenerateUniqueIdentifier(uid, SITE_STUDY_UID_ROOT);
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
610
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
611 default:
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
612 throw OrthancException(ErrorCode_ParameterOutOfRange);
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
613 }
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
614 }
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
615
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
616 bool FromDcmtkBridge::SaveToMemoryBuffer(std::string& buffer,
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
617 DcmDataset* dataSet)
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
618 {
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
619 // 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
620 // 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
621 // syntax, with explicit length.
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
622
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
623 // 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
624
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
625
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
626 /**
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
627 * 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
628 * "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
629 * 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
630 * (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
631 **/
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
632 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
633 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
634 {
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
635 // 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
636 // 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
637 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
638 }
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
639
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
640 E_EncodingType encodingType = /*opt_sequenceType*/ EET_ExplicitLength;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
641
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
642 // 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
643 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
644 ff.validateMetaInfo(xfer);
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
645
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
646 // 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
647 uint32_t s = ff.calcElementLength(xfer, encodingType);
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
648 buffer.resize(s);
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
649 DcmOutputBufferStream ob(&buffer[0], s);
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
650
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
651 // 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
652 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
653 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
654 /*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
655 /*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
656 ff.transferEnd();
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
657
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
658 // Handle errors
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
659 if (c.good())
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
660 {
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
661 return true;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
662 }
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
663 else
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
664 {
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
665 buffer.clear();
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
666 return false;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
667 }
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
668 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669 }