File indexing completed on 2025-10-29 07:55:54
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Direction.hpp"
0013 #include "Acts/Detector/Portal.hpp"
0014 #include "Acts/Detector/detail/PortalHelper.hpp"
0015 #include "Acts/Geometry/GeometryContext.hpp"
0016 #include "Acts/Surfaces/CurvilinearSurface.hpp"
0017 #include "Acts/Surfaces/PlaneSurface.hpp"
0018 #include "Acts/Surfaces/Surface.hpp"
0019 #include "ActsPlugins/Json/PortalJsonConverter.hpp"
0020 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0021
0022 #include <fstream>
0023
0024 #include <nlohmann/json.hpp>
0025
0026 namespace Acts::Experimental {
0027 class DetectorVolume {};
0028 }
0029
0030 using namespace Acts;
0031
0032 GeometryContext tContext;
0033
0034 namespace ActsTests {
0035
0036 BOOST_AUTO_TEST_SUITE(JsonSuite)
0037
0038 BOOST_AUTO_TEST_CASE(PortalUnconnected) {
0039 std::ofstream out;
0040
0041 std::shared_ptr<PlaneSurface> surface =
0042 CurvilinearSurface(Vector3(0., 0., 0.), Vector3(0., 1., 0.))
0043 .planeSurface();
0044
0045 auto portal = std::make_shared<Experimental::Portal>(std::move(surface));
0046
0047 BOOST_CHECK_NE(portal, nullptr);
0048
0049 auto jPortal = PortalJsonConverter::toJson(tContext, *portal, {});
0050
0051 out.open("portal.json");
0052 out << jPortal.dump(4);
0053 out.close();
0054
0055
0056 auto in =
0057 std::ifstream("portal.json", std::ifstream::in | std::ifstream::binary);
0058 BOOST_CHECK(in.good());
0059 nlohmann::json jPortalIn;
0060 in >> jPortalIn;
0061 in.close();
0062
0063 auto portalIn = PortalJsonConverter::fromJson(tContext, jPortalIn, {});
0064
0065 BOOST_CHECK_NE(portalIn, nullptr);
0066 }
0067
0068 BOOST_AUTO_TEST_CASE(PortalSingleConnected) {
0069 std::ofstream out;
0070
0071 auto forwardVolume = std::make_shared<Experimental::DetectorVolume>();
0072 auto backwardVolume = std::make_shared<Experimental::DetectorVolume>();
0073
0074 std::shared_ptr<PlaneSurface> surface =
0075 CurvilinearSurface(Vector3(0., 0., 0.), Vector3(0., 1., 0.))
0076 .planeSurface();
0077
0078 auto portal = std::make_shared<Experimental::Portal>(std::move(surface));
0079 BOOST_CHECK_NE(portal, nullptr);
0080
0081 Experimental::detail::PortalHelper::attachExternalNavigationDelegate(
0082 *portal, forwardVolume, Direction::Forward());
0083 Experimental::detail::PortalHelper::attachExternalNavigationDelegate(
0084 *portal, backwardVolume, Direction::Backward());
0085
0086 std::vector<const Experimental::DetectorVolume*> detectorVolumes = {
0087 forwardVolume.get(), backwardVolume.get()};
0088
0089 BOOST_CHECK_THROW(PortalJsonConverter::toJson(tContext, *portal, {}),
0090 std::runtime_error);
0091 auto jPortal =
0092 PortalJsonConverter::toJson(tContext, *portal, detectorVolumes);
0093
0094 out.open("portal-single-connected.json");
0095 out << jPortal.dump(4);
0096 out.close();
0097
0098
0099 auto in = std::ifstream("portal-single-connected.json",
0100 std::ifstream::in | std::ifstream::binary);
0101 BOOST_CHECK(in.good());
0102 nlohmann::json jPortalIn;
0103 in >> jPortalIn;
0104 in.close();
0105
0106 auto portalIn = PortalJsonConverter::fromJson(
0107 tContext, jPortalIn, {forwardVolume, backwardVolume});
0108 BOOST_CHECK_NE(portalIn, nullptr);
0109 }
0110
0111 BOOST_AUTO_TEST_CASE(PortalMultiConnected) {
0112 std::ofstream out;
0113
0114 auto forwardVolumeA = std::make_shared<Experimental::DetectorVolume>();
0115 auto forwardVolumeB = std::make_shared<Experimental::DetectorVolume>();
0116 auto forwardVolumeC = std::make_shared<Experimental::DetectorVolume>();
0117
0118 auto backwardVolume = std::make_shared<Experimental::DetectorVolume>();
0119
0120 std::shared_ptr<PlaneSurface> surface =
0121 CurvilinearSurface(Vector3(0., 0., 0.), Vector3(0., 1., 0.))
0122 .planeSurface();
0123
0124 auto portal = std::make_shared<Experimental::Portal>(std::move(surface));
0125 BOOST_CHECK_NE(portal, nullptr);
0126
0127
0128 Experimental::detail::PortalHelper::attachExternalNavigationDelegate(
0129 *portal, backwardVolume, Direction::Backward());
0130
0131 Experimental::detail::PortalHelper::attachDetectorVolumesUpdater(
0132 tContext, *portal, {forwardVolumeA, forwardVolumeB, forwardVolumeC},
0133 Direction::Forward(), {-100, 10, 20, 200}, AxisDirection::AxisX);
0134
0135 std::vector<const Experimental::DetectorVolume*> detectorVolumes = {
0136 forwardVolumeA.get(), forwardVolumeB.get(), forwardVolumeC.get(),
0137 backwardVolume.get()};
0138
0139 auto jPortal =
0140 PortalJsonConverter::toJson(tContext, *portal, detectorVolumes);
0141
0142 out.open("portal-multi-connected.json");
0143 out << jPortal.dump(4);
0144 out.close();
0145 }
0146
0147 BOOST_AUTO_TEST_SUITE_END()
0148
0149 }