17 #ifndef MITKPYRAMIDREGISTRATIONMETHODHELPER_H
18 #define MITKPYRAMIDREGISTRATIONMETHODHELPER_H
22 #include <itkCommand.h>
24 #include <itkRegularStepGradientDescentOptimizer.h>
25 #include <itkMattesMutualInformationImageToImageMetricv4.h>
26 #include <itkCorrelationImageToImageMetricv4.h>
27 #include <itkGradientDescentLineSearchOptimizerv4.h>
29 #include <itkImageRegistrationMethodv4.h>
31 #include <itkAffineTransform.h>
32 #include <itkEuler3DTransform.h>
34 #include <itkMattesMutualInformationImageToImageMetric.h>
35 #include <itkNormalizedCorrelationImageToImageMetric.h>
37 #include <itkMultiResolutionImageRegistrationMethod.h>
38 #include <itkImageMomentsCalculator.h>
47 #define AccessTwoImagesFixedDimensionTypeSubsetByItk(mitkImage1, mitkImage2, itkImageTypeFunction, dimension) \
49 const mitk::PixelType& pixelType1 = mitkImage1->GetPixelType(); \
50 const mitk::PixelType& pixelType2 = mitkImage2->GetPixelType(); \
51 const mitk::Image* constImage1 = mitkImage1; \
52 const mitk::Image* constImage2 = mitkImage2; \
53 mitk::Image* nonConstImage1 = const_cast<mitk::Image*>(constImage1); \
54 mitk::Image* nonConstImage2 = const_cast<mitk::Image*>(constImage2); \
55 nonConstImage1->Update(); \
56 nonConstImage2->Update(); \
57 _checkSpecificDimension(mitkImage1, (dimension)); \
58 _checkSpecificDimension(mitkImage2, (dimension)); \
59 _accessTwoImagesByItkForEach(itkImageTypeFunction, ((short, dimension))((unsigned short, dimension))((float, dimension))((double, dimension)), ((short, dimension))((unsigned short, dimension))((float, dimension))((double, dimension)) ) \
61 std::string msg("Pixel type "); \
62 msg.append(pixelType1.GetComponentTypeAsString() ); \
63 msg.append(" or pixel type "); \
64 msg.append(pixelType2.GetComponentTypeAsString() ); \
65 msg.append(" is not in " MITK_PP_STRINGIZE(MITK_ACCESSBYITK_TYPES_DIMN_SEQ(dimension))); \
66 throw mitk::AccessByItkException(msg); \
75 template <
typename RegistrationType >
83 itkFactorylessNewMacro(Self)
90 if( registration == NULL)
93 MITK_DEBUG <<
"\t - Pyramid level " << registration->GetCurrentLevel();
94 if( registration->GetCurrentLevel() == 0 )
95 {
MITK_WARN(
"OptCommand") <<
"Cast to registration failed";
99 OptimizerType* optimizer =
dynamic_cast< OptimizerType*
>(registration->GetOptimizer());
101 if( optimizer == NULL)
102 {
MITK_WARN(
"OptCommand") <<
"Cast to optimizer failed";
107 << optimizer->GetValue() <<
" : " << optimizer->GetCurrentPosition();
109 optimizer->SetMaximumStepLength( optimizer->GetMaximumStepLength() * 0.25f );
110 optimizer->SetMinimumStepLength( optimizer->GetMinimumStepLength() * 0.1f );
114 void Execute(
const itk::Object * ,
const itk::EventObject & )
override{}
117 #include <itkGradientDescentLineSearchOptimizerv4.h>
119 template <
typename RegistrationType >
127 itkFactorylessNewMacro(Self)
134 if( registration == NULL)
137 MITK_DEBUG <<
"\t - Pyramid level " << registration->GetCurrentLevel();
138 if( registration->GetCurrentLevel() == 0 )
141 OptimizerType* optimizer =
dynamic_cast< OptimizerType*
>( registration->GetOptimizer() );
143 if( optimizer == NULL)
144 {
MITK_WARN(
"OptCommand4") <<
"Cast to optimizer failed";
148 optimizer->SetNumberOfIterations( optimizer->GetNumberOfIterations() * 2.5 );
149 optimizer->SetMaximumStepSizeInPhysicalUnits( optimizer->GetMaximumStepSizeInPhysicalUnits() * 0.4);
151 MITK_INFO(
"Pyramid.Command.Iter") << optimizer->GetNumberOfIterations();
152 MITK_INFO(
"Pyramid.Command.MaxStep") << optimizer->GetMaximumStepSizeInPhysicalUnits();
156 void Execute(
const itk::Object * ,
const itk::EventObject & )
override{}
160 template <
typename OptimizerType>
165 itkFactorylessNewMacro(Self)
171 OptimizerType* optimizer =
dynamic_cast< OptimizerType*
>( caller );
173 unsigned int currentIter = optimizer->GetCurrentIteration();
174 MITK_INFO <<
"[" << currentIter <<
"] : " << optimizer->GetValue() <<
" : " << optimizer->GetCurrentPosition();
178 void Execute(
const itk::Object * ,
const itk::EventObject & )
override
184 template <
typename OptimizerType>
192 OptimizerType* optimizer =
dynamic_cast< OptimizerType*
>( object );
194 if(
typeid( event ) !=
typeid( itk::IterationEvent ) )
197 unsigned int currentIter = optimizer->GetCurrentIteration();
198 MITK_INFO <<
"[" << currentIter <<
"] : " << optimizer->GetCurrentMetricValue() <<
" : "
199 << optimizer->GetMetric()->GetParameters() ;
204 void Execute(
const itk::Object * ,
const itk::EventObject & )
override
212 #endif // MITKPYRAMIDREGISTRATIONMETHODHELPER_H
void Execute(itk::Object *caller, const itk::EventObject &) override
mitkClassMacroItkParent(PyramidOptControlCommandv4< RegistrationType >, itk::Command) static Pointer New()
itk::GradientDescentLineSearchOptimizerv4 OptimizerType
void Execute(const itk::Object *, const itk::EventObject &) override
void Execute(itk::Object *caller, const itk::EventObject &) override
void Execute(const itk::Object *, const itk::EventObject &) override
The PyramidOptControlCommand class stears the step lenght of the gradient descent optimizer in multi-...
mitkClassMacroItkParent(PyramidOptControlCommand< RegistrationType >, itk::Command) static Pointer New()
mitkClassMacroItkParent(OptimizerIterationCommand< OptimizerType >, itk::Command) static Pointer New()
void Execute(const itk::Object *, const itk::EventObject &) override
void Execute(itk::Object *caller, const itk::EventObject &) override
::map::core::RegistrationBase RegistrationType
itk::RegularStepGradientDescentOptimizer OptimizerType
void Execute(const itk::Object *, const itk::EventObject &) override
void Execute(itk::Object *object, const itk::EventObject &event) override