/*========================================================================= Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: setIdentityDirection3D.cxx,v $ Language: C++ Date: $Date: 2010/02/15 08:19:50 $ Version: $Revision: 1.2 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #if defined(_MSC_VER) #pragma warning ( disable : 4786 ) #endif #ifdef __BORLANDC__ #define ITK_LEAN_AND_MEAN #endif #include "itkImage.h" #include "itkImageFileReader.h" #include "itkImageFileWriter.h" #include "itkOrientedImage.h" #include "itkOrientImageFilter.h" #include "itkChangeInformationImageFilter.h" int main( int argc, char * argv[] ) { if( argc < 3 ) { std::cerr << "Usage: " << std::endl; std::cerr << argv[0] << " inputImageFile outputImageFile" << std::endl; std::cerr << "It generates an outputImageFile which has the same format with inputImageFile, but with identity DCM" << std::endl; return EXIT_FAILURE; } const unsigned int Dimension = 3; typedef unsigned short InputPixelType; typedef unsigned short OutputPixelType; typedef itk::Image< InputPixelType, Dimension > InputImageType; typedef itk::Image< OutputPixelType, Dimension > OutputImageType; typedef itk::ImageFileReader< InputImageType > ReaderType; typedef itk::ImageFileWriter< OutputImageType > WriterType; ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); reader->SetFileName( argv[1] ); try { reader->Update(); } catch (itk::ExceptionObject & e) { std::cerr << e << std::endl; return EXIT_FAILURE; } typedef itk::ChangeInformationImageFilter< InputImageType > ChangeType; InputImageType::DirectionType directionCosines; directionCosines.SetIdentity(); ChangeType::Pointer change = ChangeType::New(); change->SetInput( reader->GetOutput() ); change->ChangeDirectionOn(); change->SetOutputDirection(directionCosines); change->Update(); writer->SetFileName( argv[2] ); writer->SetInput( change->GetOutput() ); try { writer->Update(); } catch( itk::ExceptionObject & excep ) { std::cerr << "Exception catched !" << std::endl; std::cerr << excep << std::endl; } ReaderType::Pointer reader2 = ReaderType::New(); reader2->SetFileName( argv[2] ); reader2->Update(); std::cerr << "Output Direction " << std::endl; std::cerr << reader2->GetOutput()->GetDirection()<< std::endl; std::cout << "Input Direction is: " << std::endl; std::cout << reader->GetOutput()->GetDirection() << std::endl; std::cout << "Filter Direction is: " << std::endl; std::cout << change->GetOutput()->GetDirection() << std::endl; return EXIT_SUCCESS; }