ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkSimpleMultiResolutionImageRegistrationUI.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkSimpleMultiResolutionImageRegistrationUI_h
19 #define itkSimpleMultiResolutionImageRegistrationUI_h
20 
22 #include "itkCommand.h"
23 #include "itkArray.h"
25 
26 // The following classes are examples of simple user interface
27 // that controls a MultiResolutionImageRegistrationMethod process
28 
29 template <typename TRegistrator>
31 {
32 public:
34  m_Tag(0)
35  {
36 
37  if ( !ptr ) return;
38  m_Registrator = ptr;
40  iterationCommand =
42 
43  iterationCommand->SetCallbackFunction( this,
45 
46  m_Tag = m_Registrator->AddObserver( itk::IterationEvent(), iterationCommand );
47 
48  }
49 
51  {
52  if( m_Registrator ) { m_Registrator->RemoveObserver( m_Tag ); }
53  }
54 
55  virtual void StartNewLevel()
56  {
57  std::cout << "--- Starting level " << m_Registrator->GetCurrentLevel()
58  << std::endl;
59  }
60 
61 protected:
62  typename TRegistrator::Pointer m_Registrator;
63  unsigned long m_Tag;
64 
65 };
66 
67 
68 // This UI supports registration methods with gradient descent
69 // type optimizers.
70 // This UI allows the number of iterations and learning rate
71 // to be changes at each resolution level.
72 template <typename TRegistration>
74  public SimpleMultiResolutionImageRegistrationUI<TRegistration>
75 {
76 public:
77 
80 
82  Superclass(ptr) {};
84 
86  {
87  m_NumberOfIterations = iter;
88  }
89 
91  {
92  m_LearningRates = rates;
93  }
94 
95  virtual void StartNewLevel()
96  {
97 
98  // call the superclass's implementation
100 
101  if ( !this->m_Registrator ) return;
102 
103  // Try to cast the optimizer to a gradient descent type,
104  // return if casting didn't work.
106  this->m_Registrator->GetModifiableOptimizer() );
107  if ( !optimizer ) return;
108 
109  unsigned int level = this->m_Registrator->GetCurrentLevel();
110  if ( m_NumberOfIterations.Size() >= level + 1 )
111  {
112  optimizer->SetNumberOfIterations( m_NumberOfIterations[level] );
113  }
114 
115  if ( m_LearningRates.Size() >= level + 1 )
116  {
117  optimizer->SetLearningRate( m_LearningRates[level] );
118  }
119 
120  std::cout << " No. Iterations: "
121  << optimizer->GetNumberOfIterations()
122  << " Learning rate: "
123  << optimizer->GetLearningRate()
124  << std::endl;
125  }
126 
127 private:
130 
131 };
132 
133 
134 #endif
Implement a gradient descent optimizer.
static Pointer New()
SizeValueType Size(void) const
Definition: itkArray.h:124
SimpleMultiResolutionImageRegistrationUI< TRegistration > Superclass