selxItkResampleFilter.h 5.97 KB
Newer Older
1
2
/*=========================================================================
 *
3
 *  Copyright Leiden University Medical Center, Erasmus University Medical
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 *  Center and contributors
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/

#ifndef selxItkResampleFilter_h
#define selxItkResampleFilter_h

23
24
#include "selxComponentBase.h"
#include "selxInterfaces.h"
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "itkImageRegistrationMethodv4.h"
#include "itkGradientDescentOptimizerv4.h"
#include "itkImageSource.h"
#include <itkTransformToDisplacementFieldFilter.h>
#include <string.h>
#include "selxMacro.h"

#include "itkComposeDisplacementFieldsImageFilter.h"
#include "itkGaussianExponentialDiffeomorphicTransform.h"
#include "itkGaussianExponentialDiffeomorphicTransformParametersAdaptor.h"

namespace selx
{
38
39
40
41
template< int Dimensionality, class TPixel, class TInternalComputationValue >
class ItkResampleFilterComponent :
  public SuperElastixComponent<
  Accepting< itkTransformInterface< TInternalComputationValue, Dimensionality >,
42
  itkImageDomainFixedInterface< Dimensionality >,
43
44
45
46
47
48
49
50
  itkImageMovingInterface< Dimensionality, TPixel >
  >,
  Providing< itkImageInterface< Dimensionality, TPixel >,
  ReconnectTransformInterface
  >
  >
{
public:
51

52
  selxNewMacro( ItkResampleFilterComponent, ComponentBase );
53

54
  //itkStaticConstMacro(Dimensionality, unsigned int, Dimensionality);
55

56
57
  ItkResampleFilterComponent();
  virtual ~ItkResampleFilterComponent();
58

59
  typedef TPixel PixelType;
60

61
  // Get the type definitions from the interfaces
62
  typedef typename itkImageDomainFixedInterface< Dimensionality>::ItkImageDomainType  FixedImageDomainType;
63
64
  typedef typename itkImageMovingInterface< Dimensionality, TPixel >::ItkImageType MovingImageType;
  typedef typename itkImageInterface< Dimensionality, TPixel >::ItkImageType       ResultImageType;
65

66
  typedef itk::ResampleImageFilter< MovingImageType, ResultImageType > ResampleFilterType;
67

68
  //Accepting Interfaces:
69
  virtual int Set( itkImageDomainFixedInterface< Dimensionality> * ) override;
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

  virtual int Set( itkImageMovingInterface< Dimensionality, TPixel > * ) override;

  virtual int Set( itkTransformInterface< TInternalComputationValue, Dimensionality > * ) override;

  //Providing Interfaces:
  virtual typename ResultImageType::Pointer GetItkImage() override;

  virtual void ReconnectTransform() override;

  //BaseClass methods
  virtual bool MeetsCriterion( const ComponentBase::CriterionType & criterion ) override;

  //static const char * GetName() { return "ItkResampleFilter"; } ;
  static const char * GetDescription() { return "ItkResampleFilter Component"; }

private:

  typename ResampleFilterType::Pointer m_ResampleFilter;
  itkTransformInterface< TInternalComputationValue, Dimensionality > * m_TransformComponent;

protected:

  /* The following struct returns the string name of computation type */
  /* default implementation */
95

96
  static inline const std::string GetTypeNameString()
97
  {
98
99
100
    itkGenericExceptionMacro( << "Unknown ScalarType" << typeid( TPixel ).name() );
    // TODO: provide the user instructions how to enable the compilation of the component with the required template types (if desired)
    // We might define an exception object that can communicate various error messages: for simple user, for developer user, etc
101
  }
102
103
104


  static inline const std::string GetPixelTypeNameString()
105
  {
106
107
108
    itkGenericExceptionMacro( << "Unknown PixelType" << typeid( TPixel ).name() );
    // TODO: provide the user instructions how to enable the compilation of the component with the required template types (if desired)
    // We might define an exception object that can communicate various error messages: for simple user, for developer user, etc
109
  }
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
};

// unfortunately partial specialization of member functions is not allowed, without partially specializing the entire class.

/*
template <int Dimensionality>
class ItkResampleFilterComponent < Dimensionality, double >
{
  static inline const std::string GetPixelTypeNameString();
};

template <int Dimensionality>
inline const std::string
  ItkResampleFilterComponent<Dimensionality, double>
  ::GetPixelTypeNameString()
{
  return std::string("double");
}
*/

template< >
inline const std::string
ItkResampleFilterComponent< 2, float, double >
::GetPixelTypeNameString()
{
  return std::string( "float" );
}


template< >
inline const std::string
ItkResampleFilterComponent< 2, double, double >
::GetPixelTypeNameString()
{
  return std::string( "double" );
}


template< >
inline const std::string
ItkResampleFilterComponent< 3, float, double >
::GetPixelTypeNameString()
{
  return std::string( "float" );
}


template< >
inline const std::string
ItkResampleFilterComponent< 3, double, double >
::GetPixelTypeNameString()
{
  return std::string( "double" );
}


template< >
inline const std::string
ItkResampleFilterComponent< 2, float, double >
::GetTypeNameString()
{
  return std::string( "2_float" );
}


template< >
inline const std::string
ItkResampleFilterComponent< 2, double, double >
::GetTypeNameString()
{
  return std::string( "2_double" );
}


template< >
inline const std::string
ItkResampleFilterComponent< 3, float, double >
::GetTypeNameString()
{
  return std::string( "3_float" );
}


template< >
inline const std::string
ItkResampleFilterComponent< 3, double, double >
::GetTypeNameString()
{
  return std::string( "3_double" );
}
200
201
202
203
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
#include "selxItkResampleFilter.hxx"
#endif
204
#endif // #define GDOptimizer3rdPartyComponent_h