ezconfig
Create C++ Objects from Yaml and Json
Loading...
Searching...
No Matches
smooth.hpp
1// Copyright (c) 2023 Petter Nilsson. MIT License. https://github.com/pettni/ezconfig
2
3#pragma once
4
5#include <yaml-cpp/yaml.h>
6
7#include "eigen.hpp"
8#include "smooth_fwd.hpp"
9
10namespace YAML {
11
12template<typename T>
13bool convert<smooth::SO2<T>>::decode(const Node & yaml, smooth::SO2<T> & obj)
14{
15 if (yaml.IsMap()) {
16 if (yaml["qz"]) {
17 obj = smooth::SO2<T>(yaml["qz"].template as<T>(), yaml["qw"].template as<T>());
18 } else if (yaml["z"]) {
19 obj = smooth::SO2<T>(yaml["z"].template as<T>(), yaml["w"].template as<T>());
20 }
21 return false;
22 } else {
23 obj = smooth::SO2<T>(yaml.template as<T>());
24 }
25 return true;
26}
27
28template<typename T>
29bool convert<smooth::SE2<T>>::decode(const Node & yaml, smooth::SE2<T> & obj)
30{
31 if (yaml["qw"] || yaml["w"]) {
32 obj.so2() = yaml.as<smooth::SO2<T>>();
33 obj.r2() = yaml.as<Eigen::Vector2<T>>();
34 } else if (yaml["yaw"]) {
35 obj.so2() = yaml["yaw"].as<smooth::SO2<T>>();
36 obj.r2() = yaml.as<Eigen::Vector2<T>>();
37 } else {
38 obj.so2() = yaml["orientation"].as<smooth::SO2<T>>();
39 obj.r2() = yaml["translation"].as<Eigen::Vector2<T>>();
40 }
41 return true;
42}
43
44template<typename T>
45bool convert<smooth::SO3<T>>::decode(const Node & yaml, smooth::SO3<T> & obj)
46{
47 obj = smooth::SO3<T>(yaml.as<Eigen::Quaternion<T>>());
48 return true;
49}
50
51template<typename T>
52bool convert<smooth::SE3<T>>::decode(const Node & yaml, smooth::SE3<T> & obj)
53{
54 if (yaml["qw"]) {
55 obj.so3() = yaml.as<smooth::SO3<T>>();
56 obj.r3() = yaml.as<Eigen::Vector3<T>>();
57 } else {
58 obj.so3() = yaml["orientation"].as<smooth::SO3<T>>();
59 obj.r3() = yaml["translation"].as<Eigen::Vector3<T>>();
60 }
61 return true;
62}
63
64} // namespace YAML
YAML forward declarations.
Definition yaml_fwd.hpp:16