selxNiftyregComponentTest.cxx 4.31 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*=========================================================================
 *
 *  Copyright Leiden University Medical Center, Erasmus University Medical
 *  Center and contributors
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/

20
21
#include "selxSuperElastixFilterCustomComponents.h"

22
23
24
#include "selxRegistrationController.h"

#include "selxNiftyregReadImageComponent.h"
25
#include "selxNiftyregWriteImageComponent.h"
26
#include "selxNiftyregf3dComponent.h"
27
28
29
#include "selxDataManager.h"
#include "gtest/gtest.h"

30
31
namespace selx
{
32
33
34
class NiftyregComponentTest : public ::testing::Test
{
public:
Floris Berendsen's avatar
Floris Berendsen committed
35
36
37
38
39
40
41

  typedef std::unique_ptr< Blueprint >                       BlueprintPointer;
  typedef itk::UniquePointerDataObjectDecorator< Blueprint > BlueprintITKType;
  typedef BlueprintITKType::Pointer                          BlueprintITKPointer;
  typedef Blueprint::ParameterMapType                        ParameterMapType;
  typedef Blueprint::ParameterValueType                      ParameterValueType;
  typedef DataManager                                        DataManagerType;
42
43

  /** register all example components */
Floris Berendsen's avatar
Floris Berendsen committed
44
  typedef TypeList< Niftyregf3dComponent< float >, NiftyregReadImageComponent< float >,
45
    NiftyregWriteImageComponent< float >, RegistrationControllerComponent< >> RegisterComponents;
46

47
48
  virtual void SetUp()
  {
49
50
51
    // Instantiate SuperElastixFilter before each test and
    // register the components we want to have available in SuperElastix
    superElastixFilter = SuperElastixFilterCustomComponents< RegisterComponents >::New();
Floris Berendsen's avatar
Floris Berendsen committed
52
    dataManager        = DataManagerType::New();
53
54
  }

Floris Berendsen's avatar
Floris Berendsen committed
55

56
57
  virtual void TearDown()
  {
Floris Berendsen's avatar
Floris Berendsen committed
58
    // Unregister all components after each test
59
    itk::ObjectFactoryBase::UnRegisterAllFactories();
Floris Berendsen's avatar
Floris Berendsen committed
60
    // Delete the SuperElastixFilter after each test
61
    superElastixFilter = nullptr;
62
  }
Floris Berendsen's avatar
Floris Berendsen committed
63
64
65
66
67
68
69


  // Blueprint holds a configuration for SuperElastix
  BlueprintPointer            blueprint;
  SuperElastixFilter::Pointer superElastixFilter;
  // Data manager provides the paths to the input and output data for unit tests
  DataManagerType::Pointer dataManager;
70
};
71

Floris Berendsen's avatar
Floris Berendsen committed
72
TEST_F( NiftyregComponentTest, Register2d )
73
{
Floris Berendsen's avatar
Floris Berendsen committed
74
  /** make example blueprint configuration */
75
  BlueprintPointer blueprint = BlueprintPointer( new Blueprint() );
76
77
  blueprint->SetComponent( "FixedImage", { { "NameOfClass", { "NiftyregReadImageComponent" } }, { "FileName", { this->dataManager->GetInputFile( "r16slice.nii.gz" ) } } } );
  blueprint->SetComponent( "MovingImage", { { "NameOfClass", { "NiftyregReadImageComponent" } }, { "FileName", { this->dataManager->GetInputFile( "r64slice.nii.gz" ) } } } );
Floris Berendsen's avatar
Floris Berendsen committed
78
  blueprint->SetComponent( "RegistrationMethod", { { "NameOfClass", { "Niftyregf3dComponent" } } } );
79
  blueprint->SetComponent( "ResultImage", { { "NameOfClass", { "NiftyregWriteImageComponent" } }, { "FileName", { this->dataManager->GetOutputFile("Nifty_warped_r64to16.nii.gz") } } });
Floris Berendsen's avatar
Floris Berendsen committed
80
  blueprint->SetComponent( "Controller", { { "NameOfClass", { "RegistrationControllerComponent" } } } );
81

Floris Berendsen's avatar
Floris Berendsen committed
82

83
84
85
  blueprint->SetConnection("FixedImage", "RegistrationMethod", { { "NameOfInterface", { "NiftyregReferenceImageInterface" } } });
  blueprint->SetConnection( "MovingImage", "RegistrationMethod", { { "NameOfInterface", { "NiftyregFloatingImageInterface" } } });
  blueprint->SetConnection("RegistrationMethod", "ResultImage", { {} }); //{ { "NameOfInterface", { "NiftyregWarpedImageInterface" } } });
Floris Berendsen's avatar
Floris Berendsen committed
86
  blueprint->SetConnection( "RegistrationMethod", "Controller", { {} } );
87
  blueprint->SetConnection("ResultImage", "Controller", { {} });
Floris Berendsen's avatar
Floris Berendsen committed
88

89
90
91
92
  BlueprintITKPointer superElastixFilterBlueprint = BlueprintITKType::New();
  superElastixFilterBlueprint->Set( blueprint );
  EXPECT_NO_THROW( superElastixFilter->SetBlueprint( superElastixFilterBlueprint ) );

Floris Berendsen's avatar
Floris Berendsen committed
93
  EXPECT_NO_THROW( superElastixFilter->Update() );
94
}
95
}