Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkParameterFitBackgroundJob.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 #include "mitkModelFitInfo.h"
15 
16 void ParameterFitBackgroundJob::OnFitEvent(::itk::Object* caller, const itk::EventObject & event)
17 {
18  itk::ProgressEvent progressEvent;
19  itk::InitializeEvent initEvent;
20  itk::StartEvent startEvent;
21  itk::EndEvent endEvent;
22 
23  if (progressEvent.CheckEvent(&event))
24  {
25  mitk::ParameterFitImageGeneratorBase* castedReporter = dynamic_cast<mitk::ParameterFitImageGeneratorBase*>(caller);
26  emit JobProgress(castedReporter->GetProgress());
27  }
28  else if (initEvent.CheckEvent(&event))
29  {
30  emit JobStatusChanged(QString("Initializing parameter fit generator"));
31  }
32  else if (startEvent.CheckEvent(&event))
33  {
34  emit JobStatusChanged(QString("Started fitting process."));
35  }
36  else if (endEvent.CheckEvent(&event))
37  {
38  emit JobStatusChanged(QString("Finished fitting process."));
39  }
40 }
41 
44 {
45 };
46 
49 {
50  if (!generator)
51  {
52  mitkThrow() << "Cannot create parameter fit background job. Passed fit generator is NULL.";
53  }
54 
55  if (!fitInfo)
56  {
57  mitkThrow() << "Cannot create parameter fit background job. Passed model traits interface is NULL.";
58  }
59 
60  m_Generator = generator;
61  m_ModelFitInfo = fitInfo;
62  m_ParentNode = parentNode;
63  m_AdditionalRelevantNodes = additionalRelevantNodes;
64 
65  m_spCommand = ::itk::MemberCommand<ParameterFitBackgroundJob>::New();
66  m_spCommand->SetCallbackFunction(this, &ParameterFitBackgroundJob::OnFitEvent);
67  m_ObserverID = m_Generator->AddObserver(::itk::AnyEvent(), m_spCommand);
68 };
69 
73 {
74  return m_ParentNode;
75 };
76 
78 {
80 };
81 
82 
85 {
86  m_Generator->RemoveObserver(m_ObserverID);
87 };
88 
89 void
91 run()
92 {
93  try
94  {
95  emit JobStatusChanged(QString("Started fit session.Generate UID: ")+QString::fromStdString(m_ModelFitInfo->uid));
96 
97  m_Generator->Generate();
98 
99  emit JobStatusChanged(QString("Generate result nodes."));
100 
101  m_Results = mitk::modelFit::CreateResultNodeMap(m_Generator->GetParameterImages(), m_Generator->GetDerivedParameterImages(), m_Generator->GetCriterionImages(), m_Generator->GetEvaluationParameterImages(), m_ModelFitInfo);
102 
103  emit ResultsAreAvailable(m_Results, this);
104  }
105  catch (::std::exception& e)
106  {
107  emit Error(QString("Error while fitting data. Details: ")+QString::fromLatin1(e.what()));
108  }
109  catch (...)
110  {
111  emit Error(QString("Unkown error when fitting the data."));
112  }
113 
114  emit Finished();
115 };
void ResultsAreAvailable(mitk::modelFit::ModelFitResultNodeVectorType resultMap, const ParameterFitBackgroundJob *pJob)
void OnFitEvent(::itk::Object *, const itk::EventObject &event)
void JobStatusChanged(QString info)
virtual double GetProgress() const =0
mitk::modelFit::ModelFitResultNodeVectorType m_Results
#define mitkThrow()
std::vector< DataNode::Pointer > ModelFitResultNodeVectorType
MITKMODELFIT_EXPORT ModelFitResultNodeVectorType CreateResultNodeMap(const ModelFitResultImageMapType &results, const ModelFitResultImageMapType &derivedResults, const ModelFitResultImageMapType &criterionResults, const ModelFitResultImageMapType &evaluationResults, const ModelFitInfo *fitInfo)
void JobProgress(double progress)
Data class that stores all information about a modelfit that is relevant to the visualization and sto...
ParameterFitBackgroundJob(mitk::ParameterFitImageGeneratorBase *generator, const mitk::modelFit::ModelFitInfo *fitInfo, mitk::DataNode *parentNode=nullptr)
mitk::modelFit::ModelFitResultNodeVectorType GetAdditionalRelevantNodes() const
mitk::modelFit::ModelFitResultNodeVectorType m_AdditionalRelevantNodes
::itk::MemberCommand< ParameterFitBackgroundJob >::Pointer m_spCommand
mitk::modelFit::ModelFitInfo::ConstPointer m_ModelFitInfo
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57
void Error(QString err)
mitk::ParameterFitImageGeneratorBase::Pointer m_Generator