]> Creatis software - clitk.git/blob - tools/clitkChangeImageInfoGenericFilter.cxx
Debug RTStruct conversion with empty struc
[clitk.git] / tools / clitkChangeImageInfoGenericFilter.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
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
8
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.
12
13   It is distributed under dual licence
14
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
20
21 #include "clitkChangeImageInfoGenericFilter.h"
22
23 // itk include
24 #include <itkChangeInformationImageFilter.h>
25
26 namespace clitk
27 {
28
29 //--------------------------------------------------------------------
30 ChangeImageInfoGenericFilter::ChangeImageInfoGenericFilter():
31   ImageToImageGenericFilter<Self>("ChangeImageInfo")
32 {
33   InitializeImageType<2>();
34   InitializeImageType<3>();
35   InitializeImageType<4>();
36 }
37 //--------------------------------------------------------------------
38
39 //--------------------------------------------------------------------
40 template<unsigned int Dim>
41 void ChangeImageInfoGenericFilter::InitializeImageType()
42 {
43   ADD_DEFAULT_IMAGE_TYPES(Dim);
44 }
45 //--------------------------------------------------------------------
46
47 //--------------------------------------------------------------------
48 void ChangeImageInfoGenericFilter::SetArgsInfo(const args_info_type & a)
49 {
50   mArgsInfo=a;
51   if (mArgsInfo.verbose_given)
52     SetIOVerbose(mArgsInfo.verbose_flag);
53   if (mArgsInfo.imagetypes_given && mArgsInfo.imagetypes_flag)
54     this->PrintAvailableImageTypes();
55
56   if (mArgsInfo.input_given) {
57     SetInputFilename(mArgsInfo.input_arg);
58   }
59   if (mArgsInfo.output_given) {
60     SetOutputFilename(mArgsInfo.output_arg);
61   }
62 }
63 //--------------------------------------------------------------------
64
65 //--------------------------------------------------------------------
66 // Update with the number of dimensions and the pixeltype
67 //--------------------------------------------------------------------
68 template<class InputImageType>
69 void
70 ChangeImageInfoGenericFilter::UpdateWithInputImageType()
71 {
72   // Reading input
73   typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
74
75   // Main filter
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);
80
81   // Direction
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."
87                 << std::endl;
88       exit(1);
89     }
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);
95   }
96
97   // Spacing
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."
103                 << std::endl;
104       exit(1);
105     }
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);
110   }
111
112   // Origin
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."
118                 << std::endl;
119       exit(1);
120     }
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);
125   }
126
127   ciif->Update();
128   this->template SetNextOutput<InputImageType>(ciif->GetOutput());
129 }
130 //--------------------------------------------------------------------
131
132 }//end clitk
133
134 #endif  //#define clitkChangeImageInfoGenericFilter_cxx