diff --git a/Modules/SemanticRelations/include/mitkControlPointManager.h b/Modules/SemanticRelations/include/mitkControlPointManager.h index c1fcce9ec8..a9bd1f33bb 100644 --- a/Modules/SemanticRelations/include/mitkControlPointManager.h +++ b/Modules/SemanticRelations/include/mitkControlPointManager.h @@ -1,166 +1,61 @@ /*=================================================================== 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. ===================================================================*/ #ifndef MITKCONTROLPOINTMANAGER_H #define MITKCONTROLPOINTMANAGER_H // semantic relations module #include "mitkSemanticTypes.h" #include // mitk core #include namespace mitk { /* * @brief Provides helper functions that are needed to work with control points. * * These functions help to generate new control points, check for overlapping / containing control points or provide functionality * to find a fitting control point or even extend an already existing control point. */ /* - * @brief Generates a control point from a given vector of data nodes. - * The start point and the end point for the newly generated control point are determined by the - * earliest and the latest date of all the given data nodes, using 'GetStartPoint' and 'GetEndPoint'. - * - * @par dataNodes A vector of data node pointers that contain all the dates, that should be included in the newly generated control point. - */ - MITKSEMANTICRELATIONS_EXPORT SemanticTypes::ControlPoint GenerateControlPoint(const std::vector& dataNodes); - /* * @brief Generates a control point from a given data node. - * The date is extracted from the data node by using the 'DICOMHelper::GetDateFromDataNode'-function. Inside the helper-function - * the randomly generated UID is assigned to the UID of the date. - * 'GenerateControlPoint(const SemanticTypes::Date&)' is used to generate a new control point from this extracted date. + * The date is extracted from the data node by using the 'DICOMHelper::GetDICOMDateFromDataNode'-function. + * 'GenerateControlPoint(const SemanticTypes::TimePoint&)' is used to generate a new control point from this extracted date. * * @par datanode A data node pointer, whose date should be included in the newly generated control point. */ MITKSEMANTICRELATIONS_EXPORT SemanticTypes::ControlPoint GenerateControlPoint(const mitk::DataNode* datanode); /* - * @brief Generates a control point from a given date. - * Providing a single date, this date is assigned to both the start point and the end point of the newly created control point. - * In order to reference both dates as individual instances, a new randomly generated UID is assigned to the UID of the end point. - * - * @par date A single date that is used to define both the start point and the end point of the newly created control point. - */ - MITKSEMANTICRELATIONS_EXPORT SemanticTypes::ControlPoint GenerateControlPoint(const SemanticTypes::Date& date); - /* - * @brief Returns a string that displays the start point and the end point of the given control point in the format "YYYY-MM-DD to YYYY-MM-DD". - * If the end point is the same as the start point, only one date is returned in the format "YYYY-MM-DD". - * This function is used in the GUI to display the dates of a control point as header in the "information-type - control-point"-matrix. + * @brief Returns a string that displays the given control point in the format "YYYY-MM-DD". + * This function is used in the GUI to display the control point as header in the "information-type - control-point"-matrix. * * @par controlPoint The control point to convert into a string. */ MITKSEMANTICRELATIONS_EXPORT std::string GetControlPointAsString(const SemanticTypes::ControlPoint& controlPoint); - /* - * @brief Checks if the date that is extracted from the given data node lies inside the given control point. - * To lie inside the given control point, - * - the extracted date has to be greater or equal to the start point of the control point - * AND - * - the date has to be smaller or equal to the end point of the control point - * - * @par dataNode The data node whose extracted date has to be checked. - * @par controlPoint The control point in which the extracted date of the data node may lie. - * - * @return True, if the extracted date lies inside the given control point; false otherwise. - */ - MITKSEMANTICRELATIONS_EXPORT bool InsideControlPoint(const mitk::DataNode* dataNode, const SemanticTypes::ControlPoint& controlPoint); - /* - * @brief Checks if the given date lies inside the given control point. - * To lie inside the given control point, - * - the date has to be greater or equal to the start point of the control point - * AND - * - the date has to be smaller or equal to the end point of the control point - * - * @par date The date to be checked. - * @par controlPoint The control point in which the date may lie. - * - * @return True, if the date lies inside the given control point; false otherwise. - */ - MITKSEMANTICRELATIONS_EXPORT bool InsideControlPoint(const SemanticTypes::Date& date, const SemanticTypes::ControlPoint& controlPoint); - /* - * @brief Checks if a given control point lies inside another given control point. - * To lie inside another control point, - * - the start point of the first control point has to be greater or equal to the start point of the second control point - * AND - * - the end point of the first control point has to be smaller or equal to the end point of the second control point - * - * @par containedControlPoint The control point that may be contained in the second control point. - * @par containingControlPoint The control point in which the first control point may lie. - * - * @return True, if the first control point lies inside the second control point; false otherwise. - */ - MITKSEMANTICRELATIONS_EXPORT bool InsideControlPoint(const SemanticTypes::ControlPoint& containedControlPoint, const SemanticTypes::ControlPoint& containingControlPoint); - /* - * @brief Checks if a given control point overlaps with a neighboring control point. - * To overlap, - * - the start point of the first control point has to be smaller than the end point of the second control point - * AND - * - the end point of the first control point has to be greater than the start point of the second control point - * - * @par controlPoint The control point to be checked. - * @par neighboringControlPoint The neighboring control point to be checked. - * - * @return True, if both the control points overlap with eatch other; false otherwise. - */ - MITKSEMANTICRELATIONS_EXPORT bool CheckForOverlap(const SemanticTypes::ControlPoint& controlPoint, const SemanticTypes::ControlPoint& neighboringControlPoint); - /* - * @brief Extracts a date from the given data node using the 'DICOMHelper::GetDateFromDataNode'-function. - * If a real date can be extracted, the second 'FindFittingControlPoint'-function is used to find a control point that contains the given date. - * If no date can be extracted from the data node, the function prints an info and returns an empty control point. - * - * @par dataNode A data node pointer, whose extracted date may be found in the given control points. - * @par allControlPoints A vector of control points that may contain the extracted date. - * - * @return The return value of the second 'FindFittingControlPoint'-function. - * An empty control point, if no date can be extracted from the data node. - */ - MITKSEMANTICRELATIONS_EXPORT SemanticTypes::ControlPoint FindFittingControlPoint(const mitk::DataNode* dataNode, std::vector& allControlPoints); - /* - * @brief Tries to find a control point in all the given control points that contains the given date. - * The correct control point may be found by using the 'InsideControlPoint' function with the date, evaluated on each control point. - * - * @par date The date that may be found in the given control points. - * @par allControlPoints A vector of control points that may contain the given date. - * - * @return The control point that contains the given date. An empty control point, if the date is not contained in any of the given control points. - */ - MITKSEMANTICRELATIONS_EXPORT SemanticTypes::ControlPoint FindFittingControlPoint(const SemanticTypes::Date& date, std::vector& allControlPoints); - /* - * @brief Extracts a date from the given data node using the 'DICOMHelper::GetDateFromDataNode'-function. - * If a real date can be extracted, the second 'ExtendClosestControlPoint'-function is used to try to extend a close control point. - * If no date can be extracted from the data node, the function prints an info and returns an empty control point. - * - * @par dataNode A data node pointer, whose extracted date may be used to extend a close control points. - * @par allControlPoints A vector of control points of which the closest control point may be extended by the extracted date. - * - * @return The return value of the second 'ExtendClosestControlPoint'-function. - * An empty control point, if no date can be extracted from the data node. - */ - MITKSEMANTICRELATIONS_EXPORT SemanticTypes::ControlPoint ExtendClosestControlPoint(const mitk::DataNode* dataNode, std::vector& allControlPoints); - /* - * @brief Tries to find the closest control point to the given date in all the given control points. This is done by sorting the given vector of all control points and - * finding the first control point that is newer than the given date. Then the distances to the neighboring control points (older and newer, if existent) is calculated, - * using 'CalculateDistanceInDays'. If the smaller distance is smaller than a certain threshold, the corresponding control point is extended and returned, using the - * 'ExtendControlPoint'-function. If not, an empty control point is returned. + /** + * @brief Returns an already existing control point from the given vector of control points. This existing control point has the + * the same date (year, month, day) as the given single control point. + * If no existing control point can be found an empty control point is returned. * - * @return The return value of the 'ExtendControlPoint'-function. - * An empty control point, if the distance between the date and the closest control point exceeds a certain threshold. + * @par controlPoint The control point to check for existence. + * @par allControlPoints The vector of already existing control points. */ - MITKSEMANTICRELATIONS_EXPORT SemanticTypes::ControlPoint ExtendClosestControlPoint(const SemanticTypes::Date& date, std::vector& allControlPoints); + MITKSEMANTICRELATIONS_EXPORT SemanticTypes::ControlPoint FindExistingControlPoint(const SemanticTypes::ControlPoint& controlPoint, std::vector& allControlPoints); } // namespace mitk #endif // MITKCONTROLPOINTMANAGER_H diff --git a/Modules/SemanticRelations/include/mitkDICOMHelper.h b/Modules/SemanticRelations/include/mitkDICOMHelper.h index d8e6d97a07..082ad69e0f 100644 --- a/Modules/SemanticRelations/include/mitkDICOMHelper.h +++ b/Modules/SemanticRelations/include/mitkDICOMHelper.h @@ -1,111 +1,110 @@ /*=================================================================== 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. ===================================================================*/ #ifndef MITKDICOMHELPER_H #define MITKDICOMHELPER_H #include // semantic relations module #include "mitkSemanticTypes.h" // mitk core #include #include // c++ #include /* * @brief Provides helper functions to convert DICOM Tag information. * * In order to identify the patient of an image or segmentation or to set the control point of DICOM data, * these functions are used to retrieve the DICOM tags from the given data nodes and convert them into semantic types * that can be used by the SemanticRelations class. */ namespace mitk { /* * @brief Extracts a specific DICOM tag from the node's base data * and returns the tag as a string. This tag string is used as an identifier for the patient (case). * * @pre The given data node or the node's base data has to be valid (!nullptr). * @pre The node's base data has to have the specific DICOM Tag property set. * @throw mitk::Exception if the given data node, the node's base data or the extracted DICOM tag are invalid (==nullptr). * * @par dataNode The data node, of which the DICOM tag should be extracted. * * @return The extracted DICOM tag as string. * An empty string, if the DICOM tag can not be extracted (i.e. the data node or * the underlying base data is invalid or the DICOM tag does not exist for the given data node). */ MITKSEMANTICRELATIONS_EXPORT SemanticTypes::CaseID GetCaseIDFromDataNode(const mitk::DataNode* dataNode); /* * @brief Extracts a specific DICOM tag (currently "0x0020, 0x000e": SeriesInstanceUID) from the node's base data * and returns the tag as a string. This tag string is used as an identifier for the image instance. * * @pre The given data node or the node's base data has to be valid (!nullptr). * @pre The node's base data has to have the "0x0020, 0x000e" DICOM Tag property set. * @throw mitk::Exception if the given data node, the node's base data or the extracted DICOM tag are invalid (==nullptr). * * @par dataNode The data node, of which the DICOM tag should be extracted. * * @return The extracted DICOM tag as string. * An empty string, if the DICOM tag can not be extracted (i.e. the data node or * the underlying base data is invalid or the DICOM tag does not exist for the given data node). */ MITKSEMANTICRELATIONS_EXPORT SemanticTypes::ID GetIDFromDataNode(const mitk::DataNode* dataNode); /* * @brief Extracts a specific DICOM tag (currently "0x0008, 0x0022": AcquisitionDate) from the node's base data - * and returns the tag as a string. This tag string is used as the date of the image data. + * and returns the tag as a control point. * * @pre The given data node or the node's base data has to be valid (!nullptr). * @pre The node's base data has to have the "0x0008, 0x0022" DICOM Tag property set. * @throw mitk::Exception if the given data node, the node's base data or the extracted DICOM tag are invalid (==nullptr). * * @par dataNode The data node, of which the DICOM tag should be extracted. * - * @return The extracted DICOM tag as string. - * An empty string, if the DICOM tag can not be extracted (i.e. the data node or + * @return The extracted DICOM tag as control point. + * An empty control point, if the DICOM tag can not be extracted (i.e. the data node or * the underlying base data is invalid or the DICOM tag does not exist for the given data node). */ - MITKSEMANTICRELATIONS_EXPORT SemanticTypes::Date GetDICOMDateFromDataNode(const mitk::DataNode* dataNode); + MITKSEMANTICRELATIONS_EXPORT SemanticTypes::ControlPoint GetDICOMDateFromDataNode(const mitk::DataNode* dataNode); /** - * @brief Extracts a specific DICOM tag from the node's base data and returns the tag as a string. - * This tag string is used as the modality of the image data. + * @brief Extracts a specific DICOM tag from the node's base data and returns the tag as a information type (a string). * * @pre The given data node or the node's base data has to be valid (!nullptr). * @pre The node's base data has to have the "0x0008, 0x0060" DICOM Tag property set. * @throw mitk::Exception if the given data node, the node's base data or the extracted DICOM tag are invalid (==nullptr). * * @par dataNode The data node, of which the DICOM tag should be extracted. * - * @return The extracted DICOM tag as string. - * An empty string, if the DICOM tag can not be extracted (i.e. the data node or + * @return The extracted DICOM tag as information type (a string). + * An empty information type, if the DICOM tag can not be extracted (i.e. the data node or * the underlying base data is invalid or the DICOM tag does not exist for the given data node). */ MITKSEMANTICRELATIONS_EXPORT SemanticTypes::InformationType GetDICOMModalityFromDataNode(const mitk::DataNode* dataNode); /* * @brief Removes leading and trailing whitespace from the given string. * * @par identifier The value of a DICOM tag. * - * @return The trimmed DICOM tag + * @return The trimmed DICOM tag */ MITKSEMANTICRELATIONS_EXPORT std::string TrimDICOM(const std::string& identifier); } // namespace mitk #endif // MITKDICOMHELPER_H diff --git a/Modules/SemanticRelations/include/mitkRelationStorage.h b/Modules/SemanticRelations/include/mitkRelationStorage.h index 5e2e1e9b54..499702ff5c 100644 --- a/Modules/SemanticRelations/include/mitkRelationStorage.h +++ b/Modules/SemanticRelations/include/mitkRelationStorage.h @@ -1,88 +1,87 @@ /*=================================================================== 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. ===================================================================*/ #ifndef MITKRELATIONSTORAGE_H #define MITKRELATIONSTORAGE_H // semantic relations module #include "mitkDICOMHelper.h" #include "mitkSemanticTypes.h" // mitk core #include #include namespace mitk { class RelationStorage { public: void SetDataStorage(DataStorage::Pointer dataStorage); std::vector GetAllLesionsOfCase(const SemanticTypes::CaseID& caseID); SemanticTypes::Lesion GetRepresentedLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& segmentationID); std::vector GetAllSegmentationsOfCase(const SemanticTypes::CaseID& caseID); std::vector mitk::RelationStorage::GetAllSegmentationIDsOfCase(const SemanticTypes::CaseID& caseID); SemanticTypes::ControlPoint GetControlPointOfData(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& dataNodeID); std::vector GetAllControlPointsOfCase(const SemanticTypes::CaseID& caseID); SemanticTypes::InformationType GetInformationTypeOfImage(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& imageID); std::vector GetAllInformationTypesOfCase(const SemanticTypes::CaseID& caseID); std::vector GetAllImagesOfCase(const SemanticTypes::CaseID& caseID); std::vector GetAllImageIDsOfCase(const SemanticTypes::CaseID& caseID); std::vector GetAllCaseIDs(); void AddCase(const SemanticTypes::CaseID& caseID); void AddImage(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& imageNodeID); void RemoveImage(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& imageNodeID); void AddSegmentation(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& segmentationNodeID, const SemanticTypes::ID& parentDataNodeID); void RemoveSegmentation(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& segmentationNodeID); void AddLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion); void OverwriteLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion); void LinkSegmentationToLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& segmentationID, const SemanticTypes::Lesion& lesion); void UnlinkSegmentationFromLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& segmentationID); void RemoveLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion); void RemoveLesionClass(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& lesionClassID); void AddControlPoint(const SemanticTypes::CaseID& caseID, const SemanticTypes::ControlPoint& controlPoint); - void OverwriteControlPoint(const SemanticTypes::CaseID& caseID, const SemanticTypes::ControlPoint& controlPoint); void LinkDataToControlPoint(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& dataNodeID, const SemanticTypes::ControlPoint& controlPoint); void UnlinkDataFromControlPoint(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& dataNodeID); void RemoveControlPointFromCase(const SemanticTypes::CaseID& caseID, const SemanticTypes::ControlPoint& controlPoint); void AddInformationTypeToImage(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& imageID, const SemanticTypes::InformationType informationType); void RemoveInformationTypeFromImage(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& imageID); void RemoveInformationTypeFromCase(const SemanticTypes::CaseID& caseID, const SemanticTypes::InformationType informationType); private: // access the storage and retrieve the case data, stored under the given case ID mitk::PropertyList::Pointer GetStorageData(const SemanticTypes::CaseID& caseID); mitk::SemanticTypes::Lesion GenerateLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& lesionID); DataStorage::Pointer m_DataStorage; }; } // namespace mitk #endif // MITKRELATIONSTORAGE_H diff --git a/Modules/SemanticRelations/include/mitkSemanticRelations.h b/Modules/SemanticRelations/include/mitkSemanticRelations.h index 8befb09cfa..516b0989d8 100644 --- a/Modules/SemanticRelations/include/mitkSemanticRelations.h +++ b/Modules/SemanticRelations/include/mitkSemanticRelations.h @@ -1,632 +1,595 @@ /*=================================================================== 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. ===================================================================*/ #ifndef MITKSEMANTICRELATIONS_H #define MITKSEMANTICRELATIONS_H #include // semantic relations module #include "mitkControlPointManager.h" #include "mitkDICOMHelper.h" #include "mitkISemanticRelationsObservable.h" #include "mitkISemanticRelationsObserver.h" #include "mitkRelationStorage.h" #include "mitkSemanticTypes.h" // mitk core #include #include namespace mitk { /* * @brief The API provides functions to query and manipulate image relations and instances, * that are helpful during follow-up examination, like control-points (time period), * types of the images or lesions that may be visible on multiple images. * * The class is able to generate IDs from given data nodes using DICOM information. * These IDs are used to identify the corresponding instances of a specific case. * The case can also be directly identified by the given case ID. * * In the BlackSwan context the case is identified with the DICOM PatientID. * * In order for most functions to work the case ID has to be defined in the model. If not, * the functions do nothing. */ class MITKSEMANTICRELATIONS_EXPORT SemanticRelations : public ISemanticRelationsObservable { public: SemanticRelations(mitk::DataStorage::Pointer dataStorage); ~SemanticRelations(); - typedef std::vector LesionVector; - typedef std::vector LesionClassVector; - typedef std::vector ControlpointVector; - typedef std::vector InformationTypeVector; - typedef std::vector DataNodeVector; + using LesionVector = std::vector; + using LesionClassVector = std::vector; + using ControlPointVector = std::vector; + using InformationTypeVector = std::vector; + using DataNodeVector = std::vector ; + /************************************************************************/ /* functions to implement the observer pattern */ /************************************************************************/ /* * @brief Adds the given concrete observer to the vector that holds all currently registered observer. * If the observer is already registered, it will not be added to the observer vector. * * @param observer The concrete observer to register. */ virtual void AddObserver(ISemanticRelationsObserver* observer) override; /* * @brief Removes the given concrete observer from the vector that holds all currently registered observer. * * @param observer The concrete observer to unregister. */ virtual void RemoveObserver(ISemanticRelationsObserver* observer) override; /************************************************************************/ /* functions to get instances / attributes */ /************************************************************************/ /* * @brief Returns a vector of all lesions that are currently available for the given case. * The lesions may be marked by a segmentation or may be empty - with no connection to a specific image / segmentation of the case data. * If no lesions are stored for the current case, an empty vector is returned. * * @param caseID The current case identifier is defined by the given string. * @return A vector of lesions. */ LesionVector GetAllLesionsOfCase(const SemanticTypes::CaseID& caseID) const; /** * @brief * * */ LesionClassVector GetAllLesionClassesOfCase(const SemanticTypes::CaseID& caseID) const; /* * @brief Returns a vector of all lesions that are valid for the given case, given a specific control point. * * @param caseID The current case identifier is defined by the given string. * @param controlPoint A specific control point which has to be available at a returned (found) lesion: * Only those lesions are returned for which the image of the associated segmentation is linked to the given control point. * If the control point instance does not exist, an empty vector is returned. * @return A vector of control points. */ LesionVector GetAllLesionsOfCase(const SemanticTypes::CaseID& caseID, const SemanticTypes::ControlPoint& controlPoint) const; /* * @brief Returns a vector of all lesions that are currently available for the current case and are connected to the given image (via a segmentation). * If no lesions are stored for the current case, an empty vector is returned. If no segmentation nodes are * connected with the image node, no lesions for the specific image will be found and an empty vector is returned. * * @pre The given image data node has to be valid (!nullptr). * @throw SemanticRelationException, if the given image data node is invalid (==nullptr). * @pre The image node has to have associated segmentation nodes (child nodes) in order to reference a lesion. * * @param imageNode The current case identifier is extracted from the given data node, which contains DICOM information about the case. * @return A vector of lesions. */ LesionVector GetAllLesionsInImage(const DataNode* imageNode) const; /* * @brief Returns the lesion that is defined by the given segmentation data. * * @pre The given segmentation data node has to be valid (!nullptr). * @throw SemanticRelationException, if the given segmentation data node is invalid (==nullptr). * @pre The segmentation data node has to represent a lesion. If not, the retrieved lesion will be empty, which leads to an exception. * @throw SemanticRelationException, if the segmentation does not represent an existing lesion (this can be checked via 'IsRepresentingALesion'). * * @param segmentationNode The segmentation identifier is extracted from the given data node. * @return The represented lesion. */ SemanticTypes::Lesion GetRepresentedLesion(const DataNode* segmentationNode) const; /* * @brief Check if the given segmentation refers to an existing lesion instance. * This function can be used before calling 'GetRepresentedLesion' in order to avoid a possible exception. * * @param segmentationNode The segmentation identifier is extracted from the given data node. * @return True, if the segmentation refers to an existing lesion; false otherwise. */ bool IsRepresentingALesion(const DataNode* segmentationNode) const; /** * @brief * * */ bool InstanceExists(const DataNode* dataNode) const; /* * @brief Return a vector of all segmentations that are currently available for the given case. * The segmentations may be connected / not connected to a lesion of the case. * If no segmentations are stored for the current case, an empty vector is returned. * * @pre The data storage member has to be valid (!nullptr). * @throw SemanticRelationException, if the data storage member is invalid (==nullptr). * * @param caseID The current case identifier is defined by the given string. * @return A vector of data nodes representing segmentations. */ mitk::SemanticRelations::DataNodeVector GetAllSegmentationsOfCase(const SemanticTypes::CaseID& caseID) const; /* * @brief Return a vector of all segmentations that define the given lesion. These segmentations don't have to be linked to the same image. * If the lesion is not referred to by any segmentation, an empty vector is returned. * * @pre The data storage member has to be valid (!nullptr). * @throw SemanticRelationException, if the data storage member is invalid (==nullptr). * @pre The UID of the lesion has to exist for a lesion instance. * @throw SemanticRelationException, if UID of the lesion does not exist for a lesion instance (this can be checked via 'InstanceExists'). * * @param caseID The current case identifier is defined by the given string. * @param lesion A Lesion with a UID that identifies the corresponding lesion instance. * @return A vector of data nodes representing segmentations that define the given lesion. */ DataNodeVector GetAllSegmentationsOfLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion) const; /* * @brief Return a vector of all images that are currently available for the given case. * * @pre The data storage member has to be valid (!nullptr). * @throw SemanticRelationException, if the data storage member is invalid (==nullptr). * * @param caseID The current case identifier is defined by the given string. * @return A vector of data nodes representing images. */ DataNodeVector GetAllImagesOfCase(const SemanticTypes::CaseID& caseID) const; /* * @brief Return a vector of all images that are connected to those segmentations that are linked to the given lesion. * If the lesion is not referred to by any segmentation, an empty vector is returned. * * @pre The UID of the lesion has to exist for a lesion instance. * @throw SemanticRelationException, if UID of the lesion does not exist for a lesion instance (this can be checked via 'InstanceExists'). * * @param caseID The current case identifier is defined by the given string. * @param lesion A Lesion with a UID that identifies the corresponding lesion instance. * @return A vector of data nodes representing images on which the lesions are visible. */ DataNodeVector GetAllImagesOfLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion) const; /* * @brief Check if the given lesion instance exists. * This function can be used before calling 'GetAllSegmentationsOfLesion' in order to avoid a possible exception. * This function can be used before calling 'AddLesionInstance' in order to avoid a possible exception. * * @param caseID The current case identifier is defined by the given string. * @param lesion A Lesion with a UID that identifies the corresponding lesion instance. * @return True, if the lesion instance exists; false otherwise. */ bool InstanceExists(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion) const; /* * @brief Return a vector of all control points that are valid for the given case. * * @param caseID The current case identifier is defined by the given string. * @return A vector of control points. */ - ControlpointVector GetAllControlPointsOfCase(const SemanticTypes::CaseID& caseID) const; + ControlPointVector GetAllControlPointsOfCase(const SemanticTypes::CaseID& caseID) const; /* * @brief Return a vector of all control points that are valid for the given case, given a specific lesion * * @param caseID The current case identifier is defined by the given string. * @param lesion A specific lesion which has to be available at a returned (found) control point: * Only those control points are returned for which an associated data has a segmentation that references the given lesion. * If the lesion does not exists, an empty vector is returned. * @return A vector of control points. */ - ControlpointVector GetAllControlPointsOfCase(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion) const; + ControlPointVector GetAllControlPointsOfCase(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion) const; /* * @brief Return a vector of all control points that are valid for the given case, given a specific information type. * * @param caseID The current case identifier is defined by the given string. * @param informationType A specific information type which has to be available at a returned (found) control point: * Only those control points are returned for which an associated data has the given information type. * If the information type instance does not exists, an empty vector is returned. * @return A vector of control points. */ - ControlpointVector GetAllControlPointsOfCase(const SemanticTypes::CaseID& caseID, const SemanticTypes::InformationType& informationType) const; + ControlPointVector GetAllControlPointsOfCase(const SemanticTypes::CaseID& caseID, const SemanticTypes::InformationType& informationType) const; /* * @brief Return the control point of a data node. * If the data node is not linked to a control point or the data node refers to a non-existing control point, * a control point with an empty UID is returned. * * @pre The given data node has to be valid (!nullptr). * @throw SemanticRelationException, if the given data node is invalid (==nullptr). * * @param dataNode The current case identifier is extracted from the given data node, which contains DICOM information about the case. * @return The control point of the given data node. */ SemanticTypes::ControlPoint GetControlPointOfData(const DataNode* dataNode) const; /* * @brief Return a vector of all image nodes that link to the given control point. * If the control point is not referred to by any data node, an empty vector is returned. * * @pre The UID of the control point has to exist for a control point instance. * @throw SemanticRelationException, if the UID of the control point does not exist for a control point instance (this can be checked via 'InstanceExists'). * * @param caseID The current case identifier is defined by the given string. * @param controlPoint A control point with a UID that identifies the corresponding control point instance. * @return A vector of image nodes that link to the given control point. */ DataNodeVector GetAllImagesOfControlPoint(const SemanticTypes::CaseID& caseID, const SemanticTypes::ControlPoint& controlPoint) const; /* * @brief Check if the given control point instance exists. * This function can be used before calling 'GetAllDataOfControlPoint' in order to avoid a possible exception. * This function can be used before adding, linking and unlinking control points to avoid a possible exception. * * @param caseID The current case identifier is defined by the given string. * @param controlPoint A control point with a UID that identifies the corresponding control point instance. * @return True, if the control point instance exists; false otherwise. */ bool InstanceExists(const SemanticTypes::CaseID& caseID, const SemanticTypes::ControlPoint& controlPoint) const; /* * @brief Return a vector of all information types that are valid for the given case. * * @param caseID The current case identifier is defined by the given string. * @return A vector of information types. */ InformationTypeVector GetAllInformationTypesOfCase(const SemanticTypes::CaseID& caseID) const; /* * @brief Return a vector of all information types that are valid for the given case, given a specific control point. * * @param caseID The current case identifier is defined by the given string. * @param controlPoint A specific control point which has to be available at a returned (found) information type: * Only those information types are returned for which an associated data is linked to the given control point. * If the control point instance does not exist, an empty vector is returned. * @return A vector of information types. */ InformationTypeVector GetAllInformationTypesOfCase(const SemanticTypes::CaseID& caseID, const SemanticTypes::ControlPoint& controlPoint) const; /* * @brief Return the information type of the given image. * If the image does not contain any information type, an empty information type is returned. * * @pre The given image data node has to be valid (!nullptr). * @throw SemanticRelationException, if the given image data node is invalid (==nullptr). * * @param imageNode The current case identifier is extracted from the given data node, which contains DICOM information about the case. * @return The information type of the given data node. */ SemanticTypes::InformationType GetInformationTypeOfImage(const DataNode* imageNode) const; /* * @brief Return a vector of all image nodes that are defined with the given information type. * * @pre The information type has to exist for the given case (and is therefore used by at least one data node). * @throw SemanticRelationException, if the information type is not used by any data node (this can be checked via 'InstanceExists'). * * @param caseID The current case identifier is defined by the given string. * @param informationType An information type that identifies the corresponding information type instance. * @return A vector of image nodes that are defined with the given information type. */ DataNodeVector GetAllImagesOfInformationType(const SemanticTypes::CaseID& caseID, const SemanticTypes::InformationType& informationType) const; /* * @brief Return a vector of all image nodes that are defined with the given information type and with the given control point. * * @pre The UID of the control point has to exist for a control point instance. * The information type has to exist for the given case (and is therefore used by at least one data node). * @throw SemanticRelationException, if the UID of the control point does not exist for a control point instance (this can be checked via 'InstanceExists') or * if the information type is not used by any data node (this can be checked via 'InstanceExists'). * * @param caseID The current case identifier is defined by the given string. * @param controlPoint A control point with a UID that identifies the corresponding control point instance. * @param informationType An information type that identifies the corresponding information type instance. * @return A vector of image nodes that are defined with the given information type with the given control point. */ DataNodeVector GetAllSpecificImages(const SemanticTypes::CaseID& caseID, const SemanticTypes::ControlPoint& controlPoint, const SemanticTypes::InformationType& informationType) const; /** * @brief Return a vector of all segmentation nodes that are defined with the given information type and with the given control point. * The function uses the 'GetAllSpecificImages'-function to retrieve the specific images and then searches for the derived nodes (segmentation child nodes). * * @pre The UID of the control point has to exist for a control point instance. * The information type has to exist for the given case (and is therefore used by at least one data node). * @throw SemanticRelationException, if the UID of the control point does not exist for a control point instance (this can be checked via 'InstanceExists') or * if the information type is not used by any data node (this can be checked via 'InstanceExists'). * * @param caseID The current case identifier is defined by the given string. * @param controlPoint A control point with a UID that identifies the corresponding control point instance. * @param informationType An information type that identifies the corresponding information type instance. * @return A vector of segmentation nodes that are defined with the given information type with the given control point. */ DataNodeVector GetAllSpecificSegmentations(const SemanticTypes::CaseID& caseID, const SemanticTypes::ControlPoint& controlPoint, const SemanticTypes::InformationType& informationType) const; /* * @brief Check if the given information type exists. * This function can be used before calling 'GetAllDataOfInformationType' in order to avoid a possible exception. * * @param caseID The current case identifier is defined by the given string. * @param informationType An information type * @return True, if the information type exists; false otherwise. */ bool InstanceExists(const SemanticTypes::CaseID& caseID, const SemanticTypes::InformationType& informationType) const; /* * @brief Return a vector of all CaseIDs that are currently available. * * @return A vector of CaseIDs as strings. */ std::vector GetAllCaseIDs() const; /************************************************************************/ /* functions to add / remove instances / attributes */ /************************************************************************/ /* * @brief Add the given image to the set of already existing images. * The date is extracted from the DICOM data of the image node and is compared to already existing control points in the semantic relations model. * The function tries to find a fitting control point or to extend an already existing control point, if the extracted control point is close to * any other, already existing control point. * Finally, the image is linked to the correct control point. * * @pre The given image data node has to be valid (!nullptr). * @throw SemanticRelationException, if the given image data node is invalid (==nullptr). * * @param imageNode The current case identifier and node identifier is extracted from the given image data node, which contains DICOM information about the case and the node. */ void AddImage(const DataNode* imageNode); /* * @brief Remove the given image from the set of already existing images. * * @pre The given image data node has to be valid (!nullptr). * @throw SemanticRelationException, if the given image data node is invalid (==nullptr). * * @param imageNode The current case identifier and node identifier is extracted from the given image data node, which contains DICOM information about the case and the node. */ void RemoveImage(const DataNode* imageNode); /* * @brief Add a newly created lesion to the set of already existing lesions - with no connection to a specific image / segmentation of the case data. * * @pre The UID of the lesion must not already exist for a lesion instance. * @throw SemanticRelationException, it the UID of the lesion already exists for a lesion instance (this can be checked via 'InstanceExists'). * * @param caseID The current case identifier is defined by the given string. * @param lesion The lesion instance to add. */ void AddLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion); /* * @brief Overwrite an already existing lesion instance (this may be useful to overwrite the lesion with a different lesion class). * * @pre The UID of the lesion has to exist for a lesion instance. * @throw SemanticRelationException, if the UID of the lesion does not exist for a lesion instance (this can be checked via 'InstanceExists'). * * @param caseID The current case identifier is defined by the given string. * @param lesion The lesion instance that overwrites an existing lesion. */ void OverwriteLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion); /* * @brief Add a newly created lesion to the set of already existing lesions. The lesion is added and a reference to * the lesion is added to the segmentation data. If the segmentation is already linked to a lesion, the * old linkage is overwritten (this can be checked via 'IsRepresentingALesion'). * * @pre The given segmentation data node has to be valid (!nullptr). * @throw SemanticRelationException, if the given segmentation data node is invalid (==nullptr). * @pre The UID of the lesion must not already exist for a lesion instance. * @throw SemanticRelationException, if the UID of the lesion already exists for a lesion instance (this can be checked via 'InstanceExists'). * * @param segmentationNode The segmentation identifier is extracted from the given data node. The segmentation node has DICOM information from its parent node. * @param lesion The lesion instance to add and link. */ void AddLesionAndLinkSegmentation(const DataNode* segmentationNode, const SemanticTypes::Lesion& lesion); /* * @brief Remove the given lesion from the set of already existing lesions. * * @pre The UID of the lesion has to exist for a lesion instance. * @throw SemanticRelationException, if the UID of the lesion does not exist for a lesion instance (this can be checked via 'InstanceExists'). * @pre The function needs to assure that no segmentation is still representing (linked to) this lesion. * @throw SemanticRelationException, if the lesion instance to remove is still linked to by any segmentation (this can be checked via 'GetAllSegmentationsOfLesion'). * * @param caseID The current case identifier is defined by the given string. * @param lesion The lesion instance to remove. */ void RemoveLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion); /* * @brief Add a segmentation instance to the set of already existing segmentations - with no connection to a specific lesion. * * @param segmentationNode The segmentation identifier is extracted from the given data node. The segmentation node has DICOM information from its parent node. * @param parentNode The node identifier of the parent node is extracted from the given parent data node. */ void AddSegmentation(const DataNode* segmentationNode, const DataNode* parentNode); /* * @brief Link the given segmentation instance to an an already existing lesion instance. If the segmentation is already linked to a lesion instance, the * old linkage is overwritten (this can be checked via 'IsRepresentingALesion'). * * @pre The given segmentation data node has to be valid (!nullptr). * @throw SemanticRelationException, if the given segmentation data node is invalid (==nullptr). * @pre The UID of the lesion has to exist for a lesion instance. * @throw SemanticRelationException, if the UID of the lesion does not exist for a lesion instance (this can be checked via 'InstanceExists'). * * @param segmentationNode The segmentation identifier is extracted from the given data node. The segmentation node has DICOM information from its parent node. * @param lesion The lesion instance to link. */ void LinkSegmentationToLesion(const DataNode* segmentationNode, const SemanticTypes::Lesion& lesion); /* * @brief Unlink the given segmentation instance from the linked lesion instance. * The lesion may stay unlinked to any segmentation. * * @pre The given segmentation data node has to be valid (!nullptr). * @throw SemanticRelationException, if the given segmentation data node is invalid (==nullptr). * * @param segmentationNode The segmentation identifier is extracted from the given data node. The segmentation node has DICOM information from its parent node. */ void UnlinkSegmentationFromLesion(const DataNode* segmentationNode); /* * @brief Remove the given segmentation from the set of already existing segmentations. * * @pre The given segmentation data node has to be valid (!nullptr). * @throw SemanticRelationException, if the given segmentation data node is invalid (==nullptr). * * @param segmentationNode The segmentation identifier is extracted from the given data node. The segmentation node has DICOM information from its parent node. */ void RemoveSegmentation(const DataNode* segmentationNode); /** - * @brief Use the given date to set the control point for the given data node. - * The function tries to find a fitting control point for the given data and link to this control point or extend it. - * If no fitting (or any) control point is found a new control point is generated from the date and added to the semantic relations storage. + * @brief Set the control point for the given data node. * * @pre The given data node has to be valid (!nullptr). * @throw SemanticRelationException, if the given data node is invalid (==nullptr). - */ - void SetControlPointFromDate(const DataNode* dataNode, const SemanticTypes::Date& date); + void SetControlPointOfData(const DataNode* dataNode, const SemanticTypes::ControlPoint& controlPoint); /* * @brief Add a newly created control point to the set of already existing control points. A reference to the control point is added to the given data. * This function combines adding a control point and linking it, since a control point with no associated data is not allowed. * * @pre The given data node has to be valid (!nullptr). * @throw SemanticRelationException, if the given data node is invalid (==nullptr). * @pre The UID of the control point must not already exist for a control point instance. * @throw SemanticRelationException, if the UID of the control point already exists for a control point instance (this can be checked via 'InstanceExists'). * @pre The given control point must not already be contained in an existing control point interval. * @throw SemanticRelationException, if the given control point is already contained in an existing control point interval (this can be checked via 'CheckContainingControlPoint'). * @pre The given control point must contain the date of the given data node (if parameter 'checkConsistence = true'). * @throw SemanticRelationException, if the given control point does not contain the date of the given data node and 'checkConsistence = true' (this can be checked via 'ControlPointManager::InsideControlPoint'). * * @param dataNode The current case identifier is extracted from the given data node, which contains DICOM information about the case. * @param controlPoint The control point instance to add. For a newly added control point always has "startDate = endDate". * @param checkConsistence If true, the function checks, whether the date of the data node actually lies inside the control point to link. */ void AddControlPointAndLinkData(const DataNode* dataNode, const SemanticTypes::ControlPoint& controlPoint, bool checkConsistence = true); /* - * @brief Link the given data to an already existing control point and overwrite the start or end point of the control point. - * - * @pre The given data node has to be valid (!nullptr). - * @throw SemanticRelationException, if the given data node is invalid (==nullptr). - * @pre The UID of the control point has to exist for a control point instance. - * @throw SemanticRelationException, if the UID of the control point does not exists for a control point instance (this can be checked via 'InstanceExists'). - * @pre The given control point must contain the date of the given data node (if parameter 'checkConsistence = true'). - * @throw SemanticRelationException, if the given control point does not contain the date of the given data node and 'checkConsistence = true' (this can be checked via 'ControlPointManager::InsideControlPoint'). - * @pre The given control point must differ from the overwritten control point, but only either in the start point or in the end point. - * It is not possible to overwrite a single control point from a single date and simultaneously changing both ends of the time period. - * @throw SemanticRelationException, if the given control point does not differ from the overwritten control point or if the given control point differs in the start date and the end date from the overwritten control point. - * @pre The given control point must not overlap with an already existing control point. - * @throw SemanticRelationException, if the given control point overlaps with an already existing control point interval (this can be checked via 'CheckOverlappingControlPoint'). - * - * @param dataNode The current case identifier is extracted from the given data node, which contains DICOM information about the case. - * @param controlPoint The control point instance that overwrites an existing control point. - * @param checkConsistence If true, the function checks, whether the date of the data node actually lies inside the control point to link. - */ - void OverwriteControlPointAndLinkData(const DataNode* dataNode, const SemanticTypes::ControlPoint& controlPoint, bool checkConsistence = true); - /* * @brief Link the given data to an already existing control point. * * @pre The given data node has to be valid (!nullptr). * @throw SemanticRelationException, if the given data node is invalid (==nullptr). * @pre The UID of the control point has to exist for a control point instance. * @throw SemanticRelationException, if the UID of the control point does not exists for a control point instance (this can be checked via 'InstanceExists'). * @pre The given control point must contain the date of the given data node (if parameter 'checkConsistence = true'). * @throw SemanticRelationException, if the given control point does not contain the date of the given data node and 'checkConsistence = true' (this can be checked via 'ControlPointManager::InsideControlPoint'). * * @param dataNode The current case identifier is extracted from the given data node, which contains DICOM information about the case. * @param controlPoint The control point instance to add link. * @param checkConsistence If true, the function checks, whether the date of the data node actually lies inside the control point to link. */ void LinkDataToControlPoint(const DataNode* dataNode, const SemanticTypes::ControlPoint& controlPoint, bool checkConsistence = true); /* * @brief Unlink the given image from the linked control point. * If data is unlinked from a control point, the function needs to check whether the control point is still linked to any other data: * - if not, the control point instance will be removed (has to be removed since a control point with no associated data is not allowed). * - if so, the function has to make sure that the control point instance is shortened to its minimum time period (e.g. moving the end point to an earlier date). * * @param dataNode The current case identifier is extracted from the given data node, which contains DICOM information about the case. */ void UnlinkDataFromControlPoint(const DataNode* dataNode); /** * @brief Set (and possibly overwrite) the information type of the given image. * An already associated information type might be removed if is not referenced by any other image: * * @pre The given image data node has to be valid (!nullptr). * @throw SemanticRelationException, if the given image data node is invalid (==nullptr). * @post If the information type instance did not exist before, it is now added. * * @param imageNode The current case identifier is extracted from the given data node, which contains DICOM information about the case. * @param informationType An information type that identifies the corresponding information type instance. */ void SetInformationType(const DataNode* imageNode, const SemanticTypes::InformationType& informationType); /* * @brief Set the information type of the given image. * * @pre The given image data node has to be valid (!nullptr). * @throw SemanticRelationException, if the given image data node is invalid (==nullptr). * @post If the information type instance did not exist before, it is now added. * * @param imageNode The current case identifier is extracted from the given data node, which contains DICOM information about the case. * @param informationType An information type that identifies the corresponding information type instance. */ void AddInformationTypeToImage(const DataNode* imageNode, const SemanticTypes::InformationType& informationType); /* * @brief Remove the information type of the given image. * If the information type is removed, the function needs to check whether the information type is referenced by any other image: * - if not, the information type instance can be removed (has to be removed since an information type with no associated image is not allowed). * - if so, the information type is just removed from the given image. * * @pre The given image data node has to be valid (!nullptr). * @throw SemanticRelationException, if the given image data node is invalid (==nullptr). * * @param imageNode The current case identifier is extracted from the given data node, which contains DICOM information about the case. */ void RemoveInformationTypeFromImage(const DataNode* imageNode); private: // the relation storage serves as a storage accessor and can be sub-classed for custom demands std::shared_ptr m_RelationStorage; DataStorage::Pointer m_DataStorage; /* * @brief A vector that stores the currently registered observer of this observable subject. */ static std::vector m_ObserverVector; /* * @brief The SemanticRelations, as an example of an observable subject, notifies (updates) the observer with a given case ID. * The view's caseID was set before in the GUI. The parts of the view that observe changes in the semantic relations are only updated, * if the given case ID is equal to the observer's current caseID and thus the observer currently shows the semantic information of the given case. * * @param caseID The caseID that identifies the currently active patient / case. */ virtual void NotifyObserver(const mitk::SemanticTypes::CaseID& caseID) const override; /* * @brief Determine if the given control point contains images, which are connected to segmentations that represent the given lesion. * If the lesion or the control point are not correctly stored, the function returns false. * * @param caseID The current case identifier is defined by the given string. * @param lesion A Lesion with a UID that identifies the corresponding lesion instance. * @param controlPoint A control point with a UID that identifies the corresponding control point instance. * * @return True, if the given control point contains data that is related to the given lesion; false otherwise. */ bool ControlPointContainsLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion, const SemanticTypes::ControlPoint& controlPoint) const; /* * @brief Determine if the given control point contains images, which refer to the given information type. * If the information type or the control point are not correctly stored, the function returns false. * * @param caseID The current case identifier is defined by the given string. * @param informationType An information type that identifies the corresponding information type instance. * @param controlPoint A control point with a UID that identifies the corresponding control point instance. * * @return True, if the given control point contains data that is related to the given information type; false otherwise. */ bool ControlPointContainsInformationType(const SemanticTypes::CaseID& caseID, const SemanticTypes::InformationType& informationType, const SemanticTypes::ControlPoint& controlPoint) const; - /* - * @brief Check if the given control point overlaps with an already existing control point. - * If the UID already exists, then the given control point may overlap with the previous or next control point, - * because the start point or the end point of the given control point might be modified (different to the same control point - * that is stored at the moment). - * If the UID does not already exists, the previous and next control point are found by comparing the dates of the already - * existing control points and the given control point. - * - * @param caseID The current case identifier is defined by the given string. - * @param controlPoint A control point with a UID that identifies the corresponding control point instance. - */ - bool CheckOverlappingControlPoint(const SemanticTypes::CaseID& caseID, const SemanticTypes::ControlPoint& controlPoint); - /* - * @brief Check if the given control point is contained within an already existing control point. - * If the UID already exists, then the given control point is contained in this same control point. - * However, the function does not check if the given control point is really contained (just compares UID) in this case. - * If the UID does not already exist, the already existing control points are tested to see if they contain the - * given control point. + /** + * @brief Remove all control points from the storage that are not referenced by any image anymore. + * This might happen if an image has been removed (and unlinked from the corresponding control point) + * or if the user sets a new control point for an image manually in the GUI. * - * @param caseID The current case identifier is defined by the given string. - * @param controlPoint A control point with a UID that identifies the corresponding control point instance. + * @param caseID The current case identifier is defined by the given string. */ - bool CheckContainingControlPoint(const SemanticTypes::CaseID& caseID, const SemanticTypes::ControlPoint& controlPoint); + void ClearControlPoints(const SemanticTypes::CaseID& caseID); }; } // namespace mitk #endif // MITKSEMANTICRELATIONS_H diff --git a/Modules/SemanticRelations/include/mitkSemanticTypes.h b/Modules/SemanticRelations/include/mitkSemanticTypes.h index fce79141d7..cdb7128860 100644 --- a/Modules/SemanticRelations/include/mitkSemanticTypes.h +++ b/Modules/SemanticRelations/include/mitkSemanticTypes.h @@ -1,116 +1,90 @@ /*=================================================================== 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. ===================================================================*/ #ifndef MITKSEMANTICTYPES_H #define MITKSEMANTICTYPES_H // c++ -#include -#include -#include -#include +#include #include namespace mitk { namespace SemanticTypes { - typedef std::string ID; - typedef std::string CaseID; // an ID of the current case (e.g. the DICOM PatientID) - typedef std::string InformationType; + using ID = std::string; + using CaseID = std::string; // an ID of the current case (e.g. the DICOM PatientID) + using InformationType = std::string; /* - * @brief The date type to be used for control points. + * @brief The concept of a control point. */ - struct Date + struct ControlPoint { ID UID; int year = 0; int month = 0; int day = 0; - bool operator<(const Date& other) const + bool operator<(const ControlPoint& other) const { return std::tie(year, month, day) < std::tie(other.year, other.month, other.day); } - bool operator>(const Date& other) const + bool operator>(const ControlPoint& other) const { return std::tie(year, month, day) > std::tie(other.year, other.month, other.day); } - bool operator==(const Date& other) const + bool operator==(const ControlPoint& other) const { return (!operator<(other) && !operator>(other)); } - bool operator!=(const Date& other) const + bool operator!=(const ControlPoint& other) const { return (operator<(other) || operator>(other)); } - bool operator<=(const Date& other) const + bool operator<=(const ControlPoint& other) const { return (operator<(other) || operator==(other)); } - bool operator>=(const Date& other) const + bool operator>=(const ControlPoint& other) const { return (operator>(other) || operator==(other)); } }; - /* - * @brief The concept of a control point. - */ - struct ControlPoint // alternatively: ExaminationPoint - { - ID UID; - Date startPoint; - Date endPoint; - - bool operator<(const ControlPoint& other) const - { - return startPoint < other.startPoint; - } - bool operator!=(const ControlPoint& other) const - { - return (startPoint != other.startPoint) || (endPoint != other.endPoint); - } - bool operator==(const ControlPoint& other) const - { - return (startPoint == other.startPoint) && (endPoint == other.endPoint); - } - }; - /* * @brief The concept of a lesion class. */ struct LesionClass { ID UID; - std::string classType = ""; // could be a "focal lesion" or "diffuse lesion" in the BlackSwan context + std::string classType = ""; }; /* * @brief The concept of a lesion. */ struct Lesion { ID UID; std::string name = ""; LesionClass lesionClass; }; } // namespace SemanticTypes } // namespace mitk #endif // MITKSEMANTICTYPES_H diff --git a/Modules/SemanticRelations/src/mitkControlPointManager.cpp b/Modules/SemanticRelations/src/mitkControlPointManager.cpp index 20626fc866..e37e061fbb 100644 --- a/Modules/SemanticRelations/src/mitkControlPointManager.cpp +++ b/Modules/SemanticRelations/src/mitkControlPointManager.cpp @@ -1,304 +1,77 @@ /*=================================================================== 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. ===================================================================*/ // semantic relations module #include "mitkControlPointManager.h" #include "mitkDICOMHelper.h" #include "mitkUIDGeneratorBoost.h" // mitk core #include -// c++ -#include - -mitk::SemanticTypes::Date GetStartPoint(const std::vector& dataNodes); - -mitk::SemanticTypes::Date GetEndPoint(const std::vector& dataNodes); - -void ExtendControlPoint(mitk::SemanticTypes::ControlPoint& controlPoint, mitk::SemanticTypes::Date date); - -double CalculateDistanceInDays(mitk::SemanticTypes::Date leftDate, mitk::SemanticTypes::Date rightDate); - -mitk::SemanticTypes::ControlPoint mitk::GenerateControlPoint(const std::vector& dataNodes) -{ - SemanticTypes::ControlPoint controlPoint; - SemanticTypes::Date startPoint = GetStartPoint(dataNodes); - SemanticTypes::Date endPoint = GetEndPoint(dataNodes); - - // set the values of the control point - controlPoint.UID = UIDGeneratorBoost::GenerateUID(); - controlPoint.startPoint = startPoint; - controlPoint.endPoint = endPoint; - - return controlPoint; -} +double CalculateDistanceInDays(mitk::SemanticTypes::ControlPoint leftControlPoint, mitk::SemanticTypes::ControlPoint rightControlPoint); mitk::SemanticTypes::ControlPoint mitk::GenerateControlPoint(const mitk::DataNode* datanode) { - SemanticTypes::ControlPoint controlPoint; - SemanticTypes::Date date = GetDICOMDateFromDataNode(datanode); - - return GenerateControlPoint(date); -} - -mitk::SemanticTypes::ControlPoint mitk::GenerateControlPoint(const SemanticTypes::Date& date) -{ - SemanticTypes::ControlPoint controlPoint; - - // set the values of the control point + SemanticTypes::ControlPoint controlPoint = GetDICOMDateFromDataNode(datanode); controlPoint.UID = UIDGeneratorBoost::GenerateUID(); - controlPoint.startPoint = date; - controlPoint.endPoint = date; - // create new UID so that the start point and the end point have a different UID - controlPoint.endPoint.UID = UIDGeneratorBoost::GenerateUID(); return controlPoint; } std::string mitk::GetControlPointAsString(const SemanticTypes::ControlPoint& controlPoint) { - std::stringstream dateAsString; - - SemanticTypes::Date startPoint = controlPoint.startPoint; - SemanticTypes::Date endPoint = controlPoint.endPoint; - - dateAsString << std::to_string(controlPoint.startPoint.year) << "-" - << std::setfill('0') << std::setw(2) << std::to_string(startPoint.month) << "-" - << std::setfill('0') << std::setw(2) << std::to_string(startPoint.day); - if (startPoint != endPoint) - { - dateAsString << " to \n " << std::to_string(endPoint.year) << "-" - << std::setfill('0') << std::setw(2) << std::to_string(endPoint.month) << "-" - << std::setfill('0') << std::setw(2) << std::to_string(endPoint.day); - } - - return dateAsString.str(); -} - -bool mitk::InsideControlPoint(const mitk::DataNode* dataNode, const SemanticTypes::ControlPoint& controlPoint) -{ - SemanticTypes::Date date = GetDICOMDateFromDataNode(dataNode); - if (date >= controlPoint.startPoint && date <= controlPoint.endPoint && !controlPoint.UID.empty()) - { - return true; - } - return false; -} - -bool mitk::InsideControlPoint(const SemanticTypes::Date& date, const SemanticTypes::ControlPoint& controlPoint) -{ - if (date >= controlPoint.startPoint && date <= controlPoint.endPoint) - { - return true; - } - return false; -} - -bool mitk::InsideControlPoint(const SemanticTypes::ControlPoint& containedControlPoint, const SemanticTypes::ControlPoint& containingControlPoint) -{ - if (containedControlPoint.startPoint >= containingControlPoint.startPoint && containedControlPoint.endPoint <= containingControlPoint.endPoint) - { - return true; - } - return false; -} - -bool mitk::CheckForOverlap(const SemanticTypes::ControlPoint& controlPoint, const SemanticTypes::ControlPoint& neighboringControlPoint) -{ - if (controlPoint.startPoint >= neighboringControlPoint.endPoint || controlPoint.endPoint <= neighboringControlPoint.startPoint) - { - return false; - } - return true; -} - -mitk::SemanticTypes::ControlPoint mitk::FindFittingControlPoint(const mitk::DataNode* dataNode, std::vector& allControlPoints) -{ - SemanticTypes::Date dateFromDataNode = GetDICOMDateFromDataNode(dataNode); - if (0 == dateFromDataNode.year) - { - MITK_INFO << "Could not deduce a valid date from the given data node."; - return SemanticTypes::ControlPoint(); - } - - return FindFittingControlPoint(dateFromDataNode, allControlPoints); -} - -mitk::SemanticTypes::ControlPoint mitk::FindFittingControlPoint(const SemanticTypes::Date& date, std::vector& allControlPoints) -{ - // check if the date of the data node fits into an existing control point interval - for (const auto& controlPoint : allControlPoints) - { - if (InsideControlPoint(date, controlPoint)) - { - // return the fitting control point that contains the date from the given data node - return controlPoint; - } - } - - return SemanticTypes::ControlPoint(); -} - -mitk::SemanticTypes::ControlPoint mitk::ExtendClosestControlPoint(const mitk::DataNode* dataNode, std::vector& allControlPoints) -{ - SemanticTypes::Date dateFromDataNode = GetDICOMDateFromDataNode(dataNode); - if (0 == dateFromDataNode.year) - { - MITK_INFO << "Could not deduce a valid date from the given data node."; - return SemanticTypes::ControlPoint(); - } + std::stringstream controlPointAsString; + controlPointAsString << std::to_string(controlPoint.year) << "-" + << std::setfill('0') << std::setw(2) << std::to_string(controlPoint.month) << "-" + << std::setfill('0') << std::setw(2) << std::to_string(controlPoint.day); - return ExtendClosestControlPoint(dateFromDataNode, allControlPoints); + return controlPointAsString.str(); } -mitk::SemanticTypes::ControlPoint mitk::ExtendClosestControlPoint(const SemanticTypes::Date& date, std::vector& allControlPoints) +mitk::SemanticTypes::ControlPoint mitk::FindExistingControlPoint(const SemanticTypes::ControlPoint& controlPoint, std::vector& allControlPoints) { - // sort the vector of control points for easier lookup - std::sort(allControlPoints.begin(), allControlPoints.end()); - // new date does not fit into an existing control point - // check if the date of the data node is close to an already existing control point - std::vector::const_iterator it; - for (it = allControlPoints.begin(); it != allControlPoints.end(); ++it) + for (const auto& currentControlPoint : allControlPoints) { - if (date < it->startPoint) + if (controlPoint == currentControlPoint) { - break; // cannot be inside this control point; therefore has to be greater ("newer") than 'it->endPoint' + return currentControlPoint; } } - SemanticTypes::ControlPoint nextControlPoint; - SemanticTypes::ControlPoint previousControlPoint; - SemanticTypes::Date nextDate; - SemanticTypes::Date previousDate; - if (it == allControlPoints.begin()) - { - // new date is smaller ("older") than the smallest already existing control point - nextControlPoint = *it; - nextDate = it->startPoint; - } - else if (it != allControlPoints.end()) - { - // new date is greater ("newer") than the smallest already existing control point, - // but smaller ("older") than the greatest already existing control point - nextControlPoint = *it; - nextDate = nextControlPoint.startPoint; - previousControlPoint = *(--it); - previousDate = previousControlPoint.endPoint; - } - else - { - // new date is greater ("newer") than the greatest already existing control point - previousControlPoint = *(--it); - previousDate = previousControlPoint.endPoint; - } - - // test distance to next and previous time period - double distanceToNextTimePeriod = CalculateDistanceInDays(nextDate, date); - double distanceToPreviousTimePeriod = CalculateDistanceInDays(previousDate, date); - - SemanticTypes::ControlPoint closestControlPoint; - double closestDistanceInDays = 0.0; - if (distanceToNextTimePeriod < distanceToPreviousTimePeriod) - { - // date is closer to the next control point - closestControlPoint = nextControlPoint; - closestDistanceInDays = distanceToNextTimePeriod; - } - else - { - // date is closer to the previous control point - closestControlPoint = previousControlPoint; - closestDistanceInDays = distanceToPreviousTimePeriod; - } - - // extend the control point or create a control point - double THRESHOLD_DISTANCE_IN_DAYS = 30.0; - if (std::abs(closestDistanceInDays) < THRESHOLD_DISTANCE_IN_DAYS) - { - // extend the closest control point - ExtendControlPoint(closestControlPoint, date); - return closestControlPoint; - } - return SemanticTypes::ControlPoint(); } -mitk::SemanticTypes::Date GetStartPoint(const std::vector& dataNodes) -{ - // lambda function for "less than" comparison of two dates of two data nodes - auto minLambda = [](const mitk::DataNode::Pointer& left, const mitk::DataNode::Pointer& right) - { - return GetDICOMDateFromDataNode(left) < GetDICOMDateFromDataNode(right); - }; - - // find the data node with the smallest date value and return this earliest date as the start point - auto minElement = std::min_element(dataNodes.begin(), dataNodes.end(), minLambda); - return GetDICOMDateFromDataNode(*minElement); -} - -mitk::SemanticTypes::Date GetEndPoint(const std::vector& dataNodes) -{ - // lambda function for "greater than" comparison of two dates of two data nodes - auto maxLambda = [](const mitk::DataNode::Pointer& left, const mitk::DataNode::Pointer& right) - { - return GetDICOMDateFromDataNode(left) > GetDICOMDateFromDataNode(right); - }; - - // find the data node with the largest date value and return this latest date as the end point - auto maxElement = std::max_element(dataNodes.begin(), dataNodes.end(), maxLambda); - return GetDICOMDateFromDataNode(*maxElement); -} - -void ExtendControlPoint(mitk::SemanticTypes::ControlPoint& controlPoint, mitk::SemanticTypes::Date date) -{ - if (controlPoint.startPoint > date) - { - // date has to extend the older start point of the control point (move start point to the earlier date) - controlPoint.startPoint.year = date.year; - controlPoint.startPoint.month = date.month; - controlPoint.startPoint.day = date.day; - } - else if (controlPoint.endPoint < date) - { - // date has to extend the newer end point of the control point (move end point to the later date) - controlPoint.endPoint.year = date.year; - controlPoint.endPoint.month = date.month; - controlPoint.endPoint.day = date.day; - } - // else: date is inside the control point -} - -double CalculateDistanceInDays(mitk::SemanticTypes::Date leftDate, mitk::SemanticTypes::Date rightDate) +double CalculateDistanceInDays(mitk::SemanticTypes::ControlPoint leftControlPoint, mitk::SemanticTypes::ControlPoint rightControlPoint) { - // compute distance here - std::tm leftTimeStructure = { 0, 0, 0, leftDate.day, leftDate.month - 1, leftDate.year - 1900 }; - std::tm rightTimeStructure = { 0, 0, 0, rightDate.day, rightDate.month - 1, rightDate.year - 1900 }; + std::tm leftTimeStructure = { 0, 0, 0, leftControlPoint.day, leftControlPoint.month - 1, leftControlPoint.year - 1900 }; + std::tm rightTimeStructure = { 0, 0, 0, rightControlPoint.day, rightControlPoint.month - 1, rightControlPoint.year - 1900 }; time_t leftTime = mktime(&leftTimeStructure); time_t rightTime = mktime(&rightTimeStructure); if (leftTime == -1 || rightTime == -1) { // date is not initialized, no difference can be computed return std::numeric_limits::max(); } + // compute distance here double secondsPerDay = 60 * 60 * 24; double timeDifferenceInDays = std::difftime(leftTime, rightTime) / secondsPerDay; return timeDifferenceInDays; } diff --git a/Modules/SemanticRelations/src/mitkDICOMHelper.cpp b/Modules/SemanticRelations/src/mitkDICOMHelper.cpp index cc05dc88cd..c119edbeae 100644 --- a/Modules/SemanticRelations/src/mitkDICOMHelper.cpp +++ b/Modules/SemanticRelations/src/mitkDICOMHelper.cpp @@ -1,163 +1,163 @@ /*=================================================================== 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. ===================================================================*/ // semantic relations module #include "mitkDICOMHelper.h" #include "mitkSemanticRelationException.h" #include "mitkUIDGeneratorBoost.h" // mitk core #include // c++ #include -mitk::SemanticTypes::Date GetDateFromString(const std::string& dateAsString); +mitk::SemanticTypes::ControlPoint GetControlPointFromString(const std::string& dateAsString); mitk::SemanticTypes::CaseID mitk::GetCaseIDFromDataNode(const mitk::DataNode* dataNode) { if (nullptr == dataNode) { mitkThrowException(SemanticRelationException) << "Not a valid data node."; } mitk::BaseData* baseData = dataNode->GetData(); if (nullptr == baseData) { mitkThrowException(SemanticRelationException) << "No valid base data."; } // extract suitable DICOM tag to use as the case id // two alternatives can be used: // - DICOM tag "0x0010, 0x0010" is PatientName // - DICOM tag "0x0010, 0x0020" is PatientID // in the current implementation the PatientID (0x0010, 0x0010) is used mitk::BaseProperty* dicomTag = baseData->GetProperty(mitk::GeneratePropertyNameForDICOMTag(0x0010, 0x0010).c_str()); if (nullptr == dicomTag) { mitkThrowException(SemanticRelationException) << "Not a valid DICOM property."; } std::string dicomTagAsString = dicomTag->GetValueAsString(); return dicomTagAsString; } mitk::SemanticTypes::ID mitk::GetIDFromDataNode(const mitk::DataNode* dataNode) { if (nullptr == dataNode) { mitkThrowException(SemanticRelationException) << "Not a valid data node."; } mitk::BaseData* baseData = dataNode->GetData(); if (nullptr == baseData) { mitkThrowException(SemanticRelationException) << "No valid base data."; } // extract suitable DICOM tag to use as the data node id // DICOM tag "0x0020, 0x000e" is SeriesInstanceUID mitk::BaseProperty* dicomTag = baseData->GetProperty(mitk::GeneratePropertyNameForDICOMTag(0x0020, 0x000e).c_str()); if (nullptr == dicomTag) { mitkThrowException(SemanticRelationException) << "Not a valid DICOM property."; } std::string dicomTagAsString = dicomTag->GetValueAsString(); return dicomTagAsString; } -mitk::SemanticTypes::Date mitk::GetDICOMDateFromDataNode(const mitk::DataNode* dataNode) +mitk::SemanticTypes::ControlPoint mitk::GetDICOMDateFromDataNode(const mitk::DataNode* dataNode) { if (nullptr == dataNode) { mitkThrowException(SemanticRelationException) << "Not a valid data node."; } mitk::BaseData* baseData = dataNode->GetData(); if (nullptr == baseData) { mitkThrowException(SemanticRelationException) << "No valid base data."; } // extract suitable DICOM tag to use as the data node id // DICOM tag "0x0008, 0x0022" is AcquisitionDate mitk::BaseProperty* acquisitionDateProperty = baseData->GetProperty(mitk::GeneratePropertyNameForDICOMTag(0x0008, 0x0022).c_str()); if (nullptr == acquisitionDateProperty) { mitkThrowException(SemanticRelationException) << "Not a valid DICOM property."; } std::string acquisitionDateAsString = acquisitionDateProperty->GetValueAsString(); - return GetDateFromString(acquisitionDateAsString); + return GetControlPointFromString(acquisitionDateAsString); } mitk::SemanticTypes::InformationType mitk::GetDICOMModalityFromDataNode(const mitk::DataNode* dataNode) { if (nullptr == dataNode) { mitkThrowException(SemanticRelationException) << "Not a valid data node."; } mitk::BaseData* baseData = dataNode->GetData(); if (nullptr == baseData) { mitkThrowException(SemanticRelationException) << "No valid base data."; } // extract suitable DICOM tag to use as the information type // DICOM tag "0x0008, 0x0060" is Modality mitk::BaseProperty* dicomTag = baseData->GetProperty(mitk::GeneratePropertyNameForDICOMTag(0x0008, 0x0060).c_str()); if (nullptr == dicomTag) { mitkThrowException(SemanticRelationException) << "Not a valid DICOM property."; } std::string dicomTagAsString = dicomTag->GetValueAsString(); return dicomTagAsString; } std::string mitk::TrimDICOM(const std::string& identifier) { if (identifier.empty()) { return identifier; } // leading whitespace std::size_t first = identifier.find_first_not_of(' '); if (std::string::npos == first) { return ""; } // trailing whitespace std::size_t last = identifier.find_last_not_of(' '); return identifier.substr(first, last - first + 1); } -mitk::SemanticTypes::Date GetDateFromString(const std::string& dateAsString) +mitk::SemanticTypes::ControlPoint GetControlPointFromString(const std::string& dateAsString) { if (dateAsString.size() != 8) // string does not represent a DICOM date { - return mitk::SemanticTypes::Date(); + return mitk::SemanticTypes::ControlPoint(); } - mitk::SemanticTypes::Date date; - date.UID = mitk::UIDGeneratorBoost::GenerateUID(); + mitk::SemanticTypes::ControlPoint controlPoint; + // date expected to be YYYYMMDD (8 characters) - date.year = std::strtoul(dateAsString.substr(0, 4).c_str(), nullptr, 10); - date.month = std::strtoul(dateAsString.substr(4, 2).c_str(), nullptr, 10); - date.day = std::strtoul(dateAsString.substr(6, 2).c_str(), nullptr, 10); + controlPoint.year = std::strtoul(dateAsString.substr(0, 4).c_str(), nullptr, 10); + controlPoint.month = std::strtoul(dateAsString.substr(4, 2).c_str(), nullptr, 10); + controlPoint.day = std::strtoul(dateAsString.substr(6, 2).c_str(), nullptr, 10); - return date; + return controlPoint; } diff --git a/Modules/SemanticRelations/src/mitkRelationStorage.cpp b/Modules/SemanticRelations/src/mitkRelationStorage.cpp index 71abf627c2..ebd0a502fa 100644 --- a/Modules/SemanticRelations/src/mitkRelationStorage.cpp +++ b/Modules/SemanticRelations/src/mitkRelationStorage.cpp @@ -1,1406 +1,1188 @@ /*=================================================================== 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. ===================================================================*/ // semantic relations module #include "mitkRelationStorage.h" #include "mitkNodePredicates.h" // multi label module #include // mitk core #include #include // c++ #include #include void mitk::RelationStorage::SetDataStorage(DataStorage::Pointer dataStorage) { if (m_DataStorage != dataStorage) { // set the new data storage m_DataStorage = dataStorage; } } std::vector mitk::RelationStorage::GetAllLesionsOfCase(const SemanticTypes::CaseID& caseID) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return std::vector(); } // retrieve a vector property that contains the valid lesion-IDs for the current case mitk::VectorProperty* vectorProperty = dynamic_cast*>(propertyList->GetProperty("lesions")); if (nullptr == vectorProperty) { MITK_INFO << "Could not find any lesion in the storage."; return std::vector(); } std::vector vectorValue = vectorProperty->GetValue(); std::vector allLesionsOfCase; for (const auto& lesionID : vectorValue) { SemanticTypes::Lesion generatedLesion = GenerateLesion(caseID, lesionID); if (!generatedLesion.UID.empty()) { allLesionsOfCase.push_back(generatedLesion); } } return allLesionsOfCase; } mitk::SemanticTypes::Lesion mitk::RelationStorage::GetRepresentedLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& segmentationID) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return SemanticTypes::Lesion(); } // retrieve a vector property that contains the referenced ID of a segmentation (0. image ID 1. lesion ID) mitk::VectorProperty* segmentationVectorProperty = dynamic_cast*>(propertyList->GetProperty(segmentationID)); if (nullptr == segmentationVectorProperty) { MITK_INFO << "Could not find the segmentation node " << segmentationID << " in the storage."; return SemanticTypes::Lesion(); } std::vector segmentationVectorValue = segmentationVectorProperty->GetValue(); // the lesion ID of a segmentation is the second value in the vector if (segmentationVectorValue.size() != 2) { MITK_INFO << "Incorrect segmentation storage. Not two (2) IDs stored."; return SemanticTypes::Lesion(); } else { std::string lesionID = segmentationVectorValue[1]; return GenerateLesion(caseID, lesionID); } } std::vector mitk::RelationStorage::GetAllSegmentationsOfCase(const SemanticTypes::CaseID& caseID) { if (m_DataStorage.IsNull()) { MITK_INFO << "No valid data storage found in the mitkPersistenceService-class. Segmentations of the current case can not be retrieved."; return std::vector(); } std::vector allSegmentationIDsOfCase = GetAllSegmentationIDsOfCase(caseID); std::vector allSegmentationsOfCase; // get all segmentation nodes of the current data storage // only those nodes are respected, that are currently held in the data storage DataStorage::SetOfObjects::ConstPointer segmentationNodes = m_DataStorage->GetSubset(NodePredicates::GetSegmentationPredicate()); for (auto it = segmentationNodes->Begin(); it != segmentationNodes->End(); ++it) { DataNode* segmentationNode = it->Value(); try { // find the corresponding segmentation node for the given segmentation ID std::string nodeCaseID = GetCaseIDFromDataNode(segmentationNode); std::string nodeSegmentationID = GetIDFromDataNode(segmentationNode); if (nodeCaseID == caseID && (std::find(allSegmentationIDsOfCase.begin(), allSegmentationIDsOfCase.end(), nodeSegmentationID) != allSegmentationIDsOfCase.end())) { // found current image node in the storage, add it to the return vector allSegmentationsOfCase.push_back(segmentationNode); } } catch (const std::exception&) { // found a segmentation node that is not stored in the semantic relations // this segmentation node does not have any DICOM information --> exception thrown // continue with the next segmentation to compare IDs continue; } } return allSegmentationsOfCase; } std::vector mitk::RelationStorage::GetAllSegmentationIDsOfCase(const SemanticTypes::CaseID& caseID) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return std::vector(); } // retrieve a vector property that contains the valid segmentation-IDs for the current case mitk::VectorProperty* allSegmentationsVectorProperty = dynamic_cast*>(propertyList->GetProperty("segmentations")); if (nullptr == allSegmentationsVectorProperty) { MITK_INFO << "Could not find any segmentation in the storage."; return std::vector(); } return allSegmentationsVectorProperty->GetValue(); } mitk::SemanticTypes::ControlPoint mitk::RelationStorage::GetControlPointOfData(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& dataNodeID) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return SemanticTypes::ControlPoint(); } // retrieve a vector property that contains the information type and the referenced ID of a data node (0. information type 1. control point ID) mitk::VectorProperty* dataNodeVectorProperty = dynamic_cast*>(propertyList->GetProperty(dataNodeID)); if (nullptr == dataNodeVectorProperty) { MITK_INFO << "Could not find the data node " << dataNodeID << " in the storage."; return SemanticTypes::ControlPoint(); } std::vector dataNodeVectorValue = dataNodeVectorProperty->GetValue(); SemanticTypes::ControlPoint controlPoint; // an image node has to have exactly two values (the information type and the ID of the control point) if (dataNodeVectorValue.size() != 2) { MITK_INFO << "Incorrect data storage. Not two (2) values stored."; return SemanticTypes::ControlPoint(); } else { // the second value of the data node vector is the ID of the referenced control point std::string controlPointID = dataNodeVectorValue[1]; - // retrieve a vector property that contains the referenced ID of the dates of a control point (0. startPoint ID 1. endPoint ID) - mitk::VectorProperty* controlPointVectorProperty = dynamic_cast*>(propertyList->GetProperty(controlPointID)); + // retrieve a vector property that contains the integer values of the date of a control point (0. year 1. month 2. day) + mitk::VectorProperty* controlPointVectorProperty = dynamic_cast*>(propertyList->GetProperty(controlPointID)); if (nullptr == controlPointVectorProperty) { MITK_INFO << "Could not find the control point " << controlPointID << " in the storage."; return SemanticTypes::ControlPoint(); } - std::vector controlPointVectorValue = controlPointVectorProperty->GetValue(); - // a control point has to have exactly two values (the ID of two dates) - if (controlPointVectorValue.size() != 2) + std::vector controlPointVectorValue = controlPointVectorProperty->GetValue(); + // a control point has to have exactly three integer values (year, month and day) + if (controlPointVectorValue.size() != 3) { - MITK_INFO << "Incorrect control point storage. Not two (2) IDs of the start point and the end point are stored."; + MITK_INFO << "Incorrect control point storage. Not three (3) values of the date are stored."; return SemanticTypes::ControlPoint(); } else { - // retrieve the start date - std::string startPointID = controlPointVectorValue[0]; - mitk::VectorProperty* startPointVectorProperty = dynamic_cast*>(propertyList->GetProperty(startPointID)); - if (nullptr == startPointVectorProperty) - { - MITK_INFO << "Could not find the start date " << startPointID << " of the control point " << controlPointID << " in the storage."; - return SemanticTypes::ControlPoint(); - } - - std::vector startPointValue = startPointVectorProperty->GetValue(); - SemanticTypes::Date startPoint; - // a date has to have exactly three integer values - if (startPointValue.size() != 3) - { - MITK_INFO << "Incorrect start point storage. Not three (3) values of the date are stored."; - return SemanticTypes::ControlPoint(); - } - else - { - startPoint.UID = startPointID; - startPoint.year = startPointValue[0]; - startPoint.month = startPointValue[1]; - startPoint.day = startPointValue[2]; - } - - // retrieve the end date - std::string endPointID = controlPointVectorValue[1]; - mitk::VectorProperty* endPointVectorProperty = dynamic_cast*>(propertyList->GetProperty(endPointID)); - if (nullptr == endPointVectorProperty) - { - MITK_INFO << "Could not find the end date " << endPointID << " of the control point " << controlPointID << " in the storage."; - return SemanticTypes::ControlPoint(); - } - - std::vector endPointValue = endPointVectorProperty->GetValue(); - SemanticTypes::Date endPoint; - // a date has to have exactly three integer values - if (endPointValue.size() != 3) - { - MITK_INFO << "Incorrect end point storage. Not three (3) values of the date are stored."; - return SemanticTypes::ControlPoint(); - } - else - { - endPoint.UID = endPointID; - endPoint.year = endPointValue[0]; - endPoint.month = endPointValue[1]; - endPoint.day = endPointValue[2]; - } - // set the values of the control point controlPoint.UID = controlPointID; - controlPoint.startPoint = startPoint; - controlPoint.endPoint = endPoint; + controlPoint.year = controlPointVectorValue[0]; + controlPoint.month = controlPointVectorValue[1]; + controlPoint.day = controlPointVectorValue[2]; } } return controlPoint; } std::vector mitk::RelationStorage::GetAllControlPointsOfCase(const SemanticTypes::CaseID& caseID) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return std::vector(); } // retrieve a vector property that contains the valid control point-IDs for the current case mitk::VectorProperty* vectorProperty = dynamic_cast*>(propertyList->GetProperty("controlpoints")); if (nullptr == vectorProperty) { MITK_INFO << "Could not find any control points in the storage."; return std::vector(); } std::vector vectorValue = vectorProperty->GetValue(); std::vector allControlPoints; for (const auto& controlPointID : vectorValue) { - // retrieve a vector property that contains the referenced ID of the dates of a control point (0. startPoint ID 1. endPoint ID) - mitk::VectorProperty* controlPointVectorProperty = dynamic_cast*>(propertyList->GetProperty(controlPointID)); + // retrieve a vector property that contains the integer values of the date of a control point (0. year 1. month 2. day) + mitk::VectorProperty* controlPointVectorProperty = dynamic_cast*>(propertyList->GetProperty(controlPointID)); if (nullptr == controlPointVectorProperty) { MITK_INFO << "Could not find the control point " << controlPointID << " in the storage."; continue; } - std::vector controlPointVectorValue = controlPointVectorProperty->GetValue(); - // a control point has to have exactly two values (the ID of two dates) - if (controlPointVectorValue.size() != 2) + std::vector controlPointVectorValue = controlPointVectorProperty->GetValue(); + // a control point has to have exactly three integer values (year, month and day) + if (controlPointVectorValue.size() != 3) { - MITK_INFO << "Incorrect control point storage. Not two (2) IDs of the start point and the end point are stored."; + MITK_INFO << "Incorrect control point storage. Not three (3) values of the date are stored."; continue; } else { - // retrieve the start date - std::string startPointID = controlPointVectorValue[0]; - mitk::VectorProperty* startPointVectorProperty = dynamic_cast*>(propertyList->GetProperty(startPointID)); - if (nullptr == startPointVectorProperty) - { - MITK_INFO << "Could not find the start date " << startPointID << " of the control point " << controlPointID << " in the storage."; - continue; - } - - std::vector startPointValue = startPointVectorProperty->GetValue(); - SemanticTypes::Date startPoint; - // a date has to have exactly three integer values - if (startPointValue.size() != 3) - { - MITK_INFO << "Incorrect start point storage. Not three (3) values of the date are stored."; - continue; - } - else - { - startPoint.UID = startPointID; - startPoint.year = startPointValue[0]; - startPoint.month = startPointValue[1]; - startPoint.day = startPointValue[2]; - } - - // retrieve the end date - std::string endPointID = controlPointVectorValue[1]; - mitk::VectorProperty* endPointVectorProperty = dynamic_cast*>(propertyList->GetProperty(endPointID)); - if (nullptr == endPointVectorProperty) - { - MITK_INFO << "Could not find the end date " << endPointID << " of the control point " << controlPointID << " in the storage."; - continue; - } - - std::vector endPointValue = endPointVectorProperty->GetValue(); - SemanticTypes::Date endPoint; - // a date has to have exactly three integer values - if (endPointValue.size() != 3) - { - MITK_INFO << "Incorrect end point storage. Not three (3) values of the date are stored."; - continue; - } - else - { - endPoint.UID = endPointID; - endPoint.year = endPointValue[0]; - endPoint.month = endPointValue[1]; - endPoint.day = endPointValue[2]; - } - + // set the values of the control point SemanticTypes::ControlPoint generatedControlPoint; generatedControlPoint.UID = controlPointID; - generatedControlPoint.startPoint = startPoint; - generatedControlPoint.endPoint = endPoint; + generatedControlPoint.year = controlPointVectorValue[0]; + generatedControlPoint.month = controlPointVectorValue[1]; + generatedControlPoint.day = controlPointVectorValue[2]; allControlPoints.push_back(generatedControlPoint); } } return allControlPoints; } mitk::SemanticTypes::InformationType mitk::RelationStorage::GetInformationTypeOfImage(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& imageID) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return SemanticTypes::InformationType(); } // retrieve a vector property that contains the information type and the referenced ID of an image data node (0. information type 1. control point ID) mitk::VectorProperty* dataNodeVectorProperty = dynamic_cast*>(propertyList->GetProperty(imageID)); if (nullptr == dataNodeVectorProperty) { MITK_INFO << "Could not find the image " << imageID << " in the storage."; return SemanticTypes::InformationType(); } std::vector dataNodeVectorValue = dataNodeVectorProperty->GetValue(); // an image node has to have exactly two values (the information type and the ID of the control point) if (dataNodeVectorValue.size() != 2) { MITK_INFO << "Incorrect data storage. Not two (2) values stored."; return SemanticTypes::InformationType(); } else { // the first value of the data node vector is the information type return dataNodeVectorValue[0]; } } std::vector mitk::RelationStorage::GetAllInformationTypesOfCase(const SemanticTypes::CaseID& caseID) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return std::vector(); } // retrieve a vector property that contains the valid information types of the current case mitk::VectorProperty* informationTypeVectorProperty = dynamic_cast*>(propertyList->GetProperty("informationtypes")); if (nullptr == informationTypeVectorProperty) { MITK_INFO << "Could not find any information types in the storage."; return std::vector(); } return informationTypeVectorProperty->GetValue(); } std::vector mitk::RelationStorage::GetAllImagesOfCase(const SemanticTypes::CaseID& caseID) { if (m_DataStorage.IsNull()) { MITK_INFO << "No valid data storage found in the mitkPersistenceService-class. Images of the current case can not be retrieved."; return std::vector(); } std::vector allImageIDsOfCase = GetAllImageIDsOfCase(caseID); std::vector allImagesOfCase; // get all image nodes of the current data storage // only those nodes are respected, that are currently held in the data storage DataStorage::SetOfObjects::ConstPointer imageNodes = m_DataStorage->GetSubset(NodePredicates::GetImagePredicate()); for (auto it = imageNodes->Begin(); it != imageNodes->End(); ++it) { DataNode* imageNode = it->Value(); // find the corresponding image node for the given segmentation ID std::string nodeCaseID = GetCaseIDFromDataNode(imageNode); std::string nodeImageID = GetIDFromDataNode(imageNode); if (nodeCaseID == caseID && (std::find(allImageIDsOfCase.begin(), allImageIDsOfCase.end(), nodeImageID) != allImageIDsOfCase.end())) { // found current image node in the storage, add it to the return vector allImagesOfCase.push_back(imageNode); } } return allImagesOfCase; } std::vector mitk::RelationStorage::GetAllImageIDsOfCase(const SemanticTypes::CaseID& caseID) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return std::vector(); } // retrieve a vector property that contains the valid image-IDs of the current case mitk::VectorProperty* allImagesVectorProperty = dynamic_cast*>(propertyList->GetProperty("images")); if (nullptr == allImagesVectorProperty) { MITK_INFO << "Could not find any image in the storage."; return std::vector(); } return allImagesVectorProperty->GetValue(); } std::vector mitk::RelationStorage::GetAllCaseIDs() { PERSISTENCE_GET_SERVICE_MACRO if (nullptr == persistenceService) { MITK_INFO << "Persistence service could not be loaded"; return std::vector(); } // the property list is valid for a certain scenario and contains all the case IDs of the radiological user's MITK session std::string listIdentifier = "caseIDs"; mitk::PropertyList::Pointer propertyList = persistenceService->GetPropertyList(listIdentifier); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << listIdentifier << " for the current MITK workbench / session."; return std::vector(); } // retrieve a vector property that contains all case IDs mitk::VectorProperty* caseIDsVectorProperty = dynamic_cast*>(propertyList->GetProperty(listIdentifier)); if (nullptr == caseIDsVectorProperty) { MITK_INFO << "Could not find the property " << listIdentifier << " for the " << listIdentifier << " property list."; return std::vector(); } return caseIDsVectorProperty->GetValue(); } void mitk::RelationStorage::AddCase(const SemanticTypes::CaseID& caseID) { PERSISTENCE_GET_SERVICE_MACRO if (nullptr == persistenceService) { MITK_INFO << "Persistence service could not be loaded"; return; } // the property list is valid for a certain scenario and contains all the case IDs of the radiological user's MITK session std::string listIdentifier = "caseIDs"; mitk::PropertyList::Pointer propertyList = persistenceService->GetPropertyList(listIdentifier); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << listIdentifier << " for the current MITK workbench / session."; return; } // retrieve a vector property that contains all case IDs mitk::VectorProperty::Pointer caseIDsVectorProperty = dynamic_cast*>(propertyList->GetProperty(listIdentifier)); std::vector caseIDsVectorValue; if (nullptr == caseIDsVectorProperty) { caseIDsVectorProperty = mitk::VectorProperty::New(); } else { caseIDsVectorValue = caseIDsVectorProperty->GetValue(); } auto existingCase = std::find(caseIDsVectorValue.begin(), caseIDsVectorValue.end(), caseID); if (existingCase != caseIDsVectorValue.end()) { return; } else { // add case to the "caseIDs" property list caseIDsVectorValue.push_back(caseID); caseIDsVectorProperty->SetValue(caseIDsVectorValue); propertyList->SetProperty(listIdentifier, caseIDsVectorProperty); } } void mitk::RelationStorage::AddImage(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& imageNodeID) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return; } // retrieve a vector property that contains the valid image-IDs for the current case mitk::VectorProperty::Pointer allImagesVectorProperty = dynamic_cast*>(propertyList->GetProperty("images")); std::vector allImagesIDs; if (nullptr == allImagesVectorProperty) { allImagesVectorProperty = mitk::VectorProperty::New(); } else { allImagesIDs = allImagesVectorProperty->GetValue(); } auto existingImage = std::find(allImagesIDs.begin(), allImagesIDs.end(), imageNodeID); if (existingImage != allImagesIDs.end()) { return; } else { // add image to the "images" property list allImagesIDs.push_back(imageNodeID); allImagesVectorProperty->SetValue(allImagesIDs); propertyList->SetProperty("images", allImagesVectorProperty); // add the image itself mitk::VectorProperty::Pointer imageNodeVectorProperty = mitk::VectorProperty::New(); // an image node has to have exactly two values (the information type and the ID of the control point) std::vector imageNodeVectorValue(2); imageNodeVectorProperty->SetValue(imageNodeVectorValue); propertyList->SetProperty(imageNodeID, imageNodeVectorProperty); } } void mitk::RelationStorage::RemoveImage(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& imageNodeID) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return; } // retrieve a vector property that contains the valid image-IDs for the current case mitk::VectorProperty::Pointer allImagesVectorProperty = dynamic_cast*>(propertyList->GetProperty("images")); if (nullptr == allImagesVectorProperty) { MITK_INFO << "Could not find any images in the storage."; return; } // remove the image reference from the list of all images of the current case std::vector allImagesIDs = allImagesVectorProperty->GetValue(); allImagesIDs.erase(std::remove(allImagesIDs.begin(), allImagesIDs.end(), imageNodeID), allImagesIDs.end()); if (allImagesIDs.size() == 0) { // no more images stored -> remove the images property list propertyList->DeleteProperty("images"); } else { // or store the modified vector value allImagesVectorProperty->SetValue(allImagesIDs); } // remove the image instance itself propertyList->DeleteProperty(imageNodeID); } void mitk::RelationStorage::AddSegmentation(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& segmentationNodeID, const SemanticTypes::ID& parentNodeID) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return; } // retrieve a vector property that contains the valid segmentation-IDs for the current case mitk::VectorProperty::Pointer allSegmentationsVectorProperty = dynamic_cast*>(propertyList->GetProperty("segmentations")); std::vector allSegmentationsIDs; if (nullptr == allSegmentationsVectorProperty) { allSegmentationsVectorProperty = mitk::VectorProperty::New(); } else { allSegmentationsIDs = allSegmentationsVectorProperty->GetValue(); } auto existingImage = std::find(allSegmentationsIDs.begin(), allSegmentationsIDs.end(), segmentationNodeID); if (existingImage != allSegmentationsIDs.end()) { return; } else { // add segmentation to the "segmentations" property list allSegmentationsIDs.push_back(segmentationNodeID); allSegmentationsVectorProperty->SetValue(allSegmentationsIDs); propertyList->SetProperty("segmentations", allSegmentationsVectorProperty); // add the segmentation itself mitk::VectorProperty::Pointer segmentationNodeVectorProperty = mitk::VectorProperty::New(); // a segmentation node has to have exactly two values (the ID of the referenced image and the ID of the referenced lesion) std::vector segmentationNodeVectorValue(2); segmentationNodeVectorValue[0] = parentNodeID; segmentationNodeVectorProperty->SetValue(segmentationNodeVectorValue); propertyList->SetProperty(segmentationNodeID, segmentationNodeVectorProperty); } } void mitk::RelationStorage::RemoveSegmentation(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& segmentationNodeID) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return; } // retrieve a vector property that contains the valid segmentation-IDs for the current case mitk::VectorProperty::Pointer allSegmentationsVectorProperty = dynamic_cast*>(propertyList->GetProperty("segmentations")); if (nullptr == allSegmentationsVectorProperty) { MITK_INFO << "Could not find any segmentation in the storage."; return; } // remove the lesion reference from the list of all lesions of the current case std::vector allSegmentationsIDs = allSegmentationsVectorProperty->GetValue(); allSegmentationsIDs.erase(std::remove(allSegmentationsIDs.begin(), allSegmentationsIDs.end(), segmentationNodeID), allSegmentationsIDs.end()); if (allSegmentationsIDs.size() == 0) { // no more segmentations stored -> remove the segmentations property list propertyList->DeleteProperty("segmentations"); } else { // or store the modified vector value allSegmentationsVectorProperty->SetValue(allSegmentationsIDs); } // remove the lesion instance itself propertyList->DeleteProperty(segmentationNodeID); } void mitk::RelationStorage::AddLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return; } // retrieve a vector property that contains the valid lesion-IDs for the current case mitk::VectorProperty::Pointer lesionsVectorProperty = dynamic_cast*>(propertyList->GetProperty("lesions")); std::vector lesionsVectorValue; if (nullptr == lesionsVectorProperty) { lesionsVectorProperty = mitk::VectorProperty::New(); } else { lesionsVectorValue = lesionsVectorProperty->GetValue(); } const auto& existingIndex = std::find(lesionsVectorValue.begin(), lesionsVectorValue.end(), lesion.UID); if (existingIndex != lesionsVectorValue.end()) { return; } else { // add the new lesion id from the given lesion to the vector of all current lesion IDs lesionsVectorValue.push_back(lesion.UID); // overwrite the current vector property with the new, extended string vector lesionsVectorProperty->SetValue(lesionsVectorValue); propertyList->SetProperty("lesions", lesionsVectorProperty); // add the lesion with the lesion UID as the key and the lesion information as value std::vector lesionData; lesionData.push_back(lesion.name); lesionData.push_back(lesion.lesionClass.UID); mitk::VectorProperty::Pointer newLesionVectorProperty = mitk::VectorProperty::New(); newLesionVectorProperty->SetValue(lesionData); propertyList->SetProperty(lesion.UID, newLesionVectorProperty); // add the lesion class with the lesion class UID as key and the class type as value std::string lesionClassType = lesion.lesionClass.classType; propertyList->SetStringProperty(lesion.lesionClass.UID.c_str(), lesionClassType.c_str()); } } void mitk::RelationStorage::OverwriteLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return; } // retrieve a vector property that contains the valid lesion-IDs for the current case mitk::VectorProperty* lesionVectorProperty = dynamic_cast*>(propertyList->GetProperty("lesions")); if (nullptr == lesionVectorProperty) { MITK_INFO << "Could not find any lesion in the storage."; return; } std::vector lesionVectorValue = lesionVectorProperty->GetValue(); const auto existingLesion = std::find(lesionVectorValue.begin(), lesionVectorValue.end(), lesion.UID); if (existingLesion != lesionVectorValue.end()) { // overwrite the referenced lesion class UID with the new, given lesion class data std::vector lesionData; lesionData.push_back(lesion.name); lesionData.push_back(lesion.lesionClass.UID); mitk::VectorProperty::Pointer newLesionVectorProperty = mitk::VectorProperty::New(); newLesionVectorProperty->SetValue(lesionData); propertyList->SetProperty(lesion.UID, newLesionVectorProperty); // overwrite the lesion class with the lesion class UID as key and the new, given class type as value std::string lesionClassType = lesion.lesionClass.classType; propertyList->SetStringProperty(lesion.lesionClass.UID.c_str(), lesionClassType.c_str()); } else { MITK_INFO << "Could not find lesion " << lesion.UID << " in the storage. Cannot overwrite the lesion."; } } void mitk::RelationStorage::LinkSegmentationToLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& segmentationID, const SemanticTypes::Lesion& lesion) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return; } // retrieve a vector property that contains the valid lesion-IDs for the current case mitk::VectorProperty* lesionVectorProperty = dynamic_cast*>(propertyList->GetProperty("lesions")); if (nullptr == lesionVectorProperty) { MITK_INFO << "Could not find any lesion property in the storage."; return; } std::vector lesionVectorValue = lesionVectorProperty->GetValue(); const auto existingLesion = std::find(lesionVectorValue.begin(), lesionVectorValue.end(), lesion.UID); if (existingLesion != lesionVectorValue.end()) { // set / overwrite the lesion reference of the given segmentation // retrieve a vector property that contains the referenced ID of a segmentation (0. image ID 1. lesion ID) mitk::VectorProperty* segmentationVectorProperty = dynamic_cast*>(propertyList->GetProperty(segmentationID)); if (nullptr == segmentationVectorProperty) { MITK_INFO << "Could not find the segmentation node " << segmentationID << " in the storage. Cannot link segmentation to lesion."; return; } std::vector segmentationVectorValue = segmentationVectorProperty->GetValue(); if (segmentationVectorValue.size() != 2) { MITK_INFO << "Incorrect segmentation storage. Not two (2) IDs stored."; return; } else { // the lesion ID of a segmentation is the second value in the vector segmentationVectorValue[1] = lesion.UID; segmentationVectorProperty->SetValue(segmentationVectorValue); } } else { MITK_INFO << "Could not find lesion " << lesion.UID << " in the storage. Cannot link segmentation to lesion."; } } void mitk::RelationStorage::UnlinkSegmentationFromLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& segmentationID) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return; } // retrieve a vector property that contains the referenced ID of a segmentation (0. image ID 1. lesion ID) mitk::VectorProperty* segmentationVectorProperty = dynamic_cast*>(propertyList->GetProperty(segmentationID)); if (nullptr == segmentationVectorProperty) { MITK_INFO << "Could not find the segmentation node " << segmentationID << " in the storage. Cannot unlink lesion from segmentation."; return; } std::vector segmentationVectorValue = segmentationVectorProperty->GetValue(); // a segmentation has to have exactly two values (the ID of the linked image and the ID of the lesion) if (segmentationVectorValue.size() != 2) { MITK_INFO << "Incorrect data storage. Not two (2) values stored."; return; } else { // the second value of the data node vector is the ID of the referenced lesion // set the lesion reference to an empty string for removal segmentationVectorValue[1] = ""; segmentationVectorProperty->SetValue(segmentationVectorValue); } } void mitk::RelationStorage::RemoveLesion(const mitk::SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return; } // retrieve a vector property that contains the valid lesions of the current case mitk::VectorProperty* lesionVectorProperty = dynamic_cast*>(propertyList->GetProperty("lesions")); if (nullptr == lesionVectorProperty) { MITK_INFO << "Could not find any lesion property in the storage."; return; } // remove the lesion reference from the list of all lesions of the current case std::vector lesionVectorValue = lesionVectorProperty->GetValue(); lesionVectorValue.erase(std::remove(lesionVectorValue.begin(), lesionVectorValue.end(), lesion.UID), lesionVectorValue.end()); if (lesionVectorValue.size() == 0) { // no more lesions stored -> remove the lesions property list propertyList->DeleteProperty("lesions"); } else { // or store the modified vector value lesionVectorProperty->SetValue(lesionVectorValue); } // remove the lesion instance itself // the lesion data is stored under the lesion ID mitk::VectorProperty* lesionDataProperty = dynamic_cast*>(propertyList->GetProperty(lesion.UID)); if (nullptr == lesionDataProperty) { MITK_INFO << "Lesion " << lesion.UID << " not found (already removed?). Cannot remove the lesion."; return; } std::vector lesionData = lesionDataProperty->GetValue(); // a lesion date has to have exactly two values (the name of the lesion and the UID of the lesion class) if (lesionData.size() != 2) { MITK_INFO << "Incorrect lesion data storage. Not two (2) strings of the lesion UID and the lesion name are stored."; } else { std::string lesionClassID = lesionData[1]; RemoveLesionClass(caseID, lesionClassID); } propertyList->DeleteProperty(lesion.UID); } void mitk::RelationStorage::RemoveLesionClass(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& lesionClassID) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return; } // retrieve a vector property that contains the lesion class mitk::StringProperty* lesionClassProperty = dynamic_cast(propertyList->GetProperty(lesionClassID)); if (nullptr == lesionClassProperty) { MITK_INFO << "Lesion class " << lesionClassID << " not found (already removed?). Cannot remove the lesion class."; return; } // retrieve a vector property that contains the valid lesions of the current case mitk::VectorProperty* lesionVectorProperty = dynamic_cast*>(propertyList->GetProperty("lesions")); if (nullptr == lesionVectorProperty) { return; } // check if the lesion class ID is referenced by any other lesion std::vector lesionVectorValue = lesionVectorProperty->GetValue(); const auto existingLesionClass = std::find_if(lesionVectorValue.begin(), lesionVectorValue.end(), [&propertyList, &lesionClassID](const std::string& lesionID) { mitk::VectorProperty* lesionDataProperty = dynamic_cast*>(propertyList->GetProperty(lesionID)); if (nullptr == lesionDataProperty) { return false; } else { std::vector lesionData = lesionDataProperty->GetValue(); // a lesion date has to have exactly two values (the name of the lesion and the UID of the lesion class) if (lesionData.size() != 2) { return false; } else { return lesionData[1] == lesionClassID; } } }); if (existingLesionClass == lesionVectorValue.end()) { // lesion class ID not referenced; remove lesion class propertyList->DeleteProperty(lesionClassID); } } void mitk::RelationStorage::AddControlPoint(const SemanticTypes::CaseID& caseID, const SemanticTypes::ControlPoint& controlPoint) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return; } // retrieve a vector property that contains the valid controlPoint UIDs for the current case mitk::VectorProperty::Pointer controlPointVectorProperty = dynamic_cast*>(propertyList->GetProperty("controlpoints")); std::vector controlPointVectorValue; if (nullptr == controlPointVectorProperty) { controlPointVectorProperty = mitk::VectorProperty::New(); } else { controlPointVectorValue = controlPointVectorProperty->GetValue(); } const auto existingControlPoint = std::find(controlPointVectorValue.begin(), controlPointVectorValue.end(), controlPoint.UID); if (existingControlPoint != controlPointVectorValue.end()) { return; } else { // add the new control point UID from the given control point to the vector of all current control point UIDs controlPointVectorValue.push_back(controlPoint.UID); // overwrite the current vector property with the new, extended string vector controlPointVectorProperty->SetValue(controlPointVectorValue); propertyList->SetProperty("controlpoints", controlPointVectorProperty); - // set the year, month and day of the start point - std::vector startPointValue; - startPointValue.push_back(controlPoint.startPoint.year); - startPointValue.push_back(controlPoint.startPoint.month); - startPointValue.push_back(controlPoint.startPoint.day); - - // store the start point - mitk::VectorProperty::Pointer startPointVectorProperty = mitk::VectorProperty::New(); - startPointVectorProperty->SetValue(startPointValue); - propertyList->SetProperty(controlPoint.startPoint.UID, startPointVectorProperty); - - // set the year, month and day of the end point - std::vector endPointValue; - endPointValue.push_back(controlPoint.endPoint.year); - endPointValue.push_back(controlPoint.endPoint.month); - endPointValue.push_back(controlPoint.endPoint.day); - - // store the end point - mitk::VectorProperty::Pointer endPointVectorProperty = mitk::VectorProperty::New(); - endPointVectorProperty->SetValue(endPointValue); - propertyList->SetProperty(controlPoint.endPoint.UID, endPointVectorProperty); - - // store the start point UID and the end point UID - std::vector controlPointDateReferences; - controlPointDateReferences.push_back(controlPoint.startPoint.UID); - controlPointDateReferences.push_back(controlPoint.endPoint.UID); - // store the control point references (the start point UID and the end point UID) - mitk::VectorProperty::Pointer newControlPointVectorProperty = mitk::VectorProperty::New(); - newControlPointVectorProperty->SetValue(controlPointDateReferences); - propertyList->SetProperty(controlPoint.UID, newControlPointVectorProperty); - } -} + // store the control point values (the three integer values of a date) + std::vector controlPointDate; + controlPointDate.push_back(controlPoint.year); + controlPointDate.push_back(controlPoint.month); + controlPointDate.push_back(controlPoint.day); -void mitk::RelationStorage::OverwriteControlPoint(const SemanticTypes::CaseID& caseID, const SemanticTypes::ControlPoint& controlPoint) -{ - mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); - if (nullptr == propertyList) - { - MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; - return; - } - // retrieve a vector property that contains the valid controlPoint UIDs for the current case - mitk::VectorProperty* controlPointVectorProperty = dynamic_cast*>(propertyList->GetProperty("controlpoints")); - if (nullptr == controlPointVectorProperty) - { - MITK_INFO << "Could not find any control point property in the storage."; - return; - } - - std::vector controlPointVectorValue = controlPointVectorProperty->GetValue(); - const auto existingControlPoint = std::find(controlPointVectorValue.begin(), controlPointVectorValue.end(), controlPoint.UID); - if (existingControlPoint != controlPointVectorValue.end()) - { - // retrieve the start date - mitk::VectorProperty* startPointVectorProperty = dynamic_cast*>(propertyList->GetProperty(controlPoint.startPoint.UID)); - if (nullptr == startPointVectorProperty) - { - MITK_INFO << "Could not find the start date " << controlPoint.startPoint.UID << " of the control point " << controlPoint.UID << " in the storage."; - return; - } - std::vector startPointValue = startPointVectorProperty->GetValue(); - // a date has to have exactly three integer values - if (startPointValue.size() != 3) - { - MITK_INFO << "Incorrect start point storage. Not three (3) values of the date are stored."; - return; - } - else - { - // set the year, month and day of the start point - startPointValue[0] = controlPoint.startPoint.year; - startPointValue[1] = controlPoint.startPoint.month; - startPointValue[2] = controlPoint.startPoint.day; - // overwrite the start point - startPointVectorProperty->SetValue(startPointValue); - } - - // retrieve the end date - mitk::VectorProperty* endPointVectorProperty = dynamic_cast*>(propertyList->GetProperty(controlPoint.endPoint.UID)); - if (nullptr == endPointVectorProperty) - { - MITK_INFO << "Could not find the end date " << controlPoint.endPoint.UID << " of the control point " << controlPoint.UID << " in the storage."; - return; - } - std::vector endPointValue = endPointVectorProperty->GetValue(); - // a date has to have exactly three integer values - if (endPointValue.size() != 3) - { - MITK_INFO << "Incorrect end point storage. Not three (3) values of the date are stored."; - return; - } - else - { - // set the year, month and day of the end point - endPointValue[0] = controlPoint.endPoint.year; - endPointValue[1] = controlPoint.endPoint.month; - endPointValue[2] = controlPoint.endPoint.day; - // overwrite the end point - endPointVectorProperty->SetValue(endPointValue); - } - } - else - { - MITK_INFO << "Could not find control point " << controlPoint.UID << " in the storage. Cannot overwrite the control point."; + mitk::VectorProperty::Pointer newControlPointVectorProperty = mitk::VectorProperty::New(); + newControlPointVectorProperty->SetValue(controlPointDate); + propertyList->SetProperty(controlPoint.UID, newControlPointVectorProperty); } } void mitk::RelationStorage::LinkDataToControlPoint(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& dataNodeID, const SemanticTypes::ControlPoint& controlPoint) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return; } // retrieve a vector property that contains the valid controlPoint UIDs for the current case mitk::VectorProperty* controlPointVectorProperty = dynamic_cast*>(propertyList->GetProperty("controlpoints")); if (nullptr == controlPointVectorProperty) { MITK_INFO << "Could not find any control point property in the storage."; return; } std::vector controlPointVectorValue = controlPointVectorProperty->GetValue(); const auto existingControlPoint = std::find(controlPointVectorValue.begin(), controlPointVectorValue.end(), controlPoint.UID); if (existingControlPoint != controlPointVectorValue.end()) { // set / overwrite the control point reference of the given data // retrieve a vector property that contains the referenced ID of a data node (0. information type 1. control point ID) mitk::VectorProperty* dataNodeVectorProperty = dynamic_cast*>(propertyList->GetProperty(dataNodeID)); if (nullptr == dataNodeVectorProperty) { MITK_INFO << "Could not find the data node " << dataNodeID << " in the storage. Cannot link data to control point."; return; } std::vector dataNodeVectorValue = dataNodeVectorProperty->GetValue(); // an image node has to have exactly two values (the information type and the ID of the control point) if (dataNodeVectorValue.size() != 2) { MITK_INFO << "Incorrect data storage. Not two (2) values stored."; return; } else { // the second value of the data node vector is the ID of the referenced control point dataNodeVectorValue[1] = controlPoint.UID; dataNodeVectorProperty->SetValue(dataNodeVectorValue); } } else { MITK_INFO << "Could not find control point " << controlPoint.UID << " in the storage. Cannot link data to control point."; } } void mitk::RelationStorage::UnlinkDataFromControlPoint(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& dataNodeID) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return; } // retrieve a vector property that contains the referenced ID of a date (0. information type 1. control point ID) mitk::VectorProperty* dataNodeVectorProperty = dynamic_cast*>(propertyList->GetProperty(dataNodeID)); if (nullptr == dataNodeVectorProperty) { MITK_INFO << "Could not find the date " << dataNodeID << " in the storage. Cannot unlink control point from date."; return; } std::vector dataNodeVectorValue = dataNodeVectorProperty->GetValue(); // a data node has to have exactly two values (the information type and the ID of the control point) if (dataNodeVectorValue.size() != 2) { MITK_INFO << "Incorrect data storage. Not two (2) values stored."; return; } else { // the second value of the data node vector is the ID of the referenced control point // set the control point reference to an empty string for removal dataNodeVectorValue[1] = ""; dataNodeVectorProperty->SetValue(dataNodeVectorValue); } } void mitk::RelationStorage::RemoveControlPointFromCase(const SemanticTypes::CaseID& caseID, const SemanticTypes::ControlPoint& controlPoint) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return; } // retrieve a vector property that contains the valid controlPoint UIDs for the current case mitk::VectorProperty* allControlPointsVectorProperty = dynamic_cast*>(propertyList->GetProperty("controlpoints")); if (nullptr == allControlPointsVectorProperty) { MITK_INFO << "Could not find any control point property in the storage."; return; } // remove the control point reference from the list of all control points of the current case std::vector currentControlPointVectorValue = allControlPointsVectorProperty->GetValue(); currentControlPointVectorValue.erase(std::remove(currentControlPointVectorValue.begin(), currentControlPointVectorValue.end(), controlPoint.UID), currentControlPointVectorValue.end()); allControlPointsVectorProperty->SetValue(currentControlPointVectorValue); // remove the control point instance itself - // the start and end point is stored under the control point ID - // retrieve a vector property that contains the referenced ID of the dates of a control point (0. startPoint ID 1. endPoint ID) - mitk::VectorProperty* controlPointVectorProperty = dynamic_cast*>(propertyList->GetProperty(controlPoint.UID)); - if (nullptr == controlPointVectorProperty) - { - MITK_INFO << "Control point " << controlPoint.UID << " not found (already removed?). Cannot remove the control point."; - return; - } - - std::vector controlPointVectorValue = controlPointVectorProperty->GetValue(); - // a control point has to have exactly two values (the ID of two dates) - if (controlPointVectorValue.size() != 2) - { - MITK_INFO << "Incorrect control point storage. Not two (2) IDs of the start point and the end point are stored."; - } - else - { - // retrieve the start date - std::string startPointID = controlPointVectorValue[0]; - // delete the start date property - propertyList->DeleteProperty(startPointID); - // retrieve the end date - std::string endPointID = controlPointVectorValue[1]; - // delete the end date property - propertyList->DeleteProperty(endPointID); - } propertyList->DeleteProperty(controlPoint.UID); } void mitk::RelationStorage::AddInformationTypeToImage(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& imageID, const SemanticTypes::InformationType informationType) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return; } // retrieve a vector property that contains the valid information types of the current case mitk::VectorProperty::Pointer informationTypeVectorProperty = dynamic_cast*>(propertyList->GetProperty("informationtypes")); std::vector informationTypeVectorValue; if (nullptr == informationTypeVectorProperty) { informationTypeVectorProperty = mitk::VectorProperty::New(); } else { informationTypeVectorValue = informationTypeVectorProperty->GetValue(); } const auto existingInformationType = std::find(informationTypeVectorValue.begin(), informationTypeVectorValue.end(), informationType); if (existingInformationType == informationTypeVectorValue.end()) { // at first: add the information type to the storage informationTypeVectorValue.push_back(informationType); informationTypeVectorProperty->SetValue(informationTypeVectorValue); propertyList->SetProperty("informationtypes", informationTypeVectorProperty); } // set / overwrite the information type of the given data // retrieve a vector property that contains the referenced ID of an image (0. information type 1. control point ID) mitk::VectorProperty* imageNodeVectorProperty = dynamic_cast*>(propertyList->GetProperty(imageID)); if (nullptr == imageNodeVectorProperty) { MITK_INFO << "Could not find the image " << imageID << " in the storage. Cannot add information type to image."; return; } std::vector imageNodeVectorValue = imageNodeVectorProperty->GetValue(); // an image node has to have exactly two values (the information type and the ID of the control point) if (imageNodeVectorValue.size() != 2) { MITK_INFO << "Incorrect data storage. Not two (2) values stored."; return; } else { // the first value of the data node vector is the information type imageNodeVectorValue[0] = informationType; imageNodeVectorProperty->SetValue(imageNodeVectorValue); } } void mitk::RelationStorage::RemoveInformationTypeFromImage(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& imageID) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return; } // retrieve a vector property that contains the referenced ID of an image (0. information type 1. control point ID) mitk::VectorProperty* imageNodeVectorProperty = dynamic_cast*>(propertyList->GetProperty(imageID)); if (nullptr == imageNodeVectorProperty) { MITK_INFO << "Could not find the image " << imageID << " in the storage. Cannot remove information type from image."; return; } std::vector imageNodeVectorValue = imageNodeVectorProperty->GetValue(); // an image node has to have exactly two values (the information type and the ID of the control point) if (imageNodeVectorValue.size() != 2) { MITK_INFO << "Incorrect data storage. Not two (2) values stored."; return; } else { // the first value of the data node vector is the information type // set the information type to an empty string for removal imageNodeVectorValue[0] = ""; imageNodeVectorProperty->SetValue(imageNodeVectorValue); } } void mitk::RelationStorage::RemoveInformationTypeFromCase(const SemanticTypes::CaseID& caseID, const SemanticTypes::InformationType informationType) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return; } // retrieve a vector property that contains the valid information types of the current case mitk::VectorProperty* informationTypeVectorProperty = dynamic_cast*>(propertyList->GetProperty("informationtypes")); if (nullptr == informationTypeVectorProperty) { MITK_INFO << "Could not find any information type property in the storage."; return; } std::vector informationTypeVectorValue = informationTypeVectorProperty->GetValue(); informationTypeVectorValue.erase(std::remove(informationTypeVectorValue.begin(), informationTypeVectorValue.end(), informationType), informationTypeVectorValue.end()); if (informationTypeVectorValue.size() == 0) { // no more information types stored -> remove the information types property list propertyList->DeleteProperty("informationtypes"); } else { // or store the modified vector value informationTypeVectorProperty->SetValue(informationTypeVectorValue); } } mitk::PropertyList::Pointer mitk::RelationStorage::GetStorageData(const SemanticTypes::CaseID& caseID) { // access the storage PERSISTENCE_GET_SERVICE_MACRO if (nullptr == persistenceService) { MITK_INFO << "Persistence service could not be loaded"; return nullptr; } // the property list is valid for a whole case and contains all the properties for the current case // the persistence service may create a new property list with the given ID, if no property list is found return persistenceService->GetPropertyList(const_cast(caseID)); } mitk::SemanticTypes::Lesion mitk::RelationStorage::GenerateLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::ID& lesionID) { mitk::PropertyList::Pointer propertyList = GetStorageData(caseID); if (nullptr == propertyList) { MITK_INFO << "Could not find the property list " << caseID << " for the current MITK workbench / session."; return SemanticTypes::Lesion(); } mitk::VectorProperty* lesionDataProperty = dynamic_cast*>(propertyList->GetProperty(lesionID)); if (nullptr == lesionDataProperty) { MITK_INFO << "Lesion " << lesionID << " not found. Lesion can not be retrieved."; return SemanticTypes::Lesion(); } std::vector lesionData = lesionDataProperty->GetValue(); // a lesion date has to have exactly two values (the name of the lesion and the UID of the lesion class) if (lesionData.size() != 2) { MITK_INFO << "Incorrect lesion data storage. Not two (2) strings of the lesion name and the lesion UID are stored."; return SemanticTypes::Lesion(); } // the lesion class ID is stored as the second property std::string lesionClassID = lesionData[1]; mitk::StringProperty* lesionClassProperty = dynamic_cast(propertyList->GetProperty(lesionClassID)); if (nullptr != lesionClassProperty) { SemanticTypes::LesionClass generatedLesionClass; generatedLesionClass.UID = lesionClassID; generatedLesionClass.classType = lesionClassProperty->GetValue(); SemanticTypes::Lesion generatedLesion; generatedLesion.UID = lesionID; generatedLesion.name = lesionData[0]; generatedLesion.lesionClass = generatedLesionClass; return generatedLesion; } else { MITK_INFO << "Incorrect lesion class storage. Lesion " << lesionID << " can not be retrieved."; return SemanticTypes::Lesion(); } } diff --git a/Modules/SemanticRelations/src/mitkSemanticRelations.cpp b/Modules/SemanticRelations/src/mitkSemanticRelations.cpp index e8fdde432a..d17d962025 100644 --- a/Modules/SemanticRelations/src/mitkSemanticRelations.cpp +++ b/Modules/SemanticRelations/src/mitkSemanticRelations.cpp @@ -1,1145 +1,934 @@ /*=================================================================== 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. ===================================================================*/ // semantic relations module #include "mitkSemanticRelations.h" #include "mitkSemanticRelationException.h" #include "mitkNodePredicates.h" #include "mitkUIDGeneratorBoost.h" // multi label module #include // c++ #include +#include std::vector mitk::SemanticRelations::m_ObserverVector; mitk::SemanticRelations::SemanticRelations(DataStorage::Pointer dataStorage) : m_DataStorage(dataStorage) { m_RelationStorage = std::make_shared(); m_RelationStorage->SetDataStorage(m_DataStorage); } mitk::SemanticRelations::~SemanticRelations() { // nothing here } void mitk::SemanticRelations::AddObserver(ISemanticRelationsObserver* observer) { std::vector::iterator existingObserver = std::find(m_ObserverVector.begin(), m_ObserverVector.end(), observer); if (existingObserver != m_ObserverVector.end()) { // no need to add the already existing observer return; } m_ObserverVector.push_back(observer); } void mitk::SemanticRelations::RemoveObserver(ISemanticRelationsObserver* observer) { m_ObserverVector.erase(std::remove(m_ObserverVector.begin(), m_ObserverVector.end(), observer), m_ObserverVector.end()); } /************************************************************************/ /* functions to get instances / attributes */ /************************************************************************/ mitk::SemanticRelations::LesionVector mitk::SemanticRelations::GetAllLesionsOfCase(const SemanticTypes::CaseID& caseID) const { return m_RelationStorage->GetAllLesionsOfCase(caseID); } mitk::SemanticRelations::LesionVector mitk::SemanticRelations::GetAllLesionsOfCase(const SemanticTypes::CaseID& caseID, const SemanticTypes::ControlPoint& controlPoint) const { LesionVector allLesions = GetAllLesionsOfCase(caseID); // filter the lesions: use only those, where the associated data is connected to image data that refers to the given control point using a lambda function auto lambda = [&caseID, &controlPoint, this](const SemanticTypes::Lesion& lesion) { return !ControlPointContainsLesion(caseID, lesion, controlPoint); }; allLesions.erase(std::remove_if(allLesions.begin(), allLesions.end(), lambda), allLesions.end()); return allLesions; } mitk::SemanticRelations::LesionClassVector mitk::SemanticRelations::GetAllLesionClassesOfCase(const SemanticTypes::CaseID& caseID) const { LesionVector allLesionsOfCase = GetAllLesionsOfCase(caseID); LesionClassVector allLesionClassesOfCase; for (const auto& lesion : allLesionsOfCase) { allLesionClassesOfCase.push_back(lesion.lesionClass); } // remove duplicate entries auto lessThan = [](const SemanticTypes::LesionClass& lesionClassL, const SemanticTypes::LesionClass& lesionClassR) { return lesionClassL.UID < lesionClassR.UID; }; auto equal = [](const SemanticTypes::LesionClass& lesionClassL, const SemanticTypes::LesionClass& lesionClassR) { return lesionClassL.UID == lesionClassR.UID; }; std::sort(allLesionClassesOfCase.begin(), allLesionClassesOfCase.end(), lessThan); allLesionClassesOfCase.erase(std::unique(allLesionClassesOfCase.begin(), allLesionClassesOfCase.end(), equal), allLesionClassesOfCase.end()); return allLesionClassesOfCase; } mitk::SemanticRelations::LesionVector mitk::SemanticRelations::GetAllLesionsInImage(const DataNode* imageNode) const { if (nullptr == imageNode) { mitkThrowException(SemanticRelationException) << "Not a valid image data node."; } if (m_DataStorage.IsNull()) { mitkThrowException(SemanticRelationException) << "Not a valid data storage."; } LesionVector allLesionsInImage; // get child nodes of the current node with the segmentation predicate DataStorage::SetOfObjects::ConstPointer segmentationNodes = m_DataStorage->GetDerivations(imageNode, NodePredicates::GetSegmentationPredicate(), false); for (auto it = segmentationNodes->Begin(); it != segmentationNodes->End(); ++it) { DataNode* segmentationNode = it->Value(); try { SemanticTypes::Lesion representedLesion = GetRepresentedLesion(segmentationNode); allLesionsInImage.push_back(representedLesion); } catch (const SemanticRelationException&) { continue; } } return allLesionsInImage; } mitk::SemanticTypes::Lesion mitk::SemanticRelations::GetRepresentedLesion(const DataNode* segmentationNode) const { if (nullptr == segmentationNode) { mitkThrowException(SemanticRelationException) << "Not a valid segmentation data node."; } SemanticTypes::CaseID caseID = GetCaseIDFromDataNode(segmentationNode); SemanticTypes::ID segmentationID = GetIDFromDataNode(segmentationNode); SemanticTypes::Lesion representedLesion = m_RelationStorage->GetRepresentedLesion(caseID, segmentationID); if (representedLesion.UID.empty()) { mitkThrowException(SemanticRelationException) << "Could not find a represented lesion instance for the given segmentation node " << segmentationNode->GetName(); } else { return representedLesion; } } bool mitk::SemanticRelations::IsRepresentingALesion(const DataNode* segmentationNode) const { try { SemanticTypes::Lesion representedLesion = GetRepresentedLesion(segmentationNode); return true; } catch (const Exception&) { return false; } } bool mitk::SemanticRelations::InstanceExists(const DataNode* dataNode) const { try { SemanticTypes::CaseID caseID = GetCaseIDFromDataNode(dataNode); SemanticTypes::ID dataNodeID = GetIDFromDataNode(dataNode); if (mitk::NodePredicates::GetImagePredicate()->CheckNode(dataNode)) { std::vector allImageIDsOfCase = m_RelationStorage->GetAllImageIDsOfCase(caseID); return std::find(allImageIDsOfCase.begin(), allImageIDsOfCase.end(), dataNodeID) != allImageIDsOfCase.end(); } else if (mitk::NodePredicates::GetSegmentationPredicate()->CheckNode(dataNode)) { std::vector allSegmentationIDsOfCase = m_RelationStorage->GetAllSegmentationIDsOfCase(caseID); return std::find(allSegmentationIDsOfCase.begin(), allSegmentationIDsOfCase.end(), dataNodeID) != allSegmentationIDsOfCase.end(); } else { return false; } } catch (const SemanticRelationException&) { return false; } } mitk::SemanticRelations::DataNodeVector mitk::SemanticRelations::GetAllSegmentationsOfCase(const SemanticTypes::CaseID& caseID) const { if (m_DataStorage.IsNull()) { mitkThrowException(SemanticRelationException) << "Not a valid data storage."; } return m_RelationStorage->GetAllSegmentationsOfCase(caseID); } mitk::SemanticRelations::DataNodeVector mitk::SemanticRelations::GetAllSegmentationsOfLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion) const { if (m_DataStorage.IsNull()) { mitkThrowException(SemanticRelationException) << "Not a valid data storage."; } if (InstanceExists(caseID, lesion)) { // lesion exists, retrieve all case segmentations from the storage DataNodeVector allSegmentationsOfLesion = GetAllSegmentationsOfCase(caseID); // filter all segmentations: check for semantic relation with the given lesion using a lambda function auto lambda = [&lesion, this](DataNode::Pointer segmentation) { try { SemanticTypes::Lesion representedLesion = GetRepresentedLesion(segmentation); return lesion.UID != representedLesion.UID; } catch (const SemanticRelationException&) { return true; } }; allSegmentationsOfLesion.erase(std::remove_if(allSegmentationsOfLesion.begin(), allSegmentationsOfLesion.end(), lambda), allSegmentationsOfLesion.end()); return allSegmentationsOfLesion; } else { mitkThrowException(SemanticRelationException) << "Could not find an existing lesion instance for the given caseID " << caseID << " and lesion " << lesion.UID << "."; } } mitk::SemanticRelations::DataNodeVector mitk::SemanticRelations::GetAllImagesOfCase(const SemanticTypes::CaseID& caseID) const { if (m_DataStorage.IsNull()) { mitkThrowException(SemanticRelationException) << "Not a valid data storage."; } return m_RelationStorage->GetAllImagesOfCase(caseID); } mitk::SemanticRelations::DataNodeVector mitk::SemanticRelations::GetAllImagesOfLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion) const { if (m_DataStorage.IsNull()) { mitkThrowException(SemanticRelationException) << "Not a valid data storage."; } DataNodeVector allImagesOfLesion; // 1. get all segmentations that define the lesion // 2. retrieve the parent node (source) of the found segmentation node DataNodeVector allSegmentationsOfLesion = GetAllSegmentationsOfLesion(caseID, lesion); for (const auto& segmentationNode : allSegmentationsOfLesion) { // get parent node of the current segmentation node with the node predicate DataStorage::SetOfObjects::ConstPointer parentNodes = m_DataStorage->GetSources(segmentationNode, NodePredicates::GetImagePredicate(), false); for (auto it = parentNodes->Begin(); it != parentNodes->End(); ++it) { DataNode::Pointer dataNode = it->Value(); allImagesOfLesion.push_back(it->Value()); } } std::sort(allImagesOfLesion.begin(), allImagesOfLesion.end()); allImagesOfLesion.erase(std::unique(allImagesOfLesion.begin(), allImagesOfLesion.end()), allImagesOfLesion.end()); return allImagesOfLesion; } bool mitk::SemanticRelations::InstanceExists(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion) const { LesionVector allLesions = GetAllLesionsOfCase(caseID); // filter all lesions: check for equality with the given lesion using a lambda function auto lambda = [&lesion](const SemanticTypes::Lesion& currentLesion) { return currentLesion.UID == lesion.UID; }; const auto existingLesion = std::find_if(allLesions.begin(), allLesions.end(), lambda); if (existingLesion != allLesions.end()) { return true; } else { return false; } } -mitk::SemanticRelations::ControlpointVector mitk::SemanticRelations::GetAllControlPointsOfCase(const SemanticTypes::CaseID& caseID) const +mitk::SemanticRelations::ControlPointVector mitk::SemanticRelations::GetAllControlPointsOfCase(const SemanticTypes::CaseID& caseID) const { return m_RelationStorage->GetAllControlPointsOfCase(caseID); } -mitk::SemanticRelations::ControlpointVector mitk::SemanticRelations::GetAllControlPointsOfCase(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion) const +mitk::SemanticRelations::ControlPointVector mitk::SemanticRelations::GetAllControlPointsOfCase(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion) const { - ControlpointVector allControlPoints = GetAllControlPointsOfCase(caseID); + ControlPointVector allControlPoints = GetAllControlPointsOfCase(caseID); // filter the control points: use only those, where the associated image data has a segmentation that refers to the given lesion using a lambda function auto lambda = [&caseID, &lesion, this](const SemanticTypes::ControlPoint& controlPoint) { return !ControlPointContainsLesion(caseID, lesion, controlPoint); }; allControlPoints.erase(std::remove_if(allControlPoints.begin(), allControlPoints.end(), lambda), allControlPoints.end()); return allControlPoints; } -mitk::SemanticRelations::ControlpointVector mitk::SemanticRelations::GetAllControlPointsOfCase(const SemanticTypes::CaseID& caseID, const SemanticTypes::InformationType& informationType) const +mitk::SemanticRelations::ControlPointVector mitk::SemanticRelations::GetAllControlPointsOfCase(const SemanticTypes::CaseID& caseID, const SemanticTypes::InformationType& informationType) const { - ControlpointVector allControlPoints = GetAllControlPointsOfCase(caseID); + ControlPointVector allControlPoints = GetAllControlPointsOfCase(caseID); // filter the control points: use only those, where the associated image data refers to the given information type using a lambda function auto lambda = [&caseID, &informationType, this](const SemanticTypes::ControlPoint& controlPoint) { return !ControlPointContainsInformationType(caseID, informationType, controlPoint); }; allControlPoints.erase(std::remove_if(allControlPoints.begin(), allControlPoints.end(), lambda), allControlPoints.end()); return allControlPoints; } mitk::SemanticTypes::ControlPoint mitk::SemanticRelations::GetControlPointOfData(const DataNode* dataNode) const { if (nullptr == dataNode) { mitkThrowException(SemanticRelationException) << "Not a valid data node."; } SemanticTypes::CaseID caseID = GetCaseIDFromDataNode(dataNode); SemanticTypes::ID dataNodeID = GetIDFromDataNode(dataNode); return m_RelationStorage->GetControlPointOfData(caseID, dataNodeID); } mitk::SemanticRelations::DataNodeVector mitk::SemanticRelations::GetAllImagesOfControlPoint(const SemanticTypes::CaseID& caseID, const SemanticTypes::ControlPoint& controlPoint) const { if (m_DataStorage.IsNull()) { mitkThrow() << "Not a valid data storage."; } if (InstanceExists(caseID, controlPoint)) { // control point exists, retrieve all images from the storage DataNodeVector allImagesOfControlPoint = GetAllImagesOfCase(caseID); // filter all images to remove the ones with a different control point using a lambda function auto lambda = [&controlPoint, this](DataNode::Pointer imageNode) { return controlPoint.UID != GetControlPointOfData(imageNode).UID; }; allImagesOfControlPoint.erase(std::remove_if(allImagesOfControlPoint.begin(), allImagesOfControlPoint.end(), lambda), allImagesOfControlPoint.end()); return allImagesOfControlPoint; } else { mitkThrowException(SemanticRelationException) << "Could not find an existing control point instance for the given caseID " << caseID << " and control point " << controlPoint.UID << "."; } } bool mitk::SemanticRelations::InstanceExists(const SemanticTypes::CaseID& caseID, const SemanticTypes::ControlPoint& controlPoint) const { - ControlpointVector allControlPoints = GetAllControlPointsOfCase(caseID); + ControlPointVector allControlPoints = GetAllControlPointsOfCase(caseID); // filter all control points: check for equality with the given control point using a lambda function auto lambda = [&controlPoint](const SemanticTypes::ControlPoint& currentControlPoint) { return currentControlPoint.UID == controlPoint.UID; }; const auto existingControlPoint = std::find_if(allControlPoints.begin(), allControlPoints.end(), lambda); if (existingControlPoint != allControlPoints.end()) { return true; } else { return false; } } mitk::SemanticRelations::InformationTypeVector mitk::SemanticRelations::GetAllInformationTypesOfCase(const SemanticTypes::CaseID& caseID) const { return m_RelationStorage->GetAllInformationTypesOfCase(caseID); } mitk::SemanticRelations::InformationTypeVector mitk::SemanticRelations::GetAllInformationTypesOfCase(const SemanticTypes::CaseID& caseID, const SemanticTypes::ControlPoint& controlPoint) const { InformationTypeVector allInformationTypes = GetAllInformationTypesOfCase(caseID); // filter the information types: use only those, where the associated data refers to the given control point using a lambda function auto lambda = [&caseID, &controlPoint, this](const SemanticTypes::InformationType& informationType) { return !ControlPointContainsInformationType(caseID, informationType, controlPoint); }; allInformationTypes.erase(std::remove_if(allInformationTypes.begin(), allInformationTypes.end(), lambda), allInformationTypes.end()); return allInformationTypes; } mitk::SemanticTypes::InformationType mitk::SemanticRelations::GetInformationTypeOfImage(const DataNode* imageNode) const { if (nullptr == imageNode) { mitkThrowException(SemanticRelationException) << "Not a valid image data node."; } SemanticTypes::CaseID caseID = GetCaseIDFromDataNode(imageNode); SemanticTypes::ID imageID = GetIDFromDataNode(imageNode); return m_RelationStorage->GetInformationTypeOfImage(caseID, imageID); } mitk::SemanticRelations::DataNodeVector mitk::SemanticRelations::GetAllImagesOfInformationType(const SemanticTypes::CaseID& caseID, const SemanticTypes::InformationType& informationType) const { if (m_DataStorage.IsNull()) { mitkThrow() << "Not a valid data storage."; } if (InstanceExists(caseID, informationType)) { // information type exists, retrieve all images from the storage DataNodeVector allImagesOfInformationType = GetAllImagesOfCase(caseID); // filter all images to remove the ones with a different information type using a lambda function auto lambda = [&informationType, this](DataNode::Pointer imageNode) { return informationType != GetInformationTypeOfImage(imageNode); }; allImagesOfInformationType.erase(std::remove_if(allImagesOfInformationType.begin(), allImagesOfInformationType.end(), lambda), allImagesOfInformationType.end()); return allImagesOfInformationType; } else { mitkThrowException(SemanticRelationException) << "Could not find an existing information type for the given caseID " << caseID << " and information type " << informationType; } } mitk::SemanticRelations::DataNodeVector mitk::SemanticRelations::GetAllSpecificImages(const SemanticTypes::CaseID& caseID, const SemanticTypes::ControlPoint& controlPoint, const SemanticTypes::InformationType& informationType) const { if (m_DataStorage.IsNull()) { mitkThrow() << "Not a valid data storage."; } if (InstanceExists(caseID, controlPoint)) { if (InstanceExists(caseID, informationType)) { // control point exists, information type exists, retrieve all images from the storage DataNodeVector allImagesOfCase = GetAllImagesOfCase(caseID); // filter all images to remove the ones with a different control point and information type using a lambda function auto lambda = [&controlPoint, &informationType, this](DataNode::Pointer imageNode) { return (informationType != GetInformationTypeOfImage(imageNode)) || (controlPoint != GetControlPointOfData(imageNode)); }; allImagesOfCase.erase(std::remove_if(allImagesOfCase.begin(), allImagesOfCase.end(), lambda), allImagesOfCase.end()); return allImagesOfCase; } else { mitkThrowException(SemanticRelationException) << "Could not find an existing information type for the given caseID " << caseID << " and information type " << informationType; } } else { mitkThrowException(SemanticRelationException) << "Could not find an existing control point for the given caseID " << caseID << " and control point " << controlPoint.UID; } } mitk::SemanticRelations::DataNodeVector mitk::SemanticRelations::GetAllSpecificSegmentations(const SemanticTypes::CaseID& caseID, const SemanticTypes::ControlPoint& controlPoint, const SemanticTypes::InformationType& informationType) const { if (m_DataStorage.IsNull()) { mitkThrow() << "Not a valid data storage."; } DataNodeVector allSpecificImages = GetAllSpecificImages(caseID, controlPoint, informationType); DataNodeVector allSpecificSegmentations; for (const auto& imageNode : allSpecificImages) { DataStorage::SetOfObjects::ConstPointer segmentationNodes = m_DataStorage->GetDerivations(imageNode, NodePredicates::GetSegmentationPredicate(), false); for (auto it = segmentationNodes->Begin(); it != segmentationNodes->End(); ++it) { allSpecificSegmentations.push_back(it->Value()); } } return allSpecificSegmentations; } bool mitk::SemanticRelations::InstanceExists(const SemanticTypes::CaseID& caseID, const SemanticTypes::InformationType& informationType) const { InformationTypeVector allInformationTypes = GetAllInformationTypesOfCase(caseID); // filter all information types: check for equality with the given information type using a lambda function auto lambda = [&informationType](const SemanticTypes::InformationType& currentInformationType) { return currentInformationType == informationType; }; const auto existingInformationType = std::find_if(allInformationTypes.begin(), allInformationTypes.end(), lambda); if (existingInformationType != allInformationTypes.end()) { return true; } else { return false; } } std::vector mitk::SemanticRelations::GetAllCaseIDs() const { return m_RelationStorage->GetAllCaseIDs(); } /************************************************************************/ /* functions to add / remove instances / attributes */ /************************************************************************/ void mitk::SemanticRelations::AddImage(const DataNode* imageNode) { if (nullptr == imageNode) { mitkThrowException(SemanticRelationException) << "Not a valid data node."; } // continue with a valid data node SemanticTypes::CaseID caseID = GetCaseIDFromDataNode(imageNode); SemanticTypes::ID nodeID = GetIDFromDataNode(imageNode); m_RelationStorage->AddCase(caseID); m_RelationStorage->AddImage(caseID, nodeID); SemanticTypes::InformationType informationType = GetDICOMModalityFromDataNode(imageNode); AddInformationTypeToImage(imageNode, informationType); - // find the correct control point for this image - std::vector allControlPoints = GetAllControlPointsOfCase(caseID); - if (allControlPoints.empty()) - { - // no stored control point - // create a new control point for the image data - SemanticTypes::ControlPoint newControlPoint = GenerateControlPoint(imageNode); - AddControlPointAndLinkData(imageNode, newControlPoint); - NotifyObserver(caseID); - return; - } - - // some control points already exist - find a control point where the date of the data node fits in - SemanticTypes::ControlPoint fittingControlPoint = FindFittingControlPoint(imageNode, allControlPoints); - if (fittingControlPoint.UID.empty()) - { - // did not find a fitting control point, although some control points already exist - // need to see if a close control point can be extended - SemanticTypes::ControlPoint extendedControlPoint = ExtendClosestControlPoint(imageNode, allControlPoints); - if (extendedControlPoint.UID.empty()) - { - // closest control point can not be extended - // create a new control point for the image data - SemanticTypes::ControlPoint newControlPoint = GenerateControlPoint(imageNode); - AddControlPointAndLinkData(imageNode, newControlPoint); - } - else - { - // found a control point that was extended - OverwriteControlPointAndLinkData(imageNode, extendedControlPoint); - } - } - else - { - // found a fitting control point - LinkDataToControlPoint(imageNode, fittingControlPoint); - } - - NotifyObserver(caseID); + // set the correct control point for this image + SemanticTypes::ControlPoint controlPoint = GenerateControlPoint(imageNode); + SetControlPointOfData(imageNode, controlPoint); } void mitk::SemanticRelations::RemoveImage(const DataNode* imageNode) { if (nullptr == imageNode) { mitkThrowException(SemanticRelationException) << "Not a valid data node."; } // continue with a valid data node SemanticTypes::CaseID caseID = GetCaseIDFromDataNode(imageNode); SemanticTypes::ID nodeID = GetIDFromDataNode(imageNode); RemoveInformationTypeFromImage(imageNode); UnlinkDataFromControlPoint(imageNode); m_RelationStorage->RemoveImage(caseID, nodeID); NotifyObserver(caseID); } void mitk::SemanticRelations::AddLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion) { if (InstanceExists(caseID, lesion)) { mitkThrowException(SemanticRelationException) << "The lesion " << lesion.UID << " to add already exists for the given case."; } else { m_RelationStorage->AddLesion(caseID, lesion); NotifyObserver(caseID); } } void mitk::SemanticRelations::OverwriteLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion) { if (InstanceExists(caseID, lesion)) { m_RelationStorage->OverwriteLesion(caseID, lesion); NotifyObserver(caseID); } else { mitkThrowException(SemanticRelationException) << "The lesion " << lesion.UID << " to overwrite does not exist for the given case."; } } void mitk::SemanticRelations::AddLesionAndLinkSegmentation(const DataNode* segmentationNode, const SemanticTypes::Lesion& lesion) { if (nullptr == segmentationNode) { mitkThrowException(SemanticRelationException) << "Not a valid segmentation data node."; } SemanticTypes::CaseID caseID = GetCaseIDFromDataNode(segmentationNode); AddLesion(caseID, lesion); LinkSegmentationToLesion(segmentationNode, lesion); NotifyObserver(caseID); } void mitk::SemanticRelations::RemoveLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion) { if (InstanceExists(caseID, lesion)) { DataNodeVector allSegmentationsOfLesion = GetAllSegmentationsOfLesion(caseID, lesion); if (allSegmentationsOfLesion.empty()) { // no more segmentations are linked to the specific lesion // the lesion can be removed from the storage m_RelationStorage->RemoveLesion(caseID, lesion); NotifyObserver(caseID); } else { mitkThrowException(SemanticRelationException) << "The lesion " << lesion.UID << " to remove is still referred to by a segmentation node. Lesion will not be removed."; } } else { mitkThrowException(SemanticRelationException) << "The lesion " << lesion.UID << " to remove does not exist for the given case."; } } void mitk::SemanticRelations::AddSegmentation(const DataNode* segmentationNode, const DataNode* parentNode) { if (nullptr == segmentationNode) { mitkThrowException(SemanticRelationException) << "Not a valid segmentation data node."; } if (nullptr == parentNode) { mitkThrowException(SemanticRelationException) << "Not a valid parent data node."; } // continue with a valid data node SemanticTypes::CaseID caseID = GetCaseIDFromDataNode(segmentationNode); SemanticTypes::ID segmentationNodeID = GetIDFromDataNode(segmentationNode); SemanticTypes::ID parentNodeID = GetIDFromDataNode(parentNode); m_RelationStorage->AddSegmentation(caseID, segmentationNodeID, parentNodeID); NotifyObserver(caseID); } void mitk::SemanticRelations::LinkSegmentationToLesion(const DataNode* segmentationNode, const SemanticTypes::Lesion& lesion) { if (nullptr == segmentationNode) { mitkThrowException(SemanticRelationException) << "Not a valid segmentation data node."; } SemanticTypes::CaseID caseID = GetCaseIDFromDataNode(segmentationNode); if (InstanceExists(caseID, lesion)) { SemanticTypes::ID segmentationID = GetIDFromDataNode(segmentationNode); m_RelationStorage->LinkSegmentationToLesion(caseID, segmentationID, lesion); NotifyObserver(caseID); } else { mitkThrowException(SemanticRelationException) << "The lesion " << lesion.UID << " to link does not exist for the given case."; } } void mitk::SemanticRelations::UnlinkSegmentationFromLesion(const DataNode* segmentationNode) { if (nullptr == segmentationNode) { mitkThrowException(SemanticRelationException) << "Not a valid segmentation data node."; } SemanticTypes::CaseID caseID = GetCaseIDFromDataNode(segmentationNode); SemanticTypes::ID segmentationID = GetIDFromDataNode(segmentationNode); m_RelationStorage->UnlinkSegmentationFromLesion(caseID, segmentationID); NotifyObserver(caseID); } void mitk::SemanticRelations::RemoveSegmentation(const DataNode* segmentationNode) { if (nullptr == segmentationNode) { mitkThrowException(SemanticRelationException) << "Not a valid segmentation data node."; } // continue with a valid data node SemanticTypes::CaseID caseID = GetCaseIDFromDataNode(segmentationNode); SemanticTypes::ID segmentationNodeID = GetIDFromDataNode(segmentationNode); m_RelationStorage->RemoveSegmentation(caseID, segmentationNodeID); NotifyObserver(caseID); } -void mitk::SemanticRelations::SetControlPointFromDate(const DataNode* dataNode, const SemanticTypes::Date& date) +void mitk::SemanticRelations::SetControlPointOfData(const DataNode* dataNode, const SemanticTypes::ControlPoint& controlPoint) { if (nullptr == dataNode) { mitkThrowException(SemanticRelationException) << "Not a valid data node."; } SemanticTypes::CaseID caseID = GetCaseIDFromDataNode(dataNode); - - // store the current control point to relink it, if anything goes wrong - mitk::SemanticTypes::ControlPoint originalControlPoint = GetControlPointOfData(dataNode); - // unlink the data, that is about to receive a new date - // this is needed in order to not extend a single control point, to which the selected node is currently linked - UnlinkDataFromControlPoint(dataNode); - - ControlpointVector allControlPoints = GetAllControlPointsOfCase(caseID); - if (!allControlPoints.empty()) + ControlPointVector allControlPoints = GetAllControlPointsOfCase(caseID); + // need to check if an already existing control point fits/contains the user control point + SemanticTypes::ControlPoint existingControlPoint = FindExistingControlPoint(controlPoint, allControlPoints); + if (!existingControlPoint.UID.empty()) { - // need to check if an already existing control point fits/contains the user control point - SemanticTypes::ControlPoint fittingControlPoint = FindFittingControlPoint(date, allControlPoints); - if (!fittingControlPoint.UID.empty()) + try { - try - { - // found a fitting control point - LinkDataToControlPoint(dataNode, fittingControlPoint, false); - } - catch (const SemanticRelationException&) - { - try - { - // link to the original control point - LinkDataToControlPoint(dataNode, originalControlPoint, false); - } - catch (const SemanticRelationException&) - { - mitkThrowException(SemanticRelationException) << "The data can not be linked. Inconsistency in the semantic relations storage assumed."; - } - } - return; + // found a fitting control point + LinkDataToControlPoint(dataNode, existingControlPoint, false); } - - // did not find a fitting control point, although some control points already exist - // need to check if a close control point can be found and extended - SemanticTypes::ControlPoint extendedControlPoint = ExtendClosestControlPoint(date, allControlPoints); - if (!extendedControlPoint.UID.empty()) + catch (const SemanticRelationException&) { - try - { - // found and extended a close control point - OverwriteControlPointAndLinkData(dataNode, extendedControlPoint, false); - } - catch (const SemanticRelationException&) - { - try - { - // link to the original control point - LinkDataToControlPoint(dataNode, originalControlPoint, false); - } - catch (const SemanticRelationException&) - { - mitkThrowException(SemanticRelationException) << "The data can not be linked Inconsistency in the semantic relations storage assumed."; - } - } - return; + mitkThrowException(SemanticRelationException) << "The data can not be linked. Inconsistency in the semantic relations storage assumed."; } } - - // generate a control point from the user-given date - SemanticTypes::ControlPoint controlPointFromUserDate = GenerateControlPoint(date); - try - { - AddControlPointAndLinkData(dataNode, controlPointFromUserDate, false); - } - catch (const SemanticRelationException&) + else { try { - // link to the original control point - LinkDataToControlPoint(dataNode, originalControlPoint, false); + AddControlPointAndLinkData(dataNode, controlPoint, false); } catch (const SemanticRelationException&) { mitkThrowException(SemanticRelationException) << "The data can not be linked. Inconsistency in the semantic relations storage assumed."; } } + ClearControlPoints(caseID); NotifyObserver(caseID); } void mitk::SemanticRelations::AddControlPointAndLinkData(const DataNode* dataNode, const SemanticTypes::ControlPoint& controlPoint, bool checkConsistence) { if (nullptr == dataNode) { mitkThrowException(SemanticRelationException) << "Not a valid data node."; } SemanticTypes::CaseID caseID = GetCaseIDFromDataNode(dataNode); if (InstanceExists(caseID, controlPoint)) { mitkThrowException(SemanticRelationException) << "The control point " << controlPoint.UID << " to add already exists for the given case. \n Use 'LinkDataToControlPoint' instead."; } - // control point does not already exist - bool contained = CheckContainingControlPoint(caseID, controlPoint); - if (contained) - { - mitkThrowException(SemanticRelationException) << "The control point " << controlPoint.UID << " to add is already contained in an existing control point."; - } - - // control point is not already contained in an existing control point - if (checkConsistence) - { - // to check the consistency, the control point manager checks, if the date extracted from the data node is inside the given control point - bool insideControlPoint = InsideControlPoint(dataNode, controlPoint); - if (!insideControlPoint) - { - mitkThrowException(SemanticRelationException) << "The control point " << controlPoint.UID << " to add does not contain the date of the given data node."; - } - } m_RelationStorage->AddControlPoint(caseID, controlPoint); - LinkDataToControlPoint(dataNode, controlPoint, checkConsistence); } -void mitk::SemanticRelations::OverwriteControlPointAndLinkData(const DataNode* dataNode, const SemanticTypes::ControlPoint& controlPoint, bool checkConsistence) -{ - if (nullptr == dataNode) - { - mitkThrowException(SemanticRelationException) << "Not a valid data node."; - } - - SemanticTypes::CaseID caseID = GetCaseIDFromDataNode(dataNode); - - ControlpointVector allControlPoints = GetAllControlPointsOfCase(caseID); - const auto existingControlPoint = std::find_if(allControlPoints.begin(), allControlPoints.end(), - [&controlPoint](const SemanticTypes::ControlPoint& currentControlPoint) { return currentControlPoint.UID == controlPoint.UID; }); - - if (existingControlPoint != allControlPoints.end()) - { - // control point does already exist - if (checkConsistence) - { - // to check the consistency, the control point manager checks, if the date extracted from the data node is inside the given control point - bool insideControlPoint = InsideControlPoint(dataNode, controlPoint); - if (!insideControlPoint) - { - mitkThrowException(SemanticRelationException) << "The overwriting control point " << controlPoint.UID << " does not contain the date of the given data node."; - } - } - - bool sameStartPoint = controlPoint.startPoint == (*existingControlPoint).startPoint; - bool sameEndPoint = controlPoint.endPoint == (*existingControlPoint).endPoint; - if (!sameStartPoint && !sameEndPoint) - { - mitkThrowException(SemanticRelationException) << "The overwriting control point " << controlPoint.UID << " differs in the start date and in the end date from the original control point."; - } - if (sameStartPoint && sameEndPoint) - { - mitkThrowException(SemanticRelationException) << "The overwriting control point " << controlPoint.UID << " does not differ from the original control point."; - } - - bool overlapping = CheckOverlappingControlPoint(caseID, controlPoint); - if (overlapping) - { - mitkThrowException(SemanticRelationException) << "The overwriting control point " << controlPoint.UID << " overlaps with an already existing control point"; - } - else - { - m_RelationStorage->OverwriteControlPoint(caseID, controlPoint); - LinkDataToControlPoint(dataNode, controlPoint, checkConsistence); - } - } - else - { - mitkThrowException(SemanticRelationException) << "The control point " << controlPoint.UID << " to overwrite does not exist for the given case. \n Use 'AddControlPointAndLinkData' instead."; - } -} - void mitk::SemanticRelations::LinkDataToControlPoint(const DataNode* dataNode, const SemanticTypes::ControlPoint& controlPoint, bool checkConsistence) { if (nullptr == dataNode) { mitkThrowException(SemanticRelationException) << "Not a valid data node."; } SemanticTypes::CaseID caseID = GetCaseIDFromDataNode(dataNode); if (InstanceExists(caseID, controlPoint)) { SemanticTypes::ID dataID = GetIDFromDataNode(dataNode); - - // control point does already exist - if (checkConsistence) - { - // to check the consistency, the control point manager checks, if the date extracted from the data node is inside the given control point - bool insideControlPoint = InsideControlPoint(dataNode, controlPoint); - if (!insideControlPoint) - { - mitkThrowException(SemanticRelationException) << "The data to link does not lie inside the given control point " << controlPoint.UID << " ."; - } - } m_RelationStorage->LinkDataToControlPoint(caseID, dataID, controlPoint); } else { mitkThrowException(SemanticRelationException) << "The control point " << controlPoint.UID << " to link does not exist for the given case."; } } void mitk::SemanticRelations::UnlinkDataFromControlPoint(const DataNode* dataNode) { if (nullptr == dataNode) { mitkThrowException(SemanticRelationException) << "Not a valid data node."; } SemanticTypes::CaseID caseID = GetCaseIDFromDataNode(dataNode); SemanticTypes::ID dataID = GetIDFromDataNode(dataNode); SemanticTypes::ControlPoint controlPoint = m_RelationStorage->GetControlPointOfData(caseID, dataID); m_RelationStorage->UnlinkDataFromControlPoint(caseID, dataID); - - DataNodeVector allImagesOfControlPoint = GetAllImagesOfControlPoint(caseID, controlPoint); - if (allImagesOfControlPoint.empty()) - { - // no more data is linked to the specific control point - // the control point can be removed from the storage - m_RelationStorage->RemoveControlPointFromCase(caseID, controlPoint); - } - else - { - // some data is still linked to this control point - // the control point can not be removed, but has to be adjusted to fit the remaining data - SemanticTypes::ControlPoint adjustedControlPoint = GenerateControlPoint(allImagesOfControlPoint); - // set the UIDs to be the same, so that all references still work - adjustedControlPoint.UID = controlPoint.UID; - adjustedControlPoint.startPoint.UID = controlPoint.startPoint.UID; - adjustedControlPoint.endPoint.UID = controlPoint.endPoint.UID; - m_RelationStorage->OverwriteControlPoint(caseID, adjustedControlPoint); - } + ClearControlPoints(caseID); } void mitk::SemanticRelations::SetInformationType(const DataNode* imageNode, const SemanticTypes::InformationType& informationType) { RemoveInformationTypeFromImage(imageNode); AddInformationTypeToImage(imageNode, informationType); SemanticTypes::CaseID caseID = GetCaseIDFromDataNode(imageNode); NotifyObserver(caseID); } void mitk::SemanticRelations::AddInformationTypeToImage(const DataNode* imageNode, const SemanticTypes::InformationType& informationType) { if (nullptr == imageNode) { mitkThrowException(SemanticRelationException) << "Not a valid image data node."; } SemanticTypes::CaseID caseID = GetCaseIDFromDataNode(imageNode); SemanticTypes::ID imageID = GetIDFromDataNode(imageNode); m_RelationStorage->AddInformationTypeToImage(caseID, imageID, informationType); } void mitk::SemanticRelations::RemoveInformationTypeFromImage(const DataNode* imageNode) { if (nullptr == imageNode) { mitkThrowException(SemanticRelationException) << "Not a valid image data node."; } SemanticTypes::CaseID caseID = GetCaseIDFromDataNode(imageNode); SemanticTypes::ID imageID = GetIDFromDataNode(imageNode); SemanticTypes::InformationType originalInformationType = m_RelationStorage->GetInformationTypeOfImage(caseID, imageID); m_RelationStorage->RemoveInformationTypeFromImage(caseID, imageID); // check for further references to the removed information type std::vector allImageIDsVectorValue = m_RelationStorage->GetAllImageIDsOfCase(caseID); for (const auto otherImageID : allImageIDsVectorValue) { SemanticTypes::InformationType otherInformationType = m_RelationStorage->GetInformationTypeOfImage(caseID, otherImageID); if (otherInformationType == originalInformationType) { // found the information type in another image -> cannot remove the information type from the case return; } } // given information type was not referred by any other image of the case -> the information type can be removed from the case m_RelationStorage->RemoveInformationTypeFromCase(caseID, originalInformationType); } /************************************************************************/ /* private functions */ /************************************************************************/ void mitk::SemanticRelations::NotifyObserver(const SemanticTypes::CaseID& caseID) const { for (auto& observer : m_ObserverVector) { observer->Update(caseID); } } bool mitk::SemanticRelations::ControlPointContainsLesion(const SemanticTypes::CaseID& caseID, const SemanticTypes::Lesion& lesion, const SemanticTypes::ControlPoint& controlPoint) const { DataNodeVector allImagesOfLesion; try { allImagesOfLesion = GetAllImagesOfLesion(caseID, lesion); } catch (const SemanticRelationException&) { // error retrieving image data; lesion has to be outside the control point return false; } DataNodeVector allImagesOfControlPoint; try { allImagesOfControlPoint = GetAllImagesOfControlPoint(caseID, controlPoint); } catch (const SemanticRelationException&) { // error retrieving control point data; lesion has to be outside the control point return false; } std::sort(allImagesOfLesion.begin(), allImagesOfLesion.end()); std::sort(allImagesOfControlPoint.begin(), allImagesOfControlPoint.end()); DataNodeVector allImagesIntersection; // set intersection removes duplicated nodes, since 'GetAllImagesOfControlPoint' only contains at most one of each node std::set_intersection(allImagesOfLesion.begin(), allImagesOfLesion.end(), allImagesOfControlPoint.begin(), allImagesOfControlPoint.end(), std::back_inserter(allImagesIntersection)); // if the vector of intersecting data is empty, the control point does not contain the lesion return !allImagesIntersection.empty(); } bool mitk::SemanticRelations::ControlPointContainsInformationType(const SemanticTypes::CaseID& caseID, const SemanticTypes::InformationType& informationType, const SemanticTypes::ControlPoint& controlPoint) const { DataNodeVector allImagesIntersection = GetAllSpecificImages(caseID, controlPoint, informationType); return !allImagesIntersection.empty(); } -bool mitk::SemanticRelations::CheckOverlappingControlPoint(const SemanticTypes::CaseID& caseID, const SemanticTypes::ControlPoint& controlPoint) +void mitk::SemanticRelations::ClearControlPoints(const SemanticTypes::CaseID& caseID) { - ControlpointVector allControlPoints = GetAllControlPointsOfCase(caseID); - if (allControlPoints.empty()) + ControlPointVector allControlPointsOfCase; + try { - return false; - } - - std::sort(allControlPoints.begin(), allControlPoints.end()); - const auto existingControlPoint = std::find_if(allControlPoints.begin(), allControlPoints.end(), - [&controlPoint](const SemanticTypes::ControlPoint& currentControlPoint) { return currentControlPoint.UID == controlPoint.UID; }); + allControlPointsOfCase = GetAllControlPointsOfCase(caseID); - auto nextControlPoint = allControlPoints.end(); - auto previousControlPoint = allControlPoints.begin(); - if (existingControlPoint != allControlPoints.end()) - { - // case overwriting: control point already contained in the list of all existing control points - nextControlPoint = std::next(existingControlPoint, 1); - if (existingControlPoint != allControlPoints.begin()) - { - previousControlPoint = std::prev(existingControlPoint, 1); - } } - else + catch (const SemanticRelationException&) { - // case adding: control point not contained in the list of all existing control points - nextControlPoint = std::find_if(allControlPoints.begin(), allControlPoints.end(), - [&controlPoint](const SemanticTypes::ControlPoint& currentControlPoint) { return currentControlPoint.startPoint >= controlPoint.endPoint; }); - if (nextControlPoint != allControlPoints.begin()) - { - previousControlPoint = std::prev(existingControlPoint, 1); - } + // error retrieving control point data + return; } - // check the neighboring control points for overlap - bool overlapWithNext = false; - bool overlapWithPrevious = CheckForOverlap(controlPoint, *previousControlPoint); - - if (nextControlPoint != allControlPoints.end()) + DataNodeVector allImagesOfCase; + try { - overlapWithNext = CheckForOverlap(controlPoint, *nextControlPoint); + allImagesOfCase = GetAllImagesOfCase(caseID); } - - return overlapWithNext || overlapWithPrevious; // return true if at least one overlap is detected -} - -bool mitk::SemanticRelations::CheckContainingControlPoint(const SemanticTypes::CaseID& caseID, const SemanticTypes::ControlPoint& controlPoint) -{ - ControlpointVector allControlPoints = GetAllControlPointsOfCase(caseID); - if (allControlPoints.empty()) + catch (const SemanticRelationException&) { - return false; + // error retrieving image data + return; } - const auto existingControlPoint = std::find_if(allControlPoints.begin(), allControlPoints.end(), - [&controlPoint](const SemanticTypes::ControlPoint& currentControlPoint) { return currentControlPoint.UID == controlPoint.UID; }); - - if (existingControlPoint != allControlPoints.end()) + ControlPointVector allControlPoints; + for (const auto& image : allImagesOfCase) { - // case overwriting: control point already contained in the list of all existing control points - // -> duplicated control point found (regardless of the actual start point and end point) - return true; - } - else - { - // case adding: control point not contained in the list of all existing control points - for (const auto& existingControlPoint : allControlPoints) + try { - bool contained = InsideControlPoint(controlPoint, existingControlPoint); - if (contained) - { - return true; - } + allControlPoints.push_back(GetControlPointOfData(image)); + } + catch (const SemanticRelationException&) + { + // error retrieving control point of data + continue; + } + } + + std::sort(allControlPointsOfCase.begin(), allControlPointsOfCase.end()); + std::sort(allControlPoints.begin(), allControlPoints.end()); + ControlPointVector allControlPointsDifference; + + std::set_difference(allControlPointsOfCase.begin(), allControlPointsOfCase.end(), + allControlPoints.begin(), allControlPoints.end(), + std::inserter(allControlPointsDifference, allControlPointsDifference.begin())); + + for (const auto& controlPoint : allControlPointsDifference) + { + m_RelationStorage->RemoveControlPointFromCase(caseID, controlPoint); } - return false; } diff --git a/Modules/SemanticRelationsUI/include/QmitkControlPointDialog.h b/Modules/SemanticRelationsUI/include/QmitkControlPointDialog.h index 535df9684f..f8c23395da 100644 --- a/Modules/SemanticRelationsUI/include/QmitkControlPointDialog.h +++ b/Modules/SemanticRelationsUI/include/QmitkControlPointDialog.h @@ -1,46 +1,46 @@ /*=================================================================== 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. ===================================================================*/ #ifndef QMITKCONTROLPOINTDIALOG_H #define QMITKCONTROLPOINTDIALOG_H #include // semantic relations module #include "mitkSemanticTypes.h" #include #include class MITKSEMANTICRELATIONSUI_EXPORT QmitkControlPointDialog : public QDialog { Q_OBJECT public: QmitkControlPointDialog(QWidget *parent = nullptr); virtual ~QmitkControlPointDialog(); - void SetCurrentDate(mitk::SemanticTypes::Date currentDate); + void SetCurrentDate(mitk::SemanticTypes::ControlPoint currentControlPoint); QDate GetCurrentDate() const; private: QDateEdit* m_DateEdit; }; #endif // QMITKCONTROLPOINTDIALOG_H diff --git a/Modules/SemanticRelationsUI/src/QmitkControlPointDialog.cpp b/Modules/SemanticRelationsUI/src/QmitkControlPointDialog.cpp index 678ba857c8..685ff22eaf 100644 --- a/Modules/SemanticRelationsUI/src/QmitkControlPointDialog.cpp +++ b/Modules/SemanticRelationsUI/src/QmitkControlPointDialog.cpp @@ -1,69 +1,67 @@ /*=================================================================== 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 "QmitkControlPointDialog.h" #include #include #include #include #include QmitkControlPointDialog::QmitkControlPointDialog(QWidget* parent) : QDialog(parent) { - //QDialog::setFixedSize(250, 105); - QBoxLayout* verticalLayout = new QVBoxLayout(this); verticalLayout->setMargin(5); verticalLayout->setSpacing(5); QLabel* dateLabel = new QLabel(tr("Set date"), this); verticalLayout->addWidget(dateLabel); m_DateEdit = new QDateEdit(this); m_DateEdit->setDisplayFormat("yyyy-MM-dd"); m_DateEdit->setFocus(); verticalLayout->addWidget(m_DateEdit); QPushButton* acceptButton = new QPushButton(tr("Ok"), this); QPushButton* cancelButton = new QPushButton(tr("Cancel"), this); acceptButton->setDefault(true); connect(acceptButton, &QPushButton::clicked, this, &QmitkControlPointDialog::accept); connect(cancelButton, &QPushButton::clicked, this, &QmitkControlPointDialog::reject); QBoxLayout* horizontalLayout = new QHBoxLayout(); horizontalLayout->setSpacing(5); horizontalLayout->addStretch(); horizontalLayout->addWidget(acceptButton); horizontalLayout->addWidget(cancelButton); verticalLayout->addLayout(horizontalLayout); } QmitkControlPointDialog::~QmitkControlPointDialog() { } -void QmitkControlPointDialog::SetCurrentDate(mitk::SemanticTypes::Date currentDate) +void QmitkControlPointDialog::SetCurrentDate(mitk::SemanticTypes::ControlPoint currentControlPoint) { - m_DateEdit->setDate(QDate(currentDate.year, currentDate.month, currentDate.day)); + m_DateEdit->setDate(QDate(currentControlPoint.year, currentControlPoint.month, currentControlPoint.day)); } QDate QmitkControlPointDialog::GetCurrentDate() const { return m_DateEdit->date(); } diff --git a/Plugins/org.mitk.gui.qt.semanticrelations/files.cmake b/Plugins/org.mitk.gui.qt.semanticrelations/files.cmake index 61da5e0556..a79146ff6e 100644 --- a/Plugins/org.mitk.gui.qt.semanticrelations/files.cmake +++ b/Plugins/org.mitk.gui.qt.semanticrelations/files.cmake @@ -1,42 +1,42 @@ set(INTERNAL_CPP_FILES mitkPluginActivator.cpp QmitkDataNodeAddToSemanticRelationsAction.cpp - QmitkDataNodeControlPointAction.cpp QmitkDataNodeInformationTypeAction.cpp QmitkDataNodeRemoveFromSemanticRelationsAction.cpp QmitkDataNodeOpenInAction.cpp + QmitkDataNodeSetControlPointAction.cpp QmitkLesionInfoWidget.cpp QmitkSemanticRelationsContextMenu.cpp QmitkSemanticRelationsNodeSelectionDialog.cpp QmitkSemanticRelationsView.cpp ) set(UI_FILES src/internal/QmitkLesionInfoWidgetControls.ui src/internal/QmitkSemanticRelationsControls.ui ) set(MOC_H_FILES src/internal/mitkPluginActivator.h src/internal/QmitkDataNodeAddToSemanticRelationsAction.h - src/internal/QmitkDataNodeControlPointAction.h src/internal/QmitkDataNodeInformationTypeAction.h src/internal/QmitkDataNodeRemoveFromSemanticRelationsAction.h src/internal/QmitkDataNodeOpenInAction.h + src/internal/QmitkDataNodeSetControlPointAction.h src/internal/QmitkLesionInfoWidget.h src/internal/QmitkSemanticRelationsContextMenu.h src/internal/QmitkSemanticRelationsNodeSelectionDialog.h src/internal/QmitkSemanticRelationsView.h ) set(CACHED_RESOURCE_FILES resources/SemanticRelations_48.png plugin.xml ) set(QRC_FILES ) foreach(file ${INTERNAL_CPP_FILES}) set(CPP_FILES ${CPP_FILES} src/internal/${file}) endforeach(file ${INTERNAL_CPP_FILES}) diff --git a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeControlPointAction.cpp b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeSetControlPointAction.cpp similarity index 71% rename from Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeControlPointAction.cpp rename to Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeSetControlPointAction.cpp index 2ad0ce853a..da86800e94 100644 --- a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeControlPointAction.cpp +++ b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeSetControlPointAction.cpp @@ -1,152 +1,152 @@ /*=================================================================== 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. ===================================================================*/ // semantic relations plugin -#include "QmitkDataNodeControlPointAction.h" +#include "QmitkDataNodeSetControlPointAction.h" // semantic relations module #include #include #include // semantic relations UI module #include "QmitkControlPointDialog.h" // mitk gui common plugin #include // berry #include #include // qt #include -QmitkDataNodeControlPointAction::QmitkDataNodeControlPointAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite) +QmitkDataNodeSetControlPointAction::QmitkDataNodeSetControlPointAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite) : QAction(parent) , m_WorkbenchPartSite(workbenchPartSite) { setText(tr("Set control point")); m_Parent = parent; InitializeAction(); } -QmitkDataNodeControlPointAction::QmitkDataNodeControlPointAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite) +QmitkDataNodeSetControlPointAction::QmitkDataNodeSetControlPointAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite) : QAction(parent) , m_WorkbenchPartSite(berry::IWorkbenchPartSite::Pointer(workbenchPartSite)) { setText(tr("Set control point")); m_Parent = parent; InitializeAction(); } -QmitkDataNodeControlPointAction::~QmitkDataNodeControlPointAction() +QmitkDataNodeSetControlPointAction::~QmitkDataNodeSetControlPointAction() { // nothing here } -void QmitkDataNodeControlPointAction::SetDataStorage(mitk::DataStorage* dataStorage) +void QmitkDataNodeSetControlPointAction::SetDataStorage(mitk::DataStorage* dataStorage) { if (m_DataStorage != dataStorage) { // set the new data storage m_DataStorage = dataStorage; m_SemanticRelations = std::make_unique(m_DataStorage.Lock()); } } -void QmitkDataNodeControlPointAction::InitializeAction() +void QmitkDataNodeSetControlPointAction::InitializeAction() { - connect(this, &QAction::triggered, this, &QmitkDataNodeControlPointAction::OnActionTriggered); + connect(this, &QAction::triggered, this, &QmitkDataNodeSetControlPointAction::OnActionTriggered); } -void QmitkDataNodeControlPointAction::OnActionTriggered(bool checked) +void QmitkDataNodeSetControlPointAction::OnActionTriggered(bool checked) { if (nullptr == m_SemanticRelations) { return; } auto dataNode = GetSelectedNode(); if (dataNode.IsNull()) { return; } QmitkControlPointDialog* inputDialog = new QmitkControlPointDialog(m_Parent); inputDialog->setWindowTitle("Set control point"); inputDialog->SetCurrentDate(mitk::GetDICOMDateFromDataNode(dataNode)); int dialogReturnValue = inputDialog->exec(); if (QDialog::Rejected == dialogReturnValue) { return; } const QDate& userSelectedDate = inputDialog->GetCurrentDate(); - mitk::SemanticTypes::Date date; - date.UID = mitk::UIDGeneratorBoost::GenerateUID(); - date.year = userSelectedDate.year(); - date.month = userSelectedDate.month(); - date.day = userSelectedDate.day(); + mitk::SemanticTypes::ControlPoint controlPoint; + controlPoint.UID = mitk::UIDGeneratorBoost::GenerateUID(); + controlPoint.year = userSelectedDate.year(); + controlPoint.month = userSelectedDate.month(); + controlPoint.day = userSelectedDate.day(); try { - m_SemanticRelations->SetControlPointFromDate(dataNode, date); + m_SemanticRelations->SetControlPointOfData(dataNode, controlPoint); } catch (const mitk::SemanticRelationException&) { return; } } -QList QmitkDataNodeControlPointAction::GetSelectedNodes() +QList QmitkDataNodeSetControlPointAction::GetSelectedNodes() { QList selectedNodes; if (m_WorkbenchPartSite.Expired()) { return selectedNodes; } berry::ISelection::ConstPointer selection = m_WorkbenchPartSite.Lock()->GetWorkbenchWindow()->GetSelectionService()->GetSelection(); mitk::DataNodeSelection::ConstPointer currentSelection = selection.Cast(); if (currentSelection.IsNull() || currentSelection->IsEmpty()) { return selectedNodes; } selectedNodes = QList::fromStdList(currentSelection->GetSelectedDataNodes()); return selectedNodes; } -mitk::DataNode::Pointer QmitkDataNodeControlPointAction::GetSelectedNode() +mitk::DataNode::Pointer QmitkDataNodeSetControlPointAction::GetSelectedNode() { QList selectedNodes = GetSelectedNodes(); if (selectedNodes.empty()) { return nullptr; } // no batch action; should only be called with a single node mitk::DataNode::Pointer dataNode = selectedNodes.front(); if (nullptr == dataNode) { return nullptr; } return dataNode; } diff --git a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeControlPointAction.h b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeSetControlPointAction.h similarity index 80% rename from Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeControlPointAction.h rename to Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeSetControlPointAction.h index 08be01e956..a948081620 100644 --- a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeControlPointAction.h +++ b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeSetControlPointAction.h @@ -1,64 +1,64 @@ /*=================================================================== 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. ===================================================================*/ #ifndef QMITKDATANODECONTROLPOINTEACTION_H #define QMITKDATANODECONTROLPOINTEACTION_H // mitk core #include #include #include // semantic relations module #include // berry #include // qt #include -class QmitkDataNodeControlPointAction : public QAction +class QmitkDataNodeSetControlPointAction : public QAction { Q_OBJECT public: - QmitkDataNodeControlPointAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); - QmitkDataNodeControlPointAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite); + QmitkDataNodeSetControlPointAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); + QmitkDataNodeSetControlPointAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite); - virtual ~QmitkDataNodeControlPointAction() override; + virtual ~QmitkDataNodeSetControlPointAction() override; void SetDataStorage(mitk::DataStorage* dataStorage); private Q_SLOTS: void OnActionTriggered(bool); protected: void InitializeAction(); QList GetSelectedNodes(); mitk::DataNode::Pointer GetSelectedNode(); QWidget* m_Parent; berry::IWorkbenchPartSite::WeakPtr m_WorkbenchPartSite; mitk::WeakPointer m_DataStorage; std::unique_ptr m_SemanticRelations; }; #endif // QMITKDATANODECONTROLPOINTEACTION_H diff --git a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkSemanticRelationsContextMenu.cpp b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkSemanticRelationsContextMenu.cpp index 4fdf19c9c8..f63bb4fc42 100644 --- a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkSemanticRelationsContextMenu.cpp +++ b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkSemanticRelationsContextMenu.cpp @@ -1,74 +1,74 @@ /*=================================================================== 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. ===================================================================*/ // semantic relations plugin #include "QmitkSemanticRelationsContextMenu.h" QmitkSemanticRelationsContextMenu::QmitkSemanticRelationsContextMenu(berry::IWorkbenchPartSite::Pointer workbenchPartSite, QWidget* parent) : QMenu(parent) { m_WorkbenchPartSite = workbenchPartSite; m_Parent = parent; InitDefaultActions(); } QmitkSemanticRelationsContextMenu::~QmitkSemanticRelationsContextMenu() { // nothing here } void QmitkSemanticRelationsContextMenu::SetDataStorage(mitk::DataStorage* dataStorage) { if (m_DataStorage != dataStorage) { // set the new data storage - also for all actions m_DataStorage = dataStorage; m_ControlPointAction->SetDataStorage(m_DataStorage.Lock()); m_InformationTypeAction->SetDataStorage(m_DataStorage.Lock()); m_RemoveFromSemanticRelationsAction->SetDataStorage(m_DataStorage.Lock()); } } void QmitkSemanticRelationsContextMenu::SetControlledRenderer(RenderWindowLayerUtilities::RendererVector controlledRenderer) { if (m_ControlledRenderer != controlledRenderer) { // set the new set of controlled renderer m_ControlledRenderer = controlledRenderer; m_OpenInAction->SetControlledRenderer(m_ControlledRenderer); } } void QmitkSemanticRelationsContextMenu::OnContextMenuRequested(const QPoint& /*pos*/) { popup(QCursor::pos()); } void QmitkSemanticRelationsContextMenu::InitDefaultActions() { - m_ControlPointAction = new QmitkDataNodeControlPointAction(m_Parent, m_WorkbenchPartSite.Lock()); + m_ControlPointAction = new QmitkDataNodeSetControlPointAction(m_Parent, m_WorkbenchPartSite.Lock()); addAction(m_ControlPointAction); m_InformationTypeAction = new QmitkDataNodeInformationTypeAction(m_Parent, m_WorkbenchPartSite.Lock()); addAction(m_InformationTypeAction); m_RemoveFromSemanticRelationsAction = new QmitkDataNodeRemoveFromSemanticRelationsAction(m_Parent, m_WorkbenchPartSite.Lock()); addAction(m_RemoveFromSemanticRelationsAction); m_OpenInAction = new QmitkDataNodeOpenInAction(m_Parent, m_WorkbenchPartSite.Lock()); addAction(m_OpenInAction); } diff --git a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkSemanticRelationsContextMenu.h b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkSemanticRelationsContextMenu.h index 54dfacb155..3daa83805f 100644 --- a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkSemanticRelationsContextMenu.h +++ b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkSemanticRelationsContextMenu.h @@ -1,71 +1,71 @@ /*=================================================================== 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. ===================================================================*/ #ifndef QMITKSEMANTICRELATIONSCONTEXTMENU_H #define QMITKSEMANTICRELATIONSCONTEXTMENU_H // semantic relations plugin -#include "QmitkDataNodeControlPointAction.h" +#include "QmitkDataNodeSetControlPointAction.h" #include "QmitkDataNodeInformationTypeAction.h" #include "QmitkDataNodeRemoveFromSemanticRelationsAction.h" #include "QmitkDataNodeOpenInAction.h" // mitk core #include #include // mitk render window manager module #include // blueberry ui qt plugin #include //qt #include class QmitkSemanticRelationsContextMenu : public QMenu { Q_OBJECT public: QmitkSemanticRelationsContextMenu(berry::IWorkbenchPartSite::Pointer workbenchPartSite, QWidget* parent = nullptr); virtual ~QmitkSemanticRelationsContextMenu() override; void SetDataStorage(mitk::DataStorage* dataStorage); void SetControlledRenderer(RenderWindowLayerUtilities::RendererVector controlledRenderer); public Q_SLOTS: void OnContextMenuRequested(const QPoint&); private: void InitDefaultActions(); QWidget* m_Parent; berry::IWorkbenchPartSite::WeakPtr m_WorkbenchPartSite; mitk::WeakPointer m_DataStorage; RenderWindowLayerUtilities::RendererVector m_ControlledRenderer; - QmitkDataNodeControlPointAction* m_ControlPointAction; + QmitkDataNodeSetControlPointAction* m_ControlPointAction; QmitkDataNodeInformationTypeAction* m_InformationTypeAction; QmitkDataNodeRemoveFromSemanticRelationsAction* m_RemoveFromSemanticRelationsAction; QmitkDataNodeOpenInAction* m_OpenInAction; }; #endif // QMITKSEMANTICRELATIONSCONTEXTMENU_H