~ubuntu-branches/debian/sid/simpleitk/sid

« back to all changes in this revision

Viewing changes to Code/Registration/src/sitkCreateInterpolator.hxx

  • Committer: Package Import Robot
  • Author(s): Ghislain Antony Vaillant
  • Date: 2017-11-02 08:49:18 UTC
  • Revision ID: package-import@ubuntu.com-20171102084918-7hs09ih668xq87ej
Tags: upstream-1.0.1
ImportĀ upstreamĀ versionĀ 1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*=========================================================================
 
2
*
 
3
*  Copyright Insight Software Consortium
 
4
*
 
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
 
8
*
 
9
*         http://www.apache.org/licenses/LICENSE-2.0.txt
 
10
*
 
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.
 
16
*
 
17
*=========================================================================*/
 
18
#ifndef sitkCreateInterpolator_hxx
 
19
#define sitkCreateInterpolator_hxx
 
20
 
 
21
 
 
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>
 
29
 
 
30
namespace itk
 
31
{
 
32
 
 
33
namespace simple
 
34
{
 
35
 
 
36
template<typename TInterpolatorType>
 
37
typename TInterpolatorType::Pointer
 
38
ConditionalCreateInterpolator( const TrueType & )
 
39
{
 
40
  return TInterpolatorType::New();
 
41
}
 
42
 
 
43
template<typename TInterpolatorType>
 
44
TInterpolatorType*
 
45
ConditionalCreateInterpolator( const FalseType & )
 
46
{
 
47
  return NULL;
 
48
}
 
49
 
 
50
template< typename TImageType >
 
51
typename itk::InterpolateImageFunction< TImageType, double >::Pointer
 
52
CreateInterpolator( const TImageType *image, InterpolatorEnum itype )
 
53
{
 
54
  typedef typename itk::InterpolateImageFunction< TImageType, double >::Pointer RType;
 
55
  typedef typename itk::ZeroFluxNeumannBoundaryCondition<TImageType,TImageType> BoundaryCondition;
 
56
  //typedef typename itk::ConstantBoundaryCondition<TImageType> BoundaryCondition;
 
57
 
 
58
  typedef typename TImageType::SpacingType SpacingType;
 
59
 
 
60
  static const unsigned int WindowingRadius = 5;
 
61
 
 
62
  const SpacingType &spacing = image->GetSpacing();
 
63
 
 
64
  switch( itype )
 
65
    {
 
66
    case sitkNearestNeighbor:
 
67
    {
 
68
      typedef itk::NearestNeighborInterpolateImageFunction<TImageType, double> InterpolatorType;
 
69
      return RType( InterpolatorType::New() );
 
70
    }
 
71
    case sitkLinear:
 
72
    {
 
73
      typedef itk::LinearInterpolateImageFunction<TImageType, double> InterpolatorType;
 
74
      return RType( InterpolatorType::New() );
 
75
    }
 
76
    case sitkBSpline:
 
77
    {
 
78
      typedef itk::BSplineInterpolateImageFunction<TImageType, double> InterpolatorType;
 
79
      return RType( ConditionalCreateInterpolator<InterpolatorType>( typename IsBasic<TImageType>::Type() ) );
 
80
    }
 
81
    case sitkGaussian:
 
82
    {
 
83
    typedef itk::GaussianInterpolateImageFunction<TImageType, double> InterpolatorType;
 
84
 
 
85
    typename InterpolatorType::ArrayType sigma;
 
86
 
 
87
    for( unsigned int i = 0; i < TImageType::ImageDimension; ++i )
 
88
      {
 
89
      sigma[i] = 0.8*spacing[i];
 
90
      }
 
91
    typename InterpolatorType::Pointer p = InterpolatorType::New();
 
92
    p->SetSigma(sigma);
 
93
    p->SetAlpha(4.0);
 
94
    return RType(p);
 
95
    }
 
96
    case sitkLabelGaussian:
 
97
    {
 
98
    typedef itk::LabelImageGaussianInterpolateImageFunction<TImageType, double> InterpolatorType;
 
99
 
 
100
    typename InterpolatorType::ArrayType sigma;
 
101
 
 
102
    for( unsigned int i = 0; i < TImageType::ImageDimension; ++i )
 
103
      {
 
104
      sigma[i] = spacing[i];
 
105
      }
 
106
    typename InterpolatorType::Pointer p = InterpolatorType::New();
 
107
    p->SetSigma(sigma);
 
108
    p->SetAlpha(1.0);
 
109
    return RType(p);
 
110
    }
 
111
    case sitkHammingWindowedSinc:
 
112
    {
 
113
 
 
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() ) );
 
117
    }
 
118
    case sitkCosineWindowedSinc:
 
119
    {
 
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() ) );
 
123
    }
 
124
    case sitkWelchWindowedSinc:
 
125
    {
 
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() ) );
 
129
    }
 
130
    case sitkLanczosWindowedSinc:
 
131
    {
 
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() ) );
 
135
    }
 
136
    case sitkBlackmanWindowedSinc:
 
137
    {
 
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() ) );
 
141
    }
 
142
    default:
 
143
      return NULL;
 
144
    }
 
145
 
 
146
}
 
147
 
 
148
 
 
149
} // end namespace simple
 
150
} // end namespace itk
 
151
 
 
152
 
 
153
#endif // sitkCreateInterpolator_hxx