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);
00062
00064 typedef FixedArray<TComponent, 3> BaseArray;
00065
00067 typedef TComponent ComponentType;
00068 typedef typename Superclass::ValueType ValueType;
00069
00071 RGBPixel() {};
00072
00074 RGBPixel (const ComponentType& r) { this->Fill(r); }
00075
00077 template< class TRGBPixelValueType >
00078 RGBPixel(const RGBPixel< TRGBPixelValueType >& r): BaseArray(r) {}
00079 RGBPixel(const ComponentType r[3]): BaseArray(r) {}
00081
00083 template< class TRGBPixelValueType >
00084 Self& operator= (const RGBPixel< TRGBPixelValueType > & r)
00085 {
00086 BaseArray::operator=(r);
00087 return *this;
00088 }
00090
00091 Self& operator= (const ComponentType r[3]);
00092
00094 Self operator+(const Self &vec) const;
00095 Self operator-(const Self &vec) const;
00096 const Self & operator+=(const Self &vec);
00097 const Self & operator-=(const Self &vec);
00098 Self operator*(const ComponentType &f) const;
00100
00101 bool operator<(const Self &vec) const;
00102 bool operator==(const Self &vec) const;
00103
00105 static unsigned int GetNumberOfComponents(){ return 3;}
00106
00108 ComponentType GetNthComponent(int c) const
00109 { return this->operator[](c); }
00110
00112 ComponentType GetScalarValue() const
00113 {
00114 return static_cast<ComponentType> (vcl_sqrt(
00115 static_cast<double>(this->operator[](0)) * static_cast<double>(this->operator[](0)) +
00116 static_cast<double>(this->operator[](1)) * static_cast<double>(this->operator[](1)) +
00117 static_cast<double>(this->operator[](2)) * static_cast<double>(this->operator[](2))));
00118 }
00119
00121 void SetNthComponent(int c, const ComponentType& v)
00122 { this->operator[](c) = v; }
00123
00125 void SetRed( ComponentType red ) { this->operator[](0) = red;}
00126
00128 void SetGreen( ComponentType green ) {this->operator[](1) = green;}
00129
00131 void SetBlue( ComponentType blue ) {this->operator[](2) = blue;}
00132
00134 void Set( ComponentType red, ComponentType green, ComponentType blue )
00135 { this->operator[](0) = red; this->operator[](1) = green; this->operator[](2) = blue;}
00136
00138 const ComponentType & GetRed( void ) const { return this->operator[](0);}
00139
00141 const ComponentType & GetGreen( void ) const { return this->operator[](1);}
00142
00144 const ComponentType & GetBlue( void ) const { return this->operator[](2);}
00145
00147 ComponentType GetLuminance( void ) const;
00148 };
00149
00150
00151 template< typename TComponent >
00152 ITK_EXPORT std::ostream& operator<<(std::ostream& os,
00153 const RGBPixel<TComponent> & c);
00154 template< typename TComponent >
00155 ITK_EXPORT std::istream& operator>>(std::istream& is,
00156 RGBPixel<TComponent> & c);
00157
00158 }
00159
00160
00161 #define ITK_TEMPLATE_RGBPixel(_, EXPORT, x, y) namespace itk { \
00162 _(1(class EXPORT RGBPixel< ITK_TEMPLATE_1 x >)) \
00163 namespace Templates { typedef RGBPixel< ITK_TEMPLATE_1 x > RGBPixel##y; } \
00164 }
00165
00166 #if ITK_TEMPLATE_EXPLICIT
00167 # include "Templates/itkRGBPixel+-.h"
00168 #endif
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178 #include "itkNumericTraitsRGBPixel.h"
00179
00180 #if ITK_TEMPLATE_TXX
00181 # include "itkRGBPixel.txx"
00182 #endif
00183
00184 #endif
00185