selxRegistrationItkv4Test.cxx 35.3 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
#include "selxRegistrationController.h"
47
#include "selxItkCompositeTransformComponent.h"
48

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

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

55
#include "selxDefaultComponents.h"
56

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

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

  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,
74
75
76
77
78
    MetricComponent1,
    GDOptimizer3rdPartyComponent,
    GDOptimizer4thPartyComponent,
    SSDMetric3rdPartyComponent,
    SSDMetric4thPartyComponent,
79
80
81
82
83
84
85
86
87
88
89
90
    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 >,
Floris Berendsen's avatar
WIP    
Floris Berendsen committed
91
92
    ItkImageRegistrationMethodv4Component< 3, double, double >,
    ItkImageRegistrationMethodv4Component< 2, float, double >,
93
    ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component< 3, double >,
94
    ItkMeanSquaresImageToImageMetricv4Component< 3, double, double >,
95
    ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component< 2, float >,
Floris Berendsen's avatar
Floris Berendsen committed
96
    ItkMeanSquaresImageToImageMetricv4Component< 2, float, double  >,
97
98
99
    ItkGradientDescentOptimizerv4Component< double >,
    ItkAffineTransformComponent< double, 3 >,
    ItkGaussianExponentialDiffeomorphicTransformComponent< double, 3 >,
Floris Berendsen's avatar
Floris Berendsen committed
100
    ItkGaussianExponentialDiffeomorphicTransformParametersAdaptorsContainerComponent< 3, double >,
101
102
103
104
    ItkTransformDisplacementFilterComponent< 2, float, double >,
    ItkTransformDisplacementFilterComponent< 3, double, double >,
    ItkResampleFilterComponent< 2, float, double >,
    ItkResampleFilterComponent< 3, double, double >,
105
106
    RegistrationControllerComponent< >,
    ItkCompositeTransformComponent<double, 3> > RegisterComponents;
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

  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()
  {
123
124
  }

125
126
127

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

131

132
  BlueprintPointerType blueprint;
133
134
};

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

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

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

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

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

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

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

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

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

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

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

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

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

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

197
  EXPECT_NO_THROW( superElastixFilter->SetBlueprint( blueprint ) );
198
199
200
201
202

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

286
  EXPECT_NO_THROW( superElastixFilter->SetBlueprint( blueprint ) );
287
288
289
290
291

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

375
  EXPECT_NO_THROW( superElastixFilter->SetBlueprint( blueprint ) );
376
377
378
379
380

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

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

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

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

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

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

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

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

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

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

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

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

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

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

439
  blueprint->AddComponent( "Controller", { { "NameOfClass", { "RegistrationControllerComponent" } } } );
440

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

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

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

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

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

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

  blueprint->AddConnection( "FixedImageSource", "TransformResolutionAdaptor", { {} } );
  blueprint->AddConnection( "TransformResolutionAdaptor", "RegistrationMethod", { {} } );
466
467
468
469
470
471
472
473
474
475
  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
476

477
478
  // Instantiate SuperElastix
  SuperElastixFilterType::Pointer superElastixFilter;
479
  EXPECT_NO_THROW( superElastixFilter = SuperElastixFilterType::New() );
480

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

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

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

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

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

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

503
  EXPECT_NO_THROW( superElastixFilter->SetBlueprint( blueprint ) );
504
505
506
507
508

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  // 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
609
  fixedImageReader->SetFileName( dataManager->GetInputFile( "sphereA3d.mhd" ) );
610
611

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

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

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

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

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

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

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

Floris Berendsen's avatar
Floris Berendsen committed
635
  blueprint->WriteBlueprint( dataManager->GetOutputFile( "RegistrationItkv4Test_DisplacementField_network.dot" ) );
636
}
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709

TEST_F(RegistrationItkv4Test, CompositeTransform)
{
  /** make example blueprint configuration */
  blueprint = Blueprint::New();

  blueprint->AddComponent("MultiStageTransformController", { { "NameOfClass", { "ItkCompositeTransformComponent" } } });

  blueprint->AddComponent("RegistrationMethod1", { { "NameOfClass", { "ItkImageRegistrationMethodv4Component" } },
  { "Dimensionality", { "2" } },
  { "InternalComputationValueType", { "double" } },
  { "PixelType", { "float" } } });

  blueprint->AddComponent("FixedImageSource", { { "NameOfClass", { "ItkImageSourceFixedComponent" } } });
  blueprint->AddConnection("FixedImageSource", "RegistrationMethod1", {});

  blueprint->AddComponent("MovingImageSource", { { "NameOfClass", { "ItkImageSourceMovingComponent" } } });
  blueprint->AddConnection("MovingImageSource", "RegistrationMethod1", {});

  blueprint->AddComponent("ResultImageSink", { { "NameOfClass", { "ItkImageSinkComponent" } } });

  blueprint->AddComponent("Metric1", { { "NameOfClass", { "ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component" } } });
  blueprint->AddConnection("Metric1", "RegistrationMethod1", {});
  blueprint->AddComponent("Transform1", { { "NameOfClass", { "ItkAffineTransformComponent" } } });
  blueprint->AddConnection("Transform1", "RegistrationMethod1", {});
  blueprint->AddComponent("Optimizer1", { { "NameOfClass", { "ItkGradientDescentOptimizerv4Component" } } });
  blueprint->AddConnection("Optimizer1", "RegistrationMethod1", {});

  blueprint->AddConnection("RegistrationMethod1", "MultiStageTransformController", {}); // MultiStageTransformInterface

  blueprint->AddComponent("ResampleFilter", { { "NameOfClass", { "ItkResampleFilterComponent" } } });
  blueprint->AddConnection("FixedImageSource", "ResampleFilter", { {} });
  blueprint->AddConnection("MovingImageSource", "ResampleFilter", { {} });
  blueprint->AddConnection("MultiStageTransformController", "ResampleFilter", { {} }); //ReconnectTransformInterface

  blueprint->AddConnection("ResampleFilter", "ResultImageSink", {});



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

  blueprint->WriteBlueprint(dataManager->GetOutputFile("RegistrationItkv4Test_CompositeTransform.dot"));

  // Instantiate SuperElastix
  SuperElastixFilterType::Pointer superElastixFilter;
  EXPECT_NO_THROW(superElastixFilter = SuperElastixFilterType::New());

  // Set up the readers and writers
  ImageReader2DType::Pointer fixedImageReader = ImageReader2DType::New();
  fixedImageReader->SetFileName(dataManager->GetInputFile("coneA2d64.mhd"));

  ImageReader2DType::Pointer movingImageReader = ImageReader2DType::New();
  movingImageReader->SetFileName(dataManager->GetInputFile("coneB2d64.mhd"));

  ImageWriter2DType::Pointer resultImageWriter = ImageWriter2DType::New();
  resultImageWriter->SetFileName(dataManager->GetOutputFile("RegistrationItkv4Test_CompositeTransform.mhd"));

  // Connect SuperElastix in an itk pipeline
  superElastixFilter->SetInput("FixedImageSource", fixedImageReader->GetOutput());
  superElastixFilter->SetInput("MovingImageSource", movingImageReader->GetOutput());

  resultImageWriter->SetInput(superElastixFilter->GetOutput< Image2DType >("ResultImageSink"));

  EXPECT_NO_THROW(superElastixFilter->SetBlueprint(blueprint));

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

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

}
710
} // namespace selx