Template Function cpplot::to_json(nlohmann::json&, const Eigen::DenseBase<Derived>&)¶
- Defined in File eigen.h
Function Documentation¶
-
template <typename Derived>
voidcpplot
::
to_json
(nlohmann::json &j, const Eigen::DenseBase<Derived> &in) A serialiser to convert dense eigen arrays to json objects using nlohmann::json.
Turns eigen array into a valid json array. 1D arrays become lists: [24.23, 3.4, 8.4] 2D arrays become lists of lists: [[24.23, 3.4, 8.4],[45.23, 5.4, 9.4]]
TODO manage tensors for 3d volumetric plots
Output is written as a row major array. So (assuming eigen’s default settings for orientation), doing:
Eigen::ArrayXXd arr(5,2); arr << 0.0, 0.1, 1.0, 1.1, 2.0, 2.1, 3.0, 3.1, 4.0, 4.1; nlohmann::json j; to_json(j, arr); std::cout << “array element 0,1: ” << arr(0,1) << std::endl; std::cout << “array element 1,0: ” << arr(1,0) << std::endl; std::cout << j << std::endl;
Prints:
array 0,1: 0.1 array 1,0: 1 [[0,0.1],[1,1.1],[2,2.1],[3,3.1],[4,4.1]]
- Template Parameters
Derived
: The derived array or matrix type
- Parameters
j
: An nlohmann::json arrayin
: The matrix or array to serialise into json array