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 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 DD(m_ArgsInfo.panel_position_arg);
135 if (m_ArgsInfo.panel_shift_given) // one should read the specific values for each angle in Frame.dbf
136 filter->SetPanelShift(m_ArgsInfo.panel_shift_arg[0], m_ArgsInfo.panel_shift_arg[1]);
137 else { // approximate panel positions hard coded values for the elekta synergy
138 if (strcmp(m_ArgsInfo.panel_position_arg,"small") ==0)
139 filter->SetPanelShift(0., 0.);
140 else if (strcmp(m_ArgsInfo.panel_position_arg,"medium") ==0)
141 filter->SetPanelShift(114.84, 0.); // VD : 120 , 0 ?
142 else if (strcmp(m_ArgsInfo.panel_position_arg,"large") ==0)
143 filter->SetPanelShift(190., 0.);
144 else assert(false); //Unsupported panel position
147 if (m_ArgsInfo.like_given)
149 typedef itk::ImageFileReader<OutputImageType> ReaderType;
150 ReaderType::Pointer reader2=ReaderType::New();
151 reader2->SetFileName(m_ArgsInfo.like_arg);
154 OutputImageType::Pointer image=reader2->GetOutput();
155 filter->SetOutputParametersFromImage(image);
159 if (m_ArgsInfo.origin_given)
161 OutputImageType::PointType origin;
162 for(i=0;i<OutputImageDimension;i++)
163 origin[i]=m_ArgsInfo.origin_arg[i];
164 filter->SetOutputOrigin(origin);
166 if (m_ArgsInfo.spacing_given)
168 OutputImageType::SpacingType spacing;
169 for(i=0;i<OutputImageDimension;i++)
170 spacing[i]=m_ArgsInfo.spacing_arg[i];
171 filter->SetOutputSpacing(spacing);
173 if (m_ArgsInfo.size_given)
175 OutputImageType::SizeType size;
176 for(i=0;i<OutputImageDimension;i++)
177 size[i]=m_ArgsInfo.size_arg[i];
178 filter->SetOutputSize(size);
186 OutputImageType::Pointer output=filter->GetOutput();
189 typedef itk::ImageFileWriter<OutputImageType> OutputWriterType;
190 OutputWriterType::Pointer outputWriter = OutputWriterType::New();
191 outputWriter->SetInput(output);
192 outputWriter->SetFileName(m_ArgsInfo.output_arg);
193 if (m_Verbose)std::cout<<"Writing projected image..."<<std::endl;
194 outputWriter->Update();
198 //====================================================================
201 #endif //#define CLITKCONEBEAMPROJECTIMAGEGENERICFILTER_CXX