selxRegistrationItkv4Test.cxx 24.8 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"
40
#include "selxItkGaussianExponentialDiffeomorphicTransformParametersAdaptorComponent.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 >,
99
    ItkGaussianExponentialDiffeomorphicTransformParametersAdaptorComponent<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();

387
388
389
  blueprint->AddComponent("RegistrationMethod", { { "NameOfClass", { "ItkImageRegistrationMethodv4Component" } },
                                                          { "Dimensionality", { "3" } },
                                                          { "ShrinkFactorsPerLevel", { "4", "2", "1" } } });
390
391

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

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

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

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

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

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

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

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

429
430
  blueprint->AddComponent( "Transform",      { { "NameOfClass",    { "ItkGaussianExponentialDiffeomorphicTransformComponent" } },
                                               { "Dimensionality", { "3" } } } );
431
432
433
434
435
  
  blueprint->AddComponent("TransformResolutionAdaptor", { { "NameOfClass", { "ItkGaussianExponentialDiffeomorphicTransformParametersAdaptorComponent" } },
                                                          { "Dimensionality", { "3" } }, 
                                                          { "ShrinkFactorsPerLevel", { "4", "2", "1" } } });
    
436
  blueprint->AddComponent( "Controller", { { "NameOfClass", { "RegistrationControllerComponent" } } } );
437

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

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

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

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

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

  blueprint->AddConnection( "FixedImageSource", "Transform", { {} } );
  blueprint->AddConnection( "Transform", "RegistrationMethod", { {} } );
460
461
462
  
  blueprint->AddConnection( "FixedImageSource", "TransformResolutionAdaptor", { {} });
  blueprint->AddConnection( "TransformResolutionAdaptor", "RegistrationMethod", { {} }); 
463
464
465
466
467
468
469
470
471
472
  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
473

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

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

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

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

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

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

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

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

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

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

509
  blueprint->WriteBlueprint( dataManager->GetOutputFile( "RegistrationItkv4Test_DisplacementField_network.dot" ) );
510
}
511
} // namespace selx