ITK
4.2.0
Insight Segmentation and Registration Toolkit
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
ITK
Modules
Registration
Common
include
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
21
#include "
itkMultiResolutionImageRegistrationMethod.h
"
22
#include "
itkCommand.h
"
23
#include "
itkArray.h
"
24
#include "
itkGradientDescentOptimizer.h
"
25
26
// The following classes are examples of simple user interface
27
// that controls a MultiResolutionImageRegistrationMethod process
28
29
template
<
typename
TRegistrator>
30
class
SimpleMultiResolutionImageRegistrationUI
31
{
32
public
:
33
SimpleMultiResolutionImageRegistrationUI
( TRegistrator * ptr )
34
{
35
36
if
( !ptr )
return
;
37
m_Registrator
= ptr;
38
typename
itk::SimpleMemberCommand<SimpleMultiResolutionImageRegistrationUI>::Pointer
39
iterationCommand =
40
itk::SimpleMemberCommand<SimpleMultiResolutionImageRegistrationUI>::New
();
41
42
iterationCommand->SetCallbackFunction(
this
,
43
&
SimpleMultiResolutionImageRegistrationUI::StartNewLevel
);
44
45
m_Tag
=
m_Registrator
->AddObserver(
itk::IterationEvent
(), iterationCommand );
46
47
}
48
49
virtual
~SimpleMultiResolutionImageRegistrationUI
()
50
{
51
if
(
m_Registrator
) {
m_Registrator
->RemoveObserver(
m_Tag
); }
52
}
53
54
virtual
void
StartNewLevel
()
55
{
56
std::cout <<
"--- Starting level "
<<
m_Registrator
->GetCurrentLevel()
57
<< std::endl;
58
}
59
60
protected
:
61
typename
TRegistrator::Pointer
m_Registrator
;
62
unsigned
long
m_Tag
;
63
64
};
65
66
67
// This UI supports registration methods with gradient descent
68
// type optimizers.
69
// This UI allows the number of iterations and learning rate
70
// to be changes at each resolution level.
71
template
<
typename
TRegistration>
72
class
SimpleMultiResolutionImageRegistrationUI2
:
73
public
SimpleMultiResolutionImageRegistrationUI
<TRegistration>
74
{
75
public
:
76
77
typedef
SimpleMultiResolutionImageRegistrationUI<TRegistration>
78
Superclass
;
79
80
SimpleMultiResolutionImageRegistrationUI2
( TRegistration * ptr ) :
81
Superclass
(ptr) {};
82
virtual
~SimpleMultiResolutionImageRegistrationUI2
(){}
83
84
void
SetNumberOfIterations
(
itk::Array<unsigned int>
& iter )
85
{
86
m_NumberOfIterations
= iter;
87
}
88
89
void
SetLearningRates
(
itk::Array<double>
& rates )
90
{
91
m_LearningRates
= rates;
92
}
93
94
virtual
void
StartNewLevel
()
95
{
96
97
// call the superclass's implementation
98
this->
Superclass::StartNewLevel
();
99
100
if
( !this->
m_Registrator
)
return
;
101
102
// Try to cast the optimizer to a gradient descent type,
103
// return if casting didn't work.
104
itk::GradientDescentOptimizer::Pointer
optimizer;
105
optimizer =
dynamic_cast<
itk::GradientDescentOptimizer
*
>
(
106
this->
m_Registrator
->GetOptimizer() );
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
:
128
itk::Array<unsigned int>
m_NumberOfIterations
;
129
itk::Array<double>
m_LearningRates
;
130
131
};
132
133
134
#endif
135
Generated on Tue Jul 10 2012 23:44:31 for ITK by
1.8.1