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() {};
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 }
00152
00153 #ifndef ITK_MANUAL_INSTANTIATION
00154 #include "itkRGBPixel.txx"
00155 #endif
00156
00157 #endif