#if defined(_MSC_VER) //Warning about: identifier was truncated to '255' characters in the debug information (MVC6.0 Debug) #pragma warning( disable : 4786 ) #endif // General includes #include // ITK includes #include "itkNumericTraits.h" #include "itkImage.h" #include "itkImageFileReader.h" #include "itkImageFileWriter.h" #include "itkObliqueSectionImageFilter.h" #include "itkLookAtTransformInitializer.h" #include "itkResampleImageFilter.h" #include "itkRigid3DTransform.h" int main(int argc, char* argv[]) { try { // Typedefs const int Dimension = 3; typedef float PixelType; typedef itk::Image< PixelType, Dimension > ImageType; typedef itk::ImageFileReader< ImageType > ReaderType; typedef itk::ImageFileWriter< ImageType > WriterType; typedef itk::Rigid3DTransform< double > TransformType; typedef itk::LookAtTransformInitializer< TransformType, ImageType > TransformInitalizerType; typedef itk::ResampleImageFilter< ImageType, ImageType > ResampleFilterType; // Get arguments int arg = 1; char* OutputFilename = argv[arg++]; char* InputFilename = argv[arg++]; double center0 = atof( argv[arg++] ); double center1 = atof( argv[arg++] ); double center2 = atof( argv[arg++] ); double direction0 = atof( argv[arg++] ); double direction1 = atof( argv[arg++] ); double direction2 = atof( argv[arg++] ); double up0 = atof( argv[arg++] ); double up1 = atof( argv[arg++] ); double up2 = atof( argv[arg++] ); // Read input ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName( InputFilename ); reader->Update( ); ImageType::Pointer input = reader->GetOutput(); // Create transform TransformType::Pointer transform = TransformType::New(); // Create transform initializer TransformInitalizerType::PointType center; center[0] = center0; center[1] = center1; center[2] = center2; TransformInitalizerType::VectorType direction; direction[0] = direction0; direction[1] = direction1; direction[2] = direction2; TransformInitalizerType::VectorType up; up[0] = up0; up[1] = up1; up[2] = up2; TransformInitalizerType::Pointer init = TransformInitalizerType::New(); init->SetTransform( transform ); init->SetImage( input ); init->SetPlane( center, direction, up ); init->InitializeTransform(); // Setup output parameters ImageType::SizeType size; size = input->GetLargestPossibleRegion().GetSize(); size[2] = 1; ImageType::SpacingType spacing; spacing = input->GetSpacing(); // Create resample filter ResampleFilterType::Pointer filterResample = ResampleFilterType::New(); filterResample->SetInput( reader->GetOutput() ); filterResample->SetTransform( transform ); filterResample->SetSize( size ); filterResample->SetOutputSpacing( spacing ); filterResample->Update( ); // Write output WriterType::Pointer writer = WriterType::New(); writer->SetFileName( OutputFilename ); writer->SetInput( filterResample->GetOutput() ); writer->Update(); } catch (itk::ExceptionObject & err) { std::cerr << "ExceptionObject caught !" << std::endl; std::cerr << err << std::endl; return EXIT_FAILURE; } //Return return EXIT_SUCCESS; }