]> Creatis software - clitk.git/blob - tools/clitkConeBeamProjectImageGenericFilter.txx
vv now builds even with all options turned off
[clitk.git] / tools / clitkConeBeamProjectImageGenericFilter.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://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_TXX
19 #define CLITKCONEBEAMPROJECTIMAGEGENERICFILTER_TXX
20 /**
21    =================================================
22    * @file   clitkConeBeamProjectImageGenericFilter.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  PixelType> void ConeBeamProjectImageGenericFilter::UpdateWithPixelType()
36   {
37     
38     //===================================================================
39     // Read the input image 
40     const unsigned int InputImageDimension=3;
41     typedef itk::Image<PixelType, InputImageDimension> InputImageType;
42     typedef itk::ImageFileReader<InputImageType> ImageReaderType;
43     typename  ImageReaderType::Pointer reader = ImageReaderType::New();
44     reader->SetFileName(m_InputFileName);
45     reader->Update();
46     typename InputImageType::Pointer input = reader->GetOutput();
47
48     // Define the output type
49     //JV always float?
50     typedef float OutputPixelType; 
51     const unsigned int OutputImageDimension=2;
52     typedef itk::Image<OutputPixelType, OutputImageDimension> OutputImageType;
53
54     // Create the ConeBeamProjectImageFilter
55     typedef clitk::ConeBeamProjectImageFilter<InputImageType, OutputImageType> ConeBeamProjectImageFilterType;
56     typename ConeBeamProjectImageFilterType::Pointer filter=ConeBeamProjectImageFilterType::New();
57
58     // Pass all the necessary parameters
59     filter->SetInput(input);
60     filter->SetVerbose(m_Verbose);
61     if (m_ArgsInfo.threads_given) filter->SetNumberOfThreads(m_ArgsInfo.threads_arg);
62     
63     // Projection parameters
64     typename InputImageType::PointType iso;
65     unsigned int i;
66     if (m_ArgsInfo.iso_given)
67       for(i=0;i<InputImageDimension;i++)
68         {
69           iso[i]=m_ArgsInfo.iso_arg[i];
70           filter->SetIsoCenter(iso);
71         }
72     filter->SetSourceToScreen(m_ArgsInfo.screen_arg);
73     filter->SetSourceToAxis(m_ArgsInfo.axis_arg); 
74     filter->SetProjectionAngle(m_ArgsInfo.angle_arg);
75     if (m_ArgsInfo.matrix_given)
76       {
77         itk::Matrix<double,4,4> rt =ReadMatrix3D(m_ArgsInfo.matrix_arg);
78         filter->SetRigidTransformMatrix(rt);
79       }
80     filter->SetEdgePaddingValue(static_cast<OutputPixelType>(m_ArgsInfo.pad_arg));
81
82     // Output image info
83     if (m_ArgsInfo.like_given)
84       {
85         typedef itk::ImageFileReader<OutputImageType> ReaderType;
86         ReaderType::Pointer reader2=ReaderType::New();
87         reader2->SetFileName(m_ArgsInfo.like_arg);
88         reader2->Update();
89
90         OutputImageType::Pointer image=reader2->GetOutput();
91         filter->SetOutputParametersFromImage(image);
92       }
93     else
94       {
95         if (m_ArgsInfo.origin_given)
96           {
97             OutputImageType::PointType origin;
98             for(i=0;i<OutputImageDimension;i++)
99               origin[i]=m_ArgsInfo.origin_arg[i];
100             filter->SetOutputOrigin(origin);
101           }
102         if (m_ArgsInfo.spacing_given)
103           {
104             OutputImageType::SpacingType spacing;
105             for(i=0;i<OutputImageDimension;i++)
106               spacing[i]=m_ArgsInfo.spacing_arg[i];
107             filter->SetOutputSpacing(spacing);
108           }
109         if (m_ArgsInfo.size_given)
110           {
111             OutputImageType::SizeType size;
112             for(i=0;i<OutputImageDimension;i++)
113               size[i]=m_ArgsInfo.size_arg[i];
114             filter->SetOutputSize(size);
115           }
116       }
117
118     //Go
119     filter->Update();
120     
121     //Get the output
122     OutputImageType::Pointer output=filter->GetOutput();
123  
124     //Write the output
125     typedef itk::ImageFileWriter<OutputImageType> OutputWriterType;
126     OutputWriterType::Pointer outputWriter = OutputWriterType::New();
127     outputWriter->SetInput(output);
128     outputWriter->SetFileName(m_ArgsInfo.output_arg); 
129     if (m_Verbose)std::cout<<"Writing projected image..."<<std::endl;
130     outputWriter->Update(); 
131   }
132
133 }
134  
135 #endif //#define CLITKGENERICIMAGEFILTER