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