UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
flags.hpp
1
45#ifndef UFO_VISION_COLOR_FLAGS_HPP
46#define UFO_VISION_COLOR_FLAGS_HPP
47
48// STL
49#include <cstdint>
50#include <format>
51#include <ostream>
52#include <string_view>
53#include <utility>
54
55namespace ufo
56{
70enum class ColorFlags : std::uint8_t {
71 None = 0,
72 Alpha = 1 << 0,
73 Weight = 1 << 1,
74 All = Alpha | Weight
75};
76
83[[nodiscard]] constexpr ColorFlags operator|(ColorFlags a, ColorFlags b) noexcept
84{
85 return static_cast<ColorFlags>(std::to_underlying(a) | std::to_underlying(b));
86}
87
94[[nodiscard]] constexpr ColorFlags operator&(ColorFlags a, ColorFlags b) noexcept
95{
96 return static_cast<ColorFlags>(std::to_underlying(a) & std::to_underlying(b));
97}
98
104[[nodiscard]] constexpr ColorFlags operator~(ColorFlags a) noexcept
105{
106 // Mask to the two defined bits so the result is always a valid combination.
107 return static_cast<ColorFlags>(~std::to_underlying(a) &
108 std::to_underlying(ColorFlags::All));
109}
110
114[[nodiscard]] consteval bool alphaset(ColorFlags flags) noexcept
115{
116 return (flags & ColorFlags::Alpha) != ColorFlags::None;
117}
118
122[[nodiscard]] consteval bool weightset(ColorFlags flags) noexcept
123{
124 return (flags & ColorFlags::Weight) != ColorFlags::None;
125}
126
132[[nodiscard]] constexpr std::string_view toString(ColorFlags flags) noexcept
133{
134 using enum ColorFlags;
135 switch (flags) {
136 case None: return "None";
137 case Alpha: return "Alpha";
138 case Weight: return "Weight";
139 case (Alpha | Weight): return "Alpha|Weight";
140 }
141 std::unreachable();
142}
143
147inline std::ostream& operator<<(std::ostream& os, ColorFlags flags)
148{
149 return os << toString(flags);
150}
151
155} // namespace ufo
156
157template <>
158struct std::formatter<ufo::ColorFlags> : std::formatter<std::string_view> {
159 auto format(ufo::ColorFlags flags, std::format_context& ctx) const
160 {
161 return std::formatter<std::string_view>::format(ufo::toString(flags), ctx);
162 }
163};
164
165#endif // UFO_VISION_COLOR_FLAGS_HPP
consteval bool alphaset(ColorFlags flags) noexcept
Returns true if the Alpha flag is set.
Definition flags.hpp:114
constexpr ColorFlags operator~(ColorFlags a) noexcept
Bitwise complement - inverts all valid ColorFlags bits.
Definition flags.hpp:104
ColorFlags
Bitmask controlling optional fields in a Color specialisation.
Definition flags.hpp:70
consteval bool weightset(ColorFlags flags) noexcept
Returns true if the Weight flag is set.
Definition flags.hpp:122
@ Alpha
Include an alpha channel.
@ None
No optional fields.
@ Weight
Include an accumulation weight.
@ All
All optional fields.
STL namespace.
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 std::string_view toString(ScalarType type) noexcept
Returns a human-readable string for a ScalarType value.
constexpr T a(Lab< T, Flags > color) noexcept
Returns the un-weighted green–red axis value.
Definition lab.hpp:310
Represents a generic scalar weight as a single float value.
Definition weight.hpp:67