File indexing completed on 2025-12-11 09:40:23
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Geometry/GeometryContext.hpp"
0013 #include "Acts/Surfaces/Surface.hpp"
0014 #include "ActsPlugins/Json/ActsJson.hpp"
0015 #include "ActsPlugins/Json/AlgebraJsonConverter.hpp"
0016 #include "ActsPlugins/Json/SurfaceBoundsJsonConverter.hpp"
0017
0018 #include <memory>
0019 #include <string>
0020 #include <tuple>
0021 #include <utility>
0022 #include <vector>
0023
0024 #include <nlohmann/json.hpp>
0025
0026
0027
0028 namespace Acts {
0029 class ISurfaceMaterial;
0030
0031 using SurfaceAndMaterialWithContext =
0032 std::tuple<std::shared_ptr<const Acts::Surface>,
0033 std::shared_ptr<const Acts::ISurfaceMaterial>,
0034 Acts::GeometryContext>;
0035
0036
0037
0038
0039 void to_json(nlohmann::json& j, const SurfaceAndMaterialWithContext& surface);
0040
0041
0042
0043
0044
0045 void to_json(nlohmann::json& j, const Surface& surface);
0046
0047
0048
0049
0050
0051 void to_json(nlohmann::json& j, const std::shared_ptr<const Surface>& surface);
0052
0053
0054
0055
0056
0057
0058 void toJson(nlohmann::json& j, const std::shared_ptr<const Surface>& surface,
0059 const Acts::GeometryContext& gctx);
0060
0061
0062
0063
0064
0065
0066 std::shared_ptr<Surface> surfaceFromJson(const nlohmann::json& j);
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 template <typename surface_t, typename bounds_t>
0077 std::shared_ptr<surface_t> surfaceFromJsonT(const nlohmann::json& j) {
0078 nlohmann::json jTransform = j["transform"];
0079 Transform3 sTransform = Transform3JsonConverter::fromJson(jTransform);
0080 if constexpr (std::is_same_v<bounds_t, void>) {
0081 return Surface::makeShared<surface_t>(sTransform);
0082 } else {
0083 nlohmann::json jBounds = j["bounds"];
0084 auto sBounds = SurfaceBoundsJsonConverter::fromJson<bounds_t>(jBounds);
0085 return Surface::makeShared<surface_t>(sTransform, std::move(sBounds));
0086 }
0087 }
0088
0089 namespace SurfaceJsonConverter {
0090
0091 struct Options {
0092
0093 Transform3JsonConverter::Options transformOptions =
0094 Transform3JsonConverter::Options{};
0095
0096 bool writeMaterial = true;
0097
0098 bool portal = false;
0099 };
0100
0101
0102
0103
0104
0105
0106
0107
0108 nlohmann::json toJson(const GeometryContext& gctx, const Surface& surface,
0109 const Options& options = Options{});
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120 nlohmann::json toJsonDetray(const GeometryContext& gctx, const Surface& surface,
0121 const Options& options = Options{});
0122
0123
0124
0125
0126
0127
0128 std::shared_ptr<Surface> fromJson(const nlohmann::json& jSurface);
0129
0130 }
0131
0132
0133 NLOHMANN_JSON_SERIALIZE_ENUM(
0134 Surface::SurfaceType,
0135 {{Surface::SurfaceType::Cone, "ConeSurface"},
0136 {Surface::SurfaceType::Cylinder, "CylinderSurface"},
0137 {Surface::SurfaceType::Disc, "DiscSurface"},
0138 {Surface::SurfaceType::Perigee, "PerigeeSurface"},
0139 {Surface::SurfaceType::Plane, "PlaneSurface"},
0140 {Surface::SurfaceType::Straw, "StrawSurface"},
0141 {Surface::SurfaceType::Curvilinear, "CurvilinearSurface"},
0142 {Surface::SurfaceType::Other, "Other"}})
0143
0144 }