selxMonolithicTransformix.hxx 5.5 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
#include "selxMonolithicTransformix.h"
21
22
23
24

namespace selx
{
  template<int Dimensionality, class TPixel>
25
  MonolithicTransformixComponent< Dimensionality, TPixel>::MonolithicTransformixComponent()
26
  {
27
    m_transformixFilter = TransformixFilterType::New();
28

29
    elxParameterObjectPointer elxParameterObject = elxParameterObjectType::New();
30

31
32
    m_transformixFilter->ComputeDeformationFieldOn();
    m_transformixFilter->LogToConsoleOn();
33
34
35
    m_transformixFilter->LogToFileOff();
    m_transformixFilter->SetOutputDirectory(".");

36
37
38
    //TODO m_elastixFilter returns a nullptr GetTransformParameterObject instead of a valid object. However, we need this object to satisfy the input conditions of m_transformixFilter
    //m_transformixFilter->SetTransformParameterObject(m_elastixFilter->GetTransformParameterObject());
    m_transformixFilter->SetTransformParameterObject(elxParameterObject); // supply a dummy object
39
40
41
42
43
44

    //TODO: instantiating the filter in the constructor might be heavy for the use in component selector factory, since all components of the database are created during the selection process.
    // we could choose to keep the component light weighted (for checking criteria such as names and connections) until the settings are passed to the filter, but this requires an additional initialization step.
  }

  template<int Dimensionality, class TPixel>
45
  MonolithicTransformixComponent< Dimensionality, TPixel>::~MonolithicTransformixComponent()
46
47
48
49
  {
  }

  template<int Dimensionality, class TPixel>
50
  int MonolithicTransformixComponent< Dimensionality, TPixel>::Set(itkImageDomainFixedInterface<Dimensionality>* component)
51
  {
52
53
54
55
    auto fixedImageDomain = component->GetItkImageDomainFixed();
    // Currently, the fixed image domain is part of the transformParameter map, which will be set by elastix.
    // TODO:  make this component use the provided domain
    
56
    return 0;
57
58
59
  }

  template<int Dimensionality, class TPixel>
60
  int MonolithicTransformixComponent< Dimensionality, TPixel>::Set(itkImageMovingInterface<Dimensionality, TPixel>* component)
61
  {
62
    auto movingImage = component->GetItkImageMoving();
63
    // connect the itk pipeline
64
    this->m_transformixFilter->SetInput(movingImage);
65
    return 0;
66
67
  }

68
69
  template<int Dimensionality, class TPixel>
  int MonolithicTransformixComponent< Dimensionality, TPixel>::Set(elastixTransformParameterObjectInterfaceType* component)
70
71
  {

72
73
74
75
76
77
    auto transformParameterObject = component->GetTransformParameterObject();
    // connect the itk pipeline
    this->m_transformixFilter->SetTransformParameterObject(transformParameterObject);
    // store the interface for the ReconnectTransform call
    this->m_TransformParameterObjectInterface = component;
    return 0;
78
  }
79

80
81
  //Since elastixFilter is not a true itkfilter we cannot use itkImageSourceInterface (yet)
 
82
  template<int Dimensionality, class TPixel>
83
  typename MonolithicTransformixComponent< Dimensionality, TPixel>::ResultImageType::Pointer MonolithicTransformixComponent< Dimensionality, TPixel>::GetItkImage()
84
  {
85
    return this->m_transformixFilter->GetOutput();
86
87
  }
  
88
89
90


  template<int Dimensionality, class TPixel>
91
  void MonolithicTransformixComponent< Dimensionality, TPixel>::ReconnectTransform(void)
92
  {
93
    // TODO currently, the pipeline with elastix and tranformix can only be created after the update of elastix
94
95
    this->m_transformixFilter->SetTransformParameterObject(this->m_TransformParameterObjectInterface->GetTransformParameterObject());
    //this->m_transformixFilter->Update();
96
97
98
99
100
  }


  template<int Dimensionality, class TPixel>
  bool
101
    MonolithicTransformixComponent< Dimensionality, TPixel>
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
    ::MeetsCriterion(const CriterionType &criterion)
  {
    bool hasUndefinedCriteria(false);
    bool meetsCriteria(false);
    if (criterion.first == "ComponentProperty")
    {
      meetsCriteria = true;
      for (auto const & criterionValue : criterion.second) // auto&& preferred?
      {
        if (criterionValue != "SomeProperty")  // e.g. "GradientDescent", "SupportsSparseSamples
        {
          meetsCriteria = false;
        }
      }
    }
    else if (criterion.first == "Dimensionality") //Supports this?
    {
      meetsCriteria = true;
      for (auto const & criterionValue : criterion.second) // auto&& preferred?
      {
Floris Berendsen's avatar
Floris Berendsen committed
122
        if (std::stoi(criterionValue) != Dimensionality)
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
        {
          meetsCriteria = false;
        }
      }

    }
    else if (criterion.first == "PixelType") //Supports this?
    {
      meetsCriteria = true;
      for (auto const & criterionValue : criterion.second) // auto&& preferred?
      {
        if (criterionValue != Self::GetPixelTypeNameString())
        {
          meetsCriteria = false;
        }
      }

140
    }
141
142
143
144
    return meetsCriteria;
  }

} //end namespace selx