libcamera: src/ipa/libipa/pwl.h Source File

libcamera v0.5.0 Supporting cameras in Linux since 2019 |

Loading...
Searching...
No Matches
pwl.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2/*
3 * Copyright (C) 2019, Raspberry Pi Ltd
4 *
5 * Piecewise linear functions interface
6 */
7#pragma once
8
9#include <algorithm>
10#include <functional>
11#include <string>
12#include <utility>
13#include <vector>
14
15#include "libcamera/internal/vector.h"
16
17namespace libcamera {
18
19namespace ipa {
20
21 class Pwl
22{
23public:
24 using Point = Vector<double, 2>;
25
26 struct Interval {
27 Interval(double _start, double _end)
28 : start(_start), end(_end) {}
29
30 bool contains(double value)
31 {
32 return value >= start && value <= end;
33 }
34
35 double clamp(double value)
36 {
37 return std::clamp(value, start, end);
38 }
39
40 double length() const { return end - start; }
41
42 double start, end;
43 };
44
45 Pwl();
46 Pwl(const std::vector<Point> &points);
47 Pwl(std::vector<Point> &&points);
48
49 void append(double x, double y, double eps = 1e-6);
50
51 bool empty() const { return points_.empty(); }
52 void clear() { points_.clear(); }
53 size_t size() const { return points_.size(); }
54
55 Interval domain() const;
56 Interval range() const;
57
58 double eval(double x, int *span = nullptr,
59 bool updateSpan = true) const;
60
61 std::pair<Pwl, bool> inverse(double eps = 1e-6) const;
62 Pwl compose(const Pwl &other, double eps = 1e-6) const;
63
64 void map(std::function<void(double x, double y)> f) const;
65
66 static Pwl
67 combine(const Pwl &pwl0, const Pwl &pwl1,
68 std::function<double(double x, double y0, double y1)> f,
69 double eps = 1e-6);
70
71 Pwl &operator*=(double d);
72
73 std::string toString() const;
74
75private:
76 static void map2(const Pwl &pwl0, const Pwl &pwl1,
77 std::function<void(double x, double y0, double y1)> f);
78 void prepend(double x, double y, double eps = 1e-6);
79 int findSpan(double x, int span) const;
80
81 std::vector<Point> points_;
82};
83
84} /* namespace ipa */
85
86} /* namespace libcamera */
libcamera::Vector
Vector class.
Definition vector.h:34
libcamera::ipa::Pwl
Describe a univariate piecewise linear function in two-dimensional real space.
Definition pwl.h:22
libcamera::ipa::Pwl::toString
std::string toString() const
Assemble and return a string describing the piecewise linear function.
Definition pwl.cpp:415
libcamera::ipa::Pwl::append
void append(double x, double y, double eps=1e-6)
Append a point to the end of the piecewise linear function.
Definition pwl.cpp:135
libcamera::ipa::Pwl::map
void map(std::function< void(double x, double y)> f) const
Apply function to (x, y) values at every control point.
Definition pwl.cpp:338
libcamera::ipa::Pwl::combine
static Pwl combine(const Pwl &pwl0, const Pwl &pwl1, std::function< double(double x, double y0, double y1)> f, double eps=1e-6)
Combine two Pwls.
Definition pwl.cpp:388
libcamera::ipa::Pwl::compose
Pwl compose(const Pwl &other, double eps=1e-6) const
Compose two piecewise linear functions together.
Definition pwl.cpp:289
libcamera::ipa::Pwl::empty
bool empty() const
Check if the piecewise linear function is empty.
Definition pwl.h:51
libcamera::ipa::Pwl::eval
double eval(double x, int *span=nullptr, bool updateSpan=true) const
Evaluate the piecewise linear function.
Definition pwl.cpp:207
libcamera::ipa::Pwl::domain
Interval domain() const
Get the domain of the piecewise linear function.
Definition pwl.cpp:177
libcamera::ipa::Pwl::inverse
std::pair< Pwl, bool > inverse(double eps=1e-6) const
Compute the inverse function.
Definition pwl.cpp:248
libcamera::ipa::Pwl::Point
Vector< double, 2 > Point
Describe a point in two-dimensional real space.
Definition pwl.h:24
libcamera::ipa::Pwl::clear
void clear()
Clear the piecewise linear function.
Definition pwl.h:52
libcamera::ipa::Pwl::size
size_t size() const
Retrieve the number of points in the piecewise linear function.
Definition pwl.h:53
libcamera::ipa::Pwl::operator*=
Pwl & operator*=(double d)
Multiply the piecewise linear function.
Definition pwl.cpp:404
libcamera::ipa::Pwl::Pwl
Pwl()
Construct an empty piecewise linear function.
Definition pwl.cpp:99
libcamera::ipa::Pwl::range
Interval range() const
Get the range of the piecewise linear function.
Definition pwl.cpp:186
libcamera::ipa
The IPA (Image Processing Algorithm) namespace.
Definition af.cpp:58
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
libcamera::ipa::Pwl::Interval::clamp
double clamp(double value)
Clamp a value such that it is within the interval.
Definition pwl.h:35
libcamera::ipa::Pwl::Interval::start
double start
Start of the interval.
Definition pwl.h:42
libcamera::ipa::Pwl::Interval::Interval
Interval(double _start, double _end)
Construct an interval.
Definition pwl.h:27
libcamera::ipa::Pwl::Interval::end
double end
End of the interval.
Definition pwl.h:42
libcamera::ipa::Pwl::Interval::contains
bool contains(double value)
Check if a given value falls within the interval.
Definition pwl.h:30
libcamera::ipa::Pwl::Interval::length
double length() const
Compute the length of the interval.
Definition pwl.h:40
vector.h
Vector class.