28 template<
typename T,
unsigned int R,
unsigned int C,
29 std::enable_if_t<std::is_arithmetic_v<T>> * =
nullptr>
31 template<
typename T,
unsigned int R,
unsigned int C>
43 for (
const auto &pair : matrices)
44 matrices_[pair.first] = pair.second;
56 const std::string &key_name,
57 const std::string &matrix_name)
66 for (
const auto &value : yaml.
asList()) {
67 unsigned int ct = std::stoul(value[key_name].get<std::string>(
""));
68 std::optional<Matrix<T, R, C>> matrix =
75 matrices_[ct] = *matrix;
78 <<
"Read matrix '" << matrix_name <<
"' for key '" 79 << key_name <<
"' " << ct <<
": " 80 << matrices_[ct].toString();
83 if (matrices_.size() < 1) {
93 ASSERT(matrices_.size() > 0);
95 if (matrices_.size() == 1 ||
96 ct <= matrices_.begin()->first)
97 return matrices_.begin()->second;
99 if (ct >= matrices_.rbegin()->first)
100 return matrices_.rbegin()->second;
102 if (matrices_.find(ct) != matrices_.end())
103 return matrices_[ct];
106 auto iter = matrices_.upper_bound(ct);
107 unsigned int ctUpper = iter->first;
108 unsigned int ctLower = (--iter)->first;
110 double lambda = (ct - ctLower) / static_cast<double>(ctUpper - ctLower);
112 lambda * matrices_[ctUpper] + (1.0 - lambda) * matrices_[ctLower];
117 std::map<unsigned int, Matrix<T, R, C>> matrices_;
MatrixInterpolator(const std::map< unsigned int, Matrix< T, R, C >> &matrices)
Construct a matrix interpolator from a map of matrices.
Definition: matrix_interpolator.h:41
#define LOG(category, severity)
Log a message.
Top-level libcamera namespace.
Definition: backtrace.h:17
ListAdapter asList() const
Wrap a list YamlObject in an adapter that exposes iterators.
Definition: yaml_parser.h:196
#define ASSERT(condition)
Abort program execution if assertion fails.
int readYaml(const libcamera::YamlObject &yaml, const std::string &key_name, const std::string &matrix_name)
Initialize an MatrixInterpolator instance from yaml.
Definition: matrix_interpolator.h:55
bool isList() const
Return whether the YamlObject is a list.
Definition: yaml_parser.h:153
#define LOG_DECLARE_CATEGORY(name)
Declare a category of log messages.
static Matrix identity()
Construct an identity matrix.
Definition: matrix.h:44
A class representing the tree structure of the YAML content.
Definition: yaml_parser.h:25
void reset()
Reset the matrix interpolator content to a single identity matrix.
Definition: matrix_interpolator.h:49
Matrix class.
Definition: matrix.h:31
Class for storing, retrieving, and interpolating matrices.
Definition: matrix_interpolator.h:33