selxRegistrationItkv4Test.cxx 15.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
#include "Overlord.h"

//#include "ComponentFactory.h"
#include "TransformComponent1.h"
#include "MetricComponent1.h"
#include "GDOptimizer3rdPartyComponent.h"
#include "GDOptimizer4thPartyComponent.h"
#include "SSDMetric3rdPartyComponent.h"
#include "SSDMetric4thPartyComponent.h"

#include "selxItkSmoothingRecursiveGaussianImageFilterComponent.h"
12
#include "selxItkImageFilterSink.h"
13
#include "selxDisplacementFieldItkImageFilterSink.h"
14
15
16
17
#include "selxItkImageSource.h"


#include "selxItkImageRegistrationMethodv4Component.h"
18
#include "selxItkANTSNeighborhoodCorrelationImageToImageMetricv4.h"
19
#include "selxItkMeanSquaresImageToImageMetricv4.h"
20
21
22
#include "selxItkImageSourceFixed.h"
#include "selxItkImageSourceMoving.h"

23
#include "selxDataManager.h"
24
25
26
27
28
29
30
31
32
33
34
35
#include "gtest/gtest.h"

namespace selx {

class RegistrationItkv4Test : public ::testing::Test {
public:
  typedef Overlord::Pointer                 OverlordPointerType;
  typedef Blueprint::Pointer                BlueprintPointerType;
  typedef Blueprint::ConstPointer           BlueprintConstPointerType;
  typedef Blueprint::ComponentIndexType     ComponentIndexType;
  typedef Blueprint::ParameterMapType       ParameterMapType;
  typedef Blueprint::ParameterValueType     ParameterValueType;
36
  typedef DataManager DataManagerType;
37
38
39
40
41
42
43
44
45
46
47

  virtual void SetUp() {
    /** register all example components */
    ComponentFactory<TransformComponent1>::RegisterOneFactory();
    ComponentFactory<MetricComponent1>::RegisterOneFactory();
    ComponentFactory<GDOptimizer3rdPartyComponent>::RegisterOneFactory();
    ComponentFactory<GDOptimizer4thPartyComponent>::RegisterOneFactory();
    ComponentFactory<SSDMetric3rdPartyComponent>::RegisterOneFactory();
    ComponentFactory<SSDMetric4thPartyComponent>::RegisterOneFactory();

    
48
    ComponentFactory<ItkImageFilterSinkComponent<3,double>>::RegisterOneFactory();
49
50
    ComponentFactory<ItkImageFilterSinkComponent<2, float>>::RegisterOneFactory();

51
    ComponentFactory<DisplacementFieldItkImageFilterSinkComponent<3, double>>::RegisterOneFactory();
52
53
54
    ComponentFactory<DisplacementFieldItkImageFilterSinkComponent<2, float>>::RegisterOneFactory();
    
    //ComponentFactory<ItkImageSourceComponent>::RegisterOneFactory();
55
56
57
58
59
60

    ComponentFactory<ItkImageSourceFixedComponent<2, float>>::RegisterOneFactory();
    ComponentFactory<ItkImageSourceMovingComponent<2, float>>::RegisterOneFactory();

    ComponentFactory<ItkImageSourceFixedComponent<3, double>>::RegisterOneFactory();
    ComponentFactory<ItkImageSourceMovingComponent<3, double>>::RegisterOneFactory();
61
62
63
64
65
66
67
68


    ComponentFactory<ItkSmoothingRecursiveGaussianImageFilterComponent<3, double>>::RegisterOneFactory();
    ComponentFactory<ItkSmoothingRecursiveGaussianImageFilterComponent<2, double>>::RegisterOneFactory();
    ComponentFactory<ItkSmoothingRecursiveGaussianImageFilterComponent<3, float>>::RegisterOneFactory();
    ComponentFactory<ItkSmoothingRecursiveGaussianImageFilterComponent<2, float>>::RegisterOneFactory();

    ComponentFactory<ItkImageRegistrationMethodv4Component<3, double>>::RegisterOneFactory();
69
    ComponentFactory<ItkImageRegistrationMethodv4Component<2, float>>::RegisterOneFactory();
70

71
    ComponentFactory<ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component<3, double>>::RegisterOneFactory();
72
    ComponentFactory<ItkMeanSquaresImageToImageMetricv4Component<3, double>>::RegisterOneFactory();
73
74
75
76

    ComponentFactory<ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component<2, float>>::RegisterOneFactory();
    ComponentFactory<ItkMeanSquaresImageToImageMetricv4Component<2, float>>::RegisterOneFactory();

77
78
79
80
81
82
83
84
  }

  virtual void TearDown() {
    itk::ObjectFactoryBase::UnRegisterAllFactories();
  }

