-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCombineITKTransforms.cpp
46 lines (44 loc) · 1.53 KB
/
CombineITKTransforms.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "CombineITKTransforms.h"
int CombineITKTransforms( int argc , char* argv[] )
{
//check if next to last is "-o"
bool badArguments = false ;
if( argc >= 5 )
{
if( strcmp( argv[ argc - 2 ] , "-o" ) )
{
badArguments = true ;
}
}
if( argc < 5 || badArguments )
{
std::cout<< argv[ 0 ] << " " << argv[ 1 ] << " inputTransform1 [inputTransform2 inputTransform3 ...] -o outputTransform" << std::endl ;
std::cout<< "inputTransforms should be in the order in which they are applied to the input image" << std::endl ;
return 1 ;
}
//Set parameters
std::list< std::string > listTransformFiles ;
for( int i = 2 ; i < argc - 2 ; i++ )//argc - 1: outputFileName ; argc - 2: "-o"
{
std::string input ;
input.assign( argv[ i ] ) ;
listTransformFiles.push_back( input ) ;
}
//Creation of the itkTransformFileWriter
itk::TransformFileWriter::Pointer transformWriter = itk::TransformFileWriter::New() ;
transformWriter->SetFileName( argv[ argc - 1 ] ) ;
do
{
itk::TransformFileReader::Pointer transformFile = itk::TransformFileReader::New() ;
transformFile->SetFileName( listTransformFiles.front().c_str() ) ;
transformFile->Update() ;
do
{
transformWriter->AddTransform( transformFile->GetTransformList()->front() ) ;
transformFile->GetTransformList()->pop_front() ;
}while( transformFile->GetTransformList()->size() ) ;
listTransformFiles.pop_front() ;
}while( listTransformFiles.size() ) ;
transformWriter->Update() ;
return 0 ;
}