]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Algorithms/RGBExtractFunction.h
...
[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
14 namespace cpExtensions
15 {
16   namespace Algorithms
17   {
18     /**
19      */
20     template< class P >
21     struct RGBExtractFunction
22     {
23       typedef RGBExtractFunction    Self;
24       typedef P                     TOutPixel;
25       typedef typename P::ValueType TValue;
26
27       template< class Tr, class Tg, class Tb >
28       P operator()( const Tr& r, const Tg& g, const Tb& b ) const
29         {
30           P out;
31           out[ 0 ] = TValue( r );
32           out[ 1 ] = TValue( g );
33           out[ 2 ] = TValue( b );
34           return( out );
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$