  BlueprintPointerType blueprint;
  Overlord::Pointer overlord;
85
86


87
88
};

89
TEST_F(RegistrationItkv4Test, ImagesOnly)
90
{
91
92
  /** make example blueprint configuration */
  blueprint = Blueprint::New();
93

94
95
  ParameterMapType component0Parameters;
  component0Parameters["NameOfClass"] = { "ItkImageRegistrationMethodv4Component" };
96
  component0Parameters["Dimensionality"] = { "3" }; // should be derived from the inputs
97
  ComponentIndexType index0 = blueprint->AddComponent(component0Parameters);
98

99
100
  ParameterMapType component1Parameters;
  component1Parameters["NameOfClass"] = { "ItkImageSourceFixedComponent" };
101
  component1Parameters["Dimensionality"] = { "3" }; // should be derived from the inputs
102
  ComponentIndexType index1 = blueprint->AddComponent(component1Parameters);
103

104
105
  ParameterMapType component2Parameters;
  component2Parameters["NameOfClass"] = { "ItkImageSourceMovingComponent" };
106
  component2Parameters["Dimensionality"] = { "3" }; // should be derived from the inputs
107
  ComponentIndexType index2 = blueprint->AddComponent(component2Parameters);
108

109
  ParameterMapType component3Parameters;
110
  component3Parameters["NameOfClass"] = { "ItkImageFilterSinkComponent" };
111
  component3Parameters["Dimensionality"] = { "3" }; // should be derived from the outputs
112
  ComponentIndexType index3 = blueprint->AddComponent(component3Parameters);
113
114


115
116
117
  ParameterMapType connection1Parameters;
  connection1Parameters["NameOfInterface"] = { "itkImageSourceFixedInterface" };
  blueprint->AddConnection(index1, index0, connection1Parameters);
118

119
120
121
  ParameterMapType connection2Parameters;
  connection2Parameters["NameOfInterface"] = { "itkImageSourceMovingInterface" };
  blueprint->AddConnection(index2, index0, connection2Parameters);
122

123
124
125
  ParameterMapType connection3Parameters;
  connection3Parameters["NameOfInterface"] = { "itkImageSourceInterface" };
  blueprint->AddConnection(index0, index3, connection3Parameters);
126

127
128
  EXPECT_NO_THROW(overlord = Overlord::New());
  EXPECT_NO_THROW(overlord->SetBlueprint(blueprint));
129
130
131
132
133
134
  
  //The Overlord is not yet an itkfilter with inputs and outputs, therefore it reads and writes the files temporarily.
  DataManagerType::Pointer dataManager = DataManagerType::New();
  overlord->inputFileNames = { dataManager->GetInputFile("sphereA3d.mhd"), dataManager->GetInputFile("sphereB3d.mhd") };
  overlord->outputFileNames = { dataManager->GetOutputFile("RegistrationItkv4Test_ImagesOnly.mhd") };

135
  bool allUniqueComponents;
136
  EXPECT_NO_THROW(allUniqueComponents = overlord->Configure());
137
  EXPECT_TRUE(allUniqueComponents);
138
  EXPECT_NO_THROW(overlord->Execute());
139
  
140
141
}

142
143
144
145
146
147
148
TEST_F(RegistrationItkv4Test, WithANTSCCMetric)
{
  /** make example blueprint configuration */
  blueprint = Blueprint::New();

  ParameterMapType component0Parameters;
  component0Parameters["NameOfClass"] = { "ItkImageRegistrationMethodv4Component" };
149
  component0Parameters["Dimensionality"] = { "3" }; // should be derived from the inputs
150
151
152
153
  ComponentIndexType index0 = blueprint->AddComponent(component0Parameters);

  ParameterMapType component1Parameters;
  component1Parameters["NameOfClass"] = { "ItkImageSourceFixedComponent" };
154
  component1Parameters["Dimensionality"] = { "3" }; // should be derived from the inputs
155
  ComponentIndexType index1 = blueprint->AddComponent(component1Parameters);
156
  
157
158
  ParameterMapType component2Parameters;
  component2Parameters["NameOfClass"] = { "ItkImageSourceMovingComponent" };
159
  component2Parameters["Dimensionality"] = { "3" }; // should be derived from the inputs
160
161
162
  ComponentIndexType index2 = blueprint->AddComponent(component2Parameters);

  ParameterMapType component3Parameters;
163
  component3Parameters["NameOfClass"] = { "ItkImageFilterSinkComponent" };
164
  component3Parameters["Dimensionality"] = { "3" }; // should be derived from the inputs
165
166
167
168
  ComponentIndexType index3 = blueprint->AddComponent(component3Parameters);

  ParameterMapType component4Parameters;
  component4Parameters["NameOfClass"] = { "ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component" };
169
  component4Parameters["Dimensionality"] = { "3" }; // should be derived from the inputs
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
  ComponentIndexType index4 = blueprint->AddComponent(component4Parameters);


  ParameterMapType connection1Parameters;
  connection1Parameters["NameOfInterface"] = { "itkImageSourceFixedInterface" };
  blueprint->AddConnection(index1, index0, connection1Parameters);

  ParameterMapType connection2Parameters;
  connection2Parameters["NameOfInterface"] = { "itkImageSourceMovingInterface" };
  blueprint->AddConnection(index2, index0, connection2Parameters);

  ParameterMapType connection3Parameters;
  connection3Parameters["NameOfInterface"] = { "itkImageSourceInterface" };
  blueprint->AddConnection(index0, index3, connection3Parameters);

  ParameterMapType connection4Parameters;
  connection4Parameters["NameOfInterface"] = { "itkMetricv4Interface" };
  blueprint->AddConnection(index4, index0, connection4Parameters);

  EXPECT_NO_THROW(overlord = Overlord::New());
  EXPECT_NO_THROW(overlord->SetBlueprint(blueprint));
191
192
193
194
195
196
  
  //The Overlord is not yet an itkfilter with inputs and outputs, therefore it reads and writes the files temporarily.
  DataManagerType::Pointer dataManager = DataManagerType::New();
  overlord->inputFileNames = { dataManager->GetInputFile("sphereA3d.mhd"), dataManager->GetInputFile("sphereB3d.mhd") };
  overlord->outputFileNames = { dataManager->GetOutputFile("RegistrationItkv4Test_WithANTSCCMetric.mhd") };

197
198
199
  bool allUniqueComponents;
  EXPECT_NO_THROW(allUniqueComponents = overlord->Configure());
  EXPECT_TRUE(allUniqueComponents);
200
201
  EXPECT_NO_THROW(overlord->Execute());
  //overlord->Execute();
202
}
203
204
205
206
207
208
209
TEST_F(RegistrationItkv4Test, WithMeanSquaresMetric)
{
  /** make example blueprint configuration */
  blueprint = Blueprint::New();

  ParameterMapType component0Parameters;
  component0Parameters["NameOfClass"] = { "ItkImageRegistrationMethodv4Component" };
210
  component0Parameters["Dimensionality"] = { "3" }; // should be derived from the inputs
211
212
213
214
  ComponentIndexType index0 = blueprint->AddComponent(component0Parameters);

  ParameterMapType component1Parameters;
  component1Parameters["NameOfClass"] = { "ItkImageSourceFixedComponent" };
215
  component1Parameters["Dimensionality"] = { "3" }; // should be derived from the inputs
216
217
218
219
  ComponentIndexType index1 = blueprint->AddComponent(component1Parameters);

  ParameterMapType component2Parameters;
  component2Parameters["NameOfClass"] = { "ItkImageSourceMovingComponent" };
220
  component2Parameters["Dimensionality"] = { "3" }; // should be derived from the inputs
221
222
223
  ComponentIndexType index2 = blueprint->AddComponent(component2Parameters);

  ParameterMapType component3Parameters;
224
  component3Parameters["NameOfClass"] = { "ItkImageFilterSinkComponent" };
225
  component3Parameters["Dimensionality"] = { "3" }; // should be derived from the inputs
226
227
228
229
  ComponentIndexType index3 = blueprint->AddComponent(component3Parameters);

  ParameterMapType component4Parameters;
  component4Parameters["NameOfClass"] = { "ItkMeanSquaresImageToImageMetricv4Component" };
230
  component4Parameters["Dimensionality"] = { "3" }; // should be derived from the inputs
231
  ComponentIndexType index4 = blueprint->AddComponent(component4Parameters);
232

233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251

  ParameterMapType connection1Parameters;
  connection1Parameters["NameOfInterface"] = { "itkImageSourceFixedInterface" };
  blueprint->AddConnection(index1, index0, connection1Parameters);

  ParameterMapType connection2Parameters;
  connection2Parameters["NameOfInterface"] = { "itkImageSourceMovingInterface" };
  blueprint->AddConnection(index2, index0, connection2Parameters);

  ParameterMapType connection3Parameters;
  connection3Parameters["NameOfInterface"] = { "itkImageSourceInterface" };
  blueprint->AddConnection(index0, index3, connection3Parameters);

  ParameterMapType connection4Parameters;
  connection4Parameters["NameOfInterface"] = { "itkMetricv4Interface" };
  blueprint->AddConnection(index4, index0, connection4Parameters);

  EXPECT_NO_THROW(overlord = Overlord::New());
  EXPECT_NO_THROW(overlord->SetBlueprint(blueprint));
252
253
254
255
256
257
  
  //The Overlord is not yet an itkfilter with inputs and outputs, therefore it reads and writes the files temporarily.
  DataManagerType::Pointer dataManager = DataManagerType::New();
  overlord->inputFileNames = { dataManager->GetInputFile("sphereA3d.mhd"), dataManager->GetInputFile("sphereB3d.mhd") };
  overlord->outputFileNames = { dataManager->GetOutputFile("RegistrationItkv4Test_WithMeanSquaresMetric.mhd") };

258
259
260
261
262
263
  bool allUniqueComponents;
  EXPECT_NO_THROW(allUniqueComponents = overlord->Configure());
  EXPECT_TRUE(allUniqueComponents);
  EXPECT_NO_THROW(overlord->Execute());
  //overlord->Execute();
}
264

265
TEST_F(RegistrationItkv4Test, DisplacementField2D)
266
267
268
269
270
271
{
  /** make example blueprint configuration */
  blueprint = Blueprint::New();

  ParameterMapType component0Parameters;
  component0Parameters["NameOfClass"] = { "ItkImageRegistrationMethodv4Component" };
272
  component0Parameters["Dimensionality"] = { "2" }; // should be derived from the inputs
273
274
275
276
  ComponentIndexType index0 = blueprint->AddComponent(component0Parameters);

  ParameterMapType component1Parameters;
  component1Parameters["NameOfClass"] = { "ItkImageSourceFixedComponent" };
277
  component1Parameters["Dimensionality"] = { "2" }; // should be derived from the inputs
278
279
280
281
  ComponentIndexType index1 = blueprint->AddComponent(component1Parameters);

  ParameterMapType component2Parameters;
  component2Parameters["NameOfClass"] = { "ItkImageSourceMovingComponent" };
282
  component2Parameters["Dimensionality"] = { "2" }; // should be derived from the inputs
283
284
285
286
  ComponentIndexType index2 = blueprint->AddComponent(component2Parameters);

  ParameterMapType component3Parameters;
  component3Parameters["NameOfClass"] = { "ItkImageFilterSinkComponent" };
287
  component3Parameters["Dimensionality"] = { "2" }; // should be derived from the outputs
288
289
290
291
  ComponentIndexType index3 = blueprint->AddComponent(component3Parameters);

  ParameterMapType component4Parameters;
  component4Parameters["NameOfClass"] = { "DisplacementFieldItkImageFilterSinkComponent" };
292
  component4Parameters["Dimensionality"] = { "2" }; // should be derived from the outputs
293
294
  ComponentIndexType index4 = blueprint->AddComponent(component4Parameters);

295
296
297
298
299
300
  ParameterMapType component5Parameters;
  component5Parameters["NameOfClass"] = { "ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component" };
  component5Parameters["Dimensionality"] = { "2" }; // should be derived from the inputs
  ComponentIndexType index5 = blueprint->AddComponent(component5Parameters);


301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
  ParameterMapType connection1Parameters;
  connection1Parameters["NameOfInterface"] = { "itkImageSourceFixedInterface" };
  blueprint->AddConnection(index1, index0, connection1Parameters);

  ParameterMapType connection2Parameters;
  connection2Parameters["NameOfInterface"] = { "itkImageSourceMovingInterface" };
  blueprint->AddConnection(index2, index0, connection2Parameters);

  ParameterMapType connection3Parameters;
  connection3Parameters["NameOfInterface"] = { "itkImageSourceInterface" };
  blueprint->AddConnection(index0, index3, connection3Parameters);

  ParameterMapType connection4Parameters;
  connection4Parameters["NameOfInterface"] = { "DisplacementFieldItkImageSourceInterface" };
  blueprint->AddConnection(index0, index4, connection4Parameters);

317
318
319
320
  ParameterMapType connection5Parameters;
  connection5Parameters["NameOfInterface"] = { "itkMetricv4Interface" };
  blueprint->AddConnection(index5, index0, connection5Parameters);

321
  EXPECT_NO_THROW(overlord = Overlord::New());
322
323
324
325
326
327

  //The Overlord is not yet an itkfilter with inputs and outputs, therefore it reads and writes the files temporarily.
  DataManagerType::Pointer dataManager = DataManagerType::New();
  overlord->inputFileNames = { dataManager->GetInputFile("BrainProtonDensitySliceBorder20.png"), dataManager->GetInputFile("BrainProtonDensitySliceR10X13Y17.png") };
  overlord->outputFileNames = { dataManager->GetOutputFile("RegistrationItkv4Test_BrainProtonDensity.mhd"), dataManager->GetOutputFile("RegistrationItkv4Test_Displacement_BrainProtonDensity.mhd") };

328
329
330
331
  EXPECT_NO_THROW(overlord->SetBlueprint(blueprint));
  bool allUniqueComponents;
  EXPECT_NO_THROW(allUniqueComponents = overlord->Configure());
  EXPECT_TRUE(allUniqueComponents);
332
333
  //EXPECT_NO_THROW(overlord->Execute());
  overlord->Execute();
334
}
335
} // namespace selx
336