File indexing completed on 2026-07-31 08:19:06
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/Geometry/GeometryContext.hpp"
0013 #include "Acts/Geometry/GeometryIdentifier.hpp"
0014 #include "Acts/Surfaces/ConeBounds.hpp"
0015 #include "Acts/Surfaces/ConeSurface.hpp"
0016 #include "Acts/Surfaces/CylinderBounds.hpp"
0017 #include "Acts/Surfaces/CylinderSurface.hpp"
0018 #include "Acts/Surfaces/DiamondBounds.hpp"
0019 #include "Acts/Surfaces/DiscSurface.hpp"
0020 #include "Acts/Surfaces/LineBounds.hpp"
0021 #include "Acts/Surfaces/PerigeeSurface.hpp"
0022 #include "Acts/Surfaces/PlaneSurface.hpp"
0023 #include "Acts/Surfaces/PointBounds.hpp"
0024 #include "Acts/Surfaces/PointSurface.hpp"
0025 #include "Acts/Surfaces/RadialBounds.hpp"
0026 #include "Acts/Surfaces/StrawSurface.hpp"
0027 #include "Acts/Surfaces/Surface.hpp"
0028 #include "Acts/Surfaces/SurfaceBounds.hpp"
0029 #include "Acts/Surfaces/TrapezoidBounds.hpp"
0030 #include "ActsPlugins/Json/SurfaceJsonConverter.hpp"
0031
0032 #include <fstream>
0033 #include <memory>
0034 #include <string>
0035
0036 #include <nlohmann/json.hpp>
0037
0038 using namespace Acts;
0039
0040 namespace {
0041 std::ofstream out;
0042
0043 auto gctx = GeometryContext::dangerouslyDefaultConstruct();
0044 }
0045
0046 namespace ActsTests {
0047
0048 BOOST_AUTO_TEST_SUITE(JsonSuite)
0049
0050 BOOST_AUTO_TEST_CASE(ConeSurfaceRoundTripTests) {
0051 Transform3 trf(Transform3::Identity() * Translation3(0., 0., -7.));
0052 auto cone = std::make_shared<ConeBounds>(0.123, 10., 100.);
0053 auto coneRef = Surface::makeShared<ConeSurface>(trf, cone);
0054 coneRef->assignGeometryId(GeometryIdentifier(13u));
0055
0056
0057 nlohmann::json coneOut = SurfaceJsonConverter::toJson(gctx, *coneRef);
0058 out.open("ConeSurface.json");
0059 out << coneOut.dump(2);
0060 out.close();
0061
0062 auto in = std::ifstream("ConeSurface.json",
0063 std::ifstream::in | std::ifstream::binary);
0064 BOOST_CHECK(in.good());
0065 nlohmann::json coneIn;
0066 in >> coneIn;
0067 in.close();
0068
0069 auto coneTest = SurfaceJsonConverter::fromJson(coneIn);
0070
0071 BOOST_CHECK(coneTest->localToGlobalTransform(gctx).isApprox(
0072 coneRef->localToGlobalTransform(gctx)));
0073 BOOST_CHECK_EQUAL(coneTest->geometryId(), coneRef->geometryId());
0074 BOOST_CHECK_EQUAL(coneTest->bounds(), coneRef->bounds());
0075 }
0076
0077 BOOST_AUTO_TEST_CASE(DiscSurfaceRoundTripTests) {
0078 Transform3 trf(Transform3::Identity() * Translation3(0., 0., -7.));
0079 auto ring = std::make_shared<RadialBounds>(0., 4.);
0080 auto ringDiscRef = Surface::makeShared<DiscSurface>(trf, ring);
0081 ringDiscRef->assignGeometryId(GeometryIdentifier(10u));
0082
0083
0084 nlohmann::json discOut = SurfaceJsonConverter::toJson(gctx, *ringDiscRef);
0085 out.open("DiscSurface.json");
0086 out << discOut.dump(2);
0087 out.close();
0088
0089 auto in = std::ifstream("DiscSurface.json",
0090 std::ifstream::in | std::ifstream::binary);
0091 BOOST_CHECK(in.good());
0092 nlohmann::json discIn;
0093 in >> discIn;
0094 in.close();
0095
0096 auto ringDiscTest = SurfaceJsonConverter::fromJson(discIn);
0097
0098 BOOST_CHECK(ringDiscTest->localToGlobalTransform(gctx).isApprox(
0099 ringDiscRef->localToGlobalTransform(gctx)));
0100 BOOST_CHECK_EQUAL(ringDiscTest->geometryId(), ringDiscRef->geometryId());
0101 BOOST_CHECK_EQUAL(ringDiscTest->bounds(), ringDiscRef->bounds());
0102 }
0103
0104 BOOST_AUTO_TEST_CASE(CylinderSurfaceRoundTripTests) {
0105 Transform3 trf(Transform3::Identity() * Translation3(0., 0., -7.));
0106 auto tube = std::make_shared<CylinderBounds>(5., 20.);
0107 auto cylinderRef = Surface::makeShared<CylinderSurface>(trf, tube);
0108 cylinderRef->assignGeometryId(GeometryIdentifier(11u));
0109
0110
0111 nlohmann::json cylinderOut = SurfaceJsonConverter::toJson(gctx, *cylinderRef);
0112 out.open("CylinderSurface.json");
0113 out << cylinderOut.dump(2);
0114 out.close();
0115
0116 auto in = std::ifstream("CylinderSurface.json",
0117 std::ifstream::in | std::ifstream::binary);
0118 BOOST_CHECK(in.good());
0119 nlohmann::json cylinderIn;
0120 in >> cylinderIn;
0121 in.close();
0122
0123 auto cylinderTest = SurfaceJsonConverter::fromJson(cylinderIn);
0124
0125 BOOST_CHECK(cylinderTest->localToGlobalTransform(gctx).isApprox(
0126 cylinderRef->localToGlobalTransform(gctx)));
0127 BOOST_CHECK_EQUAL(cylinderTest->geometryId(), cylinderRef->geometryId());
0128 BOOST_CHECK_EQUAL(cylinderTest->bounds(), cylinderRef->bounds());
0129 }
0130
0131 BOOST_AUTO_TEST_CASE(PlaneSurfaceRoundTripTests) {
0132 Transform3 trf(Transform3::Identity() * Translation3(0., 0., -7.));
0133 auto trapezoid = std::make_shared<TrapezoidBounds>(2., 3., 4.);
0134 auto trapezoidPlaneRef = Surface::makeShared<PlaneSurface>(trf, trapezoid);
0135 trapezoidPlaneRef->assignGeometryId(GeometryIdentifier(9u));
0136
0137
0138 nlohmann::json planeOut =
0139 SurfaceJsonConverter::toJson(gctx, *trapezoidPlaneRef);
0140 to_json(planeOut, *trapezoidPlaneRef);
0141 out.open("PlaneSurface.json");
0142 out << planeOut.dump(2);
0143 out.close();
0144
0145 auto in = std::ifstream("PlaneSurface.json",
0146 std::ifstream::in | std::ifstream::binary);
0147 BOOST_CHECK(in.good());
0148 nlohmann::json planeIn;
0149 in >> planeIn;
0150 in.close();
0151
0152 auto trapezoidPlaneTest = SurfaceJsonConverter::fromJson(planeIn);
0153
0154 BOOST_CHECK(trapezoidPlaneTest->localToGlobalTransform(gctx).isApprox(
0155 trapezoidPlaneRef->localToGlobalTransform(gctx)));
0156 BOOST_CHECK_EQUAL(trapezoidPlaneTest->geometryId(),
0157 trapezoidPlaneRef->geometryId());
0158 BOOST_CHECK_EQUAL(trapezoidPlaneTest->bounds(), trapezoidPlaneRef->bounds());
0159 }
0160
0161 BOOST_AUTO_TEST_CASE(StrawSurfaceRoundTripTests) {
0162 Transform3 trf(Transform3::Identity() * Translation3(0., 0., -7.));
0163 auto straw = std::make_shared<LineBounds>(1., 100.);
0164 auto strawRef = Surface::makeShared<StrawSurface>(trf, straw);
0165 strawRef->assignGeometryId(GeometryIdentifier(12u));
0166
0167
0168 nlohmann::json strawOut = SurfaceJsonConverter::toJson(gctx, *strawRef);
0169 out.open("StrawSurface.json");
0170 out << strawOut.dump(2);
0171 out.close();
0172
0173 auto in = std::ifstream("StrawSurface.json",
0174 std::ifstream::in | std::ifstream::binary);
0175 BOOST_CHECK(in.good());
0176 nlohmann::json strawIn;
0177 in >> strawIn;
0178 in.close();
0179
0180 auto strawTest = SurfaceJsonConverter::fromJson(strawIn);
0181
0182 BOOST_CHECK(strawTest->localToGlobalTransform(gctx).isApprox(
0183 strawRef->localToGlobalTransform(gctx)));
0184 BOOST_CHECK_EQUAL(strawTest->geometryId(), strawRef->geometryId());
0185 BOOST_CHECK_EQUAL(strawTest->bounds(), strawRef->bounds());
0186 }
0187
0188 BOOST_AUTO_TEST_CASE(PerigeeRoundTripTests) {
0189 Transform3 trf(Transform3::Identity() * Translation3(-1., -2., -7.));
0190 auto perigeeRef = Surface::makeShared<PerigeeSurface>(trf);
0191 perigeeRef->assignGeometryId(GeometryIdentifier(99u));
0192
0193
0194 nlohmann::json perigeeOut = SurfaceJsonConverter::toJson(gctx, *perigeeRef);
0195 out.open("PerigeeSurface.json");
0196 out << perigeeOut.dump(2);
0197 out.close();
0198
0199 auto in = std::ifstream("PerigeeSurface.json",
0200 std::ifstream::in | std::ifstream::binary);
0201 BOOST_CHECK(in.good());
0202 nlohmann::json perigeeIn;
0203 in >> perigeeIn;
0204 in.close();
0205
0206 auto perigeeTest = SurfaceJsonConverter::fromJson(perigeeIn);
0207
0208 BOOST_CHECK(perigeeTest->localToGlobalTransform(gctx).isApprox(
0209 perigeeRef->localToGlobalTransform(gctx)));
0210 BOOST_CHECK_EQUAL(perigeeTest->geometryId(), perigeeRef->geometryId());
0211 }
0212
0213 BOOST_AUTO_TEST_CASE(PointSurfaceRoundTripTests) {
0214 Transform3 trf(Transform3::Identity() * Translation3(1., -2., 3.));
0215
0216
0217 auto pointRef = Surface::makeShared<PointSurface>(trf);
0218 pointRef->assignGeometryId(GeometryIdentifier(77u));
0219
0220 nlohmann::json pointOut = SurfaceJsonConverter::toJson(gctx, *pointRef);
0221 out.open("PointSurface.json");
0222 out << pointOut.dump(2);
0223 out.close();
0224
0225 auto in = std::ifstream("PointSurface.json",
0226 std::ifstream::in | std::ifstream::binary);
0227 BOOST_CHECK(in.good());
0228 nlohmann::json jPointIn;
0229 in >> jPointIn;
0230 in.close();
0231
0232 auto pointTest = SurfaceJsonConverter::fromJson(jPointIn);
0233 BOOST_CHECK_EQUAL(pointTest->type(), Surface::Point);
0234 BOOST_CHECK(pointTest->localToGlobalTransform(gctx).isApprox(
0235 pointRef->localToGlobalTransform(gctx)));
0236 BOOST_CHECK_EQUAL(pointTest->geometryId(), pointRef->geometryId());
0237
0238
0239 auto pbounds = std::make_shared<PointBounds>(5.);
0240 auto boundedRef = Surface::makeShared<PointSurface>(trf, pbounds);
0241 boundedRef->assignGeometryId(GeometryIdentifier(78u));
0242
0243 nlohmann::json boundedOut = SurfaceJsonConverter::toJson(gctx, *boundedRef);
0244 out.open("PointSurfaceBounded.json");
0245 out << boundedOut.dump(2);
0246 out.close();
0247
0248 auto bins = std::ifstream("PointSurfaceBounded.json",
0249 std::ifstream::in | std::ifstream::binary);
0250 BOOST_CHECK(bins.good());
0251 nlohmann::json jBoundedIn;
0252 bins >> jBoundedIn;
0253 bins.close();
0254
0255 auto boundedTest = SurfaceJsonConverter::fromJson(jBoundedIn);
0256 BOOST_CHECK_EQUAL(boundedTest->type(), Surface::Point);
0257 BOOST_CHECK_EQUAL(boundedTest->bounds(), boundedRef->bounds());
0258 }
0259
0260 BOOST_AUTO_TEST_CASE(DiamondPlaneSurfaceRoundTripTests) {
0261 Transform3 trf(Transform3::Identity() * Translation3(0., 0., -7.));
0262 auto diamond = std::make_shared<DiamondBounds>(1., 3., 2., 4., 5.);
0263 auto diamondPlaneRef = Surface::makeShared<PlaneSurface>(trf, diamond);
0264 diamondPlaneRef->assignGeometryId(GeometryIdentifier(14u));
0265
0266 nlohmann::json planeOut =
0267 SurfaceJsonConverter::toJson(gctx, *diamondPlaneRef);
0268 out.open("DiamondPlaneSurface.json");
0269 out << planeOut.dump(2);
0270 out.close();
0271
0272 auto in = std::ifstream("DiamondPlaneSurface.json",
0273 std::ifstream::in | std::ifstream::binary);
0274 BOOST_CHECK(in.good());
0275 nlohmann::json planeIn;
0276 in >> planeIn;
0277 in.close();
0278
0279 auto diamondPlaneTest = SurfaceJsonConverter::fromJson(planeIn);
0280
0281 BOOST_CHECK(diamondPlaneTest->localToGlobalTransform(gctx).isApprox(
0282 diamondPlaneRef->localToGlobalTransform(gctx)));
0283 BOOST_CHECK_EQUAL(diamondPlaneTest->geometryId(),
0284 diamondPlaneRef->geometryId());
0285 BOOST_CHECK_EQUAL(diamondPlaneTest->bounds(), diamondPlaneRef->bounds());
0286 }
0287
0288 BOOST_AUTO_TEST_SUITE_END()
0289
0290 }