1
/*=========================================================================
3
* Copyright Insight Software Consortium
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0.txt
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
17
*=========================================================================*/
18
#ifndef sitkCreateInterpolator_hxx
19
#define sitkCreateInterpolator_hxx
22
#include "sitkInterpolator.h"
23
#include <itkNearestNeighborInterpolateImageFunction.h>
24
#include <itkLinearInterpolateImageFunction.h>
25
#include <itkBSplineInterpolateImageFunction.h>
26
#include <itkGaussianInterpolateImageFunction.h>
27
#include <itkLabelImageGaussianInterpolateImageFunction.h>
28
#include <itkWindowedSincInterpolateImageFunction.h>
36
template<typename TInterpolatorType>
37
typename TInterpolatorType::Pointer
38
ConditionalCreateInterpolator( const TrueType & )
40
return TInterpolatorType::New();
43
template<typename TInterpolatorType>
45
ConditionalCreateInterpolator( const FalseType & )
50
template< typename TImageType >
51
typename itk::InterpolateImageFunction< TImageType, double >::Pointer
52
CreateInterpolator( const TImageType *image, InterpolatorEnum itype )
54
typedef typename itk::InterpolateImageFunction< TImageType, double >::Pointer RType;
55
typedef typename itk::ZeroFluxNeumannBoundaryCondition<TImageType,TImageType> BoundaryCondition;
56
//typedef typename itk::ConstantBoundaryCondition<TImageType> BoundaryCondition;
58
typedef typename TImageType::SpacingType SpacingType;
60
static const unsigned int WindowingRadius = 5;
62
const SpacingType &spacing = image->GetSpacing();
66
case sitkNearestNeighbor:
68
typedef itk::NearestNeighborInterpolateImageFunction<TImageType, double> InterpolatorType;
69
return RType( InterpolatorType::New() );
73
typedef itk::LinearInterpolateImageFunction<TImageType, double> InterpolatorType;
74
return RType( InterpolatorType::New() );
78
typedef itk::BSplineInterpolateImageFunction<TImageType, double> InterpolatorType;
79
return RType( ConditionalCreateInterpolator<InterpolatorType>( typename IsBasic<TImageType>::Type() ) );
83
typedef itk::GaussianInterpolateImageFunction<TImageType, double> InterpolatorType;
85
typename InterpolatorType::ArrayType sigma;
87
for( unsigned int i = 0; i < TImageType::ImageDimension; ++i )
89
sigma[i] = 0.8*spacing[i];
91
typename InterpolatorType::Pointer p = InterpolatorType::New();
96
case sitkLabelGaussian:
98
typedef itk::LabelImageGaussianInterpolateImageFunction<TImageType, double> InterpolatorType;
100
typename InterpolatorType::ArrayType sigma;
102
for( unsigned int i = 0; i < TImageType::ImageDimension; ++i )
104
sigma[i] = spacing[i];
106
typename InterpolatorType::Pointer p = InterpolatorType::New();
111
case sitkHammingWindowedSinc:
114
typedef typename itk::Function::HammingWindowFunction<WindowingRadius, double, double > WindowFunction;
115
typedef itk::WindowedSincInterpolateImageFunction<TImageType, WindowingRadius, WindowFunction, BoundaryCondition> InterpolatorType;
116
return RType( ConditionalCreateInterpolator<InterpolatorType>( typename IsBasic<TImageType>::Type() ) );
118
case sitkCosineWindowedSinc:
120
typedef typename itk::Function::CosineWindowFunction<WindowingRadius, double, double > WindowFunction;
121
typedef itk::WindowedSincInterpolateImageFunction<TImageType, WindowingRadius, WindowFunction, BoundaryCondition> InterpolatorType;
122
return RType( ConditionalCreateInterpolator<InterpolatorType>( typename IsBasic<TImageType>::Type() ) );
124
case sitkWelchWindowedSinc:
126
typedef typename itk::Function::WelchWindowFunction<WindowingRadius, double, double > WindowFunction;
127
typedef itk::WindowedSincInterpolateImageFunction<TImageType, WindowingRadius, WindowFunction, BoundaryCondition> InterpolatorType;
128
return RType( ConditionalCreateInterpolator<InterpolatorType>( typename IsBasic<TImageType>::Type() ) );
130
case sitkLanczosWindowedSinc:
132
typedef typename itk::Function::LanczosWindowFunction<WindowingRadius, double, double > WindowFunction;
133
typedef itk::WindowedSincInterpolateImageFunction<TImageType, WindowingRadius, WindowFunction, BoundaryCondition> InterpolatorType;
134
return RType( ConditionalCreateInterpolator<InterpolatorType>( typename IsBasic<TImageType>::Type() ) );
136
case sitkBlackmanWindowedSinc:
138
typedef typename itk::Function::BlackmanWindowFunction<WindowingRadius, double, double > WindowFunction;
139
typedef itk::WindowedSincInterpolateImageFunction<TImageType, WindowingRadius, WindowFunction, BoundaryCondition> InterpolatorType;
140
return RType( ConditionalCreateInterpolator<InterpolatorType>( typename IsBasic<TImageType>::Type() ) );
149
} // end namespace simple
150
} // end namespace itk
153
#endif // sitkCreateInterpolator_hxx