Mercurial > hg > orthanc
annotate OrthancFramework/Sources/DicomFormat/DicomPath.cpp @ 5657:dedbf019a707
Improved parsing of multiple numerical values in DICOM tags
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Thu, 06 Jun 2024 17:55:13 +0200 |
parents | f7adfb22e20e |
children |
rev | line source |
---|---|
4681 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
4681 | 8 * |
9 * This program is free software: you can redistribute it and/or | |
10 * modify it under the terms of the GNU Lesser General Public License | |
11 * as published by the Free Software Foundation, either version 3 of | |
12 * the License, or (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, but | |
15 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 * Lesser General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU Lesser General Public | |
20 * License along with this program. If not, see | |
21 * <http://www.gnu.org/licenses/>. | |
22 **/ | |
23 | |
24 | |
25 #include "../PrecompiledHeaders.h" | |
26 #include "DicomPath.h" | |
27 | |
28 | |
29 #if !defined(ORTHANC_ENABLE_DCMTK) | |
30 # error Macro ORTHANC_ENABLE_DCMTK must be defined | |
31 #endif | |
32 | |
33 #if ORTHANC_ENABLE_DCMTK == 1 | |
34 # include "../DicomParsing/FromDcmtkBridge.h" | |
35 #endif | |
36 | |
37 #include "../OrthancException.h" | |
38 #include "../Toolbox.h" | |
39 | |
40 #include <boost/lexical_cast.hpp> | |
41 | |
42 | |
43 namespace Orthanc | |
44 { | |
45 DicomPath::PrefixItem::PrefixItem(DicomTag tag, | |
46 bool isUniversal, | |
47 size_t index) : | |
48 tag_(tag), | |
49 isUniversal_(isUniversal), | |
50 index_(index) | |
51 { | |
52 } | |
53 | |
54 | |
55 size_t DicomPath::PrefixItem::GetIndex() const | |
56 { | |
57 if (isUniversal_) | |
58 { | |
59 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
60 } | |
61 else | |
62 { | |
63 return index_; | |
64 } | |
65 } | |
66 | |
67 | |
4689
ead3b81f4541
added DicomPath::SetPrefixIndex()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4685
diff
changeset
|
68 void DicomPath::PrefixItem::SetIndex(size_t index) |
ead3b81f4541
added DicomPath::SetPrefixIndex()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4685
diff
changeset
|
69 { |
ead3b81f4541
added DicomPath::SetPrefixIndex()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4685
diff
changeset
|
70 isUniversal_ = false; |
ead3b81f4541
added DicomPath::SetPrefixIndex()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4685
diff
changeset
|
71 index_ = index; |
ead3b81f4541
added DicomPath::SetPrefixIndex()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4685
diff
changeset
|
72 } |
ead3b81f4541
added DicomPath::SetPrefixIndex()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4685
diff
changeset
|
73 |
ead3b81f4541
added DicomPath::SetPrefixIndex()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4685
diff
changeset
|
74 |
4681 | 75 DicomTag DicomPath::ParseTag(const std::string& token) |
76 { | |
77 DicomTag tag(0,0); | |
78 | |
79 if (token[0] == '(' && | |
80 token[token.size() - 1] == ')') | |
81 { | |
82 std::string hex = token.substr(1, token.size() - 2); | |
83 if (!DicomTag::ParseHexadecimal(tag, hex.c_str())) | |
84 { | |
85 throw OrthancException(ErrorCode_UnknownDicomTag, "Cannot parse tag: " + token); | |
86 } | |
87 } | |
88 else | |
89 { | |
90 #if ORTHANC_ENABLE_DCMTK == 1 | |
91 tag = FromDcmtkBridge::ParseTag(token); | |
92 #else | |
93 if (!DicomTag::ParseHexadecimal(tag, token.c_str())) | |
94 { | |
95 throw OrthancException(ErrorCode_UnknownDicomTag, "Cannot parse tag without DCMTK: " + token); | |
96 } | |
97 #endif | |
98 } | |
99 | |
100 return tag; | |
101 } | |
102 | |
103 | |
104 const DicomPath::PrefixItem& DicomPath::GetLevel(size_t i) const | |
105 { | |
106 if (i >= prefix_.size()) | |
107 { | |
108 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
109 } | |
110 else | |
111 { | |
112 return prefix_[i]; | |
113 } | |
114 } | |
115 | |
116 | |
4690 | 117 DicomPath::DicomPath(const Orthanc::DicomTag& tag) : |
118 finalTag_(tag) | |
119 { | |
120 } | |
121 | |
122 | |
4681 | 123 DicomPath::DicomPath(const Orthanc::DicomTag& sequence, |
124 size_t index, | |
125 const Orthanc::DicomTag& tag) : | |
126 finalTag_(tag) | |
127 { | |
128 AddIndexedTagToPrefix(sequence, index); | |
129 } | |
130 | |
131 | |
132 DicomPath::DicomPath(const Orthanc::DicomTag& sequence1, | |
133 size_t index1, | |
134 const Orthanc::DicomTag& sequence2, | |
135 size_t index2, | |
136 const Orthanc::DicomTag& tag) : | |
137 finalTag_(tag) | |
138 { | |
139 AddIndexedTagToPrefix(sequence1, index1); | |
140 AddIndexedTagToPrefix(sequence2, index2); | |
141 } | |
142 | |
143 | |
144 DicomPath::DicomPath(const Orthanc::DicomTag& sequence1, | |
145 size_t index1, | |
146 const Orthanc::DicomTag& sequence2, | |
147 size_t index2, | |
148 const Orthanc::DicomTag& sequence3, | |
149 size_t index3, | |
150 const Orthanc::DicomTag& tag) : | |
151 finalTag_(tag) | |
152 { | |
153 AddIndexedTagToPrefix(sequence1, index1); | |
154 AddIndexedTagToPrefix(sequence2, index2); | |
155 AddIndexedTagToPrefix(sequence3, index3); | |
156 } | |
157 | |
158 | |
4683
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
159 DicomPath::DicomPath(const std::vector<Orthanc::DicomTag>& parentTags, |
4690 | 160 const std::vector<size_t>& parentIndexes, |
4683
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
161 const Orthanc::DicomTag& finalTag) : |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
162 finalTag_(finalTag) |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
163 { |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
164 if (parentTags.size() != parentIndexes.size()) |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
165 { |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
166 throw OrthancException(ErrorCode_ParameterOutOfRange); |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
167 } |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
168 else |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
169 { |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
170 prefix_.reserve(parentTags.size()); |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
171 |
4685
693f049729ba
New versions of Keep(), Remove() and Replace() in DicomModification that use DicomPath
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4683
diff
changeset
|
172 for (size_t i = 0; i < parentTags.size(); i++) |
4683
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
173 { |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
174 prefix_.push_back(PrefixItem::CreateIndexed(parentTags[i], parentIndexes[i])); |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
175 } |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
176 } |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
177 } |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
178 |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
179 |
4681 | 180 void DicomPath::AddIndexedTagToPrefix(const Orthanc::DicomTag& tag, |
181 size_t index) | |
182 { | |
183 prefix_.push_back(PrefixItem::CreateIndexed(tag, index)); | |
184 } | |
185 | |
186 | |
187 void DicomPath::AddUniversalTagToPrefix(const Orthanc::DicomTag& tag) | |
188 { | |
189 prefix_.push_back(PrefixItem::CreateUniversal(tag)); | |
190 } | |
191 | |
192 | |
4690 | 193 size_t DicomPath::GetPrefixLength() const |
194 { | |
195 return prefix_.size(); | |
196 } | |
197 | |
198 | |
199 const Orthanc::DicomTag& DicomPath::GetFinalTag() const | |
200 { | |
201 return finalTag_; | |
202 } | |
203 | |
204 | |
205 const Orthanc::DicomTag& DicomPath::GetPrefixTag(size_t level) const | |
206 { | |
207 return GetLevel(level).GetTag(); | |
208 } | |
209 | |
210 | |
211 bool DicomPath::IsPrefixUniversal(size_t level) const | |
212 { | |
213 return GetLevel(level).IsUniversal(); | |
214 } | |
215 | |
216 | |
217 size_t DicomPath::GetPrefixIndex(size_t level) const | |
218 { | |
219 return GetLevel(level).GetIndex(); | |
220 } | |
221 | |
222 | |
4682
d38a7040474a
FromDcmtkBridge::RemovePath() and FromDcmtkBridge::ReplacePath()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4681
diff
changeset
|
223 bool DicomPath::HasUniversal() const |
d38a7040474a
FromDcmtkBridge::RemovePath() and FromDcmtkBridge::ReplacePath()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4681
diff
changeset
|
224 { |
d38a7040474a
FromDcmtkBridge::RemovePath() and FromDcmtkBridge::ReplacePath()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4681
diff
changeset
|
225 for (size_t i = 0; i < prefix_.size(); i++) |
d38a7040474a
FromDcmtkBridge::RemovePath() and FromDcmtkBridge::ReplacePath()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4681
diff
changeset
|
226 { |
d38a7040474a
FromDcmtkBridge::RemovePath() and FromDcmtkBridge::ReplacePath()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4681
diff
changeset
|
227 if (prefix_[i].IsUniversal()) |
d38a7040474a
FromDcmtkBridge::RemovePath() and FromDcmtkBridge::ReplacePath()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4681
diff
changeset
|
228 { |
d38a7040474a
FromDcmtkBridge::RemovePath() and FromDcmtkBridge::ReplacePath()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4681
diff
changeset
|
229 return true; |
d38a7040474a
FromDcmtkBridge::RemovePath() and FromDcmtkBridge::ReplacePath()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4681
diff
changeset
|
230 } |
d38a7040474a
FromDcmtkBridge::RemovePath() and FromDcmtkBridge::ReplacePath()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4681
diff
changeset
|
231 } |
d38a7040474a
FromDcmtkBridge::RemovePath() and FromDcmtkBridge::ReplacePath()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4681
diff
changeset
|
232 |
d38a7040474a
FromDcmtkBridge::RemovePath() and FromDcmtkBridge::ReplacePath()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4681
diff
changeset
|
233 return false; |
d38a7040474a
FromDcmtkBridge::RemovePath() and FromDcmtkBridge::ReplacePath()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4681
diff
changeset
|
234 } |
d38a7040474a
FromDcmtkBridge::RemovePath() and FromDcmtkBridge::ReplacePath()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4681
diff
changeset
|
235 |
d38a7040474a
FromDcmtkBridge::RemovePath() and FromDcmtkBridge::ReplacePath()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4681
diff
changeset
|
236 |
4689
ead3b81f4541
added DicomPath::SetPrefixIndex()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4685
diff
changeset
|
237 void DicomPath::SetPrefixIndex(size_t level, |
ead3b81f4541
added DicomPath::SetPrefixIndex()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4685
diff
changeset
|
238 size_t index) |
ead3b81f4541
added DicomPath::SetPrefixIndex()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4685
diff
changeset
|
239 { |
ead3b81f4541
added DicomPath::SetPrefixIndex()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4685
diff
changeset
|
240 if (level >= prefix_.size()) |
ead3b81f4541
added DicomPath::SetPrefixIndex()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4685
diff
changeset
|
241 { |
ead3b81f4541
added DicomPath::SetPrefixIndex()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4685
diff
changeset
|
242 throw OrthancException(ErrorCode_ParameterOutOfRange); |
ead3b81f4541
added DicomPath::SetPrefixIndex()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4685
diff
changeset
|
243 } |
ead3b81f4541
added DicomPath::SetPrefixIndex()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4685
diff
changeset
|
244 else |
ead3b81f4541
added DicomPath::SetPrefixIndex()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4685
diff
changeset
|
245 { |
ead3b81f4541
added DicomPath::SetPrefixIndex()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4685
diff
changeset
|
246 prefix_[level].SetIndex(index); |
ead3b81f4541
added DicomPath::SetPrefixIndex()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4685
diff
changeset
|
247 } |
ead3b81f4541
added DicomPath::SetPrefixIndex()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4685
diff
changeset
|
248 } |
ead3b81f4541
added DicomPath::SetPrefixIndex()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4685
diff
changeset
|
249 |
ead3b81f4541
added DicomPath::SetPrefixIndex()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4685
diff
changeset
|
250 |
4681 | 251 std::string DicomPath::Format() const |
252 { | |
253 std::string s; | |
254 | |
255 for (size_t i = 0; i < prefix_.size(); i++) | |
256 { | |
257 s += "(" + prefix_[i].GetTag().Format() + ")"; | |
258 | |
259 if (prefix_[i].IsUniversal()) | |
260 { | |
261 s += "[*]."; | |
262 } | |
263 else | |
264 { | |
265 s += "[" + boost::lexical_cast<std::string>(prefix_[i].GetIndex()) + "]."; | |
266 } | |
267 } | |
268 | |
269 return s + "(" + finalTag_.Format() + ")"; | |
270 } | |
271 | |
272 | |
4682
d38a7040474a
FromDcmtkBridge::RemovePath() and FromDcmtkBridge::ReplacePath()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4681
diff
changeset
|
273 DicomPath DicomPath::Parse(const std::string& s) |
4681 | 274 { |
275 std::vector<std::string> tokens; | |
276 Toolbox::TokenizeString(tokens, s, '.'); | |
277 | |
278 if (tokens.empty()) | |
279 { | |
280 throw OrthancException(ErrorCode_ParameterOutOfRange, "Empty path to DICOM tags"); | |
281 } | |
282 | |
283 const DicomTag finalTag = ParseTag(Toolbox::StripSpaces(tokens[tokens.size() - 1])); | |
284 | |
285 DicomPath path(finalTag); | |
286 | |
287 for (size_t i = 0; i < tokens.size() - 1; i++) | |
288 { | |
289 size_t pos = tokens[i].find('['); | |
290 if (pos == std::string::npos) | |
291 { | |
292 throw OrthancException(ErrorCode_ParameterOutOfRange, "Parent path doesn't contain an index"); | |
293 } | |
294 else | |
295 { | |
296 const std::string left = Orthanc::Toolbox::StripSpaces(tokens[i].substr(0, pos)); | |
297 const std::string right = Orthanc::Toolbox::StripSpaces(tokens[i].substr(pos + 1)); | |
298 | |
299 if (left.empty()) | |
300 { | |
301 throw OrthancException(ErrorCode_ParameterOutOfRange, "Parent path doesn't contain a tag"); | |
302 } | |
303 else if (right.empty() || | |
304 right[right.size() - 1] != ']') | |
305 { | |
306 throw OrthancException(ErrorCode_ParameterOutOfRange, "Parent path doesn't contain the end of the index"); | |
307 } | |
308 else | |
309 { | |
310 DicomTag tag = ParseTag(left); | |
311 | |
312 try | |
313 { | |
4690 | 314 std::string t = Toolbox::StripSpaces(right.substr(0, right.size() - 1)); |
315 if (t == "*") | |
4681 | 316 { |
4682
d38a7040474a
FromDcmtkBridge::RemovePath() and FromDcmtkBridge::ReplacePath()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4681
diff
changeset
|
317 path.AddUniversalTagToPrefix(tag); |
4681 | 318 } |
319 else | |
320 { | |
4690 | 321 int index = boost::lexical_cast<int>(t); |
4681 | 322 if (index < 0) |
323 { | |
4690 | 324 throw OrthancException(ErrorCode_ParameterOutOfRange, "Negative index in parent path: " + t); |
4681 | 325 } |
326 else | |
327 { | |
328 path.AddIndexedTagToPrefix(tag, static_cast<size_t>(index)); | |
329 } | |
330 } | |
331 } | |
332 catch (boost::bad_lexical_cast&) | |
333 { | |
334 throw OrthancException(ErrorCode_ParameterOutOfRange, "Not a valid index in parent path: [" + right); | |
335 } | |
336 } | |
337 } | |
338 } | |
339 | |
340 return path; | |
341 } | |
4683
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
342 |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
343 |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
344 bool DicomPath::IsMatch(const DicomPath& pattern, |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
345 const DicomPath& path) |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
346 { |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
347 if (path.HasUniversal()) |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
348 { |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
349 throw OrthancException(ErrorCode_BadParameterType); |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
350 } |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
351 else if (path.GetPrefixLength() < pattern.GetPrefixLength()) |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
352 { |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
353 return false; |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
354 } |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
355 else |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
356 { |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
357 for (size_t i = 0; i < pattern.GetPrefixLength(); i++) |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
358 { |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
359 if (path.GetPrefixTag(i) != pattern.GetPrefixTag(i) || |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
360 (!pattern.IsPrefixUniversal(i) && |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
361 path.GetPrefixIndex(i) != pattern.GetPrefixIndex(i))) |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
362 { |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
363 return false; |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
364 } |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
365 } |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
366 |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
367 if (path.GetPrefixLength() == pattern.GetPrefixLength()) |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
368 { |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
369 return (path.GetFinalTag() == pattern.GetFinalTag()); |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
370 } |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
371 else |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
372 { |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
373 return (path.GetPrefixTag(pattern.GetPrefixLength()) == pattern.GetFinalTag()); |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
374 } |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
375 } |
7182f5732480
use of DicomPath in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4682
diff
changeset
|
376 } |
4735
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
377 |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
378 |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
379 bool DicomPath::IsMatch(const DicomPath& pattern, |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
380 const std::vector<Orthanc::DicomTag>& prefixTags, |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
381 const std::vector<size_t>& prefixIndexes, |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
382 const DicomTag& finalTag) |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
383 { |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
384 if (prefixTags.size() != prefixIndexes.size()) |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
385 { |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
386 throw OrthancException(ErrorCode_ParameterOutOfRange); |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
387 } |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
388 |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
389 if (prefixTags.size() < pattern.GetPrefixLength()) |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
390 { |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
391 return false; |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
392 } |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
393 else |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
394 { |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
395 for (size_t i = 0; i < pattern.GetPrefixLength(); i++) |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
396 { |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
397 if (prefixTags[i] != pattern.GetPrefixTag(i) || |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
398 (!pattern.IsPrefixUniversal(i) && |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
399 prefixIndexes[i] != pattern.GetPrefixIndex(i))) |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
400 { |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
401 return false; |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
402 } |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
403 } |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
404 |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
405 if (prefixTags.size() == pattern.GetPrefixLength()) |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
406 { |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
407 return (finalTag == pattern.GetFinalTag()); |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
408 } |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
409 else |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
410 { |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
411 return (prefixTags[pattern.GetPrefixLength()] == pattern.GetFinalTag()); |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
412 } |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
413 } |
e17fdc43ef6c
optimized version of DicomPath::IsMatch()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4690
diff
changeset
|
414 } |
4681 | 415 } |