ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
IJsonConvertible.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <fmt/format.h>
11 
12 #include <Eigen/Core>
13 
14 #include "CVCoreLib.h"
15 #include "Eigen.h"
16 
18 namespace Json {
19 class Value;
20 } // namespace Json
22 
23 namespace cloudViewer {
24 namespace utility {
25 
31 Json::Value CV_CORE_LIB_API StringToJson(const std::string &json_str);
32 
37 std::string CV_CORE_LIB_API JsonToString(const Json::Value &json);
38 
42 public:
43  virtual ~IJsonConvertible() {}
44 
45 public:
46  virtual bool ConvertToJsonValue(Json::Value &value) const = 0;
47  virtual bool ConvertFromJsonValue(const Json::Value &value) = 0;
48 
50  virtual std::string ToString() const;
51 
52 public:
53  static bool EigenVector3dFromJsonArray(Eigen::Vector3d &vec,
54  const Json::Value &value);
55  static bool EigenVector3dToJsonArray(const Eigen::Vector3d &vec,
56  Json::Value &value);
57  static bool EigenVector4dFromJsonArray(Eigen::Vector4d &vec,
58  const Json::Value &value);
59  static bool EigenVector4dToJsonArray(const Eigen::Vector4d &vec,
60  Json::Value &value);
61  static bool EigenMatrix3dFromJsonArray(Eigen::Matrix3d &mat,
62  const Json::Value &value);
63  static bool EigenMatrix3dToJsonArray(const Eigen::Matrix3d &mat,
64  Json::Value &value);
65  static bool EigenMatrix4dFromJsonArray(Eigen::Matrix4d &mat,
66  const Json::Value &value);
67  static bool EigenMatrix4dToJsonArray(const Eigen::Matrix4d &mat,
68  Json::Value &value);
69  static bool EigenMatrix4dFromJsonArray(Eigen::Matrix4d_u &mat,
70  const Json::Value &value);
71  static bool EigenMatrix4dToJsonArray(const Eigen::Matrix4d_u &mat,
72  Json::Value &value);
73  static bool EigenMatrix6dFromJsonArray(Eigen::Matrix6d &mat,
74  const Json::Value &value);
75  static bool EigenMatrix6dToJsonArray(const Eigen::Matrix6d &mat,
76  Json::Value &value);
77  static bool EigenMatrix6dFromJsonArray(Eigen::Matrix6d_u &mat,
78  const Json::Value &value);
79  static bool EigenMatrix6dToJsonArray(const Eigen::Matrix6d_u &mat,
80  Json::Value &value);
81 };
82 
83 } // namespace utility
84 } // namespace cloudViewer
85 
86 namespace fmt {
87 template <>
88 struct formatter<Json::Value> {
89  template <typename FormatContext>
90  auto format(const Json::Value &value,
91  FormatContext &ctx) const -> decltype(ctx.out()) {
92  return format_to(ctx.out(), "{}",
94  }
95 
96  template <typename ParseContext>
97  constexpr auto parse(ParseContext &ctx) -> decltype(ctx.begin()) {
98  return ctx.begin();
99  }
100 };
101 
102 } // namespace fmt
#define CV_CORE_LIB_API
Definition: CVCoreLibWin.h:15
virtual bool ConvertToJsonValue(Json::Value &value) const =0
virtual bool ConvertFromJsonValue(const Json::Value &value)=0
Eigen::Matrix< double, 6, 6, Eigen::DontAlign > Matrix6d_u
Definition: Eigen.h:112
Eigen::Matrix< double, 4, 4, Eigen::DontAlign > Matrix4d_u
Definition: Eigen.h:113
Eigen::Matrix< double, 6, 6 > Matrix6d
Extending Eigen namespace by adding frequently used matrix type.
Definition: Eigen.h:106
Json::Value StringToJson(const std::string &json_str)
Parse string and conver to Json::value. Throws exception if the conversion is invalid.
std::string JsonToString(const Json::Value &json)
Serialize a Json::Value to a string.
Generic file read and write utility for python interface.
constexpr auto parse(ParseContext &ctx) -> decltype(ctx.begin())
auto format(const Json::Value &value, FormatContext &ctx) const -> decltype(ctx.out())