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 = std::stoi( argv[3] );
}
using InputPixelType = unsigned char;
using OutputPixelType = unsigned char;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
reader->SetFileName( argv[1] );
writer->SetFileName( argv[2] );
InputImageType, OutputImageType >;
FilterType::Pointer filter = FilterType::New();
TransformType::Pointer transform = TransformType::New();
InputImageType, double >;
InterpolatorType::Pointer interpolator = InterpolatorType::New();
filter->SetInterpolator( interpolator );
filter->SetDefaultPixelValue( 100 );
spacing[0] = 40.0 / 40.0;
spacing[1] = 30.0 / 40.0;
filter->SetOutputSpacing( spacing );
filter->SetOutputDirection( reader->GetOutput()->GetDirection() );
origin[0] = 50.0;
origin[1] = 130.0;
filter->SetOutputOrigin( origin );
size[0] = 5 * 40;
size[1] = 4 * 40;
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;
}