| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkRGBPixel.txx.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 |
DEF |
#ifndef _itkRGBPixel_txx |
| 18 |
DEF |
#define _itkRGBPixel_txx |
| 19 |
|
#include "itkRGBPixel.h" |
| 20 |
|
#include "itkNumericTraits.h" |
| 21 |
|
|
| 22 |
|
namespace itk |
| 23 |
|
{ |
| 24 |
|
|
| 25 |
|
/* |
| 26 |
IND |
** Assigment from a plain array |
| 27 |
IND |
**/ |
| 28 |
|
template<class T> |
| 29 |
|
RGBPixel<T>& |
| 30 |
|
RGBPixel<T> |
| 31 |
|
::operator= (const ComponentType r[3]) |
| 32 |
|
{ |
| 33 |
|
BaseArray::operator=(r); |
| 34 |
|
return *this; |
| 35 |
|
} |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
/** |
| 40 |
|
* Returns a temporary copy of a vector |
| 41 |
|
*/ |
| 42 |
|
template<class T> |
| 43 |
|
RGBPixel<T> |
| 44 |
|
RGBPixel<T> |
| 45 |
|
::operator+(const Self & r) const |
| 46 |
|
{ |
| 47 |
|
Self result; |
| 48 |
|
for( unsigned int i=0; i<3; i++) |
| 49 |
|
{ |
| 50 |
|
result[i] = (*this)[i] + r[i]; |
| 51 |
|
} |
| 52 |
|
return result; |
| 53 |
|
} |
| 54 |
|
|
| 55 |
|
|
| 56 |
EML |
|
| 57 |
EML |
|
| 58 |
|
/** |
| 59 |
|
* Returns a temporary copy of a vector |
| 60 |
|
*/ |
| 61 |
|
template<class T> |
| 62 |
|
RGBPixel<T> |
| 63 |
|
RGBPixel<T> |
| 64 |
|
::operator-(const Self & r) const |
| 65 |
|
{ |
| 66 |
|
Self result; |
| 67 |
|
for( unsigned int i=0; i<3; i++) |
| 68 |
|
{ |
| 69 |
|
result[i] = (*this)[i] - r[i]; |
| 70 |
|
} |
| 71 |
|
return result; |
| 72 |
|
} |
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
/** |
| 77 |
|
* Returns a temporary copy of a vector |
| 78 |
|
*/ |
| 79 |
|
template<class T> |
| 80 |
|
const RGBPixel<T> & |
| 81 |
|
RGBPixel<T> |
| 82 |
|
::operator+=(const Self & r) |
| 83 |
|
{ |
| 84 |
|
for( unsigned int i=0; i<3; i++) |
| 85 |
|
{ |
| 86 |
|
(*this)[i] += r[i]; |
| 87 |
|
} |
| 88 |
|
return *this; |
| 89 |
|
} |
| 90 |
|
|
| 91 |
|
|
| 92 |
EML |
|
| 93 |
|
|
| 94 |
|
/** |
| 95 |
|
* Returns a temporary copy of a vector |
| 96 |
|
*/ |
| 97 |
|
template<class T> |
| 98 |
|
const RGBPixel<T> & |
| 99 |
|
RGBPixel<T> |
| 100 |
|
::operator-=(const Self & r) |
| 101 |
|
{ |
| 102 |
|
for( unsigned int i=0; i<3; i++) |
| 103 |
|
{ |
| 104 |
|
(*this)[i] -= r[i]; |
| 105 |
|
} |
| 106 |
|
return *this; |
| 107 |
|
} |
| 108 |
|
|
| 109 |
|
|
| 110 |
EML |
|
| 111 |
EML |
|
| 112 |
EML |
|
| 113 |
|
/** |
| 114 |
|
* Returns a temporary copy of a vector |
| 115 |
|
*/ |
| 116 |
|
template<class T> |
| 117 |
|
RGBPixel<T> |
| 118 |
|
RGBPixel<T> |
| 119 |
|
::operator*(const ComponentType & r) const |
| 120 |
|
{ |
| 121 |
|
Self result; |
| 122 |
|
for( unsigned int i=0; i<3; i++) |
| 123 |
|
{ |
| 124 |
|
result[i] = (*this)[i] * r; |
| 125 |
|
} |
| 126 |
|
return result; |
| 127 |
|
} |
| 128 |
|
|
| 129 |
|
|
| 130 |
EML |
|
| 131 |
EML |
|
| 132 |
|
/* |
| 133 |
|
* Compute luminance |
| 134 |
|
*/ |
| 135 |
|
template<class T> |
| 136 |
|
typename RGBPixel<T>::ComponentType |
| 137 |
|
RGBPixel<T> |
| 138 |
|
::GetLuminance() const |
| 139 |
|
{ |
| 140 |
|
const double luminance = |
| 141 |
IND |
****0.30 * this->GetRed() + |
| 142 |
IND |
****0.59 * this->GetGreen() + |
| 143 |
IND |
****0.11 * this->GetBlue(); |
| 144 |
|
return static_cast<ComponentType>( luminance ); |
| 145 |
|
} |
| 146 |
|
|
| 147 |
|
|
| 148 |
EML |
|
| 149 |
EML |
|
| 150 |
|
/** |
| 151 |
|
* Print content to an ostream |
| 152 |
|
*/ |
| 153 |
|
template<class TComponent> |
| 154 |
|
std::ostream & |
| 155 |
|
operator<<(std::ostream& os,const RGBPixel<TComponent> & c ) |
| 156 |
|
{ |
| 157 |
LEN |
os << static_cast<typename NumericTraits<TComponent>::PrintType>(c[0]) << " "; |
| 158 |
LEN |
os << static_cast<typename NumericTraits<TComponent>::PrintType>(c[1]) << " "; |
| 159 |
SEM |
os << static_cast<typename NumericTraits<TComponent>::PrintType>(c[2]) ; |
| 160 |
|
return os; |
| 161 |
|
} |
| 162 |
|
|
| 163 |
|
|
| 164 |
|
/** |
| 165 |
|
* Read content from an istream |
| 166 |
|
*/ |
| 167 |
|
template<class TComponent> |
| 168 |
|
std::istream & |
| 169 |
|
operator>>(std::istream& is, RGBPixel<TComponent> & c ) |
| 170 |
|
{ |
| 171 |
|
TComponent red; |
| 172 |
|
TComponent green; |
| 173 |
|
TComponent blue; |
| 174 |
|
is >> red >> green >> blue; |
| 175 |
|
c.SetRed( red ); |
| 176 |
|
c.SetGreen( green ); |
| 177 |
|
c.SetBlue( blue ); |
| 178 |
|
return is; |
| 179 |
|
} |
| 180 |
|
|
| 181 |
|
} // end namespace itk |
| 182 |
|
|
| 183 |
|
#endif |
| 184 |
|
|