Mercurial > hg > orthanc
comparison OrthancFramework/Sources/DicomFormat/DicomMap.cpp @ 5044:6fed78e13233
Refactored DicomMap to handle sequences when needed
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 28 Jun 2022 17:45:09 +0200 |
parents | 1c08cd68250a |
children | ea9e2680da6f |
comparison
equal
deleted
inserted
replaced
5043:ec5c203a97ea | 5044:6fed78e13233 |
---|---|
355 } | 355 } |
356 | 356 |
357 void DicomMap::SetValue(uint16_t group, uint16_t element, const std::string &str, bool isBinary) | 357 void DicomMap::SetValue(uint16_t group, uint16_t element, const std::string &str, bool isBinary) |
358 { | 358 { |
359 SetValueInternal(group, element, new DicomValue(str, isBinary)); | 359 SetValueInternal(group, element, new DicomValue(str, isBinary)); |
360 } | |
361 | |
362 void DicomMap::SetValue(const DicomTag& tag, const Json::Value& value) | |
363 { | |
364 SetValueInternal(tag.GetGroup(), tag.GetElement(), new DicomValue(value)); | |
360 } | 365 } |
361 | 366 |
362 bool DicomMap::HasTag(uint16_t group, uint16_t element) const | 367 bool DicomMap::HasTag(uint16_t group, uint16_t element) const |
363 { | 368 { |
364 return HasTag(DicomTag(group, element)); | 369 return HasTag(DicomTag(group, element)); |
1326 return value->ParseDouble(result); | 1331 return value->ParseDouble(result); |
1327 } | 1332 } |
1328 } | 1333 } |
1329 | 1334 |
1330 | 1335 |
1331 void DicomMap::FromDicomAsJson(const Json::Value& dicomAsJson, bool append) | 1336 void DicomMap::FromDicomAsJson(const Json::Value& dicomAsJson, bool append, bool parseSequences) |
1332 { | 1337 { |
1333 if (dicomAsJson.type() != Json::objectValue) | 1338 if (dicomAsJson.type() != Json::objectValue) |
1334 { | 1339 { |
1335 throw OrthancException(ErrorCode_BadFileFormat); | 1340 throw OrthancException(ErrorCode_BadFileFormat); |
1336 } | 1341 } |
1369 else | 1374 else |
1370 { | 1375 { |
1371 SetValue(tag, value["Value"].asString(), false /* not binary */); | 1376 SetValue(tag, value["Value"].asString(), false /* not binary */); |
1372 } | 1377 } |
1373 } | 1378 } |
1379 else if (value["Type"] == "Sequence" && parseSequences) | |
1380 { | |
1381 if (value["Value"].type() != Json::arrayValue) | |
1382 { | |
1383 printf("%s", dicomAsJson.toStyledString().c_str()); | |
1384 throw OrthancException(ErrorCode_CorruptedFile); | |
1385 } | |
1386 else | |
1387 { | |
1388 SetValue(tag, value["Value"]); | |
1389 } | |
1390 } | |
1374 } | 1391 } |
1375 } | 1392 } |
1376 | 1393 |
1377 | 1394 |
1378 void DicomMap::Merge(const DicomMap& other) | 1395 void DicomMap::Merge(const DicomMap& other) |
1433 } | 1450 } |
1434 | 1451 |
1435 return true; | 1452 return true; |
1436 } | 1453 } |
1437 | 1454 |
1438 #if ORTHANC_ENABLE_DCMTK == 1 | 1455 void DicomMap::ExtractSequences(DicomMap& result) const |
1439 void DicomMap::ExtractSequences(std::set<DicomTag>& sequences, const std::set<DicomTag>& tags) | 1456 { |
1440 { | 1457 result.Clear(); |
1441 sequences.clear(); | 1458 |
1442 | 1459 for (Content::const_iterator it = content_.begin(); it != content_.end(); ++it) |
1443 for (std::set<DicomTag>::const_iterator it = tags.begin(); it != tags.end(); ++it) | 1460 { |
1444 { | 1461 if (it->second->IsSequence()) |
1445 ValueRepresentation vr = FromDcmtkBridge::LookupValueRepresentation(*it); | 1462 { |
1446 if (vr == ValueRepresentation_Sequence) | 1463 result.SetValue(it->first, it->second->GetSequenceContent()); |
1447 { | 1464 } |
1448 sequences.insert(*it); | 1465 } |
1449 } | 1466 } |
1450 } | |
1451 } | |
1452 #endif | |
1453 | 1467 |
1454 void DicomMap::Serialize(Json::Value& target) const | 1468 void DicomMap::Serialize(Json::Value& target) const |
1455 { | 1469 { |
1456 target = Json::objectValue; | 1470 target = Json::objectValue; |
1457 | 1471 |
1671 | 1685 |
1672 content_ = kept; | 1686 content_ = kept; |
1673 } | 1687 } |
1674 | 1688 |
1675 | 1689 |
1690 void DicomMap::RemoveSequences() | |
1691 { | |
1692 Content kept; | |
1693 | |
1694 for (Content::iterator it = content_.begin(); it != content_.end(); ++it) | |
1695 { | |
1696 assert(it->second != NULL); | |
1697 | |
1698 if (!it->second->IsSequence()) | |
1699 { | |
1700 kept[it->first] = it->second; | |
1701 } | |
1702 else | |
1703 { | |
1704 delete it->second; | |
1705 } | |
1706 } | |
1707 | |
1708 content_ = kept; | |
1709 } | |
1710 | |
1676 void DicomMap::DumpMainDicomTags(Json::Value& target, | 1711 void DicomMap::DumpMainDicomTags(Json::Value& target, |
1677 ResourceType level) const | 1712 ResourceType level) const |
1678 { | 1713 { |
1679 const std::set<DicomTag>& mainDicomTags = DicomMap::MainDicomTagsConfiguration::GetInstance().GetMainDicomTagsByLevel(level); | 1714 const std::set<DicomTag>& mainDicomTags = DicomMap::MainDicomTagsConfiguration::GetInstance().GetMainDicomTagsByLevel(level); |
1680 | 1715 |