ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkRGBAPixel.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 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
30namespace itk
31{
57
58template <typename TComponent = unsigned short>
59class ITK_TEMPLATE_EXPORT RGBAPixel : public FixedArray<TComponent, 4>
60{
61public:
63 using Self = RGBAPixel;
65
67 static constexpr unsigned int Dimension = 4;
68
70 static constexpr unsigned int Length = 4;
71
74
76 using ComponentType = TComponent;
78
81#ifdef ITK_FUTURE_LEGACY_REMOVE
82 RGBAPixel() = default;
83#else
84 constexpr RGBAPixel()
86 {
87 // `: Superclass(Superclass())` is a workaround for an old compiler bug. A simple `: Superclass()` triggered
88 // warnings from GCC 9.4.0 saying: "warning: '<anonymous>' may be used uninitialized in this function
89 // [-Wmaybe-uninitialized]".
90 }
91#endif
92
95 template <typename TRGBAPixelValueType>
100 : BaseArray(r)
101 {}
102
103
104#if defined(ITK_LEGACY_REMOVE)
106 RGBAPixel(std::nullptr_t) = delete;
107
109 explicit RGBAPixel(const ComponentType & r) { this->Fill(r); }
110#else
111 RGBAPixel(const ComponentType & r) { this->Fill(r); }
112#endif
113
115 RGBAPixel &
117
120 Self
121 operator+(const Self & r) const;
122 Self
123 operator-(const Self & r) const;
124 Self
125 operator*(const ComponentType & r) const;
126 Self
127 operator/(const ComponentType & r) const;
129
132 const Self &
133 operator+=(const Self & r);
134 const Self &
135 operator-=(const Self & r);
136 const Self &
138 const Self &
141
143 bool
144 operator<(const Self & r) const;
145
146 bool
147 operator==(const Self & r) const;
148
150 static unsigned int
152 {
153 return 4;
154 }
155
157 ComponentType
158 GetNthComponent(int c) const
159 {
160 return this->operator[](c);
161 }
162
164 ComponentType
166 {
167 return static_cast<ComponentType>(
168 std::sqrt(static_cast<double>(this->operator[](0)) * static_cast<double>(this->operator[](0)) +
169 static_cast<double>(this->operator[](1)) * static_cast<double>(this->operator[](1)) +
170 static_cast<double>(this->operator[](2)) * static_cast<double>(this->operator[](2))));
171 }
172
174 void
176 {
177 this->operator[](c) = v;
178 }
179
181 void
183 {
184 this->operator[](0) = red;
185 }
186
188 void
190 {
191 this->operator[](1) = green;
192 }
193
195 void
197 {
198 this->operator[](2) = blue;
199 }
200
202 void
204 {
205 this->operator[](3) = alpha;
206 }
207
209 void
211 {
212 this->operator[](0) = red;
213 this->operator[](1) = green;
214 this->operator[](2) = blue;
215 this->operator[](3) = alpha;
216 }
217
219 const ComponentType &
220 GetRed() const
221 {
222 return this->operator[](0);
223 }
224
226 const ComponentType &
227 GetGreen() const
228 {
229 return this->operator[](1);
230 }
231
233 const ComponentType &
234 GetBlue() const
235 {
236 return this->operator[](2);
237 }
238
240 const ComponentType &
241 GetAlpha() const
242 {
243 return this->operator[](3);
244 }
245
247 LuminanceType
249};
250
251template <typename TComponent>
252std::ostream &
253operator<<(std::ostream & os, const RGBAPixel<TComponent> & c);
254
255template <typename TComponent>
256std::istream &
257operator>>(std::istream & is, RGBAPixel<TComponent> & c);
258
259template <typename T>
260inline void
262{
263 a.swap(b);
264}
265
266} // end namespace itk
267
268//
269// Numeric traits must be included after (optionally) including the explicit
270// instantiations control of this class, in case the implicit instantiation
271// needs to be disabled.
272//
273// NumericTraits must be included before (optionally) including the .hxx file,
274// in case the .hxx requires to use NumericTraits.
275//
277
278#ifndef ITK_MANUAL_INSTANTIATION
279# include "itkRGBAPixel.hxx"
280#endif
281
282#endif
ITK_GCC_PRAGMA_PUSH ITK_GCC_SUPPRESS_Warray_bounds constexpr reference operator[](unsigned int index)
void Fill(const ValueType &)
Represent Red, Green, Blue and Alpha components for color images.
RGBAPixel(std::nullptr_t)=delete
ComponentType GetNthComponent(int c) const
RGBAPixel & operator=(const ComponentType r[4])
RGBAPixel(const RGBAPixel< TRGBAPixelValueType > &r)
void SetAlpha(ComponentType alpha)
LuminanceType GetLuminance() const
const Self & operator+=(const Self &r)
static constexpr unsigned int Length
RGBAPixel(const ComponentType &r)
Self operator+(const Self &r) const
FixedArray< T, 4 > Superclass
Self operator-(const Self &r) const
void SetNthComponent(int c, const ComponentType &v)
const ComponentType & GetAlpha() const
const ComponentType & GetRed() const
bool operator==(const Self &r) const
const ComponentType & GetGreen() const
void SetGreen(ComponentType green)
static unsigned int GetNumberOfComponents()
ComponentType GetScalarValue() const
typename NumericTraits< ComponentType >::RealType LuminanceType
Self operator/(const ComponentType &r) const
static constexpr unsigned int Dimension
const Self & operator/=(const ComponentType &r)
bool operator<(const Self &r) const
void SetBlue(ComponentType blue)
void Set(ComponentType red, ComponentType green, ComponentType blue, ComponentType alpha)
FixedArray< T, 4 > BaseArray
const Self & operator-=(const Self &r)
Self operator*(const ComponentType &r) const
const Self & operator*=(const ComponentType &r)
RGBAPixel()=default
const ComponentType & GetBlue() const
void SetRed(ComponentType red)
RGBAPixel(const ComponentType r[4])
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
void swap(Array< T > &a, Array< T > &b) noexcept
Definition itkArray.h:247
std::istream & operator>>(std::istream &is, Point< T, VPointDimension > &vct)
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, typename AnatomicalOrientation::CoordinateEnum value)