File indexing completed on 2026-09-27 08:14:28
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsPlugins/Json/ExtentJsonConverter.hpp"
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Utilities/BinningType.hpp"
0013 #include "Acts/Utilities/Enumerate.hpp"
0014 #include "Acts/Utilities/RangeXD.hpp"
0015 #include "ActsPlugins/Json/UtilitiesJsonConverter.hpp"
0016
0017 #include <array>
0018 #include <iterator>
0019 #include <vector>
0020
0021 void Acts::to_json(nlohmann::json& j, const Acts::ExtentEnvelope& e) {
0022 for (auto aDir : allAxisDirections()) {
0023 if (e[aDir] != zeroEnvelope) {
0024 j[axisDirectionName(aDir)] = Range1D<double>(e[aDir][0], e[aDir][1]);
0025 }
0026 }
0027 }
0028
0029 void Acts::from_json(const nlohmann::json& j, Acts::ExtentEnvelope& e) {
0030 for (const auto& [key, value] : j.items()) {
0031 AxisDirection aDir = axisDirectionFromName(key);
0032 e[aDir] = {value["min"].get<double>(), value["max"].get<double>()};
0033 }
0034 }
0035
0036 void Acts::to_json(nlohmann::json& j, const Acts::Extent& e) {
0037 {
0038 nlohmann::json jrange;
0039 const auto& xrange = e.range();
0040 for (auto ibv : allAxisDirections()) {
0041 if (e.constrains(ibv)) {
0042 jrange[axisDirectionName(ibv)] = xrange[toUnderlying(ibv)];
0043 }
0044 }
0045 j["range"] = jrange;
0046 }
0047
0048 {
0049 nlohmann::json jenvelope;
0050 const auto& envelope = e.envelope();
0051 for (auto ibv : allAxisDirections()) {
0052 if (envelope[ibv] != zeroEnvelope) {
0053 jenvelope[axisDirectionName(ibv)] =
0054 Range1D<double>(envelope[ibv][0], envelope[ibv][1]);
0055 }
0056 }
0057 if (!jenvelope.empty()) {
0058 j["envelope"] = jenvelope;
0059 }
0060 }
0061 }
0062
0063 void Acts::from_json(const nlohmann::json& j, Acts::Extent& e) {
0064 const auto& jrange = j["range"];
0065
0066 for (const auto& [key, value] : jrange.items()) {
0067 AxisDirection bval = axisDirectionFromName(key);
0068 e.set(bval, value["min"], value["max"]);
0069 }
0070
0071 if (j.contains("envelope")) {
0072 const auto& jenvelope = j["envelope"];
0073 ExtentEnvelope envelope;
0074
0075 for (const auto& [key, value] : jenvelope.items()) {
0076 AxisDirection bval = axisDirectionFromName(key);
0077 envelope[bval] = {value["min"], value["max"]};
0078 }
0079
0080 e.setEnvelope(envelope);
0081 }
0082 }