19 #include <QThreadPool> 28 #include <mapAlgorithmEvents.h> 29 #include <mapAlgorithmWrapperEvent.h> 30 #include <mapExceptionObjectMacros.h> 31 #include <mapImageRegistrationAlgorithmInterface.h> 32 #include <mapRegistrationAlgorithmInterface.h> 34 const mitk::Image *QmitkFramesRegistrationJob::GetTargetDataAsImage()
const 41 return m_spLoadedAlgorithm;
44 void QmitkFramesRegistrationJob::OnMapAlgorithmEvent(::itk::Object *,
const itk::EventObject &event)
46 const map::events::AlgorithmEvent *pAlgEvent =
dynamic_cast<const map::events::AlgorithmEvent *
>(&event);
47 const map::events::AlgorithmIterationEvent *pIterationEvent =
48 dynamic_cast<const map::events::AlgorithmIterationEvent *
>(&event);
49 const map::events::AlgorithmWrapperEvent *pWrapEvent =
50 dynamic_cast<const map::events::AlgorithmWrapperEvent *
>(&event);
51 const map::events::AlgorithmResolutionLevelEvent *pLevelEvent =
52 dynamic_cast<const map::events::AlgorithmResolutionLevelEvent *
>(&event);
54 const map::events::InitializingAlgorithmEvent *pInitEvent =
55 dynamic_cast<const map::events::InitializingAlgorithmEvent *
>(&event);
56 const map::events::StartingAlgorithmEvent *pStartEvent =
57 dynamic_cast<const map::events::StartingAlgorithmEvent *
>(&event);
58 const map::events::StoppingAlgorithmEvent *pStoppingEvent =
59 dynamic_cast<const map::events::StoppingAlgorithmEvent *
>(&event);
60 const map::events::StoppedAlgorithmEvent *pStoppedEvent =
61 dynamic_cast<const map::events::StoppedAlgorithmEvent *
>(&event);
62 const map::events::FinalizingAlgorithmEvent *pFinalizingEvent =
63 dynamic_cast<const map::events::FinalizingAlgorithmEvent *
>(&event);
64 const map::events::FinalizedAlgorithmEvent *pFinalizedEvent =
65 dynamic_cast<const map::events::FinalizedAlgorithmEvent *
>(&event);
66 const itk::ProgressEvent *pProgressEvent =
dynamic_cast<const itk::ProgressEvent *
>(&event);
67 const mitk::FrameRegistrationEvent *pFrameRegEvent =
dynamic_cast<const mitk::FrameRegistrationEvent *
>(&event);
68 const mitk::FrameMappingEvent *pFrameMapEvent =
dynamic_cast<const mitk::FrameMappingEvent *
>(&event);
74 else if (pFrameRegEvent)
78 else if (pFrameMapEvent)
90 else if (pStoppingEvent)
94 else if (pStoppedEvent)
98 if (!pStoppedEvent->getComment().empty())
100 emit
AlgorithmInfo(QString(
"Stopping condition: ") + QString::fromStdString(pStoppedEvent->getComment()));
103 else if (pFinalizingEvent)
107 else if (pFinalizedEvent)
111 else if (pIterationEvent)
113 const IIterativeAlgorithm *pIterative =
114 dynamic_cast<const IIterativeAlgorithm *
>(this->m_spLoadedAlgorithm.GetPointer());
116 map::algorithm::facet::IterativeAlgorithmInterface::IterationCountType count = 0;
117 bool hasCount =
false;
119 if (pIterative && pIterative->hasIterationCount())
122 count = pIterative->getCurrentIteration();
125 emit
AlgorithmIterated(QString::fromStdString(pIterationEvent->getComment()), hasCount, count);
127 else if (pLevelEvent)
129 const IMultiResAlgorithm *pResAlg =
130 dynamic_cast<const IMultiResAlgorithm *
>(this->m_spLoadedAlgorithm.GetPointer());
132 map::algorithm::facet::MultiResRegistrationAlgorithmInterface::ResolutionLevelCountType count = 0;
133 bool hasCount =
false;
134 QString
info = QString::fromStdString(pLevelEvent->getComment());
136 if (pResAlg && pResAlg->hasLevelCount())
138 count = pResAlg->getCurrentLevel() + 1;
140 info = QString(
"Level #") + QString::number(pResAlg->getCurrentLevel() + 1) + QString(
" ") +
info;
145 else if (pAlgEvent && !pWrapEvent)
147 emit
AlgorithmInfo(QString::fromStdString(pAlgEvent->getComment()));
152 :
m_TargetDataUID(
"Missing target UID"), m_spLoadedAlgorithm(pAlgorithm)
158 m_spCommand = ::itk::MemberCommand<QmitkFramesRegistrationJob>::New();
159 m_spCommand->SetCallbackFunction(
this, &QmitkFramesRegistrationJob::OnMapAlgorithmEvent);
160 m_ObserverID = m_spLoadedAlgorithm->AddObserver(::map::events::AlgorithmEvent(), m_spCommand);
165 m_spLoadedAlgorithm->RemoveObserver(m_ObserverID);
174 m_helper->Set4DImage(this->GetTargetDataAsImage());
176 m_helper->SetAlgorithm(this->m_spLoadedAlgorithm);
185 m_helper->AddObserver(::map::events::AnyMatchPointEvent(), m_spCommand);
186 m_helper->AddObserver(::itk::ProgressEvent(), m_spCommand);
189 m_spMappedImageNode = m_helper->GetRegisteredImage();
192 if (m_spMappedImageNode.IsNull())
194 emit
Error(QString(
"Error. No registration was determined. No results to store."));
201 catch (::std::exception &e)
203 emit
Error(QString(
"Error while registering data. Details: ") + QString::fromLatin1(e.what()));
207 emit
Error(QString(
"Unkown error when registering data."));
mitk::BaseData::ConstPointer m_spTargetData
void FrameRegistered(double progress)
void FrameMapped(double progress)
void AlgorithmStatusChanged(QString info)
QmitkFramesRegistrationJob(map::algorithm::RegistrationAlgorithmBase *pAlgorithm)
void AlgorithmIterated(QString info, bool hasIterationCount, unsigned long currentIteration)
mitk::NodeUIDType m_TargetDataUID
static void info(const char *fmt,...)
void LevelChanged(QString info, bool hasLevelCount, unsigned long currentLevel)
void FrameProcessed(double progress)
const map::algorithm::RegistrationAlgorithmBase * GetLoadedAlgorithm() const
mitk::Image::ConstPointer m_spTargetMask
Image class for storing images.
mitk::ImageMappingInterpolator::Type m_InterpolatorType
~QmitkFramesRegistrationJob() override
void AlgorithmInfo(QString info)
void ResultIsAvailable(mitk::Image::Pointer spResult, const QmitkFramesRegistrationJob *pJob)
mitk::TimeFramesRegistrationHelper::IgnoreListType m_IgnoreList