Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkRGBPixel.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkRGBPixel.h,v $
00005   Language:  C++
00006   Date:      $Date: 2006/12/04 18:30:32 $
00007   Version:   $Revision: 1.39 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkRGBPixel_h
00018 #define __itkRGBPixel_h
00019 
00020 // Undefine an eventual RGBPixel macro
00021 #ifdef RGBPixel
00022 #undef RGBPixel
00023 #endif
00024 
00025 #include <itkIndent.h>
00026 #include <itkFixedArray.h>
00027 #include "vnl/vnl_math.h"
00028 
00029 namespace itk
00030 {
00031 
00050 template < typename TComponent = unsigned short >
00051 class RGBPixel: public FixedArray<TComponent,3>
00052 {
00053 public:
00055   typedef RGBPixel  Self;
00056   typedef FixedArray<TComponent, 3> Superclass;
00057 
00059   itkStaticConstMacro(Dimension, unsigned int, 3);
00060   itkStaticConstMacro(Length, unsigned int, 3);
00062 
00064   typedef FixedArray<TComponent, 3> BaseArray;
00065 
00067   typedef TComponent ComponentType;
00068   typedef typename Superclass::ValueType ValueType;
00069 
00071   RGBPixel() {};
00072 
00074   RGBPixel (const ComponentType& r) { this->Fill(r); }
00075 
00077   template< class TRGBPixelValueType >
00078   RGBPixel(const RGBPixel< TRGBPixelValueType >& r): BaseArray(r) {}
00079   RGBPixel(const ComponentType  r[3]): BaseArray(r) {}  
00081 
00083   template< class TRGBPixelValueType >
00084   Self& operator= (const RGBPixel< TRGBPixelValueType > & r)
00085     {
00086     BaseArray::operator=(r);
00087     return *this;
00088     }
00090 
00091   Self& operator= (const ComponentType r[3]);
00092 
00094   Self operator+(const Self &vec) const;
00095   Self operator-(const Self &vec) const;
00096   const Self & operator+=(const Self &vec);
00097   const Self & operator-=(const Self &vec);
00098   Self operator*(const ComponentType &f) const;
00100 
00101  
00103   static unsigned int GetNumberOfComponents(){ return 3;}
00104 
00106   ComponentType GetNthComponent(int c) const
00107     { return this->operator[](c); }
00108 
00110   ComponentType GetScalarValue() const
00111     {
00112       return static_cast<ComponentType> (vcl_sqrt(
00113         static_cast<double>(this->operator[](0)) * static_cast<double>(this->operator[](0)) +
00114         static_cast<double>(this->operator[](1)) * static_cast<double>(this->operator[](1)) +
00115         static_cast<double>(this->operator[](2)) * static_cast<double>(this->operator[](2)))); 
00116     }
00117 
00119   void SetNthComponent(int c, const ComponentType& v)  
00120     {  this->operator[](c) = v; }
00121 
00123   void SetRed( ComponentType red ) { this->operator[](0) = red;}
00124 
00126   void SetGreen( ComponentType green ) {this->operator[](1) = green;}
00127 
00129   void SetBlue( ComponentType blue ) {this->operator[](2) = blue;}
00130 
00132   void Set( ComponentType red, ComponentType green, ComponentType blue )
00133     { this->operator[](0) = red; this->operator[](1) = green; this->operator[](2) = blue;}
00134 
00136   const ComponentType & GetRed( void ) const { return this->operator[](0);}
00137 
00139   const ComponentType & GetGreen( void ) const { return this->operator[](1);}
00140 
00142   const ComponentType & GetBlue( void ) const { return this->operator[](2);}
00143 
00145   ComponentType GetLuminance( void ) const;
00146 };
00147 
00148 
00149 template< typename TComponent  >  
00150 ITK_EXPORT std::ostream& operator<<(std::ostream& os, 
00151                                     const RGBPixel<TComponent> & c); 
00152 template< typename TComponent  >  
00153 ITK_EXPORT std::istream& operator>>(std::istream& is, 
00154                                           RGBPixel<TComponent> & c); 
00155 
00156 } // end namespace itk
00157 
00158 // Define instantiation macro for this template.
00159 #define ITK_TEMPLATE_RGBPixel(_, EXPORT, x, y) namespace itk { \
00160   _(1(class EXPORT RGBPixel< ITK_TEMPLATE_1 x >)) \
00161   namespace Templates { typedef RGBPixel< ITK_TEMPLATE_1 x > RGBPixel##y; } \
00162   }
00163 
00164 #if ITK_TEMPLATE_EXPLICIT
00165 # include "Templates/itkRGBPixel+-.h"
00166 #endif
00167 
00168 #if ITK_TEMPLATE_TXX
00169 # include "itkRGBPixel.txx"
00170 #endif
00171 
00172 #ifndef ITKCommon_EXPORTS
00173   #include "itkNumericTraitsRGBPixel.h"
00174 #endif
00175 
00176 #endif
00177 

Generated at Sun Sep 23 14:08:22 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000