comparison Core/DicomFormat/DicomMap.cpp @ 0:3959d33612cc

initial commit
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 19 Jul 2012 14:32:22 +0200
parents
children 2cefaf5b3c2e
comparison
equal deleted inserted replaced
-1:000000000000 0:3959d33612cc
1 /**
2 * Palantir - A Lightweight, RESTful DICOM Store
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"
26 #include "../PalantirException.h"
27
28
29 namespace Palantir
30 {
31 static DicomTag patientTags[] =
32 {
33 DicomTag(0x0008, 0x0050), // AccessionNumber
34 DicomTag(0x0010, 0x0010), // PatientName
35 DicomTag(0x0010, 0x0020), // PatientID
36 DicomTag(0x0010, 0x0030), // PatientBirthDate
37 DicomTag(0x0010, 0x0040), // PatientSex
38 DicomTag(0x0010, 0x1000), // OtherPatientIDs
39 DicomTag(0x0010, 0x1010), // PatientAge
40 DicomTag(0x0010, 0x1040) // PatientAddress
41 };
42
43 static DicomTag studyTags[] =
44 {
45 DicomTag(0x0008, 0x0020), // StudyDate
46 DicomTag(0x0008, 0x0030), // StudyTime
47 DicomTag(0x0008, 0x1030), // StudyDescription
48 DicomTag(0x0020, 0x000d), // StudyInstanceUID
49 DicomTag(0x0020, 0x0010), // StudyID
50 DicomTag(0x0010, 0x1020), // PatientSize
51 DicomTag(0x0010, 0x1030) // PatientWeight
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
62 DicomTag(0x0010, 0x1080), // MilitaryRank
63 DicomTag(0x0018, 0x0024), // SequenceName
64 DicomTag(0x0018, 0x1030), // ProtocolName
65 DicomTag(0x0020, 0x000e), // SeriesInstanceUID
66 DicomTag(0x0020, 0x0011), // SeriesNumber
67 DicomTag(0x0054, 0x0081) // NumberOfSlices
68 };
69
70 static DicomTag instanceTags[] =
71 {
72 DicomTag(0x0008, 0x0012), // InstanceCreationDate
73 DicomTag(0x0008, 0x0013), // InstanceCreationTime
74 DicomTag(0x0008, 0x0018), // SOPInstanceUID
75 DicomTag(0x0020, 0x0012), // AcquisitionNumber
76 DicomTag(0x0020, 0x0013), // InstanceNumber
77 DicomTag(0x0054, 0x1330) // ImageIndex
78 };
79
80
81
82
83 void DicomMap::SetValue(uint16_t group,
84 uint16_t element,
85 DicomValue* value)
86 {
87 DicomTag tag(group, element);
88 Map::iterator it = map_.find(tag);
89
90 if (it != map_.end())
91 {
92 delete it->second;
93 it->second = value;
94 }
95 else
96 {
97 map_.insert(std::make_pair(tag, value));
98 }
99 }
100
101 void DicomMap::SetValue(DicomTag tag,
102 DicomValue* value)
103 {
104 SetValue(tag.GetGroup(), tag.GetElement(), value);
105 }
106
107
108
109
110 void DicomMap::Clear()
111 {
112 for (Map::iterator it = map_.begin(); it != map_.end(); it++)
113 {
114 delete it->second;
115 }
116
117 map_.clear();
118 }
119
120
121 void DicomMap::ExtractTags(DicomMap& result,
122 const DicomTag* tags,
123 size_t count) const
124 {
125 result.Clear();
126
127 for (unsigned int i = 0; i < count; i++)
128 {
129 Map::const_iterator it = map_.find(tags[i]);
130 if (it != map_.end())
131 {
132 result.SetValue(it->first, it->second->Clone());
133 }
134 }
135 }
136
137
138 void DicomMap::ExtractPatientInformation(DicomMap& result) const
139 {
140 ExtractTags(result, patientTags, sizeof(patientTags) / sizeof(DicomTag));
141 }
142
143 void DicomMap::ExtractStudyInformation(DicomMap& result) const
144 {
145 ExtractTags(result, studyTags, sizeof(studyTags) / sizeof(DicomTag));
146 }
147
148 void DicomMap::ExtractSeriesInformation(DicomMap& result) const
149 {
150 ExtractTags(result, seriesTags, sizeof(seriesTags) / sizeof(DicomTag));
151 }
152
153 void DicomMap::ExtractInstanceInformation(DicomMap& result) const
154 {
155 ExtractTags(result, instanceTags, sizeof(instanceTags) / sizeof(DicomTag));
156 }
157
158
159 DicomMap* DicomMap::Clone() const
160 {
161 std::auto_ptr<DicomMap> result(new DicomMap);
162
163 for (Map::const_iterator it = map_.begin(); it != map_.end(); it++)
164 {
165 result->map_.insert(std::make_pair(it->first, it->second->Clone()));
166 }
167
168 return result.release();
169 }
170
171
172 const DicomValue& DicomMap::GetValue(const DicomTag& tag) const
173 {
174 Map::const_iterator it = map_.find(tag);
175
176 if (it == map_.end())
177 {
178 throw PalantirException("Inexistent tag");
179 }
180 else
181 {
182 return *it->second;
183 }
184 }
185
186
187 void DicomMap::Remove(const DicomTag& tag)
188 {
189 Map::iterator it = map_.find(tag);
190 if (it != map_.end())
191 {
192 delete it->second;
193 map_.erase(it);
194 }
195 }
196
197
198 static void SetupFindTemplate(DicomMap& result,
199 const DicomTag* tags,
200 size_t count)
201 {
202 result.Clear();
203
204 for (size_t i = 0; i < count; i++)
205 {
206 result.SetValue(tags[i], "");
207 }
208 }
209
210 void DicomMap::SetupFindPatientTemplate(DicomMap& result)
211 {
212 SetupFindTemplate(result, patientTags, sizeof(patientTags) / sizeof(DicomTag));
213 }
214
215 void DicomMap::SetupFindStudyTemplate(DicomMap& result)
216 {
217 SetupFindTemplate(result, studyTags, sizeof(studyTags) / sizeof(DicomTag));
218 result.SetValue(DicomTag::ACCESSION_NUMBER, "");
219 result.SetValue(DicomTag::PATIENT_ID, "");
220 }
221
222 void DicomMap::SetupFindSeriesTemplate(DicomMap& result)
223 {
224 SetupFindTemplate(result, seriesTags, sizeof(seriesTags) / sizeof(DicomTag));
225 result.SetValue(DicomTag::ACCESSION_NUMBER, "");
226 result.SetValue(DicomTag::PATIENT_ID, "");
227 result.SetValue(DicomTag::STUDY_UID, "");
228 }
229
230 void DicomMap::SetupFindInstanceTemplate(DicomMap& result)
231 {
232 SetupFindTemplate(result, instanceTags, sizeof(instanceTags) / sizeof(DicomTag));
233 result.SetValue(DicomTag::ACCESSION_NUMBER, "");
234 result.SetValue(DicomTag::PATIENT_ID, "");
235 result.SetValue(DicomTag::STUDY_UID, "");
236 result.SetValue(DicomTag::SERIES_UID, "");
237 }
238
239
240 void DicomMap::CopyTagIfExists(const DicomMap& source,
241 const DicomTag& tag)
242 {
243 if (source.HasTag(tag))
244 {
245 SetValue(tag, source.GetValue(tag));
246 }
247 }
248 }