Orfeo Toolbox  3.16
itkRGBPixel.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkRGBPixel.txx,v $
5  Language: C++
6  Date: $Date: 2009-03-03 15:08:40 $
7  Version: $Revision: 1.29 $
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 __itkRGBPixel_txx
18 #define __itkRGBPixel_txx
19 #include "itkRGBPixel.h"
20 #include "itkNumericTraits.h"
21 
22 namespace itk
23 {
24 
28 template<class T>
29 RGBPixel<T>&
32 {
33  BaseArray::operator=(r);
34  return *this;
35 }
36 
37 
38 
42 template<class 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 
58 template<class T>
61 ::operator-(const Self & r) const
62 {
63  Self result;
64  for( unsigned int i=0; i<3; i++)
65  {
66  result[i] = (*this)[i] - r[i];
67  }
68  return result;
69 }
70 
71 
72 
76 template<class T>
77 const RGBPixel<T> &
79 ::operator+=(const Self & r)
80 {
81  for( unsigned int i=0; i<3; i++)
82  {
83  (*this)[i] += r[i];
84  }
85  return *this;
86 }
87 
91 template<class T>
92 const RGBPixel<T> &
94 ::operator-=(const Self & r)
95 {
96  for( unsigned int i=0; i<3; i++)
97  {
98  (*this)[i] -= r[i];
99  }
100  return *this;
101 }
102 
106 template<class T>
109 ::operator*(const ComponentType & r) const
110 {
111  Self result;
112  for( unsigned int i=0; i<3; i++)
113  {
114  result[i] = (*this)[i] * r;
115  }
116  return result;
117 }
118 
119 
123 template<class T>
124 bool
126 ::operator==(const Self & r) const
127 {
128  for( unsigned int i=0; i<3; i++)
129  {
130  if((*this)[i] != r[i])
131  {
132  return false;
133  }
134  }
135  return true;
136 }
137 
141 template<class T>
142 bool
144 ::operator<(const Self & r) const
145 {
146  for( unsigned int i=0; i<3; i++)
147  {
148  if((*this)[i] >= r[i])
149  {
150  return false;
151  }
152  }
153  return true;
154 }
155 
159 template<class T>
163 {
164  const double luminance =
165  0.30 * this->GetRed() +
166  0.59 * this->GetGreen() +
167  0.11 * this->GetBlue();
168  return static_cast<ComponentType>( luminance );
169 }
170 
174 template<class TComponent>
175 std::ostream &
176 operator<<(std::ostream& os,const RGBPixel<TComponent> & c )
177 {
178  os << static_cast<typename NumericTraits<TComponent>::PrintType>(c[0]) << " ";
179  os << static_cast<typename NumericTraits<TComponent>::PrintType>(c[1]) << " ";
180  os << static_cast<typename NumericTraits<TComponent>::PrintType>(c[2]);
181  return os;
182 }
183 
184 
188 template<class TComponent>
189 std::istream &
190 operator>>(std::istream& is, RGBPixel<TComponent> & c )
191 {
192  TComponent red;
193  TComponent green;
194  TComponent blue;
195  is >> red >> green >> blue;
196  c.SetRed( red );
197  c.SetGreen( green );
198  c.SetBlue( blue );
199  return is;
200 }
201 
202 } // end namespace itk
203 
204 #endif

Generated at Sun Feb 3 2013 00:03:29 for Orfeo Toolbox with doxygen 1.8.1.1