File indexing completed on 2025-10-21 08:04:46
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/Detector/DetectorVolume.hpp"
0013 #include "Acts/Detector/PortalGenerators.hpp"
0014 #include "Acts/Detector/detail/CylindricalDetectorHelper.hpp"
0015 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
0016 #include "Acts/Navigation/InternalNavigation.hpp"
0017 #include "Acts/Utilities/Enumerate.hpp"
0018 #include "ActsPlugins/ActSVG/PortalSvgConverter.hpp"
0019 #include "ActsPlugins/ActSVG/SvgUtils.hpp"
0020
0021 #include <algorithm>
0022 #include <fstream>
0023 #include <memory>
0024 #include <ranges>
0025 #include <vector>
0026
0027 using namespace Acts;
0028 using namespace ActsPlugins;
0029
0030 GeometryContext tContext;
0031
0032 namespace ActsTests {
0033
0034 BOOST_AUTO_TEST_SUITE(ActSvgSuite)
0035
0036 BOOST_AUTO_TEST_CASE(CylinderPortalsSvg) {
0037
0038 Svg::Style portalStyle;
0039 portalStyle.fillColor = {255, 255, 255};
0040 portalStyle.fillOpacity = 0.;
0041 portalStyle.highlightColor = {255, 255, 255};
0042 portalStyle.highlights = {};
0043 portalStyle.strokeColor = {25, 25, 25};
0044 portalStyle.strokeWidth = 0.5;
0045 portalStyle.quarterSegments = 72u;
0046
0047 double rInner = 10.;
0048 double rOuter = 100.;
0049 double zHalfL = 200.;
0050
0051 Transform3 nominal = Transform3::Identity();
0052
0053 auto cylinderBounds =
0054 std::make_unique<CylinderVolumeBounds>(rInner, rOuter, zHalfL);
0055
0056 auto portalGenerator = Experimental::defaultPortalGenerator();
0057
0058 auto cylinderVolume = Experimental::DetectorVolumeFactory::construct(
0059 portalGenerator, tContext, "CylinderVolume", nominal,
0060 std::move(cylinderBounds), Experimental::tryAllPortals());
0061
0062 Svg::PortalConverter::Options portalOptions;
0063 portalOptions.volumeIndices[cylinderVolume.get()] = 0;
0064 Svg::SurfaceConverter::Options surfaceOptions;
0065 surfaceOptions.style = portalStyle;
0066 portalOptions.surfaceOptions = surfaceOptions;
0067
0068 std::vector<Svg::ProtoPortal> protoPortals;
0069
0070 std::ranges::for_each(cylinderVolume->portals(), [&](const auto& p) {
0071 protoPortals.push_back(
0072 Svg::PortalConverter::convert(tContext, *p, portalOptions));
0073 });
0074
0075
0076 std::vector<actsvg::svg::object> zrPortals;
0077 std::size_t ip = 0;
0078 std::ranges::for_each(protoPortals, [&](const auto& p) {
0079 zrPortals.push_back(Svg::View::zr(p, "Portal_zr" + std::to_string(ip++)));
0080 });
0081 Svg::toFile(zrPortals, "SimpleCylinderPortals_ZR.svg");
0082
0083
0084 std::vector<actsvg::svg::object> xyPortals;
0085 ip = 0;
0086 std::ranges::for_each(protoPortals, [&](const auto& p) {
0087 xyPortals.push_back(Svg::View::xy(p, "Portal_xy" + std::to_string(ip++)));
0088 });
0089 Svg::toFile(xyPortals, "SimpleCylinderPortals_XY.svg");
0090 }
0091
0092 BOOST_AUTO_TEST_CASE(CylinderContainerPortalsSvg) {
0093
0094 Svg::Style portalStyle;
0095 portalStyle.fillColor = {255, 255, 255};
0096 portalStyle.fillOpacity = 0.;
0097 portalStyle.highlightColor = {255, 255, 255};
0098 portalStyle.highlights = {};
0099 portalStyle.strokeColor = {25, 25, 25};
0100 portalStyle.strokeWidth = 0.5;
0101 portalStyle.quarterSegments = 72u;
0102
0103 double rInner = 10.;
0104 double rMiddle = 100.;
0105 double rOuter = 300.;
0106 double zHalfL = 200.;
0107
0108 Transform3 nominal = Transform3::Identity();
0109
0110 auto portalGenerator = Experimental::defaultPortalGenerator();
0111
0112 auto cylinderBoundsI =
0113 std::make_unique<CylinderVolumeBounds>(rInner, rMiddle, zHalfL);
0114
0115 auto cylinderBoundsO =
0116 std::make_unique<CylinderVolumeBounds>(rMiddle, rOuter, zHalfL);
0117
0118 auto cylinderVolumeI = Experimental::DetectorVolumeFactory::construct(
0119 portalGenerator, tContext, "CylinderVolumeI", nominal,
0120 std::move(cylinderBoundsI), Experimental::tryAllPortals());
0121
0122 auto cylinderVolumeO = Experimental::DetectorVolumeFactory::construct(
0123 portalGenerator, tContext, "CylinderVolumeO", nominal,
0124 std::move(cylinderBoundsO), Experimental::tryAllPortals());
0125
0126 std::vector<std::shared_ptr<Experimental::DetectorVolume>> rVolumes = {
0127 cylinderVolumeI, cylinderVolumeO};
0128
0129 Experimental::detail::CylindricalDetectorHelper::connectInR(tContext,
0130 rVolumes, {});
0131
0132 std::set<const Experimental::Portal*> portals;
0133 for (auto& v : rVolumes) {
0134 for (auto& p : v->portals()) {
0135 portals.insert(p);
0136 }
0137 }
0138 std::vector<Svg::ProtoPortal> protoPortals;
0139
0140 Svg::PortalConverter::Options portalOptions;
0141 portalOptions.volumeIndices[cylinderVolumeI.get()] = 0;
0142 portalOptions.volumeIndices[cylinderVolumeO.get()] = 1;
0143
0144 Svg::SurfaceConverter::Options surfaceOptions;
0145 surfaceOptions.style = portalStyle;
0146 portalOptions.surfaceOptions = surfaceOptions;
0147
0148 for (const auto& portal : portals) {
0149 protoPortals.push_back(
0150 Svg::PortalConverter::convert(tContext, *portal, portalOptions));
0151 }
0152
0153 std::vector<actsvg::svg::object> zrPortals;
0154 std::size_t ip = 0;
0155 std::ranges::for_each(protoPortals, [&](const auto& p) {
0156 zrPortals.push_back(Svg::View::zr(p, "Portal_zr" + std::to_string(ip++)));
0157 });
0158 Svg::toFile(zrPortals, "CylinderContainerPortals_ZR.svg");
0159 }
0160
0161 BOOST_AUTO_TEST_SUITE_END()
0162
0163 }