]> Creatis software - cpPlugins.git/blob - plugins/ImageArithmeticFilters/PowImageFilter.cxx
62c2a8561168f12fb0faf83640aa222fe379d39d
[cpPlugins.git] / plugins / ImageArithmeticFilters / PowImageFilter.cxx
1 #include <ImageArithmeticFilters/PowImageFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/Image_Demanglers.h>
4
5 #include <itkPowImageFilter.h>
6
7 // -------------------------------------------------------------------------
8 cpPluginsImageArithmeticFilters::PowImageFilter::
9 PowImageFilter( )
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   this->m_Parameters.ConfigureAsReal( "Constant" );
18   this->m_Parameters.SetReal( "Constant", 1 );
19 }
20
21 // -------------------------------------------------------------------------
22 cpPluginsImageArithmeticFilters::PowImageFilter::
23 ~PowImageFilter( )
24 {
25 }
26
27 // -------------------------------------------------------------------------
28 void cpPluginsImageArithmeticFilters::PowImageFilter::
29 _GenerateData( )
30 {
31   auto o = this->GetInputData( "Input1" );
32   cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
33     this->_Error( "Invalid input image (0)." );
34 }
35
36 // -------------------------------------------------------------------------
37 template< class _TInput1 >
38 void cpPluginsImageArithmeticFilters::PowImageFilter::
39 _GD0( _TInput1* input1 )
40 {
41   auto input2 = this->GetInputData< _TInput1 >( "Input2" );
42   if( input2 == NULL )
43     this->_Error( "Incompatible second input image." );
44   this->_GD1( input2, input1 );
45 }
46
47 // -------------------------------------------------------------------------
48 template< class _TInput2, class _TInput1 >
49 void cpPluginsImageArithmeticFilters::PowImageFilter::
50 _GD1( _TInput2* input2, _TInput1* input1 )
51 {
52   typedef itk::PowImageFilter< _TInput1, _TInput2, _TInput1 > _TFilter;
53
54   // Configure filter
55   auto filter = this->_CreateITK< _TFilter >( );
56   filter->SetInput1( input1 );
57   filter->SetInput2( input2 );
58   filter->Update( );
59
60   // Connect output
61   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
62 }
63
64 // eof - $RCSfile$
65
66 /* TODO
67    filter->SetInput1( image0 );
68    auto image1 = this->GetInputData< _TImage >( "Input1" );
69    if( image1 == NULL )
70    filter->SetConstant( this->m_Parameters.GetReal( "Constant" ) );
71    else
72    filter->SetInput2( image1 );
73    filter->Update( );
74
75    // Connect output
76    this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
77 */
78
79 // eof - $RCSfile$