diff --git a/Modules/RegistrationOntology/src/mitkLesionPropagation.cpp b/Modules/RegistrationOntology/src/mitkLesionPropagation.cpp index f5086eb254..08aa868ab7 100644 --- a/Modules/RegistrationOntology/src/mitkLesionPropagation.cpp +++ b/Modules/RegistrationOntology/src/mitkLesionPropagation.cpp @@ -1,228 +1,228 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkLesionPropagation.h" // semantic relations module #include #include #include // mitk core #include #include // DICOMQI module #include // multilabel module #include mitk::LesionPropagation::LesionPropagation(DataStorage* dataStorage) : m_DataStorage(dataStorage) , m_SemanticRelationsDataStorageAccess(std::make_unique(dataStorage)) , m_SemanticRelationsIntegration(std::make_unique()) { // nothing here } mitk::BaseData* mitk::LesionPropagation::FindClosestSegmentationMask(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& sourceLesion, DataNode* targetImage) { auto allImagesOfLesion = m_SemanticRelationsDataStorageAccess->GetAllImagesOfLesion(caseID, sourceLesion); SemanticRelationsDataStorageAccess::DataNodeVector sameControlPointImages; SemanticRelationsDataStorageAccess::DataNodeVector sameInformationTypeImages; SemanticRelationsDataStorageAccess::DataNodeVector noRelation; for (const auto& image : allImagesOfLesion) { bool sameControlPoint = CheckControlPoint(image, targetImage); bool sameInformationType = CheckInformationType(image, targetImage); if(sameControlPoint && !sameInformationType) { // lesion image and target image are in the same control point relation group sameControlPointImages.push_back(image); } if (sameInformationType && !sameControlPoint) { // lesion image and target image are in the same information type relation group sameInformationTypeImages.push_back(image); } if (!sameControlPoint && !sameInformationType) { // lesion image and target image are none of the above relation groups noRelation.push_back(image); } } // sorted all lesion images according to the target image's relation group for (const auto& image : sameControlPointImages) { // check if any image in the same control point relation group is registered to the target image bool registered = CheckRegistration(image, targetImage); if (registered) { auto segmentationNode = GetSegmentationFromRelatedImage(sourceLesion, image); if (nullptr != segmentationNode) { return segmentationNode->GetData(); } } } for (const auto& image : sameInformationTypeImages) { bool registered = CheckRegistration(image, targetImage); if (registered) { // check if any image in the same information type relation group is registered to the target image auto segmentationNode = GetSegmentationFromRelatedImage(sourceLesion, image); if (nullptr != segmentationNode) { return segmentationNode->GetData(); } } } for (const auto& image : noRelation) { bool registered = CheckRegistration(image, targetImage); if (registered) { // need special registration check for non-related images auto segmentationNode = GetSegmentationFromRelatedImage(sourceLesion, image); if (nullptr != segmentationNode) { return segmentationNode->GetData(); } } } return nullptr; } mitk::DataNode::Pointer mitk::LesionPropagation::PropagateSegmentationMask(const SemanticTypes::CaseID& caseID, BaseData* segmentationMask, DataNode* targetImage) { if (m_DataStorage.IsExpired()) { return nullptr; } if (nullptr == targetImage) { return nullptr; } BaseData* targetImageData = targetImage->GetData(); if (nullptr == targetImageData) { return nullptr; } auto dataStorage = m_DataStorage.Lock(); // clone the segmentation image / the base data Image::Pointer segmentation = dynamic_cast(segmentationMask); auto labelSetImage = segmentation->Clone(); // copy DICOM information from the target image to the new segmentation - DICOMQIPropertyHandler::DeriveDICOMSourceProperties(targetImageData, segmentationMask); + DICOMQIPropertyHandler::DeriveDICOMSourceProperties(targetImageData, labelSetImage); // DICOM tag is "SeriesInstanceUID" - needs to be removed to define a new tag with UID std::string nodeIDPropertyKey = GeneratePropertyNameForDICOMTag(0x0020, 0x000e); labelSetImage->RemoveProperty(nodeIDPropertyKey); auto newSegmentationNode = DataNode::New(); newSegmentationNode->SetData(labelSetImage); newSegmentationNode->SetProperty("name", StringProperty::New("PropagatedLesion")); newSegmentationNode->SetProperty("binary", BoolProperty::New(true)); dataStorage->Add(newSegmentationNode, targetImage); return newSegmentationNode; } bool mitk::LesionPropagation::CheckControlPoint(const DataNode* lesionImage, const DataNode* targetImage) { auto lesionImageControlPoint = SemanticRelationsInference::GetControlPointOfImage(lesionImage); auto targetImageControlPoint = SemanticRelationsInference::GetControlPointOfImage(targetImage); if (lesionImageControlPoint.UID == targetImageControlPoint.UID) { return true; } return false; } bool mitk::LesionPropagation::CheckInformationType(const DataNode* lesionImage, const DataNode* targetImage) { auto lesionImageInformationType = SemanticRelationsInference::GetInformationTypeOfImage(lesionImage); auto targetImageInformationType = SemanticRelationsInference::GetInformationTypeOfImage(targetImage); if (lesionImageInformationType == targetImageInformationType) { return true; } return false; } mitk::DataNode* mitk::LesionPropagation::GetSegmentationFromRelatedImage(const SemanticTypes::Lesion& sourceLesion, const DataNode* lesionImage) { // found an image of the source lesion that is registered to the target image // could clone the mask and copy it to the target image // need to find the correct segmentation amongst many segmentations of the source image SemanticRelationsDataStorageAccess::DataNodeVector allSpecificSegmentations; try { allSpecificSegmentations = m_SemanticRelationsDataStorageAccess->GetAllSpecificSegmentations(mitk::GetCaseIDFromDataNode(lesionImage), SemanticRelationsInference::GetControlPointOfImage(lesionImage), SemanticRelationsInference::GetInformationTypeOfImage(lesionImage)); } catch (const SemanticRelationException&) { return nullptr; } auto lambda = [this, &sourceLesion](const DataNode* specificSegmentation) { try { auto representedLesion = SemanticRelationsInference::GetLesionOfSegmentation(specificSegmentation); return sourceLesion.UID == representedLesion.UID; } catch (const SemanticRelationException&) { return false; } }; auto segmentation = std::find_if(allSpecificSegmentations.begin(), allSpecificSegmentations.end(), lambda); // return segmentation as image mask of source lesion if (segmentation != allSpecificSegmentations.end()) { return *segmentation; } return nullptr; } bool mitk::LesionPropagation::CheckRegistration(const DataNode* lesionImage, const DataNode* targetImage) { // #TODO // for now we will always return true // registration ontology is not fully implemented return true; }