comparison OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp @ 4735:e17fdc43ef6c

optimized version of DicomPath::IsMatch()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 05 Jul 2021 17:03:46 +0200
parents b51c08bd5c38
children bf852fd773b7
comparison
equal deleted inserted replaced
4734:b51c08bd5c38 4735:e17fdc43ef6c
2259 ASSERT_EQ(0u, cache.GetNumberOfItems()); 2259 ASSERT_EQ(0u, cache.GetNumberOfItems());
2260 ASSERT_FALSE(ParsedDicomCache::Accessor(cache, "e").IsValid()); 2260 ASSERT_FALSE(ParsedDicomCache::Accessor(cache, "e").IsValid());
2261 } 2261 }
2262 2262
2263 2263
2264 static bool MyIsMatch(const DicomPath& a,
2265 const DicomPath& b)
2266 {
2267 bool expected = DicomPath::IsMatch(a, b);
2268
2269 std::vector<DicomTag> prefixTags;
2270 std::vector<size_t> prefixIndexes;
2271
2272 for (size_t i = 0; i < b.GetPrefixLength(); i++)
2273 {
2274 prefixTags.push_back(b.GetPrefixTag(i));
2275 prefixIndexes.push_back(b.GetPrefixIndex(i));
2276 }
2277
2278 if (expected == DicomPath::IsMatch(a, prefixTags, prefixIndexes, b.GetFinalTag()))
2279 {
2280 return expected;
2281 }
2282 else
2283 {
2284 throw OrthancException(ErrorCode_InternalError);
2285 }
2286 }
2287
2288
2264 TEST(DicomModification, DicomPath) 2289 TEST(DicomModification, DicomPath)
2265 { 2290 {
2266 // Those are samples inspired by those from "man dcmodify" 2291 // Those are samples inspired by those from "man dcmodify"
2267 2292
2268 static const DicomTag DICOM_TAG_ACQUISITION_MATRIX(0x0018, 0x1310); 2293 static const DicomTag DICOM_TAG_ACQUISITION_MATRIX(0x0018, 0x1310);
2364 ASSERT_THROW(DicomPath::Parse("(0010,0010)[].PatientID"), OrthancException); 2389 ASSERT_THROW(DicomPath::Parse("(0010,0010)[].PatientID"), OrthancException);
2365 ASSERT_THROW(DicomPath::Parse("(0010,0010[].PatientID"), OrthancException); 2390 ASSERT_THROW(DicomPath::Parse("(0010,0010[].PatientID"), OrthancException);
2366 ASSERT_THROW(DicomPath::Parse("(0010,0010)0].PatientID"), OrthancException); 2391 ASSERT_THROW(DicomPath::Parse("(0010,0010)0].PatientID"), OrthancException);
2367 ASSERT_THROW(DicomPath::Parse("(0010,0010)[-1].PatientID"), OrthancException); 2392 ASSERT_THROW(DicomPath::Parse("(0010,0010)[-1].PatientID"), OrthancException);
2368 2393
2369 ASSERT_TRUE(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)"), 2394 ASSERT_TRUE(MyIsMatch(DicomPath::Parse("(0010,0010)"),
2370 DicomPath::Parse("(0010,0010)"))); 2395 DicomPath::Parse("(0010,0010)")));
2371 ASSERT_FALSE(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)"), 2396 ASSERT_FALSE(MyIsMatch(DicomPath::Parse("(0010,0010)"),
2372 DicomPath::Parse("(0010,0020)"))); 2397 DicomPath::Parse("(0010,0020)")));
2373 ASSERT_TRUE(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)"), 2398 ASSERT_TRUE(MyIsMatch(DicomPath::Parse("(0010,0010)"),
2374 DicomPath::Parse("(0010,0010)[1].(0010,0020)"))); 2399 DicomPath::Parse("(0010,0010)[1].(0010,0020)")));
2375 ASSERT_FALSE(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)[1].(0010,0020)"), 2400 ASSERT_FALSE(MyIsMatch(DicomPath::Parse("(0010,0010)[1].(0010,0020)"),
2376 DicomPath::Parse("(0010,0010)"))); 2401 DicomPath::Parse("(0010,0010)")));
2377 ASSERT_TRUE(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)[1].(0010,0020)"), 2402 ASSERT_TRUE(MyIsMatch(DicomPath::Parse("(0010,0010)[1].(0010,0020)"),
2378 DicomPath::Parse("(0010,0010)[1].(0010,0020)"))); 2403 DicomPath::Parse("(0010,0010)[1].(0010,0020)")));
2379 ASSERT_TRUE(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)[*].(0010,0020)"), 2404 ASSERT_TRUE(MyIsMatch(DicomPath::Parse("(0010,0010)[*].(0010,0020)"),
2380 DicomPath::Parse("(0010,0010)[1].(0010,0020)"))); 2405 DicomPath::Parse("(0010,0010)[1].(0010,0020)")));
2381 ASSERT_FALSE(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)[2].(0010,0020)"), 2406 ASSERT_FALSE(MyIsMatch(DicomPath::Parse("(0010,0010)[2].(0010,0020)"),
2382 DicomPath::Parse("(0010,0010)[1].(0010,0020)"))); 2407 DicomPath::Parse("(0010,0010)[1].(0010,0020)")));
2383 ASSERT_THROW(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)[1].(0010,0020)"), 2408 ASSERT_THROW(MyIsMatch(DicomPath::Parse("(0010,0010)[1].(0010,0020)"),
2384 DicomPath::Parse("(0010,0010)[*].(0010,0020)")), OrthancException); 2409 DicomPath::Parse("(0010,0010)[*].(0010,0020)")), OrthancException);
2385 ASSERT_TRUE(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)[*].(0010,0020)[*].(0010,0030)"), 2410 ASSERT_TRUE(MyIsMatch(DicomPath::Parse("(0010,0010)[*].(0010,0020)[*].(0010,0030)"),
2386 DicomPath::Parse("(0010,0010)[1].(0010,0020)[2].(0010,0030)[3].(0010,0040)"))); 2411 DicomPath::Parse("(0010,0010)[1].(0010,0020)[2].(0010,0030)[3].(0010,0040)")));
2387 ASSERT_TRUE(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)[1].(0010,0020)[2].(0010,0030)"), 2412 ASSERT_TRUE(MyIsMatch(DicomPath::Parse("(0010,0010)[1].(0010,0020)[2].(0010,0030)"),
2388 DicomPath::Parse("(0010,0010)[1].(0010,0020)[2].(0010,0030)[3].(0010,0040)"))); 2413 DicomPath::Parse("(0010,0010)[1].(0010,0020)[2].(0010,0030)[3].(0010,0040)")));
2389 ASSERT_FALSE(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)[1].(0010,0020)[3].(0010,0030)"), 2414 ASSERT_FALSE(MyIsMatch(DicomPath::Parse("(0010,0010)[1].(0010,0020)[3].(0010,0030)"),
2390 DicomPath::Parse("(0010,0010)[1].(0010,0020)[2].(0010,0030)[3].(0010,0040)"))); 2415 DicomPath::Parse("(0010,0010)[1].(0010,0020)[2].(0010,0030)[3].(0010,0040)")));
2391 ASSERT_FALSE(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)[2].(0010,0020)[2].(0010,0030)"), 2416 ASSERT_FALSE(MyIsMatch(DicomPath::Parse("(0010,0010)[2].(0010,0020)[2].(0010,0030)"),
2392 DicomPath::Parse("(0010,0010)[1].(0010,0020)[2].(0010,0030)[3].(0010,0040)"))); 2417 DicomPath::Parse("(0010,0010)[1].(0010,0020)[2].(0010,0030)[3].(0010,0040)")));
2393 } 2418 }
2394 2419
2395 2420
2396 2421
2397 TEST(ParsedDicomFile, DicomPath) 2422 TEST(ParsedDicomFile, DicomPath)