File indexing completed on 2026-03-28 07:46:17
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsPlugins/Json/IndexGridNavigationJsonConverter.hpp"
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "ActsPlugins/Json/GridJsonConverter.hpp"
0013
0014 #include <limits>
0015
0016 namespace {
0017
0018
0019 template <typename IndexPolicyType>
0020 void writeSurfacesAndProjections(
0021 nlohmann::json& jPolicy, const Acts::GeometryContext& gctx,
0022 const IndexPolicyType& policy, const Acts::TrackingVolume& volume,
0023 const Acts::IndexGridNavigationJsonConverter::Options& options) {
0024
0025 nlohmann::json jSurfaces = nlohmann::json::array();
0026 nlohmann::json jProjectedSurfaces = nlohmann::json::array();
0027 const auto& indexGrid = policy.indexGrid();
0028
0029 bool writeReferenceRange = false;
0030 std::array<double, 2u> referenceRange = {
0031 std::numeric_limits<double>::max(),
0032 std::numeric_limits<double>::lowest()};
0033
0034 if (options.writeSurfaces || options.writeProjectedSurfaces) {
0035 for (const auto& surface : volume.surfaces()) {
0036 if (options.writeSurfaces) {
0037 nlohmann::json jSurface =
0038 Acts::SurfaceJsonConverter::toJson(gctx, surface);
0039 jSurfaces.push_back(jSurface);
0040 }
0041
0042 if (options.writeProjectedSurfaces) {
0043 nlohmann::json jProjectedSurface;
0044 auto polyhedron =
0045 surface.polyhedronRepresentation(gctx, options.numPolyhedronPoints);
0046 for (const auto& vertex : polyhedron.vertices) {
0047
0048 if (indexGrid.casts.size() == 1u &&
0049 indexGrid.casts[0] == Acts::AxisDirection::AxisPhi) {
0050 std::array<Acts::AxisDirection, 2u> rphi = {
0051 Acts::AxisDirection::AxisR, Acts::AxisDirection::AxisPhi};
0052 auto pVertex = Acts::GridAccessHelpers::castPosition<
0053 Acts::RegularDiscIndexGrid>(
0054 indexGrid.toLocalFrame(gctx) * vertex, rphi);
0055
0056 referenceRange[0] = std::min(referenceRange[0], pVertex[0]);
0057 referenceRange[1] = std::max(referenceRange[1], pVertex[0]);
0058 writeReferenceRange = true;
0059
0060 jProjectedSurface.push_back(pVertex);
0061 } else {
0062
0063 jProjectedSurface.push_back(
0064 Acts::GridAccessHelpers::castPosition<decltype(indexGrid.grid)>(
0065 indexGrid.toLocalFrame(gctx) * vertex, indexGrid.casts));
0066 }
0067 }
0068 jProjectedSurfaces.push_back(jProjectedSurface);
0069 }
0070 }
0071 }
0072
0073 if (!jSurfaces.empty()) {
0074 jPolicy["surfaces"] = jSurfaces;
0075 }
0076 if (!jProjectedSurfaces.empty()) {
0077 jPolicy["projectedSurfaces"] = jProjectedSurfaces;
0078 }
0079 if (writeReferenceRange) {
0080 jPolicy["projectedReferenceRange"] = referenceRange;
0081 }
0082 }
0083
0084 }
0085
0086 nlohmann::json Acts::IndexGridNavigationJsonConverter::toJson(
0087 const RegularCylinderIndexGridNavigationPolicy& policy) {
0088 nlohmann::json jPolicy;
0089
0090 jPolicy["type"] = "RegularCylinderIndexGridNavigationPolicy";
0091 jPolicy["grid"] = Acts::GridJsonConverter::toJson(policy.indexGrid().grid);
0092 return jPolicy;
0093 }
0094
0095 nlohmann::json Acts::IndexGridNavigationJsonConverter::toJson(
0096 const GeometryContext& gctx,
0097 const RegularCylinderIndexGridNavigationPolicy& policy,
0098 const TrackingVolume& volume, const Options& options) {
0099 nlohmann::json jPolicy = toJson(policy);
0100 writeSurfacesAndProjections(jPolicy, gctx, policy, volume, options);
0101 return jPolicy;
0102 }
0103
0104 nlohmann::json Acts::IndexGridNavigationJsonConverter::toJson(
0105 const RegularPlaneIndexGridNavigationPolicy& policy) {
0106 nlohmann::json jPolicy;
0107
0108 jPolicy["type"] = "RegularPlaneIndexGridNavigationPolicy";
0109 jPolicy["grid"] = Acts::GridJsonConverter::toJson(policy.indexGrid().grid);
0110 return jPolicy;
0111 }
0112
0113 nlohmann::json Acts::IndexGridNavigationJsonConverter::toJson(
0114 const GeometryContext& gctx,
0115 const RegularPlaneIndexGridNavigationPolicy& policy,
0116 const TrackingVolume& volume, const Options& options) {
0117 nlohmann::json jPolicy = toJson(policy);
0118 writeSurfacesAndProjections(jPolicy, gctx, policy, volume, options);
0119 return jPolicy;
0120 }
0121 nlohmann::json Acts::IndexGridNavigationJsonConverter::toJson(
0122 const RegularDiscIndexGridNavigationPolicy& policy) {
0123 nlohmann::json jPolicy;
0124
0125 jPolicy["type"] = "RegularDiscIndexGridNavigationPolicy";
0126 jPolicy["grid"] = Acts::GridJsonConverter::toJson(policy.indexGrid().grid);
0127 return jPolicy;
0128 }
0129
0130 nlohmann::json Acts::IndexGridNavigationJsonConverter::toJson(
0131 const GeometryContext& gctx,
0132 const RegularDiscIndexGridNavigationPolicy& policy,
0133 const TrackingVolume& volume, const Options& options) {
0134 nlohmann::json jPolicy = toJson(policy);
0135 writeSurfacesAndProjections(jPolicy, gctx, policy, volume, options);
0136 return jPolicy;
0137 }
0138
0139 nlohmann::json Acts::IndexGridNavigationJsonConverter::toJson(
0140 const RegularRingIndexGridNavigationPolicy& policy) {
0141 nlohmann::json jPolicy;
0142
0143 jPolicy["type"] = "RegularRingIndexGridNavigationPolicy";
0144 jPolicy["grid"] = Acts::GridJsonConverter::toJson(policy.indexGrid().grid);
0145 return jPolicy;
0146 }
0147
0148 nlohmann::json Acts::IndexGridNavigationJsonConverter::toJson(
0149 const GeometryContext& gctx,
0150 const RegularRingIndexGridNavigationPolicy& policy,
0151 const TrackingVolume& volume, const Options& options) {
0152 nlohmann::json jPolicy = toJson(policy);
0153 writeSurfacesAndProjections(jPolicy, gctx, policy, volume, options);
0154 return jPolicy;
0155 }