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

22
23
24
25
26
27
#include "selxTransformComponent1.h"
#include "selxMetricComponent1.h"
#include "selxGDOptimizer3rdPartyComponent.h"
#include "selxGDOptimizer4thPartyComponent.h"
#include "selxSSDMetric3rdPartyComponent.h"
#include "selxSSDMetric4thPartyComponent.h"
28
29

#include "selxItkSmoothingRecursiveGaussianImageFilterComponent.h"
30
#include "selxDisplacementFieldItkImageFilterSink.h"
31
#include "selxItkImageSource.h"
32
#include "selxItkImageSink.h"
33
34

#include "selxItkImageRegistrationMethodv4Component.h"
35
#include "selxItkANTSNeighborhoodCorrelationImageToImageMetricv4.h"
36
#include "selxItkMeanSquaresImageToImageMetricv4.h"
37
#include "selxItkGradientDescentOptimizerv4.h"
38
#include "selxItkAffineTransform.h"
39
#include "selxItkGaussianExponentialDiffeomorphicTransform.h"
Floris Berendsen's avatar
Floris Berendsen committed
40
#include "selxItkGaussianExponentialDiffeomorphicTransformParametersAdaptorsContainerComponent.h"
41
#include "selxItkTransformDisplacementFilter.h"
42
#include "selxItkResampleFilter.h"
43
44
45
#include "selxItkImageSourceFixed.h"
#include "selxItkImageSourceMoving.h"

46
47
#include "selxRegistrationController.h"

Floris Berendsen's avatar
Floris Berendsen committed
48
49
50
51
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"

#include "itkMeshFileReader.h"
52
#include "itkMeshFileWriter.h"
Floris Berendsen's avatar
Floris Berendsen committed
53

54
#include "selxDefaultComponents.h"
55

56
#include "selxDataManager.h"
57
58
#include "gtest/gtest.h"

59
60
61
62
namespace selx
{
class RegistrationItkv4Test : public ::testing::Test
{
63
public:
64
65
66
67
68
69
70
71
72

  typedef Blueprint::Pointer            BlueprintPointerType;
  typedef Blueprint::ConstPointer       BlueprintConstPointerType;
  typedef Blueprint::ParameterMapType   ParameterMapType;
  typedef Blueprint::ParameterValueType ParameterValueType;
  typedef DataManager                   DataManagerType;

  /** register all example components */
  typedef TypeList< TransformComponent1,
73
74
75
76
77
    MetricComponent1,
    GDOptimizer3rdPartyComponent,
    GDOptimizer4thPartyComponent,
    SSDMetric3rdPartyComponent,
    SSDMetric4thPartyComponent,
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
    DisplacementFieldItkImageFilterSinkComponent< 3, double >,
    DisplacementFieldItkImageFilterSinkComponent< 2, float >,
    ItkImageSinkComponent< 3, double >,
    ItkImageSinkComponent< 2, float >,
    ItkImageSourceFixedComponent< 2, float >,
    ItkImageSourceMovingComponent< 2, float >,
    ItkImageSourceFixedComponent< 3, double >,
    ItkImageSourceMovingComponent< 3, double >,
    ItkSmoothingRecursiveGaussianImageFilterComponent< 3, double >,
    ItkSmoothingRecursiveGaussianImageFilterComponent< 2, double >,
    ItkSmoothingRecursiveGaussianImageFilterComponent< 3, float >,
    ItkSmoothingRecursiveGaussianImageFilterComponent< 2, float >,
    ItkImageRegistrationMethodv4Component< 3, double >,
    ItkImageRegistrationMethodv4Component< 2, float >,
    ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component< 3, double >,
    ItkMeanSquaresImageToImageMetricv4Component< 3, double >,
    ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component< 2, float >,
    ItkMeanSquaresImageToImageMetricv4Component< 2, float >,
    ItkGradientDescentOptimizerv4Component< double >,
    ItkAffineTransformComponent< double, 3 >,
    ItkGaussianExponentialDiffeomorphicTransformComponent< double, 3 >,
Floris Berendsen's avatar
Floris Berendsen committed
99
    ItkGaussianExponentialDiffeomorphicTransformParametersAdaptorsContainerComponent< 3, double >,
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
    ItkTransformDisplacementFilterComponent< 2, float, double >,
    ItkTransformDisplacementFilterComponent< 3, double, double >,
    ItkResampleFilterComponent< 2, float, double >,
    ItkResampleFilterComponent< 3, double, double >,
    RegistrationControllerComponent< >> RegisterComponents;

  typedef SuperElastixFilter< RegisterComponents > SuperElastixFilterType;

