00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkRGBAPixel_h
00018 #define __itkRGBAPixel_h
00019
00020
00021 #ifdef RGBAPixel
00022 #undef RGBAPixel
00023 #endif
00024
00025 #include <itkIndent.h>
00026 #include <itkFixedArray.h>
00027 #include "vnl/vnl_math.h"
00028
00029 namespace itk
00030 {
00031
00051 template < typename TComponent = unsigned short >
00052 class RGBAPixel: public FixedArray<TComponent,4>
00053 {
00054 public:
00056 typedef RGBAPixel Self;
00057 typedef FixedArray<TComponent, 4> Super;
00058
00060 itkStaticConstMacro(Dimension, unsigned int, 4);
00061
00063 itkStaticConstMacro(Length, unsigned int, 4);
00064
00066 typedef FixedArray<TComponent, 4> BaseArray;
00067
00069 typedef TComponent ComponentType;
00070
00072 RGBAPixel() {this->Fill(0);}
00073 RGBAPixel (const ComponentType& r)
00074 { this->Fill(r) ;}
00075
00077 RGBAPixel(const Self& r): BaseArray(r) {}
00078 RGBAPixel(const ComponentType r[4]): BaseArray(r) {}
00079
00081 RGBAPixel& operator= (const Self& r);
00082 RGBAPixel& operator= (const ComponentType r[4]);
00083
00085 static unsigned int GetNumberOfComponents(){ return 4;}
00086
00088 ComponentType GetNthComponent(int c) const
00089 { return this->operator[](c); }
00090
00092 ComponentType GetScalarValue() const
00093 {
00094 return static_cast<ComponentType> (vcl_sqrt(
00095 static_cast<double>(this->operator[](0)) * static_cast<double>(this->operator[](0)) +
00096 static_cast<double>(this->operator[](1)) * static_cast<double>(this->operator[](1)) +
00097 static_cast<double>(this->operator[](2)) * static_cast<double>(this->operator[](2))));
00098 }
00099
00101 void SetNthComponent(int c, const ComponentType& v)
00102 { this->operator[](c) = v; }
00103
00105 void SetRed( ComponentType red ) { this->operator[](0) = red;}
00106
00108 void SetGreen( ComponentType green ) {this->operator[](1) = green;}
00109
00111 void SetBlue( ComponentType blue ) {this->operator[](2) = blue;}
00112
00114 void SetAlpha( ComponentType alpha ) {this->operator[](3) = alpha;}
00115
00117 void Set( ComponentType red, ComponentType green, ComponentType blue, ComponentType alpha )
00118 { this->operator[](0) = red; this->operator[](1) = green; this->operator[](2) = blue; this->operator[](3) = alpha;}
00119
00121 const ComponentType & GetRed( void ) const { return this->operator[](0);}
00122
00124 const ComponentType & GetGreen( void ) const { return this->operator[](1);}
00125
00127 const ComponentType & GetBlue( void ) const { return this->operator[](2);}
00128
00130 const ComponentType & GetAlpha( void ) const { return this->operator[](3);}
00131
00133 ComponentType GetLuminance( void ) const;
00134 };
00135
00136
00137 template< typename TComponent >
00138 ITK_EXPORT std::ostream& operator<<(std::ostream& os,
00139 const RGBAPixel<TComponent> & c);
00140
00141 template< typename TComponent >
00142 ITK_EXPORT std::istream& operator>>(std::istream& is,
00143 RGBAPixel<TComponent> & c);
00144
00145 }
00146
00147 #ifndef ITK_MANUAL_INSTANTIATION
00148 #include "itkRGBAPixel.txx"
00149 #endif
00150
00151 #endif