Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkMultiModalAffine_default.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 "mapDeploymentDLLHelper.h"
18 #include "mapDiscreteElements.h"
19 #include "mapITKAffineMattesMIMultiResRegistrationAlgorithmTemplate.h"
20 #include "mapConfigure.h"
21 
23 
24 namespace mitk
25 {
26  typedef map::core::discrete::Elements<3>::InternalImageType ImageType;
27 
32  class MultiModalAffineDefaultRegistrationAlgorithm :
33  public map::algorithm::boxed::ITKAffineMattesMIMultiResRegistrationAlgorithm<ImageType, ImageType, ::map::algorithm::MITK_MultiModal_affine_defaultUIDPolicy, SealedFixedInterpolatorPolicyMacro< ::itk::LinearInterpolateImageFunction<ImageType, map::core::continuous::ScalarType> >, map::algorithm::itk::NoComponentInitializationPolicy>
34  {
35  public:
36  typedef MultiModalAffineDefaultRegistrationAlgorithm Self;
37 
38  typedef ITKAffineMattesMIMultiResRegistrationAlgorithm<ImageType, ImageType, ::map::algorithm::MITK_MultiModal_affine_defaultUIDPolicy, SealedFixedInterpolatorPolicyMacro< ::itk::LinearInterpolateImageFunction<ImageType, map::core::continuous::ScalarType> >, map::algorithm::itk::NoComponentInitializationPolicy>
39  Superclass;
40 
41  typedef ::itk::SmartPointer<Self> Pointer;
42  typedef ::itk::SmartPointer<const Self> ConstPointer;
43 
44  itkTypeMacro(MultiModalAffineDefaultRegistrationAlgorithm,
45  ITKAffineMattesMIMultiResRegistrationAlgorithm);
46  mapNewAlgorithmMacro(Self);
47 
48  protected:
49  MultiModalAffineDefaultRegistrationAlgorithm()
50  {
51  };
52 
53  virtual ~MultiModalAffineDefaultRegistrationAlgorithm()
54  {
55  };
56 
57  void configureAlgorithm()
58  {
59  Superclass::configureAlgorithm();
60 
61  this->setResolutionLevels(3);
62  this->_preInitialize = true;
63  this->_useCenterOfGravity = false;
64 
65  this->getConcreteOptimizerControl()->getConcreteOptimizer()->SetMaximumStepLength(3.00);
66  this->getConcreteOptimizerControl()->getConcreteOptimizer()->SetMinimumStepLength(0.5);
67  this->getConcreteOptimizerControl()->getConcreteOptimizer()->SetNumberOfIterations(200);
68  this->getConcreteOptimizerControl()->getConcreteOptimizer()->SetRelaxationFactor(0.8);
69  this->getConcreteOptimizerControl()->getConcreteOptimizer()->SetGradientMagnitudeTolerance(1e-4);
70 
71  //metric
72  this->getConcreteMetricControl()->getConcreteMetric()->SetNumberOfHistogramBins(30);
73  this->getConcreteMetricControl()->getConcreteMetric()->SetUseAllPixels(true);
74  this->getConcreteMetricControl()->getConcreteMetric()->ReinitializeSeed();
75  this->getConcreteMetricControl()->getConcreteMetric()->UseExplicitPDFDerivativesOn();
76  }
77 
78  void
79  doInterLevelSetup()
80  {
81  Superclass::doInterLevelSetup();
82 
83  //scale setting
84  int dimCount = ImageType::ImageDimension*ImageType::ImageDimension + ImageType::ImageDimension;
85  int matrixEnd = ImageType::ImageDimension*ImageType::ImageDimension;
86  Superclass::ConcreteOptimizerType::ScalesType scales(dimCount);
87  double matrixScale = 1.0;
88  double transScale = 1.0;
89 
90  if (this->getCurrentLevel() == 0)
91  {
92  matrixScale = 10.0;
93  transScale = 1.0 / 10000;
94  }
95  else
96  {
97  matrixScale = 1.0;
98  transScale = 1.0 / 1000;
99  }
100 
101  for (int i = 0; i < dimCount; ++i)
102  {
103  if (i < matrixEnd)
104  {
105  scales[i] = matrixScale;
106 
107  }
108  else
109  {
110  scales[i] = transScale;
111  }
112  }
113 
114  getConcreteOptimizerControl()->getConcreteOptimizer()->SetScales(scales);
115 
116  //spatial samples setting
117  if (this->getCurrentLevel() != 0)
118  {
119  getConcreteMetricControl()->getConcreteMetric()->SetUseAllPixels(false);
120 
121  unsigned int nrOfSmpl = ::itk::Math::Round<unsigned int, double>
122  (this->getMovingImage()->GetLargestPossibleRegion().GetNumberOfPixels() * 0.30);
123 
124  getConcreteMetricControl()->getConcreteMetric()->SetNumberOfSpatialSamples(nrOfSmpl);
125  }
126  };
127 
128  private:
129 
130  MultiModalAffineDefaultRegistrationAlgorithm(const Self& source); //purposely not implemented
131  void operator=(const Self&); //purposely not implemented
132  };
133 
134 }
135 
136 mapDeployAlgorithmMacro(mitk::MultiModalAffineDefaultRegistrationAlgorithm);
itk::SmartPointer< Self > Pointer
DataCollection - Class to facilitate loading/accessing structured data.
itkEventMacroDeclaration(FocusChangedEvent, itk::AnyEvent) class MITKCORE_EXPORT TestingRenderingManager typedef RenderingManager Superclass
itk::SmartPointer< const Self > ConstPointer
mapDeployAlgorithmMacro(mitk::MultiModalAffineDefaultRegistrationAlgorithm)
map::core::discrete::Elements< 3 >::InternalImageType ImageType