diff --git a/Modules/MatchPointRegistration/Helper/mitkResultNodeGenerationHelper.cpp b/Modules/MatchPointRegistration/Helper/mitkResultNodeGenerationHelper.cpp index fcf8b0a2db..fe95072436 100644 --- a/Modules/MatchPointRegistration/Helper/mitkResultNodeGenerationHelper.cpp +++ b/Modules/MatchPointRegistration/Helper/mitkResultNodeGenerationHelper.cpp @@ -1,81 +1,81 @@ /*=================================================================== 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 "mitkResultNodeGenerationHelper.h" #include #include #include mitk::DataNode::Pointer mitk::generateRegistrationResultNode(const std::string& nodeName, mitk::MAPRegistrationWrapper::Pointer resultReg, const std::string& algorithmUID, const std::string& movingNodeUID, const std::string& targetNodeUID) { if (resultReg.IsNull()) { mitkThrow() << "Cannot generate registration result node. Passed registration wrapper points to NULL."; } mitk::DataNode::Pointer m_spRegNode = mitk::DataNode::New(); m_spRegNode->SetData(resultReg); m_spRegNode->SetName(nodeName); - m_spRegNode->AddProperty(mitk::nodeProp_RegAlgUsed,mitk::StringProperty::New(algorithmUID)); - m_spRegNode->AddProperty(mitk::nodeProp_RegAlgMovingData,mitk::StringProperty::New(movingNodeUID)); - m_spRegNode->AddProperty(mitk::nodeProp_RegAlgTargetData,mitk::StringProperty::New(targetNodeUID)); - m_spRegNode->AddProperty(mitk::nodeProp_RegUID,mitk::StringProperty::New(resultReg->GetRegistration()->getRegistrationUID())); + resultReg->SetProperty(mitk::Prop_RegAlgUsed, mitk::StringProperty::New(algorithmUID)); + resultReg->SetProperty(mitk::Prop_RegAlgMovingData, mitk::StringProperty::New(movingNodeUID)); + resultReg->SetProperty(mitk::Prop_RegAlgTargetData, mitk::StringProperty::New(targetNodeUID)); + resultReg->SetProperty(mitk::Prop_RegUID, mitk::StringProperty::New(resultReg->GetRegistration()->getRegistrationUID())); return m_spRegNode; }; mitk::DataNode::Pointer mitk::generateMappedResultNode(const std::string& nodeName, mitk::BaseData::Pointer mappedData, const std::string& regUID, const std::string& inputNodeUID, const bool refinedGeometry, const std::string& interpolator) { if (mappedData.IsNull()) { mitkThrow() << "Cannot generate mapping result node. Passed mapped data points to NULL."; } mitk::DataNode::Pointer mappedDataNode = mitk::DataNode::New(); mappedDataNode->SetData(mappedData); mappedDataNode->SetName(nodeName); if (!regUID.empty()) { - mappedDataNode->AddProperty(mitk::nodeProp_RegUID, mitk::StringProperty::New(regUID)); + mappedData->SetProperty(mitk::Prop_RegUID, mitk::StringProperty::New(regUID)); } - mappedDataNode->AddProperty(mitk::nodeProp_MappingInputData,mitk::StringProperty::New(inputNodeUID)); + mappedData->SetProperty(mitk::Prop_MappingInputData, mitk::StringProperty::New(inputNodeUID)); if (refinedGeometry) { - mappedDataNode->AddProperty(mitk::nodeProp_MappingInterpolator,mitk::StringProperty::New("None")); - mappedDataNode->AddProperty(mitk::nodeProp_MappingRefinedGeometry,mitk::BoolProperty::New(true)); + mappedData->SetProperty(mitk::Prop_MappingInterpolator, mitk::StringProperty::New("None")); + mappedData->SetProperty(mitk::Prop_MappingRefinedGeometry, mitk::BoolProperty::New(true)); } else { mitk::Image* image = dynamic_cast(mappedData.GetPointer()); if(image) { - mappedDataNode->AddProperty(mitk::nodeProp_MappingInterpolator,mitk::StringProperty::New(interpolator)); + mappedData->SetProperty(mitk::Prop_MappingInterpolator, mitk::StringProperty::New(interpolator)); } else { - mappedDataNode->AddProperty(mitk::nodeProp_MappingInterpolator,mitk::StringProperty::New("None")); - mappedDataNode->SetColor(0.0,0.0,1.0); + mappedData->SetProperty(mitk::Prop_MappingInterpolator, mitk::StringProperty::New("None")); + mappedDataNode->SetColor(0.0, 0.0, 1.0); } } return mappedDataNode; }; diff --git a/Modules/MatchPointRegistration/Helper/mitkUIDHelper.cpp b/Modules/MatchPointRegistration/Helper/mitkUIDHelper.cpp index b9bb54215d..8d886532e5 100644 --- a/Modules/MatchPointRegistration/Helper/mitkUIDHelper.cpp +++ b/Modules/MatchPointRegistration/Helper/mitkUIDHelper.cpp @@ -1,57 +1,98 @@ /*=================================================================== 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 "mitkUIDHelper.h" // Mitk #include #include +#include +#include mitk::NodeUIDType mitk::EnsureUID(mitk::DataNode* node) { if (!node) { mitkThrow() << "Cannot ensure node UID. Passed node pointer is NULL."; } std::string propUID = ""; if (!node->GetStringProperty(mitk::nodeProp_UID,propUID)) { mitk::UIDGenerator generator; propUID = generator.GetUID(); node->SetStringProperty(mitk::nodeProp_UID,propUID.c_str()); } return propUID; }; bool mitk::CheckUID(const mitk::DataNode* node, const NodeUIDType& uid) { bool result = false; if (node) { std::string propUID = ""; if (node->GetStringProperty(mitk::nodeProp_UID,propUID)) { result = propUID == uid; } } return result; }; + +mitk::NodeUIDType mitk::EnsureUID(mitk::BaseData* data) +{ + if (!data) + { + mitkThrow() << "Cannot ensure node UID. Passed node pointer is NULL."; + } + + BaseProperty::Pointer uidProp = data->GetProperty(mitk::Prop_UID); + std::string propUID = ""; + + if (uidProp.IsNotNull()) + { + propUID = uidProp->GetValueAsString(); + } + else + { + mitk::UIDGenerator generator; + propUID = generator.GetUID(); + + data->SetProperty(mitk::Prop_UID, mitk::StringProperty::New(propUID)); + } + + return propUID; +}; + +bool mitk::CheckUID(const mitk::BaseData* data, const NodeUIDType& uid) +{ + bool result = false; + + BaseProperty::Pointer uidProp = data->GetProperty(mitk::Prop_UID); + + if (uidProp.IsNotNull()) + { + result = uidProp->GetValueAsString() == uid; + } + + return result; +}; diff --git a/Modules/MatchPointRegistration/Helper/mitkUIDHelper.h b/Modules/MatchPointRegistration/Helper/mitkUIDHelper.h index 9a27a57f8e..a0c3652d8d 100644 --- a/Modules/MatchPointRegistration/Helper/mitkUIDHelper.h +++ b/Modules/MatchPointRegistration/Helper/mitkUIDHelper.h @@ -1,43 +1,50 @@ /*=================================================================== 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 mitkUIDHelper_h #define mitkUIDHelper_h -//MITK -#include +#include //MITK #include "MitkMatchPointRegistrationExports.h" #include "mitkMatchPointPropertyTags.h" namespace mitk { + class DataNode; + class BaseData; typedef std::string NodeUIDType; - /** Gets the content of the property "matchpoint.uid". If it does not exist, the property will be added with a new UID. + /** Gets the content of the property "node.uid". If it does not exist, the property will be added with a new UID. @pre Passed node is a valid pointer.*/ NodeUIDType MITKMATCHPOINTREGISTRATION_EXPORT EnsureUID(mitk::DataNode* node); - /** Helper that checks if the content of property "matchpoint.uid" equals the passed uid. If the property does not exist or node is invalid, return will be false.*/ + /** Helper that checks if the content of property "node.uid" equals the passed uid. If the property does not exist or node is invalid, return will be false.*/ bool MITKMATCHPOINTREGISTRATION_EXPORT CheckUID(const mitk::DataNode* node, const NodeUIDType& uid); + /** Gets the content of the property "data.uid". If it does not exist, the property will be added with a new UID. + @pre Passed node is a valid pointer.*/ + NodeUIDType MITKMATCHPOINTREGISTRATION_EXPORT EnsureUID(mitk::BaseData* data); + + /** Helper that checks if the content of property "data.uid" equals the passed uid. If the property does not exist or node is invalid, return will be false.*/ + bool MITKMATCHPOINTREGISTRATION_EXPORT CheckUID(const mitk::BaseData* data, const NodeUIDType& uid); } #endif diff --git a/Modules/MatchPointRegistration/mitkMatchPointPropertyTags.h b/Modules/MatchPointRegistration/mitkMatchPointPropertyTags.h index 39dae53e31..e17b074d9d 100644 --- a/Modules/MatchPointRegistration/mitkMatchPointPropertyTags.h +++ b/Modules/MatchPointRegistration/mitkMatchPointPropertyTags.h @@ -1,40 +1,50 @@ /*=================================================================== 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 _MITK_MATCHPOINTPROPERTY_TAGS__H_ #define _MITK_MATCHPOINTPROPERTY_TAGS__H_ // MITK #include "MitkMatchPointRegistrationExports.h" namespace mitk { -const char* const nodeProp_RegAlgUsed = "matchpoint.Registration.Algorithm.UID"; -const char* const nodeProp_RegAlgTargetData = "matchpoint.Registration.Algorithm.UsedData.target"; -const char* const nodeProp_RegAlgMovingData = "matchpoint.Registration.Algorithm.UsedData.moving"; -const char* const nodeProp_RegUID = "matchpoint.Registration.UID"; -const char* const nodeProp_MappingInput = "matchpoint.Mapping.Input"; -const char* const nodeProp_MappingInputData = "matchpoint.Mapping.Input.Data"; -const char* const nodeProp_MappingInterpolator = "matchpoint.Mapping.Interpolator"; -const char* const nodeProp_MappingRefinedGeometry = "matchpoint.Mapping.RefinedGeometry"; -const char* const nodeProp_UID = "matchpoint.UID"; - + /**UID of the algorithm that was used to determin a registration.*/ + const char* const Prop_RegAlgUsed = "matchpoint.Registration.Algorithm.UID"; + /**UID(s) of the data object(s) used as target for determining the registration.*/ + const char* const Prop_RegAlgTargetData = "matchpoint.Registration.Algorithm.UsedData.target"; + /**UID(s) of the data object(s) used as moving objects for determining the registration.*/ + const char* const Prop_RegAlgMovingData = "matchpoint.Registration.Algorithm.UsedData.moving"; + /**UID of the registration instance.*/ + const char* const Prop_RegUID = "matchpoint.Registration.UID"; + /**Input "section" that specifies what wwas mapped.*/ + const char* const Prop_MappingInput = "matchpoint.Mapping.Input"; + /**UID of the data object that was mapped (so the source) by the specified registration to generate the current instance.*/ + const char* const Prop_MappingInputData = "matchpoint.Mapping.Input.Data"; + /**Type of the interpolation strategy that was used to map the object. If not set, no interpolation was needed for mapping.*/ + const char* const Prop_MappingInterpolator = "matchpoint.Mapping.Interpolator"; + /**Indicates that the data was not mapped (in termes of resampled), but "just" the geometry was refined.*/ + const char* const Prop_MappingRefinedGeometry = "matchpoint.Mapping.RefinedGeometry"; + /**MatchPoint UID to uniquely identify an data object.*/ + const char* const Prop_UID = "data.UID"; + /**MatchPoint UID to uniquely identify an node.*/ + const char* const nodeProp_UID = "matchpoint.UID"; } #endif diff --git a/Modules/MatchPointRegistrationUI/Qmitk/QmitkFramesRegistrationJob.cpp b/Modules/MatchPointRegistrationUI/Qmitk/QmitkFramesRegistrationJob.cpp index 684493099d..bf1ff14004 100644 --- a/Modules/MatchPointRegistrationUI/Qmitk/QmitkFramesRegistrationJob.cpp +++ b/Modules/MatchPointRegistrationUI/Qmitk/QmitkFramesRegistrationJob.cpp @@ -1,215 +1,215 @@ /*=================================================================== 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 "QmitkFramesRegistrationJob.h" // Mitk #include // Qt #include // Map4CTK #include #include #include #include // MatchPoint #include #include #include #include #include const mitk::Image *QmitkFramesRegistrationJob::GetTargetDataAsImage() const { return dynamic_cast(m_spTargetData.GetPointer()); }; const map::algorithm::RegistrationAlgorithmBase *QmitkFramesRegistrationJob::GetLoadedAlgorithm() const { return m_spLoadedAlgorithm; }; void QmitkFramesRegistrationJob::OnMapAlgorithmEvent(::itk::Object *, const itk::EventObject &event) { const map::events::AlgorithmEvent *pAlgEvent = dynamic_cast(&event); const map::events::AlgorithmIterationEvent *pIterationEvent = dynamic_cast(&event); const map::events::AlgorithmWrapperEvent *pWrapEvent = dynamic_cast(&event); const map::events::AlgorithmResolutionLevelEvent *pLevelEvent = dynamic_cast(&event); const map::events::InitializingAlgorithmEvent *pInitEvent = dynamic_cast(&event); const map::events::StartingAlgorithmEvent *pStartEvent = dynamic_cast(&event); const map::events::StoppingAlgorithmEvent *pStoppingEvent = dynamic_cast(&event); const map::events::StoppedAlgorithmEvent *pStoppedEvent = dynamic_cast(&event); const map::events::FinalizingAlgorithmEvent *pFinalizingEvent = dynamic_cast(&event); const map::events::FinalizedAlgorithmEvent *pFinalizedEvent = dynamic_cast(&event); const itk::ProgressEvent *pProgressEvent = dynamic_cast(&event); const mitk::FrameRegistrationEvent *pFrameRegEvent = dynamic_cast(&event); const mitk::FrameMappingEvent *pFrameMapEvent = dynamic_cast(&event); if (pProgressEvent) { emit FrameProcessed(m_helper->GetProgress()); } else if (pFrameRegEvent) { emit FrameRegistered(m_helper->GetProgress()); } else if (pFrameMapEvent) { emit FrameMapped(m_helper->GetProgress()); } else if (pInitEvent) { emit AlgorithmStatusChanged(QString("Initializing algorithm ...")); } else if (pStartEvent) { emit AlgorithmStatusChanged(QString("Starting algorithm ...")); } else if (pStoppingEvent) { emit AlgorithmStatusChanged(QString("Stopping algorithm ...")); } else if (pStoppedEvent) { emit AlgorithmStatusChanged(QString("Stopped algorithm ...")); if (!pStoppedEvent->getComment().empty()) { emit AlgorithmInfo(QString("Stopping condition: ") + QString::fromStdString(pStoppedEvent->getComment())); } } else if (pFinalizingEvent) { emit AlgorithmStatusChanged(QString("Finalizing algorithm and results ...")); } else if (pFinalizedEvent) { emit AlgorithmStatusChanged(QString("Finalized algorithm ...")); } else if (pIterationEvent) { const IIterativeAlgorithm *pIterative = dynamic_cast(this->m_spLoadedAlgorithm.GetPointer()); map::algorithm::facet::IterativeAlgorithmInterface::IterationCountType count = 0; bool hasCount = false; if (pIterative && pIterative->hasIterationCount()) { hasCount = true; count = pIterative->getCurrentIteration(); } emit AlgorithmIterated(QString::fromStdString(pIterationEvent->getComment()), hasCount, count); } else if (pLevelEvent) { const IMultiResAlgorithm *pResAlg = dynamic_cast(this->m_spLoadedAlgorithm.GetPointer()); map::algorithm::facet::MultiResRegistrationAlgorithmInterface::ResolutionLevelCountType count = 0; bool hasCount = false; QString info = QString::fromStdString(pLevelEvent->getComment()); if (pResAlg && pResAlg->hasLevelCount()) { count = pResAlg->getCurrentLevel() + 1; hasCount = true; info = QString("Level #") + QString::number(pResAlg->getCurrentLevel() + 1) + QString(" ") + info; } emit LevelChanged(info, hasCount, count); } else if (pAlgEvent && !pWrapEvent) { emit AlgorithmInfo(QString::fromStdString(pAlgEvent->getComment())); } } QmitkFramesRegistrationJob::QmitkFramesRegistrationJob(map::algorithm::RegistrationAlgorithmBase *pAlgorithm) - : m_spLoadedAlgorithm(pAlgorithm), m_TargetNodeUID("Missing target UID") + : m_spLoadedAlgorithm(pAlgorithm), m_TargetDataUID("Missing target UID") { m_MappedName = "Unnamed RegJob"; m_spTargetMask = NULL; m_spCommand = ::itk::MemberCommand::New(); m_spCommand->SetCallbackFunction(this, &QmitkFramesRegistrationJob::OnMapAlgorithmEvent); m_ObserverID = m_spLoadedAlgorithm->AddObserver(::map::events::AlgorithmEvent(), m_spCommand); }; QmitkFramesRegistrationJob::~QmitkFramesRegistrationJob() { m_spLoadedAlgorithm->RemoveObserver(m_ObserverID); }; void QmitkFramesRegistrationJob::run() { try { m_helper = mitk::TimeFramesRegistrationHelper::New(); m_helper->Set4DImage(this->GetTargetDataAsImage()); m_helper->SetTargetMask(this->m_spTargetMask); m_helper->SetAlgorithm(this->m_spLoadedAlgorithm); m_helper->SetIgnoreList(this->m_IgnoreList); m_helper->SetAllowUndefPixels(this->m_allowUndefPixels); m_helper->SetAllowUnregPixels(this->m_allowUnregPixels); m_helper->SetErrorValue(this->m_errorValue); m_helper->SetPaddingValue(this->m_paddingValue); m_helper->SetInterpolatorType(this->m_InterpolatorType); m_helper->AddObserver(::map::events::AnyMatchPointEvent(), m_spCommand); m_helper->AddObserver(::itk::ProgressEvent(), m_spCommand); // perform registration m_spMappedImageNode = m_helper->GetRegisteredImage(); // wrap the registration in a data node if (m_spMappedImageNode.IsNull()) { emit Error(QString("Error. No registration was determined. No results to store.")); } else { emit ResultIsAvailable(m_spMappedImageNode, this); } } catch (::std::exception &e) { emit Error(QString("Error while registering data. Details: ") + QString::fromLatin1(e.what())); } catch (...) { emit Error(QString("Unkown error when registering data.")); } emit Finished(); }; diff --git a/Modules/MatchPointRegistrationUI/Qmitk/QmitkFramesRegistrationJob.h b/Modules/MatchPointRegistrationUI/Qmitk/QmitkFramesRegistrationJob.h index 1f5af2db93..3721cdaae8 100644 --- a/Modules/MatchPointRegistrationUI/Qmitk/QmitkFramesRegistrationJob.h +++ b/Modules/MatchPointRegistrationUI/Qmitk/QmitkFramesRegistrationJob.h @@ -1,104 +1,104 @@ /*=================================================================== 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 __QMITK_FRAMES_REGISTRATION_JOB_H #define __QMITK_FRAMES_REGISTRATION_JOB_H // QT #include #include // ITK #include // MITK #include #include #include // MatchPoint #include #include #include #include #include // Map4CTK #include "mitkUIDHelper.h" #include #include /** Simple helper job class that could be used to process a frame registration in a paralell thread. * This is e.g. used be plugins to keep the GUI responsive while doing a frame registration*/ class MITKMATCHPOINTREGISTRATIONUI_EXPORT QmitkFramesRegistrationJob : public QObject, public QRunnable, public QmitkMappingJobSettings { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT public: QmitkFramesRegistrationJob(map::algorithm::RegistrationAlgorithmBase *pAlgorithm); ~QmitkFramesRegistrationJob(); void run(); signals: void Finished(); void Error(QString err); void ResultIsAvailable(mitk::Image::Pointer spResult, const QmitkFramesRegistrationJob *pJob); void AlgorithmIterated(QString info, bool hasIterationCount, unsigned long currentIteration); void LevelChanged(QString info, bool hasLevelCount, unsigned long currentLevel); void AlgorithmStatusChanged(QString info); void AlgorithmInfo(QString info); void FrameProcessed(double progress); void FrameRegistered(double progress); void FrameMapped(double progress); public: // Inputs mitk::BaseData::ConstPointer m_spTargetData; mitk::Image::ConstPointer m_spTargetMask; // job settings mitk::TimeFramesRegistrationHelper::IgnoreListType m_IgnoreList; - mitk::NodeUIDType m_TargetNodeUID; - mitk::NodeUIDType m_TargetMaskNodeUID; + mitk::NodeUIDType m_TargetDataUID; + mitk::NodeUIDType m_TargetMaskDataUID; const map::algorithm::RegistrationAlgorithmBase *GetLoadedAlgorithm() const; private: typedef map::algorithm::facet::IterativeAlgorithmInterface IIterativeAlgorithm; typedef map::algorithm::facet::MultiResRegistrationAlgorithmInterface IMultiResAlgorithm; mitk::Image::Pointer m_spMappedImageNode; ::itk::MemberCommand::Pointer m_spCommand; unsigned long m_ObserverID; map::algorithm::RegistrationAlgorithmBase::Pointer m_spLoadedAlgorithm; mitk::TimeFramesRegistrationHelper::Pointer m_helper; // Helper functions const mitk::Image *GetTargetDataAsImage() const; void OnMapAlgorithmEvent(::itk::Object *, const itk::EventObject &event); }; #endif diff --git a/Modules/MatchPointRegistrationUI/Qmitk/QmitkMappingJob.h b/Modules/MatchPointRegistrationUI/Qmitk/QmitkMappingJob.h index 33d591ec94..8aa51baea5 100644 --- a/Modules/MatchPointRegistrationUI/Qmitk/QmitkMappingJob.h +++ b/Modules/MatchPointRegistrationUI/Qmitk/QmitkMappingJob.h @@ -1,105 +1,105 @@ /*=================================================================== 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 __QMITK_MAPPING_JOB_H #define __QMITK_MAPPING_JOB_H // QT #include #include // ITK #include "itkCommand.h" // MatchPoint #include // MITK #include #include #include #include #include struct MITKMATCHPOINTREGISTRATIONUI_EXPORT QmitkMappingJobSettings { public: /**Job name*/ std::string m_MappedName; /**Indicates of mapper should try to refine geometry (true) or map the data (false)*/ bool m_doGeometryRefinement; /**Indicates if the mapper should allow undefined pixels (true) or mapping should fail (false)*/ bool m_allowUndefPixels; /** Value of undefined pixels. Only relevant if m_allowUndefPixels is true. */ double m_paddingValue; /**Indicates if the mapper should allow pixels that are not covered by the registration (true) or mapping should fail * (false)*/ bool m_allowUnregPixels; /** Value of unreged pixels. Only relevant if m_allowUnregPixels is true. */ double m_errorValue; /** Type of interpolator. Only relevant for images and if m_doGeometryRefinement is false. */ mitk::ImageMappingInterpolator::Type m_InterpolatorType; /** Display name of the interpolator*/ std::string m_InterpolatorLabel; QmitkMappingJobSettings(); }; class MITKMATCHPOINTREGISTRATIONUI_EXPORT QmitkMappingJob : public QObject, public QRunnable, public QmitkMappingJobSettings { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT public: QmitkMappingJob(); ~QmitkMappingJob(); void run(); signals: void Error(QString err); /**Signal is emitted to return the mapped data itself. Use it if you are only interested in the mapped data*/ void MapResultIsAvailable(mitk::BaseData::Pointer spMappedData, const QmitkMappingJob *job); void AlgorithmInfo(QString info); public: // Inputs mitk::DataNode::Pointer m_spRegNode; mitk::BaseData::ConstPointer m_spInputData; - mitk::NodeUIDType m_InputNodeUID; + mitk::NodeUIDType m_InputDataUID; mitk::BaseGeometry::Pointer m_spRefGeometry; const map::core::RegistrationBase *GetRegistration() const; protected: // mapped data. mitk::BaseData::Pointer m_spMappedData; ::itk::MemberCommand::Pointer m_spCommand; unsigned long m_ObserverID; // Helper functions const mitk::Image *GetInputDataAsImage() const; const mitk::PointSet *GetInputDataAsPointSet() const; void OnMapAlgorithmEvent(::itk::Object *, const itk::EventObject &event); }; #endif diff --git a/Modules/MatchPointRegistrationUI/Qmitk/QmitkRegistrationJob.cpp b/Modules/MatchPointRegistrationUI/Qmitk/QmitkRegistrationJob.cpp index dd903f445a..04bfecceb5 100644 --- a/Modules/MatchPointRegistrationUI/Qmitk/QmitkRegistrationJob.cpp +++ b/Modules/MatchPointRegistrationUI/Qmitk/QmitkRegistrationJob.cpp @@ -1,205 +1,205 @@ /*=================================================================== 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 "QmitkRegistrationJob.h" // Mitk #include #include #include #include #include #include #include // Qt #include // MatchPoint #include #include #include #include #include const mitk::Image *QmitkRegistrationJob::GetTargetDataAsImage() const { return dynamic_cast(m_spTargetData.GetPointer()); }; const mitk::Image *QmitkRegistrationJob::GetMovingDataAsImage() const { return dynamic_cast(m_spMovingData.GetPointer()); }; const map::algorithm::RegistrationAlgorithmBase *QmitkRegistrationJob::GetLoadedAlgorithm() const { return m_spLoadedAlgorithm; }; void QmitkRegistrationJob::OnMapAlgorithmEvent(::itk::Object *, const itk::EventObject &event) { const map::events::AlgorithmEvent *pAlgEvent = dynamic_cast(&event); const map::events::AlgorithmIterationEvent *pIterationEvent = dynamic_cast(&event); const map::events::AlgorithmWrapperEvent *pWrapEvent = dynamic_cast(&event); const map::events::AlgorithmResolutionLevelEvent *pLevelEvent = dynamic_cast(&event); const map::events::InitializingAlgorithmEvent *pInitEvent = dynamic_cast(&event); const map::events::StartingAlgorithmEvent *pStartEvent = dynamic_cast(&event); const map::events::StoppingAlgorithmEvent *pStoppingEvent = dynamic_cast(&event); const map::events::StoppedAlgorithmEvent *pStoppedEvent = dynamic_cast(&event); const map::events::FinalizingAlgorithmEvent *pFinalizingEvent = dynamic_cast(&event); const map::events::FinalizedAlgorithmEvent *pFinalizedEvent = dynamic_cast(&event); if (pInitEvent) { emit AlgorithmStatusChanged(QString("Initializing algorithm ...")); } else if (pStartEvent) { emit AlgorithmStatusChanged(QString("Starting algorithm ...")); } else if (pStoppingEvent) { emit AlgorithmStatusChanged(QString("Stopping algorithm ...")); } else if (pStoppedEvent) { emit AlgorithmStatusChanged(QString("Stopped algorithm ...")); if (!pStoppedEvent->getComment().empty()) { emit AlgorithmInfo(QString("Stopping condition: ") + QString::fromStdString(pStoppedEvent->getComment())); } } else if (pFinalizingEvent) { emit AlgorithmStatusChanged(QString("Finalizing algorithm and results ...")); } else if (pFinalizedEvent) { emit AlgorithmStatusChanged(QString("Finalized algorithm ...")); } else if (pIterationEvent) { const IIterativeAlgorithm *pIterative = dynamic_cast(this->m_spLoadedAlgorithm.GetPointer()); map::algorithm::facet::IterativeAlgorithmInterface::IterationCountType count = 0; bool hasCount = false; if (pIterative && pIterative->hasIterationCount()) { hasCount = true; count = pIterative->getCurrentIteration(); } emit AlgorithmIterated(QString::fromStdString(pIterationEvent->getComment()), hasCount, count); } else if (pLevelEvent) { const IMultiResAlgorithm *pResAlg = dynamic_cast(this->m_spLoadedAlgorithm.GetPointer()); map::algorithm::facet::MultiResRegistrationAlgorithmInterface::ResolutionLevelCountType count = 0; bool hasCount = false; QString info = QString::fromStdString(pLevelEvent->getComment()); if (pResAlg && pResAlg->hasLevelCount()) { count = pResAlg->getCurrentLevel() + 1; hasCount = true; info = QString("Level #") + QString::number(pResAlg->getCurrentLevel() + 1) + QString(" ") + info; } emit LevelChanged(info, hasCount, count); } else if (pAlgEvent && !pWrapEvent) { emit AlgorithmInfo(QString::fromStdString(pAlgEvent->getComment())); } } QmitkRegistrationJob::QmitkRegistrationJob(map::algorithm::RegistrationAlgorithmBase *pAlgorithm) { m_MapEntity = false; m_StoreReg = false; m_ErrorOccured = false; m_spLoadedAlgorithm = pAlgorithm; m_JobName = "Unnamed RegJob"; - m_MovingNodeUID = "Missing moving UID"; - m_TargetNodeUID = "Missing target UID"; + m_MovingDataUID = "Missing moving UID"; + m_TargetDataUID = "Missing target UID"; m_spTargetMask = NULL; m_spMovingMask = NULL; m_spCommand = ::itk::MemberCommand::New(); m_spCommand->SetCallbackFunction(this, &QmitkRegistrationJob::OnMapAlgorithmEvent); m_ObserverID = m_spLoadedAlgorithm->AddObserver(::map::events::AlgorithmEvent(), m_spCommand); }; QmitkRegistrationJob::~QmitkRegistrationJob() { m_spLoadedAlgorithm->RemoveObserver(m_ObserverID); }; void QmitkRegistrationJob::run() { try { mitk::MITKAlgorithmHelper helper(m_spLoadedAlgorithm); mitk::MaskedAlgorithmHelper maskedHelper(m_spLoadedAlgorithm); //*@TODO Data Check and failure handle helper.SetData(this->m_spMovingData, this->m_spTargetData); maskedHelper.SetMasks(this->m_spMovingMask, this->m_spTargetMask); // perform registration m_spResultRegistration = helper.GetRegistration(); // wrap the registration in a data node if (m_spResultRegistration.IsNull()) { emit Error(QString("Error. No registration was determined. No results to store.")); } else { mitk::MAPRegistrationWrapper::Pointer spRegWrapper = mitk::MAPRegistrationWrapper::New(); spRegWrapper->SetRegistration(m_spResultRegistration); emit RegResultIsAvailable(spRegWrapper, this); } } catch (::std::exception &e) { emit Error(QString("Error while registering data. Details: ") + QString::fromLatin1(e.what())); } catch (...) { emit Error(QString("Unkown error when registering data.")); } emit Finished(); }; diff --git a/Modules/MatchPointRegistrationUI/Qmitk/QmitkRegistrationJob.h b/Modules/MatchPointRegistrationUI/Qmitk/QmitkRegistrationJob.h index 85a4328ec2..a1ffdd634b 100644 --- a/Modules/MatchPointRegistrationUI/Qmitk/QmitkRegistrationJob.h +++ b/Modules/MatchPointRegistrationUI/Qmitk/QmitkRegistrationJob.h @@ -1,105 +1,105 @@ /*=================================================================== 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 __QMITK_REGISTRATION_JOB_H #define __QMITK_REGISTRATION_JOB_H // QT #include #include // ITK #include // MITK #include "mitkUIDHelper.h" #include #include #include // MatchPoint #include #include #include #include #include #include class MITKMATCHPOINTREGISTRATIONUI_EXPORT QmitkRegistrationJob : public QObject, public QRunnable { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT public: QmitkRegistrationJob(map::algorithm::RegistrationAlgorithmBase *pAlgorithm); ~QmitkRegistrationJob(); void run(); signals: void Finished(); void Error(QString err); void RegResultIsAvailable(mitk::MAPRegistrationWrapper::Pointer spResultRegistration, const QmitkRegistrationJob *pJob); void AlgorithmIterated(QString info, bool hasIterationCount, unsigned long currentIteration); void LevelChanged(QString info, bool hasLevelCount, unsigned long currentLevel); void AlgorithmStatusChanged(QString info); void AlgorithmInfo(QString info); public: // Inputs mitk::BaseData::ConstPointer m_spTargetData; mitk::BaseData::ConstPointer m_spMovingData; mitk::Image::ConstPointer m_spTargetMask; mitk::Image::ConstPointer m_spMovingMask; // job settings bool m_MapEntity; bool m_StoreReg; bool m_ErrorOccured; std::string m_JobName; - mitk::NodeUIDType m_TargetNodeUID; - mitk::NodeUIDType m_MovingNodeUID; - mitk::NodeUIDType m_TargetMaskNodeUID; - mitk::NodeUIDType m_MovingMaskNodeUID; + mitk::NodeUIDType m_TargetDataUID; + mitk::NodeUIDType m_MovingDataUID; + mitk::NodeUIDType m_TargetMaskDataUID; + mitk::NodeUIDType m_MovingMaskDataUID; const map::algorithm::RegistrationAlgorithmBase *GetLoadedAlgorithm() const; protected: typedef map::algorithm::facet::IterativeAlgorithmInterface IIterativeAlgorithm; typedef map::algorithm::facet::MultiResRegistrationAlgorithmInterface IMultiResAlgorithm; // Result registration. map::core::RegistrationBase::Pointer m_spResultRegistration; mitk::DataNode::Pointer m_spRegNode; // mapped image. May be null if m_MapEntity is false. mitk::DataNode::Pointer m_spMappedImageNode; ::itk::MemberCommand::Pointer m_spCommand; unsigned long m_ObserverID; map::algorithm::RegistrationAlgorithmBase::Pointer m_spLoadedAlgorithm; // Helper functions const mitk::Image *GetTargetDataAsImage() const; const mitk::Image *GetMovingDataAsImage() const; void OnMapAlgorithmEvent(::itk::Object *, const itk::EventObject &event); }; #endif diff --git a/Plugins/org.mitk.gui.qt.matchpoint.algorithm.control/src/internal/QmitkMatchPoint.cpp b/Plugins/org.mitk.gui.qt.matchpoint.algorithm.control/src/internal/QmitkMatchPoint.cpp index 4e1deb18ab..7fc75f8a91 100644 --- a/Plugins/org.mitk.gui.qt.matchpoint.algorithm.control/src/internal/QmitkMatchPoint.cpp +++ b/Plugins/org.mitk.gui.qt.matchpoint.algorithm.control/src/internal/QmitkMatchPoint.cpp @@ -1,980 +1,977 @@ /*=================================================================== 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 "org_mitk_gui_qt_matchpoint_algorithmcontrol_Activator.h" // Blueberry #include #include #include #include // Mitk #include #include #include #include #include #include #include #include #include #include // Qmitk #include "QmitkMatchPoint.h" #include #include // Qt #include #include #include #include #include // MatchPoint #include #include #include #include #include #include #include #include #include const std::string QmitkMatchPoint::VIEW_ID = "org.mitk.views.matchpoint.algorithm.control"; QmitkMatchPoint::QmitkMatchPoint() : m_Parent(NULL), m_LoadedDLLHandle(NULL), m_LoadedAlgorithm(NULL) { m_CanLoadAlgorithm = false; m_ValidInputs = false; m_Working = false; m_spSelectedTargetData = NULL; m_spSelectedMovingData = NULL; m_spSelectedTargetMaskData = NULL; m_spSelectedMovingMaskData = NULL; } QmitkMatchPoint::~QmitkMatchPoint() { // remove selection service berry::ISelectionService* s = this->GetSite()->GetWorkbenchWindow()->GetSelectionService(); if (s) { s->RemoveSelectionListener(m_AlgorithmSelectionListener.data()); } } void QmitkMatchPoint::SetFocus() { } void QmitkMatchPoint::CreateConnections() { connect(m_Controls.checkMovingMask, SIGNAL(toggled(bool)), this, SLOT(OnMaskCheckBoxToggeled(bool))); connect(m_Controls.checkTargetMask, SIGNAL(toggled(bool)), this, SLOT(OnMaskCheckBoxToggeled(bool))); // ------ // Tab 1 - Shared library loading interface // ------ connect(m_Controls.m_pbLoadSelected, SIGNAL(clicked()), this, SLOT(OnLoadAlgorithmButtonPushed())); // ----- // Tab 2 - Execution // ----- connect(m_Controls.m_pbStartReg, SIGNAL(clicked()), this, SLOT(OnStartRegBtnPushed())); connect(m_Controls.m_pbStopReg, SIGNAL(clicked()), this, SLOT(OnStopRegBtnPushed())); connect(m_Controls.m_pbSaveLog, SIGNAL(clicked()), this, SLOT(OnSaveLogBtnPushed())); } const map::deployment::DLLInfo* QmitkMatchPoint::GetSelectedAlgorithmDLL() const { return m_SelectedAlgorithmInfo; } void QmitkMatchPoint::OnMaskCheckBoxToggeled(bool checked) { if (!m_Working) { CheckInputs(); ConfigureRegistrationControls(); } }; void QmitkMatchPoint::OnSelectedAlgorithmChanged() { std::stringstream descriptionString; ::map::deployment::DLLInfo::ConstPointer currentItemInfo = GetSelectedAlgorithmDLL(); if (!currentItemInfo) { Error(QString("No valid algorithm is selected. ABORTING.")); return; } m_Controls.m_teAlgorithmDetails->updateInfo(currentItemInfo); m_Controls.m_lbSelectedAlgorithm->setText(QString::fromStdString( currentItemInfo->getAlgorithmUID().getName())); // enable loading m_CanLoadAlgorithm = true; this->AdaptFolderGUIElements(); } void QmitkMatchPoint::OnLoadAlgorithmButtonPushed() { map::deployment::DLLInfo::ConstPointer dllInfo = GetSelectedAlgorithmDLL(); if (!dllInfo) { Error(QString("No valid algorithm is selected. Cannot load algorithm. ABORTING.")); return; } ::map::deployment::DLLHandle::Pointer tempDLLHandle = ::map::deployment::openDeploymentDLL( dllInfo->getLibraryFilePath()); ::map::algorithm::RegistrationAlgorithmBase::Pointer tempAlgorithm = ::map::deployment::getRegistrationAlgorithm(tempDLLHandle); if (tempAlgorithm.IsNull()) { Error(QString("Error. Cannot load selected algorithm.")); return; } this->m_LoadedAlgorithm = tempAlgorithm; this->m_LoadedDLLHandle = tempDLLHandle; this->m_Controls.m_AlgoConfigurator->setAlgorithm(m_LoadedAlgorithm); m_Controls.checkMovingMask->setChecked(false); m_Controls.checkTargetMask->setChecked(false); this->AdaptFolderGUIElements(); this->CheckInputs(); this->ConfigureRegistrationControls(); this->ConfigureProgressInfos(); this->m_Controls.m_tabs->setCurrentIndex(1); } void QmitkMatchPoint::Error(QString msg) { mitk::StatusBar::GetInstance()->DisplayErrorText(msg.toLatin1()); MITK_ERROR << msg.toStdString().c_str(); m_Controls.m_teLog->append(QString("") + msg + QString("")); } void QmitkMatchPoint::AdaptFolderGUIElements() { m_Controls.m_pbLoadSelected->setEnabled(m_CanLoadAlgorithm); } void QmitkMatchPoint::CreateQtPartControl(QWidget* parent) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi(parent); m_Parent = parent; m_Controls.checkMovingMask->setChecked(false); m_Controls.checkTargetMask->setChecked(false); m_Controls.m_tabs->setCurrentIndex(0); m_AlgorithmSelectionListener.reset(new berry::SelectionChangedAdapter(this, &QmitkMatchPoint::OnAlgorithmSelectionChanged)); // register selection listener GetSite()->GetWorkbenchWindow()->GetSelectionService()->AddSelectionListener( m_AlgorithmSelectionListener.data()); this->CreateConnections(); this->AdaptFolderGUIElements(); this->CheckInputs(); this->ConfigureProgressInfos(); this->ConfigureRegistrationControls(); berry::ISelection::ConstPointer selection = GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection("org.mitk.views.matchpoint.algorithm.browser"); this->UpdateAlgorithmSelection(selection); } bool QmitkMatchPoint::CheckInputs() { bool validMoving = false; bool validTarget = false; bool validMovingMask = false; bool validTargetMask = false; mitk::NodePredicateDataType::Pointer isLabelSet = mitk::NodePredicateDataType::New("LabelSetImage"); mitk::NodePredicateDataType::Pointer isImage = mitk::NodePredicateDataType::New("Image"); mitk::NodePredicateProperty::Pointer isBinary = mitk::NodePredicateProperty::New("binary", mitk::BoolProperty::New(true)); mitk::NodePredicateAnd::Pointer isLegacyMask = mitk::NodePredicateAnd::New(isImage, isBinary); mitk::NodePredicateOr::Pointer maskPredicate = mitk::NodePredicateOr::New(isLegacyMask, isLabelSet); if (m_LoadedAlgorithm.IsNull()) { m_Controls.m_lbMovingName->setText(QString("No algorithm seleted!")); m_spSelectedMovingNode = NULL; m_spSelectedMovingData = NULL; m_Controls.m_lbTargetName->setText(QString("No algorithm seleted!")); m_spSelectedTargetNode = NULL; m_spSelectedTargetData = NULL; m_spSelectedMovingMaskNode = NULL; m_spSelectedMovingMaskData = NULL; m_spSelectedTargetMaskNode = NULL; m_spSelectedTargetMaskData = NULL; } else { QList nodes = this->GetDataManagerSelection(); mitk::Image* movingImage = NULL; mitk::PointSet* movingPointSet = NULL; mitk::Image* targetImage = NULL; mitk::PointSet* targetPointSet = NULL; mitk::Image* movingMaskImage = NULL; mitk::Image* targetMaskImage = NULL; typedef ::map::core::continuous::Elements<3>::InternalPointSetType InternalDefaultPointSetType; typedef ::map::algorithm::facet::PointSetRegistrationAlgorithmInterface PointSetRegInterface; typedef ::map::algorithm::facet::MaskedRegistrationAlgorithmInterface<3, 3> MaskRegInterface; PointSetRegInterface* pPointSetInterface = dynamic_cast (m_LoadedAlgorithm.GetPointer()); MaskRegInterface* pMaskInterface = dynamic_cast(m_LoadedAlgorithm.GetPointer()); if (nodes.count() < 1) { m_Controls.m_lbMovingName->setText(QString("no data selected!")); m_spSelectedMovingNode = NULL; m_spSelectedMovingData = NULL; } else { m_spSelectedMovingNode = nodes.front(); m_spSelectedMovingData = m_spSelectedMovingNode->GetData(); movingImage = dynamic_cast(m_spSelectedMovingNode->GetData()); movingPointSet = dynamic_cast(m_spSelectedMovingNode->GetData()); if (movingPointSet && pPointSetInterface) { validMoving = true; } else if (movingImage && !pPointSetInterface) { if (movingImage->GetDimension() - 1 == m_LoadedAlgorithm->getMovingDimensions() && movingImage->GetTimeSteps() > 1) { //images has multiple time steps and a time step has the correct dimensionality mitk::ImageTimeSelector::Pointer imageTimeSelector = mitk::ImageTimeSelector::New(); imageTimeSelector->SetInput(movingImage); imageTimeSelector->SetTimeNr(0); imageTimeSelector->UpdateLargestPossibleRegion(); m_spSelectedMovingData = imageTimeSelector->GetOutput(); validMoving = true; m_Controls.m_teLog->append( QString("Selected moving image has multiple time steps. First time step is used as moving image.")); } else if (movingImage->GetDimension() != m_LoadedAlgorithm->getMovingDimensions()) { m_Controls.m_lbMovingName->setText(QString("wrong image dimension. ") + QString::number(m_LoadedAlgorithm->getMovingDimensions()) + QString("D needed")); } else { validMoving = true; } } else { m_Controls.m_lbMovingName->setText(QString("no supported data selected!")); } nodes.removeFirst(); } if (nodes.count() < 1) { m_Controls.m_lbTargetName->setText(QString("no data selected!")); m_spSelectedTargetNode = NULL; m_spSelectedTargetData = NULL; } else { m_spSelectedTargetNode = nodes.front(); m_spSelectedTargetData = m_spSelectedTargetNode->GetData(); targetImage = dynamic_cast(m_spSelectedTargetNode->GetData()); targetPointSet = dynamic_cast(m_spSelectedTargetNode->GetData()); if (targetPointSet && pPointSetInterface) { validTarget = true; } else if (targetImage && !pPointSetInterface) { if (targetImage->GetDimension() - 1 == m_LoadedAlgorithm->getTargetDimensions() && targetImage->GetTimeSteps() > 1) { //images has multiple time steps and a time step has the correct dimensionality mitk::ImageTimeSelector::Pointer imageTimeSelector = mitk::ImageTimeSelector::New(); imageTimeSelector->SetInput(targetImage); imageTimeSelector->SetTimeNr(0); imageTimeSelector->UpdateLargestPossibleRegion(); m_spSelectedTargetData = imageTimeSelector->GetOutput(); validTarget = true; m_Controls.m_teLog->append( QString("Selected target image has multiple time steps. First time step is used as target image.")); } else if (targetImage->GetDimension() != m_LoadedAlgorithm->getTargetDimensions()) { m_Controls.m_lbTargetName->setText(QString("wrong image dimension. ") + QString::number(m_LoadedAlgorithm->getTargetDimensions()) + QString("D needed")); } else { validTarget = true; } } else { m_Controls.m_lbTargetName->setText(QString("no supported data selected!")); } nodes.removeFirst(); } if (m_Controls.checkMovingMask->isChecked()) { if (nodes.count() < 1) { m_Controls.m_lbMovingMaskName->setText(QString("no data selected!")); m_spSelectedMovingMaskNode = NULL; m_spSelectedMovingMaskData = NULL; } else { m_spSelectedMovingMaskNode = nodes.front(); m_spSelectedMovingMaskData = NULL; movingMaskImage = dynamic_cast(m_spSelectedMovingMaskNode->GetData()); bool isMask = maskPredicate->CheckNode(m_spSelectedMovingMaskNode); if (!isMask) { m_Controls.m_lbMovingMaskName->setText(QString("no mask selected!")); } else if (movingMaskImage && pMaskInterface) { if (movingMaskImage->GetDimension() - 1 == m_LoadedAlgorithm->getMovingDimensions() && movingMaskImage->GetTimeSteps() > 1) { //images has multiple time steps and a time step has the correct dimensionality mitk::ImageTimeSelector::Pointer imageTimeSelector = mitk::ImageTimeSelector::New(); imageTimeSelector->SetInput(movingMaskImage); imageTimeSelector->SetTimeNr(0); imageTimeSelector->UpdateLargestPossibleRegion(); m_spSelectedMovingMaskData = imageTimeSelector->GetOutput(); validMovingMask = true; m_Controls.m_teLog->append( QString("Selected moving mask has multiple time steps. First time step is used as moving mask.")); } else if (movingMaskImage->GetDimension() != m_LoadedAlgorithm->getMovingDimensions()) { m_Controls.m_lbMovingMaskName->setText(QString("wrong image dimension. ") + QString::number(m_LoadedAlgorithm->getMovingDimensions()) + QString("D needed")); } else { m_spSelectedMovingMaskData = movingMaskImage; validMovingMask = true; } } else { m_Controls.m_lbMovingMaskName->setText( QString("no supported data selected!")); } nodes.removeFirst(); } } else { m_Controls.m_lbMovingMaskName->setText(QString("mask deactivated")); validMovingMask = true; m_spSelectedMovingMaskNode = NULL; m_spSelectedMovingMaskData = NULL; } if (m_Controls.checkTargetMask->isChecked()) { if (nodes.count() < 1) { m_Controls.m_lbTargetMaskName->setText(QString("no data selected!")); m_spSelectedTargetMaskNode = NULL; m_spSelectedTargetMaskData = NULL; } else { m_spSelectedTargetMaskNode = nodes.front(); m_spSelectedTargetMaskData = NULL; targetMaskImage = dynamic_cast(m_spSelectedTargetMaskNode->GetData()); bool isMask = maskPredicate->CheckNode(m_spSelectedTargetMaskNode); if (!isMask) { m_Controls.m_lbTargetMaskName->setText(QString("no mask selected!")); } else if (targetMaskImage && pMaskInterface) { if (targetMaskImage->GetDimension() - 1 == m_LoadedAlgorithm->getTargetDimensions() && targetMaskImage->GetTimeSteps() > 1) { //images has multiple time steps and a time step has the correct dimensionality mitk::ImageTimeSelector::Pointer imageTimeSelector = mitk::ImageTimeSelector::New(); imageTimeSelector->SetInput(targetMaskImage); imageTimeSelector->SetTimeNr(0); imageTimeSelector->UpdateLargestPossibleRegion(); m_spSelectedTargetMaskData = imageTimeSelector->GetOutput(); validTargetMask = true; m_Controls.m_teLog->append( QString("Selected target mask has multiple time steps. First time step is used as target mask.")); } else if (targetMaskImage->GetDimension() != m_LoadedAlgorithm->getTargetDimensions()) { m_Controls.m_lbTargetMaskName->setText(QString("wrong image dimension. ") + QString::number(m_LoadedAlgorithm->getTargetDimensions()) + QString("D needed")); } else { m_spSelectedTargetMaskData = targetMaskImage; validTargetMask = true; } } else { m_Controls.m_lbTargetMaskName->setText( QString("no supported data selected!")); } } } else { m_Controls.m_lbTargetMaskName->setText(QString("mask deactivated")); validTargetMask = true; m_spSelectedTargetMaskNode = NULL; m_spSelectedTargetMaskData = NULL; } } if (validMoving) { m_Controls.m_lbMovingName->setText(QString::fromStdString(GetInputNodeDisplayName( m_spSelectedMovingNode))); } if (validTarget) { m_Controls.m_lbTargetName->setText(QString::fromStdString(GetInputNodeDisplayName( m_spSelectedTargetNode))); } if (validMovingMask && m_Controls.checkMovingMask->isChecked()) { m_Controls.m_lbMovingMaskName->setText(QString::fromStdString(GetInputNodeDisplayName( m_spSelectedMovingMaskNode))); } if (validTargetMask && m_Controls.checkTargetMask->isChecked()) { m_Controls.m_lbTargetMaskName->setText(QString::fromStdString(GetInputNodeDisplayName( m_spSelectedTargetMaskNode))); } m_ValidInputs = validMoving && validTarget && validMovingMask && validTargetMask; return m_ValidInputs; } std::string QmitkMatchPoint::GetInputNodeDisplayName(const mitk::DataNode* node) const { std::string result = "UNDEFINED/NULL"; if (node) { result = node->GetName(); const mitk::PointSet* pointSet = dynamic_cast(node->GetData()); if (pointSet) { mitk::DataStorage::SetOfObjects::ConstPointer sources = this->GetDataStorage()->GetSources(node); if (sources.IsNotNull() && sources->Size() > 0) { result = result + " (" + sources->GetElement(0)->GetName() + ")"; } } } return result; } mitk::DataStorage::SetOfObjects::Pointer QmitkMatchPoint::GetRegNodes() const { mitk::DataStorage::SetOfObjects::ConstPointer nodes = this->GetDataStorage()->GetAll(); mitk::DataStorage::SetOfObjects::Pointer result = mitk::DataStorage::SetOfObjects::New(); for (mitk::DataStorage::SetOfObjects::const_iterator pos = nodes->begin(); pos != nodes->end(); ++pos) { if (mitk::MITKRegistrationHelper::IsRegNode(*pos)) { result->push_back(*pos); } } return result; } std::string QmitkMatchPoint::GetDefaultRegJobName() const { mitk::DataStorage::SetOfObjects::ConstPointer nodes = this->GetRegNodes().GetPointer(); mitk::DataStorage::SetOfObjects::ElementIdentifier estimatedIndex = nodes->Size(); bool isUnique = false; std::string result = "Unnamed Reg"; while (!isUnique) { ++estimatedIndex; result = "Reg #" +::map::core::convert::toStr(estimatedIndex); isUnique = this->GetDataStorage()->GetNamedNode(result) == NULL; } return result; } void QmitkMatchPoint::ConfigureRegistrationControls() { m_Controls.m_tabSelection->setEnabled(!m_Working); m_Controls.m_leRegJobName->setEnabled(!m_Working); m_Controls.groupMasks->setEnabled(!m_Working); m_Controls.m_pbStartReg->setEnabled(false); m_Controls.m_pbStopReg->setEnabled(false); m_Controls.m_pbStopReg->setVisible(false); m_Controls.m_lbMovingMaskName->setVisible(m_Controls.checkMovingMask->isChecked()); m_Controls.m_lbTargetMaskName->setVisible(m_Controls.checkTargetMask->isChecked()); if (m_LoadedAlgorithm.IsNotNull()) { m_Controls.m_tabSettings->setEnabled(!m_Working); m_Controls.m_tabExecution->setEnabled(true); m_Controls.m_pbStartReg->setEnabled(m_ValidInputs && !m_Working); m_Controls.m_leRegJobName->setEnabled(!m_Working); m_Controls.m_checkMapEntity->setEnabled(!m_Working); m_Controls.m_checkStoreReg->setEnabled(!m_Working); const IStoppableAlgorithm* pIterativ = dynamic_cast (m_LoadedAlgorithm.GetPointer()); if (pIterativ) { m_Controls.m_pbStopReg->setVisible(pIterativ->isStoppable()); } typedef ::map::algorithm::facet::MaskedRegistrationAlgorithmInterface<3, 3> MaskRegInterface; const MaskRegInterface* pMaskReg = dynamic_cast (m_LoadedAlgorithm.GetPointer()); m_Controls.groupMasks->setVisible(pMaskReg != NULL); //if the stop button is set to visible and the algorithm is working -> //then the algorithm is stoppable, thus enable the button. m_Controls.m_pbStopReg->setEnabled(m_Controls.m_pbStopReg->isVisible() && m_Working); this->m_Controls.m_lbLoadedAlgorithmName->setText( QString::fromStdString(m_LoadedAlgorithm->getUID()->toStr())); } else { m_Controls.m_tabSettings->setEnabled(false); m_Controls.m_tabExecution->setEnabled(false); this->m_Controls.m_lbLoadedAlgorithmName->setText( QString("no algorithm loaded!")); m_Controls.groupMasks->setVisible(false); } if (!m_Working) { this->m_Controls.m_leRegJobName->setText(QString::fromStdString(this->GetDefaultRegJobName())); } } void QmitkMatchPoint::ConfigureProgressInfos() { const IIterativeAlgorithm* pIterative = dynamic_cast (m_LoadedAlgorithm.GetPointer()); const IMultiResAlgorithm* pMultiRes = dynamic_cast (m_LoadedAlgorithm.GetPointer()); m_Controls.m_progBarIteration->setVisible(pIterative); m_Controls.m_lbProgBarIteration->setVisible(pIterative); if (pIterative) { QString format = "%p% (%v/%m)"; if (!pIterative->hasMaxIterationCount()) { format = "%v"; m_Controls.m_progBarIteration->setMaximum(0); } else { m_Controls.m_progBarIteration->setMaximum(pIterative->getMaxIterations()); } m_Controls.m_progBarIteration->setFormat(format); } if (pMultiRes) { m_Controls.m_progBarLevel->setMaximum(pMultiRes->getResolutionLevels()); } else { m_Controls.m_progBarLevel->setMaximum(1); } m_Controls.m_progBarIteration->reset(); m_Controls.m_progBarLevel->reset(); } void QmitkMatchPoint::OnSelectionChanged(berry::IWorkbenchPart::Pointer /*source*/, const QList& nodes) { if (!m_Working) { CheckInputs(); ConfigureRegistrationControls(); } } void QmitkMatchPoint::OnStartRegBtnPushed() { this->m_Working = true; //////////////////////////////// //configure GUI this->ConfigureProgressInfos(); m_Controls.m_progBarIteration->reset(); m_Controls.m_progBarLevel->reset(); this->ConfigureRegistrationControls(); if (m_Controls.m_checkClearLog->checkState() == Qt::Checked) { this->m_Controls.m_teLog->clear(); } ///////////////////////// //create job and put it into the thread pool QmitkRegistrationJob* pJob = new QmitkRegistrationJob(m_LoadedAlgorithm); pJob->setAutoDelete(true); pJob->m_spTargetData = m_spSelectedTargetData; pJob->m_spMovingData = m_spSelectedMovingData; - pJob->m_TargetNodeUID = mitk::EnsureUID(this->m_spSelectedTargetNode); - pJob->m_MovingNodeUID = mitk::EnsureUID(this->m_spSelectedMovingNode); + pJob->m_TargetDataUID = mitk::EnsureUID(this->m_spSelectedTargetNode->GetData()); + pJob->m_MovingDataUID = mitk::EnsureUID(this->m_spSelectedMovingNode->GetData()); if (m_spSelectedTargetMaskData.IsNotNull()) { pJob->m_spTargetMask = m_spSelectedTargetMaskData; - pJob->m_TargetMaskNodeUID = mitk::EnsureUID(this->m_spSelectedTargetMaskNode); + pJob->m_TargetMaskDataUID = mitk::EnsureUID(this->m_spSelectedTargetMaskNode->GetData()); } if (m_spSelectedMovingMaskData.IsNotNull()) { pJob->m_spMovingMask = m_spSelectedMovingMaskData; - pJob->m_MovingMaskNodeUID = mitk::EnsureUID(this->m_spSelectedMovingMaskNode); + pJob->m_MovingMaskDataUID = mitk::EnsureUID(this->m_spSelectedMovingMaskNode->GetData()); } pJob->m_JobName = m_Controls.m_leRegJobName->text().toStdString(); pJob->m_StoreReg = m_Controls.m_checkStoreReg->checkState() == Qt::Checked; connect(pJob, SIGNAL(Error(QString)), this, SLOT(OnRegJobError(QString))); connect(pJob, SIGNAL(Finished()), this, SLOT(OnRegJobFinished())); connect(pJob, SIGNAL(RegResultIsAvailable(mitk::MAPRegistrationWrapper::Pointer, const QmitkRegistrationJob*)), this, SLOT(OnRegResultIsAvailable(mitk::MAPRegistrationWrapper::Pointer, const QmitkRegistrationJob*)), Qt::BlockingQueuedConnection); - connect(pJob, SIGNAL(MapResultNodeIsAvailable(mitk::BaseData::Pointer, const QmitkMappingJob*)), - this, SLOT(OnMapResultIsAvailable(mitk::BaseData::Pointer, const QmitkMappingJob*)), - Qt::BlockingQueuedConnection); connect(pJob, SIGNAL(AlgorithmInfo(QString)), this, SLOT(OnAlgorithmInfo(QString))); connect(pJob, SIGNAL(AlgorithmStatusChanged(QString)), this, SLOT(OnAlgorithmStatusChanged(QString))); connect(pJob, SIGNAL(AlgorithmIterated(QString, bool, unsigned long)), this, SLOT(OnAlgorithmIterated(QString, bool, unsigned long))); connect(pJob, SIGNAL(LevelChanged(QString, bool, unsigned long)), this, SLOT(OnLevelChanged(QString, bool, unsigned long))); QThreadPool* threadPool = QThreadPool::globalInstance(); threadPool->start(pJob); } void QmitkMatchPoint::OnStopRegBtnPushed() { if (m_LoadedAlgorithm.IsNotNull()) { IStoppableAlgorithm* pIterativ = dynamic_cast(m_LoadedAlgorithm.GetPointer()); if (pIterativ && pIterativ->isStoppable()) { if (pIterativ->stopAlgorithm()) { } else { } m_Controls.m_pbStopReg->setEnabled(false); } else { } } } void QmitkMatchPoint::OnSaveLogBtnPushed() { QDateTime currentTime = QDateTime::currentDateTime(); QString fileName = tr("registration_log_") + currentTime.toString(tr("yyyy-MM-dd_hh-mm-ss")) + tr(".txt"); fileName = QFileDialog::getSaveFileName(NULL, tr("Save registration log"), fileName, tr("Text files (*.txt)")); if (fileName.isEmpty()) { QMessageBox::critical(NULL, tr("No file selected!"), tr("Cannot save registration log file. Please selected a file.")); } else { std::ofstream file; std::ios_base::openmode iOpenFlag = std::ios_base::out | std::ios_base::trunc; file.open(fileName.toStdString().c_str(), iOpenFlag); if (!file.is_open()) { mitkThrow() << "Cannot open or create specified file to save. File path: " << fileName.toStdString(); } file << this->m_Controls.m_teLog->toPlainText().toStdString() << std::endl; file.close(); } } void QmitkMatchPoint::OnRegJobError(QString err) { Error(err); }; void QmitkMatchPoint::OnRegJobFinished() { this->m_Working = false; this->GetRenderWindowPart()->RequestUpdate(); this->CheckInputs(); this->ConfigureRegistrationControls(); this->ConfigureProgressInfos(); }; void QmitkMatchPoint::OnRegResultIsAvailable(mitk::MAPRegistrationWrapper::Pointer spResultRegistration, const QmitkRegistrationJob* pRegJob) { mitk::DataNode::Pointer spResultRegistrationNode = mitk::generateRegistrationResultNode( pRegJob->m_JobName, spResultRegistration, pRegJob->GetLoadedAlgorithm()->getUID()->toStr(), - pRegJob->m_MovingNodeUID, pRegJob->m_TargetNodeUID); + pRegJob->m_MovingDataUID, pRegJob->m_TargetDataUID); if (pRegJob->m_StoreReg) { m_Controls.m_teLog->append( QString(" Storing registration object in data manager ... ")); this->GetDataStorage()->Add(spResultRegistrationNode); this->GetRenderWindowPart()->RequestUpdate(); } if (m_Controls.m_checkMapEntity->checkState() == Qt::Checked) { QmitkMappingJob* pMapJob = new QmitkMappingJob(); pMapJob->setAutoDelete(true); pMapJob->m_spInputData = pRegJob->m_spMovingData; - pMapJob->m_InputNodeUID = pRegJob->m_MovingNodeUID; + pMapJob->m_InputDataUID = pRegJob->m_MovingDataUID; pMapJob->m_spRegNode = spResultRegistrationNode; pMapJob->m_doGeometryRefinement = false; pMapJob->m_spRefGeometry = pRegJob->m_spTargetData->GetGeometry()->Clone().GetPointer(); pMapJob->m_MappedName = pRegJob->m_JobName + std::string(" mapped moving data"); pMapJob->m_allowUndefPixels = true; pMapJob->m_paddingValue = 100; pMapJob->m_allowUnregPixels = true; pMapJob->m_errorValue = 200; pMapJob->m_InterpolatorLabel = "Linear Interpolation"; pMapJob->m_InterpolatorType = mitk::ImageMappingInterpolator::Linear; connect(pMapJob, SIGNAL(Error(QString)), this, SLOT(OnMapJobError(QString))); connect(pMapJob, SIGNAL(MapResultIsAvailable(mitk::BaseData::Pointer, const QmitkMappingJob*)), this, SLOT(OnMapResultIsAvailable(mitk::BaseData::Pointer, const QmitkMappingJob*)), Qt::BlockingQueuedConnection); connect(pMapJob, SIGNAL(AlgorithmInfo(QString)), this, SLOT(OnAlgorithmInfo(QString))); m_Controls.m_teLog->append( QString("Started mapping input data...")); QThreadPool* threadPool = QThreadPool::globalInstance(); threadPool->start(pMapJob); } }; void QmitkMatchPoint::OnMapJobError(QString err) { Error(err); }; void QmitkMatchPoint::OnMapResultIsAvailable(mitk::BaseData::Pointer spMappedData, const QmitkMappingJob* job) { m_Controls.m_teLog->append(QString("Mapped entity stored. Name: ") + QString::fromStdString(job->m_MappedName) + QString("")); mitk::DataNode::Pointer spMappedNode = mitk::generateMappedResultNode(job->m_MappedName, - spMappedData, job->GetRegistration()->getRegistrationUID(), job->m_InputNodeUID, + spMappedData, job->GetRegistration()->getRegistrationUID(), job->m_InputDataUID, job->m_doGeometryRefinement, job->m_InterpolatorLabel); this->GetDataStorage()->Add(spMappedNode); this->GetRenderWindowPart()->RequestUpdate(); }; void QmitkMatchPoint::OnAlgorithmIterated(QString info, bool hasIterationCount, unsigned long currentIteration) { if (hasIterationCount) { m_Controls.m_progBarIteration->setValue(currentIteration); } m_Controls.m_teLog->append(info); }; void QmitkMatchPoint::OnLevelChanged(QString info, bool hasLevelCount, unsigned long currentLevel) { if (hasLevelCount) { m_Controls.m_progBarLevel->setValue(currentLevel); } m_Controls.m_teLog->append(QString("") + info + QString("")); }; void QmitkMatchPoint::OnAlgorithmStatusChanged(QString info) { m_Controls.m_teLog->append(QString("") + info + QString(" ")); }; void QmitkMatchPoint::OnAlgorithmInfo(QString info) { m_Controls.m_teLog->append(QString("") + info + QString("")); }; void QmitkMatchPoint::OnAlgorithmSelectionChanged(const berry::IWorkbenchPart::Pointer& sourcepart, const berry::ISelection::ConstPointer& selection) { // check for null selection if (selection.IsNull()) { return; } if (sourcepart != this) { UpdateAlgorithmSelection(selection); } } void QmitkMatchPoint::UpdateAlgorithmSelection(berry::ISelection::ConstPointer selection) { mitk::MAPAlgorithmInfoSelection::ConstPointer currentSelection = selection.Cast(); if (currentSelection) { mitk::MAPAlgorithmInfoSelection::AlgorithmInfoVectorType infoVector = currentSelection->GetSelectedAlgorithmInfo(); if (!infoVector.empty()) { // only the first selection is of interest, the rest will be skipped. this->m_SelectedAlgorithmInfo = infoVector[0]; } } this->OnSelectedAlgorithmChanged(); }; diff --git a/Plugins/org.mitk.gui.qt.matchpoint.evaluator/src/internal/QmitkMatchPointRegistrationEvaluator.cpp b/Plugins/org.mitk.gui.qt.matchpoint.evaluator/src/internal/QmitkMatchPointRegistrationEvaluator.cpp index e70b85a35d..8589869c1c 100644 --- a/Plugins/org.mitk.gui.qt.matchpoint.evaluator/src/internal/QmitkMatchPointRegistrationEvaluator.cpp +++ b/Plugins/org.mitk.gui.qt.matchpoint.evaluator/src/internal/QmitkMatchPointRegistrationEvaluator.cpp @@ -1,331 +1,331 @@ /*=================================================================== 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. ===================================================================*/ // Blueberry #include #include // Mitk #include -#include +#include #include #include #include "mitkRegVisPropertyTags.h" #include "mitkMatchPointPropertyTags.h" #include "mitkRegEvaluationObject.h" #include "mitkRegistrationHelper.h" #include "mitkRegEvaluationMapper2D.h" #include // Qmitk #include "QmitkRenderWindow.h" #include "QmitkMatchPointRegistrationEvaluator.h" // Qt #include #include #include const std::string QmitkMatchPointRegistrationEvaluator::VIEW_ID = "org.mitk.views.matchpoint.registration.evaluator"; QmitkMatchPointRegistrationEvaluator::QmitkMatchPointRegistrationEvaluator() : m_Parent(NULL), m_activeEvaluation(false), m_autoMoving(false), m_autoTarget(false), m_currentSelectedTimeStep(0), HelperNodeName("RegistrationEvaluationHelper") { m_currentSelectedPosition.Fill(0.0); } QmitkMatchPointRegistrationEvaluator::~QmitkMatchPointRegistrationEvaluator() { if (this->m_selectedEvalNode.IsNotNull() && this->GetDataStorage().IsNotNull()) { this->GetDataStorage()->Remove(this->m_selectedEvalNode); } } void QmitkMatchPointRegistrationEvaluator::SetFocus() { } void QmitkMatchPointRegistrationEvaluator::Error(QString msg) { mitk::StatusBar::GetInstance()->DisplayErrorText(msg.toLatin1()); MITK_ERROR << msg.toStdString().c_str(); } void QmitkMatchPointRegistrationEvaluator::CreateQtPartControl(QWidget* parent) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi(parent); m_Parent = parent; connect(m_Controls.pbEval, SIGNAL(clicked()), this, SLOT(OnEvalBtnPushed())); connect(m_Controls.pbStop, SIGNAL(clicked()), this, SLOT(OnStopBtnPushed())); connect(m_Controls.evalSettings, SIGNAL(SettingsChanged(mitk::DataNode*)), this, SLOT(OnSettingsChanged(mitk::DataNode*))); this->m_SliceChangeListener.RenderWindowPartActivated(this->GetRenderWindowPart()); connect(&m_SliceChangeListener, SIGNAL(SliceChanged()), this, SLOT(OnSliceChanged())); m_selectedEvalNode = this->GetDataStorage()->GetNamedNode(HelperNodeName); this->CheckInputs(); this->ConfigureControls(); } void QmitkMatchPointRegistrationEvaluator::RenderWindowPartActivated(mitk::IRenderWindowPart* renderWindowPart) { this->m_SliceChangeListener.RenderWindowPartActivated(renderWindowPart); } void QmitkMatchPointRegistrationEvaluator::RenderWindowPartDeactivated( mitk::IRenderWindowPart* renderWindowPart) { this->m_SliceChangeListener.RenderWindowPartDeactivated(renderWindowPart); } void QmitkMatchPointRegistrationEvaluator::CheckInputs() { if (!m_activeEvaluation) { QList dataNodes = this->GetDataManagerSelection(); this->m_autoMoving = false; this->m_autoTarget = false; this->m_spSelectedMovingNode = NULL; this->m_spSelectedTargetNode = NULL; this->m_spSelectedRegNode = NULL; if (dataNodes.size() > 0) { //test if auto select works - if (mitk::MITKRegistrationHelper::IsRegNode(dataNodes[0])) + if (mitk::MITKRegistrationHelper::IsRegNode(dataNodes[0]) && dataNodes[0]->GetData()) { this->m_spSelectedRegNode = dataNodes[0]; dataNodes.pop_front(); - mitk::BaseProperty* uidProp = m_spSelectedRegNode->GetProperty(mitk::nodeProp_RegAlgMovingData); + mitk::BaseProperty* uidProp = m_spSelectedRegNode->GetData()->GetProperty(mitk::Prop_RegAlgMovingData); if (uidProp) { //search for the moving node - mitk::NodePredicateProperty::Pointer predicate = mitk::NodePredicateProperty::New(mitk::nodeProp_UID, + mitk::NodePredicateDataProperty::Pointer predicate = mitk::NodePredicateDataProperty::New(mitk::Prop_UID, uidProp); this->m_spSelectedMovingNode = this->GetDataStorage()->GetNode(predicate); this->m_autoMoving = this->m_spSelectedMovingNode.IsNotNull(); } - uidProp = m_spSelectedRegNode->GetProperty(mitk::nodeProp_RegAlgTargetData); + uidProp = m_spSelectedRegNode->GetData()->GetProperty(mitk::Prop_RegAlgTargetData); if (uidProp) { //search for the target node - mitk::NodePredicateProperty::Pointer predicate = mitk::NodePredicateProperty::New(mitk::nodeProp_UID, + mitk::NodePredicateDataProperty::Pointer predicate = mitk::NodePredicateDataProperty::New(mitk::Prop_UID, uidProp); this->m_spSelectedTargetNode = this->GetDataStorage()->GetNode(predicate); this->m_autoTarget = this->m_spSelectedTargetNode.IsNotNull(); } } //if still nodes are selected -> ignore possible auto select if (!dataNodes.empty()) { mitk::Image* inputImage = dynamic_cast(dataNodes[0]->GetData()); if (inputImage) { this->m_spSelectedMovingNode = dataNodes[0]; this->m_autoMoving = false; dataNodes.pop_front(); } } if (!dataNodes.empty()) { mitk::Image* inputImage = dynamic_cast(dataNodes[0]->GetData()); if (inputImage) { this->m_spSelectedTargetNode = dataNodes[0]; this->m_autoTarget = false; dataNodes.pop_front(); } } } } } void QmitkMatchPointRegistrationEvaluator::OnSelectionChanged(berry::IWorkbenchPart::Pointer source, const QList& nodes) { this->CheckInputs(); this->ConfigureControls(); }; void QmitkMatchPointRegistrationEvaluator::ConfigureControls() { //configure input data widgets if (this->m_spSelectedRegNode.IsNull()) { if (this->m_spSelectedMovingNode.IsNotNull() && this->m_spSelectedTargetNode.IsNotNull()) { m_Controls.lbRegistrationName->setText( QString("No registration selected! Direct comparison")); } else { m_Controls.lbRegistrationName->setText( QString("No registration selected!")); } } else { m_Controls.lbRegistrationName->setText(QString::fromStdString( this->m_spSelectedRegNode->GetName())); } if (this->m_spSelectedMovingNode.IsNull()) { m_Controls.lbMovingName->setText(QString("no moving image selected!")); } else { if (this->m_autoMoving) { m_Controls.lbMovingName->setText(QString("") + QString::fromStdString( this->m_spSelectedMovingNode->GetName()) + QString(" (auto selected)")); } else { m_Controls.lbMovingName->setText(QString::fromStdString(this->m_spSelectedMovingNode->GetName())); } } if (this->m_spSelectedTargetNode.IsNull()) { m_Controls.lbTargetName->setText(QString("no target image selected!")); } else { if (this->m_autoTarget) { m_Controls.lbTargetName->setText(QString("") + QString::fromStdString( this->m_spSelectedTargetNode->GetName()) + QString(" (auto selected)")); } else { m_Controls.lbTargetName->setText(QString::fromStdString(this->m_spSelectedTargetNode->GetName())); } } //config settings widget this->m_Controls.evalSettings->setVisible(m_activeEvaluation); this->m_Controls.pbEval->setEnabled(this->m_spSelectedMovingNode.IsNotNull() && this->m_spSelectedTargetNode.IsNotNull()); this->m_Controls.pbEval->setVisible(!m_activeEvaluation); this->m_Controls.pbStop->setVisible(m_activeEvaluation); this->m_Controls.lbMovingName->setEnabled(!m_activeEvaluation); this->m_Controls.lbRegistrationName->setEnabled(!m_activeEvaluation); this->m_Controls.lbTargetName->setEnabled(!m_activeEvaluation); } void QmitkMatchPointRegistrationEvaluator::OnSliceChanged() { mitk::Point3D currentSelectedPosition = GetRenderWindowPart()->GetSelectedPosition(NULL); unsigned int currentSelectedTimeStep = GetRenderWindowPart()->GetTimeNavigationController()->GetTime()->GetPos(); if (m_currentSelectedPosition != currentSelectedPosition || m_currentSelectedTimeStep != currentSelectedTimeStep || m_selectedNodeTime > m_currentPositionTime) { //the current position has been changed or the selected node has been changed since the last position validation -> check position m_currentSelectedPosition = currentSelectedPosition; m_currentSelectedTimeStep = currentSelectedTimeStep; m_currentPositionTime.Modified(); if (this->m_selectedEvalNode.IsNotNull()) { this->m_selectedEvalNode->SetProperty(mitk::nodeProp_RegEvalCurrentPosition, mitk::GenericProperty::New(currentSelectedPosition)); } } } void QmitkMatchPointRegistrationEvaluator::OnSettingsChanged(mitk::DataNode*) { this->GetRenderWindowPart()->RequestUpdate(); }; void QmitkMatchPointRegistrationEvaluator::OnEvalBtnPushed() { //reinit view mitk::RenderingManager::GetInstance()->InitializeViews(m_spSelectedTargetNode->GetData()->GetTimeSlicedGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true); mitk::RegEvaluationObject::Pointer regEval = mitk::RegEvaluationObject::New(); mitk::MAPRegistrationWrapper::Pointer reg; if (m_spSelectedRegNode.IsNotNull()) { reg = dynamic_cast(this->m_spSelectedRegNode->GetData()); } else { //generate a dymme reg to use reg = mitk::GenerateIdentityRegistration3D(); } regEval->SetRegistration(reg); regEval->SetTargetNode(this->m_spSelectedTargetNode); regEval->SetMovingNode(this->m_spSelectedMovingNode); if (this->m_selectedEvalNode.IsNotNull()) { this->GetDataStorage()->Remove(this->m_selectedEvalNode); } this->m_selectedEvalNode = mitk::DataNode::New(); this->m_selectedEvalNode->SetData(regEval); mitk::RegEvaluationMapper2D::SetDefaultProperties(this->m_selectedEvalNode); this->m_selectedEvalNode->SetName(HelperNodeName); this->m_selectedEvalNode->SetBoolProperty("helper object", true); this->GetDataStorage()->Add(this->m_selectedEvalNode); this->m_Controls.evalSettings->SetNode(this->m_selectedEvalNode); this->OnSliceChanged(); this->GetRenderWindowPart()->RequestUpdate(); this->m_activeEvaluation = true; this->CheckInputs(); this->ConfigureControls(); } void QmitkMatchPointRegistrationEvaluator::OnStopBtnPushed() { this->m_activeEvaluation = false; this->GetDataStorage()->Remove(this->m_selectedEvalNode); this->m_selectedEvalNode = nullptr; this->m_Controls.evalSettings->SetNode(this->m_selectedEvalNode); this->CheckInputs(); this->ConfigureControls(); this->GetRenderWindowPart()->RequestUpdate(); } \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.matchpoint.framereg/src/internal/QmitkMatchPointFrameCorrection.cpp b/Plugins/org.mitk.gui.qt.matchpoint.framereg/src/internal/QmitkMatchPointFrameCorrection.cpp index 680480ae60..d13b88d10a 100644 --- a/Plugins/org.mitk.gui.qt.matchpoint.framereg/src/internal/QmitkMatchPointFrameCorrection.cpp +++ b/Plugins/org.mitk.gui.qt.matchpoint.framereg/src/internal/QmitkMatchPointFrameCorrection.cpp @@ -1,820 +1,820 @@ /*=================================================================== 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 "org_mitk_gui_qt_matchpoint_framereg_Activator.h" // Blueberry #include #include #include #include // Mitk #include #include #include #include #include #include #include #include #include #include // Qmitk #include "QmitkMatchPointFrameCorrection.h" #include #include // Qt #include #include #include #include #include // MatchPoint #include #include #include #include #include #include #include #include #include const std::string QmitkMatchPointFrameCorrection::VIEW_ID = "org.mitk.views.matchpoint.algorithm.framereg"; QmitkMatchPointFrameCorrection::QmitkMatchPointFrameCorrection() : m_Parent(NULL), m_LoadedDLLHandle(NULL), m_LoadedAlgorithm(NULL), m_CanLoadAlgorithm(false), m_ValidInputs(false), m_Working(false) { m_spSelectedTargetData = NULL; m_spSelectedTargetMaskData = NULL; } QmitkMatchPointFrameCorrection::~QmitkMatchPointFrameCorrection() { // remove selection service berry::ISelectionService* s = this->GetSite()->GetWorkbenchWindow()->GetSelectionService(); if (s) { s->RemoveSelectionListener(m_AlgorithmSelectionListener.data()); } } void QmitkMatchPointFrameCorrection::SetFocus() { } void QmitkMatchPointFrameCorrection::CreateConnections() { connect(m_Controls.checkTargetMask, SIGNAL(toggled(bool)), this, SLOT(OnMaskCheckBoxToggeled(bool))); // ------ // Tab 1 - Shared library loading interface // ------ connect(m_Controls.m_pbLoadSelected, SIGNAL(clicked()), this, SLOT(OnLoadAlgorithmButtonPushed())); // ----- // Tab 2 - Execution // ----- connect(m_Controls.m_pbStartReg, SIGNAL(clicked()), this, SLOT(OnStartRegBtnPushed())); connect(m_Controls.m_pbSaveLog, SIGNAL(clicked()), this, SLOT(OnSaveLogBtnPushed())); // ----- // Tab 4 - Frames // ----- connect(m_Controls.m_btnFrameSelAll, SIGNAL(clicked()), this, SLOT(OnFramesSelectAllPushed())); connect(m_Controls.m_btnFrameDeSelAll, SIGNAL(clicked()), this, SLOT(OnFramesDeSelectAllPushed())); connect(m_Controls.m_btnFrameInvert, SIGNAL(clicked()), this, SLOT(OnFramesInvertPushed())); } const map::deployment::DLLInfo* QmitkMatchPointFrameCorrection::GetSelectedAlgorithmDLL() const { return m_SelectedAlgorithmInfo; } void QmitkMatchPointFrameCorrection::OnMaskCheckBoxToggeled(bool checked) { if (!m_Working) { CheckInputs(); ConfigureRegistrationControls(); } }; void QmitkMatchPointFrameCorrection::OnSelectedAlgorithmChanged() { std::stringstream descriptionString; ::map::deployment::DLLInfo::ConstPointer currentItemInfo = GetSelectedAlgorithmDLL(); if (!currentItemInfo) { return; } m_Controls.m_teAlgorithmDetails->updateInfo(currentItemInfo); m_Controls.m_lbSelectedAlgorithm->setText(QString::fromStdString( currentItemInfo->getAlgorithmUID().getName())); // enable loading m_CanLoadAlgorithm = true; this->AdaptFolderGUIElements(); } void QmitkMatchPointFrameCorrection::OnLoadAlgorithmButtonPushed() { map::deployment::DLLInfo::ConstPointer dllInfo = GetSelectedAlgorithmDLL(); if (!dllInfo) { Error(QString("No valid algorithm is selected. Cannot load algorithm. ABORTING.")); return; } ::map::deployment::DLLHandle::Pointer tempDLLHandle = ::map::deployment::openDeploymentDLL( dllInfo->getLibraryFilePath()); ::map::algorithm::RegistrationAlgorithmBase::Pointer tempAlgorithm = ::map::deployment::getRegistrationAlgorithm(tempDLLHandle); if (tempAlgorithm.IsNull()) { Error(QString("Error. Cannot load selected algorithm.")); return; } this->m_LoadedAlgorithm = tempAlgorithm; this->m_LoadedDLLHandle = tempDLLHandle; this->m_Controls.m_AlgoConfigurator->setAlgorithm(m_LoadedAlgorithm); m_Controls.checkTargetMask->setChecked(false); this->AdaptFolderGUIElements(); this->CheckInputs(); this->ConfigureRegistrationControls(); this->ConfigureProgressInfos(); this->m_Controls.m_tabs->setCurrentIndex(1); } void QmitkMatchPointFrameCorrection::Error(QString msg) { mitk::StatusBar::GetInstance()->DisplayErrorText(msg.toLatin1()); MITK_ERROR << msg.toStdString().c_str(); m_Controls.m_teLog->append(QString("") + msg + QString("")); } void QmitkMatchPointFrameCorrection::AdaptFolderGUIElements() { m_Controls.m_pbLoadSelected->setEnabled(m_CanLoadAlgorithm); } void QmitkMatchPointFrameCorrection::CreateQtPartControl(QWidget* parent) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi(parent); m_Parent = parent; m_Controls.checkTargetMask->setChecked(false); m_Controls.m_tabs->setCurrentIndex(0); m_Controls.m_mapperSettings->AllowSampling(false); m_AlgorithmSelectionListener.reset(new berry::SelectionChangedAdapter(this, &QmitkMatchPointFrameCorrection::OnAlgorithmSelectionChanged)); // register selection listener GetSite()->GetWorkbenchWindow()->GetSelectionService()->AddSelectionListener( m_AlgorithmSelectionListener.data()); this->CreateConnections(); this->AdaptFolderGUIElements(); this->CheckInputs(); this->ConfigureProgressInfos(); this->ConfigureRegistrationControls(); berry::ISelection::ConstPointer selection = GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection("org.mitk.views.matchpoint.algorithm.browser"); this->UpdateAlgorithmSelection(selection); } bool QmitkMatchPointFrameCorrection::CheckInputs() { bool validTarget = false; bool validTargetMask = false; mitk::DataNode::Pointer oldTargetNode = m_spSelectedTargetNode; mitk::NodePredicateDataType::Pointer isLabelSet = mitk::NodePredicateDataType::New("LabelSetImage"); mitk::NodePredicateDataType::Pointer isImage = mitk::NodePredicateDataType::New("Image"); mitk::NodePredicateProperty::Pointer isBinary = mitk::NodePredicateProperty::New("binary", mitk::BoolProperty::New(true)); mitk::NodePredicateAnd::Pointer isLegacyMask = mitk::NodePredicateAnd::New(isImage, isBinary); mitk::NodePredicateOr::Pointer maskPredicate = mitk::NodePredicateOr::New(isLegacyMask, isLabelSet); if (m_LoadedAlgorithm.IsNull()) { m_Controls.m_lbLoadedAlgorithmName->setText( QString("No algorithm seleted!")); m_spSelectedTargetNode = NULL; m_spSelectedTargetData = NULL; m_spSelectedTargetMaskNode = NULL; m_spSelectedTargetMaskData = NULL; } else { QList nodes = this->GetDataManagerSelection(); mitk::Image* targetImage = NULL; mitk::PointSet* targetPointSet = NULL; mitk::Image* targetMaskImage = NULL; typedef ::map::algorithm::facet::MaskedRegistrationAlgorithmInterface<3, 3> MaskRegInterface; MaskRegInterface* pMaskInterface = dynamic_cast(m_LoadedAlgorithm.GetPointer()); if (nodes.count() < 1) { m_Controls.m_lbTargetName->setText(QString("no data selected!")); m_spSelectedTargetNode = NULL; m_spSelectedTargetData = NULL; } else { m_spSelectedTargetNode = nodes.front(); m_spSelectedTargetData = m_spSelectedTargetNode->GetData(); targetImage = dynamic_cast(m_spSelectedTargetNode->GetData()); if (targetImage) { if (targetImage->GetTimeSteps() < 1) { m_Controls.m_lbTargetName->setText(QString("Image has no mulitple time steps")); } else if (targetImage->GetDimension() != m_LoadedAlgorithm->getTargetDimensions() + 1) { m_Controls.m_lbTargetName->setText(QString("wrong image dimension. ") + QString::number(m_LoadedAlgorithm->getTargetDimensions()) + QString("D+t needed")); } else { validTarget = true; } } else { m_Controls.m_lbTargetName->setText(QString("no supported data selected!")); } nodes.removeFirst(); } if (m_Controls.checkTargetMask->isChecked()) { if (nodes.count() < 1) { m_Controls.m_lbTargetMaskName->setText(QString("no data selected!")); m_spSelectedTargetMaskNode = NULL; m_spSelectedTargetMaskData = NULL; } else { m_spSelectedTargetMaskNode = nodes.front(); m_spSelectedTargetMaskData = NULL; targetMaskImage = dynamic_cast(m_spSelectedTargetMaskNode->GetData()); bool isMask = maskPredicate->CheckNode(m_spSelectedTargetMaskNode); if (!isMask) { m_Controls.m_lbTargetMaskName->setText(QString("no mask selected!")); } else if (targetMaskImage && pMaskInterface) { m_spSelectedTargetMaskData = targetMaskImage; validTargetMask = true; } else { m_Controls.m_lbTargetMaskName->setText( QString("no supported data selected!")); } } } else { m_Controls.m_lbTargetMaskName->setText(QString("mask deactivated")); validTargetMask = true; m_spSelectedTargetMaskNode = NULL; m_spSelectedTargetMaskData = NULL; } } if (validTarget) { m_Controls.m_lbTargetName->setText(QString::fromStdString(GetInputNodeDisplayName( m_spSelectedTargetNode))); if (oldTargetNode != m_spSelectedTargetNode) { ConfigureFrameList(); } } else { m_Controls.m_listFrames->clear(); } if (validTargetMask && m_Controls.checkTargetMask->isChecked()) { m_Controls.m_lbTargetMaskName->setText(QString::fromStdString(GetInputNodeDisplayName( m_spSelectedTargetMaskNode))); } m_ValidInputs = validTarget && validTargetMask; return m_ValidInputs; } std::string QmitkMatchPointFrameCorrection::GetInputNodeDisplayName(const mitk::DataNode* node) const { std::string result = "UNDEFINED/NULL"; if (node) { result = node->GetName(); const mitk::PointSet* pointSet = dynamic_cast(node->GetData()); if (pointSet) { mitk::DataStorage::SetOfObjects::ConstPointer sources = this->GetDataStorage()->GetSources(node); if (sources.IsNotNull() && sources->Size() > 0) { result = result + " (" + sources->GetElement(0)->GetName() + ")"; } } } return result; } mitk::DataStorage::SetOfObjects::Pointer QmitkMatchPointFrameCorrection::GetRegNodes() const { mitk::DataStorage::SetOfObjects::ConstPointer nodes = this->GetDataStorage()->GetAll(); mitk::DataStorage::SetOfObjects::Pointer result = mitk::DataStorage::SetOfObjects::New(); for (mitk::DataStorage::SetOfObjects::const_iterator pos = nodes->begin(); pos != nodes->end(); ++pos) { if (mitk::MITKRegistrationHelper::IsRegNode(*pos)) { result->push_back(*pos); } } return result; } std::string QmitkMatchPointFrameCorrection::GetDefaultJobName() const { mitk::DataStorage::SetOfObjects::ConstPointer nodes = this->GetRegNodes().GetPointer(); mitk::DataStorage::SetOfObjects::ElementIdentifier newIndex = 0; bool isUnique = false; std::string baseName = "corrected #"; if (m_spSelectedTargetNode.IsNotNull()) { baseName = m_spSelectedTargetNode->GetName() + "corrected #"; } std::string result = baseName; while (!isUnique) { ++newIndex; result = baseName + ::map::core::convert::toStr(newIndex); isUnique = this->GetDataStorage()->GetNamedNode(result) == NULL; } return result; } void QmitkMatchPointFrameCorrection::ConfigureRegistrationControls() { m_Controls.m_tabSelection->setEnabled(!m_Working); m_Controls.m_leRegJobName->setEnabled(!m_Working); m_Controls.groupMasks->setEnabled(!m_Working); m_Controls.m_pbStartReg->setEnabled(false); m_Controls.m_lbTargetMaskName->setVisible(m_Controls.checkTargetMask->isChecked()); if (m_LoadedAlgorithm.IsNotNull()) { m_Controls.m_tabSettings->setEnabled(!m_Working); m_Controls.m_tabExclusion->setEnabled(!m_Working); m_Controls.m_tabExecution->setEnabled(true); m_Controls.m_pbStartReg->setEnabled(m_ValidInputs && !m_Working); m_Controls.m_leRegJobName->setEnabled(!m_Working); typedef ::map::algorithm::facet::MaskedRegistrationAlgorithmInterface<3, 3> MaskRegInterface; const MaskRegInterface* pMaskReg = dynamic_cast (m_LoadedAlgorithm.GetPointer()); m_Controls.groupMasks->setVisible(pMaskReg != NULL); this->m_Controls.m_lbLoadedAlgorithmName->setText( QString::fromStdString(m_LoadedAlgorithm->getUID()->toStr())); } else { m_Controls.m_tabSettings->setEnabled(false); m_Controls.m_tabExclusion->setEnabled(false); m_Controls.m_tabExecution->setEnabled(false); this->m_Controls.m_lbLoadedAlgorithmName->setText( QString("no algorithm loaded!")); m_Controls.groupMasks->setVisible(false); } if (!m_Working) { this->m_Controls.m_leRegJobName->setText(QString::fromStdString(this->GetDefaultJobName())); } } void QmitkMatchPointFrameCorrection::ConfigureProgressInfos() { const IIterativeAlgorithm* pIterative = dynamic_cast (m_LoadedAlgorithm.GetPointer()); const IMultiResAlgorithm* pMultiRes = dynamic_cast (m_LoadedAlgorithm.GetPointer()); m_Controls.m_progBarIteration->setVisible(pIterative); m_Controls.m_lbProgBarIteration->setVisible(pIterative); if (pIterative) { QString format = "%p% (%v/%m)"; if (!pIterative->hasMaxIterationCount()) { format = "%v"; m_Controls.m_progBarIteration->setMaximum(0); } else { m_Controls.m_progBarIteration->setMaximum(pIterative->getMaxIterations()); } m_Controls.m_progBarIteration->setFormat(format); } if (pMultiRes) { m_Controls.m_progBarLevel->setMaximum(pMultiRes->getResolutionLevels()); } else { m_Controls.m_progBarLevel->setMaximum(1); } m_Controls.m_progBarIteration->reset(); m_Controls.m_progBarLevel->reset(); m_Controls.m_progBarFrame->reset(); } void QmitkMatchPointFrameCorrection::ConfigureFrameList() { m_Controls.m_listFrames->clear(); if (m_spSelectedTargetData.IsNotNull()) { mitk::TimeGeometry::ConstPointer tg = m_spSelectedTargetData->GetTimeGeometry(); for (unsigned int i = 1; i < tg->CountTimeSteps(); ++i) { QString lable = "Timepoint #" + QString::number(i) + QString(" (") + QString::number( tg->GetMinimumTimePoint(i)) + QString(" ms - " + QString::number(tg->GetMaximumTimePoint( i)) + QString(" ms)")); QListWidgetItem* item = new QListWidgetItem(lable, m_Controls.m_listFrames); item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); item->setCheckState(Qt::Checked); } } } void QmitkMatchPointFrameCorrection::OnFramesSelectAllPushed() { for (unsigned int row = 0; row < m_Controls.m_listFrames->count(); row++) { QListWidgetItem* item = m_Controls.m_listFrames->item(row); item->setCheckState(Qt::Checked); } }; void QmitkMatchPointFrameCorrection::OnFramesDeSelectAllPushed() { for (unsigned int row = 0; row < m_Controls.m_listFrames->count(); row++) { QListWidgetItem* item = m_Controls.m_listFrames->item(row); item->setCheckState(Qt::Unchecked); } }; void QmitkMatchPointFrameCorrection::OnFramesInvertPushed() { for (unsigned int row = 0; row < m_Controls.m_listFrames->count(); row++) { QListWidgetItem* item = m_Controls.m_listFrames->item(row); if (item->checkState() == Qt::Unchecked) { item->setCheckState(Qt::Checked); } else { item->setCheckState(Qt::Unchecked); } } }; mitk::TimeFramesRegistrationHelper::IgnoreListType QmitkMatchPointFrameCorrection::GenerateIgnoreList() const { mitk::TimeFramesRegistrationHelper::IgnoreListType result; for (unsigned int row = 0; row < m_Controls.m_listFrames->count(); row++) { QListWidgetItem* item = m_Controls.m_listFrames->item(row); if (item->checkState() == Qt::Unchecked) { result.push_back(row + 1); } } return result; } void QmitkMatchPointFrameCorrection::OnSelectionChanged(berry::IWorkbenchPart::Pointer /*source*/, const QList& nodes) { if (!m_Working) { CheckInputs(); ConfigureRegistrationControls(); } } void QmitkMatchPointFrameCorrection::OnStartRegBtnPushed() { this->m_Working = true; //////////////////////////////// //configure GUI this->ConfigureProgressInfos(); m_Controls.m_progBarIteration->reset(); m_Controls.m_progBarLevel->reset(); this->ConfigureRegistrationControls(); if (m_Controls.m_checkClearLog->checkState() == Qt::Checked) { this->m_Controls.m_teLog->clear(); } ///////////////////////// //create job and put it into the thread pool QmitkFramesRegistrationJob* pJob = new QmitkFramesRegistrationJob(m_LoadedAlgorithm); pJob->setAutoDelete(true); pJob->m_spTargetData = m_spSelectedTargetData; - pJob->m_TargetNodeUID = mitk::EnsureUID(this->m_spSelectedTargetNode); + pJob->m_TargetDataUID = mitk::EnsureUID(this->m_spSelectedTargetNode->GetData()); pJob->m_IgnoreList = this->GenerateIgnoreList(); if (m_spSelectedTargetMaskData.IsNotNull()) { pJob->m_spTargetMask = m_spSelectedTargetMaskData; - pJob->m_TargetMaskNodeUID = mitk::EnsureUID(this->m_spSelectedTargetMaskNode); + pJob->m_TargetMaskDataUID = mitk::EnsureUID(this->m_spSelectedTargetMaskNode->GetData()); } pJob->m_MappedName = m_Controls.m_leRegJobName->text().toStdString(); m_Controls.m_mapperSettings->ConfigureJobSettings(pJob); connect(pJob, SIGNAL(Error(QString)), this, SLOT(OnRegJobError(QString))); connect(pJob, SIGNAL(Finished()), this, SLOT(OnRegJobFinished())); connect(pJob, SIGNAL(ResultIsAvailable(mitk::Image::Pointer, const QmitkFramesRegistrationJob*)), this, SLOT(OnMapResultIsAvailable(mitk::Image::Pointer, const QmitkFramesRegistrationJob*)), Qt::BlockingQueuedConnection); connect(pJob, SIGNAL(AlgorithmInfo(QString)), this, SLOT(OnAlgorithmInfo(QString))); connect(pJob, SIGNAL(AlgorithmStatusChanged(QString)), this, SLOT(OnAlgorithmStatusChanged(QString))); connect(pJob, SIGNAL(AlgorithmIterated(QString, bool, unsigned long)), this, SLOT(OnAlgorithmIterated(QString, bool, unsigned long))); connect(pJob, SIGNAL(LevelChanged(QString, bool, unsigned long)), this, SLOT(OnLevelChanged(QString, bool, unsigned long))); connect(pJob, SIGNAL(FrameRegistered(double)), this, SLOT(OnFrameRegistered(double))); connect(pJob, SIGNAL(FrameMapped(double)), this, SLOT(OnFrameMapped(double))); connect(pJob, SIGNAL(FrameProcessed(double)), this, SLOT(OnFrameProcessed(double))); QThreadPool* threadPool = QThreadPool::globalInstance(); threadPool->start(pJob); } void QmitkMatchPointFrameCorrection::OnSaveLogBtnPushed() { QDateTime currentTime = QDateTime::currentDateTime(); QString fileName = tr("registration_log_") + currentTime.toString(tr("yyyy-MM-dd_hh-mm-ss")) + tr(".txt"); fileName = QFileDialog::getSaveFileName(NULL, tr("Save registration log"), fileName, tr("Text files (*.txt)")); if (fileName.isEmpty()) { QMessageBox::critical(NULL, tr("No file selected!"), tr("Cannot save registration log file. Please selected a file.")); } else { std::ofstream file; std::ios_base::openmode iOpenFlag = std::ios_base::out | std::ios_base::trunc; file.open(fileName.toStdString().c_str(), iOpenFlag); if (!file.is_open()) { mitkThrow() << "Cannot open or create specified file to save. File path: " << fileName.toStdString(); } file << this->m_Controls.m_teLog->toPlainText().toStdString() << std::endl; file.close(); } } void QmitkMatchPointFrameCorrection::OnRegJobError(QString err) { Error(err); }; void QmitkMatchPointFrameCorrection::OnRegJobFinished() { this->m_Working = false; this->GetRenderWindowPart()->RequestUpdate(); this->CheckInputs(); this->ConfigureRegistrationControls(); this->ConfigureProgressInfos(); }; void QmitkMatchPointFrameCorrection::OnMapResultIsAvailable(mitk::Image::Pointer spMappedData, const QmitkFramesRegistrationJob* job) { m_Controls.m_teLog->append(QString("Corrected image stored. Name: ") + QString::fromStdString(job->m_MappedName) + QString("")); mitk::DataNode::Pointer spResultNode = mitk::generateMappedResultNode(job->m_MappedName, - spMappedData.GetPointer(), "", job->m_TargetNodeUID, false, job->m_InterpolatorLabel); + spMappedData.GetPointer(), "", job->m_TargetDataUID, false, job->m_InterpolatorLabel); this->GetDataStorage()->Add(spResultNode, this->m_spSelectedTargetNode); this->GetRenderWindowPart()->RequestUpdate(); }; void QmitkMatchPointFrameCorrection::OnMapJobError(QString err) { Error(err); }; void QmitkMatchPointFrameCorrection::OnAlgorithmIterated(QString info, bool hasIterationCount, unsigned long currentIteration) { if (hasIterationCount) { m_Controls.m_progBarIteration->setValue(currentIteration); } m_Controls.m_teLog->append(info); }; void QmitkMatchPointFrameCorrection::OnLevelChanged(QString info, bool hasLevelCount, unsigned long currentLevel) { if (hasLevelCount) { m_Controls.m_progBarLevel->setValue(currentLevel); } m_Controls.m_teLog->append(QString("") + info + QString("")); }; void QmitkMatchPointFrameCorrection::OnAlgorithmStatusChanged(QString info) { m_Controls.m_teLog->append(QString("") + info + QString(" ")); }; void QmitkMatchPointFrameCorrection::OnAlgorithmInfo(QString info) { m_Controls.m_teLog->append(QString("") + info + QString("")); }; void QmitkMatchPointFrameCorrection::OnFrameProcessed(double progress) { m_Controls.m_teLog->append(QString("Frame processed...")); m_Controls.m_progBarFrame->setValue(100 * progress); }; void QmitkMatchPointFrameCorrection::OnFrameRegistered(double progress) { m_Controls.m_teLog->append(QString("Frame registered...")); m_Controls.m_progBarFrame->setValue(100 * progress); }; void QmitkMatchPointFrameCorrection::OnFrameMapped(double progress) { m_Controls.m_teLog->append(QString("Frame mapped...")); m_Controls.m_progBarFrame->setValue(100 * progress); }; void QmitkMatchPointFrameCorrection::OnAlgorithmSelectionChanged(const berry::IWorkbenchPart::Pointer& sourcepart, const berry::ISelection::ConstPointer& selection) { // check for null selection if (selection.IsNull()) { return; } if (sourcepart != this) { UpdateAlgorithmSelection(selection); } } void QmitkMatchPointFrameCorrection::UpdateAlgorithmSelection(berry::ISelection::ConstPointer selection) { mitk::MAPAlgorithmInfoSelection::ConstPointer currentSelection = selection.Cast(); if (currentSelection) { mitk::MAPAlgorithmInfoSelection::AlgorithmInfoVectorType infoVector = currentSelection->GetSelectedAlgorithmInfo(); if (!infoVector.empty()) { // only the first selection is of interest, the rest will be skipped. this->m_SelectedAlgorithmInfo = infoVector[0]; } } this->OnSelectedAlgorithmChanged(); }; diff --git a/Plugins/org.mitk.gui.qt.matchpoint.manipulator/src/internal/QmitkMatchPointRegistrationManipulator.cpp b/Plugins/org.mitk.gui.qt.matchpoint.manipulator/src/internal/QmitkMatchPointRegistrationManipulator.cpp index e0c3b80927..933767badf 100644 --- a/Plugins/org.mitk.gui.qt.matchpoint.manipulator/src/internal/QmitkMatchPointRegistrationManipulator.cpp +++ b/Plugins/org.mitk.gui.qt.matchpoint.manipulator/src/internal/QmitkMatchPointRegistrationManipulator.cpp @@ -1,727 +1,727 @@ /*=================================================================== 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. ===================================================================*/ // Blueberry #include #include // Mitk #include -#include +#include #include #include #include "mitkRegVisPropertyTags.h" #include "mitkMatchPointPropertyTags.h" #include "mitkRegEvaluationObject.h" #include "mitkRegistrationHelper.h" #include "mitkRegEvaluationMapper2D.h" #include #include #include // Qmitk #include "QmitkRenderWindow.h" #include "QmitkMatchPointRegistrationManipulator.h" #include // Qt #include #include #include #include //MatchPoint #include #include #include #include #include #include #include const std::string QmitkMatchPointRegistrationManipulator::VIEW_ID = "org.mitk.views.matchpoint.registration.manipulator"; QmitkMatchPointRegistrationManipulator::QmitkMatchPointRegistrationManipulator() : m_Parent(NULL), m_activeManipulation(false), m_autoMoving(false), m_autoTarget(false), m_currentSelectedTimeStep(0), HelperNodeName("RegistrationManipulationEvaluationHelper"), m_internalUpdate(false) { m_currentSelectedPosition.Fill(0.0); } QmitkMatchPointRegistrationManipulator::~QmitkMatchPointRegistrationManipulator() { if (this->m_EvalNode.IsNotNull() && this->GetDataStorage().IsNotNull()) { this->GetDataStorage()->Remove(this->m_EvalNode); } } void QmitkMatchPointRegistrationManipulator::SetFocus() { } void QmitkMatchPointRegistrationManipulator::Error(QString msg) { mitk::StatusBar::GetInstance()->DisplayErrorText(msg.toLatin1()); MITK_ERROR << msg.toStdString().c_str(); } void QmitkMatchPointRegistrationManipulator::CreateQtPartControl(QWidget* parent) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi(parent); m_Parent = parent; connect(m_Controls.pbStart, SIGNAL(clicked()), this, SLOT(OnStartBtnPushed())); connect(m_Controls.pbCancel, SIGNAL(clicked()), this, SLOT(OnCancelBtnPushed())); connect(m_Controls.pbStore, SIGNAL(clicked()), this, SLOT(OnStoreBtnPushed())); connect(m_Controls.evalSettings, SIGNAL(SettingsChanged(mitk::DataNode*)), this, SLOT(OnSettingsChanged(mitk::DataNode*))); connect(m_Controls.radioSelectedReg, SIGNAL(toggled(bool)), m_Controls.lbRegistrationName, SLOT(setVisible(bool))); connect(m_Controls.slideRotX, SIGNAL(valueChanged(int)), this, SLOT(OnRotXSlideChanged(int))); connect(m_Controls.sbRotX, SIGNAL(valueChanged(double)), this, SLOT(OnRotXChanged(double))); connect(m_Controls.slideRotY, SIGNAL(valueChanged(int)), this, SLOT(OnRotYSlideChanged(int))); connect(m_Controls.sbRotY, SIGNAL(valueChanged(double)), this, SLOT(OnRotYChanged(double))); connect(m_Controls.slideRotZ, SIGNAL(valueChanged(int)), this, SLOT(OnRotZSlideChanged(int))); connect(m_Controls.sbRotZ, SIGNAL(valueChanged(double)), this, SLOT(OnRotZChanged(double))); connect(m_Controls.slideTransX, SIGNAL(valueChanged(int)), this, SLOT(OnTransXSlideChanged(int))); connect(m_Controls.sbTransX, SIGNAL(valueChanged(double)), this, SLOT(OnTransXChanged(double))); connect(m_Controls.slideTransY, SIGNAL(valueChanged(int)), this, SLOT(OnTransYSlideChanged(int))); connect(m_Controls.sbTransY, SIGNAL(valueChanged(double)), this, SLOT(OnTransYChanged(double))); connect(m_Controls.slideTransZ, SIGNAL(valueChanged(int)), this, SLOT(OnTransZSlideChanged(int))); connect(m_Controls.sbTransZ, SIGNAL(valueChanged(double)), this, SLOT(OnTransZChanged(double))); connect(m_Controls.comboCenter, SIGNAL(currentIndexChanged(int)), this, SLOT(OnCenterTypeChanged(int))); this->m_SliceChangeListener.RenderWindowPartActivated(this->GetRenderWindowPart()); connect(&m_SliceChangeListener, SIGNAL(SliceChanged()), this, SLOT(OnSliceChanged())); m_Controls.radioNewReg->setChecked(true); m_Controls.groupScale->setVisible(false); m_Controls.lbRegistrationName->setVisible(false); m_EvalNode = this->GetDataStorage()->GetNamedNode(HelperNodeName); this->CheckInputs(); this->StopSession(); this->ConfigureControls(); } void QmitkMatchPointRegistrationManipulator::RenderWindowPartActivated(mitk::IRenderWindowPart* renderWindowPart) { this->m_SliceChangeListener.RenderWindowPartActivated(renderWindowPart); } void QmitkMatchPointRegistrationManipulator::RenderWindowPartDeactivated( mitk::IRenderWindowPart* renderWindowPart) { this->m_SliceChangeListener.RenderWindowPartDeactivated(renderWindowPart); } void QmitkMatchPointRegistrationManipulator::CheckInputs() { if (!m_activeManipulation) { QList dataNodes = this->GetDataManagerSelection(); this->m_autoMoving = false; this->m_autoTarget = false; this->m_SelectedMovingNode = NULL; this->m_SelectedTargetNode = NULL; this->m_SelectedPreRegNode = NULL; this->m_SelectedPreReg = NULL; if (dataNodes.size() > 0) { //test if auto select works if (mitk::MITKRegistrationHelper::IsRegNode(dataNodes[0])) { mitk::DataNode::Pointer regNode = dataNodes[0]; dataNodes.pop_front(); mitk::MAPRegistrationWrapper* regWrapper = dynamic_cast(regNode->GetData()); if (regWrapper) { this->m_SelectedPreReg = dynamic_cast(regWrapper->GetRegistration()); } if (this->m_SelectedPreReg.IsNotNull()) { this->m_SelectedPreRegNode = regNode; - mitk::BaseProperty* uidProp = m_SelectedPreRegNode->GetProperty(mitk::nodeProp_RegAlgMovingData); + mitk::BaseProperty* uidProp = m_SelectedPreRegNode->GetData()->GetProperty(mitk::Prop_RegAlgMovingData); if (uidProp) { //search for the moving node - mitk::NodePredicateProperty::Pointer predicate = mitk::NodePredicateProperty::New(mitk::nodeProp_UID, + mitk::NodePredicateDataProperty::Pointer predicate = mitk::NodePredicateDataProperty::New(mitk::Prop_UID, uidProp); this->m_SelectedMovingNode = this->GetDataStorage()->GetNode(predicate); this->m_autoMoving = this->m_SelectedMovingNode.IsNotNull(); } - uidProp = m_SelectedPreRegNode->GetProperty(mitk::nodeProp_RegAlgTargetData); + uidProp = m_SelectedPreRegNode->GetData()->GetProperty(mitk::Prop_RegAlgTargetData); if (uidProp) { //search for the target node - mitk::NodePredicateProperty::Pointer predicate = mitk::NodePredicateProperty::New(mitk::nodeProp_UID, + mitk::NodePredicateDataProperty::Pointer predicate = mitk::NodePredicateDataProperty::New(mitk::Prop_UID, uidProp); this->m_SelectedTargetNode = this->GetDataStorage()->GetNode(predicate); this->m_autoTarget = this->m_SelectedTargetNode.IsNotNull(); } } } //if still nodes are selected -> ignore possible auto select if (!dataNodes.empty()) { mitk::Image* inputImage = dynamic_cast(dataNodes[0]->GetData()); if (inputImage) { this->m_SelectedMovingNode = dataNodes[0]; this->m_autoMoving = false; dataNodes.pop_front(); } } if (!dataNodes.empty()) { mitk::Image* inputImage = dynamic_cast(dataNodes[0]->GetData()); if (inputImage) { this->m_SelectedTargetNode = dataNodes[0]; this->m_autoTarget = false; dataNodes.pop_front(); } } } } } void QmitkMatchPointRegistrationManipulator::OnSelectionChanged(berry::IWorkbenchPart::Pointer source, const QList& nodes) { this->CheckInputs(); this->ConfigureControls(); }; void QmitkMatchPointRegistrationManipulator::ConfigureControls() { //configure input data widgets if (this->m_SelectedPreRegNode.IsNull()) { m_Controls.lbRegistrationName->setText( QString("No registration selected!")); } else { m_Controls.lbRegistrationName->setText(QString::fromStdString( this->m_SelectedPreRegNode->GetName())); } if (this->m_SelectedMovingNode.IsNull()) { m_Controls.lbMovingName->setText(QString("no moving image selected!")); } else { if (this->m_autoMoving) { m_Controls.lbMovingName->setText(QString("") + QString::fromStdString( this->m_SelectedMovingNode->GetName()) + QString(" (auto selected)")); } else { m_Controls.lbMovingName->setText(QString::fromStdString(this->m_SelectedMovingNode->GetName())); } } if (this->m_SelectedTargetNode.IsNull()) { m_Controls.lbTargetName->setText(QString("no target image selected!")); } else { if (this->m_autoTarget) { m_Controls.lbTargetName->setText(QString("") + QString::fromStdString( this->m_SelectedTargetNode->GetName()) + QString(" (auto selected)")); } else { m_Controls.lbTargetName->setText(QString::fromStdString(this->m_SelectedTargetNode->GetName())); } } if (!m_activeManipulation) { QString name = "ManuelRegistration"; if (m_SelectedPreRegNode.IsNotNull()) { name = QString::fromStdString(m_SelectedPreRegNode->GetName()) + " manual refined"; } this->m_Controls.lbNewRegName->setText(name); } //config settings widget this->m_Controls.groupReg->setEnabled(!m_activeManipulation); this->m_Controls.lbMovingName->setEnabled(!m_activeManipulation); this->m_Controls.lbTargetName->setEnabled(!m_activeManipulation); this->m_Controls.pbStart->setEnabled(this->m_SelectedMovingNode.IsNotNull() && this->m_SelectedTargetNode.IsNotNull() && !m_activeManipulation); this->m_Controls.lbNewRegName->setEnabled(m_activeManipulation); this->m_Controls.checkMapEntity->setEnabled(m_activeManipulation); this->m_Controls.tabWidget->setEnabled(m_activeManipulation); this->m_Controls.pbCancel->setEnabled(m_activeManipulation); this->m_Controls.pbStore->setEnabled(m_activeManipulation); this->UpdateTransformWidgets(); } void QmitkMatchPointRegistrationManipulator::InitSession() { this->m_InverseCurrentTransform = TransformType::New(); this->m_InverseCurrentTransform->SetIdentity(); this->m_DirectCurrentTransform = TransformType::New(); this->m_DirectCurrentTransform->SetIdentity(); this->m_CurrentRegistrationWrapper = mitk::MAPRegistrationWrapper::New(); m_CurrentRegistration = MAPRegistrationType::New(); this->m_CurrentRegistrationWrapper->SetRegistration(m_CurrentRegistration); ::map::core::RegistrationManipulator manipulator(m_CurrentRegistration); ::map::core::PreCachedRegistrationKernel<3, 3>::Pointer kernel = ::map::core::PreCachedRegistrationKernel<3, 3>::New(); manipulator.setDirectMapping(::map::core::NullRegistrationKernel < 3, 3 >::New()); if (this->m_Controls.radioNewReg->isChecked()) { //new registration kernel->setTransformModel(m_InverseCurrentTransform); manipulator.setInverseMapping(kernel); //init to map the image centers auto movingCenter = m_SelectedMovingNode->GetData()->GetTimeGeometry()->GetCenterInWorld(); auto targetCenter = m_SelectedTargetNode->GetData()->GetTimeGeometry()->GetCenterInWorld(); auto offset = targetCenter - movingCenter; m_DirectCurrentTransform->SetOffset(offset); m_DirectCurrentTransform->GetInverse(m_InverseCurrentTransform); } else { //use selected pre registration as baseline itk::CompositeTransform < ::map::core::continuous::ScalarType, 3>::Pointer compTransform = itk::CompositeTransform < ::map::core::continuous::ScalarType, 3>::New(); const map::core::RegistrationKernel<3, 3>* preKernel = dynamic_cast*>(&this->m_SelectedPreReg->getInverseMapping()); compTransform->AddTransform(preKernel->getTransformModel()->Clone()); compTransform->AddTransform(this->m_InverseCurrentTransform); kernel->setTransformModel(compTransform); manipulator.setInverseMapping(kernel); } m_Controls.comboCenter->setCurrentIndex(0); this->ConfigureTransformCenter(0); //set bounds of the translation slider widget to have sensible ranges auto currenttrans = m_DirectCurrentTransform->GetTranslation(); this->m_Controls.slideTransX->setMinimum(currenttrans[0] - 250); this->m_Controls.slideTransY->setMinimum(currenttrans[1] - 250); this->m_Controls.slideTransZ->setMinimum(currenttrans[2] - 250); this->m_Controls.slideTransX->setMaximum(currenttrans[0] + 250); this->m_Controls.slideTransY->setMaximum(currenttrans[1] + 250); this->m_Controls.slideTransZ->setMaximum(currenttrans[2] + 250); //reinit view mitk::RenderingManager::GetInstance()->InitializeViews(m_SelectedTargetNode->GetData()->GetTimeSlicedGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true); //generate evaluation node mitk::RegEvaluationObject::Pointer regEval = mitk::RegEvaluationObject::New(); regEval->SetRegistration(this->m_CurrentRegistrationWrapper); regEval->SetTargetNode(this->m_SelectedTargetNode); regEval->SetMovingNode(this->m_SelectedMovingNode); this->m_EvalNode = mitk::DataNode::New(); this->m_EvalNode->SetData(regEval); mitk::RegEvaluationMapper2D::SetDefaultProperties(this->m_EvalNode); this->m_EvalNode->SetName(HelperNodeName); this->m_EvalNode->SetBoolProperty("helper object", true); this->GetDataStorage()->Add(this->m_EvalNode); this->m_Controls.evalSettings->SetNode(this->m_EvalNode); this->m_activeManipulation = true; }; void QmitkMatchPointRegistrationManipulator::StopSession() { this->m_InverseCurrentTransform = TransformType::New(); this->m_InverseCurrentTransform->SetIdentity(); this->m_DirectCurrentTransform = TransformType::New(); this->m_DirectCurrentTransform->SetIdentity(); this->m_CurrentRegistration = nullptr; this->m_CurrentRegistrationWrapper = nullptr; this->GetDataStorage()->Remove(this->m_EvalNode); this->m_EvalNode = nullptr; this->m_activeManipulation = false; }; void QmitkMatchPointRegistrationManipulator::UpdateTransformWidgets() { this->m_internalUpdate = true; this->m_Controls.sbTransX->setValue(this->m_DirectCurrentTransform->GetTranslation()[0]); this->m_Controls.sbTransY->setValue(this->m_DirectCurrentTransform->GetTranslation()[1]); this->m_Controls.sbTransZ->setValue(this->m_DirectCurrentTransform->GetTranslation()[2]); this->m_Controls.slideTransX->setValue(this->m_DirectCurrentTransform->GetTranslation()[0]); this->m_Controls.slideTransY->setValue(this->m_DirectCurrentTransform->GetTranslation()[1]); this->m_Controls.slideTransZ->setValue(this->m_DirectCurrentTransform->GetTranslation()[2]); this->m_Controls.sbRotX->setValue(this->m_DirectCurrentTransform->GetAngleX()*(180 / boost::math::double_constants::pi)); this->m_Controls.sbRotY->setValue(this->m_DirectCurrentTransform->GetAngleY()*(180 / boost::math::double_constants::pi)); this->m_Controls.sbRotZ->setValue(this->m_DirectCurrentTransform->GetAngleZ()*(180 / boost::math::double_constants::pi)); this->m_Controls.slideRotX->setValue(this->m_DirectCurrentTransform->GetAngleX()*(180 / boost::math::double_constants::pi)); this->m_Controls.slideRotY->setValue(this->m_DirectCurrentTransform->GetAngleY()*(180 / boost::math::double_constants::pi)); this->m_Controls.slideRotZ->setValue(this->m_DirectCurrentTransform->GetAngleZ()*(180 / boost::math::double_constants::pi)); this->m_internalUpdate = false; }; void QmitkMatchPointRegistrationManipulator::UpdateTransform(bool updateRotation) { if (updateRotation) { if (m_Controls.comboCenter->currentIndex() == 2) { ConfigureTransformCenter(2); } this->m_DirectCurrentTransform->SetRotation(this->m_Controls.sbRotX->value()*(boost::math::double_constants::pi / 180), this->m_Controls.sbRotY->value()*(boost::math::double_constants::pi / 180), this->m_Controls.sbRotZ->value()*(boost::math::double_constants::pi / 180)); } else { TransformType::OutputVectorType trans; trans[0] = this->m_Controls.sbTransX->value(); trans[1] = this->m_Controls.sbTransY->value(); trans[2] = this->m_Controls.sbTransZ->value(); this->m_DirectCurrentTransform->SetTranslation(trans); } this->m_DirectCurrentTransform->GetInverse(this->m_InverseCurrentTransform); this->UpdateTransformWidgets(); this->m_EvalNode->Modified(); this->m_CurrentRegistrationWrapper->Modified(); this->GetRenderWindowPart()->RequestUpdate(); }; void QmitkMatchPointRegistrationManipulator::OnSliceChanged() { mitk::Point3D currentSelectedPosition = GetRenderWindowPart()->GetSelectedPosition(NULL); unsigned int currentSelectedTimeStep = GetRenderWindowPart()->GetTimeNavigationController()->GetTime()->GetPos(); if (m_currentSelectedPosition != currentSelectedPosition || m_currentSelectedTimeStep != currentSelectedTimeStep || m_selectedNodeTime > m_currentPositionTime) { //the current position has been changed or the selected node has been changed since the last position validation -> check position m_currentSelectedPosition = currentSelectedPosition; m_currentSelectedTimeStep = currentSelectedTimeStep; m_currentPositionTime.Modified(); if (this->m_EvalNode.IsNotNull()) { this->m_EvalNode->SetProperty(mitk::nodeProp_RegEvalCurrentPosition, mitk::GenericProperty::New(currentSelectedPosition)); } if (m_activeManipulation && m_Controls.comboCenter->currentIndex() == 2) { //update transform with the current position. OnCenterTypeChanged(m_Controls.comboCenter->currentIndex()); } } } void QmitkMatchPointRegistrationManipulator::OnSettingsChanged(mitk::DataNode*) { this->GetRenderWindowPart()->RequestUpdate(); }; void QmitkMatchPointRegistrationManipulator::OnStartBtnPushed() { this->InitSession(); this->OnSliceChanged(); this->GetRenderWindowPart()->RequestUpdate(); this->CheckInputs(); this->ConfigureControls(); } void QmitkMatchPointRegistrationManipulator::OnCancelBtnPushed() { this->StopSession(); this->CheckInputs(); this->ConfigureControls(); this->GetRenderWindowPart()->RequestUpdate(); } void QmitkMatchPointRegistrationManipulator::OnStoreBtnPushed() { mitk::MAPRegistrationWrapper::Pointer newRegWrapper = mitk::MAPRegistrationWrapper::New(); MAPRegistrationType::Pointer newReg = MAPRegistrationType::New(); newRegWrapper->SetRegistration(newReg); ::map::core::RegistrationManipulator manipulator(newReg); ::map::core::PreCachedRegistrationKernel<3, 3>::Pointer kernel = ::map::core::PreCachedRegistrationKernel<3, 3>::New(); kernel->setTransformModel(m_InverseCurrentTransform); ::map::core::PreCachedRegistrationKernel<3, 3>::Pointer kernel2 = ::map::core::PreCachedRegistrationKernel<3, 3>::New(); kernel2->setTransformModel(m_InverseCurrentTransform->GetInverseTransform()); manipulator.setInverseMapping(kernel); manipulator.setDirectMapping(kernel2); if (this->m_Controls.radioSelectedReg->isChecked()) { //compine registration with selected pre registration as baseline typedef ::map::core::RegistrationCombinator CombinatorType; CombinatorType::Pointer combinator = CombinatorType::New(); newReg = combinator->process(*m_SelectedPreReg,*newReg); newRegWrapper->SetRegistration(newReg); } mitk::DataNode::Pointer spResultRegistrationNode = mitk::generateRegistrationResultNode( this->m_Controls.lbNewRegName->text().toStdString(), newRegWrapper, "org.mitk::manual_registration", - mitk::EnsureUID(m_SelectedMovingNode), mitk::EnsureUID(m_SelectedTargetNode)); + mitk::EnsureUID(m_SelectedMovingNode->GetData()), mitk::EnsureUID(m_SelectedTargetNode->GetData())); this->GetDataStorage()->Add(spResultRegistrationNode); if (m_Controls.checkMapEntity->checkState() == Qt::Checked) { QmitkMappingJob* pMapJob = new QmitkMappingJob(); pMapJob->setAutoDelete(true); pMapJob->m_spInputData = this->m_SelectedMovingNode->GetData(); - pMapJob->m_InputNodeUID = mitk::EnsureUID(m_SelectedMovingNode); + pMapJob->m_InputDataUID = mitk::EnsureUID(m_SelectedMovingNode->GetData()); pMapJob->m_spRegNode = spResultRegistrationNode; pMapJob->m_doGeometryRefinement = false; pMapJob->m_spRefGeometry = this->m_SelectedTargetNode->GetData()->GetGeometry()->Clone().GetPointer(); pMapJob->m_MappedName = this->m_Controls.lbNewRegName->text().toStdString() + std::string(" mapped moving data"); pMapJob->m_allowUndefPixels = true; pMapJob->m_paddingValue = 100; pMapJob->m_allowUnregPixels = true; pMapJob->m_errorValue = 200; pMapJob->m_InterpolatorLabel = "Linear Interpolation"; pMapJob->m_InterpolatorType = mitk::ImageMappingInterpolator::Linear; connect(pMapJob, SIGNAL(Error(QString)), this, SLOT(OnMapJobError(QString))); connect(pMapJob, SIGNAL(MapResultIsAvailable(mitk::BaseData::Pointer, const QmitkMappingJob*)), this, SLOT(OnMapResultIsAvailable(mitk::BaseData::Pointer, const QmitkMappingJob*)), Qt::BlockingQueuedConnection); QThreadPool* threadPool = QThreadPool::globalInstance(); threadPool->start(pMapJob); } this->StopSession(); this->CheckInputs(); this->ConfigureControls(); this->GetRenderWindowPart()->RequestUpdate(); } void QmitkMatchPointRegistrationManipulator::OnMapResultIsAvailable(mitk::BaseData::Pointer spMappedData, const QmitkMappingJob* job) { mitk::DataNode::Pointer spMappedNode = mitk::generateMappedResultNode(job->m_MappedName, - spMappedData, job->GetRegistration()->getRegistrationUID(), job->m_InputNodeUID, + spMappedData, job->GetRegistration()->getRegistrationUID(), job->m_InputDataUID, job->m_doGeometryRefinement, job->m_InterpolatorLabel); this->GetDataStorage()->Add(spMappedNode); this->GetRenderWindowPart()->RequestUpdate(); }; void QmitkMatchPointRegistrationManipulator::OnRotXChanged(double x) { if (!m_internalUpdate) { m_internalUpdate = true; this->m_Controls.slideRotX->setValue(x); m_internalUpdate = false; this->UpdateTransform(true); } }; void QmitkMatchPointRegistrationManipulator::OnRotXSlideChanged(int x) { if (!m_internalUpdate) { this->m_Controls.sbRotX->setValue(x); } }; void QmitkMatchPointRegistrationManipulator::OnRotYChanged(double y) { if (!m_internalUpdate) { m_internalUpdate = true; this->m_Controls.slideRotY->setValue(y); m_internalUpdate = false; this->UpdateTransform(true); } }; void QmitkMatchPointRegistrationManipulator::OnRotYSlideChanged(int y) { if (!m_internalUpdate) { this->m_Controls.sbRotY->setValue(y); } }; void QmitkMatchPointRegistrationManipulator::OnRotZChanged(double z) { if (!m_internalUpdate) { m_internalUpdate = true; this->m_Controls.slideRotZ->setValue(z); m_internalUpdate = false; this->UpdateTransform(true); } }; void QmitkMatchPointRegistrationManipulator::OnRotZSlideChanged(int z) { if (!m_internalUpdate) { this->m_Controls.sbRotZ->setValue(z); } }; void QmitkMatchPointRegistrationManipulator::OnTransXChanged(double x) { if (!m_internalUpdate) { m_internalUpdate = true; this->m_Controls.slideTransX->setValue(x); m_internalUpdate = false; this->UpdateTransform(); } }; void QmitkMatchPointRegistrationManipulator::OnTransXSlideChanged(int x) { if (!m_internalUpdate) { this->m_Controls.sbTransX->setValue(x); } }; void QmitkMatchPointRegistrationManipulator::OnTransYChanged(double y) { if (!m_internalUpdate) { m_internalUpdate = true; this->m_Controls.slideTransY->setValue(y); m_internalUpdate = false; this->UpdateTransform(); } }; void QmitkMatchPointRegistrationManipulator::OnTransYSlideChanged(int y) { if (!m_internalUpdate) { this->m_Controls.sbTransY->setValue(y); } }; void QmitkMatchPointRegistrationManipulator::OnTransZChanged(double z) { if (!m_internalUpdate) { m_internalUpdate = true; this->m_Controls.slideTransZ->setValue(z); m_internalUpdate = false; this->UpdateTransform(); } }; void QmitkMatchPointRegistrationManipulator::OnTransZSlideChanged(int z) { if (!m_internalUpdate) { this->m_Controls.sbTransZ->setValue(z); } }; void QmitkMatchPointRegistrationManipulator::OnCenterTypeChanged(int index) { ConfigureTransformCenter(index); this->UpdateTransformWidgets(); if (this->m_EvalNode.IsNotNull()) { this->m_EvalNode->Modified(); } this->m_CurrentRegistrationWrapper->Modified(); this->GetRenderWindowPart()->RequestUpdate(); }; void QmitkMatchPointRegistrationManipulator::ConfigureTransformCenter(int centerType) { auto offset = m_DirectCurrentTransform->GetOffset(); if (centerType == 0) { //image center auto center = m_SelectedMovingNode->GetData()->GetTimeGeometry()->GetCenterInWorld(); m_DirectCurrentTransform->SetCenter(center); } else if (centerType == 1) { //world origin TransformType::OutputPointType itkCenter; itkCenter.Fill(0.0); m_DirectCurrentTransform->SetCenter(itkCenter); } else { //current selected point auto newCenter = m_InverseCurrentTransform->TransformPoint(m_currentSelectedPosition); m_DirectCurrentTransform->SetCenter(newCenter); } m_DirectCurrentTransform->SetOffset(offset); m_DirectCurrentTransform->GetInverse(m_InverseCurrentTransform); }; diff --git a/Plugins/org.mitk.gui.qt.matchpoint.mapper/src/internal/QmitkMatchPointMapper.cpp b/Plugins/org.mitk.gui.qt.matchpoint.mapper/src/internal/QmitkMatchPointMapper.cpp index 9684a8fb4c..e739675940 100644 --- a/Plugins/org.mitk.gui.qt.matchpoint.mapper/src/internal/QmitkMatchPointMapper.cpp +++ b/Plugins/org.mitk.gui.qt.matchpoint.mapper/src/internal/QmitkMatchPointMapper.cpp @@ -1,681 +1,681 @@ /*=================================================================== 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 "org_mitk_gui_qt_matchpoint_mapper_Activator.h" // Blueberry #include #include // Mitk #include #include -#include +#include #include "mitkImageMappingHelper.h" #include "mitkMAPRegistrationWrapper.h" #include "mitkMatchPointPropertyTags.h" #include "mitkRegistrationHelper.h" #include #include #include #include #include #include #include #include // Qmitk #include "QmitkMatchPointMapper.h" // Qt #include #include #include #include const std::string QmitkMatchPointMapper::VIEW_ID = "org.mitk.views.matchpoint.mapper"; QmitkMatchPointMapper::QmitkMatchPointMapper() : m_Parent(NULL), m_preparedForBinaryInput(false) { } void QmitkMatchPointMapper::SetFocus() { //m_Controls.buttonPerformImageProcessing->setFocus(); } void QmitkMatchPointMapper::CreateConnections() { // show first page m_Controls.m_tabs->setCurrentIndex(0); connect(m_Controls.m_pbLockReg, SIGNAL(clicked()), this, SLOT(OnLockRegButtonPushed())); connect(m_Controls.m_pbLockInput, SIGNAL(clicked()), this, SLOT(OnLockInputButtonPushed())); connect(m_Controls.m_pbLockRef, SIGNAL(clicked()), this, SLOT(OnLockReferenceButtonPushed())); connect(m_Controls.m_cbManualRef, SIGNAL(clicked()), this, SLOT(OnManualRefChecked())); connect(m_Controls.m_cbLinkFactors, SIGNAL(clicked()), this, SLOT(OnLinkSampleFactorChecked())); connect(m_Controls.m_sbXFactor, SIGNAL(valueChanged(double)), this, SLOT(OnXFactorChanged(double))); connect(m_Controls.m_pbMap, SIGNAL(clicked()), this, SLOT(OnMapBtnPushed())); connect(m_Controls.m_pbRefine, SIGNAL(clicked()), this, SLOT(OnRefineBtnPushed())); } void QmitkMatchPointMapper::Error(QString msg) { mitk::StatusBar::GetInstance()->DisplayErrorText(msg.toLatin1()); MITK_ERROR << msg.toStdString().c_str(); m_Controls.m_teLog->append(QString("") + msg + QString("")); } void QmitkMatchPointMapper::CreateQtPartControl(QWidget* parent) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi(parent); m_Parent = parent; this->CreateConnections(); this->CheckInputs(); this->ConfigureProgressInfos(); this->ConfigureMappingControls(); } /** Method checks if the currently selected reg node has a direct kernel that * can be decomposed in a rotation matrix and a offset. If this is true, true * is returned. In all other cases false is returned.*/ bool QmitkMatchPointMapper::IsAbleToRefineGeometry() const { bool result = false; if (this->m_spSelectedRegNode.IsNotNull()) { const mitk::MAPRegistrationWrapper* wrapper = dynamic_cast (this->m_spSelectedRegNode->GetData()); //if the helper does not return null, we can refine the geometry. result = mitk::MITKRegistrationHelper::getAffineMatrix(wrapper, false).IsNotNull(); } return result; } bool QmitkMatchPointMapper::IsBinaryInput() const { mitk::NodePredicateDataType::Pointer isLabelSet = mitk::NodePredicateDataType::New("LabelSetImage"); mitk::NodePredicateDataType::Pointer isImage = mitk::NodePredicateDataType::New("Image"); mitk::NodePredicateProperty::Pointer isBinary = mitk::NodePredicateProperty::New("binary", mitk::BoolProperty::New(true)); mitk::NodePredicateAnd::Pointer isLegacyMask = mitk::NodePredicateAnd::New(isImage, isBinary); mitk::NodePredicateOr::Pointer maskPredicate = mitk::NodePredicateOr::New(isLegacyMask, isLabelSet); bool result = false; if(this->m_spSelectedInputNode.IsNotNull()) { result = maskPredicate->CheckNode(this->m_spSelectedInputNode); } return result; } bool QmitkMatchPointMapper::IsPointSetInput() const { bool result = false; if (this->m_spSelectedInputNode.IsNotNull()) { result = dynamic_cast(this->m_spSelectedInputNode->GetData()) != NULL; } return result; } mitk::DataNode::Pointer QmitkMatchPointMapper::GetSelectedRegNode() { mitk::DataNode::Pointer spResult = NULL; typedef QList NodeListType; NodeListType nodes = this->GetDataManagerSelection(); for (NodeListType::iterator pos = nodes.begin(); pos != nodes.end(); ++pos) { if (mitk::MITKRegistrationHelper::IsRegNode(*pos)) { spResult = *pos; break; } } return spResult; } QList QmitkMatchPointMapper::GetSelectedDataNodes() { typedef QList NodeListType; NodeListType nodes = this->GetDataManagerSelection(); NodeListType result; for (NodeListType::iterator pos = nodes.begin(); pos != nodes.end(); ++pos) { if (!mitk::MITKRegistrationHelper::IsRegNode(*pos)) { result.push_back(*pos); } } return result; } mitk::DataNode::Pointer QmitkMatchPointMapper::GetAutoRefNodeByReg() { mitk::DataNode::Pointer spResult = NULL; - if (this->m_spSelectedRegNode.IsNotNull()) + if (this->m_spSelectedRegNode.IsNotNull() && this->m_spSelectedRegNode->GetData()) { std::string nodeName; - mitk::BaseProperty* uidProp = m_spSelectedRegNode->GetProperty(mitk::nodeProp_RegAlgTargetData); + mitk::BaseProperty* uidProp = m_spSelectedRegNode->GetData()->GetProperty(mitk::Prop_RegAlgTargetData); if (uidProp) { //search for the target node - mitk::NodePredicateProperty::Pointer predicate = mitk::NodePredicateProperty::New(mitk::nodeProp_UID, + mitk::NodePredicateDataProperty::Pointer predicate = mitk::NodePredicateDataProperty::New(mitk::Prop_UID, uidProp); spResult = this->GetDataStorage()->GetNode(predicate); } } if (spResult.IsNull() && this->m_spSelectedInputNode.IsNotNull()) { //no really reference is available -> use the input as reference spResult = this->m_spSelectedInputNode; m_Controls.m_teLog->append( QString("Cannot determine reference automatically. Use input image as reference.")); } return spResult; } void QmitkMatchPointMapper::CheckInputs() { mitk::DataNode::Pointer regNode = this->GetSelectedRegNode(); QList dataNodes = this->GetSelectedDataNodes(); //first set the internal nodes according to selection if (!m_Controls.m_pbLockReg->isChecked()) { this->m_spSelectedRegNode = regNode; } if (!m_Controls.m_pbLockInput->isChecked()) { mitk::DataNode::Pointer inputNode = NULL; if (dataNodes.size() > 0) { inputNode = dataNodes[0]; } this->m_spSelectedInputNode = inputNode; } if (!(m_Controls.m_cbManualRef->isChecked())) { this->m_spSelectedRefNode = this->GetAutoRefNodeByReg(); } else { if (!m_Controls.m_pbLockRef->isChecked()) { mitk::DataNode::Pointer refNode = NULL; int relevantIndex = 1; if (m_Controls.m_pbLockInput->isChecked()) { //the input is locked thus use the first selected data node relevantIndex = 0; } if (dataNodes.size() > relevantIndex) { refNode = dataNodes[relevantIndex]; } this->m_spSelectedRefNode = refNode; } } //second, check validity of the selected nodes this->CheckNodesValidity(this->m_ValidReg, this->m_ValidInput, this->m_ValidRef); //third, configure widgets if (this->m_spSelectedRegNode.IsNull()) { m_Controls.m_lbRegistrationName->setText( QString("no registration selected!")); } else { if (this->m_ValidReg) { m_Controls.m_lbRegistrationName->setText(QString::fromStdString( this->m_spSelectedRegNode->GetName())); } else { m_Controls.m_lbRegistrationName->setText(QString("") + QString::fromStdString( this->m_spSelectedRegNode->GetName()) + QString("")); } } if (this->m_spSelectedInputNode.IsNull()) { m_Controls.m_lbInputName->setText(QString("no input selected!")); } else { if (this->m_ValidInput) { m_Controls.m_lbInputName->setText(QString::fromStdString(this->m_spSelectedInputNode->GetName())); } else { m_Controls.m_lbInputName->setText(QString("") + QString::fromStdString( this->m_spSelectedInputNode->GetName()) + QString("")); } } if (this->m_spSelectedRefNode.IsNull()) { if (this->m_ValidRef) { m_Controls.m_lbReferenceName->setText(QString("input needs no reference needed")); } else { m_Controls.m_lbReferenceName->setText(QString("no reference selected!")); } } else { if (this->m_ValidRef) { m_Controls.m_lbReferenceName->setText(QString::fromStdString(this->m_spSelectedRefNode->GetName())); if (this->m_spSelectedRefNode->GetData() && this->m_spSelectedRefNode->GetData()->GetTimeSteps() > 1) { m_Controls.m_teLog->append( QString("Selected reference image has multiple time steps. Only geometry of time step 1 is used as reference.")); } } else { m_Controls.m_lbReferenceName->setText(QString("") + QString::fromStdString( this->m_spSelectedRefNode->GetName()) + QString("")); } } this->m_Controls.m_pbLockInput->setEnabled(this->m_spSelectedInputNode.IsNotNull()); this->m_Controls.m_pbLockReg->setEnabled(this->m_spSelectedRegNode.IsNotNull()); this->m_Controls.m_pbLockRef->setEnabled(this->m_spSelectedRefNode.IsNotNull()); } void QmitkMatchPointMapper::CheckNodesValidity(bool& validReg, bool& validInput, bool& validRef) { validReg = this->m_spSelectedRegNode.IsNotNull(); validInput = this->m_spSelectedInputNode.IsNotNull(); validRef = this->m_spSelectedRefNode.IsNotNull(); if (this->m_spSelectedRegNode.IsNotNull()) { if (this->m_spSelectedInputNode.IsNotNull()) { validInput = false; const mitk::MAPRegistrationWrapper* wrapper = dynamic_cast < const mitk::MAPRegistrationWrapper* > (m_spSelectedRegNode->GetData()); mitk::Image* inputImage = dynamic_cast(m_spSelectedInputNode->GetData()); if (inputImage && wrapper) { if (inputImage->GetDimension() - 1 == wrapper->GetMovingDimensions() && inputImage->GetTimeSteps() > 1) { //images has multiple time steps and a time step has the correct dimensionality validInput = true; } if (inputImage->GetDimension() == wrapper->GetMovingDimensions()) { validInput = true; } } if (this->IsPointSetInput() && wrapper) { if (wrapper->GetMovingDimensions() == 3) { validInput = true; } } } if (this->m_spSelectedRefNode.IsNotNull()) { validRef = false; const mitk::MAPRegistrationWrapper* wrapper = dynamic_cast < const mitk::MAPRegistrationWrapper* > (m_spSelectedRegNode->GetData()); mitk::BaseGeometry* geometry = NULL; if (m_spSelectedRefNode->GetData()) { geometry = m_spSelectedRefNode->GetData()->GetGeometry(); } if (geometry && wrapper) { if (wrapper->GetTargetDimensions() == 3) { validRef = true; } else if (wrapper->GetTargetDimensions() == 2) { mitk::BaseGeometry::BoundsArrayType bounds = geometry->GetBounds(); if (bounds[4] != 0 || bounds[5] != 0) { //array "bounds" is constructed as [min Dim1, max Dim1, min Dim2, max Dim2, min Dim3, max Dim3] //therfore [4] and [5] must be 0 validRef = true; } } } } else if (this->IsPointSetInput()) { validRef = true; } } } void QmitkMatchPointMapper::ConfigureMappingControls() { this->m_Controls.m_pbMap->setEnabled(this->m_ValidInput && this->m_ValidRef && (this->m_ValidReg || this->m_spSelectedRegNode.IsNull())); this->m_Controls.m_pbRefine->setEnabled(this->m_ValidInput && this->m_ValidReg && this->IsAbleToRefineGeometry() && !this->IsPointSetInput()); this->m_Controls.m_pbLockRef->setEnabled(this->m_Controls.m_cbManualRef->isChecked()); this->m_Controls.m_lbReferenceName->setEnabled(this->m_Controls.m_cbManualRef->isChecked()); if (this->m_ValidInput && this->m_ValidReg) { this->m_Controls.m_leMappedName->setText(tr("mapped_by_") + QString::fromStdString( m_spSelectedRegNode->GetName())); } else { this->m_Controls.m_leMappedName->setText(tr("mappedData")); } if (this->IsBinaryInput() != this->m_preparedForBinaryInput) { if (this->IsBinaryInput()) { m_Controls.m_teLog->append( QString("Binary input (mask) detected. Preparing for mask mapping (default interpolation: nearest neigbour; padding value: 0)")); this->m_Controls.m_comboInterpolator->setCurrentIndex(0); this->m_Controls.m_sbErrorValue->setValue(0); this->m_Controls.m_sbPaddingValue->setValue(0); } else { this->m_Controls.m_comboInterpolator->setCurrentIndex(1); } this->m_preparedForBinaryInput = this->IsBinaryInput(); } OnLinkSampleFactorChecked(); } void QmitkMatchPointMapper::ConfigureProgressInfos() { } void QmitkMatchPointMapper::OnSelectionChanged(berry::IWorkbenchPart::Pointer /*source*/, const QList& nodes) { this->CheckInputs(); this->ConfigureMappingControls(); } void QmitkMatchPointMapper::OnLockRegButtonPushed() { if (this->m_Controls.m_pbLockReg->isChecked()) { if (this->m_spSelectedRegNode.IsNotNull()) { this->m_spSelectedRegNode->SetSelected(false); this->GetDataStorage()->Modified(); } } this->CheckInputs(); this->ConfigureMappingControls(); } void QmitkMatchPointMapper::OnLockInputButtonPushed() { if (this->m_Controls.m_pbLockInput->isChecked()) { if (this->m_spSelectedInputNode.IsNotNull()) { this->m_spSelectedInputNode->SetSelected(false); this->GetDataStorage()->Modified(); } } this->CheckInputs(); this->ConfigureMappingControls(); } void QmitkMatchPointMapper::OnLockReferenceButtonPushed() { if (this->m_Controls.m_pbLockRef->isChecked()) { if (this->m_spSelectedRefNode.IsNotNull()) { this->m_spSelectedRefNode->SetSelected(false); this->GetDataStorage()->Modified(); } } this->CheckInputs(); this->ConfigureMappingControls(); } void QmitkMatchPointMapper::OnManualRefChecked() { this->CheckInputs(); this->ConfigureMappingControls(); } void QmitkMatchPointMapper::OnLinkSampleFactorChecked() { this->m_Controls.m_sbYFactor->setEnabled(!(this->m_Controls.m_cbLinkFactors->isChecked())); this->m_Controls.m_sbZFactor->setEnabled(!(this->m_Controls.m_cbLinkFactors->isChecked())); if (m_Controls.m_cbLinkFactors->isChecked()) { this->m_Controls.m_sbYFactor->setValue(this->m_Controls.m_sbXFactor->value()); this->m_Controls.m_sbZFactor->setValue(this->m_Controls.m_sbXFactor->value()); } } void QmitkMatchPointMapper::OnMapBtnPushed() { SpawnMappingJob(); } void QmitkMatchPointMapper::OnRefineBtnPushed() { SpawnMappingJob(true); } void QmitkMatchPointMapper::SpawnMappingJob(bool doGeometryRefinement) { if (m_Controls.m_checkClearLog->checkState() == Qt::Checked) { this->m_Controls.m_teLog->clear(); } ///////////////////////// //create job and put it into the thread pool QmitkMappingJob* pJob = new QmitkMappingJob(); pJob->setAutoDelete(true); pJob->m_spInputData = this->m_spSelectedInputNode->GetData(); - pJob->m_InputNodeUID = mitk::EnsureUID(this->m_spSelectedInputNode); + pJob->m_InputDataUID = mitk::EnsureUID(this->m_spSelectedInputNode->GetData()); pJob->m_doGeometryRefinement = doGeometryRefinement; pJob->m_spRegNode = m_spSelectedRegNode; if (m_spSelectedRegNode.IsNull()) { pJob->m_spRegNode = mitk::DataNode::New(); pJob->m_spRegNode->SetData(mitk::GenerateIdentityRegistration3D().GetPointer()); pJob->m_spRegNode->SetName("Auto_Generated_Identity_Transform"); m_Controls.m_teLog->append( QString("No registration selected. Preforming mapping with identity transform")); } if (!doGeometryRefinement) { pJob->m_spRefGeometry = m_spSelectedRefNode->GetData()->GetGeometry()->Clone().GetPointer(); //check for super/sub sampling if (m_Controls.m_groupActivateSampling->isChecked()) { //change the pixel count and spacing of the geometry mitk::BaseGeometry::BoundsArrayType geoBounds = pJob->m_spRefGeometry->GetBounds(); mitk::Vector3D geoSpacing = pJob->m_spRefGeometry->GetSpacing(); geoSpacing[0] = geoSpacing[0] / m_Controls.m_sbXFactor->value(); geoSpacing[1] = geoSpacing[1] / m_Controls.m_sbYFactor->value(); geoSpacing[2] = geoSpacing[2] / m_Controls.m_sbZFactor->value(); geoBounds[1] = geoBounds[1] * m_Controls.m_sbXFactor->value(); geoBounds[3] = geoBounds[3] * m_Controls.m_sbYFactor->value(); geoBounds[5] = geoBounds[5] * m_Controls.m_sbZFactor->value(); pJob->m_spRefGeometry->SetBounds(geoBounds); pJob->m_spRefGeometry->SetSpacing(geoSpacing); } } pJob->m_MappedName = m_Controls.m_leMappedName->text().toStdString(); pJob->m_allowUndefPixels = m_Controls.m_groupAllowUndefPixels->isChecked(); pJob->m_paddingValue = m_Controls.m_sbPaddingValue->value(); pJob->m_allowUnregPixels = m_Controls.m_groupAllowUnregPixels->isChecked(); pJob->m_errorValue = m_Controls.m_sbErrorValue->value(); pJob->m_InterpolatorLabel = m_Controls.m_comboInterpolator->currentText().toStdString(); switch (m_Controls.m_comboInterpolator->currentIndex()) { case 0: pJob->m_InterpolatorType = mitk::ImageMappingInterpolator::NearestNeighbor; break; case 1: pJob->m_InterpolatorType = mitk::ImageMappingInterpolator::Linear; break; case 2: pJob->m_InterpolatorType = mitk::ImageMappingInterpolator::BSpline_3; break; case 3: pJob->m_InterpolatorType = mitk::ImageMappingInterpolator::WSinc_Hamming; break; case 4: pJob->m_InterpolatorType = mitk::ImageMappingInterpolator::WSinc_Welch; break; } connect(pJob, SIGNAL(Error(QString)), this, SLOT(OnMapJobError(QString))); connect(pJob, SIGNAL(MapResultIsAvailable(mitk::BaseData::Pointer, const QmitkMappingJob*)), this, SLOT(OnMapResultIsAvailable(mitk::BaseData::Pointer, const QmitkMappingJob*)), Qt::BlockingQueuedConnection); connect(pJob, SIGNAL(AlgorithmInfo(QString)), this, SLOT(OnMappingInfo(QString))); m_Controls.m_teLog->append(QString("Started mapping job. Name: ") + m_Controls.m_leMappedName->text() + QString("")); QThreadPool* threadPool = QThreadPool::globalInstance(); threadPool->start(pJob); } void QmitkMatchPointMapper::OnMapJobError(QString err) { Error(err); }; void QmitkMatchPointMapper::OnMapResultIsAvailable(mitk::BaseData::Pointer spMappedData, const QmitkMappingJob* job) { m_Controls.m_teLog->append(QString("Mapped entity stored. Name: ") + QString::fromStdString(job->m_MappedName) + QString("")); mitk::DataNode::Pointer spMappedNode = mitk::generateMappedResultNode(job->m_MappedName, - spMappedData, job->GetRegistration()->getRegistrationUID(), job->m_InputNodeUID, + spMappedData, job->GetRegistration()->getRegistrationUID(), job->m_InputDataUID, job->m_doGeometryRefinement, job->m_InterpolatorLabel); this->GetDataStorage()->Add(spMappedNode); this->GetRenderWindowPart()->RequestUpdate(); this->CheckInputs(); this->ConfigureMappingControls(); }; void QmitkMatchPointMapper::OnMappingInfo(QString info) { m_Controls.m_teLog->append(QString("") + info + QString("")); }; void QmitkMatchPointMapper::OnXFactorChanged(double d) { if (m_Controls.m_cbLinkFactors->isChecked()) { this->m_Controls.m_sbYFactor->setValue(d); this->m_Controls.m_sbZFactor->setValue(d); } } diff --git a/Plugins/org.mitk.gui.qt.matchpoint.visualizer/src/internal/QmitkMatchPointRegistrationVisualizer.cpp b/Plugins/org.mitk.gui.qt.matchpoint.visualizer/src/internal/QmitkMatchPointRegistrationVisualizer.cpp index ca795f7fc9..95810cc919 100644 --- a/Plugins/org.mitk.gui.qt.matchpoint.visualizer/src/internal/QmitkMatchPointRegistrationVisualizer.cpp +++ b/Plugins/org.mitk.gui.qt.matchpoint.visualizer/src/internal/QmitkMatchPointRegistrationVisualizer.cpp @@ -1,846 +1,846 @@ /*=================================================================== 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 "org_mitk_gui_qt_matchpoint_visualizer_Activator.h" // Blueberry #include #include // Mitk #include #include #include -#include +#include #include "mitkRegVisDirectionProperty.h" #include "mitkRegVisStyleProperty.h" #include "mitkRegVisColorStyleProperty.h" #include "mitkRegVisPropertyTags.h" #include "mitkRegVisHelper.h" #include "mitkMatchPointPropertyTags.h" #include "mitkRegistrationHelper.h" // Qmitk #include "QmitkMatchPointRegistrationVisualizer.h" // Qt #include #include const std::string QmitkMatchPointRegistrationVisualizer::VIEW_ID = "org.mitk.views.matchpoint.visualizer"; QmitkMatchPointRegistrationVisualizer::QmitkMatchPointRegistrationVisualizer() : m_Parent(NULL), m_internalUpdateGuard(false), m_spSelectedFOVRefNode(NULL), m_spSelectedRegNode(NULL) { } void QmitkMatchPointRegistrationVisualizer::SetFocus() { //m_Controls->buttonPerformImageProcessing->setFocus(); } void QmitkMatchPointRegistrationVisualizer::CreateConnections() { // show first page connect(m_Controls->m_pbLockReg, SIGNAL(clicked()), this, SLOT(OnLockRegButtonPushed())); connect(m_Controls->m_pbStyleGrid, SIGNAL(clicked()), this, SLOT(OnStyleButtonPushed())); connect(m_Controls->m_pbStyleGlyph, SIGNAL(clicked()), this, SLOT(OnStyleButtonPushed())); connect(m_Controls->m_pbStylePoints, SIGNAL(clicked()), this, SLOT(OnStyleButtonPushed())); connect(m_Controls->m_comboDirection, SIGNAL(currentIndexChanged(int)), this, SLOT(OnDirectionChanged(int))); connect(m_Controls->m_pbUpdateViz, SIGNAL(clicked()), this, SLOT(OnUpdateBtnPushed())); connect(m_Controls->m_pbUseFOVRef, SIGNAL(clicked()), this, SLOT(OnUseFOVRefBtnPushed())); connect(m_Controls->radioColorUni, SIGNAL(toggled(bool)), m_Controls->btnUniColor, SLOT(setEnabled(bool))); connect(m_Controls->radioColorVecMag, SIGNAL(toggled(bool)), m_Controls->groupColorCoding, SLOT(setEnabled(bool))); connect(m_Controls->m_pbStyleGrid, SIGNAL(toggled(bool)), m_Controls->tabGrid, SLOT(setEnabled(bool))); connect(m_Controls->cbVevMagInterlolate, SIGNAL(toggled(bool)), this, SLOT(OnColorInterpolationChecked(bool))); } void QmitkMatchPointRegistrationVisualizer::Error(QString msg) { mitk::StatusBar::GetInstance()->DisplayErrorText(msg.toLatin1()); MITK_ERROR << msg.toStdString().c_str(); } void QmitkMatchPointRegistrationVisualizer::CreateQtPartControl(QWidget* parent) { m_Controls = new Ui::MatchPointRegVisControls; // create GUI widgets from the Qt Designer's .ui file m_Controls->setupUi(parent); m_Parent = parent; this->m_Controls->btnVecMagColorSmall->setDisplayColorName(false); this->m_Controls->btnVecMagColorMedium->setDisplayColorName(false); this->m_Controls->btnVecMagColorLarge->setDisplayColorName(false); this->m_Controls->btnVecMagColorNeg->setDisplayColorName(false); this->m_Controls->btnUniColor->setDisplayColorName(false); this->m_Controls->btnStartGridColor->setDisplayColorName(false); this->CreateConnections(); this->m_Controls->radioColorUni->setChecked(false); this->m_Controls->radioColorVecMag->setChecked(true); this->CheckInputs(); this->LoadStateFromNode(); this->ConfigureVisualizationControls(); } mitk::MAPRegistrationWrapper* QmitkMatchPointRegistrationVisualizer::GetCurrentRegistration() { mitk::MAPRegistrationWrapper* result = NULL; if (this->m_spSelectedRegNode.IsNotNull()) { result = dynamic_cast(this->m_spSelectedRegNode->GetData()); assert(result); } return result; } mitk::DataNode::Pointer QmitkMatchPointRegistrationVisualizer::GetSelectedRegNode() const { mitk::DataNode::Pointer spResult = NULL; typedef QList NodeListType; NodeListType nodes = this->GetDataManagerSelection(); for (NodeListType::iterator pos = nodes.begin(); pos != nodes.end(); ++pos) { if (mitk::MITKRegistrationHelper::IsRegNode(*pos)) { spResult = *pos; break; } } return spResult; } mitk::DataNode::Pointer QmitkMatchPointRegistrationVisualizer::GetRefNodeOfReg(bool target) const { mitk::DataNode::Pointer spResult = NULL; - if (this->m_spSelectedRegNode.IsNotNull()) + if (this->m_spSelectedRegNode.IsNotNull() && m_spSelectedRegNode->GetData()) { std::string nodeName; mitk::BaseProperty* uidProp; if (target) { - uidProp = m_spSelectedRegNode->GetProperty(mitk::nodeProp_RegAlgTargetData); + uidProp = m_spSelectedRegNode->GetData()->GetProperty(mitk::Prop_RegAlgTargetData); } else { - uidProp = m_spSelectedRegNode->GetProperty(mitk::nodeProp_RegAlgMovingData); + uidProp = m_spSelectedRegNode->GetData()->GetProperty(mitk::Prop_RegAlgMovingData); } if (uidProp) { //search for the target node - mitk::NodePredicateProperty::Pointer predicate = mitk::NodePredicateProperty::New(mitk::nodeProp_UID, + mitk::NodePredicateDataProperty::Pointer predicate = mitk::NodePredicateDataProperty::New(mitk::Prop_UID, uidProp); spResult = this->GetDataStorage()->GetNode(predicate); } } return spResult; } mitk::DataNode::Pointer QmitkMatchPointRegistrationVisualizer::GetSelectedDataNode() { typedef QList NodeListType; NodeListType nodes = this->GetDataManagerSelection(); mitk::DataNode::Pointer result; for (NodeListType::iterator pos = nodes.begin(); pos != nodes.end(); ++pos) { if (!mitk::MITKRegistrationHelper::IsRegNode(*pos) && (*pos)->GetData() && (*pos)->GetData()->GetGeometry()) { result = *pos; break; } } return result; } void QmitkMatchPointRegistrationVisualizer::CheckInputs() { mitk::DataNode::Pointer regNode = this->GetSelectedRegNode(); if (!m_Controls->m_pbLockReg->isChecked()) { this->m_spSelectedRegNode = regNode; } this->InitRegNode(); mitk::DataNode::Pointer fovNode = this->GetSelectedDataNode(); if (!m_Controls->m_pbLockFOVRef->isChecked()) { this->m_spSelectedFOVRefNode = fovNode; } } void QmitkMatchPointRegistrationVisualizer::ConfigureVisualizationControls() { if (!m_internalUpdateGuard) { m_internalUpdateGuard = true; m_Controls->groupViz->setVisible(this->m_spSelectedRegNode.IsNotNull()); m_Controls->m_pbUpdateViz->setEnabled(this->m_spSelectedRegNode.IsNotNull()); m_Controls->m_boxSettings->setEnabled(this->m_spSelectedRegNode.IsNotNull()); m_Controls->m_boxStyles->setEnabled(this->m_spSelectedRegNode.IsNotNull()); this->ActualizeRegInfo(this->GetCurrentRegistration()); if (this->m_spSelectedRegNode.IsNull()) { m_Controls->m_lbRegistrationName->setText( QString("no registration selected!")); } else { m_Controls->m_lbRegistrationName->setText(QString::fromStdString( this->m_spSelectedRegNode->GetName())); } this->m_Controls->m_pbLockReg->setEnabled(this->m_spSelectedRegNode.IsNotNull()); this->m_Controls->m_pbUseFOVRef->setEnabled(this->m_spSelectedRegNode.IsNotNull() && this->m_spSelectedFOVRefNode.IsNotNull()); this->m_Controls->m_checkUseRefSize->setEnabled(this->m_spSelectedRegNode.IsNotNull() && this->m_spSelectedFOVRefNode.IsNotNull()); this->m_Controls->m_checkUseRefOrigin->setEnabled(this->m_spSelectedRegNode.IsNotNull() && this->m_spSelectedFOVRefNode.IsNotNull()); this->m_Controls->m_checkUseRefSpacing->setEnabled(this->m_spSelectedRegNode.IsNotNull() && this->m_spSelectedFOVRefNode.IsNotNull()); this->m_Controls->m_pbLockFOVRef->setEnabled(this->m_spSelectedFOVRefNode.IsNotNull()); if (this->m_spSelectedFOVRefNode.IsNull()) { m_Controls->m_lbFOVRef->setText(QString("no valid reference selected!")); } else { m_Controls->m_lbFOVRef->setText(QString::fromStdString(this->m_spSelectedFOVRefNode->GetName())); } m_internalUpdateGuard = false; } } void QmitkMatchPointRegistrationVisualizer::StoreStateInNode() { if (this->m_spSelectedRegNode.IsNotNull()) { //general this->m_spSelectedRegNode->SetProperty(mitk::nodeProp_RegVisDirection, mitk::RegVisDirectionProperty::New(this->m_Controls->m_comboDirection->currentIndex())); this->m_spSelectedRegNode->SetBoolProperty(mitk::nodeProp_RegVisGrid, this->m_Controls->m_pbStyleGrid->isChecked()); this->m_spSelectedRegNode->SetBoolProperty(mitk::nodeProp_RegVisGlyph, this->m_Controls->m_pbStyleGlyph->isChecked()); this->m_spSelectedRegNode->SetBoolProperty(mitk::nodeProp_RegVisPoints, this->m_Controls->m_pbStylePoints->isChecked()); //Visualization if (this->m_Controls->radioColorUni->isChecked()) { this->m_spSelectedRegNode->SetProperty(mitk::nodeProp_RegVisColorStyle, mitk::RegVisColorStyleProperty::New(0)); } else { this->m_spSelectedRegNode->SetProperty(mitk::nodeProp_RegVisColorStyle, mitk::RegVisColorStyleProperty::New(1)); } float tmpColor[3]; tmpColor[0] = this->m_Controls->btnUniColor->color().redF(); tmpColor[1] = this->m_Controls->btnUniColor->color().greenF(); tmpColor[2] = this->m_Controls->btnUniColor->color().blueF(); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisColorUni, mitk::ColorProperty::New(tmpColor), NULL, true); tmpColor[0] = this->m_Controls->btnVecMagColorNeg->color().redF(); tmpColor[1] = this->m_Controls->btnVecMagColorNeg->color().greenF(); tmpColor[2] = this->m_Controls->btnVecMagColorNeg->color().blueF(); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisColor1Value, mitk::ColorProperty::New(tmpColor), NULL, true); tmpColor[0] = this->m_Controls->btnVecMagColorSmall->color().redF(); tmpColor[1] = this->m_Controls->btnVecMagColorSmall->color().greenF(); tmpColor[2] = this->m_Controls->btnVecMagColorSmall->color().blueF(); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisColor2Value, mitk::ColorProperty::New(tmpColor), NULL, true); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisColor2Magnitude, mitk::DoubleProperty::New(this->m_Controls->sbVecMagSmall->value()), NULL, true); tmpColor[0] = this->m_Controls->btnVecMagColorMedium->color().redF(); tmpColor[1] = this->m_Controls->btnVecMagColorMedium->color().greenF(); tmpColor[2] = this->m_Controls->btnVecMagColorMedium->color().blueF(); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisColor3Value, mitk::ColorProperty::New(tmpColor), NULL, true); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisColor3Magnitude, mitk::DoubleProperty::New(this->m_Controls->sbVecMagMedium->value()), NULL, true); tmpColor[0] = this->m_Controls->btnVecMagColorLarge->color().redF(); tmpColor[1] = this->m_Controls->btnVecMagColorLarge->color().greenF(); tmpColor[2] = this->m_Controls->btnVecMagColorLarge->color().blueF(); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisColor4Value, mitk::ColorProperty::New(tmpColor), NULL, true); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisColor4Magnitude, mitk::DoubleProperty::New(this->m_Controls->sbVecMagLarge->value()), NULL, true); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisColorInterpolate, mitk::BoolProperty::New(this->m_Controls->cbVevMagInterlolate->isChecked()), NULL, true); //Grid Settings this->m_spSelectedRegNode->SetIntProperty(mitk::nodeProp_RegVisGridFrequence, this->m_Controls->m_sbGridFrequency->value()); this->m_spSelectedRegNode->SetBoolProperty(mitk::nodeProp_RegVisGridShowStart, this->m_Controls->m_groupShowStartGrid->isChecked()); tmpColor[0] = this->m_Controls->btnStartGridColor->color().redF(); tmpColor[1] = this->m_Controls->btnStartGridColor->color().greenF(); tmpColor[2] = this->m_Controls->btnStartGridColor->color().blueF(); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisGridStartColor, mitk::ColorProperty::New(tmpColor), NULL, true); //FOV mitk::Vector3D value; value[0] = this->m_Controls->m_sbFOVSizeX->value(); value[1] = this->m_Controls->m_sbFOVSizeY->value(); value[2] = this->m_Controls->m_sbFOVSizeZ->value(); this->m_spSelectedRegNode->SetProperty(mitk::nodeProp_RegVisFOVSize, mitk::Vector3DProperty::New(value)); value[0] = this->m_Controls->m_sbGridSpX->value(); value[1] = this->m_Controls->m_sbGridSpY->value(); value[2] = this->m_Controls->m_sbGridSpZ->value(); this->m_spSelectedRegNode->SetProperty(mitk::nodeProp_RegVisFOVSpacing, mitk::Vector3DProperty::New(value)); mitk::Point3D origin; origin[0] = this->m_Controls->m_sbFOVOriginX->value(); origin[1] = this->m_Controls->m_sbFOVOriginY->value(); origin[2] = this->m_Controls->m_sbFOVOriginZ->value(); this->m_spSelectedRegNode->SetProperty(mitk::nodeProp_RegVisFOVOrigin, mitk::Point3dProperty::New(origin)); mitk::Vector3D orientationRow1; mitk::Vector3D orientationRow2; mitk::Vector3D orientationRow3; orientationRow1.SetVnlVector(m_FOVRefOrientation.GetVnlMatrix().get_row(0)); orientationRow2.SetVnlVector(m_FOVRefOrientation.GetVnlMatrix().get_row(1)); orientationRow3.SetVnlVector(m_FOVRefOrientation.GetVnlMatrix().get_row(2)); this->m_spSelectedRegNode->SetProperty(mitk::nodeProp_RegVisFOVOrientation1, mitk::Vector3DProperty::New(orientationRow1)); this->m_spSelectedRegNode->SetProperty(mitk::nodeProp_RegVisFOVOrientation2, mitk::Vector3DProperty::New(orientationRow2)); this->m_spSelectedRegNode->SetProperty(mitk::nodeProp_RegVisFOVOrientation3, mitk::Vector3DProperty::New(orientationRow3)); } } void QmitkMatchPointRegistrationVisualizer::LoadStateFromNode() { if (this->m_spSelectedRegNode.IsNotNull()) { mitk::RegVisDirectionProperty* directionProp = NULL; if (this->m_spSelectedRegNode->GetProperty(directionProp, mitk::nodeProp_RegVisDirection)) { this->m_Controls->m_comboDirection->setCurrentIndex(directionProp->GetValueAsId()); } else { this->Error(QString("Cannot configure plugin controlls correctly. Node property ") + QString( mitk::nodeProp_RegVisDirection) + QString(" has not the assumed type.")); } bool styleActive = false; if (this->m_spSelectedRegNode->GetBoolProperty(mitk::nodeProp_RegVisGrid, styleActive)) { this->m_Controls->m_pbStyleGrid->setChecked(styleActive); this->m_Controls->tabGrid->setEnabled(styleActive); } else { this->Error(QString("Cannot configure plugin controlls correctly. Node property ") + QString( mitk::nodeProp_RegVisGrid) + QString(" has not the assumed type.")); } if (this->m_spSelectedRegNode->GetBoolProperty(mitk::nodeProp_RegVisGlyph, styleActive)) { this->m_Controls->m_pbStyleGlyph->setChecked(styleActive); } else { this->Error(QString("Cannot configure plugin controlls correctly. Node property ") + QString( mitk::nodeProp_RegVisGlyph) + QString(" has not the assumed type.")); } if (this->m_spSelectedRegNode->GetBoolProperty(mitk::nodeProp_RegVisPoints, styleActive)) { this->m_Controls->m_pbStylePoints->setChecked(styleActive); } else { this->Error(QString("Cannot configure plugin controlls correctly. Node property ") + QString( mitk::nodeProp_RegVisPoints) + QString(" has not the assumed type.")); } /////////////////////////////////////////////////////// //visualization mitk::RegVisColorStyleProperty* colorStyleProp = NULL; if (this->m_spSelectedRegNode->GetProperty(colorStyleProp, mitk::nodeProp_RegVisColorStyle)) { this->m_Controls->radioColorUni->setChecked(colorStyleProp->GetValueAsId() == 0); this->m_Controls->radioColorVecMag->setChecked(colorStyleProp->GetValueAsId() == 1); } else { this->Error(QString("Cannot configure plugin controlls correctly. Node property ") + QString( mitk::nodeProp_RegVisColorStyle) + QString(" has not the assumed type.")); } QColor tmpColor; float colorUni[3] = { 0.0, 0.0, 0.0 }; this->m_spSelectedRegNode->GetColor(colorUni, NULL, mitk::nodeProp_RegVisColorUni); tmpColor.setRgbF(colorUni[0], colorUni[1], colorUni[2]); this->m_Controls->btnUniColor->setColor(tmpColor); float color1[3] = { 0.0, 0.0, 0.0 }; this->m_spSelectedRegNode->GetColor(color1, NULL, mitk::nodeProp_RegVisColor1Value); tmpColor.setRgbF(color1[0], color1[1], color1[2]); this->m_Controls->btnVecMagColorNeg->setColor(tmpColor); float color2[3] = { 0.25, 0.25, 0.25 }; this->m_spSelectedRegNode->GetColor(color2, NULL, mitk::nodeProp_RegVisColor2Value); tmpColor.setRgbF(color2[0], color2[1], color2[2]); this->m_Controls->btnVecMagColorSmall->setColor(tmpColor); float color3[3] = { 0.5, 0.5, 0.5 }; this->m_spSelectedRegNode->GetColor(color3, NULL, mitk::nodeProp_RegVisColor3Value); tmpColor.setRgbF(color3[0], color3[1], color3[2]); this->m_Controls->btnVecMagColorMedium->setColor(tmpColor); float color4[3] = { 1.0, 1.0, 1.0 }; this->m_spSelectedRegNode->GetColor(color4, NULL, mitk::nodeProp_RegVisColor4Value); tmpColor.setRgbF(color4[0], color4[1], color4[2]); this->m_Controls->btnVecMagColorLarge->setColor(tmpColor); double mag2 = 0; this->m_spSelectedRegNode->GetPropertyValue(mitk::nodeProp_RegVisColor2Magnitude, mag2); double mag3 = 0; this->m_spSelectedRegNode->GetPropertyValue(mitk::nodeProp_RegVisColor3Magnitude, mag3); double mag4 = 0; this->m_spSelectedRegNode->GetPropertyValue(mitk::nodeProp_RegVisColor4Magnitude, mag4); bool interpolate = true; this->m_spSelectedRegNode->GetBoolProperty(mitk::nodeProp_RegVisColorInterpolate, interpolate); this->m_Controls->sbVecMagSmall->setValue(mag2); this->m_Controls->sbVecMagMedium->setValue(mag3); this->m_Controls->sbVecMagLarge->setValue(mag4); this->m_Controls->cbVevMagInterlolate->setChecked(interpolate); /////////////////////////////////////////////////////// //Grid general bool showStart = false; if (this->m_spSelectedRegNode->GetBoolProperty(mitk::nodeProp_RegVisGridShowStart, showStart)) { this->m_Controls->m_groupShowStartGrid->setChecked(showStart); } else { this->Error(QString("Cannot configure plugin controlls correctly. Node property ") + QString( mitk::nodeProp_RegVisGridShowStart) + QString(" is not correctly defined.")); } int gridFrequ = 5; if (this->m_spSelectedRegNode->GetIntProperty(mitk::nodeProp_RegVisGridFrequence, gridFrequ)) { this->m_Controls->m_sbGridFrequency->setValue(gridFrequ); } else { this->Error(QString("Cannot configure plugin controlls correctly. Node property ") + QString( mitk::nodeProp_RegVisGridFrequence) + QString(" is not correctly defined.")); } float colorStart[3] = { 0.0, 0.0, 0.0 }; this->m_spSelectedRegNode->GetColor(colorStart, NULL, mitk::nodeProp_RegVisGridStartColor); tmpColor.setRgbF(colorStart[0], colorStart[1], colorStart[2]); this->m_Controls->btnStartGridColor->setColor(tmpColor); /////////////////////////////////////////////////////// //FOV mitk::Vector3DProperty* valueProp = NULL; if (this->m_spSelectedRegNode->GetProperty(valueProp, mitk::nodeProp_RegVisFOVSize)) { this->m_Controls->m_sbFOVSizeX->setValue(valueProp->GetValue()[0]); this->m_Controls->m_sbFOVSizeY->setValue(valueProp->GetValue()[1]); this->m_Controls->m_sbFOVSizeZ->setValue(valueProp->GetValue()[2]); } else { this->Error(QString("Cannot configure plugin controlls correctly. Node property ") + QString( mitk::nodeProp_RegVisFOVSize) + QString(" is not correctly defined.")); } if (this->m_spSelectedRegNode->GetProperty(valueProp, mitk::nodeProp_RegVisFOVSpacing)) { this->m_Controls->m_sbGridSpX->setValue(valueProp->GetValue()[0]); this->m_Controls->m_sbGridSpY->setValue(valueProp->GetValue()[1]); this->m_Controls->m_sbGridSpZ->setValue(valueProp->GetValue()[2]); } else { this->Error(QString("Cannot configure plugin controlls correctly. Node property ") + QString( mitk::nodeProp_RegVisFOVSpacing) + QString(" is not correctly defined.")); } mitk::Point3dProperty* originProp = NULL; if (this->m_spSelectedRegNode->GetProperty(originProp, mitk::nodeProp_RegVisFOVOrigin)) { this->m_Controls->m_sbFOVOriginX->setValue(originProp->GetValue()[0]); this->m_Controls->m_sbFOVOriginY->setValue(originProp->GetValue()[1]); this->m_Controls->m_sbFOVOriginZ->setValue(originProp->GetValue()[2]); } else { this->Error(QString("Cannot configure plugin controlls correctly. Node property ") + QString( mitk::nodeProp_RegVisFOVOrigin) + QString(" is not correctly defined.")); } mitk::Vector3DProperty* orientationProp1; mitk::Vector3DProperty* orientationProp2; mitk::Vector3DProperty* orientationProp3; if (this->m_spSelectedRegNode->GetProperty(orientationProp1, mitk::nodeProp_RegVisFOVOrientation1) && this->m_spSelectedRegNode->GetProperty(orientationProp2, mitk::nodeProp_RegVisFOVOrientation2) && this->m_spSelectedRegNode->GetProperty(orientationProp3, mitk::nodeProp_RegVisFOVOrientation3)) { this->m_Controls->m_sbFOVOriginX->setValue(originProp->GetValue()[0]); this->m_Controls->m_sbFOVOriginY->setValue(originProp->GetValue()[1]); this->m_Controls->m_sbFOVOriginZ->setValue(originProp->GetValue()[2]); m_FOVRefOrientation.GetVnlMatrix().set_row(0, orientationProp1->GetValue().GetVnlVector()); m_FOVRefOrientation.GetVnlMatrix().set_row(1, orientationProp2->GetValue().GetVnlVector()); m_FOVRefOrientation.GetVnlMatrix().set_row(2, orientationProp3->GetValue().GetVnlVector()); } else { m_FOVRefOrientation.SetIdentity(); this->Error(QString("Cannot configure plugin controlls correctly. One of the node propertiesy ") + QString(mitk::nodeProp_RegVisFOVOrientation1) + QString(mitk::nodeProp_RegVisFOVOrientation2) + QString(mitk::nodeProp_RegVisFOVOrientation3) + QString(" is not correctly defined.")); } this->UpdateOrientationMatrixWidget(); } } void QmitkMatchPointRegistrationVisualizer::CheckAndSetDefaultFOVRef() { //check if node has a default reference node. mitk::DataNode::Pointer defaultRef = this->GetRefNodeOfReg( this->m_Controls->m_comboDirection->currentIndex() == 1); //direction value 1 = show inverse mapping -> we need the target image used for the registration. //if there is a default node and no m_spSelectedFOVRefNode is set -> set default node and transfer values if (defaultRef.IsNotNull() && this->m_spSelectedFOVRefNode.IsNull() && !(this->m_Controls->m_pbLockFOVRef->isDown())) { //there is a default ref and no ref lock -> select default ref and transfer its values this->m_spSelectedFOVRefNode = defaultRef; this->m_Controls->m_checkUseRefSize->setChecked(true); this->m_Controls->m_checkUseRefOrigin->setChecked(true); this->m_Controls->m_checkUseRefSpacing->setChecked(true); this->m_Controls->m_checkUseRefOrientation->setChecked(true); //auto transfere values this->OnUseFOVRefBtnPushed(); } } void QmitkMatchPointRegistrationVisualizer::OnSelectionChanged( berry::IWorkbenchPart::Pointer /*source*/, const QList& nodes) { this->CheckInputs(); this->LoadStateFromNode(); this->CheckAndSetDefaultFOVRef(); this->ConfigureVisualizationControls(); } void QmitkMatchPointRegistrationVisualizer::ActualizeRegInfo(mitk::MAPRegistrationWrapper* currentReg) { std::stringstream descriptionString; m_Controls->m_teRegInfo->clear(); if (currentReg) { descriptionString << "Moving dimension: " << currentReg->GetMovingDimensions() << "
"; descriptionString << "Target dimension: " << currentReg->GetTargetDimensions() << "
"; descriptionString << "Limited moving representation: " << currentReg->HasLimitedMovingRepresentation() << "
"; descriptionString << "Limited target representation: " << currentReg->HasLimitedTargetRepresentation() << "
"; mitk::MAPRegistrationWrapper::TagMapType tagMap = currentReg->GetTags(); descriptionString << "
Tags:
"; for (mitk::MAPRegistrationWrapper::TagMapType::const_iterator pos = tagMap.begin(); pos != tagMap.end(); ++pos) { descriptionString << pos->first << " : " << pos->second << "
"; } } else { descriptionString << "no registration selected!"; } m_Controls->m_teRegInfo->insertHtml(QString::fromStdString(descriptionString.str())); } void QmitkMatchPointRegistrationVisualizer::OnDirectionChanged(int index) { this->CheckAndSetDefaultFOVRef(); this->ConfigureVisualizationControls(); }; void QmitkMatchPointRegistrationVisualizer::OnLockRegButtonPushed() { if (this->m_Controls->m_pbLockReg->isChecked()) { if (this->m_spSelectedRegNode.IsNotNull()) { this->m_spSelectedRegNode->SetSelected(false); this->GetDataStorage()->Modified(); } } this->CheckInputs(); this->ConfigureVisualizationControls(); } void QmitkMatchPointRegistrationVisualizer::OnUpdateBtnPushed() { this->StoreStateInNode(); mitk::Geometry3D::Pointer gridDesc; unsigned int gridFrequ = 5; mitk::GetGridGeometryFromNode(this->m_spSelectedRegNode, gridDesc, gridFrequ); this->GetCurrentRegistration()->SetGeometry(gridDesc); mitk::RenderingManager::GetInstance()->ForceImmediateUpdateAll(); } void QmitkMatchPointRegistrationVisualizer::OnStyleButtonPushed() { } void QmitkMatchPointRegistrationVisualizer::OnColorInterpolationChecked(bool checked) { if (checked) { this->m_Controls->labelVecMagSmall->setText(QString("=")); this->m_Controls->labelVecMagMedium->setText(QString("=")); this->m_Controls->labelVecMagLarge->setText(QString("=")); } else { this->m_Controls->labelVecMagSmall->setText(QString(">")); this->m_Controls->labelVecMagMedium->setText(QString(">")); this->m_Controls->labelVecMagLarge->setText(QString(">")); } }; mitk::ScalarType QmitkMatchPointRegistrationVisualizer::GetSaveSpacing(mitk::ScalarType gridRes, mitk::ScalarType spacing, unsigned int maxGridRes) const { mitk::ScalarType newSpacing = spacing; mitk::ScalarType scaling = gridRes / maxGridRes; if (scaling > 1.0) { newSpacing = spacing * scaling; } return newSpacing; } void QmitkMatchPointRegistrationVisualizer::OnUseFOVRefBtnPushed() { if (this->m_spSelectedFOVRefNode.IsNotNull()) { assert(this->m_spSelectedFOVRefNode->GetData()); assert(this->m_spSelectedFOVRefNode->GetData()->GetGeometry()); mitk::BaseGeometry* gridRef = this->m_spSelectedFOVRefNode->GetData()->GetGeometry(); mitk::Vector3D spacing = gridRef->GetSpacing(); mitk::Point3D origin = gridRef->GetOrigin(); mitk::Geometry3D::BoundsArrayType bounds = gridRef->GetBounds(); mitk::AffineTransform3D::ConstPointer fovTransform = gridRef->GetIndexToWorldTransform(); if (this->m_Controls->m_checkUseRefSize->isChecked()) { this->m_Controls->m_sbFOVSizeX->setValue((bounds[1] - bounds[0])*spacing[0]); this->m_Controls->m_sbFOVSizeY->setValue((bounds[3] - bounds[2])*spacing[1]); this->m_Controls->m_sbFOVSizeZ->setValue((bounds[5] - bounds[4])*spacing[2]); } if (this->m_Controls->m_checkUseRefSpacing->isChecked()) { this->m_Controls->m_sbGridSpX->setValue(GetSaveSpacing((bounds[1] - bounds[0]), spacing[0], 20)); this->m_Controls->m_sbGridSpY->setValue(GetSaveSpacing((bounds[3] - bounds[2]), spacing[1], 20)); this->m_Controls->m_sbGridSpZ->setValue(GetSaveSpacing((bounds[5] - bounds[4]), spacing[2], 20)); } if (this->m_Controls->m_checkUseRefOrigin->isChecked()) { this->m_Controls->m_sbFOVOriginX->setValue(origin[0]); this->m_Controls->m_sbFOVOriginY->setValue(origin[1]); this->m_Controls->m_sbFOVOriginZ->setValue(origin[2]); } if (this->m_Controls->m_checkUseRefOrientation->isChecked()) { this->m_FOVRefOrientation = fovTransform->GetMatrix(); this->UpdateOrientationMatrixWidget(); } } } void QmitkMatchPointRegistrationVisualizer::UpdateOrientationMatrixWidget() { for (unsigned int r = 0; r < 3; ++r) { for (unsigned int c = 0; c < 3; ++c) { this->m_Controls->m_tableOrientation->item(r, c)->setText(QString::number(this->m_FOVRefOrientation.GetVnlMatrix().get(r, c))); } } } void QmitkMatchPointRegistrationVisualizer::InitRegNode() { if (this->m_spSelectedRegNode.IsNotNull()) { this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisGrid, mitk::BoolProperty::New(true)); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisGlyph, mitk::BoolProperty::New(false)); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisPoints, mitk::BoolProperty::New(false)); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisDirection, mitk::RegVisDirectionProperty::New()); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisColorStyle, mitk::RegVisColorStyleProperty::New(1)); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisColorUni, mitk::ColorProperty::New(0, 0.5, 0)); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisGridFrequence, mitk::IntProperty::New(3)); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisGridShowStart, mitk::BoolProperty::New(false)); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisGridStartColor, mitk::ColorProperty::New(0.5, 0, 0)); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisFOVSize, mitk::Vector3DProperty::New(mitk::Vector3D(100.0))); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisFOVSpacing, mitk::Vector3DProperty::New(mitk::Vector3D(5.0))); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisColor1Value, mitk::ColorProperty::New(0, 0, 0.5)); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisColor2Value, mitk::ColorProperty::New(0, 0.7, 0)); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisColor2Magnitude, mitk::DoubleProperty::New(1)); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisColor3Value, mitk::ColorProperty::New(1, 1, 0)); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisColor3Magnitude, mitk::DoubleProperty::New(5)); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisColor4Value, mitk::ColorProperty::New(1, 0, 0)); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisColor4Magnitude, mitk::DoubleProperty::New(15)); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisColorInterpolate, mitk::BoolProperty::New(true)); mitk::Point3D origin; origin.Fill(0.0); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisFOVOrigin, mitk::Point3dProperty::New(mitk::Point3D(origin))); mitk::Vector3D vec(0.0); vec.SetElement(0, 1.0); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisFOVOrientation1, mitk::Vector3DProperty::New(vec)); vec.Fill(0.0); vec.SetElement(1, 1.0); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisFOVOrientation2, mitk::Vector3DProperty::New(vec)); vec.Fill(0.0); vec.SetElement(2, 1.0); this->m_spSelectedRegNode->AddProperty(mitk::nodeProp_RegVisFOVOrientation3, mitk::Vector3DProperty::New(vec)); } }