15#include <nlohmann/json.hpp>
29template <
typename Derived>
30void toJson(
const Eigen::MatrixBase<Derived>& mat, nlohmann::json& j) {
33 j = nlohmann::json::array();
34 for (
int col_i = 0; col_i < mat.cols(); ++col_i) {
35 nlohmann::json jcol = nlohmann::json::array();
36 for (
int row_i = 0; row_i < mat.rows(); ++row_i) {
37 jcol.push_back(mat(row_i, col_i));
49 if constexpr (T::RowsAtCompileTime == Eigen::Dynamic || T::ColsAtCompileTime == Eigen::Dynamic) {
52 const auto numCols = j.size();
54 const auto numRows = j.at(0).size();
55 result.resize(numRows, numCols);
57 std::vector<typename T::Scalar> coef;
58 for (
int col_i = 0; col_i < numCols; ++col_i) {
60 std::copy(coef.begin(), coef.end(), result.col(col_i).begin());
66 const int Rows = T::RowsAtCompileTime;
67 const int Cols = T::ColsAtCompileTime;
70 if (Rows == 1 && Cols != -1 && j.size() == Cols &&
71 j[0].type() != nlohmann::json::value_t::array) {
72 std::vector<typename T::Scalar> coef = j;
73 std::copy(coef.begin(), coef.end(), result.row(0).begin());
75 Cols == 1 && Rows != -1 && j.size() == Rows &&
76 j[0].type() != nlohmann::json::value_t::array) {
77 std::vector<typename T::Scalar> coef = j;
78 std::copy(coef.begin(), coef.end(), result.col(0).begin());
82 const auto numCols = j.size();
84 for (
int col_i = 0; col_i < Cols; ++col_i) {
85 std::vector<typename T::Scalar> coef = j[col_i];
86 std::copy(coef.begin(), coef.end(), result.col(col_i).begin());
108 const JointPhysicalProperties& jointProperties,
116 const JointPhysicalProperties& jointProperties);
130 const nlohmann::json& j,
131 const std::string& jointName,
141 const std::string& json,
142 const std::string& jointName,
ParameterLimits parameterLimitsFromJson(const Character &character, const nlohmann::json &j)
std::unordered_map< std::string, ParameterSet > ParameterSets
T fromJson(const nlohmann::json &j)
std::vector< ParameterLimit > ParameterLimits
void toJson(const Eigen::MatrixBase< Derived > &mat, nlohmann::json &j)
void jointPhysicalPropertiesToJson(const JointPhysicalProperties &jointProperties, nlohmann::json &j)
Serializes one joint's physical mass properties.
JointPhysicalProperties jointPhysicalPropertiesFromJson(const nlohmann::json &j, const std::string &jointName, const size_t jointIndex)
Parses one joint's physical mass properties from JSON.
ParameterTransformT< float > ParameterTransform
std::optional< JointPhysicalProperties > jointPhysicalPropertiesFromJsonString(const std::string &json, const std::string &jointName, const size_t jointIndex)
Parses one joint's physical mass properties from its canonical on-disk JSON string.
void parameterSetsToJson(const Character &character, nlohmann::json &j)
void poseConstraintsToJson(const Character &character, nlohmann::json &j)
ParameterTransform parameterTransformFromJson(const Character &character, const nlohmann::json &j)
std::string jointPhysicalPropertiesToJsonString(const JointPhysicalProperties &jointProperties)
Serializes one joint's physical mass properties to its canonical on-disk JSON string.
void parameterTransformToJson(const Character &character, nlohmann::json &j)
ParameterSets parameterSetsFromJson(const Character &character, const nlohmann::json &j)
std::unordered_map< std::string, PoseConstraint > PoseConstraints
void parameterLimitsToJson(const Character &character, nlohmann::json &j)
PoseConstraints poseConstraintsFromJson(const Character &character, const nlohmann::json &j)