selxMonolithicTransformix.h 6.18 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
#ifndef selxMonolithicTransformixComponent_h
#define selxMonolithicTransformixComponent_h
22

23
24
#include "selxComponentBase.h"
#include "selxInterfaces.h"
25
26
#include "itkImageSource.h"

27
28
29
#include "elxElastixFilter.h"
#include "elxParameterObject.h"
#include "elxTransformixFilter.h"
30
31

#include <string.h>
32
#include "selxMacro.h"
33
34
35
namespace selx
{
  template <int Dimensionality, class TPixel>
36
  class MonolithicTransformixComponent : 
37
    public SuperElastixComponent<
38
      Accepting< 
39
40
41
        itkImageDomainFixedInterface<Dimensionality>,
        itkImageMovingInterface<Dimensionality, TPixel>,
        elastixTransformParameterObjectInterface<itk::Image<TPixel, Dimensionality>, itk::Image<TPixel, Dimensionality>>
42
43
      >,
      Providing< 
44
        itkImageInterface<Dimensionality, TPixel>, 
45
        ReconnectTransformInterface
46
47
48
49
      >
    >
  {
  public:
50
    selxNewMacro(MonolithicTransformixComponent, ComponentBase);
51

52
    //itkStaticConstMacro(Dimensionality, unsigned int, Dimensionality);
53

54
55
    MonolithicTransformixComponent();
    virtual ~MonolithicTransformixComponent();
56
57
    
    typedef typename ComponentBase::CriterionType CriterionType;
58
59
60
    typedef TPixel PixelType;

    // fixed and moving image types are all the same, these aliases can be used to be explicit. 
61
62
    typedef typename itkImageMovingInterface<Dimensionality, TPixel>::ItkImageType MovingImageType;
    typedef typename itkImageInterface<Dimensionality, TPixel>::ItkImageType ResultImageType;
63

64
65
    typedef elastix::ParameterObject elxParameterObjectType;
    typedef elxParameterObjectType::Pointer elxParameterObjectPointer;
Floris Berendsen's avatar
Floris Berendsen committed
66
    
67
    typedef elastix::TransformixFilter<MovingImageType> TransformixFilterType;
68

69
70
71
    typedef elastixTransformParameterObjectInterface<itk::Image<TPixel, Dimensionality>, itk::Image<TPixel, Dimensionality>> elastixTransformParameterObjectInterfaceType;
    // Accepting Interfaces:
    virtual int Set(itkImageDomainFixedInterface<Dimensionality>*) override;
72
    virtual int Set(itkImageMovingInterface<Dimensionality, TPixel>*) override;
73
    virtual int Set(elastixTransformParameterObjectInterfaceType*) override;
74
    
75
76
77
    // Providing Interfaces:
    virtual typename ResultImageType::Pointer GetItkImage() override;
    virtual void ReconnectTransform() override;
78
79

    virtual bool MeetsCriterion(const CriterionType &criterion) override;
80
    static const char * GetDescription() { return "MonolithicTransformix Component"; };
81
  private:
82
    
83
    typename TransformixFilterType::Pointer m_transformixFilter;
84
    elastixTransformParameterObjectInterfaceType* m_TransformParameterObjectInterface;
85

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
  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>
110
  class MonolithicTransformixComponent < Dimensionality, double >
111
112
113
114
115
116
  {
    static inline const std::string GetPixelTypeNameString();
  };

  template <int Dimensionality>
  inline const std::string
117
    MonolithicTransformixComponent<Dimensionality, double>
118
119
120
121
122
123
124
125
    ::GetPixelTypeNameString()
  {
    return std::string("double");
  }
  */

  template <>
  inline const std::string
126
    MonolithicTransformixComponent<2, float>
127
128
129
130
131
132
133
134
    ::GetPixelTypeNameString()
  {
    return std::string("float");
  }


  template <>
  inline const std::string
135
    MonolithicTransformixComponent<2, double>
136
137
138
139
140
141
142
    ::GetPixelTypeNameString()
  {
    return std::string("double");
  }

  template <>
  inline const std::string
143
    MonolithicTransformixComponent<3, float>
144
145
146
147
148
149
150
    ::GetPixelTypeNameString()
  {
    return std::string("float");
  }

  template <>
  inline const std::string
151
    MonolithicTransformixComponent<3, double>
152
153
154
155
156
157
    ::GetPixelTypeNameString()
  {
    return std::string("double");
  }
  template <>
  inline const std::string
158
    MonolithicTransformixComponent<2, float>
159
160
161
162
163
164
165
    ::GetTypeNameString()
  {
    return std::string("2_float");
  }

  template <>
  inline const std::string
166
    MonolithicTransformixComponent<2, double>
167
168
169
170
171
172
173
    ::GetTypeNameString()
  {
    return std::string("2_double");
  }

  template <>
  inline const std::string
174
    MonolithicTransformixComponent<3,float>
175
176
177
178
179
180
181
    ::GetTypeNameString()
  {
    return std::string("3_float");
  }
  
  template <>
  inline const std::string
182
    MonolithicTransformixComponent<3,double>
183
184
185
186
187
188
    ::GetTypeNameString()
  {
    return std::string("3_double");
  }
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
189
#include "selxMonolithicTransformix.hxx"
190
191
#endif
#endif // #define GDOptimizer3rdPartyComponent_h