23 std::string GenerateRegExForNumber(
unsigned int tagNumber)
25 std::ostringstream resultRegEx;
27 std::ostringstream hexNumber;
28 hexNumber << std::hex << tagNumber;
29 std::regex reg_character(
"([a-f]+)");
30 if (std::regex_search(hexNumber.str(), reg_character))
35 << std::setw(4) << std::setfill(
'0') << std::hex << tagNumber
37 << std::setw(4) << std::setfill(
'0') << std::hex << std::uppercase << tagNumber << std::nouppercase
43 resultRegEx << std::setw(4) << std::setfill(
'0') << std::hex << tagNumber;
46 return resultRegEx.str();
65 if (!(this->
tag == right.
tag))
return false;
66 if (this->
type != right.
type)
return false;
143 mitkThrow() <<
"Error. Cannot return info of path node. Node index is out of bound. Index: " << index <<
"; Path: " << this->
ToStr();
155 mitkThrow() <<
"Error. Cannot return info of path node. Node index is out of bound. Index: " << index <<
"; Path: " << this->
ToStr();
193 std::ostringstream nameStream;
195 if (this->
Size() == 0)
return nameStream.str();
213 << std::setw(4) << std::setfill(
'0') << std::hex << std::uppercase << node.tag.GetGroup() << std::nouppercase
215 << std::setw(4) << std::setfill(
'0') << std::hex << std::uppercase << node.tag.GetElement() << std::nouppercase
220 nameStream <<
"[" << node.selection <<
"]";
229 nameStream <<
"INVALID_NODE";
233 return nameStream.str();
251 if (rightIter == rightEnd)
return false;
253 if (leftPos.tag.GetElement() < rightIter->tag.GetElement())
return true;
254 if (rightIter->tag.GetElement() < leftPos.tag.GetElement())
return false;
256 if (leftPos.tag.GetGroup() < rightIter->tag.GetGroup())
return true;
257 if (rightIter->tag.GetGroup()< leftPos.tag.GetGroup())
return false;
259 if (leftPos.type < rightIter->type)
return true;
260 if (rightIter->type< leftPos.type)
return false;
262 if (leftPos.selection < rightIter->selection)
return true;
263 if (rightIter->selection< leftPos.selection)
return false;
266 return rightIter != rightEnd;
280 if (&path ==
this)
return *
this;
320 std::istringstream f(pathStr);
323 while (getline(f, subStr,
'.'))
333 std::regex reg_element(
"\\(([A - Fa - f\\d]{4}),([A - Fa - f\\d]{4})\\)");
334 std::regex reg_anySelection(
"\\(([A - Fa - f\\d]{4}),([A - Fa - f\\d]{4})\\)\\[\\*\\]");
335 std::regex reg_Selection(
"\\(([A - Fa - f\\d]{4}),([A - Fa - f\\d]{4})\\)\\[(\\d+)\\]");
337 if (std::regex_match(subStr, sm, reg_anySelection))
340 info.
tag =
DICOMTag(std::stoul(sm[1],
nullptr, 16), std::stoul(sm[2],
nullptr, 16));
342 else if (std::regex_match(subStr, sm, reg_Selection))
345 info.
tag =
DICOMTag(std::stoul(sm[1],
nullptr, 16), std::stoul(sm[2],
nullptr, 16));
348 else if (std::regex_match(subStr, sm, reg_element))
351 info.
tag =
DICOMTag(std::stoul(sm[1],
nullptr, 16), std::stoul(sm[2],
nullptr, 16));
354 result.push_back(info);
397 auto leftPos = left.
GetNodes().cbegin();
398 auto rightPos = right.
GetNodes().cbegin();
399 auto leftEnd = left.
GetNodes().cend();
400 auto rightEnd = right.
GetNodes().cend();
402 while (leftPos != leftEnd && rightPos != rightEnd)
404 if (!leftPos->Matches(*rightPos))
break;
409 if (leftPos == leftEnd && rightPos == rightEnd)
return true;
421 std::ostringstream nameStream;
423 nameStream <<
"DICOM";
425 for (
const auto& node : tagPath.
GetNodes())
431 nameStream <<
"([A-Fa-f\\d]{4})\\.([A-Fa-f\\d]{4})";
435 nameStream << GenerateRegExForNumber(node.tag.GetGroup())
437 << GenerateRegExForNumber(node.tag.GetElement());
441 nameStream <<
"\\.\\[" << node.selection <<
"\\]";
445 nameStream <<
"\\.\\[(\\d*)\\]";
450 nameStream <<
"INVALIDNODE";
454 return nameStream.str();
459 std::ostringstream nameStream;
461 nameStream <<
"DICOM";
463 for (
const auto& node : tagPath.
GetNodes())
469 nameStream <<
"([A-Fa-f\\d]{4})_([A-Fa-f\\d]{4})";
473 nameStream << GenerateRegExForNumber(node.tag.GetGroup())
475 << GenerateRegExForNumber(node.tag.GetElement());
479 nameStream <<
"_\\[" << node.selection <<
"\\]";
483 nameStream <<
"_\\[(\\d*)\\]";
488 nameStream <<
"INVALIDNODE";
492 return nameStream.str();
497 std::ostringstream nameStream;
499 nameStream <<
"DICOM";
501 int captureGroup = 1;
503 for (
const auto& node : tagPath.
GetNodes())
509 nameStream <<
"$" << captureGroup++;
510 nameStream <<
"_$" << captureGroup++;
514 nameStream << std::setw(4) << std::setfill(
'0') << std::hex << std::uppercase << node.tag.GetGroup() << std::nouppercase <<
"_" 515 << std::setw(4) << std::setfill(
'0') << std::hex << std::uppercase << node.tag.GetElement();
519 nameStream <<
"_[" << node.selection <<
"]";
523 nameStream <<
"_[$" << captureGroup++ <<
"]";
528 nameStream <<
"INVALID_NODE";
532 return nameStream.str();
537 std::ostringstream nameStream;
539 nameStream <<
"DICOM";
541 int captureGroup = 1;
543 for (
const auto& node : tagPath.
GetNodes())
549 nameStream <<
"$" << captureGroup++;
550 nameStream <<
".$" << captureGroup++;
554 nameStream << std::setw(4) << std::setfill(
'0') << std::hex << std::uppercase << node.tag.GetGroup() << std::nouppercase <<
"." 555 << std::setw(4) << std::setfill(
'0') << std::hex << std::uppercase << node.tag.GetElement();
559 nameStream <<
".[" << node.selection <<
"]";
563 nameStream <<
".[$"<<captureGroup++<<
"]";
568 nameStream <<
"INVALID_NODE";
572 return nameStream.str();
580 mitkThrow() <<
"Cannot convert DICOMTagPath into DCMTK search path. Path has element wild cards. Path: " << tagPath.
ToStr();
583 return tagPath.
ToStr();
592 std::istringstream f(propertyName);
595 if (getline(f, subStr,
'.'))
597 if (subStr !=
"DICOM")
602 unsigned int nrCount = 0;
603 unsigned long group = 0;
604 unsigned long element = 0;
606 while (getline(f, subStr,
'.'))
615 else if (nrCount != 0)
624 std::regex reg_element(
"([A-Fa-f\\d]{4})");
625 std::regex reg_anySelection(
"\\[\\*\\]");
626 std::regex reg_Selection(
"\\[(\\d+)\\]");
628 if (std::regex_match(subStr, sm, reg_anySelection))
640 else if (std::regex_match(subStr, sm, reg_Selection))
652 else if (std::regex_match(subStr, sm, reg_element))
656 group = std::stoul(sm[1],
nullptr, 16);
659 else if (nrCount == 1)
661 element = std::stoul(sm[1],
nullptr, 16);
664 else if (nrCount == 2)
667 group = std::stoul(sm[1],
nullptr, 16);
691 std::ostringstream nameStream;
693 nameStream <<
"DICOM";
695 for (
const auto& node : tagPath.
GetNodes())
705 nameStream << std::setw(4) << std::setfill(
'0') << std::hex << std::uppercase << node.tag.GetGroup() << std::nouppercase <<
"." 706 << std::setw(4) << std::setfill(
'0') << std::hex << std::uppercase << node.tag.GetElement();
710 nameStream <<
".[" << node.selection <<
"]";
714 nameStream <<
".[*]";
719 nameStream <<
"INVALID_NODE";
723 return nameStream.str();
DICOMTagPath & AddElement(unsigned int group, unsigned int element)
bool operator==(const NodeInfo &right) const
DICOMTagPath & AddAnySelection(unsigned int group, unsigned int element)
bool HasItemSelectionWildcardsOnly() const
Class is used to identify (nested) attributes in a DICOM dataset. In contrast to the class DICOMTag...
bool Equals(const DICOMTagPath &path) const
NodeInfoVectorType m_NodeInfos
const NodeInfoVectorType & GetNodes() const
MITKDICOMREADER_EXPORT std::string DICOMTagPathToPersistenceKeyRegEx(const DICOMTagPath &tagPath)
bool operator==(const DICOMTagPath &path) const
DICOMTagPath & AddAnyElement()
Representation of a DICOM tag.
bool operator<(const DICOMTagPath &right) const
std::vector< NodeInfo > NodeInfoVectorType
DataCollection - Class to facilitate loading/accessing structured data.
PathIndexType AddNode(const NodeInfo &newNode)
static void info(const char *fmt,...)
MITKDICOMREADER_EXPORT std::string DICOMTagPathToPersistenceNameTemplate(const DICOMTagPath &tagPath)
MITKDICOMREADER_EXPORT std::string DICOMTagPathToPropertyName(const DICOMTagPath &tagPath)
PathIndexType Size() const
static bool DICOMTagPathesMatch(const DICOMTagPath &left, const DICOMTagPath &right)
NodeInfoVectorType::size_type PathIndexType
DICOMTagPath & FromStr(const std::string &pathStr)
bool Matches(const NodeInfo &right) const
MITKDICOMREADER_EXPORT std::string DICOMTagPathToPersistenceKeyTemplate(const DICOMTagPath &tagPath)
std::string ToStr() const
DICOMTagPath & operator=(const DICOMTagPath &path)
MITKDICOMREADER_EXPORT std::string DICOMTagPathToPropertyRegEx(const DICOMTagPath &tagPath)
const NodeInfo & GetNode(const PathIndexType &index) const
DICOMTagPath & AddSelection(unsigned int group, unsigned int element, ItemSelectionIndex index)
ItemSelectionIndex selection
MITKDICOMREADER_EXPORT std::string DICOMTagPathToDCMTKSearchPath(const DICOMTagPath &tagPath)
MITKDICOMREADER_EXPORT DICOMTagPath PropertyNameToDICOMTagPath(const std::string &propertyName)
MITKCORE_EXPORT std::ostream & operator<<(std::ostream &o, DataNode::Pointer &dtn)
NodeInfo & GetFirstNode()