]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/BasicFilters/RGBImageToOtherChannelsFilter.cxx
...
[cpPlugins.git] / lib / cpPlugins / Plugins / BasicFilters / RGBImageToOtherChannelsFilter.cxx
1 #include "RGBImageToOtherChannelsFilter.h"
2 #include <cpPlugins/Interface/Image.h>
3
4 #include <cpExtensions/Algorithms/RGBImageToOtherChannelsFilter.h>
5 #include <cpExtensions/Algorithms/RGBExtractFunction.h>
6 #include <cpExtensions/Algorithms/RGBToHSVFunction.h>
7 #include <cpExtensions/Algorithms/RGBToYPbPrFunction.h>
8
9 // -------------------------------------------------------------------------
10 cpPlugins::BasicFilters::RGBImageToOtherChannelsFilter::
11 RGBImageToOtherChannelsFilter( )
12   : Superclass( )
13 {
14   typedef cpPlugins::Interface::Parameters TParameters;
15
16   this->_AddInput( "Input" );
17   this->_AddOutput< cpPlugins::Interface::Image >( "Output" );
18
19   std::vector< std::string > choices;
20   choices.push_back( "HSV" );
21   choices.push_back( "YPbPr" );
22   this->m_Parameters->ConfigureAsChoices( "OutChannel", choices );
23 }
24
25 // -------------------------------------------------------------------------
26 cpPlugins::BasicFilters::RGBImageToOtherChannelsFilter::
27 ~RGBImageToOtherChannelsFilter( )
28 {
29 }
30
31 // -------------------------------------------------------------------------
32 std::string cpPlugins::BasicFilters::RGBImageToOtherChannelsFilter::
33 _GenerateData( )
34 {
35   auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input" );
36   if( image == NULL )
37     return( "RGBImageToOtherChannelsFilter: No input image." );
38
39   itk::DataObject* itk_image = NULL;
40   std::string r = "";
41   cpPlugins_Image_Demangle_AllRGBTypes( 2, image, itk_image, r, _GD0 );
42   else cpPlugins_Image_Demangle_AllRGBTypes( 3, image, itk_image, r, _GD0 );
43   else cpPlugins_Image_Demangle_AllRGBTypes( 4, image, itk_image, r, _GD0 );
44   else r = "RGBImageToOtherChannelsFilter: Input image type not supported.";
45   return( r );
46 }
47
48 // -------------------------------------------------------------------------
49 template< class I >
50 std::string cpPlugins::BasicFilters::RGBImageToOtherChannelsFilter::
51 _GD0( itk::DataObject* image )
52 {
53   typedef typename I::PixelType _P;
54
55   std::string outc = this->m_Parameters->GetSelectedChoice( "OutChannel" );
56   std::string r = "";
57
58   using namespace cpExtensions::Algorithms;
59   if( outc == "HSV" )
60     r = this->_RealGD< I, RGBToHSVFunction< _P > >( image );
61   else if( outc == "YPbPr" )
62     r = this->_RealGD< I, RGBToYPbPrFunction< _P > >( image );
63   else if( outc == "Copy" )
64     r = this->_RealGD< I, RGBExtractFunction< _P > >( image );
65   else
66     r =
67       std::string( "RGBImageToOtherChannelsFilter: Conversor not available: " ) +
68       outc;
69   return( r );
70 }
71
72 // -------------------------------------------------------------------------
73 template< class I, class C >
74 std::string cpPlugins::BasicFilters::RGBImageToOtherChannelsFilter::
75 _RealGD( itk::DataObject* image )
76 {
77   typedef itk::Image< itk::RGBPixel< double >, I::ImageDimension > _O;
78   typedef
79     cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, _O, C >
80     _F;
81
82   // Configure filter
83   _F* filter = this->_CreateITK< _F >( );
84   filter->SetInput( dynamic_cast< I* >( image ) );
85   filter->Update( );
86
87   // Connect output
88   auto out = this->GetOutputData< cpPlugins::Interface::Image >( "Output" );
89   if( out != NULL )
90   {
91     out->SetITK< _O >( filter->GetOutput( ) );
92     return( "" );
93   }
94   else
95     return( "RGBImageToOtherChannelsFilter: output not correctly created." );
96
97   return( "" );
98 }
99
100 // eof - $RCSfile$