]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Algorithms/RGBExtractFunction.h
8db169720ee77e49f5c3826e4a937235c4bef34d
[cpPlugins.git] / lib / cpExtensions / Algorithms / RGBExtractFunction.h
1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
4
5 #ifndef __CPEXTENSIONS__ALGORITHMS__RGBEXTRACTFUNCTION__H__
6 #define __CPEXTENSIONS__ALGORITHMS__RGBEXTRACTFUNCTION__H__
7
8 #include <cmath>
9 #include <limits>
10 #include <vnl/vnl_math.h>
11
12 #include <itkRGBPixel.h>
13 #include <itkVector.h>
14
15 namespace cpExtensions
16   {
17     namespace Algorithms
18     {
19       /**
20        */
21       template< class O >
22       struct RGBExtractFunction
23       {
24         typedef RGBExtractFunction  Self;
25         typedef itk::Vector< O, 3 > TOutPixel;
26
27         template< class Tr, class Tg, class Tb >
28         TOutPixel operator()( const Tr& r, const Tg& g, const Tb& b ) const
29           {
30             TOutPixel rgb;
31             rgb[ 0 ] = O( r );
32             rgb[ 1 ] = O( g );
33             rgb[ 2 ] = O( b );
34             return( rgb );
35           }
36
37         template< class C >
38         TOutPixel operator()( const itk::RGBPixel< C >& rgb ) const
39           {
40             return(
41               this->operator()(
42                 rgb.GetRed( ), rgb.GetGreen( ), rgb.GetBlue( )
43                 )
44               );
45           }
46       };
47
48     } // ecapseman
49
50 } // ecapseman
51
52 #endif // __CPEXTENSIONS__ALGORITHMS__RGBEXTRACTFUNCTION__H__
53
54 // eof - $RCSfile$