File indexing completed on 2026-07-16 08:08:31
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>(indexGrid.transform * vertex, rphi);
0054
0055 referenceRange[0] = std::min(referenceRange[0], pVertex[0]);
0056 referenceRange[1] = std::max(referenceRange[1], pVertex[0]);
0057 writeReferenceRange = true;
0058
0059 jProjectedSurface.push_back(pVertex);
0060 } else {
0061
0062 jProjectedSurface.push_back(
0063 Acts::GridAccessHelpers::castPosition<decltype(indexGrid.grid)>(
0064 indexGrid.transform * vertex, indexGrid.casts));
0065 }
0066 }
0067 jProjectedSurfaces.push_back(jProjectedSurface);
0068 }
0069 }
0070 }
0071
0072 if (!jSurfaces.empty()) {
0073 jPolicy["surfaces"] = jSurfaces;
0074 }
0075 if (!jProjectedSurfaces.empty()) {
0076 jPolicy["projectedSurfaces"] = jProjectedSurfaces;
0077 }
0078 if (writeReferenceRange) {
0079 jPolicy["projectedReferenceRange"] = referenceRange;
0080 }
0081 }
0082
0083 }
0084
0085 nlohmann::json Acts::IndexGridNavigationJsonConverter::toJson(
0086 const RegularCylinderIndexGridNavigationPolicy& policy) {
0087 nlohmann::json jPolicy;
0088
0089 jPolicy["type"] = "RegularCylinderIndexGridNavigationPolicy";
0090 jPolicy["grid"] = Acts::GridJsonConverter::toJson(policy.indexGrid().grid);
0091 return jPolicy;
0092 }
0093
0094 nlohmann::json Acts::IndexGridNavigationJsonConverter::toJson(
0095 const GeometryContext& gctx,
0096 const RegularCylinderIndexGridNavigationPolicy& policy,
0097 const TrackingVolume& volume, const Options& options) {
0098 nlohmann::json jPolicy = toJson(policy);
0099 writeSurfacesAndProjections(jPolicy, gctx, policy, volume, options);
0100 return jPolicy;
0101 }
0102
0103 nlohmann::json Acts::IndexGridNavigationJsonConverter::toJson(
0104 const RegularPlaneIndexGridNavigationPolicy& policy) {
0105 nlohmann::json jPolicy;
0106
0107 jPolicy["type"] = "RegularPlaneIndexGridNavigationPolicy";
0108 jPolicy["grid"] = Acts::GridJsonConverter::toJson(policy.indexGrid().grid);
0109 return jPolicy;
0110 }
0111
0112 nlohmann::json Acts::IndexGridNavigationJsonConverter::toJson(
0113 const GeometryContext& gctx,
0114 const RegularPlaneIndexGridNavigationPolicy& policy,
0115 const TrackingVolume& volume, const Options& options) {
0116 nlohmann::json jPolicy = toJson(policy);
0117 writeSurfacesAndProjections(jPolicy, gctx, policy, volume, options);
0118 return jPolicy;
0119 }
0120 nlohmann::json Acts::IndexGridNavigationJsonConverter::toJson(
0121 const RegularDiscIndexGridNavigationPolicy& policy) {
0122 nlohmann::json jPolicy;
0123
0124 jPolicy["type"] = "RegularDiscIndexGridNavigationPolicy";
0125 jPolicy["grid"] = Acts::GridJsonConverter::toJson(policy.indexGrid().grid);
0126 return jPolicy;
0127 }
0128
0129 nlohmann::json Acts::IndexGridNavigationJsonConverter::toJson(
0130 const GeometryContext& gctx,
0131 const RegularDiscIndexGridNavigationPolicy& policy,
0132 const TrackingVolume& volume, const Options& options) {
0133 nlohmann::json jPolicy = toJson(policy);
0134 writeSurfacesAndProjections(jPolicy, gctx, policy, volume, options);
0135 return jPolicy;
0136 }
0137
0138 nlohmann::json Acts::IndexGridNavigationJsonConverter::toJson(
0139 const RegularRingIndexGridNavigationPolicy& policy) {
0140 nlohmann::json jPolicy;
0141
0142 jPolicy["type"] = "RegularRingIndexGridNavigationPolicy";
0143 jPolicy["grid"] = Acts::GridJsonConverter::toJson(policy.indexGrid().grid);
0144 return jPolicy;
0145 }
0146
0147 nlohmann::json Acts::IndexGridNavigationJsonConverter::toJson(
0148 const GeometryContext& gctx,
0149 const RegularRingIndexGridNavigationPolicy& policy,
0150 const TrackingVolume& volume, const Options& options) {
0151 nlohmann::json jPolicy = toJson(policy);
0152 writeSurfacesAndProjections(jPolicy, gctx, policy, volume, options);
0153 return jPolicy;
0154 }