25 return m_PurposeTag.empty();
30 return ruleID == this->
GetRuleID() || (
IsAbstract() && ruleID.find(
"SourceImageRelation ") == 0);
35 return "SourceImageRelation " + m_PurposeTag;
50 return m_DestinationRole;
55 auto node =
dynamic_cast<const DataNode*
>(owner);
57 auto image =
nullptr != node
58 ?
dynamic_cast<const Image*
>(node->GetData())
59 : dynamic_cast<const Image*>(owner);
61 return image !=
nullptr;
70 : m_PurposeTag(
""), m_DisplayName(
"Abstract image to image relation"), m_SourceRole(
"derived data"), m_DestinationRole(
"source image")
78 purposeTag, displayName,
"derived data",
"source image"){};
81 const std::string &displayName,
82 const std::string &sourceRole,
83 const std::string &destinationRole)
84 : m_PurposeTag(purposeTag), m_DisplayName(displayName), m_SourceRole(sourceRole), m_DestinationRole(destinationRole){};
94 auto regEx = std::regex(itemRegExStr);
100 for (
const auto &key : keys)
102 if (std::regex_match(key, regEx))
105 if (sequItemProp.IsNotNull())
107 auto finding = std::find(std::cbegin(relevantReferenceIndices), std::cend(relevantReferenceIndices), sequItemProp->GetValueAsString());
108 if (finding != std::cend(relevantReferenceIndices))
114 result.push_back(instanceID);
127 std::vector<std::string> result;
135 if (destInstanceUIDProp.IsNull())
145 auto regEx = std::regex(sourceRegExStr);
147 std::vector<std::string> keys;
152 for (
const auto &key : keys)
154 if (std::regex_match(key, regEx))
157 if (destination==
nullptr || *refUIDProp == *destInstanceUIDProp)
160 auto currentKeyPathSelection = currentKeyPath.GetNode(2).selection;
165 if (this->
IsAbstract() || (purposeProp.IsNotNull() && purposeProp->GetValueAsString() == this->m_PurposeTag))
167 result.push_back(std::to_string(currentKeyPathSelection));
183 return !relevantReferences.empty();
187 for (
auto referenceIndex : relevantReferences)
193 if (purposeProp.IsNotNull() && purposeProp->GetValueAsString() == this->m_PurposeTag)
210 std::mutex sequenceItemCreationLock;
216 std::lock_guard<std::mutex> guard(sequenceItemCreationLock);
221 std::vector<PropertyKeyPath::ItemSelectionIndex> instanceIDs;
227 auto regEx = std::regex(regExStr);
228 std::smatch instance_matches;
234 for (
const auto &key : keys)
236 if (std::regex_search(key, instance_matches, regEx))
238 if (instance_matches.size()>1)
240 instanceIDs.push_back(std::stoi(instance_matches[1]));
248 std::sort(instanceIDs.begin(), instanceIDs.end());
249 if (!instanceIDs.empty())
251 newID = instanceIDs.back()+1;
275 if (destInstanceUIDProp.IsNotNull() && destClassUIDProp.IsNotNull())
278 std::string newSelectionIndexStr;
279 if (!existingRefs.empty())
281 newSelectionIndexStr = existingRefs[0];
299 newSelectionIndexStr = std::to_string(newSelectionIndex);
307 MITK_DEBUG <<
"Cannot connect SourceImageRelationRule on data layer. Passed destination does not have properties for DICOM SOP Instance UIDs(0x0008, 0x0018) and DICOM SOP Class UID(0x0008, 0x0016)";
316 if (imageRefProp.IsNotNull())
318 auto deletedImageRefSequenceIndex = imageRefProp->GetValueAsString();
321 std::sort(refs.begin(), refs.end());
323 for (
auto refIndexStr : refs)
325 auto refIndex = std::stoi(refIndexStr);
327 if (refIndex >= std::stoi(deletedImageRefSequenceIndex))
340 for (
const auto &key : keys)
342 if (key.find(prefix) == 0)
344 if (refIndexStr != deletedImageRefSequenceIndex)
348 newPath.GetNode(2).selection = refIndex - 1;
356 if (std::regex_match(key, regEx))
359 if (imageSequenceItemProp->GetValueAsString() == std::to_string(refIndex))
373 itk::LightObject::Pointer result =
Self::New(this->m_PurposeTag, this->m_DisplayName, this->m_SourceRole, this->m_DestinationRole).GetPointer();
bool HasImplicitDataRelation(const IPropertyProvider *source, const IPropertyProvider *destination) const override
bool IsDestinationCandidate(const IPropertyProvider *owner) const override
MITKCORE_EXPORT std::string PropertyKeyPathToPropertyName(const PropertyKeyPath &tagPath)
std::string InstanceIDType
bool IsAbstract() const override
PropertyRelationRuleBase::RuleIDType RuleIDType
std::string MITKCORE_EXPORT GeneratePropertyNameForDICOMTag(unsigned int group, unsigned int element)
std::string GetSourceRoleName() const override
itk::LightObject::Pointer InternalClone() const override
PropertyKeyPath & AddElement(const ElementNameType &name)
virtual BaseProperty::ConstPointer GetConstProperty(const std::string &propertyKey, const std::string &contextName="", bool fallBackOnDefaultContext=true) const =0
Get property by its key.
PropertyRelationRuleBase::RelationUIDType RelationUIDType
PropertyKeyPath & AddSelection(const ElementNameType &name, ItemSelectionIndex index)
RelationUIDType Connect(IPropertyOwner *source, const IPropertyProvider *destination) const
std::string GetRIIPropertyRegEx(const std::string propName="", const InstanceIDType &instanceID="") const
InstanceIDVectorType GetInstanceID_datalayer(const IPropertyProvider *source, const IPropertyProvider *destination) const override
static PropertyKeyPath GetRootKeyPath()
SourceImageRelationRule()
virtual void RemoveProperty(const std::string &propertyKey, const std::string &contextName="", bool fallBackOnDefaultContext=false)=0
Removes a property. If the property does not exist, nothing will be done.
std::string GetDestinationRoleName() const override
Image class for storing images.
MITKCORE_EXPORT PropertyKeyPath PropertyNameToPropertyKeyPath(const std::string &propertyName)
RelationUIDType Connect(Image *source, const Image *destination) const
std::vcl_size_t ItemSelectionIndex
mitk::Image::Pointer image
static std::vector< std::string > GetPropertyKeys(const mitk::IPropertyProvider *owner)
RuleIDType GetRuleID() const override
void Disconnect_datalayer(IPropertyOwner *source, const InstanceIDType &instanceID) const override
static InstanceIDType GetInstanceIDByPropertyName(const std::string propName)
RuleIDType GetRuleIDByInstanceID(const IPropertyProvider *source, const InstanceIDType &instanceID) const
PropertyKeyPath::ItemSelectionIndex CreateNewSourceImageSequenceItem(IPropertyOwner *source) const
PropertyKeyPath & AddAnyElement()
PropertyRelationRuleBase::InstanceIDVectorType InstanceIDVectorType
std::string GetDisplayName() const override
std::vector< InstanceIDType > InstanceIDVectorType
std::vector< std::string > GetReferenceSequenceIndices(const IPropertyProvider *source, const IPropertyProvider *destination=nullptr) const
Class that can be used to specify nested or wild carded property keys. E.g. for the use in context of...
void Connect_datalayer(IPropertyOwner *source, const IPropertyProvider *destination, const InstanceIDType &instanceID) const override
virtual BaseProperty * GetNonConstProperty(const std::string &propertyKey, const std::string &contextName="", bool fallBackOnDefaultContext=true)=0
Get property by its key.
MITKCORE_EXPORT std::string PropertyKeyPathToPropertyRegEx(const PropertyKeyPath &tagPath)
bool IsSupportedRuleID(const RuleIDType &ruleID) const override
Class for nodes of the DataTree.
virtual void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName="", bool fallBackOnDefaultContext=false)=0
Add new or change existent property.
PropertyKeyPath & AddAnySelection(const ElementNameType &name)