Mercurial > hg > orthanc
annotate Core/DicomFormat/DicomMap.cpp @ 562:f64e3838d6e1 find-move-scp
refactoring enumerations
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 18 Sep 2013 16:49:48 +0200 |
parents | aa50783f9550 |
children | c2be0a0e049e |
rev | line source |
---|---|
0 | 1 /** |
59 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
398 | 3 * Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege, |
0 | 4 * Belgium |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
136 | 10 * |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
0 | 22 * |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
33 #include "DicomMap.h" | |
34 | |
35 #include <stdio.h> | |
36 #include <memory> | |
37 #include "DicomString.h" | |
59 | 38 #include "../OrthancException.h" |
0 | 39 |
40 | |
59 | 41 namespace Orthanc |
0 | 42 { |
43 static DicomTag patientTags[] = | |
44 { | |
38 | 45 //DicomTag(0x0010, 0x1010), // PatientAge |
46 //DicomTag(0x0010, 0x1040) // PatientAddress | |
77 | 47 DicomTag(0x0010, 0x0010), // PatientName |
48 DicomTag(0x0010, 0x0030), // PatientBirthDate | |
49 DicomTag(0x0010, 0x0040), // PatientSex | |
50 DicomTag(0x0010, 0x1000), // OtherPatientIDs | |
80 | 51 DICOM_TAG_PATIENT_ID |
0 | 52 }; |
53 | |
54 static DicomTag studyTags[] = | |
55 { | |
38 | 56 //DicomTag(0x0010, 0x1020), // PatientSize |
57 //DicomTag(0x0010, 0x1030) // PatientWeight | |
77 | 58 DicomTag(0x0008, 0x0020), // StudyDate |
59 DicomTag(0x0008, 0x0030), // StudyTime | |
60 DicomTag(0x0008, 0x1030), // StudyDescription | |
61 DicomTag(0x0020, 0x0010), // StudyID | |
80 | 62 DICOM_TAG_ACCESSION_NUMBER, |
63 DICOM_TAG_STUDY_INSTANCE_UID | |
0 | 64 }; |
65 | |
66 static DicomTag seriesTags[] = | |
67 { | |
38 | 68 //DicomTag(0x0010, 0x1080), // MilitaryRank |
77 | 69 DicomTag(0x0008, 0x0021), // SeriesDate |
70 DicomTag(0x0008, 0x0031), // SeriesTime | |
71 DicomTag(0x0008, 0x0060), // Modality | |
72 DicomTag(0x0008, 0x0070), // Manufacturer | |
73 DicomTag(0x0008, 0x1010), // StationName | |
74 DicomTag(0x0008, 0x103e), // SeriesDescription | |
75 DicomTag(0x0018, 0x0015), // BodyPartExamined | |
76 DicomTag(0x0018, 0x0024), // SequenceName | |
77 DicomTag(0x0018, 0x1030), // ProtocolName | |
78 DicomTag(0x0020, 0x0011), // SeriesNumber | |
433 | 79 DICOM_TAG_CARDIAC_NUMBER_OF_IMAGES, |
80 | 80 DICOM_TAG_IMAGES_IN_ACQUISITION, |
433 | 81 DICOM_TAG_NUMBER_OF_TEMPORAL_POSITIONS, |
80 | 82 DICOM_TAG_NUMBER_OF_SLICES, |
433 | 83 DICOM_TAG_NUMBER_OF_TIME_SLICES, |
80 | 84 DICOM_TAG_SERIES_INSTANCE_UID |
0 | 85 }; |
86 | |
87 static DicomTag instanceTags[] = | |
88 { | |
77 | 89 DicomTag(0x0008, 0x0012), // InstanceCreationDate |
90 DicomTag(0x0008, 0x0013), // InstanceCreationTime | |
91 DicomTag(0x0020, 0x0012), // AcquisitionNumber | |
80 | 92 DICOM_TAG_IMAGE_INDEX, |
93 DICOM_TAG_INSTANCE_NUMBER, | |
84 | 94 DICOM_TAG_NUMBER_OF_FRAMES, |
433 | 95 DICOM_TAG_TEMPORAL_POSITION_IDENTIFIER, |
80 | 96 DICOM_TAG_SOP_INSTANCE_UID |
0 | 97 }; |
98 | |
99 | |
100 | |
101 | |
102 void DicomMap::SetValue(uint16_t group, | |
103 uint16_t element, | |
104 DicomValue* value) | |
105 { | |
106 DicomTag tag(group, element); | |
107 Map::iterator it = map_.find(tag); | |
108 | |
109 if (it != map_.end()) | |
110 { | |
111 delete it->second; | |
112 it->second = value; | |
113 } | |
114 else | |
115 { | |
116 map_.insert(std::make_pair(tag, value)); | |
117 } | |
118 } | |
119 | |
120 void DicomMap::SetValue(DicomTag tag, | |
121 DicomValue* value) | |
122 { | |
123 SetValue(tag.GetGroup(), tag.GetElement(), value); | |
124 } | |
125 | |
126 | |
127 | |
128 | |
129 void DicomMap::Clear() | |
130 { | |
131 for (Map::iterator it = map_.begin(); it != map_.end(); it++) | |
132 { | |
133 delete it->second; | |
134 } | |
135 | |
136 map_.clear(); | |
137 } | |
138 | |
139 | |
140 void DicomMap::ExtractTags(DicomMap& result, | |
141 const DicomTag* tags, | |
142 size_t count) const | |
143 { | |
144 result.Clear(); | |
145 | |
146 for (unsigned int i = 0; i < count; i++) | |
147 { | |
148 Map::const_iterator it = map_.find(tags[i]); | |
149 if (it != map_.end()) | |
150 { | |
151 result.SetValue(it->first, it->second->Clone()); | |
152 } | |
153 } | |
154 } | |
155 | |
156 | |
157 void DicomMap::ExtractPatientInformation(DicomMap& result) const | |
158 { | |
159 ExtractTags(result, patientTags, sizeof(patientTags) / sizeof(DicomTag)); | |
160 } | |
161 | |
162 void DicomMap::ExtractStudyInformation(DicomMap& result) const | |
163 { | |
164 ExtractTags(result, studyTags, sizeof(studyTags) / sizeof(DicomTag)); | |
165 } | |
166 | |
167 void DicomMap::ExtractSeriesInformation(DicomMap& result) const | |
168 { | |
169 ExtractTags(result, seriesTags, sizeof(seriesTags) / sizeof(DicomTag)); | |
170 } | |
171 | |
172 void DicomMap::ExtractInstanceInformation(DicomMap& result) const | |
173 { | |
174 ExtractTags(result, instanceTags, sizeof(instanceTags) / sizeof(DicomTag)); | |
175 } | |
176 | |
177 | |
80 | 178 |
0 | 179 DicomMap* DicomMap::Clone() const |
180 { | |
181 std::auto_ptr<DicomMap> result(new DicomMap); | |
182 | |
183 for (Map::const_iterator it = map_.begin(); it != map_.end(); it++) | |
184 { | |
185 result->map_.insert(std::make_pair(it->first, it->second->Clone())); | |
186 } | |
187 | |
188 return result.release(); | |
189 } | |
190 | |
191 | |
192 const DicomValue& DicomMap::GetValue(const DicomTag& tag) const | |
193 { | |
80 | 194 const DicomValue* value = TestAndGetValue(tag); |
195 | |
196 if (value) | |
197 { | |
198 return *value; | |
199 } | |
200 else | |
201 { | |
202 throw OrthancException("Inexistent tag"); | |
203 } | |
204 } | |
205 | |
206 | |
207 const DicomValue* DicomMap::TestAndGetValue(const DicomTag& tag) const | |
208 { | |
0 | 209 Map::const_iterator it = map_.find(tag); |
210 | |
211 if (it == map_.end()) | |
212 { | |
80 | 213 return NULL; |
0 | 214 } |
215 else | |
216 { | |
80 | 217 return it->second; |
0 | 218 } |
219 } | |
220 | |
221 | |
222 void DicomMap::Remove(const DicomTag& tag) | |
223 { | |
224 Map::iterator it = map_.find(tag); | |
225 if (it != map_.end()) | |
226 { | |
227 delete it->second; | |
228 map_.erase(it); | |
229 } | |
230 } | |
231 | |
232 | |
233 static void SetupFindTemplate(DicomMap& result, | |
234 const DicomTag* tags, | |
235 size_t count) | |
236 { | |
237 result.Clear(); | |
238 | |
239 for (size_t i = 0; i < count; i++) | |
240 { | |
241 result.SetValue(tags[i], ""); | |
242 } | |
243 } | |
244 | |
245 void DicomMap::SetupFindPatientTemplate(DicomMap& result) | |
246 { | |
247 SetupFindTemplate(result, patientTags, sizeof(patientTags) / sizeof(DicomTag)); | |
248 } | |
249 | |
250 void DicomMap::SetupFindStudyTemplate(DicomMap& result) | |
251 { | |
252 SetupFindTemplate(result, studyTags, sizeof(studyTags) / sizeof(DicomTag)); | |
80 | 253 result.SetValue(DICOM_TAG_ACCESSION_NUMBER, ""); |
254 result.SetValue(DICOM_TAG_PATIENT_ID, ""); | |
0 | 255 } |
256 | |
257 void DicomMap::SetupFindSeriesTemplate(DicomMap& result) | |
258 { | |
259 SetupFindTemplate(result, seriesTags, sizeof(seriesTags) / sizeof(DicomTag)); | |
80 | 260 result.SetValue(DICOM_TAG_ACCESSION_NUMBER, ""); |
261 result.SetValue(DICOM_TAG_PATIENT_ID, ""); | |
262 result.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, ""); | |
0 | 263 } |
264 | |
265 void DicomMap::SetupFindInstanceTemplate(DicomMap& result) | |
266 { | |
267 SetupFindTemplate(result, instanceTags, sizeof(instanceTags) / sizeof(DicomTag)); | |
80 | 268 result.SetValue(DICOM_TAG_ACCESSION_NUMBER, ""); |
269 result.SetValue(DICOM_TAG_PATIENT_ID, ""); | |
270 result.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, ""); | |
271 result.SetValue(DICOM_TAG_SERIES_INSTANCE_UID, ""); | |
0 | 272 } |
273 | |
274 | |
275 void DicomMap::CopyTagIfExists(const DicomMap& source, | |
276 const DicomTag& tag) | |
277 { | |
278 if (source.HasTag(tag)) | |
279 { | |
280 SetValue(tag, source.GetValue(tag)); | |
281 } | |
282 } | |
562
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
283 |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
284 |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
285 bool DicomMap::IsMainDicomTag(const DicomTag& tag, ResourceType level) |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
286 { |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
287 DicomTag *tags = NULL; |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
288 size_t size; |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
289 |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
290 switch (level) |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
291 { |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
292 case ResourceType_Patient: |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
293 tags = patientTags; |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
294 size = sizeof(patientTags) / sizeof(DicomTag); |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
295 break; |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
296 |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
297 case ResourceType_Study: |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
298 tags = studyTags; |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
299 size = sizeof(studyTags) / sizeof(DicomTag); |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
300 break; |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
301 |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
302 case ResourceType_Series: |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
303 tags = seriesTags; |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
304 size = sizeof(seriesTags) / sizeof(DicomTag); |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
305 break; |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
306 |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
307 case ResourceType_Instance: |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
308 tags = instanceTags; |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
309 size = sizeof(instanceTags) / sizeof(DicomTag); |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
310 break; |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
311 |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
312 default: |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
313 throw OrthancException(ErrorCode_ParameterOutOfRange); |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
314 } |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
315 |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
316 for (size_t i = 0; i < size; i++) |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
317 { |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
318 if (tags[i] == tag) |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
319 { |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
320 return true; |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
321 } |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
322 } |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
323 |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
324 return false; |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
325 } |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
326 |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
327 bool DicomMap::IsMainDicomTag(const DicomTag& tag) |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
328 { |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
329 return (IsMainDicomTag(tag, ResourceType_Patient) || |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
330 IsMainDicomTag(tag, ResourceType_Study) || |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
331 IsMainDicomTag(tag, ResourceType_Series) || |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
332 IsMainDicomTag(tag, ResourceType_Instance)); |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
433
diff
changeset
|
333 } |
0 | 334 } |