selxItkImageRegistrationMethodv4Component.h 7 KB
Newer Older
Floris Berendsen's avatar
Floris Berendsen committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*=========================================================================
 *
 *  Copyright Leiden University Medical Center, Erasmus University Medical 
 *  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.
 *
 *=========================================================================*/

20
21
22
23
24
25
#ifndef selxItkImageRegistrationMethodv4Component_h
#define selxItkImageRegistrationMethodv4Component_h

#include "ComponentBase.h"
#include "Interfaces.h"
#include "itkImageRegistrationMethodv4.h"
26
#include "itkGradientDescentOptimizerv4.h"
27
#include "itkImageSource.h"
28
#include <itkTransformToDisplacementFieldFilter.h>
29
#include <string.h>
30
#include "selxMacro.h"
31
32
33
34
35
36
37


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


38
39
40
41
42
namespace selx
{
  template <int Dimensionality, class TPixel>
  class ItkImageRegistrationMethodv4Component : 
    public Implements<
43
44
    Accepting< itkImageFixedInterface<Dimensionality, TPixel>, 
               itkImageMovingInterface<Dimensionality, TPixel>,
45
46
               itkMetricv4Interface<Dimensionality, TPixel>,
               itkOptimizerv4Interface<double>
47
             >,
48
    Providing< itkTransformInterface<double, Dimensionality>,
49
50
               RunRegistrationInterface
             >
51
52
53
    >
  {
  public:
54
    selxNewMacro(ItkImageRegistrationMethodv4Component, ComponentBase);
55

FBerendsen's avatar
FBerendsen committed
56
    //itkStaticConstMacro(Dimensionality, unsigned int, Dimensionality);
57
58
59
60
61

    ItkImageRegistrationMethodv4Component();
    virtual ~ItkImageRegistrationMethodv4Component();

    typedef TPixel PixelType;
62
63
    
    // Get the type definitions from the interfaces 
64
65
    typedef typename itkImageFixedInterface<Dimensionality, TPixel>::ItkImageType FixedImageType;
    typedef typename itkImageMovingInterface<Dimensionality, TPixel>::ItkImageType MovingImageType;
66
67
    typedef typename itkTransformInterface<double, Dimensionality>::TransformPointer TransformPointer;
    typedef typename itkOptimizerv4Interface<double>::InternalComputationValueType InternalComputationValueType;
68
    
69

70
71
72
    // TODO for now we hard code the transform to be a stationary velocity field. See Set(*MetricInterface) for implementation
    typedef double RealType;
    typedef itk::GaussianExponentialDiffeomorphicTransform<RealType, Dimensionality> ConstantVelocityFieldTransformType;
73
74
    //typedef itk::ImageRegistrationMethodv4<FixedImageType, MovingImageType, ConstantVelocityFieldTransformType> TheItkFilterType;
    typedef itk::ImageRegistrationMethodv4<FixedImageType, MovingImageType> TheItkFilterType;
FBerendsen's avatar
FBerendsen committed
75
76
77
    typedef typename TheItkFilterType::ImageMetricType ImageMetricType;
    typedef itk::RegistrationParameterScalesFromPhysicalShift<ImageMetricType> ScalesEstimatorType;
    
78
    //Accepting Interfaces:
79
80
    virtual int Set(itkImageFixedInterface<Dimensionality, TPixel>*) override;
    virtual int Set(itkImageMovingInterface<Dimensionality, TPixel>*) override;
81
    virtual int Set(itkMetricv4Interface<Dimensionality, TPixel>*) override;
82
    virtual int Set(itkOptimizerv4Interface<InternalComputationValueType>*) override;
83
84
    
    //Providing Interfaces:
85
    virtual TransformPointer GetItkTransform() override;
86
    virtual void RunRegistration() override;
87

88
    //BaseClass methods
FBerendsen's avatar
FBerendsen committed
89
    virtual bool MeetsCriterion(const ComponentBase::CriterionType &criterion) override;    
90
    //static const char * GetName() { return "ItkImageRegistrationMethodv4"; } ;
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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
    static const char * GetDescription() { return "ItkImageRegistrationMethodv4 Component"; };
  private:
    typename TheItkFilterType::Pointer m_theItkFilter;
  protected:
    /* The following struct returns the string name of computation type */
    /* default implementation */

    static inline const std::string GetTypeNameString()
    {
      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
    }

    static inline const std::string GetPixelTypeNameString()
    {
      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
    }

  };

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

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

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

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


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

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

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

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

  template <>
  inline const std::string
    ItkImageRegistrationMethodv4Component<3,float>
    ::GetTypeNameString()
  {
    return std::string("3_float");
  }
  
  template <>
  inline const std::string
    ItkImageRegistrationMethodv4Component<3,double>
    ::GetTypeNameString()
  {
    return std::string("3_double");
  }
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
#include "selxItkImageRegistrationMethodv4Component.hxx"
#endif
#endif // #define GDOptimizer3rdPartyComponent_h