  typedef itk::Image< float, 2 >              Image2DType;
  typedef itk::ImageFileReader< Image2DType > ImageReader2DType;
  typedef itk::ImageFileWriter< Image2DType > ImageWriter2DType;

  typedef itk::Image< double, 3 >             Image3DType;
  typedef itk::ImageFileReader< Image3DType > ImageReader3DType;
  typedef itk::ImageFileWriter< Image3DType > ImageWriter3DType;

  typedef itk::Image< itk::Vector< double, 3 >, 3 >       DisplacementImage3DType;
  typedef itk::ImageFileWriter< DisplacementImage3DType > DisplacementImageWriter3DType;

  virtual void SetUp()
  {
121
122
  }

123
124
125

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

129

130
  BlueprintPointerType blueprint;
131
132
};

133
// These test are disabled, since may not want to check each component with this much boilerplate code.
134
135
// We should consider moving functional tests outside the unit tests
// Anyway, the Blueprint configuration needs to be updated
136
TEST_F( RegistrationItkv4Test, DISABLED_3DImagesOnly )
137
{
138
139
  /** make example blueprint configuration */
  blueprint = Blueprint::New();
140

141
  ParameterMapType component0Parameters;
142
143
144
  component0Parameters[ "NameOfClass" ]    = { "ItkImageRegistrationMethodv4Component" };
  component0Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the inputs
  blueprint->AddComponent( "RegistrationMethod", component0Parameters );
145

146
  ParameterMapType component1Parameters;
147
148
149
  component1Parameters[ "NameOfClass" ]    = { "ItkImageSourceFixedComponent" };
  component1Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the inputs
  blueprint->AddComponent( "FixedImageSource", component1Parameters );
150

151
  ParameterMapType component2Parameters;
152
153
154
  component2Parameters[ "NameOfClass" ]    = { "ItkImageSourceMovingComponent" };
  component2Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the inputs
  blueprint->AddComponent( "MovingImageSource", component2Parameters );
155

156
  ParameterMapType component3Parameters;
157
158
159
  component3Parameters[ "NameOfClass" ]    = { "ItkImageSinkComponent" };
  component3Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the outputs
  blueprint->AddComponent( "ResultImageSink", component3Parameters );
160

161
  ParameterMapType connection1Parameters;
162
163
  connection1Parameters[ "NameOfInterface" ] = { "itkImageFixedInterface" };
  blueprint->AddConnection( "FixedImageSource", "RegistrationMethod", connection1Parameters );
164

165
  ParameterMapType connection2Parameters;
166
167
  connection2Parameters[ "NameOfInterface" ] = { "itkImageMovingInterface" };
  blueprint->AddConnection( "MovingImageSource", "RegistrationMethod", connection2Parameters );
168

169
  ParameterMapType connection3Parameters;
170
171
  connection3Parameters[ "NameOfInterface" ] = { "itkImageInterface" };
  blueprint->AddConnection( "RegistrationMethod", "ResultImageSink", connection3Parameters );
172

173
174
  // Instantiate SuperElastix
  SuperElastixFilterType::Pointer superElastixFilter;
175
  EXPECT_NO_THROW( superElastixFilter = SuperElastixFilterType::New() );
176
177

  // Data manager provides the paths to the input and output data for unit tests
178
179
  DataManagerType::Pointer dataManager = DataManagerType::New();

180
181
  // Set up the readers and writers
  ImageReader3DType::Pointer fixedImageReader = ImageReader3DType::New();
182
  fixedImageReader->SetFileName( dataManager->GetInputFile( "sphereA3d.mhd" ) );
183
184

  ImageReader3DType::Pointer movingImageReader = ImageReader3DType::New();
185
  movingImageReader->SetFileName( dataManager->GetInputFile( "sphereB3d.mhd" ) );
186
187

  ImageWriter3DType::Pointer resultImageWriter = ImageWriter3DType::New();
188
  resultImageWriter->SetFileName( dataManager->GetOutputFile( "RegistrationItkv4Test_ImagesOnly.mhd" ) );
189
190

  // Connect SuperElastix in an itk pipeline
191
192
193
  superElastixFilter->SetInput( "FixedImageSource", fixedImageReader->GetOutput() );
  superElastixFilter->SetInput( "MovingImageSource", movingImageReader->GetOutput() );
  resultImageWriter->SetInput( superElastixFilter->GetOutput< Image3DType >( "ResultImageSink" ) );
194

195
  EXPECT_NO_THROW( superElastixFilter->SetBlueprint( blueprint ) );
196
197
198
199
200

  //Optional Update call
  //superElastixFilter->Update();

  // Update call on the writers triggers SuperElastix to configure and execute
201
  EXPECT_NO_THROW( resultImageWriter->Update() );
202
203
}

204
// These test are disabled, since may not want to check each component with this much boilerplate code.
205
206
// We should consider moving functional tests outside the unit tests
// Anyway, the Blueprint configuration needs to be updated
207
TEST_F( RegistrationItkv4Test, DISABLED_3DANTSCCMetric )
208
209
210
211
212
{
  /** make example blueprint configuration */
  blueprint = Blueprint::New();

  ParameterMapType component0Parameters;
213
214
215
  component0Parameters[ "NameOfClass" ]    = { "ItkImageRegistrationMethodv4Component" };
  component0Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the inputs
  blueprint->AddComponent( "RegistrationMethod", component0Parameters );
216
217

  ParameterMapType component1Parameters;
218
219
220
  component1Parameters[ "NameOfClass" ]    = { "ItkImageSourceFixedComponent" };
  component1Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the inputs
  blueprint->AddComponent( "FixedImageSource", component1Parameters );
221

222
  ParameterMapType component2Parameters;
223
224
225
  component2Parameters[ "NameOfClass" ]    = { "ItkImageSourceMovingComponent" };
  component2Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the inputs
  blueprint->AddComponent( "MovingImageSource", component2Parameters );
226
227

  ParameterMapType component3Parameters;
228
229
230
  component3Parameters[ "NameOfClass" ]    = { "ItkImageSinkComponent" };
  component3Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the outputs
  blueprint->AddComponent( "ResultImageSink", component3Parameters );
231
232

  ParameterMapType component4Parameters;
233
234
235
  component4Parameters[ "NameOfClass" ]    = { "ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component" };
  component4Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the inputs
  blueprint->AddComponent( "Metric", component4Parameters );
236

237
  ParameterMapType component5Parameters;
238
239
240
  component5Parameters[ "NameOfClass" ]        = { "ItkGradientDescentOptimizerv4Component" };
  component5Parameters[ "NumberOfIterations" ] = { "1" };
  blueprint->AddComponent( "Optimizer", component5Parameters );
241
242

  ParameterMapType connection1Parameters;
243
244
  connection1Parameters[ "NameOfInterface" ] = { "itkImageFixedInterface" };
  blueprint->AddConnection( "FixedImageSource", "RegistrationMethod", connection1Parameters );
245
246

  ParameterMapType connection2Parameters;
247
248
  connection2Parameters[ "NameOfInterface" ] = { "itkImageMovingInterface" };
  blueprint->AddConnection( "MovingImageSource", "RegistrationMethod", connection2Parameters );
249
250

  ParameterMapType connection3Parameters;
251
252
253
  connection3Parameters[ "NameOfInterface" ] = { "itkImageInterface" };
  blueprint->AddConnection( "RegistrationMethod", "ResultImageSink", connection3Parameters );

254
  ParameterMapType connection4Parameters;
255
256
  connection4Parameters[ "NameOfInterface" ] = { "itkMetricv4Interface" };
  blueprint->AddConnection( "Metric", "RegistrationMethod", connection4Parameters );
257

258
  ParameterMapType connection5Parameters;
259
260
  connection5Parameters[ "NameOfInterface" ] = { "itkOptimizerv4Interface" };
  blueprint->AddConnection( "Optimizer", "RegistrationMethod", connection5Parameters );
261

262
263
  // Instantiate SuperElastix
  SuperElastixFilterType::Pointer superElastixFilter;
264
  EXPECT_NO_THROW( superElastixFilter = SuperElastixFilterType::New() );
265
266

  // Data manager provides the paths to the input and output data for unit tests
267
  DataManagerType::Pointer dataManager = DataManagerType::New();
268
269
270

  // Set up the readers and writers
  ImageReader3DType::Pointer fixedImageReader = ImageReader3DType::New();
271
  fixedImageReader->SetFileName( dataManager->GetInputFile( "sphereA3d.mhd" ) );
272
273

  ImageReader3DType::Pointer movingImageReader = ImageReader3DType::New();
274
  movingImageReader->SetFileName( dataManager->GetInputFile( "sphereB3d.mhd" ) );
275
276

  ImageWriter3DType::Pointer resultImageWriter = ImageWriter3DType::New();
277
  resultImageWriter->SetFileName( dataManager->GetOutputFile( "RegistrationItkv4Test_WithANTSCCMetric.mhd" ) );
278
279

  // Connect SuperElastix in an itk pipeline
280
281
282
  superElastixFilter->SetInput( "FixedImageSource", fixedImageReader->GetOutput() );
  superElastixFilter->SetInput( "MovingImageSource", movingImageReader->GetOutput() );
  resultImageWriter->SetInput( superElastixFilter->GetOutput< Image3DType >( "ResultImageSink" ) );
283

284
  EXPECT_NO_THROW( superElastixFilter->SetBlueprint( blueprint ) );
285
286
287
288
289

  //Optional Update call
  //superElastixFilter->Update();

  // Update call on the writers triggers SuperElastix to configure and execute
290
  EXPECT_NO_THROW( resultImageWriter->Update() );
291
}
292

293
// These test are disabled, since may not want to check each component with this much boilerplate code.
294
295
// We should consider moving functional tests outside the unit tests
// Anyway, the Blueprint configuration needs to be updated
296
TEST_F( RegistrationItkv4Test, DISABLED_3DMeanSquaresMetric )
297
298
299
300
301
{
  /** make example blueprint configuration */
  blueprint = Blueprint::New();

  ParameterMapType component0Parameters;
302
303
304
  component0Parameters[ "NameOfClass" ]    = { "ItkImageRegistrationMethodv4Component" };
  component0Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the inputs
  blueprint->AddComponent( "RegistrationMethod", component0Parameters );
305
306

  ParameterMapType component1Parameters;
307
308
309
  component1Parameters[ "NameOfClass" ]    = { "ItkImageSourceFixedComponent" };
  component1Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the inputs
  blueprint->AddComponent( "FixedImageSource", component1Parameters );
310
311

  ParameterMapType component2Parameters;
312
313
314
  component2Parameters[ "NameOfClass" ]    = { "ItkImageSourceMovingComponent" };
  component2Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the inputs
  blueprint->AddComponent( "MovingImageSource", component2Parameters );
315
316

  ParameterMapType component3Parameters;
317
318
319
  component3Parameters[ "NameOfClass" ]    = { "ItkImageSinkComponent" };
  component3Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the outputs
  blueprint->AddComponent( "ResultImageSink", component3Parameters );
320
321

  ParameterMapType component4Parameters;
322
323
324
  component4Parameters[ "NameOfClass" ]    = { "ItkMeanSquaresImageToImageMetricv4Component" };
  component4Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the inputs
  blueprint->AddComponent( "Metric", component4Parameters );
325

326
  ParameterMapType component5Parameters;
327
328
329
  component5Parameters[ "NameOfClass" ]        = { "ItkGradientDescentOptimizerv4Component" };
  component5Parameters[ "NumberOfIterations" ] = { "1" };
  blueprint->AddComponent( "Optimizer", component5Parameters );
330
331

  ParameterMapType connection1Parameters;
332
333
  connection1Parameters[ "NameOfInterface" ] = { "itkImageFixedInterface" };
  blueprint->AddConnection( "FixedImageSource", "RegistrationMethod", connection1Parameters );
334
335

  ParameterMapType connection2Parameters;
336
337
  connection2Parameters[ "NameOfInterface" ] = { "itkImageMovingInterface" };
  blueprint->AddConnection( "MovingImageSource", "RegistrationMethod", connection2Parameters );
338
339

  ParameterMapType connection3Parameters;
340
341
  connection3Parameters[ "NameOfInterface" ] = { "itkImageInterface" };
  blueprint->AddConnection( "RegistrationMethod", "ResultImageSink", connection3Parameters );
342
343

  ParameterMapType connection4Parameters;
344
345
  connection4Parameters[ "NameOfInterface" ] = { "itkMetricv4Interface" };
  blueprint->AddConnection( "Metric", "RegistrationMethod", connection4Parameters );
346

347
  ParameterMapType connection5Parameters;
348
349
  connection5Parameters[ "NameOfInterface" ] = { "itkOptimizerv4Interface" };
  blueprint->AddConnection( "Optimizer", "RegistrationMethod", connection5Parameters );
350

351
352
  // Instantiate SuperElastix
  SuperElastixFilterType::Pointer superElastixFilter;
353
  EXPECT_NO_THROW( superElastixFilter = SuperElastixFilterType::New() );
354
355

  // Data manager provides the paths to the input and output data for unit tests
356
  DataManagerType::Pointer dataManager = DataManagerType::New();
357
358
359

  // Set up the readers and writers
  ImageReader3DType::Pointer fixedImageReader = ImageReader3DType::New();
360
  fixedImageReader->SetFileName( dataManager->GetInputFile( "sphereA3d.mhd" ) );
361
362

  ImageReader3DType::Pointer movingImageReader = ImageReader3DType::New();
363
  movingImageReader->SetFileName( dataManager->GetInputFile( "sphereB3d.mhd" ) );
364
365

  ImageWriter3DType::Pointer resultImageWriter = ImageWriter3DType::New();
366
  resultImageWriter->SetFileName( dataManager->GetOutputFile( "RegistrationItkv4Test_WithMeanSquaresMetric.mhd" ) );
367
368

  // Connect SuperElastix in an itk pipeline
369
370
371
  superElastixFilter->SetInput( "FixedImageSource", fixedImageReader->GetOutput() );
  superElastixFilter->SetInput( "MovingImageSource", movingImageReader->GetOutput() );
  resultImageWriter->SetInput( superElastixFilter->GetOutput< Image3DType >( "ResultImageSink" ) );
372

373
  EXPECT_NO_THROW( superElastixFilter->SetBlueprint( blueprint ) );
374
375
376
377
378

  //Optional Update call
  //superElastixFilter->Update();

  // Update call on the writers triggers SuperElastix to configure and execute
379
  EXPECT_NO_THROW( resultImageWriter->Update() );
380
}
381

382
TEST_F( RegistrationItkv4Test, FullyConfigured3d )
383
384
385
386
{
  /** make example blueprint configuration */
  blueprint = Blueprint::New();

Floris Berendsen's avatar
Floris Berendsen committed
387
388
389
390
  blueprint->AddComponent( "RegistrationMethod", { { "NameOfClass", { "ItkImageRegistrationMethodv4Component" } },
                                                   { "Dimensionality", { "3" } },
                                                   { "NumberOfLevels", { "2" } },
                                                   { "ShrinkFactorsPerLevel", { "2", "1" } } } );
391
392

  ParameterMapType component1Parameters;
393
394
395
  component1Parameters[ "NameOfClass" ]    = { "ItkImageSourceFixedComponent" };
  component1Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the inputs
  blueprint->AddComponent( "FixedImageSource", component1Parameters );
396
397

  ParameterMapType component2Parameters;
398
399
400
  component2Parameters[ "NameOfClass" ]    = { "ItkImageSourceMovingComponent" };
  component2Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the inputs
  blueprint->AddComponent( "MovingImageSource", component2Parameters );
401
402

  ParameterMapType component3Parameters;
403
404
405
  component3Parameters[ "NameOfClass" ]    = { "ItkImageSinkComponent" };
  component3Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the outputs
  blueprint->AddComponent( "ResultImageSink", component3Parameters );
406
407

  ParameterMapType component4Parameters;
408
409
410
  component4Parameters[ "NameOfClass" ]    = { "DisplacementFieldItkImageFilterSinkComponent" };
  component4Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the outputs
  blueprint->AddComponent( "ResultDisplacementFieldSink", component4Parameters );
411

412
  ParameterMapType component5Parameters;
413
414
415
  component5Parameters[ "NameOfClass" ]    = { "ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component" };
  component5Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the inputs
  blueprint->AddComponent( "Metric", component5Parameters );
416

417
  ParameterMapType component6Parameters;
418
419
420
  component6Parameters[ "NameOfClass" ]    = { "ItkTransformDisplacementFilterComponent" };
  component6Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the outputs
  blueprint->AddComponent( "TransformDisplacementFilter", component6Parameters );
421

422
  ParameterMapType component7Parameters;
423
424
425
  component7Parameters[ "NameOfClass" ]        = { "ItkGradientDescentOptimizerv4Component" };
  component7Parameters[ "NumberOfIterations" ] = { "1" };
  blueprint->AddComponent( "Optimizer", component7Parameters );
426

427
428
  blueprint->AddComponent( "ResampleFilter", { { "NameOfClass",    { "ItkResampleFilterComponent" } },
                                               { "Dimensionality", { "3" } } } );
429

430
431
  blueprint->AddComponent( "Transform",      { { "NameOfClass",    { "ItkGaussianExponentialDiffeomorphicTransformComponent" } },
                                               { "Dimensionality", { "3" } } } );
Floris Berendsen's avatar
Floris Berendsen committed
432
433
434
435
436

  blueprint->AddComponent( "TransformResolutionAdaptor", { { "NameOfClass", { "ItkGaussianExponentialDiffeomorphicTransformParametersAdaptorsContainerComponent" } },
                                                           { "Dimensionality", { "3" } },
                                                           { "ShrinkFactorsPerLevel", { "2", "1" } } } );

437
  blueprint->AddComponent( "Controller", { { "NameOfClass", { "RegistrationControllerComponent" } } } );
438

439
  ParameterMapType connection1Parameters;
440
441
  connection1Parameters[ "NameOfInterface" ] = { "itkImageFixedInterface" };
  blueprint->AddConnection( "FixedImageSource", "RegistrationMethod", connection1Parameters );
442
443

  ParameterMapType connection2Parameters;
444
445
  connection2Parameters[ "NameOfInterface" ] = { "itkImageMovingInterface" };
  blueprint->AddConnection( "MovingImageSource", "RegistrationMethod", connection2Parameters );
446
447

  ParameterMapType connection3Parameters;
448
449
  connection3Parameters[ "NameOfInterface" ] = { "itkImageInterface" };
  blueprint->AddConnection( "ResampleFilter", "ResultImageSink", connection3Parameters );
450
451

  ParameterMapType connection4Parameters;
452
453
  connection4Parameters[ "NameOfInterface" ] = { "DisplacementFieldItkImageSourceInterface" };
  blueprint->AddConnection( "TransformDisplacementFilter", "ResultDisplacementFieldSink", connection4Parameters );
454

455
  ParameterMapType connection5Parameters;
456
457
458
459
460
  connection5Parameters[ "NameOfInterface" ] = { "itkMetricv4Interface" };
  blueprint->AddConnection( "Metric", "RegistrationMethod", connection5Parameters );

  blueprint->AddConnection( "FixedImageSource", "Transform", { {} } );
  blueprint->AddConnection( "Transform", "RegistrationMethod", { {} } );
Floris Berendsen's avatar
Floris Berendsen committed
461
462
463

  blueprint->AddConnection( "FixedImageSource", "TransformResolutionAdaptor", { {} } );
  blueprint->AddConnection( "TransformResolutionAdaptor", "RegistrationMethod", { {} } );
464
465
466
467
468
469
470
471
472
473
  blueprint->AddConnection( "Optimizer", "RegistrationMethod", { {} } );
  blueprint->AddConnection( "RegistrationMethod", "TransformDisplacementFilter", { {} } );
  blueprint->AddConnection( "FixedImageSource", "TransformDisplacementFilter", { {} } );
  blueprint->AddConnection( "RegistrationMethod", "ResampleFilter", { {} } );
  blueprint->AddConnection( "FixedImageSource", "ResampleFilter", { {} } );
  blueprint->AddConnection( "MovingImageSource", "ResampleFilter", { {} } );

  blueprint->AddConnection( "RegistrationMethod", "Controller", { {} } );          //RunRegistrationInterface
  blueprint->AddConnection( "ResampleFilter", "Controller", { {} } );              //ReconnectTransformInterface
  blueprint->AddConnection( "TransformDisplacementFilter", "Controller", { {} } ); //ReconnectTransformInterface
474

475
476
  // Instantiate SuperElastix
  SuperElastixFilterType::Pointer superElastixFilter;
477
  EXPECT_NO_THROW( superElastixFilter = SuperElastixFilterType::New() );
478

479
  // Data manager provides the paths to the input and output data for unit tests
480
  DataManagerType::Pointer dataManager = DataManagerType::New();
481
482
483

  // Set up the readers and writers
  ImageReader3DType::Pointer fixedImageReader = ImageReader3DType::New();
484
  fixedImageReader->SetFileName( dataManager->GetInputFile( "sphereA3d.mhd" ) );
485
486

  ImageReader3DType::Pointer movingImageReader = ImageReader3DType::New();
487
  movingImageReader->SetFileName( dataManager->GetInputFile( "sphereB3d.mhd" ) );
488
489

  ImageWriter3DType::Pointer resultImageWriter = ImageWriter3DType::New();
490
  resultImageWriter->SetFileName( dataManager->GetOutputFile( "RegistrationItkv4Test_DisplacementField_image.mhd" ) );
491
492

  DisplacementImageWriter3DType::Pointer resultDisplacementWriter = DisplacementImageWriter3DType::New();
493
  resultDisplacementWriter->SetFileName( dataManager->GetOutputFile( "RegistrationItkv4Test_DisplacementField_displacement.mhd" ) );
494
495

  // Connect SuperElastix in an itk pipeline
496
497
498
499
  superElastixFilter->SetInput( "FixedImageSource", fixedImageReader->GetOutput() );
  superElastixFilter->SetInput( "MovingImageSource", movingImageReader->GetOutput() );
  resultImageWriter->SetInput( superElastixFilter->GetOutput< Image3DType >( "ResultImageSink" ) );
  resultDisplacementWriter->SetInput( superElastixFilter->GetOutput< DisplacementImage3DType >( "ResultDisplacementFieldSink" ) );
500

501
  EXPECT_NO_THROW( superElastixFilter->SetBlueprint( blueprint ) );
502
503
504
505
506

  //Optional Update call
  //superElastixFilter->Update();

  // Update call on the writers triggers SuperElastix to configure and execute
507
508
  EXPECT_NO_THROW( resultImageWriter->Update() );
  EXPECT_NO_THROW( resultDisplacementWriter->Update() );
509

510
  blueprint->WriteBlueprint( dataManager->GetOutputFile( "RegistrationItkv4Test_DisplacementField_network.dot" ) );
511
}
Floris Berendsen's avatar
Floris Berendsen committed
512
TEST_F( RegistrationItkv4Test, FullyConfigured3dAffine )
513
514
515
516
{
  /** make example blueprint configuration */
  blueprint = Blueprint::New();

Floris Berendsen's avatar
Floris Berendsen committed
517
518
519
  blueprint->AddComponent( "RegistrationMethod", { { "NameOfClass", { "ItkImageRegistrationMethodv4Component" } },
                                                   { "Dimensionality", { "3" } },
                                                   { "NumberOfLevels", { "2" } } } );
520
521

  ParameterMapType component1Parameters;
Floris Berendsen's avatar
Floris Berendsen committed
522
523
524
  component1Parameters[ "NameOfClass" ]    = { "ItkImageSourceFixedComponent" };
  component1Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the inputs
  blueprint->AddComponent( "FixedImageSource", component1Parameters );
525
526

  ParameterMapType component2Parameters;
Floris Berendsen's avatar
Floris Berendsen committed
527
528
529
  component2Parameters[ "NameOfClass" ]    = { "ItkImageSourceMovingComponent" };
  component2Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the inputs
  blueprint->AddComponent( "MovingImageSource", component2Parameters );
530
531

  ParameterMapType component3Parameters;
Floris Berendsen's avatar
Floris Berendsen committed
532
533
534
  component3Parameters[ "NameOfClass" ]    = { "ItkImageSinkComponent" };
  component3Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the outputs
  blueprint->AddComponent( "ResultImageSink", component3Parameters );
535
536

  ParameterMapType component4Parameters;
Floris Berendsen's avatar
Floris Berendsen committed
537
538
539
  component4Parameters[ "NameOfClass" ]    = { "DisplacementFieldItkImageFilterSinkComponent" };
  component4Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the outputs
  blueprint->AddComponent( "ResultDisplacementFieldSink", component4Parameters );
540
541

  ParameterMapType component5Parameters;
Floris Berendsen's avatar
Floris Berendsen committed
542
543
544
  component5Parameters[ "NameOfClass" ]    = { "ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component" };
  component5Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the inputs
  blueprint->AddComponent( "Metric", component5Parameters );
545
546

  ParameterMapType component6Parameters;
Floris Berendsen's avatar
Floris Berendsen committed
547
548
549
  component6Parameters[ "NameOfClass" ]    = { "ItkTransformDisplacementFilterComponent" };
  component6Parameters[ "Dimensionality" ] = { "3" }; // should be derived from the outputs
  blueprint->AddComponent( "TransformDisplacementFilter", component6Parameters );
550
551

  ParameterMapType component7Parameters;
Floris Berendsen's avatar
Floris Berendsen committed
552
553
554
  component7Parameters[ "NameOfClass" ]        = { "ItkGradientDescentOptimizerv4Component" };
  component7Parameters[ "NumberOfIterations" ] = { "10" };
  blueprint->AddComponent( "Optimizer", component7Parameters );
555

Floris Berendsen's avatar
Floris Berendsen committed
556
557
  blueprint->AddComponent( "ResampleFilter", { { "NameOfClass", { "ItkResampleFilterComponent" } },
                                               { "Dimensionality", { "3" } } } );
558

Floris Berendsen's avatar
Floris Berendsen committed
559
560
  blueprint->AddComponent( "Transform", { { "NameOfClass", { "ItkAffineTransformComponent" } },
                                          { "Dimensionality", { "3" } } } );
561

Floris Berendsen's avatar
Floris Berendsen committed
562
  blueprint->AddComponent( "Controller", { { "NameOfClass", { "RegistrationControllerComponent" } } } );
563
564

  ParameterMapType connection1Parameters;
Floris Berendsen's avatar
Floris Berendsen committed
565
566
  connection1Parameters[ "NameOfInterface" ] = { "itkImageFixedInterface" };
  blueprint->AddConnection( "FixedImageSource", "RegistrationMethod", connection1Parameters );
567
568

  ParameterMapType connection2Parameters;
Floris Berendsen's avatar
Floris Berendsen committed
569
570
  connection2Parameters[ "NameOfInterface" ] = { "itkImageMovingInterface" };
  blueprint->AddConnection( "MovingImageSource", "RegistrationMethod", connection2Parameters );
571
572

  ParameterMapType connection3Parameters;
Floris Berendsen's avatar
Floris Berendsen committed
573
574
  connection3Parameters[ "NameOfInterface" ] = { "itkImageInterface" };
  blueprint->AddConnection( "ResampleFilter", "ResultImageSink", connection3Parameters );
575
576

  ParameterMapType connection4Parameters;
Floris Berendsen's avatar
Floris Berendsen committed
577
578
  connection4Parameters[ "NameOfInterface" ] = { "DisplacementFieldItkImageSourceInterface" };
  blueprint->AddConnection( "TransformDisplacementFilter", "ResultDisplacementFieldSink", connection4Parameters );
579
580

  ParameterMapType connection5Parameters;
Floris Berendsen's avatar
Floris Berendsen committed
581
582
  connection5Parameters[ "NameOfInterface" ] = { "itkMetricv4Interface" };
  blueprint->AddConnection( "Metric", "RegistrationMethod", connection5Parameters );
583

584
  //blueprint->AddConnection( "FixedImageSource", "Transform", { {} } );
Floris Berendsen's avatar
Floris Berendsen committed
585
  blueprint->AddConnection( "Transform", "RegistrationMethod", { {} } );
586

Floris Berendsen's avatar
Floris Berendsen committed
587
588
589
590
591
592
  blueprint->AddConnection( "Optimizer", "RegistrationMethod", { {} } );
  blueprint->AddConnection( "RegistrationMethod", "TransformDisplacementFilter", { {} } );
  blueprint->AddConnection( "FixedImageSource", "TransformDisplacementFilter", { {} } );
  blueprint->AddConnection( "RegistrationMethod", "ResampleFilter", { {} } );
  blueprint->AddConnection( "FixedImageSource", "ResampleFilter", { {} } );
  blueprint->AddConnection( "MovingImageSource", "ResampleFilter", { {} } );
593

Floris Berendsen's avatar
Floris Berendsen committed
594
595
596
  blueprint->AddConnection( "RegistrationMethod", "Controller", { {} } );          //RunRegistrationInterface
  blueprint->AddConnection( "ResampleFilter", "Controller", { {} } );              //ReconnectTransformInterface
  blueprint->AddConnection( "TransformDisplacementFilter", "Controller", { {} } ); //ReconnectTransformInterface
597
598
599

  // Instantiate SuperElastix
  SuperElastixFilterType::Pointer superElastixFilter;
Floris Berendsen's avatar
Floris Berendsen committed
600
  EXPECT_NO_THROW( superElastixFilter = SuperElastixFilterType::New() );
601
602
603
604
605
606

  // Data manager provides the paths to the input and output data for unit tests
  DataManagerType::Pointer dataManager = DataManagerType::New();

  // Set up the readers and writers
  ImageReader3DType::Pointer fixedImageReader = ImageReader3DType::New();
Floris Berendsen's avatar
Floris Berendsen committed
607
  fixedImageReader->SetFileName( dataManager->GetInputFile( "sphereA3d.mhd" ) );
608
609

  ImageReader3DType::Pointer movingImageReader = ImageReader3DType::New();
Floris Berendsen's avatar
Floris Berendsen committed
610
  movingImageReader->SetFileName( dataManager->GetInputFile( "sphereB3d.mhd" ) );
611
612

  ImageWriter3DType::Pointer resultImageWriter = ImageWriter3DType::New();
Floris Berendsen's avatar
Floris Berendsen committed
613
  resultImageWriter->SetFileName( dataManager->GetOutputFile( "RegistrationItkv4Test_DisplacementField_image.mhd" ) );
614
615

  DisplacementImageWriter3DType::Pointer resultDisplacementWriter = DisplacementImageWriter3DType::New();
Floris Berendsen's avatar
Floris Berendsen committed
616
  resultDisplacementWriter->SetFileName( dataManager->GetOutputFile( "RegistrationItkv4Test_DisplacementField_displacement.mhd" ) );
617
618

  // Connect SuperElastix in an itk pipeline
Floris Berendsen's avatar
Floris Berendsen committed
619
620
621
622
  superElastixFilter->SetInput( "FixedImageSource", fixedImageReader->GetOutput() );
  superElastixFilter->SetInput( "MovingImageSource", movingImageReader->GetOutput() );
  resultImageWriter->SetInput( superElastixFilter->GetOutput< Image3DType >( "ResultImageSink" ) );
  resultDisplacementWriter->SetInput( superElastixFilter->GetOutput< DisplacementImage3DType >( "ResultDisplacementFieldSink" ) );
623

Floris Berendsen's avatar
Floris Berendsen committed
624
  EXPECT_NO_THROW( superElastixFilter->SetBlueprint( blueprint ) );
625
626
627
628
629

  //Optional Update call
  //superElastixFilter->Update();

  // Update call on the writers triggers SuperElastix to configure and execute
Floris Berendsen's avatar
Floris Berendsen committed
630
631
  EXPECT_NO_THROW( resultImageWriter->Update() );
  EXPECT_NO_THROW( resultDisplacementWriter->Update() );
632

Floris Berendsen's avatar
Floris Berendsen committed
633
  blueprint->WriteBlueprint( dataManager->GetOutputFile( "RegistrationItkv4Test_DisplacementField_network.dot" ) );
634
}
635
} // namespace selx