]> Creatis software - cpPlugins.git/blob - plugins/ImageArithmeticFilters/SubtractImageFilter.cxx
...
[cpPlugins.git] / plugins / ImageArithmeticFilters / SubtractImageFilter.cxx
1 #include <ImageArithmeticFilters/SubtractImageFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/Image_Demanglers.h>
4
5 #include <itkSubtractImageFilter.h>
6
7 // -------------------------------------------------------------------------
8 cpPluginsImageArithmeticFilters::SubtractImageFilter::
9 SubtractImageFilter( )
10   : Superclass( )
11 {
12   typedef cpPlugins::DataObjects::Image _TImage;
13   this->_ConfigureInput< _TImage >( "Input1", true, false );
14   this->_ConfigureInput< _TImage >( "Input2", true, false );
15   this->_ConfigureOutput< _TImage >( "Output" );
16 }
17
18 // -------------------------------------------------------------------------
19 cpPluginsImageArithmeticFilters::SubtractImageFilter::
20 ~SubtractImageFilter( )
21 {
22 }
23
24 // -------------------------------------------------------------------------
25 void cpPluginsImageArithmeticFilters::SubtractImageFilter::
26 _GenerateData( )
27 {
28   auto o = this->GetInputData( "Input1" );
29   cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
30     this->_Error( "Invalid input image (0)." );
31 }
32
33 // -------------------------------------------------------------------------
34 template< class _TInput1 >
35 void cpPluginsImageArithmeticFilters::SubtractImageFilter::
36 _GD0( _TInput1* input1 )
37 {
38   auto input2 = this->GetInputData< _TInput1 >( "Input2" );
39   if( input2 == NULL )
40     this->_Error( "Incompatible second input image." );
41   this->_GD1( input2, input1 );
42 }
43
44 // -------------------------------------------------------------------------
45 template< class _TInput2, class _TInput1 >
46 void cpPluginsImageArithmeticFilters::SubtractImageFilter::
47 _GD1( _TInput2* input2, _TInput1* input1 )
48 {
49   typedef itk::SubtractImageFilter< _TInput1, _TInput2, _TInput1 > _TFilter;
50
51   // Configure filter
52   auto filter = this->_CreateITK< _TFilter >( );
53   filter->SetInput1( input1 );
54   filter->SetInput2( input2 );
55   filter->Update( );
56
57   // Connect output
58   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
59 }
60
61 // eof - $RCSfile$