]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Algorithms/RGBExtractFunction.h
Code cleaning
[cpPlugins.git] / lib / cpExtensions / Algorithms / RGBExtractFunction.h
diff --git a/lib/cpExtensions/Algorithms/RGBExtractFunction.h b/lib/cpExtensions/Algorithms/RGBExtractFunction.h
new file mode 100644 (file)
index 0000000..ec7126b
--- /dev/null
@@ -0,0 +1,54 @@
+// -------------------------------------------------------------------------
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// -------------------------------------------------------------------------
+
+#ifndef __CPEXTENSIONS__ALGORITHMS__RGBEXTRACTFUNCTION__H__
+#define __CPEXTENSIONS__ALGORITHMS__RGBEXTRACTFUNCTION__H__
+
+#include <cmath>
+#include <limits>
+#include <vnl/vnl_math.h>
+
+#include <itkRGBPixel.h>
+
+namespace cpExtensions
+{
+  namespace Algorithms
+  {
+    /**
+     */
+    template< class P >
+    struct RGBExtractFunction
+    {
+      typedef RGBExtractFunction    Self;
+      typedef P                     TOutPixel;
+      typedef typename P::ValueType TValue;
+
+      template< class Tr, class Tg, class Tb >
+      P operator()( const Tr& r, const Tg& g, const Tb& b ) const
+        {
+          P out;
+          out[ 0 ] = TValue( r );
+          out[ 1 ] = TValue( g );
+          out[ 2 ] = TValue( b );
+          return( out );
+        }
+
+      template< class C >
+      TOutPixel operator()( const itk::RGBPixel< C >& rgb ) const
+        {
+          return(
+            this->operator()(
+              rgb.GetRed( ), rgb.GetGreen( ), rgb.GetBlue( )
+              )
+            );
+        }
+    };
+
+  } // ecapseman
+
+} // ecapseman
+
+#endif // __CPEXTENSIONS__ALGORITHMS__RGBEXTRACTFUNCTION__H__
+
+// eof - $RCSfile$