File indexing completed on 2025-12-15 09:42:29
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 template <typename ObjType>
0034 concept hasPrintOperator = requires(const ObjType& obj, std::ostream& ostr) {
0035 { ostr << obj } -> std::same_as<std::ostream&>;
0036 };
0037
0038
0039
0040
0041
0042
0043
0044
0045 template <typename derived_t>
0046 inline std::string toString(const Eigen::MatrixBase<derived_t>& matrix,
0047 int precision = 4, const std::string& offset = "") {
0048 std::ostringstream sout;
0049
0050 sout << std::setiosflags(std::ios::fixed) << std::setprecision(precision);
0051 if (matrix.cols() == 1) {
0052 sout << "(";
0053 for (int i = 0; i < matrix.rows(); ++i) {
0054 double val = detail::roundWithPrecision(matrix(i, 0), precision);
0055 sout << val;
0056 if (i != matrix.rows() - 1) {
0057 sout << ", ";
0058 }
0059 }
0060 sout << ")";
0061 } else {
0062 for (int i = 0; i < matrix.rows(); ++i) {
0063 for (int j = 0; j < matrix.cols(); ++j) {
0064 if (j == 0) {
0065 sout << "(";
0066 }
0067 double val = detail::roundWithPrecision(matrix(i, j), precision);
0068 sout << val;
0069 if (j == matrix.cols() - 1) {
0070 sout << ")";
0071 } else {
0072 sout << ", ";
0073 }
0074 }
0075 if (i != matrix.rows() -
0076 1) {
0077 sout << std::endl;
0078 sout << offset;
0079 }
0080 }
0081 }
0082 return sout.str();
0083 }
0084
0085
0086
0087
0088
0089 inline std::string toString(const Acts::Translation3& translation,
0090 int precision = 4) {
0091 Acts::Vector3 trans;
0092 trans[0] = translation.x();
0093 trans[1] = translation.y();
0094 trans[2] = translation.z();
0095 return toString(trans, precision);
0096 }
0097
0098
0099
0100
0101
0102
0103 inline std::string toString(const Acts::Transform3& transform,
0104 int precision = 4, const std::string& offset = "") {
0105 std::ostringstream sout;
0106 sout << "Translation : " << toString(transform.translation(), precision)
0107 << std::endl;
0108 std::string rotationOffset = offset + " ";
0109 sout << offset << "Rotation : "
0110 << toString(transform.rotation(), precision + 2, rotationOffset);
0111 return sout.str();
0112 }
0113
0114
0115
0116
0117
0118 inline std::string toString(const std::vector<double>& pVector,
0119 int precision = 4) {
0120 std::ostringstream sout;
0121 sout << std::setiosflags(std::ios::fixed) << std::setprecision(precision);
0122 sout << "(";
0123 for (const auto [i, val] : enumerate(pVector)) {
0124 sout << val;
0125 if (i != pVector.size() - 1) {
0126 sout << ", ";
0127 }
0128 }
0129 sout << ")";
0130 return sout.str();
0131 }
0132
0133 }