1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18 #ifndef clitkChangeImageInfoGenericFilter_cxx
19 #define clitkChangeImageInfoGenericFilter_cxx
21 #include "clitkChangeImageInfoGenericFilter.h"
24 #include <itkChangeInformationImageFilter.h>
29 //--------------------------------------------------------------------
30 ChangeImageInfoGenericFilter::ChangeImageInfoGenericFilter():
31 ImageToImageGenericFilter<Self>("ChangeImageInfo")
33 InitializeImageType<2>();
34 InitializeImageType<3>();
35 InitializeImageType<4>();
37 //--------------------------------------------------------------------
39 //--------------------------------------------------------------------
40 template<unsigned int Dim>
41 void ChangeImageInfoGenericFilter::InitializeImageType()
43 ADD_DEFAULT_IMAGE_TYPES(Dim);
45 //--------------------------------------------------------------------
47 //--------------------------------------------------------------------
48 void ChangeImageInfoGenericFilter::SetArgsInfo(const args_info_type & a)
51 if (mArgsInfo.verbose_given)
52 SetIOVerbose(mArgsInfo.verbose_flag);
53 if (mArgsInfo.imagetypes_given && mArgsInfo.imagetypes_flag)
54 this->PrintAvailableImageTypes();
56 if (mArgsInfo.input_given) {
57 SetInputFilename(mArgsInfo.input_arg);
59 if (mArgsInfo.output_given) {
60 SetOutputFilename(mArgsInfo.output_arg);
63 //--------------------------------------------------------------------
65 //--------------------------------------------------------------------
66 // Update with the number of dimensions and the pixeltype
67 //--------------------------------------------------------------------
68 template<class InputImageType>
70 ChangeImageInfoGenericFilter::UpdateWithInputImageType()
73 typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
76 typedef typename itk::ChangeInformationImageFilter<InputImageType> CIIFType;
77 typename CIIFType::Pointer ciif = CIIFType::New();
78 const unsigned int Dimension = InputImageType::ImageDimension;
79 ciif->SetInput(input);
82 ciif->SetChangeDirection(mArgsInfo.direction_given);
83 if( ciif->GetChangeDirection() ) {
84 if(mArgsInfo.direction_given != Dimension*Dimension) {
85 std::cerr << "You must provide " << Dimension*Dimension
86 << " values for --direction."
90 typename InputImageType::DirectionType dir;
91 for(unsigned int i=0; i<Dimension; i++)
92 for(unsigned int j=0; j<Dimension; j++)
93 dir[i][j] = mArgsInfo.direction_arg[i*Dimension+j];
94 ciif->SetOutputDirection(dir);
98 ciif->SetChangeSpacing(mArgsInfo.spacing_given);
99 if( ciif->GetChangeSpacing() ) {
100 if(mArgsInfo.spacing_given != Dimension) {
101 std::cerr << "You must provide " << Dimension
102 << " values for --spacing."
106 typename InputImageType::SpacingType spacing;
107 for(unsigned int i=0; i<Dimension; i++)
108 spacing[i] = mArgsInfo.spacing_arg[i];
109 ciif->SetOutputSpacing(spacing);
113 ciif->SetChangeOrigin(mArgsInfo.origin_given);
114 if( ciif->GetChangeOrigin() ) {
115 if(mArgsInfo.origin_given != Dimension) {
116 std::cerr << "You must provide " << Dimension
117 << " values for --origin."
121 typename InputImageType::PointType origin;
122 for(unsigned int i=0; i<Dimension; i++)
123 origin[i] = mArgsInfo.origin_arg[i];
124 ciif->SetOutputOrigin(origin);
128 this->template SetNextOutput<InputImageType>(ciif->GetOutput());
130 //--------------------------------------------------------------------
134 #endif //#define clitkChangeImageInfoGenericFilter_cxx