Skip to content
Snippets Groups Projects
Commit cfe4be1c authored by Raphael Grimm's avatar Raphael Grimm
Browse files

Add VirtualRobot::json::posquatArray2eigen4fVector

parent 2edac601
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
#include "converters.h"
namespace VirtualRobot::json
{
Eigen::Matrix4f posquat2eigen4f(const std::string& str)
......@@ -24,7 +25,28 @@ namespace VirtualRobot::json
j.at("qw").get<float>()
);
}
}
std::vector<Eigen::Matrix4f> posquatArray2eigen4fVector(const std::string& str)
{
return posquatArray2eigen4fVector(::nlohmann::json::parse(str));
}
std::vector<Eigen::Matrix4f> posquatArray2eigen4fVector(const char* str)
{
return posquatArray2eigen4fVector(::nlohmann::json::parse(str));
}
std::vector<Eigen::Matrix4f> posquatArray2eigen4fVector(const nlohmann::json& j)
{
if (!j.is_array())
{
throw std::invalid_argument{"posquatArray2eigen4fVector: json has to be an array"};
}
std::vector<Eigen::Matrix4f> result;
result.reserve(j.size());
for (const auto& element : j)
{
result.emplace_back(posquat2eigen4f(element));
}
return result;
}
}
......@@ -10,4 +10,8 @@ namespace VirtualRobot::json
Eigen::Matrix4f posquat2eigen4f(const std::string& str);
Eigen::Matrix4f posquat2eigen4f(const char* str);
Eigen::Matrix4f posquat2eigen4f(const nlohmann::json& j);
std::vector<Eigen::Matrix4f> posquatArray2eigen4fVector(const std::string& str);
std::vector<Eigen::Matrix4f> posquatArray2eigen4fVector(const char* str);
std::vector<Eigen::Matrix4f> posquatArray2eigen4fVector(const nlohmann::json& j);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment