Mercurial > hg > orthanc
annotate Core/DicomFormat/DicomMap.cpp @ 59:c996319e90bc orthanc-renaming
renaming in Core
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sun, 16 Sep 2012 09:28:56 +0200 |
parents | 293038baf8f1 |
children | b8dfde8d64e8 |
rev | line source |
---|---|
0 | 1 /** |
59 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
0 | 3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege, |
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. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 **/ | |
19 | |
20 | |
21 #include "DicomMap.h" | |
22 | |
23 #include <stdio.h> | |
24 #include <memory> | |
25 #include "DicomString.h" | |
59 | 26 #include "../OrthancException.h" |
0 | 27 |
28 | |
59 | 29 namespace Orthanc |
0 | 30 { |
31 static DicomTag patientTags[] = | |
32 { | |
33 DicomTag(0x0010, 0x0010), // PatientName | |
34 DicomTag(0x0010, 0x0020), // PatientID | |
35 DicomTag(0x0010, 0x0030), // PatientBirthDate | |
36 DicomTag(0x0010, 0x0040), // PatientSex | |
38 | 37 DicomTag(0x0010, 0x1000) // OtherPatientIDs |
38 //DicomTag(0x0010, 0x1010), // PatientAge | |
39 //DicomTag(0x0010, 0x1040) // PatientAddress | |
0 | 40 }; |
41 | |
42 static DicomTag studyTags[] = | |
43 { | |
44 DicomTag(0x0008, 0x0020), // StudyDate | |
45 DicomTag(0x0008, 0x0030), // StudyTime | |
38 | 46 DicomTag(0x0008, 0x0050), // AccessionNumber |
0 | 47 DicomTag(0x0008, 0x1030), // StudyDescription |
48 DicomTag(0x0020, 0x000d), // StudyInstanceUID | |
38 | 49 DicomTag(0x0020, 0x0010) // StudyID |
50 //DicomTag(0x0010, 0x1020), // PatientSize | |
51 //DicomTag(0x0010, 0x1030) // PatientWeight | |
0 | 52 }; |
53 | |
54 static DicomTag seriesTags[] = | |
55 { | |
56 DicomTag(0x0008, 0x0021), // SeriesDate | |
57 DicomTag(0x0008, 0x0031), // SeriesTime | |
58 DicomTag(0x0008, 0x0060), // Modality | |
59 DicomTag(0x0008, 0x0070), // Manufacturer | |
60 DicomTag(0x0008, 0x1010), // StationName | |
61 DicomTag(0x0008, 0x103e), // SeriesDescription | |
38 | 62 //DicomTag(0x0010, 0x1080), // MilitaryRank |
63 DicomTag(0x0018, 0x0015), // BodyPartExamined | |
0 | 64 DicomTag(0x0018, 0x0024), // SequenceName |
65 DicomTag(0x0018, 0x1030), // ProtocolName | |
66 DicomTag(0x0020, 0x000e), // SeriesInstanceUID | |
67 DicomTag(0x0020, 0x0011), // SeriesNumber | |
41
c1097a676eca
better naming for preview images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
38
diff
changeset
|
68 DicomTag(0x0020, 0x1002), // ImagesInAcquisition |
0 | 69 DicomTag(0x0054, 0x0081) // NumberOfSlices |
70 }; | |
71 | |
72 static DicomTag instanceTags[] = | |
73 { | |
74 DicomTag(0x0008, 0x0012), // InstanceCreationDate | |
75 DicomTag(0x0008, 0x0013), // InstanceCreationTime | |
76 DicomTag(0x0008, 0x0018), // SOPInstanceUID | |
77 DicomTag(0x0020, 0x0012), // AcquisitionNumber | |
78 DicomTag(0x0020, 0x0013), // InstanceNumber | |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
79 DicomTag(0x0028, 0x0008), // NumberOfFrames |
0 | 80 DicomTag(0x0054, 0x1330) // ImageIndex |
81 }; | |
82 | |
83 | |
84 | |
85 | |
86 void DicomMap::SetValue(uint16_t group, | |
87 uint16_t element, | |
88 DicomValue* value) | |
89 { | |
90 DicomTag tag(group, element); | |
91 Map::iterator it = map_.find(tag); | |
92 | |
93 if (it != map_.end()) | |
94 { | |
95 delete it->second; | |
96 it->second = value; | |
97 } | |
98 else | |
99 { | |
100 map_.insert(std::make_pair(tag, value)); | |
101 } | |
102 } | |
103 | |
104 void DicomMap::SetValue(DicomTag tag, | |
105 DicomValue* value) | |
106 { | |
107 SetValue(tag.GetGroup(), tag.GetElement(), value); | |
108 } | |
109 | |
110 | |
111 | |
112 | |
113 void DicomMap::Clear() | |
114 { | |
115 for (Map::iterator it = map_.begin(); it != map_.end(); it++) | |
116 { | |
117 delete it->second; | |
118 } | |
119 | |
120 map_.clear(); | |
121 } | |
122 | |
123 | |
124 void DicomMap::ExtractTags(DicomMap& result, | |
125 const DicomTag* tags, | |
126 size_t count) const | |
127 { | |
128 result.Clear(); | |
129 | |
130 for (unsigned int i = 0; i < count; i++) | |
131 { | |
132 Map::const_iterator it = map_.find(tags[i]); | |
133 if (it != map_.end()) | |
134 { | |
135 result.SetValue(it->first, it->second->Clone()); | |
136 } | |
137 } | |
138 } | |
139 | |
140 | |
141 void DicomMap::ExtractPatientInformation(DicomMap& result) const | |
142 { | |
143 ExtractTags(result, patientTags, sizeof(patientTags) / sizeof(DicomTag)); | |
144 } | |
145 | |
146 void DicomMap::ExtractStudyInformation(DicomMap& result) const | |
147 { | |
148 ExtractTags(result, studyTags, sizeof(studyTags) / sizeof(DicomTag)); | |
149 } | |
150 | |
151 void DicomMap::ExtractSeriesInformation(DicomMap& result) const | |
152 { | |
153 ExtractTags(result, seriesTags, sizeof(seriesTags) / sizeof(DicomTag)); | |
154 } | |
155 | |
156 void DicomMap::ExtractInstanceInformation(DicomMap& result) const | |
157 { | |
158 ExtractTags(result, instanceTags, sizeof(instanceTags) / sizeof(DicomTag)); | |
159 } | |
160 | |
161 | |
162 DicomMap* DicomMap::Clone() const | |
163 { | |
164 std::auto_ptr<DicomMap> result(new DicomMap); | |
165 | |
166 for (Map::const_iterator it = map_.begin(); it != map_.end(); it++) | |
167 { | |
168 result->map_.insert(std::make_pair(it->first, it->second->Clone())); | |
169 } | |
170 | |
171 return result.release(); | |
172 } | |
173 | |
174 | |
175 const DicomValue& DicomMap::GetValue(const DicomTag& tag) const | |
176 { | |
177 Map::const_iterator it = map_.find(tag); | |
178 | |
179 if (it == map_.end()) | |
180 { | |
59 | 181 throw OrthancException("Inexistent tag"); |
0 | 182 } |
183 else | |
184 { | |
185 return *it->second; | |
186 } | |
187 } | |
188 | |
189 | |
190 void DicomMap::Remove(const DicomTag& tag) | |
191 { | |
192 Map::iterator it = map_.find(tag); | |
193 if (it != map_.end()) | |
194 { | |
195 delete it->second; | |
196 map_.erase(it); | |
197 } | |
198 } | |
199 | |
200 | |
201 static void SetupFindTemplate(DicomMap& result, | |
202 const DicomTag* tags, | |
203 size_t count) | |
204 { | |
205 result.Clear(); | |
206 | |
207 for (size_t i = 0; i < count; i++) | |
208 { | |
209 result.SetValue(tags[i], ""); | |
210 } | |
211 } | |
212 | |
213 void DicomMap::SetupFindPatientTemplate(DicomMap& result) | |
214 { | |
215 SetupFindTemplate(result, patientTags, sizeof(patientTags) / sizeof(DicomTag)); | |
216 } | |
217 | |
218 void DicomMap::SetupFindStudyTemplate(DicomMap& result) | |
219 { | |
220 SetupFindTemplate(result, studyTags, sizeof(studyTags) / sizeof(DicomTag)); | |
221 result.SetValue(DicomTag::ACCESSION_NUMBER, ""); | |
222 result.SetValue(DicomTag::PATIENT_ID, ""); | |
223 } | |
224 | |
225 void DicomMap::SetupFindSeriesTemplate(DicomMap& result) | |
226 { | |
227 SetupFindTemplate(result, seriesTags, sizeof(seriesTags) / sizeof(DicomTag)); | |
228 result.SetValue(DicomTag::ACCESSION_NUMBER, ""); | |
229 result.SetValue(DicomTag::PATIENT_ID, ""); | |
230 result.SetValue(DicomTag::STUDY_UID, ""); | |
231 } | |
232 | |
233 void DicomMap::SetupFindInstanceTemplate(DicomMap& result) | |
234 { | |
235 SetupFindTemplate(result, instanceTags, sizeof(instanceTags) / sizeof(DicomTag)); | |
236 result.SetValue(DicomTag::ACCESSION_NUMBER, ""); | |
237 result.SetValue(DicomTag::PATIENT_ID, ""); | |
238 result.SetValue(DicomTag::STUDY_UID, ""); | |
239 result.SetValue(DicomTag::SERIES_UID, ""); | |
240 } | |
241 | |
242 | |
243 void DicomMap::CopyTagIfExists(const DicomMap& source, | |
244 const DicomTag& tag) | |
245 { | |
246 if (source.HasTag(tag)) | |
247 { | |
248 SetValue(tag, source.GetValue(tag)); | |
249 } | |
250 } | |
251 } |