17 #ifndef __itkPDEDeformableRegistrationFilter_txx
18 #define __itkPDEDeformableRegistrationFilter_txx
30 #include "vnl/vnl_math.h"
37 template <
class TFixedImage,
class TMovingImage,
class TDeformationField>
42 this->SetNumberOfRequiredInputs(2);
44 this->SetNumberOfIterations(10);
47 for( j = 0; j < ImageDimension; j++ )
49 m_StandardDeviations[j] = 1.0;
50 m_UpdateFieldStandardDeviations[j] = 1.0;
53 m_TempField = DeformationFieldType::New();
55 m_MaximumKernelWidth = 30;
56 m_StopRegistrationFlag =
false;
58 m_SmoothDeformationField =
true;
59 m_SmoothUpdateField =
false;
66 template <
class TFixedImage,
class TMovingImage,
class TDeformationField>
79 template <
class TFixedImage,
class TMovingImage,
class TDeformationField>
93 template <
class TFixedImage,
class TMovingImage,
class TDeformationField>
106 template <
class TFixedImage,
class TMovingImage,
class TDeformationField>
120 template <
class TFixedImage,
class TMovingImage,
class TDeformationField>
121 std::vector<SmartPointer<DataObject> >::size_type
125 typename std::vector<SmartPointer<DataObject> >::size_type num = 0;
127 if (this->GetFixedImage())
132 if (this->GetMovingImage())
144 template <
class TFixedImage,
class TMovingImage,
class TDeformationField>
152 for( j = 0; j < ImageDimension; j++ )
154 if( value != m_StandardDeviations[j] )
159 if( j < ImageDimension )
162 for( j = 0; j < ImageDimension; j++ )
164 m_StandardDeviations[j] = value;
173 template <
class TFixedImage,
class TMovingImage,
class TDeformationField>
181 for( j = 0; j < ImageDimension; j++ )
183 if( value != m_UpdateFieldStandardDeviations[j] )
188 if( j < ImageDimension )
191 for( j = 0; j < ImageDimension; j++ )
193 m_UpdateFieldStandardDeviations[j] = value;
203 template <
class TFixedImage,
class TMovingImage,
class TDeformationField>
208 Superclass::PrintSelf(os, indent);
209 os << indent <<
"Smooth deformation field: "
210 << (m_SmoothDeformationField ?
"on" :
"off") << std::endl;
211 os << indent <<
"Standard deviations: [";
213 for( j = 0; j < ImageDimension - 1; j++ )
215 os << m_StandardDeviations[j] <<
", ";
217 os << m_StandardDeviations[j] <<
"]" << std::endl;
218 os << indent <<
"Smooth update field: "
219 << (m_SmoothUpdateField ?
"on" :
"off") << std::endl;
220 os << indent <<
"Update field standard deviations: [";
221 for( j = 0; j < ImageDimension - 1; j++ )
223 os << m_UpdateFieldStandardDeviations[j] <<
", ";
225 os << m_UpdateFieldStandardDeviations[j] <<
"]" << std::endl;
226 os << indent <<
"StopRegistrationFlag: ";
227 os << m_StopRegistrationFlag << std::endl;
228 os << indent <<
"MaximumError: ";
229 os << m_MaximumError << std::endl;
230 os << indent <<
"MaximumKernelWidth: ";
231 os << m_MaximumKernelWidth << std::endl;
239 template <
class TFixedImage,
class TMovingImage,
class TDeformationField>
248 if( !movingPtr || !fixedPtr )
250 itkExceptionMacro( <<
"Fixed and/or moving image not set" );
256 (this->GetDifferenceFunction().GetPointer());
260 itkExceptionMacro(<<
"FiniteDifferenceFunction not of type PDEDeformableRegistrationFilterFunction");
266 this->Superclass::InitializeIteration();
277 template <
class TFixedImage,
class TMovingImage,
class TDeformationField>
287 this->Superclass::CopyInputToOutput();
292 for(
unsigned int j = 0; j < ImageDimension; j++ )
297 typename OutputImageType::Pointer output = this->GetOutput();
301 while( ! out.IsAtEnd() )
310 template <
class TFixedImage,
class TMovingImage,
class TDeformationField>
318 if( this->GetInput(0) )
322 this->Superclass::GenerateOutputInformation();
325 else if( this->GetFixedImage() )
329 for (
unsigned int idx = 0; idx <
330 this->GetNumberOfOutputs(); ++idx )
332 output = this->GetOutput(idx);
335 output->CopyInformation(this->GetFixedImage());
344 template <
class TFixedImage,
class TMovingImage,
class TDeformationField>
351 Superclass::GenerateInputRequestedRegion();
358 movingPtr->SetRequestedRegionToLargestPossibleRegion();
371 inputPtr->SetRequestedRegion( outputPtr->GetRequestedRegion() );
376 fixedPtr->SetRequestedRegion( outputPtr->GetRequestedRegion() );
385 template <
class TFixedImage,
class TMovingImage,
class TDeformationField>
390 this->Superclass::PostProcessOutput();
391 m_TempField->Initialize();
398 template <
class TFixedImage,
class TMovingImage,
class TDeformationField>
403 this->Superclass::Initialize();
404 m_StopRegistrationFlag =
false;
411 template <
class TFixedImage,
class TMovingImage,
class TDeformationField>
420 m_TempField->SetOrigin( field->GetOrigin() );
421 m_TempField->SetSpacing( field->GetSpacing() );
422 m_TempField->SetDirection( field->GetDirection() );
423 m_TempField->SetLargestPossibleRegion(
424 field->GetLargestPossibleRegion() );
425 m_TempField->SetRequestedRegion(
426 field->GetRequestedRegion() );
427 m_TempField->SetBufferedRegion( field->GetBufferedRegion() );
428 m_TempField->Allocate();
430 typedef typename DeformationFieldType::PixelType
VectorType;
431 typedef typename VectorType::ValueType ScalarType;
435 DeformationFieldType> SmootherType;
437 OperatorType * oper =
new OperatorType;
438 typename SmootherType::Pointer smoother = SmootherType::New();
440 typedef typename DeformationFieldType::PixelContainerPointer
441 PixelContainerPointer;
442 PixelContainerPointer swapPtr;
445 smoother->GraftOutput( m_TempField );
447 for(
unsigned int j = 0; j < ImageDimension; j++ )
450 oper->SetDirection( j );
451 double variance = vnl_math_sqr( m_StandardDeviations[j] );
452 oper->SetVariance( variance );
453 oper->SetMaximumError( m_MaximumError );
454 oper->SetMaximumKernelWidth( m_MaximumKernelWidth );
455 oper->CreateDirectional();
458 smoother->SetOperator( *oper );
459 smoother->SetInput( field );
462 if ( j < ImageDimension - 1 )
465 swapPtr = smoother->GetOutput()->GetPixelContainer();
466 smoother->GraftOutput( field );
467 field->SetPixelContainer( swapPtr );
468 smoother->Modified();
474 m_TempField->SetPixelContainer( field->GetPixelContainer() );
475 this->GraftOutput( smoother->GetOutput() );
484 template <
class TFixedImage,
class TMovingImage,
class TDeformationField>
492 typedef typename DeformationFieldType::PixelType
VectorType;
493 typedef typename VectorType::ValueType ScalarType;
497 DeformationFieldType> SmootherType;
499 OperatorType opers[ImageDimension];
500 typename SmootherType::Pointer smoothers[ImageDimension];
502 for(
unsigned int j = 0; j < ImageDimension; j++ )
505 opers[j].SetDirection( j );
506 double variance = vnl_math_sqr( this->GetUpdateFieldStandardDeviations()[j] );
508 opers[j].SetVariance( variance );
509 opers[j].SetMaximumError( this->GetMaximumError() );
510 opers[j].SetMaximumKernelWidth( this->GetMaximumKernelWidth() );
511 opers[j].CreateDirectional();
513 smoothers[j] = SmootherType::New();
514 smoothers[j]->SetOperator( opers[j] );
515 smoothers[j]->ReleaseDataFlagOn();
519 smoothers[j]->SetInput( smoothers[j-1]->GetOutput() );
522 smoothers[0]->SetInput( field );
523 smoothers[ImageDimension-1]->GetOutput()
524 ->SetRequestedRegion( field->GetBufferedRegion() );
526 smoothers[ImageDimension-1]->Update();
529 field->SetPixelContainer( smoothers[ImageDimension-1]->GetOutput()
530 ->GetPixelContainer() );
531 field->SetRequestedRegion( smoothers[ImageDimension-1]->GetOutput()
532 ->GetRequestedRegion() );
533 field->SetBufferedRegion( smoothers[ImageDimension-1]->GetOutput()
534 ->GetBufferedRegion() );
535 field->SetLargestPossibleRegion( smoothers[ImageDimension-1]->GetOutput()
536 ->GetLargestPossibleRegion() );
537 field->CopyInformation( smoothers[ImageDimension-1]->GetOutput() );