[Insight-users] RegistrationInterfaceCommand and Bus error

Serena Fabbri fabbri at u.washington.edu
Fri Jul 17 13:53:35 EDT 2009


Hi All,
I am registering with a Multi-Resolution Registration.
I need to obtain the pixels number of the fixed image, but when I call 
GetLargestPossibleRegion().GetSize() in RegistrationInterfaceCommand Class I get error 
message: 
Bus error

Could anyone point out me where the error is?

Thank you.
Serena.


#include "itkCommand.h"
template <typename TRegistration>
class RegistrationInterfaceCommand : public itk::Command 
{
public:
   typedef  RegistrationInterfaceCommand   Self;
   typedef  itk::Command                   Superclass;
   typedef  itk::SmartPointer<Self>        Pointer;
   itkNewMacro( Self );

protected:
   RegistrationInterfaceCommand() {};

public:
   typedef   TRegistration                              RegistrationType;
   typedef   RegistrationType *                         RegistrationPointer;
   typedef   itk::LBFGSBOptimizer					   OptimizerType;
   typedef   OptimizerType *                            OptimizerPointer;

   typedef   itk::Image< float, 3 >					   InternalImageType;
   typedef   itk::MattesMutualInformationImageToImageMetric<
 								InternalImageType,
 								InternalImageType >    MetricType;
   typedef   MetricType *							   MetricPointer;

   typedef   itk::Image< unsigned short, 3 >			   FixedImageType;
   typedef  const  FixedImageType *					   FixedImagePointer;

 	void Execute(itk::Object * object, const itk::EventObject & event)
   {

     if( !(itk::IterationEvent().CheckEvent( &event )) )
       {
       return;
       }
     std::cout<<96<<std::endl;
     RegistrationPointer registration =
                             dynamic_cast<RegistrationPointer>( object );

     OptimizerPointer optimizer = dynamic_cast< OptimizerPointer >(
                        registration->GetOptimizer() );


 	MetricPointer metric = dynamic_cast< MetricPointer >(
 					  registration->GetMetric() );

     FixedImagePointer  fixedImage = dynamic_cast< FixedImagePointer >(
 					  registration->GetFixedImage() );

 	  int size[3]; int npixel=0;

 	  size[0]=fixedImage->GetLargestPossibleRegion().GetSize()[0];

 	  size[1]=fixedImage->GetLargestPossibleRegion().GetSize()[1];

 	  size[2]=fixedImage->GetLargestPossibleRegion().GetSize()[2];

 	  npixel=size[0]*size[1]*size[2];

     std::cout << "-------------------------------------" << std::endl;
     std::cout << "MultiResolution Level : "
               << registration->GetCurrentLevel()  << std::endl;
     std::cout << std::endl;

     if ( registration->GetCurrentLevel() == 0 )
       {
 		  optimizer->SetCostFunctionConvergenceFactor( 1.e1 );
 		  optimizer->SetProjectedGradientTolerance( 1e-8 );
 		  optimizer->SetMaximumNumberOfIterations( 30 );
 		  optimizer->SetMaximumNumberOfEvaluations( 200 );
 		  optimizer->SetMaximumNumberOfCorrections( 200 );
 		  metric->SetNumberOfHistogramBins( 256 );
 		  metric->SetNumberOfSpatialSamples( static_cast<unsigned int>( (npixel/64) * 20.0 / 
100.0 ) );
       }
 	  if ( registration->GetCurrentLevel() == 1)
       {
 		  optimizer->SetCostFunctionConvergenceFactor( 1.e1 );
 		  optimizer->SetProjectedGradientTolerance( 1e-8 );
 		  optimizer->SetMaximumNumberOfIterations( 30 );
 		  optimizer->SetMaximumNumberOfEvaluations( 200 );
 		  optimizer->SetMaximumNumberOfCorrections( 200 );
 		  metric->SetNumberOfHistogramBins( 256 );
 		  metric->SetNumberOfSpatialSamples( static_cast<unsigned int>( (npixel/8) * 20.0 / 100.0 
) );
       }

       if ( registration->GetCurrentLevel() != 0 &&  registration->GetCurrentLevel() != 1 )
       {
 		  optimizer->SetCostFunctionConvergenceFactor( 1.e1 );
 		  optimizer->SetProjectedGradientTolerance( 1e-8 );
 		  optimizer->SetMaximumNumberOfIterations( 200 );
 		  optimizer->SetMaximumNumberOfEvaluations( 200 );
 		  optimizer->SetMaximumNumberOfCorrections( 200 );
 		  metric->SetNumberOfHistogramBins( 25 );
 		  metric->SetNumberOfSpatialSamples( static_cast<unsigned int>( npixel * 20.0 / 100.0 ) );
       }
   }

   void Execute(const itk::Object * , const itk::EventObject & )
     {return; }
};








More information about the Insight-users mailing list