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> Superclass;
00058
00060 #if defined(__BORLANDC__)
00061 enum {Dimension = 4};
00062 #else
00063 itkStaticConstMacro(Dimension, unsigned int, 4);
00064 #endif
00065
00066
00068 #if defined(__BORLANDC__)
00069 enum {Length = 4};
00070 #else
00071 itkStaticConstMacro(Length, unsigned int, 4);
00072 #endif
00073
00074
00076 typedef FixedArray<TComponent, 4> BaseArray;
00077
00079 typedef TComponent ComponentType;
00080
00082 RGBAPixel() {this->Fill(0);}
00083 RGBAPixel (const ComponentType& r)
00084 { this->Fill(r);}
00086
00088 RGBAPixel(const Self& r): BaseArray(r) {}
00089 RGBAPixel(const ComponentType r[4]): BaseArray(r) {}
00091
00093 RGBAPixel& operator= (const Self& r);
00094 RGBAPixel& operator= (const ComponentType r[4]);
00096
00098 static unsigned int GetNumberOfComponents(){ return 4;}
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 SetAlpha( ComponentType alpha ) {this->operator[](3) = alpha;}
00128
00130 void Set( ComponentType red, ComponentType green, ComponentType blue, ComponentType alpha )
00131 { this->operator[](0) = red; this->operator[](1) = green; this->operator[](2) = blue; this->operator[](3) = alpha;}
00132
00134 const ComponentType & GetRed( void ) const { return this->operator[](0);}
00135
00137 const ComponentType & GetGreen( void ) const { return this->operator[](1);}
00138
00140 const ComponentType & GetBlue( void ) const { return this->operator[](2);}
00141
00143 const ComponentType & GetAlpha( void ) const { return this->operator[](3);}
00144
00146 ComponentType GetLuminance( void ) const;
00147 };
00148
00149
00150 template< typename TComponent >
00151 ITK_EXPORT std::ostream& operator<<(std::ostream& os,
00152 const RGBAPixel<TComponent> & c);
00153
00154 template< typename TComponent >
00155 ITK_EXPORT std::istream& operator>>(std::istream& is,
00156 RGBAPixel<TComponent> & c);
00157
00158 }
00159
00160
00161 #define ITK_TEMPLATE_RGBAPixel(_, EXPORT, x, y) namespace itk { \
00162 _(1(class EXPORT RGBAPixel< ITK_TEMPLATE_1 x >)) \
00163 namespace Templates { typedef RGBAPixel< ITK_TEMPLATE_1 x > RGBAPixel##y; } \
00164 }
00165
00166 #if ITK_TEMPLATE_EXPLICIT
00167 # include "Templates/itkRGBAPixel+-.h"
00168 #endif
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178 #include "itkNumericTraitsRGBAPixel.h"
00179
00180 #if ITK_TEMPLATE_TXX
00181 # include "itkRGBAPixel.txx"
00182 #endif
00183
00184 #endif
00185