Mercurial > hg > orthanc
comparison OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h @ 4044:d25f4c0fa160 framework
splitting code into OrthancFramework and OrthancServer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 10 Jun 2020 20:30:34 +0200 |
parents | Core/DicomParsing/FromDcmtkBridge.h@f9863630ec7f |
children | c02a2d9efbc2 |
comparison
equal
deleted
inserted
replaced
4043:6c6239aec462 | 4044:d25f4c0fa160 |
---|---|
1 /** | |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #pragma once | |
35 | |
36 #include "ITagVisitor.h" | |
37 #include "../DicomFormat/DicomElement.h" | |
38 #include "../DicomFormat/DicomMap.h" | |
39 | |
40 #include <dcmtk/dcmdata/dcdatset.h> | |
41 #include <dcmtk/dcmdata/dcmetinf.h> | |
42 #include <dcmtk/dcmdata/dcpixseq.h> | |
43 #include <dcmtk/dcmdata/dcfilefo.h> | |
44 #include <json/json.h> | |
45 | |
46 #if !defined(ORTHANC_ENABLE_LUA) | |
47 # error The macro ORTHANC_ENABLE_LUA must be defined | |
48 #endif | |
49 | |
50 #if ORTHANC_ENABLE_DCMTK != 1 | |
51 # error The macro ORTHANC_ENABLE_DCMTK must be set to 1 | |
52 #endif | |
53 | |
54 #if ORTHANC_BUILD_UNIT_TESTS == 1 | |
55 # include <gtest/gtest_prod.h> | |
56 #endif | |
57 | |
58 #if ORTHANC_ENABLE_LUA == 1 | |
59 # include "../Lua/LuaFunctionCall.h" | |
60 #endif | |
61 | |
62 #if !defined(ORTHANC_ENABLE_DCMTK_JPEG) | |
63 # error The macro ORTHANC_ENABLE_DCMTK_JPEG must be defined | |
64 #endif | |
65 | |
66 #if !defined(ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS) | |
67 # error The macro ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS must be defined | |
68 #endif | |
69 | |
70 | |
71 namespace Orthanc | |
72 { | |
73 class ORTHANC_PUBLIC FromDcmtkBridge : public boost::noncopyable | |
74 { | |
75 #if ORTHANC_BUILD_UNIT_TESTS == 1 | |
76 FRIEND_TEST(FromDcmtkBridge, FromJson); | |
77 #endif | |
78 | |
79 friend class ParsedDicomFile; | |
80 | |
81 private: | |
82 FromDcmtkBridge(); // Pure static class | |
83 | |
84 static void ExtractDicomSummary(DicomMap& target, | |
85 DcmItem& dataset, | |
86 unsigned int maxStringLength, | |
87 Encoding defaultEncoding, | |
88 const std::set<DicomTag>& ignoreTagLength); | |
89 | |
90 static void DatasetToJson(Json::Value& parent, | |
91 DcmItem& item, | |
92 DicomToJsonFormat format, | |
93 DicomToJsonFlags flags, | |
94 unsigned int maxStringLength, | |
95 Encoding encoding, | |
96 bool hasCodeExtensions, | |
97 const std::set<DicomTag>& ignoreTagLength); | |
98 | |
99 static void ElementToJson(Json::Value& parent, | |
100 DcmElement& element, | |
101 DicomToJsonFormat format, | |
102 DicomToJsonFlags flags, | |
103 unsigned int maxStringLength, | |
104 Encoding dicomEncoding, | |
105 bool hasCodeExtensions, | |
106 const std::set<DicomTag>& ignoreTagLength); | |
107 | |
108 static void ExtractDicomAsJson(Json::Value& target, | |
109 DcmDataset& dataset, | |
110 DicomToJsonFormat format, | |
111 DicomToJsonFlags flags, | |
112 unsigned int maxStringLength, | |
113 Encoding defaultEncoding, | |
114 const std::set<DicomTag>& ignoreTagLength); | |
115 | |
116 static void ChangeStringEncoding(DcmItem& dataset, | |
117 Encoding source, | |
118 bool hasSourceCodeExtensions, | |
119 Encoding target); | |
120 | |
121 public: | |
122 static void InitializeDictionary(bool loadPrivateDictionary); | |
123 | |
124 static void RegisterDictionaryTag(const DicomTag& tag, | |
125 ValueRepresentation vr, | |
126 const std::string& name, | |
127 unsigned int minMultiplicity, | |
128 unsigned int maxMultiplicity, | |
129 const std::string& privateCreator); | |
130 | |
131 static Encoding DetectEncoding(bool& hasCodeExtensions, | |
132 DcmItem& dataset, | |
133 Encoding defaultEncoding); | |
134 | |
135 static Encoding DetectEncoding(DcmItem& dataset, | |
136 Encoding defaultEncoding) | |
137 { | |
138 // Compatibility wrapper for Orthanc <= 1.5.4 | |
139 bool hasCodeExtensions; // ignored | |
140 return DetectEncoding(hasCodeExtensions, dataset, defaultEncoding); | |
141 } | |
142 | |
143 static DicomTag Convert(const DcmTag& tag); | |
144 | |
145 static DicomTag GetTag(const DcmElement& element); | |
146 | |
147 static bool IsUnknownTag(const DicomTag& tag); | |
148 | |
149 static DicomValue* ConvertLeafElement(DcmElement& element, | |
150 DicomToJsonFlags flags, | |
151 unsigned int maxStringLength, | |
152 Encoding encoding, | |
153 bool hasCodeExtensions, | |
154 const std::set<DicomTag>& ignoreTagLength); | |
155 | |
156 static void ExtractHeaderAsJson(Json::Value& target, | |
157 DcmMetaInfo& header, | |
158 DicomToJsonFormat format, | |
159 DicomToJsonFlags flags, | |
160 unsigned int maxStringLength); | |
161 | |
162 static std::string GetTagName(const DicomTag& tag, | |
163 const std::string& privateCreator); | |
164 | |
165 static std::string GetTagName(const DcmElement& element); | |
166 | |
167 static std::string GetTagName(const DicomElement& element) | |
168 { | |
169 return GetTagName(element.GetTag(), ""); | |
170 } | |
171 | |
172 static DicomTag ParseTag(const char* name); | |
173 | |
174 static DicomTag ParseTag(const std::string& name) | |
175 { | |
176 return ParseTag(name.c_str()); | |
177 } | |
178 | |
179 static bool HasTag(const DicomMap& fields, | |
180 const std::string& tagName) | |
181 { | |
182 return fields.HasTag(ParseTag(tagName)); | |
183 } | |
184 | |
185 static const DicomValue& GetValue(const DicomMap& fields, | |
186 const std::string& tagName) | |
187 { | |
188 return fields.GetValue(ParseTag(tagName)); | |
189 } | |
190 | |
191 static void SetValue(DicomMap& target, | |
192 const std::string& tagName, | |
193 DicomValue* value) | |
194 { | |
195 const DicomTag tag = ParseTag(tagName); | |
196 target.SetValueInternal(tag.GetGroup(), tag.GetElement(), value); | |
197 } | |
198 | |
199 static void ToJson(Json::Value& result, | |
200 const DicomMap& values, | |
201 bool simplify); | |
202 | |
203 static std::string GenerateUniqueIdentifier(ResourceType level); | |
204 | |
205 static bool SaveToMemoryBuffer(std::string& buffer, | |
206 DcmDataset& dataSet); | |
207 | |
208 static bool Transcode(DcmFileFormat& dicom, | |
209 DicomTransferSyntax syntax, | |
210 const DcmRepresentationParameter* representation); | |
211 | |
212 static ValueRepresentation Convert(DcmEVR vr); | |
213 | |
214 static ValueRepresentation LookupValueRepresentation(const DicomTag& tag); | |
215 | |
216 static DcmElement* CreateElementForTag(const DicomTag& tag, | |
217 const std::string& privateCreator); | |
218 | |
219 static void FillElementWithString(DcmElement& element, | |
220 const std::string& utf8alue, // Encoded using UTF-8 | |
221 bool decodeDataUriScheme, | |
222 Encoding dicomEncoding); | |
223 | |
224 static DcmElement* FromJson(const DicomTag& tag, | |
225 const Json::Value& element, // Encoded using UTF-8 | |
226 bool decodeDataUriScheme, | |
227 Encoding dicomEncoding, | |
228 const std::string& privateCreator); | |
229 | |
230 static DcmPixelSequence* GetPixelSequence(DcmDataset& dataset); | |
231 | |
232 static Encoding ExtractEncoding(const Json::Value& json, | |
233 Encoding defaultEncoding); | |
234 | |
235 static DcmDataset* FromJson(const Json::Value& json, // Encoded using UTF-8 | |
236 bool generateIdentifiers, | |
237 bool decodeDataUriScheme, | |
238 Encoding defaultEncoding, | |
239 const std::string& privateCreator); | |
240 | |
241 static DcmFileFormat* LoadFromMemoryBuffer(const void* buffer, | |
242 size_t size); | |
243 | |
244 static void FromJson(DicomMap& values, | |
245 const Json::Value& result); | |
246 | |
247 #if ORTHANC_ENABLE_LUA == 1 | |
248 static void ExecuteToDicom(DicomMap& target, | |
249 LuaFunctionCall& call); | |
250 #endif | |
251 | |
252 static void ExtractDicomSummary(DicomMap& target, | |
253 DcmItem& dataset, | |
254 const std::set<DicomTag>& ignoreTagLength); | |
255 | |
256 static void ExtractDicomSummary(DicomMap& target, | |
257 DcmItem& dataset) | |
258 { | |
259 std::set<DicomTag> none; | |
260 ExtractDicomSummary(target, dataset, none); | |
261 } | |
262 | |
263 static void ExtractDicomAsJson(Json::Value& target, | |
264 DcmDataset& dataset, | |
265 const std::set<DicomTag>& ignoreTagLength); | |
266 | |
267 static void InitializeCodecs(); | |
268 | |
269 static void FinalizeCodecs(); | |
270 | |
271 static void Apply(DcmItem& dataset, | |
272 ITagVisitor& visitor, | |
273 Encoding defaultEncoding); | |
274 | |
275 static bool LookupDcmtkTransferSyntax(E_TransferSyntax& target, | |
276 DicomTransferSyntax source); | |
277 | |
278 static bool LookupOrthancTransferSyntax(DicomTransferSyntax& target, | |
279 E_TransferSyntax source); | |
280 | |
281 static bool LookupOrthancTransferSyntax(DicomTransferSyntax& target, | |
282 DcmFileFormat& dicom); | |
283 }; | |
284 } |