- auto input = this->GetInput( );
- TScalar coeff = TScalar( 1 );
- if( this->m_UseImageSpacing )
- {
- typename _TInputImage::PointType pa, pb;
- input->TransformIndexToPhysicalPoint( a, pa );
- input->TransformIndexToPhysicalPoint( b, pb );
- coeff = TScalar( pa.EuclideanDistanceTo( pb ) );
-
- } // fi
- TScalar va = TScalar( input->GetPixel( a ) );
- return( va * coeff );
+ this->Superclass::_BeforeGenerateData( );
+
+ TCostFunction* cost =
+ dynamic_cast< TCostFunction* >( this->GetCostFunction( ) );
+ if( cost == NULL )
+ itkExceptionMacro( << "CostFunction not well defined." );
+ cost->SetImage( this->GetInput( ) );