36 : data_(std::move(
data))
43 const std::string &key_name,
44 const std::string &value_name)
47 lastInterpolatedKey_.reset();
57 for (
const auto &value : yaml.
asList()) {
58 unsigned int ct = std::stoul(value[key_name].get<std::string>(
""));
59 std::optional<T>
data =
60 value[value_name].get<T>();
68 if (data_.size() < 1) {
78 data_ = std::move(
data);
79 lastInterpolatedKey_.reset();
82 const std::map<unsigned int, T> &
data()
const
91 if (lastInterpolatedKey_.has_value() &&
92 *lastInterpolatedKey_ == key)
93 return lastInterpolatedValue_;
95 auto it = data_.lower_bound(key);
97 if (it == data_.begin())
100 if (it == data_.end())
101 return std::prev(it)->second;
103 if (it->first == key)
106 auto it2 = std::prev(it);
107 double lambda = (key - it2->first) /
static_cast<double>(it->first - it2->first);
108 interpolate(it2->second, it->second, lastInterpolatedValue_, lambda);
109 lastInterpolatedKey_ = key;
111 return lastInterpolatedValue_;
116 dest = a * (1.0 - lambda) + b * lambda;
120 std::map<unsigned int, T> data_;
121 T lastInterpolatedValue_;
122 std::optional<unsigned int> lastInterpolatedKey_;
A class representing a tree structure of values.
Definition value_node.h:27
bool isEmpty() const
Return whether the ValueNode is an empty.
Definition value_node.h:199
ListAdapter asList()
Wrap a list ValueNode in an adapter that exposes iterators.
Definition value_node.h:230
bool isList() const
Return whether the ValueNode is a list.
Definition value_node.h:191
Class for storing, retrieving, and interpolating objects.
Definition interpolator.h:28
const T & getInterpolated(unsigned int key)
Retrieve an interpolated value for the given key.
Definition interpolator.h:87
Interpolator(const std::map< unsigned int, T > &data)
Construct an interpolator from a map of objects.
Definition interpolator.h:31
void setData(std::map< unsigned int, T > &&data)
Set the internal map.
Definition interpolator.h:76
Interpolator()=default
Construct an empty interpolator.
const std::map< unsigned int, T > & data() const
Access the internal map.
Definition interpolator.h:82
int readYaml(const ValueNode &yaml, const std::string &key_name, const std::string &value_name)
Initialize an Interpolator instance from yaml.
Definition interpolator.h:42
Interpolator(std::map< unsigned int, T > &&data)
Construct an interpolator from a map of objects.
Definition interpolator.h:35
void interpolate(const T &a, const T &b, T &dest, double lambda)
Interpolate between two instances of T.
Definition interpolator.h:114
#define LOG_DECLARE_CATEGORY(name)
Declare a category of log messages.
Definition log.h:51
#define LOG(category, severity)
Log a message.
Definition log.h:155
#define ASSERT(condition)
Abort program execution if assertion fails.
Definition log.h:159
The IPA (Image Processing Algorithm) namespace.
Definition af.cpp:58
Top-level libcamera namespace.
Definition backtrace.h:17
Data structure to manage tree of values.