]> Creatis software - clitk.git/blob - tools/clitkBackProjectImageGenericFilter.txx
Set mode of regular files to non-executable (644) instead of executable (755)
[clitk.git] / tools / clitkBackProjectImageGenericFilter.txx
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 CLITKBACKPROJECTIMAGEGENERICFILTER_TXX
19 #define CLITKBACKPROJECTIMAGEGENERICFILTER_TXX
20 /**
21    =================================================
22    * @file   clitkBackProjectImageGenericFilter.txx
23    * @author Jef Vandemeulebroucke <jef@creatis.insa-lyon.fr>
24    * @date   30 April 2008
25    * 
26    * @brief Project a 3D image using a cone-beam geometry
27    * 
28    =================================================*/
29
30
31 namespace clitk
32 {
33
34   //================================================================================
35   template <class  InputPixelType> void BackProjectImageGenericFilter::UpdateWithPixelType()
36   {
37    
38     //---------------------------------
39     // Define the images
40     //---------------------------------
41     const unsigned int InputImageDimension=2;
42     typedef itk::Image<InputPixelType, InputImageDimension> InputImageType;
43     typedef itk::ImageFileReader<InputImageType> ImageReaderType;
44     typename  ImageReaderType::Pointer reader = ImageReaderType::New();
45     reader->SetFileName(m_InputFileName);
46     reader->Update();
47     typename InputImageType::Pointer input = reader->GetOutput();
48
49     //Define the output type
50     //JV always float?
51     const unsigned int OutputImageDimension=3;    
52     typedef float OutputPixelType;    
53     typedef itk::Image<OutputPixelType, OutputImageDimension> OutputImageType;
54    
55     //Create the BackProjectImageFilter
56     typedef BackProjectImageFilter<InputImageType, OutputImageType> BackProjectImageFilterType;
57     typename BackProjectImageFilterType::Pointer filter=BackProjectImageFilterType::New();
58    
59
60     //---------------------------------
61     //Pass all the necessary parameters
62     //---------------------------------
63     unsigned int i=0;
64     filter->SetInput(input);
65     if (m_ArgsInfo.threads_given) filter->SetNumberOfThreads(m_ArgsInfo.threads_arg);
66    
67     //Projection parameters
68     OutputImageType::PointType iso;
69     if (m_ArgsInfo.iso_given)
70       {
71         for(i=0;i<OutputImageDimension;i++)
72           iso[i]=m_ArgsInfo.iso_arg[i];
73         filter->SetIsoCenter(iso);
74       }
75     filter->SetSourceToScreen(m_ArgsInfo.screen_arg);
76     filter->SetSourceToAxis(m_ArgsInfo.axis_arg); 
77     filter->SetProjectionAngle(m_ArgsInfo.angle_arg);
78     if (m_ArgsInfo.matrix_given)
79       {
80         itk::Matrix<double,4,4> rt =ReadMatrix3D(m_ArgsInfo.matrix_arg);
81         filter->SetRigidTransformMatrix(rt);
82       }
83     filter->SetEdgePaddingValue(static_cast<OutputPixelType>(m_ArgsInfo.pad_arg));
84     
85     //Output image info
86     if (m_ArgsInfo.like_given)
87       {
88         typedef itk::ImageFileReader<OutputImageType> ReaderType;
89         ReaderType::Pointer reader2=ReaderType::New();
90         reader2->SetFileName(m_ArgsInfo.like_arg);
91         reader2->Update();
92
93         OutputImageType::Pointer image=reader2->GetOutput();
94         filter->SetOutputParametersFromImage(image);
95       }
96     else
97       {
98         if(m_ArgsInfo.origin_given)
99           {
100             OutputImageType::PointType origin;
101             for(i=0;i<OutputImageDimension;i++)
102               origin[i]=m_ArgsInfo.origin_arg[i];
103             filter->SetOutputOrigin(origin);
104           }
105         if (m_ArgsInfo.spacing_given)
106           {
107             OutputImageType::SpacingType spacing;
108             for(i=0;i<OutputImageDimension;i++)
109               spacing[i]=m_ArgsInfo.spacing_arg[i];
110             filter->SetOutputSpacing(spacing);
111           }
112         if (m_ArgsInfo.spacing_given)
113           {
114             OutputImageType::SizeType size;
115             for(i=0;i<OutputImageDimension;i++)
116               size[i]=m_ArgsInfo.size_arg[i];
117             filter->SetOutputSize(size);
118           }
119       }
120
121     //Go
122     filter->Update();
123     
124     //Get the output
125     OutputImageType::Pointer output=filter->GetOutput();
126  
127     //Write the output
128     typedef itk::ImageFileWriter<OutputImageType> OutputWriterType;
129     OutputWriterType::Pointer outputWriter = OutputWriterType::New();
130     outputWriter->SetInput(output);
131     outputWriter->SetFileName(m_ArgsInfo.output_arg); 
132     if (m_Verbose)std::cout<<"Writing back projected image..."<<std::endl;
133     outputWriter->Update(); 
134   }
135
136 }
137  
138 #endif //#define CLITKBACKPROJECTIMAGEGENERICFILTER_TXX