Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /acts/Tests/UnitTests/Plugins/ActSVG/SurfaceSvgConverterTests.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Geometry/GeometryContext.hpp"
0012 #include "Acts/Surfaces/AnnulusBounds.hpp"
0013 #include "Acts/Surfaces/ConvexPolygonBounds.hpp"
0014 #include "Acts/Surfaces/DiamondBounds.hpp"
0015 #include "Acts/Surfaces/DiscSurface.hpp"
0016 #include "Acts/Surfaces/PlaneSurface.hpp"
0017 #include "Acts/Surfaces/RadialBounds.hpp"
0018 #include "Acts/Surfaces/RectangleBounds.hpp"
0019 #include "Acts/Surfaces/TrapezoidBounds.hpp"
0020 #include "Acts/Utilities/Diagnostics.hpp"
0021 #include "Acts/Utilities/TransformHelpers.hpp"
0022 #include "ActsPlugins/ActSVG/SurfaceSvgConverter.hpp"
0023 #include "ActsPlugins/ActSVG/SvgUtils.hpp"
0024 
0025 #include <fstream>
0026 #include <numbers>
0027 
0028 using namespace Acts;
0029 using namespace ActsPlugins;
0030 
0031 namespace ActsTests {
0032 
0033 /// Helper to run planar Test
0034 ///
0035 /// @param surface
0036 /// @param identification
0037 void runPlanarTests(const Surface& surface, const Svg::Style& style,
0038                     const std::string& identification) {
0039   // Default Geometry context
0040   auto geoCtx = GeometryContext::dangerouslyDefaultConstruct();
0041 
0042   using SurfaceOptions = Svg::SurfaceConverter::Options;
0043 
0044   SurfaceOptions sOptions;
0045   sOptions.style = style;
0046   sOptions.templateSurface = true;
0047 
0048   // Svg proto object & actual object
0049   auto svgTemplate = Svg::SurfaceConverter::convert(geoCtx, surface, sOptions);
0050   auto xyTemplate = Svg::View::xy(svgTemplate, identification + "_template");
0051   Svg::toFile({xyTemplate}, xyTemplate._id + ".svg");
0052   // Positioned
0053   sOptions.templateSurface = false;
0054   auto svgObject = Svg::SurfaceConverter::convert(geoCtx, surface, sOptions);
0055   auto xyObject = Svg::View::xy(svgObject, identification);
0056   auto xyAxes = Svg::axesXY(static_cast<double>(xyObject._x_range[0]),
0057                             static_cast<double>(xyObject._x_range[1]),
0058                             static_cast<double>(xyObject._y_range[0]),
0059                             static_cast<double>(xyObject._y_range[1]));
0060 
0061   Svg::toFile({xyObject, xyAxes}, xyObject._id + ".svg");
0062 }
0063 
0064 BOOST_AUTO_TEST_SUITE(ActSvg)
0065 
0066 // actsvg 0.4.57 removed the sheet displays; the entry point is kept as a
0067 // deprecated stub so callers get a diagnostic rather than a missing symbol.
0068 BOOST_AUTO_TEST_CASE(SurfaceSheetThrows) {
0069   Svg::ProtoSurface pSurface;
0070   ACTS_PUSH_IGNORE_DEPRECATED()
0071   BOOST_CHECK_THROW(Svg::Sheet::xy(pSurface, "sheet"), std::runtime_error);
0072   ACTS_POP_IGNORE_DEPRECATED()
0073 }
0074 
0075 BOOST_AUTO_TEST_CASE(PlanarSurfaces) {
0076   // Planar style
0077   Svg::Style planarStyle;
0078   planarStyle.fillColor = {51, 153, 255};
0079   planarStyle.fillOpacity = 0.75;
0080   planarStyle.highlightColor = {255, 153, 51};
0081   planarStyle.highlights = {"mouseover", "mouseout"};
0082   planarStyle.strokeWidth = 0.5;
0083   planarStyle.quarterSegments = 0u;
0084 
0085   // Rectangle case
0086   auto rectangleBounds = std::make_shared<RectangleBounds>(36., 64.);
0087   auto transform = Transform3::Identity();
0088   transform.pretranslate(Vector3{20., 20., 100.});
0089   auto rectanglePlane =
0090       Surface::makeShared<PlaneSurface>(transform, rectangleBounds);
0091   runPlanarTests(*rectanglePlane, planarStyle, "rectangle");
0092 
0093   // Trapezoid case:
0094   auto trapezoidBounds = std::make_shared<TrapezoidBounds>(36., 64., 105.);
0095   auto trapeozidPlane =
0096       Surface::makeShared<PlaneSurface>(transform, trapezoidBounds);
0097   runPlanarTests(*trapeozidPlane, planarStyle, "trapezoid");
0098 
0099   // Trapezoid case shifted and rotated
0100   double phi = std::numbers::pi / 8.;
0101   double radius = 150.;
0102   Vector3 center(radius * std::cos(phi), radius * std::sin(phi), 0.);
0103 
0104   Vector3 localY(std::cos(phi), std::sin(phi), 0.);
0105   Vector3 localZ(0., 0., 1.);
0106   Vector3 localX = localY.cross(localZ);
0107   RotationMatrix3 rotation;
0108   rotation.col(0) = localX;
0109   rotation.col(1) = localY;
0110   rotation.col(2) = localZ;
0111   transform = makeTransform3(rotation, center);
0112   // Create the module surface
0113   auto trapeozidPlaneTransformed =
0114       Surface::makeShared<PlaneSurface>(transform, trapezoidBounds);
0115 
0116   runPlanarTests(*trapeozidPlaneTransformed, planarStyle, "trapezoid_rotated");
0117   // A reference test for the rotated one
0118   auto geoCtx = GeometryContext::dangerouslyDefaultConstruct();
0119   actsvg::proto::surface<std::vector<Vector3>> reference;
0120   reference._vertices =
0121       trapeozidPlaneTransformed->polyhedronRepresentation(geoCtx, 1u).vertices;
0122   auto referenceTrapezoid = Svg::View::xy(reference, "trapezoid");
0123   auto referenceAxes = Svg::axesXY(-200., 200., -200., 200);
0124   Svg::toFile({referenceTrapezoid, referenceAxes}, "trapezoid_reference.svg");
0125 
0126   // Let's create one with a flipped z-axis
0127   Vector3 flocalZ(0., 0., -1.);
0128   Vector3 flocalX = localY.cross(flocalZ);
0129   RotationMatrix3 frotation;
0130   frotation.col(0) = flocalX;
0131   frotation.col(1) = localY;
0132   frotation.col(2) = flocalZ;
0133   auto ftransform = makeTransform3(frotation, center);
0134   // Create the module surface
0135   auto ftrapeozidPlaneTransformed =
0136       Surface::makeShared<PlaneSurface>(ftransform, trapezoidBounds);
0137 
0138   runPlanarTests(*ftrapeozidPlaneTransformed, planarStyle,
0139                  "flipped_trapezoid_rotated");
0140   actsvg::proto::surface<std::vector<Vector3>> freference;
0141   freference._vertices =
0142       ftrapeozidPlaneTransformed->polyhedronRepresentation(geoCtx, 1u).vertices;
0143 
0144   auto freferenceTrapezoid = Svg::View::xy(freference, "flipped_trapezoid");
0145   Svg::toFile({freferenceTrapezoid, referenceAxes},
0146               "flipped_trapezoid_reference.svg");
0147 
0148   // Diamond
0149   auto diamondBounds = std::make_shared<DiamondBounds>(36., 64., 14., 40., 30.);
0150   transform = Transform3::Identity();
0151   auto diamond = Surface::makeShared<PlaneSurface>(transform, diamondBounds);
0152   runPlanarTests(*diamond, planarStyle, "diamond");
0153 
0154   // ConvexPolygon
0155   std::vector<Vector2> vertices = {
0156       {-10., -10.}, {10., -15.}, {20., 5.}, {-5., 15.}, {-12, 0.}};
0157   auto polygonBounds = std::make_shared<ConvexPolygonBounds<5u>>(vertices);
0158   auto polygon = Surface::makeShared<PlaneSurface>(transform, polygonBounds);
0159   runPlanarTests(*polygon, planarStyle, "polygon");
0160 }
0161 
0162 BOOST_AUTO_TEST_CASE(DiscSurfaces) {
0163   // Planar style
0164   Svg::Style discStyle;
0165   discStyle.fillColor = {0, 204, 153};
0166   discStyle.fillOpacity = 0.75;
0167   discStyle.highlightColor = {153, 204, 0};
0168   discStyle.highlights = {"mouseover", "mouseout"};
0169   discStyle.strokeWidth = 0.5;
0170   discStyle.quarterSegments = 72u;
0171 
0172   auto transform = Transform3::Identity();
0173   transform.pretranslate(Vector3{20., 20., 100.});
0174 
0175   // Full disc case
0176   auto fullDiscBounds = std::make_shared<RadialBounds>(0., 64.);
0177   auto fullDisc = Surface::makeShared<DiscSurface>(transform, fullDiscBounds);
0178   runPlanarTests(*fullDisc, discStyle, "full_disc");
0179 
0180   // Full ring case:
0181   auto fullRingBounds = std::make_shared<RadialBounds>(36., 64.);
0182   auto fullRing = Surface::makeShared<DiscSurface>(transform, fullRingBounds);
0183   runPlanarTests(*fullRing, discStyle, "full_ring");
0184 
0185   // Sectorial disc case
0186   auto sectoralDiscBounds = std::make_shared<RadialBounds>(
0187       0., 64., std::numbers::pi / 4., std::numbers::pi / 2.);
0188   auto sectoralDisc =
0189       Surface::makeShared<DiscSurface>(transform, sectoralDiscBounds);
0190   runPlanarTests(*sectoralDisc, discStyle, "full_disc");
0191 
0192   // Annulus shape
0193   double minRadius = 7.2;
0194   double maxRadius = 12.0;
0195   double minPhi = 0.74195;
0196   double maxPhi = 1.33970;
0197 
0198   Vector2 offset{-3., 2.};
0199 
0200   auto annulusDiscBounds = std::make_shared<AnnulusBounds>(
0201       minRadius, maxRadius, minPhi, maxPhi, offset);
0202   auto annulusDisc =
0203       Surface::makeShared<DiscSurface>(transform, annulusDiscBounds);
0204   runPlanarTests(*annulusDisc, discStyle, "annulus_disc");
0205 }
0206 
0207 BOOST_AUTO_TEST_SUITE_END()
0208 
0209 }  // namespace ActsTests