Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkRigidRegistrationObserver.h
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 #ifndef MITKRIGIDREGISTRATIONOBSERVER_H
18 #define MITKRIGIDREGISTRATIONOBSERVER_H
19 
21 #include "itkCommand.h"
22 #include "itkSingleValuedNonLinearOptimizer.h"
23 #include "mitkCommon.h"
24 #include <itkAmoebaOptimizer.h>
25 #include <itkConjugateGradientOptimizer.h>
26 #include <itkExhaustiveOptimizer.h>
27 #include <itkFRPROptimizer.h>
28 #include <itkGradientDescentOptimizer.h>
29 #include <itkLBFGSBOptimizer.h>
30 #include <itkLBFGSOptimizer.h>
31 #include <itkNormalVariateGenerator.h>
32 #include <itkOnePlusOneEvolutionaryOptimizer.h>
33 #include <itkPowellOptimizer.h>
34 #include <itkQuaternionRigidTransformGradientDescentOptimizer.h>
35 #include <itkRegularStepGradientDescentOptimizer.h>
36 #include <itkSPSAOptimizer.h>
37 #include <itkVersorRigid3DTransformOptimizer.h>
38 #include <itkVersorTransformOptimizer.h>
39 
40 namespace mitk
41 {
66  {
67  public:
69  typedef itk::Command Superclass;
71  itkFactorylessNewMacro(Self) itkCloneMacro(Self)
72 
73  typedef itk::SingleValuedNonLinearOptimizer OptimizerType;
74  typedef OptimizerType *OptimizerPointer;
75 
83  void Execute(itk::Object *caller, const itk::EventObject &event) override;
84 
89  void Execute(const itk::Object *object, const itk::EventObject &event) override;
90 
95  void AddStepsToDo(int steps);
96 
101  void SetRemainingProgress(int steps);
102 
109  double GetCurrentOptimizerValue();
110 
116  itk::Array<double> GetCurrentTranslation();
117 
124  void SetStopOptimization(bool stopOptimization);
125 
126  protected:
128 
129  void HandleOptimizationIterationEvent(OptimizerType *optimizer);
130 
131  private:
132  double m_OptimizerValue;
133  itk::Array<double> m_Params;
134  bool m_StopOptimization;
135  };
136 
137  template <class RegistrationType>
139  {
140  public:
141  typedef itk::RegularStepGradientDescentBaseOptimizer OptimizerType;
142 
144  itkFactorylessNewMacro(Self) itkCloneMacro(Self)
145 
146  void Execute(itk::Object *caller, const itk::EventObject & /*event*/) override
147  {
148  RegistrationType *registration = dynamic_cast<RegistrationType *>(caller);
149 
150  if (registration == NULL)
151  return;
152 
153  OptimizerType *optimizer = dynamic_cast<OptimizerType *>(registration->GetOptimizer());
154 
155  if (optimizer == NULL)
156  {
157  MITK_WARN("Pyramid.Registration.Command") << "No step adaptation possible with given optimizer, cast failed! ";
158  return;
159  }
160 
161  MITK_DEBUG << "\t - Pyramid level " << registration->GetCurrentLevel();
162 
163  if (registration->GetCurrentLevel() == 0)
164  {
165  MITK_INFO("Pyramid.Registration.Command") << "First pyramid resolution level: ";
166  MITK_INFO("Pyramid.Registration.Command") << " Current settings: \n"
167  << " Step length: (" << optimizer->GetMinimumStepLength() << ","
168  << optimizer->GetMaximumStepLength()
169  << "), Tolerance: " << optimizer->GetGradientMagnitudeTolerance()
170  << " Iterations: " << optimizer->GetNumberOfIterations();
171  return;
172  }
173 
174  optimizer->SetMaximumStepLength(optimizer->GetMaximumStepLength() * 0.25f);
175  optimizer->SetMinimumStepLength(optimizer->GetMinimumStepLength() * 0.1f);
176  optimizer->SetGradientMagnitudeTolerance(optimizer->GetGradientMagnitudeTolerance() * 0.1f);
177  optimizer->SetNumberOfIterations(optimizer->GetNumberOfIterations() * 1.5f);
178 
179  MITK_INFO("Pyramid.Registration.Command") << " Current settings: \n"
180  << " Step length: (" << optimizer->GetMinimumStepLength() << ","
181  << optimizer->GetMaximumStepLength()
182  << "), Tolerance: " << optimizer->GetGradientMagnitudeTolerance()
183  << " Iterations: " << optimizer->GetNumberOfIterations();
184  }
185 
186  void Execute(const itk::Object * /*object*/, const itk::EventObject & /*event*/) override {}
187  };
188 
189 } // namespace mitk
190 
191 #endif // MITKRIGIDREGISTRATIONOBSERVER_H
Observer to react on rigid registration optimizer events.
#define MITK_INFO
Definition: mitkLogMacros.h:22
#define MITKRIGIDREGISTRATION_EXPORT
#define MITK_DEBUG
Definition: mitkLogMacros.h:26
DataCollection - Class to facilitate loading/accessing structured data.
#define MITK_WARN
Definition: mitkLogMacros.h:23
#define mitkClassMacroItkParent(className, SuperClassName)
Definition: mitkCommon.h:53
void Execute(const itk::Object *, const itk::EventObject &) override
itk::SingleValuedNonLinearOptimizer OptimizerType
itk::RegularStepGradientDescentBaseOptimizer OptimizerType
::map::core::RegistrationBase RegistrationType