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: 2005/08/12 16:16:03 $
00007   Version:   $Revision: 1.36 $
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);
00061 
00063   typedef FixedArray<TComponent, 3> BaseArray;
00064   
00066   typedef TComponent ComponentType;
00067   typedef typename Superclass::ValueType ValueType;
00068   
00070   RGBPixel() {};
00072   RGBPixel (const ComponentType& r) { this->Fill(r); }
00073   
00075   template< class TRGBPixelValueType >
00076   RGBPixel(const RGBPixel< TRGBPixelValueType >& r): BaseArray(r) {}
00077   RGBPixel(const ComponentType  r[3]): BaseArray(r) {}  
00078     
00080   template< class TRGBPixelValueType >
00081   Self& operator= (const RGBPixel< TRGBPixelValueType > & r)
00082     {
00083     BaseArray::operator=(r);
00084     return *this;
00085     }
00086  
00087   Self& operator= (const ComponentType r[3]);
00088 
00090   Self operator+(const Self &vec) const;
00091   Self operator-(const Self &vec) const;
00092   const Self & operator+=(const Self &vec);
00093   const Self & operator-=(const Self &vec);
00094   Self operator*(const ComponentType &f) const;
00095 
00096  
00098   static unsigned int GetNumberOfComponents(){ return 3;}
00099 
00101   ComponentType GetNthComponent(int c) const
00102     { return this->operator[](c); }
00103 
00105   ComponentType GetScalarValue() const
00106     {
00107       return static_cast<ComponentType> (vcl_sqrt(
00108         static_cast<double>(this->operator[](0)) * static_cast<double>(this->operator[](0)) +
00109         static_cast<double>(this->operator[](1)) * static_cast<double>(this->operator[](1)) +
00110         static_cast<double>(this->operator[](2)) * static_cast<double>(this->operator[](2)))); 
00111     }
00112 
00114   void SetNthComponent(int c, const ComponentType& v)  
00115     {  this->operator[](c) = v; }
00116 
00118   void SetRed( ComponentType red ) { this->operator[](0) = red;}
00119 
00121   void SetGreen( ComponentType green ) {this->operator[](1) = green;}
00122 
00124   void SetBlue( ComponentType blue ) {this->operator[](2) = blue;}
00125 
00127   void Set( ComponentType red, ComponentType green, ComponentType blue )
00128     { this->operator[](0) = red; this->operator[](1) = green; this->operator[](2) = blue;}
00129 
00131   const ComponentType & GetRed( void ) const { return this->operator[](0);}
00132 
00134   const ComponentType & GetGreen( void ) const { return this->operator[](1);}
00135 
00137   const ComponentType & GetBlue( void ) const { return this->operator[](2);}
00138 
00140   ComponentType GetLuminance( void ) const;
00141 };
00142 
00143 
00144 template< typename TComponent  >  
00145 ITK_EXPORT std::ostream& operator<<(std::ostream& os, 
00146                                     const RGBPixel<TComponent> & c); 
00147 template< typename TComponent  >  
00148 ITK_EXPORT std::istream& operator>>(std::istream& is, 
00149                                           RGBPixel<TComponent> & c); 
00150 
00151 } // end namespace itk
00152 
00153 #ifndef ITK_MANUAL_INSTANTIATION
00154 #include "itkRGBPixel.txx"
00155 #endif
00156 
00157 #endif

Generated at Wed May 24 23:58:42 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000