00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkRGBPixel_h
00018 #define __itkRGBPixel_h
00019
00020
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() {this->Fill(0);}
00071 RGBPixel (const ComponentType& r) { this->Fill(r); }
00072
00074 RGBPixel(const Self& r): BaseArray(r) {}
00075 RGBPixel(const ComponentType r[3]): BaseArray(r) {}
00076
00078 Self& operator= (const Self& r);
00079 Self& operator= (const ComponentType r[3]);
00080
00082 Self operator+(const Self &vec) const;
00083 Self operator-(const Self &vec) const;
00084 const Self & operator+=(const Self &vec);
00085 const Self & operator-=(const Self &vec);
00086 Self operator*(const ComponentType &f) const;
00087
00088
00090 static int GetNumberOfComponents(){ return 3;}
00091
00093 ComponentType GetNthComponent(int c) const
00094 { return this->operator[](c); }
00095
00097 ComponentType GetScalarValue() const
00098 {
00099 return static_cast<ComponentType> (vcl_sqrt(
00100 static_cast<double>(this->operator[](0)) * static_cast<double>(this->operator[](0)) +
00101 static_cast<double>(this->operator[](1)) * static_cast<double>(this->operator[](1)) +
00102 static_cast<double>(this->operator[](2)) * static_cast<double>(this->operator[](2))));
00103 }
00104
00106 void SetNthComponent(int c, const ComponentType& v)
00107 { this->operator[](c) = v; }
00108
00110 void SetRed( ComponentType red ) { this->operator[](0) = red;}
00111
00113 void SetGreen( ComponentType green ) {this->operator[](1) = green;}
00114
00116 void SetBlue( ComponentType blue ) {this->operator[](2) = blue;}
00117
00119 void Set( ComponentType red, ComponentType green, ComponentType blue )
00120 { this->operator[](0) = red; this->operator[](1) = green; this->operator[](2) = blue;}
00121
00123 const ComponentType & GetRed( void ) const { return this->operator[](0);}
00124
00126 const ComponentType & GetGreen( void ) const { return this->operator[](1);}
00127
00129 const ComponentType & GetBlue( void ) const { return this->operator[](2);}
00130
00132 ComponentType GetLuminance( void ) const;
00133 };
00134
00135
00136 template< typename TComponent >
00137 ITK_EXPORT std::ostream& operator<<(std::ostream& os,
00138 const RGBPixel<TComponent> & c);
00139 template< typename TComponent >
00140 ITK_EXPORT std::istream& operator>>(std::istream& is,
00141 RGBPixel<TComponent> & c);
00142
00143 }
00144
00145 #ifndef ITK_MANUAL_INSTANTIATION
00146 #include "itkRGBPixel.txx"
00147 #endif
00148
00149 #endif