UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
lab.hpp
1
45#ifndef UFO_VISION_COLOR_LAB_HPP
46#define UFO_VISION_COLOR_LAB_HPP
47
48// UFO
49#include <ufo/vision/color/flags.hpp>
50
51// STL
52#include <concepts>
53#include <cstdint>
54#include <format>
55#include <ostream>
56
57namespace ufo
58{
75template <class T = float, ColorFlags Flags = ColorFlags::None>
76 requires(std::integral<T> || std::floating_point<T>)
77struct Lab;
78
86template <class T>
87 requires(std::integral<T> || std::floating_point<T>)
96
103 T a;
104
111 T b;
112
120 [[nodiscard]] friend constexpr bool operator==(Lab const& a,
121 Lab const& b) noexcept = default;
122};
123
131template <class T>
132 requires(std::integral<T> || std::floating_point<T>)
141
148 T a;
149
156 T b;
157
165
173 [[nodiscard]] friend constexpr bool operator==(Lab const& a,
174 Lab const& b) noexcept = default;
175};
176
185template <class T>
186 requires(std::integral<T> || std::floating_point<T>)
195
202 T a;
203
210 T b;
211
215 float weight;
216
224 [[nodiscard]] friend constexpr bool operator==(Lab const& a,
225 Lab const& b) noexcept = default;
226};
227
236template <class T>
237 requires(std::integral<T> || std::floating_point<T>)
246
253 T a;
254
261 T b;
262
270
274 float weight;
275
283 [[nodiscard]] friend constexpr bool operator==(Lab const& a,
284 Lab const& b) noexcept = default;
285};
286
293template <class T, ColorFlags Flags>
294[[nodiscard]] constexpr T lightness(Lab<T, Flags> color) noexcept
295{
296 if constexpr (weightset(Flags) && std::floating_point<T>) {
297 return color.lightness / static_cast<T>(color.weight);
298 } else {
299 return color.lightness;
300 }
301}
302
309template <class T, ColorFlags Flags>
310[[nodiscard]] constexpr T a(Lab<T, Flags> color) noexcept
311{
312 if constexpr (weightset(Flags) && std::floating_point<T>) {
313 return color.a / static_cast<T>(color.weight);
314 } else {
315 return color.a;
316 }
317}
318
325template <class T, ColorFlags Flags>
326[[nodiscard]] constexpr T b(Lab<T, Flags> color) noexcept
327{
328 if constexpr (weightset(Flags) && std::floating_point<T>) {
329 return color.b / static_cast<T>(color.weight);
330 } else {
331 return color.b;
332 }
333}
334
339
344
349
354
359
364
369
374
381template <class T, ColorFlags Flags>
382inline std::ostream& operator<<(std::ostream& out, Lab<T, Flags> const& c)
383{
384 out << "Lightness: " << c.lightness << " a: " << c.a << " b: " << c.b;
385 if constexpr (alphaset(Flags)) {
386 out << " Alpha: " << +c.alpha;
387 }
388 if constexpr (weightset(Flags)) {
389 out << " Weight: " << c.weight;
390 }
391 return out;
392}
393
397} // namespace ufo
398
402template <class T, ufo::ColorFlags Flags>
403struct std::formatter<ufo::Lab<T, Flags>> {
404 constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
405
406 auto format(ufo::Lab<T, Flags> const& c, std::format_context& ctx) const
407 {
408 auto out =
409 std::format_to(ctx.out(), "Lightness: {} a: {} b: {}", c.lightness, c.a, c.b);
410 if constexpr (ufo::alphaset(Flags)) {
411 out = std::format_to(out, " Alpha: {}", +c.alpha);
412 }
413 if constexpr (ufo::weightset(Flags)) {
414 out = std::format_to(out, " Weight: {}", c.weight);
415 }
416 return out;
417 }
418};
419
420#endif // UFO_VISION_COLOR_LAB_HPP
consteval bool alphaset(ColorFlags flags) noexcept
Returns true if the Alpha flag is set.
Definition flags.hpp:114
consteval bool weightset(ColorFlags flags) noexcept
Returns true if the Weight flag is set.
Definition flags.hpp:122
All vision-related classes and functions.
Definition cloud.hpp:49
constexpr T b(Lab< T, Flags > color) noexcept
Returns the un-weighted blue–yellow axis value.
Definition lab.hpp:326
constexpr T a(Lab< T, Flags > color) noexcept
Returns the un-weighted green–red axis value.
Definition lab.hpp:310
constexpr T lightness(Lab< T, Flags > color) noexcept
Returns the un-weighted lightness value.
Definition lab.hpp:294
friend constexpr bool operator==(Lab const &a, Lab const &b) noexcept=default
Returns true if a and b are equal.
T a
Green–red axis.
Definition lab.hpp:148
T b
Blue–yellow axis.
Definition lab.hpp:156
T lightness
Lightness channel.
Definition lab.hpp:140
T b
Blue–yellow axis (possibly pre-multiplied by weight).
Definition lab.hpp:261
friend constexpr bool operator==(Lab const &a, Lab const &b) noexcept=default
Returns true if a and b are equal.
T lightness
Lightness channel (possibly pre-multiplied by weight).
Definition lab.hpp:245
float weight
Accumulation weight (positive).
Definition lab.hpp:274
T a
Green–red axis (possibly pre-multiplied by weight).
Definition lab.hpp:253
friend constexpr bool operator==(Lab const &a, Lab const &b) noexcept=default
Returns true if a and b are equal.
T a
Green–red axis.
Definition lab.hpp:103
T lightness
Lightness channel.
Definition lab.hpp:95
T b
Blue–yellow axis.
Definition lab.hpp:111
friend constexpr bool operator==(Lab const &a, Lab const &b) noexcept=default
Returns true if a and b are equal.
T lightness
Lightness channel (possibly pre-multiplied by weight).
Definition lab.hpp:194
T b
Blue–yellow axis (possibly pre-multiplied by weight).
Definition lab.hpp:210
T a
Green–red axis (possibly pre-multiplied by weight).
Definition lab.hpp:202
float weight
Accumulation weight (positive).
Definition lab.hpp:215
Oklab perceptual color.
Definition lab.hpp:77