]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/BasicFilters/RGBImageToOtherChannelsFilter.cxx
Widget integration (step 6/6): Interactive architecture finished. Needs to be tested...
[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->_MakeOutput< 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   cpPlugins::Interface::Image* image =
36     this->GetInput< cpPlugins::Interface::Image >( "Input" );
37   if( image == NULL )
38     return( "RGBImageToOtherChannelsFilter: No input image." );
39
40   itk::DataObject* itk_image = NULL;
41   std::string r = "";
42   cpPlugins_Image_Demangle_AllRGBTypes( 2, image, itk_image, r, _GD0 );
43   else cpPlugins_Image_Demangle_AllRGBTypes( 3, image, itk_image, r, _GD0 );
44   else cpPlugins_Image_Demangle_AllRGBTypes( 4, image, itk_image, r, _GD0 );
45   else r = "RGBImageToOtherChannelsFilter: Input image type not supported.";
46   return( r );
47 }
48
49 // -------------------------------------------------------------------------
50 template< class I >
51 std::string cpPlugins::BasicFilters::RGBImageToOtherChannelsFilter::
52 _GD0( itk::DataObject* image )
53 {
54   typedef typename I::PixelType _P;
55
56   std::string outc = this->m_Parameters->GetSelectedChoice( "OutChannel" );
57   std::string r = "";
58
59   using namespace cpExtensions::Algorithms;
60   if( outc == "HSV" )
61     r = this->_RealGD< I, RGBToHSVFunction< _P > >( image );
62   else if( outc == "YPbPr" )
63     r = this->_RealGD< I, RGBToYPbPrFunction< _P > >( image );
64   else if( outc == "Copy" )
65     r = this->_RealGD< I, RGBExtractFunction< _P > >( image );
66   else
67     r =
68       std::string( "RGBImageToOtherChannelsFilter: Conversor not available: " ) +
69       outc;
70   return( r );
71 }
72
73 // -------------------------------------------------------------------------
74 template< class I, class C >
75 std::string cpPlugins::BasicFilters::RGBImageToOtherChannelsFilter::
76 _RealGD( itk::DataObject* image )
77 {
78   typedef itk::Image< itk::RGBPixel< double >, I::ImageDimension > _O;
79   typedef
80     cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, _O, C >
81     _F;
82
83   // Configure filter
84   _F* filter = this->_CreateITK< _F >( );
85   filter->SetInput( dynamic_cast< I* >( image ) );
86   filter->Update( );
87
88   // Connect output
89   cpPlugins::Interface::Image* out =
90     this->GetOutput< cpPlugins::Interface::Image >( "Output" );
91   if( out != NULL )
92   {
93     out->SetITK< _O >( filter->GetOutput( ) );
94     return( "" );
95   }
96   else
97     return( "RGBImageToOtherChannelsFilter: output not correctly created." );
98
99   return( "" );
100 }
101
102 // eof - $RCSfile$