diff --git a/Modules/DiffusionImaging/DiffusionCore/Algorithms/mitkPyramidRegistrationMethodHelper.h b/Modules/DiffusionImaging/DiffusionCore/Algorithms/mitkPyramidRegistrationMethodHelper.h index 7790702c2b..84c8374bcd 100644 --- a/Modules/DiffusionImaging/DiffusionCore/Algorithms/mitkPyramidRegistrationMethodHelper.h +++ b/Modules/DiffusionImaging/DiffusionCore/Algorithms/mitkPyramidRegistrationMethodHelper.h @@ -1,95 +1,142 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKPYRAMIDREGISTRATIONMETHODHELPER_H #define MITKPYRAMIDREGISTRATIONMETHODHELPER_H #include #include #include #include #include #include #include #include #include #include "mitkImageAccessByItk.h" /** * @brief Provides same functionality as \a AccessTwoImagesFixedDimensionByItk for a subset of types * * For now, the subset defined is only short and float. */ #define AccessTwoImagesFixedDimensionTypeSubsetByItk(mitkImage1, mitkImage2, itkImageTypeFunction, dimension) \ { \ const mitk::PixelType& pixelType1 = mitkImage1->GetPixelType(); \ const mitk::PixelType& pixelType2 = mitkImage2->GetPixelType(); \ const mitk::Image* constImage1 = mitkImage1; \ const mitk::Image* constImage2 = mitkImage2; \ mitk::Image* nonConstImage1 = const_cast(constImage1); \ mitk::Image* nonConstImage2 = const_cast(constImage2); \ nonConstImage1->Update(); \ nonConstImage2->Update(); \ _checkSpecificDimension(mitkImage1, (dimension)); \ _checkSpecificDimension(mitkImage2, (dimension)); \ _accessTwoImagesByItkForEach(itkImageTypeFunction, ((short, dimension))((float, dimension)), ((short, dimension))((float, dimension)) ) \ { \ std::string msg("Pixel type "); \ msg.append(pixelType1.GetComponentTypeAsString() ); \ msg.append(" or pixel type "); \ msg.append(pixelType2.GetComponentTypeAsString() ); \ msg.append(" is not in " MITK_PP_STRINGIZE(MITK_ACCESSBYITK_TYPES_DIMN_SEQ(dimension))); \ throw mitk::AccessByItkException(msg); \ } \ } /** * @brief The PyramidOptControlCommand class stears the step lenght of the * gradient descent optimizer in multi-scale registration methods */ template class PyramidOptControlCommand : public itk::Command { public: typedef itk::RegularStepGradientDescentOptimizer OptimizerType; itkNewMacro( PyramidOptControlCommand ) void Execute(itk::Object *caller, const itk::EventObject & /*event*/) { RegistrationType* registration = dynamic_cast< RegistrationType* >( caller ); + std::cout << "\t - Pyramid level " << registration->GetCurrentLevel() << std::endl; if( registration->GetCurrentLevel() == 0 ) return; + + OptimizerType* optimizer = dynamic_cast< OptimizerType* >(registration->GetOptimizer()); - optimizer->SetMaximumStepLength( optimizer->GetMaximumStepLength() * 0.25f ); + std::cout << optimizer->GetStopConditionDescription() << std::endl; + + optimizer->SetMaximumStepLength( optimizer->GetMaximumStepLength() * 0.5f ); optimizer->SetMinimumStepLength( optimizer->GetMinimumStepLength() * 0.1f ); + optimizer->SetNumberOfIterations( optimizer->GetNumberOfIterations() * 1.5f ); } void Execute(const itk::Object * /*object*/, const itk::EventObject & /*event*/){} }; +template +class OptimizerIterationCommand : public itk::Command +{ +public: + itkNewMacro( OptimizerIterationCommand ) + + void Execute(itk::Object *caller, const itk::EventObject & event) + { + OptimizerType* optimizer = dynamic_cast< OptimizerType* >( caller ); + + unsigned int currentIter = optimizer->GetCurrentIteration(); + std::cout << "[" << currentIter << "] : " << optimizer->GetValue() << " : " << optimizer->GetCurrentPosition() << std::endl; + +/* typedef typename OptimizerType::CostFunctionType CostFunctionType; + const CostFunctionType *cfcn = optimizer->GetCostFunction(); + + const std::string match("MattesMutualInformationImageToImageMetric"); + const std::string name( cfcn->GetNameOfClass() ); + + double compareValue = -0.1; + + if ( name.compare( match ) == 0 ) + { + compareValue = -0.2; + } + + if (optimizer->GetValue() > compareValue ) + { + optimizer->StopOptimization(); + itkGenericExceptionMacro( << " Unrealistic metric value reached. Stopping optimization! "); + } +*/ + } + + void Execute(const itk::Object * object, const itk::EventObject & event) + { + + } +}; + + #endif // MITKPYRAMIDREGISTRATIONMETHODHELPER_H