Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "QmitkMappingJob.h"
18 
19 // Mitk
20 #include <mitkImageAccessByItk.h>
24 #include <mitkProperties.h>
25 
26 // Qt
27 #include <QThreadPool>
28 
29 #include <mapEvents.h>
30 
32 {
33  m_doGeometryRefinement = false;
34  m_MappedName = "";
35  m_allowUndefPixels = true;
36  m_paddingValue = 0;
37  m_allowUnregPixels = true;
38  m_errorValue = 0;
40 };
41 
43 {
44  return dynamic_cast<const mitk::Image *>(m_spInputData.GetPointer());
45 };
46 
48 {
49  return dynamic_cast<const mitk::PointSet *>(m_spInputData.GetPointer());
50 };
51 
52 const map::core::RegistrationBase *QmitkMappingJob::GetRegistration() const
53 {
54  const mitk::MAPRegistrationWrapper *wrapper =
55  dynamic_cast<const mitk::MAPRegistrationWrapper *>(m_spRegNode->GetData());
56 
57  return dynamic_cast<const map::core::RegistrationBase *>(wrapper->GetRegistration());
58 };
59 
60 void QmitkMappingJob::OnMapAlgorithmEvent(::itk::Object *, const itk::EventObject &event)
61 {
62  const map::events::AnyMatchPointEvent *pMAPEvent = dynamic_cast<const map::events::AnyMatchPointEvent *>(&event);
63 
64  if (pMAPEvent)
65  {
66  emit AlgorithmInfo(QString::fromStdString(pMAPEvent->getComment()));
67  }
68 }
69 
71 {
72  m_spRefGeometry = NULL;
73 
75  m_spCommand->SetCallbackFunction(this, &QmitkMappingJob::OnMapAlgorithmEvent);
76 };
77 
79 
81 {
82  const mitk::Image *inputImage = this->GetInputDataAsImage();
83  const mitk::PointSet *inputSet = this->GetInputDataAsPointSet();
84  m_spMappedData = NULL;
85 
87  {
88  try
89  {
90  mitk::Image::Pointer spResultImage = NULL;
91 
92  if (inputImage)
93  {
94  spResultImage = mitk::ImageMappingHelper::refineGeometry(inputImage, this->GetRegistration(), true);
95  }
96 
97  m_spMappedData = spResultImage;
98 
99  if (spResultImage.IsNotNull())
100  {
101  emit MapResultIsAvailable(spResultImage.GetPointer(), this);
102  }
103  else
104  {
105  emit Error(QString("Error when when refining image geometry."));
106  }
107  }
108  catch (std::exception &e)
109  {
110  emit Error(QString("Error when refining image geometry. Error description: ") + QString::fromLatin1(e.what()));
111  }
112  catch (...)
113  {
114  emit Error(QString("Unknown error when refining image geometry."));
115  }
116  }
117  else
118  {
119  try
120  {
121  mitk::BaseData::Pointer spResultData = NULL;
122 
123  if (inputImage)
124  {
125  spResultData = mitk::ImageMappingHelper::map(this->GetInputDataAsImage(),
126  this->GetRegistration(),
127  !(this->m_allowUndefPixels),
128  this->m_paddingValue,
129  this->m_spRefGeometry,
130  !(this->m_allowUnregPixels),
131  this->m_errorValue,
132  this->m_InterpolatorType)
133  .GetPointer();
134  }
135  else if (inputSet)
136  {
138  errorValue.id = -1;
139  errorValue.pointSpec = mitk::PTUNDEFINED;
140  errorValue.selected = false;
141  spResultData = mitk::PointSetMappingHelper::map(inputSet, this->GetRegistration(), -1, false, errorValue);
142  }
143 
144  if (spResultData.IsNotNull())
145  {
146  emit MapResultIsAvailable(spResultData, this);
147  }
148  else
149  {
150  emit Error(QString("Error when mapping input data to result."));
151  }
152 
153  m_spMappedData = spResultData;
154  }
155  catch (std::exception &e)
156  {
157  emit Error(QString("Error when mapping data. Error description: ") + QString::fromLatin1(e.what()));
158  }
159  catch (...)
160  {
161  emit Error(QString("Unkown error when mapping data."));
162  }
163  }
164 };
void Error(QString err)
void OnMapAlgorithmEvent(::itk::Object *, const itk::EventObject &event)
mitk::BaseData::ConstPointer m_spInputData
struct for data of a point
Definition: mitkPointSet.h:95
mitk::DataNode::Pointer m_spRegNode
const map::core::RegistrationBase * GetRegistration() const
MAPRegistrationWrapper Wrapper class to allow the handling of MatchPoint registration objects as mitk...
mitk::PointSpecificationType pointSpec
Definition: mitkPointSet.h:99
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()
Data structure which stores a set of points. Superclass of mitk::Mesh.
Definition: mitkPointSet.h:79
Image class for storing images.
Definition: mitkImage.h:76
MITKMATCHPOINTREGISTRATION_EXPORT ResultImageType::Pointer refineGeometry(const InputImageType *input, const RegistrationType *registration, bool throwOnError=true)
void AlgorithmInfo(QString info)
::itk::MemberCommand< QmitkMappingJob >::Pointer m_spCommand
mitk::BaseGeometry::Pointer m_spRefGeometry
mitk::BaseData::Pointer m_spMappedData
const mitk::Image * GetInputDataAsImage() const
const mitk::PointSet * GetInputDataAsPointSet() const
mitk::ImageMappingInterpolator::Type m_InterpolatorType
MITKMATCHPOINTREGISTRATION_EXPORT ResultImageType::Pointer map(const InputImageType *input, const RegistrationType *registration, bool throwOnOutOfInputAreaError=false, const double &paddingValue=0, const ResultImageGeometryType *resultGeometry=NULL, bool throwOnMappingError=true, const double &errorValue=0, mitk::ImageMappingInterpolator::Type interpolatorType=mitk::ImageMappingInterpolator::Linear)
void MapResultIsAvailable(mitk::BaseData::Pointer spMappedData, const QmitkMappingJob *job)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.