| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkRGBAPixel.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:46 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
|
=========================================================================*/ |
| 17 |
|
#ifndef __itkRGBAPixel_h |
| 18 |
|
#define __itkRGBAPixel_h |
| 19 |
|
|
| 20 |
|
// Undefine an eventual RGBAPixel macro |
| 21 |
|
#ifdef RGBAPixel |
| 22 |
|
#undef RGBAPixel |
| 23 |
|
#endif |
| 24 |
|
|
| 25 |
|
#include <itkIndent.h> |
| 26 |
|
#include <itkFixedArray.h> |
| 27 |
|
#include "vnl/vnl_math.h" |
| 28 |
|
|
| 29 |
|
namespace itk |
| 30 |
|
{ |
| 31 |
|
|
| 32 |
|
/** \class RGBAPixel |
| 33 |
|
* \brief Represent Red, Green, Blue cand Alpha component for color images |
| 34 |
|
* |
| 35 |
|
* This class is templated over the representation used for each |
| 36 |
|
* component. |
| 37 |
|
* |
| 38 |
|
* The following syntax for assigning an index is allowed/suggested: |
| 39 |
|
* |
| 40 |
|
* RGBAPixel<float> pixel; pixel = 1.0f, 0.0f, .5f, .8; |
| 41 |
|
* RGBAPixel<char> pixelArray[2]; |
| 42 |
WCM,WCM |
* pixelArray[0] = 255, 255, 255, 230; |
| 43 |
WCM |
* pixelArray[1] = 255, 255, 244, 255; |
| 44 |
|
* |
| 45 |
|
* Since RGBAPixel is a subclass of Array, you can access its components as: |
| 46 |
|
* pixel[0], pixel[1], pixel[2], pixel[3] |
| 47 |
|
* \ingroup ImageObjects |
| 48 |
|
* |
| 49 |
|
*/ |
| 50 |
|
|
| 51 |
|
template < typename TComponent = unsigned short > |
| 52 |
|
class RGBAPixel: public FixedArray<TComponent,4> |
| 53 |
|
{ |
| 54 |
|
public: |
| 55 |
|
/** Standard class typedefs. */ |
| 56 |
|
typedef RGBAPixel Self; |
| 57 |
TDA |
typedef FixedArray<TComponent, 4> Super; |
| 58 |
|
|
| 59 |
|
/** Dimension of the vector space. */ |
| 60 |
|
itkStaticConstMacro(Dimension, unsigned int, 4); |
| 61 |
|
|
| 62 |
|
/** Length of the pixel. */ |
| 63 |
|
itkStaticConstMacro(Length, unsigned int, 4); |
| 64 |
|
|
| 65 |
|
/** Convenience typedefs. */ |
| 66 |
|
typedef FixedArray<TComponent, 4> BaseArray; |
| 67 |
|
|
| 68 |
|
/** Define the component type. */ |
| 69 |
|
typedef TComponent ComponentType; |
| 70 |
|
|
| 71 |
|
/** Default constructor has nothing to do. */ |
| 72 |
|
RGBAPixel() {this->Fill(0);} |
| 73 |
|
RGBAPixel (const ComponentType& r) |
| 74 |
SEM,IND |
**{ this->Fill(r) ;} |
| 75 |
|
|
| 76 |
|
/** Pass-through constructor for the Array base class. */ |
| 77 |
|
RGBAPixel(const Self& r): BaseArray(r) {} |
| 78 |
|
RGBAPixel(const ComponentType r[4]): BaseArray(r) {} |
| 79 |
|
|
| 80 |
|
/** Pass-through assignment operator for the Array base class. */ |
| 81 |
|
RGBAPixel& operator= (const Self& r); |
| 82 |
|
RGBAPixel& operator= (const ComponentType r[4]); |
| 83 |
|
|
| 84 |
|
/** Return the number of componentsxquery-rep. */ |
| 85 |
|
static unsigned int GetNumberOfComponents(){ return 4;} |
| 86 |
|
|
| 87 |
|
/** Return the value for the Nth component. */ |
| 88 |
|
ComponentType GetNthComponent(int c) const |
| 89 |
|
{ return this->operator[](c); } |
| 90 |
|
|
| 91 |
|
/** Return the value for the Nth component. */ |
| 92 |
|
ComponentType GetScalarValue() const |
| 93 |
|
{ |
| 94 |
IND |
******return static_cast<ComponentType> (vcl_sqrt( |
| 95 |
LEN |
static_cast<double>(this->operator[](0)) * static_cast<double>(this->operator[](0)) + |
| 96 |
LEN,IND |
**********static_cast<double>(this->operator[](1)) * static_cast<double>(this->operator[](1)) + |
| 97 |
LEN,IND |
**********static_cast<double>(this->operator[](2)) * static_cast<double>(this->operator[](2)))); |
| 98 |
|
} |
| 99 |
|
|
| 100 |
|
/** Set the Nth component to v. */ |
| 101 |
|
void SetNthComponent(int c, const ComponentType& v) |
| 102 |
|
{ this->operator[](c) = v; } |
| 103 |
|
|
| 104 |
|
/** Set the Red component. */ |
| 105 |
|
void SetRed( ComponentType red ) { this->operator[](0) = red;} |
| 106 |
|
|
| 107 |
|
/** Set the Green component. */ |
| 108 |
|
void SetGreen( ComponentType green ) {this->operator[](1) = green;} |
| 109 |
|
|
| 110 |
|
/** Set the Blue component. */ |
| 111 |
|
void SetBlue( ComponentType blue ) {this->operator[](2) = blue;} |
| 112 |
|
|
| 113 |
|
/** Set the Alpha component. */ |
| 114 |
|
void SetAlpha( ComponentType alpha ) {this->operator[](3) = alpha;} |
| 115 |
|
|
| 116 |
|
/** Set the four components. */ |
| 117 |
LEN |
void Set( ComponentType red, ComponentType green, ComponentType blue, ComponentType alpha ) |
| 118 |
LEN |
{ this->operator[](0) = red; this->operator[](1) = green; this->operator[](2) = blue; this->operator[](3) = alpha;} |
| 119 |
|
|
| 120 |
|
/** Get the Red component. */ |
| 121 |
|
const ComponentType & GetRed( void ) const { return this->operator[](0);} |
| 122 |
|
|
| 123 |
|
/** Get the Green component. */ |
| 124 |
|
const ComponentType & GetGreen( void ) const { return this->operator[](1);} |
| 125 |
|
|
| 126 |
|
/** Get the Blue component. */ |
| 127 |
|
const ComponentType & GetBlue( void ) const { return this->operator[](2);} |
| 128 |
|
|
| 129 |
|
/** Get the Alpha component. */ |
| 130 |
|
const ComponentType & GetAlpha( void ) const { return this->operator[](3);} |
| 131 |
|
|
| 132 |
|
/** Get Luminance out of RGB */ |
| 133 |
|
ComponentType GetLuminance( void ) const; |
| 134 |
|
}; |
| 135 |
|
|
| 136 |
|
|
| 137 |
|
template< typename TComponent > |
| 138 |
|
ITK_EXPORT std::ostream& operator<<(std::ostream& os, |
| 139 |
|
const RGBAPixel<TComponent> & c); |
| 140 |
|
|
| 141 |
|
template< typename TComponent > |
| 142 |
|
ITK_EXPORT std::istream& operator>>(std::istream& is, |
| 143 |
|
RGBAPixel<TComponent> & c); |
| 144 |
|
|
| 145 |
|
} // end namespace itk |
| 146 |
|
|
| 147 |
|
#ifndef ITK_MANUAL_INSTANTIATION |
| 148 |
|
#include "itkRGBAPixel.txx" |
| 149 |
|
#endif |
| 150 |
|
|
| 151 |
|
#endif |
| 152 |
|
|