Mercurial > hg > orthanc
comparison OrthancFramework/Sources/DicomParsing/ParsedDicomFile.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/ParsedDicomFile.h@cc6ed76bba27 |
children | e00f3d089991 |
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 "../OrthancFramework.h" | |
37 | |
38 #if !defined(ORTHANC_ENABLE_JPEG) | |
39 # error Macro ORTHANC_ENABLE_JPEG must be defined to use this file | |
40 #endif | |
41 | |
42 #if !defined(ORTHANC_ENABLE_PNG) | |
43 # error Macro ORTHANC_ENABLE_PNG must be defined to use this file | |
44 #endif | |
45 | |
46 #if !defined(ORTHANC_ENABLE_CIVETWEB) | |
47 # error Macro ORTHANC_ENABLE_CIVETWEB must be defined to use this file | |
48 #endif | |
49 | |
50 #if !defined(ORTHANC_ENABLE_MONGOOSE) | |
51 # error Macro ORTHANC_ENABLE_MONGOOSE must be defined to use this file | |
52 #endif | |
53 | |
54 #if !defined(ORTHANC_SANDBOXED) | |
55 # error The macro ORTHANC_SANDBOXED must be defined | |
56 #endif | |
57 | |
58 #if !defined(ORTHANC_ENABLE_DCMTK) | |
59 # error The macro ORTHANC_ENABLE_DCMTK must be defined | |
60 #endif | |
61 | |
62 #if ORTHANC_ENABLE_DCMTK != 1 | |
63 # error The macro ORTHANC_ENABLE_DCMTK must be set to 1 to use this file | |
64 #endif | |
65 | |
66 #include "ITagVisitor.h" | |
67 #include "../DicomFormat/DicomInstanceHasher.h" | |
68 #include "../Images/ImageAccessor.h" | |
69 #include "../IDynamicObject.h" | |
70 #include "../Toolbox.h" | |
71 | |
72 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 | |
73 # include "../RestApi/RestApiOutput.h" | |
74 #endif | |
75 | |
76 #include <boost/shared_ptr.hpp> | |
77 | |
78 | |
79 class DcmDataset; | |
80 class DcmFileFormat; | |
81 | |
82 namespace Orthanc | |
83 { | |
84 class ORTHANC_PUBLIC ParsedDicomFile : public IDynamicObject | |
85 { | |
86 private: | |
87 struct PImpl; | |
88 boost::shared_ptr<PImpl> pimpl_; | |
89 | |
90 ParsedDicomFile(ParsedDicomFile& other, | |
91 bool keepSopInstanceUid); | |
92 | |
93 void CreateFromDicomMap(const DicomMap& source, | |
94 Encoding defaultEncoding, | |
95 bool permissive, | |
96 const std::string& defaultPrivateCreator, | |
97 const std::map<uint16_t, std::string>& privateCreators); | |
98 | |
99 void RemovePrivateTagsInternal(const std::set<DicomTag>* toKeep); | |
100 | |
101 void UpdateStorageUid(const DicomTag& tag, | |
102 const std::string& value, | |
103 bool decodeDataUriScheme); | |
104 | |
105 void InvalidateCache(); | |
106 | |
107 bool EmbedContentInternal(const std::string& dataUriScheme); | |
108 | |
109 ParsedDicomFile(DcmFileFormat* dicom); // This takes ownership (no clone) | |
110 | |
111 public: | |
112 ParsedDicomFile(bool createIdentifiers); // Create a minimal DICOM instance | |
113 | |
114 ParsedDicomFile(const DicomMap& map, | |
115 Encoding defaultEncoding, | |
116 bool permissive | |
117 ); | |
118 | |
119 ParsedDicomFile(const DicomMap& map, | |
120 Encoding defaultEncoding, | |
121 bool permissive, | |
122 const std::string& defaultPrivateCreator, | |
123 const std::map<uint16_t, std::string>& privateCreators | |
124 ); | |
125 | |
126 ParsedDicomFile(const void* content, | |
127 size_t size); | |
128 | |
129 ParsedDicomFile(const std::string& content); | |
130 | |
131 ParsedDicomFile(DcmDataset& dicom); // This clones the DCMTK object | |
132 | |
133 ParsedDicomFile(DcmFileFormat& dicom); // This clones the DCMTK object | |
134 | |
135 static ParsedDicomFile* AcquireDcmtkObject(DcmFileFormat* dicom) // No clone here | |
136 { | |
137 return new ParsedDicomFile(dicom); | |
138 } | |
139 | |
140 DcmFileFormat& GetDcmtkObject() const; | |
141 | |
142 // The "ParsedDicomFile" object cannot be used after calling this method | |
143 DcmFileFormat* ReleaseDcmtkObject(); | |
144 | |
145 ParsedDicomFile* Clone(bool keepSopInstanceUid); | |
146 | |
147 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 | |
148 void SendPathValue(RestApiOutput& output, | |
149 const UriComponents& uri); | |
150 | |
151 void Answer(RestApiOutput& output); | |
152 #endif | |
153 | |
154 void Remove(const DicomTag& tag); | |
155 | |
156 // Replace the DICOM tag as a NULL/empty value (e.g. for anonymization) | |
157 void Clear(const DicomTag& tag, | |
158 bool onlyIfExists); | |
159 | |
160 void Replace(const DicomTag& tag, | |
161 const std::string& utf8Value, | |
162 bool decodeDataUriScheme, | |
163 DicomReplaceMode mode, | |
164 const std::string& privateCreator /* used only for private tags */); | |
165 | |
166 void Replace(const DicomTag& tag, | |
167 const Json::Value& value, // Assumed to be encoded with UTF-8 | |
168 bool decodeDataUriScheme, | |
169 DicomReplaceMode mode, | |
170 const std::string& privateCreator /* used only for private tags */); | |
171 | |
172 void Insert(const DicomTag& tag, | |
173 const Json::Value& value, // Assumed to be encoded with UTF-8 | |
174 bool decodeDataUriScheme, | |
175 const std::string& privateCreator /* used only for private tags */); | |
176 | |
177 // Cannot be applied to private tags | |
178 void ReplacePlainString(const DicomTag& tag, | |
179 const std::string& utf8Value); | |
180 | |
181 // Cannot be applied to private tags | |
182 void SetIfAbsent(const DicomTag& tag, | |
183 const std::string& utf8Value); | |
184 | |
185 void RemovePrivateTags() | |
186 { | |
187 RemovePrivateTagsInternal(NULL); | |
188 } | |
189 | |
190 void RemovePrivateTags(const std::set<DicomTag>& toKeep) | |
191 { | |
192 RemovePrivateTagsInternal(&toKeep); | |
193 } | |
194 | |
195 // WARNING: This function handles the decoding of strings to UTF8 | |
196 bool GetTagValue(std::string& value, | |
197 const DicomTag& tag); | |
198 | |
199 DicomInstanceHasher GetHasher(); | |
200 | |
201 void SaveToMemoryBuffer(std::string& buffer); | |
202 | |
203 #if ORTHANC_SANDBOXED == 0 | |
204 void SaveToFile(const std::string& path); | |
205 #endif | |
206 | |
207 void EmbedContent(const std::string& dataUriScheme); | |
208 | |
209 void EmbedImage(const ImageAccessor& accessor); | |
210 | |
211 void EmbedImage(MimeType mime, | |
212 const std::string& content); | |
213 | |
214 Encoding DetectEncoding(bool& hasCodeExtensions) const; | |
215 | |
216 // WARNING: This function only sets the encoding, it will not | |
217 // convert the encoding of the tags. Use "ChangeEncoding()" if need be. | |
218 void SetEncoding(Encoding encoding); | |
219 | |
220 void DatasetToJson(Json::Value& target, | |
221 DicomToJsonFormat format, | |
222 DicomToJsonFlags flags, | |
223 unsigned int maxStringLength); | |
224 | |
225 void DatasetToJson(Json::Value& target, | |
226 DicomToJsonFormat format, | |
227 DicomToJsonFlags flags, | |
228 unsigned int maxStringLength, | |
229 const std::set<DicomTag>& ignoreTagLength); | |
230 | |
231 // This version uses the default parameters for | |
232 // FileContentType_DicomAsJson | |
233 void DatasetToJson(Json::Value& target, | |
234 const std::set<DicomTag>& ignoreTagLength); | |
235 | |
236 void DatasetToJson(Json::Value& target); | |
237 | |
238 void HeaderToJson(Json::Value& target, | |
239 DicomToJsonFormat format); | |
240 | |
241 bool HasTag(const DicomTag& tag) const; | |
242 | |
243 void EmbedPdf(const std::string& pdf); | |
244 | |
245 bool ExtractPdf(std::string& pdf); | |
246 | |
247 void GetRawFrame(std::string& target, // OUT | |
248 MimeType& mime, // OUT | |
249 unsigned int frameId); // IN | |
250 | |
251 unsigned int GetFramesCount() const; | |
252 | |
253 static ParsedDicomFile* CreateFromJson(const Json::Value& value, | |
254 DicomFromJsonFlags flags, | |
255 const std::string& privateCreator); | |
256 | |
257 void ChangeEncoding(Encoding target); | |
258 | |
259 void ExtractDicomSummary(DicomMap& target) const; | |
260 | |
261 void ExtractDicomSummary(DicomMap& target, | |
262 const std::set<DicomTag>& ignoreTagLength) const; | |
263 | |
264 bool LookupTransferSyntax(std::string& result); | |
265 | |
266 bool LookupPhotometricInterpretation(PhotometricInterpretation& result) const; | |
267 | |
268 void Apply(ITagVisitor& visitor); | |
269 }; | |
270 } |