File indexing completed on 2025-01-18 09:27:42
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/Plugins/Json/ActsJson.hpp"
0014 #include "Acts/Plugins/Json/AlgebraJsonConverter.hpp"
0015 #include "Acts/Plugins/Json/SurfaceBoundsJsonConverter.hpp"
0016 #include "Acts/Surfaces/Surface.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 void to_json(nlohmann::json& j, const SurfaceAndMaterialWithContext& surface);
0038
0039
0040
0041
0042 void to_json(nlohmann::json& j, const Surface& surface);
0043
0044
0045
0046
0047 void to_json(nlohmann::json& j, const std::shared_ptr<const Surface>& surface);
0048
0049
0050
0051
0052
0053
0054 void toJson(nlohmann::json& j, const std::shared_ptr<const Surface>& surface,
0055 const Acts::GeometryContext& gctx);
0056
0057
0058
0059
0060
0061
0062 std::shared_ptr<Surface> surfaceFromJson(const nlohmann::json& j);
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 template <typename surface_t, typename bounds_t>
0073 std::shared_ptr<surface_t> surfaceFromJsonT(const nlohmann::json& j) {
0074 nlohmann::json jTransform = j["transform"];
0075 Transform3 sTransform = Transform3JsonConverter::fromJson(jTransform);
0076 if constexpr (std::is_same_v<bounds_t, void>) {
0077 return Surface::makeShared<surface_t>(sTransform);
0078 } else {
0079 nlohmann::json jBounds = j["bounds"];
0080 auto sBounds = SurfaceBoundsJsonConverter::fromJson<bounds_t>(jBounds);
0081 return Surface::makeShared<surface_t>(sTransform, std::move(sBounds));
0082 }
0083 }
0084
0085 namespace SurfaceJsonConverter {
0086
0087 struct Options {
0088
0089 Transform3JsonConverter::Options transformOptions =
0090 Transform3JsonConverter::Options{};
0091
0092 bool writeMaterial = true;
0093
0094 bool portal = false;
0095 };
0096
0097
0098
0099
0100
0101
0102
0103
0104 nlohmann::json toJson(const GeometryContext& gctx, const Surface& surface,
0105 const Options& options = Options{});
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116 nlohmann::json toJsonDetray(const GeometryContext& gctx, const Surface& surface,
0117 const Options& options = Options{});
0118
0119
0120
0121
0122
0123
0124 std::shared_ptr<Surface> fromJson(const nlohmann::json& jSurface);
0125
0126 }
0127
0128
0129 NLOHMANN_JSON_SERIALIZE_ENUM(
0130 Surface::SurfaceType,
0131 {{Surface::SurfaceType::Cone, "ConeSurface"},
0132 {Surface::SurfaceType::Cylinder, "CylinderSurface"},
0133 {Surface::SurfaceType::Disc, "DiscSurface"},
0134 {Surface::SurfaceType::Perigee, "PerigeeSurface"},
0135 {Surface::SurfaceType::Plane, "PlaneSurface"},
0136 {Surface::SurfaceType::Straw, "StrawSurface"},
0137 {Surface::SurfaceType::Curvilinear, "CurvilinearSurface"},
0138 {Surface::SurfaceType::Other, "Other"}})
0139
0140 }