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: 2002/09/11 19:57:13 $
00007   Version:   $Revision: 1.22 $
00008 
00009   Copyright (c) 2002 Insight 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> Super;
00057   
00059   typedef FixedArray<TComponent, 3> BaseArray;
00060   
00062   typedef TComponent ComponentType;
00063 
00065   RGBPixel() {Fill(0);}
00066   RGBPixel (const ComponentType& r);
00067   
00069   RGBPixel(const Self& r): BaseArray(r) {}
00070   RGBPixel(const ComponentType  r[3]): BaseArray(r) {}  
00071     
00073   RGBPixel& operator= (const Self& r);
00074   RGBPixel& operator= (const ComponentType r[3]);
00075   
00077   static int GetNumberOfComponents(){ return 3;}
00078 
00080   ComponentType GetNthComponent(int c) const
00081     { return this->operator[](c); }
00082 
00084   ComponentType GetScalarValue() const
00085     {
00086       return static_cast<ComponentType> (vnl_math_sqrt(
00087         static_cast<double>(this->operator[](0)) * static_cast<double>(this->operator[](0)) +
00088         static_cast<double>(this->operator[](1)) * static_cast<double>(this->operator[](1)) +
00089         static_cast<double>(this->operator[](2)) * static_cast<double>(this->operator[](2)))); 
00090     }
00091 
00093   void SetNthComponent(int c, const ComponentType& v)  
00094     {  this->operator[](c) = v; }
00095 
00097   void SetRed( ComponentType red ) { this->operator[](0) = red;}
00098 
00100   void SetGreen( ComponentType green ) {this->operator[](1) = green;}
00101 
00103   void SetBlue( ComponentType blue ) {this->operator[](2) = blue;}
00104 
00106   void Set( ComponentType red, ComponentType green, ComponentType blue )
00107     { this->operator[](0) = red; this->operator[](1) = green; this->operator[](2) = blue;}
00108 
00110   const ComponentType & GetRed( void ) const { return this->operator[](0);}
00111 
00113   const ComponentType & GetGreen( void ) const { return this->operator[](1);}
00114 
00116   const ComponentType & GetBlue( void ) const { return this->operator[](2);}
00117 };
00118 
00119 
00120 template< typename TComponent  >  
00121 ITK_EXPORT std::ostream& operator<<(std::ostream& os, 
00122                                     const RGBPixel<TComponent> & c); 
00123 template< typename TComponent  >  
00124 ITK_EXPORT std::istream& operator>>(std::istream& is, 
00125                                           RGBPixel<TComponent> & c); 
00126 
00127 } // end namespace itk
00128 
00129 #ifndef ITK_MANUAL_INSTANTIATION
00130 #include "itkRGBPixel.txx"
00131 #endif
00132 
00133 #endif

Generated at Wed Mar 12 01:13:10 2003 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000