comparison Resources/Orthanc/Core/DicomFormat/DicomMap.h @ 200:03afbee0cc7b

integration of Orthanc core into Stone
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 23 Mar 2018 11:04:03 +0100
parents
children
comparison
equal deleted inserted replaced
199:dabe9982fca3 200:03afbee0cc7b
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-2018 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 "DicomTag.h"
37 #include "DicomValue.h"
38 #include "../Enumerations.h"
39
40 #include <set>
41 #include <map>
42 #include <json/json.h>
43
44 namespace Orthanc
45 {
46 class DicomMap : public boost::noncopyable
47 {
48 private:
49 friend class DicomArray;
50 friend class FromDcmtkBridge;
51 friend class ParsedDicomFile;
52
53 typedef std::map<DicomTag, DicomValue*> Map;
54
55 Map map_;
56
57 // Warning: This takes the ownership of "value"
58 void SetValue(uint16_t group,
59 uint16_t element,
60 DicomValue* value);
61
62 void SetValue(DicomTag tag,
63 DicomValue* value);
64
65 void ExtractTags(DicomMap& source,
66 const DicomTag* tags,
67 size_t count) const;
68
69 static void GetMainDicomTagsInternal(std::set<DicomTag>& result, ResourceType level);
70
71 public:
72 DicomMap()
73 {
74 }
75
76 ~DicomMap()
77 {
78 Clear();
79 }
80
81 size_t GetSize() const
82 {
83 return map_.size();
84 }
85
86 DicomMap* Clone() const;
87
88 void Assign(const DicomMap& other);
89
90 void Clear();
91
92 void SetValue(uint16_t group,
93 uint16_t element,
94 const DicomValue& value)
95 {
96 SetValue(group, element, value.Clone());
97 }
98
99 void SetValue(const DicomTag& tag,
100 const DicomValue& value)
101 {
102 SetValue(tag, value.Clone());
103 }
104
105 void SetValue(const DicomTag& tag,
106 const std::string& str,
107 bool isBinary)
108 {
109 SetValue(tag, new DicomValue(str, isBinary));
110 }
111
112 void SetValue(uint16_t group,
113 uint16_t element,
114 const std::string& str,
115 bool isBinary)
116 {
117 SetValue(group, element, new DicomValue(str, isBinary));
118 }
119
120 bool HasTag(uint16_t group, uint16_t element) const
121 {
122 return HasTag(DicomTag(group, element));
123 }
124
125 bool HasTag(const DicomTag& tag) const
126 {
127 return map_.find(tag) != map_.end();
128 }
129
130 const DicomValue& GetValue(uint16_t group, uint16_t element) const
131 {
132 return GetValue(DicomTag(group, element));
133 }
134
135 const DicomValue& GetValue(const DicomTag& tag) const;
136
137 // DO NOT delete the returned value!
138 const DicomValue* TestAndGetValue(uint16_t group, uint16_t element) const
139 {
140 return TestAndGetValue(DicomTag(group, element));
141 }
142
143 // DO NOT delete the returned value!
144 const DicomValue* TestAndGetValue(const DicomTag& tag) const;
145
146 void Remove(const DicomTag& tag);
147
148 void ExtractPatientInformation(DicomMap& result) const;
149
150 void ExtractStudyInformation(DicomMap& result) const;
151
152 void ExtractSeriesInformation(DicomMap& result) const;
153
154 void ExtractInstanceInformation(DicomMap& result) const;
155
156 static void SetupFindPatientTemplate(DicomMap& result);
157
158 static void SetupFindStudyTemplate(DicomMap& result);
159
160 static void SetupFindSeriesTemplate(DicomMap& result);
161
162 static void SetupFindInstanceTemplate(DicomMap& result);
163
164 void CopyTagIfExists(const DicomMap& source,
165 const DicomTag& tag);
166
167 static bool IsMainDicomTag(const DicomTag& tag, ResourceType level);
168
169 static bool IsMainDicomTag(const DicomTag& tag);
170
171 static void GetMainDicomTags(std::set<DicomTag>& result, ResourceType level);
172
173 static void GetMainDicomTags(std::set<DicomTag>& result);
174
175 void GetTags(std::set<DicomTag>& tags) const;
176
177 static void LoadMainDicomTags(const DicomTag*& tags,
178 size_t& size,
179 ResourceType level);
180
181 static bool ParseDicomMetaInformation(DicomMap& result,
182 const char* dicom,
183 size_t size);
184
185 void LogMissingTagsForStore() const;
186
187 bool CopyToString(std::string& result,
188 const DicomTag& tag,
189 bool allowBinary) const;
190
191 bool ParseInteger32(int32_t& result,
192 const DicomTag& tag) const;
193
194 bool ParseInteger64(int64_t& result,
195 const DicomTag& tag) const;
196
197 bool ParseUnsignedInteger32(uint32_t& result,
198 const DicomTag& tag) const;
199
200 bool ParseUnsignedInteger64(uint64_t& result,
201 const DicomTag& tag) const;
202
203 bool ParseFloat(float& result,
204 const DicomTag& tag) const;
205
206 bool ParseDouble(double& result,
207 const DicomTag& tag) const;
208 };
209 }