]> Creatis software - cpPlugins.git/blob - plugins/ITKBinaryFunctorFilters/BinaryBooleanImageFilter.cxx
yet another refactoring
[cpPlugins.git] / plugins / ITKBinaryFunctorFilters / BinaryBooleanImageFilter.cxx
1 #include <ITKBinaryFunctorFilters/BinaryBooleanImageFilter.h>
2 #include <cpInstances/DataObjects/Image.h>
3
4 #include <itkAndImageFilter.h>
5 #include <itkOrImageFilter.h>
6 #include <itkXorImageFilter.h>
7
8 // -------------------------------------------------------------------------
9 cpPluginsITKBinaryFunctorFilters::BinaryBooleanImageFilter::
10 BinaryBooleanImageFilter( )
11   : Superclass( )
12 {
13   typedef cpInstances::DataObjects::Image _TImage;
14
15   this->_ConfigureInput< _TImage >( "Input1", true, false );
16   this->_ConfigureInput< _TImage >( "Input2", true, false );
17   this->_ConfigureOutput< _TImage >( "Output" );
18
19   std::vector< std::string > choices;
20   choices.push_back( "And" );
21   choices.push_back( "Or" );
22   choices.push_back( "Xor" );
23   this->m_Parameters.ConfigureAsChoices( "Operator", choices );
24 }
25
26 // -------------------------------------------------------------------------
27 cpPluginsITKBinaryFunctorFilters::BinaryBooleanImageFilter::
28 ~BinaryBooleanImageFilter( )
29 {
30 }
31
32 // -------------------------------------------------------------------------
33 void cpPluginsITKBinaryFunctorFilters::BinaryBooleanImageFilter::
34 _GenerateData( )
35 {
36   auto o = this->GetInputData( "Input1" );
37   cpPlugins_Demangle_Image_IntPixels_AllDims_1( o, _GD0 )
38     this->_Error( "Invalid input image." );
39 }
40
41 // -------------------------------------------------------------------------
42 template< class _TImage >
43 void cpPluginsITKBinaryFunctorFilters::BinaryBooleanImageFilter::
44 _GD0( _TImage* image1 )
45 {
46   typedef itk::AndImageFilter< _TImage, _TImage > _TAnd;
47   typedef itk::OrImageFilter< _TImage, _TImage > _TOr;
48   typedef itk::XorImageFilter< _TImage, _TImage > _TXor;
49
50   auto image2 = this->GetInputData< _TImage >( "Input2" );
51   if( image2 == NULL )
52     this->_Error( "Incompatible second input image." );
53   std::string op = this->m_Parameters.GetSelectedChoice( "Operator" );
54   if     ( op == "And" ) this->_GD1< _TAnd, _TImage >( image1, image2 );
55   else if( op == "Or" ) this->_GD1< _TOr, _TImage >( image1, image2 );
56   else if( op == "Xor" ) this->_GD1< _TXor, _TImage >( image1, image2 );
57 }
58
59 // -------------------------------------------------------------------------
60 template< class _TFilter, class _TImage >
61 void cpPluginsITKBinaryFunctorFilters::BinaryBooleanImageFilter::
62 _GD1( _TImage* image1, _TImage* image2 )
63 {
64   // Configure filter
65   auto filter = this->_CreateITK< _TFilter >( );
66   filter->SetInput1( image1 );
67   filter->SetInput2( image2 );
68   filter->Update( );
69
70   // Connect output
71   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
72 }
73
74 // eof - $RCSfile$