UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
gray.hpp
1
45#ifndef UFO_VISION_COLOR_GRAY_HPP
46#define UFO_VISION_COLOR_GRAY_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{
73template <class T = float, ColorFlags Flags = ColorFlags::None>
74 requires(std::integral<T> || std::floating_point<T>)
75struct Gray;
76
84template <class T>
85 requires(std::integral<T> || std::floating_point<T>)
94
102 [[nodiscard]] friend constexpr bool operator==(Gray const& a,
103 Gray const& b) noexcept = default;
104};
105
113template <class T>
114 requires(std::integral<T> || std::floating_point<T>)
123
131
139 [[nodiscard]] friend constexpr bool operator==(Gray const& a,
140 Gray const& b) noexcept = default;
141};
142
150template <class T>
151 requires(std::integral<T> || std::floating_point<T>)
160
164 float weight;
165
173 [[nodiscard]] friend constexpr bool operator==(Gray const& a,
174 Gray const& b) noexcept = default;
175};
176
184template <class T>
185 requires(std::integral<T> || std::floating_point<T>)
194
202
206 float weight;
207
215 [[nodiscard]] friend constexpr bool operator==(Gray const& a,
216 Gray const& b) noexcept = default;
217};
218
225template <class T, ColorFlags Flags>
226[[nodiscard]] constexpr T gray(Gray<T, Flags> color) noexcept
227{
228 if constexpr (weightset(Flags) && std::floating_point<T>) {
229 return color.gray / static_cast<T>(color.weight);
230 } else {
231 return color.gray;
232 }
233}
234
239
244
249
254
259
264
269
274
281template <class T, ColorFlags Flags>
282inline std::ostream& operator<<(std::ostream& out, Gray<T, Flags> const& c)
283{
284 out << "Gray: " << +c.gray;
285 if constexpr (alphaset(Flags)) {
286 out << " Alpha: " << +c.alpha;
287 }
288 if constexpr (weightset(Flags)) {
289 out << " Weight: " << c.weight;
290 }
291 return out;
292}
293
297} // namespace ufo
298
302template <class T, ufo::ColorFlags Flags>
303struct std::formatter<ufo::Gray<T, Flags>> {
304 constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
305
306 auto format(ufo::Gray<T, Flags> const& c, std::format_context& ctx) const
307 {
308 auto out = std::format_to(ctx.out(), "Gray: {}", +c.gray);
309 if constexpr (ufo::alphaset(Flags)) {
310 out = std::format_to(out, " Alpha: {}", +c.alpha);
311 }
312 if constexpr (ufo::weightset(Flags)) {
313 out = std::format_to(out, " Weight: {}", c.weight);
314 }
315 return out;
316 }
317};
318
319#endif // UFO_VISION_COLOR_GRAY_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 gray(Gray< T, Flags > color) noexcept
Returns the un-weighted gray channel value.
Definition gray.hpp:226
constexpr T a(Lab< T, Flags > color) noexcept
Returns the un-weighted green–red axis value.
Definition lab.hpp:310
friend constexpr bool operator==(Gray const &a, Gray const &b) noexcept=default
Returns true if a and b are equal.
T alpha
Alpha channel (possibly pre-multiplied by weight).
Definition gray.hpp:201
float weight
Accumulation weight (positive).
Definition gray.hpp:206
friend constexpr bool operator==(Gray const &a, Gray const &b) noexcept=default
Returns true if a and b are equal.
T gray
Gray channel (possibly pre-multiplied by weight).
Definition gray.hpp:193
friend constexpr bool operator==(Gray const &a, Gray const &b) noexcept=default
Returns true if a and b are equal.
friend constexpr bool operator==(Gray const &a, Gray const &b) noexcept=default
Returns true if a and b are equal.
T gray
Gray channel (possibly pre-multiplied by weight).
Definition gray.hpp:159
float weight
Accumulation weight (positive).
Definition gray.hpp:164
Grayscale color.
Definition gray.hpp:75