UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
lch.hpp
1
45#ifndef UFO_VISION_COLOR_LCH_HPP
46#define UFO_VISION_COLOR_LCH_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 Lch;
78
86template <class T>
87 requires(std::integral<T> || std::floating_point<T>)
96
104
112
120 [[nodiscard]] friend constexpr bool operator==(Lch const& a,
121 Lch const& b) noexcept = default;
122};
123
131template <class T>
132 requires(std::integral<T> || std::floating_point<T>)
141
149
157
165
173 [[nodiscard]] friend constexpr bool operator==(Lch const& a,
174 Lch const& b) noexcept = default;
175};
176
185template <class T>
186 requires(std::integral<T> || std::floating_point<T>)
195
203
211
215 float weight;
216
224 [[nodiscard]] friend constexpr bool operator==(Lch const& a,
225 Lch const& b) noexcept = default;
226};
227
236template <class T>
237 requires(std::integral<T> || std::floating_point<T>)
246
254
262
270
274 float weight;
275
283 [[nodiscard]] friend constexpr bool operator==(Lch const& a,
284 Lch const& b) noexcept = default;
285};
286
293template <class T, ColorFlags Flags>
294[[nodiscard]] constexpr T lightness(Lch<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 chroma(Lch<T, Flags> color) noexcept
311{
312 if constexpr (weightset(Flags) && std::floating_point<T>) {
313 return color.chroma / static_cast<T>(color.weight);
314 } else {
315 return color.chroma;
316 }
317}
318
325template <class T, ColorFlags Flags>
326[[nodiscard]] constexpr T hue(Lch<T, Flags> color) noexcept
327{
328 if constexpr (weightset(Flags) && std::floating_point<T>) {
329 return color.hue / static_cast<T>(color.weight);
330 } else {
331 return color.hue;
332 }
333}
334
339
344
349
354
359
364
369
374
381template <class T, ColorFlags Flags>
382inline std::ostream& operator<<(std::ostream& out, Lch<T, Flags> const& c)
383{
384 out << "Lightness: " << c.lightness << " Chroma: " << c.chroma << " Hue: " << c.hue;
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::Lch<T, Flags>> {
404 constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
405
406 auto format(ufo::Lch<T, Flags> const& c, std::format_context& ctx) const
407 {
408 auto out = std::format_to(ctx.out(), "Lightness: {} Chroma: {} Hue: {}", c.lightness,
409 c.chroma, c.hue);
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_LCH_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 chroma(Lch< T, Flags > color) noexcept
Returns the un-weighted chroma value.
Definition lch.hpp:310
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
constexpr T hue(Lch< T, Flags > color) noexcept
Returns the un-weighted hue angle value.
Definition lch.hpp:326
friend constexpr bool operator==(Lch const &a, Lch const &b) noexcept=default
Returns true if a and b are equal.
T chroma
Chroma (radius).
Definition lch.hpp:148
T lightness
Lightness channel.
Definition lch.hpp:140
T hue
Hue angle in degrees.
Definition lch.hpp:156
friend constexpr bool operator==(Lch const &a, Lch const &b) noexcept=default
Returns true if a and b are equal.
T hue
Hue angle (possibly pre-multiplied by weight).
Definition lch.hpp:261
T chroma
Chroma (possibly pre-multiplied by weight).
Definition lch.hpp:253
float weight
Accumulation weight (positive).
Definition lch.hpp:274
T lightness
Lightness channel (possibly pre-multiplied by weight).
Definition lch.hpp:245
friend constexpr bool operator==(Lch const &a, Lch const &b) noexcept=default
Returns true if a and b are equal.
T chroma
Chroma (radius).
Definition lch.hpp:103
T hue
Hue angle in degrees.
Definition lch.hpp:111
T lightness
Lightness channel.
Definition lch.hpp:95
T chroma
Chroma (possibly pre-multiplied by weight).
Definition lch.hpp:202
friend constexpr bool operator==(Lch const &a, Lch const &b) noexcept=default
Returns true if a and b are equal.
T hue
Hue angle (possibly pre-multiplied by weight).
Definition lch.hpp:210
T lightness
Lightness channel (possibly pre-multiplied by weight).
Definition lch.hpp:194
float weight
Accumulation weight (positive).
Definition lch.hpp:215
OkLch color.
Definition lch.hpp:77