Medical Imaging Interaction Toolkit  2018.4.99-9a29ffc6
Medical Imaging Interaction Toolkit
QmitkMappingJob.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 
13 #include "QmitkMappingJob.h"
14 
15 // Mitk
16 #include <mitkImageAccessByItk.h>
20 #include <mitkProperties.h>
21 
22 // Qt
23 #include <QThreadPool>
24 
25 #include <mapEvents.h>
26 
28 {
29  m_doGeometryRefinement = false;
30  m_MappedName = "";
31  m_allowUndefPixels = true;
32  m_paddingValue = 0;
33  m_allowUnregPixels = true;
34  m_errorValue = 0;
36 };
37 
39 {
40  return dynamic_cast<const mitk::Image *>(m_spInputData.GetPointer());
41 };
42 
44 {
45  return dynamic_cast<const mitk::PointSet *>(m_spInputData.GetPointer());
46 };
47 
48 const map::core::RegistrationBase *QmitkMappingJob::GetRegistration() const
49 {
50  const mitk::MAPRegistrationWrapper *wrapper =
51  dynamic_cast<const mitk::MAPRegistrationWrapper *>(m_spRegNode->GetData());
52 
53  return dynamic_cast<const map::core::RegistrationBase *>(wrapper->GetRegistration());
54 };
55 
56 void QmitkMappingJob::OnMapAlgorithmEvent(::itk::Object *, const itk::EventObject &event)
57 {
58  const map::events::AnyMatchPointEvent *pMAPEvent = dynamic_cast<const map::events::AnyMatchPointEvent *>(&event);
59 
60  if (pMAPEvent)
61  {
62  emit AlgorithmInfo(QString::fromStdString(pMAPEvent->getComment()));
63  }
64 }
65 
67 {
68  m_spRefGeometry = nullptr;
69 
70  m_spCommand = ::itk::MemberCommand<QmitkMappingJob>::New();
71  m_spCommand->SetCallbackFunction(this, &QmitkMappingJob::OnMapAlgorithmEvent);
72 };
73 
75 
77 {
78  const mitk::Image *inputImage = this->GetInputDataAsImage();
79  const mitk::PointSet *inputSet = this->GetInputDataAsPointSet();
80  m_spMappedData = nullptr;
81 
83  {
84  try
85  {
86  mitk::Image::Pointer spResultImage = nullptr;
87 
88  if (inputImage)
89  {
90  spResultImage = mitk::ImageMappingHelper::refineGeometry(inputImage, this->GetRegistration(), true);
91  }
92 
93  m_spMappedData = spResultImage;
94 
95  if (spResultImage.IsNotNull())
96  {
97  emit MapResultIsAvailable(spResultImage.GetPointer(), this);
98  }
99  else
100  {
101  emit Error(QString("Error when when refining image geometry."));
102  }
103  }
104  catch (std::exception &e)
105  {
106  emit Error(QString("Error when refining image geometry. Error description: ") + QString::fromLatin1(e.what()));
107  }
108  catch (...)
109  {
110  emit Error(QString("Unknown error when refining image geometry."));
111  }
112  }
113  else
114  {
115  try
116  {
117  mitk::BaseData::Pointer spResultData = nullptr;
118 
119  if (inputImage)
120  {
121  spResultData = mitk::ImageMappingHelper::map(this->GetInputDataAsImage(),
122  this->GetRegistration(),
123  !(this->m_allowUndefPixels),
124  this->m_paddingValue,
125  this->m_spRefGeometry,
126  !(this->m_allowUnregPixels),
127  this->m_errorValue,
128  this->m_InterpolatorType)
129  .GetPointer();
130  }
131  else if (inputSet)
132  {
134  errorValue.id = -1;
135  errorValue.pointSpec = mitk::PTUNDEFINED;
136  errorValue.selected = false;
137  spResultData = mitk::PointSetMappingHelper::map(inputSet, this->GetRegistration(), -1, false, errorValue);
138  }
139 
140  if (spResultData.IsNotNull())
141  {
142  emit MapResultIsAvailable(spResultData, this);
143  }
144  else
145  {
146  emit Error(QString("Error when mapping input data to result."));
147  }
148 
149  m_spMappedData = spResultData;
150  }
151  catch (std::exception &e)
152  {
153  emit Error(QString("Error when mapping data. Error description: ") + QString::fromLatin1(e.what()));
154  }
155  catch (...)
156  {
157  emit Error(QString("Unkown error when mapping data."));
158  }
159  }
160 };
void OnMapAlgorithmEvent(::itk::Object *, const itk::EventObject &event)
const mitk::Image * GetInputDataAsImage() const
const map::core::RegistrationBase * GetRegistration() const
~QmitkMappingJob() override
struct for data of a point
Definition: mitkPointSet.h:93
MAPRegistrationWrapper Wrapper class to allow the handling of MatchPoint registration objects as mitk...
mitk::PointSpecificationType pointSpec
Definition: mitkPointSet.h:97
MITKMATCHPOINTREGISTRATION_EXPORT ::mitk::PointSet::Pointer map(const ::mitk::PointSet *input, const RegistrationType *registration, int timeStep=-1, bool throwOnMappingError=true, const ::mitk::PointSet::PointDataType &errorPointValue=::mitk::PointSet::PointDataType())
::map::core::RegistrationBase * GetRegistration()
void run() override
Data structure which stores a set of points. Superclass of mitk::Mesh.
Definition: mitkPointSet.h:75
Image class for storing images.
Definition: mitkImage.h:72
MITKMATCHPOINTREGISTRATION_EXPORT ResultImageType::Pointer refineGeometry(const InputImageType *input, const RegistrationType *registration, bool throwOnError=true)
MITKMATCHPOINTREGISTRATION_EXPORT ResultImageType::Pointer map(const InputImageType *input, const RegistrationType *registration, bool throwOnOutOfInputAreaError=false, const double &paddingValue=0, const ResultImageGeometryType *resultGeometry=nullptr, bool throwOnMappingError=true, const double &errorValue=0, mitk::ImageMappingInterpolator::Type interpolatorType=mitk::ImageMappingInterpolator::Linear)
mitk::ImageMappingInterpolator::Type m_InterpolatorType
const mitk::PointSet * GetInputDataAsPointSet() const