ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkRGBAPixel.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkRGBAPixel_h
19 #define itkRGBAPixel_h
20 
21 // Undefine an eventual RGBAPixel macro
22 #ifdef RGBAPixel
23 #undef RGBAPixel
24 #endif
25 
26 #include "itkIndent.h"
27 #include "itkFixedArray.h"
28 #include "itkMath.h"
29 
30 namespace itk
31 {
58 template< typename TComponent = unsigned short >
59 class ITK_TEMPLATE_EXPORT RGBAPixel:public FixedArray< TComponent, 4 >
60 {
61 public:
63  typedef RGBAPixel Self;
65 
67  itkStaticConstMacro(Dimension, unsigned int, 4);
68 
70  itkStaticConstMacro(Length, unsigned int, 4);
71 
74 
76  typedef TComponent ComponentType;
78 
80  RGBAPixel() { this->Fill(0); }
81  RGBAPixel (const ComponentType & r) { this->Fill(r); }
83 
85  template< typename TRGBAPixelValueType >
87  RGBAPixel(const ComponentType r[4]):BaseArray(r) {}
89 
91  RGBAPixel & operator=(const Self & r);
92 
93  RGBAPixel & operator=(const ComponentType r[4]);
94 
96  Self operator+(const Self & vec) const;
97 
98  Self operator-(const Self & vec) const;
99 
100  const Self & operator+=(const Self & vec);
101 
102  const Self & operator-=(const Self & vec);
103 
104  Self operator *(const ComponentType & f) const;
105 
106  bool operator==(const Self & vec) const;
107 
109  static unsigned int GetNumberOfComponents() { return 4; }
110 
112  ComponentType GetNthComponent(int c) const { return this->operator[](c); }
113 
116  {
117  return static_cast< ComponentType >( std::sqrt(
118  static_cast< double >( this->operator[](0) )
119  * static_cast< double >( this->operator[](0) )
120  + static_cast< double >( this->operator[](1) )
121  * static_cast< double >( this->operator[](1) )
122  + static_cast< double >( this->operator[](2) )
123  * static_cast< double >( this->operator[](2) ) ) );
124  }
125 
127  void SetNthComponent(int c, const ComponentType & v) { this->operator[](c) = v; }
128 
130  void SetRed(ComponentType red) { this->operator[](0) = red; }
131 
133  void SetGreen(ComponentType green) { this->operator[](1) = green; }
134 
136  void SetBlue(ComponentType blue) { this->operator[](2) = blue; }
137 
139  void SetAlpha(ComponentType alpha) { this->operator[](3) = alpha; }
140 
143  {
144  this->operator[](0) = red;
145  this->operator[](1) = green;
146  this->operator[](2) = blue;
147  this->operator[](3) = alpha;
148  }
150 
152  const ComponentType & GetRed(void) const { return this->operator[](0); }
153 
155  const ComponentType & GetGreen(void) const { return this->operator[](1); }
156 
158  const ComponentType & GetBlue(void) const { return this->operator[](2); }
159 
161  const ComponentType & GetAlpha(void) const { return this->operator[](3); }
162 
164  LuminanceType GetLuminance() const;
165 };
166 
167 template< typename TComponent >
168 std::ostream & operator<<(std::ostream & os,
169  const RGBAPixel< TComponent > & c);
170 
171 template< typename TComponent >
172 std::istream & operator>>(std::istream & is,
173  RGBAPixel< TComponent > & c);
174 } // end namespace itk
175 
176 //
177 // Numeric traits must be included after (optionally) including the explicit
178 // instantiations control of this class, in case the implicit instantiation
179 // needs to be disabled.
180 //
181 // NumericTraits must be included before (optionally) including the .hxx file,
182 // in case the .hxx requires to use NumericTraits.
183 //
185 
186 #ifndef ITK_MANUAL_INSTANTIATION
187 #include "itkRGBAPixel.hxx"
188 #endif
189 
190 #endif
RGBAPixel(const ComponentType &r)
Definition: itkRGBAPixel.h:81
void Set(ComponentType red, ComponentType green, ComponentType blue, ComponentType alpha)
Definition: itkRGBAPixel.h:142
const ComponentType & GetBlue(void) const
Definition: itkRGBAPixel.h:158
RGBAPixel(const ComponentType r[4])
Definition: itkRGBAPixel.h:87
ConstNeighborhoodIterator< TImage > operator-(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
Represent Red, Green, Blue and Alpha components for color images.
Definition: itkRGBAPixel.h:59
std::istream & operator>>(std::istream &is, Point< T, NPointDimension > &v)
CovariantVector< T, NVectorDimension > operator*(const T &scalar, const CovariantVector< T, NVectorDimension > &v)
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:192
void SetRed(ComponentType red)
Definition: itkRGBAPixel.h:130
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:50
FixedArray< TComponent, 4 > BaseArray
Definition: itkRGBAPixel.h:73
NumericTraits< ComponentType >::RealType LuminanceType
Definition: itkRGBAPixel.h:77
const ComponentType & GetRed(void) const
Definition: itkRGBAPixel.h:152
ConstNeighborhoodIterator< TImage > operator+(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
void SetGreen(ComponentType green)
Definition: itkRGBAPixel.h:133
void SetBlue(ComponentType blue)
Definition: itkRGBAPixel.h:136
TComponent ComponentType
Definition: itkRGBAPixel.h:76
ComponentType GetScalarValue() const
Definition: itkRGBAPixel.h:115
void SetAlpha(ComponentType alpha)
Definition: itkRGBAPixel.h:139
const ComponentType & GetAlpha(void) const
Definition: itkRGBAPixel.h:161
static unsigned int GetNumberOfComponents()
Definition: itkRGBAPixel.h:109
RGBAPixel Self
Definition: itkRGBAPixel.h:63
FixedArray< TComponent, 4 > Superclass
Definition: itkRGBAPixel.h:64
RGBAPixel(const RGBAPixel< TRGBAPixelValueType > &r)
Definition: itkRGBAPixel.h:86
ComponentType GetNthComponent(int c) const
Definition: itkRGBAPixel.h:112
void SetNthComponent(int c, const ComponentType &v)
Definition: itkRGBAPixel.h:127
bool ITKIOXML_EXPORT operator==(itk::FancyString &s, const std::string &)
const ComponentType & GetGreen(void) const
Definition: itkRGBAPixel.h:155