File indexing completed on 2025-01-18 09:11:12
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Utilities/Enumerate.hpp"
0013
0014 #include <iomanip>
0015 #include <iostream>
0016 #include <string>
0017
0018 #include "Eigen/Dense"
0019
0020 namespace Acts {
0021
0022 namespace detail {
0023 inline double roundWithPrecision(double val, int precision) {
0024 if (val < 0 && std::abs(val) * std::pow(10, precision) < 1.) {
0025 return -val;
0026 }
0027 return val;
0028 }
0029 }
0030
0031
0032
0033
0034
0035
0036
0037
0038 template <typename derived_t>
0039 inline std::string toString(const Eigen::MatrixBase<derived_t>& matrix,
0040 int precision = 4, const std::string& offset = "") {
0041 std::ostringstream sout;
0042
0043 sout << std::setiosflags(std::ios::fixed) << std::setprecision(precision);
0044 if (matrix.cols() == 1) {
0045 sout << "(";
0046 for (int i = 0; i < matrix.rows(); ++i) {
0047 double val = detail::roundWithPrecision(matrix(i, 0), precision);
0048 sout << val;
0049 if (i != matrix.rows() - 1) {
0050 sout << ", ";
0051 }
0052 }
0053 sout << ")";
0054 } else {
0055 for (int i = 0; i < matrix.rows(); ++i) {
0056 for (int j = 0; j < matrix.cols(); ++j) {
0057 if (j == 0) {
0058 sout << "(";
0059 }
0060 double val = detail::roundWithPrecision(matrix(i, j), precision);
0061 sout << val;
0062 if (j == matrix.cols() - 1) {
0063 sout << ")";
0064 } else {
0065 sout << ", ";
0066 }
0067 }
0068 if (i != matrix.rows() -
0069 1) {
0070 sout << std::endl;
0071 sout << offset;
0072 }
0073 }
0074 }
0075 return sout.str();
0076 }
0077
0078
0079
0080
0081
0082 inline std::string toString(const Acts::Translation3& translation,
0083 int precision = 4) {
0084 Acts::Vector3 trans;
0085 trans[0] = translation.x();
0086 trans[1] = translation.y();
0087 trans[2] = translation.z();
0088 return toString(trans, precision);
0089 }
0090
0091
0092
0093
0094
0095
0096 inline std::string toString(const Acts::Transform3& transform,
0097 int precision = 4, const std::string& offset = "") {
0098 std::ostringstream sout;
0099 sout << "Translation : " << toString(transform.translation(), precision)
0100 << std::endl;
0101 std::string rotationOffset = offset + " ";
0102 sout << offset << "Rotation : "
0103 << toString(transform.rotation(), precision + 2, rotationOffset);
0104 return sout.str();
0105 }
0106
0107
0108
0109
0110 inline std::string toString(const std::vector<double>& pVector,
0111 int precision = 4) {
0112 std::ostringstream sout;
0113 sout << std::setiosflags(std::ios::fixed) << std::setprecision(precision);
0114 sout << "(";
0115 for (const auto [i, val] : enumerate(pVector)) {
0116 sout << val;
0117 if (i != pVector.size() - 1) {
0118 sout << ", ";
0119 }
0120 }
0121 sout << ")";
0122 return sout.str();
0123 }
0124
0125 }