Orfeo Toolbox  3.16
itkPointSetToPointSetRegistrationMethod.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkPointSetToPointSetRegistrationMethod.txx,v $
5  Language: C++
6  Date: $Date: 2009-01-26 21:45:56 $
7  Version: $Revision: 1.3 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkPointSetToPointSetRegistrationMethod_txx
18 #define __itkPointSetToPointSetRegistrationMethod_txx
19 
21 
22 
23 namespace itk
24 {
25 
29 template < typename TFixedPointSet, typename TMovingPointSet >
32 {
33  this->SetNumberOfRequiredOutputs( 1 ); // for the Transform
34 
35  m_FixedPointSet = 0; // has to be provided by the user.
36  m_MovingPointSet = 0; // has to be provided by the user.
37  m_Transform = 0; // has to be provided by the user.
38  m_Metric = 0; // has to be provided by the user.
39  m_Optimizer = 0; // has to be provided by the user.
40 
41 
42  m_InitialTransformParameters = ParametersType(1);
43  m_LastTransformParameters = ParametersType(1);
44 
45  m_InitialTransformParameters.Fill( 0.0f );
46  m_LastTransformParameters.Fill( 0.0f );
47 
48  TransformOutputPointer transformDecorator =
49  static_cast< TransformOutputType * >(
50  this->MakeOutput(0).GetPointer() );
51 
52  this->ProcessObject::SetNthOutput( 0, transformDecorator.GetPointer() );
53 }
54 
55 
56 /*
57  * Set the initial transform parameters
58  */
59 template < typename TFixedPointSet, typename TMovingPointSet >
60 void
63 {
64  m_InitialTransformParameters = param;
65  this->Modified();
66 }
67 
71 template < typename TFixedPointSet, typename TMovingPointSet >
72 void
75 {
76 
77  if( !m_FixedPointSet )
78  {
79  itkExceptionMacro(<<"FixedPointSet is not present");
80  }
81 
82  if( !m_MovingPointSet )
83  {
84  itkExceptionMacro(<<"MovingPointSet is not present");
85  }
86 
87  if ( !m_Metric )
88  {
89  itkExceptionMacro(<<"Metric is not present" );
90  }
91 
92  if ( !m_Optimizer )
93  {
94  itkExceptionMacro(<<"Optimizer is not present" );
95  }
96 
97  if( !m_Transform )
98  {
99  itkExceptionMacro(<<"Transform is not present");
100  }
101 
102  // Setup the metric
103  m_Metric->SetMovingPointSet( m_MovingPointSet );
104  m_Metric->SetFixedPointSet( m_FixedPointSet );
105  m_Metric->SetTransform( m_Transform );
106 
107  m_Metric->Initialize();
108 
109  // Setup the optimizer
110  m_Optimizer->SetCostFunction( m_Metric );
111 
112  // Validate initial transform parameters
113  if ( m_InitialTransformParameters.Size() !=
114  m_Transform->GetNumberOfParameters() )
115  {
116  itkExceptionMacro(<<"Size mismatch between initial parameter and transform");
117  }
118 
119  m_Optimizer->SetInitialPosition( m_InitialTransformParameters );
120 
121  //
122  // Connect the transform to the Decorator.
123  //
124  TransformOutputType * transformOutput =
125  static_cast< TransformOutputType * >( this->ProcessObject::GetOutput(0) );
126 
127  transformOutput->Set( m_Transform.GetPointer() );
128 }
129 
130 
131 /*
132  * Starts the Registration Process
133  */
134 template < typename TFixedPointSet, typename TMovingPointSet >
135 void
138 {
139 
140  // StartRegistration is an old API from before
141  // the RegistrationMethod was a subclass of ProcessObject.
142  // Historically, one could call StartRegistration() instead of
143  // calling Update(). However, when called directly by the user, the
144  // inputs to the RegistrationMethod may not be up to date. This
145  // may cause an unexpected behavior.
146  //
147  // Since we cannot eliminate StartRegistration for backward
148  // compability reasons, we check whether StartRegistration was
149  // called directly or whether Update() (which in turn called
150  // StartRegistration()).
151  if (!m_Updating)
152  {
153  this->Update();
154  }
155  else
156  {
157  try
158  {
159  // initialize the interconnects between components
160  this->Initialize();
161  }
162  catch( ExceptionObject& err )
163  {
164  m_LastTransformParameters = ParametersType(1);
165  m_LastTransformParameters.Fill( 0.0f );
166 
167  // pass exception to caller
168  throw err;
169  }
170 
171 
172  try
173  {
174  // do the optimization
175  m_Optimizer->StartOptimization();
176  }
177  catch( ExceptionObject& err )
178  {
179  // An error has occurred in the optimization.
180  // Update the parameters
181  m_LastTransformParameters = m_Optimizer->GetCurrentPosition();
182 
183  // Pass exception to caller
184  throw err;
185  }
186 
187 
188  // get the results
189  m_LastTransformParameters = m_Optimizer->GetCurrentPosition();
190 
191  m_Transform->SetParameters( m_LastTransformParameters );
192  }
193 }
194 
195 
199 template < typename TFixedPointSet, typename TMovingPointSet >
200 void
202 ::PrintSelf(std::ostream& os, Indent indent) const
203 {
204  Superclass::PrintSelf( os, indent );
205  os << indent << "Metric: " << m_Metric.GetPointer() << std::endl;
206  os << indent << "Optimizer: " << m_Optimizer.GetPointer() << std::endl;
207  os << indent << "Transform: " << m_Transform.GetPointer() << std::endl;
208  os << indent << "Fixed PointSet: " << m_FixedPointSet.GetPointer() << std::endl;
209  os << indent << "Moving PointSet: " << m_MovingPointSet.GetPointer() << std::endl;
210  os << indent << "Initial Transform Parameters: " << m_InitialTransformParameters << std::endl;
211  os << indent << "Last Transform Parameters: " << m_LastTransformParameters << std::endl;
212 }
213 
214 
215 template < typename TFixedPointSet, typename TMovingPointSet >
216 void
219 {
220  this->StartRegistration();
221 }
222 
226 template < typename TFixedPointSet, typename TMovingPointSet >
229 ::GetOutput() const
230 {
231  return static_cast< const TransformOutputType * >( this->ProcessObject::GetOutput(0) );
232 }
233 
234 
235 template < typename TFixedPointSet, typename TMovingPointSet >
238 ::MakeOutput(unsigned int output)
239 {
240  switch (output)
241  {
242  case 0:
243  return static_cast<DataObject*>(TransformOutputType::New().GetPointer());
244  break;
245  default:
246  itkExceptionMacro("MakeOutput request for an output number larger than the expected number of outputs");
247  return 0;
248  }
249 }
250 
251 
255 template < typename TFixedPointSet, typename TMovingPointSet >
256 unsigned long
258 ::GetMTime() const
259 {
260  unsigned long mtime = Superclass::GetMTime();
261  unsigned long m;
262 
263 
264  // Some of the following should be removed once ivars are put in the
265  // input and output lists
266 
267  if (m_Transform)
268  {
269  m = m_Transform->GetMTime();
270  mtime = (m > mtime ? m : mtime);
271  }
272 
273  if (m_Metric)
274  {
275  m = m_Metric->GetMTime();
276  mtime = (m > mtime ? m : mtime);
277  }
278 
279  if (m_Optimizer)
280  {
281  m = m_Optimizer->GetMTime();
282  mtime = (m > mtime ? m : mtime);
283  }
284 
285  if (m_FixedPointSet)
286  {
287  m = m_FixedPointSet->GetMTime();
288  mtime = (m > mtime ? m : mtime);
289  }
290 
291  if (m_MovingPointSet)
292  {
293  m = m_MovingPointSet->GetMTime();
294  mtime = (m > mtime ? m : mtime);
295  }
296 
297  return mtime;
298 
299 }
300 
301 
302 } // end namespace itk
303 
304 
305 #endif

Generated at Sat Feb 2 2013 23:59:47 for Orfeo Toolbox with doxygen 1.8.1.1