5 #ifndef CNOID_UTIL_EIGEN_ARCHIVE_H
6 #define CNOID_UTIL_EIGEN_ARCHIVE_H
10 #include <fmt/format.h>
12 #include <initializer_list>
13 #include "exportdecl.h"
17 template<
typename Derived>
20 const int nr = x.rows();
21 const int nc = x.cols();
22 if(listing->
size() != nr * nc){
24 fmt::format(
"A {0} x {1} matrix / vector value is expected", nr, nc));
27 for(
int i=0; i < nr; ++i){
28 for(
int j=0; j < nc; ++j){
29 x(i, j) = (*listing)[index++].toDouble();
35 template<
typename Derived>
42 template<
typename Derived>
43 bool read(
const Mapping* mapping,
const std::string& key, Eigen::MatrixBase<Derived>& x)
54 template<
typename Derived>
55 bool read(
const Mapping* mapping, std::initializer_list<const char*> keys, Eigen::MatrixBase<Derived>& x)
57 for(
auto& key : keys){
58 if(
read(mapping, key, x)){
66 template<
typename Derived>
67 bool read(
const Mapping& mapping,
const std::string& key, Eigen::MatrixBase<Derived>& x)
69 return read(&mapping, key, x);
73 template<
typename Derived>
74 bool read(
const Mapping& mapping, std::initializer_list<const char*> keys, Eigen::MatrixBase<Derived>& x)
76 return read(&mapping, keys, x);
80 template<
typename Scalar,
int Dim,
int Mode>
81 bool read(
const Mapping* mapping,
const std::string& key, Eigen::Transform<Scalar, Dim, Mode>& T)
83 return read(mapping, key, T.matrix());
87 template<
typename Scalar,
int Dim,
int Mode>
88 bool read(
const Mapping* mapping, std::initializer_list<const char*> keys, Eigen::Transform<Scalar, Dim, Mode>& T)
91 for(
auto& key : keys){
92 if(
read(*mapping, key, M)){
100 template<
typename Scalar,
int Dim,
int Mode>
101 bool read(
const Mapping& mapping,
const std::string& key, Eigen::Transform<Scalar, Dim, Mode>& T)
103 return read(&mapping, key, T.matrix());
107 template<
typename Scalar,
int Dim,
int Mode>
108 bool read(
const Mapping& mapping, std::initializer_list<const char*> keys, Eigen::Transform<Scalar, Dim, Mode>& T)
110 return read(&mapping, keys, T.matrix());
114 template<
typename Derived>
115 void readEx(
const Mapping* mapping,
const std::string& key, Eigen::MatrixBase<Derived>& x)
117 if(!
read(mapping, key, x)){
123 template<
typename Derived>
124 void readEx(
const Mapping* mapping, std::initializer_list<const char*> keys, Eigen::MatrixBase<Derived>& x)
126 for(
auto& key : keys){
127 if(
read(mapping, key, x)){
131 if(keys.begin() != keys.end()){
137 template<
typename Derived>
138 void readEx(
const Mapping& mapping,
const std::string& key, Eigen::MatrixBase<Derived>& x)
144 template<
typename Derived>
148 const int nr = x.rows();
149 const int nc = x.cols();
151 for(
int i=0; i < nr; ++i){
155 for(
int i=0; i < nr; ++i){
157 for(
int j=0; j < nc; ++j){
166 template<
typename Derived>
169 return *
write(&mapping, key, x);
173 template<
typename Scalar,
int Dim,
int Mode>
176 return write(mapping, key, T.matrix());
180 template<
typename Scalar,
int Dim,
int Mode>
183 return *
write(&mapping, key, T.matrix());
190 CNOID_EXPORT
bool readAngleAxis(
const Mapping* mapping,
const std::string& key, Eigen::AngleAxisd& aa);
191 CNOID_EXPORT
bool readAngleAxis(
const Mapping* mapping, std::initializer_list<const char*> keys, Eigen::AngleAxisd& aa);
192 CNOID_EXPORT
bool readAngleAxis(
const Mapping& mapping,
const std::string& key, Eigen::AngleAxisd& aa);
193 CNOID_EXPORT
bool readDegreeAngleAxis(
const Mapping& mapping,
const std::string& key, Eigen::AngleAxisd& aa);
194 CNOID_EXPORT
bool readRadianAngleAxis(
const Mapping& mapping,
const std::string& key, Eigen::AngleAxisd& aa);
196 CNOID_EXPORT Listing*
writeDegreeAngleAxis(Mapping* mapping,
const std::string& key,
const Eigen::AngleAxisd& aa);
197 CNOID_EXPORT Listing&
writeDegreeAngleAxis(Mapping& mapping,
const std::string& key,
const Eigen::AngleAxisd& aa);
198 CNOID_EXPORT Listing*
writeRadianAngleAxis_(Mapping* mapping,
const std::string& key,
const Eigen::AngleAxisd& aa);
200 CNOID_EXPORT
bool read(
201 const Mapping& mapping,
const std::string& key, std::function<
void(
const Eigen::Vector3d& value)> setterFunc);
204 CNOID_EXPORT Listing*
writeAngleAxis(Mapping* mapping,
const std::string& key,
const Eigen::AngleAxisd& aa);
206 CNOID_EXPORT Listing&
writeAngleAxis(Mapping& mapping,
const std::string& key,
const Eigen::AngleAxisd& aa);
208 [[deprecated(
"Use readAngleAxis")]]
209 CNOID_EXPORT
bool read(
const Mapping& mapping,
const std::string& key, Eigen::AngleAxisd& aa);
210 [[deprecated(
"Use writeDegreeAngleAxis")]]
211 CNOID_EXPORT Listing&
write(Mapping& mapping,
const std::string& key,
const Eigen::AngleAxisd& aa);