ITK  6.0.0
Insight Toolkit
itkRGBPixel.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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 itkRGBPixel_h
19#define itkRGBPixel_h
20
21// Undefine an eventual RGBPixel macro
22#ifdef RGBPixel
23# undef RGBPixel
24#endif
25
26#include "itkIndent.h"
27#include "itkFixedArray.h"
28#include "itkMath.h"
29
30namespace itk
31{
57template <typename TComponent = unsigned short>
58class ITK_TEMPLATE_EXPORT RGBPixel : public FixedArray<TComponent, 3>
59{
60public:
62 using Self = RGBPixel;
64
67
69 static constexpr unsigned int Dimension = 3;
70
72 static constexpr unsigned int Length = 3;
73
75 using ComponentType = TComponent;
77
80#ifdef ITK_FUTURE_LEGACY_REMOVE
81 RGBPixel() = default;
82#else
83 RGBPixel() { this->Fill(0); }
84#endif
87#if defined(ITK_LEGACY_REMOVE)
89 explicit RGBPixel(const ComponentType & r) { this->Fill(r); }
90
92 RGBPixel(std::nullptr_t) = delete;
93#else
94
97 RGBPixel(const ComponentType & r) { this->Fill(r); }
98#endif
99
101 template <typename TRGBPixelValueType>
103 : BaseArray(r)
104 {}
106 : BaseArray(r)
107 {}
111 template <typename TRGBPixelValueType>
112 Self &
114 {
115 BaseArray::operator=(r);
116 return *this;
117 }
120 Self &
122
124 Self
125 operator+(const Self & r) const;
126 Self
127 operator-(const Self & r) const;
128 Self operator*(const ComponentType & r) const;
129 Self
130 operator/(const ComponentType & r) const;
134 const Self &
135 operator+=(const Self & r);
136 const Self &
137 operator-=(const Self & r);
138 const Self &
140 const Self &
145 bool
146 operator<(const Self & r) const;
147
148 bool
149 operator==(const Self & r) const;
150
152 static unsigned int
154 {
155 return 3;
156 }
157
159 ComponentType
160 GetNthComponent(int c) const
161 {
162 return this->operator[](c);
163 }
164
166 ComponentType
168 {
169 return static_cast<ComponentType>(
170 std::sqrt(static_cast<double>(this->operator[](0)) * static_cast<double>(this->operator[](0)) +
171 static_cast<double>(this->operator[](1)) * static_cast<double>(this->operator[](1)) +
172 static_cast<double>(this->operator[](2)) * static_cast<double>(this->operator[](2))));
173 }
174
176 void
178 {
179 this->operator[](c) = v;
180 }
181
183 void
185 {
186 this->operator[](0) = red;
187 }
188
190 void
192 {
193 this->operator[](1) = green;
194 }
195
197 void
199 {
200 this->operator[](2) = blue;
201 }
202
204 void
206 {
207 this->operator[](0) = red;
208 this->operator[](1) = green;
209 this->operator[](2) = blue;
210 }
214 const ComponentType &
215 GetRed() const
216 {
217 return this->operator[](0);
218 }
219
221 const ComponentType &
222 GetGreen() const
223 {
224 return this->operator[](1);
225 }
226
228 const ComponentType &
229 GetBlue() const
230 {
231 return this->operator[](2);
232 }
233
235 LuminanceType
237};
238
239template <typename TComponent>
240std::ostream &
241operator<<(std::ostream & os, const RGBPixel<TComponent> & c);
242
243template <typename TComponent>
244std::istream &
245operator>>(std::istream & is, RGBPixel<TComponent> & c);
246
247template <typename T>
248inline void
250{
251 a.swap(b);
252}
253
254} // end namespace itk
255
256//
257// Numeric traits must be included after (optionally) including the explicit
258// instantiations control of this class, in case the implicit instantiation
259// needs to be disabled.
260//
261// NumericTraits must be included before (optionally) including the .hxx file,
262// in case the .hxx requires to use NumericTraits.
263//
265
266
267#ifndef ITK_MANUAL_INSTANTIATION
268# include "itkRGBPixel.hxx"
269#endif
270
271#endif
Pixel-wise addition of two images.
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:54
void swap(FixedArray &other)
Represent Red, Green and Blue components for color images.
Definition: itkRGBPixel.h:59
ComponentType GetNthComponent(int c) const
Definition: itkRGBPixel.h:160
static unsigned int GetNumberOfComponents()
Definition: itkRGBPixel.h:153
void Set(ComponentType red, ComponentType green, ComponentType blue)
Definition: itkRGBPixel.h:205
Self operator*(const ComponentType &r) const
Self & operator=(const RGBPixel< TRGBPixelValueType > &r)
Definition: itkRGBPixel.h:113
RGBPixel(const RGBPixel< TRGBPixelValueType > &r)
Definition: itkRGBPixel.h:102
const ComponentType & GetBlue() const
Definition: itkRGBPixel.h:229
TComponent ComponentType
Definition: itkRGBPixel.h:75
const Self & operator-=(const Self &r)
RGBPixel(const ComponentType &r)
Definition: itkRGBPixel.h:89
LuminanceType GetLuminance() const
void SetBlue(ComponentType blue)
Definition: itkRGBPixel.h:198
void SetRed(ComponentType red)
Definition: itkRGBPixel.h:184
typename NumericTraits< ComponentType >::RealType LuminanceType
Definition: itkRGBPixel.h:76
RGBPixel(std::nullptr_t)=delete
Self operator-(const Self &r) const
Self operator+(const Self &r) const
RGBPixel(const ComponentType r[3])
Definition: itkRGBPixel.h:105
const Self & operator*=(const ComponentType &r)
const Self & operator/=(const ComponentType &r)
Self & operator=(const ComponentType r[3])
const ComponentType & GetGreen() const
Definition: itkRGBPixel.h:222
ComponentType GetScalarValue() const
Definition: itkRGBPixel.h:167
void SetGreen(ComponentType green)
Definition: itkRGBPixel.h:191
const Self & operator+=(const Self &r)
void SetNthComponent(int c, const ComponentType &v)
Definition: itkRGBPixel.h:177
Self operator/(const ComponentType &r) const
bool operator==(const Self &r) const
const ComponentType & GetRed() const
Definition: itkRGBPixel.h:215
RGBPixel()=default
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
void swap(Array< T > &a, Array< T > &b) noexcept
Definition: itkArray.h:242
std::istream & operator>>(std::istream &is, Point< T, VPointDimension > &vct)
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, typename AnatomicalOrientation::CoordinateEnum value)
bool operator<(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:557