1 #include <ITKBinaryFunctorFilters/BinaryBooleanImageFilter.h>
2 #include <cpInstances/DataObjects/Image.h>
4 #include <itkAndImageFilter.h>
5 #include <itkOrImageFilter.h>
6 #include <itkXorImageFilter.h>
8 // -------------------------------------------------------------------------
9 cpPluginsITKBinaryFunctorFilters::BinaryBooleanImageFilter::
10 BinaryBooleanImageFilter( )
13 typedef cpInstances::DataObjects::Image _TImage;
15 this->_ConfigureInput< _TImage >( "Input1", true, false );
16 this->_ConfigureInput< _TImage >( "Input2", true, false );
17 this->_ConfigureOutput< _TImage >( "Output" );
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 );
26 // -------------------------------------------------------------------------
27 cpPluginsITKBinaryFunctorFilters::BinaryBooleanImageFilter::
28 ~BinaryBooleanImageFilter( )
32 // -------------------------------------------------------------------------
33 void cpPluginsITKBinaryFunctorFilters::BinaryBooleanImageFilter::
36 auto o = this->GetInputData( "Input1" );
37 cpPlugins_Demangle_Image_IntPixels_AllDims_1( o, _GD0 )
38 this->_Error( "Invalid input image." );
41 // -------------------------------------------------------------------------
42 template< class _TImage >
43 void cpPluginsITKBinaryFunctorFilters::BinaryBooleanImageFilter::
44 _GD0( _TImage* image1 )
46 typedef itk::AndImageFilter< _TImage, _TImage > _TAnd;
47 typedef itk::OrImageFilter< _TImage, _TImage > _TOr;
48 typedef itk::XorImageFilter< _TImage, _TImage > _TXor;
50 auto image2 = this->GetInputData< _TImage >( "Input2" );
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 );
59 // -------------------------------------------------------------------------
60 template< class _TFilter, class _TImage >
61 void cpPluginsITKBinaryFunctorFilters::BinaryBooleanImageFilter::
62 _GD1( _TImage* image1, _TImage* image2 )
65 auto filter = this->_CreateITK< _TFilter >( );
66 filter->SetInput1( image1 );
67 filter->SetInput2( image2 );
71 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );