-
Notifications
You must be signed in to change notification settings - Fork 22
/
itkElastixRegistrationMethod.hxx
788 lines (653 loc) · 25 KB
/
itkElastixRegistrationMethod.hxx
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
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
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
/*=========================================================================
*
* Copyright Insight Software Consortium
*
* 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.
*
*=========================================================================*/
/*=========================================================================
*
* Copyright UMC Utrecht 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.
*
*=========================================================================*/
#ifndef itkElastixRegistrationMethod_hxx
#define itkElastixRegistrationMethod_hxx
#include "elxPixelType.h"
#include "itkElastixRegistrationMethod.h"
namespace itk
{
template< typename TFixedImage, typename TMovingImage >
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::ElastixRegistrationMethod()
{
this->SetPrimaryInputName( "FixedImage" );
this->SetPrimaryOutputName( "ResultImage" );
this->AddRequiredInputName( "MovingImage", 1 );
this->AddRequiredInputName( "ParameterObject", 2 );
this->m_InitialTransformParameterFileName = "";
this->m_FixedPointSetFileName = "";
this->m_MovingPointSetFileName = "";
this->m_OutputDirectory = "";
this->m_LogFileName = "";
this->m_LogToConsole = false;
this->m_LogToFile = false;
this->m_NumberOfThreads = 0;
ParameterObjectPointer defaultParameterObject = elastix::ParameterObject::New();
defaultParameterObject->AddParameterMap( elastix::ParameterObject::GetDefaultParameterMap( "translation" ) );
defaultParameterObject->AddParameterMap( elastix::ParameterObject::GetDefaultParameterMap( "affine" ) );
defaultParameterObject->AddParameterMap( elastix::ParameterObject::GetDefaultParameterMap( "bspline" ) );
this->SetParameterObject( defaultParameterObject );
this->m_InputUID = 0;
}
template< typename TFixedImage, typename TMovingImage >
void
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::GenerateData()
{
// Force compiler to instantiate the image dimensions, otherwise we may get
// Undefined symbols for architecture x86_64:
// "elastix::ElastixRegistrationMethod<itk::Image<float, 2u> >::FixedImageDimension"
// on some platforms.
const unsigned int fixedImageDimension = FixedImageDimension;
const unsigned int movingImageDimension = MovingImageDimension;
DataObjectContainerPointer fixedImageContainer = DataObjectContainerType::New();
DataObjectContainerPointer movingImageContainer = DataObjectContainerType::New();
DataObjectContainerPointer fixedMaskContainer = nullptr;
DataObjectContainerPointer movingMaskContainer = nullptr;
DataObjectContainerPointer resultImageContainer = nullptr;
ElastixMainObjectPointer transform = nullptr;
ParameterMapVectorType transformParameterMapVector;
FlatDirectionCosinesType fixedImageOriginalDirection;
// Split inputs into separate containers
const NameArrayType inputNames = this->GetInputNames();
for( unsigned int i = 0; i < inputNames.size(); ++i )
{
if( this->IsInputOfType( "FixedImage", inputNames[ i ] ) )
{
fixedImageContainer->push_back( this->ProcessObject::GetInput( inputNames[ i ] ) );
continue;
}
if( this->IsInputOfType( "MovingImage", inputNames[ i ] ) )
{
movingImageContainer->push_back( this->ProcessObject::GetInput( inputNames[ i ] ) );
continue;
}
if( this->IsInputOfType( "FixedMask", inputNames[ i ] ) )
{
if( fixedMaskContainer.IsNull() )
{
fixedMaskContainer = DataObjectContainerType::New();
}
fixedMaskContainer->push_back( this->ProcessObject::GetInput( inputNames[ i ] ) );
continue;
}
if( this->IsInputOfType( "MovingMask", inputNames[ i ] ) )
{
if( movingMaskContainer.IsNull() )
{
movingMaskContainer = DataObjectContainerType::New();
}
movingMaskContainer->push_back( this->ProcessObject::GetInput( inputNames[ i ] ) );
}
}
// Set ParameterMap
ParameterObjectPointer parameterObject = itkDynamicCastInDebugMode< elastix::ParameterObject * >( this->ProcessObject::GetInput( "ParameterObject" ) );
ParameterMapVectorType parameterMapVector = parameterObject->GetParameterMap();
if( parameterMapVector.size() == 0 )
{
itkExceptionMacro( "Empty parameter map in parameter object." );
}
// Elastix must always write result image to guarantee that the ITK pipeline is in a consistent state
parameterMapVector[ parameterMapVector.size() - 1 ][ "WriteResultImage" ] = ParameterValueVectorType( 1, "true" );
// Setup argument map
ArgumentMapType argumentMap;
if( !this->m_InitialTransformParameterFileName.empty() )
{
argumentMap.insert( ArgumentMapEntryType( "-t0", this->m_InitialTransformParameterFileName ) );
}
if( !this->m_FixedPointSetFileName.empty() )
{
argumentMap.insert( ArgumentMapEntryType( "-fp", this->m_FixedPointSetFileName ) );
}
if( !this->m_MovingPointSetFileName.empty() )
{
argumentMap.insert( ArgumentMapEntryType( "-mp", this->m_MovingPointSetFileName ) );
}
// Setup output directory
if( this->GetOutputDirectory().empty() )
{
if( this->GetLogToFile() )
{
itkExceptionMacro( "LogToFileOn() requires an output directory to be specified." )
}
// There must be an "-out" as this is checked later in the code
argumentMap.insert( ArgumentMapEntryType( "-out", "output_path_not_set" ) );
}
else
{
if( !itksys::SystemTools::FileExists( this->GetOutputDirectory() ) )
{
itkExceptionMacro( "Output directory \"" << this->GetOutputDirectory() << "\" does not exist." );
}
if( this->GetOutputDirectory()[ this->GetOutputDirectory().size() - 1 ] != '/'
&& this->GetOutputDirectory()[ this->GetOutputDirectory().size() - 1 ] != '\\' )
{
this->SetOutputDirectory( this->GetOutputDirectory() + "/" );
}
argumentMap.insert( ArgumentMapEntryType( "-out", this->GetOutputDirectory() ) );
}
// Setup log file
std::string logFileName;
if( this->GetLogToFile() )
{
if( this->GetLogFileName().empty() )
{
logFileName = this->GetOutputDirectory() + "elastix.log";
}
else
{
logFileName = this->GetOutputDirectory() + this->GetLogFileName();
}
}
// Set Number of threads
if( this->m_NumberOfThreads > 0 )
{
argumentMap.insert( ArgumentMapEntryType( "-threads", std::to_string( this->m_NumberOfThreads ) ) );
}
// Setup xout
if( elastix::xoutSetup( logFileName.c_str(), this->GetLogToFile(), this->GetLogToConsole() ) )
{
itkExceptionMacro( "Error while setting up xout" );
}
// Run the (possibly multiple) registration(s)
for( unsigned int i = 0; i < parameterMapVector.size(); ++i )
{
// Set image dimension from input images (overrides user settings)
parameterMapVector[ i ][ "FixedImageDimension" ]
= ParameterValueVectorType( 1, std::to_string( fixedImageDimension ) ) ;
parameterMapVector[ i ][ "MovingImageDimension" ]
= ParameterValueVectorType( 1, std::to_string( movingImageDimension ) );
parameterMapVector[ i ][ "ResultImagePixelType" ]
= ParameterValueVectorType( 1, elastix::PixelType< typename TFixedImage::PixelType >::ToString() );
// Initial transform parameter files are handled via arguments and enclosing loop, not InitialTransformParametersFileName
if( parameterMapVector[ i ].find( "InitialTransformParametersFileName" ) != parameterMapVector[ i ].end() )
{
parameterMapVector[ i ][ "InitialTransformParametersFileName" ] = ParameterValueVectorType( 1, "NoInitialTransform" );
}
// Create new instance of ElastixMain
ElastixMainPointer elastix = ElastixMainType::New();
// Set elastix levels
elastix->SetElastixLevel( i );
elastix->SetTotalNumberOfElastixLevels( parameterMapVector.size() );
// Set stuff we get from a previous registration
elastix->SetInitialTransform( transform );
elastix->SetFixedImageContainer( fixedImageContainer );
elastix->SetMovingImageContainer( movingImageContainer );
elastix->SetFixedMaskContainer( fixedMaskContainer );
elastix->SetMovingMaskContainer( movingMaskContainer );
elastix->SetResultImageContainer( resultImageContainer );
elastix->SetOriginalFixedImageDirectionFlat( fixedImageOriginalDirection );
// Start registration
unsigned int isError = 0;
try
{
isError = elastix->Run( argumentMap, parameterMapVector[ i ] );
}
catch( itk::ExceptionObject & e )
{
itkExceptionMacro( << "Errors occurred during registration: " << e.what() );
}
if( isError != 0 )
{
itkExceptionMacro( << "Internal elastix error: See elastix log (use LogToConsoleOn() or LogToFileOn())." );
}
// Get stuff in order to put it in the next registration
transform = elastix->GetFinalTransform();
fixedImageContainer = elastix->GetFixedImageContainer();
movingImageContainer = elastix->GetMovingImageContainer();
fixedMaskContainer = elastix->GetFixedMaskContainer();
movingMaskContainer = elastix->GetMovingMaskContainer();
resultImageContainer = elastix->GetResultImageContainer();
fixedImageOriginalDirection = elastix->GetOriginalFixedImageDirectionFlat();
transformParameterMapVector.push_back( elastix->GetTransformParametersMap() );
if( i > 0 )
{
transformParameterMapVector[ i ][ "InitialTransformParametersFileName" ]
= ParameterValueVectorType( 1, std::to_string( i - 1 ) );
}
// TODO: Fix elastix corrupting default pixel value parameter
transformParameterMapVector[ transformParameterMapVector.size() - 1 ][ "DefaultPixelValue" ]
= parameterMapVector[ i ][ "DefaultPixelValue" ];
} // End loop over registrations
// Save result image
if( resultImageContainer.IsNotNull() && resultImageContainer->Size() > 0 && resultImageContainer->ElementAt( 0 ).IsNotNull() )
{
this->GraftOutput( "ResultImage", resultImageContainer->ElementAt( 0 ) );
}
else
{
itkExceptionMacro( "Errors occured during registration: Could not read result image." );
}
// Save parameter map
elastix::ParameterObject::Pointer transformParameterObject = elastix::ParameterObject::New();
transformParameterObject->SetParameterMap( transformParameterMapVector );
this->SetOutput( "TransformParameterObject", transformParameterObject );
}
template< typename TFixedImage, typename TMovingImage >
void
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::SetParameterObject( ParameterObjectType * parameterObject )
{
this->ProcessObject::SetInput( "ParameterObject", parameterObject );
}
template< typename TFixedImage, typename TMovingImage >
typename ElastixRegistrationMethod< TFixedImage, TMovingImage >::ParameterObjectType *
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::GetParameterObject()
{
return itkDynamicCastInDebugMode< ParameterObjectType * >( itk::ProcessObject::GetInput( "ParameterObject" ) );
}
template< typename TFixedImage, typename TMovingImage >
const typename ElastixRegistrationMethod< TFixedImage, TMovingImage >::ParameterObjectType *
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::GetParameterObject() const
{
return itkDynamicCastInDebugMode< const ParameterObjectType * >( itk::ProcessObject::GetInput( "ParameterObject" ) );
}
template< typename TFixedImage, typename TMovingImage >
typename ElastixRegistrationMethod< TFixedImage, TMovingImage >::ParameterObjectType *
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::GetTransformParameterObject()
{
if( this->HasOutput( "TransformParameterObject") )
{
return itkDynamicCastInDebugMode< ParameterObjectType * >( itk::ProcessObject::GetOutput( "TransformParameterObject" ) );
}
itkExceptionMacro( "TransformParameterObject has not been generated. Update() ElastixRegistrationMethod before requesting this output.")
}
template< typename TFixedImage, typename TMovingImage >
const typename ElastixRegistrationMethod< TFixedImage, TMovingImage >::ParameterObjectType *
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::GetTransformParameterObject() const
{
if( this->HasOutput( "TransformParameterObject") )
{
return itkDynamicCastInDebugMode< const ParameterObjectType * >( itk::ProcessObject::GetOutput( "TransformParameterObject" ) );
}
itkExceptionMacro( "TransformParameterObject has not been generated. Update() ElastixRegistrationMethod before requesting this output.")
}
template< typename TFixedImage, typename TMovingImage >
void
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::SetFixedImage( TFixedImage * fixedImage )
{
this->RemoveInputsOfType( "FixedImage" );
this->ProcessObject::SetInput( "FixedImage", fixedImage );
}
template< typename TFixedImage, typename TMovingImage >
void
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::AddFixedImage( TFixedImage * fixedImage )
{
if( this->ProcessObject::GetInput( "FixedImage" ) == ITK_NULLPTR )
{
this->SetFixedImage( fixedImage );
}
else
{
this->ProcessObject::SetInput( this->MakeUniqueName( "FixedImage" ), fixedImage );
}
}
template< typename TFixedImage, typename TMovingImage >
const typename ElastixRegistrationMethod< TFixedImage, TMovingImage >::FixedImageType *
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::GetFixedImage() const
{
if( this->GetNumberOfInputsOfType( "FixedImage" ) > 1 )
{
itkExceptionMacro( "Please provide an index when more than one fixed images are available." );
}
return itkDynamicCastInDebugMode< const TFixedImage * >( this->ProcessObject::GetInput( "FixedImage" ) );
}
template< typename TFixedImage, typename TMovingImage >
const typename ElastixRegistrationMethod< TFixedImage, TMovingImage >::FixedImageType *
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::GetFixedImage( const unsigned int index ) const
{
unsigned int n = 0;
NameArrayType inputNames = this->GetInputNames();
for( unsigned int i = 0; i < inputNames.size(); ++i )
{
if( this->IsInputOfType( "FixedImage", inputNames[ i ] ) )
{
if( index == n )
{
return itkDynamicCastInDebugMode< const TFixedImage * >( this->ProcessObject::GetInput( inputNames[ i ] ) );
}
n++;
}
}
itkExceptionMacro( << "Index exceeds the number of fixed images (index: "
<< index << ", "
<< "number of fixed images: " << n << ")" );
}
template< typename TFixedImage, typename TMovingImage >
unsigned int
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::GetNumberOfFixedImages() const
{
return this->GetNumberOfInputsOfType( "FixedImage" );
}
template< typename TFixedImage, typename TMovingImage >
void
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::SetMovingImage( TMovingImage * movingImage )
{
this->RemoveInputsOfType( "MovingImage" );
this->ProcessObject::SetInput( "MovingImage", movingImage );
}
template< typename TFixedImage, typename TMovingImage >
void
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::AddMovingImage( TMovingImage * movingImage )
{
if( this->ProcessObject::GetInput( "MovingImage" ) == ITK_NULLPTR )
{
this->SetMovingImage( movingImage );
}
else
{
this->ProcessObject::SetInput( this->MakeUniqueName( "MovingImage" ), movingImage );
}
}
template< typename TFixedImage, typename TMovingImage >
const typename ElastixRegistrationMethod< TFixedImage, TMovingImage >::MovingImageType *
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::GetMovingImage() const
{
if( this->GetNumberOfInputsOfType( "MovingImage" ) > 1 )
{
itkExceptionMacro( "Please provide an index when more than one fixed images are available." );
}
return itkDynamicCastInDebugMode< const TMovingImage * >( this->ProcessObject::GetInput( "MovingImage" ) );
}
template< typename TFixedImage, typename TMovingImage >
const typename ElastixRegistrationMethod< TFixedImage, TMovingImage >::MovingImageType *
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::GetMovingImage( const unsigned int index ) const
{
unsigned int n = 0;
NameArrayType inputNames = this->GetInputNames();
for( unsigned int i = 0; i < inputNames.size(); ++i )
{
if( this->IsInputOfType( "MovingImage", inputNames[ i ] ) )
{
if( index == n )
{
return itkDynamicCastInDebugMode< const TMovingImage * >( this->ProcessObject::GetInput( inputNames[ i ] ) );
}
n++;
}
}
itkExceptionMacro( << "Index exceeds the number of moving images (index: "
<< index << ", "
<< "number of moving images: " << n << ")" );
}
template< typename TFixedImage, typename TMovingImage >
unsigned int
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::GetNumberOfMovingImages() const
{
return this->GetNumberOfInputsOfType( "MovingImage" );
}
template< typename TFixedImage, typename TMovingImage >
void
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::SetFixedMask( FixedMaskType * fixedMask )
{
this->RemoveInputsOfType( "FixedMask" );
this->ProcessObject::SetInput( "FixedMask", fixedMask );
}
template< typename TFixedImage, typename TMovingImage >
void
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::AddFixedMask( FixedMaskType * fixedMask )
{
this->ProcessObject::SetInput( this->MakeUniqueName( "FixedMask" ), fixedMask );
}
template< typename TFixedImage, typename TMovingImage >
const typename ElastixRegistrationMethod< TFixedImage, TMovingImage >::FixedMaskType *
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::GetFixedMask() const
{
return itkDynamicCastInDebugMode< const FixedMaskType * >( this->ProcessObject::GetInput( "FixedMask" ) );
}
template< typename TFixedImage, typename TMovingImage >
const typename ElastixRegistrationMethod< TFixedImage, TMovingImage >::FixedMaskType *
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::GetFixedMask( const unsigned int index ) const
{
unsigned int n = 0;
NameArrayType inputNames = this->GetInputNames();
for( unsigned int i = 0; i < inputNames.size(); ++i )
{
if( this->IsInputOfType( "FixedMask", inputNames[ i ] ) )
{
if( index == n )
{
return itkDynamicCastInDebugMode< const FixedMaskType * >( this->ProcessObject::GetInput( inputNames[ i ] ) );
}
n++;
}
}
itkExceptionMacro( << "Index exceeds the number of fixed masks (index: "
<< index << ", "
<< "number of fixed masks: " << n << ")" );
}
template< typename TFixedImage, typename TMovingImage >
void
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::RemoveFixedMask()
{
this->RemoveInputsOfType( "FixedMask" );
}
template< typename TFixedImage, typename TMovingImage >
unsigned int
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::GetNumberOfFixedMasks() const
{
return this->GetNumberOfInputsOfType( "FixedMask" );
}
template< typename TFixedImage, typename TMovingImage >
void
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::SetMovingMask( MovingMaskType * movingMask )
{
this->RemoveInputsOfType( "MovingMask" );
this->AddMovingMask( movingMask );
}
template< typename TFixedImage, typename TMovingImage >
void
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::AddMovingMask( MovingMaskType * movingMask )
{
this->ProcessObject::SetInput( this->MakeUniqueName( "MovingMask" ), movingMask );
}
template< typename TFixedImage, typename TMovingImage >
const typename ElastixRegistrationMethod< TFixedImage, TMovingImage >::MovingMaskType *
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::GetMovingMask() const
{
return itkDynamicCastInDebugMode< const MovingMaskType * >( this->ProcessObject::GetInput( "MovingMask" ) );
}
template< typename TFixedImage, typename TMovingImage >
const typename ElastixRegistrationMethod< TFixedImage, TMovingImage >::MovingMaskType *
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::GetMovingMask( const unsigned int index ) const
{
unsigned int n = 0;
NameArrayType inputNames = this->GetInputNames();
for( unsigned int i = 0; i < inputNames.size(); ++i )
{
if( this->IsInputOfType( "MovingMask", inputNames[ i ] ) )
{
if( index == n )
{
return itkDynamicCastInDebugMode< const MovingMaskType * >( this->ProcessObject::GetInput( inputNames[ i ] ) );
}
n++;
}
}
itkExceptionMacro( << "Index exceeds the number of moving masks (index: "
<< index << ", "
<< "number of moving masks: " << n << ")" );
}
template< typename TFixedImage, typename TMovingImage >
void
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::RemoveMovingMask()
{
this->RemoveInputsOfType( "MovingMask" );
}
template< typename TFixedImage, typename TMovingImage >
unsigned int
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::GetNumberOfMovingMasks() const
{
return this->GetNumberOfInputsOfType( "MovingMask" );
}
template< typename TFixedImage, typename TMovingImage >
void
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::SetInput(FixedImageType * fixedImage)
{
this->SetFixedImage(fixedImage);
}
template< typename TFixedImage, typename TMovingImage >
const typename ElastixRegistrationMethod< TFixedImage, TMovingImage >::FixedImageType *
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::GetInput() const
{
return this->GetFixedImage();
}
template< typename TFixedImage, typename TMovingImage >
const DataObject *
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::GetInput(DataObjectPointerArraySizeType index) const
{
switch(index)
{
case 0:
return this->GetFixedImage();
case 1:
return this->GetMovingImage();
case 2:
return this->GetParameterObject();
default:
return this->ProcessObject::GetInput(index);
}
}
template< typename TFixedImage, typename TMovingImage >
void
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::SetInput(DataObjectPointerArraySizeType index, DataObject * input)
{
switch(index)
{
case 0:
this->SetFixedImage( itkDynamicCastInDebugMode< TFixedImage * >( input ) );
break;
case 1:
this->SetMovingImage( itkDynamicCastInDebugMode< TMovingImage * >( input ) );
break;
case 2:
this->SetParameterObject( itkDynamicCastInDebugMode< ParameterObjectType * >( input ) );
break;
default:
this->ProcessObject::SetNthInput( index, input );
}
}
template< typename TFixedImage, typename TMovingImage >
void
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::SetLogFileName( const std::string logFileName )
{
this->m_LogFileName = logFileName;
this->LogToFileOn();
}
template< typename TFixedImage, typename TMovingImage >
void
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::RemoveLogFileName()
{
this->m_LogFileName = "";
this->LogToFileOff();
}
template< typename TFixedImage, typename TMovingImage >
std::string
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::MakeUniqueName( const DataObjectIdentifierType & inputName )
{
return inputName + std::to_string( this->m_InputUID++ );
}
template< typename TFixedImage, typename TMovingImage >
bool
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::IsInputOfType( const DataObjectIdentifierType & inputType, DataObjectIdentifierType inputName ) const
{
return std::strncmp( inputType.c_str(), inputName.c_str(), std::min( inputType.size(), inputName.size() ) ) == 0;
}
template< typename TFixedImage, typename TMovingImage >
unsigned int
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::GetNumberOfInputsOfType( const DataObjectIdentifierType & inputType ) const
{
unsigned int n = 0;
NameArrayType inputNames = this->GetInputNames();
for( unsigned int i = 0; i < inputNames.size(); ++i )
{
if( this->IsInputOfType( inputType, inputNames[ i ] ) )
{
n++;
}
}
return n;
}
template< typename TFixedImage, typename TMovingImage >
void
ElastixRegistrationMethod< TFixedImage, TMovingImage >
::RemoveInputsOfType( const DataObjectIdentifierType & inputType )
{
NameArrayType inputNames = this->GetInputNames();
for( unsigned int i = 0; i < inputNames.size(); ++i )
{
if( this->IsInputOfType( inputType, inputNames[ i ] ) )
{
this->RemoveInput( inputNames[ i ] );
}
}
}
} // namespace itk
#endif