]> Creatis software - clitk.git/blob - tools/clitkConeBeamProjectImageGenericFilter.cxx
fix string comparison
[clitk.git] / tools / clitkConeBeamProjectImageGenericFilter.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://oncora1.lyon.fnclcc.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 CLITKCONEBEAMPROJECTIMAGEGENERICFILTER_CXX
19 #define CLITKCONEBEAMPROJECTIMAGEGENERICFILTER_CXX
20
21 /**
22  * @file   clitkConeBeamProjectImageGenericFilter.cxx
23  * @author Jef Vandemeulebroucke <jef@creatis.insa-lyon.fr>
24  * @date   Wed April 30  13:47:57 2008
25  * 
26  * @brief  
27  * 
28  * 
29  */
30
31 #include "clitkConeBeamProjectImageGenericFilter.h"
32
33 namespace clitk
34 {
35
36   //====================================================================
37   // Constructor
38   ConeBeamProjectImageGenericFilter::ConeBeamProjectImageGenericFilter()
39   {
40     m_Verbose=false;
41     m_InputFileName="";
42   }
43
44   //====================================================================
45   // Update
46   void ConeBeamProjectImageGenericFilter::Update()
47   {
48     //Read the PixelType and dimension of the input image
49     int Dimension;
50     std::string PixelType;
51     clitk::ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType);
52     if (Dimension == 3)
53       {
54         if (m_Verbose) std::cout  << "Input was detected to be "<< Dimension << "D and " << PixelType << "..." << std::endl;
55   
56         if(PixelType == "short"){  
57           if (m_Verbose) std::cout  << "Launching Projection in signed short..." << std::endl;
58           UpdateWithPixelType<signed short>(); 
59         }
60         
61 //      else if(PixelType == "unsigned_short"){  
62 //        if (m_Verbose) std::cout  << "Launching Projection in unsigned_short..." << std::endl;
63 //        UpdateWithPixelType<unsigned short>(); 
64 //      }
65         
66         else if (PixelType == "unsigned_char"){ 
67           if (m_Verbose) std::cout  << "Launching Projection in unsigned_char..." << std::endl;
68           UpdateWithPixelType<unsigned char>();
69         }
70         
71 //      else if (PixelType == "char"){ 
72 //        if (m_Verbose) std::cout  << "Launching Projection in signed_char..." << std::endl;
73 //        UpdateWithPixelType<signed char>();
74 //      }
75         else {
76           if (m_Verbose) std::cout  << "Launching Projection in float..." << std::endl;
77           UpdateWithPixelType<float>();
78         }
79       }
80     
81     else {itkExceptionMacro(<< "Input Image dimension is " << Dimension 
82                             << " but I can only work on 3D images.");
83     }
84   }
85   
86   //================================================================================
87   template <class  PixelType> void ConeBeamProjectImageGenericFilter::UpdateWithPixelType()
88   {
89     
90     //===================================================================
91     // Read the input image 
92     const unsigned int InputImageDimension=3;
93     typedef itk::Image<PixelType, InputImageDimension> InputImageType;
94     typedef itk::ImageFileReader<InputImageType> ImageReaderType;
95     typename  ImageReaderType::Pointer reader = ImageReaderType::New();
96     reader->SetFileName(m_InputFileName);
97     reader->Update();
98     typename InputImageType::Pointer input = reader->GetOutput();
99
100     // Define the output type
101     //JV always float?
102     typedef float OutputPixelType; 
103     const unsigned int OutputImageDimension=2;
104     typedef itk::Image<OutputPixelType, OutputImageDimension> OutputImageType;
105
106     // Create the ConeBeamProjectImageFilter
107     typedef clitk::ConeBeamProjectImageFilter<InputImageType, OutputImageType> ConeBeamProjectImageFilterType;
108     typename ConeBeamProjectImageFilterType::Pointer filter=ConeBeamProjectImageFilterType::New();
109
110     // Pass all the necessary parameters
111     filter->SetInput(input);
112     filter->SetVerbose(m_Verbose);
113     if (m_ArgsInfo.threads_given) filter->SetNumberOfThreads(m_ArgsInfo.threads_arg);
114     
115     // Projection parameters
116     typename InputImageType::PointType iso;
117     unsigned int i;
118     if (m_ArgsInfo.iso_given)
119       for(i=0;i<InputImageDimension;i++)
120         {
121           iso[i]=m_ArgsInfo.iso_arg[i];
122           filter->SetIsoCenter(iso);
123         }
124     filter->SetSourceToScreen(m_ArgsInfo.screen_arg);
125     filter->SetSourceToAxis(m_ArgsInfo.axis_arg); 
126     filter->SetProjectionAngle(m_ArgsInfo.angle_arg);
127     if (m_ArgsInfo.matrix_given)
128       {
129         itk::Matrix<double,4,4> rt =ReadMatrix3D(m_ArgsInfo.matrix_arg);
130         filter->SetRigidTransformMatrix(rt);
131       }
132     filter->SetEdgePaddingValue(static_cast<OutputPixelType>(m_ArgsInfo.pad_arg));
133
134     // Panel position (hard coded values for the elekta synergy)
135     // Two be more precise, one should read the specific values for each angle in Frame.dbf
136     DD(m_ArgsInfo.panel_position_arg);
137     if (strcmp(m_ArgsInfo.panel_position_arg,"small") ==0)
138       filter->SetPanelShift(0.);
139     else if (strcmp(m_ArgsInfo.panel_position_arg,"medium") ==0)
140       filter->SetPanelShift(114.84);
141     else if (strcmp(m_ArgsInfo.panel_position_arg,"large") ==0)
142       filter->SetPanelShift(190.);
143     else assert(false); //Unsupported panel position
144     // Output image info
145     if (m_ArgsInfo.like_given)
146       {
147         typedef itk::ImageFileReader<OutputImageType> ReaderType;
148         ReaderType::Pointer reader2=ReaderType::New();
149         reader2->SetFileName(m_ArgsInfo.like_arg);
150         reader2->Update();
151
152         OutputImageType::Pointer image=reader2->GetOutput();
153         filter->SetOutputParametersFromImage(image);
154       }
155     else
156       {
157         if (m_ArgsInfo.origin_given)
158           {
159             OutputImageType::PointType origin;
160             for(i=0;i<OutputImageDimension;i++)
161               origin[i]=m_ArgsInfo.origin_arg[i];
162             filter->SetOutputOrigin(origin);
163           }
164         if (m_ArgsInfo.spacing_given)
165           {
166             OutputImageType::SpacingType spacing;
167             for(i=0;i<OutputImageDimension;i++)
168               spacing[i]=m_ArgsInfo.spacing_arg[i];
169             filter->SetOutputSpacing(spacing);
170           }
171         if (m_ArgsInfo.size_given)
172           {
173             OutputImageType::SizeType size;
174             for(i=0;i<OutputImageDimension;i++)
175               size[i]=m_ArgsInfo.size_arg[i];
176             filter->SetOutputSize(size);
177           }
178       }
179
180     //Go
181     filter->Update();
182     
183     //Get the output
184     OutputImageType::Pointer output=filter->GetOutput();
185  
186     //Write the output
187     typedef itk::ImageFileWriter<OutputImageType> OutputWriterType;
188     OutputWriterType::Pointer outputWriter = OutputWriterType::New();
189     outputWriter->SetInput(output);
190     outputWriter->SetFileName(m_ArgsInfo.output_arg); 
191     if (m_Verbose)std::cout<<"Writing projected image..."<<std::endl;
192     outputWriter->Update(); 
193   }
194
195
196   //====================================================================
197
198 }
199 #endif  //#define CLITKCONEBEAMPROJECTIMAGEGENERICFILTER_CXX