How to get text representation for Vector3f or other types in Eigen library. I see lot of examples that uses .format() which returns WithFormat class. This then can be used with cout. However I'm looking for way to get Vector3f as std:string in some human readable form. Exact formatting isn't too important so if Eigen has any default formatting then that works as well.
Note: I can certainly use stringstream to replace cout but I'm hopping there is more direct way to do this.
The easiest solution I found out, not sure if optimal, is:
static std::string toString(const Eigen::MatrixXd& mat){
std::stringstream ss;
ss << mat;
return ss.str();
}
As far as I know, the stringstream method is the way to go. In fact, in the IO.h file (Eigen::internal::print_matrix
) the developers use stringstreams to obtain the width of each entry.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With