]> Creatis software - clitk.git/blob - registration/clitkResampleBSplineDeformableTransformImageFilter.txx
Debug RTStruct conversion with empty struc
[clitk.git] / registration / clitkResampleBSplineDeformableTransformImageFilter.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://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 clitkResampleBSplineDeformableTransformImageFilter_txx
19 #define clitkResampleBSplineDeformableTransformImageFilter_txx
20
21 /* =================================================
22  * @file   clitkResampleBSplineDeformableTransformImageFilter.txx
23  * @author 
24  * @date   
25  * 
26  * @brief 
27  * 
28  ===================================================*/
29
30
31 namespace clitk
32 {
33
34   //-------------------------------------------------------------------
35   // Update with the number of dimensions
36   //-------------------------------------------------------------------
37   template<class InputImageType, class OutputImageType>
38   ResampleBSplineDeformableTransformImageFilter<InputImageType, OutputImageType>::ResampleBSplineDeformableTransformImageFilter()
39   {
40    m_Verbose=false;
41    m_SplineOrders.Fill(3);
42    m_Size.Fill(0);
43    m_OutputSpacing.Fill(1.0);
44    m_OutputOrigin.Fill(-1);
45    m_OutputStartIndex.Fill(0);
46    m_OutputDirection.SetIdentity();
47    
48    // Components
49    m_Resampler = ResamplerType::New();
50    m_Function = FunctionType::New();
51    m_Identity = IdentityTransformType::New();
52    m_Decomposition = DecompositionType::New();
53    
54    // Connect
55    m_Resampler->SetInterpolator( m_Function );
56    m_Resampler->SetTransform( m_Identity );
57    m_Decomposition->SetInput( m_Resampler->GetOutput() );
58
59   }
60
61   //-------------------------------------------------------------------
62   // Output Info
63   //-------------------------------------------------------------------
64   template <class InputImageType, class  OutputImageType> 
65   void 
66   ResampleBSplineDeformableTransformImageFilter<InputImageType, OutputImageType>::SetOutputSpacing( const double* spacing )
67   {
68     OutputSpacingType s(spacing);
69     this->SetOutputSpacing( s );
70   }
71   
72   //-------------------------------------------------------------------
73   // Output Info
74   //-------------------------------------------------------------------
75   template <class InputImageType, class  OutputImageType> 
76   void 
77   ResampleBSplineDeformableTransformImageFilter<InputImageType, OutputImageType>::SetOutputOrigin( const double* origin )
78   {
79     OutputPointType p(origin);
80     this->SetOutputOrigin( p );
81   }
82
83
84
85   //-------------------------------------------------------------------
86   // Update with the number of dimensions and the pixeltype
87   //-------------------------------------------------------------------
88   template <class InputImageType, class  OutputImageType> 
89   void 
90   ResampleBSplineDeformableTransformImageFilter<InputImageType, OutputImageType>::GenerateData()
91   {
92
93     // Resample?
94     bool sizeIsCorrect=true;
95     
96     if (this->GetInput()->GetSpacing()  !=m_OutputSpacing)
97       sizeIsCorrect=false;
98     else if (this->GetInput()->GetLargestPossibleRegion().GetSize()!=m_Size)
99       sizeIsCorrect=false;
100     else if (this->GetInput()->GetOrigin()!=m_OutputOrigin)
101       sizeIsCorrect=false;
102     
103     // No resampling resquired
104     if (sizeIsCorrect)
105       {
106         if(m_Verbose)std::cout<<"Output properties are up to date, no resampling required!"<<std::endl;
107         typedef itk::CastImageFilter<InputImageType, OutputImageType>  CastImageFilterType;
108         typename CastImageFilterType::Pointer caster = CastImageFilterType::New();
109         caster->SetInput(this->GetInput());
110         caster->Update();
111         this->GraftOutput(caster->GetOutput());
112       }
113
114     // Resample
115     else
116       {
117         if(m_Verbose)std::cout<<"Resampling transform..."<<std::endl;
118
119         // Resample the coeeficients to values of correct size, spacing,...
120         m_Resampler->SetInput( this->GetInput() );
121         m_Resampler->SetSize( m_Size);
122         m_Resampler->SetOutputSpacing( m_OutputSpacing );
123         m_Resampler->SetOutputOrigin( m_OutputOrigin );
124         m_Resampler->SetOutputDirection( m_OutputDirection );
125         m_Resampler->SetOutputStartIndex( m_OutputStartIndex );
126         
127         // Transform the values back to Bspline coefficients
128         m_Decomposition->SetSplineOrders( m_SplineOrders );     
129         m_Decomposition->Update();
130         this->GraftOutput( m_Decomposition->GetOutput() );
131       }
132
133   }
134
135
136 }//end clitk
137  
138 #endif //#define clitkResampleBSplineDeformableTransformImageFilter_txx