Loading...
Searching...
No Matches
pwl.h
Go to the documentation of this file.
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (C) 2019, Raspberry Pi Ltd
*
* Piecewise linear functions interface
*/
#pragma once
#include <algorithm>
#include <functional>
#include <string>
#include <utility>
#include <vector>
#include "libcamera/internal/vector.h"
namespace libcamera {
namespace ipa {
class Pwl
{
public:
using Point = Vector<double, 2>;
struct Interval {
Interval(double _start, double _end)
: start(_start), end(_end) {}
bool contains(double value)
{
return value >= start && value <= end;
}
double clamp(double value)
{
return std::clamp(value, start, end);
}
double length() const { return end - start; }
double start, end;
};
Pwl();
Pwl(const std::vector<Point> &points);
Pwl(std::vector<Point> &&points);
void append(double x, double y, double eps = 1e-6);
bool empty() const { return points_.empty(); }
void clear() { points_.clear(); }
size_t size() const { return points_.size(); }
Interval domain() const;
Interval range() const;
double eval(double x, int *span = nullptr,
bool updateSpan = true) const;
std::pair<Pwl, bool> inverse(double eps = 1e-6) const;
Pwl compose(const Pwl &other, double eps = 1e-6) const;
void map(std::function<void(double x, double y)> f) const;
static Pwl
combine(const Pwl &pwl0, const Pwl &pwl1,
std::function<double(double x, double y0, double y1)> f,
double eps = 1e-6);
Pwl &operator*=(double d);
std::string toString() const;
private:
static void map2(const Pwl &pwl0, const Pwl &pwl1,
std::function<void(double x, double y0, double y1)> f);
void prepend(double x, double y, double eps = 1e-6);
int findSpan(double x, int span) const;
std::vector<Point> points_;
};
} /* namespace ipa */
} /* namespace libcamera */
libcamera::Vector
Vector class.
Definition vector.h:35
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:418
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:134
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:341
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:391
libcamera::ipa::Pwl::compose
Pwl compose(const Pwl &other, double eps=1e-6) const
Compose two piecewise linear functions together.
Definition pwl.cpp:292
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:206
libcamera::ipa::Pwl::domain
Interval domain() const
Get the domain of the piecewise linear function.
Definition pwl.cpp:176
libcamera::ipa::Pwl::inverse
std::pair< Pwl, bool > inverse(double eps=1e-6) const
Compute the inverse function.
Definition pwl.cpp:251
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:407
libcamera::ipa::Pwl::Pwl
Pwl()
Construct an empty piecewise linear function.
Definition pwl.cpp:98
libcamera::ipa::Pwl::range
Interval range() const
Get the range of the piecewise linear function.
Definition pwl.cpp:185
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.