Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkRGBAPixel.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkRGBAPixel.h,v $
00005   Language:  C++
00006   Date:      $Date: 2008-07-02 22:09:47 $
00007   Version:   $Revision: 1.19 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkRGBAPixel_h
00018 #define __itkRGBAPixel_h
00019 
00020 // Undefine an eventual RGBAPixel macro
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   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) ;}
00076 
00078   RGBAPixel(const Self& r): BaseArray(r) {}
00079   RGBAPixel(const ComponentType  r[4]): BaseArray(r) {}  
00081 
00083   RGBAPixel& operator= (const Self& r);
00084   RGBAPixel& operator= (const ComponentType r[4]);
00086 
00088   static unsigned int GetNumberOfComponents(){ return 4;}
00089 
00091   ComponentType GetNthComponent(int c) const
00092     { return this->operator[](c); }
00093 
00095   ComponentType GetScalarValue() const
00096     {
00097       return static_cast<ComponentType> (vcl_sqrt(
00098         static_cast<double>(this->operator[](0)) * static_cast<double>(this->operator[](0)) +
00099         static_cast<double>(this->operator[](1)) * static_cast<double>(this->operator[](1)) +
00100         static_cast<double>(this->operator[](2)) * static_cast<double>(this->operator[](2)))); 
00101     }
00102 
00104   void SetNthComponent(int c, const ComponentType& v)  
00105     {  this->operator[](c) = v; }
00106 
00108   void SetRed( ComponentType red ) { this->operator[](0) = red;}
00109 
00111   void SetGreen( ComponentType green ) {this->operator[](1) = green;}
00112 
00114   void SetBlue( ComponentType blue ) {this->operator[](2) = blue;}
00115 
00117   void SetAlpha( ComponentType alpha ) {this->operator[](3) = alpha;}
00118 
00120   void Set( ComponentType red, ComponentType green, ComponentType blue, ComponentType alpha )
00121     { this->operator[](0) = red; this->operator[](1) = green; this->operator[](2) = blue; this->operator[](3) = alpha;}
00122 
00124   const ComponentType & GetRed( void ) const { return this->operator[](0);}
00125 
00127   const ComponentType & GetGreen( void ) const { return this->operator[](1);}
00128 
00130   const ComponentType & GetBlue( void ) const { return this->operator[](2);}
00131 
00133   const ComponentType & GetAlpha( void ) const { return this->operator[](3);}
00134 
00136   ComponentType GetLuminance( void ) const;
00137 };
00138 
00139 
00140 template< typename TComponent  >  
00141 ITK_EXPORT std::ostream& operator<<(std::ostream& os, 
00142                                     const RGBAPixel<TComponent> & c); 
00143 
00144 template< typename TComponent  >  
00145 ITK_EXPORT std::istream& operator>>(std::istream& is, 
00146                                           RGBAPixel<TComponent> & c); 
00147 
00148 } // end namespace itk
00149 
00150 // Define instantiation macro for this template.
00151 #define ITK_TEMPLATE_RGBAPixel(_, EXPORT, x, y) namespace itk { \
00152   _(1(class EXPORT RGBAPixel< ITK_TEMPLATE_1 x >)) \
00153   namespace Templates { typedef RGBAPixel< ITK_TEMPLATE_1 x > RGBAPixel##y; } \
00154   }
00155 
00156 #if ITK_TEMPLATE_EXPLICIT
00157 # include "Templates/itkRGBAPixel+-.h"
00158 #endif
00159 
00160 //
00161 // Numeric traits must be included after (optionally) including the explicit
00162 // instantiations control of this class, in case the implicit instantiation
00163 // needs to be disabled. 
00164 //
00165 // NumericTraits must be included before (optionally) including the .txx file,
00166 // in case the .txx requires to use NumericTraits.
00167 //
00168 #include "itkNumericTraitsRGBAPixel.h"
00169 
00170 #if ITK_TEMPLATE_TXX
00171 # include "itkRGBAPixel.txx"
00172 #endif
00173 
00174 #endif
00175 

Generated at Wed Nov 5 23:58:45 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000