27 std::string GenerateRegExForNumber(
unsigned int tagNumber)
29 std::ostringstream resultRegEx;
31 std::ostringstream hexNumber;
32 hexNumber << std::hex << tagNumber;
33 std::regex reg_character(
"([a-f]+)");
34 if (std::regex_search(hexNumber.str(), reg_character))
39 << std::setw(4) << std::setfill(
'0') << std::hex << tagNumber
41 << std::setw(4) << std::setfill(
'0') << std::hex << std::uppercase << tagNumber << std::nouppercase
47 resultRegEx << std::setw(4) << std::setfill(
'0') << std::hex << tagNumber;
50 return resultRegEx.str();
69 if (!(this->tag == right.
tag))
return false;
70 if (this->type != right.
type)
return false;
71 if (this->selection != right.
selection)
return false;
79 if (type == NodeType::AnyElement || right.
type == NodeType::AnyElement)
83 else if (tag == right.
tag && type != NodeType::Invalid && right.
type != NodeType::Invalid)
85 if (type == NodeType::Element && right.
type == NodeType::Element)
89 else if(selection == right.
selection || type == NodeType::AnySelection || right.
type == NodeType::AnySelection)
147 mitkThrow() <<
"Error. Cannot return info of path node. Node index is out of bound. Index: " << index <<
"; Path: " << this->
ToStr();
159 mitkThrow() <<
"Error. Cannot return info of path node. Node index is out of bound. Index: " << index <<
"; Path: " << this->
ToStr();
197 std::ostringstream nameStream;
199 if (this->
Size() == 0)
return nameStream.str();
217 << std::setw(4) << std::setfill(
'0') << std::hex << std::uppercase << node.tag.GetGroup() << std::nouppercase
219 << std::setw(4) << std::setfill(
'0') << std::hex << std::uppercase << node.tag.GetElement() << std::nouppercase
224 nameStream <<
"[" << node.selection <<
"]";
233 nameStream <<
"INVALID_NODE";
237 return nameStream.str();
255 if (rightIter == rightEnd)
return false;
257 if (leftPos.tag.GetElement() < rightIter->tag.GetElement())
return true;
258 if (rightIter->tag.GetElement() < leftPos.tag.GetElement())
return false;
260 if (leftPos.tag.GetGroup() < rightIter->tag.GetGroup())
return true;
261 if (rightIter->tag.GetGroup()< leftPos.tag.GetGroup())
return false;
263 if (leftPos.type < rightIter->type)
return true;
264 if (rightIter->type< leftPos.type)
return false;
266 if (leftPos.selection < rightIter->selection)
return true;
267 if (rightIter->selection< leftPos.selection)
return false;
270 return rightIter != rightEnd;
284 if (&path ==
this)
return *
this;
324 std::istringstream f(pathStr);
327 while (getline(f, subStr,
'.'))
337 std::regex reg_element(
"\\(([A - Fa - f\\d]{4}),([A - Fa - f\\d]{4})\\)");
338 std::regex reg_anySelection(
"\\(([A - Fa - f\\d]{4}),([A - Fa - f\\d]{4})\\)\\[\\*\\]");
339 std::regex reg_Selection(
"\\(([A - Fa - f\\d]{4}),([A - Fa - f\\d]{4})\\)\\[(\\d+)\\]");
341 if (std::regex_match(subStr, sm, reg_anySelection))
344 info.
tag =
DICOMTag(std::stoul(sm[1],
nullptr, 16), std::stoul(sm[2],
nullptr, 16));
346 else if (std::regex_match(subStr, sm, reg_Selection))
349 info.
tag =
DICOMTag(std::stoul(sm[1],
nullptr, 16), std::stoul(sm[2],
nullptr, 16));
352 else if (std::regex_match(subStr, sm, reg_element))
355 info.
tag =
DICOMTag(std::stoul(sm[1],
nullptr, 16), std::stoul(sm[2],
nullptr, 16));
358 result.push_back(info);
401 NodeInfoVectorType::const_iterator leftPos = left.
GetNodes().cbegin();
402 NodeInfoVectorType::const_iterator rightPos = right.
GetNodes().cbegin();
403 NodeInfoVectorType::const_iterator leftEnd = left.
GetNodes().cend();
404 NodeInfoVectorType::const_iterator rightEnd = right.
GetNodes().cend();
406 while (leftPos != leftEnd && rightPos != rightEnd)
408 if (!leftPos->Matches(*rightPos))
break;
413 if (leftPos == leftEnd && rightPos == rightEnd)
return true;
425 std::ostringstream nameStream;
427 nameStream <<
"DICOM";
429 for (
const auto& node : tagPath.
GetNodes())
435 nameStream <<
"([A-Fa-f\\d]{4})\\.([A-Fa-f\\d]{4})";
439 nameStream << GenerateRegExForNumber(node.tag.GetGroup())
441 << GenerateRegExForNumber(node.tag.GetElement());
445 nameStream <<
"\\.\\[" << node.selection <<
"\\]";
449 nameStream <<
"\\.\\[(\\d*)\\]";
454 nameStream <<
"INVALIDNODE";
458 return nameStream.str();
463 std::ostringstream nameStream;
465 nameStream <<
"DICOM";
467 for (
const auto& node : tagPath.
GetNodes())
473 nameStream <<
"([A-Fa-f\\d]{4})_([A-Fa-f\\d]{4})";
477 nameStream << GenerateRegExForNumber(node.tag.GetGroup())
479 << GenerateRegExForNumber(node.tag.GetElement());
483 nameStream <<
"_\\[" << node.selection <<
"\\]";
487 nameStream <<
"_\\[(\\d*)\\]";
492 nameStream <<
"INVALIDNODE";
496 return nameStream.str();
501 std::ostringstream nameStream;
503 nameStream <<
"DICOM";
505 int captureGroup = 1;
507 for (
const auto& node : tagPath.
GetNodes())
513 nameStream <<
"$" << captureGroup++;
514 nameStream <<
"_$" << captureGroup++;
518 nameStream << std::setw(4) << std::setfill(
'0') << std::hex << std::uppercase << node.tag.GetGroup() << std::nouppercase <<
"_"
519 << std::setw(4) << std::setfill(
'0') << std::hex << std::uppercase << node.tag.GetElement();
523 nameStream <<
"_[" << node.selection <<
"]";
527 nameStream <<
"_[$" << captureGroup++ <<
"]";
532 nameStream <<
"INVALID_NODE";
536 return nameStream.str();
541 std::ostringstream nameStream;
543 nameStream <<
"DICOM";
545 int captureGroup = 1;
547 for (
const auto& node : tagPath.
GetNodes())
553 nameStream <<
"$" << captureGroup++;
554 nameStream <<
".$" << captureGroup++;
558 nameStream << std::setw(4) << std::setfill(
'0') << std::hex << std::uppercase << node.tag.GetGroup() << std::nouppercase <<
"."
559 << std::setw(4) << std::setfill(
'0') << std::hex << std::uppercase << node.tag.GetElement();
563 nameStream <<
".[" << node.selection <<
"]";
567 nameStream <<
".[$"<<captureGroup++<<
"]";
572 nameStream <<
"INVALID_NODE";
576 return nameStream.str();
584 mitkThrow() <<
"Cannot convert DICOMTagPath into DCMTK search path. Path has element wild cards. Path: " << tagPath.
ToStr();
587 return tagPath.
ToStr();
596 std::istringstream f(propertyName);
599 if (getline(f, subStr,
'.'))
601 if (subStr !=
"DICOM")
606 unsigned int nrCount = 0;
607 unsigned long group = 0;
608 unsigned long element = 0;
610 while (getline(f, subStr,
'.'))
619 else if (nrCount != 0)
628 std::regex reg_element(
"([A-Fa-f\\d]{4})");
629 std::regex reg_anySelection(
"\\[\\*\\]");
630 std::regex reg_Selection(
"\\[(\\d+)\\]");
632 if (std::regex_match(subStr, sm, reg_anySelection))
644 else if (std::regex_match(subStr, sm, reg_Selection))
656 else if (std::regex_match(subStr, sm, reg_element))
660 group = std::stoul(sm[1],
nullptr, 16);
663 else if (nrCount == 1)
665 element = std::stoul(sm[1],
nullptr, 16);
668 else if (nrCount == 2)
671 group = std::stoul(sm[1],
nullptr, 16);
695 std::ostringstream nameStream;
697 nameStream <<
"DICOM";
699 for (
const auto& node : tagPath.
GetNodes())
709 nameStream << std::setw(4) << std::setfill(
'0') << std::hex << std::uppercase << node.tag.GetGroup() << std::nouppercase <<
"."
710 << std::setw(4) << std::setfill(
'0') << std::hex << std::uppercase << node.tag.GetElement();
714 nameStream <<
".[" << node.selection <<
"]";
718 nameStream <<
".[*]";
723 nameStream <<
"INVALID_NODE";
727 return nameStream.str();
DICOMTagPath & AddElement(unsigned int group, unsigned int element)
DICOMTagPath & AddAnySelection(unsigned int group, unsigned int element)
bool operator==(const DICOMTagPath &path) const
Class is used to identify (nested) attributes in a DICOM dataset. In contrast to the class DICOMTag...
MITKCORE_EXPORT std::ostream & operator<<(std::ostream &o, DataNode::Pointer &dtn)
bool Equals(const DICOMTagPath &path) const
NodeInfoVectorType m_NodeInfos
MITKDICOMREADER_EXPORT std::string DICOMTagPathToPersistenceKeyRegEx(const DICOMTagPath &tagPath)
DICOMTagPath & AddAnyElement()
Representation of a DICOM tag.
bool operator==(const NodeInfo &right) const
std::vector< NodeInfo > NodeInfoVectorType
DataCollection - Class to facilitate loading/accessing structured data.
std::string ToStr() const
PathIndexType AddNode(const NodeInfo &newNode)
static void info(const char *fmt,...)
MITKDICOMREADER_EXPORT std::string DICOMTagPathToPersistenceNameTemplate(const DICOMTagPath &tagPath)
const NodeInfoVectorType & GetNodes() const
MITKDICOMREADER_EXPORT std::string DICOMTagPathToPropertyName(const DICOMTagPath &tagPath)
static bool DICOMTagPathesMatch(const DICOMTagPath &left, const DICOMTagPath &right)
NodeInfoVectorType::size_type PathIndexType
PathIndexType Size() const
DICOMTagPath & FromStr(const std::string &pathStr)
const NodeInfo & GetNode(const PathIndexType &index) const
bool operator<(const DICOMTagPath &right) const
MITKDICOMREADER_EXPORT std::string DICOMTagPathToPersistenceKeyTemplate(const DICOMTagPath &tagPath)
DICOMTagPath & operator=(const DICOMTagPath &path)
MITKDICOMREADER_EXPORT std::string DICOMTagPathToPropertyRegEx(const DICOMTagPath &tagPath)
bool HasItemSelectionWildcardsOnly() const
DICOMTagPath & AddSelection(unsigned int group, unsigned int element, ItemSelectionIndex index)
bool Matches(const NodeInfo &right) const
ItemSelectionIndex selection
MITKDICOMREADER_EXPORT std::string DICOMTagPathToDCMTKSearchPath(const DICOMTagPath &tagPath)
MITKDICOMREADER_EXPORT DICOMTagPath PropertyNameToDICOMTagPath(const std::string &propertyName)
NodeInfo & GetFirstNode()