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 clitkResampleBSplineDeformableTransformImageFilter_txx
19 #define clitkResampleBSplineDeformableTransformImageFilter_txx
21 /* =================================================
22 * @file clitkResampleBSplineDeformableTransformImageFilter.txx
28 ===================================================*/
34 //-------------------------------------------------------------------
35 // Update with the number of dimensions
36 //-------------------------------------------------------------------
37 template<class InputImageType, class OutputImageType>
38 ResampleBSplineDeformableTransformImageFilter<InputImageType, OutputImageType>::ResampleBSplineDeformableTransformImageFilter()
41 m_SplineOrders.Fill(3);
43 m_OutputSpacing.Fill(1.0);
44 m_OutputOrigin.Fill(-1);
45 m_OutputStartIndex.Fill(0);
46 m_OutputDirection.SetIdentity();
49 m_Resampler = ResamplerType::New();
50 m_Function = FunctionType::New();
51 m_Identity = IdentityTransformType::New();
52 m_Decomposition = DecompositionType::New();
55 m_Resampler->SetInterpolator( m_Function );
56 m_Resampler->SetTransform( m_Identity );
57 m_Decomposition->SetInput( m_Resampler->GetOutput() );
61 //-------------------------------------------------------------------
63 //-------------------------------------------------------------------
64 template <class InputImageType, class OutputImageType>
66 ResampleBSplineDeformableTransformImageFilter<InputImageType, OutputImageType>::SetOutputSpacing( const double* spacing )
68 OutputSpacingType s(spacing);
69 this->SetOutputSpacing( s );
72 //-------------------------------------------------------------------
74 //-------------------------------------------------------------------
75 template <class InputImageType, class OutputImageType>
77 ResampleBSplineDeformableTransformImageFilter<InputImageType, OutputImageType>::SetOutputOrigin( const double* origin )
79 OutputPointType p(origin);
80 this->SetOutputOrigin( p );
85 //-------------------------------------------------------------------
86 // Update with the number of dimensions and the pixeltype
87 //-------------------------------------------------------------------
88 template <class InputImageType, class OutputImageType>
90 ResampleBSplineDeformableTransformImageFilter<InputImageType, OutputImageType>::GenerateData()
94 bool sizeIsCorrect=true;
96 if (this->GetInput()->GetSpacing() !=m_OutputSpacing)
98 else if (this->GetInput()->GetLargestPossibleRegion().GetSize()!=m_Size)
100 else if (this->GetInput()->GetOrigin()!=m_OutputOrigin)
103 // No resampling resquired
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());
111 this->GraftOutput(caster->GetOutput());
117 if(m_Verbose)std::cout<<"Resampling transform..."<<std::endl;
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 );
127 // Transform the values back to Bspline coefficients
128 m_Decomposition->SetSplineOrders( m_SplineOrders );
129 m_Decomposition->Update();
130 this->GraftOutput( m_Decomposition->GetOutput() );
138 #endif //#define clitkResampleBSplineDeformableTransformImageFilter_txx