int main( int argc, char * argv[] )
{
if( argc < 4 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " inputImageFile outputImageFile";
std::cerr << " [exampleAction={0,1}]" << std::endl;
return EXIT_FAILURE;
}
int exampleAction = 0;
if( argc >= 4 )
{
exampleAction = atoi( argv[3] );
}
const unsigned int Dimension = 2;
typedef unsigned char InputPixelType;
typedef unsigned char OutputPixelType;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
reader->SetFileName( argv[1] );
writer->SetFileName( argv[2] );
InputImageType, OutputImageType > FilterType;
FilterType::Pointer filter = FilterType::New();
TransformType::Pointer transform = TransformType::New();
InputImageType, double > InterpolatorType;
InterpolatorType::Pointer interpolator = InterpolatorType::New();
filter->SetInterpolator( interpolator );
filter->SetDefaultPixelValue( 100 );
double spacing[ Dimension ];
spacing[0] = 40.0 / 40.0;
spacing[1] = 30.0 / 40.0;
filter->SetOutputSpacing( spacing );
filter->SetOutputDirection( reader->GetOutput()->GetDirection() );
double origin[ Dimension ];
origin[0] = 50.0;
origin[1] = 130.0;
filter->SetOutputOrigin( origin );
InputImageType::SizeType size;
size[0] = 5 * 40;
size[1] = 4 * 40;
filter->SetSize( size );
filter->SetInput( reader->GetOutput() );
writer->SetInput( filter->GetOutput() );
TransformType::OutputVectorType translation1;
translation1[0] = -origin[0];
translation1[1] = -origin[1];
transform->Translate( translation1 );
const double degreesToRadians = std::atan(1.0) / 45.0;
transform->Rotate2D( -30.0 * degreesToRadians, false );
TransformType::OutputVectorType translation2;
translation2[0] = origin[0];
translation2[1] = origin[1];
transform->Translate( translation2, false );
filter->SetTransform( transform );
if( exampleAction == 0 )
{
try
{
writer->Update();
}
{
std::cerr << "Exception catched !" << std::endl;
std::cerr << excep << std::endl;
}
}
return EXIT_SUCCESS;
}