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://oncora1.lyon.fnclcc.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 CLITKCONEBEAMPROJECTIMAGEGENERICFILTER_CXX
19 #define CLITKCONEBEAMPROJECTIMAGEGENERICFILTER_CXX
22 * @file clitkConeBeamProjectImageGenericFilter.cxx
23 * @author Jef Vandemeulebroucke <jef@creatis.insa-lyon.fr>
24 * @date Wed April 30 13:47:57 2008
31 #include "clitkConeBeamProjectImageGenericFilter.h"
36 //====================================================================
38 ConeBeamProjectImageGenericFilter::ConeBeamProjectImageGenericFilter()
44 //====================================================================
46 void ConeBeamProjectImageGenericFilter::Update()
48 //Read the PixelType and dimension of the input image
50 std::string PixelType;
51 clitk::ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType);
54 if (m_Verbose) std::cout << "Input was detected to be "<< Dimension << "D and " << PixelType << "..." << std::endl;
56 if(PixelType == "short"){
57 if (m_Verbose) std::cout << "Launching Projection in signed short..." << std::endl;
58 UpdateWithPixelType<signed short>();
61 // else if(PixelType == "unsigned_short"){
62 // if (m_Verbose) std::cout << "Launching Projection in unsigned_short..." << std::endl;
63 // UpdateWithPixelType<unsigned short>();
66 else if (PixelType == "unsigned_char"){
67 if (m_Verbose) std::cout << "Launching Projection in unsigned_char..." << std::endl;
68 UpdateWithPixelType<unsigned char>();
71 // else if (PixelType == "char"){
72 // if (m_Verbose) std::cout << "Launching Projection in signed_char..." << std::endl;
73 // UpdateWithPixelType<signed char>();
76 if (m_Verbose) std::cout << "Launching Projection in float..." << std::endl;
77 UpdateWithPixelType<float>();
81 else {itkExceptionMacro(<< "Input Image dimension is " << Dimension
82 << " but I can only work on 3D images.");
86 //================================================================================
87 template <class PixelType> void ConeBeamProjectImageGenericFilter::UpdateWithPixelType()
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);
98 typename InputImageType::Pointer input = reader->GetOutput();
100 // Define the output type
102 typedef float OutputPixelType;
103 const unsigned int OutputImageDimension=2;
104 typedef itk::Image<OutputPixelType, OutputImageDimension> OutputImageType;
106 // Create the ConeBeamProjectImageFilter
107 typedef clitk::ConeBeamProjectImageFilter<InputImageType, OutputImageType> ConeBeamProjectImageFilterType;
108 typename ConeBeamProjectImageFilterType::Pointer filter=ConeBeamProjectImageFilterType::New();
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);
115 // Projection parameters
116 typename InputImageType::PointType iso;
118 if (m_ArgsInfo.iso_given)
119 for(i=0;i<InputImageDimension;i++)
121 iso[i]=m_ArgsInfo.iso_arg[i];
122 filter->SetIsoCenter(iso);
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)
129 itk::Matrix<double,4,4> rt =ReadMatrix3D(m_ArgsInfo.matrix_arg);
130 filter->SetRigidTransformMatrix(rt);
132 filter->SetEdgePaddingValue(static_cast<OutputPixelType>(m_ArgsInfo.pad_arg));
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 if (strcmp(m_ArgsInfo.panel_position_arg,"small") !=0)
137 filter->SetPanelShift(0.);
138 else if (strcmp(m_ArgsInfo.panel_position_arg,"medium") !=0)
139 filter->SetPanelShift(114.84);
140 else if (strcmp(m_ArgsInfo.panel_position_arg,"large") !=0)
141 filter->SetPanelShift(190.);
142 else assert(false); //Unsupported panel position
144 if (m_ArgsInfo.like_given)
146 typedef itk::ImageFileReader<OutputImageType> ReaderType;
147 ReaderType::Pointer reader2=ReaderType::New();
148 reader2->SetFileName(m_ArgsInfo.like_arg);
151 OutputImageType::Pointer image=reader2->GetOutput();
152 filter->SetOutputParametersFromImage(image);
156 if (m_ArgsInfo.origin_given)
158 OutputImageType::PointType origin;
159 for(i=0;i<OutputImageDimension;i++)
160 origin[i]=m_ArgsInfo.origin_arg[i];
161 filter->SetOutputOrigin(origin);
163 if (m_ArgsInfo.spacing_given)
165 OutputImageType::SpacingType spacing;
166 for(i=0;i<OutputImageDimension;i++)
167 spacing[i]=m_ArgsInfo.spacing_arg[i];
168 filter->SetOutputSpacing(spacing);
170 if (m_ArgsInfo.size_given)
172 OutputImageType::SizeType size;
173 for(i=0;i<OutputImageDimension;i++)
174 size[i]=m_ArgsInfo.size_arg[i];
175 filter->SetOutputSize(size);
183 OutputImageType::Pointer output=filter->GetOutput();
186 typedef itk::ImageFileWriter<OutputImageType> OutputWriterType;
187 OutputWriterType::Pointer outputWriter = OutputWriterType::New();
188 outputWriter->SetInput(output);
189 outputWriter->SetFileName(m_ArgsInfo.output_arg);
190 if (m_Verbose)std::cout<<"Writing projected image..."<<std::endl;
191 outputWriter->Update();
195 //====================================================================
198 #endif //#define CLITKCONEBEAMPROJECTIMAGEGENERICFILTER_CXX