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: 2009-03-12 01:11:16 $
00007   Version:   $Revision: 1.43 $
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   typedef FixedArray<TComponent, 3> BaseArray;
00060 
00062 #if defined(__BORLANDC__)
00063   enum {Dimension = 3};
00064 #else
00065   itkStaticConstMacro(Dimension, unsigned int, 3);
00066 #endif
00067 
00068 
00070 #if defined(__BORLANDC__)
00071   enum {Length = 3};
00072 #else
00073   itkStaticConstMacro(Length, unsigned int, 3);
00074 #endif
00075 
00076 
00078   typedef TComponent                     ComponentType;
00079   typedef typename Superclass::ValueType ValueType;
00080 
00082   RGBPixel() {};
00083 
00085   RGBPixel (const ComponentType& r) { this->Fill(r); }
00086 
00088   template< class TRGBPixelValueType >
00089   RGBPixel(const RGBPixel< TRGBPixelValueType >& r): BaseArray(r) {}
00090   RGBPixel(const ComponentType  r[3]): BaseArray(r) {}  
00092 
00094   template< class TRGBPixelValueType >
00095   Self& operator= (const RGBPixel< TRGBPixelValueType > & r)
00096     {
00097     BaseArray::operator=(r);
00098     return *this;
00099     }
00101 
00102   Self& operator= (const ComponentType r[3]);
00103 
00105   Self operator+(const Self &vec) const;
00106   Self operator-(const Self &vec) const;
00107   const Self & operator+=(const Self &vec);
00108   const Self & operator-=(const Self &vec);
00109   Self operator*(const ComponentType &f) const;
00111 
00112   bool operator<(const Self &vec) const;
00113   bool operator==(const Self &vec) const;
00114  
00116   static unsigned int GetNumberOfComponents(){ return 3;}
00117 
00119   ComponentType GetNthComponent(int c) const
00120     { return this->operator[](c); }
00121 
00123   ComponentType GetScalarValue() const
00124     {
00125     return static_cast<ComponentType> (vcl_sqrt(
00126                                          static_cast<double>(this->operator[](0)) * static_cast<double>(this->operator[](0)) +
00127                                          static_cast<double>(this->operator[](1)) * static_cast<double>(this->operator[](1)) +
00128                                          static_cast<double>(this->operator[](2)) * static_cast<double>(this->operator[](2)))); 
00129     }
00130 
00132   void SetNthComponent(int c, const ComponentType& v)  
00133     {  this->operator[](c) = v; }
00134 
00136   void SetRed( ComponentType red ) { this->operator[](0) = red;}
00137 
00139   void SetGreen( ComponentType green ) {this->operator[](1) = green;}
00140 
00142   void SetBlue( ComponentType blue ) {this->operator[](2) = blue;}
00143 
00145   void Set( ComponentType red, ComponentType green, ComponentType blue )
00146     { this->operator[](0) = red; this->operator[](1) = green; this->operator[](2) = blue;}
00147 
00149   const ComponentType & GetRed( void ) const { return this->operator[](0);}
00150 
00152   const ComponentType & GetGreen( void ) const { return this->operator[](1);}
00153 
00155   const ComponentType & GetBlue( void ) const { return this->operator[](2);}
00156 
00158   ComponentType GetLuminance( void ) const;
00159 };
00160 
00161 
00162 template< typename TComponent  >  
00163 ITK_EXPORT std::ostream& operator<<(std::ostream& os, 
00164                                     const RGBPixel<TComponent> & c); 
00165 template< typename TComponent  >  
00166 ITK_EXPORT std::istream& operator>>(std::istream& is, 
00167                                           RGBPixel<TComponent> & c); 
00168 
00169 } // end namespace itk
00170 
00171 // Define instantiation macro for this template.
00172 #define ITK_TEMPLATE_RGBPixel(_, EXPORT, x, y) namespace itk { \
00173   _(1(class EXPORT RGBPixel< ITK_TEMPLATE_1 x >)) \
00174   namespace Templates { typedef RGBPixel< ITK_TEMPLATE_1 x > RGBPixel##y; } \
00175   }
00176 
00177 #if ITK_TEMPLATE_EXPLICIT
00178 # include "Templates/itkRGBPixel+-.h"
00179 #endif
00180 
00181 //
00182 // Numeric traits must be included after (optionally) including the explicit
00183 // instantiations control of this class, in case the implicit instantiation
00184 // needs to be disabled. 
00185 //
00186 // NumericTraits must be included before (optionally) including the .txx file,
00187 // in case the .txx requires to use NumericTraits.
00188 //
00189 #include "itkNumericTraitsRGBPixel.h"
00190 
00191 #if ITK_TEMPLATE_TXX
00192 # include "itkRGBPixel.txx"
00193 #endif
00194 
00195 #endif
00196 

Generated at Thu May 28 11:25:53 2009 for ITK by doxygen 1.5.5 written by Dimitri van Heesch, © 1997-2000