itkRGBPixel.h
Go to the documentation of this file.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 typedef FixedArray<TComponent, 3> BaseArray;
00060
00062 #if defined(__BORLANDC__)
00063 enum {Dimension = 3};
00064 #else
00065 itkStaticConstMacro(Dimension, unsigned int, 3);
00066 #endif
00067
00068
00070 #if defined(__BORLANDC__)
00071 enum {Length = 3};
00072 #else
00073 itkStaticConstMacro(Length, unsigned int, 3);
00074 #endif
00075
00076
00078 typedef TComponent ComponentType;
00079 typedef typename Superclass::ValueType ValueType;
00080
00082 RGBPixel() {};
00083
00085 RGBPixel (const ComponentType& r) { this->Fill(r); }
00086
00088 template< class TRGBPixelValueType >
00089 RGBPixel(const RGBPixel< TRGBPixelValueType >& r): BaseArray(r) {}
00090 RGBPixel(const ComponentType r[3]): BaseArray(r) {}
00092
00094 template< class TRGBPixelValueType >
00095 Self& operator= (const RGBPixel< TRGBPixelValueType > & r)
00096 {
00097 BaseArray::operator=(r);
00098 return *this;
00099 }
00101
00102 Self& operator= (const ComponentType r[3]);
00103
00105 Self operator+(const Self &vec) const;
00106 Self operator-(const Self &vec) const;
00107 const Self & operator+=(const Self &vec);
00108 const Self & operator-=(const Self &vec);
00109 Self operator*(const ComponentType &f) const;
00111
00112 bool operator<(const Self &vec) const;
00113 bool operator==(const Self &vec) const;
00114
00116 static unsigned int GetNumberOfComponents(){ return 3;}
00117
00119 ComponentType GetNthComponent(int c) const
00120 { return this->operator[](c); }
00121
00123 ComponentType GetScalarValue() const
00124 {
00125 return static_cast<ComponentType> (vcl_sqrt(
00126 static_cast<double>(this->operator[](0)) * static_cast<double>(this->operator[](0)) +
00127 static_cast<double>(this->operator[](1)) * static_cast<double>(this->operator[](1)) +
00128 static_cast<double>(this->operator[](2)) * static_cast<double>(this->operator[](2))));
00129 }
00130
00132 void SetNthComponent(int c, const ComponentType& v)
00133 { this->operator[](c) = v; }
00134
00136 void SetRed( ComponentType red ) { this->operator[](0) = red;}
00137
00139 void SetGreen( ComponentType green ) {this->operator[](1) = green;}
00140
00142 void SetBlue( ComponentType blue ) {this->operator[](2) = blue;}
00143
00145 void Set( ComponentType red, ComponentType green, ComponentType blue )
00146 { this->operator[](0) = red; this->operator[](1) = green; this->operator[](2) = blue;}
00147
00149 const ComponentType & GetRed( void ) const { return this->operator[](0);}
00150
00152 const ComponentType & GetGreen( void ) const { return this->operator[](1);}
00153
00155 const ComponentType & GetBlue( void ) const { return this->operator[](2);}
00156
00158 ComponentType GetLuminance( void ) const;
00159 };
00160
00161
00162 template< typename TComponent >
00163 ITK_EXPORT std::ostream& operator<<(std::ostream& os,
00164 const RGBPixel<TComponent> & c);
00165 template< typename TComponent >
00166 ITK_EXPORT std::istream& operator>>(std::istream& is,
00167 RGBPixel<TComponent> & c);
00168
00169 }
00170
00171
00172 #define ITK_TEMPLATE_RGBPixel(_, EXPORT, x, y) namespace itk { \
00173 _(1(class EXPORT RGBPixel< ITK_TEMPLATE_1 x >)) \
00174 namespace Templates { typedef RGBPixel< ITK_TEMPLATE_1 x > RGBPixel##y; } \
00175 }
00176
00177 #if ITK_TEMPLATE_EXPLICIT
00178 # include "Templates/itkRGBPixel+-.h"
00179 #endif
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 #include "itkNumericTraitsRGBPixel.h"
00190
00191 #if ITK_TEMPLATE_TXX
00192 # include "itkRGBPixel.txx"
00193 #endif
00194
00195 #endif
00196