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