]> Creatis software - clitk.git/blob - itk/clitkBackProjectImageFilter.h
8ff8def40ec2cbf344ee7d4bd643d20d4f680623
[clitk.git] / itk / clitkBackProjectImageFilter.h
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 __clitkBackProjectImageFilter_h
19 #define __clitkBackProjectImageFilter_h
20 #include "clitkTransformUtilities.h"
21
22 //itk include
23 #include "itkInterpolateImageFunction.h"                                  
24 #include "itkImageToImageFilter.h"                                  
25 #include "itkTransform.h"
26 #include "itkVector.h"
27
28
29 namespace clitk
30 {
31
32   template <class InputImageType, class OutputImageType>
33   class ITK_EXPORT BackProjectImageFilter : 
34     public itk::ImageToImageFilter<InputImageType,OutputImageType> 
35   {
36   public:
37     //------------------------------------
38     // Standard itk typedefs
39     //-----------------------------------
40     typedef BackProjectImageFilter                                  Self;
41     typedef itk::ImageToImageFilter<InputImageType,OutputImageType> Superclass;
42     typedef itk::SmartPointer<Self>                                 Pointer;
43     typedef itk::SmartPointer<const Self>                           ConstPointer;
44
45     /** Method for creation through the object factory. */
46     itkNewMacro(Self); 
47
48     /** Run-time type information (and related methods). */
49     itkTypeMacro(BackProjectImageFilter, ImageToImageFilter); 
50
51     /** Dimension of the domain space. */
52     itkStaticConstMacro(InputImageDimension, unsigned int, Superclass::InputImageDimension);
53     itkStaticConstMacro(OutputImageDimension, unsigned int, Superclass::OutputImageDimension);
54
55     //------------------------------------
56     // Typedefs
57     //------------------------------------
58     typedef typename InputImageType::Pointer InputImagePointer;
59     typedef typename InputImageType::ConstPointer InputImageConstPointer;
60     typedef typename InputImageType::PixelType InputPixelType;
61     typedef typename InputImageType::SizeType InputSizeType;
62     typedef typename InputImageType::SpacingType InputSpacingType;
63     typedef typename InputImageType::DirectionType InputDirectionType;
64     typedef typename InputImageType::IndexType InputIndexType;
65     typedef typename InputImageType::PointType InputPointType;
66     typedef typename itk::ContinuousIndex<double,InputImageDimension> ContinuousInputIndexType;
67     typedef typename InputImageType::RegionType InputImageRegionType;
68     typedef itk::Vector<double,InputImageDimension+1> HomogeneInputVectorType;
69     typedef itk::Vector<double,InputImageDimension> Homogene2DVectorType;
70     typedef itk::Point<double,InputImageDimension+1> HomogeneInputPointType;
71     typedef itk::Point<double,InputImageDimension> Homogene2DPointType;
72
73     typedef typename OutputImageType::Pointer OutputImagePointer;
74     typedef typename OutputImageType::ConstPointer OutputImageConstPointer;
75     typedef typename OutputImageType::PixelType OutputPixelType;
76     typedef typename OutputImageType::SizeType OutputSizeType;
77     typedef typename OutputImageType::SpacingType OutputSpacingType;
78     typedef typename OutputImageType::DirectionType OutputDirectionType;
79     typedef typename OutputImageType::IndexType OutputIndexType;
80     typedef typename OutputImageType::PointType OutputPointType;
81     typedef typename itk::ContinuousIndex<double,OutputImageDimension> ContinuousOutputIndexType;
82     typedef typename OutputImageType::RegionType OutputImageRegionType;
83     typedef itk::Vector<double,OutputImageDimension+1> HomogeneOutputVectorType;
84     typedef itk::Point<double,OutputImageDimension+1> HomogeneOutputPointType;
85
86     typedef itk::Matrix<double,4,4> MatrixType;
87   
88     //------------------------------------
89     // Projection geometry
90     //-----------------------------------
91     void SetIsoCenter( const OutputPointType& i )
92     {
93       if( m_IsoCenter!=i)
94         {
95           m_IsoCenter=i;
96           m_IsInitialized=false;
97           this->Modified();
98         }
99     }
100        
101     void SetSourceToScreen(const double &s)
102     {
103       if( m_SourceToScreen!=s)
104         {
105           m_SourceToScreen=s;
106           m_IsInitialized=false;
107           this->Modified();
108         }
109     }
110     
111     void SetSourceToAxis( const double& s)
112     {
113       if( m_SourceToAxis!=s)
114         {
115           m_SourceToAxis=s;
116           m_IsInitialized=false;
117           this->Modified();
118         }
119     }
120     
121     void SetProjectionAngle(const double& s)
122     {
123       if( m_SourceToScreen!=s)
124         {
125           m_ProjectionAngle=s;
126           m_IsInitialized=false;
127           this->Modified();
128         }
129     }
130     
131     void SetRigidTransformMatrix(const MatrixType& m)
132     {
133       if(m_RigidTransformMatrix != m)
134         {
135           m_RigidTransformMatrix=m;
136           m_IsInitialized=false;
137           this->Modified();
138         }
139     }
140        
141     void SetEdgePaddingValue(const OutputPixelType& p)
142     {
143       if (m_EdgePaddingValue!=p)
144         {
145           m_EdgePaddingValue=p;
146           m_IsInitialized=false;
147           this->Modified();
148         }
149     }
150
151     void SetPanelShift(double x, double y)
152     {
153       m_PanelShift[0] = x;
154       m_PanelShift[1] = y;
155     }
156     //     itkSetMacro(IsoCenter, OutputPointType);
157     //     itkGetConstReferenceMacro(IsoCenter, OutputPointType)
158     //     itkSetMacro( SourceToScreen, double );
159     //     itkGetMacro( SourceToScreen, double );
160     //     itkSetMacro( SourceToAxis, double );
161     //     itkGetMacro( SourceToAxis, double );
162     //     itkSetMacro(RigidTransformMatrix, itk::Matrix<double,4,4>));
163     //     itkGetConstReferenceMacro(RigidTransformMatrix, itk::Matrix<double,4,4>);
164     //     void SetRigidTransformMatrix(const  itk::Matrix<double,4,4> & m);
165     //     itk::Matrix<double,4,4> GetRigidTransformMatrix( void ){return m_RigidTransformMatrix;}
166     //     itkSetMacro( EdgePaddingValue, OutputPixelType );
167     //     itkGetMacro( EdgePaddingValue, OutputPixelType );
168     //     itkSetMacro( ProjectionAngle, double );
169     //     itkGetMacro( ProjectionAngle, double );
170   
171     //-----------------------------------
172     //Output image properties
173     //-----------------------------------
174     void SetOutputSize(const OutputSizeType& p)
175     {
176       if (m_OutputSize!=p)
177         {
178           m_OutputSize=p;
179           m_IsInitialized=false;
180           this->Modified();
181         }
182     }
183      
184     /** Set the output image spacing. */
185     void SetOutputSpacing(const OutputSpacingType & p)
186     {
187       if (m_OutputSpacing!=p)
188         {
189           m_OutputSpacing=p;
190           m_IsInitialized=false;
191           this->Modified();
192         }
193     }
194     
195     /** Set the output image origin. */
196     void SetOutputOrigin(const OutputPointType& p)
197     {
198       if (m_OutputOrigin!=p)
199         {
200           m_OutputOrigin=p;
201           m_IsInitialized=false;
202           this->Modified();
203         }
204     }
205
206     /** Helper method to set the output parameters based on this image */
207     void SetOutputParametersFromImage( const OutputImagePointer image );
208
209     /** Helper method to set the output parameters based on this image */
210     void SetOutputParametersFromImage( const OutputImageConstPointer  image );
211
212
213     void Initialize(void) throw (itk::ExceptionObject);
214
215   protected:
216
217     // Constructor
218     BackProjectImageFilter();
219
220     // Destructor
221     ~BackProjectImageFilter(){};
222
223     // Print the object
224     void PrintSelf(std::ostream& os, itk::Indent indent) const;
225
226     // Calculate the projection matrix
227     void CalculateProjectionMatrix(void);
228
229     // Calculate the coordinate increments
230     void CalculateCoordinateIncrements( void );
231  
232     /** Overrides GenerateInputRequestedRegion() in order to inform
233      * the pipeline execution model of different input requested regions
234      * than the output requested region.
235      * \sa ImageToImageFilter::GenerateInputRequestedRegion() */
236     virtual void GenerateInputRequestedRegion();
237     
238     // Generate Output Information
239     virtual void GenerateOutputInformation (void);
240
241     // Threaded Generate Data
242     void BeforeThreadedGenerateData(void );
243   
244     // Threaded Generate Data
245     void ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread, itk::ThreadIdType threadId );
246  
247     //------------------------------------------------
248     //Member data
249     //------------------------------------------------
250     bool m_IsInitialized;
251     
252     // Input
253     InputImagePointer m_ModifiedInput;
254
255     // Projection geometry
256     OutputPointType m_IsoCenter;
257     itk::Matrix<double,3,4>  m_ProjectionMatrix;
258     HomogeneInputVectorType m_LineInc, m_ColInc, m_PlaneInc;
259     // Homogene2DVectorType m_LineInc, m_ColInc, m_PlaneInc;
260     MatrixType  m_RigidTransformMatrix;
261     double  m_SourceToScreen;
262     double  m_SourceToAxis;
263     OutputPixelType m_EdgePaddingValue;
264     double m_ProjectionAngle;
265     double m_PanelShift[2];
266
267     // Output image info
268     OutputSizeType                m_OutputSize;        // Size of the output image
269     OutputSpacingType             m_OutputSpacing;     // output image spacing
270     OutputPointType               m_OutputOrigin;      // output image origin
271    
272   private:
273     BackProjectImageFilter( const Self& ); //purposely not implemented
274     void operator=( const Self& ); //purposely not implemented
275
276
277   };
278
279 } // namespace clitk
280
281 #ifndef ITK_MANUAL_INSTANTIATION
282 #include "clitkBackProjectImageFilter.txx"
283 #endif
284
285 #endif